yukigo 0.1.0 → 0.2.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 +3 -3
- package/CHANGELOG.md +26 -0
- package/README.md +193 -199
- package/dist/analyzer/GraphBuilder.d.ts +29 -0
- package/dist/analyzer/GraphBuilder.js +99 -0
- package/dist/analyzer/index.d.ts +11 -23
- package/dist/analyzer/index.js +100 -58
- package/dist/analyzer/inspections/functional/functional.d.ts +44 -0
- package/dist/analyzer/inspections/functional/functional.js +149 -0
- package/dist/analyzer/inspections/functional/smells.d.ts +16 -0
- package/dist/analyzer/inspections/functional/smells.js +98 -0
- package/dist/analyzer/inspections/{generic.d.ts → generic/generic.d.ts} +70 -43
- package/dist/analyzer/inspections/generic/generic.js +604 -0
- package/dist/analyzer/inspections/generic/smells.d.ts +61 -0
- package/dist/analyzer/inspections/generic/smells.js +349 -0
- package/dist/analyzer/inspections/imperative/imperative.d.ts +35 -0
- package/dist/analyzer/inspections/imperative/imperative.js +109 -0
- package/dist/analyzer/inspections/imperative/smells.d.ts +16 -0
- package/dist/analyzer/inspections/imperative/smells.js +58 -0
- package/dist/analyzer/inspections/logic/logic.d.ts +32 -0
- package/dist/analyzer/inspections/logic/logic.js +96 -0
- package/dist/analyzer/inspections/logic/smells.d.ts +15 -0
- package/dist/analyzer/inspections/logic/smells.js +60 -0
- package/dist/analyzer/inspections/object/object.d.ts +88 -0
- package/dist/analyzer/inspections/object/object.js +319 -0
- package/dist/analyzer/inspections/object/smells.d.ts +30 -0
- package/dist/analyzer/inspections/object/smells.js +135 -0
- package/dist/analyzer/utils.d.ts +26 -4
- package/dist/analyzer/utils.js +71 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpreter/components/EnvBuilder.d.ts +9 -5
- package/dist/interpreter/components/EnvBuilder.js +100 -30
- package/dist/interpreter/components/Operations.d.ts +4 -4
- package/dist/interpreter/components/Operations.js +17 -2
- package/dist/interpreter/components/PatternMatcher.d.ts +47 -17
- package/dist/interpreter/components/PatternMatcher.js +264 -119
- package/dist/interpreter/components/RuntimeContext.d.ts +35 -0
- package/dist/interpreter/components/RuntimeContext.js +93 -0
- package/dist/interpreter/components/TestRunner.d.ts +18 -0
- package/dist/interpreter/components/TestRunner.js +103 -0
- package/dist/interpreter/components/Visitor.d.ts +63 -57
- package/dist/interpreter/components/Visitor.js +508 -173
- package/dist/interpreter/components/logic/LogicEngine.d.ts +29 -0
- package/dist/interpreter/components/logic/LogicEngine.js +259 -0
- package/dist/interpreter/components/logic/LogicResolver.d.ts +53 -0
- package/dist/interpreter/components/logic/LogicResolver.js +471 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +14 -0
- package/dist/interpreter/components/logic/LogicTranslator.js +99 -0
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +12 -0
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +147 -0
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +19 -0
- package/dist/interpreter/components/runtimes/LazyRuntime.js +269 -0
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +35 -0
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +126 -0
- package/dist/interpreter/entities.d.ts +105 -0
- package/dist/interpreter/entities.js +96 -0
- package/dist/interpreter/errors.d.ts +1 -1
- package/dist/interpreter/index.d.ts +4 -12
- package/dist/interpreter/index.js +10 -13
- package/dist/interpreter/trampoline.d.ts +17 -0
- package/dist/interpreter/trampoline.js +38 -0
- package/dist/interpreter/utils.d.ts +4 -7
- package/dist/interpreter/utils.js +25 -17
- package/dist/tester/index.d.ts +25 -0
- package/dist/tester/index.js +108 -0
- package/dist/utils/helpers.d.ts +0 -4
- package/dist/utils/helpers.js +20 -24
- package/package.json +2 -2
- package/src/analyzer/GraphBuilder.ts +142 -0
- package/src/analyzer/index.ts +185 -132
- package/src/analyzer/inspections/functional/functional.ts +121 -0
- package/src/analyzer/inspections/functional/smells.ts +102 -0
- package/src/analyzer/inspections/{generic.ts → generic/generic.ts} +581 -499
- package/src/analyzer/inspections/generic/smells.ts +365 -0
- package/src/analyzer/inspections/imperative/imperative.ts +101 -0
- package/src/analyzer/inspections/imperative/smells.ts +54 -0
- package/src/analyzer/inspections/logic/logic.ts +90 -0
- package/src/analyzer/inspections/logic/smells.ts +54 -0
- package/src/analyzer/inspections/{object.ts → object/object.ts} +264 -282
- package/src/analyzer/inspections/object/smells.ts +144 -0
- package/src/analyzer/utils.ts +109 -26
- package/src/index.ts +3 -2
- package/src/interpreter/components/EnvBuilder.ts +202 -97
- package/src/interpreter/components/Operations.ts +99 -81
- package/src/interpreter/components/PatternMatcher.ts +475 -254
- package/src/interpreter/components/RuntimeContext.ts +119 -0
- package/src/interpreter/components/TestRunner.ts +151 -0
- package/src/interpreter/components/Visitor.ts +1065 -493
- package/src/interpreter/components/logic/LogicEngine.ts +519 -0
- package/src/interpreter/components/logic/LogicResolver.ts +858 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +149 -0
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +227 -0
- package/src/interpreter/components/runtimes/LazyRuntime.ts +334 -0
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +224 -0
- package/src/interpreter/errors.ts +47 -47
- package/src/interpreter/index.ts +52 -59
- package/src/interpreter/trampoline.ts +71 -0
- package/src/interpreter/utils.ts +84 -79
- package/src/tester/index.ts +128 -0
- package/src/utils/helpers.ts +67 -73
- package/tests/analyzer/functional.spec.ts +207 -221
- package/tests/analyzer/generic.spec.ts +178 -100
- package/tests/analyzer/helpers.spec.ts +83 -83
- package/tests/analyzer/logic.spec.ts +237 -292
- package/tests/analyzer/oop.spec.ts +323 -338
- package/tests/analyzer/transitive.spec.ts +166 -0
- package/tests/interpreter/EnvBuilder.spec.ts +183 -178
- package/tests/interpreter/FunctionRuntime.spec.ts +223 -234
- package/tests/interpreter/LazyRuntime.spec.ts +225 -190
- package/tests/interpreter/LogicEngine.spec.ts +327 -194
- package/tests/interpreter/LogicSubstitution.spec.ts +80 -0
- package/tests/interpreter/ObjectRuntime.spec.ts +606 -0
- package/tests/interpreter/Operations.spec.ts +220 -220
- package/tests/interpreter/PatternSystem.spec.ts +213 -189
- package/tests/interpreter/Tests.spec.ts +122 -0
- package/tests/interpreter/interpreter.spec.ts +991 -937
- package/tests/tester/Tester.spec.ts +153 -0
- package/tsconfig.build.json +15 -7
- package/tsconfig.json +25 -17
- package/dist/analyzer/inspections/functional.d.ts +0 -46
- package/dist/analyzer/inspections/functional.js +0 -123
- package/dist/analyzer/inspections/generic.js +0 -427
- package/dist/analyzer/inspections/imperative.d.ts +0 -37
- package/dist/analyzer/inspections/imperative.js +0 -105
- package/dist/analyzer/inspections/logic.d.ts +0 -49
- package/dist/analyzer/inspections/logic.js +0 -140
- package/dist/analyzer/inspections/object.d.ts +0 -83
- package/dist/analyzer/inspections/object.js +0 -235
- package/dist/interpreter/components/FunctionRuntime.d.ts +0 -8
- package/dist/interpreter/components/FunctionRuntime.js +0 -52
- package/dist/interpreter/components/LazyRuntime.d.ts +0 -7
- package/dist/interpreter/components/LazyRuntime.js +0 -75
- package/dist/interpreter/components/LogicEngine.d.ts +0 -21
- package/dist/interpreter/components/LogicEngine.js +0 -152
- package/dist/interpreter/components/LogicResolver.d.ts +0 -11
- package/dist/interpreter/components/LogicResolver.js +0 -87
- package/src/analyzer/inspections/functional.ts +0 -159
- package/src/analyzer/inspections/imperative.ts +0 -129
- package/src/analyzer/inspections/logic.ts +0 -166
- package/src/interpreter/components/FunctionRuntime.ts +0 -79
- package/src/interpreter/components/LazyRuntime.ts +0 -97
- package/src/interpreter/components/LogicEngine.ts +0 -227
- package/src/interpreter/components/LogicResolver.ts +0 -130
|
@@ -1,427 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
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;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { StopTraversalException, TraverseVisitor, } from "@yukigo/ast";
|
|
2
|
-
import { executeVisitor } from "../utils.js";
|
|
3
|
-
export class BindingVisitor extends TraverseVisitor {
|
|
4
|
-
targetBinding;
|
|
5
|
-
isInsideTargetScope = false; // this flag helps to check nested functions inside the targetBinding scope
|
|
6
|
-
constructor(binding) {
|
|
7
|
-
super();
|
|
8
|
-
this.targetBinding = binding;
|
|
9
|
-
}
|
|
10
|
-
visitProcedure(node) {
|
|
11
|
-
const currentFunctionName = node.identifier.value;
|
|
12
|
-
// if not inside scope then is top-level
|
|
13
|
-
if (!this.isInsideTargetScope) {
|
|
14
|
-
if (!this.targetBinding || currentFunctionName === this.targetBinding) {
|
|
15
|
-
this.isInsideTargetScope = true;
|
|
16
|
-
this.traverseCollection(node.equations);
|
|
17
|
-
this.isInsideTargetScope = false;
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
// if inside the scope of targetBinding then traverse
|
|
23
|
-
this.traverseCollection(node.equations);
|
|
24
|
-
}
|
|
25
|
-
visitFunction(node) {
|
|
26
|
-
const currentFunctionName = node.identifier.value;
|
|
27
|
-
// if not inside scope then is top-level
|
|
28
|
-
if (!this.isInsideTargetScope) {
|
|
29
|
-
if (!this.targetBinding || currentFunctionName === this.targetBinding) {
|
|
30
|
-
this.isInsideTargetScope = true;
|
|
31
|
-
this.traverseCollection(node.equations);
|
|
32
|
-
this.isInsideTargetScope = false;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// if inside the scope of targetBinding then traverse
|
|
38
|
-
this.traverseCollection(node.equations);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export class DeclaresEnumeration extends TraverseVisitor {
|
|
42
|
-
enumName;
|
|
43
|
-
constructor(enumName) {
|
|
44
|
-
super();
|
|
45
|
-
this.enumName = enumName;
|
|
46
|
-
}
|
|
47
|
-
visitEnumeration(node) {
|
|
48
|
-
if (node.identifier.value === this.enumName)
|
|
49
|
-
throw StopTraversalException;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
export class DeclaresProcedure extends TraverseVisitor {
|
|
53
|
-
procedureName;
|
|
54
|
-
constructor(procedureName) {
|
|
55
|
-
super();
|
|
56
|
-
this.procedureName = procedureName;
|
|
57
|
-
}
|
|
58
|
-
visitProcedure(node) {
|
|
59
|
-
if (node.identifier.value === this.procedureName)
|
|
60
|
-
throw StopTraversalException;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
export class UsesForLoop extends BindingVisitor {
|
|
64
|
-
visitForLoop(node) {
|
|
65
|
-
throw StopTraversalException;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
export class UsesWhile extends BindingVisitor {
|
|
69
|
-
visitWhile(node) {
|
|
70
|
-
throw StopTraversalException;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export class UsesRepeat extends BindingVisitor {
|
|
74
|
-
visitRepeat(node) {
|
|
75
|
-
throw StopTraversalException;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
export class UsesLoop extends BindingVisitor {
|
|
79
|
-
visitForLoop(node) {
|
|
80
|
-
throw StopTraversalException;
|
|
81
|
-
}
|
|
82
|
-
visitWhile(node) {
|
|
83
|
-
throw StopTraversalException;
|
|
84
|
-
}
|
|
85
|
-
visitRepeat(node) {
|
|
86
|
-
throw StopTraversalException;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export class UsesSwitch extends BindingVisitor {
|
|
90
|
-
visitSwitch(node) {
|
|
91
|
-
throw StopTraversalException;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export const imperativeInspections = {
|
|
95
|
-
DeclaresEnumeration: (node, args) => executeVisitor(node, new DeclaresEnumeration(args[0])),
|
|
96
|
-
DeclaresProcedure: (node, args) => executeVisitor(node, new DeclaresProcedure(args[0])),
|
|
97
|
-
UsesForEach: (node, args) => {
|
|
98
|
-
throw Error("Inspection not implemented");
|
|
99
|
-
},
|
|
100
|
-
UsesForLoop: (node, args, binding) => executeVisitor(node, new UsesForLoop(binding)),
|
|
101
|
-
UsesRepeat: (node, args, binding) => executeVisitor(node, new UsesRepeat(binding)),
|
|
102
|
-
UsesWhile: (node, args, binding) => executeVisitor(node, new UsesWhile(binding)),
|
|
103
|
-
UsesLoop: (node, args, binding) => executeVisitor(node, new UsesLoop(binding)),
|
|
104
|
-
UsesSwitch: (node, args, binding) => executeVisitor(node, new UsesSwitch(binding)),
|
|
105
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Exist, Fact, Findall, Forall, Not, Rule, TraverseVisitor, UnifyOperation } from "@yukigo/ast";
|
|
2
|
-
import { InspectionMap } from "../utils.js";
|
|
3
|
-
export declare abstract class DeclaresBinding extends TraverseVisitor {
|
|
4
|
-
protected readonly targetBinding: string;
|
|
5
|
-
constructor(binding: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class DeclaresFact extends DeclaresBinding {
|
|
8
|
-
visitFact(node: Fact): void;
|
|
9
|
-
}
|
|
10
|
-
export declare class DeclaresRule extends DeclaresBinding {
|
|
11
|
-
visitRule(node: Rule): void;
|
|
12
|
-
}
|
|
13
|
-
export declare class DeclaresPredicate extends DeclaresBinding {
|
|
14
|
-
visitFact(node: Fact): void;
|
|
15
|
-
visitRule(node: Rule): void;
|
|
16
|
-
}
|
|
17
|
-
export declare class PredicateVisitor extends TraverseVisitor {
|
|
18
|
-
private readonly targetBinding;
|
|
19
|
-
protected isInsideTargetScope: boolean;
|
|
20
|
-
constructor(binding: string);
|
|
21
|
-
visitFact(node: Fact): void;
|
|
22
|
-
visitRule(node: Rule): void;
|
|
23
|
-
}
|
|
24
|
-
export declare class UsesFindall extends TraverseVisitor {
|
|
25
|
-
visitFindall(node: Findall): void;
|
|
26
|
-
}
|
|
27
|
-
export declare class UsesForall extends TraverseVisitor {
|
|
28
|
-
visitForall(node: Forall): void;
|
|
29
|
-
}
|
|
30
|
-
export declare class UsesNot extends TraverseVisitor {
|
|
31
|
-
visitNot(node: Not): void;
|
|
32
|
-
visitExist(node: Exist): void;
|
|
33
|
-
}
|
|
34
|
-
export declare class UsesUnificationOperator extends PredicateVisitor {
|
|
35
|
-
visitUnifyOperation(node: UnifyOperation): void;
|
|
36
|
-
}
|
|
37
|
-
export declare class UsesCut extends PredicateVisitor {
|
|
38
|
-
visitExist(node: Exist): void;
|
|
39
|
-
}
|
|
40
|
-
export declare class UsesFail extends PredicateVisitor {
|
|
41
|
-
visitExist(node: Exist): void;
|
|
42
|
-
}
|
|
43
|
-
export declare class HasRedundantReduction extends TraverseVisitor {
|
|
44
|
-
private readonly targetBinding;
|
|
45
|
-
protected isInsideTargetScope: boolean;
|
|
46
|
-
constructor(binding: string);
|
|
47
|
-
visitRule(node: Rule): void;
|
|
48
|
-
}
|
|
49
|
-
export declare const logicInspections: InspectionMap;
|