@abaplint/core 2.120.110 → 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.
Files changed (26) hide show
  1. package/build/abaplint.d.ts +12 -0
  2. package/build/src/abap/2_statements/statements/authority_check.js +1 -1
  3. package/build/src/abap/2_statements/statements/commit.js +1 -1
  4. package/build/src/abap/2_statements/statements/convert.js +2 -2
  5. package/build/src/abap/2_statements/statements/do.js +2 -1
  6. package/build/src/abap/2_statements/statements/exit.js +2 -1
  7. package/build/src/abap/2_statements/statements/get_time.js +3 -2
  8. package/build/src/abap/2_statements/statements/perform.js +1 -1
  9. package/build/src/abap/2_statements/statements/rollback.js +1 -1
  10. package/build/src/abap/2_statements/statements/wait.js +1 -1
  11. package/build/src/abap/5_syntax/_current_scope.js +15 -0
  12. package/build/src/abap/5_syntax/expressions/for.js +32 -4
  13. package/build/src/abap/5_syntax/expressions/inline_loop_definition.js +8 -3
  14. package/build/src/abap/5_syntax/expressions/loop_group_by.js +123 -13
  15. package/build/src/abap/5_syntax/expressions/select.js +34 -2
  16. package/build/src/abap/5_syntax/statements/loop.js +12 -1
  17. package/build/src/abap/5_syntax/statements/move.js +8 -0
  18. package/build/src/abap/5_syntax/syntax.js +7 -0
  19. package/build/src/abap/types/event_definition.js +12 -0
  20. package/build/src/abap/types/function_module_definition.js +16 -0
  21. package/build/src/registry.js +1 -1
  22. package/build/src/rules/downport.js +5 -0
  23. package/build/src/rules/function_module_parameter_names.js +139 -0
  24. package/build/src/rules/index.js +2 -0
  25. package/build/src/rules/unhandled_classic_exception.js +278 -0
  26. package/package.json +1 -1
@@ -1593,6 +1593,9 @@ export declare class CurrentScope {
1593
1593
  private readonly localFriends;
1594
1594
  /** types of the FOR and LET names used in a procedure, key is the scope node of the procedure */
1595
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;
1596
1599
  static buildDefault(reg: IRegistry, obj: IObject): CurrentScope;
1597
1600
  private static addBuiltIn;
1598
1601
  private constructor();
@@ -1663,6 +1666,10 @@ export declare class CurrentScope {
1663
1666
  checkLocalName(name: string, type: AbstractType | undefined): string | undefined;
1664
1667
  /** types are compared by their structure, ABAP compares the declared types, so this finds a subset of the errors */
1665
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;
1666
1673
  getEnclosingMethodName(): string | undefined;
1667
1674
  getEnclosingClassName(): string | undefined;
1668
1675
  isGlobalOO(): boolean;
@@ -3098,12 +3105,17 @@ declare class FunctionModuleDefinition {
3098
3105
  private parameters;
3099
3106
  private globalParameters;
3100
3107
  private moduleType;
3108
+ private exceptions;
3109
+ private classBasedExceptions;
3101
3110
  constructor(data: any);
3102
3111
  getParameters(): readonly IFunctionModuleParameter[];
3103
3112
  getModuleType(): FunctionModuleType | undefined;
3104
3113
  getDescription(): string | undefined;
3105
3114
  getName(): string;
3106
3115
  isGlobalParameters(): boolean;
3116
+ /** the classic exceptions, or the exception classes if isClassBasedExceptions() */
3117
+ getExceptions(): readonly string[];
3118
+ isClassBasedExceptions(): boolean;
3107
3119
  private parse;
3108
3120
  }
3109
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 options = (0, combi_1.seq)((0, combi_1.alt)("STAMP FIELD", "FIELD"), expressions_1.Target);
10
- return (0, combi_1.verNotLang)(version_1.LanguageVersion.KeyUser, (0, combi_1.seq)("GET TIME", (0, combi_1.opt)(options)));
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.KeyUser, ret);
17
+ return (0, combi_1.verNotLang)(version_1.LanguageVersion.Cloud, ret);
18
18
  }
19
19
  }
20
20
  exports.Wait = Wait;
