@abaplint/core 2.120.92 → 2.120.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/abaplint.d.ts +5 -0
- package/build/src/abap/2_statements/expressions/sql_from_source.js +1 -1
- package/build/src/abap/2_statements/expressions/sql_path_for_entity.js +11 -1
- package/build/src/abap/2_statements/expressions/string_template_formatting.js +2 -1
- package/build/src/abap/2_statements/expressions/type_structure.js +1 -1
- package/build/src/abap/2_statements/statements/get_permissions.js +7 -3
- package/build/src/abap/5_syntax/_builtin.js +8 -8
- package/build/src/abap/5_syntax/_sorted_key_write.js +264 -0
- package/build/src/abap/5_syntax/syntax.js +10 -0
- package/build/src/objects/service_binding.js +1 -1
- package/build/src/registry.js +1 -1
- package/build/src/rules/downport.js +493 -22
- package/package.json +5 -5
package/build/abaplint.d.ts
CHANGED
|
@@ -7159,6 +7159,10 @@ declare class SQLPathForColumn extends Expression {
|
|
|
7159
7159
|
}
|
|
7160
7160
|
|
|
7161
7161
|
declare class SQLPathForEntity extends Expression {
|
|
7162
|
+
private readonly withPrefix;
|
|
7163
|
+
/** withPrefix = false when the entity name is already parsed by the caller, eg. in SQLFromSource,
|
|
7164
|
+
* otherwise the prefix would match a following keyword */
|
|
7165
|
+
constructor(withPrefix?: boolean);
|
|
7162
7166
|
getRunnable(): IStatementRunnable;
|
|
7163
7167
|
}
|
|
7164
7168
|
|
|
@@ -7862,6 +7866,7 @@ export declare class SyntaxLogic {
|
|
|
7862
7866
|
private readonly reg;
|
|
7863
7867
|
private scope;
|
|
7864
7868
|
private loopTables;
|
|
7869
|
+
private sortedLines;
|
|
7865
7870
|
private helpers;
|
|
7866
7871
|
constructor(reg: IRegistry, object: ABAPObject);
|
|
7867
7872
|
run(): ISyntaxResult;
|
|
@@ -17,7 +17,7 @@ class SQLFromSource extends combi_1.Expression {
|
|
|
17
17
|
const privileged = (0, combi_1.ver)(version_1.Release.v752, (0, combi_1.seq)("WITH", _1.SQLPrivilegedAccess));
|
|
18
18
|
const providedBy = (0, combi_1.optPrio)((0, combi_1.ver)(version_1.Release.v796, _1.SQLProvidedBy));
|
|
19
19
|
const exposeClient = (0, combi_1.optPrio)((0, combi_1.ver)(version_1.Release.v913, _1.SQLExposeClientAs));
|
|
20
|
-
const pathForEntity = (0, combi_1.optPrio)((0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, new sql_path_for_entity_1.SQLPathForEntity()));
|
|
20
|
+
const pathForEntity = (0, combi_1.optPrio)((0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, new sql_path_for_entity_1.SQLPathForEntity(false)));
|
|
21
21
|
return (0, combi_1.seq)((0, combi_1.altPrio)(new sql_hierarchy_aggregate_1.SQLHierarchyAggregate(), new sql_hierarchy_accessor_1.SQLHierarchyAccessor(), new sql_hierarchy_source_1.SQLHierarchySource(), (0, combi_1.seq)(with_name_1.WithName, pathForEntity), (0, combi_1.seq)(new _1.DatabaseTable(true), (0, combi_1.optPrio)(_1.SQLCDSParameters), pathForEntity), tab), providedBy, (0, combi_1.optPrio)(privileged), (0, combi_1.optPrio)(aas), exposeClient);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -7,9 +7,19 @@ const database_table_1 = require("./database_table");
|
|
|
7
7
|
const sql_cte_path_prefix_1 = require("./sql_cte_path_prefix");
|
|
8
8
|
const version_1 = require("../../../version");
|
|
9
9
|
class SQLPathForEntity extends combi_1.Expression {
|
|
10
|
+
/** withPrefix = false when the entity name is already parsed by the caller, eg. in SQLFromSource,
|
|
11
|
+
* otherwise the prefix would match a following keyword */
|
|
12
|
+
constructor(withPrefix = true) {
|
|
13
|
+
super();
|
|
14
|
+
this.withPrefix = withPrefix;
|
|
15
|
+
}
|
|
10
16
|
getRunnable() {
|
|
17
|
+
const segments = (0, combi_1.plus)(new sql_path_segment_1.SQLPathSegment());
|
|
18
|
+
if (this.withPrefix === false) {
|
|
19
|
+
return (0, combi_1.ver)(version_1.Release.v740sp05, segments);
|
|
20
|
+
}
|
|
11
21
|
const prefix = (0, combi_1.altPrio)(new sql_cte_path_prefix_1.SQLCTEPathPrefix(), new database_table_1.DatabaseTable());
|
|
12
|
-
return (0, combi_1.ver)(version_1.Release.v740sp05, (0, combi_1.seq)((0, combi_1.optPrio)(prefix),
|
|
22
|
+
return (0, combi_1.ver)(version_1.Release.v740sp05, (0, combi_1.seq)((0, combi_1.optPrio)(prefix), segments));
|
|
13
23
|
}
|
|
14
24
|
}
|
|
15
25
|
exports.SQLPathForEntity = SQLPathForEntity;
|
|
@@ -28,7 +28,8 @@ class StringTemplateFormatting extends combi_1.Expression {
|
|
|
28
28
|
const alpha = (0, combi_1.ver)(version_1.Release.v740sp02, (0, combi_1.seq)("ALPHA =", alphaOptions), { also: combi_1.AlsoIn.OpenABAP });
|
|
29
29
|
const xsd = (0, combi_1.ver)(version_1.Release.v740sp02, (0, combi_1.seq)("XSD =", zeroXSDOptions));
|
|
30
30
|
const country = (0, combi_1.seq)("COUNTRY =", _1.Source);
|
|
31
|
-
const
|
|
31
|
+
const currency = (0, combi_1.seq)("CURRENCY =", _1.Source);
|
|
32
|
+
const formatting = (0, combi_1.altPrio)((0, combi_1.seq)("TIME =", dateTimeOptions), (0, combi_1.seq)("DATE =", dateTimeOptions), (0, combi_1.seq)("CASE =", caseOptions), (0, combi_1.seq)("ZERO =", zeroXSDOptions), xsd, (0, combi_1.seq)("STYLE =", styleOptions), (0, combi_1.per)(sign, number, decimals, width, pad, alpha, align, country, currency, (0, combi_1.seq)("EXPONENT =", _1.Source)), (0, combi_1.per)(timezone, timestamp));
|
|
32
33
|
return formatting;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
@@ -8,7 +8,7 @@ const _derived_types_1 = require("./_derived_types");
|
|
|
8
8
|
class TypeStructure extends combi_1.Expression {
|
|
9
9
|
getRunnable() {
|
|
10
10
|
const entity = (0, combi_1.alt)(_1.TypeName, _1.EntityAssociation);
|
|
11
|
-
const derivedTypes = (0, _derived_types_1.derivedTypesAlt)((0, combi_1.ver)(version_1.Release.v779, (0, combi_1.seq)("FUNCTION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v779, (0, combi_1.seq)("ACTION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.seq)("ACTION IMPORT", _1.Source), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL AUTHORIZATION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL AUTHORIZATION RESULT", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL FEATURES REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL FEATURES RESULT", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v780, (0, combi_1.seq)("AUTHORIZATION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v776, (0, combi_1.seq)("FEATURES REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.seq)("PERMISSIONS REQUEST",
|
|
11
|
+
const derivedTypes = (0, _derived_types_1.derivedTypesAlt)((0, combi_1.ver)(version_1.Release.v779, (0, combi_1.seq)("FUNCTION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v779, (0, combi_1.seq)("ACTION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.seq)("ACTION IMPORT", _1.Source), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL AUTHORIZATION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL AUTHORIZATION RESULT", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL FEATURES REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v781, (0, combi_1.seq)("GLOBAL FEATURES RESULT", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v780, (0, combi_1.seq)("AUTHORIZATION REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.ver)(version_1.Release.v776, (0, combi_1.seq)("FEATURES REQUEST", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.seq)("PERMISSIONS REQUEST", entity), (0, combi_1.ver)(version_1.Release.v780, (0, combi_1.seq)("PERMISSIONS RESULT", entity), { also: combi_1.AlsoIn.OpenABAP }), (0, combi_1.seq)("READ LINK", _1.EntityAssociation), (0, combi_1.seq)("HIERARCHY", _1.NamespaceSimpleName), (0, combi_1.seq)("EVENT", _1.EventName));
|
|
12
12
|
const structure = (0, combi_1.ver)(version_1.Release.v774, (0, combi_1.seq)("STRUCTURE FOR", derivedTypes), { also: combi_1.AlsoIn.OpenABAP });
|
|
13
13
|
const response = (0, combi_1.ver)(version_1.Release.v776, (0, combi_1.seq)("RESPONSE FOR", (0, combi_1.altPrio)((0, combi_1.seq)("FAILED EARLY", _1.NamespaceSimpleName), (0, combi_1.seq)("FAILED LATE", _1.NamespaceSimpleName), (0, combi_1.seq)("FAILED", _1.NamespaceSimpleName), (0, combi_1.seq)("MAPPED EARLY", _1.NamespaceSimpleName), (0, combi_1.seq)("MAPPED LATE", _1.NamespaceSimpleName), (0, combi_1.seq)("MAPPED", _1.NamespaceSimpleName), (0, combi_1.seq)("REPORTED EARLY", _1.NamespaceSimpleName), (0, combi_1.seq)("REPORTED LATE", _1.NamespaceSimpleName), (0, combi_1.seq)("REPORTED", _1.NamespaceSimpleName))), { also: combi_1.AlsoIn.OpenABAP });
|
|
14
14
|
const request = (0, combi_1.ver)(version_1.Release.v778, (0, combi_1.seq)("REQUEST FOR", (0, combi_1.alt)("CHANGE", "DELETE"), _1.NamespaceSimpleName), { also: combi_1.AlsoIn.OpenABAP });
|
|
@@ -6,9 +6,13 @@ const expressions_1 = require("../expressions");
|
|
|
6
6
|
const version_1 = require("../../../version");
|
|
7
7
|
class GetPermissions {
|
|
8
8
|
getMatcher() {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const aspect = (0, combi_1.altPrio)("FEATURES", "AUTHORIZATION");
|
|
10
|
+
const only = (0, combi_1.seq)("ONLY", (0, combi_1.altPrio)((0, combi_1.seq)("GLOBAL", (0, combi_1.optPrio)(aspect)), (0, combi_1.seq)("INSTANCE", (0, combi_1.optPrio)(aspect)), aspect, expressions_1.Dynamic));
|
|
11
|
+
const query = (0, combi_1.seq)("ENTITY", (0, combi_1.alt)(expressions_1.NamespaceSimpleName, expressions_1.EntityAssociation), (0, combi_1.optPrio)((0, combi_1.seq)("FROM", expressions_1.Source)), "REQUEST", expressions_1.Source, "RESULT", expressions_1.Target);
|
|
12
|
+
const long = (0, combi_1.seq)("OF", expressions_1.NamespaceSimpleName, (0, combi_1.plus)(query));
|
|
13
|
+
const operations = (0, combi_1.seq)("OPERATIONS", expressions_1.Source);
|
|
14
|
+
const response = (0, combi_1.optPrio)((0, combi_1.per)((0, combi_1.seq)("FAILED", expressions_1.Target), (0, combi_1.seq)("REPORTED", expressions_1.Target)));
|
|
15
|
+
const s = (0, combi_1.seq)("GET PERMISSIONS", (0, combi_1.optPrio)((0, combi_1.seq)((0, combi_1.opt)("FORWARDING"), "PRIVILEGED")), (0, combi_1.optPrio)(only), (0, combi_1.altPrio)(long, operations, query), response);
|
|
12
16
|
return (0, combi_1.ver)(version_1.Release.v754, s, { also: combi_1.AlsoIn.OpenABAP });
|
|
13
17
|
}
|
|
14
18
|
}
|
|
@@ -176,14 +176,14 @@ class BuiltIn {
|
|
|
176
176
|
BuiltIn.getCache.push(this.buildConstant("abap_undefined", new basic_1.CharacterType(1, { qualifiedName: "ABAP_BOOL", ddicName: "ABAP_BOOL" }), "'-'"));
|
|
177
177
|
BuiltIn.getCache.push(this.buildConstant("abap_off", new basic_1.CharacterType(1, { qualifiedName: "ABAP_BOOL", ddicName: "ABAP_BOOL" }), "' '"));
|
|
178
178
|
BuiltIn.getCache.push(this.buildConstant("abap_on", new basic_1.CharacterType(1, { qualifiedName: "ABAP_BOOL", ddicName: "ABAP_BOOL" }), "'X'"));
|
|
179
|
-
BuiltIn.getCache.push(this.buildConstant("col_background", basic_1.
|
|
180
|
-
BuiltIn.getCache.push(this.buildConstant("col_heading", basic_1.
|
|
181
|
-
BuiltIn.getCache.push(this.buildConstant("col_key", basic_1.
|
|
182
|
-
BuiltIn.getCache.push(this.buildConstant("col_negative", basic_1.
|
|
183
|
-
BuiltIn.getCache.push(this.buildConstant("col_group", basic_1.
|
|
184
|
-
BuiltIn.getCache.push(this.buildConstant("col_normal", basic_1.
|
|
185
|
-
BuiltIn.getCache.push(this.buildConstant("col_positive", basic_1.
|
|
186
|
-
BuiltIn.getCache.push(this.buildConstant("col_total", basic_1.
|
|
179
|
+
BuiltIn.getCache.push(this.buildConstant("col_background", new basic_1.CharacterType(1), "'0'"));
|
|
180
|
+
BuiltIn.getCache.push(this.buildConstant("col_heading", new basic_1.CharacterType(1), "'1'"));
|
|
181
|
+
BuiltIn.getCache.push(this.buildConstant("col_key", new basic_1.CharacterType(1), "'4'"));
|
|
182
|
+
BuiltIn.getCache.push(this.buildConstant("col_negative", new basic_1.CharacterType(1), "'6'"));
|
|
183
|
+
BuiltIn.getCache.push(this.buildConstant("col_group", new basic_1.CharacterType(1), "'7'"));
|
|
184
|
+
BuiltIn.getCache.push(this.buildConstant("col_normal", new basic_1.CharacterType(1), "'2'"));
|
|
185
|
+
BuiltIn.getCache.push(this.buildConstant("col_positive", new basic_1.CharacterType(1), "'5'"));
|
|
186
|
+
BuiltIn.getCache.push(this.buildConstant("col_total", new basic_1.CharacterType(1), "'3'"));
|
|
187
187
|
BuiltIn.getCache.push(this.buildConstant("space", new basic_1.CharacterType(1, { derivedFromConstant: true }), "' '"));
|
|
188
188
|
}
|
|
189
189
|
ret.push(...BuiltIn.getCache);
|
|
@@ -0,0 +1,264 @@
|
|
|
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.SortedKeyWrite = void 0;
|
|
37
|
+
const Expressions = __importStar(require("../2_statements/expressions"));
|
|
38
|
+
const Statements = __importStar(require("../2_statements/statements"));
|
|
39
|
+
const Structures = __importStar(require("../3_structures/structures"));
|
|
40
|
+
const tokens_1 = require("../1_lexer/tokens");
|
|
41
|
+
const basic_1 = require("../types/basic");
|
|
42
|
+
const _object_oriented_1 = require("./_object_oriented");
|
|
43
|
+
const _syntax_input_1 = require("./_syntax_input");
|
|
44
|
+
/** The key components of the primary key of a sorted or hashed table line are write-protected,
|
|
45
|
+
* "write accesses to key fields using a field symbol or a data reference produce a syntax error if
|
|
46
|
+
* this is known statically, otherwise a runtime error", see the ABAP keyword documentation for LOOP AT itab
|
|
47
|
+
* and READ TABLE, result.
|
|
48
|
+
* Only conservative cases are handled: a field symbol or data reference local to the method, form or function
|
|
49
|
+
* module, bound by LOOP AT or READ TABLE ... ASSIGNING / REFERENCE INTO a table named by a plain chain of
|
|
50
|
+
* names, components and attributes, and written by an assignment or CLEAR. The binding of a LOOP ends with the LOOP,
|
|
51
|
+
* any other assignment of the field symbol or reference ends it as well. */
|
|
52
|
+
class SortedKeyWrite {
|
|
53
|
+
constructor() {
|
|
54
|
+
this.bindings = new Map();
|
|
55
|
+
this.procedure = undefined;
|
|
56
|
+
}
|
|
57
|
+
enter(node, filename) {
|
|
58
|
+
if (SortedKeyWrite.isProcedure(node)) {
|
|
59
|
+
this.bindings.clear();
|
|
60
|
+
this.procedure = { filename, start: node.getFirstToken().getStart() };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
leave(node) {
|
|
64
|
+
if (SortedKeyWrite.isProcedure(node)) {
|
|
65
|
+
this.bindings.clear();
|
|
66
|
+
this.procedure = undefined;
|
|
67
|
+
}
|
|
68
|
+
else if (node.get() instanceof Structures.Loop) {
|
|
69
|
+
const loop = node.findDirectStatement(Statements.Loop);
|
|
70
|
+
for (const [identifier, binding] of this.bindings) {
|
|
71
|
+
if (binding.loop === loop) {
|
|
72
|
+
this.bindings.delete(identifier);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** call before the statement is checked */
|
|
78
|
+
check(node, input) {
|
|
79
|
+
if (this.bindings.size === 0) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const s = node.get();
|
|
83
|
+
if (!(s instanceof Statements.Move) && !(s instanceof Statements.Clear)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const target of node.findDirectExpressions(Expressions.Target)) {
|
|
87
|
+
const message = this.checkTarget(target, input.scope);
|
|
88
|
+
if (message !== undefined) {
|
|
89
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, target.getFirstToken(), message));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/** call after the statement is checked, the inline declarations are then known */
|
|
95
|
+
update(node, input) {
|
|
96
|
+
var _a, _b, _c, _d;
|
|
97
|
+
var _e, _f, _g;
|
|
98
|
+
if (this.procedure === undefined) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// any assignment of a field symbol or reference ends its binding
|
|
102
|
+
for (const fs of node.findAllExpressions(Expressions.FSTarget)) {
|
|
103
|
+
this.unbind(fs.findFirstExpression(Expressions.TargetFieldSymbol), input.scope);
|
|
104
|
+
}
|
|
105
|
+
if (node.get() instanceof Statements.Unassign) {
|
|
106
|
+
this.unbind(node.findDirectExpression(Expressions.TargetFieldSymbol), input.scope);
|
|
107
|
+
}
|
|
108
|
+
for (const target of node.findAllExpressions(Expressions.Target)) {
|
|
109
|
+
if (target.getChildren().length === 1) {
|
|
110
|
+
this.unbind(target.findDirectExpression(Expressions.TargetField), input.scope);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const s = node.get();
|
|
114
|
+
let table = undefined;
|
|
115
|
+
let result = undefined;
|
|
116
|
+
if (s instanceof Statements.Loop && node.findDirectExpression(Expressions.LoopGroupBy) === undefined) {
|
|
117
|
+
table = (_e = (_a = node.findDirectExpression(Expressions.LoopSource)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.SimpleSource2)) !== null && _e !== void 0 ? _e : (_b = node.findDirectExpression(Expressions.LoopSource)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.Source);
|
|
118
|
+
result = node.findDirectExpression(Expressions.LoopTarget);
|
|
119
|
+
}
|
|
120
|
+
else if (s instanceof Statements.ReadTable) {
|
|
121
|
+
table = (_f = node.findDirectExpression(Expressions.SimpleSource2)) !== null && _f !== void 0 ? _f : node.findDirectExpression(Expressions.Source);
|
|
122
|
+
result = node.findDirectExpression(Expressions.ReadTableTarget);
|
|
123
|
+
}
|
|
124
|
+
if (table === undefined || result === undefined
|
|
125
|
+
|| result.findDirectTokenByText("CASTING") !== undefined
|
|
126
|
+
|| node.findDirectTokenByText("CASTING") !== undefined) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let name = undefined;
|
|
130
|
+
let reference = false;
|
|
131
|
+
if (result.findDirectTokenByText("ASSIGNING") !== undefined) {
|
|
132
|
+
name = (_c = result.findDirectExpression(Expressions.FSTarget)) === null || _c === void 0 ? void 0 : _c.findFirstExpression(Expressions.TargetFieldSymbol);
|
|
133
|
+
}
|
|
134
|
+
else if (result.findDirectTokenByText("REFERENCE") !== undefined) {
|
|
135
|
+
const target = result.findDirectExpression(Expressions.Target);
|
|
136
|
+
if ((target === null || target === void 0 ? void 0 : target.getChildren().length) === 1) {
|
|
137
|
+
name = (_g = target.findDirectExpression(Expressions.TargetField)) !== null && _g !== void 0 ? _g : (_d = target.findDirectExpression(Expressions.InlineData)) === null || _d === void 0 ? void 0 : _d.findDirectExpression(Expressions.TargetField);
|
|
138
|
+
}
|
|
139
|
+
reference = true;
|
|
140
|
+
}
|
|
141
|
+
const identifier = input.scope.findVariable(name === null || name === void 0 ? void 0 : name.concatTokens());
|
|
142
|
+
if (identifier === undefined
|
|
143
|
+
|| identifier.getFilename() !== this.procedure.filename
|
|
144
|
+
|| identifier.getStart().isBefore(this.procedure.start)) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const key = SortedKeyWrite.findKey(SortedKeyWrite.findType(table, input.scope));
|
|
148
|
+
if (key !== undefined) {
|
|
149
|
+
this.bindings.set(identifier, { key, reference, loop: s instanceof Statements.Loop ? node : undefined });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
////////////////
|
|
153
|
+
unbind(node, scope) {
|
|
154
|
+
const found = node ? scope.findVariable(node.concatTokens()) : undefined;
|
|
155
|
+
if (found !== undefined) {
|
|
156
|
+
this.bindings.delete(found);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
checkTarget(target, scope) {
|
|
160
|
+
var _a, _b, _c, _d;
|
|
161
|
+
const children = target.getChildren();
|
|
162
|
+
const first = children[0];
|
|
163
|
+
if (!((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.TargetFieldSymbol) && !((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.TargetField)) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
const found = scope.findVariable(first.concatTokens());
|
|
167
|
+
const binding = found ? this.bindings.get(found) : undefined;
|
|
168
|
+
if (binding === undefined) {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
let i = 1;
|
|
172
|
+
const path = [];
|
|
173
|
+
if (binding.reference === true) {
|
|
174
|
+
if (((_a = children[i]) === null || _a === void 0 ? void 0 : _a.get()) instanceof tokens_1.InstanceArrow && ((_b = children[i + 1]) === null || _b === void 0 ? void 0 : _b.get()) instanceof Expressions.AttributeName) {
|
|
175
|
+
path.push(children[i + 1].concatTokens().toUpperCase());
|
|
176
|
+
i = i + 2;
|
|
177
|
+
}
|
|
178
|
+
else if (((_c = children[i]) === null || _c === void 0 ? void 0 : _c.get()) instanceof Expressions.Dereference) {
|
|
179
|
+
i = i + 1;
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
// the reference itself
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (; i < children.length; i++) {
|
|
187
|
+
const get = children[i].get();
|
|
188
|
+
if (get instanceof tokens_1.Dash && ((_d = children[i + 1]) === null || _d === void 0 ? void 0 : _d.get()) instanceof Expressions.ComponentName) {
|
|
189
|
+
path.push(children[i + 1].concatTokens().toUpperCase());
|
|
190
|
+
i++;
|
|
191
|
+
}
|
|
192
|
+
else if (!(get instanceof Expressions.FieldOffset) && !(get instanceof Expressions.FieldLength)) {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (binding.key === "line") {
|
|
197
|
+
return "The line of a sorted or hashed table cannot be changed, it is the table key";
|
|
198
|
+
}
|
|
199
|
+
const name = path.join("-");
|
|
200
|
+
if (name !== "" && binding.key.some(k => k === name || k.startsWith(name + "-") || name.startsWith(k + "-"))) {
|
|
201
|
+
return `Key component "${name}" of a sorted or hashed table line cannot be changed`;
|
|
202
|
+
}
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
/** the primary key components of a sorted or hashed table, "line" when it is the whole line, else undefined */
|
|
206
|
+
static findKey(type) {
|
|
207
|
+
var _a;
|
|
208
|
+
if (!(type instanceof basic_1.TableType)
|
|
209
|
+
|| (type.getAccessType() !== basic_1.TableAccessType.sorted && type.getAccessType() !== basic_1.TableAccessType.hashed)) {
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
const row = type.getRowType();
|
|
213
|
+
if (row instanceof basic_1.VoidType || row instanceof basic_1.UnknownType || row.isGeneric()) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
const keyType = type.getOptions().keyType;
|
|
217
|
+
const fields = ((_a = type.getOptions().primaryKey) === null || _a === void 0 ? void 0 : _a.keyFields) || [];
|
|
218
|
+
if (keyType === basic_1.TableKeyType.default) {
|
|
219
|
+
// the default key of a structured line is not resolved
|
|
220
|
+
return row instanceof basic_1.StructureType ? undefined : "line";
|
|
221
|
+
}
|
|
222
|
+
else if (keyType !== basic_1.TableKeyType.user || fields.length === 0) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
else if (fields.includes("TABLE_LINE")) {
|
|
226
|
+
return "line";
|
|
227
|
+
}
|
|
228
|
+
return fields;
|
|
229
|
+
}
|
|
230
|
+
/** the type of a table given by a plain chain of names, components and attributes, else undefined */
|
|
231
|
+
static findType(node, scope) {
|
|
232
|
+
var _a, _b;
|
|
233
|
+
const chain = node.getChildren().length === 1 ? node.findDirectExpression(Expressions.FieldChain) : undefined;
|
|
234
|
+
const children = (chain === null || chain === void 0 ? void 0 : chain.getChildren()) || [];
|
|
235
|
+
const first = children[0];
|
|
236
|
+
if (!((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.SourceField) && !((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.SourceFieldSymbol)) {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
let type = (_a = scope.findVariable(first.concatTokens())) === null || _a === void 0 ? void 0 : _a.getType();
|
|
240
|
+
for (let i = 1; i < children.length && type !== undefined; i++) {
|
|
241
|
+
const get = children[i].get();
|
|
242
|
+
const next = children[i + 1];
|
|
243
|
+
if (get instanceof tokens_1.Dash && (next === null || next === void 0 ? void 0 : next.get()) instanceof Expressions.ComponentName) {
|
|
244
|
+
type = type instanceof basic_1.StructureType ? type.getComponentByName(next.concatTokens()) : undefined;
|
|
245
|
+
i++;
|
|
246
|
+
}
|
|
247
|
+
else if (get instanceof tokens_1.InstanceArrow && (next === null || next === void 0 ? void 0 : next.get()) instanceof Expressions.AttributeName) {
|
|
248
|
+
const def = type instanceof basic_1.ObjectReferenceType ? scope.findObjectDefinition(type.getIdentifierName()) : undefined;
|
|
249
|
+
type = (_b = new _object_oriented_1.ObjectOriented(scope).searchAttributeName(def, next.concatTokens())) === null || _b === void 0 ? void 0 : _b.getType();
|
|
250
|
+
i++;
|
|
251
|
+
}
|
|
252
|
+
else if (!(get instanceof Expressions.TableBody) || i !== children.length - 1) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return type;
|
|
257
|
+
}
|
|
258
|
+
static isProcedure(node) {
|
|
259
|
+
const get = node.get();
|
|
260
|
+
return get instanceof Structures.Method || get instanceof Structures.Form || get instanceof Structures.FunctionModule;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.SortedKeyWrite = SortedKeyWrite;
|
|
264
|
+
//# sourceMappingURL=_sorted_key_write.js.map
|
|
@@ -193,6 +193,7 @@ const assert_error_1 = require("./assert_error");
|
|
|
193
193
|
const field_group_1 = require("./statements/field_group");
|
|
194
194
|
const stuff_1 = require("../../stuff");
|
|
195
195
|
const _loop_table_change_1 = require("./_loop_table_change");
|
|
196
|
+
const _sorted_key_write_1 = require("./_sorted_key_write");
|
|
196
197
|
// -----------------------------------
|
|
197
198
|
const map = {};
|
|
198
199
|
function addToMap(handler) {
|
|
@@ -357,6 +358,7 @@ class SyntaxLogic {
|
|
|
357
358
|
this.issues = [];
|
|
358
359
|
this.deferred = [];
|
|
359
360
|
this.loopTables = new _loop_table_change_1.LoopTableChange();
|
|
361
|
+
this.sortedLines = new _sorted_key_write_1.SortedKeyWrite();
|
|
360
362
|
this.reg.getDDICReferences().clear(this.object);
|
|
361
363
|
this.reg.getMSAGReferences().clear(this.object);
|
|
362
364
|
if (this.object instanceof objects_1.Program && this.object.isInclude()) {
|
|
@@ -425,6 +427,9 @@ class SyntaxLogic {
|
|
|
425
427
|
const loop = node instanceof nodes_1.StructureNode
|
|
426
428
|
&& node.get() instanceof Structures.Loop
|
|
427
429
|
&& this.loopTables.push(node, this.scope);
|
|
430
|
+
if (node instanceof nodes_1.StructureNode) {
|
|
431
|
+
this.sortedLines.enter(node, this.currentFile.getFilename());
|
|
432
|
+
}
|
|
428
433
|
for (const child of node.getChildren()) {
|
|
429
434
|
const isStructure = child instanceof nodes_1.StructureNode;
|
|
430
435
|
const isStatement = child instanceof nodes_1.StatementNode;
|
|
@@ -469,6 +474,9 @@ class SyntaxLogic {
|
|
|
469
474
|
if (loop === true) {
|
|
470
475
|
this.loopTables.pop();
|
|
471
476
|
}
|
|
477
|
+
if (node instanceof nodes_1.StructureNode) {
|
|
478
|
+
this.sortedLines.leave(node);
|
|
479
|
+
}
|
|
472
480
|
}
|
|
473
481
|
/**
|
|
474
482
|
* if this returns true, then the traversal should continue with next child
|
|
@@ -558,9 +566,11 @@ class SyntaxLogic {
|
|
|
558
566
|
return;
|
|
559
567
|
}
|
|
560
568
|
this.loopTables.check(node, input);
|
|
569
|
+
this.sortedLines.check(node, input);
|
|
561
570
|
const name = s.constructor.name;
|
|
562
571
|
if (map[name]) {
|
|
563
572
|
map[name].runSyntax(node, input);
|
|
573
|
+
this.sortedLines.update(node, input);
|
|
564
574
|
return;
|
|
565
575
|
}
|
|
566
576
|
if (s instanceof Statements.FunctionModule) {
|
package/build/src/registry.js
CHANGED
|
@@ -182,6 +182,7 @@ Current rules:
|
|
|
182
182
|
* SELECT INTO @DATA definitions are outlined
|
|
183
183
|
* Some occurrences of string template formatting option ALPHA changed to function module call
|
|
184
184
|
* SELECT/INSERT/MODIFY/DELETE/UPDATE "," in field list removed, "@" in source/targets removed
|
|
185
|
+
* OPEN CURSOR/FETCH NEXT CURSOR/CLOSE CURSOR "@" in source/targets removed
|
|
185
186
|
* PARTIALLY IMPLEMENTED removed, it can be quick fixed via rule implement_methods
|
|
186
187
|
* RAISE EXCEPTION ... MESSAGE
|
|
187
188
|
* Moving with +=, -=, /=, *=, &&= is expanded
|
|
@@ -287,6 +288,7 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
287
288
|
highSyntax = new syntax_1.SyntaxLogic(this.highReg, highSyntaxObj).run();
|
|
288
289
|
}
|
|
289
290
|
let containsUnknown = false;
|
|
291
|
+
const notDownported = [];
|
|
290
292
|
for (let i = 0; i < lowStatements.length; i++) {
|
|
291
293
|
const low = lowStatements[i];
|
|
292
294
|
const high = highStatements[i];
|
|
@@ -298,6 +300,12 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
298
300
|
if (issue) {
|
|
299
301
|
ret.push(issue);
|
|
300
302
|
}
|
|
303
|
+
else {
|
|
304
|
+
const nope = this.notDownported(low, high, lowFile, highSyntax);
|
|
305
|
+
if (nope) {
|
|
306
|
+
notDownported.push(nope);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
301
309
|
}
|
|
302
310
|
catch (e) {
|
|
303
311
|
if (e instanceof SkipToNextFile) {
|
|
@@ -354,6 +362,20 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
354
362
|
}
|
|
355
363
|
}
|
|
356
364
|
}
|
|
365
|
+
// MOVE-CORRESPONDING between tables parses in the low version, but is only allowed from
|
|
366
|
+
// v740sp05, "MOVE-CORRESPONDING with tables possible from v740sp05"
|
|
367
|
+
if (ret.length === 0) {
|
|
368
|
+
for (let i = 0; i < lowStatements.length; i++) {
|
|
369
|
+
if (lowStatements[i].getFirstToken().getStart() instanceof virtual_position_1.VirtualPosition) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const issue = this.downportMoveCorrespondingTables(highStatements[i], lowFile, highSyntax);
|
|
373
|
+
if (issue) {
|
|
374
|
+
ret.push(issue);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
357
379
|
// INTO after WHERE parses as a valid SELECT in the low version, but is only allowed in
|
|
358
380
|
// strict SQL syntax, so move it also when the statement is no longer Unknown
|
|
359
381
|
if (ret.length === 0) {
|
|
@@ -366,10 +388,53 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
366
388
|
}
|
|
367
389
|
}
|
|
368
390
|
}
|
|
391
|
+
// nothing could be rewritten, name the statements which stay invalid in the low version
|
|
392
|
+
if (ret.length === 0) {
|
|
393
|
+
ret.push(...notDownported);
|
|
394
|
+
}
|
|
369
395
|
}
|
|
370
396
|
return ret;
|
|
371
397
|
}
|
|
372
398
|
////////////////////
|
|
399
|
+
/** for a statement no downport applies to, an issue without fix if it stays invalid in the low version */
|
|
400
|
+
notDownported(low, high, lowFile, highSyntax) {
|
|
401
|
+
var _a, _b;
|
|
402
|
+
if (this.lowReg.getConfig().isOpenABAP()) {
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
// a constructor expression with #, where the type cannot be inferred as it is void
|
|
406
|
+
if (low.get() instanceof _statement_1.Unknown) {
|
|
407
|
+
for (const infer of high.findAllExpressionsRecursive(Expressions.TypeNameOrInfer)) {
|
|
408
|
+
if (infer.concatTokens() !== "#") {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
const token = infer.getFirstToken();
|
|
412
|
+
const spag = highSyntax.spaghetti.lookupPosition(token.getStart(), lowFile.getFilename());
|
|
413
|
+
const voided = spag === null || spag === void 0 ? void 0 : spag.getData().references.some(r => r.referenceType === _reference_1.ReferenceType.InferredType
|
|
414
|
+
&& r.position.getStart().equals(token.getStart())
|
|
415
|
+
&& r.resolved instanceof _typed_identifier_1.TypedIdentifier
|
|
416
|
+
&& r.resolved.getType() instanceof basic_1.VoidType
|
|
417
|
+
&& r.resolved.getType().getQualifiedName() === undefined);
|
|
418
|
+
if (voided === true) {
|
|
419
|
+
return issue_1.Issue.atToken(lowFile, token, "Cannot downport, inferred type is void", this.getMetadata().key, this.conf.severity);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return undefined;
|
|
423
|
+
}
|
|
424
|
+
// the statement might still parse in the low version, eg. DATA(name) as offset/length access
|
|
425
|
+
for (const i of high.findAllExpressionsRecursive(Expressions.InlineData)) {
|
|
426
|
+
const nameToken = (_a = i.findDirectExpression(Expressions.TargetField)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
427
|
+
if (nameToken === undefined) {
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
const name = nameToken.getStr();
|
|
431
|
+
const found = (_b = highSyntax.spaghetti.lookupPosition(nameToken.getStart(), lowFile.getFilename())) === null || _b === void 0 ? void 0 : _b.findVariable(name);
|
|
432
|
+
if ((found === null || found === void 0 ? void 0 : found.getType()) instanceof basic_1.VoidType && found.getType().getQualifiedName() === undefined) {
|
|
433
|
+
return issue_1.Issue.atToken(lowFile, i.getFirstToken(), `Cannot downport, type of ${name} is void`, this.getMetadata().key, this.conf.severity);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
373
438
|
/** clones the orginal repository into highReg, and parses it with higher language version */
|
|
374
439
|
initHighReg() {
|
|
375
440
|
// use default configuration, ie. default target version
|
|
@@ -456,6 +521,10 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
456
521
|
if (found) {
|
|
457
522
|
return found;
|
|
458
523
|
}
|
|
524
|
+
found = this.downportMoveCorrespondingTables(high, lowFile, highSyntax);
|
|
525
|
+
if (found) {
|
|
526
|
+
return found;
|
|
527
|
+
}
|
|
459
528
|
found = this.downportRef(low, high, lowFile, highSyntax);
|
|
460
529
|
if (found) {
|
|
461
530
|
return found;
|
|
@@ -480,6 +549,10 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
480
549
|
if (found) {
|
|
481
550
|
return found;
|
|
482
551
|
}
|
|
552
|
+
found = this.downportOpenCursorInline(low, high, lowFile);
|
|
553
|
+
if (found) {
|
|
554
|
+
return found;
|
|
555
|
+
}
|
|
483
556
|
found = this.downportSQLMoveInto(low, high, lowFile, highSyntax);
|
|
484
557
|
if (found) {
|
|
485
558
|
return found;
|
|
@@ -562,6 +635,10 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
562
635
|
if (found) {
|
|
563
636
|
return found;
|
|
564
637
|
}
|
|
638
|
+
found = this.outlineReadTableVoidTarget(high, lowFile, highSyntax);
|
|
639
|
+
if (found) {
|
|
640
|
+
return found;
|
|
641
|
+
}
|
|
565
642
|
found = this.outlineData(high, lowFile, highSyntax);
|
|
566
643
|
if (found) {
|
|
567
644
|
return found;
|
|
@@ -574,6 +651,10 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
574
651
|
if (found) {
|
|
575
652
|
return found;
|
|
576
653
|
}
|
|
654
|
+
found = this.replaceInstanceOf(low, high, lowFile, highSyntax, highFile);
|
|
655
|
+
if (found) {
|
|
656
|
+
return found;
|
|
657
|
+
}
|
|
577
658
|
found = this.replaceLineFunctions(high, lowFile, highSyntax, highFile);
|
|
578
659
|
if (found) {
|
|
579
660
|
return found;
|
|
@@ -653,13 +734,48 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
653
734
|
if (from === undefined) {
|
|
654
735
|
return undefined;
|
|
655
736
|
}
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
const
|
|
737
|
+
// UP TO after INTO is only valid behind WHERE when it follows an ORDER BY, else move it along in front of INTO
|
|
738
|
+
let move = into.concatTokens();
|
|
739
|
+
const fixes = [];
|
|
740
|
+
const upTo = high.findFirstExpression(Expressions.SQLUpTo);
|
|
741
|
+
const orderBy = high.findFirstExpression(Expressions.SQLOrderBy);
|
|
742
|
+
if (upTo !== undefined
|
|
743
|
+
&& into.getLastToken().getEnd().isBefore(upTo.getFirstToken().getStart())
|
|
744
|
+
&& (orderBy === undefined || upTo.getFirstToken().getStart().isBefore(orderBy.getFirstToken().getStart()))) {
|
|
745
|
+
move = upTo.concatTokens() + ` ` + move;
|
|
746
|
+
fixes.push(edit_helper_1.EditHelper.deleteRange(lowFile, upTo.getFirstToken().getStart(), upTo.getLastToken().getEnd()));
|
|
747
|
+
}
|
|
748
|
+
// edits are applied in sequence, so work from the end of the statement towards the start
|
|
749
|
+
fixes.push(edit_helper_1.EditHelper.deleteRange(lowFile, into.getFirstToken().getStart(), into.getLastToken().getEnd()));
|
|
750
|
+
fixes.push(edit_helper_1.EditHelper.insertAt(lowFile, from.getLastToken().getEnd(), ` ` + move));
|
|
751
|
+
const fix = edit_helper_1.EditHelper.mergeList(fixes);
|
|
659
752
|
return issue_1.Issue.atToken(lowFile, low.getFirstToken(), "SQL, move INTO", this.getMetadata().key, this.conf.severity, fix);
|
|
660
753
|
}
|
|
754
|
+
/** the work area of INSERT/MODIFY/UPDATE/DELETE dbtab FROM @( ... ) takes its type from the
|
|
755
|
+
* database table, a "#" constructor cannot be outlined with DATA( ) as there is nothing to infer from */
|
|
756
|
+
sqlWorkAreaType(high, sqlSource) {
|
|
757
|
+
if (!(high.get() instanceof Statements.InsertDatabase)
|
|
758
|
+
&& !(high.get() instanceof Statements.ModifyDatabase)
|
|
759
|
+
&& !(high.get() instanceof Statements.UpdateDatabase)
|
|
760
|
+
&& !(high.get() instanceof Statements.DeleteDatabase)) {
|
|
761
|
+
return undefined;
|
|
762
|
+
}
|
|
763
|
+
else if (high.getChildren().includes(sqlSource) === false) {
|
|
764
|
+
return undefined;
|
|
765
|
+
}
|
|
766
|
+
const table = high.findDirectExpression(Expressions.DatabaseTable);
|
|
767
|
+
if (table === undefined || table.findDirectExpression(Expressions.Dynamic) !== undefined) {
|
|
768
|
+
return undefined;
|
|
769
|
+
}
|
|
770
|
+
const name = table.concatTokens();
|
|
771
|
+
if (high.findDirectTokenByText("TABLE") !== undefined) {
|
|
772
|
+
return `STANDARD TABLE OF ${name} WITH DEFAULT KEY`;
|
|
773
|
+
}
|
|
774
|
+
return name;
|
|
775
|
+
}
|
|
661
776
|
/** removes @'s and commas */
|
|
662
777
|
downportSQLExtras(low, high, lowFile, highSyntax) {
|
|
778
|
+
var _a;
|
|
663
779
|
if (!(low.get() instanceof _statement_1.Unknown)) {
|
|
664
780
|
return undefined;
|
|
665
781
|
}
|
|
@@ -668,7 +784,10 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
668
784
|
&& !(high.get() instanceof Statements.UpdateDatabase)
|
|
669
785
|
&& !(high.get() instanceof Statements.ModifyDatabase)
|
|
670
786
|
&& !(high.get() instanceof Statements.DeleteDatabase)
|
|
671
|
-
&& !(high.get() instanceof Statements.InsertDatabase)
|
|
787
|
+
&& !(high.get() instanceof Statements.InsertDatabase)
|
|
788
|
+
&& !(high.get() instanceof Statements.OpenCursor)
|
|
789
|
+
&& !(high.get() instanceof Statements.FetchNextCursor)
|
|
790
|
+
&& !(high.get() instanceof Statements.CloseCursor)) {
|
|
672
791
|
return undefined;
|
|
673
792
|
}
|
|
674
793
|
let fix = undefined;
|
|
@@ -685,12 +804,28 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
685
804
|
high.findAllExpressionsRecursive(Expressions.SQLSource),
|
|
686
805
|
high.findAllExpressionsRecursive(Expressions.SQLSourceNoSpace),
|
|
687
806
|
high.findAllExpressionsRecursive(Expressions.SQLSourceSimple)].flat();
|
|
688
|
-
|
|
807
|
+
// the deletions are applied one after the other, so handle the candidates from the end of the statement,
|
|
808
|
+
// in FETCH NEXT CURSOR and OPEN CURSOR a source or target comes before the others
|
|
809
|
+
candidates.sort((a, b) => a.getFirstToken().getStart().isAfter(b.getFirstToken().getStart()) ? -1 : 1);
|
|
810
|
+
for (const c of candidates) {
|
|
689
811
|
if (c.getFirstToken() instanceof tokens_1.WAt
|
|
690
812
|
|| c.getFirstToken() instanceof tokens_1.At) {
|
|
691
813
|
const tokens = c.getAllTokens();
|
|
692
814
|
if (tokens[1] instanceof tokens_1.ParenLeftW && tokens[tokens.length - 1] instanceof tokens_1.WParenRightW) {
|
|
693
815
|
const source = c.findDirectExpression(Expressions.Source);
|
|
816
|
+
if (((_a = source === null || source === void 0 ? void 0 : source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.concatTokens()) === "#") {
|
|
817
|
+
const workAreaType = this.sqlWorkAreaType(high, c);
|
|
818
|
+
if (workAreaType === undefined) {
|
|
819
|
+
return issue_1.Issue.atToken(lowFile, low.getFirstToken(), "SQL, outline complex @, type of # not known", this.getMetadata().key, this.conf.severity);
|
|
820
|
+
}
|
|
821
|
+
const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
822
|
+
const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
|
|
823
|
+
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getFirstToken().getStart(), `DATA ${uniqueName} TYPE ${workAreaType}.
|
|
824
|
+
${indentation}${uniqueName} = ${source === null || source === void 0 ? void 0 : source.concatTokens()}.\n${indentation}`);
|
|
825
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, c.getFirstToken().getStart(), c.getLastToken().getEnd(), "@" + uniqueName);
|
|
826
|
+
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
827
|
+
return issue_1.Issue.atToken(lowFile, low.getFirstToken(), "SQL, outline complex @", this.getMetadata().key, this.conf.severity, fix);
|
|
828
|
+
}
|
|
694
829
|
const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
695
830
|
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), `DATA(${uniqueName}) = ${source === null || source === void 0 ? void 0 : source.concatTokens()}.\n`);
|
|
696
831
|
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, c.getFirstToken().getStart(), c.getLastToken().getEnd(), "@" + uniqueName);
|
|
@@ -732,6 +867,26 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
732
867
|
}
|
|
733
868
|
return undefined;
|
|
734
869
|
}
|
|
870
|
+
/** OPEN CURSOR @DATA(name), the cursor is always of type cursor */
|
|
871
|
+
downportOpenCursorInline(low, high, lowFile) {
|
|
872
|
+
var _a, _b, _c;
|
|
873
|
+
if (!(low.get() instanceof _statement_1.Unknown)) {
|
|
874
|
+
return undefined;
|
|
875
|
+
}
|
|
876
|
+
else if (!(high.get() instanceof Statements.OpenCursor)) {
|
|
877
|
+
return undefined;
|
|
878
|
+
}
|
|
879
|
+
const inlineData = (_b = (_a = high.findDirectExpression(Expressions.SQLTarget)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Target)) === null || _b === void 0 ? void 0 : _b.findDirectExpression(Expressions.InlineData);
|
|
880
|
+
const name = (_c = inlineData === null || inlineData === void 0 ? void 0 : inlineData.findFirstExpression(Expressions.TargetField)) === null || _c === void 0 ? void 0 : _c.concatTokens();
|
|
881
|
+
if (inlineData === undefined || name === undefined) {
|
|
882
|
+
return undefined;
|
|
883
|
+
}
|
|
884
|
+
const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
|
|
885
|
+
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getStart(), `DATA ${name} TYPE cursor.\n${indentation}`);
|
|
886
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, inlineData.getFirstToken().getStart(), inlineData.getLastToken().getEnd(), name);
|
|
887
|
+
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
888
|
+
return issue_1.Issue.atToken(lowFile, inlineData.getFirstToken(), "Outline OPEN CURSOR @DATA", this.getMetadata().key, this.conf.severity, fix);
|
|
889
|
+
}
|
|
735
890
|
downportSelectExistence(low, high, lowFile, highSyntax) {
|
|
736
891
|
var _a, _b, _c, _d;
|
|
737
892
|
if (!(low.get() instanceof _statement_1.Unknown)) {
|
|
@@ -780,7 +935,7 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
780
935
|
return undefined;
|
|
781
936
|
}
|
|
782
937
|
downportSelectFields(low, high, lowFile, _highSyntax) {
|
|
783
|
-
var _a;
|
|
938
|
+
var _a, _b, _c;
|
|
784
939
|
if (!(low.get() instanceof _statement_1.Unknown)) {
|
|
785
940
|
return undefined;
|
|
786
941
|
}
|
|
@@ -791,12 +946,19 @@ Make sure to test the downported code, it might not always be completely correct
|
|
|
791
946
|
if (fields === undefined) {
|
|
792
947
|
return undefined;
|
|
793
948
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
949
|
+
// everything behind the FIELDS keyword, including DISTINCT
|
|
950
|
+
const code = fields.concatTokens().replace(/^FIELDS\s+/i, "");
|
|
951
|
+
// the field list goes behind SELECT, or behind SINGLE [FOR UPDATE], which must stay in front of it
|
|
952
|
+
const tokens = high.getTokens();
|
|
953
|
+
let insertAfter = tokens[0];
|
|
954
|
+
if (((_a = tokens[1]) === null || _a === void 0 ? void 0 : _a.getStr().toUpperCase()) === "SINGLE") {
|
|
955
|
+
insertAfter = tokens[1];
|
|
956
|
+
if (((_b = tokens[2]) === null || _b === void 0 ? void 0 : _b.getStr().toUpperCase()) === "FOR" && ((_c = tokens[3]) === null || _c === void 0 ? void 0 : _c.getStr().toUpperCase()) === "UPDATE") {
|
|
957
|
+
insertAfter = tokens[3];
|
|
958
|
+
}
|
|
797
959
|
}
|
|
798
960
|
const fix1 = edit_helper_1.EditHelper.deleteRange(lowFile, fields.getFirstToken().getStart(), fields.getLastToken().getEnd());
|
|
799
|
-
const fix2 = edit_helper_1.EditHelper.insertAt(lowFile,
|
|
961
|
+
const fix2 = edit_helper_1.EditHelper.insertAt(lowFile, insertAfter.getEnd(), " " + code);
|
|
800
962
|
const fix = edit_helper_1.EditHelper.merge(fix1, fix2);
|
|
801
963
|
return issue_1.Issue.atToken(lowFile, fields.getFirstToken(), "Replace FIELDS", this.getMetadata().key, this.conf.severity, fix);
|
|
802
964
|
}
|
|
@@ -1085,6 +1247,14 @@ ${indentation}${uniqueName} = ${source.concatTokens()}.\n${indentation}`);
|
|
|
1085
1247
|
continue;
|
|
1086
1248
|
}
|
|
1087
1249
|
const condition = this.tableCondition(tableExpression);
|
|
1250
|
+
let guard = [];
|
|
1251
|
+
if (high.get() instanceof Statements.If) {
|
|
1252
|
+
const found = this.shortCircuitGuard(high.findDirectExpression(Expressions.Cond), fieldChain);
|
|
1253
|
+
if (found === "later") {
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
guard = found;
|
|
1257
|
+
}
|
|
1088
1258
|
// ASSIGNING, not INTO: from v740 a table expression in a read position addresses the
|
|
1089
1259
|
// row rather than copying it, so "REF #( tab[ i ]-comp )" and "ASSIGN tab[ i ]-comp"
|
|
1090
1260
|
// hand back an address INTO a work area would not preserve. The write path
|
|
@@ -1094,14 +1264,22 @@ ${indentation}${uniqueName} = ${source.concatTokens()}.\n${indentation}`);
|
|
|
1094
1264
|
const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
|
|
1095
1265
|
const firstToken = high.getFirstToken();
|
|
1096
1266
|
// note that the tabix restore should be done before throwing the exception
|
|
1267
|
+
let read = `${tabixBackup} = sy-tabix.
|
|
1268
|
+
READ TABLE ${pre} ${condition}ASSIGNING ${uniqueName}.
|
|
1269
|
+
sy-tabix = ${tabixBackup}.
|
|
1270
|
+
IF sy-subrc <> 0.
|
|
1271
|
+
RAISE EXCEPTION TYPE cx_sy_itab_line_not_found.
|
|
1272
|
+
ENDIF.`;
|
|
1273
|
+
if (guard.length > 0) {
|
|
1274
|
+
// the operands in front of the table expression are evaluated first and can stop the
|
|
1275
|
+
// evaluation, so the row is only read when they let the evaluation reach it
|
|
1276
|
+
read = `IF ${guard.join(" AND ")}.
|
|
1277
|
+
${read.replace(/^/gm, " ")}
|
|
1278
|
+
ENDIF.`;
|
|
1279
|
+
}
|
|
1097
1280
|
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, firstToken.getStart(), `FIELD-SYMBOLS ${uniqueName} LIKE LINE OF ${pre}.
|
|
1098
1281
|
${indentation}DATA ${tabixBackup} LIKE sy-tabix.
|
|
1099
|
-
${
|
|
1100
|
-
${indentation}READ TABLE ${pre} ${condition}ASSIGNING ${uniqueName}.
|
|
1101
|
-
${indentation}sy-tabix = ${tabixBackup}.
|
|
1102
|
-
${indentation}IF sy-subrc <> 0.
|
|
1103
|
-
${indentation} RAISE EXCEPTION TYPE cx_sy_itab_line_not_found.
|
|
1104
|
-
${indentation}ENDIF.
|
|
1282
|
+
${read.replace(/\n/g, "\n" + indentation).replace(/^/, indentation)}
|
|
1105
1283
|
${indentation}`);
|
|
1106
1284
|
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, startToken.getStart(), tableExpression.getLastToken().getEnd(), uniqueName);
|
|
1107
1285
|
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
@@ -1112,6 +1290,73 @@ ${indentation}`);
|
|
|
1112
1290
|
}
|
|
1113
1291
|
return undefined;
|
|
1114
1292
|
}
|
|
1293
|
+
/** ABAP evaluates the operands of AND and OR left to right and stops as soon as the result
|
|
1294
|
+
* is known, so in "IF lv_last > 0 AND tab[ lv_last ] = x." the table expression is only read
|
|
1295
|
+
* when lv_last > 0. Outlined in front of the IF, the read and its CX_SY_ITAB_LINE_NOT_FOUND
|
|
1296
|
+
* raise would run unconditionally. Returns the operands that must hold for the evaluation to
|
|
1297
|
+
* reach the target, empty when it is always reached (or the shape is not handled, which keeps
|
|
1298
|
+
* the unconditional outline), and "later" when an operand in front of it holds a table
|
|
1299
|
+
* expression itself, which must be outlined first. Operands with method calls or NEW are not
|
|
1300
|
+
* repeated in a guard, as that would evaluate them twice. */
|
|
1301
|
+
shortCircuitGuard(cond, target) {
|
|
1302
|
+
var _a;
|
|
1303
|
+
if (cond === undefined) {
|
|
1304
|
+
return [];
|
|
1305
|
+
}
|
|
1306
|
+
const guard = [];
|
|
1307
|
+
const negated = [];
|
|
1308
|
+
let term = [];
|
|
1309
|
+
for (const child of cond.getChildren()) {
|
|
1310
|
+
if (child instanceof nodes_1.TokenNode) {
|
|
1311
|
+
const operator = child.getFirstToken().getStr().toUpperCase();
|
|
1312
|
+
if (operator === "EQUIV") {
|
|
1313
|
+
return [];
|
|
1314
|
+
}
|
|
1315
|
+
else if (operator === "OR") {
|
|
1316
|
+
negated.push(term);
|
|
1317
|
+
term = [];
|
|
1318
|
+
}
|
|
1319
|
+
continue;
|
|
1320
|
+
}
|
|
1321
|
+
else if (!(child instanceof nodes_1.ExpressionNode)) {
|
|
1322
|
+
return [];
|
|
1323
|
+
}
|
|
1324
|
+
if (child.findAllExpressionsRecursive(Expressions.FieldChain).includes(target) === false) {
|
|
1325
|
+
term.push(child);
|
|
1326
|
+
continue;
|
|
1327
|
+
}
|
|
1328
|
+
guard.push(...term);
|
|
1329
|
+
let inner = [];
|
|
1330
|
+
if (child.get() instanceof Expressions.CondSub) {
|
|
1331
|
+
const found = this.shortCircuitGuard(child.findDirectExpression(Expressions.Cond), target);
|
|
1332
|
+
if (found === "later") {
|
|
1333
|
+
return found;
|
|
1334
|
+
}
|
|
1335
|
+
inner = found;
|
|
1336
|
+
}
|
|
1337
|
+
const operands = [...negated.flat(), ...guard];
|
|
1338
|
+
if (operands.some(o => o.findFirstExpression(Expressions.TableExpression) !== undefined)) {
|
|
1339
|
+
return "later";
|
|
1340
|
+
}
|
|
1341
|
+
for (const o of operands) {
|
|
1342
|
+
if (o.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
1343
|
+
return [];
|
|
1344
|
+
}
|
|
1345
|
+
for (const m of o.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
1346
|
+
const name = (_a = m.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
|
|
1347
|
+
if (_builtin_1.BuiltIn.searchBuiltin(name) === undefined) {
|
|
1348
|
+
return [];
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return [
|
|
1353
|
+
...negated.map(t => "NOT ( " + t.map(o => o.concatTokens()).join(" AND ") + " )"),
|
|
1354
|
+
...guard.map(o => o.concatTokens()),
|
|
1355
|
+
...inner
|
|
1356
|
+
];
|
|
1357
|
+
}
|
|
1358
|
+
return [];
|
|
1359
|
+
}
|
|
1115
1360
|
tableCondition(tableExpression) {
|
|
1116
1361
|
let condition = "";
|
|
1117
1362
|
let keyName = "";
|
|
@@ -1220,6 +1465,72 @@ ${indentation}`);
|
|
|
1220
1465
|
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
1221
1466
|
return issue_1.Issue.atToken(lowFile, source.getFirstToken(), "Outline built-in function in INSERT", this.getMetadata().key, this.conf.severity, fix);
|
|
1222
1467
|
}
|
|
1468
|
+
/** MOVE-CORRESPONDING between internal tables is possible from v740sp05, in 702 move row by row;
|
|
1469
|
+
* a typed target must be a standard table, as a row is added before its fields are filled, and a
|
|
1470
|
+
* fully generic target carries no table kind, so its row is added with INSERT INTO TABLE */
|
|
1471
|
+
downportMoveCorrespondingTables(high, lowFile, highSyntax) {
|
|
1472
|
+
var _a, _b;
|
|
1473
|
+
if (!(high.get() instanceof Statements.MoveCorresponding)) {
|
|
1474
|
+
return undefined;
|
|
1475
|
+
}
|
|
1476
|
+
else if (this.lowReg.getConfig().isOpenABAP()) {
|
|
1477
|
+
return undefined;
|
|
1478
|
+
}
|
|
1479
|
+
const concat = high.concatTokens().toUpperCase();
|
|
1480
|
+
if (concat.includes(" EXPANDING NESTED TABLES") || concat.startsWith("MOVE-CORRESPONDING EXACT ")) {
|
|
1481
|
+
return undefined;
|
|
1482
|
+
}
|
|
1483
|
+
const keeping = concat.includes(" KEEPING TARGET LINES");
|
|
1484
|
+
// only plain variables and field symbols, their types are known from the scope
|
|
1485
|
+
const source = high.findDirectExpression(Expressions.Source);
|
|
1486
|
+
const sourceField = source === null || source === void 0 ? void 0 : source.getFirstChild();
|
|
1487
|
+
const target = high.findDirectExpression(Expressions.SimpleTarget);
|
|
1488
|
+
if (source === undefined
|
|
1489
|
+
|| target === undefined
|
|
1490
|
+
|| source.getChildren().length !== 1
|
|
1491
|
+
|| !((sourceField === null || sourceField === void 0 ? void 0 : sourceField.get()) instanceof Expressions.FieldChain)
|
|
1492
|
+
|| sourceField.getChildren().length !== 1
|
|
1493
|
+
|| target.getChildren().length !== 1) {
|
|
1494
|
+
return undefined;
|
|
1495
|
+
}
|
|
1496
|
+
const sourceName = source.concatTokens();
|
|
1497
|
+
const targetName = target.concatTokens();
|
|
1498
|
+
if (sourceName.toUpperCase() === targetName.toUpperCase()) {
|
|
1499
|
+
return undefined;
|
|
1500
|
+
}
|
|
1501
|
+
const spag = highSyntax.spaghetti.lookupPosition(high.getFirstToken().getStart(), lowFile.getFilename());
|
|
1502
|
+
const sourceType = (_a = spag === null || spag === void 0 ? void 0 : spag.findVariable(sourceName)) === null || _a === void 0 ? void 0 : _a.getType();
|
|
1503
|
+
const targetType = (_b = spag === null || spag === void 0 ? void 0 : spag.findVariable(targetName)) === null || _b === void 0 ? void 0 : _b.getType();
|
|
1504
|
+
if (!(sourceType instanceof basic_1.TableType)
|
|
1505
|
+
|| !(targetType instanceof basic_1.TableType)
|
|
1506
|
+
|| sourceType.isWithHeader() === true
|
|
1507
|
+
|| targetType.isWithHeader() === true
|
|
1508
|
+
|| (targetType.getAccessType() !== basic_1.TableAccessType.standard && targetType.getAccessType() !== undefined)) {
|
|
1509
|
+
return undefined;
|
|
1510
|
+
}
|
|
1511
|
+
for (const t of [sourceType, targetType]) {
|
|
1512
|
+
const row = t.getRowType();
|
|
1513
|
+
if (!(row instanceof basic_1.StructureType || row instanceof basic_1.AnyType || row instanceof basic_1.VoidType)) {
|
|
1514
|
+
return undefined;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
const fsType = (name, type) => type.isGeneric() ? "TYPE any" : "LIKE LINE OF " + name;
|
|
1518
|
+
const sourceFS = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax, true);
|
|
1519
|
+
const targetFS = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax, true);
|
|
1520
|
+
const addRow = targetType.getAccessType() === undefined
|
|
1521
|
+
? `INSERT INITIAL LINE INTO TABLE ${targetName}`
|
|
1522
|
+
: `APPEND INITIAL LINE TO ${targetName}`;
|
|
1523
|
+
const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
|
|
1524
|
+
const code = `FIELD-SYMBOLS ${sourceFS} ${fsType(sourceName, sourceType)}.\n` +
|
|
1525
|
+
indentation + `FIELD-SYMBOLS ${targetFS} ${fsType(targetName, targetType)}.\n` +
|
|
1526
|
+
(keeping ? "" : indentation + `CLEAR ${targetName}.\n`) +
|
|
1527
|
+
indentation + `LOOP AT ${sourceName} ASSIGNING ${sourceFS}.\n` +
|
|
1528
|
+
indentation + ` ${addRow} ASSIGNING ${targetFS}.\n` +
|
|
1529
|
+
indentation + ` MOVE-CORRESPONDING ${sourceFS} TO ${targetFS}.\n` +
|
|
1530
|
+
indentation + `ENDLOOP.`;
|
|
1531
|
+
const fix = edit_helper_1.EditHelper.replaceRange(lowFile, high.getFirstToken().getStart(), high.getLastToken().getEnd(), code);
|
|
1532
|
+
return issue_1.Issue.atToken(lowFile, high.getFirstToken(), "Downport MOVE-CORRESPONDING with tables", this.getMetadata().key, this.conf.severity, fix);
|
|
1533
|
+
}
|
|
1223
1534
|
/** the ABAP type returned by the built-in function this Source starts with, or undefined
|
|
1224
1535
|
* if it does not start with one, or with one that predates 702 */
|
|
1225
1536
|
builtinReturnType(source, lowFile, highSyntax) {
|
|
@@ -1482,6 +1793,16 @@ ${indentation}${uniqueName2}->if_t100_message~t100key = ${uniqueName1}.\n`;
|
|
|
1482
1793
|
const fix = edit_helper_1.EditHelper.replaceToken(lowFile, token, "DEFAULT");
|
|
1483
1794
|
return issue_1.Issue.atToken(lowFile, i.getFirstToken(), "Downport EMPTY KEY", this.getMetadata().key, this.conf.severity, fix);
|
|
1484
1795
|
}
|
|
1796
|
+
if (node.get() instanceof Statements.CreateData) {
|
|
1797
|
+
// the key of CREATE DATA is not a TypeTableKey expression, its keywords are direct tokens
|
|
1798
|
+
const tokens = node.getChildren().filter(c => c instanceof nodes_1.TokenNode).map(c => c.getFirstToken());
|
|
1799
|
+
for (let j = 0; j < tokens.length - 1; j++) {
|
|
1800
|
+
if (tokens[j].getStr().toUpperCase() === "EMPTY" && tokens[j + 1].getStr().toUpperCase() === "KEY") {
|
|
1801
|
+
const fix = edit_helper_1.EditHelper.replaceToken(lowFile, tokens[j], "DEFAULT");
|
|
1802
|
+
return issue_1.Issue.atToken(lowFile, tokens[j], "Downport EMPTY KEY", this.getMetadata().key, this.conf.severity, fix);
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1485
1806
|
return undefined;
|
|
1486
1807
|
}
|
|
1487
1808
|
callFunctionParameterSimple(high, lowFile, highSyntax) {
|
|
@@ -1881,10 +2202,18 @@ CONSTANTS: BEGIN OF ${structureName},\n`;
|
|
|
1881
2202
|
if (!(low.get() instanceof _statement_1.Unknown)) {
|
|
1882
2203
|
return undefined;
|
|
1883
2204
|
}
|
|
1884
|
-
|
|
1885
|
-
|
|
2205
|
+
let target = undefined;
|
|
2206
|
+
if (high.get() instanceof Statements.Move) {
|
|
2207
|
+
target = high.findDirectExpression(Expressions.Target);
|
|
2208
|
+
}
|
|
2209
|
+
else if (high.get() instanceof Statements.Clear
|
|
2210
|
+
|| high.get() instanceof Statements.Free
|
|
2211
|
+
|| high.get() instanceof Statements.Append
|
|
2212
|
+
|| high.get() instanceof Statements.InsertInternal) {
|
|
2213
|
+
// the writable operand, eg. "CLEAR tab[ 1 ]-comp" or "APPEND 1 TO tab[ 1 ]-sub", is a Target
|
|
2214
|
+
// just like the left-hand side of an assignment, so it is lowered the same way
|
|
2215
|
+
target = high.findDirectExpressions(Expressions.Target).find(t => t.findDirectExpression(Expressions.TableExpression) !== undefined);
|
|
1886
2216
|
}
|
|
1887
|
-
const target = high.findDirectExpression(Expressions.Target);
|
|
1888
2217
|
if (target === undefined) {
|
|
1889
2218
|
return undefined;
|
|
1890
2219
|
}
|
|
@@ -1910,13 +2239,16 @@ ${indentation}sy-tabix = ${tabixBackup}.
|
|
|
1910
2239
|
${indentation}IF sy-subrc <> 0.
|
|
1911
2240
|
${indentation} RAISE EXCEPTION TYPE cx_sy_itab_line_not_found.
|
|
1912
2241
|
${indentation}ENDIF.
|
|
1913
|
-
${indentation}
|
|
2242
|
+
${indentation}`;
|
|
1914
2243
|
const start = target.getFirstToken().getStart();
|
|
1915
2244
|
const end = (_a = tableExpression.findDirectTokenByText("]")) === null || _a === void 0 ? void 0 : _a.getEnd();
|
|
1916
2245
|
if (end === undefined) {
|
|
1917
2246
|
return undefined;
|
|
1918
2247
|
}
|
|
1919
|
-
|
|
2248
|
+
// the READ TABLE goes in front of the statement, the target need not be its first operand
|
|
2249
|
+
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getFirstToken().getStart(), code);
|
|
2250
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, start, end, uniqueName);
|
|
2251
|
+
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
1920
2252
|
return issue_1.Issue.atToken(lowFile, high.getFirstToken(), "Downport, move with table target", this.getMetadata().key, this.conf.severity, fix);
|
|
1921
2253
|
}
|
|
1922
2254
|
moveWithOperator(low, high, lowFile) {
|
|
@@ -2433,9 +2765,31 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
2433
2765
|
else {
|
|
2434
2766
|
type = "TYPE " + type;
|
|
2435
2767
|
}
|
|
2768
|
+
let move = indentation + `MOVE-CORRESPONDING ${correspondingBody === null || correspondingBody === void 0 ? void 0 : correspondingBody.concatTokens()} TO ${uniqueName}.\n`;
|
|
2769
|
+
if ((correspondingBody === null || correspondingBody === void 0 ? void 0 : correspondingBody.findDirectTokenByText("EXCEPT")) !== undefined) {
|
|
2770
|
+
// MOVE-CORRESPONDING has no EXCEPT, move everything and clear the excepted components afterwards
|
|
2771
|
+
if (correspondingBody.findDirectExpression(Expressions.CorrespondingBodyMapping) !== undefined
|
|
2772
|
+
|| !(this.findCorrespondingType(s, high, lowFile, highSyntax) instanceof basic_1.StructureType)) {
|
|
2773
|
+
continue;
|
|
2774
|
+
}
|
|
2775
|
+
const children = correspondingBody.getChildren();
|
|
2776
|
+
const exceptIndex = children.findIndex(c => c instanceof nodes_1.TokenNode && c.getFirstToken().getStr().toUpperCase() === "EXCEPT");
|
|
2777
|
+
const fields = correspondingBody.findDirectExpressions(Expressions.Field);
|
|
2778
|
+
if (fields.length === 0) {
|
|
2779
|
+
// EXCEPT *, without MAPPING nothing is moved
|
|
2780
|
+
move = "";
|
|
2781
|
+
}
|
|
2782
|
+
else {
|
|
2783
|
+
const body = children.slice(0, exceptIndex).map(c => c.concatTokens()).join(" ");
|
|
2784
|
+
move = indentation + `MOVE-CORRESPONDING ${body} TO ${uniqueName}.\n`;
|
|
2785
|
+
for (const f of fields) {
|
|
2786
|
+
move += indentation + `CLEAR ${uniqueName}-${f.concatTokens()}.\n`;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2436
2790
|
const abap = `DATA ${uniqueName} ${type}.\n` +
|
|
2437
2791
|
indentation + `CLEAR ${uniqueName}.\n` + // might be called inside a loop
|
|
2438
|
-
|
|
2792
|
+
move +
|
|
2439
2793
|
indentation;
|
|
2440
2794
|
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getFirstToken().getStart(), abap);
|
|
2441
2795
|
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, firstToken.getStart(), s.getLastToken().getEnd(), uniqueName);
|
|
@@ -2679,6 +3033,33 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
2679
3033
|
const issue = issue_1.Issue.atPosition(lowFile, pos, "Rename before outline", this.getMetadata().key, this.conf.severity, fix);
|
|
2680
3034
|
throw new SkipToNextFile(issue);
|
|
2681
3035
|
}
|
|
3036
|
+
/** the type of the value a CORRESPONDING operator returns, if it can be determined */
|
|
3037
|
+
findCorrespondingType(s, high, lowFile, highSyntax) {
|
|
3038
|
+
var _a, _b;
|
|
3039
|
+
const expr = s.findDirectExpression(Expressions.TypeNameOrInfer);
|
|
3040
|
+
if (expr === undefined) {
|
|
3041
|
+
return undefined;
|
|
3042
|
+
}
|
|
3043
|
+
const spag = highSyntax.spaghetti.lookupPosition(expr.getFirstToken().getStart(), lowFile.getFilename());
|
|
3044
|
+
if (spag === undefined) {
|
|
3045
|
+
return undefined;
|
|
3046
|
+
}
|
|
3047
|
+
if (expr.concatTokens() !== "#") {
|
|
3048
|
+
return (_a = spag.findType(expr.concatTokens())) === null || _a === void 0 ? void 0 : _a.getType();
|
|
3049
|
+
}
|
|
3050
|
+
for (const r of spag.getData().references) {
|
|
3051
|
+
if (r.referenceType === _reference_1.ReferenceType.InferredType
|
|
3052
|
+
&& r.resolved instanceof _typed_identifier_1.TypedIdentifier
|
|
3053
|
+
&& r.position.getStart().equals(expr.getFirstToken().getStart())) {
|
|
3054
|
+
return r.resolved.getType();
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
const target = high.findDirectExpression(Expressions.Target);
|
|
3058
|
+
if (high.get() instanceof Statements.Move && high.findDirectExpression(Expressions.Source) === s && target !== undefined) {
|
|
3059
|
+
return (_b = spag.findVariable(target.concatTokens())) === null || _b === void 0 ? void 0 : _b.getType();
|
|
3060
|
+
}
|
|
3061
|
+
return undefined;
|
|
3062
|
+
}
|
|
2682
3063
|
findType(i, lowFile, highSyntax, ref = false) {
|
|
2683
3064
|
var _a, _b;
|
|
2684
3065
|
const expr = i.findDirectExpression(Expressions.TypeNameOrInfer);
|
|
@@ -2755,6 +3136,48 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
2755
3136
|
}
|
|
2756
3137
|
return undefined;
|
|
2757
3138
|
}
|
|
3139
|
+
/** READ TABLE [REFERENCE] INTO DATA( ) where the row type is void, no TYPE can be written, use LIKE LINE OF like LOOP does */
|
|
3140
|
+
outlineReadTableVoidTarget(node, lowFile, highSyntax) {
|
|
3141
|
+
var _a, _b;
|
|
3142
|
+
if (!(node.get() instanceof Statements.ReadTable)) {
|
|
3143
|
+
return undefined;
|
|
3144
|
+
}
|
|
3145
|
+
if (this.lowReg.getConfig().isOpenABAP()) {
|
|
3146
|
+
return undefined;
|
|
3147
|
+
}
|
|
3148
|
+
const source = node.findDirectExpression(Expressions.SimpleSource2);
|
|
3149
|
+
const target = node.findDirectExpression(Expressions.ReadTableTarget);
|
|
3150
|
+
const inline = (_a = target === null || target === void 0 ? void 0 : target.findDirectExpression(Expressions.Target)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.InlineData);
|
|
3151
|
+
if (source === undefined || target === undefined || inline === undefined) {
|
|
3152
|
+
return undefined;
|
|
3153
|
+
}
|
|
3154
|
+
const nameToken = (_b = inline.findDirectExpression(Expressions.TargetField)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
|
|
3155
|
+
if (nameToken === undefined) {
|
|
3156
|
+
return undefined;
|
|
3157
|
+
}
|
|
3158
|
+
const name = nameToken.getStr();
|
|
3159
|
+
const spag = highSyntax.spaghetti.lookupPosition(nameToken.getStart(), lowFile.getFilename());
|
|
3160
|
+
const found = spag === null || spag === void 0 ? void 0 : spag.findVariable(name);
|
|
3161
|
+
const table = spag === null || spag === void 0 ? void 0 : spag.findVariable(source.concatTokens());
|
|
3162
|
+
const isReference = target.findDirectTokenByText("REFERENCE") !== undefined;
|
|
3163
|
+
if (isReference === true && !((table === null || table === void 0 ? void 0 : table.getType()) instanceof basic_1.VoidType)) {
|
|
3164
|
+
return undefined;
|
|
3165
|
+
}
|
|
3166
|
+
else if (isReference === false
|
|
3167
|
+
&& (!((found === null || found === void 0 ? void 0 : found.getType()) instanceof basic_1.VoidType) || found.getType().getQualifiedName() !== undefined)) {
|
|
3168
|
+
return undefined;
|
|
3169
|
+
}
|
|
3170
|
+
const indentation = " ".repeat(node.getFirstToken().getStart().getCol() - 1);
|
|
3171
|
+
let code = `DATA ${name} LIKE LINE OF ${source.concatTokens()}.\n${indentation}`;
|
|
3172
|
+
if (isReference === true) {
|
|
3173
|
+
const likeName = this.uniqueName(node.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
3174
|
+
code = `DATA ${likeName} LIKE LINE OF ${source.concatTokens()}.\n${indentation}DATA ${name} LIKE REF TO ${likeName}.\n${indentation}`;
|
|
3175
|
+
}
|
|
3176
|
+
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, node.getFirstToken().getStart(), code);
|
|
3177
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, inline.getFirstToken().getStart(), inline.getLastToken().getEnd(), name);
|
|
3178
|
+
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
3179
|
+
return issue_1.Issue.atToken(lowFile, inline.getFirstToken(), "Outline DATA", this.getMetadata().key, this.conf.severity, fix);
|
|
3180
|
+
}
|
|
2758
3181
|
outlineData(node, lowFile, highSyntax) {
|
|
2759
3182
|
// hmm, no guard here, as DATA(SDF) is valid in 702
|
|
2760
3183
|
var _a, _b;
|
|
@@ -3279,6 +3702,54 @@ ${indentation} output = ${uniqueName}.\n`;
|
|
|
3279
3702
|
}
|
|
3280
3703
|
return undefined;
|
|
3281
3704
|
}
|
|
3705
|
+
/** IS [NOT] INSTANCE OF is 750, outline it as a cast in a TRY before the statement,
|
|
3706
|
+
* the cast of an initial reference succeeds, while IS INSTANCE OF is false, hence the IS BOUND */
|
|
3707
|
+
replaceInstanceOf(low, high, lowFile, highSyntax, highFile) {
|
|
3708
|
+
if (!(low.get() instanceof _statement_1.Unknown)) {
|
|
3709
|
+
return undefined;
|
|
3710
|
+
}
|
|
3711
|
+
else if (!(high.get() instanceof Statements.If)
|
|
3712
|
+
&& !(high.get() instanceof Statements.ElseIf)
|
|
3713
|
+
&& !(high.get() instanceof Statements.Check)) {
|
|
3714
|
+
// the condition of eg. WHILE is evaluated more than once
|
|
3715
|
+
return undefined;
|
|
3716
|
+
}
|
|
3717
|
+
for (const c of high.findAllExpressionsRecursive(Expressions.Compare)) {
|
|
3718
|
+
const className = c.findDirectExpression(Expressions.ClassName);
|
|
3719
|
+
const source = c.findDirectExpression(Expressions.Source);
|
|
3720
|
+
if (className === undefined || source === undefined) {
|
|
3721
|
+
continue;
|
|
3722
|
+
}
|
|
3723
|
+
const children = c.getChildren();
|
|
3724
|
+
const operator = children.slice(children.indexOf(source) + 1).map(n => n.concatTokens().toUpperCase()).join(" ");
|
|
3725
|
+
const negated = operator.startsWith("IS NOT INSTANCE OF");
|
|
3726
|
+
let insertAt = high.getFirstToken().getStart();
|
|
3727
|
+
if (high.get() instanceof Statements.ElseIf) {
|
|
3728
|
+
// assumption: no side effects in IF conditions
|
|
3729
|
+
insertAt = this.findStartOfIf(high, highFile);
|
|
3730
|
+
if (insertAt === undefined) {
|
|
3731
|
+
return undefined;
|
|
3732
|
+
}
|
|
3733
|
+
}
|
|
3734
|
+
const castName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
3735
|
+
const boolName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
|
|
3736
|
+
const indentation = " ".repeat(insertAt.getCol() - 1);
|
|
3737
|
+
const code = `DATA ${castName} TYPE REF TO ${className.concatTokens()}.
|
|
3738
|
+
${indentation}DATA ${boolName} TYPE abap_bool.
|
|
3739
|
+
${indentation}TRY.
|
|
3740
|
+
${indentation} ${castName} ?= ${source.concatTokens()}.
|
|
3741
|
+
${indentation} ${boolName} = boolc( ${castName} IS BOUND ).
|
|
3742
|
+
${indentation} CATCH cx_sy_move_cast_error.
|
|
3743
|
+
${indentation} ${boolName} = abap_false.
|
|
3744
|
+
${indentation}ENDTRY.
|
|
3745
|
+
${indentation}`;
|
|
3746
|
+
const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, insertAt, code);
|
|
3747
|
+
const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, source.getFirstToken().getStart(), className.getLastToken().getEnd(), boolName + (negated ? " = abap_false" : " = abap_true"));
|
|
3748
|
+
const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
|
|
3749
|
+
return issue_1.Issue.atToken(lowFile, source.getFirstToken(), "Downport IS INSTANCE OF", this.getMetadata().key, this.conf.severity, fix);
|
|
3750
|
+
}
|
|
3751
|
+
return undefined;
|
|
3752
|
+
}
|
|
3282
3753
|
/** sy-subrc and sy-tabix, when read from the position on, in the procedure around it or the file outside of one;
|
|
3283
3754
|
* inside a loop from the start of the outermost loop, as the next pass reads what this one left */
|
|
3284
3755
|
readSyFields(position, highFile) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/core",
|
|
3
|
-
"version": "2.120.
|
|
3
|
+
"version": "2.120.94",
|
|
4
4
|
"description": "abaplint - Core API",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"typings": "build/abaplint.d.ts",
|
|
@@ -52,21 +52,21 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://abaplint.org",
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@microsoft/api-extractor": "^7.
|
|
55
|
+
"@microsoft/api-extractor": "^7.60.1",
|
|
56
56
|
"@types/chai": "^4.3.20",
|
|
57
57
|
"@types/mocha": "^10.0.10",
|
|
58
58
|
"@types/node": "^24.13.3",
|
|
59
59
|
"c8": "^11.0.0",
|
|
60
60
|
"chai": "^4.5.0",
|
|
61
61
|
"eslint": "^9.39.5",
|
|
62
|
-
"mocha": "^11.
|
|
63
|
-
"rimraf": "^6.1.
|
|
62
|
+
"mocha": "^11.8.0",
|
|
63
|
+
"rimraf": "^6.1.4",
|
|
64
64
|
"source-map-support": "^0.5.21",
|
|
65
65
|
"ts-json-schema-generator": "^2.9.0",
|
|
66
66
|
"typescript": "^7.0.2"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"fast-xml-parser": "^5.
|
|
69
|
+
"fast-xml-parser": "^5.12.0",
|
|
70
70
|
"json5": "^2.2.3",
|
|
71
71
|
"vscode-languageserver-types": "^3.18.0"
|
|
72
72
|
}
|