@abaplint/transpiler-cli 2.14.30 → 2.14.32
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/bundle.js +480 -182
- package/package.json +3 -3
package/build/bundle.js
CHANGED
|
@@ -46337,6 +46337,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
46337
46337
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
46338
46338
|
exports.ModifyInternal = void 0;
|
|
46339
46339
|
const Expressions = __importStar(__webpack_require__(/*! ../../2_statements/expressions */ "./node_modules/@abaplint/core/build/src/abap/2_statements/expressions/index.js"));
|
|
46340
|
+
const nodes_1 = __webpack_require__(/*! ../../nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
|
|
46340
46341
|
const source_1 = __webpack_require__(/*! ../expressions/source */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/source.js");
|
|
46341
46342
|
const target_1 = __webpack_require__(/*! ../expressions/target */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/target.js");
|
|
46342
46343
|
const fstarget_1 = __webpack_require__(/*! ../expressions/fstarget */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/expressions/fstarget.js");
|
|
@@ -46345,15 +46346,22 @@ const basic_1 = __webpack_require__(/*! ../../types/basic */ "./node_modules/@ab
|
|
|
46345
46346
|
const _syntax_input_1 = __webpack_require__(/*! ../_syntax_input */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_syntax_input.js");
|
|
46346
46347
|
class ModifyInternal {
|
|
46347
46348
|
runSyntax(node, input) {
|
|
46348
|
-
|
|
46349
|
-
source_1.Source.runSyntax(s, input);
|
|
46350
|
-
}
|
|
46349
|
+
var _a;
|
|
46351
46350
|
// there is only one
|
|
46352
46351
|
const target = node.findFirstExpression(Expressions.Target);
|
|
46353
|
-
|
|
46354
|
-
|
|
46355
|
-
|
|
46356
|
-
|
|
46352
|
+
// it might be a dynamic target
|
|
46353
|
+
const targetType = target ? target_1.Target.runSyntax(target, input) : undefined;
|
|
46354
|
+
// the FROM work area has the row type of the table, used for inferring "#"
|
|
46355
|
+
const rowType = targetType instanceof basic_1.TableType ? targetType.getRowType() : undefined;
|
|
46356
|
+
const children = node.getChildren();
|
|
46357
|
+
for (let i = 0; i < children.length; i++) {
|
|
46358
|
+
const s = children[i];
|
|
46359
|
+
if (s instanceof nodes_1.ExpressionNode && s.get() instanceof Expressions.Source) {
|
|
46360
|
+
const isFrom = ((_a = children[i - 1]) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === "FROM";
|
|
46361
|
+
source_1.Source.runSyntax(s, input, isFrom ? rowType : undefined);
|
|
46362
|
+
}
|
|
46363
|
+
}
|
|
46364
|
+
if (target) {
|
|
46357
46365
|
if (targetType instanceof basic_1.VoidType
|
|
46358
46366
|
|| targetType instanceof basic_1.AnyType
|
|
46359
46367
|
|| targetType instanceof basic_1.UnknownType) {
|
|
@@ -52216,7 +52224,8 @@ class SyntaxLogic {
|
|
|
52216
52224
|
}
|
|
52217
52225
|
}
|
|
52218
52226
|
}
|
|
52219
|
-
|
|
52227
|
+
// statements only have expressions and tokens as children, nothing to traverse
|
|
52228
|
+
if (isStructure) {
|
|
52220
52229
|
this.traverse(child);
|
|
52221
52230
|
}
|
|
52222
52231
|
}
|
|
@@ -62326,6 +62335,31 @@ exports.MemoryFile = MemoryFile;
|
|
|
62326
62335
|
|
|
62327
62336
|
/***/ },
|
|
62328
62337
|
|
|
62338
|
+
/***/ "./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js"
|
|
62339
|
+
/*!***********************************************************************!*\
|
|
62340
|
+
!*** ./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js ***!
|
|
62341
|
+
\***********************************************************************/
|
|
62342
|
+
(__unused_webpack_module, exports) {
|
|
62343
|
+
|
|
62344
|
+
"use strict";
|
|
62345
|
+
|
|
62346
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
62347
|
+
exports.getCachedRawRows = getCachedRawRows;
|
|
62348
|
+
const rowCache = new WeakMap();
|
|
62349
|
+
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one,
|
|
62350
|
+
* so the rows can be cached per file object. The result must not be modified */
|
|
62351
|
+
function getCachedRawRows(file) {
|
|
62352
|
+
let rows = rowCache.get(file);
|
|
62353
|
+
if (rows === undefined) {
|
|
62354
|
+
rows = file.getRawRows();
|
|
62355
|
+
rowCache.set(file, rows);
|
|
62356
|
+
}
|
|
62357
|
+
return rows;
|
|
62358
|
+
}
|
|
62359
|
+
//# sourceMappingURL=raw_rows_cache.js.map
|
|
62360
|
+
|
|
62361
|
+
/***/ },
|
|
62362
|
+
|
|
62329
62363
|
/***/ "./node_modules/@abaplint/core/build/src/index.js"
|
|
62330
62364
|
/*!********************************************************!*\
|
|
62331
62365
|
!*** ./node_modules/@abaplint/core/build/src/index.js ***!
|
|
@@ -62510,11 +62544,12 @@ exports.Issue = void 0;
|
|
|
62510
62544
|
const position_1 = __webpack_require__(/*! ./position */ "./node_modules/@abaplint/core/build/src/position.js");
|
|
62511
62545
|
const virtual_position_1 = __webpack_require__(/*! ./virtual_position */ "./node_modules/@abaplint/core/build/src/virtual_position.js");
|
|
62512
62546
|
const severity_1 = __webpack_require__(/*! ./severity */ "./node_modules/@abaplint/core/build/src/severity.js");
|
|
62547
|
+
const raw_rows_cache_1 = __webpack_require__(/*! ./files/raw_rows_cache */ "./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js");
|
|
62513
62548
|
class Issue {
|
|
62514
62549
|
//////////////////////////
|
|
62515
62550
|
static atRow(file, row, message, key, severity) {
|
|
62516
62551
|
const start = new position_1.Position(row, 1);
|
|
62517
|
-
const end = new position_1.Position(row,
|
|
62552
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
62518
62553
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
62519
62554
|
return new Issue({
|
|
62520
62555
|
filename: file.getFilename(),
|
|
@@ -62530,7 +62565,7 @@ class Issue {
|
|
|
62530
62565
|
}
|
|
62531
62566
|
static atPosition(file, start, message, key, severity, fix) {
|
|
62532
62567
|
const row = start.getRow();
|
|
62533
|
-
const end = new position_1.Position(row,
|
|
62568
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
62534
62569
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
62535
62570
|
return new Issue({
|
|
62536
62571
|
filename: file.getFilename(),
|
|
@@ -74734,6 +74769,8 @@ class Registry {
|
|
|
74734
74769
|
this.objects = {};
|
|
74735
74770
|
this.objectsByType = {};
|
|
74736
74771
|
this.dependencies = {};
|
|
74772
|
+
/** upper case filename to object containing the file, kept in sync by add/remove methods */
|
|
74773
|
+
this.filenameIndex = new Map();
|
|
74737
74774
|
this.setConfig(conf ? conf : config_1.Config.getDefault());
|
|
74738
74775
|
this.clear();
|
|
74739
74776
|
}
|
|
@@ -74742,13 +74779,14 @@ class Registry {
|
|
|
74742
74779
|
this.objects = {};
|
|
74743
74780
|
this.objectsByType = {};
|
|
74744
74781
|
this.dependencies = {};
|
|
74782
|
+
this.filenameIndex = new Map();
|
|
74745
74783
|
this.ddicReferences = new ddic_references_1.DDICReferences();
|
|
74746
74784
|
this.msagReferences = new msag_references_1.MSAGReferences();
|
|
74747
74785
|
this.macroReferences = new macro_references_1.MacroReferences();
|
|
74748
74786
|
}
|
|
74749
74787
|
static abaplintVersion() {
|
|
74750
74788
|
// magic, see build script "version.js"
|
|
74751
|
-
return "2.120.
|
|
74789
|
+
return "2.120.105";
|
|
74752
74790
|
}
|
|
74753
74791
|
getDDICReferences() {
|
|
74754
74792
|
return this.ddicReferences;
|
|
@@ -74801,11 +74839,13 @@ class Registry {
|
|
|
74801
74839
|
}
|
|
74802
74840
|
getFileByName(filename) {
|
|
74803
74841
|
const upper = filename.toUpperCase();
|
|
74804
|
-
|
|
74805
|
-
|
|
74806
|
-
|
|
74807
|
-
|
|
74808
|
-
|
|
74842
|
+
const obj = this.filenameIndex.get(upper);
|
|
74843
|
+
if (obj === undefined) {
|
|
74844
|
+
return undefined;
|
|
74845
|
+
}
|
|
74846
|
+
for (const f of obj.getFiles()) {
|
|
74847
|
+
if (f.getFilename().toUpperCase() === upper) {
|
|
74848
|
+
return f;
|
|
74809
74849
|
}
|
|
74810
74850
|
}
|
|
74811
74851
|
return undefined;
|
|
@@ -74846,6 +74886,7 @@ class Registry {
|
|
|
74846
74886
|
removeFile(file) {
|
|
74847
74887
|
const obj = this.find(file.getObjectName(), file.getObjectType());
|
|
74848
74888
|
obj.removeFile(file);
|
|
74889
|
+
this.unindexFile(file.getFilename(), obj);
|
|
74849
74890
|
if (obj.getFiles().length === 0) {
|
|
74850
74891
|
this.ddicReferences.clear(obj);
|
|
74851
74892
|
this.msagReferences.clear(obj);
|
|
@@ -74872,6 +74913,7 @@ class Registry {
|
|
|
74872
74913
|
found = this.findOrCreate(f.getObjectName(), f.getObjectType());
|
|
74873
74914
|
}
|
|
74874
74915
|
found.addFile(f);
|
|
74916
|
+
this.filenameIndex.set(filename.toUpperCase(), found);
|
|
74875
74917
|
}
|
|
74876
74918
|
return this;
|
|
74877
74919
|
}
|
|
@@ -74940,11 +74982,13 @@ class Registry {
|
|
|
74940
74982
|
// assumption: the file is already in the registry
|
|
74941
74983
|
findObjectForFile(file) {
|
|
74942
74984
|
const filename = file.getFilename();
|
|
74943
|
-
|
|
74944
|
-
|
|
74945
|
-
|
|
74946
|
-
|
|
74947
|
-
|
|
74985
|
+
const obj = this.filenameIndex.get(filename.toUpperCase());
|
|
74986
|
+
if (obj === undefined) {
|
|
74987
|
+
return undefined;
|
|
74988
|
+
}
|
|
74989
|
+
for (const ofile of obj.getFiles()) {
|
|
74990
|
+
if (ofile.getFilename() === filename) {
|
|
74991
|
+
return obj;
|
|
74948
74992
|
}
|
|
74949
74993
|
}
|
|
74950
74994
|
return undefined;
|
|
@@ -75036,6 +75080,9 @@ class Registry {
|
|
|
75036
75080
|
if (this.objects[remove.getName()][remove.getType()] === undefined) {
|
|
75037
75081
|
throw new Error("removeObject: object not found");
|
|
75038
75082
|
}
|
|
75083
|
+
for (const f of remove.getFiles()) {
|
|
75084
|
+
this.unindexFile(f.getFilename(), remove);
|
|
75085
|
+
}
|
|
75039
75086
|
if (Object.keys(this.objects[remove.getName()]).length === 1) {
|
|
75040
75087
|
delete this.objects[remove.getName()];
|
|
75041
75088
|
}
|
|
@@ -75049,6 +75096,12 @@ class Registry {
|
|
|
75049
75096
|
delete this.objectsByType[remove.getType()][remove.getName()];
|
|
75050
75097
|
}
|
|
75051
75098
|
}
|
|
75099
|
+
unindexFile(filename, obj) {
|
|
75100
|
+
const upper = filename.toUpperCase();
|
|
75101
|
+
if (this.filenameIndex.get(upper) === obj) {
|
|
75102
|
+
this.filenameIndex.delete(upper);
|
|
75103
|
+
}
|
|
75104
|
+
}
|
|
75052
75105
|
find(name, type) {
|
|
75053
75106
|
const searchType = type ? type : "UNKNOWN";
|
|
75054
75107
|
const searchName = name.toUpperCase();
|
|
@@ -75346,6 +75399,7 @@ const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_st
|
|
|
75346
75399
|
const tokens_1 = __webpack_require__(/*! ../abap/1_lexer/tokens */ "./node_modules/@abaplint/core/build/src/abap/1_lexer/tokens/index.js");
|
|
75347
75400
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
|
|
75348
75401
|
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/syntax.js");
|
|
75402
|
+
const raw_rows_cache_1 = __webpack_require__(/*! ../files/raw_rows_cache */ "./node_modules/@abaplint/core/build/src/files/raw_rows_cache.js");
|
|
75349
75403
|
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "./node_modules/@abaplint/core/build/src/abap/nodes/index.js");
|
|
75350
75404
|
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "./node_modules/@abaplint/core/build/src/abap/types/_typed_identifier.js");
|
|
75351
75405
|
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "./node_modules/@abaplint/core/build/src/abap/types/basic/index.js");
|
|
@@ -76652,16 +76706,6 @@ class Hierarchy {
|
|
|
76652
76706
|
exports.Hierarchy = Hierarchy;
|
|
76653
76707
|
////////////////////////////////////////
|
|
76654
76708
|
// edits
|
|
76655
|
-
const rowCache = new WeakMap();
|
|
76656
|
-
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
|
|
76657
|
-
function rowsOf(file) {
|
|
76658
|
-
let rows = rowCache.get(file);
|
|
76659
|
-
if (rows === undefined) {
|
|
76660
|
-
rows = file.getRawRows();
|
|
76661
|
-
rowCache.set(file, rows);
|
|
76662
|
-
}
|
|
76663
|
-
return rows;
|
|
76664
|
-
}
|
|
76665
76709
|
/** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
|
|
76666
76710
|
function mergeEdits(file, edits) {
|
|
76667
76711
|
const list = [];
|
|
@@ -76681,7 +76725,7 @@ function deleteRegion(file, first, last) {
|
|
|
76681
76725
|
if (first === last && first.getColon() !== undefined) {
|
|
76682
76726
|
return edit_helper_1.EditHelper.deleteStatement(file, first);
|
|
76683
76727
|
}
|
|
76684
|
-
const rows =
|
|
76728
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
76685
76729
|
const start = first.getStart();
|
|
76686
76730
|
const end = last.getEnd();
|
|
76687
76731
|
const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
|
|
@@ -76696,7 +76740,7 @@ function deleteStatement(file, statement) {
|
|
|
76696
76740
|
}
|
|
76697
76741
|
/** the source code between two positions, as written */
|
|
76698
76742
|
function rawText(file, start, end) {
|
|
76699
|
-
const rows =
|
|
76743
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
76700
76744
|
if (start.getRow() === end.getRow()) {
|
|
76701
76745
|
return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
|
|
76702
76746
|
}
|
|
@@ -86606,8 +86650,23 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
86606
86650
|
}
|
|
86607
86651
|
highSyntaxObj = this.highReg.findObjectForFile(f);
|
|
86608
86652
|
}
|
|
86653
|
+
// the syntax run is expensive and most statements need no downport, so run it on first use
|
|
86654
|
+
let computedSyntax = undefined;
|
|
86655
|
+
const runHighSyntax = () => {
|
|
86656
|
+
if (computedSyntax === undefined) {
|
|
86657
|
+
computedSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
86658
|
+
}
|
|
86659
|
+
return computedSyntax;
|
|
86660
|
+
};
|
|
86661
|
+
const highSyntax = {
|
|
86662
|
+
get issues() {
|
|
86663
|
+
return runHighSyntax().issues;
|
|
86664
|
+
},
|
|
86665
|
+
get spaghetti() {
|
|
86666
|
+
return runHighSyntax().spaghetti;
|
|
86667
|
+
},
|
|
86668
|
+
};
|
|
86609
86669
|
for (const lowFile of lowObj.getABAPFiles()) {
|
|
86610
|
-
let highSyntax = undefined;
|
|
86611
86670
|
const highFile = highObj.getABAPFileByName(lowFile.getFilename());
|
|
86612
86671
|
if (highFile === undefined) {
|
|
86613
86672
|
continue;
|
|
@@ -86626,9 +86685,6 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
86626
86685
|
// actively editing the files
|
|
86627
86686
|
continue;
|
|
86628
86687
|
}
|
|
86629
|
-
if (highSyntax === undefined) {
|
|
86630
|
-
highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
86631
|
-
}
|
|
86632
86688
|
let containsUnknown = false;
|
|
86633
86689
|
const notDownported = [];
|
|
86634
86690
|
for (let i = 0; i < lowStatements.length; i++) {
|
|
@@ -109518,6 +109574,8 @@ const _irule_1 = __webpack_require__(/*! ./_irule */ "./node_modules/@abaplint/c
|
|
|
109518
109574
|
const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/syntax.js");
|
|
109519
109575
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
|
|
109520
109576
|
const types_1 = __webpack_require__(/*! ../abap/types */ "./node_modules/@abaplint/core/build/src/abap/types/index.js");
|
|
109577
|
+
const position_1 = __webpack_require__(/*! ../position */ "./node_modules/@abaplint/core/build/src/position.js");
|
|
109578
|
+
const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "./node_modules/@abaplint/core/build/src/virtual_position.js");
|
|
109521
109579
|
class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
109522
109580
|
constructor() {
|
|
109523
109581
|
super(...arguments);
|
|
@@ -109557,24 +109615,36 @@ ENDMETHOD.`,
|
|
|
109557
109615
|
if (this.getConfig().allowInTestclassIncludes === true && file.getFilename().includes(".testclasses.")) {
|
|
109558
109616
|
return [];
|
|
109559
109617
|
}
|
|
109560
|
-
const staticMethodCalls =
|
|
109618
|
+
const staticMethodCalls = new Set();
|
|
109619
|
+
for (const s of this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop())) {
|
|
109620
|
+
staticMethodCalls.add(StaticCallViaInstance.positionKey(s));
|
|
109621
|
+
}
|
|
109622
|
+
if (staticMethodCalls.size === 0) {
|
|
109623
|
+
return [];
|
|
109624
|
+
}
|
|
109561
109625
|
const tokens = file.getTokens();
|
|
109562
109626
|
for (let i = 0; i < tokens.length - 1; i++) {
|
|
109563
109627
|
const token = tokens[i];
|
|
109564
109628
|
if (token.getStr() !== "->") {
|
|
109565
109629
|
continue;
|
|
109566
109630
|
}
|
|
109567
|
-
const next = tokens[i + 1];
|
|
109568
|
-
|
|
109569
|
-
|
|
109570
|
-
|
|
109571
|
-
|
|
109572
|
-
|
|
109573
|
-
|
|
109631
|
+
const next = tokens[i + 1].getStart();
|
|
109632
|
+
// a plain reference position also matches a token inside a macro call at the same row and column
|
|
109633
|
+
if (staticMethodCalls.has(StaticCallViaInstance.positionKey(next))
|
|
109634
|
+
|| (next instanceof virtual_position_1.VirtualPosition
|
|
109635
|
+
&& staticMethodCalls.has(StaticCallViaInstance.positionKey(new position_1.Position(next.getRow(), next.getCol()))))) {
|
|
109636
|
+
const message = "Avoid calling static method via instance";
|
|
109637
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
|
|
109574
109638
|
}
|
|
109575
109639
|
}
|
|
109576
109640
|
return issues;
|
|
109577
109641
|
}
|
|
109642
|
+
static positionKey(p) {
|
|
109643
|
+
if (p instanceof virtual_position_1.VirtualPosition) {
|
|
109644
|
+
return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
|
|
109645
|
+
}
|
|
109646
|
+
return p.getRow() + ":" + p.getCol();
|
|
109647
|
+
}
|
|
109578
109648
|
listMethodCalls(filename, node) {
|
|
109579
109649
|
const ret = [];
|
|
109580
109650
|
for (const r of node.getData().references) {
|
|
@@ -113165,31 +113235,40 @@ const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ ".
|
|
|
113165
113235
|
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "./node_modules/@abaplint/core/build/src/edit_helper.js");
|
|
113166
113236
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "./node_modules/@abaplint/core/build/src/abap/5_syntax/_reference.js");
|
|
113167
113237
|
const _statement_1 = __webpack_require__(/*! ../abap/2_statements/statements/_statement */ "./node_modules/@abaplint/core/build/src/abap/2_statements/statements/_statement.js");
|
|
113238
|
+
const virtual_position_1 = __webpack_require__(/*! ../virtual_position */ "./node_modules/@abaplint/core/build/src/virtual_position.js");
|
|
113168
113239
|
class WorkArea {
|
|
113169
113240
|
constructor() {
|
|
113170
|
-
|
|
113241
|
+
// keyed by identifier position, insertion order is kept
|
|
113242
|
+
this.workarea = new Map();
|
|
113171
113243
|
}
|
|
113172
113244
|
push(id) {
|
|
113173
|
-
|
|
113174
|
-
|
|
113175
|
-
|
|
113176
|
-
}
|
|
113245
|
+
const key = WorkArea.buildKey(id);
|
|
113246
|
+
if (this.workarea.has(key) === false) {
|
|
113247
|
+
this.workarea.set(key, id);
|
|
113177
113248
|
}
|
|
113178
|
-
this.workarea.push(id);
|
|
113179
113249
|
}
|
|
113180
113250
|
removeIfExists(id) {
|
|
113181
|
-
|
|
113182
|
-
|
|
113183
|
-
|
|
113184
|
-
|
|
113251
|
+
this.workarea.delete(WorkArea.buildKey(id));
|
|
113252
|
+
}
|
|
113253
|
+
/** removes the identifiers referenced somewhere */
|
|
113254
|
+
removeReferenced(referenced) {
|
|
113255
|
+
for (const key of [...this.workarea.keys()]) {
|
|
113256
|
+
if (referenced.has(key)) {
|
|
113257
|
+
this.workarea.delete(key);
|
|
113185
113258
|
}
|
|
113186
113259
|
}
|
|
113187
113260
|
}
|
|
113188
113261
|
get() {
|
|
113189
|
-
return this.workarea;
|
|
113262
|
+
return [...this.workarea.values()];
|
|
113190
113263
|
}
|
|
113191
113264
|
count() {
|
|
113192
|
-
return this.workarea.
|
|
113265
|
+
return this.workarea.size;
|
|
113266
|
+
}
|
|
113267
|
+
/** identifiers from one macro call share the row and column, the virtual position tells them apart */
|
|
113268
|
+
static buildKey(id) {
|
|
113269
|
+
const start = id.getStart();
|
|
113270
|
+
const key = id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
113271
|
+
return start instanceof virtual_position_1.VirtualPosition ? key + "," + start.vrow + "," + start.vcol : key;
|
|
113193
113272
|
}
|
|
113194
113273
|
}
|
|
113195
113274
|
class UnusedTypesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
@@ -113205,6 +113284,8 @@ exports.UnusedTypesConf = UnusedTypesConf;
|
|
|
113205
113284
|
class UnusedTypes {
|
|
113206
113285
|
constructor() {
|
|
113207
113286
|
this.conf = new UnusedTypesConf();
|
|
113287
|
+
/** keys of the identifiers with a type reference in any object, built once per run when needed */
|
|
113288
|
+
this.referenced = undefined;
|
|
113208
113289
|
}
|
|
113209
113290
|
getMetadata() {
|
|
113210
113291
|
return {
|
|
@@ -113228,6 +113309,7 @@ class UnusedTypes {
|
|
|
113228
113309
|
}
|
|
113229
113310
|
initialize(reg) {
|
|
113230
113311
|
this.reg = reg;
|
|
113312
|
+
this.referenced = undefined;
|
|
113231
113313
|
return this;
|
|
113232
113314
|
}
|
|
113233
113315
|
run(obj) {
|
|
@@ -113252,20 +113334,10 @@ class UnusedTypes {
|
|
|
113252
113334
|
if (this.workarea.count() === 0) {
|
|
113253
113335
|
return []; // exit early if all types are used in the current object
|
|
113254
113336
|
}
|
|
113255
|
-
|
|
113256
|
-
|
|
113257
|
-
|
|
113258
|
-
|
|
113259
|
-
else if (o instanceof _abap_object_1.ABAPObject) {
|
|
113260
|
-
if (this.reg.isDependency(o)) {
|
|
113261
|
-
continue; // do not search in dependencies
|
|
113262
|
-
}
|
|
113263
|
-
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
113264
|
-
this.traverse(syntax.spaghetti.getTop(), o, false);
|
|
113265
|
-
}
|
|
113266
|
-
if (this.workarea.count() === 0) {
|
|
113267
|
-
return []; // exit early if all types are used
|
|
113268
|
-
}
|
|
113337
|
+
// uses in other objects, collected once instead of searching all objects for each object
|
|
113338
|
+
this.workarea.removeReferenced(this.getReferenced());
|
|
113339
|
+
if (this.workarea.count() === 0) {
|
|
113340
|
+
return []; // exit early if all types are used
|
|
113269
113341
|
}
|
|
113270
113342
|
// what is left is unused
|
|
113271
113343
|
const ret = [];
|
|
@@ -113309,6 +113381,33 @@ class UnusedTypes {
|
|
|
113309
113381
|
return false;
|
|
113310
113382
|
}
|
|
113311
113383
|
////////////////////////////
|
|
113384
|
+
getReferenced() {
|
|
113385
|
+
if (this.referenced === undefined) {
|
|
113386
|
+
const referenced = new Set();
|
|
113387
|
+
for (const o of this.reg.getObjects()) {
|
|
113388
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
113389
|
+
continue; // do not search in dependencies
|
|
113390
|
+
}
|
|
113391
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
113392
|
+
this.collectReferenced(syntax.spaghetti.getTop(), referenced);
|
|
113393
|
+
}
|
|
113394
|
+
this.referenced = referenced;
|
|
113395
|
+
}
|
|
113396
|
+
return this.referenced;
|
|
113397
|
+
}
|
|
113398
|
+
/** same nodes and references as checkNode() with add = false */
|
|
113399
|
+
collectReferenced(node, referenced) {
|
|
113400
|
+
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
113401
|
+
for (const r of node.getData().references) {
|
|
113402
|
+
if (r.referenceType === _reference_1.ReferenceType.TypeReference && r.resolved) {
|
|
113403
|
+
referenced.add(WorkArea.buildKey(r.resolved));
|
|
113404
|
+
}
|
|
113405
|
+
}
|
|
113406
|
+
}
|
|
113407
|
+
for (const c of node.getChildren()) {
|
|
113408
|
+
this.collectReferenced(c, referenced);
|
|
113409
|
+
}
|
|
113410
|
+
}
|
|
113312
113411
|
traverse(node, obj, add) {
|
|
113313
113412
|
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
113314
113413
|
this.checkNode(node, obj, add);
|
|
@@ -113428,17 +113527,17 @@ class WorkArea {
|
|
|
113428
113527
|
this.workarea = new Map();
|
|
113429
113528
|
}
|
|
113430
113529
|
push(id, count = 1) {
|
|
113431
|
-
const key =
|
|
113530
|
+
const key = WorkArea.buildKey(id);
|
|
113432
113531
|
if (this.workarea.has(key)) {
|
|
113433
113532
|
return;
|
|
113434
113533
|
}
|
|
113435
|
-
this.workarea.set(key, { id, count });
|
|
113534
|
+
this.workarea.set(key, { id, count, required: count });
|
|
113436
113535
|
}
|
|
113437
113536
|
removeIfExists(id) {
|
|
113438
113537
|
if (id === undefined) {
|
|
113439
113538
|
return;
|
|
113440
113539
|
}
|
|
113441
|
-
const key =
|
|
113540
|
+
const key = WorkArea.buildKey(id);
|
|
113442
113541
|
const found = this.workarea.get(key);
|
|
113443
113542
|
if (found !== undefined) {
|
|
113444
113543
|
found.count--;
|
|
@@ -113447,13 +113546,23 @@ class WorkArea {
|
|
|
113447
113546
|
}
|
|
113448
113547
|
}
|
|
113449
113548
|
}
|
|
113549
|
+
/** removes the identifiers with enough references, counts include all objects, also the one the
|
|
113550
|
+
* identifiers belong to, so it is compared to the required count and not the remaining count */
|
|
113551
|
+
removeReferenced(counts) {
|
|
113552
|
+
var _a;
|
|
113553
|
+
for (const [key, entry] of this.workarea) {
|
|
113554
|
+
if (((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) >= entry.required) {
|
|
113555
|
+
this.workarea.delete(key);
|
|
113556
|
+
}
|
|
113557
|
+
}
|
|
113558
|
+
}
|
|
113450
113559
|
get() {
|
|
113451
113560
|
return [...this.workarea.values()];
|
|
113452
113561
|
}
|
|
113453
113562
|
count() {
|
|
113454
113563
|
return this.workarea.size;
|
|
113455
113564
|
}
|
|
113456
|
-
buildKey(id) {
|
|
113565
|
+
static buildKey(id) {
|
|
113457
113566
|
const start = id.getStart();
|
|
113458
113567
|
return id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
113459
113568
|
}
|
|
@@ -113461,6 +113570,8 @@ class WorkArea {
|
|
|
113461
113570
|
class UnusedVariables {
|
|
113462
113571
|
constructor() {
|
|
113463
113572
|
this.conf = new UnusedVariablesConf();
|
|
113573
|
+
/** read, write and type references per identifier key in all objects, built once per run when needed */
|
|
113574
|
+
this.referenceCounts = undefined;
|
|
113464
113575
|
}
|
|
113465
113576
|
getMetadata() {
|
|
113466
113577
|
return {
|
|
@@ -113498,6 +113609,7 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
113498
113609
|
}
|
|
113499
113610
|
initialize(reg) {
|
|
113500
113611
|
this.reg = reg;
|
|
113612
|
+
this.referenceCounts = undefined;
|
|
113501
113613
|
return this;
|
|
113502
113614
|
}
|
|
113503
113615
|
run(obj) {
|
|
@@ -113525,34 +113637,53 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
113525
113637
|
if (this.workarea.count() === 0) {
|
|
113526
113638
|
return this.buildIssues(obj); // exit early if all variables are used
|
|
113527
113639
|
}
|
|
113528
|
-
this.findUses(top
|
|
113529
|
-
|
|
113530
|
-
|
|
113531
|
-
|
|
113532
|
-
|
|
113533
|
-
|
|
113534
|
-
|
|
113640
|
+
this.findUses(top);
|
|
113641
|
+
if (this.workarea.count() === 0) {
|
|
113642
|
+
return this.buildIssues(obj); // exit early if all variables are used
|
|
113643
|
+
}
|
|
113644
|
+
// uses in other objects, the counts are built once instead of searching all objects for each object
|
|
113645
|
+
this.workarea.removeReferenced(this.getReferenceCounts());
|
|
113646
|
+
return this.buildIssues(obj);
|
|
113647
|
+
}
|
|
113648
|
+
getReferenceCounts() {
|
|
113649
|
+
if (this.referenceCounts === undefined) {
|
|
113650
|
+
const counts = new Map();
|
|
113651
|
+
for (const o of this.reg.getObjects()) {
|
|
113652
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
113535
113653
|
continue; // do not search in dependencies
|
|
113536
113654
|
}
|
|
113537
113655
|
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
113538
|
-
this.
|
|
113539
|
-
if (this.workarea.count() === 0) {
|
|
113540
|
-
return this.buildIssues(obj); // exit early if all variables are used
|
|
113541
|
-
}
|
|
113656
|
+
this.countUses(syntax.spaghetti.getTop(), counts);
|
|
113542
113657
|
}
|
|
113658
|
+
this.referenceCounts = counts;
|
|
113543
113659
|
}
|
|
113544
|
-
return this.
|
|
113660
|
+
return this.referenceCounts;
|
|
113661
|
+
}
|
|
113662
|
+
static isUse(r) {
|
|
113663
|
+
return r.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
113664
|
+
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
113665
|
+
|| r.referenceType === _reference_1.ReferenceType.TypeReference;
|
|
113545
113666
|
}
|
|
113546
|
-
findUses(node
|
|
113667
|
+
findUses(node) {
|
|
113547
113668
|
for (const r of node.getData().references) {
|
|
113548
|
-
if (r
|
|
113549
|
-
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
113550
|
-
|| r.referenceType === _reference_1.ReferenceType.TypeReference) {
|
|
113669
|
+
if (UnusedVariables.isUse(r)) {
|
|
113551
113670
|
this.workarea.removeIfExists(r.resolved);
|
|
113552
113671
|
}
|
|
113553
113672
|
}
|
|
113554
113673
|
for (const c of node.getChildren()) {
|
|
113555
|
-
this.findUses(c
|
|
113674
|
+
this.findUses(c);
|
|
113675
|
+
}
|
|
113676
|
+
}
|
|
113677
|
+
countUses(node, counts) {
|
|
113678
|
+
var _a;
|
|
113679
|
+
for (const r of node.getData().references) {
|
|
113680
|
+
if (r.resolved !== undefined && UnusedVariables.isUse(r)) {
|
|
113681
|
+
const key = WorkArea.buildKey(r.resolved);
|
|
113682
|
+
counts.set(key, ((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
113683
|
+
}
|
|
113684
|
+
}
|
|
113685
|
+
for (const c of node.getChildren()) {
|
|
113686
|
+
this.countUses(c, counts);
|
|
113556
113687
|
}
|
|
113557
113688
|
}
|
|
113558
113689
|
buildWorkarea(node, obj) {
|
|
@@ -116847,43 +116978,92 @@ class Chunk {
|
|
|
116847
116978
|
if (search === "") {
|
|
116848
116979
|
throw new Error("Chunk.replaceAll, search string must not be empty");
|
|
116849
116980
|
}
|
|
116850
|
-
const
|
|
116981
|
+
const escaped = search.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
116982
|
+
return this.replaceMatches(new RegExp(escaped, "g"), () => replacement);
|
|
116983
|
+
}
|
|
116984
|
+
/** Replace every match of a global pattern in one forward pass. The replacer
|
|
116985
|
+
* returns the new text, or undefined to keep the match. Source-map positions
|
|
116986
|
+
* are moved once at the end, so the cost is linear in the code size plus
|
|
116987
|
+
* mappings * log(replacements), however many matches there are. */
|
|
116988
|
+
replaceMatches(pattern, replacer) {
|
|
116989
|
+
if (!pattern.global) {
|
|
116990
|
+
throw new Error("Chunk.replaceMatches, pattern must be global");
|
|
116991
|
+
}
|
|
116992
|
+
const advance = (position, text) => {
|
|
116993
|
+
const lastNewline = text.lastIndexOf("\n");
|
|
116994
|
+
if (lastNewline < 0) {
|
|
116995
|
+
return { line: position.line, column: position.column + text.length };
|
|
116996
|
+
}
|
|
116997
|
+
let lines = 0;
|
|
116998
|
+
for (let index = text.indexOf("\n"); index >= 0; index = text.indexOf("\n", index + 1)) {
|
|
116999
|
+
lines++;
|
|
117000
|
+
}
|
|
117001
|
+
return { line: position.line + lines, column: text.length - lastNewline - 1 };
|
|
117002
|
+
};
|
|
117003
|
+
const edits = [];
|
|
117004
|
+
const output = [];
|
|
117005
|
+
let oldPosition = { line: 1, column: 0 };
|
|
117006
|
+
let newPosition = { line: 1, column: 0 };
|
|
116851
117007
|
let cursor = 0;
|
|
116852
|
-
|
|
116853
|
-
const
|
|
116854
|
-
if (
|
|
116855
|
-
|
|
117008
|
+
for (const match of this.raw.matchAll(pattern)) {
|
|
117009
|
+
const replacement = replacer(match);
|
|
117010
|
+
if (replacement === undefined || replacement === match[0]) {
|
|
117011
|
+
continue;
|
|
116856
117012
|
}
|
|
116857
|
-
|
|
116858
|
-
|
|
116859
|
-
|
|
116860
|
-
|
|
116861
|
-
|
|
116862
|
-
|
|
116863
|
-
|
|
116864
|
-
|
|
116865
|
-
|
|
116866
|
-
|
|
116867
|
-
|
|
116868
|
-
|
|
116869
|
-
|
|
116870
|
-
|
|
116871
|
-
|
|
116872
|
-
|
|
116873
|
-
|
|
116874
|
-
|
|
116875
|
-
|
|
116876
|
-
|
|
116877
|
-
|
|
116878
|
-
|
|
116879
|
-
|
|
117013
|
+
const between = this.raw.substring(cursor, match.index);
|
|
117014
|
+
output.push(between, replacement);
|
|
117015
|
+
const oldStart = advance(oldPosition, between);
|
|
117016
|
+
const newStart = advance(newPosition, between);
|
|
117017
|
+
oldPosition = advance(oldStart, match[0]);
|
|
117018
|
+
newPosition = advance(newStart, replacement);
|
|
117019
|
+
edits.push({ oldStart, oldEnd: oldPosition, newStart, newEnd: newPosition });
|
|
117020
|
+
cursor = match.index + match[0].length;
|
|
117021
|
+
}
|
|
117022
|
+
if (edits.length === 0) {
|
|
117023
|
+
return this;
|
|
117024
|
+
}
|
|
117025
|
+
output.push(this.raw.substring(cursor));
|
|
117026
|
+
const before = (a, b) => a.line < b.line || (a.line === b.line && a.column < b.column);
|
|
117027
|
+
for (const mapping of this.mappings) {
|
|
117028
|
+
const position = mapping.generated;
|
|
117029
|
+
// last edit starting at or before this mapping
|
|
117030
|
+
let low = 0;
|
|
117031
|
+
let high = edits.length - 1;
|
|
117032
|
+
let found = -1;
|
|
117033
|
+
while (low <= high) {
|
|
117034
|
+
const middle = Math.floor((low + high) / 2);
|
|
117035
|
+
if (before(position, edits[middle].oldStart)) {
|
|
117036
|
+
high = middle - 1;
|
|
116880
117037
|
}
|
|
117038
|
+
else {
|
|
117039
|
+
found = middle;
|
|
117040
|
+
low = middle + 1;
|
|
117041
|
+
}
|
|
117042
|
+
}
|
|
117043
|
+
if (found < 0) {
|
|
117044
|
+
continue;
|
|
117045
|
+
}
|
|
117046
|
+
const edit = edits[found];
|
|
117047
|
+
if (before(position, edit.oldEnd) && position.line === edit.oldStart.line) {
|
|
117048
|
+
// inside the replaced text, keep the offset from its start
|
|
117049
|
+
position.column = edit.newStart.column + position.column - edit.oldStart.column;
|
|
117050
|
+
position.line = edit.newStart.line;
|
|
117051
|
+
}
|
|
117052
|
+
else if (before(position, edit.oldEnd)) {
|
|
117053
|
+
position.line += edit.newStart.line - edit.oldStart.line;
|
|
117054
|
+
}
|
|
117055
|
+
else if (position.line === edit.oldEnd.line) {
|
|
117056
|
+
position.column = edit.newEnd.column + position.column - edit.oldEnd.column;
|
|
117057
|
+
position.line = edit.newEnd.line;
|
|
117058
|
+
}
|
|
117059
|
+
else {
|
|
117060
|
+
position.line += edit.newEnd.line - edit.oldEnd.line;
|
|
116881
117061
|
}
|
|
116882
|
-
this.raw = this.raw.substring(0, index) + replacement + this.raw.substring(index + search.length);
|
|
116883
117062
|
}
|
|
116884
|
-
|
|
116885
|
-
|
|
116886
|
-
this.
|
|
117063
|
+
this.raw = output.join("");
|
|
117064
|
+
const end = advance(newPosition, output[output.length - 1]);
|
|
117065
|
+
this.lineCount = end.line;
|
|
117066
|
+
this.lastLineLength = end.column;
|
|
116887
117067
|
return this;
|
|
116888
117068
|
}
|
|
116889
117069
|
stripLastNewline() {
|
|
@@ -117329,14 +117509,20 @@ class DatabaseSetup {
|
|
|
117329
117509
|
for (const obj of this.reg.getObjects()) {
|
|
117330
117510
|
if (obj instanceof abaplint.Objects.Table
|
|
117331
117511
|
&& obj.getTableCategory() === abaplint.Objects.TableCategory.Transparent) {
|
|
117332
|
-
|
|
117512
|
+
const statement = schemaGenerator.buildTABL(obj).trim();
|
|
117513
|
+
if (statement.length > 0) {
|
|
117514
|
+
statements.push(statement);
|
|
117515
|
+
}
|
|
117333
117516
|
}
|
|
117334
117517
|
}
|
|
117335
117518
|
// CREATE VIEWs after TABLEs
|
|
117336
117519
|
// todo: what if the view is based on another view?
|
|
117337
117520
|
for (const obj of this.reg.getObjects()) {
|
|
117338
117521
|
if (obj instanceof abaplint.Objects.View) {
|
|
117339
|
-
|
|
117522
|
+
const statement = schemaGenerator.buildVIEW(obj).trim();
|
|
117523
|
+
if (statement.length > 0) {
|
|
117524
|
+
statements.push(statement);
|
|
117525
|
+
}
|
|
117340
117526
|
}
|
|
117341
117527
|
}
|
|
117342
117528
|
return statements;
|
|
@@ -123887,7 +124073,8 @@ class TableExpressionTranspiler {
|
|
|
123887
124073
|
else {
|
|
123888
124074
|
// conditions
|
|
123889
124075
|
for (const c of node.getChildren()) {
|
|
123890
|
-
|
|
124076
|
+
// only the keywords, a component can be named "key" or "components"
|
|
124077
|
+
if (c === keyName || (c instanceof core_1.Nodes.TokenNode && ["KEY", "COMPONENTS"].includes(c.concatTokens().toUpperCase()))) {
|
|
123891
124078
|
continue;
|
|
123892
124079
|
}
|
|
123893
124080
|
if (c instanceof core_1.Nodes.ExpressionNode && c.get() instanceof core_1.Expressions.ComponentChainSimple) {
|
|
@@ -141828,10 +142015,14 @@ class Traversal {
|
|
|
141828
142015
|
if (this.getCurrentObject().getABAPFileByName(filename) !== undefined) {
|
|
141829
142016
|
return true;
|
|
141830
142017
|
}
|
|
141831
|
-
const
|
|
141832
|
-
const found = file ? this.reg.findObjectForFile(file) : undefined;
|
|
142018
|
+
const found = this.findObjectForFilename(filename);
|
|
141833
142019
|
return found instanceof abaplint.Objects.Program && found.isInclude();
|
|
141834
142020
|
}
|
|
142021
|
+
/** the object containing the file, undefined if the file is not in the registry */
|
|
142022
|
+
findObjectForFilename(filename) {
|
|
142023
|
+
const file = this.reg.getFileByName(filename);
|
|
142024
|
+
return file === undefined ? undefined : this.reg.findObjectForFile(file);
|
|
142025
|
+
}
|
|
141835
142026
|
traverse(node) {
|
|
141836
142027
|
if (node instanceof abaplint.Nodes.StructureNode) {
|
|
141837
142028
|
return this.traverseStructure(node);
|
|
@@ -141986,17 +142177,12 @@ class Traversal {
|
|
|
141986
142177
|
let name = t.getStr().toLowerCase().replace(/^!/, "");
|
|
141987
142178
|
if (filename && this.isCurrentObjectFile(filename) === false) {
|
|
141988
142179
|
// the prefix is from a different object
|
|
141989
|
-
const
|
|
141990
|
-
if (
|
|
141991
|
-
|
|
141992
|
-
|
|
141993
|
-
|
|
141994
|
-
|
|
141995
|
-
}
|
|
141996
|
-
else {
|
|
141997
|
-
return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + name;
|
|
141998
|
-
}
|
|
141999
|
-
}
|
|
142180
|
+
const found = this.findObjectForFilename(filename);
|
|
142181
|
+
if (found instanceof abaplint.Objects.Interface) {
|
|
142182
|
+
return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + found.getName().toLowerCase() + "$" + name;
|
|
142183
|
+
}
|
|
142184
|
+
else if (found) {
|
|
142185
|
+
return Traversal.escapeNamespace(this.lookupClassOrInterface(found.getName(), t)) + "." + name;
|
|
142000
142186
|
}
|
|
142001
142187
|
}
|
|
142002
142188
|
const className = this.isStaticClassAttribute(t);
|
|
@@ -142261,12 +142447,7 @@ class Traversal {
|
|
|
142261
142447
|
isTypePool(token) {
|
|
142262
142448
|
const ref = this.findReadOrWriteReference(token);
|
|
142263
142449
|
if (ref?.getFilename().endsWith(".type.abap")) {
|
|
142264
|
-
|
|
142265
|
-
if (file === undefined) {
|
|
142266
|
-
return undefined;
|
|
142267
|
-
}
|
|
142268
|
-
const obj = this.reg.findObjectForFile(file);
|
|
142269
|
-
return obj?.getName();
|
|
142450
|
+
return this.findObjectForFilename(ref.getFilename())?.getName();
|
|
142270
142451
|
}
|
|
142271
142452
|
return undefined;
|
|
142272
142453
|
}
|
|
@@ -142706,8 +142887,7 @@ this.INTERNAL_ID = abap.internalIdCounter++;\n`;
|
|
|
142706
142887
|
findEnumValueIndex(identifier) {
|
|
142707
142888
|
// the enum can be declared in another object, eg. a global interface the class implements
|
|
142708
142889
|
const filename = identifier.getFilename();
|
|
142709
|
-
const
|
|
142710
|
-
const obj = raw === undefined ? undefined : this.reg.findObjectForFile(raw);
|
|
142890
|
+
const obj = this.findObjectForFilename(filename);
|
|
142711
142891
|
const file = obj instanceof abaplint.ABAPObject ? obj.getABAPFileByName(filename) : undefined;
|
|
142712
142892
|
for (const enumeration of file?.getStructure()?.findAllStructures(abaplint.Structures.TypeEnum) || []) {
|
|
142713
142893
|
const values = enumeration.getChildren().filter(c => c instanceof abaplint.Nodes.StatementNode
|
|
@@ -143093,49 +143273,167 @@ class TypeFactoryRegistry {
|
|
|
143093
143273
|
this.inProgress.delete(type);
|
|
143094
143274
|
}
|
|
143095
143275
|
}
|
|
143276
|
+
/** Matches every call to a factory of this module, the name is the match minus "()" */
|
|
143277
|
+
callPattern() {
|
|
143278
|
+
const prefix = ("$t_" + this.modulePrefix + "_").replace(/[$]/g, "\\$");
|
|
143279
|
+
return new RegExp(prefix + "\\d+\\(\\)", "g");
|
|
143280
|
+
}
|
|
143281
|
+
countCalls(text, into) {
|
|
143282
|
+
for (const match of text.matchAll(this.callPattern())) {
|
|
143283
|
+
const name = match[0].slice(0, -2);
|
|
143284
|
+
into.set(name, (into.get(name) ?? 0) + 1);
|
|
143285
|
+
}
|
|
143286
|
+
}
|
|
143096
143287
|
/** Inline factories whose declaration and calls cost more than their use-site
|
|
143097
|
-
* expressions. This keeps opting in safe for small, mostly unique modules.
|
|
143288
|
+
* expressions. This keeps opting in safe for small, mostly unique modules.
|
|
143289
|
+
*
|
|
143290
|
+
* Factories are considered in registration order and the first one worth
|
|
143291
|
+
* inlining is inlined, until none is left. Inlining a factory only changes the
|
|
143292
|
+
* use counts of the factories it calls and the sizes of the factories calling
|
|
143293
|
+
* it, so these are updated in place instead of recounting all text, and the
|
|
143294
|
+
* text itself is rewritten once at the end. */
|
|
143098
143295
|
finalize(body) {
|
|
143099
|
-
|
|
143100
|
-
|
|
143101
|
-
|
|
143102
|
-
|
|
143103
|
-
|
|
143104
|
-
|
|
143105
|
-
|
|
143106
|
-
|
|
143107
|
-
|
|
143108
|
-
|
|
143296
|
+
const states = new Map();
|
|
143297
|
+
const ordered = [];
|
|
143298
|
+
for (const factory of this.factories.values()) {
|
|
143299
|
+
const state = {
|
|
143300
|
+
factory,
|
|
143301
|
+
order: ordered.length,
|
|
143302
|
+
uses: 0,
|
|
143303
|
+
expressionBytes: this.utf8Bytes(factory.expression),
|
|
143304
|
+
callBytes: this.utf8Bytes(factory.name + "()"),
|
|
143305
|
+
declarationBytes: this.utf8Bytes("function " + factory.name + "() { return ; }\n"),
|
|
143306
|
+
children: new Map(),
|
|
143307
|
+
parents: new Set(),
|
|
143308
|
+
inlined: false,
|
|
143309
|
+
};
|
|
143310
|
+
states.set(factory.name, state);
|
|
143311
|
+
ordered.push(state);
|
|
143312
|
+
}
|
|
143313
|
+
const bodyCalls = new Map();
|
|
143314
|
+
this.countCalls(body.getCode(), bodyCalls);
|
|
143315
|
+
for (const [name, count] of bodyCalls) {
|
|
143316
|
+
const state = states.get(name);
|
|
143317
|
+
if (state !== undefined) {
|
|
143318
|
+
state.uses += count;
|
|
143319
|
+
}
|
|
143320
|
+
}
|
|
143321
|
+
for (const state of ordered) {
|
|
143322
|
+
const calls = new Map();
|
|
143323
|
+
this.countCalls(state.factory.expression, calls);
|
|
143324
|
+
for (const [name, count] of calls) {
|
|
143325
|
+
const child = states.get(name);
|
|
143326
|
+
if (child !== undefined && child !== state) {
|
|
143327
|
+
state.children.set(name, count);
|
|
143328
|
+
child.parents.add(state.factory.name);
|
|
143329
|
+
child.uses += count;
|
|
143330
|
+
}
|
|
143331
|
+
}
|
|
143332
|
+
}
|
|
143333
|
+
const shouldInline = (state) => {
|
|
143334
|
+
const inlineBytes = state.expressionBytes * state.uses;
|
|
143335
|
+
const helperBytes = state.declarationBytes + state.expressionBytes + state.callBytes * state.uses;
|
|
143336
|
+
return state.uses === 0 || helperBytes >= inlineBytes;
|
|
143337
|
+
};
|
|
143338
|
+
// min-heap of registration order, entries are validated when popped
|
|
143339
|
+
const heap = [];
|
|
143340
|
+
const push = (value) => {
|
|
143341
|
+
heap.push(value);
|
|
143342
|
+
let index = heap.length - 1;
|
|
143343
|
+
while (index > 0) {
|
|
143344
|
+
const parent = Math.floor((index - 1) / 2);
|
|
143345
|
+
if (heap[parent] <= value) {
|
|
143346
|
+
break;
|
|
143109
143347
|
}
|
|
143110
|
-
|
|
143111
|
-
|
|
143112
|
-
|
|
143113
|
-
|
|
143114
|
-
|
|
143115
|
-
|
|
143116
|
-
|
|
143117
|
-
|
|
143118
|
-
|
|
143348
|
+
heap[index] = heap[parent];
|
|
143349
|
+
index = parent;
|
|
143350
|
+
}
|
|
143351
|
+
heap[index] = value;
|
|
143352
|
+
};
|
|
143353
|
+
const pop = () => {
|
|
143354
|
+
const top = heap[0];
|
|
143355
|
+
const last = heap.pop();
|
|
143356
|
+
if (heap.length > 0) {
|
|
143357
|
+
let index = 0;
|
|
143358
|
+
while (true) {
|
|
143359
|
+
let child = index * 2 + 1;
|
|
143360
|
+
if (child >= heap.length) {
|
|
143361
|
+
break;
|
|
143119
143362
|
}
|
|
143120
|
-
|
|
143121
|
-
|
|
143122
|
-
|
|
143363
|
+
if (child + 1 < heap.length && heap[child + 1] < heap[child]) {
|
|
143364
|
+
child++;
|
|
143365
|
+
}
|
|
143366
|
+
if (heap[child] >= last) {
|
|
143367
|
+
break;
|
|
143368
|
+
}
|
|
143369
|
+
heap[index] = heap[child];
|
|
143370
|
+
index = child;
|
|
143123
143371
|
}
|
|
143372
|
+
heap[index] = last;
|
|
143373
|
+
}
|
|
143374
|
+
return top;
|
|
143375
|
+
};
|
|
143376
|
+
for (const state of ordered) {
|
|
143377
|
+
if (shouldInline(state)) {
|
|
143378
|
+
push(state.order);
|
|
143124
143379
|
}
|
|
143125
143380
|
}
|
|
143126
|
-
|
|
143127
|
-
|
|
143128
|
-
|
|
143129
|
-
|
|
143130
|
-
|
|
143131
|
-
|
|
143132
|
-
const
|
|
143133
|
-
|
|
143134
|
-
|
|
143381
|
+
while (heap.length > 0) {
|
|
143382
|
+
const state = ordered[pop()];
|
|
143383
|
+
if (state.inlined || !shouldInline(state)) {
|
|
143384
|
+
continue;
|
|
143385
|
+
}
|
|
143386
|
+
state.inlined = true;
|
|
143387
|
+
const name = state.factory.name;
|
|
143388
|
+
for (const parentName of state.parents) {
|
|
143389
|
+
const parent = states.get(parentName);
|
|
143390
|
+
const occurrences = parent.children.get(name);
|
|
143391
|
+
parent.children.delete(name);
|
|
143392
|
+
parent.expressionBytes += occurrences * (state.expressionBytes - state.callBytes);
|
|
143393
|
+
for (const [childName, count] of state.children) {
|
|
143394
|
+
parent.children.set(childName, (parent.children.get(childName) ?? 0) + occurrences * count);
|
|
143395
|
+
states.get(childName).parents.add(parentName);
|
|
143396
|
+
}
|
|
143397
|
+
}
|
|
143398
|
+
for (const [childName, count] of state.children) {
|
|
143399
|
+
const child = states.get(childName);
|
|
143400
|
+
child.uses += count * (state.uses - 1);
|
|
143401
|
+
child.parents.delete(name);
|
|
143402
|
+
}
|
|
143403
|
+
for (const affected of [...state.parents, ...state.children.keys()]) {
|
|
143404
|
+
const other = states.get(affected);
|
|
143405
|
+
if (shouldInline(other)) {
|
|
143406
|
+
push(other.order);
|
|
143407
|
+
}
|
|
143135
143408
|
}
|
|
143136
|
-
count++;
|
|
143137
|
-
cursor = index + search.length;
|
|
143138
143409
|
}
|
|
143410
|
+
// rewrite all text once, expanding inlined calls recursively
|
|
143411
|
+
const expanded = new Map();
|
|
143412
|
+
const expand = (text) => text.replace(this.callPattern(), call => {
|
|
143413
|
+
const state = states.get(call.slice(0, -2));
|
|
143414
|
+
if (state === undefined || state.inlined === false) {
|
|
143415
|
+
return call;
|
|
143416
|
+
}
|
|
143417
|
+
let result = expanded.get(state.factory.name);
|
|
143418
|
+
if (result === undefined) {
|
|
143419
|
+
result = expand(state.factory.expression);
|
|
143420
|
+
expanded.set(state.factory.name, result);
|
|
143421
|
+
}
|
|
143422
|
+
return result;
|
|
143423
|
+
});
|
|
143424
|
+
body.replaceMatches(this.callPattern(), match => {
|
|
143425
|
+
const state = states.get(match[0].slice(0, -2));
|
|
143426
|
+
return state?.inlined === true ? expand(match[0]) : undefined;
|
|
143427
|
+
});
|
|
143428
|
+
for (const [key, factory] of this.factories) {
|
|
143429
|
+
if (states.get(factory.name).inlined) {
|
|
143430
|
+
this.factories.delete(key);
|
|
143431
|
+
}
|
|
143432
|
+
else {
|
|
143433
|
+
factory.expression = expand(factory.expression);
|
|
143434
|
+
}
|
|
143435
|
+
}
|
|
143436
|
+
return this.render();
|
|
143139
143437
|
}
|
|
143140
143438
|
utf8Bytes(input) {
|
|
143141
143439
|
let bytes = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/transpiler-cli",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.32",
|
|
4
4
|
"description": "Transpiler - Command Line Interface",
|
|
5
5
|
"funding": "https://github.com/sponsors/larshp",
|
|
6
6
|
"bin": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"author": "abaplint",
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@abaplint/core": "^2.120.
|
|
31
|
-
"@abaplint/transpiler": "^2.14.
|
|
30
|
+
"@abaplint/core": "^2.120.105",
|
|
31
|
+
"@abaplint/transpiler": "^2.14.32",
|
|
32
32
|
"@types/glob": "^9.0.0",
|
|
33
33
|
"@types/node": "^26.6.6",
|
|
34
34
|
"@types/progress": "^2.0.7",
|