diff --git a/build.gradle b/build.gradle index b44fbb4..8190ee4 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ dependencies { } group = "org.bdware.sc" -version = "1.7.6" +version = "1.7.8" tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE) task copyLibs(type: Copy) { diff --git a/src/main/base/org/bdware/sc/node/ContractNode.java b/src/main/base/org/bdware/sc/node/ContractNode.java index 8c84638..d2512a8 100644 --- a/src/main/base/org/bdware/sc/node/ContractNode.java +++ b/src/main/base/org/bdware/sc/node/ContractNode.java @@ -130,6 +130,7 @@ public class ContractNode { public void merge(ContractNode contract) { sigRequired |= contract.sigRequired; instrumentBranch |= contract.instrumentBranch; + imports.addAll(contract.getImports()); for (FunctionNode fn : contract.functions) { functions.add(fn); functionMap.put(fn.functionName, fn); @@ -237,7 +238,7 @@ public class ContractNode { } public void maintainRouteJoinInfo(JsonObject methodRouteInfoMap, JsonObject methodJoinInfoMap, - JsonObject dependentFunctions) { + JsonObject dependentFunctions) { // all functions存了ContractNode中,所有的FunctionNode List allFunctions = getFunctions(); for (FunctionNode functionNode : allFunctions) { @@ -262,10 +263,33 @@ public class ContractNode { } } } + + for (InterfaceNode interfaceNode : interfaceMap.values()) { + AnnotationNode doopAnnotation = interfaceNode.getAnnotation("DOOP"); + DoipOperationInfo doipOperationInfo = interfaceNode.getDoipOperationInfo(); + if (doopAnnotation != null && doipOperationInfo != null) { + RouteInfo routeInfo = interfaceNode.getRouteInfo(); + JoinInfo joinInfo = interfaceNode.getJoinInfo(); + if (routeInfo != null) { + packSourceFunctionAndDependentFunctions(getFunction(routeInfo.funcName), + dependentFunctions); + methodRouteInfoMap.add(doipOperationInfo.operationName, + JsonUtil.parseObjectAsJsonObject(routeInfo)); + } + if (joinInfo != null) { + packSourceFunctionAndDependentFunctions(getFunction(joinInfo.joinCountFuncName), + dependentFunctions); + packSourceFunctionAndDependentFunctions(getFunction(joinInfo.joinFuncName), + dependentFunctions); + methodJoinInfoMap.add(doipOperationInfo.operationName, + JsonUtil.parseObjectAsJsonObject(joinInfo)); + } + } + } } public void packSourceFunctionAndDependentFunctions(FunctionNode sourceFunctionNode, - JsonObject functions) { + JsonObject functions) { if (sourceFunctionNode == null) return; functions.addProperty(sourceFunctionNode.functionName, sourceFunctionNode.plainText()); @@ -291,8 +315,16 @@ public class ContractNode { + " -> " + annotationNode.getType()); } functionNode.annotations.addAll(node.annotations); - } else - throw new RuntimeException("unimplemented functions:" + node.functionName); + } else { + //now we accept only interfaces. + //just ignore! + // throw new RuntimeException("unimplemented functions:" + node.functionName); + } + } } + + public Collection getInterfaces() { + return interfaceMap.values(); + } } diff --git a/src/main/base/org/bdware/sc/visitor/FunctionDependencyVisitor.java b/src/main/base/org/bdware/sc/visitor/FunctionDependencyVisitor.java index fc65c42..6965dd4 100644 --- a/src/main/base/org/bdware/sc/visitor/FunctionDependencyVisitor.java +++ b/src/main/base/org/bdware/sc/visitor/FunctionDependencyVisitor.java @@ -5,6 +5,8 @@ import org.bdware.sc.node.FunctionNode; import org.bdware.sc.parser.YJSParser; import org.bdware.sc.parser.YJSParserBaseVisitor; +import java.util.List; + public class FunctionDependencyVisitor extends YJSParserBaseVisitor { public static String APPLY = ".apply"; @@ -21,12 +23,19 @@ public class FunctionDependencyVisitor extends YJSParserBaseVisitor singleExpress = ctx.arguments().singleExpression(); + if (singleExpress != null && singleExpress.size() > 0) { + for (YJSParser.SingleExpressionContext sin : singleExpress) { + funText = sin.getText(); + if (cn.getFunction(funText)!=null) + fn.addDependentFunctions(funText); + } } } return fn;