@abaplint/core 2.120.105 → 2.120.107

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.
@@ -7869,6 +7869,7 @@ export declare class SyntaxLogic {
7869
7869
  private readonly reg;
7870
7870
  private scope;
7871
7871
  private loopTables;
7872
+ private currentMethod;
7872
7873
  private sortedLines;
7873
7874
  private helpers;
7874
7875
  constructor(reg: IRegistry, object: ABAPObject);
@@ -0,0 +1,220 @@
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.SuperConstructorCall = void 0;
37
+ const Expressions = __importStar(require("../2_statements/expressions"));
38
+ const Statements = __importStar(require("../2_statements/statements"));
39
+ const _statement_1 = require("../2_statements/statements/_statement");
40
+ const dash_1 = require("../1_lexer/tokens/dash");
41
+ const identifier_1 = require("../1_lexer/tokens/identifier");
42
+ const virtual_position_1 = require("../../virtual_position");
43
+ const _syntax_input_1 = require("./_syntax_input");
44
+ /** The constructor of a subclass must call SUPER->CONSTRUCTOR, and before the call instance
45
+ * attributes, instance methods and ME cannot be used. Runs when the method has been traversed,
46
+ * scopeNode is the outermost scope of the method, holding the references of its body. */
47
+ class SuperConstructorCall {
48
+ static check(method, scopeNode, input) {
49
+ var _a;
50
+ const methodStatement = method.findDirectStatement(Statements.MethodImplementation);
51
+ const methodName = (_a = methodStatement === null || methodStatement === void 0 ? void 0 : methodStatement.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
52
+ if (methodStatement === undefined || (methodName === null || methodName === void 0 ? void 0 : methodName.toUpperCase()) !== "CONSTRUCTOR") {
53
+ return;
54
+ }
55
+ const classDefinition = input.scope.findClassDefinition(input.scope.getName());
56
+ const superName = classDefinition === null || classDefinition === void 0 ? void 0 : classDefinition.getSuperClass();
57
+ if (classDefinition === undefined || superName === undefined || superName.toUpperCase() === "OBJECT") {
58
+ return;
59
+ }
60
+ const statements = method.findAllStatementNodes();
61
+ for (const s of statements) {
62
+ const type = s.get();
63
+ if (type instanceof _statement_1.Unknown || type instanceof _statement_1.MacroCall
64
+ || s.getFirstToken().getStart() instanceof virtual_position_1.VirtualPosition) {
65
+ return;
66
+ }
67
+ }
68
+ const callIndex = statements.findIndex(s => SuperConstructorCall.isSuperConstructorCall(s));
69
+ // at most one issue is reported per constructor
70
+ if (callIndex < 0) {
71
+ const message = "The constructor of a subclass must call SUPER->CONSTRUCTOR";
72
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, methodStatement.getFirstToken(), message));
73
+ return;
74
+ }
75
+ // the statements before the call, the call itself can pass instance attributes, eg. previous = previous,
76
+ // declarations can refer to instance attributes for typing, eg. DATA ls_row LIKE LINE OF mt_table
77
+ const before = statements.slice(1, callIndex)
78
+ .filter(s => !(s.get() instanceof _statement_1.NativeSQL) && !SuperConstructorCall.isDeclaration(s));
79
+ const offending = SuperConstructorCall.findInstanceAccess(before, classDefinition, scopeNode, input);
80
+ if (offending !== undefined) {
81
+ const message = "Instance attributes, instance methods and ME can only be accessed after SUPER->CONSTRUCTOR is called";
82
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, offending, message));
83
+ }
84
+ }
85
+ static isDeclaration(statement) {
86
+ const type = statement.get();
87
+ return type instanceof Statements.Data
88
+ || type instanceof Statements.DataBegin
89
+ || type instanceof Statements.DataEnd
90
+ || type instanceof Statements.Constant
91
+ || type instanceof Statements.ConstantBegin
92
+ || type instanceof Statements.ConstantEnd
93
+ || type instanceof Statements.Type
94
+ || type instanceof Statements.TypeBegin
95
+ || type instanceof Statements.TypeEnd
96
+ || type instanceof Statements.Static
97
+ || type instanceof Statements.StaticBegin
98
+ || type instanceof Statements.StaticEnd
99
+ || type instanceof Statements.IncludeType
100
+ || type instanceof Statements.FieldSymbol;
101
+ }
102
+ static isSuperConstructorCall(statement) {
103
+ const tokens = statement.getTokens();
104
+ for (let i = 0; i < tokens.length - 2; i++) {
105
+ if (tokens[i].getStr().toUpperCase() === "SUPER"
106
+ && tokens[i + 1].getStr() === "->"
107
+ && tokens[i + 2].getStr().toUpperCase() === "CONSTRUCTOR") {
108
+ return true;
109
+ }
110
+ }
111
+ return false;
112
+ }
113
+ /** returns the first offending token */
114
+ static findInstanceAccess(statements, classDefinition, scopeNode, input) {
115
+ const instance = SuperConstructorCall.listInstanceMembers(classDefinition, input);
116
+ const references = SuperConstructorCall.listReferences(scopeNode, input.filename);
117
+ for (const statement of statements) {
118
+ const tokens = statement.getTokens();
119
+ for (let i = 0; i < tokens.length; i++) {
120
+ const token = tokens[i];
121
+ if (SuperConstructorCall.isMe(tokens, i)) {
122
+ return token;
123
+ }
124
+ const resolved = references.get(SuperConstructorCall.key(token));
125
+ if (resolved !== undefined
126
+ && resolved.some(r => instance.has(r))
127
+ && SuperConstructorCall.isOwnAccess(tokens, i)) {
128
+ return token;
129
+ }
130
+ }
131
+ }
132
+ return undefined;
133
+ }
134
+ /** ME used as a value, me->component is allowed for constants and static components,
135
+ * instance components are found via the references */
136
+ static isMe(tokens, index) {
137
+ var _a;
138
+ const token = tokens[index];
139
+ if (!(token instanceof identifier_1.Identifier) || token.getStr().toUpperCase() !== "ME") {
140
+ return false;
141
+ }
142
+ const prev = tokens[index - 1];
143
+ if (prev !== undefined && (prev instanceof dash_1.Dash || ["->", "=>", "~"].includes(prev.getStr()))) {
144
+ return false;
145
+ }
146
+ return ((_a = tokens[index + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) !== "->";
147
+ }
148
+ /** the member is accessed via the implicit or explicit self reference, not via another object or class */
149
+ static isOwnAccess(tokens, index) {
150
+ var _a;
151
+ const prev = tokens[index - 1];
152
+ if (prev === undefined) {
153
+ return true;
154
+ }
155
+ else if (prev.getStr() === "->") {
156
+ return ((_a = tokens[index - 2]) === null || _a === void 0 ? void 0 : _a.getStr().toUpperCase()) === "ME";
157
+ }
158
+ return !(prev instanceof dash_1.Dash || ["=>", "~"].includes(prev.getStr()));
159
+ }
160
+ /** instance attributes and methods of the class, its super classes and implemented interfaces */
161
+ static listInstanceMembers(classDefinition, input) {
162
+ const ret = new Set();
163
+ const visited = new Set();
164
+ const stack = [classDefinition];
165
+ while (stack.length > 0) {
166
+ const current = stack.pop();
167
+ const name = current.getName().toUpperCase();
168
+ if (visited.has(name)) {
169
+ continue;
170
+ }
171
+ visited.add(name);
172
+ for (const a of current.getAttributes().getInstance()) {
173
+ ret.add(a);
174
+ }
175
+ for (const m of current.getMethodDefinitions().getAll()) {
176
+ if (m.isStatic() === false) {
177
+ ret.add(m);
178
+ }
179
+ }
180
+ for (const i of current.getImplementing()) {
181
+ const intf = input.scope.findInterfaceDefinition(i.name);
182
+ if (intf !== undefined) {
183
+ stack.push(intf);
184
+ }
185
+ }
186
+ if ("getSuperClass" in current) {
187
+ const sup = input.scope.findClassDefinition(current.getSuperClass());
188
+ if (sup !== undefined) {
189
+ stack.push(sup);
190
+ }
191
+ }
192
+ }
193
+ return ret;
194
+ }
195
+ /** resolved references of the method body by token position */
196
+ static listReferences(node, filename) {
197
+ var _a;
198
+ const ret = new Map();
199
+ const stack = node ? [node] : [];
200
+ while (stack.length > 0) {
201
+ const current = stack.pop();
202
+ stack.push(...current.getChildren());
203
+ for (const r of current.getData().references) {
204
+ if (r.resolved === undefined || r.position.getFilename() !== filename) {
205
+ continue;
206
+ }
207
+ const key = SuperConstructorCall.key(r.position.getToken());
208
+ const list = (_a = ret.get(key)) !== null && _a !== void 0 ? _a : [];
209
+ list.push(r.resolved);
210
+ ret.set(key, list);
211
+ }
212
+ }
213
+ return ret;
214
+ }
215
+ static key(token) {
216
+ return token.getRow() + ":" + token.getCol();
217
+ }
218
+ }
219
+ exports.SuperConstructorCall = SuperConstructorCall;
220
+ //# sourceMappingURL=_super_constructor_call.js.map
@@ -127,8 +127,8 @@ class ValueBody {
127
127
  }
128
128
  for (const s of foo.findDirectExpressions(Expressions.Source)) {
129
129
  const sourceType = source_1.Source.runSyntax(s, input, rowType);
130
- if (rowType instanceof basic_1.StringType && sourceType instanceof basic_1.CharacterType) {
131
- const message = "VALUE, source type CharacterType not compatible with StringType";
130
+ if ((rowType instanceof basic_1.StringType || rowType instanceof basic_1.XStringType) && sourceType instanceof basic_1.CharacterType) {
131
+ const message = "VALUE, source type CharacterType not compatible with " + rowType.constructor.name;
132
132
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message));
133
133
  }
134
134
  else if (this.insertsUsingTableKey(targetType)) {
@@ -48,6 +48,11 @@ class Append {
48
48
  let targetType = undefined;
49
49
  const target = node.findDirectExpression(Expressions.Target);
50
50
  if (target) {
51
+ if (target.findDirectExpression(Expressions.TableExpression) !== undefined) {
52
+ const message = "APPEND, table expression not allowed in target";
53
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, target.getFirstToken(), message));
54
+ return;
55
+ }
51
56
  targetType = target_1.Target.runSyntax(target, input);
52
57
  }
53
58
  // a hashed table has no index, APPEND adds at the end
@@ -48,7 +48,7 @@ const _raise_message_1 = require("../_raise_message");
48
48
  class Raise {
49
49
  runSyntax(node, input) {
50
50
  // todo
51
- var _a, _b, _c, _d, _e, _f;
51
+ var _a, _b, _c, _d, _e, _f, _g;
52
52
  const helper = new _object_oriented_1.ObjectOriented(input.scope);
53
53
  let method;
54
54
  const exceptionName = node.findDirectExpression(Expressions.ExceptionName);
@@ -64,7 +64,12 @@ class Raise {
64
64
  if (found === null || found === void 0 ? void 0 : found.id) {
65
65
  input.scope.addReference(classTok, found.id, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
66
66
  const def = input.scope.findObjectDefinition(className);
67
- method = (_b = helper.searchMethodName(def, "CONSTRUCTOR")) === null || _b === void 0 ? void 0 : _b.method;
67
+ if (((_b = input.scope.findClassDefinition(className)) === null || _b === void 0 ? void 0 : _b.isAbstract()) === true) {
68
+ const message = className + " is abstract, cannot be instantiated";
69
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, classTok, message));
70
+ return;
71
+ }
72
+ method = (_c = helper.searchMethodName(def, "CONSTRUCTOR")) === null || _c === void 0 ? void 0 : _c.method;
68
73
  }
69
74
  else if (input.scope.getDDIC().inErrorNamespace(className) === false) {
70
75
  const extra = { ooName: className, ooType: "Void" };
@@ -88,7 +93,7 @@ class Raise {
88
93
  }
89
94
  else if (type instanceof basic_1.ObjectReferenceType) {
90
95
  const def = input.scope.findObjectDefinition(type.getIdentifierName());
91
- method = (_c = helper.searchMethodName(def, "CONSTRUCTOR")) === null || _c === void 0 ? void 0 : _c.method;
96
+ method = (_d = helper.searchMethodName(def, "CONSTRUCTOR")) === null || _d === void 0 ? void 0 : _d.method;
92
97
  }
93
98
  else if (type !== undefined) {
94
99
  const message = "RAISE EXCEPTION, must be object reference, got " + type.constructor.name;
@@ -117,10 +122,10 @@ class Raise {
117
122
  for (const s of node.findDirectExpressions(Expressions.MessageSource)) {
118
123
  message_source_1.MessageSource.runSyntax(s, input);
119
124
  }
120
- const id = (_d = node.findExpressionAfterToken("ID")) === null || _d === void 0 ? void 0 : _d.concatTokens();
121
- let number = (_e = node.findDirectExpression(Expressions.MessageNumber)) === null || _e === void 0 ? void 0 : _e.concatTokens();
125
+ const id = (_e = node.findExpressionAfterToken("ID")) === null || _e === void 0 ? void 0 : _e.concatTokens();
126
+ let number = (_f = node.findDirectExpression(Expressions.MessageNumber)) === null || _f === void 0 ? void 0 : _f.concatTokens();
122
127
  if (number === undefined) {
123
- const num = (_f = node.findExpressionAfterToken("NUMBER")) === null || _f === void 0 ? void 0 : _f.concatTokens();
128
+ const num = (_g = node.findExpressionAfterToken("NUMBER")) === null || _g === void 0 ? void 0 : _g.concatTokens();
124
129
  if (num === null || num === void 0 ? void 0 : num.startsWith("'")) {
125
130
  number = num.substring(1, num.length - 1).toUpperCase();
126
131
  }
@@ -195,6 +195,7 @@ const field_group_1 = require("./statements/field_group");
195
195
  const stuff_1 = require("../../stuff");
196
196
  const _loop_table_change_1 = require("./_loop_table_change");
197
197
  const _sorted_key_write_1 = require("./_sorted_key_write");
198
+ const _super_constructor_call_1 = require("./_super_constructor_call");
198
199
  // -----------------------------------
199
200
  const map = {};
200
201
  function addToMap(handler) {
@@ -541,6 +542,9 @@ class SyntaxLogic {
541
542
  else if (stru instanceof Structures.Try) {
542
543
  try_1.Try.runSyntax(node, input);
543
544
  }
545
+ else if (stru instanceof Structures.Method) {
546
+ this.currentMethod = node;
547
+ }
544
548
  return false;
545
549
  }
546
550
  updateScopeStatement(node) {
@@ -588,12 +592,17 @@ class SyntaxLogic {
588
592
  this.scope.pop(node.getLastToken().getEnd());
589
593
  }
590
594
  else if (s instanceof Statements.EndMethod) {
595
+ let popped = undefined;
591
596
  if (this.scope.getType() === _scope_type_1.ScopeType.Method) {
592
- this.scope.pop(node.getLastToken().getEnd());
597
+ popped = this.scope.pop(node.getLastToken().getEnd());
593
598
  }
594
599
  if (this.scope.getType() === _scope_type_1.ScopeType.MethodInstance) {
595
- this.scope.pop(node.getLastToken().getEnd());
600
+ popped = this.scope.pop(node.getLastToken().getEnd());
601
+ }
602
+ if (this.currentMethod !== undefined && popped !== undefined) {
603
+ _super_constructor_call_1.SuperConstructorCall.check(this.currentMethod, popped.getTop(), input);
596
604
  }
605
+ this.currentMethod = undefined;
597
606
  }
598
607
  }
599
608
  updateSelectionEventScope(node) {
@@ -78,7 +78,7 @@ class Registry {
78
78
  }
79
79
  static abaplintVersion() {
80
80
  // magic, see build script "version.js"
81
- return "2.120.105";
81
+ return "2.120.107";
82
82
  }
83
83
  getDDICReferences() {
84
84
  return this.ddicReferences;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.105",
3
+ "version": "2.120.107",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",