@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
package/build/abaplint.d.ts
CHANGED
|
@@ -1591,6 +1591,11 @@ export declare class CurrentScope {
|
|
|
1591
1591
|
protected allowHeaderUse: string | undefined;
|
|
1592
1592
|
protected parentObj: IObject;
|
|
1593
1593
|
private readonly localFriends;
|
|
1594
|
+
/** types of the FOR and LET names used in a procedure, key is the scope node of the procedure */
|
|
1595
|
+
private readonly localNameTypes;
|
|
1596
|
+
/** row type of the members of a group, key is the identifier of the group variable,
|
|
1597
|
+
* a LOOP AT ... GROUP BY binds the group until its ENDLOOP */
|
|
1598
|
+
private readonly groupMemberTypes;
|
|
1594
1599
|
static buildDefault(reg: IRegistry, obj: IObject): CurrentScope;
|
|
1595
1600
|
private static addBuiltIn;
|
|
1596
1601
|
private constructor();
|
|
@@ -1651,6 +1656,20 @@ export declare class CurrentScope {
|
|
|
1651
1656
|
isInStaticMethod(): boolean;
|
|
1652
1657
|
addLocalFriend(className: string, friendName: string): void;
|
|
1653
1658
|
isLocalFriend(className: string, friendName: string): boolean;
|
|
1659
|
+
/**
|
|
1660
|
+
* Checks a local name of a constructor expression, FOR, LET and REDUCE INIT, before it is added,
|
|
1661
|
+
* returns the error message, or undefined when the name can be declared.
|
|
1662
|
+
* The name cannot be a data object of the procedure or of an enclosing expression, attributes and
|
|
1663
|
+
* globals seen from a method or a form are only obscured, which ABAP reports as a warning.
|
|
1664
|
+
* Within a procedure, a name can be reused by another expression only with the same type.
|
|
1665
|
+
*/
|
|
1666
|
+
checkLocalName(name: string, type: AbstractType | undefined): string | undefined;
|
|
1667
|
+
/** types are compared by their structure, ABAP compares the declared types, so this finds a subset of the errors */
|
|
1668
|
+
private static isComparable;
|
|
1669
|
+
setGroupMemberType(group: TypedIdentifier, rowType: AbstractType): void;
|
|
1670
|
+
findGroupMemberType(group: TypedIdentifier): AbstractType | undefined;
|
|
1671
|
+
removeGroupMemberType(group: TypedIdentifier): void;
|
|
1672
|
+
private static groupKey;
|
|
1654
1673
|
getEnclosingMethodName(): string | undefined;
|
|
1655
1674
|
getEnclosingClassName(): string | undefined;
|
|
1656
1675
|
isGlobalOO(): boolean;
|
|
@@ -3086,12 +3105,17 @@ declare class FunctionModuleDefinition {
|
|
|
3086
3105
|
private parameters;
|
|
3087
3106
|
private globalParameters;
|
|
3088
3107
|
private moduleType;
|
|
3108
|
+
private exceptions;
|
|
3109
|
+
private classBasedExceptions;
|
|
3089
3110
|
constructor(data: any);
|
|
3090
3111
|
getParameters(): readonly IFunctionModuleParameter[];
|
|
3091
3112
|
getModuleType(): FunctionModuleType | undefined;
|
|
3092
3113
|
getDescription(): string | undefined;
|
|
3093
3114
|
getName(): string;
|
|
3094
3115
|
isGlobalParameters(): boolean;
|
|
3116
|
+
/** the classic exceptions, or the exception classes if isClassBasedExceptions() */
|
|
3117
|
+
getExceptions(): readonly string[];
|
|
3118
|
+
isClassBasedExceptions(): boolean;
|
|
3095
3119
|
private parse;
|
|
3096
3120
|
}
|
|
3097
3121
|
|
|
@@ -8,7 +8,7 @@ class AuthorityCheck {
|
|
|
8
8
|
getMatcher() {
|
|
9
9
|
const field = (0, combi_1.seq)("FIELD", expressions_1.Source);
|
|
10
10
|
const id = (0, combi_1.seq)("ID", expressions_1.Source, (0, combi_1.alt)(field, "DUMMY"));
|
|
11
|
-
const ret = (0, combi_1.seq)("AUTHORITY-CHECK OBJECT", expressions_1.Source, (0, combi_1.opt)((0, combi_1.seq)("FOR USER", expressions_1.Source)), (0, combi_1.plus)(id));
|
|
11
|
+
const ret = (0, combi_1.seq)("AUTHORITY-CHECK OBJECT", expressions_1.Source, (0, combi_1.opt)((0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.seq)("FOR USER", expressions_1.Source))), (0, combi_1.plus)(id));
|
|
12
12
|
return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, ret);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -7,7 +7,7 @@ const version_1 = require("../../../version");
|
|
|
7
7
|
class Commit {
|
|
8
8
|
getMatcher() {
|
|
9
9
|
const work = (0, combi_1.seq)("WORK", (0, combi_1.opt)("AND WAIT"));
|
|
10
|
-
return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("COMMIT", (0, combi_1.alt)(work, expressions_1.DatabaseConnection)));
|
|
10
|
+
return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("COMMIT", (0, combi_1.alt)(work, (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, expressions_1.DatabaseConnection))));
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.Commit = Commit;
|
|
@@ -17,9 +17,9 @@ class Convert {
|
|
|
17
17
|
const tim = (0, combi_1.seq)("TIME", expressions_1.Source);
|
|
18
18
|
const stamp = (0, combi_1.seq)("INTO TIME STAMP", expressions_1.Target);
|
|
19
19
|
const intoutc = (0, combi_1.ver)(version_1.Release.v754, (0, combi_1.seq)("INTO UTCLONG", expressions_1.Target), { also: combi_1.AlsoIn.OpenABAP });
|
|
20
|
-
const invert = (0, combi_1.seq)("INTO INVERTED-DATE", expressions_1.Target);
|
|
20
|
+
const invert = (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.seq)("INTO INVERTED-DATE", expressions_1.Target));
|
|
21
21
|
const date = (0, combi_1.seq)((0, combi_1.per)(dat, tim), (0, combi_1.per)(daylightSource, stamp, zone, invert, intoutc));
|
|
22
|
-
const inv = (0, combi_1.seq)("INVERTED-DATE", expressions_1.Source, "INTO DATE", expressions_1.Target);
|
|
22
|
+
const inv = (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.seq)("INVERTED-DATE", expressions_1.Source, "INTO DATE", expressions_1.Target));
|
|
23
23
|
const utclong = (0, combi_1.ver)(version_1.Release.v754, (0, combi_1.seq)("UTCLONG", expressions_1.Source, (0, combi_1.per)(zone, into, daylightTarget)), { also: combi_1.AlsoIn.OpenABAP });
|
|
24
24
|
return (0, combi_1.seq)("CONVERT", (0, combi_1.alt)(time, date, inv, utclong));
|
|
25
25
|
}
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Do = void 0;
|
|
4
4
|
const combi_1 = require("../combi");
|
|
5
|
+
const version_1 = require("../../../version");
|
|
5
6
|
const expressions_1 = require("../expressions");
|
|
6
7
|
class Do {
|
|
7
8
|
getMatcher() {
|
|
8
9
|
const range = (0, combi_1.seq)("RANGE", expressions_1.Source);
|
|
9
10
|
const vary = (0, combi_1.seq)("VARYING", expressions_1.Target, "FROM", expressions_1.Source, "NEXT", expressions_1.Source, (0, combi_1.optPrio)(range));
|
|
10
11
|
const times = (0, combi_1.seq)(expressions_1.Source, "TIMES");
|
|
11
|
-
return (0, combi_1.seq)("DO", (0, combi_1.optPrio)((0, combi_1.per)((0, combi_1.plus)(vary), times)));
|
|
12
|
+
return (0, combi_1.seq)("DO", (0, combi_1.optPrio)((0, combi_1.per)((0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.plus)(vary)), times)));
|
|
12
13
|
}
|
|
13
14
|
}
|
|
14
15
|
exports.Do = Do;
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Exit = void 0;
|
|
4
4
|
const combi_1 = require("../combi");
|
|
5
|
+
const version_1 = require("../../../version");
|
|
5
6
|
class Exit {
|
|
6
7
|
getMatcher() {
|
|
7
|
-
return (0, combi_1.seq)("EXIT", (0, combi_1.opt)((0, combi_1.alt)("FROM SQL", "FROM STEP-LOOP")));
|
|
8
|
+
return (0, combi_1.seq)("EXIT", (0, combi_1.opt)((0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.alt)("FROM SQL", "FROM STEP-LOOP"))));
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
11
|
exports.Exit = Exit;
|
|
@@ -6,8 +6,9 @@ const expressions_1 = require("../expressions");
|
|
|
6
6
|
const version_1 = require("../../../version");
|
|
7
7
|
class GetTime {
|
|
8
8
|
getMatcher() {
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const stamp = (0, combi_1.seq)("GET TIME STAMP FIELD", expressions_1.Target);
|
|
10
|
+
const time = (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.seq)("GET TIME", (0, combi_1.opt)((0, combi_1.seq)("FIELD", expressions_1.Target))));
|
|
11
|
+
return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.alt)(stamp, time));
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
exports.GetTime = GetTime;
|
|
@@ -42,7 +42,7 @@ const expressions_1 = require("../expressions");
|
|
|
42
42
|
class Perform {
|
|
43
43
|
getMatcher() {
|
|
44
44
|
const level = (0, combi_1.seq)("LEVEL", Expressions.Source);
|
|
45
|
-
const commit = (0, combi_1.alt)((0, combi_1.seq)("ON COMMIT", (0, combi_1.opt)(level)), "ON ROLLBACK");
|
|
45
|
+
const commit = (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.alt)((0, combi_1.seq)("ON COMMIT", (0, combi_1.opt)(level)), "ON ROLLBACK"));
|
|
46
46
|
const short = (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, (0, combi_1.seq)(Expressions.FormName, (0, combi_1.tok)(tokens_1.ParenLeft), Expressions.IncludeName, (0, combi_1.tok)(tokens_1.ParenRightW)));
|
|
47
47
|
const program = (0, combi_1.seq)("IN PROGRAM", (0, combi_1.opt)((0, combi_1.alt)(Expressions.Dynamic, Expressions.IncludeName)));
|
|
48
48
|
const found = (0, combi_1.str)("IF FOUND");
|
|
@@ -6,7 +6,7 @@ const expressions_1 = require("../expressions");
|
|
|
6
6
|
const version_1 = require("../../../version");
|
|
7
7
|
class Rollback {
|
|
8
8
|
getMatcher() {
|
|
9
|
-
return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("ROLLBACK", (0, combi_1.altPrio)("WORK", expressions_1.DatabaseConnection)));
|
|
9
|
+
return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("ROLLBACK", (0, combi_1.altPrio)("WORK", (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, expressions_1.DatabaseConnection))));
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.Rollback = Rollback;
|
|
@@ -14,7 +14,7 @@ class Wait {
|
|
|
14
14
|
const type = (0, combi_1.seq)("FOR", (0, combi_1.per)(channels, push, tasks));
|
|
15
15
|
const until = (0, combi_1.seq)((0, combi_1.opt)(type), "UNTIL", expressions_1.Cond, (0, combi_1.opt)(up));
|
|
16
16
|
const ret = (0, combi_1.seq)("WAIT", (0, combi_1.alt)(until, up));
|
|
17
|
-
return (0, combi_1.verNotLang)(version_1.LanguageVersion.
|
|
17
|
+
return (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, ret);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.Wait = Wait;
|
|
@@ -8,6 +8,9 @@ const spaghetti_scope_1 = require("./spaghetti_scope");
|
|
|
8
8
|
const _identifier_1 = require("../4_file_information/_identifier");
|
|
9
9
|
const _scope_type_1 = require("./_scope_type");
|
|
10
10
|
const syntax_1 = require("./syntax");
|
|
11
|
+
const basic_1 = require("../types/basic");
|
|
12
|
+
/** scopes of constructor expressions, their names are local to the expression */
|
|
13
|
+
const EXPRESSION_SCOPES = new Set([_scope_type_1.ScopeType.For, _scope_type_1.ScopeType.Let, _scope_type_1.ScopeType.OpenSQL]);
|
|
11
14
|
class CurrentScope {
|
|
12
15
|
static buildDefault(reg, obj) {
|
|
13
16
|
const s = new CurrentScope(reg, obj);
|
|
@@ -30,6 +33,11 @@ class CurrentScope {
|
|
|
30
33
|
}
|
|
31
34
|
constructor(reg, obj) {
|
|
32
35
|
this.localFriends = new Map();
|
|
36
|
+
/** types of the FOR and LET names used in a procedure, key is the scope node of the procedure */
|
|
37
|
+
this.localNameTypes = new WeakMap();
|
|
38
|
+
/** row type of the members of a group, key is the identifier of the group variable,
|
|
39
|
+
* a LOOP AT ... GROUP BY binds the group until its ENDLOOP */
|
|
40
|
+
this.groupMemberTypes = new Map();
|
|
33
41
|
this.current = undefined;
|
|
34
42
|
this.parentObj = obj;
|
|
35
43
|
this.reg = reg;
|
|
@@ -518,6 +526,62 @@ class CurrentScope {
|
|
|
518
526
|
var _a;
|
|
519
527
|
return ((_a = this.localFriends.get(className.toUpperCase())) === null || _a === void 0 ? void 0 : _a.includes(friendName.toUpperCase())) === true;
|
|
520
528
|
}
|
|
529
|
+
/**
|
|
530
|
+
* Checks a local name of a constructor expression, FOR, LET and REDUCE INIT, before it is added,
|
|
531
|
+
* returns the error message, or undefined when the name can be declared.
|
|
532
|
+
* The name cannot be a data object of the procedure or of an enclosing expression, attributes and
|
|
533
|
+
* globals seen from a method or a form are only obscured, which ABAP reports as a warning.
|
|
534
|
+
* Within a procedure, a name can be reused by another expression only with the same type.
|
|
535
|
+
*/
|
|
536
|
+
checkLocalName(name, type) {
|
|
537
|
+
const upper = name.toUpperCase();
|
|
538
|
+
let procedure = this.current;
|
|
539
|
+
while (procedure !== undefined) {
|
|
540
|
+
if (procedure.getData().vars[upper] !== undefined) {
|
|
541
|
+
return `Variable ${name} already defined`;
|
|
542
|
+
}
|
|
543
|
+
if (EXPRESSION_SCOPES.has(procedure.getIdentifier().stype) === false) {
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
procedure = procedure.getParent();
|
|
547
|
+
}
|
|
548
|
+
if (procedure === undefined || type === undefined || CurrentScope.isComparable(type) === false) {
|
|
549
|
+
return undefined;
|
|
550
|
+
}
|
|
551
|
+
let names = this.localNameTypes.get(procedure);
|
|
552
|
+
if (names === undefined) {
|
|
553
|
+
names = new Map();
|
|
554
|
+
this.localNameTypes.set(procedure, names);
|
|
555
|
+
}
|
|
556
|
+
const previous = names.get(upper);
|
|
557
|
+
if (previous === undefined) {
|
|
558
|
+
names.set(upper, type);
|
|
559
|
+
}
|
|
560
|
+
else if (previous.toText(0) !== type.toText(0)) {
|
|
561
|
+
return `Variable ${name} already defined with a different type`;
|
|
562
|
+
}
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
/** types are compared by their structure, ABAP compares the declared types, so this finds a subset of the errors */
|
|
566
|
+
static isComparable(type) {
|
|
567
|
+
return !(type instanceof basic_1.VoidType)
|
|
568
|
+
&& !(type instanceof basic_1.UnknownType)
|
|
569
|
+
&& type.containsVoid() === false
|
|
570
|
+
&& type.isGeneric() === false
|
|
571
|
+
&& type.toText(0).includes("Unknown type") === false;
|
|
572
|
+
}
|
|
573
|
+
setGroupMemberType(group, rowType) {
|
|
574
|
+
this.groupMemberTypes.set(CurrentScope.groupKey(group), rowType);
|
|
575
|
+
}
|
|
576
|
+
findGroupMemberType(group) {
|
|
577
|
+
return this.groupMemberTypes.get(CurrentScope.groupKey(group));
|
|
578
|
+
}
|
|
579
|
+
removeGroupMemberType(group) {
|
|
580
|
+
this.groupMemberTypes.delete(CurrentScope.groupKey(group));
|
|
581
|
+
}
|
|
582
|
+
static groupKey(group) {
|
|
583
|
+
return group.getFilename() + ":" + group.getStart().getRow() + ":" + group.getStart().getCol();
|
|
584
|
+
}
|
|
521
585
|
getEnclosingMethodName() {
|
|
522
586
|
let curr = this.current;
|
|
523
587
|
while (curr !== undefined) {
|
|
@@ -42,9 +42,11 @@ const _scope_type_1 = require("../_scope_type");
|
|
|
42
42
|
const component_cond_1 = require("./component_cond");
|
|
43
43
|
const cond_1 = require("./cond");
|
|
44
44
|
const basic_1 = require("../../types/basic");
|
|
45
|
+
const loop_group_by_1 = require("./loop_group_by");
|
|
45
46
|
const _typed_identifier_1 = require("../../types/_typed_identifier");
|
|
46
47
|
const _reference_1 = require("../_reference");
|
|
47
48
|
const let_1 = require("./let");
|
|
49
|
+
const _syntax_input_1 = require("../_syntax_input");
|
|
48
50
|
class For {
|
|
49
51
|
static runSyntax(node, input) {
|
|
50
52
|
var _a;
|
|
@@ -68,13 +70,19 @@ class For {
|
|
|
68
70
|
for (const f of inlineField) {
|
|
69
71
|
inline_field_definition_1.InlineFieldDefinition.runSyntax(f, input);
|
|
70
72
|
}
|
|
73
|
+
let groupsSource = undefined;
|
|
71
74
|
if (groupsToken !== undefined) {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
const message = input.scope.checkLocalName(groupsToken.getStr(), undefined);
|
|
76
|
+
if (message !== undefined) {
|
|
77
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, groupsToken, message));
|
|
78
|
+
return scoped;
|
|
79
|
+
}
|
|
80
|
+
groupsSource = this.runGroups(node, groupsToken, input);
|
|
76
81
|
}
|
|
77
82
|
for (const s of node.findDirectExpressions(Expressions.Source)) {
|
|
83
|
+
if (s === groupsSource) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
78
86
|
source_1.Source.runSyntax(s, input);
|
|
79
87
|
}
|
|
80
88
|
for (const s of node.findDirectExpressions(Expressions.ComponentCond)) {
|
|
@@ -88,6 +96,32 @@ class For {
|
|
|
88
96
|
}
|
|
89
97
|
return scoped;
|
|
90
98
|
}
|
|
99
|
+
/** FOR GROUPS group OF wa IN itab GROUP BY key, returns the itab source */
|
|
100
|
+
static runGroups(node, groupsToken, input) {
|
|
101
|
+
var _a;
|
|
102
|
+
const tableSource = node.findExpressionAfterToken("IN");
|
|
103
|
+
let rowType = basic_1.VoidType.get("ForGroups");
|
|
104
|
+
if ((tableSource === null || tableSource === void 0 ? void 0 : tableSource.get()) instanceof Expressions.Source) {
|
|
105
|
+
const tableType = source_1.Source.runSyntax(tableSource, input);
|
|
106
|
+
if (tableType instanceof basic_1.TableType) {
|
|
107
|
+
rowType = tableType.getRowType();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const waToken = (_a = node.findExpressionAfterToken("OF")) === null || _a === void 0 ? void 0 : _a.getFirstToken();
|
|
111
|
+
if (waToken !== undefined) {
|
|
112
|
+
const wa = new _typed_identifier_1.TypedIdentifier(waToken, input.filename, rowType, ["inline" /* IdentifierMeta.InlineDefinition */]);
|
|
113
|
+
input.scope.addIdentifier(wa);
|
|
114
|
+
input.scope.addReference(waToken, wa, _reference_1.ReferenceType.DataWriteReference, input.filename);
|
|
115
|
+
}
|
|
116
|
+
const keyType = node.findDirectTokenByText("BY") !== undefined
|
|
117
|
+
? loop_group_by_1.LoopGroupBy.runKey(node, input)
|
|
118
|
+
: basic_1.VoidType.get("ForGroups");
|
|
119
|
+
const group = new _typed_identifier_1.TypedIdentifier(groupsToken, input.filename, keyType, ["inline" /* IdentifierMeta.InlineDefinition */]);
|
|
120
|
+
input.scope.addIdentifier(group);
|
|
121
|
+
input.scope.addReference(groupsToken, group, _reference_1.ReferenceType.DataWriteReference, input.filename);
|
|
122
|
+
input.scope.setGroupMemberType(group, rowType);
|
|
123
|
+
return (tableSource === null || tableSource === void 0 ? void 0 : tableSource.get()) instanceof Expressions.Source ? tableSource : undefined;
|
|
124
|
+
}
|
|
91
125
|
}
|
|
92
126
|
exports.For = For;
|
|
93
127
|
//# sourceMappingURL=for.js.map
|
|
@@ -66,8 +66,8 @@ class InlineFieldDefinition {
|
|
|
66
66
|
type = new unknown_type_1.UnknownType("InlineFieldDefinition, fallback");
|
|
67
67
|
}
|
|
68
68
|
const name = field.getStr();
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
const message = input.scope.checkLocalName(name, type);
|
|
70
|
+
if (message !== undefined) {
|
|
71
71
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
72
72
|
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
73
73
|
}
|
|
@@ -40,6 +40,7 @@ const basic_1 = require("../../types/basic");
|
|
|
40
40
|
const _typed_identifier_1 = require("../../types/_typed_identifier");
|
|
41
41
|
const _reference_1 = require("../_reference");
|
|
42
42
|
const _syntax_input_1 = require("../_syntax_input");
|
|
43
|
+
const loop_group_by_1 = require("./loop_group_by");
|
|
43
44
|
class InlineLoopDefinition {
|
|
44
45
|
static runSyntax(node, input) {
|
|
45
46
|
if (node === undefined) {
|
|
@@ -52,8 +53,12 @@ class InlineLoopDefinition {
|
|
|
52
53
|
const source = node.findDirectExpression(Expressions.Source);
|
|
53
54
|
if (source && target) {
|
|
54
55
|
const sourceType = source_1.Source.runSyntax(source, input);
|
|
55
|
-
|
|
56
|
-
|
|
56
|
+
const inGroup = node.concatTokens().toUpperCase().includes(" IN GROUP ");
|
|
57
|
+
let rowType = inGroup ? loop_group_by_1.LoopGroupBy.findMemberType(source, input) : undefined;
|
|
58
|
+
if (rowType !== undefined) {
|
|
59
|
+
// FOR ... IN GROUP, the members have the row type of the grouped table
|
|
60
|
+
}
|
|
61
|
+
else if (sourceType instanceof basic_1.TableType) {
|
|
57
62
|
rowType = sourceType.getRowType();
|
|
58
63
|
}
|
|
59
64
|
else if (sourceType instanceof basic_1.VoidType) {
|
|
@@ -65,7 +70,7 @@ class InlineLoopDefinition {
|
|
|
65
70
|
return;
|
|
66
71
|
}
|
|
67
72
|
if (rowType === undefined
|
|
68
|
-
&&
|
|
73
|
+
&& inGroup
|
|
69
74
|
&& sourceType !== undefined) {
|
|
70
75
|
rowType = sourceType;
|
|
71
76
|
}
|
|
@@ -74,6 +79,11 @@ class InlineLoopDefinition {
|
|
|
74
79
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
75
80
|
return;
|
|
76
81
|
}
|
|
82
|
+
const message = input.scope.checkLocalName(target.getFirstToken().getStr(), rowType);
|
|
83
|
+
if (message !== undefined) {
|
|
84
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, target.getFirstToken(), message));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
77
87
|
const identifier = new _typed_identifier_1.TypedIdentifier(target.getFirstToken(), input.filename, rowType, ["inline" /* IdentifierMeta.InlineDefinition */]);
|
|
78
88
|
input.scope.addReference(target.getFirstToken(), identifier, _reference_1.ReferenceType.DataWriteReference, input.filename);
|
|
79
89
|
input.scope.addReference(target.getFirstToken(), identifier, _reference_1.ReferenceType.DataReadReference, input.filename);
|
|
@@ -81,6 +91,11 @@ class InlineLoopDefinition {
|
|
|
81
91
|
}
|
|
82
92
|
const index = node.findExpressionAfterToken("INTO");
|
|
83
93
|
if (index && index.get() instanceof Expressions.TargetField) {
|
|
94
|
+
const message = input.scope.checkLocalName(index.getFirstToken().getStr(), basic_1.IntegerType.get());
|
|
95
|
+
if (message !== undefined) {
|
|
96
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, index.getFirstToken(), message));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
84
99
|
const identifier = new _typed_identifier_1.TypedIdentifier(index.getFirstToken(), input.filename, basic_1.IntegerType.get(), ["inline" /* IdentifierMeta.InlineDefinition */]);
|
|
85
100
|
input.scope.addReference(index.getFirstToken(), identifier, _reference_1.ReferenceType.DataWriteReference, input.filename);
|
|
86
101
|
input.scope.addIdentifier(identifier);
|
|
@@ -35,34 +35,144 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.LoopGroupBy = void 0;
|
|
37
37
|
const Expressions = __importStar(require("../../2_statements/expressions"));
|
|
38
|
+
const nodes_1 = require("../../nodes");
|
|
38
39
|
const basic_1 = require("../../types/basic");
|
|
39
|
-
const
|
|
40
|
+
const _reference_1 = require("../_reference");
|
|
40
41
|
const inline_data_1 = require("./inline_data");
|
|
41
42
|
const fstarget_1 = require("./fstarget");
|
|
42
43
|
const target_1 = require("./target");
|
|
43
44
|
const source_1 = require("./source");
|
|
45
|
+
const field_chain_1 = require("./field_chain");
|
|
44
46
|
class LoopGroupBy {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @param rowType row type of the grouped table, the type of the members of each group
|
|
49
|
+
* @param representative the row target of the LOOP, it is the group when GROUP BY has no target
|
|
50
|
+
*/
|
|
51
|
+
static runSyntax(node, input, rowType, representative) {
|
|
52
|
+
var _a;
|
|
53
|
+
const keyType = this.runKey(node, input);
|
|
54
|
+
const groupTarget = node.findDirectExpression(Expressions.LoopGroupByTarget);
|
|
55
|
+
const target = groupTarget === null || groupTarget === void 0 ? void 0 : groupTarget.findDirectExpression(Expressions.Target);
|
|
56
|
+
const fsTarget = groupTarget === null || groupTarget === void 0 ? void 0 : groupTarget.findDirectExpression(Expressions.FSTarget);
|
|
57
|
+
if (target) {
|
|
58
|
+
const inline = target.findDirectExpression(Expressions.InlineData);
|
|
48
59
|
if (inline) {
|
|
49
|
-
|
|
60
|
+
const isReference = (groupTarget === null || groupTarget === void 0 ? void 0 : groupTarget.findDirectTokenByText("REFERENCE")) !== undefined;
|
|
61
|
+
inline_data_1.InlineData.runSyntax(inline, input, isReference ? new basic_1.DataReference(keyType) : keyType);
|
|
50
62
|
}
|
|
51
63
|
else {
|
|
52
|
-
target_1.Target.runSyntax(
|
|
64
|
+
target_1.Target.runSyntax(target, input);
|
|
53
65
|
}
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
fstarget_1.FSTarget.runSyntax(
|
|
67
|
+
else if (fsTarget) {
|
|
68
|
+
fstarget_1.FSTarget.runSyntax(fsTarget, input, keyType);
|
|
57
69
|
}
|
|
58
|
-
|
|
59
|
-
|
|
70
|
+
// bind the group until ENDLOOP, see unbind(), also when the row type is unknown
|
|
71
|
+
const group = this.findTargetIdentifier((_a = target !== null && target !== void 0 ? target : fsTarget) !== null && _a !== void 0 ? _a : representative, input.scope);
|
|
72
|
+
if (group) {
|
|
73
|
+
input.scope.setGroupMemberType(group, rowType !== null && rowType !== void 0 ? rowType : basic_1.VoidType.get("GroupMember"));
|
|
60
74
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
}
|
|
76
|
+
/** the row target of a LOOP, it is the group when GROUP BY has no target */
|
|
77
|
+
static findRepresentative(loop) {
|
|
78
|
+
var _a;
|
|
79
|
+
const loopTarget = loop.findDirectExpression(Expressions.LoopTarget);
|
|
80
|
+
return (_a = loopTarget === null || loopTarget === void 0 ? void 0 : loopTarget.findDirectExpression(Expressions.Target)) !== null && _a !== void 0 ? _a : loopTarget === null || loopTarget === void 0 ? void 0 : loopTarget.findDirectExpression(Expressions.FSTarget);
|
|
81
|
+
}
|
|
82
|
+
/** called at the end of a LOOP structure, the group of a LOOP AT ... GROUP BY is not bound after its ENDLOOP */
|
|
83
|
+
static unbind(loop, scope) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const groupBy = loop.findDirectExpression(Expressions.LoopGroupBy);
|
|
86
|
+
if (groupBy === undefined) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const groupTarget = groupBy.findDirectExpression(Expressions.LoopGroupByTarget);
|
|
90
|
+
const node = (_b = (_a = groupTarget === null || groupTarget === void 0 ? void 0 : groupTarget.findDirectExpression(Expressions.Target)) !== null && _a !== void 0 ? _a : groupTarget === null || groupTarget === void 0 ? void 0 : groupTarget.findDirectExpression(Expressions.FSTarget)) !== null && _b !== void 0 ? _b : this.findRepresentative(loop);
|
|
91
|
+
const group = this.findTargetIdentifier(node, scope);
|
|
92
|
+
if (group) {
|
|
93
|
+
scope.removeGroupMemberType(group);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** LOOP AT GROUP group, the name of the group when it is a variable that no enclosing group loop binds */
|
|
97
|
+
static findUnboundGroup(source, input) {
|
|
98
|
+
if (source === undefined) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
const name = this.groupName(source);
|
|
102
|
+
const found = input.scope.findVariable(name);
|
|
103
|
+
if (found === undefined || input.scope.findGroupMemberType(found) !== undefined) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
return name;
|
|
107
|
+
}
|
|
108
|
+
/** type of the group key, from GROUP BY expr or GROUP BY ( name = expr ... ) */
|
|
109
|
+
static runKey(node, input) {
|
|
110
|
+
const components = node.findDirectExpressions(Expressions.LoopGroupByComponent);
|
|
111
|
+
if (components.length === 0) {
|
|
112
|
+
// LOOP: the key is the first child of LoopGroupBy, FOR GROUPS: the key follows GROUP BY
|
|
113
|
+
const key = node.get() instanceof Expressions.LoopGroupBy ? node.getFirstChild() : node.findExpressionAfterToken("BY");
|
|
114
|
+
let type = undefined;
|
|
115
|
+
if (key instanceof nodes_1.ExpressionNode && key.get() instanceof Expressions.Source) {
|
|
116
|
+
type = source_1.Source.runSyntax(key, input);
|
|
117
|
+
}
|
|
118
|
+
else if (key instanceof nodes_1.ExpressionNode && key.get() instanceof Expressions.FieldChain) {
|
|
119
|
+
type = field_chain_1.FieldChain.runSyntax(key, input, _reference_1.ReferenceType.DataReadReference);
|
|
120
|
+
}
|
|
121
|
+
return type !== null && type !== void 0 ? type : basic_1.VoidType.get("GroupKey");
|
|
122
|
+
}
|
|
123
|
+
const fields = [];
|
|
124
|
+
let dynamic = false;
|
|
125
|
+
for (const c of components) {
|
|
126
|
+
const single = c.findDirectExpression(Expressions.ComponentCompareSingle);
|
|
127
|
+
if (single) {
|
|
128
|
+
const source = single.findDirectExpression(Expressions.Source);
|
|
129
|
+
const type = source ? source_1.Source.runSyntax(source, input) : undefined;
|
|
130
|
+
const name = single.findDirectExpression(Expressions.ComponentChainSimple);
|
|
131
|
+
if (name === undefined) {
|
|
132
|
+
dynamic = true;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
fields.push({ name: name.concatTokens(), type: type !== null && type !== void 0 ? type : basic_1.VoidType.get("GroupKey") });
|
|
64
136
|
}
|
|
137
|
+
else {
|
|
138
|
+
// GROUP SIZE and GROUP INDEX
|
|
139
|
+
const name = c.findDirectExpression(Expressions.ComponentName);
|
|
140
|
+
if (name) {
|
|
141
|
+
fields.push({ name: name.concatTokens(), type: basic_1.IntegerType.get() });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (dynamic === true || fields.length === 0) {
|
|
146
|
+
return basic_1.VoidType.get("GroupKey");
|
|
147
|
+
}
|
|
148
|
+
return new basic_1.StructureType(fields);
|
|
149
|
+
}
|
|
150
|
+
/** the group variable in LOOP AT GROUP group and FOR ... IN GROUP group */
|
|
151
|
+
static findMemberType(source, input) {
|
|
152
|
+
if (source === undefined) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
const found = input.scope.findVariable(this.groupName(source));
|
|
156
|
+
return found ? input.scope.findGroupMemberType(found) : undefined;
|
|
157
|
+
}
|
|
158
|
+
static groupName(source) {
|
|
159
|
+
return source.concatTokens().replace(/\s/g, "").replace(/->\*$/, "");
|
|
160
|
+
}
|
|
161
|
+
static findTargetIdentifier(node, scope) {
|
|
162
|
+
var _a;
|
|
163
|
+
var _b, _c;
|
|
164
|
+
if (node === undefined) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const inline = (_b = node.findDirectExpression(Expressions.InlineData)) !== null && _b !== void 0 ? _b : node.findDirectExpression(Expressions.InlineFS);
|
|
168
|
+
let name;
|
|
169
|
+
if (inline) {
|
|
170
|
+
name = (_a = ((_c = inline.findFirstExpression(Expressions.TargetField)) !== null && _c !== void 0 ? _c : inline.findFirstExpression(Expressions.TargetFieldSymbol))) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr();
|
|
171
|
+
}
|
|
172
|
+
else if (node.getChildren().length === 1) {
|
|
173
|
+
name = node.getFirstToken().getStr();
|
|
65
174
|
}
|
|
175
|
+
return scope.findVariable(name);
|
|
66
176
|
}
|
|
67
177
|
}
|
|
68
178
|
exports.LoopGroupBy = LoopGroupBy;
|
|
@@ -50,6 +50,8 @@ const _reference_1 = require("../_reference");
|
|
|
50
50
|
const _syntax_input_1 = require("../_syntax_input");
|
|
51
51
|
const version_1 = require("../../../version");
|
|
52
52
|
const _check_database_fields_1 = require("./_check_database_fields");
|
|
53
|
+
const field_chain_1 = require("./field_chain");
|
|
54
|
+
const tokens_1 = require("../../1_lexer/tokens");
|
|
53
55
|
const isSimple = /^\w+$/;
|
|
54
56
|
// SQL functions where the result has the same type as the first argument
|
|
55
57
|
const sameTypeAsFirstArgument = new Set(["UPPER", "LOWER", "LTRIM", "RTRIM"]);
|
|
@@ -258,7 +260,7 @@ class Select {
|
|
|
258
260
|
if (intoStructure) {
|
|
259
261
|
const inlineList = intoStructure.findAllExpressions(Expressions.InlineData);
|
|
260
262
|
if (inlineList.length === 1) {
|
|
261
|
-
inline_data_1.InlineData.runSyntax(inlineList[0], input, this.buildStructureType(fields, dbSources, input
|
|
263
|
+
inline_data_1.InlineData.runSyntax(inlineList[0], input, this.buildStructureType(fields, dbSources, input, from));
|
|
262
264
|
}
|
|
263
265
|
else {
|
|
264
266
|
for (const inline of inlineList) {
|
|
@@ -325,13 +327,19 @@ class Select {
|
|
|
325
327
|
return basic_1.IntegerType.get();
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
|
-
static buildStructureType(fields, dbSources,
|
|
330
|
+
static buildStructureType(fields, dbSources, input, from) {
|
|
329
331
|
var _a, _b, _c, _d, _e, _f;
|
|
332
|
+
const scope = input.scope;
|
|
330
333
|
if (fields.length === 1 && dbSources.length === 1) {
|
|
331
334
|
// COUNT( * ) yields an integer regardless of the (possibly dynamic) table
|
|
332
335
|
if (/^count\(\s*\*\s*\)$/i.test(fields[0].code)) {
|
|
333
336
|
return this.countResultType(scope);
|
|
334
337
|
}
|
|
338
|
+
// a host variable yields its own type regardless of the table
|
|
339
|
+
const hostType = this.findHostFieldType(fields[0], input);
|
|
340
|
+
if (hostType) {
|
|
341
|
+
return hostType;
|
|
342
|
+
}
|
|
335
343
|
const dbType = (_a = dbSources[0]) === null || _a === void 0 ? void 0 : _a.parseType(scope.getRegistry());
|
|
336
344
|
if (dbType === undefined) {
|
|
337
345
|
const name = ((_b = dbSources[0]) === null || _b === void 0 ? void 0 : _b.getName()) || "buildStructureTypeError";
|
|
@@ -483,6 +491,30 @@ class Select {
|
|
|
483
491
|
}
|
|
484
492
|
return components;
|
|
485
493
|
}
|
|
494
|
+
/** returns the type of the field list entry if it is a single ABAP host variable, "@var" or "@( var )" */
|
|
495
|
+
static findHostFieldType(field, input) {
|
|
496
|
+
var _a;
|
|
497
|
+
if (!(field.expression.get() instanceof Expressions.SQLField)) {
|
|
498
|
+
return undefined;
|
|
499
|
+
}
|
|
500
|
+
const children = field.expression.getChildren().filter(c => !(c.get() instanceof Expressions.SQLAsName) && c.concatTokens().toUpperCase() !== "AS");
|
|
501
|
+
if (!(((_a = children[0]) === null || _a === void 0 ? void 0 : _a.get()) instanceof tokens_1.WAt)) {
|
|
502
|
+
return undefined;
|
|
503
|
+
}
|
|
504
|
+
// "@var" has two children, "@( var )" has four, anything else is an expression
|
|
505
|
+
const chain = children.length === 2 ? children[1] : children.length === 4 ? children[2] : undefined;
|
|
506
|
+
if (!(chain instanceof nodes_1.ExpressionNode) || !(chain.get() instanceof Expressions.SimpleFieldChain2)) {
|
|
507
|
+
return undefined;
|
|
508
|
+
}
|
|
509
|
+
// only resolve the type here, errors for the host variable are not reported by this lookup
|
|
510
|
+
const issues = [];
|
|
511
|
+
const type = field_chain_1.FieldChain.runSyntax(chain, Object.assign(Object.assign({}, input), { issues }));
|
|
512
|
+
// a generic host type cannot type the inline declaration, keep it voided
|
|
513
|
+
if (issues.length > 0 || type === undefined || type.isGeneric()) {
|
|
514
|
+
return undefined;
|
|
515
|
+
}
|
|
516
|
+
return type;
|
|
517
|
+
}
|
|
486
518
|
/** returns the SQLFunction node if the field list entry is a single SQL function call */
|
|
487
519
|
static findFunctionColumn(field, requireAlias = true) {
|
|
488
520
|
if (requireAlias === true && field.as === "") {
|
|
@@ -110,6 +110,17 @@ class Loop {
|
|
|
110
110
|
}
|
|
111
111
|
if (sourceType instanceof basic_1.TableType) {
|
|
112
112
|
rowType = sourceType.getRowType();
|
|
113
|
+
}
|
|
114
|
+
else if (concat.startsWith("LOOP AT GROUP ")) {
|
|
115
|
+
const unbound = loop_group_by_1.LoopGroupBy.findUnboundGroup(firstSource, input);
|
|
116
|
+
if (unbound !== undefined) {
|
|
117
|
+
const message = `No group is bound to "${unbound}"`;
|
|
118
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
rowType = loop_group_by_1.LoopGroupBy.findMemberType(firstSource, input);
|
|
122
|
+
}
|
|
123
|
+
if (rowType) {
|
|
113
124
|
sourceType = rowType;
|
|
114
125
|
if (targetConcat === null || targetConcat === void 0 ? void 0 : targetConcat.startsWith("REFERENCE INTO ")) {
|
|
115
126
|
sourceType = new basic_1.DataReference(sourceType);
|
|
@@ -195,7 +206,7 @@ class Loop {
|
|
|
195
206
|
}
|
|
196
207
|
const group = node.findDirectExpression(Expressions.LoopGroupBy);
|
|
197
208
|
if (group) {
|
|
198
|
-
loop_group_by_1.LoopGroupBy.runSyntax(group, input);
|
|
209
|
+
loop_group_by_1.LoopGroupBy.runSyntax(group, input, rowType, loop_group_by_1.LoopGroupBy.findRepresentative(node));
|
|
199
210
|
}
|
|
200
211
|
}
|
|
201
212
|
}
|