@@ -35,6 +35,9 @@ class CurrentScope {
35
35
  this.localFriends = new Map();
36
36
  /** types of the FOR and LET names used in a procedure, key is the scope node of the procedure */
37
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();
38
41
  this.current = undefined;
39
42
  this.parentObj = obj;
40
43
  this.reg = reg;
@@ -567,6 +570,18 @@ class CurrentScope {
567
570
  && type.isGeneric() === false
568
571
  && type.toText(0).includes("Unknown type") === false;
569
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
+ }
570
585
  getEnclosingMethodName() {
571
586
  let curr = this.current;
572
587
  while (curr !== undefined) {
@@ -42,6 +42,7 @@ 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");
@@ -69,18 +70,19 @@ class For {
69
70
  for (const f of inlineField) {
70
71
  inline_field_definition_1.InlineFieldDefinition.runSyntax(f, input);
71
72
  }
73
+ let groupsSource = undefined;
72
74
  if (groupsToken !== undefined) {
73
75
  const message = input.scope.checkLocalName(groupsToken.getStr(), undefined);
74
76
  if (message !== undefined) {
75
77
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, groupsToken, message));
76
78
  return scoped;
77
79
  }
78
- const type = basic_1.VoidType.get("todoGroupBy");
79
- const identifier = new _typed_identifier_1.TypedIdentifier(groupsToken, input.filename, type, ["inline" /* IdentifierMeta.InlineDefinition */]);
80
- input.scope.addIdentifier(identifier);
81
- input.scope.addReference(groupsToken, identifier, _reference_1.ReferenceType.DataWriteReference, input.filename);
80
+ groupsSource = this.runGroups(node, groupsToken, input);
82
81
  }
83
82
  for (const s of node.findDirectExpressions(Expressions.Source)) {
83
+ if (s === groupsSource) {
84
+ continue;
85
+ }
84
86
  source_1.Source.runSyntax(s, input);
85
87
  }
86
88
  for (const s of node.findDirectExpressions(Expressions.ComponentCond)) {
@@ -94,6 +96,32 @@ class For {
94
96
  }
95
97
  return scoped;
96
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
+ }
97
125
  }
98
126
  exports.For = For;
99
127
  //# sourceMappingURL=for.js.map
@@ -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
- let rowType = undefined;
56
- if (sourceType instanceof basic_1.TableType) {
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
- && node.concatTokens().toUpperCase().includes(" IN GROUP ")
73
+ && inGroup
69
74
  && sourceType !== undefined) {
70
75
  rowType = sourceType;
71
76
  }
@@ -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 component_compare_1 = require("./component_compare");
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
- static runSyntax(node, input) {
46
- for (const t of node.findAllExpressions(Expressions.Target)) {
47
- const inline = t.findDirectExpression(Expressions.InlineData);
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
- inline_data_1.InlineData.runSyntax(inline, input, basic_1.VoidType.get("todoGroupBy"));
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(t, input);
64
+ target_1.Target.runSyntax(target, input);
53
65
  }
54
66
  }
55
- for (const t of node.findAllExpressions(Expressions.FSTarget)) {
56
- fstarget_1.FSTarget.runSyntax(t, input, basic_1.VoidType.get("todoGroupBy"));
67
+ else if (fsTarget) {
68
+ fstarget_1.FSTarget.runSyntax(fsTarget, input, keyType);
57
69
  }
58
- for (const t of node.findDirectExpressions(Expressions.Source)) {
59
- source_1.Source.runSyntax(t, input, basic_1.VoidType.get("todoGroupBy"));
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
- for (const c of node.findDirectExpressions(Expressions.LoopGroupByComponent)) {
62
- for (const t of c.findDirectExpressions(Expressions.ComponentCompareSingle)) {
63
- component_compare_1.ComponentCompare.runSyntax(t, input);
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.scope, from));
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, scope, from) {
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
  }
@@ -45,6 +45,7 @@ const basic_1 = require("../../types/basic");
45
45
  const nodes_1 = require("../../nodes");
46
46
  class Move {
47
47
  runSyntax(node, input) {
48
+ var _a;
48
49
  const targets = node.findDirectExpressions(Expressions.Target);
49
50
  const firstTarget = targets[0];
50
51
  const inline = firstTarget === null || firstTarget === void 0 ? void 0 : firstTarget.findDirectExpression(Expressions.InlineData);
@@ -85,6 +86,13 @@ class Move {
85
86
  sourceType = dereference_1.Dereference.runSyntax(node, sourceType, input);
86
87
  }
87
88
  if (inline) {
89
+ // the length of a text symbol depends on the text pool, "DATA(x) = TEXT-abc." does not compile
90
+ const sourceChildren = (_a = source === null || source === void 0 ? void 0 : source.getChildren()) !== null && _a !== void 0 ? _a : [];
91
+ if (sourceChildren.length === 1 && sourceChildren[0].get() instanceof Expressions.TextElement) {
92
+ const message = `"${source.concatTokens().toUpperCase()}" has a generic type that cannot be used for declarations`;
93
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, source.getFirstToken(), message));
94
+ return;
95
+ }
88
96
  if (sourceType instanceof basic_1.PackedType && (source === null || source === void 0 ? void 0 : source.findDirectExpression(Expressions.ArithOperator))) {
89
97
  sourceType = new basic_1.PackedType(8, 0);
90
98
  }
@@ -52,6 +52,7 @@ const statics_1 = require("./structures/statics");
52
52
  const constants_1 = require("./structures/constants");
53
53
  const cleanup_1 = require("./structures/cleanup");
54
54
  const try_1 = require("./structures/try");
55
+ const loop_group_by_1 = require("./expressions/loop_group_by");
55
56
  const class_definition_1 = require("../types/class_definition");
56
57
  const interface_definition_1 = require("../types/interface_definition");
57
58
  const delete_memory_1 = require("./statements/delete_memory");
@@ -477,6 +478,12 @@ class SyntaxLogic {
477
478
  if (loop === true) {
478
479
  this.loopTables.pop();
479
480
  }
481
+ if (node instanceof nodes_1.StructureNode && node.get() instanceof Structures.Loop) {
482
+ const loopStatement = node.findDirectStatement(Statements.Loop);
483
+ if (loopStatement) {
484
+ loop_group_by_1.LoopGroupBy.unbind(loopStatement, this.scope);
485
+ }
486
+ }
480
487
  if (node instanceof nodes_1.StructureNode) {
481
488
  this.sortedLines.leave(node);
482
489
  }
@@ -39,6 +39,7 @@ const Expressions = __importStar(require("../2_statements/expressions"));
39
39
  const events_1 = require("../2_statements/statements/events");
40
40
  const expressions_1 = require("../2_statements/expressions");
41
41
  const method_param_1 = require("../5_syntax/expressions/method_param");
42
+ const _syntax_input_1 = require("../5_syntax/_syntax_input");
42
43
  class EventDefinition extends _identifier_1.Identifier {
43
44
  constructor(node, _visibility, input) {
44
45
  if (!(node.get() instanceof events_1.Events)) {
@@ -61,10 +62,21 @@ class EventDefinition extends _identifier_1.Identifier {
61
62
  }
62
63
  ///////////////
63
64
  parse(node, input) {
65
+ var _a;
66
+ var _b;
64
67
  for (const e of node.findAllExpressions(expressions_1.MethodParam)) {
68
+ if (this.isPassByValue(e) === false) {
69
+ const name = (_b = (_a = e.findDirectExpression(Expressions.MethodParamName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) !== null && _b !== void 0 ? _b : "";
70
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, e.getFirstToken(), "Event parameter " + name + " must be passed by VALUE"));
71
+ }
65
72
  this.parameters.push(method_param_1.MethodParam.runSyntax(e, input, []));
66
73
  }
67
74
  }
75
+ // event parameters can only be passed by value
76
+ isPassByValue(param) {
77
+ const first = param.getFirstToken().getStr().toUpperCase();
78
+ return first === "VALUE" || first === "!VALUE";
79
+ }
68
80
  }
69
81
  exports.EventDefinition = EventDefinition;
70
82
  //# sourceMappingURL=event_definition.js.map
@@ -34,6 +34,13 @@ class FunctionModuleDefinition {
34
34
  isGlobalParameters() {
35
35
  return this.globalParameters;
36
36
  }
37
+ /** the classic exceptions, or the exception classes if isClassBasedExceptions() */
38
+ getExceptions() {
39
+ return this.exceptions;
40
+ }
41
+ isClassBasedExceptions() {
42
+ return this.classBasedExceptions;
43
+ }
37
44
  ///////////////
38
45
  parse(data) {
39
46
  if (data.FUNCNAME === undefined) {
@@ -43,6 +50,8 @@ class FunctionModuleDefinition {
43
50
  this.description = data.SHORT_TEXT;
44
51
  this.parameters = [];
45
52
  this.globalParameters = data.GLOBAL_FLAG === "X";
53
+ this.exceptions = [];
54
+ this.classBasedExceptions = data.EXCEPTION_CLASSES === "X";
46
55
  this.moduleType = FunctionModuleType.regular;
47
56
  if (data.REMOTE_CALL === "R") {
48
57
  this.moduleType = FunctionModuleType.remote;
@@ -111,6 +120,13 @@ class FunctionModuleDefinition {
111
120
  });
112
121
  }
113
122
  }
123
+ if (data.EXCEPTION) {
124
+ for (const exception of (0, xml_utils_1.xmlToArray)(data.EXCEPTION.RSEXC)) {
125
+ if (typeof exception.EXCEPTION === "string") {
126
+ this.exceptions.push(exception.EXCEPTION);
127
+ }
128
+ }
129
+ }
114
130
  }
115
131
  }
116
132
  exports.FunctionModuleDefinition = FunctionModuleDefinition;
@@ -78,7 +78,7 @@ class Registry {
78
78
  }
79
79
  static abaplintVersion() {
80
80
  // magic, see build script "version.js"
81
- return "2.120.110";
81
+ return "2.120.111";
82
82
  }
83
83
  getDDICReferences() {
84
84
  return this.ddicReferences;
@@ -3196,6 +3196,11 @@ ${indentation} output = ${uniqueName}.\n`;
3196
3196
  if (this.lowReg.getConfig().isOpenABAP()) {
3197
3197
  return undefined;
3198
3198
  }
3199
+ else if (node.get() instanceof Statements.Loop
3200
+ && node.concatTokens().toUpperCase().startsWith("LOOP AT GROUP ")) {
3201
+ // rewritten by the LOOP GROUP downport, the inline target is outlined afterwards
3202
+ return undefined;
3203
+ }
3199
3204
  for (const i of node.findAllExpressionsRecursive(Expressions.InlineData)) {
3200
3205
  const nameToken = (_a = i.findDirectExpression(Expressions.TargetField)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
3201
3206
  if (nameToken === undefined) {
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionModuleParameterNames = exports.FunctionModuleParameterNamesConf = void 0;
4
+ const issue_1 = require("../issue");
5
+ const _irule_1 = require("./_irule");
6
+ const function_group_1 = require("../objects/function_group");
7
+ const _naming_rule_config_1 = require("./_naming_rule_config");
8
+ const name_validator_1 = require("../utils/name_validator");
9
+ const function_module_definition_1 = require("../abap/types/function_module_definition");
10
+ const position_1 = require("../position");
11
+ class FunctionModuleParameterNamesConf extends _naming_rule_config_1.NamingRuleConfig {
12
+ constructor() {
13
+ super(...arguments);
14
+ /** The pattern for importing parameters */
15
+ this.importing = "^I._.+$";
16
+ /** The pattern for exporting parameters */
17
+ this.exporting = "^E._.+$";
18
+ /** The pattern for changing parameters */
19
+ this.changing = "^C._.+$";
20
+ /** The pattern for tables parameters */
21
+ this.tables = "^T._.+$";
22
+ }
23
+ }
24
+ exports.FunctionModuleParameterNamesConf = FunctionModuleParameterNamesConf;
25
+ class FunctionModuleParameterNames {
26
+ constructor() {
27
+ this.conf = new FunctionModuleParameterNamesConf();
28
+ this.regex = this.compile();
29
+ }
30
+ getMetadata() {
31
+ return {
32
+ key: "function_module_parameter_names",
33
+ title: "Function module parameter naming conventions",
34
+ shortDescription: `Allows you to enforce a pattern, such as a prefix, for function module parameter names`,
35
+ extendedInformation: `Checks the parameters of function modules in function groups,
36
+ with a separate pattern for importing, exporting, changing and tables parameters.`,
37
+ tags: [_irule_1.RuleTag.Naming, _irule_1.RuleTag.SingleFile],
38
+ badExample: `FUNCTION z_get_name.
39
+ *" IMPORTING
40
+ *" VALUE(CUSTOMER) TYPE STRING
41
+ *" EXPORTING
42
+ *" VALUE(NAME) TYPE STRING
43
+ ENDFUNCTION.`,
44
+ goodExample: `FUNCTION z_get_name.
45
+ *" IMPORTING
46
+ *" VALUE(IV_CUSTOMER) TYPE STRING
47
+ *" EXPORTING
48
+ *" VALUE(EV_NAME) TYPE STRING
49
+ ENDFUNCTION.`,
50
+ };
51
+ }
52
+ getDescription(expected, actual) {
53
+ return this.conf.patternKind === "required" ?
54
+ "Function module parameter name does not match pattern " + expected + ": " + actual :
55
+ "Function module parameter name must not match pattern " + expected + ": " + actual;
56
+ }
57
+ getConfig() {
58
+ return this.conf;
59
+ }
60
+ setConfig(conf) {
61
+ this.conf = conf;
62
+ this.regex = this.compile();
63
+ }
64
+ compile() {
65
+ return {
66
+ importing: new RegExp(this.conf.importing, "i"),
67
+ exporting: new RegExp(this.conf.exporting, "i"),
68
+ changing: new RegExp(this.conf.changing, "i"),
69
+ tables: new RegExp(this.conf.tables, "i"),
70
+ ignorePatterns: name_validator_1.NameValidator.compileIgnorePatterns(this.conf),
71
+ };
72
+ }
73
+ initialize(_reg) {
74
+ return this;
75
+ }
76
+ run(obj) {
77
+ if (this.conf.patternKind === undefined) {
78
+ this.conf.patternKind = "required";
79
+ }
80
+ if (!(obj instanceof function_group_1.FunctionGroup)) {
81
+ return [];
82
+ }
83
+ let ret = [];
84
+ for (const module of obj.getModules()) {
85
+ ret = ret.concat(this.checkModule(obj, module));
86
+ }
87
+ return ret;
88
+ }
89
+ checkModule(obj, module) {
90
+ const ret = [];
91
+ for (const p of module.getParameters()) {
92
+ let expected;
93
+ let regex;
94
+ switch (p.direction) {
95
+ case function_module_definition_1.FunctionModuleParameterDirection.importing:
96
+ expected = this.conf.importing;
97
+ regex = this.regex.importing;
98
+ break;
99
+ case function_module_definition_1.FunctionModuleParameterDirection.exporting:
100
+ expected = this.conf.exporting;
101
+ regex = this.regex.exporting;
102
+ break;
103
+ case function_module_definition_1.FunctionModuleParameterDirection.changing:
104
+ expected = this.conf.changing;
105
+ regex = this.regex.changing;
106
+ break;
107
+ case function_module_definition_1.FunctionModuleParameterDirection.tables:
108
+ expected = this.conf.tables;
109
+ regex = this.regex.tables;
110
+ break;
111
+ default:
112
+ continue;
113
+ }
114
+ const issue = this.checkParameter(obj, module, p, expected, regex);
115
+ if (issue) {
116
+ ret.push(issue);
117
+ }
118
+ }
119
+ return ret;
120
+ }
121
+ checkParameter(obj, module, param, expected, regex) {
122
+ if (!name_validator_1.NameValidator.violatesRule(param.name, regex, this.conf, this.regex.ignorePatterns)) {
123
+ return undefined;
124
+ }
125
+ // the parameter is only defined in the XML, so report at the start of the module file, if it exists
126
+ const file = this.findModuleFile(obj, module) || obj.getMainABAPFile();
127
+ if (file === undefined) {
128
+ return undefined;
129
+ }
130
+ const message = this.getDescription(expected, param.name);
131
+ return issue_1.Issue.atPosition(file, new position_1.Position(1, 1), message, this.getMetadata().key, this.conf.severity);
132
+ }
133
+ findModuleFile(obj, module) {
134
+ const search = "." + module.getName().toLowerCase().replace(/\//g, "#") + ".abap";
135
+ return obj.getABAPFiles().find(f => f.getFilename().toLowerCase().endsWith(search));
136
+ }
137
+ }
138
+ exports.FunctionModuleParameterNames = FunctionModuleParameterNames;
139
+ //# sourceMappingURL=function_module_parameter_names.js.map
@@ -102,6 +102,7 @@ __exportStar(require("./forbidden_void_type"), exports);
102
102
  __exportStar(require("./form_tables_obsolete"), exports);
103
103
  __exportStar(require("./fully_type_constants"), exports);
104
104
  __exportStar(require("./fully_type_itabs"), exports);
105
+ __exportStar(require("./function_module_parameter_names"), exports);
105
106
  __exportStar(require("./function_module_recommendations"), exports);
106
107
  __exportStar(require("./functional_writing"), exports);
107
108
  __exportStar(require("./generic_regex"), exports);
@@ -230,6 +231,7 @@ __exportStar(require("./try_without_catch"), exports);
230
231
  __exportStar(require("./type_form_parameters"), exports);
231
232
  __exportStar(require("./types_naming"), exports);
232
233
  __exportStar(require("./uncaught_exception"), exports);
234
+ __exportStar(require("./unhandled_classic_exception"), exports);
233
235
  __exportStar(require("./unit_test_assertions"), exports);
234
236
  __exportStar(require("./unknown_types"), exports);
235
237
  __exportStar(require("./unnecessary_chaining"), exports);
@@ -0,0 +1,278 @@
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.UnhandledClassicException = exports.UnhandledClassicExceptionConf = void 0;
37
+ const Statements = __importStar(require("../abap/2_statements/statements"));
38
+ const Expressions = __importStar(require("../abap/2_statements/expressions"));
39
+ const issue_1 = require("../issue");
40
+ const _abap_rule_1 = require("./_abap_rule");
41
+ const _basic_rule_config_1 = require("./_basic_rule_config");
42
+ const severity_1 = require("../severity");
43
+ const _irule_1 = require("./_irule");
44
+ const syntax_1 = require("../abap/5_syntax/syntax");
45
+ const _reference_1 = require("../abap/5_syntax/_reference");
46
+ const types_1 = require("../abap/types");
47
+ const virtual_position_1 = require("../virtual_position");
48
+ class UnhandledClassicExceptionConf extends _basic_rule_config_1.BasicRuleConfig {
49
+ constructor() {
50
+ super(...arguments);
51
+ this.severity = severity_1.Severity.Warning;
52
+ /** Report an EXCEPTIONS list without OTHERS, unless the method or function module is known and all its exceptions are listed */
53
+ this.missingOthers = true;
54
+ /** Report a call without EXCEPTIONS, including a functional call, of a method or function module that declares classic exceptions */
55
+ this.missingExceptions = true;
56
+ /** missingExceptions: do not report a method call whose arguments are all literals or me, like describe_by_name( 'T100' ) */
57
+ this.allowLiteralArguments = true;
58
+ }
59
+ }
60
+ exports.UnhandledClassicExceptionConf = UnhandledClassicExceptionConf;
61
+ class UnhandledClassicException extends _abap_rule_1.ABAPRule {
62
+ constructor() {
63
+ super(...arguments);
64
+ this.conf = new UnhandledClassicExceptionConf();
65
+ }
66
+ getMetadata() {
67
+ return {
68
+ key: "unhandled_classic_exception",
69
+ title: "Unhandled classic exception",
70
+ shortDescription: `Finds calls that do not map every classic exception the callee can raise`,
71
+ extendedInformation: `A classic exception that is raised with RAISE and not mapped in the EXCEPTIONS addition of the call
72
+ ends in the runtime error RAISE_EXCEPTION. TRY ... CATCH cx_root does not catch it.
73
+
74
+ missingOthers: reports CALL FUNCTION and method calls with an EXCEPTIONS list without OTHERS.
75
+ Not reported if the function module or method is known and every exception it declares is listed,
76
+ for CALL FUNCTION ... DESTINATION this includes SYSTEM_FAILURE and COMMUNICATION_FAILURE.
77
+ CALL FUNCTION ... STARTING NEW TASK, IN UPDATE TASK and IN BACKGROUND are not checked.
78
+
79
+ missingExceptions: reports calls without EXCEPTIONS of a method or function module that declares classic exceptions,
80
+ this includes functional calls, which cannot have EXCEPTIONS.
81
+ With allowLiteralArguments, a method call whose arguments are all literals or me is not reported.
82
+
83
+ Signatures are taken from the registry, including dependencies. Methods and function modules that are not
84
+ found (void) are only checked by missingOthers.
85
+
86
+ Does not report any issues if the code contains syntax errors`,
87
+ tags: [_irule_1.RuleTag.Syntax],
88
+ badExample: `CALL FUNCTION 'Z_READ'
89
+ EXCEPTIONS
90
+ not_found = 1.
91
+
92
+ lo_type = cl_abap_typedescr=>describe_by_name( lv_name ).`,
93
+ goodExample: `CALL FUNCTION 'Z_READ'
94
+ EXCEPTIONS
95
+ not_found = 1
96
+ OTHERS = 2.
97
+
98
+ cl_abap_typedescr=>describe_by_name(
99
+ EXPORTING
100
+ p_name = lv_name
101
+ RECEIVING
102
+ p_descr_ref = lo_type
103
+ EXCEPTIONS
104
+ type_not_found = 1
105
+ OTHERS = 2 ).`,
106
+ };
107
+ }
108
+ initialize(reg) {
109
+ super.initialize(reg);
110
+ this.functionModules = undefined;
111
+ return this;
112
+ }
113
+ getConfig() {
114
+ return this.conf;
115
+ }
116
+ setConfig(conf) {
117
+ this.conf = conf;
118
+ }
119
+ runParsed(file, obj) {
120
+ var _a;
121
+ if (obj.getType() === "INTF" || file.getStructure() === undefined) {
122
+ return [];
123
+ }
124
+ const syntax = new syntax_1.SyntaxLogic(this.reg, obj).run();
125
+ if (syntax.issues.length > 0) {
126
+ return [];
127
+ }
128
+ const methods = new Map();
129
+ this.findMethodReferences(syntax.spaghetti.getTop(), file.getFilename(), methods);
130
+ const issues = [];
131
+ for (const statement of file.getStatements()) {
132
+ if (statement.get() instanceof Statements.CallFunction) {
133
+ issues.push(...this.checkCallFunction(statement, file));
134
+ continue;
135
+ }
136
+ if (statement.get() instanceof Statements.Call) {
137
+ const source = statement.findDirectExpression(Expressions.MethodSource);
138
+ const body = statement.findDirectExpression(Expressions.MethodCallBody);
139
+ const nameNode = source === null || source === void 0 ? void 0 : source.getLastChild();
140
+ if (nameNode) {
141
+ const token = nameNode.getFirstToken();
142
+ const callee = nameNode.get() instanceof Expressions.Dynamic ? undefined : this.findMethod(methods, token);
143
+ const issue = this.checkCall(file, token, callee, body === null || body === void 0 ? void 0 : body.findDirectExpression(Expressions.MethodParameters), (body === null || body === void 0 ? void 0 : body.findDirectTokenByText("EXCEPTION-TABLE")) !== undefined, false, this.onlyLiterals(body));
144
+ if (issue) {
145
+ issues.push(issue);
146
+ }
147
+ }
148
+ }
149
+ for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
150
+ const token = (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
151
+ if (token === undefined) {
152
+ continue;
153
+ }
154
+ const param = call.findDirectExpression(Expressions.MethodCallParam);
155
+ const parameters = param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.MethodParameters);
156
+ const issue = this.checkCall(file, token, this.findMethod(methods, token), parameters, false, false, this.onlyLiterals(param));
157
+ if (issue) {
158
+ issues.push(issue);
159
+ }
160
+ }
161
+ }
162
+ return issues;
163
+ }
164
+ checkCallFunction(statement, file) {
165
+ if (statement.findDirectTokenByText("STARTING")
166
+ || statement.findDirectTokenByText("UPDATE")
167
+ || statement.findDirectTokenByText("BACKGROUND")) {
168
+ return [];
169
+ }
170
+ const nameNode = statement.findDirectExpression(Expressions.FunctionName);
171
+ if (nameNode === undefined) {
172
+ return [];
173
+ }
174
+ let callee = undefined;
175
+ if (nameNode.findFirstExpression(Expressions.FieldChain) === undefined) {
176
+ const name = nameNode.concatTokens().replace(/'/g, "").replace(/`/g, "");
177
+ const module = this.findFunctionModule(name);
178
+ if (module) {
179
+ callee = {
180
+ name: module.getName(),
181
+ exceptions: module.isClassBasedExceptions() ? [] : module.getExceptions().map(e => e.toUpperCase()),
182
+ };
183
+ }
184
+ }
185
+ const issue = this.checkCall(file, nameNode.getFirstToken(), callee, statement.findDirectExpression(Expressions.FunctionParameters), statement.findDirectTokenByText("EXCEPTION-TABLE") !== undefined, statement.findDirectExpression(Expressions.Destination) !== undefined, false);
186
+ return issue ? [issue] : [];
187
+ }
188
+ checkCall(file, token, callee, parameters, exceptionTable, destination, onlyLiterals) {
189
+ if (exceptionTable === true) {
190
+ return undefined;
191
+ }
192
+ const list = parameters === null || parameters === void 0 ? void 0 : parameters.findDirectExpression(Expressions.ParameterListExceptions);
193
+ if (list === undefined) {
194
+ if (this.conf.missingExceptions === false
195
+ || callee === undefined
196
+ || callee.exceptions.length === 0
197
+ || (this.conf.allowLiteralArguments === true && onlyLiterals === true)) {
198
+ return undefined;
199
+ }
200
+ const message = `Classic exceptions of "${callee.name}" not handled: ${callee.exceptions.join(", ")}, call it with EXCEPTIONS`;
201
+ return issue_1.Issue.atToken(file, token, message, this.getMetadata().key, this.conf.severity);
202
+ }
203
+ if (this.conf.missingOthers === false) {
204
+ return undefined;
205
+ }
206
+ const listed = list.findDirectExpressions(Expressions.ParameterException)
207
+ .map(e => e.getFirstChild().concatTokens().toUpperCase());
208
+ if (listed.includes("OTHERS")) {
209
+ return undefined;
210
+ }
211
+ const position = parameters.findDirectTokenByText("EXCEPTIONS") || list.getFirstToken();
212
+ if (callee === undefined) {
213
+ const message = "EXCEPTIONS without OTHERS, an exception that is not listed ends in a runtime error";
214
+ return issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity);
215
+ }
216
+ const expected = [...callee.exceptions];
217
+ if (destination === true) {
218
+ expected.push("SYSTEM_FAILURE", "COMMUNICATION_FAILURE");
219
+ }
220
+ const missing = expected.filter(e => listed.includes(e) === false);
221
+ if (missing.length === 0) {
222
+ return undefined;
223
+ }
224
+ const message = `EXCEPTIONS without OTHERS, not mapped: ${missing.join(", ")}`;
225
+ return issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity);
226
+ }
227
+ /** true if the call has arguments and all of them are literals or me, like describe_by_name( 'T100' ) */
228
+ onlyLiterals(node) {
229
+ if (node === undefined || node.findFirstExpression(Expressions.MethodCall) !== undefined) {
230
+ return false;
231
+ }
232
+ const sources = node.findAllExpressions(Expressions.Source);
233
+ return sources.length > 0
234
+ && sources.every(s => { var _a; return (s.getChildren().length === 1 && ((_a = s.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Constant)
235
+ || s.concatTokens().toUpperCase() === "ME"; });
236
+ }
237
+ findMethod(methods, token) {
238
+ const method = methods.get(UnhandledClassicException.positionKey(token.getStart()));
239
+ if (method === undefined) {
240
+ return undefined;
241
+ }
242
+ return {
243
+ name: method.getName(),
244
+ exceptions: method.getExceptions().map(e => e.toUpperCase()),
245
+ };
246
+ }
247
+ findMethodReferences(node, filename, found) {
248
+ for (const r of node.getData().references) {
249
+ if (r.referenceType === _reference_1.ReferenceType.MethodReference
250
+ && r.position.getFilename() === filename
251
+ && r.resolved instanceof types_1.MethodDefinition) {
252
+ found.set(UnhandledClassicException.positionKey(r.position.getStart()), r.resolved);
253
+ }
254
+ }
255
+ for (const child of node.getChildren()) {
256
+ this.findMethodReferences(child, filename, found);
257
+ }
258
+ }
259
+ findFunctionModule(name) {
260
+ if (this.functionModules === undefined) {
261
+ this.functionModules = new Map();
262
+ for (const fugr of this.reg.getObjectsByType("FUGR")) {
263
+ for (const module of fugr.getModules()) {
264
+ this.functionModules.set(module.getName().toUpperCase(), module);
265
+ }
266
+ }
267
+ }
268
+ return this.functionModules.get(name.toUpperCase());
269
+ }
270
+ static positionKey(p) {
271
+ if (p instanceof virtual_position_1.VirtualPosition) {
272
+ return p.getRow() + ":" + p.getCol() + ":" + p.vrow + ":" + p.vcol;
273
+ }
274
+ return p.getRow() + ":" + p.getCol();
275
+ }
276
+ }
277
+ exports.UnhandledClassicException = UnhandledClassicException;
278
+ //# sourceMappingURL=unhandled_classic_exception.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.110",
3
+ "version": "2.120.111",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",