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
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { BooleanPrimitive, Call, Function, NilPrimitive, Return, Sequence, StopTraversalException, SymbolPrimitive, Variable, } from "yukigo-ast";
|
|
8
8
|
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
9
9
|
function isSequenceEmpty(node) {
|
|
10
|
-
return node
|
|
10
|
+
return node.is(Sequence) && node.statements.length === 0;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Basic Levenshtein distance for typo detection
|
|
@@ -32,9 +32,8 @@ function getLevenshteinDistance(a, b) {
|
|
|
32
32
|
}
|
|
33
33
|
let DiscardsExceptions = class DiscardsExceptions extends ScopedVisitor {
|
|
34
34
|
visitCatch(node) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
isSequenceEmpty(node.body)) {
|
|
35
|
+
const doesNotCatch = !node.body || node.body.is(NilPrimitive) || isSequenceEmpty(node.body);
|
|
36
|
+
if (doesNotCatch) {
|
|
38
37
|
throw new StopTraversalException();
|
|
39
38
|
}
|
|
40
39
|
}
|
|
@@ -54,7 +53,7 @@ let DoesConsolePrint = class DoesConsolePrint extends ScopedVisitor {
|
|
|
54
53
|
}
|
|
55
54
|
visitApplication(node) {
|
|
56
55
|
const func = node.functionExpr;
|
|
57
|
-
if (!(
|
|
56
|
+
if (!func.is(SymbolPrimitive))
|
|
58
57
|
return func.accept(this);
|
|
59
58
|
const name = func.value;
|
|
60
59
|
if (this.isPrintFunc(name))
|
|
@@ -85,22 +84,18 @@ let HasDeclarationTypos = class HasDeclarationTypos extends ScopedVisitor {
|
|
|
85
84
|
* (Levenshtein distance <= 2), indicating a possible typo (e.g., 'count' vs 'conut').
|
|
86
85
|
*/
|
|
87
86
|
visitSequence(node) {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
87
|
+
const names = node.statements
|
|
88
|
+
.filter((stmt) => stmt.is(Variable))
|
|
89
|
+
.map((stmt) => stmt.identifier.value);
|
|
90
|
+
names.forEach((nameA, i) => {
|
|
91
|
+
const hasTypo = names.slice(i + 1).some((nameB) => {
|
|
92
|
+
if (nameA.length <= 3 || nameB.length <= 3)
|
|
93
|
+
return false;
|
|
94
|
+
return getLevenshteinDistance(nameA, nameB) <= 2;
|
|
95
|
+
});
|
|
96
|
+
if (hasTypo)
|
|
97
|
+
throw new StopTraversalException();
|
|
98
|
+
});
|
|
104
99
|
}
|
|
105
100
|
};
|
|
106
101
|
HasDeclarationTypos = __decorate([
|
|
@@ -110,7 +105,7 @@ export { HasDeclarationTypos };
|
|
|
110
105
|
let HasEmptyIfBranches = class HasEmptyIfBranches extends ScopedVisitor {
|
|
111
106
|
visitIf(node) {
|
|
112
107
|
const isThenEmpty = !node.then || isSequenceEmpty(node.then);
|
|
113
|
-
const isElseEmpty =
|
|
108
|
+
const isElseEmpty = isSequenceEmpty(node.elseExpr);
|
|
114
109
|
if (isThenEmpty || isElseEmpty)
|
|
115
110
|
throw new StopTraversalException();
|
|
116
111
|
}
|
|
@@ -166,8 +161,8 @@ HasMisspelledIdentifiers = __decorate([
|
|
|
166
161
|
export { HasMisspelledIdentifiers };
|
|
167
162
|
let HasRedundantBooleanComparison = class HasRedundantBooleanComparison extends ScopedVisitor {
|
|
168
163
|
visitLogicalBinaryOperation(node) {
|
|
169
|
-
const isLeftBool = node.left
|
|
170
|
-
const isRightBool = node.right
|
|
164
|
+
const isLeftBool = node.left.is(BooleanPrimitive);
|
|
165
|
+
const isRightBool = node.right.is(BooleanPrimitive);
|
|
171
166
|
if (isLeftBool || isRightBool)
|
|
172
167
|
throw new StopTraversalException();
|
|
173
168
|
}
|
|
@@ -178,17 +173,14 @@ HasRedundantBooleanComparison = __decorate([
|
|
|
178
173
|
export { HasRedundantBooleanComparison };
|
|
179
174
|
let HasRedundantIf = class HasRedundantIf extends ScopedVisitor {
|
|
180
175
|
visitIf(node) {
|
|
181
|
-
if (node.elseExpr)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
176
|
+
if (!node.elseExpr)
|
|
177
|
+
return;
|
|
178
|
+
const { then, elseExpr } = node;
|
|
179
|
+
if (this.isBooleanBlock(then) && this.isBooleanBlock(elseExpr))
|
|
180
|
+
throw new StopTraversalException();
|
|
181
|
+
}
|
|
182
|
+
isBooleanBlock(node) {
|
|
183
|
+
return (node.is(Sequence) && node.statements.some((s) => s.is(BooleanPrimitive)));
|
|
192
184
|
}
|
|
193
185
|
};
|
|
194
186
|
HasRedundantIf = __decorate([
|
|
@@ -203,16 +195,21 @@ let HasRedundantLocalVariableReturn = class HasRedundantLocalVariableReturn exte
|
|
|
203
195
|
*/
|
|
204
196
|
visitSequence(node) {
|
|
205
197
|
const stmts = node.statements;
|
|
206
|
-
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
throw new StopTraversalException();
|
|
213
|
-
}
|
|
198
|
+
stmts.forEach((stmt, i) => {
|
|
199
|
+
const next = stmts[i + 1];
|
|
200
|
+
if (!next)
|
|
201
|
+
return;
|
|
202
|
+
if (this.isPointlessAssignment(stmt, next)) {
|
|
203
|
+
throw new StopTraversalException();
|
|
214
204
|
}
|
|
215
|
-
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
isPointlessAssignment(current, next) {
|
|
208
|
+
return (current.is(Variable) &&
|
|
209
|
+
next.is(Return) &&
|
|
210
|
+
next.body !== undefined &&
|
|
211
|
+
next.body.is(SymbolPrimitive) &&
|
|
212
|
+
next.body.value === current.identifier.value);
|
|
216
213
|
}
|
|
217
214
|
};
|
|
218
215
|
HasRedundantLocalVariableReturn = __decorate([
|
|
@@ -240,26 +237,20 @@ HasTooShortIdentifiers = __decorate([
|
|
|
240
237
|
export { HasTooShortIdentifiers };
|
|
241
238
|
let HasUsageTypos = class HasUsageTypos extends ScopedVisitor {
|
|
242
239
|
visitSequence(node) {
|
|
243
|
-
const
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (usage.length > 3 && getLevenshteinDistance(usage, decl) <= 1) {
|
|
258
|
-
throw new StopTraversalException();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
240
|
+
const { statements } = node;
|
|
241
|
+
const declared = new Set(statements
|
|
242
|
+
.filter((stmt) => stmt.is(Function) || stmt.is(Variable))
|
|
243
|
+
.map((stmt) => stmt.identifier.value));
|
|
244
|
+
const called = statements
|
|
245
|
+
.filter((stmt) => stmt.is(Call))
|
|
246
|
+
.map((stmt) => stmt.callee.value);
|
|
247
|
+
const hasTypo = called.some((usage) => {
|
|
248
|
+
if (declared.has(usage) || usage.length <= 3)
|
|
249
|
+
return false;
|
|
250
|
+
return Array.from(declared).some((decl) => getLevenshteinDistance(usage, decl) <= 1);
|
|
251
|
+
});
|
|
252
|
+
if (hasTypo)
|
|
253
|
+
throw new StopTraversalException();
|
|
263
254
|
}
|
|
264
255
|
};
|
|
265
256
|
HasUsageTypos = __decorate([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Enumeration, ForLoop, Procedure, Repeat, Switch,
|
|
2
|
-
import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
3
|
-
export declare class DeclaresEnumeration extends
|
|
1
|
+
import { Enumeration, ForLoop, Procedure, Repeat, Switch, While } from "yukigo-ast";
|
|
2
|
+
import { ScopedVisitor, VisitorConstructor, InspectionVisitor } from "../../utils.js";
|
|
3
|
+
export declare class DeclaresEnumeration extends InspectionVisitor {
|
|
4
4
|
private readonly enumName;
|
|
5
5
|
constructor(enumName: string);
|
|
6
6
|
visitEnumeration(node: Enumeration): void;
|
|
@@ -4,9 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { StopTraversalException,
|
|
8
|
-
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
9
|
-
export class DeclaresEnumeration extends
|
|
7
|
+
import { StopTraversalException, } from "yukigo-ast";
|
|
8
|
+
import { AutoScoped, ScopedVisitor, InspectionVisitor, } from "../../utils.js";
|
|
9
|
+
export class DeclaresEnumeration extends InspectionVisitor {
|
|
10
10
|
enumName;
|
|
11
11
|
constructor(enumName) {
|
|
12
12
|
super();
|
|
@@ -3,6 +3,7 @@ import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
|
3
3
|
export declare class HasAssignmentCondition extends ScopedVisitor {
|
|
4
4
|
visitIf(node: If): void;
|
|
5
5
|
visitWhile(node: While): void;
|
|
6
|
+
private isConditionAssignment;
|
|
6
7
|
}
|
|
7
8
|
export declare class HasAssignmentReturn extends ScopedVisitor {
|
|
8
9
|
visitReturn(node: Return): void;
|
|
@@ -8,13 +8,16 @@ import { Assignment, NumberPrimitive, Sequence, StopTraversalException, } from "
|
|
|
8
8
|
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
9
9
|
let HasAssignmentCondition = class HasAssignmentCondition extends ScopedVisitor {
|
|
10
10
|
visitIf(node) {
|
|
11
|
-
if (node.condition
|
|
11
|
+
if (this.isConditionAssignment(node.condition))
|
|
12
12
|
throw new StopTraversalException();
|
|
13
13
|
}
|
|
14
14
|
visitWhile(node) {
|
|
15
|
-
if (node.condition
|
|
15
|
+
if (this.isConditionAssignment(node.condition))
|
|
16
16
|
throw new StopTraversalException();
|
|
17
17
|
}
|
|
18
|
+
isConditionAssignment(node) {
|
|
19
|
+
return node.is(Assignment);
|
|
20
|
+
}
|
|
18
21
|
};
|
|
19
22
|
HasAssignmentCondition = __decorate([
|
|
20
23
|
AutoScoped
|
|
@@ -22,7 +25,7 @@ HasAssignmentCondition = __decorate([
|
|
|
22
25
|
export { HasAssignmentCondition };
|
|
23
26
|
let HasAssignmentReturn = class HasAssignmentReturn extends ScopedVisitor {
|
|
24
27
|
visitReturn(node) {
|
|
25
|
-
if (node.body && node.body
|
|
28
|
+
if (node.body && node.body.is(Assignment))
|
|
26
29
|
throw new StopTraversalException();
|
|
27
30
|
}
|
|
28
31
|
};
|
|
@@ -32,7 +35,7 @@ HasAssignmentReturn = __decorate([
|
|
|
32
35
|
export { HasAssignmentReturn };
|
|
33
36
|
let HasEmptyRepeat = class HasEmptyRepeat extends ScopedVisitor {
|
|
34
37
|
visitRepeat(node) {
|
|
35
|
-
if (node.body
|
|
38
|
+
if (node.body.is(Sequence) && node.body.statements.length === 0)
|
|
36
39
|
throw new StopTraversalException();
|
|
37
40
|
}
|
|
38
41
|
};
|
|
@@ -42,7 +45,7 @@ HasEmptyRepeat = __decorate([
|
|
|
42
45
|
export { HasEmptyRepeat };
|
|
43
46
|
let HasRedundantRepeat = class HasRedundantRepeat extends ScopedVisitor {
|
|
44
47
|
visitRepeat(node) {
|
|
45
|
-
if (node.count
|
|
48
|
+
if (node.count.is(NumberPrimitive) && node.count.value === 1)
|
|
46
49
|
throw new StopTraversalException();
|
|
47
50
|
}
|
|
48
51
|
};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { Exist, Fact, Findall, Forall, Not, Rule
|
|
2
|
-
import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
3
|
-
export declare class DeclaresFact extends
|
|
1
|
+
import { Exist, Fact, Findall, Forall, Not, Rule } from "yukigo-ast";
|
|
2
|
+
import { ScopedVisitor, VisitorConstructor, InspectionVisitor } from "../../utils.js";
|
|
3
|
+
export declare class DeclaresFact extends InspectionVisitor {
|
|
4
4
|
private readonly target?;
|
|
5
|
-
constructor(target?: string);
|
|
5
|
+
constructor(target?: string | undefined);
|
|
6
6
|
visitFact(node: Fact): void;
|
|
7
7
|
}
|
|
8
|
-
export declare class DeclaresRule extends
|
|
8
|
+
export declare class DeclaresRule extends InspectionVisitor {
|
|
9
9
|
private readonly target?;
|
|
10
|
-
constructor(target?: string);
|
|
10
|
+
constructor(target?: string | undefined);
|
|
11
11
|
visitRule(node: Rule): void;
|
|
12
12
|
}
|
|
13
|
-
export declare class DeclaresPredicate extends
|
|
13
|
+
export declare class DeclaresPredicate extends InspectionVisitor {
|
|
14
14
|
private readonly target?;
|
|
15
|
-
constructor(target?: string);
|
|
15
|
+
constructor(target?: string | undefined);
|
|
16
16
|
visitFact(node: Fact): void;
|
|
17
17
|
visitRule(node: Rule): void;
|
|
18
18
|
}
|
|
@@ -4,9 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { StopTraversalException,
|
|
8
|
-
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
9
|
-
export class DeclaresFact extends
|
|
7
|
+
import { StopTraversalException, } from "yukigo-ast";
|
|
8
|
+
import { AutoScoped, ScopedVisitor, InspectionVisitor } from "../../utils.js";
|
|
9
|
+
export class DeclaresFact extends InspectionVisitor {
|
|
10
10
|
target;
|
|
11
11
|
constructor(target) {
|
|
12
12
|
super();
|
|
@@ -18,7 +18,7 @@ export class DeclaresFact extends TraverseVisitor {
|
|
|
18
18
|
throw new StopTraversalException();
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
export class DeclaresRule extends
|
|
21
|
+
export class DeclaresRule extends InspectionVisitor {
|
|
22
22
|
target;
|
|
23
23
|
constructor(target) {
|
|
24
24
|
super();
|
|
@@ -30,7 +30,7 @@ export class DeclaresRule extends TraverseVisitor {
|
|
|
30
30
|
throw new StopTraversalException();
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
export class DeclaresPredicate extends
|
|
33
|
+
export class DeclaresPredicate extends InspectionVisitor {
|
|
34
34
|
target;
|
|
35
35
|
constructor(target) {
|
|
36
36
|
super();
|
|
@@ -10,10 +10,10 @@ let HasRedundantReduction = class HasRedundantReduction extends ScopedVisitor {
|
|
|
10
10
|
visitAssignOperation(node) {
|
|
11
11
|
const left = node.left;
|
|
12
12
|
const right = node.right;
|
|
13
|
-
if (!(
|
|
13
|
+
if (!left.is(SymbolPrimitive))
|
|
14
14
|
return;
|
|
15
15
|
const redundantReductionParameters = isYukigoPrimitive(right);
|
|
16
|
-
const redundantReductionFunctors = right
|
|
16
|
+
const redundantReductionFunctors = right.is(Exist);
|
|
17
17
|
const isRedundant = redundantReductionParameters || redundantReductionFunctors;
|
|
18
18
|
if (isRedundant)
|
|
19
19
|
throw new StopTraversalException();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Attribute, Class, Interface, Method, New, Object, PrimitiveMethod, Send
|
|
2
|
-
import { ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
1
|
+
import { Attribute, Class, Interface, Method, New, Object, PrimitiveMethod, Send } from "yukigo-ast";
|
|
2
|
+
import { InspectionVisitor, ScopedVisitor, VisitorConstructor } from "../../utils.js";
|
|
3
3
|
export declare class DeclaresAttribute extends ScopedVisitor {
|
|
4
4
|
private attributeName;
|
|
5
5
|
constructor(attributeName: string, scope?: string);
|
|
@@ -10,7 +10,7 @@ export declare class DeclaresClass extends ScopedVisitor {
|
|
|
10
10
|
constructor(className: string, scope?: string);
|
|
11
11
|
visitClass(node: Class): void;
|
|
12
12
|
}
|
|
13
|
-
export declare class DeclaresInterface extends
|
|
13
|
+
export declare class DeclaresInterface extends InspectionVisitor {
|
|
14
14
|
private interfaceName;
|
|
15
15
|
constructor(interfaceName: string);
|
|
16
16
|
visitInterface(node: Interface): void;
|
|
@@ -20,7 +20,7 @@ export declare class DeclaresMethod extends ScopedVisitor {
|
|
|
20
20
|
constructor(methodName: string, scope?: string);
|
|
21
21
|
visitMethod(node: Method): void;
|
|
22
22
|
}
|
|
23
|
-
export declare class DeclaresObject extends
|
|
23
|
+
export declare class DeclaresObject extends InspectionVisitor {
|
|
24
24
|
private objectName;
|
|
25
25
|
constructor(objectName: string);
|
|
26
26
|
visitObject(node: Object): void;
|
|
@@ -69,7 +69,7 @@ export declare class UsesObjectComposition extends ScopedVisitor {
|
|
|
69
69
|
constructor(scope?: string);
|
|
70
70
|
visitAttribute(node: Attribute): void;
|
|
71
71
|
}
|
|
72
|
-
export declare class UsesStaticMethodOverload extends
|
|
72
|
+
export declare class UsesStaticMethodOverload extends InspectionVisitor {
|
|
73
73
|
private scopes;
|
|
74
74
|
visitClass(node: Class): void;
|
|
75
75
|
visitObject(node: Object): void;
|
|
@@ -4,8 +4,8 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { New, Self, StopTraversalException, SymbolPrimitive,
|
|
8
|
-
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
7
|
+
import { New, Self, StopTraversalException, SymbolPrimitive, } from "yukigo-ast";
|
|
8
|
+
import { AutoScoped, InspectionVisitor, ScopedVisitor, } from "../../utils.js";
|
|
9
9
|
let DeclaresAttribute = class DeclaresAttribute extends ScopedVisitor {
|
|
10
10
|
attributeName;
|
|
11
11
|
constructor(attributeName, scope) {
|
|
@@ -36,7 +36,7 @@ DeclaresClass = __decorate([
|
|
|
36
36
|
AutoScoped
|
|
37
37
|
], DeclaresClass);
|
|
38
38
|
export { DeclaresClass };
|
|
39
|
-
export class DeclaresInterface extends
|
|
39
|
+
export class DeclaresInterface extends InspectionVisitor {
|
|
40
40
|
interfaceName;
|
|
41
41
|
constructor(interfaceName) {
|
|
42
42
|
super();
|
|
@@ -62,7 +62,7 @@ DeclaresMethod = __decorate([
|
|
|
62
62
|
AutoScoped
|
|
63
63
|
], DeclaresMethod);
|
|
64
64
|
export { DeclaresMethod };
|
|
65
|
-
export class DeclaresObject extends
|
|
65
|
+
export class DeclaresObject extends InspectionVisitor {
|
|
66
66
|
objectName;
|
|
67
67
|
constructor(objectName) {
|
|
68
68
|
super();
|
|
@@ -110,8 +110,9 @@ let Implements = class Implements extends ScopedVisitor {
|
|
|
110
110
|
this.interfaceName = interfaceName;
|
|
111
111
|
}
|
|
112
112
|
visitClass(node) {
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
const { implementsNode } = node;
|
|
114
|
+
if (implementsNode &&
|
|
115
|
+
implementsNode.identifier.value === this.interfaceName)
|
|
115
116
|
throw new StopTraversalException();
|
|
116
117
|
}
|
|
117
118
|
};
|
|
@@ -203,7 +204,7 @@ let UsesObjectComposition = class UsesObjectComposition extends ScopedVisitor {
|
|
|
203
204
|
super(scope);
|
|
204
205
|
}
|
|
205
206
|
visitAttribute(node) {
|
|
206
|
-
if (node.expression
|
|
207
|
+
if (node.expression.is(New))
|
|
207
208
|
throw new StopTraversalException();
|
|
208
209
|
}
|
|
209
210
|
};
|
|
@@ -211,7 +212,7 @@ UsesObjectComposition = __decorate([
|
|
|
211
212
|
AutoScoped
|
|
212
213
|
], UsesObjectComposition);
|
|
213
214
|
export { UsesObjectComposition };
|
|
214
|
-
export class UsesStaticMethodOverload extends
|
|
215
|
+
export class UsesStaticMethodOverload extends InspectionVisitor {
|
|
215
216
|
scopes = [];
|
|
216
217
|
visitClass(node) {
|
|
217
218
|
this.scopes.push(new Set());
|
|
@@ -250,7 +251,7 @@ let AbstractMethodCollector = class AbstractMethodCollector extends ScopedVisito
|
|
|
250
251
|
super(scope);
|
|
251
252
|
}
|
|
252
253
|
visitMethod(node) {
|
|
253
|
-
if (node.
|
|
254
|
+
if (node.isAbstract)
|
|
254
255
|
this.abstractMethods.add(node.identifier.value);
|
|
255
256
|
}
|
|
256
257
|
// stop propagation to not mix scopes
|
|
@@ -278,18 +279,18 @@ let UsesTemplateMethod = class UsesTemplateMethod extends ScopedVisitor {
|
|
|
278
279
|
this.abstractMethodsStack.pop();
|
|
279
280
|
}
|
|
280
281
|
visitSend(node) {
|
|
281
|
-
if (node.receiver
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
282
|
+
if (!node.receiver.is(Self))
|
|
283
|
+
return;
|
|
284
|
+
if (this.abstractMethodsStack.length === 0)
|
|
285
|
+
return;
|
|
286
|
+
const currentAbstractMethods = this.abstractMethodsStack[0];
|
|
287
|
+
// This doesnt match if message is complex expression
|
|
288
|
+
if (!node.selector.is(SymbolPrimitive))
|
|
289
|
+
return;
|
|
290
|
+
const selectorName = node.selector.value;
|
|
291
|
+
const isMessageAbstract = currentAbstractMethods.has(selectorName);
|
|
292
|
+
if (isMessageAbstract)
|
|
293
|
+
throw new StopTraversalException();
|
|
293
294
|
}
|
|
294
295
|
};
|
|
295
296
|
UsesTemplateMethod = __decorate([
|
|
@@ -4,10 +4,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { NilPrimitive, StopTraversalException, StringPrimitive,
|
|
8
|
-
import { AutoScoped, ScopedVisitor } from "../../utils.js";
|
|
7
|
+
import { NilPrimitive, StopTraversalException, StringPrimitive, } from "yukigo-ast";
|
|
8
|
+
import { AutoScoped, InspectionVisitor, ScopedVisitor, } from "../../utils.js";
|
|
9
9
|
import { Uses } from "../generic/generic.js";
|
|
10
|
-
class MethodCollector extends
|
|
10
|
+
class MethodCollector extends InspectionVisitor {
|
|
11
11
|
collectedMethods = [];
|
|
12
12
|
collect(node) {
|
|
13
13
|
node.expression.accept(this);
|
|
@@ -19,10 +19,8 @@ class MethodCollector extends TraverseVisitor {
|
|
|
19
19
|
}
|
|
20
20
|
let DoesNilTest = class DoesNilTest extends ScopedVisitor {
|
|
21
21
|
visitLogicalBinaryOperation(node) {
|
|
22
|
-
if (node.left
|
|
23
|
-
node.right instanceof NilPrimitive) {
|
|
22
|
+
if (node.left.is(NilPrimitive) || node.right.is(NilPrimitive))
|
|
24
23
|
throw new StopTraversalException();
|
|
25
|
-
}
|
|
26
24
|
}
|
|
27
25
|
};
|
|
28
26
|
DoesNilTest = __decorate([
|
|
@@ -31,8 +29,7 @@ DoesNilTest = __decorate([
|
|
|
31
29
|
export { DoesNilTest };
|
|
32
30
|
let DoesTypeTest = class DoesTypeTest extends ScopedVisitor {
|
|
33
31
|
visitLogicalBinaryOperation(node) {
|
|
34
|
-
if (node.left
|
|
35
|
-
node.right instanceof StringPrimitive) {
|
|
32
|
+
if (node.left.is(StringPrimitive) || node.right.is(StringPrimitive)) {
|
|
36
33
|
throw new StopTraversalException();
|
|
37
34
|
}
|
|
38
35
|
}
|
|
@@ -43,7 +40,7 @@ DoesTypeTest = __decorate([
|
|
|
43
40
|
export { DoesTypeTest };
|
|
44
41
|
let ReturnsNil = class ReturnsNil extends ScopedVisitor {
|
|
45
42
|
visitReturn(node) {
|
|
46
|
-
if (!
|
|
43
|
+
if (!node.body || node.body.is(NilPrimitive))
|
|
47
44
|
throw new StopTraversalException();
|
|
48
45
|
}
|
|
49
46
|
};
|
|
@@ -52,7 +49,7 @@ ReturnsNil = __decorate([
|
|
|
52
49
|
], ReturnsNil);
|
|
53
50
|
export { ReturnsNil };
|
|
54
51
|
let HasTooManyMethods = class HasTooManyMethods extends ScopedVisitor {
|
|
55
|
-
counter;
|
|
52
|
+
counter = 0;
|
|
56
53
|
maxMethods;
|
|
57
54
|
constructor(maxMethods = 10, scopeName) {
|
|
58
55
|
super(scopeName);
|
|
@@ -90,11 +87,9 @@ let OverridesEqualOrHashButNotBoth = class OverridesEqualOrHashButNotBoth extend
|
|
|
90
87
|
const collector = new MethodCollector();
|
|
91
88
|
const methods = collector.collect(node);
|
|
92
89
|
const names = methods.map((m) => m.identifier.value);
|
|
93
|
-
const hasEquals = names.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const hasHash = names.includes("hashCode") || names.includes("hash");
|
|
97
|
-
if ((hasEquals && !hasHash) || (!hasEquals && hasHash))
|
|
90
|
+
const hasEquals = names.some((n) => ["equals", "==", "eql?"].includes(n));
|
|
91
|
+
const hasHash = names.some((n) => ["hashCode", "hash"].includes(n));
|
|
92
|
+
if (hasEquals !== hasHash)
|
|
98
93
|
throw new StopTraversalException();
|
|
99
94
|
}
|
|
100
95
|
};
|
|
@@ -111,14 +106,7 @@ let UsesNamedSelfReference = class UsesNamedSelfReference extends ScopedVisitor
|
|
|
111
106
|
}
|
|
112
107
|
checkSelfReference(selfName, body) {
|
|
113
108
|
const checker = new Uses(selfName, this.binding);
|
|
114
|
-
|
|
115
|
-
body.accept(checker);
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
if (e instanceof StopTraversalException)
|
|
119
|
-
throw new StopTraversalException();
|
|
120
|
-
throw e;
|
|
121
|
-
}
|
|
109
|
+
body.accept(checker);
|
|
122
110
|
}
|
|
123
111
|
};
|
|
124
112
|
UsesNamedSelfReference = __decorate([
|
package/dist/analyzer/utils.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Class, Fact, Function, Method, Object as YuObject, Procedure, Rule, TraverseVisitor, Variable } from "yukigo-ast";
|
|
1
|
+
import { Class, Fact, Function, Method, Object as YuObject, Procedure, Rule, TraverseVisitor, Variable, ASTNode } from "yukigo-ast";
|
|
2
|
+
export declare class InspectionVisitor extends TraverseVisitor {
|
|
3
|
+
fallback(node: ASTNode): void;
|
|
4
|
+
}
|
|
2
5
|
export interface VisitorConstructor {
|
|
3
6
|
new (...args: any[]): TraverseVisitor & {
|
|
4
7
|
setBinding?(binding: string): void;
|
|
@@ -6,7 +9,7 @@ export interface VisitorConstructor {
|
|
|
6
9
|
IS_INTRANSITIVE?: boolean;
|
|
7
10
|
}
|
|
8
11
|
export type InspectionMap = Record<string, VisitorConstructor>;
|
|
9
|
-
export declare class ScopedVisitor extends
|
|
12
|
+
export declare class ScopedVisitor extends InspectionVisitor {
|
|
10
13
|
protected binding?: string;
|
|
11
14
|
inScope: boolean;
|
|
12
15
|
constructor(binding?: string);
|
|
@@ -19,6 +22,7 @@ export declare class ScopedVisitor extends TraverseVisitor {
|
|
|
19
22
|
visitRule(node: Rule): void;
|
|
20
23
|
visitFact(node: Fact): void;
|
|
21
24
|
visitProcedure(node: Procedure): void;
|
|
25
|
+
fallback(node: ASTNode): void;
|
|
22
26
|
private manageScope;
|
|
23
27
|
}
|
|
24
28
|
export declare function AutoScoped<T extends {
|
package/dist/analyzer/utils.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { TraverseVisitor, } from "yukigo-ast";
|
|
2
|
-
export class
|
|
2
|
+
export class InspectionVisitor extends TraverseVisitor {
|
|
3
|
+
fallback(node) { }
|
|
4
|
+
}
|
|
5
|
+
export class ScopedVisitor extends InspectionVisitor {
|
|
3
6
|
binding;
|
|
4
|
-
inScope;
|
|
7
|
+
inScope = false;
|
|
5
8
|
constructor(binding) {
|
|
6
9
|
super();
|
|
7
10
|
this.setBinding(binding);
|
|
@@ -34,6 +37,7 @@ export class ScopedVisitor extends TraverseVisitor {
|
|
|
34
37
|
visitProcedure(node) {
|
|
35
38
|
this.manageScope(node, () => super.visitProcedure(node));
|
|
36
39
|
}
|
|
40
|
+
fallback(node) { }
|
|
37
41
|
manageScope(node, traverse) {
|
|
38
42
|
const isTarget = node.identifier.value === this.binding;
|
|
39
43
|
if (isTarget)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AST, ASTNode, Class, Fact, Function, Rule, TraverseVisitor, Object, Variable, Sequence } from "yukigo-ast";
|
|
1
|
+
import { AST, ASTNode, Attribute, Class, Fact, Function, Method, Rule, TraverseVisitor, Object, Variable, Sequence } from "yukigo-ast";
|
|
2
2
|
import { RuntimeContext } from "./RuntimeContext.js";
|
|
3
|
+
import { RuntimeFunction, YuValue } from "../primitives/index.js";
|
|
3
4
|
/**
|
|
4
5
|
* Builds the initial environment by collecting all top-level function declarations.
|
|
5
6
|
* Each function captures a closure of the environment at its definition time,
|
|
@@ -7,14 +8,32 @@ import { RuntimeContext } from "./RuntimeContext.js";
|
|
|
7
8
|
*/
|
|
8
9
|
export declare class EnvBuilderVisitor extends TraverseVisitor {
|
|
9
10
|
private ctx;
|
|
11
|
+
private deferredInitializations;
|
|
10
12
|
constructor(ctx: RuntimeContext);
|
|
11
13
|
build(ast: AST): void;
|
|
14
|
+
private declareGlobalSymbols;
|
|
15
|
+
private initializeGlobalStates;
|
|
12
16
|
visitSequence(node: Sequence): void;
|
|
13
17
|
visitFunction(node: Function): void;
|
|
14
18
|
visitClass(node: Class): void;
|
|
15
19
|
visitObject(node: Object): void;
|
|
20
|
+
private resolveObjectFields;
|
|
21
|
+
private collectAllInitializers;
|
|
16
22
|
visitFact(node: Fact): void;
|
|
17
23
|
visitRule(node: Rule): void;
|
|
24
|
+
private getClassFields;
|
|
25
|
+
private getClassInitializers;
|
|
18
26
|
visitVariable(node: Variable): void;
|
|
19
27
|
visit(node: ASTNode): void;
|
|
28
|
+
fallback(node: ASTNode): string;
|
|
29
|
+
}
|
|
30
|
+
export declare class OOPCollector extends TraverseVisitor {
|
|
31
|
+
private ctx;
|
|
32
|
+
collectedMethods: Map<string, RuntimeFunction>;
|
|
33
|
+
collectedFields: Map<string, YuValue>;
|
|
34
|
+
fieldInitializers: Map<string, ASTNode>;
|
|
35
|
+
constructor(ctx: RuntimeContext);
|
|
36
|
+
visitMethod(node: Method): void;
|
|
37
|
+
visitAttribute(node: Attribute): void;
|
|
38
|
+
fallback(node: ASTNode): string;
|
|
20
39
|
}
|