@abaplint/core 2.119.57 → 2.119.59

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.
@@ -618,6 +618,9 @@ export declare class BuiltIn {
618
618
  static readonly filename = "_builtin.prog.abap";
619
619
  private static counter;
620
620
  private static readonly getCache;
621
+ private static typesCache;
622
+ private static extrasCacheKey;
623
+ private static extrasCache;
621
624
  static readonly methods: {
622
625
  [name: string]: IBuiltinMethod;
623
626
  };
@@ -1248,6 +1251,7 @@ declare class ClassDefinition_3 extends Identifier implements IClassDefinition {
1248
1251
  getCreateVisibility(): Visibility;
1249
1252
  private findSuper;
1250
1253
  private checkMethodNameLength;
1254
+ private checkClassConstructorStatic;
1251
1255
  private checkMethodsFromSuperClasses;
1252
1256
  private findFriends;
1253
1257
  private addReference;
@@ -2427,9 +2431,11 @@ declare abstract class Expression implements IStatementRunnable {
2427
2431
 
2428
2432
  declare class ExpressionNode extends AbstractNode<ExpressionNode | TokenNode> {
2429
2433
  private readonly expression;
2434
+ private tokenCount;
2430
2435
  constructor(expression: IStatementRunnable);
2431
2436
  addChild(_n: ExpressionNode | TokenNode): void;
2432
2437
  get(): IStatementRunnable;
2438
+ setChildren(children: (ExpressionNode | TokenNode)[]): ExpressionNode;
2433
2439
  countTokens(): number;
2434
2440
  getFirstToken(): Token;
2435
2441
  concatTokensWithLinebreaks(): string;
@@ -46,6 +46,7 @@ const expand_macros_1 = require("./expand_macros");
46
46
  const tokens_1 = require("../1_lexer/tokens");
47
47
  const _select_reclassify_1 = require("./_select_reclassify");
48
48
  exports.STATEMENT_MAX_TOKENS = 20000;
49
+ const EMPTY_PRAGMAS = Object.freeze([]);
49
50
  class StatementMap {
50
51
  constructor() {
51
52
  this.map = {};
@@ -244,9 +245,19 @@ class StatementParser {
244
245
  return statement;
245
246
  }
246
247
  removePragma(tokens) {
248
+ let hasPragma = false;
249
+ // skip the last token as it is the punctuation
250
+ for (let i = 0; i < tokens.length - 1; i++) {
251
+ if (tokens[i] instanceof Tokens.Pragma) {
252
+ hasPragma = true;
253
+ break;
254
+ }
255
+ }
256
+ if (hasPragma === false) {
257
+ return { tokens: tokens.slice(0, tokens.length - 1), pragmas: EMPTY_PRAGMAS };
258
+ }
247
259
  const result = [];
248
260
  const pragmas = [];
249
- // skip the last token as it is the punctuation
250
261
  for (let i = 0; i < tokens.length - 1; i++) {
251
262
  const t = tokens[i];
252
263
  if (t instanceof Tokens.Pragma) {
@@ -129,16 +129,20 @@ class BuiltIn {
129
129
  return def.predicate;
130
130
  }
131
131
  getTypes() {
132
- const ret = this.buildSY();
133
- {
134
- const id = new tokens_1.Identifier(new position_1.Position(1, 1), "abap_bool");
135
- ret.push(new _typed_identifier_1.TypedIdentifier(id, BuiltIn.filename, new basic_1.CharacterType(1, { qualifiedName: "ABAP_BOOL", ddicName: "ABAP_BOOL" })));
132
+ // the identifiers are identical for every object, share them to reduce memory usage
133
+ if (BuiltIn.typesCache === undefined) {
134
+ const ret = this.buildSY();
135
+ {
136
+ const id = new tokens_1.Identifier(new position_1.Position(1, 1), "abap_bool");
137
+ ret.push(new _typed_identifier_1.TypedIdentifier(id, BuiltIn.filename, new basic_1.CharacterType(1, { qualifiedName: "ABAP_BOOL", ddicName: "ABAP_BOOL" })));
138
+ }
139
+ {
140
+ const id = new tokens_1.Identifier(new position_1.Position(1, 1), "cursor");
141
+ ret.push(new _typed_identifier_1.TypedIdentifier(id, BuiltIn.filename, basic_1.IntegerType.get({ qualifiedName: "CURSOR", ddicName: "CURSOR" })));
142
+ }
143
+ BuiltIn.typesCache = ret;
136
144
  }
137
- {
138
- const id = new tokens_1.Identifier(new position_1.Position(1, 1), "cursor");
139
- ret.push(new _typed_identifier_1.TypedIdentifier(id, BuiltIn.filename, basic_1.IntegerType.get({ qualifiedName: "CURSOR", ddicName: "CURSOR" })));
140
- }
141
- return ret;
145
+ return BuiltIn.typesCache;
142
146
  }
143
147
  get(extras) {
144
148
  const ret = [];
@@ -171,10 +175,17 @@ class BuiltIn {
171
175
  BuiltIn.getCache.push(this.buildConstant("space", new basic_1.CharacterType(1, { derivedFromConstant: true }), "' '"));
172
176
  }
173
177
  ret.push(...BuiltIn.getCache);
174
- for (const e of extras) {
175
- const id = new tokens_1.Identifier(new position_1.Position(this.row++, 1), e);
176
- ret.push(new _typed_identifier_1.TypedIdentifier(id, BuiltIn.filename, basic_1.VoidType.get(e), ["read_only" /* IdentifierMeta.ReadOnly */, "built-in" /* IdentifierMeta.BuiltIn */], "'?'"));
178
+ // the extras are identical for every object, share them to reduce memory usage
179
+ const key = extras.join("|");
180
+ if (key !== BuiltIn.extrasCacheKey) {
181
+ BuiltIn.extrasCacheKey = key;
182
+ BuiltIn.extrasCache = [];
183
+ for (const e of extras) {
184
+ const id = new tokens_1.Identifier(new position_1.Position(this.row++, 1), e);
185
+ BuiltIn.extrasCache.push(new _typed_identifier_1.TypedIdentifier(id, BuiltIn.filename, basic_1.VoidType.get(e), ["read_only" /* IdentifierMeta.ReadOnly */, "built-in" /* IdentifierMeta.BuiltIn */], "'?'"));
186
+ }
177
187
  }
188
+ ret.push(...BuiltIn.extrasCache);
178
189
  return ret;
179
190
  }
180
191
  /////////////////////////////
@@ -383,6 +394,9 @@ exports.BuiltIn = BuiltIn;
383
394
  BuiltIn.filename = "_builtin.prog.abap";
384
395
  BuiltIn.counter = 1;
385
396
  BuiltIn.getCache = [];
397
+ BuiltIn.typesCache = undefined;
398
+ BuiltIn.extrasCacheKey = undefined;
399
+ BuiltIn.extrasCache = [];
386
400
  // todo: "pcre" vs "regex", only one of these parameters are allowed
387
401
  // todo: "pcre", only possible from 755
388
402
  BuiltIn.methods = {
@@ -1,15 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractNode = void 0;
4
+ // shared constant, so nodes without children don't waste memory on empty arrays
5
+ const EMPTY = Object.freeze([]);
4
6
  class AbstractNode {
5
7
  constructor() {
6
- this.children = [];
8
+ this.children = EMPTY;
7
9
  }
8
10
  addChild(n) {
11
+ if (this.children === EMPTY) {
12
+ this.children = [];
13
+ }
9
14
  this.children.push(n);
10
15
  }
11
16
  setChildren(children) {
12
- this.children = children;
17
+ // copy, input arrays are built via push() and carry over-allocated backing stores
18
+ this.children = children.slice();
13
19
  }
14
20
  getChildren() {
15
21
  return this.children;
@@ -7,6 +7,7 @@ const _abstract_node_1 = require("./_abstract_node");
7
7
  class ExpressionNode extends _abstract_node_1.AbstractNode {
8
8
  constructor(expression) {
9
9
  super();
10
+ this.tokenCount = 0;
10
11
  this.expression = expression;
11
12
  }
12
13
  addChild(_n) {
@@ -15,12 +16,15 @@ class ExpressionNode extends _abstract_node_1.AbstractNode {
15
16
  get() {
16
17
  return this.expression;
17
18
  }
18
- countTokens() {
19
- let ret = 0;
20
- for (const c of this.getChildren()) {
21
- ret = ret + c.countTokens();
19
+ setChildren(children) {
20
+ super.setChildren(children);
21
+ for (const child of this.getChildren()) {
22
+ this.tokenCount = this.tokenCount + child.countTokens();
22
23
  }
23
- return ret;
24
+ return this;
25
+ }
26
+ countTokens() {
27
+ return this.tokenCount;
24
28
  }
25
29
  getFirstToken() {
26
30
  for (const child of this.getChildren()) {
@@ -11,17 +11,13 @@ const string_template_middle_1 = require("../1_lexer/tokens/string_template_midd
11
11
  const string_template_end_1 = require("../1_lexer/tokens/string_template_end");
12
12
  const string_template_begin_1 = require("../1_lexer/tokens/string_template_begin");
13
13
  const string_template_1 = require("../1_lexer/tokens/string_template");
14
+ const EMPTY_PRAGMAS = Object.freeze([]);
14
15
  class StatementNode extends _abstract_node_1.AbstractNode {
15
16
  constructor(statement, colon, pragmas) {
16
17
  super();
17
18
  this.statement = statement;
18
19
  this.colon = colon;
19
- if (pragmas) {
20
- this.pragmas = pragmas;
21
- }
22
- else {
23
- this.pragmas = [];
24
- }
20
+ this.pragmas = pragmas !== null && pragmas !== void 0 ? pragmas : EMPTY_PRAGMAS;
25
21
  }
26
22
  get() {
27
23
  return this.statement;
@@ -36,7 +32,7 @@ class StatementNode extends _abstract_node_1.AbstractNode {
36
32
  if (children.length === 0) {
37
33
  throw new Error("statement: zero children");
38
34
  }
39
- this.children = children;
35
+ super.setChildren(children);
40
36
  return this;
41
37
  }
42
38
  getStart() {
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TokenNode = void 0;
4
+ const EMPTY_CHILDREN = Object.freeze([]);
4
5
  class TokenNode {
5
6
  constructor(token) {
6
7
  this.token = token;
@@ -12,7 +13,7 @@ class TokenNode {
12
13
  throw new Error("TokenNode, Method not implemented.");
13
14
  }
14
15
  getChildren() {
15
- return [];
16
+ return EMPTY_CHILDREN;
16
17
  }
17
18
  concatTokens() {
18
19
  return this.token.getStr();
@@ -97,6 +97,7 @@ class ClassDefinition extends _identifier_1.Identifier {
97
97
  // perform checks after everything has been initialized
98
98
  this.checkMethodsFromSuperClasses(input);
99
99
  this.checkMethodNameLength(input);
100
+ this.checkClassConstructorStatic(input);
100
101
  }
101
102
  getFriends() {
102
103
  return this.friends;
@@ -160,6 +161,13 @@ class ClassDefinition extends _identifier_1.Identifier {
160
161
  }
161
162
  }
162
163
  }
164
+ checkClassConstructorStatic(input) {
165
+ for (const m of this.methodDefs.getAll()) {
166
+ if (m.getName().toUpperCase() === "CLASS_CONSTRUCTOR" && m.isStatic() === false) {
167
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, m.getToken(), "CLASS_CONSTRUCTOR must be static"));
168
+ }
169
+ }
170
+ }
163
171
  checkMethodsFromSuperClasses(input) {
164
172
  var _a;
165
173
  const scope = input.scope;
@@ -7,7 +7,7 @@ const cds_name_1 = require("./cds_name");
7
7
  class CDSDefineTableFunction extends combi_1.Expression {
8
8
  getRunnable() {
9
9
  const methodName = (0, combi_1.seq)(cds_name_1.CDSName, "=", ">", cds_name_1.CDSName);
10
- return (0, combi_1.seq)((0, combi_1.star)(_1.CDSAnnotation), (0, combi_1.str)("DEFINE TABLE FUNCTION"), cds_name_1.CDSName, (0, combi_1.optPrio)(_1.CDSWithParameters), (0, combi_1.str)("RETURNS {"), (0, combi_1.plus)((0, combi_1.seq)((0, combi_1.star)(_1.CDSAnnotation), (0, combi_1.optPrio)("KEY"), cds_name_1.CDSName, ":", _1.CDSType, ";")), (0, combi_1.str)("} IMPLEMENTED BY METHOD"), methodName, (0, combi_1.opt)(";"));
10
+ return (0, combi_1.seq)((0, combi_1.star)(_1.CDSAnnotation), (0, combi_1.str)("DEFINE TABLE FUNCTION"), cds_name_1.CDSName, (0, combi_1.optPrio)(_1.CDSWithParameters), (0, combi_1.str)("RETURNS {"), (0, combi_1.plus)((0, combi_1.seq)((0, combi_1.star)(_1.CDSAnnotation), (0, combi_1.optPrio)("KEY"), cds_name_1.CDSName, ":", _1.CDSType, (0, combi_1.star)(_1.CDSAnnotation), ";")), (0, combi_1.str)("} IMPLEMENTED BY METHOD"), methodName, (0, combi_1.opt)(";"));
11
11
  }
12
12
  }
13
13
  exports.CDSDefineTableFunction = CDSDefineTableFunction;
@@ -18,7 +18,7 @@ class CDSElement extends combi_1.Expression {
18
18
  const funcWithPath = (0, combi_1.seq)(_1.CDSFunction, (0, combi_1.plusPrio)(pathSegment));
19
19
  const body = (0, combi_1.altPrio)(extensionWildcard, includeElement, _1.CDSArithmetics, _1.CDSAggregate, _1.CDSString, _1.CDSArithParen, funcWithPath, _1.CDSFunction, cds_cast_1.CDSCast, _1.CDSCase, (0, combi_1.seq)("(", _1.CDSCase, ")"), (0, combi_1.seq)(_1.CDSPrefixedName, (0, combi_1.optPrio)(cds_as_1.CDSAs), (0, combi_1.optPrio)((0, combi_1.altPrio)(redirected, colonThing))), _1.CDSInteger);
20
20
  const elementBody = (0, combi_1.altPrio)(typedVirtual, (0, combi_1.seq)((0, combi_1.altPrio)("KEY", "VIRTUAL"), body), body);
21
- return (0, combi_1.seq)((0, combi_1.starPrio)(_1.CDSAnnotation), elementBody, (0, combi_1.optPrio)(cds_as_1.CDSAs));
21
+ return (0, combi_1.seq)((0, combi_1.starPrio)(_1.CDSAnnotation), elementBody, (0, combi_1.optPrio)(cds_as_1.CDSAs), (0, combi_1.starPrio)(_1.CDSAnnotation));
22
22
  }
23
23
  }
24
24
  exports.CDSElement = CDSElement;
@@ -5,7 +5,7 @@ const combi_1 = require("../../abap/2_statements/combi");
5
5
  class CDSName extends combi_1.Expression {
6
6
  getRunnable() {
7
7
  const pre = (0, combi_1.seq)("/", (0, combi_1.regex)(/^[\w_]+$/), "/");
8
- return (0, combi_1.seq)((0, combi_1.optPrio)(":"), (0, combi_1.optPrio)(pre), (0, combi_1.regex)(/^\$?#?[\w_]+$/));
8
+ return (0, combi_1.altPrio)((0, combi_1.regex)(/^"(?:[^"]|"")*"$/), (0, combi_1.seq)((0, combi_1.optPrio)(":"), (0, combi_1.optPrio)(pre), (0, combi_1.regex)(/^\$?#?[\w_]+$/)));
9
9
  }
10
10
  }
11
11
  exports.CDSName = CDSName;
@@ -4,7 +4,7 @@ exports.CDSString = void 0;
4
4
  const combi_1 = require("../../abap/2_statements/combi");
5
5
  class CDSString extends combi_1.Expression {
6
6
  getRunnable() {
7
- const reg = (0, combi_1.regex)(/^(?:'(?:[^'\\]|''|\\'|\\\\|\\(?!'))*'|"(?:[^"\\]|""|\\"|\\\\|\\(?!"))*")$/);
7
+ const reg = (0, combi_1.regex)(/^'(?:[^'\\]|''|\\'|\\\\|\\(?!'))*'$/);
8
8
  const abapTypeName = (0, combi_1.regex)(/^(?:int[1-9]|int8|sstring|sstr|char|numc|dats|datn|tims|timn|utcl|utclong|fltp|decfloat\d+|dec|string|rawstring|rstr|raw|xstring|clnt|lang|unit|cuky|curr|quan|geom_ewkb|d34n|d16n|d34d|d16d|d34s|d16s|d34r|d16r|d|t|p|n|c|x|f)$/i);
9
9
  const abap = (0, combi_1.seq)("abap", ".", abapTypeName, (0, combi_1.optPrio)((0, combi_1.seq)("(", (0, combi_1.regex)(/^\d+$/), ")")), reg);
10
10
  return (0, combi_1.altPrio)(abap, reg);
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.119.57";
78
+ return "2.119.59";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.119.57",
3
+ "version": "2.119.59",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",