@freelog/freelog-cg-collection 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CollectionPolicyCustomVisitor.js +544 -0
- package/CollectionPolicyDecompiler.js +131 -0
- package/CollectionPolicyErrorLexerListener.js +23 -0
- package/CollectionPolicyErrorListener.js +22 -0
- package/README.md +398 -0
- package/TransitionEventArgsMatchUtil.js +79 -0
- package/gen/CollectionPolicyLexer.js +705 -0
- package/gen/CollectionPolicyListener.js +672 -0
- package/gen/CollectionPolicyParser.js +7301 -0
- package/gen/CollectionPolicyVisitor.js +454 -0
- package/gen/LexToken.js +680 -0
- package/index.js +53 -0
- package/indexTest.js +23 -0
- package/package.json +32 -0
- package/resources/event_definition.json +169 -0
- package/resources/function_definite.json +79 -0
- package/resources/test/CalculatorTest.json +26 -0
- package/resources/test/FunctionHelperTest.json +21 -0
- package/resources/variable_definite.json +10 -0
- package/resources/zhaojn.json +68 -0
- package/resources/zhaojn.sc +8 -0
- package/src/calculator/ExpArgsGroupCalculator.ts +34 -0
- package/src/calculator/ExpBooleanCalculator.ts +77 -0
- package/src/calculator/ExpCalculator.ts +68 -0
- package/src/calculator/ExpCollectionCalculator.ts +0 -0
- package/src/calculator/ExpConditionCalculator.ts +43 -0
- package/src/function-executor/FunctionHandle.ts +45 -0
- package/src/function-executor/api/FunctionApiExecutor.ts +11 -0
- package/src/function-executor/fun/FunctionFunExecutor.ts +31 -0
- package/src/function-executor/kit/FunctionKitExecutor.ts +11 -0
- package/src/function-executor/query/FunctionQueryExecutor.ts +11 -0
- package/src/function-executor/time/FunctionTimeExecutor.ts +11 -0
- package/src/helper/ExpHelper.ts +66 -0
- package/src/helper/FunctionHelper.ts +97 -0
- package/src/helper/PolicyHelper.ts +99 -0
- package/src/interface/Calculator.ts +6 -0
- package/src/interface/DefaultFunctionInvoke.ts +12 -0
- package/src/interface/FunctionInvoke.ts +6 -0
- package/src/interface/VarContextCapable.ts +3 -0
- package/src/model/AssignmentClauseInfo.ts +3 -0
- package/src/model/exp/EntityInfo.ts +7 -0
- package/src/model/exp/Exp.ts +5 -0
- package/src/model/exp/ExpAtom.ts +5 -0
- package/src/model/exp/ExpOp.ts +8 -0
- package/src/model/exp/ExpParen.ts +6 -0
- package/src/model/exp/ExpSigned.ts +7 -0
- package/src/model/exp/FunctionCallInfo.ts +13 -0
- package/src/model/exp/NumberInfo.ts +6 -0
- package/src/model/exp/StringInfo.ts +6 -0
- package/src/model/exp/VariableChainInfo.ts +7 -0
- package/src/model/exp-args-group/ExpArgsGroup.ts +10 -0
- package/src/model/exp-boolean/BooleanInfo.ts +6 -0
- package/src/model/exp-boolean/ExpBoolean.ts +5 -0
- package/src/model/exp-boolean/ExpBooleanAtom.ts +5 -0
- package/src/model/exp-boolean/ExpBooleanOpCollection.ts +8 -0
- package/src/model/exp-boolean/ExpBooleanOpCompare.ts +9 -0
- package/src/model/exp-boolean/ExpBooleanOpLogic.ts +8 -0
- package/src/model/exp-boolean/ExpBooleanParen.ts +6 -0
- package/src/model/exp-collection/ExpCollection.ts +10 -0
- package/src/model/exp-condition/ExpCondition.ts +12 -0
- package/src/model/policy/ActionInfo.ts +23 -0
- package/src/model/policy/EventInfo.ts +13 -0
- package/src/model/policy/PolicyInfo.ts +20 -0
- package/src/model/policy/VarDeclarationInfo.ts +8 -0
- package/test/calculator/CalculatorTest.test.ts +13 -0
- package/test/function/FunAddElements.ts +9 -0
- package/test/function/FunctionFunExecutorTest.test.ts +11 -0
- package/test/function/FunctionHandleTest.test.ts +9 -0
- package/test/helper/ExpHelperTest.test.ts +7 -0
- package/test/helper/FunctionHelperTest.test.ts +16 -0
- package/test/helper/PolicyHelperTest.test.ts +14 -0
- package/test/tsconfig.test.json +6 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {Calculator} from "../interface/Calculator";
|
|
2
|
+
import {AssignmentClauseInfo} from "../model/AssignmentClauseInfo";
|
|
3
|
+
import {VarContextCapable} from "../interface/VarContextCapable";
|
|
4
|
+
import {ExpHelper} from "../helper/ExpHelper";
|
|
5
|
+
import {ExpCondition} from "../model/exp-condition/ExpCondition";
|
|
6
|
+
|
|
7
|
+
export class ExpConditionCalculator implements Calculator {
|
|
8
|
+
|
|
9
|
+
private expHelper: ExpHelper;
|
|
10
|
+
|
|
11
|
+
getExpValue(varObj: AssignmentClauseInfo, varContextCapable: VarContextCapable<any>): any {
|
|
12
|
+
if (varObj.expType == "expCondition") {
|
|
13
|
+
return this.generateExpConditionValue(varObj as any, varContextCapable);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error("getExpValue fail [ExpConditionCalculator]...");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
generateExpConditionValue(expCondition: ExpCondition, varContextCapable: VarContextCapable<any>) {
|
|
20
|
+
let result = [];
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
if (expCondition.paramList.length != 0) {
|
|
23
|
+
expCondition.paramList.forEach(param => {
|
|
24
|
+
if (param.paramConditionObj == null) {
|
|
25
|
+
let paramV = this.expHelper.getExpValue(param.paramValueObj, varContextCapable);
|
|
26
|
+
result.push(paramV);
|
|
27
|
+
} else {
|
|
28
|
+
let paramC = this.expHelper.getExpValue(param.paramConditionObj, varContextCapable);
|
|
29
|
+
if (paramC) {
|
|
30
|
+
let paramV = this.expHelper.getExpValue(param.paramValueObj, varContextCapable);
|
|
31
|
+
result.push(paramV);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setExpHelper(expHelper: ExpHelper) {
|
|
41
|
+
this.expHelper = expHelper;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {FunctionInvoke} from "../interface/FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export class FunctionHandle implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
public static functionCodeMap = {
|
|
6
|
+
"Kit.Max": "F_001",
|
|
7
|
+
"Kit.IsNull": "F_002",
|
|
8
|
+
"Kit.Array.Size": "F_003"
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
invokeEnable(functionName: string): boolean {
|
|
12
|
+
return functionName in FunctionHandle.functionCodeMap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param functionName 函数的全称
|
|
17
|
+
* @param args
|
|
18
|
+
*/
|
|
19
|
+
invoke(functionName: string, args: any[]): any {
|
|
20
|
+
let functionCode = FunctionHandle.functionCodeMap[functionName];
|
|
21
|
+
let argsStr = "";
|
|
22
|
+
for (let i = 0; i < args.length; i++) {
|
|
23
|
+
if (i == 0) {
|
|
24
|
+
argsStr = JSON.stringify(args[i]);
|
|
25
|
+
} else {
|
|
26
|
+
argsStr = argsStr + "," + JSON.stringify(args[i]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let expStr = `this.${functionCode}(${argsStr})`;
|
|
30
|
+
console.debug(`invoke 【FunctionHandle】expStr = ${expStr}`)
|
|
31
|
+
return eval(expStr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
F_001(va1, var2): any {
|
|
35
|
+
return va1 >= var2 ? va1 : var2;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
F_002(va1): boolean {
|
|
39
|
+
return va1 == null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
F_003(elems): number {
|
|
43
|
+
return elems.length;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {FunctionInvoke} from "../../interface/FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export class FunctionApiExecutor implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
invokeEnable(functionName: string): boolean {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
invoke(functionName: string, args: any[]): any {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {FunctionInvoke} from "../../interface/FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export class FunctionFunExecutor implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
private executorsMap = new Map<string, FunctionInvoke>();
|
|
6
|
+
|
|
7
|
+
private functionNameSet = new Set<string>(["fun.addElements"]);
|
|
8
|
+
|
|
9
|
+
invokeEnable(functionName: string): boolean {
|
|
10
|
+
return this.functionNameSet.has(functionName) || this.executorsMap.has(functionName);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
invoke(functionName: string, args: any[]): any {
|
|
14
|
+
switch (functionName) {
|
|
15
|
+
case "fun.addElements":
|
|
16
|
+
return this.addElements(args[0], args[1]);
|
|
17
|
+
}
|
|
18
|
+
if (this.executorsMap.has(functionName)) {
|
|
19
|
+
return this.executorsMap.get(functionName).invoke(functionName, args);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
addExecutor(functionName: string, executor: FunctionInvoke) {
|
|
24
|
+
this.executorsMap.set(functionName, executor);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
addElements(set: [], elems: []) {
|
|
28
|
+
set.push(...elems);
|
|
29
|
+
return set;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {FunctionInvoke} from "../../interface/FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export class FunctionKitExecutor implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
invokeEnable(functionName: string): boolean {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
invoke(functionName: string, args: any[]): any {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {FunctionInvoke} from "../../interface/FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export class FunctionQueryExecutor implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
invokeEnable(functionName: string): boolean {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
invoke(functionName: string, args: any[]): any {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {FunctionInvoke} from "../../interface/FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export class FunctionTimeExecutor implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
invokeEnable(functionName: string): boolean {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
invoke(functionName: string, args: any[]): any {
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {ExpCalculator} from "../calculator/ExpCalculator";
|
|
2
|
+
import {VarContextCapable} from "../interface/VarContextCapable";
|
|
3
|
+
import {FunctionHelper} from "./FunctionHelper";
|
|
4
|
+
import {ExpBooleanCalculator} from "../calculator/ExpBooleanCalculator";
|
|
5
|
+
import {Calculator} from "../interface/Calculator";
|
|
6
|
+
import {AssignmentClauseInfo} from "../model/AssignmentClauseInfo";
|
|
7
|
+
import {ExpConditionCalculator} from "../calculator/ExpConditionCalculator";
|
|
8
|
+
import {ExpArgsGroupCalculator} from "../calculator/ExpArgsGroupCalculator";
|
|
9
|
+
|
|
10
|
+
export class ExpHelper implements Calculator {
|
|
11
|
+
|
|
12
|
+
private functionHelper: FunctionHelper;
|
|
13
|
+
|
|
14
|
+
private expCalculator: ExpCalculator;
|
|
15
|
+
|
|
16
|
+
private expBooleanCalculator: ExpBooleanCalculator;
|
|
17
|
+
|
|
18
|
+
private expConditionCalculator: ExpConditionCalculator;
|
|
19
|
+
|
|
20
|
+
private expArgsGroupCalculator: ExpArgsGroupCalculator;
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
this.expCalculator = new ExpCalculator();
|
|
24
|
+
this.expCalculator.setExpHelper(this);
|
|
25
|
+
this.expBooleanCalculator = new ExpBooleanCalculator();
|
|
26
|
+
this.expBooleanCalculator.setExpHelper(this);
|
|
27
|
+
this.expConditionCalculator = new ExpConditionCalculator();
|
|
28
|
+
this.expConditionCalculator.setExpHelper(this);
|
|
29
|
+
this.expArgsGroupCalculator = new ExpArgsGroupCalculator();
|
|
30
|
+
this.expArgsGroupCalculator.setExpHelper(this);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getExpValue(varObj: AssignmentClauseInfo, varContextCapable: VarContextCapable<any>): any {
|
|
34
|
+
switch (varObj.expType) {
|
|
35
|
+
case "expOp":
|
|
36
|
+
case "number":
|
|
37
|
+
case "string":
|
|
38
|
+
case "entity":
|
|
39
|
+
case "variableChain":
|
|
40
|
+
case "functionCall":
|
|
41
|
+
case "expParen":
|
|
42
|
+
case "expSigned":
|
|
43
|
+
console.debug(`getExpValue 【ExpCalculator】${JSON.stringify(varObj)}`);
|
|
44
|
+
return this.expCalculator.getExpValue(varObj, varContextCapable);
|
|
45
|
+
case "expBooleanOpLogic":
|
|
46
|
+
case "expBooleanOpCompare":
|
|
47
|
+
case "boolean":
|
|
48
|
+
console.debug("getExpValue 【ExpBooleanCalculator】");
|
|
49
|
+
return this.expBooleanCalculator.getExpValue(varObj, varContextCapable);
|
|
50
|
+
case "expCondition":
|
|
51
|
+
console.debug("getExpValue 【ExpConditionCalculator】");
|
|
52
|
+
return this.expConditionCalculator.getExpValue(varObj, varContextCapable);
|
|
53
|
+
case "expArgsGroup":
|
|
54
|
+
console.debug("getExpValue 【ExpArgsGroupCalculator】");
|
|
55
|
+
return this.expArgsGroupCalculator.getExpValue(varObj, varContextCapable);
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
throw new Error("getExpValue fail [ExpHelper]...");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setFunctionHelper(functionHelper: FunctionHelper) {
|
|
63
|
+
this.functionHelper = functionHelper;
|
|
64
|
+
this.expCalculator.setFunctionHelper(this.functionHelper);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {FunctionCallInfo} from "../model/exp/FunctionCallInfo";
|
|
2
|
+
import {FunctionInvoke} from "../interface/FunctionInvoke";
|
|
3
|
+
import {FunctionHandle} from "../function-executor/FunctionHandle";
|
|
4
|
+
import {ExpHelper} from "./ExpHelper";
|
|
5
|
+
import {VarContextCapable} from "../interface/VarContextCapable";
|
|
6
|
+
import {FunctionQueryExecutor} from "../function-executor/query/FunctionQueryExecutor";
|
|
7
|
+
import {FunctionKitExecutor} from "../function-executor/kit/FunctionKitExecutor";
|
|
8
|
+
import {FunctionTimeExecutor} from "../function-executor/time/FunctionTimeExecutor";
|
|
9
|
+
import {FunctionFunExecutor} from "../function-executor/fun/FunctionFunExecutor";
|
|
10
|
+
import {FunctionApiExecutor} from "../function-executor/api/FunctionApiExecutor";
|
|
11
|
+
|
|
12
|
+
export class FunctionHelper implements FunctionInvoke {
|
|
13
|
+
|
|
14
|
+
private expCustomList: any[];
|
|
15
|
+
|
|
16
|
+
private funcHandle: FunctionHandle;
|
|
17
|
+
|
|
18
|
+
private funcExecutors: FunctionInvoke[];
|
|
19
|
+
|
|
20
|
+
private readonly functionFunExecutor: FunctionFunExecutor;
|
|
21
|
+
|
|
22
|
+
private expHelper: ExpHelper;
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
this.expCustomList = [];
|
|
26
|
+
this.funcHandle = new FunctionHandle();
|
|
27
|
+
this.funcExecutors = [];
|
|
28
|
+
this.funcExecutors.push(new FunctionQueryExecutor());
|
|
29
|
+
this.funcExecutors.push(new FunctionKitExecutor());
|
|
30
|
+
this.funcExecutors.push(new FunctionTimeExecutor());
|
|
31
|
+
this.functionFunExecutor = new FunctionFunExecutor();
|
|
32
|
+
this.funcExecutors.push(this.functionFunExecutor);
|
|
33
|
+
this.funcExecutors.push(new FunctionApiExecutor());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setExpCustom(expCustom) {
|
|
37
|
+
this.expCustomList.push(expCustom);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getExpCustom(functionName) {
|
|
41
|
+
let expCustomListTmp = [...this.expCustomList].reverse();
|
|
42
|
+
return expCustomListTmp.find((elem) => {
|
|
43
|
+
return elem.varName == functionName;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
getFunctionValue(funcInfo: FunctionCallInfo, varContextCapable: VarContextCapable<any>): any {
|
|
48
|
+
let args = funcInfo.paramList.map(paramElem => {
|
|
49
|
+
return this.expHelper.getExpValue(paramElem.paramValueObj, varContextCapable);
|
|
50
|
+
});
|
|
51
|
+
let functionName = funcInfo.funcName;
|
|
52
|
+
if (funcInfo.varChain != null) {
|
|
53
|
+
functionName = `${funcInfo.varChain}.${functionName}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return this.invoke(functionName, args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
invokeEnable(functionName: string): boolean {
|
|
60
|
+
throw new Error("这是个空实现,不能被调用!");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
invoke(functionName: string, args: any[]): any {
|
|
64
|
+
let expCustom = this.getExpCustom(functionName);
|
|
65
|
+
if (expCustom != null) {
|
|
66
|
+
let varContextMap = new Map();
|
|
67
|
+
for (let i = 0; i < expCustom["paramList"].length; i++) {
|
|
68
|
+
varContextMap.set(expCustom["paramList"][i], args[i]);
|
|
69
|
+
}
|
|
70
|
+
return this.expHelper.getExpValue(expCustom["varValueObj"], new class implements VarContextCapable<any> {
|
|
71
|
+
getVarContext(varName: string): any {
|
|
72
|
+
return varContextMap.get(varName);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this.funcExecutors.forEach(funcExecutor => {
|
|
78
|
+
if (funcExecutor.invokeEnable(functionName)) {
|
|
79
|
+
return funcExecutor.invoke(functionName, args);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (this.funcHandle.invokeEnable(functionName)) {
|
|
84
|
+
return this.funcHandle.invoke(functionName, args);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw new Error("invoke fail [FunctionHelper]...");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
addExecutor4Fun(functionName: string, executor: FunctionInvoke) {
|
|
91
|
+
this.functionFunExecutor.addExecutor(functionName, executor);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setExpHelper(expHelper: ExpHelper): void {
|
|
95
|
+
this.expHelper = expHelper;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {PolicyInfo} from "../model/policy/PolicyInfo";
|
|
2
|
+
import {ExpHelper} from "./ExpHelper";
|
|
3
|
+
import {VarContextCapable} from "../interface/VarContextCapable";
|
|
4
|
+
import {FunctionHelper} from "./FunctionHelper";
|
|
5
|
+
import {Calculator} from "../interface/Calculator";
|
|
6
|
+
import {AssignmentClauseInfo} from "../model/AssignmentClauseInfo";
|
|
7
|
+
import {FunctionInvoke} from "../interface/FunctionInvoke";
|
|
8
|
+
|
|
9
|
+
export class PolicyHelper implements VarContextCapable<any>, Calculator, FunctionInvoke {
|
|
10
|
+
|
|
11
|
+
protected policyInfo: PolicyInfo;
|
|
12
|
+
|
|
13
|
+
protected varGlobalList;
|
|
14
|
+
|
|
15
|
+
protected varMacroList;
|
|
16
|
+
|
|
17
|
+
private expHelper: ExpHelper;
|
|
18
|
+
|
|
19
|
+
private functionHelper: FunctionHelper;
|
|
20
|
+
|
|
21
|
+
constructor(policyInfo: PolicyInfo) {
|
|
22
|
+
this.policyInfo = policyInfo;
|
|
23
|
+
this.varGlobalList = [];
|
|
24
|
+
this.varMacroList = [];
|
|
25
|
+
this.expHelper = new ExpHelper();
|
|
26
|
+
this.functionHelper = new FunctionHelper();
|
|
27
|
+
this.expHelper.setFunctionHelper(this.functionHelper);
|
|
28
|
+
this.functionHelper.setExpHelper(this.expHelper);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 在合约签约的时候,可签约条件和全局申明的变量是已经计算完毕的,在这里做这件事
|
|
32
|
+
async init(varContextCapable: VarContextCapable<any>) {
|
|
33
|
+
let varDeclarationList = this.policyInfo.varDeclarationList;
|
|
34
|
+
for (let varDeclaration of varDeclarationList) {
|
|
35
|
+
if (varDeclaration.type == "varGlobal") {
|
|
36
|
+
let value = this.expHelper.getExpValue(varDeclaration.varValueObj, varContextCapable);
|
|
37
|
+
this.getVarGlobalList().push({varName: varDeclaration.varName, varValue: value});
|
|
38
|
+
}
|
|
39
|
+
if (varDeclaration.type == "varMacro") {
|
|
40
|
+
this.varMacroList.push({varName: varDeclaration.varName, varValueObj: varDeclaration.varValueObj});
|
|
41
|
+
}
|
|
42
|
+
if (varDeclaration.type == "expCustom") {
|
|
43
|
+
this.functionHelper.setExpCustom({
|
|
44
|
+
varName: varDeclaration.varName,
|
|
45
|
+
paramList: varDeclaration.paramList,
|
|
46
|
+
varValueObj: varDeclaration.varValueObj
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setVarGlobal(varName: string, varValue: any) {
|
|
53
|
+
this.getVarGlobalList().push({varName, varValue});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setVarGlobalList(varGlobalList: []) {
|
|
57
|
+
this.varGlobalList = varGlobalList;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getVarGlobalList(): any[] {
|
|
61
|
+
return this.varGlobalList;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getVarContext(varName: string): any {
|
|
65
|
+
let varGlobalListTmp = [...this.getVarGlobalList()].reverse();
|
|
66
|
+
let result = varGlobalListTmp.find((elem) => {
|
|
67
|
+
return elem.varName == varName;
|
|
68
|
+
});
|
|
69
|
+
if (result != null) {
|
|
70
|
+
return result["varValue"];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let varMacroListTmp = [...this.varMacroList].reverse();
|
|
74
|
+
let resultObj = varMacroListTmp.find((elem) => {
|
|
75
|
+
return elem.varName == varName;
|
|
76
|
+
});
|
|
77
|
+
if (resultObj != null) {
|
|
78
|
+
return this.getExpValue(resultObj.varValueObj, this);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new Error("getVarContext fail [PolicyHelper]...");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getExpValue(varObj: AssignmentClauseInfo, varContextCapable: VarContextCapable<any>): any {
|
|
85
|
+
return this.expHelper.getExpValue(varObj, varContextCapable);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
invokeEnable(functionName: string): boolean {
|
|
89
|
+
throw new Error("这是个空实现,不能被调用!");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
invoke(functionName: string, args: any[]): any {
|
|
93
|
+
return this.functionHelper.invoke(functionName, args);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
addExecutor4Fun(functionName: string, executor: FunctionInvoke) {
|
|
97
|
+
this.functionHelper.addExecutor4Fun(functionName, executor);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {FunctionInvoke} from "./FunctionInvoke";
|
|
2
|
+
|
|
3
|
+
export abstract class DefaultFunctionInvoke implements FunctionInvoke {
|
|
4
|
+
|
|
5
|
+
invoke(functionName: string, args: any[]): any {
|
|
6
|
+
throw new Error("这是个空实现,不能被调用!");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
invokeEnable(functionName: string): boolean {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {Exp} from "./Exp";
|
|
2
|
+
import {AssignmentClauseInfo} from "../AssignmentClauseInfo";
|
|
3
|
+
|
|
4
|
+
export interface FunctionCallInfo extends Exp {
|
|
5
|
+
expType: "functionCall";
|
|
6
|
+
varChain?: string;
|
|
7
|
+
funcName: string;
|
|
8
|
+
paramList: [{
|
|
9
|
+
paramName?: string;
|
|
10
|
+
paramValue: string;
|
|
11
|
+
paramValueObj: AssignmentClauseInfo;
|
|
12
|
+
}];
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {ExpBoolean} from "./ExpBoolean";
|
|
2
|
+
|
|
3
|
+
export interface ExpBooleanOpCompare extends ExpBoolean {
|
|
4
|
+
expType: "expBooleanOpCompare";
|
|
5
|
+
op: "less" | "before" | "lessOrEqual" | "greater" | "after" | "greaterOrEqual" | "equal" | "notEqual"
|
|
6
|
+
| "<" | "<=" | ">" | ">=" | "==" | "!=";
|
|
7
|
+
var1: any;
|
|
8
|
+
var2: any;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {AssignmentClauseInfo} from "../AssignmentClauseInfo";
|
|
2
|
+
import {ExpBoolean} from "../exp-boolean/ExpBoolean";
|
|
3
|
+
|
|
4
|
+
export interface ExpCondition extends AssignmentClauseInfo {
|
|
5
|
+
expType: "expCondition";
|
|
6
|
+
paramList: [{
|
|
7
|
+
paramCondition?: string;
|
|
8
|
+
paramConditionObj?: ExpBoolean;
|
|
9
|
+
paramValue: string;
|
|
10
|
+
paramValueObj: any;
|
|
11
|
+
}];
|
|
12
|
+
}
|