@abaplint/core 2.120.86 → 2.120.88

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.
@@ -42,6 +42,18 @@ export declare abstract class ABAPObject extends AbstractObject {
42
42
  private findTextsTranslations;
43
43
  }
44
44
 
45
+ export declare class ABAPParser {
46
+ private readonly release;
47
+ private readonly languageVersion;
48
+ private readonly globalMacros;
49
+ private readonly reg?;
50
+ /** @deprecated Use `new ABAPParser(options)` instead */
51
+ constructor(release: ABAPRelease, globalMacros?: readonly string[], reg?: IRegistry);
52
+ constructor(options?: IABAPParserOptions);
53
+ private static isRelease;
54
+ parse(files: readonly IFile[]): IABAPParserResult;
55
+ }
56
+
45
57
  declare class ABAPQueryFunctionalArea extends AbstractObject {
46
58
  getType(): string;
47
59
  getAllowedNaming(): {
@@ -3304,6 +3316,25 @@ declare interface IAbaplintAppSettings {
3304
3316
  observations?: boolean;
3305
3317
  }
3306
3318
 
3319
+ export declare interface IABAPParserOptions {
3320
+ release?: ABAPRelease;
3321
+ languageVersion?: LanguageVersion;
3322
+ globalMacros?: readonly string[];
3323
+ reg?: IRegistry;
3324
+ }
3325
+
3326
+ export declare interface IABAPParserResult {
3327
+ issues: readonly Issue[];
3328
+ output: readonly ABAPFile[];
3329
+ /** runtime in milliseconds */
3330
+ runtime: number;
3331
+ runtimeExtra: {
3332
+ lexing: number;
3333
+ statements: number;
3334
+ structure: number;
3335
+ };
3336
+ }
3337
+
3307
3338
  declare class IACBinaryData extends AbstractObject {
3308
3339
  getType(): string;
3309
3340
  getAllowedNaming(): {
@@ -8,10 +8,15 @@ class FormParamType extends combi_1.Expression {
8
8
  getRunnable() {
9
9
  const def = (0, combi_1.seq)("DEFAULT", (0, combi_1.alt)(_1.Constant, _1.FieldChain));
10
10
  const table = (0, combi_1.seq)((0, combi_1.alt)("STANDARD", "HASHED", "INDEX", "SORTED", "ANY"), "TABLE");
11
- const tabseq = (0, combi_1.seq)(table, (0, combi_1.optPrio)((0, combi_1.seq)("OF", _1.TypeName)));
12
- const ret = (0, combi_1.seq)((0, combi_1.optPrio)((0, combi_1.alt)("REF TO", "LINE OF")), _1.TypeName, (0, combi_1.opt)(def));
13
- const like = (0, combi_1.seq)("LIKE", (0, combi_1.optPrio)((0, combi_1.alt)("REF TO", "LINE OF")), _1.FieldChain);
14
- return (0, combi_1.alt)((0, combi_1.seq)("TYPE", (0, combi_1.altPrio)(tabseq, (0, combi_1.ver)(version_1.Release.v916, (0, combi_1.seq)("ANY", "STRUCTURE")), ret)), like);
11
+ // the following are not valid FORM typings, fail instead of reading the
12
+ // remaining words as additional parameters
13
+ const inline = (0, combi_1.seq)((0, combi_1.alt)("TABLE", "RANGE"), "OF", (0, combi_1.failCombinator)());
14
+ const tableKey = (0, combi_1.seq)("WITH", (0, combi_1.failCombinator)());
15
+ const lengthDecimals = (0, combi_1.seq)((0, combi_1.alt)("LENGTH", "DECIMALS"), _1.Integer, (0, combi_1.failCombinator)());
16
+ const tabseq = (0, combi_1.seq)(table, (0, combi_1.optPrio)((0, combi_1.seq)("OF", (0, combi_1.altPrio)((0, combi_1.seq)("REF TO", (0, combi_1.failCombinator)()), _1.TypeName))), (0, combi_1.optPrio)(tableKey));
17
+ const ret = (0, combi_1.seq)((0, combi_1.optPrio)((0, combi_1.alt)("REF TO", "LINE OF")), _1.TypeName, (0, combi_1.optPrio)(lengthDecimals), (0, combi_1.opt)(def));
18
+ const like = (0, combi_1.seq)("LIKE", (0, combi_1.altPrio)(inline, (0, combi_1.seq)(table, (0, combi_1.failCombinator)()), (0, combi_1.seq)((0, combi_1.optPrio)((0, combi_1.alt)("REF TO", "LINE OF")), _1.FieldChain)));
19
+ return (0, combi_1.alt)((0, combi_1.seq)("TYPE", (0, combi_1.altPrio)(tabseq, (0, combi_1.ver)(version_1.Release.v916, (0, combi_1.seq)("ANY", "STRUCTURE")), inline, ret)), like);
15
20
  }
16
21
  }
17
22
  exports.FormParamType = FormParamType;
@@ -52,6 +52,7 @@ const expressions_1 = require("../2_statements/expressions");
52
52
  const _builtin_1 = require("./_builtin");
53
53
  const position_1 = require("../../position");
54
54
  const _syntax_input_1 = require("./_syntax_input");
55
+ const version_1 = require("../../version");
55
56
  class BasicTypes {
56
57
  constructor(input) {
57
58
  this.input = input;
@@ -277,7 +278,14 @@ class BasicTypes {
277
278
  }
278
279
  const chainText = typeName.concatTokens().toUpperCase();
279
280
  const f = this.input.scope.getDDIC().lookupBuiltinType(chainText, length, decimals, qualifiedName);
280
- if (f !== undefined) {
281
+ if (f instanceof Types.Integer8Type
282
+ && !(0, version_1.releaseAtLeast)(this.input.scope.getRelease(), version_1.Release.v750)
283
+ && !this.input.scope.getOpenABAP()) {
284
+ const message = "Type INT8 requires 7.50";
285
+ this.input.issues.push((0, _syntax_input_1.syntaxIssue)(this.input, typeName.getFirstToken(), message));
286
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
287
+ }
288
+ else if (f !== undefined) {
281
289
  return f;
282
290
  }
283
291
  const typ = this.input.scope.findType(chainText);
@@ -96,6 +96,10 @@ class InsertInternal {
96
96
  if (sourceType instanceof basic_1.IntegerType && targetType instanceof basic_1.Integer8Type) {
97
97
  error = true;
98
98
  }
99
+ else if (targetType instanceof basic_1.TableType && targetType.isWithHeader() && sourceType instanceof basic_1.TableType) {
100
+ // LINES OF into a table with header line, compare the row types
101
+ error = new _type_utils_1.TypeUtils(input.scope).isAssignable(sourceType.getRowType(), targetType.getRowType()) === false;
102
+ }
99
103
  else if (new _type_utils_1.TypeUtils(input.scope).isAssignable(sourceType, targetType) === false) {
100
104
  error = true;
101
105
  }
@@ -33,8 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ABAPObject = exports.Tokens = exports.ExpressionsCDS = exports.CDSParser = exports.LanguageServerTypes = exports.DDLKind = exports.DDLParser = exports.AbstractFile = exports.ABAPFile = exports.MemoryFile = exports.Edits = exports.ReferenceType = exports.NativeSQL = exports.MacroContent = exports.MacroCall = exports.SpaghettiScopeNode = exports.Token = exports.ScopeType = exports.BasicTypes = exports.TypedIdentifier = exports.AbstractType = exports.VirtualPosition = exports.Comment = exports.Unknown = exports.Empty = exports.Identifier = exports.Nodes = exports.Types = exports.Expressions = exports.Statements = exports.Structures = exports.SkipLogic = exports.Objects = exports.ArtifactsRules = exports.ArtifactsObjects = exports.ArtifactsABAP = exports.BuiltIn = exports.FormLengthStats = exports.FunctionLengthStats = exports.MethodLengthStats = exports.LanguageServer = exports.Registry = exports.CyclomaticComplexityStats = exports.versionToABAPRelease = exports.releaseAtLeast = exports.Release = exports.LanguageVersion = exports.Version = exports.Config = exports.Issue = void 0;
37
- exports.LSPEdit = exports.RuleTag = exports.Severity = exports.Visibility = exports.Info = exports.Diagnostics = exports.Rename = exports.PrettyPrinter = exports.Position = exports.CurrentScope = exports.RulesRunner = exports.SpaghettiScope = exports.SyntaxLogic = void 0;
36
+ exports.Tokens = exports.ABAPParser = exports.ExpressionsCDS = exports.CDSParser = exports.LanguageServerTypes = exports.DDLKind = exports.DDLParser = exports.AbstractFile = exports.ABAPFile = exports.MemoryFile = exports.Edits = exports.ReferenceType = exports.NativeSQL = exports.MacroContent = exports.MacroCall = exports.SpaghettiScopeNode = exports.Token = exports.ScopeType = exports.BasicTypes = exports.TypedIdentifier = exports.AbstractType = exports.VirtualPosition = exports.Comment = exports.Unknown = exports.Empty = exports.Identifier = exports.Nodes = exports.Types = exports.Expressions = exports.Statements = exports.Structures = exports.SkipLogic = exports.Objects = exports.ArtifactsRules = exports.ArtifactsObjects = exports.ArtifactsABAP = exports.BuiltIn = exports.FormLengthStats = exports.FunctionLengthStats = exports.MethodLengthStats = exports.LanguageServer = exports.Registry = exports.CyclomaticComplexityStats = exports.versionToABAPRelease = exports.releaseAtLeast = exports.Release = exports.LanguageVersion = exports.Version = exports.Config = exports.Issue = void 0;
37
+ exports.LSPEdit = exports.RuleTag = exports.Severity = exports.Visibility = exports.Info = exports.Diagnostics = exports.Rename = exports.PrettyPrinter = exports.Position = exports.CurrentScope = exports.RulesRunner = exports.SpaghettiScope = exports.SyntaxLogic = exports.ABAPObject = void 0;
38
38
  const issue_1 = require("./issue");
39
39
  Object.defineProperty(exports, "Issue", { enumerable: true, get: function () { return issue_1.Issue; } });
40
40
  const config_1 = require("./config");
@@ -131,6 +131,8 @@ Object.defineProperty(exports, "DDLParser", { enumerable: true, get: function ()
131
131
  Object.defineProperty(exports, "DDLKind", { enumerable: true, get: function () { return ddl_parser_1.DDLKind; } });
132
132
  const cds_parser_1 = require("./cds/cds_parser");
133
133
  Object.defineProperty(exports, "CDSParser", { enumerable: true, get: function () { return cds_parser_1.CDSParser; } });
134
+ const abap_parser_1 = require("./abap/abap_parser");
135
+ Object.defineProperty(exports, "ABAPParser", { enumerable: true, get: function () { return abap_parser_1.ABAPParser; } });
134
136
  const rules_runner_1 = require("./rules_runner");
135
137
  Object.defineProperty(exports, "RulesRunner", { enumerable: true, get: function () { return rules_runner_1.RulesRunner; } });
136
138
  const _irule_1 = require("./rules/_irule");
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.120.86";
78
+ return "2.120.88";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
@@ -45,6 +45,7 @@ const Expressions = __importStar(require("../abap/2_statements/expressions"));
45
45
  const Statements = __importStar(require("../abap/2_statements/statements"));
46
46
  const Structures = __importStar(require("../abap/3_structures/structures"));
47
47
  const edit_helper_1 = require("../edit_helper");
48
+ const tokens_1 = require("../abap/1_lexer/tokens");
48
49
  class AlignTypeExpressionsConf extends _basic_rule_config_1.BasicRuleConfig {
49
50
  constructor() {
50
51
  super(...arguments);
@@ -212,12 +213,18 @@ ENDINTERFACE.`,
212
213
  let column = 0;
213
214
  const st = t.findDirectStatements(Statements.Type);
214
215
  for (const s of st) {
215
- const name = s.getChildren()[1];
216
+ const children = s.getChildren();
217
+ const length = s.findDirectExpression(Expressions.ConstantFieldLength);
218
+ const nameEnd = (length !== null && length !== void 0 ? length : children[1]).getLastToken().getEnd();
219
+ const after = children[length ? 3 : 2];
220
+ if (after === undefined || after.getFirstToken() instanceof tokens_1.Punctuation) {
221
+ continue; // no TYPE clause, eg. "foo(1)," with implicit type
222
+ }
216
223
  fields.push({
217
- nameEnd: name.getLastToken().getEnd(),
218
- after: s.getChildren()[2].getFirstToken().getStart()
224
+ nameEnd: nameEnd,
225
+ after: after.getFirstToken().getStart()
219
226
  });
220
- column = Math.max(column, name.getFirstToken().getEnd().getCol() + 1);
227
+ column = Math.max(column, nameEnd.getCol() + 1);
221
228
  }
222
229
  issues.push(...this.check(fields, column, file));
223
230
  }
@@ -331,6 +331,29 @@ Make sure to test the downported code, it might not always be completely correct
331
331
  }
332
332
  }
333
333
  }
334
+ // a chained call with EXPORTING/IMPORTING/CHANGING/RECEIVING/EXCEPTIONS parses in the low
335
+ // version, but 702 reads the last call of a chain as a functional call,
336
+ // "Unexpected word CHANGING in functional method call"
337
+ if (ret.length === 0) {
338
+ for (let i = 0; i < lowStatements.length; i++) {
339
+ const issue = this.outlineChainedCallParameters(lowStatements[i], highStatements[i], lowFile, highSyntax);
340
+ if (issue) {
341
+ ret.push(issue);
342
+ break;
343
+ }
344
+ }
345
+ }
346
+ // INSERT with a 702 built-in function as the operand parses in the low version, but 702
347
+ // reads the function as a method call, "Method SUBSTRING does not exist"
348
+ if (ret.length === 0) {
349
+ for (let i = 0; i < lowStatements.length; i++) {
350
+ const issue = this.outlineInsertBuiltin(lowStatements[i], highStatements[i], lowFile, highSyntax);
351
+ if (issue) {
352
+ ret.push(issue);
353
+ break;
354
+ }
355
+ }
356
+ }
334
357
  // INTO after WHERE parses as a valid SELECT in the low version, but is only allowed in
335
358
  // strict SQL syntax, so move it also when the statement is no longer Unknown
336
359
  if (ret.length === 0) {
@@ -1163,6 +1186,40 @@ ${indentation}`);
1163
1186
  }
1164
1187
  return undefined;
1165
1188
  }
1189
+ /** INSERT substring( ... ) INTO TABLE tab, the operand is outlined into a variable */
1190
+ outlineInsertBuiltin(low, high, lowFile, highSyntax) {
1191
+ var _a;
1192
+ if (!(high.get() instanceof Statements.InsertInternal)) {
1193
+ return undefined;
1194
+ }
1195
+ else if (this.lowReg.getConfig().isOpenABAP()) {
1196
+ return undefined;
1197
+ }
1198
+ else if (low.getFirstToken().getStart() instanceof virtual_position_1.VirtualPosition) {
1199
+ return undefined;
1200
+ }
1201
+ // the whole operand is the call, a longer expression is outlined by replaceInsertExpression
1202
+ const source = high.getChildren()[1];
1203
+ if (!(source instanceof nodes_1.ExpressionNode)
1204
+ || !(source.get() instanceof Expressions.SimpleSource4 || source.get() instanceof Expressions.Source)
1205
+ || source.getChildren().length !== 1
1206
+ || !(((_a = source.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.MethodCallChain)) {
1207
+ return undefined;
1208
+ }
1209
+ const type = this.builtinReturnType(source, lowFile, highSyntax);
1210
+ if (type === undefined) {
1211
+ return undefined;
1212
+ }
1213
+ const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
1214
+ const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
1215
+ const code = `DATA ${uniqueName} TYPE ${type}.\n` +
1216
+ indentation + `${uniqueName} = ${source.concatTokens()}.\n` +
1217
+ indentation;
1218
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getFirstToken().getStart(), code);
1219
+ const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, source.getFirstToken().getStart(), source.getLastToken().getEnd(), uniqueName);
1220
+ const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
1221
+ return issue_1.Issue.atToken(lowFile, source.getFirstToken(), "Outline built-in function in INSERT", this.getMetadata().key, this.conf.severity, fix);
1222
+ }
1166
1223
  /** the ABAP type returned by the built-in function this Source starts with, or undefined
1167
1224
  * if it does not start with one, or with one that predates 702 */
1168
1225
  builtinReturnType(source, lowFile, highSyntax) {
@@ -2867,6 +2924,67 @@ ${indentation} output = ${uniqueName}.\n`;
2867
2924
  }
2868
2925
  return undefined;
2869
2926
  }
2927
+ /** a( )->b( CHANGING c = d ), the object the last method is called on is outlined into a
2928
+ * variable typed via the RETURNING parameter of the method before it */
2929
+ outlineChainedCallParameters(low, high, lowFile, highSyntax) {
2930
+ var _a, _b, _c, _d;
2931
+ if (!(high.get() instanceof Statements.Call)) {
2932
+ return undefined;
2933
+ }
2934
+ else if (this.lowReg.getConfig().isOpenABAP()) {
2935
+ return undefined;
2936
+ }
2937
+ else if (low.getFirstToken().getStart() instanceof virtual_position_1.VirtualPosition) {
2938
+ return undefined;
2939
+ }
2940
+ const chain = high.findDirectExpression(Expressions.MethodCallChain);
2941
+ const children = (chain === null || chain === void 0 ? void 0 : chain.getChildren()) || [];
2942
+ const last = children[children.length - 1];
2943
+ const arrow = children[children.length - 2];
2944
+ const previous = children[children.length - 3];
2945
+ if (chain === undefined
2946
+ || !(last instanceof nodes_1.ExpressionNode)
2947
+ || !(last.get() instanceof Expressions.MethodCall)
2948
+ || (arrow === null || arrow === void 0 ? void 0 : arrow.getFirstToken().getStr()) !== "->"
2949
+ || !(previous instanceof nodes_1.ExpressionNode)
2950
+ || !(previous.get() instanceof Expressions.MethodCall)) {
2951
+ return undefined;
2952
+ }
2953
+ const parameters = (_a = last.findDirectExpression(Expressions.MethodCallParam)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.MethodParameters);
2954
+ if (parameters === undefined) {
2955
+ return undefined;
2956
+ }
2957
+ // the type of the object, from the method that returns it
2958
+ const methodToken = (_b = previous.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
2959
+ if (methodToken === undefined) {
2960
+ return undefined;
2961
+ }
2962
+ const spag = highSyntax.spaghetti.lookupPosition(methodToken.getStart(), lowFile.getFilename());
2963
+ let type = undefined;
2964
+ for (const r of (spag === null || spag === void 0 ? void 0 : spag.getData().references) || []) {
2965
+ if (r.referenceType === _reference_1.ReferenceType.MethodReference
2966
+ && r.position.getStart().equals(methodToken.getStart())) {
2967
+ const returning = (_d = (_c = r.resolved) === null || _c === void 0 ? void 0 : _c.getParameters().getReturning()) === null || _d === void 0 ? void 0 : _d.getType();
2968
+ if (returning instanceof basic_1.ObjectReferenceType) {
2969
+ type = returning.toABAP();
2970
+ }
2971
+ break;
2972
+ }
2973
+ }
2974
+ if (type === undefined) {
2975
+ return undefined;
2976
+ }
2977
+ const object = children.slice(0, children.length - 2).map(c => c.concatTokens()).join("");
2978
+ const uniqueName = this.uniqueName(high.getFirstToken().getStart(), lowFile.getFilename(), highSyntax);
2979
+ const indentation = " ".repeat(high.getFirstToken().getStart().getCol() - 1);
2980
+ const code = `DATA ${uniqueName} TYPE ${type}.\n` +
2981
+ indentation + `${uniqueName} = ${object}.\n` +
2982
+ indentation;
2983
+ const fix1 = edit_helper_1.EditHelper.insertAt(lowFile, high.getFirstToken().getStart(), code);
2984
+ const fix2 = edit_helper_1.EditHelper.replaceRange(lowFile, chain.getFirstToken().getStart(), previous.getLastToken().getEnd(), uniqueName);
2985
+ const fix = edit_helper_1.EditHelper.merge(fix2, fix1);
2986
+ return issue_1.Issue.atToken(lowFile, chain.getFirstToken(), "Outline object of chained call with parameter keywords", this.getMetadata().key, this.conf.severity, fix);
2987
+ }
2870
2988
  /** if the source expression is the complete source of an INSERT or APPEND statement, then the
2871
2989
  * outlined variable must be typed via the row type of the table, returns the table name */
2872
2990
  findRowTypeOf(high, source) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.86",
3
+ "version": "2.120.88",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",