@abaplint/core 2.120.112 → 2.120.113

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 (33) hide show
  1. package/build/abaplint.d.ts +7 -4
  2. package/build/src/abap/2_statements/expressions/method_name.js +1 -1
  3. package/build/src/abap/5_syntax/_builtin_call.js +1 -1
  4. package/build/src/abap/5_syntax/_reserved_names.js +12 -0
  5. package/build/src/abap/5_syntax/basic_types.js +82 -8
  6. package/build/src/abap/5_syntax/expressions/_check_header_line.js +59 -0
  7. package/build/src/abap/5_syntax/expressions/inline_data.js +2 -0
  8. package/build/src/abap/5_syntax/expressions/method_call_chain.js +1 -1
  9. package/build/src/abap/5_syntax/expressions/method_call_param.js +4 -0
  10. package/build/src/abap/5_syntax/expressions/method_parameters.js +4 -0
  11. package/build/src/abap/5_syntax/expressions/type_table.js +21 -1
  12. package/build/src/abap/5_syntax/statements/class_data.js +2 -0
  13. package/build/src/abap/5_syntax/statements/data.js +2 -0
  14. package/build/src/abap/5_syntax/statements/delete_internal.js +11 -0
  15. package/build/src/abap/5_syntax/statements/insert_database.js +12 -0
  16. package/build/src/abap/5_syntax/statements/insert_internal.js +14 -2
  17. package/build/src/abap/5_syntax/statements/modify_internal.js +7 -0
  18. package/build/src/abap/5_syntax/statements/write.js +1 -1
  19. package/build/src/abap/5_syntax/syntax.js +9 -0
  20. package/build/src/abap/types/basic/floating_point_type.js +2 -2
  21. package/build/src/abap/types/basic/hex_type.js +2 -2
  22. package/build/src/abap/types/basic/numeric_type.js +2 -2
  23. package/build/src/abap/types/basic/table_type.js +2 -1
  24. package/build/src/abap/types/method_parameters.js +8 -1
  25. package/build/src/ddic.js +9 -9
  26. package/build/src/objects/table_type.js +8 -7
  27. package/build/src/registry.js +1 -1
  28. package/build/src/rules/check_subrc.js +87 -3
  29. package/build/src/rules/commented_code.js +21 -1
  30. package/build/src/rules/forbidden_statement.js +122 -0
  31. package/build/src/rules/index.js +1 -0
  32. package/build/src/rules/obsolete_statement.js +31 -1
  33. package/package.json +1 -1
