feat: support fork annotation

This commit is contained in:
CaiHQ 2023-08-23 16:00:47 +08:00
parent 6d5f005f6e
commit bb71895f6e
5 changed files with 61 additions and 2 deletions

View File

@ -55,7 +55,7 @@ dependencies {
}
group = "org.bdware.sc"
version = "1.7.8"
version = "1.7.9"
tasks.processResources.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
task copyLibs(type: Copy) {

View File

@ -3,6 +3,7 @@ package org.bdware.sc.node;
import com.google.gson.JsonObject;
import org.antlr.v4.runtime.CommonTokenStream;
import org.bdware.sc.bean.DoipOperationInfo;
import org.bdware.sc.bean.ForkInfo;
import org.bdware.sc.bean.JoinInfo;
import org.bdware.sc.bean.RouteInfo;
import org.bdware.sc.event.REvent.REventSemantics;
@ -238,6 +239,7 @@ public class ContractNode {
}
public void maintainRouteJoinInfo(JsonObject methodRouteInfoMap, JsonObject methodJoinInfoMap,
JsonObject methodForkInfoMap,
JsonObject dependentFunctions) {
// all functions存了ContractNode中所有的FunctionNode
List<FunctionNode> allFunctions = getFunctions();
@ -247,11 +249,12 @@ public class ContractNode {
if (doopAnnotation != null && doipOperationInfo != null) {
RouteInfo routeInfo = functionNode.getRouteInfo();
JoinInfo joinInfo = functionNode.getJoinInfo();
ForkInfo forkInfo = functionNode.getForkInfo();
if (routeInfo != null) {
packSourceFunctionAndDependentFunctions(getFunction(routeInfo.funcName),
dependentFunctions);
methodRouteInfoMap.add(doipOperationInfo.operationName,
JsonUtil.parseObjectAsJsonObject(routeInfo));
JsonUtil.parseObjectAsJsonObject(routeInfo));
}
if (joinInfo != null) {
packSourceFunctionAndDependentFunctions(getFunction(joinInfo.joinCountFuncName),
@ -261,6 +264,13 @@ public class ContractNode {
methodJoinInfoMap.add(doipOperationInfo.operationName,
JsonUtil.parseObjectAsJsonObject(joinInfo));
}
if (forkInfo != null) {
packSourceFunctionAndDependentFunctions(getFunction(forkInfo.funcName),
dependentFunctions);
methodForkInfoMap.add(doipOperationInfo.operationName,
JsonUtil.parseObjectAsJsonObject(forkInfo));
}
}
}
@ -270,6 +280,7 @@ public class ContractNode {
if (doopAnnotation != null && doipOperationInfo != null) {
RouteInfo routeInfo = interfaceNode.getRouteInfo();
JoinInfo joinInfo = interfaceNode.getJoinInfo();
ForkInfo forkInfo = interfaceNode.getForkInfo();
if (routeInfo != null) {
packSourceFunctionAndDependentFunctions(getFunction(routeInfo.funcName),
dependentFunctions);
@ -284,6 +295,12 @@ public class ContractNode {
methodJoinInfoMap.add(doipOperationInfo.operationName,
JsonUtil.parseObjectAsJsonObject(joinInfo));
}
if (forkInfo != null) {
packSourceFunctionAndDependentFunctions(getFunction(forkInfo.funcName),
dependentFunctions);
methodForkInfoMap.add(doipOperationInfo.operationName,
JsonUtil.parseObjectAsJsonObject(routeInfo));
}
}
}
}

View File

@ -2,6 +2,7 @@ package org.bdware.sc.node;
import com.google.gson.JsonElement;
import org.bdware.sc.bean.DoipOperationInfo;
import org.bdware.sc.bean.ForkInfo;
import org.bdware.sc.bean.JoinInfo;
import org.bdware.sc.bean.RouteInfo;
@ -38,6 +39,7 @@ public class FunctionNode extends Script {
private JsonElement homoEncryptConf;
private JsonElement homoDecryptConf;
public transient Class compiledClazz;
private ForkInfo forkInfo;
public FunctionNode(String name, String fileName) {
this.functionName = name;
@ -302,4 +304,12 @@ public class FunctionNode extends Script {
return node;
return null;
}
public void setForkInfo(ForkInfo forkInfo) {
this.forkInfo = forkInfo;
}
public ForkInfo getForkInfo() {
return forkInfo;
}
}

View File

@ -1,6 +1,7 @@
package org.bdware.sc.node;
import org.bdware.sc.bean.DoipOperationInfo;
import org.bdware.sc.bean.ForkInfo;
import org.bdware.sc.bean.JoinInfo;
import org.bdware.sc.bean.RouteInfo;
@ -153,4 +154,14 @@ public class InterfaceNode extends Script {
return node;
return null;
}
private ForkInfo forkInfo;
public void setForkInfo(ForkInfo forkInfo) {
this.forkInfo = forkInfo;
}
public ForkInfo getForkInfo() {
return forkInfo;
}
}

View File

@ -0,0 +1,21 @@
package org.bdware.sc.bean;
import org.bdware.sc.node.AnnotationNode;
import org.bdware.sc.node.ContractNode;
import org.bdware.sc.util.JsonUtil;
import java.io.Serializable;
public class ForkInfo implements Serializable {
public String funcName;
public static ForkInfo create(AnnotationNode annotationNode, ContractNode contractNode) {
ForkInfo info = new ForkInfo();
if (annotationNode.getArgs().size() == 1) {
String str = annotationNode.getArgs().get(0);
info = JsonUtil.fromJson(str, ForkInfo.class);
}
System.out.println("[ForkInfo] annotationNode:" + JsonUtil.toJson(annotationNode));
return info;
}
}