mirror of
https://gitee.com/BDWare/common
synced 2025-01-10 01:44:16 +00:00
optimize dependent function parse
support merge importNodes
This commit is contained in:
parent
bc7a54e9ce
commit
374451dd5b
@ -55,7 +55,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
group = "org.bdware.sc"
|
group = "org.bdware.sc"
|
||||||
|
|
||||||
version = "1.7.6"
|
version = "1.7.8"
|
||||||
tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
|
||||||
|
|
||||||
task copyLibs(type: Copy) {
|
task copyLibs(type: Copy) {
|
||||||
|
@ -130,6 +130,7 @@ public class ContractNode {
|
|||||||
public void merge(ContractNode contract) {
|
public void merge(ContractNode contract) {
|
||||||
sigRequired |= contract.sigRequired;
|
sigRequired |= contract.sigRequired;
|
||||||
instrumentBranch |= contract.instrumentBranch;
|
instrumentBranch |= contract.instrumentBranch;
|
||||||
|
imports.addAll(contract.getImports());
|
||||||
for (FunctionNode fn : contract.functions) {
|
for (FunctionNode fn : contract.functions) {
|
||||||
functions.add(fn);
|
functions.add(fn);
|
||||||
functionMap.put(fn.functionName, fn);
|
functionMap.put(fn.functionName, fn);
|
||||||
@ -262,6 +263,29 @@ 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,
|
public void packSourceFunctionAndDependentFunctions(FunctionNode sourceFunctionNode,
|
||||||
@ -291,8 +315,16 @@ public class ContractNode {
|
|||||||
+ " -> " + annotationNode.getType());
|
+ " -> " + annotationNode.getType());
|
||||||
}
|
}
|
||||||
functionNode.annotations.addAll(node.annotations);
|
functionNode.annotations.addAll(node.annotations);
|
||||||
} else
|
} else {
|
||||||
throw new RuntimeException("unimplemented functions:" + node.functionName);
|
//now we accept only interfaces.
|
||||||
|
//just ignore!
|
||||||
|
// throw new RuntimeException("unimplemented functions:" + node.functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<InterfaceNode> getInterfaces() {
|
||||||
|
return interfaceMap.values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import org.bdware.sc.node.FunctionNode;
|
|||||||
import org.bdware.sc.parser.YJSParser;
|
import org.bdware.sc.parser.YJSParser;
|
||||||
import org.bdware.sc.parser.YJSParserBaseVisitor;
|
import org.bdware.sc.parser.YJSParserBaseVisitor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class FunctionDependencyVisitor extends YJSParserBaseVisitor<FunctionNode> {
|
public class FunctionDependencyVisitor extends YJSParserBaseVisitor<FunctionNode> {
|
||||||
|
|
||||||
public static String APPLY = ".apply";
|
public static String APPLY = ".apply";
|
||||||
@ -21,12 +23,19 @@ public class FunctionDependencyVisitor extends YJSParserBaseVisitor<FunctionNode
|
|||||||
@Override
|
@Override
|
||||||
public FunctionNode visitArgumentsExpression(YJSParser.ArgumentsExpressionContext ctx) {
|
public FunctionNode visitArgumentsExpression(YJSParser.ArgumentsExpressionContext ctx) {
|
||||||
super.visitArgumentsExpression(ctx);
|
super.visitArgumentsExpression(ctx);
|
||||||
for (FunctionNode f : cn.getFunctions()) {
|
String funText = ctx.singleExpression().getText();
|
||||||
if (ctx.singleExpression().getText().equals(f.functionName)
|
if (funText.endsWith(APPLY)) funText = funText.replaceAll(APPLY+"$","");
|
||||||
|| ctx.singleExpression().getText().equals(f.functionName + APPLY)
|
if (funText.endsWith(CALL)) funText = funText.replaceAll(CALL+"$","");
|
||||||
|| ctx.singleExpression().getText().equals(f.functionName + CALL)) {
|
if (cn.getFunction(funText)!=null)
|
||||||
fn.addDependentFunctions(f.functionName);
|
fn.addDependentFunctions(funText);
|
||||||
break;
|
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;
|
return fn;
|
||||||
|
Loading…
Reference in New Issue
Block a user