@@ -2922,7 +2922,7 @@ declare type Fix = {
2922
2922
 
2923
2923
  declare class FloatingPointType extends AbstractType {
2924
2924
  private readonly length;
2925
- constructor(length: number, qualifiedName?: string);
2925
+ constructor(length: number, extra?: string | AbstractTypeData);
2926
2926
  getLength(): number;
2927
2927
  toText(): string;
2928
2928
  toABAP(): string;
@@ -3298,7 +3298,7 @@ declare class GetTime implements IStatement {
3298
3298
 
3299
3299
  declare class HexType extends AbstractType {
3300
3300
  private readonly length;
3301
- constructor(length: number, qualifiedName?: string);
3301
+ constructor(length: number, extra?: string | AbstractTypeData);
3302
3302
  getLength(): number;
3303
3303
  toText(): string;
3304
3304
  toABAP(): string;
@@ -5266,7 +5266,7 @@ declare class NumericGenericType extends AbstractType {
5266
5266
 
5267
5267
  declare class NumericType extends AbstractType {
5268
5268
  private readonly length;
5269
- constructor(length: number, qualifiedName?: string);
5269
+ constructor(length: number, extra?: string | AbstractTypeData);
5270
5270
  getLength(): number;
5271
5271
  toText(): string;
5272
5272
  toABAP(): string;
@@ -7883,6 +7883,8 @@ declare type SyntaxInput = {
7883
7883
  /** checks which can only run once the full object has been traversed, eg. PERFORM parameters,
7884
7884
  * the FORM might be defined after the PERFORM */
7885
7885
  deferred: (() => void)[];
7886
+ /** the statement is inside a LOOP structure */
7887
+ inLoop?: boolean;
7886
7888
  };
7887
7889
 
7888
7890
  export declare class SyntaxLogic {
@@ -7894,6 +7896,7 @@ export declare class SyntaxLogic {
7894
7896
  private readonly reg;
7895
7897
  private scope;
7896
7898
  private loopTables;
7899
+ private loopDepth;
7897
7900
  private currentMethod;
7898
7901
  private sortedLines;
7899
7902
  private helpers;
@@ -8007,7 +8010,7 @@ declare class TableType extends AbstractObject {
8007
8010
  declare class TableType_2 extends AbstractType {
8008
8011
  private readonly rowType;
8009
8012
  private readonly options;
8010
- constructor(rowType: AbstractType, options: ITableOptions, qualifiedName?: string, description?: string);
8013
+ constructor(rowType: AbstractType, options: ITableOptions, qualifiedName?: string, description?: string, ddicName?: string);
8011
8014
  getOptions(): ITableOptions;
8012
8015
  isWithHeader(): boolean;
8013
8016
  getAccessType(): TableAccessType | undefined;
@@ -4,7 +4,7 @@ exports.MethodName = void 0;
4
4
  const combi_1 = require("../combi");
5
5
  class MethodName extends combi_1.Expression {
6
6
  getRunnable() {
7
- return (0, combi_1.regex)(/^(\/\w+\/)?\w+(~\w+)?$/);
7
+ return (0, combi_1.regex)(/^!?(\/\w+\/)?\w+(~\w+)?$/);
8
8
  }
9
9
  }
10
10
  exports.MethodName = MethodName;
@@ -70,7 +70,7 @@ class BuiltInCall {
70
70
  }
71
71
  static callName(call) {
72
72
  var _a;
73
- return (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
73
+ return (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens().replace(/^!/, "");
74
74
  }
75
75
  static isNumeric(call) {
76
76
  var _a, _b, _c;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkReservedName = checkReservedName;
4
+ const _syntax_input_1 = require("./_syntax_input");
5
+ /** "me" is the self reference in classes, it cannot be declared as a parameter, attribute or variable */
6
+ function checkReservedName(token, input) {
7
+ if (token === undefined || token.getStr().toLowerCase() !== "me" || input.scope.isAnyOO() === false) {
8
+ return;
9
+ }
10
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, "\"me\" is a reserved name, it cannot be declared"));
11
+ }
12
+ //# sourceMappingURL=_reserved_names.js.map
@@ -259,11 +259,47 @@ class BasicTypes {
259
259
  }
260
260
  cloneType(type, qualifiedName) {
261
261
  // nested types(containing "-") will inherit the qualified names if possible
262
- // todo, this needs to be extended to all AbstractTypes instead of just CharacterType
263
- if (type instanceof basic_1.CharacterType
264
- && qualifiedName
265
- && qualifiedName.includes("-") === false) {
266
- type = type.cloneType({ qualifiedName });
262
+ // todo, this needs to be extended to all AbstractTypes
263
+ if (!qualifiedName || qualifiedName.includes("-") === true) {
264
+ return type;
265
+ }
266
+ // TYPES creates a new type, it is no longer the DDIC type
267
+ const data = Object.assign(Object.assign({}, type.getAbstractTypeData()), { qualifiedName, ddicName: undefined });
268
+ if (type instanceof basic_1.CharacterType) {
269
+ type = new basic_1.CharacterType(type.getLength(), data);
270
+ }
271
+ else if (type instanceof Types.IntegerType) {
272
+ type = Types.IntegerType.get(data);
273
+ }
274
+ else if (type instanceof Types.StringType) {
275
+ type = Types.StringType.get(data);
276
+ }
277
+ else if (type instanceof Types.XStringType) {
278
+ type = Types.XStringType.get(data);
279
+ }
280
+ else if (type instanceof Types.Integer8Type) {
281
+ type = new Types.Integer8Type(data);
282
+ }
283
+ else if (type instanceof Types.NumericType) {
284
+ type = new Types.NumericType(type.getLength(), data);
285
+ }
286
+ else if (type instanceof Types.HexType) {
287
+ type = new Types.HexType(type.getLength(), data);
288
+ }
289
+ else if (type instanceof Types.FloatingPointType) {
290
+ type = new Types.FloatingPointType(type.getLength(), data);
291
+ }
292
+ else if (type instanceof Types.DateType) {
293
+ type = new Types.DateType(data);
294
+ }
295
+ else if (type instanceof Types.TimeType) {
296
+ type = new Types.TimeType(data);
297
+ }
298
+ else if (type instanceof basic_1.StructureType) {
299
+ type = new basic_1.StructureType(type.getComponents().slice(), qualifiedName, undefined, type.getDescription());
300
+ }
301
+ else if (type instanceof basic_1.TableType) {
302
+ type = new basic_1.TableType(type.getRowType(), type.getOptions(), qualifiedName, type.getDescription());
267
303
  }
268
304
  return type;
269
305
  }
@@ -595,6 +631,10 @@ class BasicTypes {
595
631
  if (type === undefined) {
596
632
  return new Types.UnknownType("Type error, could not resolve \"" + name + "\", parseType");
597
633
  }
634
+ // generic tables are reported via DataReference.isGeneric()
635
+ if (type.isGeneric() === true && !(type instanceof basic_1.TableType)) {
636
+ throw new Error("LIKE REF TO not possible, \"" + name + "\" is generic");
637
+ }
598
638
  return new Types.DataReference(type, name);
599
639
  }
600
640
  else if (text === "TYPE STANDARD TABLE"
@@ -1098,15 +1138,23 @@ class BasicTypes {
1098
1138
  checkLengthDecimals(node, text) {
1099
1139
  const length = node.findDirectExpression(Expressions.Length);
1100
1140
  const decimals = node.findDirectExpression(Expressions.Decimals);
1101
- if (length === undefined && decimals === undefined) {
1141
+ const fieldLength = node.get() instanceof Statements.Parameter
1142
+ ? undefined : node.findDirectExpression(Expressions.ConstantFieldLength);
1143
+ if (length === undefined && decimals === undefined && fieldLength === undefined) {
1102
1144
  return undefined;
1103
1145
  }
1104
1146
  else if (text.startsWith("LIKE")) {
1105
- if (decimals === undefined) {
1147
+ if (decimals === undefined && fieldLength === undefined) {
1106
1148
  return undefined;
1107
1149
  }
1108
1150
  const message = "When referencing another field (with LIKE), type and length cannot be changed";
1109
- return (0, _syntax_input_1.syntaxIssue)(this.input, decimals.getFirstToken(), message);
1151
+ return (0, _syntax_input_1.syntaxIssue)(this.input, (decimals !== null && decimals !== void 0 ? decimals : node).getFirstToken(), message);
1152
+ }
1153
+ if (fieldLength !== undefined) {
1154
+ const fieldLengthIssue = this.checkFieldLength(node, text);
1155
+ if (fieldLengthIssue !== undefined) {
1156
+ return fieldLengthIssue;
1157
+ }
1110
1158
  }
1111
1159
  const builtin = text.startsWith("TYPE") ? text.substring(4).trim() : "";
1112
1160
  if (length !== undefined && ["C", "N", "X", "P"].includes(builtin) === false) {
@@ -1117,6 +1165,32 @@ class BasicTypes {
1117
1165
  }
1118
1166
  return undefined;
1119
1167
  }
1168
+ // the length in brackets, "DATA foo(8) TYPE d", as a system checks it: c, n, x and p take any length,
1169
+ // d, t and f only their own length, i any length. Their allowed lengths are ignored with a warning,
1170
+ // which is an error in classes and interfaces. Any other type is an error
1171
+ checkFieldLength(node, text) {
1172
+ var _a;
1173
+ const typeNameExpression = node.findFirstExpression(Expressions.TypeName);
1174
+ const typeName = (_a = typeNameExpression === null || typeNameExpression === void 0 ? void 0 : typeNameExpression.concatTokens().toUpperCase()) !== null && _a !== void 0 ? _a : "";
1175
+ if (typeNameExpression === undefined
1176
+ || text.includes(" REF TO ")
1177
+ || ["C", "N", "X", "P"].includes(typeName)) {
1178
+ return undefined;
1179
+ }
1180
+ const token = typeNameExpression.getFirstToken();
1181
+ const ownLength = { "D": 8, "T": 6, "F": 8 };
1182
+ if (ownLength[typeName] !== undefined) {
1183
+ const length = this.findLength(node);
1184
+ if (length !== undefined && length !== ownLength[typeName]) {
1185
+ const message = "Type \"" + typeName + "\" can only have the specified length \"" + ownLength[typeName] + "\" or no length specified at all";
1186
+ return (0, _syntax_input_1.syntaxIssue)(this.input, token, message);
1187
+ }
1188
+ }
1189
+ if ((ownLength[typeName] !== undefined || typeName === "I") && this.input.scope.isAnyOO() === false) {
1190
+ return undefined;
1191
+ }
1192
+ return (0, _syntax_input_1.syntaxIssue)(this.input, token, "Lengths specified in combination with type \"" + typeName + "\" are ignored");
1193
+ }
1120
1194
  findDecimals(node) {
1121
1195
  var _a, _b, _c;
1122
1196
  const dec = (_b = (_a = node.findDirectExpression(Expressions.Decimals)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Integer)) === null || _b === void 0 ? void 0 : _b.concatTokens();
@@ -0,0 +1,59 @@
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.checkHeaderLine = checkHeaderLine;
37
+ const Expressions = __importStar(require("../../2_statements/expressions"));
38
+ const basic_1 = require("../../types/basic");
39
+ const _syntax_input_1 = require("../_syntax_input");
40
+ // A table with header line written without [] is the header line, not the table body,
41
+ // so it cannot be passed to a table typed method parameter. Returns true if an issue was reported.
42
+ function checkHeaderLine(source, sourceType, parameterType, input) {
43
+ if (source === undefined
44
+ || !(parameterType instanceof basic_1.TableType)
45
+ || !(sourceType instanceof basic_1.TableType)
46
+ || sourceType.isWithHeader() === false) {
47
+ return false;
48
+ }
49
+ const chain = source.getChildren().length === 1 ? source.findDirectExpression(Expressions.FieldChain) : undefined;
50
+ const children = (chain === null || chain === void 0 ? void 0 : chain.getChildren()) || [];
51
+ if (chain === undefined || children[children.length - 1].get() instanceof Expressions.TableBody) {
52
+ return false;
53
+ }
54
+ const name = chain.concatTokens();
55
+ const message = `"${name}" is the header line, use "${name}[]" to pass the table body`;
56
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, source.getFirstToken(), message));
57
+ return true;
58
+ }
59
+ //# sourceMappingURL=_check_header_line.js.map
@@ -50,6 +50,7 @@ const _typed_identifier_1 = require("../../types/_typed_identifier");
50
50
  const basic_1 = require("../../types/basic");
51
51
  const _reference_1 = require("../_reference");
52
52
  const _syntax_input_1 = require("../_syntax_input");
53
+ const _reserved_names_1 = require("../_reserved_names");
53
54
  class InlineData {
54
55
  static runSyntax(node, input, type) {
55
56
  var _a;
@@ -58,6 +59,7 @@ class InlineData {
58
59
  const message = "DATA name too long, " + token.getStr();
59
60
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, message));
60
61
  }
62
+ (0, _reserved_names_1.checkReservedName)(token, input);
61
63
  if (token && type) {
62
64
  if (type instanceof basic_1.CSequenceType || type instanceof basic_1.CLikeType) {
63
65
  type = basic_1.StringType.get();
@@ -82,7 +82,7 @@ class MethodCallChain {
82
82
  // for built-in methods set className to undefined
83
83
  const className = context instanceof basic_1.ObjectReferenceType ? context.getIdentifierName() : undefined;
84
84
  const methodToken = (_a = current.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
85
- const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr();
85
+ const methodName = methodToken === null || methodToken === void 0 ? void 0 : methodToken.getStr().replace(/^!/, "");
86
86
  const def = input.scope.findObjectDefinition(className);
87
87
  const isSuper = current === children[2]
88
88
  && first.get() instanceof Expressions.FieldChain
@@ -45,6 +45,7 @@ const _syntax_input_1 = require("../_syntax_input");
45
45
  const constant_1 = require("./constant");
46
46
  const _check_offset_length_1 = require("./_check_offset_length");
47
47
  const _check_text_symbol_1 = require("./_check_text_symbol");
48
+ const _check_header_line_1 = require("./_check_header_line");
48
49
  const _builtin_1 = require("../_builtin");
49
50
  class MethodCallParam {
50
51
  /** returns the type of the unnamed argument, if any */
@@ -122,6 +123,9 @@ class MethodCallParam {
122
123
  else if ((0, _check_text_symbol_1.checkTextSymbol)(child, targetType, input)) {
123
124
  return;
124
125
  }
126
+ else if ((0, _check_header_line_1.checkHeaderLine)(child, sourceType, targetType, input)) {
127
+ return;
128
+ }
125
129
  else if (this.isAssignable(sourceType, targetType, child, method, input) === false) {
126
130
  const message = "Method parameter type not compatible";
127
131
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
@@ -47,6 +47,7 @@ const field_chain_1 = require("./field_chain");
47
47
  const _reference_1 = require("../_reference");
48
48
  const _check_offset_length_1 = require("./_check_offset_length");
49
49
  const _check_text_symbol_1 = require("./_check_text_symbol");
50
+ const _check_header_line_1 = require("./_check_header_line");
50
51
  const _builtin_1 = require("../_builtin");
51
52
  function normalizeParameterName(name) {
52
53
  return name.replace(/^!/, "").toUpperCase();
@@ -212,6 +213,9 @@ class MethodParameters {
212
213
  if ((0, _check_text_symbol_1.checkTextSymbol)(item.source, parameter.getType(), input)) {
213
214
  return;
214
215
  }
216
+ else if ((0, _check_header_line_1.checkHeaderLine)(item.source, item.sourceType, parameter.getType(), input)) {
217
+ return;
218
+ }
215
219
  else if (assignable(item.sourceType, parameter.getType(), item.source) === false) {
216
220
  const message = "Method parameter type not compatible, " + item.name;
217
221
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
@@ -63,7 +63,9 @@ class TypeTable {
63
63
  if (type === undefined) {
64
64
  return new _typed_identifier_1.TypedIdentifier(name, input.filename, new basic_1.UnknownType("TableType, fallback"));
65
65
  }
66
- for (const tt of node.findAllExpressions(Expressions.TypeTableKey)) {
66
+ const keys = node.findAllExpressions(Expressions.TypeTableKey);
67
+ TypeTable.checkUniqueness(keys, type);
68
+ for (const tt of keys) {
67
69
  const error = type_table_key_1.TypeTableKey.runSyntax(tt, type);
68
70
  if (error) {
69
71
  type = error;
@@ -71,6 +73,24 @@ class TypeTable {
71
73
  }
72
74
  return new _typed_identifier_1.TypedIdentifier(name, input.filename, type);
73
75
  }
76
+ static checkUniqueness(keys, type) {
77
+ var _a;
78
+ for (const key of keys) {
79
+ if (key.concatTokens().toUpperCase().startsWith("WITH UNIQUE EMPTY KEY")) {
80
+ throw new Error("EMPTY KEY cannot be UNIQUE");
81
+ }
82
+ }
83
+ // the primary key comes first, it is unnamed or named PRIMARY_KEY
84
+ const first = keys[0];
85
+ const keyName = (_a = first === null || first === void 0 ? void 0 : first.findDirectExpression(Expressions.Field)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
86
+ if (type instanceof basic_1.TableType
87
+ && type.getAccessType() === basic_1.TableAccessType.hashed
88
+ && first !== undefined
89
+ && (keyName === undefined || keyName === "PRIMARY_KEY")
90
+ && first.concatTokens().toUpperCase().startsWith("WITH NON-UNIQUE ")) {
91
+ throw new Error("HASHED tables cannot have NON-UNIQUE key");
92
+ }
93
+ }
74
94
  }
75
95
  exports.TypeTable = TypeTable;
76
96
  //# sourceMappingURL=type_table.js.map
@@ -40,6 +40,7 @@ const data_definition_1 = require("../expressions/data_definition");
40
40
  const unknown_type_1 = require("../../types/basic/unknown_type");
41
41
  const _syntax_input_1 = require("../_syntax_input");
42
42
  const basic_1 = require("../../types/basic");
43
+ const _reserved_names_1 = require("../_reserved_names");
43
44
  class ClassData {
44
45
  runSyntax(node, input) {
45
46
  const dd = node.findFirstExpression(Expressions.DataDefinition);
@@ -48,6 +49,7 @@ class ClassData {
48
49
  if (found === undefined) {
49
50
  return undefined;
50
51
  }
52
+ (0, _reserved_names_1.checkReservedName)(found.getToken(), input);
51
53
  if ((found === null || found === void 0 ? void 0 : found.getType().isGeneric()) === true
52
54
  && (found === null || found === void 0 ? void 0 : found.getType().containsVoid()) === false) {
53
55
  const message = "DATA definition cannot be generic, " + found.getName();
@@ -40,12 +40,14 @@ const data_definition_1 = require("../expressions/data_definition");
40
40
  const unknown_type_1 = require("../../types/basic/unknown_type");
41
41
  const _syntax_input_1 = require("../_syntax_input");
42
42
  const basic_1 = require("../../types/basic");
43
+ const _reserved_names_1 = require("../_reserved_names");
43
44
  class Data {
44
45
  runSyntax(node, input) {
45
46
  const name = node.findFirstExpression(Expressions.DefinitionName);
46
47
  const dd = node.findFirstExpression(Expressions.DataDefinition);
47
48
  if (dd) {
48
49
  const id = data_definition_1.DataDefinition.runSyntax(dd, input);
50
+ (0, _reserved_names_1.checkReservedName)(id === null || id === void 0 ? void 0 : id.getToken(), input);
49
51
  if (id && this.isOnlyDigits(id.getName()) && this.allowOnlyDigitsName(node, input) === false) {
50
52
  const message = "not possible to have a name with only digits";
51
53
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, id.getToken(), message));
@@ -78,6 +78,17 @@ class DeleteInternal {
78
78
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
79
79
  return;
80
80
  }
81
+ if (targetType instanceof basic_1.TableType && targetType.isWithHeader() === false) {
82
+ // short forms, "DELETE itab." deletes the current line inside a LOOP, otherwise both use the header line
83
+ const children = node.getChildren().length;
84
+ const short = children === 3 && input.inLoop !== true;
85
+ const shortTable = children === 4 && node.findDirectTokenByText("TABLE") !== undefined;
86
+ if (short || shortTable) {
87
+ const message = "Table does not have header line";
88
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
89
+ return;
90
+ }
91
+ }
81
92
  if (targetType instanceof basic_1.TableType) {
82
93
  targetType = targetType.getRowType();
83
94
  }
@@ -38,9 +38,12 @@ const Expressions = __importStar(require("../../2_statements/expressions"));
38
38
  const source_1 = require("../expressions/source");
39
39
  const dynamic_1 = require("../expressions/dynamic");
40
40
  const database_table_1 = require("../expressions/database_table");
41
+ const _syntax_input_1 = require("../_syntax_input");
42
+ const basic_1 = require("../../types/basic");
41
43
  const _check_database_work_area_1 = require("../expressions/_check_database_work_area");
42
44
  class InsertDatabase {
43
45
  runSyntax(node, input) {
46
+ var _a;
44
47
  const sourceTypes = new Map();
45
48
  for (const s of node.findAllExpressions(Expressions.Source)) {
46
49
  sourceTypes.set(s, source_1.Source.runSyntax(s, input));
@@ -53,6 +56,15 @@ class InsertDatabase {
53
56
  }
54
57
  const dbtab = node.findFirstExpression(Expressions.DatabaseTable);
55
58
  if (dbtab !== undefined) {
59
+ // "INSERT itab." is the short form for an internal table with header line
60
+ const localType = node.getChildren().length === 3
61
+ ? (_a = input.scope.findVariable(dbtab.concatTokens())) === null || _a === void 0 ? void 0 : _a.getType()
62
+ : undefined;
63
+ if (localType instanceof basic_1.TableType && localType.isWithHeader() === false) {
64
+ const message = "Table does not have header line";
65
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
66
+ return;
67
+ }
56
68
  const dbSource = database_table_1.DatabaseTable.runSyntax(dbtab, input);
57
69
  (0, _check_database_work_area_1.checkDatabaseWorkArea)(node, dbSource, sourceTypes, input);
58
70
  }
@@ -45,7 +45,7 @@ const _type_utils_1 = require("../_type_utils");
45
45
  const _syntax_input_1 = require("../_syntax_input");
46
46
  class InsertInternal {
47
47
  runSyntax(node, input) {
48
- var _a;
48
+ var _a, _b;
49
49
  let targetType;
50
50
  const t = node.findDirectExpression(Expressions.Target);
51
51
  if (t) {
@@ -108,9 +108,21 @@ class InsertInternal {
108
108
  // yea, well, INSERT doesnt convert the values automatically, like everything else?
109
109
  error = true;
110
110
  }
111
+ else if ((sourceType instanceof basic_1.StringType || sourceType instanceof basic_1.CharacterType)
112
+ && ((_a = sourceType.getAbstractTypeData()) === null || _a === void 0 ? void 0 : _a.derivedFromConstant) !== true
113
+ && (source === null || source === void 0 ? void 0 : source.findDirectExpression(Expressions.Constant)) === undefined
114
+ && (targetType instanceof basic_1.IntegerType
115
+ || targetType instanceof basic_1.Integer8Type
116
+ || targetType instanceof basic_1.PackedType
117
+ || targetType instanceof basic_1.FloatType
118
+ || targetType instanceof basic_1.DecFloat16Type
119
+ || targetType instanceof basic_1.DecFloat34Type)) {
120
+ // a character-like data object into a table with a numeric row type, no conversion
121
+ error = true;
122
+ }
111
123
  else if (sourceType instanceof basic_1.CharacterType
112
124
  && targetType instanceof basic_1.CharacterType
113
- && ((_a = sourceType.getAbstractTypeData()) === null || _a === void 0 ? void 0 : _a.derivedFromConstant) === true
125
+ && ((_b = sourceType.getAbstractTypeData()) === null || _b === void 0 ? void 0 : _b.derivedFromConstant) === true
114
126
  && sourceType.getLength() !== targetType.getLength()) {
115
127
  // character literal of different length than the row type
116
128
  error = true;
@@ -81,6 +81,13 @@ class ModifyInternal {
81
81
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
82
82
  return;
83
83
  }
84
+ if (node.findDirectTokenByText("FROM") === undefined
85
+ && targetType.isWithHeader() === false) {
86
+ // short form, the header line is the work area, eg. "MODIFY itab."
87
+ const message = "Table does not have header line";
88
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
89
+ return;
90
+ }
84
91
  }
85
92
  else if (targetType instanceof basic_1.StructureType) {
86
93
  // it might originate from a TABLES statement
@@ -55,7 +55,7 @@ class Write {
55
55
  const issueCount = input.issues.length;
56
56
  const type = source_1.Source.runSyntax(s, input);
57
57
  // "Arithmetic calculation not permitted here" on a system, while abs( x ) or lines( itab ) is fine
58
- const call = s === second && issueCount === input.issues.length && input.scope.getOpenABAP() === false
58
+ const call = s === second && issueCount === input.issues.length
59
59
  ? _builtin_call_1.BuiltInCall.fromSource(s, input) : undefined;
60
60
  if (call !== undefined && _builtin_call_1.BuiltInCall.isNumeric(call) && _builtin_call_1.BuiltInCall.hasDataObjectArgument(call) === false) {
61
61
  const message = `Numeric function "${_builtin_call_1.BuiltInCall.callName(call)}" in WRITE takes only a single data object as argument`;
@@ -361,6 +361,7 @@ class SyntaxLogic {
361
361
  this.issues = [];
362
362
  this.deferred = [];
363
363
  this.loopTables = new _loop_table_change_1.LoopTableChange();
364
+ this.loopDepth = 0;
364
365
  this.sortedLines = new _sorted_key_write_1.SortedKeyWrite();
365
366
  this.reg.getDDICReferences().clear(this.object);
366
367
  this.reg.getMSAGReferences().clear(this.object);
@@ -430,6 +431,10 @@ class SyntaxLogic {
430
431
  const loop = node instanceof nodes_1.StructureNode
431
432
  && node.get() instanceof Structures.Loop
432
433
  && this.loopTables.push(node, this.scope);
434
+ const isLoop = node instanceof nodes_1.StructureNode && node.get() instanceof Structures.Loop;
435
+ if (isLoop) {
436
+ this.loopDepth++;
437
+ }
433
438
  if (node instanceof nodes_1.StructureNode) {
434
439
  this.sortedLines.enter(node, this.currentFile.getFilename());
435
440
  }
@@ -478,6 +483,9 @@ class SyntaxLogic {
478
483
  if (loop === true) {
479
484
  this.loopTables.pop();
480
485
  }
486
+ if (isLoop) {
487
+ this.loopDepth--;
488
+ }
481
489
  if (node instanceof nodes_1.StructureNode && node.get() instanceof Structures.Loop) {
482
490
  const loopStatement = node.findDirectStatement(Statements.Loop);
483
491
  if (loopStatement) {
@@ -563,6 +571,7 @@ class SyntaxLogic {
563
571
  filename,
564
572
  issues: this.issues,
565
573
  deferred: this.deferred,
574
+ inLoop: this.loopDepth > 0,
566
575
  };
567
576
  // todo, refactor
568
577
  if (s instanceof Statements.Type) {
@@ -4,8 +4,8 @@ exports.FloatingPointType = void 0;
4
4
  const _abstract_type_1 = require("./_abstract_type");
5
5
  // this is the DDIC floating point type
6
6
  class FloatingPointType extends _abstract_type_1.AbstractType {
7
- constructor(length, qualifiedName) {
8
- super({ qualifiedName: qualifiedName });
7
+ constructor(length, extra) {
8
+ super(extra === undefined || typeof extra === "string" ? { qualifiedName: extra } : extra);
9
9
  if (length <= 0) {
10
10
  throw new Error("Bad LENGTH, Floating Point");
11
11
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HexType = void 0;
4
4
  const _abstract_type_1 = require("./_abstract_type");
5
5
  class HexType extends _abstract_type_1.AbstractType {
6
- constructor(length, qualifiedName) {
7
- super({ qualifiedName: qualifiedName });
6
+ constructor(length, extra) {
7
+ super(extra === undefined || typeof extra === "string" ? { qualifiedName: extra } : extra);
8
8
  if (length <= 0) {
9
9
  throw new Error("Bad LENGTH, Hex");
10
10
  }
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NumericType = void 0;
4
4
  const _abstract_type_1 = require("./_abstract_type");
5
5
  class NumericType extends _abstract_type_1.AbstractType {
6
- constructor(length, qualifiedName) {
7
- super({ qualifiedName: qualifiedName });
6
+ constructor(length, extra) {
7
+ super(extra === undefined || typeof extra === "string" ? { qualifiedName: extra } : extra);
8
8
  if (length <= 0) {
9
9
  throw new Error("Bad LENGTH, Numeric");
10
10
  }
@@ -17,11 +17,12 @@ var TableKeyType;
17
17
  TableKeyType["empty"] = "EMPTY";
18
18
  })(TableKeyType || (exports.TableKeyType = TableKeyType = {}));
19
19
  class TableType extends _abstract_type_1.AbstractType {
20
- constructor(rowType, options, qualifiedName, description) {
20
+ constructor(rowType, options, qualifiedName, description, ddicName) {
21
21
  var _a;
22
22
  super({
23
23
  qualifiedName: qualifiedName,
24
24
  description: description,
25
+ ddicName: ddicName,
25
26
  });
26
27
  this.rowType = rowType;
27
28
  this.options = options;
@@ -47,6 +47,7 @@ const _reference_1 = require("../5_syntax/_reference");
47
47
  const identifier_1 = require("../1_lexer/tokens/identifier");
48
48
  const _scope_type_1 = require("../5_syntax/_scope_type");
49
49
  const _syntax_input_1 = require("../5_syntax/_syntax_input");
50
+ const _reserved_names_1 = require("../5_syntax/_reserved_names");
50
51
  // the keywords that can follow a parameter in each section, a plain parameter name is read as them
51
52
  const KEYWORDS_AFTER = {
52
53
  "IMPORTING": ["PREFERRED", "EXPORTING", "CHANGING", "RETURNING", "RAISING", "EXCEPTIONS"],
@@ -232,6 +233,7 @@ class MethodParameters {
232
233
  if (parameter.getName().length > 30) {
233
234
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, parameter.getToken(), "Method parameter name longer than 30 characters"));
234
235
  }
236
+ (0, _reserved_names_1.checkReservedName)(parameter.getToken(), input);
235
237
  }
236
238
  }
237
239
  workaroundRAP(node, input, parentName) {
@@ -318,9 +320,14 @@ class MethodParameters {
318
320
  const id = method_param_1.MethodParam.runSyntax(p, input, [...meta, ...extraMeta]);
319
321
  input.scope.addIdentifier(id);
320
322
  target.push(id);
321
- if (opt.findDirectTokenByText("OPTIONAL")) {
323
+ const optionalToken = opt.findDirectTokenByText("OPTIONAL");
324
+ if (optionalToken) {
322
325
  const name = target[target.length - 1].getName().toUpperCase();
323
326
  this.optional.push(name);
327
+ if (opt.findFirstExpression(Expressions.Default)) {
328
+ const message = "Parameter \"" + id.getName() + "\" cannot have both DEFAULT and OPTIONAL";
329
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, optionalToken, message));
330
+ }
324
331
  }
325
332
  else if (opt.findFirstExpression(Expressions.Default)) {
326
333
  const name = target[target.length - 1].getName().toUpperCase();
package/build/src/ddic.js CHANGED
@@ -400,7 +400,7 @@ class DDIC {
400
400
  if (input.length === undefined) {
401
401
  return new Types.UnknownType(input.text + " unknown length", input.infoText);
402
402
  }
403
- return new Types.NumericType(parseInt(input.length, 10), input.qualifiedName);
403
+ return new Types.NumericType(parseInt(input.length, 10), extra);
404
404
  case "CHAR": // 1 <= len <= 30000 (1333 for table fields)
405
405
  case "LCHR": // 256 <= len <= 32000
406
406
  if (input.length === undefined) {
@@ -412,10 +412,10 @@ class DDIC {
412
412
  if (input.length === undefined) {
413
413
  return new Types.UnknownType(input.text + " unknown length", input.infoText);
414
414
  }
415
- return new Types.HexType(parseInt(input.length, 10), input.qualifiedName);
415
+ return new Types.HexType(parseInt(input.length, 10), extra);
416
416
  case "TIMN": // Native HANA
417
417
  case "TIMS":
418
- return new Types.TimeType({ qualifiedName: input.qualifiedName }); //HHMMSS
418
+ return new Types.TimeType(extra); //HHMMSS
419
419
  case "DECFLOAT16": // len = 16
420
420
  case "DECFLOAT34": // len = 34
421
421
  case "D16R": // len = 16
@@ -426,25 +426,25 @@ class DDIC {
426
426
  if (input.length === undefined) {
427
427
  return new Types.UnknownType(input.text + " unknown length", input.infoText);
428
428
  }
429
- return new Types.FloatingPointType(parseInt(input.length, 10), input.qualifiedName);
429
+ return new Types.FloatingPointType(parseInt(input.length, 10), extra);
430
430
  case "DATN": // Native HANA
431
431
  case "DATS":
432
- return new Types.DateType({ qualifiedName: input.qualifiedName }); //YYYYMMDD
432
+ return new Types.DateType(extra); //YYYYMMDD
433
433
  case "INT1":
434
434
  case "INT2":
435
435
  case "INT4":
436
- return Types.IntegerType.get({ qualifiedName: input.qualifiedName });
436
+ return Types.IntegerType.get(extra);
437
437
  case "INT8":
438
- return new Types.Integer8Type({ qualifiedName: input.qualifiedName });
438
+ return new Types.Integer8Type(extra);
439
439
  case "SSTR": // 1 <= len <= 1333
440
440
  case "SSTRING": // 1 <= len <= 1333
441
441
  case "STRG": // 256 <= len
442
442
  case "STRING": // 256 <= len
443
- return Types.StringType.get({ qualifiedName: input.qualifiedName });
443
+ return Types.StringType.get(extra);
444
444
  case "RSTR": // 256 <= len
445
445
  case "RAWSTRING": // 256 <= len
446
446
  case "GEOM_EWKB":
447
- return Types.XStringType.get({ qualifiedName: input.qualifiedName });
447
+ return Types.XStringType.get(extra);
448
448
  case "D16S":
449
449
  case "D34S":
450
450
  case "DF16_SCL":
@@ -141,34 +141,35 @@ class TableType extends _abstract_object_1.AbstractObject {
141
141
  }
142
142
  else if (this.parsedXML.rowkind === "S") {
143
143
  const lookup = ddic.lookupTableOrView(this.parsedXML.rowtype);
144
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
144
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
145
145
  if (lookup.object) {
146
146
  references.push({ object: lookup.object });
147
147
  }
148
148
  }
149
149
  else if (this.parsedXML.rowkind === "E") {
150
150
  const lookup = ddic.lookupDataElement(this.parsedXML.rowtype);
151
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
151
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
152
152
  if (lookup.object) {
153
153
  references.push({ object: lookup.object });
154
154
  }
155
155
  }
156
156
  else if (this.parsedXML.rowkind === "L") {
157
157
  const lookup = ddic.lookupTableType(this.parsedXML.rowtype);
158
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
158
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
159
159
  if (lookup.object) {
160
160
  references.push({ object: lookup.object });
161
161
  }
162
162
  }
163
163
  else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype === "OBJECT") {
164
- type = new Types.TableType(new basic_1.GenericObjectReferenceType(), tableOptions, this.getName(), this.getDescription());
164
+ type = new Types.TableType(new basic_1.GenericObjectReferenceType(), tableOptions, this.getName(), this.getDescription(), this.getName());
165
165
  }
166
166
  else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype === "DATA") {
167
- type = new Types.TableType(new basic_1.DataReference(new Types.DataType()), tableOptions, this.getName(), this.getDescription());
167
+ const row = new basic_1.DataReference(new Types.DataType());
168
+ type = new Types.TableType(row, tableOptions, this.getName(), this.getDescription(), this.getName());
168
169
  }
169
170
  else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype !== undefined) {
170
171
  const lookup = ddic.lookupObject(this.parsedXML.rowtype);
171
- type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription());
172
+ type = new Types.TableType(lookup.type, tableOptions, this.getName(), this.getDescription(), this.getName());
172
173
  if (lookup.object) {
173
174
  references.push({ object: lookup.object });
174
175
  }
@@ -184,7 +185,7 @@ class TableType extends _abstract_object_1.AbstractObject {
184
185
  decimals: this.parsedXML.decimals,
185
186
  infoText: this.getName(),
186
187
  });
187
- type = new Types.TableType(row, tableOptions, this.getName(), this.getDescription());
188
+ type = new Types.TableType(row, tableOptions, this.getName(), this.getDescription(), this.getName());
188
189
  }
189
190
  }
190
191
  else {
@@ -78,7 +78,7 @@ class Registry {
78
78
  }
79
79
  static abaplintVersion() {
80
80
  // magic, see build script "version.js"
81
- return "2.120.112";
81
+ return "2.120.113";
82
82
  }
83
83
  getDDICReferences() {
84
84
  return this.ddicReferences;
@@ -56,6 +56,10 @@ class CheckSubrcConf extends _basic_rule_config_1.BasicRuleConfig {
56
56
  this.readTable = true;
57
57
  this.assign = true;
58
58
  this.find = true;
59
+ /** CALL FUNCTION with EXCEPTIONS, unless every exception is mapped to 0 */
60
+ this.callFunction = true;
61
+ /** Method call with EXCEPTIONS, unless every exception is mapped to 0 */
62
+ this.callMethod = true;
59
63
  }
60
64
  }
61
65
  exports.CheckSubrcConf = CheckSubrcConf;
@@ -77,7 +81,17 @@ If sy-dbcnt is checked after database statements, it is considered okay.
77
81
 
78
82
  If IS ASSIGNED is checked after assigning, it is considered okay.
79
83
 
80
- FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
84
+ FIND statement with MATCH COUNT is considered okay if subrc is not checked
85
+
86
+ CALL FUNCTION and method calls are checked if they have an EXCEPTIONS addition that maps an exception to a value other than 0,
87
+ including CALL FUNCTION DESTINATION and STARTING NEW TASK. Not checked: calls without EXCEPTIONS, calls where every exception
88
+ is mapped to 0, EXCEPTION-TABLE, CALL FUNCTION IN UPDATE TASK and IN BACKGROUND.
89
+ For CALL FUNCTION the pragma ##FM_SUBRC_OK is also accepted.
90
+
91
+ A call of a method with SUBRC in its name, like check_subrc( ), is considered a check.
92
+
93
+ After ELSE, ELSEIF, WHEN, CATCH and CLEANUP the check continues after the end of the block, as these branches are not run
94
+ after the statement`,
81
95
  tags: [_irule_1.RuleTag.SingleFile, _irule_1.RuleTag.Quickfix],
82
96
  pseudoComment: "EC CI_SUBRC",
83
97
  pragma: "##SUBRC_OK",
@@ -102,7 +116,6 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
102
116
  const config = this.getConfig();
103
117
  for (let i = 0; i < statements.length; i++) {
104
118
  const statement = statements[i];
105
- // todo: CALL FUNCTION
106
119
  if (statement.getPragmas().some(t => t.getStr() === this.getMetadata().pragma)) {
107
120
  continue;
108
121
  }
@@ -188,6 +201,22 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
188
201
  const fix = this.buildFix(file, statement);
189
202
  issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, undefined, [fix]));
190
203
  }
204
+ else if (config.callFunction === true
205
+ && statement.get() instanceof Statements.CallFunction
206
+ && statement.getPragmas().some(t => t.getStr().toUpperCase() === "##FM_SUBRC_OK") === false
207
+ && this.isUpdateOrBackgroundTask(statement) === false
208
+ && this.mapsExceptionToNonZero(statement) === true
209
+ && this.isChecked(i, statements) === false) {
210
+ const fix = this.buildFix(file, statement);
211
+ issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, undefined, [fix]));
212
+ }
213
+ else if (config.callMethod === true
214
+ && statement.get() instanceof Statements.Call
215
+ && this.mapsExceptionToNonZero(statement) === true
216
+ && this.isChecked(i, statements) === false) {
217
+ const fix = this.buildFix(file, statement);
218
+ issues.push(issue_1.Issue.atStatement(file, statement, message, this.getMetadata().key, this.conf.severity, undefined, [fix]));
219
+ }
191
220
  }
192
221
  return issues;
193
222
  }
@@ -202,6 +231,22 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
202
231
  }
203
232
  return false;
204
233
  }
234
+ /** true if the EXCEPTIONS addition maps an exception to a value other than 0, then the call sets sy-subrc */
235
+ mapsExceptionToNonZero(statement) {
236
+ for (const list of statement.findAllExpressions(Expressions.ParameterListExceptions)) {
237
+ for (const exception of list.findDirectExpressions(Expressions.ParameterException)) {
238
+ const value = exception.findDirectExpression(Expressions.Integer);
239
+ if (value === undefined || parseInt(value.concatTokens().replace(/\s/g, ""), 10) !== 0) {
240
+ return true;
241
+ }
242
+ }
243
+ }
244
+ return false;
245
+ }
246
+ isUpdateOrBackgroundTask(statement) {
247
+ const concat = statement.concatTokens().toUpperCase();
248
+ return concat.includes(" IN UPDATE TASK") || concat.includes(" IN BACKGROUND ");
249
+ }
205
250
  isExemptedFind(s) {
206
251
  // see https://github.com/abaplint/abaplint/issues/2130
207
252
  return s.concatTokens().toUpperCase().includes(" MATCH COUNT ") === true;
@@ -223,6 +268,28 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
223
268
  }
224
269
  return false;
225
270
  }
271
+ /** index of the end statement that closes the block the statement at index is in */
272
+ findEnd(index, statements, open, close) {
273
+ let depth = 0;
274
+ for (let i = index + 1; i < statements.length; i++) {
275
+ const statement = statements[i].get();
276
+ if (open.some(o => statement instanceof o)) {
277
+ depth++;
278
+ }
279
+ else if (statement instanceof close) {
280
+ if (depth === 0) {
281
+ return i;
282
+ }
283
+ depth--;
284
+ }
285
+ }
286
+ return statements.length;
287
+ }
288
+ /** a method call like check_subrc( ), the method reads sy-subrc */
289
+ callsSubrcMethod(statement) {
290
+ return statement.get() instanceof Statements.Call
291
+ && statement.findAllExpressions(Expressions.MethodName).some(m => m.concatTokens().toUpperCase().includes("SUBRC"));
292
+ }
226
293
  isChecked(index, statements) {
227
294
  var _a, _b;
228
295
  let assigned = undefined;
@@ -242,9 +309,25 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
242
309
  }
243
310
  }
244
311
  else if (statement.get() instanceof Statements.EndIf
312
+ || statement.get() instanceof Statements.EndCase
313
+ || statement.get() instanceof Statements.EndTry
245
314
  || statement.get() instanceof Statements.EndTestSeam) {
246
315
  continue;
247
316
  }
317
+ else if (statement.get() instanceof Statements.Else
318
+ || statement.get() instanceof Statements.ElseIf) {
319
+ // the other branches are not run after this one, continue after ENDIF
320
+ i = this.findEnd(i, statements, [Statements.If], Statements.EndIf);
321
+ }
322
+ else if (statement.get() instanceof Statements.When
323
+ || statement.get() instanceof Statements.WhenOthers
324
+ || statement.get() instanceof Statements.WhenType) {
325
+ i = this.findEnd(i, statements, [Statements.Case, Statements.CaseType], Statements.EndCase);
326
+ }
327
+ else if (statement.get() instanceof Statements.Catch
328
+ || statement.get() instanceof Statements.Cleanup) {
329
+ i = this.findEnd(i, statements, [Statements.Try], Statements.EndTry);
330
+ }
248
331
  else {
249
332
  if (assigned && concat.includes(assigned)) {
250
333
  return true;
@@ -253,7 +336,8 @@ FIND statement with MATCH COUNT is considered okay if subrc is not checked`,
253
336
  return true;
254
337
  }
255
338
  return concat.includes(" SY-SUBRC")
256
- || concat.includes("CL_ABAP_UNIT_ASSERT=>ASSERT_SUBRC");
339
+ || concat.includes("CL_ABAP_UNIT_ASSERT=>ASSERT_SUBRC")
340
+ || this.callsSubrcMethod(statement);
257
341
  }
258
342
  }
259
343
  return false;
@@ -81,7 +81,8 @@ https://docs.abapopenchecks.org/checks/14/`,
81
81
  return [];
82
82
  }
83
83
  let containsStatement = false;
84
- for (const statementNode of statementNodes) {
84
+ for (let i = 0; i < statementNodes.length; i++) {
85
+ const statementNode = statementNodes[i];
85
86
  const statement = statementNode.get();
86
87
  if (this.getConfig().allowIncludeInFugr === true
87
88
  && obj instanceof objects_1.FunctionGroup
@@ -91,6 +92,9 @@ https://docs.abapopenchecks.org/checks/14/`,
91
92
  if (!(statement instanceof _statement_1.Unknown
92
93
  || statement instanceof _statement_1.Empty
93
94
  || statement instanceof _statement_1.Comment)) {
95
+ if (this.isSplitFromText(statementNodes, i)) {
96
+ continue;
97
+ }
94
98
  containsStatement = true;
95
99
  break;
96
100
  }
@@ -102,6 +106,22 @@ https://docs.abapopenchecks.org/checks/14/`,
102
106
  const issue = issue_1.Issue.atRange(file, posStart, posEnd, this.getMessage(), this.getMetadata().key, this.conf.severity, fix);
103
107
  return [issue];
104
108
  }
109
+ /**
110
+ * The statement parser splits an Unknown statement at a line break if the rest parses as a statement.
111
+ * In comment text, such a split is code only if no further text follows the statement on its line.
112
+ */
113
+ isSplitFromText(statementNodes, index) {
114
+ const previous = statementNodes[index - 1];
115
+ if (previous === undefined
116
+ || !(previous.get() instanceof _statement_1.Unknown)
117
+ || [".", ","].includes(previous.getLastToken().getStr())) {
118
+ return false;
119
+ }
120
+ const next = statementNodes[index + 1];
121
+ return next !== undefined
122
+ && next.get() instanceof _statement_1.Unknown
123
+ && next.getFirstToken().getRow() === statementNodes[index].getLastToken().getRow();
124
+ }
105
125
  isCommentLine(text) {
106
126
  return (text.substr(0, 1) === "*")
107
127
  || (text.trim().substr(0, 1) === "\"" && text.trim().substr(1, 1) !== "!");
@@ -0,0 +1,122 @@
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.ForbiddenStatement = exports.ForbiddenStatementConf = void 0;
37
+ const Statements = __importStar(require("../abap/2_statements/statements"));
38
+ const _abap_rule_1 = require("./_abap_rule");
39
+ const _basic_rule_config_1 = require("./_basic_rule_config");
40
+ const issue_1 = require("../issue");
41
+ const _irule_1 = require("./_irule");
42
+ class ForbiddenStatementConf extends _basic_rule_config_1.BasicRuleConfig {
43
+ constructor() {
44
+ super(...arguments);
45
+ /** List of forbidden statements, given as abaplint statement names,
46
+ * case insensitive, spaces, underscores and dashes are ignored,
47
+ * so "READ TABLE", "ReadTable" and "read_table" are the same
48
+ * @uniqueItems true
49
+ */
50
+ this.statements = [];
51
+ }
52
+ }
53
+ exports.ForbiddenStatementConf = ForbiddenStatementConf;
54
+ class ForbiddenStatement extends _abap_rule_1.ABAPRule {
55
+ constructor() {
56
+ super(...arguments);
57
+ this.conf = new ForbiddenStatementConf();
58
+ /** statement class -> configured spelling, used in the message */
59
+ this.forbidden = new Map();
60
+ }
61
+ getMetadata() {
62
+ return {
63
+ key: "forbidden_statement",
64
+ title: "Forbidden Statement",
65
+ shortDescription: `Forbid use of specified statements.`,
66
+ extendedInformation: `Nothing is reported unless statements are configured.
67
+
68
+ A configured entry matches the abaplint statement with the same name, compared case insensitive,
69
+ ignoring spaces, underscores and dashes, so "READ TABLE", "ReadTable" and "read_table" all match ReadTable.
70
+
71
+ The names are the class names in https://github.com/abaplint/abaplint/tree/main/packages/core/src/abap/2_statements/statements,
72
+ some keywords are split into several statements, eg. "INSERT" does not match anything,
73
+ use "InsertInternal" or "InsertDatabase", likewise for DELETE, MODIFY and READ. Entries that do not match a statement are ignored.
74
+
75
+ Each part of a chained statement is checked as a separate statement.`,
76
+ tags: [_irule_1.RuleTag.SingleFile],
77
+ badExample: `* with "statements": ["READ TABLE"]
78
+ READ TABLE items INDEX 1 INTO item.`,
79
+ goodExample: `* with "statements": ["READ TABLE"]
80
+ item = items[ 1 ].`,
81
+ };
82
+ }
83
+ getConfig() {
84
+ return this.conf;
85
+ }
86
+ setConfig(conf) {
87
+ this.conf = conf;
88
+ if (this.conf.statements === undefined) {
89
+ this.conf.statements = [];
90
+ }
91
+ const byName = new Map();
92
+ for (const [name, value] of Object.entries(Statements)) {
93
+ byName.set(ForbiddenStatement.normalize(name), value);
94
+ }
95
+ this.forbidden = new Map();
96
+ for (const entry of this.conf.statements) {
97
+ const found = byName.get(ForbiddenStatement.normalize(entry));
98
+ if (found !== undefined && this.forbidden.has(found) === false) {
99
+ this.forbidden.set(found, entry.trim());
100
+ }
101
+ }
102
+ }
103
+ runParsed(file) {
104
+ if (this.forbidden.size === 0) {
105
+ return [];
106
+ }
107
+ const ret = [];
108
+ for (const s of file.getStatements()) {
109
+ const name = this.forbidden.get(s.get().constructor);
110
+ if (name !== undefined) {
111
+ const message = "Statement \"" + name + "\" is forbidden";
112
+ ret.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.conf.severity));
113
+ }
114
+ }
115
+ return ret;
116
+ }
117
+ static normalize(name) {
118
+ return name.toLowerCase().replace(/[\s_-]/g, "");
119
+ }
120
+ }
121
+ exports.ForbiddenStatement = ForbiddenStatement;
122
+ //# sourceMappingURL=forbidden_statement.js.map
@@ -98,6 +98,7 @@ __exportStar(require("./fm_global_parameters_obsolete"), exports);
98
98
  __exportStar(require("./forbidden_identifier"), exports);
99
99
  __exportStar(require("./forbidden_kernel_write"), exports);
100
100
  __exportStar(require("./forbidden_pseudo_and_pragma"), exports);
101
+ __exportStar(require("./forbidden_statement"), exports);
101
102
  __exportStar(require("./forbidden_void_type"), exports);
102
103
  __exportStar(require("./form_tables_obsolete"), exports);
103
104
  __exportStar(require("./fully_type_constants"), exports);
@@ -112,6 +112,8 @@ class ObsoleteStatementConf extends _basic_rule_config_1.BasicRuleConfig {
112
112
  this.replaceInto = true;
113
113
  this.loopExtract = true;
114
114
  this.sortExtract = true;
115
+ /** Checks for TRANSLATE statement */
116
+ this.translate = true;
115
117
  }
116
118
  }
117
119
  exports.ObsoleteStatementConf = ObsoleteStatementConf;
@@ -168,7 +170,9 @@ POSIX REGEX: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/ABE
168
170
 
169
171
  OCCURENCES: check for OCCURENCES vs OCCURRENCES
170
172
 
171
- CLIENT SPECIFIED, from 754: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapselect_client_obsolete.html`,
173
+ CLIENT SPECIFIED, from 754: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapselect_client_obsolete.html
174
+
175
+ TRANSLATE: https://help.sap.com/docs/abap-cloud/abap-keywords-standard-abap/translate`,
172
176
  badExample: `REFRESH itab.
173
177
 
174
178
  COMPUTE foo = 2 + 2.
@@ -373,6 +377,11 @@ ENDIF.`,
373
377
  const issue = issue_1.Issue.atStatement(file, staNode, "SORT extract", this.getMetadata().key, this.conf.severity);
374
378
  issues.push(issue);
375
379
  }
380
+ if (this.conf.translate && sta instanceof Statements.Translate) {
381
+ const fix = this.getTranslateFix(file, staNode);
382
+ const issue = issue_1.Issue.atStatement(file, staNode, "TRANSLATE is obsolete", this.getMetadata().key, this.conf.severity, fix);
383
+ issues.push(issue);
384
+ }
376
385
  if ((0, version_1.releaseAtLeast)(configRelease, version_1.Release.v754) && this.conf.clientSpecified
377
386
  && (sta instanceof Statements.Select
378
387
  || sta instanceof Statements.SelectLoop
@@ -495,6 +504,27 @@ ENDIF.`,
495
504
  }
496
505
  return undefined;
497
506
  }
507
+ getTranslateFix(file, statementNode) {
508
+ const tokens = statementNode.getTokens();
509
+ // tokens: TRANSLATE <target> TO UPPER|LOWER CASE .
510
+ // or: TRANSLATE <target> USING <source> .
511
+ if (tokens.length < 4) {
512
+ return undefined;
513
+ }
514
+ const thirdToken = tokens[2].getStr().toUpperCase();
515
+ if (thirdToken !== "TO") {
516
+ return undefined;
517
+ }
518
+ const targetStr = tokens[1].getStr();
519
+ const directionToken = tokens[3].getStr().toUpperCase();
520
+ if (directionToken === "UPPER") {
521
+ return edit_helper_1.EditHelper.replaceRange(file, statementNode.getStart(), statementNode.getEnd(), targetStr + " = to_upper( " + targetStr + " ).");
522
+ }
523
+ else if (directionToken === "LOWER") {
524
+ return edit_helper_1.EditHelper.replaceRange(file, statementNode.getStart(), statementNode.getEnd(), targetStr + " = to_lower( " + targetStr + " ).");
525
+ }
526
+ return undefined;
527
+ }
498
528
  }
499
529
  exports.ObsoleteStatement = ObsoleteStatement;
500
530
  //# sourceMappingURL=obsolete_statement.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.112",
3
+ "version": "2.120.113",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",