optimize dependent function parse

support merge importNodes
This commit is contained in:
CaiHQ 2023-07-24 11:35:51 +08:00
parent bc7a54e9ce
commit 374451dd5b
3 changed files with 52 additions and 11 deletions

View File

@ -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) {

View File

@ -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<FunctionNode> 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<InterfaceNode> getInterfaces() {
return interfaceMap.values();
}
}

View File

@ -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<FunctionNode> {
public static String APPLY = ".apply";
@ -21,12 +23,19 @@ public class FunctionDependencyVisitor extends YJSParserBaseVisitor<FunctionNode
@Override
public FunctionNode visitArgumentsExpression(YJSParser.ArgumentsExpressionContext ctx) {
super.visitArgumentsExpression(ctx);
for (FunctionNode f : cn.getFunctions()) {
if (ctx.singleExpression().getText().equals(f.functionName)
|| ctx.singleExpression().getText().equals(f.functionName + APPLY)
|| ctx.singleExpression().getText().equals(f.functionName + CALL)) {
fn.addDependentFunctions(f.functionName);
break;
String funText = ctx.singleExpression().getText();
if (funText.endsWith(APPLY)) funText = funText.replaceAll(APPLY+"$","");
if (funText.endsWith(CALL)) funText = funText.replaceAll(CALL+"$","");
if (cn.getFunction(funText)!=null)
fn.addDependentFunctions(funText);
if (ctx.arguments() != null) {
List<YJSParser.SingleExpressionContext> 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;