yukigo 0.2.3 → 0.3.2
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 +105 -40
- package/README.md +193 -193
- package/dist/analyzer/GraphBuilder.d.ts +1 -0
- package/dist/analyzer/GraphBuilder.js +2 -1
- package/dist/analyzer/index.d.ts +0 -7
- package/dist/analyzer/index.js +3 -3
- package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
- package/dist/analyzer/inspections/functional/functional.js +1 -1
- package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
- package/dist/analyzer/inspections/functional/smells.js +27 -35
- package/dist/analyzer/inspections/generic/generic.d.ts +22 -14
- package/dist/analyzer/inspections/generic/generic.js +82 -60
- package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
- package/dist/analyzer/inspections/generic/smells.js +55 -64
- package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
- package/dist/analyzer/inspections/imperative/imperative.js +3 -3
- package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
- package/dist/analyzer/inspections/imperative/smells.js +8 -5
- package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
- package/dist/analyzer/inspections/logic/logic.js +5 -5
- package/dist/analyzer/inspections/logic/smells.js +2 -2
- package/dist/analyzer/inspections/object/object.d.ts +5 -5
- package/dist/analyzer/inspections/object/object.js +22 -21
- package/dist/analyzer/inspections/object/smells.js +11 -23
- package/dist/analyzer/utils.d.ts +6 -2
- package/dist/analyzer/utils.js +6 -2
- package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
- package/dist/interpreter/components/EnvBuilder.js +211 -66
- package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
- package/dist/interpreter/components/EqualityComparer.js +69 -0
- package/dist/interpreter/components/Operations.d.ts +17 -14
- package/dist/interpreter/components/Operations.js +61 -62
- package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
- package/dist/interpreter/components/PatternMatcher.js +185 -286
- package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
- package/dist/interpreter/components/RuntimeContext.js +43 -4
- package/dist/interpreter/components/TestRunner.d.ts +15 -13
- package/dist/interpreter/components/TestRunner.js +86 -53
- package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
- package/dist/interpreter/components/evaluators/index.d.ts +110 -0
- package/dist/interpreter/components/evaluators/index.js +21 -0
- package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
- package/dist/interpreter/components/evaluators/utils.js +50 -0
- package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
- package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
- package/dist/interpreter/components/kernel/commands.d.ts +122 -0
- package/dist/interpreter/components/kernel/commands.js +203 -0
- package/dist/interpreter/components/kernel/index.d.ts +51 -0
- package/dist/interpreter/components/kernel/index.js +176 -0
- package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
- package/dist/interpreter/components/logic/LogicEngine.js +234 -221
- package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
- package/dist/interpreter/components/logic/LogicResolver.js +73 -440
- package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
- package/dist/interpreter/components/logic/LogicTerm.js +423 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
- package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
- package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
- package/dist/interpreter/errors.d.ts +10 -0
- package/dist/interpreter/errors.js +17 -0
- package/dist/interpreter/index.d.ts +9 -5
- package/dist/interpreter/index.js +11 -13
- package/dist/interpreter/primitives/YuValue.d.ts +21 -0
- package/dist/interpreter/primitives/YuValue.js +40 -0
- package/dist/interpreter/primitives/capabilities.d.ts +90 -0
- package/dist/interpreter/primitives/capabilities.js +1 -0
- package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
- package/dist/interpreter/primitives/entities/LazyList.js +164 -0
- package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
- package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
- package/dist/interpreter/primitives/index.d.ts +14 -0
- package/dist/interpreter/primitives/index.js +14 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
- package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
- package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
- package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
- package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
- package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
- package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
- package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
- package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
- package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
- package/dist/interpreter/primitives/sequences/YuString.js +130 -0
- package/dist/interpreter/utils.d.ts +23 -10
- package/dist/interpreter/utils.js +25 -30
- package/dist/tester/index.d.ts +3 -3
- package/dist/tester/index.js +39 -28
- package/dist/utils/helpers.d.ts +13 -5
- package/dist/utils/helpers.js +38 -85
- package/package.json +3 -16
- package/src/analyzer/GraphBuilder.ts +143 -142
- package/src/analyzer/index.ts +185 -194
- package/src/analyzer/inspections/functional/functional.ts +121 -121
- package/src/analyzer/inspections/functional/smells.ts +88 -102
- package/src/analyzer/inspections/generic/generic.ts +610 -577
- package/src/analyzer/inspections/generic/smells.ts +355 -365
- package/src/analyzer/inspections/imperative/imperative.ts +104 -101
- package/src/analyzer/inspections/imperative/smells.ts +58 -54
- package/src/analyzer/inspections/logic/logic.ts +84 -90
- package/src/analyzer/inspections/logic/smells.ts +54 -54
- package/src/analyzer/inspections/object/object.ts +295 -264
- package/src/analyzer/inspections/object/smells.ts +130 -144
- package/src/analyzer/utils.ts +115 -109
- package/src/index.ts +3 -3
- package/src/interpreter/components/EnvBuilder.ts +405 -202
- package/src/interpreter/components/EqualityComparer.ts +107 -0
- package/src/interpreter/components/Operations.ts +126 -99
- package/src/interpreter/components/PatternMatcher.ts +375 -475
- package/src/interpreter/components/RuntimeContext.ts +181 -119
- package/src/interpreter/components/TestRunner.ts +223 -151
- package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
- package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
- package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
- package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
- package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
- package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
- package/src/interpreter/components/evaluators/index.ts +34 -0
- package/src/interpreter/components/evaluators/utils.ts +64 -0
- package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
- package/src/interpreter/components/kernel/commands.ts +255 -0
- package/src/interpreter/components/kernel/index.ts +222 -0
- package/src/interpreter/components/logic/LogicEngine.ts +509 -519
- package/src/interpreter/components/logic/LogicResolver.ts +209 -858
- package/src/interpreter/components/logic/LogicTerm.ts +477 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
- package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
- package/src/interpreter/errors.ts +68 -47
- package/src/interpreter/index.ts +50 -52
- package/src/interpreter/primitives/YuValue.ts +64 -0
- package/src/interpreter/primitives/capabilities.ts +111 -0
- package/src/interpreter/primitives/entities/LazyList.ts +225 -0
- package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
- package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
- package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
- package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
- package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
- package/src/interpreter/primitives/index.ts +17 -0
- package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
- package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
- package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
- package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
- package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
- package/src/interpreter/primitives/sequences/YuString.ts +165 -0
- package/src/interpreter/utils.ts +105 -84
- package/src/tester/index.ts +157 -128
- package/src/utils/helpers.ts +113 -169
- package/tests/analyzer/functional.spec.ts +221 -207
- package/tests/analyzer/generic.spec.ts +178 -178
- package/tests/analyzer/helpers.spec.ts +83 -89
- package/tests/analyzer/logic.spec.ts +237 -237
- package/tests/analyzer/oop.spec.ts +320 -323
- package/tests/analyzer/transitive.spec.ts +166 -166
- package/tests/interpreter/EnvBuilder.spec.ts +181 -183
- package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
- package/tests/interpreter/LazyRuntime.spec.ts +227 -225
- package/tests/interpreter/LogicEngine.spec.ts +371 -327
- package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
- package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
- package/tests/interpreter/Operations.spec.ts +312 -220
- package/tests/interpreter/PatternSystem.spec.ts +254 -213
- package/tests/interpreter/Tests.spec.ts +122 -122
- package/tests/interpreter/interpreter.spec.ts +1143 -991
- package/tests/kernel/YukigoKernel.spec.ts +112 -0
- package/tests/tester/Tester.spec.ts +156 -152
- package/tsconfig.build.json +16 -15
- package/tsconfig.json +27 -25
- package/dist/interpreter/components/Visitor.d.ts +0 -70
- package/dist/interpreter/components/Visitor.js +0 -634
- package/dist/interpreter/entities.d.ts +0 -105
- package/dist/interpreter/entities.js +0 -96
- package/dist/interpreter/trampoline.d.ts +0 -17
- package/dist/interpreter/trampoline.js +0 -38
- package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
- package/dist/src/analyzer/GraphBuilder.js +0 -100
- package/dist/src/analyzer/index.d.ts +0 -59
- package/dist/src/analyzer/index.js +0 -152
- package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
- package/dist/src/analyzer/inspections/functional/functional.js +0 -149
- package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/functional/smells.js +0 -98
- package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
- package/dist/src/analyzer/inspections/generic/generic.js +0 -604
- package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
- package/dist/src/analyzer/inspections/generic/smells.js +0 -349
- package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
- package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
- package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
- package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
- package/dist/src/analyzer/inspections/logic/logic.js +0 -96
- package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
- package/dist/src/analyzer/inspections/logic/smells.js +0 -60
- package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
- package/dist/src/analyzer/inspections/object/object.js +0 -321
- package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
- package/dist/src/analyzer/inspections/object/smells.js +0 -135
- package/dist/src/analyzer/utils.d.ts +0 -30
- package/dist/src/analyzer/utils.js +0 -78
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
- package/dist/src/interpreter/components/EnvBuilder.js +0 -155
- package/dist/src/interpreter/components/Operations.d.ts +0 -14
- package/dist/src/interpreter/components/Operations.js +0 -84
- package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
- package/dist/src/interpreter/components/PatternMatcher.js +0 -358
- package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
- package/dist/src/interpreter/components/RuntimeContext.js +0 -93
- package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
- package/dist/src/interpreter/components/TestRunner.js +0 -110
- package/dist/src/interpreter/components/Visitor.d.ts +0 -71
- package/dist/src/interpreter/components/Visitor.js +0 -638
- package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
- package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
- package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
- package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
- package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
- package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
- package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
- package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
- package/dist/src/interpreter/errors.d.ts +0 -19
- package/dist/src/interpreter/errors.js +0 -36
- package/dist/src/interpreter/index.d.ts +0 -24
- package/dist/src/interpreter/index.js +0 -41
- package/dist/src/interpreter/trampoline.d.ts +0 -17
- package/dist/src/interpreter/trampoline.js +0 -38
- package/dist/src/interpreter/utils.d.ts +0 -11
- package/dist/src/interpreter/utils.js +0 -65
- package/dist/src/tester/index.d.ts +0 -25
- package/dist/src/tester/index.js +0 -113
- package/dist/src/utils/helpers.d.ts +0 -13
- package/dist/src/utils/helpers.js +0 -52
- package/src/interpreter/components/Visitor.ts +0 -1065
- package/src/interpreter/trampoline.ts +0 -71
|
@@ -1,101 +1,104 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Enumeration,
|
|
3
|
-
ForLoop,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new StopTraversalException();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
throw new StopTraversalException();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
1
|
+
import {
|
|
2
|
+
Enumeration,
|
|
3
|
+
ForLoop,
|
|
4
|
+
Procedure,
|
|
5
|
+
Repeat,
|
|
6
|
+
StopTraversalException,
|
|
7
|
+
Switch,
|
|
8
|
+
While,
|
|
9
|
+
} from "yukigo-ast";
|
|
10
|
+
import {
|
|
11
|
+
AutoScoped,
|
|
12
|
+
ScopedVisitor,
|
|
13
|
+
VisitorConstructor,
|
|
14
|
+
InspectionVisitor,
|
|
15
|
+
} from "../../utils.js";
|
|
16
|
+
|
|
17
|
+
export class DeclaresEnumeration extends InspectionVisitor {
|
|
18
|
+
private readonly enumName: string;
|
|
19
|
+
constructor(enumName: string) {
|
|
20
|
+
super();
|
|
21
|
+
this.enumName = enumName;
|
|
22
|
+
}
|
|
23
|
+
visitEnumeration(node: Enumeration): void {
|
|
24
|
+
if (node.identifier.value === this.enumName)
|
|
25
|
+
throw new StopTraversalException();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
@AutoScoped
|
|
29
|
+
export class DeclaresProcedure extends ScopedVisitor {
|
|
30
|
+
private readonly procedureName: string;
|
|
31
|
+
constructor(procedureName: string, scope?: string) {
|
|
32
|
+
super(scope);
|
|
33
|
+
this.procedureName = procedureName;
|
|
34
|
+
}
|
|
35
|
+
visitProcedure(node: Procedure): void {
|
|
36
|
+
if (node.identifier.value === this.procedureName)
|
|
37
|
+
throw new StopTraversalException();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@AutoScoped
|
|
42
|
+
export class UsesForLoop extends ScopedVisitor {
|
|
43
|
+
constructor(scope?: string) {
|
|
44
|
+
super(scope);
|
|
45
|
+
}
|
|
46
|
+
visitForLoop(node: ForLoop): void {
|
|
47
|
+
throw new StopTraversalException();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
@AutoScoped
|
|
51
|
+
export class UsesWhile extends ScopedVisitor {
|
|
52
|
+
constructor(scope?: string) {
|
|
53
|
+
super(scope);
|
|
54
|
+
}
|
|
55
|
+
visitWhile(node: While): void {
|
|
56
|
+
throw new StopTraversalException();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
@AutoScoped
|
|
60
|
+
export class UsesRepeat extends ScopedVisitor {
|
|
61
|
+
constructor(scope?: string) {
|
|
62
|
+
super(scope);
|
|
63
|
+
}
|
|
64
|
+
visitRepeat(node: Repeat): void {
|
|
65
|
+
throw new StopTraversalException();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
@AutoScoped
|
|
69
|
+
export class UsesLoop extends ScopedVisitor {
|
|
70
|
+
constructor(scope?: string) {
|
|
71
|
+
super(scope);
|
|
72
|
+
}
|
|
73
|
+
visitForLoop(node: ForLoop): void {
|
|
74
|
+
throw new StopTraversalException();
|
|
75
|
+
}
|
|
76
|
+
visitWhile(node: While): void {
|
|
77
|
+
throw new StopTraversalException();
|
|
78
|
+
}
|
|
79
|
+
visitRepeat(node: Repeat): void {
|
|
80
|
+
throw new StopTraversalException();
|
|
81
|
+
}
|
|
82
|
+
// visitForEach(node: ForEach): void {
|
|
83
|
+
// throw StopTraversalException;
|
|
84
|
+
// }
|
|
85
|
+
}
|
|
86
|
+
@AutoScoped
|
|
87
|
+
export class UsesSwitch extends ScopedVisitor {
|
|
88
|
+
constructor(scope?: string) {
|
|
89
|
+
super(scope);
|
|
90
|
+
}
|
|
91
|
+
visitSwitch(node: Switch): void {
|
|
92
|
+
throw new StopTraversalException();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const imperativeInspections: Record<string, VisitorConstructor> = {
|
|
97
|
+
DeclaresEnumeration: DeclaresEnumeration,
|
|
98
|
+
DeclaresProcedure: DeclaresProcedure,
|
|
99
|
+
UsesForLoop: UsesForLoop,
|
|
100
|
+
UsesRepeat: UsesRepeat,
|
|
101
|
+
UsesWhile: UsesWhile,
|
|
102
|
+
UsesLoop: UsesLoop,
|
|
103
|
+
UsesSwitch: UsesSwitch,
|
|
104
|
+
};
|
|
@@ -1,54 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Assignment,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
import {
|
|
2
|
+
Assignment,
|
|
3
|
+
Expression,
|
|
4
|
+
If,
|
|
5
|
+
NumberPrimitive,
|
|
6
|
+
Repeat,
|
|
7
|
+
Return,
|
|
8
|
+
Sequence,
|
|
9
|
+
StopTraversalException,
|
|
10
|
+
While,
|
|
11
|
+
} from "yukigo-ast";
|
|
12
|
+
import { AutoScoped, ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
13
|
+
|
|
14
|
+
@AutoScoped
|
|
15
|
+
export class HasAssignmentCondition extends ScopedVisitor {
|
|
16
|
+
visitIf(node: If): void {
|
|
17
|
+
if (this.isConditionAssignment(node.condition))
|
|
18
|
+
throw new StopTraversalException();
|
|
19
|
+
}
|
|
20
|
+
visitWhile(node: While): void {
|
|
21
|
+
if (this.isConditionAssignment(node.condition))
|
|
22
|
+
throw new StopTraversalException();
|
|
23
|
+
}
|
|
24
|
+
private isConditionAssignment(node: Expression) {
|
|
25
|
+
return node.is(Assignment);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@AutoScoped
|
|
30
|
+
export class HasAssignmentReturn extends ScopedVisitor {
|
|
31
|
+
visitReturn(node: Return): void {
|
|
32
|
+
if (node.body && node.body.is(Assignment))
|
|
33
|
+
throw new StopTraversalException();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@AutoScoped
|
|
38
|
+
export class HasEmptyRepeat extends ScopedVisitor {
|
|
39
|
+
visitRepeat(node: Repeat): void {
|
|
40
|
+
if (node.body.is(Sequence) && node.body.statements.length === 0)
|
|
41
|
+
throw new StopTraversalException();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@AutoScoped
|
|
46
|
+
export class HasRedundantRepeat extends ScopedVisitor {
|
|
47
|
+
visitRepeat(node: Repeat): void {
|
|
48
|
+
if (node.count.is(NumberPrimitive) && node.count.value === 1)
|
|
49
|
+
throw new StopTraversalException();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const imperativeSmells: Record<string, VisitorConstructor> = {
|
|
54
|
+
HasAssignmentCondition: HasAssignmentCondition,
|
|
55
|
+
HasAssignmentReturn: HasAssignmentReturn,
|
|
56
|
+
HasEmptyRepeat: HasEmptyRepeat,
|
|
57
|
+
HasRedundantRepeat: HasRedundantRepeat,
|
|
58
|
+
};
|
|
@@ -1,90 +1,84 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
HasFindall: UsesFindall,
|
|
86
|
-
UsesForall: UsesForall,
|
|
87
|
-
HasForall: UsesForall,
|
|
88
|
-
UsesNot: UsesNot,
|
|
89
|
-
HasNot: UsesNot,
|
|
90
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Exist,
|
|
3
|
+
Fact,
|
|
4
|
+
Findall,
|
|
5
|
+
Forall,
|
|
6
|
+
Not,
|
|
7
|
+
Rule,
|
|
8
|
+
StopTraversalException,
|
|
9
|
+
} from "yukigo-ast";
|
|
10
|
+
import { AutoScoped, ScopedVisitor, VisitorConstructor, InspectionVisitor } from "../../utils.js";
|
|
11
|
+
|
|
12
|
+
export class DeclaresFact extends InspectionVisitor {
|
|
13
|
+
constructor(private readonly target?: string) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
visitFact(node: Fact): void {
|
|
17
|
+
const bindingName = node.identifier.value;
|
|
18
|
+
if (!this.target || bindingName === this.target)
|
|
19
|
+
throw new StopTraversalException();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class DeclaresRule extends InspectionVisitor {
|
|
23
|
+
constructor(private readonly target?: string) {
|
|
24
|
+
super();
|
|
25
|
+
}
|
|
26
|
+
visitRule(node: Rule): void {
|
|
27
|
+
const bindingName = node.identifier.value;
|
|
28
|
+
if (!this.target || bindingName === this.target)
|
|
29
|
+
throw new StopTraversalException();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class DeclaresPredicate extends InspectionVisitor {
|
|
33
|
+
constructor(private readonly target?: string) {
|
|
34
|
+
super();
|
|
35
|
+
}
|
|
36
|
+
visitFact(node: Fact): void {
|
|
37
|
+
new DeclaresFact(this.target).visitFact(node);
|
|
38
|
+
}
|
|
39
|
+
visitRule(node: Rule): void {
|
|
40
|
+
new DeclaresRule(this.target).visitRule(node);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
@AutoScoped
|
|
44
|
+
export class UsesFindall extends ScopedVisitor {
|
|
45
|
+
constructor(scope?: string) {
|
|
46
|
+
super(scope);
|
|
47
|
+
}
|
|
48
|
+
visitFindall(node: Findall): void {
|
|
49
|
+
throw new StopTraversalException();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
@AutoScoped
|
|
53
|
+
export class UsesForall extends ScopedVisitor {
|
|
54
|
+
constructor(scope?: string) {
|
|
55
|
+
super(scope);
|
|
56
|
+
}
|
|
57
|
+
visitForall(node: Forall): void {
|
|
58
|
+
throw new StopTraversalException();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
@AutoScoped
|
|
62
|
+
export class UsesNot extends ScopedVisitor {
|
|
63
|
+
constructor(scope?: string) {
|
|
64
|
+
super(scope);
|
|
65
|
+
}
|
|
66
|
+
visitNot(node: Not): void {
|
|
67
|
+
throw new StopTraversalException();
|
|
68
|
+
}
|
|
69
|
+
visitExist(node: Exist): void {
|
|
70
|
+
if (node.identifier.value === "not") throw new StopTraversalException();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const logicInspections: Record<string, VisitorConstructor> = {
|
|
75
|
+
DeclaresFact: DeclaresFact,
|
|
76
|
+
DeclaresRule: DeclaresRule,
|
|
77
|
+
DeclaresPredicate: DeclaresPredicate,
|
|
78
|
+
UsesFindall: UsesFindall,
|
|
79
|
+
HasFindall: UsesFindall,
|
|
80
|
+
UsesForall: UsesForall,
|
|
81
|
+
HasForall: UsesForall,
|
|
82
|
+
UsesNot: UsesNot,
|
|
83
|
+
HasNot: UsesNot,
|
|
84
|
+
};
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssignOperation,
|
|
3
|
-
Exist,
|
|
4
|
-
isYukigoPrimitive,
|
|
5
|
-
Rule,
|
|
6
|
-
StopTraversalException,
|
|
7
|
-
SymbolPrimitive,
|
|
8
|
-
UnifyOperation,
|
|
9
|
-
} from "yukigo-ast";
|
|
10
|
-
import { AutoScoped, ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
11
|
-
|
|
12
|
-
@AutoScoped
|
|
13
|
-
export class HasRedundantReduction extends ScopedVisitor {
|
|
14
|
-
visitAssignOperation(node: AssignOperation): void {
|
|
15
|
-
const left = node.left;
|
|
16
|
-
const right = node.right;
|
|
17
|
-
|
|
18
|
-
if (!(
|
|
19
|
-
|
|
20
|
-
const redundantReductionParameters = isYukigoPrimitive(right);
|
|
21
|
-
const redundantReductionFunctors = right
|
|
22
|
-
|
|
23
|
-
const isRedundant =
|
|
24
|
-
redundantReductionParameters || redundantReductionFunctors;
|
|
25
|
-
|
|
26
|
-
if (isRedundant) throw new StopTraversalException();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@AutoScoped
|
|
31
|
-
export class UsesUnificationOperator extends ScopedVisitor {
|
|
32
|
-
visitUnifyOperation(node: UnifyOperation): void {
|
|
33
|
-
throw new StopTraversalException();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
@AutoScoped
|
|
37
|
-
export class UsesCut extends ScopedVisitor {
|
|
38
|
-
visitExist(node: Exist): void {
|
|
39
|
-
if (node.identifier.value === "!") throw new StopTraversalException();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
@AutoScoped
|
|
43
|
-
export class UsesFail extends ScopedVisitor {
|
|
44
|
-
visitExist(node: Exist): void {
|
|
45
|
-
if (node.identifier.value === "fail") throw new StopTraversalException();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const logicSmells: Record<string, VisitorConstructor> = {
|
|
50
|
-
HasRedundantReduction: HasRedundantReduction,
|
|
51
|
-
UsesCut: UsesCut,
|
|
52
|
-
UsesFail: UsesFail,
|
|
53
|
-
UsesUnificationOperator: UsesUnificationOperator,
|
|
54
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
AssignOperation,
|
|
3
|
+
Exist,
|
|
4
|
+
isYukigoPrimitive,
|
|
5
|
+
Rule,
|
|
6
|
+
StopTraversalException,
|
|
7
|
+
SymbolPrimitive,
|
|
8
|
+
UnifyOperation,
|
|
9
|
+
} from "yukigo-ast";
|
|
10
|
+
import { AutoScoped, ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
11
|
+
|
|
12
|
+
@AutoScoped
|
|
13
|
+
export class HasRedundantReduction extends ScopedVisitor {
|
|
14
|
+
visitAssignOperation(node: AssignOperation): void {
|
|
15
|
+
const left = node.left;
|
|
16
|
+
const right = node.right;
|
|
17
|
+
|
|
18
|
+
if (!left.is(SymbolPrimitive)) return;
|
|
19
|
+
|
|
20
|
+
const redundantReductionParameters = isYukigoPrimitive(right);
|
|
21
|
+
const redundantReductionFunctors = right.is(Exist);
|
|
22
|
+
|
|
23
|
+
const isRedundant =
|
|
24
|
+
redundantReductionParameters || redundantReductionFunctors;
|
|
25
|
+
|
|
26
|
+
if (isRedundant) throw new StopTraversalException();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@AutoScoped
|
|
31
|
+
export class UsesUnificationOperator extends ScopedVisitor {
|
|
32
|
+
visitUnifyOperation(node: UnifyOperation): void {
|
|
33
|
+
throw new StopTraversalException();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
@AutoScoped
|
|
37
|
+
export class UsesCut extends ScopedVisitor {
|
|
38
|
+
visitExist(node: Exist): void {
|
|
39
|
+
if (node.identifier.value === "!") throw new StopTraversalException();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
@AutoScoped
|
|
43
|
+
export class UsesFail extends ScopedVisitor {
|
|
44
|
+
visitExist(node: Exist): void {
|
|
45
|
+
if (node.identifier.value === "fail") throw new StopTraversalException();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const logicSmells: Record<string, VisitorConstructor> = {
|
|
50
|
+
HasRedundantReduction: HasRedundantReduction,
|
|
51
|
+
UsesCut: UsesCut,
|
|
52
|
+
UsesFail: UsesFail,
|
|
53
|
+
UsesUnificationOperator: UsesUnificationOperator,
|
|
54
|
+
};
|