mirror of
https://gitee.com/BDWare/common
synced 2025-04-27 06:22:19 +00:00
feat: sharable var integration
This commit is contained in:
parent
0ae9339900
commit
3bf508b088
@ -16,6 +16,7 @@ public class ContractNode {
|
||||
private final List<ImportNode> imports;
|
||||
private final List<ClassNode> clzs;
|
||||
private final List<FunctionNode> functions;
|
||||
private final List<SharableNode> sharables;
|
||||
private final Map<String, FunctionNode> functionMap;
|
||||
private final Set<String> dependentContracts;
|
||||
private final Map<String, InterfaceNode> interfaceMap;
|
||||
@ -38,6 +39,7 @@ public class ContractNode {
|
||||
functions = new ArrayList<>();
|
||||
functionMap = new HashMap<>();
|
||||
interfaceMap = new HashMap<>();
|
||||
sharables = new ArrayList<>();
|
||||
isBundle = false;
|
||||
events = new HashMap<>();
|
||||
logs = new HashMap<>();
|
||||
@ -56,6 +58,10 @@ public class ContractNode {
|
||||
interfaceMap.put(interfaceNode.functionName, interfaceNode);
|
||||
}
|
||||
|
||||
public void addSharable(SharableNode sharable) {
|
||||
getSharables().add(sharable);
|
||||
}
|
||||
|
||||
public void addClass(ClassNode clzNode) {
|
||||
getClzs().add(clzNode);
|
||||
}
|
||||
@ -68,6 +74,10 @@ public class ContractNode {
|
||||
return clzs;
|
||||
}
|
||||
|
||||
public List<SharableNode> getSharables() {
|
||||
return sharables;
|
||||
}
|
||||
|
||||
public void initPlainText(CommonTokenStream cts) {
|
||||
for (ClassNode cn : clzs) {
|
||||
cn.initText(cts);
|
||||
@ -127,6 +137,7 @@ public class ContractNode {
|
||||
for (InterfaceNode interfaceNode : contract.interfaceMap.values()) {
|
||||
interfaceMap.put(interfaceNode.functionName, interfaceNode);
|
||||
}
|
||||
sharables.addAll(contract.getSharables());
|
||||
clzs.addAll(contract.clzs);
|
||||
this.events.putAll(contract.events);
|
||||
this.logs.putAll(contract.logs);
|
||||
|
25
src/main/base/org/bdware/sc/node/SharableNode.java
Normal file
25
src/main/base/org/bdware/sc/node/SharableNode.java
Normal file
@ -0,0 +1,25 @@
|
||||
package org.bdware.sc.node;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SharableNode {
|
||||
private List<String> variableStatements;
|
||||
|
||||
private String fileName;
|
||||
|
||||
public List<String> getVariableStatements() {
|
||||
return variableStatements;
|
||||
}
|
||||
|
||||
public void setVariableStatements(List<String> variableStatements) {
|
||||
this.variableStatements = variableStatements;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
@ -118,6 +118,12 @@ public class ContractReader extends YJSParserBaseVisitor<ContractNode> {
|
||||
InterfaceDeclarationContext interfaces = clzOrFunction.interfaceDeclaration();
|
||||
InterfaceReader reader = new InterfaceReader(fileName);
|
||||
node.addInterface(reader.visitInterfaceDeclaration(interfaces));
|
||||
} else if (null != clzOrFunction.sharableDeclaration()) {
|
||||
SharableDeclarationContext sharableCtx = clzOrFunction.sharableDeclaration();
|
||||
sharableCtx.sharableStatement().variableDeclarationList();
|
||||
SharableReader reader = new SharableReader(fileName);
|
||||
SharableNode sharable = reader.visitVariableDeclarationList(sharableCtx.sharableStatement().variableDeclarationList());
|
||||
node.addSharable(sharable);
|
||||
}
|
||||
}
|
||||
// ctx.getSourceInterval()
|
||||
|
28
src/main/base/org/bdware/sc/visitor/SharableReader.java
Normal file
28
src/main/base/org/bdware/sc/visitor/SharableReader.java
Normal file
@ -0,0 +1,28 @@
|
||||
package org.bdware.sc.visitor;
|
||||
|
||||
import org.bdware.sc.node.SharableNode;
|
||||
import org.bdware.sc.parser.YJSParser;
|
||||
import org.bdware.sc.parser.YJSParserBaseVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SharableReader extends YJSParserBaseVisitor<SharableNode> {
|
||||
private final String fileName;
|
||||
|
||||
public SharableReader(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SharableNode visitVariableDeclarationList(YJSParser.VariableDeclarationListContext ctx) {
|
||||
SharableNode sharableNode = new SharableNode();
|
||||
List<String> statements = new ArrayList<>();
|
||||
for (YJSParser.VariableDeclarationContext variableDeclarationContext : ctx.variableDeclaration()) {
|
||||
statements.add(variableDeclarationContext.getText());
|
||||
}
|
||||
sharableNode.setVariableStatements(statements);
|
||||
sharableNode.setFileName(fileName);
|
||||
return sharableNode;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user