yukigo 0.1.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/.mocharc.json +4 -0
- package/CHANGELOG.md +6 -0
- package/README.md +199 -0
- package/dist/analyzer/index.d.ts +71 -0
- package/dist/analyzer/index.js +110 -0
- package/dist/analyzer/inspections/functional.d.ts +46 -0
- package/dist/analyzer/inspections/functional.js +123 -0
- package/dist/analyzer/inspections/generic.d.ts +151 -0
- package/dist/analyzer/inspections/generic.js +427 -0
- package/dist/analyzer/inspections/imperative.d.ts +37 -0
- package/dist/analyzer/inspections/imperative.js +105 -0
- package/dist/analyzer/inspections/logic.d.ts +49 -0
- package/dist/analyzer/inspections/logic.js +140 -0
- package/dist/analyzer/inspections/object.d.ts +83 -0
- package/dist/analyzer/inspections/object.js +235 -0
- package/dist/analyzer/utils.d.ts +4 -0
- package/dist/analyzer/utils.js +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/interpreter/components/EnvBuilder.d.ts +16 -0
- package/dist/interpreter/components/EnvBuilder.js +78 -0
- package/dist/interpreter/components/FunctionRuntime.d.ts +8 -0
- package/dist/interpreter/components/FunctionRuntime.js +52 -0
- package/dist/interpreter/components/LazyRuntime.d.ts +7 -0
- package/dist/interpreter/components/LazyRuntime.js +75 -0
- package/dist/interpreter/components/LogicEngine.d.ts +21 -0
- package/dist/interpreter/components/LogicEngine.js +152 -0
- package/dist/interpreter/components/LogicResolver.d.ts +11 -0
- package/dist/interpreter/components/LogicResolver.js +87 -0
- package/dist/interpreter/components/Operations.d.ts +14 -0
- package/dist/interpreter/components/Operations.js +69 -0
- package/dist/interpreter/components/PatternMatcher.d.ts +41 -0
- package/dist/interpreter/components/PatternMatcher.js +206 -0
- package/dist/interpreter/components/Visitor.d.ts +64 -0
- package/dist/interpreter/components/Visitor.js +299 -0
- package/dist/interpreter/errors.d.ts +19 -0
- package/dist/interpreter/errors.js +36 -0
- package/dist/interpreter/index.d.ts +32 -0
- package/dist/interpreter/index.js +44 -0
- package/dist/interpreter/utils.d.ts +14 -0
- package/dist/interpreter/utils.js +57 -0
- package/dist/utils/helpers.d.ts +14 -0
- package/dist/utils/helpers.js +51 -0
- package/package.json +30 -0
- package/src/analyzer/index.ts +132 -0
- package/src/analyzer/inspections/functional.ts +159 -0
- package/src/analyzer/inspections/generic.ts +499 -0
- package/src/analyzer/inspections/imperative.ts +129 -0
- package/src/analyzer/inspections/logic.ts +166 -0
- package/src/analyzer/inspections/object.ts +282 -0
- package/src/analyzer/utils.ts +26 -0
- package/src/index.ts +3 -0
- package/src/interpreter/components/EnvBuilder.ts +97 -0
- package/src/interpreter/components/FunctionRuntime.ts +79 -0
- package/src/interpreter/components/LazyRuntime.ts +97 -0
- package/src/interpreter/components/LogicEngine.ts +227 -0
- package/src/interpreter/components/LogicResolver.ts +130 -0
- package/src/interpreter/components/Operations.ts +81 -0
- package/src/interpreter/components/PatternMatcher.ts +254 -0
- package/src/interpreter/components/Visitor.ts +493 -0
- package/src/interpreter/errors.ts +47 -0
- package/src/interpreter/index.ts +59 -0
- package/src/interpreter/utils.ts +79 -0
- package/src/utils/helpers.ts +73 -0
- package/tests/analyzer/functional.spec.ts +221 -0
- package/tests/analyzer/generic.spec.ts +100 -0
- package/tests/analyzer/helpers.spec.ts +83 -0
- package/tests/analyzer/logic.spec.ts +292 -0
- package/tests/analyzer/oop.spec.ts +338 -0
- package/tests/interpreter/EnvBuilder.spec.ts +178 -0
- package/tests/interpreter/FunctionRuntime.spec.ts +234 -0
- package/tests/interpreter/LazyRuntime.spec.ts +190 -0
- package/tests/interpreter/LogicEngine.spec.ts +194 -0
- package/tests/interpreter/Operations.spec.ts +220 -0
- package/tests/interpreter/PatternSystem.spec.ts +189 -0
- package/tests/interpreter/interpreter.spec.ts +937 -0
- package/tsconfig.build.json +7 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { ArithmeticBinaryOperation, ArithmeticUnaryOperation, Assignment, ASTNode, Attribute, Call, Catch, EntryPoint, Fact, Function, If, LogicalBinaryOperation, LogicalUnaryOperation, Method, Print, Procedure, Raise, Record as RecordNode, Rule, SimpleType, SymbolPrimitive, TraverseVisitor, Try, TypeAlias, TypeSignature, TypeVar, Variable } from "@yukigo/ast";
|
|
2
|
+
import { InspectionMap } from "../utils.js";
|
|
3
|
+
export declare class Assigns extends TraverseVisitor {
|
|
4
|
+
private readonly targetIdentifier;
|
|
5
|
+
constructor(targetIdentifier: string);
|
|
6
|
+
visitVariable(node: Variable): void;
|
|
7
|
+
visitAttribute(node: Attribute): void;
|
|
8
|
+
visitAssignment(node: Assignment): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class Calls extends TraverseVisitor {
|
|
11
|
+
private readonly targetCallee;
|
|
12
|
+
constructor(targetCallee: string);
|
|
13
|
+
visitCall(node: Call): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class Declares extends TraverseVisitor {
|
|
16
|
+
private readonly targetIdentifier;
|
|
17
|
+
constructor(targetIdentifier: string);
|
|
18
|
+
visit(node: ASTNode): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class DeclaresComputation extends TraverseVisitor {
|
|
21
|
+
private readonly callName;
|
|
22
|
+
constructor(callName: string);
|
|
23
|
+
visitFunction(node: Function): void;
|
|
24
|
+
visitMethod(node: Method): void;
|
|
25
|
+
visitProcedure(node: Procedure): void;
|
|
26
|
+
visitFact(node: Fact): void;
|
|
27
|
+
visitRule(node: Rule): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class DeclaresComputationWithArity extends TraverseVisitor {
|
|
30
|
+
private readonly targetBinding;
|
|
31
|
+
private readonly targetArity;
|
|
32
|
+
constructor(targetBinding: string, targetArity: number);
|
|
33
|
+
visitFunction(node: Function): void;
|
|
34
|
+
visitMethod(node: Method): void;
|
|
35
|
+
visitProcedure(node: Procedure): void;
|
|
36
|
+
visitFact(node: Fact): void;
|
|
37
|
+
visitRule(node: Rule): void;
|
|
38
|
+
}
|
|
39
|
+
export declare class DeclaresEntryPoint extends TraverseVisitor {
|
|
40
|
+
visitEntryPoint(node: EntryPoint): void;
|
|
41
|
+
}
|
|
42
|
+
export declare class DeclaresFunction extends TraverseVisitor {
|
|
43
|
+
private readonly targetBinding;
|
|
44
|
+
constructor(targetBinding: string);
|
|
45
|
+
visitFunction(node: Function): void;
|
|
46
|
+
}
|
|
47
|
+
export declare class DeclaresRecursively extends DeclaresComputation {
|
|
48
|
+
private readonly targetBinding;
|
|
49
|
+
constructor(targetBinding: string);
|
|
50
|
+
visitFunction(node: Function): void;
|
|
51
|
+
visitMethod(node: Method): void;
|
|
52
|
+
visitProcedure(node: Procedure): void;
|
|
53
|
+
visitFact(node: Fact): void;
|
|
54
|
+
visitRule(node: Rule): void;
|
|
55
|
+
visitNested(node: ASTNode): void;
|
|
56
|
+
}
|
|
57
|
+
export declare class DeclaresTypeAlias extends TraverseVisitor {
|
|
58
|
+
private readonly typeAliasName;
|
|
59
|
+
constructor(typeAliasName: string);
|
|
60
|
+
visitTypeAlias(node: TypeAlias): void;
|
|
61
|
+
}
|
|
62
|
+
export declare class DeclaresTypeSignature extends TraverseVisitor {
|
|
63
|
+
private readonly targetBinding;
|
|
64
|
+
constructor(targetBinding: string);
|
|
65
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
66
|
+
}
|
|
67
|
+
export declare class DeclaresVariable extends TraverseVisitor {
|
|
68
|
+
private readonly targetBinding;
|
|
69
|
+
constructor(targetBinding: string);
|
|
70
|
+
visitVariable(node: Variable): void;
|
|
71
|
+
}
|
|
72
|
+
export declare class Raises extends TraverseVisitor {
|
|
73
|
+
visitRaise(node: Raise): void;
|
|
74
|
+
}
|
|
75
|
+
export declare class Uses extends TraverseVisitor {
|
|
76
|
+
private readonly targetBinding;
|
|
77
|
+
constructor(targetBinding: string);
|
|
78
|
+
visitSymbolPrimitive(node: SymbolPrimitive): void;
|
|
79
|
+
}
|
|
80
|
+
export declare class UsesArithmetic extends TraverseVisitor {
|
|
81
|
+
visitArithmeticBinaryOperation(node: ArithmeticBinaryOperation): void;
|
|
82
|
+
visitArithmeticUnaryOperation(node: ArithmeticUnaryOperation): void;
|
|
83
|
+
}
|
|
84
|
+
export declare class UsesConditional extends TraverseVisitor {
|
|
85
|
+
visitIf(node: If): void;
|
|
86
|
+
}
|
|
87
|
+
export declare class UsesLogic extends TraverseVisitor {
|
|
88
|
+
visitLogicalBinaryOperation(node: LogicalBinaryOperation): void;
|
|
89
|
+
visitLogicalUnaryOperation(node: LogicalUnaryOperation): void;
|
|
90
|
+
}
|
|
91
|
+
export declare class UsesPrint extends TraverseVisitor {
|
|
92
|
+
visitPrint(node: Print): void;
|
|
93
|
+
}
|
|
94
|
+
export declare class UsesType extends TraverseVisitor {
|
|
95
|
+
private readonly targetBinding;
|
|
96
|
+
constructor(targetBinding: string);
|
|
97
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
98
|
+
visitSimpleType(node: SimpleType): void;
|
|
99
|
+
visitTypeVar(node: TypeVar): void;
|
|
100
|
+
}
|
|
101
|
+
export declare class HasBinding extends TraverseVisitor {
|
|
102
|
+
private readonly targetBinding;
|
|
103
|
+
constructor(targetBinding: string);
|
|
104
|
+
visitFunction(node: Function): void;
|
|
105
|
+
visitTypeAlias(node: TypeAlias): void;
|
|
106
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
107
|
+
visitRecord(node: RecordNode): void;
|
|
108
|
+
}
|
|
109
|
+
export declare class SubordinatesDeclarationsTo extends TraverseVisitor {
|
|
110
|
+
private childName;
|
|
111
|
+
private parentName;
|
|
112
|
+
constructor(childName: string, parentName: string);
|
|
113
|
+
visitFunction(node: Function): void;
|
|
114
|
+
}
|
|
115
|
+
export declare class SubordinatesDeclarationsToEntryPoint extends TraverseVisitor {
|
|
116
|
+
private childName;
|
|
117
|
+
constructor(childName: string);
|
|
118
|
+
visitEntryPoint(node: EntryPoint): void;
|
|
119
|
+
}
|
|
120
|
+
export declare class TypesAs extends TraverseVisitor {
|
|
121
|
+
private bindingName;
|
|
122
|
+
private typeName;
|
|
123
|
+
constructor(bindingName: string, typeName: string);
|
|
124
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
125
|
+
}
|
|
126
|
+
export declare class TypesParameterAs extends TraverseVisitor {
|
|
127
|
+
private bindingName;
|
|
128
|
+
private paramIndex;
|
|
129
|
+
private typeName;
|
|
130
|
+
constructor(bindingName: string, paramIndex: number, typeName: string);
|
|
131
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
132
|
+
}
|
|
133
|
+
export declare class TypesReturnAs extends TraverseVisitor {
|
|
134
|
+
private bindingName;
|
|
135
|
+
private typeName;
|
|
136
|
+
constructor(bindingName: string, typeName: string);
|
|
137
|
+
visitTypeSignature(node: TypeSignature): void;
|
|
138
|
+
}
|
|
139
|
+
export declare class Rescues extends TraverseVisitor {
|
|
140
|
+
private exceptionName;
|
|
141
|
+
constructor(exceptionName: string);
|
|
142
|
+
visitCatch(node: Catch): void;
|
|
143
|
+
}
|
|
144
|
+
export declare class UsesExceptionHandling extends TraverseVisitor {
|
|
145
|
+
visitTry(node: Try): void;
|
|
146
|
+
}
|
|
147
|
+
export declare class UsesExceptions extends TraverseVisitor {
|
|
148
|
+
visitTry(node: Try): void;
|
|
149
|
+
visitRaise(node: Raise): void;
|
|
150
|
+
}
|
|
151
|
+
export declare const genericInspections: InspectionMap;
|
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { ParameterizedType, StopTraversalException, SymbolPrimitive, TraverseVisitor, VariablePattern, } from "@yukigo/ast";
|
|
2
|
+
import { executeVisitor } from "../utils.js";
|
|
3
|
+
export class Assigns extends TraverseVisitor {
|
|
4
|
+
targetIdentifier;
|
|
5
|
+
constructor(targetIdentifier) {
|
|
6
|
+
super();
|
|
7
|
+
this.targetIdentifier = targetIdentifier;
|
|
8
|
+
}
|
|
9
|
+
visitVariable(node) {
|
|
10
|
+
if (node.identifier.value === this.targetIdentifier)
|
|
11
|
+
throw new StopTraversalException();
|
|
12
|
+
}
|
|
13
|
+
visitAttribute(node) {
|
|
14
|
+
if (node.identifier.value === this.targetIdentifier)
|
|
15
|
+
throw new StopTraversalException();
|
|
16
|
+
}
|
|
17
|
+
visitAssignment(node) {
|
|
18
|
+
if (node.identifier.value === this.targetIdentifier)
|
|
19
|
+
throw new StopTraversalException();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class Calls extends TraverseVisitor {
|
|
23
|
+
targetCallee;
|
|
24
|
+
constructor(targetCallee) {
|
|
25
|
+
super();
|
|
26
|
+
this.targetCallee = targetCallee;
|
|
27
|
+
}
|
|
28
|
+
visitCall(node) {
|
|
29
|
+
if (node.callee.value === this.targetCallee)
|
|
30
|
+
throw new StopTraversalException();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class Declares extends TraverseVisitor {
|
|
34
|
+
targetIdentifier;
|
|
35
|
+
constructor(targetIdentifier) {
|
|
36
|
+
super();
|
|
37
|
+
this.targetIdentifier = targetIdentifier;
|
|
38
|
+
}
|
|
39
|
+
visit(node) {
|
|
40
|
+
if ("identifier" in node &&
|
|
41
|
+
node.identifier instanceof SymbolPrimitive &&
|
|
42
|
+
node.identifier.value === this.targetIdentifier)
|
|
43
|
+
throw new StopTraversalException();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class DeclaresComputation extends TraverseVisitor {
|
|
47
|
+
callName;
|
|
48
|
+
constructor(callName) {
|
|
49
|
+
super();
|
|
50
|
+
this.callName = callName;
|
|
51
|
+
}
|
|
52
|
+
visitFunction(node) {
|
|
53
|
+
if (node.identifier.value === this.callName)
|
|
54
|
+
throw new StopTraversalException();
|
|
55
|
+
}
|
|
56
|
+
visitMethod(node) {
|
|
57
|
+
if (node.identifier.value === this.callName)
|
|
58
|
+
throw new StopTraversalException();
|
|
59
|
+
}
|
|
60
|
+
visitProcedure(node) {
|
|
61
|
+
if (node.identifier.value === this.callName)
|
|
62
|
+
throw new StopTraversalException();
|
|
63
|
+
}
|
|
64
|
+
visitFact(node) {
|
|
65
|
+
if (node.identifier.value === this.callName)
|
|
66
|
+
throw new StopTraversalException();
|
|
67
|
+
}
|
|
68
|
+
visitRule(node) {
|
|
69
|
+
if (node.identifier.value === this.callName)
|
|
70
|
+
throw new StopTraversalException();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export class DeclaresComputationWithArity extends TraverseVisitor {
|
|
74
|
+
targetBinding;
|
|
75
|
+
targetArity;
|
|
76
|
+
constructor(targetBinding, targetArity) {
|
|
77
|
+
super();
|
|
78
|
+
this.targetBinding = targetBinding;
|
|
79
|
+
this.targetArity = targetArity;
|
|
80
|
+
}
|
|
81
|
+
visitFunction(node) {
|
|
82
|
+
if (node.identifier.value === this.targetBinding &&
|
|
83
|
+
node.equations.some((eq) => eq.patterns.length === this.targetArity))
|
|
84
|
+
throw new StopTraversalException();
|
|
85
|
+
}
|
|
86
|
+
visitMethod(node) {
|
|
87
|
+
if (node.identifier.value === this.targetBinding &&
|
|
88
|
+
node.equations.some((eq) => eq.patterns.length === this.targetArity))
|
|
89
|
+
throw new StopTraversalException();
|
|
90
|
+
}
|
|
91
|
+
visitProcedure(node) {
|
|
92
|
+
if (node.identifier.value === this.targetBinding &&
|
|
93
|
+
node.equations.some((eq) => eq.patterns.length === this.targetArity))
|
|
94
|
+
throw new StopTraversalException();
|
|
95
|
+
}
|
|
96
|
+
visitFact(node) {
|
|
97
|
+
if (node.identifier.value === this.targetBinding &&
|
|
98
|
+
node.patterns.length === this.targetArity)
|
|
99
|
+
throw new StopTraversalException();
|
|
100
|
+
}
|
|
101
|
+
visitRule(node) {
|
|
102
|
+
if (node.identifier.value === this.targetBinding &&
|
|
103
|
+
node.patterns.length === this.targetArity)
|
|
104
|
+
throw new StopTraversalException();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export class DeclaresEntryPoint extends TraverseVisitor {
|
|
108
|
+
visitEntryPoint(node) {
|
|
109
|
+
throw new StopTraversalException();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class DeclaresFunction extends TraverseVisitor {
|
|
113
|
+
targetBinding;
|
|
114
|
+
constructor(targetBinding) {
|
|
115
|
+
super();
|
|
116
|
+
this.targetBinding = targetBinding;
|
|
117
|
+
}
|
|
118
|
+
visitFunction(node) {
|
|
119
|
+
if (node.identifier.value === this.targetBinding)
|
|
120
|
+
throw new StopTraversalException();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export class DeclaresRecursively extends DeclaresComputation {
|
|
124
|
+
targetBinding;
|
|
125
|
+
constructor(targetBinding) {
|
|
126
|
+
super(targetBinding);
|
|
127
|
+
this.targetBinding = targetBinding;
|
|
128
|
+
}
|
|
129
|
+
visitFunction(node) {
|
|
130
|
+
super.visitFunction(node);
|
|
131
|
+
this.visitNested(node);
|
|
132
|
+
}
|
|
133
|
+
visitMethod(node) {
|
|
134
|
+
super.visitMethod(node);
|
|
135
|
+
this.visitNested(node);
|
|
136
|
+
}
|
|
137
|
+
visitProcedure(node) {
|
|
138
|
+
super.visitProcedure(node);
|
|
139
|
+
this.visitNested(node);
|
|
140
|
+
}
|
|
141
|
+
visitFact(node) {
|
|
142
|
+
super.visitFact(node);
|
|
143
|
+
this.visitNested(node);
|
|
144
|
+
}
|
|
145
|
+
visitRule(node) {
|
|
146
|
+
super.visitRule(node);
|
|
147
|
+
this.visitNested(node);
|
|
148
|
+
}
|
|
149
|
+
visitNested(node) {
|
|
150
|
+
if ("identifier" in node &&
|
|
151
|
+
node.identifier instanceof SymbolPrimitive &&
|
|
152
|
+
node.identifier.value === this.targetBinding)
|
|
153
|
+
throw new StopTraversalException();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export class DeclaresTypeAlias extends TraverseVisitor {
|
|
157
|
+
typeAliasName;
|
|
158
|
+
constructor(typeAliasName) {
|
|
159
|
+
super();
|
|
160
|
+
this.typeAliasName = typeAliasName;
|
|
161
|
+
}
|
|
162
|
+
visitTypeAlias(node) {
|
|
163
|
+
if (node.identifier.value === this.typeAliasName)
|
|
164
|
+
throw new StopTraversalException();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
export class DeclaresTypeSignature extends TraverseVisitor {
|
|
168
|
+
targetBinding;
|
|
169
|
+
constructor(targetBinding) {
|
|
170
|
+
super();
|
|
171
|
+
this.targetBinding = targetBinding;
|
|
172
|
+
}
|
|
173
|
+
visitTypeSignature(node) {
|
|
174
|
+
if (node.identifier.value === this.targetBinding)
|
|
175
|
+
throw new StopTraversalException();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export class DeclaresVariable extends TraverseVisitor {
|
|
179
|
+
targetBinding;
|
|
180
|
+
constructor(targetBinding) {
|
|
181
|
+
super();
|
|
182
|
+
this.targetBinding = targetBinding;
|
|
183
|
+
}
|
|
184
|
+
visitVariable(node) {
|
|
185
|
+
if (node.identifier.value === this.targetBinding)
|
|
186
|
+
throw new StopTraversalException();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export class Raises extends TraverseVisitor {
|
|
190
|
+
visitRaise(node) {
|
|
191
|
+
throw new StopTraversalException();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
export class Uses extends TraverseVisitor {
|
|
195
|
+
targetBinding;
|
|
196
|
+
constructor(targetBinding) {
|
|
197
|
+
super();
|
|
198
|
+
this.targetBinding = targetBinding;
|
|
199
|
+
}
|
|
200
|
+
visitSymbolPrimitive(node) {
|
|
201
|
+
if (node.value === this.targetBinding)
|
|
202
|
+
throw new StopTraversalException();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
export class UsesArithmetic extends TraverseVisitor {
|
|
206
|
+
visitArithmeticBinaryOperation(node) {
|
|
207
|
+
throw new StopTraversalException();
|
|
208
|
+
}
|
|
209
|
+
visitArithmeticUnaryOperation(node) {
|
|
210
|
+
throw new StopTraversalException();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export class UsesConditional extends TraverseVisitor {
|
|
214
|
+
visitIf(node) {
|
|
215
|
+
throw new StopTraversalException();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
export class UsesLogic extends TraverseVisitor {
|
|
219
|
+
visitLogicalBinaryOperation(node) {
|
|
220
|
+
throw new StopTraversalException();
|
|
221
|
+
}
|
|
222
|
+
visitLogicalUnaryOperation(node) {
|
|
223
|
+
throw new StopTraversalException();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export class UsesPrint extends TraverseVisitor {
|
|
227
|
+
visitPrint(node) {
|
|
228
|
+
throw new StopTraversalException();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export class UsesType extends TraverseVisitor {
|
|
232
|
+
targetBinding;
|
|
233
|
+
constructor(targetBinding) {
|
|
234
|
+
super();
|
|
235
|
+
this.targetBinding = targetBinding;
|
|
236
|
+
}
|
|
237
|
+
visitTypeSignature(node) {
|
|
238
|
+
node.body.accept(this);
|
|
239
|
+
}
|
|
240
|
+
visitSimpleType(node) {
|
|
241
|
+
if (node.value === this.targetBinding)
|
|
242
|
+
throw new StopTraversalException();
|
|
243
|
+
}
|
|
244
|
+
visitTypeVar(node) {
|
|
245
|
+
if (node.value === this.targetBinding)
|
|
246
|
+
throw new StopTraversalException();
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export class HasBinding extends TraverseVisitor {
|
|
250
|
+
targetBinding;
|
|
251
|
+
constructor(targetBinding) {
|
|
252
|
+
super();
|
|
253
|
+
this.targetBinding = targetBinding;
|
|
254
|
+
}
|
|
255
|
+
visitFunction(node) {
|
|
256
|
+
if (node.identifier.value === this.targetBinding)
|
|
257
|
+
throw new StopTraversalException();
|
|
258
|
+
}
|
|
259
|
+
visitTypeAlias(node) {
|
|
260
|
+
if (node.identifier.value === this.targetBinding)
|
|
261
|
+
throw new StopTraversalException();
|
|
262
|
+
}
|
|
263
|
+
visitTypeSignature(node) {
|
|
264
|
+
if (node.identifier.value === this.targetBinding)
|
|
265
|
+
throw new StopTraversalException();
|
|
266
|
+
}
|
|
267
|
+
visitRecord(node) {
|
|
268
|
+
if (node.name.value === this.targetBinding)
|
|
269
|
+
throw new StopTraversalException();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export class SubordinatesDeclarationsTo extends TraverseVisitor {
|
|
273
|
+
childName;
|
|
274
|
+
parentName;
|
|
275
|
+
constructor(childName, parentName) {
|
|
276
|
+
super();
|
|
277
|
+
this.childName = childName;
|
|
278
|
+
this.parentName = parentName;
|
|
279
|
+
}
|
|
280
|
+
visitFunction(node) {
|
|
281
|
+
if (node.identifier.value === this.parentName) {
|
|
282
|
+
const childFinder = new Declares(this.childName);
|
|
283
|
+
node.equations.forEach((eq) => eq.accept(childFinder)); // we expect that this will throw if find the subordinated decl
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
super.visitFunction(node);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
export class SubordinatesDeclarationsToEntryPoint extends TraverseVisitor {
|
|
291
|
+
childName;
|
|
292
|
+
constructor(childName) {
|
|
293
|
+
super();
|
|
294
|
+
this.childName = childName;
|
|
295
|
+
}
|
|
296
|
+
visitEntryPoint(node) {
|
|
297
|
+
const childFinder = new Declares(this.childName);
|
|
298
|
+
node.expression.statements.forEach((stmt) => stmt.accept(childFinder));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export class TypesAs extends TraverseVisitor {
|
|
302
|
+
bindingName;
|
|
303
|
+
typeName;
|
|
304
|
+
constructor(bindingName, typeName) {
|
|
305
|
+
super();
|
|
306
|
+
this.bindingName = bindingName;
|
|
307
|
+
this.typeName = typeName;
|
|
308
|
+
}
|
|
309
|
+
visitTypeSignature(node) {
|
|
310
|
+
if (node.identifier.value === this.bindingName) {
|
|
311
|
+
const actualType = node.body.toString();
|
|
312
|
+
if (actualType.replace(/\s+/g, " ").trim() ===
|
|
313
|
+
this.typeName.replace(/\s+/g, " ").trim()) {
|
|
314
|
+
throw new StopTraversalException();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export class TypesParameterAs extends TraverseVisitor {
|
|
320
|
+
bindingName;
|
|
321
|
+
paramIndex;
|
|
322
|
+
typeName;
|
|
323
|
+
constructor(bindingName, paramIndex, typeName) {
|
|
324
|
+
super();
|
|
325
|
+
this.bindingName = bindingName;
|
|
326
|
+
this.paramIndex = paramIndex;
|
|
327
|
+
this.typeName = typeName;
|
|
328
|
+
}
|
|
329
|
+
visitTypeSignature(node) {
|
|
330
|
+
if (node.identifier.value === this.bindingName) {
|
|
331
|
+
if (node.body instanceof ParameterizedType) {
|
|
332
|
+
const paramType = node.body.inputs[this.paramIndex];
|
|
333
|
+
if (paramType) {
|
|
334
|
+
const actualType = paramType.toString();
|
|
335
|
+
if (actualType.replace(/\s+/g, " ").trim() ===
|
|
336
|
+
this.typeName.replace(/\s+/g, " ").trim()) {
|
|
337
|
+
throw new StopTraversalException();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
export class TypesReturnAs extends TraverseVisitor {
|
|
345
|
+
bindingName;
|
|
346
|
+
typeName;
|
|
347
|
+
constructor(bindingName, typeName) {
|
|
348
|
+
super();
|
|
349
|
+
this.bindingName = bindingName;
|
|
350
|
+
this.typeName = typeName;
|
|
351
|
+
}
|
|
352
|
+
visitTypeSignature(node) {
|
|
353
|
+
if (node.identifier.value === this.bindingName) {
|
|
354
|
+
if (node.body instanceof ParameterizedType) {
|
|
355
|
+
const actualType = node.body.returnType.toString();
|
|
356
|
+
if (actualType.replace(/\s+/g, " ").trim() ===
|
|
357
|
+
this.typeName.replace(/\s+/g, " ").trim()) {
|
|
358
|
+
throw new StopTraversalException();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
export class Rescues extends TraverseVisitor {
|
|
365
|
+
exceptionName;
|
|
366
|
+
constructor(exceptionName) {
|
|
367
|
+
super();
|
|
368
|
+
this.exceptionName = exceptionName;
|
|
369
|
+
}
|
|
370
|
+
visitCatch(node) {
|
|
371
|
+
for (const pattern of node.patterns) {
|
|
372
|
+
if (pattern instanceof VariablePattern &&
|
|
373
|
+
pattern.name.value === this.exceptionName) {
|
|
374
|
+
throw new StopTraversalException();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
export class UsesExceptionHandling extends TraverseVisitor {
|
|
380
|
+
visitTry(node) {
|
|
381
|
+
throw new StopTraversalException();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
export class UsesExceptions extends TraverseVisitor {
|
|
385
|
+
visitTry(node) {
|
|
386
|
+
throw new StopTraversalException();
|
|
387
|
+
}
|
|
388
|
+
visitRaise(node) {
|
|
389
|
+
throw new StopTraversalException();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
export const genericInspections = {
|
|
393
|
+
Assigns: (node, args) => executeVisitor(node, new Assigns(args[0])),
|
|
394
|
+
Calls: (node, args) => executeVisitor(node, new Calls(args[0])),
|
|
395
|
+
Declares: (node, args) => executeVisitor(node, new Declares(args[0])),
|
|
396
|
+
DeclaresComputation: (node, args) => executeVisitor(node, new DeclaresComputation(args[0])),
|
|
397
|
+
DeclaresComputationWithArity: (node, args, binding) => executeVisitor(node, new DeclaresComputationWithArity(binding, Number(args[0]))),
|
|
398
|
+
DeclaresEntryPoint: (node, args) => executeVisitor(node, new DeclaresEntryPoint()),
|
|
399
|
+
DeclaresFunction: (node, args) => executeVisitor(node, new DeclaresFunction(args[0])),
|
|
400
|
+
DeclaresRecursively: (node, args) => executeVisitor(node, new DeclaresRecursively(args[0])),
|
|
401
|
+
DeclaresTypeAlias: (node, args) => executeVisitor(node, new DeclaresTypeAlias(args[0])),
|
|
402
|
+
DeclaresTypeSignature: (node, args) => executeVisitor(node, new DeclaresTypeSignature(args[0])),
|
|
403
|
+
DeclaresVariable: (node, args) => executeVisitor(node, new DeclaresVariable(args[0])),
|
|
404
|
+
Delegates: (ast, args) => {
|
|
405
|
+
const declares = genericInspections.Declares(ast, args);
|
|
406
|
+
const calls = genericInspections.Calls(ast, args);
|
|
407
|
+
return declares && calls;
|
|
408
|
+
},
|
|
409
|
+
Raises: (node, args) => executeVisitor(node, new Raises()),
|
|
410
|
+
Uses: (node, args) => executeVisitor(node, new Uses(args[0])),
|
|
411
|
+
UsesArithmetic: (node, args) => executeVisitor(node, new UsesArithmetic()),
|
|
412
|
+
SubordinatesDeclarationsTo: (node, args) => executeVisitor(node, new SubordinatesDeclarationsTo(args[0], args[1])),
|
|
413
|
+
SubordinatesDeclarationsToEntryPoint: (node, args) => executeVisitor(node, new SubordinatesDeclarationsToEntryPoint(args[0])),
|
|
414
|
+
TypesAs: (node, args) => executeVisitor(node, new TypesAs(args[0], args[1])),
|
|
415
|
+
TypesParameterAs: (node, args) => executeVisitor(node, new TypesParameterAs(args[0], Number(args[1]), args[2])),
|
|
416
|
+
TypesReturnAs: (node, args) => executeVisitor(node, new TypesReturnAs(args[0], args[1])),
|
|
417
|
+
UsesConditional: (node, args) => executeVisitor(node, new UsesConditional()),
|
|
418
|
+
Rescues: (node, args) => executeVisitor(node, new Rescues(args[0])),
|
|
419
|
+
UsesExceptionHandling: (node, args) => executeVisitor(node, new UsesExceptionHandling()),
|
|
420
|
+
UsesExceptions: (node, args) => executeVisitor(node, new UsesExceptions()),
|
|
421
|
+
UsesIf: (node, args) => executeVisitor(node, new UsesConditional()),
|
|
422
|
+
UsesLogic: (node, args) => executeVisitor(node, new UsesLogic()),
|
|
423
|
+
UsesMath: (node, args) => executeVisitor(node, new UsesArithmetic()),
|
|
424
|
+
UsesPrint: (node, args) => executeVisitor(node, new UsesPrint()),
|
|
425
|
+
UsesType: (node, args) => executeVisitor(node, new UsesType(args[0])),
|
|
426
|
+
HasBinding: (node, args) => executeVisitor(node, new HasBinding(args[0])),
|
|
427
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Enumeration, ForLoop, Function, Procedure, Repeat, Switch, TraverseVisitor, While } from "@yukigo/ast";
|
|
2
|
+
import { InspectionMap } from "../utils.js";
|
|
3
|
+
export declare class BindingVisitor extends TraverseVisitor {
|
|
4
|
+
private readonly targetBinding;
|
|
5
|
+
protected isInsideTargetScope: boolean;
|
|
6
|
+
constructor(binding: string);
|
|
7
|
+
visitProcedure(node: Procedure): void;
|
|
8
|
+
visitFunction(node: Function): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class DeclaresEnumeration extends TraverseVisitor {
|
|
11
|
+
private readonly enumName;
|
|
12
|
+
constructor(enumName: string);
|
|
13
|
+
visitEnumeration(node: Enumeration): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class DeclaresProcedure extends TraverseVisitor {
|
|
16
|
+
private readonly procedureName;
|
|
17
|
+
constructor(procedureName: string);
|
|
18
|
+
visitProcedure(node: Procedure): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class UsesForLoop extends BindingVisitor {
|
|
21
|
+
visitForLoop(node: ForLoop): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class UsesWhile extends BindingVisitor {
|
|
24
|
+
visitWhile(node: While): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class UsesRepeat extends BindingVisitor {
|
|
27
|
+
visitRepeat(node: Repeat): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class UsesLoop extends BindingVisitor {
|
|
30
|
+
visitForLoop(node: ForLoop): void;
|
|
31
|
+
visitWhile(node: While): void;
|
|
32
|
+
visitRepeat(node: Repeat): void;
|
|
33
|
+
}
|
|
34
|
+
export declare class UsesSwitch extends BindingVisitor {
|
|
35
|
+
visitSwitch(node: Switch): void;
|
|
36
|
+
}
|
|
37
|
+
export declare const imperativeInspections: InspectionMap;
|