@abaplint/core 2.120.109 → 2.120.111
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 +24 -0
- package/build/src/abap/2_statements/statements/authority_check.js +1 -1
- package/build/src/abap/2_statements/statements/commit.js +1 -1
- package/build/src/abap/2_statements/statements/convert.js +2 -2
- package/build/src/abap/2_statements/statements/do.js +2 -1
- package/build/src/abap/2_statements/statements/exit.js +2 -1
- package/build/src/abap/2_statements/statements/get_time.js +3 -2
- package/build/src/abap/2_statements/statements/perform.js +1 -1
- package/build/src/abap/2_statements/statements/rollback.js +1 -1
- package/build/src/abap/2_statements/statements/wait.js +1 -1
- package/build/src/abap/5_syntax/_current_scope.js +64 -0
- package/build/src/abap/5_syntax/expressions/for.js +38 -4
- package/build/src/abap/5_syntax/expressions/inline_field_definition.js +2 -2
- package/build/src/abap/5_syntax/expressions/inline_loop_definition.js +18 -3
- package/build/src/abap/5_syntax/expressions/loop_group_by.js +123 -13
- package/build/src/abap/5_syntax/expressions/select.js +34 -2
- package/build/src/abap/5_syntax/statements/loop.js +12 -1
- package/build/src/abap/5_syntax/statements/move.js +8 -0
- package/build/src/abap/5_syntax/syntax.js +7 -0
- package/build/src/abap/types/event_definition.js +12 -0
- package/build/src/abap/types/function_module_definition.js +16 -0
- package/build/src/registry.js +1 -1
- package/build/src/rules/downport.js +5 -0
- package/build/src/rules/function_module_parameter_names.js +139 -0
- package/build/src/rules/index.js +4 -0
- package/build/src/rules/sort_required.js +487 -0
- package/build/src/rules/suspicious_loop.js +333 -0
- package/build/src/rules/unhandled_classic_exception.js +278 -0
- package/package.json +2 -2
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.SortRequired = exports.SortRequiredConf = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../abap/2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../abap/2_statements/statements"));
|
|
39
|
+
const _basic_rule_config_1 = require("./_basic_rule_config");
|
|
40
|
+
const issue_1 = require("../issue");
|
|
41
|
+
const _irule_1 = require("./_irule");
|
|
42
|
+
const syntax_1 = require("../abap/5_syntax/syntax");
|
|
43
|
+
const _abap_object_1 = require("../objects/_abap_object");
|
|
44
|
+
const basic_1 = require("../abap/types/basic");
|
|
45
|
+
const nodes_1 = require("../abap/nodes");
|
|
46
|
+
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
|
|
47
|
+
const severity_1 = require("../severity");
|
|
48
|
+
class SortRequiredConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(...arguments);
|
|
51
|
+
this.severity = severity_1.Severity.Warning;
|
|
52
|
+
/** Check READ TABLE ... WITH KEY ... BINARY SEARCH */
|
|
53
|
+
this.binarySearch = true;
|
|
54
|
+
/** Check DELETE ADJACENT DUPLICATES ... COMPARING */
|
|
55
|
+
this.adjacentDuplicates = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.SortRequiredConf = SortRequiredConf;
|
|
59
|
+
/** what a statement that writes the table does to its order */
|
|
60
|
+
var Fill;
|
|
61
|
+
(function (Fill) {
|
|
62
|
+
/** SELECT without ORDER BY, or APPEND, INSERT or COLLECT in such a SELECT loop: rows in no defined order */
|
|
63
|
+
Fill[Fill["unordered"] = 0] = "unordered";
|
|
64
|
+
/** CLEAR, DELETE, MODIFY, SORT, and APPEND, INSERT or COLLECT elsewhere: the code can add the rows in order */
|
|
65
|
+
Fill[Fill["none"] = 1] = "none";
|
|
66
|
+
/** anything else: the rows can come sorted from elsewhere */
|
|
67
|
+
Fill[Fill["unknown"] = 2] = "unknown";
|
|
68
|
+
})(Fill || (Fill = {}));
|
|
69
|
+
class SortRequired {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.conf = new SortRequiredConf();
|
|
72
|
+
}
|
|
73
|
+
getMetadata() {
|
|
74
|
+
return {
|
|
75
|
+
key: "sort_required",
|
|
76
|
+
title: "BINARY SEARCH or DELETE ADJACENT DUPLICATES without a matching SORT",
|
|
77
|
+
shortDescription: `BINARY SEARCH or DELETE ADJACENT DUPLICATES ... COMPARING on a local table not sorted by those fields`,
|
|
78
|
+
extendedInformation: `READ TABLE ... WITH KEY ... BINARY SEARCH only finds the row when the table is sorted ascending by
|
|
79
|
+
the key fields, in the order of the key. DELETE ADJACENT DUPLICATES ... COMPARING only removes all duplicates
|
|
80
|
+
when rows with equal values in the compared fields are next to each other. Neither statement checks the order:
|
|
81
|
+
on an unsorted table they give wrong results, without a dump.
|
|
82
|
+
|
|
83
|
+
Checked: a standard table declared with DATA in the method, form or function module, read with WITH KEY
|
|
84
|
+
and BINARY SEARCH, or with DELETE ADJACENT DUPLICATES ... COMPARING. Reported when
|
|
85
|
+
- the last SORT of the table before the statement is not by the key fields: for BINARY SEARCH they must be
|
|
86
|
+
the first sort fields, in the same order and ascending; for COMPARING the first sort fields must be the
|
|
87
|
+
compared fields, in any order. A SORT without BY uses the primary key.
|
|
88
|
+
- there is no SORT of the table before the statement, and it is filled by a SELECT without ORDER BY: the
|
|
89
|
+
database returns the rows in no defined order.
|
|
90
|
+
|
|
91
|
+
Not reported: parameters, attributes, global and static variables, a table that can get its rows sorted
|
|
92
|
+
from elsewhere (an assignment, a method or function call, APPEND or INSERT LINES OF, SELECT ... ORDER BY)
|
|
93
|
+
after the SORT or, without a SORT, anywhere in the procedure, a table without SORT filled only by APPEND,
|
|
94
|
+
INSERT or COLLECT (the code can add the rows in order), sorted and hashed tables, SORT with STABLE or with
|
|
95
|
+
dynamic fields, a SORT later in a loop around the statement, a SORT without BY on a default key of a
|
|
96
|
+
structured row, WITH TABLE KEY, USING KEY, dynamic components and COMPARING ALL FIELDS.
|
|
97
|
+
See also sort_empty_key and sequential_read_sorted.`,
|
|
98
|
+
tags: [_irule_1.RuleTag.SingleFile],
|
|
99
|
+
badExample: `SORT lt_titles BY id.
|
|
100
|
+
DELETE ADJACENT DUPLICATES FROM lt_titles COMPARING spras id.
|
|
101
|
+
SELECT * FROM tadir INTO TABLE lt_tadir WHERE devclass = lv_package.
|
|
102
|
+
READ TABLE lt_tadir WITH KEY object = lv_type obj_name = lv_name BINARY SEARCH TRANSPORTING NO FIELDS.`,
|
|
103
|
+
goodExample: `SORT lt_titles BY spras id.
|
|
104
|
+
DELETE ADJACENT DUPLICATES FROM lt_titles COMPARING spras id.
|
|
105
|
+
SELECT * FROM tadir INTO TABLE lt_tadir WHERE devclass = lv_package.
|
|
106
|
+
SORT lt_tadir BY object obj_name.
|
|
107
|
+
READ TABLE lt_tadir WITH KEY object = lv_type obj_name = lv_name BINARY SEARCH TRANSPORTING NO FIELDS.`,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
getConfig() {
|
|
111
|
+
return this.conf;
|
|
112
|
+
}
|
|
113
|
+
initialize(reg) {
|
|
114
|
+
this.reg = reg;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
setConfig(conf) {
|
|
118
|
+
this.conf = conf;
|
|
119
|
+
}
|
|
120
|
+
run(obj) {
|
|
121
|
+
if (!(obj instanceof _abap_object_1.ABAPObject) || obj.getType() === "INTF") {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const issues = [];
|
|
125
|
+
let spaghetti = undefined;
|
|
126
|
+
for (const file of obj.getABAPFiles()) {
|
|
127
|
+
const statements = file.getStatements();
|
|
128
|
+
for (let i = 0; i < statements.length; i++) {
|
|
129
|
+
const statement = statements[i];
|
|
130
|
+
let table;
|
|
131
|
+
let fields;
|
|
132
|
+
let binary;
|
|
133
|
+
if (statement.get() instanceof Statements.ReadTable && this.conf.binarySearch !== false) {
|
|
134
|
+
binary = true;
|
|
135
|
+
table = statement.getChildren().find(c => c instanceof nodes_1.ExpressionNode);
|
|
136
|
+
fields = this.readKey(statement);
|
|
137
|
+
}
|
|
138
|
+
else if (statement.get() instanceof Statements.DeleteInternal && this.conf.adjacentDuplicates !== false) {
|
|
139
|
+
binary = false;
|
|
140
|
+
table = statement.findDirectExpression(Expressions.Target);
|
|
141
|
+
fields = this.comparing(statement);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (table === undefined || fields === undefined || /^[\w/]+$/.test(table.concatTokens()) === false) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
const name = table.concatTokens().toUpperCase();
|
|
150
|
+
const start = this.procedureStart(i, statements);
|
|
151
|
+
if (start === undefined) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
const end = this.procedureEnd(i, statements);
|
|
155
|
+
if (spaghetti === undefined) {
|
|
156
|
+
spaghetti = new syntax_1.SyntaxLogic(this.reg, obj).run().spaghetti;
|
|
157
|
+
}
|
|
158
|
+
const id = this.findReference(table, spaghetti, file);
|
|
159
|
+
const declaration = id === undefined ? undefined : this.findDeclaration(id, file, statements, start, i);
|
|
160
|
+
const type = id === null || id === void 0 ? void 0 : id.getType();
|
|
161
|
+
if (declaration === undefined || !(type instanceof basic_1.TableType) || this.isStandard(type, declaration) === false) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
const verb = binary ? "READ TABLE ... BINARY SEARCH" : "DELETE ADJACENT DUPLICATES ... COMPARING";
|
|
165
|
+
const sortIndex = this.previousSort(name, statements, start, i);
|
|
166
|
+
let message = undefined;
|
|
167
|
+
if (sortIndex !== undefined) {
|
|
168
|
+
const sortFields = this.sortFields(statements[sortIndex], type);
|
|
169
|
+
if (sortFields !== undefined
|
|
170
|
+
&& this.matches(sortFields, fields, binary) === false
|
|
171
|
+
&& this.writtenUnknown(name, statements, sortIndex, i) === false) {
|
|
172
|
+
const by = sortFields.map(f => f.name.toLowerCase() + (f.descending ? " DESCENDING" : "")).join(" ");
|
|
173
|
+
message = `${verb} on ${table.concatTokens()} needs it sorted by ${fields.join(" ").toLowerCase()}, `
|
|
174
|
+
+ `the SORT before is by ${by}`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (this.sortedLaterInLoop(name, statements, start, i) === false
|
|
178
|
+
&& this.writtenUnknown(name, statements, start, end) === false
|
|
179
|
+
&& this.filledUnordered(name, statements, start, end) === true) {
|
|
180
|
+
message = `${verb} on ${table.concatTokens()} needs it sorted by ${fields.join(" ").toLowerCase()}, `
|
|
181
|
+
+ `there is no SORT before`;
|
|
182
|
+
}
|
|
183
|
+
if (message !== undefined) {
|
|
184
|
+
issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return issues;
|
|
189
|
+
}
|
|
190
|
+
////////////////
|
|
191
|
+
/** the components of WITH KEY, for a READ TABLE ... BINARY SEARCH with a free key */
|
|
192
|
+
readKey(statement) {
|
|
193
|
+
if (statement.findDirectTokenByText("BINARY") === undefined
|
|
194
|
+
|| statement.findDirectTokenByText("USING") !== undefined
|
|
195
|
+
|| statement.findDirectTokenByText("COMPONENTS") !== undefined) {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
const tokens = statement.getTokens().map(t => t.getStr().toUpperCase());
|
|
199
|
+
const withKey = tokens.findIndex((t, index) => t === "WITH" && tokens[index + 1] === "KEY");
|
|
200
|
+
const compare = statement.findDirectExpression(Expressions.ComponentCompareSimple);
|
|
201
|
+
if (withKey < 0 || compare === undefined || compare.findDirectExpression(Expressions.Dynamic) !== undefined) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
return compare.findDirectExpressions(Expressions.ComponentChainSimple).map(c => c.concatTokens().toUpperCase());
|
|
205
|
+
}
|
|
206
|
+
/** the fields after COMPARING, for a DELETE ADJACENT DUPLICATES with static fields */
|
|
207
|
+
comparing(statement) {
|
|
208
|
+
if (statement.findDirectTokenByText("ADJACENT") === undefined
|
|
209
|
+
|| statement.findDirectTokenByText("USING") !== undefined
|
|
210
|
+
|| statement.findDirectTokenByText("ALL") !== undefined
|
|
211
|
+
|| statement.findDirectTokenByText("COMPARING") === undefined
|
|
212
|
+
|| statement.findDirectExpression(Expressions.Dynamic) !== undefined
|
|
213
|
+
|| statement.findDirectExpression(Expressions.FieldOffset) !== undefined
|
|
214
|
+
|| statement.findDirectExpression(Expressions.FieldLength) !== undefined) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
return statement.findDirectExpressions(Expressions.SimpleFieldChain2).map(c => c.concatTokens().toUpperCase());
|
|
218
|
+
}
|
|
219
|
+
/** the sort fields of a SORT, undefined when not known */
|
|
220
|
+
sortFields(statement, type) {
|
|
221
|
+
var _a;
|
|
222
|
+
if (statement.findDirectTokenByText("STABLE") !== undefined
|
|
223
|
+
|| statement.findDirectExpression(Expressions.Dynamic) !== undefined
|
|
224
|
+
|| statement.findDirectExpression(Expressions.SourceFieldSymbol) !== undefined) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
const children = statement.getChildren();
|
|
228
|
+
const by = children.findIndex(c => c.concatTokens().toUpperCase() === "BY");
|
|
229
|
+
const descending = children.slice(0, by < 0 ? children.length : by)
|
|
230
|
+
.some(c => c.concatTokens().toUpperCase() === "DESCENDING");
|
|
231
|
+
if (by < 0) {
|
|
232
|
+
return (_a = this.primaryKey(type)) === null || _a === void 0 ? void 0 : _a.map(name => ({ name, descending }));
|
|
233
|
+
}
|
|
234
|
+
const result = [];
|
|
235
|
+
for (let j = by + 1; j < children.length; j++) {
|
|
236
|
+
const child = children[j];
|
|
237
|
+
const text = child.concatTokens().toUpperCase();
|
|
238
|
+
if (child.get() instanceof Expressions.ComponentChain) {
|
|
239
|
+
result.push({ name: text, descending });
|
|
240
|
+
}
|
|
241
|
+
else if (text === "DESCENDING" && result.length > 0) {
|
|
242
|
+
result[result.length - 1].descending = true;
|
|
243
|
+
}
|
|
244
|
+
else if (text === "ASCENDING" && result.length > 0) {
|
|
245
|
+
result[result.length - 1].descending = false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
/** the primary key components, undefined for a default key of a structured row or when not known */
|
|
251
|
+
primaryKey(type) {
|
|
252
|
+
var _a;
|
|
253
|
+
const row = type.getRowType();
|
|
254
|
+
if (row instanceof basic_1.VoidType || row instanceof basic_1.UnknownType || row.isGeneric()) {
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
257
|
+
const keyType = type.getOptions().keyType;
|
|
258
|
+
const fields = ((_a = type.getOptions().primaryKey) === null || _a === void 0 ? void 0 : _a.keyFields) || [];
|
|
259
|
+
if (keyType === basic_1.TableKeyType.user && fields.length > 0) {
|
|
260
|
+
return fields;
|
|
261
|
+
}
|
|
262
|
+
else if (keyType === basic_1.TableKeyType.empty) {
|
|
263
|
+
return [];
|
|
264
|
+
}
|
|
265
|
+
return row instanceof basic_1.StructureType || row instanceof basic_1.TableType ? undefined : ["TABLE_LINE"];
|
|
266
|
+
}
|
|
267
|
+
matches(sortFields, fields, binary) {
|
|
268
|
+
if (sortFields.length < fields.length) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
const first = sortFields.slice(0, fields.length);
|
|
272
|
+
if (binary === true) {
|
|
273
|
+
return first.every((f, index) => f.name === fields[index] && f.descending === false);
|
|
274
|
+
}
|
|
275
|
+
const names = first.map(f => f.name);
|
|
276
|
+
return fields.every(f => names.includes(f));
|
|
277
|
+
}
|
|
278
|
+
/** index of the last SORT of the table before the statement, in the same procedure */
|
|
279
|
+
previousSort(name, statements, start, index) {
|
|
280
|
+
for (let i = index - 1; i > start; i--) {
|
|
281
|
+
if (this.isSortOf(statements[i], name)) {
|
|
282
|
+
return i;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
/** a SORT of the table after the statement but inside a loop around it runs before the next pass */
|
|
288
|
+
sortedLaterInLoop(name, statements, start, index) {
|
|
289
|
+
let outer = undefined;
|
|
290
|
+
let depth = 0;
|
|
291
|
+
for (let i = index - 1; i > start; i--) {
|
|
292
|
+
if (this.endsLoop(statements[i])) {
|
|
293
|
+
depth++;
|
|
294
|
+
}
|
|
295
|
+
else if (this.startsLoop(statements[i])) {
|
|
296
|
+
if (depth === 0) {
|
|
297
|
+
outer = i;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
depth--;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (outer === undefined) {
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
depth = 0;
|
|
308
|
+
for (let i = outer + 1; i < statements.length; i++) {
|
|
309
|
+
const statement = statements[i];
|
|
310
|
+
if (this.startsLoop(statement)) {
|
|
311
|
+
depth++;
|
|
312
|
+
}
|
|
313
|
+
else if (this.endsLoop(statement)) {
|
|
314
|
+
if (depth === 0) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
depth--;
|
|
318
|
+
}
|
|
319
|
+
else if (i > index && this.isSortOf(statement, name)) {
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
isSortOf(statement, name) {
|
|
326
|
+
var _a;
|
|
327
|
+
return statement.get() instanceof Statements.Sort
|
|
328
|
+
&& ((_a = statement.findDirectExpression(Expressions.Target)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) === name;
|
|
329
|
+
}
|
|
330
|
+
/** true when a statement between from and to fills the table from a source that can be sorted */
|
|
331
|
+
writtenUnknown(name, statements, from, to) {
|
|
332
|
+
for (let i = from + 1; i < to; i++) {
|
|
333
|
+
if (this.writes(statements[i], name) && this.fillKind(i, statements, name) === Fill.unknown) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return false;
|
|
338
|
+
}
|
|
339
|
+
/** true when a statement in the procedure brings rows in no defined order */
|
|
340
|
+
filledUnordered(name, statements, start, end) {
|
|
341
|
+
for (let i = start + 1; i < end; i++) {
|
|
342
|
+
if (this.writes(statements[i], name) && this.fillKind(i, statements, name) === Fill.unordered) {
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
writes(statement, name) {
|
|
349
|
+
return statement.get() instanceof Statements.Data === false
|
|
350
|
+
&& statement.findAllExpressions(Expressions.Target).some(t => this.targetName(t) === name);
|
|
351
|
+
}
|
|
352
|
+
targetName(target) {
|
|
353
|
+
var _a;
|
|
354
|
+
const inline = target.findDirectExpression(Expressions.InlineData);
|
|
355
|
+
if (inline !== undefined) {
|
|
356
|
+
return ((_a = inline.findDirectExpression(Expressions.TargetField)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) || "";
|
|
357
|
+
}
|
|
358
|
+
return target.concatTokens().toUpperCase();
|
|
359
|
+
}
|
|
360
|
+
fillKind(index, statements, name) {
|
|
361
|
+
var _a;
|
|
362
|
+
const statement = statements[index];
|
|
363
|
+
const s = statement.get();
|
|
364
|
+
if (s instanceof Statements.Clear
|
|
365
|
+
|| s instanceof Statements.Refresh
|
|
366
|
+
|| s instanceof Statements.Free
|
|
367
|
+
|| s instanceof Statements.DeleteInternal
|
|
368
|
+
|| s instanceof Statements.ModifyInternal
|
|
369
|
+
|| s instanceof Statements.Sort) {
|
|
370
|
+
return Fill.none;
|
|
371
|
+
}
|
|
372
|
+
else if (s instanceof Statements.Append || s instanceof Statements.InsertInternal || s instanceof Statements.Collect) {
|
|
373
|
+
if (statement.findDirectTokenByText("LINES") !== undefined || statement.findDirectTokenByText("SORTED") !== undefined) {
|
|
374
|
+
return Fill.unknown;
|
|
375
|
+
}
|
|
376
|
+
const loop = this.innermostLoop(index, statements);
|
|
377
|
+
return loop !== undefined && this.selectsUnordered(loop) ? Fill.unordered : Fill.none;
|
|
378
|
+
}
|
|
379
|
+
else if (s instanceof Statements.Select || s instanceof Statements.SelectLoop) {
|
|
380
|
+
const target = (_a = statement.findFirstExpression(Expressions.SQLIntoTable)) === null || _a === void 0 ? void 0 : _a.findFirstExpression(Expressions.Target);
|
|
381
|
+
return target !== undefined && this.targetName(target) === name && this.selectsUnordered(statement)
|
|
382
|
+
? Fill.unordered : Fill.unknown;
|
|
383
|
+
}
|
|
384
|
+
return Fill.unknown;
|
|
385
|
+
}
|
|
386
|
+
selectsUnordered(statement) {
|
|
387
|
+
return (statement.get() instanceof Statements.Select || statement.get() instanceof Statements.SelectLoop)
|
|
388
|
+
&& statement.findFirstExpression(Expressions.SQLOrderBy) === undefined;
|
|
389
|
+
}
|
|
390
|
+
innermostLoop(index, statements) {
|
|
391
|
+
let depth = 0;
|
|
392
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
393
|
+
if (this.endsLoop(statements[i])) {
|
|
394
|
+
depth++;
|
|
395
|
+
}
|
|
396
|
+
else if (this.startsLoop(statements[i])) {
|
|
397
|
+
if (depth === 0) {
|
|
398
|
+
return statements[i];
|
|
399
|
+
}
|
|
400
|
+
depth--;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
/** the DATA statement or inline declaration of the table inside the procedure, before the statement;
|
|
406
|
+
* parameters, attributes, globals and statics are declared elsewhere or with another statement */
|
|
407
|
+
findDeclaration(id, file, statements, start, index) {
|
|
408
|
+
if (id.getFilename() !== file.getFilename()) {
|
|
409
|
+
return undefined;
|
|
410
|
+
}
|
|
411
|
+
const position = id.getStart();
|
|
412
|
+
for (let i = start + 1; i < index; i++) {
|
|
413
|
+
const statement = statements[i];
|
|
414
|
+
if (position.isBetween(statement.getStart(), statement.getEnd()) === false) {
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
const inline = statement.findAllExpressions(Expressions.InlineData)
|
|
418
|
+
.some(d => position.isBetween(d.getFirstToken().getStart(), d.getLastToken().getEnd()));
|
|
419
|
+
return statement.get() instanceof Statements.Data || inline ? statement : undefined;
|
|
420
|
+
}
|
|
421
|
+
return undefined;
|
|
422
|
+
}
|
|
423
|
+
/** a standard table; the result of an inline SELECT has no access type set, it is a standard table */
|
|
424
|
+
isStandard(type, declaration) {
|
|
425
|
+
const access = type.getAccessType();
|
|
426
|
+
if (access === undefined) {
|
|
427
|
+
return declaration.get() instanceof Statements.Select || declaration.get() instanceof Statements.SelectLoop;
|
|
428
|
+
}
|
|
429
|
+
return access === basic_1.TableAccessType.standard;
|
|
430
|
+
}
|
|
431
|
+
findReference(node, spaghetti, file) {
|
|
432
|
+
const start = node.getFirstToken().getStart();
|
|
433
|
+
const scope = spaghetti.lookupPosition(start, file.getFilename());
|
|
434
|
+
for (const r of (scope === null || scope === void 0 ? void 0 : scope.getData().references) || []) {
|
|
435
|
+
if (r.position.getStart().equals(start) && r.resolved instanceof _typed_identifier_1.TypedIdentifier) {
|
|
436
|
+
return r.resolved;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
procedureStart(index, statements) {
|
|
442
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
443
|
+
const s = statements[i].get();
|
|
444
|
+
if (s instanceof Statements.MethodImplementation
|
|
445
|
+
|| s instanceof Statements.Form
|
|
446
|
+
|| s instanceof Statements.FunctionModule
|
|
447
|
+
|| s instanceof Statements.Module) {
|
|
448
|
+
return i;
|
|
449
|
+
}
|
|
450
|
+
else if (s instanceof Statements.EndMethod
|
|
451
|
+
|| s instanceof Statements.EndForm
|
|
452
|
+
|| s instanceof Statements.EndFunction
|
|
453
|
+
|| s instanceof Statements.EndModule) {
|
|
454
|
+
return undefined;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return undefined;
|
|
458
|
+
}
|
|
459
|
+
procedureEnd(index, statements) {
|
|
460
|
+
for (let i = index + 1; i < statements.length; i++) {
|
|
461
|
+
const s = statements[i].get();
|
|
462
|
+
if (s instanceof Statements.EndMethod
|
|
463
|
+
|| s instanceof Statements.EndForm
|
|
464
|
+
|| s instanceof Statements.EndFunction
|
|
465
|
+
|| s instanceof Statements.EndModule) {
|
|
466
|
+
return i;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return statements.length;
|
|
470
|
+
}
|
|
471
|
+
startsLoop(statement) {
|
|
472
|
+
const s = statement.get();
|
|
473
|
+
return s instanceof Statements.Loop
|
|
474
|
+
|| s instanceof Statements.Do
|
|
475
|
+
|| s instanceof Statements.While
|
|
476
|
+
|| s instanceof Statements.SelectLoop;
|
|
477
|
+
}
|
|
478
|
+
endsLoop(statement) {
|
|
479
|
+
const s = statement.get();
|
|
480
|
+
return s instanceof Statements.EndLoop
|
|
481
|
+
|| s instanceof Statements.EndDo
|
|
482
|
+
|| s instanceof Statements.EndWhile
|
|
483
|
+
|| s instanceof Statements.EndSelect;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
exports.SortRequired = SortRequired;
|
|
487
|
+
//# sourceMappingURL=sort_required.js.map
|