@abaplint/transpiler 2.13.92 → 2.13.94
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/build/src/index.js +7 -0
- package/build/src/statements/delete_internal.js +4 -2
- package/build/src/statements/do.js +5 -2
- package/build/src/statements/insert_database.js +3 -0
- package/build/src/statements/select.js +1 -1
- package/build/src/traversal.d.ts +7 -0
- package/build/src/traversal.js +49 -17
- package/package.json +2 -2
package/build/src/index.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.Transpiler = exports.Chunk = exports.UnknownTypesEnum = exports.config =
|
|
|
37
37
|
const abaplint = __importStar(require("@abaplint/core"));
|
|
38
38
|
const validation_1 = require("./validation");
|
|
39
39
|
Object.defineProperty(exports, "config", { enumerable: true, get: function () { return validation_1.config; } });
|
|
40
|
+
const unique_identifier_1 = require("./unique_identifier");
|
|
40
41
|
const unit_test_1 = require("./unit_test");
|
|
41
42
|
const types_1 = require("./types");
|
|
42
43
|
Object.defineProperty(exports, "UnknownTypesEnum", { enumerable: true, get: function () { return types_1.UnknownTypesEnum; } });
|
|
@@ -95,6 +96,12 @@ class Transpiler {
|
|
|
95
96
|
progress?.set(reg.getObjectCount().total, "Building");
|
|
96
97
|
for (const obj of reg.getObjects()) {
|
|
97
98
|
await progress?.tick("Building, " + obj.getName());
|
|
99
|
+
// the temporary names ("unique1", ..., and the DO/WHILE sy-index backups
|
|
100
|
+
// "indexBackup1", ...) are local to the module an object becomes, so each
|
|
101
|
+
// object numbers its own: its output then depends on the registry alone,
|
|
102
|
+
// not on the objects built before it or on an earlier run in the same process
|
|
103
|
+
unique_identifier_1.UniqueIdentifier.reset();
|
|
104
|
+
unique_identifier_1.UniqueIdentifier.resetIndexBackup();
|
|
98
105
|
if (obj instanceof abaplint.Objects.TypePool) {
|
|
99
106
|
output.objects.push(...new handle_type_pool_1.HandleTypePool().runObject(obj, reg));
|
|
100
107
|
}
|
|
@@ -51,10 +51,12 @@ class DeleteInternalTranspiler {
|
|
|
51
51
|
extra.push("where: async " + traversal.traverse(componentCompare).getCode());
|
|
52
52
|
}
|
|
53
53
|
// todo, this is not completely correct, fields might have the name ADJACENT
|
|
54
|
-
// comparisons should be on table key unless other is specified, but we're unaware
|
|
55
54
|
if (node.findDirectTokenByText("ADJACENT")) {
|
|
56
55
|
extra.push("adjacent: true");
|
|
57
|
-
if (
|
|
56
|
+
if (concat.includes("COMPARING ALL FIELDS")) {
|
|
57
|
+
extra.push("allFields: true");
|
|
58
|
+
}
|
|
59
|
+
else if (node.findDirectTokenByText("COMPARING")) {
|
|
58
60
|
const comparing = node.findAllExpressions(abaplint.Expressions.SimpleFieldChain2);
|
|
59
61
|
if (comparing) {
|
|
60
62
|
const compareFields = comparing.map(i => "'" + i.getFirstToken().getStr() + "'").join(",");
|
|
@@ -46,11 +46,14 @@ class DoTranspiler {
|
|
|
46
46
|
transpile(node, traversal) {
|
|
47
47
|
const found = node.findFirstExpression(abaplint.Expressions.Source);
|
|
48
48
|
if (found) {
|
|
49
|
-
|
|
49
|
+
// the count is converted to i, like any numeric expression position: an
|
|
50
|
+
// f count read with get( ) gives its text 3,0000000000000000E+00, which
|
|
51
|
+
// no loop counter compares with, and a p count of 2.4 means 2 passes
|
|
52
|
+
const source = new expressions_1.SourceTranspiler(false).transpile(found, traversal).getCode();
|
|
50
53
|
const idSource = unique_identifier_1.UniqueIdentifier.get();
|
|
51
54
|
const id = unique_identifier_1.UniqueIdentifier.get();
|
|
52
55
|
return new chunk_1.Chunk(`const ${this.syIndexBackup} = abap.builtin.sy.get().index.get();
|
|
53
|
-
const ${idSource} = ${source};
|
|
56
|
+
const ${idSource} = new abap.types.Integer().set(${source}).get();
|
|
54
57
|
for (let ${id} = 0; ${id} < ${idSource}; ${id}++) {
|
|
55
58
|
abap.builtin.sy.get().index.set(${id} + 1);`);
|
|
56
59
|
}
|
|
@@ -61,6 +61,9 @@ class InsertDatabaseTranspiler {
|
|
|
61
61
|
const tvalues = traversal.traverse(fromTable);
|
|
62
62
|
options.push(`"table": ` + tvalues.getCode());
|
|
63
63
|
}
|
|
64
|
+
if (node.findDirectTokenByText("ACCEPTING") !== undefined) {
|
|
65
|
+
options.push(`"acceptingDuplicateKeys": true`);
|
|
66
|
+
}
|
|
64
67
|
const connection = node.findDirectExpression(abaplint.Expressions.DatabaseConnection);
|
|
65
68
|
if (connection) {
|
|
66
69
|
const con = findConnection(connection, traversal);
|
|
@@ -185,7 +185,7 @@ class SelectTranspiler {
|
|
|
185
185
|
}
|
|
186
186
|
if (!(${target} instanceof abap.types.HashedTable) && ${target}.getOptions()?.primaryKey?.type !== "SORTED") {
|
|
187
187
|
abap.statements.sort(${target}, {by: ${by}.map(k => { return {component: k}; })});
|
|
188
|
-
await abap.statements.deleteInternal(${target}, {adjacent: true,
|
|
188
|
+
await abap.statements.deleteInternal(${target}, {adjacent: true, allFields: true});
|
|
189
189
|
}
|
|
190
190
|
abap.builtin.sy.get().dbcnt.set(${target}.getArrayLength());
|
|
191
191
|
}`;
|
package/build/src/traversal.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import * as abaplint from "@abaplint/core";
|
|
2
2
|
import { Chunk } from "./chunk";
|
|
3
3
|
import { ITranspilerOptions } from "./types";
|
|
4
|
+
type IReference = ReturnType<abaplint.ISpaghettiScopeNode["getData"]>["references"][number];
|
|
5
|
+
/** the references of a scope whose start equals the token's start, in the
|
|
6
|
+
* scope's own order -- the same set and order the linear scan found:
|
|
7
|
+
* Position.equals compares row and column, a VirtualPosition compares its
|
|
8
|
+
* virtual row and column and only with another VirtualPosition */
|
|
9
|
+
export declare function referencesAt(scope: abaplint.ISpaghettiScopeNode, token: abaplint.Token): IReference[];
|
|
4
10
|
export declare class Traversal {
|
|
5
11
|
private readonly spaghetti;
|
|
6
12
|
private readonly file;
|
|
@@ -104,3 +110,4 @@ export declare class Traversal {
|
|
|
104
110
|
protected traverseStatement(node: abaplint.Nodes.StatementNode): Chunk;
|
|
105
111
|
protected traverseExpression(node: abaplint.Nodes.ExpressionNode): Chunk;
|
|
106
112
|
}
|
|
113
|
+
export {};
|
package/build/src/traversal.js
CHANGED
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Traversal = void 0;
|
|
37
|
+
exports.referencesAt = referencesAt;
|
|
37
38
|
const abaplint = __importStar(require("@abaplint/core"));
|
|
38
39
|
const StatementTranspilers = __importStar(require("./statements"));
|
|
39
40
|
const ExpressionTranspilers = __importStar(require("./expressions"));
|
|
@@ -42,6 +43,43 @@ const transpile_types_1 = require("./transpile_types");
|
|
|
42
43
|
const chunk_1 = require("./chunk");
|
|
43
44
|
const expressions_1 = require("./expressions");
|
|
44
45
|
const keywords_1 = require("./keywords");
|
|
46
|
+
/** the references of one scope, by where they start: built once per scope,
|
|
47
|
+
* so finding the reference at a token no longer walks every reference of
|
|
48
|
+
* the scope for every token, which made a long method quadratic */
|
|
49
|
+
const REFERENCE_INDEX = new WeakMap();
|
|
50
|
+
/** the references of a scope whose start equals the token's start, in the
|
|
51
|
+
* scope's own order -- the same set and order the linear scan found:
|
|
52
|
+
* Position.equals compares row and column, a VirtualPosition compares its
|
|
53
|
+
* virtual row and column and only with another VirtualPosition */
|
|
54
|
+
function referencesAt(scope, token) {
|
|
55
|
+
const references = scope.getData().references;
|
|
56
|
+
let index = REFERENCE_INDEX.get(references);
|
|
57
|
+
if (index === undefined) {
|
|
58
|
+
index = { plain: new Map(), virtual: new Map() };
|
|
59
|
+
references.forEach((r, n) => {
|
|
60
|
+
const start = r.position.getStart();
|
|
61
|
+
const key = start instanceof abaplint.VirtualPosition
|
|
62
|
+
? start.vrow + ":" + start.vcol
|
|
63
|
+
: start.getRow() + ":" + start.getCol();
|
|
64
|
+
const map = start instanceof abaplint.VirtualPosition ? index.virtual : index.plain;
|
|
65
|
+
const list = map.get(key);
|
|
66
|
+
if (list === undefined) {
|
|
67
|
+
map.set(key, [n]);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
list.push(n);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
REFERENCE_INDEX.set(references, index);
|
|
74
|
+
}
|
|
75
|
+
const start = token.getStart();
|
|
76
|
+
const found = [...(index.plain.get(start.getRow() + ":" + start.getCol()) ?? [])];
|
|
77
|
+
if (start instanceof abaplint.VirtualPosition) {
|
|
78
|
+
found.push(...(index.virtual.get(start.vrow + ":" + start.vcol) ?? []));
|
|
79
|
+
found.sort((a, b) => a - b);
|
|
80
|
+
}
|
|
81
|
+
return found.map(n => references[n]);
|
|
82
|
+
}
|
|
45
83
|
class Traversal {
|
|
46
84
|
spaghetti;
|
|
47
85
|
file;
|
|
@@ -395,9 +433,8 @@ class Traversal {
|
|
|
395
433
|
if (scope === undefined) {
|
|
396
434
|
return false;
|
|
397
435
|
}
|
|
398
|
-
for (const r of scope
|
|
399
|
-
if (r.referenceType === abaplint.ReferenceType.BuiltinMethodReference
|
|
400
|
-
&& r.position.getStart().equals(token.getStart())) {
|
|
436
|
+
for (const r of referencesAt(scope, token)) {
|
|
437
|
+
if (r.referenceType === abaplint.ReferenceType.BuiltinMethodReference) {
|
|
401
438
|
return true;
|
|
402
439
|
}
|
|
403
440
|
}
|
|
@@ -417,9 +454,8 @@ class Traversal {
|
|
|
417
454
|
if (scope === undefined) {
|
|
418
455
|
return undefined;
|
|
419
456
|
}
|
|
420
|
-
for (const r of scope
|
|
457
|
+
for (const r of referencesAt(scope, token)) {
|
|
421
458
|
if (r.referenceType === abaplint.ReferenceType.MethodReference
|
|
422
|
-
&& r.position.getStart().equals(token.getStart())
|
|
423
459
|
&& r.resolved instanceof abaplint.Types.MethodDefinition) {
|
|
424
460
|
let name = r.resolved.getName();
|
|
425
461
|
if (r.extra?.ooName && r.extra?.ooType === "INTF") {
|
|
@@ -433,8 +469,7 @@ class Traversal {
|
|
|
433
469
|
}
|
|
434
470
|
return candidate;
|
|
435
471
|
}
|
|
436
|
-
else if (r.referenceType === abaplint.ReferenceType.BuiltinMethodReference
|
|
437
|
-
&& r.position.getStart().equals(token.getStart())) {
|
|
472
|
+
else if (r.referenceType === abaplint.ReferenceType.BuiltinMethodReference) {
|
|
438
473
|
const def = r.resolved;
|
|
439
474
|
const name = def.getName();
|
|
440
475
|
return { def, name };
|
|
@@ -582,10 +617,9 @@ class Traversal {
|
|
|
582
617
|
if (scope === undefined) {
|
|
583
618
|
return undefined;
|
|
584
619
|
}
|
|
585
|
-
for (const r of scope
|
|
586
|
-
if (
|
|
587
|
-
|| r.referenceType === abaplint.ReferenceType.DataWriteReference)
|
|
588
|
-
&& r.position.getStart().equals(token.getStart())) {
|
|
620
|
+
for (const r of referencesAt(scope, token)) {
|
|
621
|
+
if (r.referenceType === abaplint.ReferenceType.DataReadReference
|
|
622
|
+
|| r.referenceType === abaplint.ReferenceType.DataWriteReference) {
|
|
589
623
|
return r.resolved;
|
|
590
624
|
}
|
|
591
625
|
}
|
|
@@ -596,9 +630,8 @@ class Traversal {
|
|
|
596
630
|
if (scope === undefined) {
|
|
597
631
|
return undefined;
|
|
598
632
|
}
|
|
599
|
-
for (const r of scope
|
|
600
|
-
if (r.referenceType === abaplint.ReferenceType.InferredType
|
|
601
|
-
&& r.position.getStart().equals(token.getStart())) {
|
|
633
|
+
for (const r of referencesAt(scope, token)) {
|
|
634
|
+
if (r.referenceType === abaplint.ReferenceType.InferredType) {
|
|
602
635
|
if (r.resolved instanceof abaplint.TypedIdentifier) {
|
|
603
636
|
return r.resolved.getType();
|
|
604
637
|
}
|
|
@@ -611,9 +644,8 @@ class Traversal {
|
|
|
611
644
|
if (scope === undefined) {
|
|
612
645
|
return undefined;
|
|
613
646
|
}
|
|
614
|
-
for (const r of scope
|
|
615
|
-
if (r.referenceType === abaplint.ReferenceType.TypeReference
|
|
616
|
-
&& r.position.getStart().equals(token.getStart())) {
|
|
647
|
+
for (const r of referencesAt(scope, token)) {
|
|
648
|
+
if (r.referenceType === abaplint.ReferenceType.TypeReference) {
|
|
617
649
|
if (r.resolved instanceof abaplint.TypedIdentifier) {
|
|
618
650
|
return r.resolved.getType();
|
|
619
651
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.94",
|
|
4
4
|
"description": "Transpiler",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/src/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"author": "abaplint",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@abaplint/core": "^2.120.
|
|
32
|
+
"@abaplint/core": "^2.120.61",
|
|
33
33
|
"source-map": "^0.8.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|