@abaplint/core 2.120.103 → 2.120.105
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/abaplint.d.ts +3 -0
- package/build/src/abap/5_syntax/statements/modify_internal.js +15 -7
- package/build/src/abap/5_syntax/syntax.js +2 -1
- package/build/src/files/raw_rows_cache.js +15 -0
- package/build/src/issue.js +3 -2
- package/build/src/registry.js +29 -11
- package/build/src/rules/_procedure_analysis.js +3 -12
- package/build/src/rules/downport.js +16 -4
- package/build/src/rules/static_call_via_instance.js +22 -8
- package/build/src/rules/unused_types.js +55 -26
- package/build/src/rules/unused_variables.js +53 -21
- package/package.json +1 -1
package/build/abaplint.d.ts
CHANGED
|
@@ -5958,6 +5958,8 @@ export declare class Registry implements IRegistry {
|
|
|
5958
5958
|
private objects;
|
|
5959
5959
|
private objectsByType;
|
|
5960
5960
|
private dependencies;
|
|
5961
|
+
/** upper case filename to object containing the file, kept in sync by add/remove methods */
|
|
5962
|
+
private filenameIndex;
|
|
5961
5963
|
private ddicReferences;
|
|
5962
5964
|
private msagReferences;
|
|
5963
5965
|
private macroReferences;
|
|
@@ -6005,6 +6007,7 @@ export declare class Registry implements IRegistry {
|
|
|
6005
6007
|
private isDirty;
|
|
6006
6008
|
private findOrCreate;
|
|
6007
6009
|
private removeObject;
|
|
6010
|
+
private unindexFile;
|
|
6008
6011
|
private find;
|
|
6009
6012
|
}
|
|
6010
6013
|
|
|
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ModifyInternal = void 0;
|
|
37
37
|
const Expressions = __importStar(require("../../2_statements/expressions"));
|
|
38
|
+
const nodes_1 = require("../../nodes");
|
|
38
39
|
const source_1 = require("../expressions/source");
|
|
39
40
|
const target_1 = require("../expressions/target");
|
|
40
41
|
const fstarget_1 = require("../expressions/fstarget");
|
|
@@ -43,15 +44,22 @@ const basic_1 = require("../../types/basic");
|
|
|
43
44
|
const _syntax_input_1 = require("../_syntax_input");
|
|
44
45
|
class ModifyInternal {
|
|
45
46
|
runSyntax(node, input) {
|
|
46
|
-
|
|
47
|
-
source_1.Source.runSyntax(s, input);
|
|
48
|
-
}
|
|
47
|
+
var _a;
|
|
49
48
|
// there is only one
|
|
50
49
|
const target = node.findFirstExpression(Expressions.Target);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
// it might be a dynamic target
|
|
51
|
+
const targetType = target ? target_1.Target.runSyntax(target, input) : undefined;
|
|
52
|
+
// the FROM work area has the row type of the table, used for inferring "#"
|
|
53
|
+
const rowType = targetType instanceof basic_1.TableType ? targetType.getRowType() : undefined;
|
|
54
|
+
const children = node.getChildren();
|
|
55
|
+
for (let i = 0; i < children.length; i++) {
|
|
56
|
+
const s = children[i];
|
|
57
|
+
if (s instanceof nodes_1.ExpressionNode && s.get() instanceof Expressions.Source) {
|
|
58
|
+
const isFrom = ((_a = children[i - 1]) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === "FROM";
|
|
59
|
+
source_1.Source.runSyntax(s, input, isFrom ? rowType : undefined);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (target) {
|
|
55
63
|
if (targetType instanceof basic_1.VoidType
|
|
56
64
|
|| targetType instanceof basic_1.AnyType
|
|
57
65
|
|| targetType instanceof basic_1.UnknownType) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCachedRawRows = getCachedRawRows;
|
|
4
|
+
const rowCache = new WeakMap();
|
|
5
|
+
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one,
|
|
6
|
+
* so the rows can be cached per file object. The result must not be modified */
|
|
7
|
+
function getCachedRawRows(file) {
|
|
8
|
+
let rows = rowCache.get(file);
|
|
9
|
+
if (rows === undefined) {
|
|
10
|
+
rows = file.getRawRows();
|
|
11
|
+
rowCache.set(file, rows);
|
|
12
|
+
}
|
|
13
|
+
return rows;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=raw_rows_cache.js.map
|
package/build/src/issue.js
CHANGED
|
@@ -4,11 +4,12 @@ exports.Issue = void 0;
|
|
|
4
4
|
const position_1 = require("./position");
|
|
5
5
|
const virtual_position_1 = require("./virtual_position");
|
|
6
6
|
const severity_1 = require("./severity");
|
|
7
|
+
const raw_rows_cache_1 = require("./files/raw_rows_cache");
|
|
7
8
|
class Issue {
|
|
8
9
|
//////////////////////////
|
|
9
10
|
static atRow(file, row, message, key, severity) {
|
|
10
11
|
const start = new position_1.Position(row, 1);
|
|
11
|
-
const end = new position_1.Position(row,
|
|
12
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
12
13
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
13
14
|
return new Issue({
|
|
14
15
|
filename: file.getFilename(),
|
|
@@ -24,7 +25,7 @@ class Issue {
|
|
|
24
25
|
}
|
|
25
26
|
static atPosition(file, start, message, key, severity, fix) {
|
|
26
27
|
const row = start.getRow();
|
|
27
|
-
const end = new position_1.Position(row,
|
|
28
|
+
const end = new position_1.Position(row, (0, raw_rows_cache_1.getCachedRawRows)(file)[row - 1].length + 1);
|
|
28
29
|
severity = severity !== null && severity !== void 0 ? severity : severity_1.Severity.Error;
|
|
29
30
|
return new Issue({
|
|
30
31
|
filename: file.getFilename(),
|
package/build/src/registry.js
CHANGED
|
@@ -61,6 +61,8 @@ class Registry {
|
|
|
61
61
|
this.objects = {};
|
|
62
62
|
this.objectsByType = {};
|
|
63
63
|
this.dependencies = {};
|
|
64
|
+
/** upper case filename to object containing the file, kept in sync by add/remove methods */
|
|
65
|
+
this.filenameIndex = new Map();
|
|
64
66
|
this.setConfig(conf ? conf : config_1.Config.getDefault());
|
|
65
67
|
this.clear();
|
|
66
68
|
}
|
|
@@ -69,13 +71,14 @@ class Registry {
|
|
|
69
71
|
this.objects = {};
|
|
70
72
|
this.objectsByType = {};
|
|
71
73
|
this.dependencies = {};
|
|
74
|
+
this.filenameIndex = new Map();
|
|
72
75
|
this.ddicReferences = new ddic_references_1.DDICReferences();
|
|
73
76
|
this.msagReferences = new msag_references_1.MSAGReferences();
|
|
74
77
|
this.macroReferences = new macro_references_1.MacroReferences();
|
|
75
78
|
}
|
|
76
79
|
static abaplintVersion() {
|
|
77
80
|
// magic, see build script "version.js"
|
|
78
|
-
return "2.120.
|
|
81
|
+
return "2.120.105";
|
|
79
82
|
}
|
|
80
83
|
getDDICReferences() {
|
|
81
84
|
return this.ddicReferences;
|
|
@@ -128,11 +131,13 @@ class Registry {
|
|
|
128
131
|
}
|
|
129
132
|
getFileByName(filename) {
|
|
130
133
|
const upper = filename.toUpperCase();
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
const obj = this.filenameIndex.get(upper);
|
|
135
|
+
if (obj === undefined) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
for (const f of obj.getFiles()) {
|
|
139
|
+
if (f.getFilename().toUpperCase() === upper) {
|
|
140
|
+
return f;
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
return undefined;
|
|
@@ -173,6 +178,7 @@ class Registry {
|
|
|
173
178
|
removeFile(file) {
|
|
174
179
|
const obj = this.find(file.getObjectName(), file.getObjectType());
|
|
175
180
|
obj.removeFile(file);
|
|
181
|
+
this.unindexFile(file.getFilename(), obj);
|
|
176
182
|
if (obj.getFiles().length === 0) {
|
|
177
183
|
this.ddicReferences.clear(obj);
|
|
178
184
|
this.msagReferences.clear(obj);
|
|
@@ -199,6 +205,7 @@ class Registry {
|
|
|
199
205
|
found = this.findOrCreate(f.getObjectName(), f.getObjectType());
|
|
200
206
|
}
|
|
201
207
|
found.addFile(f);
|
|
208
|
+
this.filenameIndex.set(filename.toUpperCase(), found);
|
|
202
209
|
}
|
|
203
210
|
return this;
|
|
204
211
|
}
|
|
@@ -267,11 +274,13 @@ class Registry {
|
|
|
267
274
|
// assumption: the file is already in the registry
|
|
268
275
|
findObjectForFile(file) {
|
|
269
276
|
const filename = file.getFilename();
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
277
|
+
const obj = this.filenameIndex.get(filename.toUpperCase());
|
|
278
|
+
if (obj === undefined) {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
for (const ofile of obj.getFiles()) {
|
|
282
|
+
if (ofile.getFilename() === filename) {
|
|
283
|
+
return obj;
|
|
275
284
|
}
|
|
276
285
|
}
|
|
277
286
|
return undefined;
|
|
@@ -363,6 +372,9 @@ class Registry {
|
|
|
363
372
|
if (this.objects[remove.getName()][remove.getType()] === undefined) {
|
|
364
373
|
throw new Error("removeObject: object not found");
|
|
365
374
|
}
|
|
375
|
+
for (const f of remove.getFiles()) {
|
|
376
|
+
this.unindexFile(f.getFilename(), remove);
|
|
377
|
+
}
|
|
366
378
|
if (Object.keys(this.objects[remove.getName()]).length === 1) {
|
|
367
379
|
delete this.objects[remove.getName()];
|
|
368
380
|
}
|
|
@@ -376,6 +388,12 @@ class Registry {
|
|
|
376
388
|
delete this.objectsByType[remove.getType()][remove.getName()];
|
|
377
389
|
}
|
|
378
390
|
}
|
|
391
|
+
unindexFile(filename, obj) {
|
|
392
|
+
const upper = filename.toUpperCase();
|
|
393
|
+
if (this.filenameIndex.get(upper) === obj) {
|
|
394
|
+
this.filenameIndex.delete(upper);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
379
397
|
find(name, type) {
|
|
380
398
|
const searchType = type ? type : "UNKNOWN";
|
|
381
399
|
const searchName = name.toUpperCase();
|
|
@@ -75,6 +75,7 @@ const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
|
75
75
|
const tokens_1 = require("../abap/1_lexer/tokens");
|
|
76
76
|
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
77
77
|
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
78
|
+
const raw_rows_cache_1 = require("../files/raw_rows_cache");
|
|
78
79
|
const nodes_1 = require("../abap/nodes");
|
|
79
80
|
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
80
81
|
const basic_1 = require("../abap/types/basic");
|
|
@@ -1381,16 +1382,6 @@ class Hierarchy {
|
|
|
1381
1382
|
exports.Hierarchy = Hierarchy;
|
|
1382
1383
|
////////////////////////////////////////
|
|
1383
1384
|
// edits
|
|
1384
|
-
const rowCache = new WeakMap();
|
|
1385
|
-
/** getRawRows() splits the source on every call; a file is never changed, edits create a new one */
|
|
1386
|
-
function rowsOf(file) {
|
|
1387
|
-
let rows = rowCache.get(file);
|
|
1388
|
-
if (rows === undefined) {
|
|
1389
|
-
rows = file.getRawRows();
|
|
1390
|
-
rowCache.set(file, rows);
|
|
1391
|
-
}
|
|
1392
|
-
return rows;
|
|
1393
|
-
}
|
|
1394
1385
|
/** edits of one fix, sorted so that applying them one after the other keeps the positions valid */
|
|
1395
1386
|
function mergeEdits(file, edits) {
|
|
1396
1387
|
const list = [];
|
|
@@ -1410,7 +1401,7 @@ function deleteRegion(file, first, last) {
|
|
|
1410
1401
|
if (first === last && first.getColon() !== undefined) {
|
|
1411
1402
|
return edit_helper_1.EditHelper.deleteStatement(file, first);
|
|
1412
1403
|
}
|
|
1413
|
-
const rows =
|
|
1404
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
1414
1405
|
const start = first.getStart();
|
|
1415
1406
|
const end = last.getEnd();
|
|
1416
1407
|
const before = rows[start.getRow() - 1].substring(0, start.getCol() - 1);
|
|
@@ -1425,7 +1416,7 @@ function deleteStatement(file, statement) {
|
|
|
1425
1416
|
}
|
|
1426
1417
|
/** the source code between two positions, as written */
|
|
1427
1418
|
function rawText(file, start, end) {
|
|
1428
|
-
const rows =
|
|
1419
|
+
const rows = (0, raw_rows_cache_1.getCachedRawRows)(file);
|
|
1429
1420
|
if (start.getRow() === end.getRow()) {
|
|
1430
1421
|
return rows[start.getRow() - 1].substring(start.getCol() - 1, end.getCol() - 1);
|
|
1431
1422
|
}
|
|
@@ -264,8 +264,23 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
264
264
|
}
|
|
265
265
|
highSyntaxObj = this.highReg.findObjectForFile(f);
|
|
266
266
|
}
|
|
267
|
+
// the syntax run is expensive and most statements need no downport, so run it on first use
|
|
268
|
+
let computedSyntax = undefined;
|
|
269
|
+
const runHighSyntax = () => {
|
|
270
|
+
if (computedSyntax === undefined) {
|
|
271
|
+
computedSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
272
|
+
}
|
|
273
|
+
return computedSyntax;
|
|
274
|
+
};
|
|
275
|
+
const highSyntax = {
|
|
276
|
+
get issues() {
|
|
277
|
+
return runHighSyntax().issues;
|
|
278
|
+
},
|
|
279
|
+
get spaghetti() {
|
|
280
|
+
return runHighSyntax().spaghetti;
|
|
281
|
+
},
|
|
282
|
+
};
|
|
267
283
|
for (const lowFile of lowObj.getABAPFiles()) {
|
|
268
|
-
let highSyntax = undefined;
|
|
269
284
|
const highFile = highObj.getABAPFileByName(lowFile.getFilename());
|
|
270
285
|
if (highFile === undefined) {
|
|
271
286
|
continue;
|
|
@@ -284,9 +299,6 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
284
299
|
// actively editing the files
|
|
285
300
|
continue;
|
|
286
301
|
}
|
|
287
|
-
if (highSyntax === undefined) {
|
|
288
|
-
highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
289
|
-
}
|
|
290
302
|
let containsUnknown = false;
|
|
291
303
|
const notDownported = [];
|
|
292
304
|
for (let i = 0; i < lowStatements.length; i++) {
|
|
@@ -9,6 +9,8 @@ const _irule_1 = require("./_irule");
|
|
|
9
9
|
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
10
10
|
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
11
11
|
const types_1 = require("../abap/types");
|
|
12
|
+
const position_1 = require("../position");
|
|
13
|
+
const virtual_position_1 = require("../virtual_position");
|
|
12
14
|
class StaticCallViaInstanceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
13
15
|
constructor() {
|
|
14
16
|
super(...arguments);
|
|
@@ -48,24 +50,36 @@ ENDMETHOD.`,
|
|
|
48
50
|
if (this.getConfig().allowInTestclassIncludes === true && file.getFilename().includes(".testclasses.")) {
|
|
49
51
|
return [];
|
|
50
52
|
}
|
|
51
|
-
const staticMethodCalls =
|
|
53
|
+
const staticMethodCalls = new Set();
|
|
54
|
+
for (const s of this.listMethodCalls(file.getFilename(), new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti.getTop())) {
|
|
55
|
+
staticMethodCalls.add(StaticCallViaInstance.positionKey(s));
|
|
56
|
+
}
|
|
57
|
+
if (staticMethodCalls.size === 0) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
52
60
|
const tokens = file.getTokens();
|
|
53
61
|
for (let i = 0; i < tokens.length - 1; i++) {
|
|
54
62
|
const token = tokens[i];
|
|
55
63
|
if (token.getStr() !== "->") {
|
|
56
64
|
continue;
|
|
57
65
|
}
|
|
58
|
-
const next = tokens[i + 1];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
const next = tokens[i + 1].getStart();
|
|
67
|
+
// a plain reference position also matches a token inside a macro call at the same row and column
|
|
68
|
+
if (staticMethodCalls.has(StaticCallViaInstance.positionKey(next))
|
|
69
|
+
|| (next instanceof virtual_position_1.VirtualPosition
|
|
70
|
+
&& staticMethodCalls.has(StaticCallViaInstance.positionKey(new position_1.Position(next.getRow(), next.getCol()))))) {
|
|
71
|
+
const message = "Avoid calling static method via instance";
|
|
72
|
+
issues.push(issue_1.Issue.atToken(file, token, message, this.getMetadata().key));
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
return issues;
|
|
68
76
|
}
|
|
77
|
+
static positionKey(p) {
|
|
78
|
+
if (p instanceof virtual_position_1.VirtualPosition) {
|
|
79
|
+
return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
|
|
80
|
+
}
|
|
81
|
+
return p.getRow() + ":" + p.getCol();
|
|
82
|
+
}
|
|
69
83
|
listMethodCalls(filename, node) {
|
|
70
84
|
const ret = [];
|
|
71
85
|
for (const r of node.getData().references) {
|
|
@@ -10,31 +10,40 @@ const _scope_type_1 = require("../abap/5_syntax/_scope_type");
|
|
|
10
10
|
const edit_helper_1 = require("../edit_helper");
|
|
11
11
|
const _reference_1 = require("../abap/5_syntax/_reference");
|
|
12
12
|
const _statement_1 = require("../abap/2_statements/statements/_statement");
|
|
13
|
+
const virtual_position_1 = require("../virtual_position");
|
|
13
14
|
class WorkArea {
|
|
14
15
|
constructor() {
|
|
15
|
-
|
|
16
|
+
// keyed by identifier position, insertion order is kept
|
|
17
|
+
this.workarea = new Map();
|
|
16
18
|
}
|
|
17
19
|
push(id) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
const key = WorkArea.buildKey(id);
|
|
21
|
+
if (this.workarea.has(key) === false) {
|
|
22
|
+
this.workarea.set(key, id);
|
|
22
23
|
}
|
|
23
|
-
this.workarea.push(id);
|
|
24
24
|
}
|
|
25
25
|
removeIfExists(id) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
this.workarea.delete(WorkArea.buildKey(id));
|
|
27
|
+
}
|
|
28
|
+
/** removes the identifiers referenced somewhere */
|
|
29
|
+
removeReferenced(referenced) {
|
|
30
|
+
for (const key of [...this.workarea.keys()]) {
|
|
31
|
+
if (referenced.has(key)) {
|
|
32
|
+
this.workarea.delete(key);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
}
|
|
33
36
|
get() {
|
|
34
|
-
return this.workarea;
|
|
37
|
+
return [...this.workarea.values()];
|
|
35
38
|
}
|
|
36
39
|
count() {
|
|
37
|
-
return this.workarea.
|
|
40
|
+
return this.workarea.size;
|
|
41
|
+
}
|
|
42
|
+
/** identifiers from one macro call share the row and column, the virtual position tells them apart */
|
|
43
|
+
static buildKey(id) {
|
|
44
|
+
const start = id.getStart();
|
|
45
|
+
const key = id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
46
|
+
return start instanceof virtual_position_1.VirtualPosition ? key + "," + start.vrow + "," + start.vcol : key;
|
|
38
47
|
}
|
|
39
48
|
}
|
|
40
49
|
class UnusedTypesConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
@@ -50,6 +59,8 @@ exports.UnusedTypesConf = UnusedTypesConf;
|
|
|
50
59
|
class UnusedTypes {
|
|
51
60
|
constructor() {
|
|
52
61
|
this.conf = new UnusedTypesConf();
|
|
62
|
+
/** keys of the identifiers with a type reference in any object, built once per run when needed */
|
|
63
|
+
this.referenced = undefined;
|
|
53
64
|
}
|
|
54
65
|
getMetadata() {
|
|
55
66
|
return {
|
|
@@ -73,6 +84,7 @@ class UnusedTypes {
|
|
|
73
84
|
}
|
|
74
85
|
initialize(reg) {
|
|
75
86
|
this.reg = reg;
|
|
87
|
+
this.referenced = undefined;
|
|
76
88
|
return this;
|
|
77
89
|
}
|
|
78
90
|
run(obj) {
|
|
@@ -97,20 +109,10 @@ class UnusedTypes {
|
|
|
97
109
|
if (this.workarea.count() === 0) {
|
|
98
110
|
return []; // exit early if all types are used in the current object
|
|
99
111
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
else if (o instanceof _abap_object_1.ABAPObject) {
|
|
105
|
-
if (this.reg.isDependency(o)) {
|
|
106
|
-
continue; // do not search in dependencies
|
|
107
|
-
}
|
|
108
|
-
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
109
|
-
this.traverse(syntax.spaghetti.getTop(), o, false);
|
|
110
|
-
}
|
|
111
|
-
if (this.workarea.count() === 0) {
|
|
112
|
-
return []; // exit early if all types are used
|
|
113
|
-
}
|
|
112
|
+
// uses in other objects, collected once instead of searching all objects for each object
|
|
113
|
+
this.workarea.removeReferenced(this.getReferenced());
|
|
114
|
+
if (this.workarea.count() === 0) {
|
|
115
|
+
return []; // exit early if all types are used
|
|
114
116
|
}
|
|
115
117
|
// what is left is unused
|
|
116
118
|
const ret = [];
|
|
@@ -154,6 +156,33 @@ class UnusedTypes {
|
|
|
154
156
|
return false;
|
|
155
157
|
}
|
|
156
158
|
////////////////////////////
|
|
159
|
+
getReferenced() {
|
|
160
|
+
if (this.referenced === undefined) {
|
|
161
|
+
const referenced = new Set();
|
|
162
|
+
for (const o of this.reg.getObjects()) {
|
|
163
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
164
|
+
continue; // do not search in dependencies
|
|
165
|
+
}
|
|
166
|
+
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
167
|
+
this.collectReferenced(syntax.spaghetti.getTop(), referenced);
|
|
168
|
+
}
|
|
169
|
+
this.referenced = referenced;
|
|
170
|
+
}
|
|
171
|
+
return this.referenced;
|
|
172
|
+
}
|
|
173
|
+
/** same nodes and references as checkNode() with add = false */
|
|
174
|
+
collectReferenced(node, referenced) {
|
|
175
|
+
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
176
|
+
for (const r of node.getData().references) {
|
|
177
|
+
if (r.referenceType === _reference_1.ReferenceType.TypeReference && r.resolved) {
|
|
178
|
+
referenced.add(WorkArea.buildKey(r.resolved));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
for (const c of node.getChildren()) {
|
|
183
|
+
this.collectReferenced(c, referenced);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
157
186
|
traverse(node, obj, add) {
|
|
158
187
|
if (node.getIdentifier().stype !== _scope_type_1.ScopeType.BuiltIn) {
|
|
159
188
|
this.checkNode(node, obj, add);
|
|
@@ -63,17 +63,17 @@ class WorkArea {
|
|
|
63
63
|
this.workarea = new Map();
|
|
64
64
|
}
|
|
65
65
|
push(id, count = 1) {
|
|
66
|
-
const key =
|
|
66
|
+
const key = WorkArea.buildKey(id);
|
|
67
67
|
if (this.workarea.has(key)) {
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
-
this.workarea.set(key, { id, count });
|
|
70
|
+
this.workarea.set(key, { id, count, required: count });
|
|
71
71
|
}
|
|
72
72
|
removeIfExists(id) {
|
|
73
73
|
if (id === undefined) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
const key =
|
|
76
|
+
const key = WorkArea.buildKey(id);
|
|
77
77
|
const found = this.workarea.get(key);
|
|
78
78
|
if (found !== undefined) {
|
|
79
79
|
found.count--;
|
|
@@ -82,13 +82,23 @@ class WorkArea {
|
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
/** removes the identifiers with enough references, counts include all objects, also the one the
|
|
86
|
+
* identifiers belong to, so it is compared to the required count and not the remaining count */
|
|
87
|
+
removeReferenced(counts) {
|
|
88
|
+
var _a;
|
|
89
|
+
for (const [key, entry] of this.workarea) {
|
|
90
|
+
if (((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) >= entry.required) {
|
|
91
|
+
this.workarea.delete(key);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
85
95
|
get() {
|
|
86
96
|
return [...this.workarea.values()];
|
|
87
97
|
}
|
|
88
98
|
count() {
|
|
89
99
|
return this.workarea.size;
|
|
90
100
|
}
|
|
91
|
-
buildKey(id) {
|
|
101
|
+
static buildKey(id) {
|
|
92
102
|
const start = id.getStart();
|
|
93
103
|
return id.getFilename() + "," + start.getRow() + "," + start.getCol();
|
|
94
104
|
}
|
|
@@ -96,6 +106,8 @@ class WorkArea {
|
|
|
96
106
|
class UnusedVariables {
|
|
97
107
|
constructor() {
|
|
98
108
|
this.conf = new UnusedVariablesConf();
|
|
109
|
+
/** read, write and type references per identifier key in all objects, built once per run when needed */
|
|
110
|
+
this.referenceCounts = undefined;
|
|
99
111
|
}
|
|
100
112
|
getMetadata() {
|
|
101
113
|
return {
|
|
@@ -133,6 +145,7 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
133
145
|
}
|
|
134
146
|
initialize(reg) {
|
|
135
147
|
this.reg = reg;
|
|
148
|
+
this.referenceCounts = undefined;
|
|
136
149
|
return this;
|
|
137
150
|
}
|
|
138
151
|
run(obj) {
|
|
@@ -160,34 +173,53 @@ Errors found in INCLUDES are reported for the main program.`,
|
|
|
160
173
|
if (this.workarea.count() === 0) {
|
|
161
174
|
return this.buildIssues(obj); // exit early if all variables are used
|
|
162
175
|
}
|
|
163
|
-
this.findUses(top
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
176
|
+
this.findUses(top);
|
|
177
|
+
if (this.workarea.count() === 0) {
|
|
178
|
+
return this.buildIssues(obj); // exit early if all variables are used
|
|
179
|
+
}
|
|
180
|
+
// uses in other objects, the counts are built once instead of searching all objects for each object
|
|
181
|
+
this.workarea.removeReferenced(this.getReferenceCounts());
|
|
182
|
+
return this.buildIssues(obj);
|
|
183
|
+
}
|
|
184
|
+
getReferenceCounts() {
|
|
185
|
+
if (this.referenceCounts === undefined) {
|
|
186
|
+
const counts = new Map();
|
|
187
|
+
for (const o of this.reg.getObjects()) {
|
|
188
|
+
if (!(o instanceof _abap_object_1.ABAPObject) || this.reg.isDependency(o)) {
|
|
170
189
|
continue; // do not search in dependencies
|
|
171
190
|
}
|
|
172
191
|
const syntax = new syntax_1.SyntaxLogic(this.reg, o).run();
|
|
173
|
-
this.
|
|
174
|
-
if (this.workarea.count() === 0) {
|
|
175
|
-
return this.buildIssues(obj); // exit early if all variables are used
|
|
176
|
-
}
|
|
192
|
+
this.countUses(syntax.spaghetti.getTop(), counts);
|
|
177
193
|
}
|
|
194
|
+
this.referenceCounts = counts;
|
|
178
195
|
}
|
|
179
|
-
return this.
|
|
196
|
+
return this.referenceCounts;
|
|
180
197
|
}
|
|
181
|
-
|
|
198
|
+
static isUse(r) {
|
|
199
|
+
return r.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
200
|
+
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
201
|
+
|| r.referenceType === _reference_1.ReferenceType.TypeReference;
|
|
202
|
+
}
|
|
203
|
+
findUses(node) {
|
|
182
204
|
for (const r of node.getData().references) {
|
|
183
|
-
if (r
|
|
184
|
-
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference
|
|
185
|
-
|| r.referenceType === _reference_1.ReferenceType.TypeReference) {
|
|
205
|
+
if (UnusedVariables.isUse(r)) {
|
|
186
206
|
this.workarea.removeIfExists(r.resolved);
|
|
187
207
|
}
|
|
188
208
|
}
|
|
189
209
|
for (const c of node.getChildren()) {
|
|
190
|
-
this.findUses(c
|
|
210
|
+
this.findUses(c);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
countUses(node, counts) {
|
|
214
|
+
var _a;
|
|
215
|
+
for (const r of node.getData().references) {
|
|
216
|
+
if (r.resolved !== undefined && UnusedVariables.isUse(r)) {
|
|
217
|
+
const key = WorkArea.buildKey(r.resolved);
|
|
218
|
+
counts.set(key, ((_a = counts.get(key)) !== null && _a !== void 0 ? _a : 0) + 1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const c of node.getChildren()) {
|
|
222
|
+
this.countUses(c, counts);
|
|
191
223
|
}
|
|
192
224
|
}
|
|
193
225
|
buildWorkarea(node, obj) {
|