add DoipOperation relevant update

This commit is contained in:
haoeliu@foxmail.com 2022-11-15 11:50:13 +08:00
parent 611d25a044
commit 4dfca5a4a0
5 changed files with 58 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package org.bdware.sc.node;
import org.antlr.v4.runtime.CommonTokenStream;
import org.bdware.doip.codec.operations.BasicOperations;
import org.bdware.sc.event.REvent.REventSemantics;
import java.util.*;
@ -12,6 +13,7 @@ public class ContractNode {
private final List<ClassNode> clzs;
private final List<FunctionNode> functions;
private final Map<String, FunctionNode> functionMap;
private final Map<BasicOperations, FunctionNode> doipOperationsMap;
private final Set<String> dependentContracts;
public Map<String, REventSemantics> events;
public Map<String, REventSemantics> logs;
@ -38,6 +40,7 @@ public class ContractNode {
permission = new ArrayList<>();
instrumentBranch = false;
dependentContracts = new HashSet<>();
doipOperationsMap = new HashMap<>();
}
public void addFunction(FunctionNode function) {
@ -196,4 +199,25 @@ public class ContractNode {
public void resetContractName(String name) {
contractName = name;
}
public void addDoipOperation(FunctionNode function) {
doipOperationsMap.put(function.getDoipOperationInfo().operationType, function);
}
public FunctionNode getDoipOperation(String action) {
FunctionNode result = null;
for (BasicOperations op : BasicOperations.values()) {
if (op.toString().equals(action)) {
result = doipOperationsMap.get(op);
return result;
}
}
result = doipOperationsMap.get(BasicOperations.Unknown);
return result;
}
public FunctionNode getDoipOperation(BasicOperations basicOperation) {
return doipOperationsMap.get(basicOperation);
}
}

View File

@ -1,6 +1,7 @@
package org.bdware.sc.node;
import com.google.gson.JsonElement;
import org.bdware.sc.bean.DoipOperationInfo;
import org.bdware.sc.bean.JoinInfo;
import org.bdware.sc.bean.RouteInfo;
@ -25,6 +26,7 @@ public class FunctionNode extends Script {
private CostDetail cost;
private RouteInfo routeInfo;
private JoinInfo joinInfo;
private DoipOperationInfo doipOperationInfo;
private boolean isHandler;
private boolean isConfidential;
private boolean isHomomorphicEncrypt;
@ -36,6 +38,14 @@ public class FunctionNode extends Script {
private JsonElement homoDecryptConf;
public transient Class compiledClazz;
public DoipOperationInfo getDoipOperationInfo() {
return doipOperationInfo;
}
public void setDoipOperationInfo(DoipOperationInfo doipOperationInfo) {
this.doipOperationInfo = doipOperationInfo;
}
public FunctionNode(String name, String fileName) {
this.functionName = name;
this.stmts = new ArrayList<>();

View File

@ -3,5 +3,6 @@ package org.bdware.sc.node;
public enum YjsType {
Oracle,
Contract,
DoipModule,
Module
}

View File

@ -72,7 +72,10 @@ public class ContractReader extends YJSParserBaseVisitor<ContractNode> {
node.setYjsType(YjsType.Contract);
} else if (null != contractDelcar.Module()) {
node.setYjsType(YjsType.Module);
} else if (null != contractDelcar.DoipModule()) {
node.setYjsType(YjsType.DoipModule);
}
if (null != contractDelcar.annotations())
annotations = contractDelcar.annotations().annotation();
for (AnnotationContext annotation : annotations) {

View File

@ -0,0 +1,20 @@
package org.bdware.sc.bean;
import org.bdware.doip.codec.operations.BasicOperations;
import org.bdware.sc.node.AnnotationNode;
import org.bdware.sc.node.ContractNode;
import org.bdware.sc.util.JsonUtil;
public class DoipOperationInfo {
public BasicOperations operationType;
public static DoipOperationInfo create(AnnotationNode annotationNode, ContractNode contractNode) {
DoipOperationInfo info = new DoipOperationInfo();
if (annotationNode.getArgs().size() == 1) {
String str = annotationNode.getArgs().get(0);
info = JsonUtil.fromJson(str, DoipOperationInfo.class);
}
System.out.println("[DoipOperationInfo] annotationNode:" + JsonUtil.toJson(annotationNode));
return info;
}
}