@abaplint/core 2.120.82 → 2.120.83

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.
@@ -361,7 +361,7 @@ class SyntaxLogic {
361
361
  this.reg.getMSAGReferences().clear(this.object);
362
362
  if (this.object instanceof objects_1.Program && this.object.isInclude()) {
363
363
  // todo, show some kind of error?
364
- return { issues: [], spaghetti: this.scope.pop(new position_1.Position(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)) };
364
+ return { issues: [], spaghetti: this.scope.pop(new position_1.Position(position_1.MAX_POSITION_VALUE, position_1.MAX_POSITION_VALUE)) };
365
365
  }
366
366
  this.traverseObject();
367
367
  // the FORM definitions are now all traversed, ie. their parameters are typed
@@ -370,7 +370,7 @@ class SyntaxLogic {
370
370
  }
371
371
  this.deferred = [];
372
372
  for (;;) {
373
- const spaghetti = this.scope.pop(new position_1.Position(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)); // pop built-in scopes
373
+ const spaghetti = this.scope.pop(new position_1.Position(position_1.MAX_POSITION_VALUE, position_1.MAX_POSITION_VALUE)); // pop built-in scopes
374
374
  if (spaghetti.getTop().getIdentifier().stype === _scope_type_1.ScopeType.BuiltIn) {
375
375
  const result = { issues: this.issues, spaghetti };
376
376
  this.object.syntaxResult = result;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DumpScope = void 0;
4
+ const position_1 = require("../position");
4
5
  const _scope_type_1 = require("../abap/5_syntax/_scope_type");
5
6
  class DumpScope {
6
7
  static dump(spaghetti) {
@@ -14,8 +15,8 @@ class DumpScope {
14
15
  const sident = "&nbsp".repeat(indent * 2);
15
16
  let ret = sident + "<u>" + identifier.stype + ", <tt>" + identifier.sname + "</tt>";
16
17
  ret += ", (" + coverage.start.getRow() + ", " + coverage.start.getCol() + ")";
17
- if (coverage.end.getRow() === Number.MAX_SAFE_INTEGER
18
- && coverage.end.getCol() === Number.MAX_SAFE_INTEGER) {
18
+ if (coverage.end.getRow() === position_1.MAX_POSITION_VALUE
19
+ && coverage.end.getCol() === position_1.MAX_POSITION_VALUE) {
19
20
  ret += ", (max, max)";
20
21
  }
21
22
  else {
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Position = void 0;
3
+ exports.Position = exports.MAX_POSITION_VALUE = void 0;
4
+ // largest value that is a Smi on all V8 builds, larger values (eg. Number.MAX_SAFE_INTEGER) make V8
5
+ // store row/col of every Position as boxed heap numbers, costing ~32 bytes per Position
6
+ exports.MAX_POSITION_VALUE = 2 ** 30 - 1;
4
7
  // first position is (1,1)
5
8
  class Position {
6
9
  constructor(row, col) {
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.120.82";
78
+ return "2.120.83";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
@@ -33,14 +33,18 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.SourceKind = exports.PredicateKind = exports.Procedure = exports.ObjectAnalysis = exports.Variable = exports.OccurrenceKind = void 0;
36
+ exports.Hierarchy = exports.NUMERIC_FUNCTIONS = exports.SourceKind = exports.PredicateKind = exports.InitialDeclaration = exports.Procedure = exports.ObjectAnalysis = exports.Variable = exports.OccurrenceKind = void 0;
37
37
  exports.findStructures = findStructures;
38
38
  exports.expressionPath = expressionPath;
39
39
  exports.plainMove = plainMove;
40
+ exports.plainCreateObject = plainCreateObject;
40
41
  exports.singleField = singleField;
41
42
  exports.singleTarget = singleTarget;
42
43
  exports.plainClear = plainClear;
43
44
  exports.plainData = plainData;
45
+ exports.initialValue = initialValue;
46
+ exports.initialDeclaration = initialDeclaration;
47
+ exports.initialAtFirstReference = initialAtFirstReference;
44
48
  exports.isImmutable = isImmutable;
45
49
  exports.isReferenceType = isReferenceType;
46
50
  exports.identicalTypes = identicalTypes;
@@ -51,6 +55,10 @@ exports.isCondition = isCondition;
51
55
  exports.dataSource = dataSource;
52
56
  exports.targetType = targetType;
53
57
  exports.unchangedBetween = unchangedBetween;
58
+ exports.formalParameter = formalParameter;
59
+ exports.passedByValue = passedByValue;
60
+ exports.literalType = literalType;
61
+ exports.expressionType = expressionType;
54
62
  exports.mergeEdits = mergeEdits;
55
63
  exports.deleteRegion = deleteRegion;
56
64
  exports.deleteStatement = deleteStatement;
@@ -70,6 +78,10 @@ const syntax_1 = require("../abap/5_syntax/syntax");
70
78
  const nodes_1 = require("../abap/nodes");
71
79
  const _typed_identifier_1 = require("../abap/types/_typed_identifier");
72
80
  const basic_1 = require("../abap/types/basic");
81
+ const class_definition_1 = require("../abap/types/class_definition");
82
+ const interface_definition_1 = require("../abap/types/interface_definition");
83
+ const class_1 = require("../objects/class");
84
+ const interface_1 = require("../objects/interface");
73
85
  const _abap_object_1 = require("../objects/_abap_object");
74
86
  const edit_helper_1 = require("../edit_helper");
75
87
  const position_1 = require("../position");
@@ -342,6 +354,23 @@ class Procedure {
342
354
  }
343
355
  return between;
344
356
  }
357
+ /** the next statement executed after a direct statement of a block, skipping declarations, which have no effect
358
+ * where they are written; undefined if there is none in the block */
359
+ nextExecuted(statement) {
360
+ const block = this.block(statement);
361
+ for (let index = this.index(statement) + 1; index < this.statements.length; index++) {
362
+ const next = this.statements[index];
363
+ const type = next.get();
364
+ if (this.block(next) !== block) {
365
+ return undefined;
366
+ }
367
+ else if (!(this.isSimple(next) && (type instanceof Statements.Data || type instanceof Statements.Type
368
+ || type instanceof Statements.Constant || type instanceof Statements.FieldSymbol || type instanceof _statement_1.Comment))) {
369
+ return next;
370
+ }
371
+ }
372
+ return undefined;
373
+ }
345
374
  /** a comment line or end of line comment between the two positions */
346
375
  hasComment(start, end) {
347
376
  if (this.comments === undefined) {
@@ -352,6 +381,18 @@ class Procedure {
352
381
  }
353
382
  return this.comments.some(c => !c.isBefore(start) && c.isBefore(end));
354
383
  }
384
+ /** a structure of one of the types contains the statement */
385
+ enclosedBy(statement, types) {
386
+ let parent = this.parents.get(statement);
387
+ while (parent !== undefined && parent !== this.structure) {
388
+ const type = parent.get();
389
+ if (types.some(t => type instanceof t)) {
390
+ return true;
391
+ }
392
+ parent = this.parents.get(parent);
393
+ }
394
+ return false;
395
+ }
355
396
  /** the IF structure of an IF or ELSEIF statement */
356
397
  ifStructure(statement) {
357
398
  let parent = this.parents.get(statement);
@@ -424,6 +465,23 @@ class Procedure {
424
465
  }
425
466
  return variable;
426
467
  }
468
+ /** memory that only this procedure can reach: a local variable, or a pass-by-value or RETURNING parameter of
469
+ * a method or form, with all references understood and its address never taken */
470
+ private(identifier) {
471
+ const variable = this.variable(identifier);
472
+ if (variable === undefined || variable.complete === false || variable.escapes()
473
+ || variable.identifier.getMeta().includes("static" /* IdentifierMeta.Static */)) {
474
+ return undefined;
475
+ }
476
+ const meta = variable.identifier.getMeta();
477
+ if (variable.isLocal()) {
478
+ return variable;
479
+ }
480
+ // function module parameters can be global parameters of the function group
481
+ const parameter = !(this.structure.get() instanceof Structures.FunctionModule)
482
+ && (meta.includes("pass_by_value" /* IdentifierMeta.PassByValue */) || meta.includes("returning" /* IdentifierMeta.MethodReturning */));
483
+ return parameter ? variable : undefined;
484
+ }
427
485
  /** all local variables declared in the procedure */
428
486
  locals() {
429
487
  var _a;
@@ -515,6 +573,17 @@ class Procedure {
515
573
  }
516
574
  return statement.findFirstExpression(Expressions.NewObject) === undefined;
517
575
  }
576
+ /** the method or builtin function called at the method name token */
577
+ methodAt(token) {
578
+ for (const reference of this.analysis.referencesAt(this.file.getFilename(), token)) {
579
+ if ((reference.referenceType === _reference_1.ReferenceType.MethodReference
580
+ || reference.referenceType === _reference_1.ReferenceType.BuiltinMethodReference)
581
+ && reference.resolved !== undefined && "getParameters" in reference.resolved) {
582
+ return reference.resolved;
583
+ }
584
+ }
585
+ return undefined;
586
+ }
518
587
  /** every data write in the statement goes to a local variable, a pass-by-value parameter or the
519
588
  * RETURNING parameter, ie. memory that no other data object, field symbol or reference can share */
520
589
  writesOnlyPrivate(statement) {
@@ -685,6 +754,31 @@ function plainMove(statement) {
685
754
  }
686
755
  return { target, source, operator };
687
756
  }
757
+ /** CREATE OBJECT target [TYPE class] [EXPORTING parameters]. without chaining, pragmas, EXCEPTIONS or dynamic parts */
758
+ function plainCreateObject(statement) {
759
+ if (!(statement.get() instanceof Statements.CreateObject) || statement.getColon() !== undefined
760
+ || statement.getPragmas().length > 0) {
761
+ return undefined;
762
+ }
763
+ const children = statement.getChildren();
764
+ const target = children[2];
765
+ if (!(target instanceof nodes_1.ExpressionNode) || !(target.get() instanceof Expressions.Target)) {
766
+ return undefined;
767
+ }
768
+ let type;
769
+ // the last child is the period
770
+ for (let i = 3; i < children.length - 1; i += 2) {
771
+ const word = children[i] instanceof nodes_1.TokenNode ? children[i].getFirstToken().getStr().toUpperCase() : "";
772
+ const value = children[i + 1];
773
+ if (word === "TYPE" && value instanceof nodes_1.ExpressionNode && value.get() instanceof Expressions.ClassName) {
774
+ type = value;
775
+ }
776
+ else if (!(word === "EXPORTING" && (value === null || value === void 0 ? void 0 : value.get()) instanceof Expressions.ParameterListS)) {
777
+ return undefined;
778
+ }
779
+ }
780
+ return { target, type };
781
+ }
688
782
  /** the source is a single field, ie. one token */
689
783
  function singleField(source) {
690
784
  var _a;
@@ -719,6 +813,49 @@ function plainData(statement) {
719
813
  return statement.get() instanceof Statements.Data
720
814
  && ((_a = statement.findDirectExpression(Expressions.DataDefinition)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Value)) === undefined;
721
815
  }
816
+ /** VALUE type( ) with an explicit type and an empty body, ie. the initial value of the type */
817
+ function initialValue(source) {
818
+ const tokens = source.getTokens();
819
+ return tokens.length === 4 && tokens[0].getStr().toUpperCase() === "VALUE"
820
+ && source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined
821
+ && tokens[1].getStr() !== "#" && tokens[2].getStr() === "(" && tokens[3].getStr() === ")";
822
+ }
823
+ var InitialDeclaration;
824
+ (function (InitialDeclaration) {
825
+ /** DATA v TYPE ... without VALUE: v is initial when the procedure starts, the statement is not executed */
826
+ InitialDeclaration["Data"] = "data";
827
+ /** DATA(v) = VALUE t( ).: sets v to the initial value of t every time it is executed, also in each loop iteration */
828
+ InitialDeclaration["Value"] = "value";
829
+ })(InitialDeclaration || (exports.InitialDeclaration = InitialDeclaration = {}));
830
+ /** how the declaration of a local variable makes it initial, undefined if it does not */
831
+ function initialDeclaration(variable) {
832
+ const declaration = variable.declaration;
833
+ if (declaration === undefined) {
834
+ return undefined;
835
+ }
836
+ else if (variable.inline === false) {
837
+ return plainData(declaration) ? InitialDeclaration.Data : undefined;
838
+ }
839
+ const move = plainMove(declaration);
840
+ return move !== undefined && move.operator === "=" && move.target.getChildren().length === 1
841
+ && move.target.findDirectExpression(Expressions.InlineData) !== undefined && initialValue(move.source)
842
+ ? InitialDeclaration.Value : undefined;
843
+ }
844
+ /** the variable is initial at the statement, which is its first reference after the declaration */
845
+ function initialAtFirstReference(procedure, variable, statement) {
846
+ const declaration = variable.declaration;
847
+ const kind = initialDeclaration(variable);
848
+ // neither the declaration nor the statement in a loop: nothing can change the variable before the statement
849
+ const noLoop = procedure.loop(declaration) === undefined && procedure.loop(statement) === undefined;
850
+ if (kind === InitialDeclaration.Data) {
851
+ return noLoop;
852
+ }
853
+ else if (kind === InitialDeclaration.Value) {
854
+ // executed before the statement in the same iteration
855
+ return noLoop || (procedure.dominates(declaration, statement) && procedure.sameLoop(declaration, statement));
856
+ }
857
+ return false;
858
+ }
722
859
  /** constants of the class or program, builtin constants like abap_true, and me: never change */
723
860
  function isImmutable(identifier) {
724
861
  if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)) {
@@ -846,7 +983,7 @@ var SourceKind;
846
983
  (function (SourceKind) {
847
984
  /** constants and me, never change */
848
985
  SourceKind["Immutable"] = "immutable";
849
- /** a local variable, or a component of it, changes only by references to the variable */
986
+ /** a local variable or a pass-by-value parameter, or a component of it, changes only by references to the variable */
850
987
  SourceKind["Local"] = "local";
851
988
  /** attributes, parameters, globals, anything reached via a reference: may change by other code */
852
989
  SourceKind["Volatile"] = "volatile";
@@ -855,6 +992,7 @@ var SourceKind;
855
992
  * expressions, field symbols or dereferencing with ->* */
856
993
  function dataSource(procedure, source) {
857
994
  var _a;
995
+ var _b;
858
996
  if (source.getChildren().length !== 1) {
859
997
  return undefined;
860
998
  }
@@ -910,7 +1048,7 @@ function dataSource(procedure, source) {
910
1048
  if (type === undefined || type.isGeneric() || (type instanceof basic_1.TableType && type.isWithHeader())) {
911
1049
  return undefined;
912
1050
  }
913
- const local = next === 1 ? procedure.local(first) : undefined;
1051
+ const local = next === 1 ? (_b = procedure.local(first)) !== null && _b !== void 0 ? _b : procedure.private(first) : undefined;
914
1052
  let kind = SourceKind.Volatile;
915
1053
  if (deref === false && isImmutable(first)) {
916
1054
  kind = SourceKind.Immutable;
@@ -991,7 +1129,8 @@ function unchangedBetween(procedure, source, from, to, read) {
991
1129
  const statement = procedure.statements[index];
992
1130
  if (index === end && read !== undefined) {
993
1131
  if (isReceiver(statement, read)
994
- || (statement.get() instanceof Statements.Move && procedure.isCallFree(statement))) {
1132
+ || (statement.get() instanceof Statements.Move && procedure.isCallFree(statement))
1133
+ || passedByValue(procedure, statement, read)) {
995
1134
  continue;
996
1135
  }
997
1136
  }
@@ -1017,6 +1156,229 @@ function isReceiver(statement, token) {
1017
1156
  && receiver.countTokens() === 1 && receiver.getFirstToken().getStart().equals(token.getStart())
1018
1157
  && ((_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()[1]) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr()) === "->";
1019
1158
  }
1159
+ /** the token is the complete actual parameter for an importing parameter: m( v ), m( p = v ),
1160
+ * CALL METHOD m EXPORTING p = v, NEW c( p = v ) or CREATE OBJECT o EXPORTING p = v */
1161
+ function formalParameter(procedure, statement, token) {
1162
+ var _a, _b, _c;
1163
+ const path = expressionPath(statement, token);
1164
+ const index = path.findIndex(e => e.get() instanceof Expressions.Source && e.countTokens() === 1);
1165
+ const source = path[index];
1166
+ if (source === undefined || source.findDirectExpression(Expressions.FieldChain) === undefined
1167
+ || !source.getFirstToken().getStart().equals(token.getStart())) {
1168
+ return undefined;
1169
+ }
1170
+ const parent = index > 0 ? path[index - 1] : undefined;
1171
+ let name;
1172
+ let call;
1173
+ if ((parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Expressions.MethodCallParam) {
1174
+ call = path[index - 2];
1175
+ }
1176
+ else if ((parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Expressions.NewObject) {
1177
+ call = parent;
1178
+ }
1179
+ else if ((parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Expressions.ParameterS && ((_a = path[index - 2]) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.ParameterListS) {
1180
+ name = (_b = parent.findDirectExpression(Expressions.ParameterName)) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr();
1181
+ const list = path[index - 3];
1182
+ const above = path[index - 4];
1183
+ if (list === undefined && statement.get() instanceof Statements.CreateObject) {
1184
+ call = statement;
1185
+ }
1186
+ else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.MethodCallParam) {
1187
+ call = above;
1188
+ }
1189
+ else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.NewObject) {
1190
+ call = list;
1191
+ }
1192
+ else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.MethodParameters && (above === null || above === void 0 ? void 0 : above.get()) instanceof Expressions.MethodCallParam) {
1193
+ call = path[index - 5];
1194
+ }
1195
+ else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.MethodParameters && (above === null || above === void 0 ? void 0 : above.get()) instanceof Expressions.MethodCallBody
1196
+ && index === 4 && statement.get() instanceof Statements.Call) {
1197
+ call = statement;
1198
+ }
1199
+ }
1200
+ if (call === undefined) {
1201
+ return undefined;
1202
+ }
1203
+ let method;
1204
+ if (call instanceof nodes_1.ExpressionNode && call.get() instanceof Expressions.MethodCall) {
1205
+ const methodName = (_c = call.findDirectExpression(Expressions.MethodName)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
1206
+ method = methodName === undefined ? undefined : procedure.methodAt(methodName);
1207
+ }
1208
+ else if (call instanceof nodes_1.StatementNode && call.get() instanceof Statements.Call) {
1209
+ const methodSource = call.findDirectExpression(Expressions.MethodSource);
1210
+ method = methodSource === undefined ? undefined : procedure.methodAt(methodSource.getLastToken());
1211
+ }
1212
+ else if (!(call.get() instanceof Expressions.NewObject) && !(call.get() instanceof Statements.CreateObject)) {
1213
+ return undefined;
1214
+ }
1215
+ const parameters = method === null || method === void 0 ? void 0 : method.getParameters();
1216
+ const formal = name !== null && name !== void 0 ? name : parameters === null || parameters === void 0 ? void 0 : parameters.getDefaultImporting();
1217
+ const parameter = formal === undefined ? undefined
1218
+ : parameters === null || parameters === void 0 ? void 0 : parameters.getImporting().find(p => p.getName().toUpperCase() === formal.toUpperCase());
1219
+ return { call, method, parameter };
1220
+ }
1221
+ /** the token is the complete actual parameter for a pass-by-value importing parameter of the only call in the
1222
+ * statement, so the method gets a copy of the value when it is called, and nothing else runs before */
1223
+ function passedByValue(procedure, statement, token) {
1224
+ var _a, _b;
1225
+ if (!(statement.get() instanceof Statements.Call) && plainMove(statement) === undefined) {
1226
+ return false;
1227
+ }
1228
+ const formal = formalParameter(procedure, statement, token);
1229
+ if ((formal === null || formal === void 0 ? void 0 : formal.method) === undefined || ((_a = formal.parameter) === null || _a === void 0 ? void 0 : _a.getMeta().includes("pass_by_value" /* IdentifierMeta.PassByValue */)) !== true
1230
+ || statement.findFirstExpression(Expressions.NewObject) !== undefined) {
1231
+ return false;
1232
+ }
1233
+ for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
1234
+ const name = (_b = call.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
1235
+ const builtin = name === undefined ? false : procedure.analysis.referencesAt(procedure.file.getFilename(), name)
1236
+ .some(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
1237
+ if (call !== formal.call && builtin === false) {
1238
+ return false;
1239
+ }
1240
+ }
1241
+ return true;
1242
+ }
1243
+ /** builtin functions whose result type follows the type of the argument */
1244
+ exports.NUMERIC_FUNCTIONS = new Set(["abs", "sign", "ceil", "floor", "trunc", "frac", "ipow", "nmax", "nmin",
1245
+ "round", "rescale"]);
1246
+ /** type of a literal: 'abc' is c LENGTH 3, `abc` is string, 12 is i */
1247
+ function literalType(constant) {
1248
+ var _a;
1249
+ var _b;
1250
+ if (constant.countTokens() !== 1) {
1251
+ return undefined;
1252
+ }
1253
+ const text = constant.getFirstToken().getStr();
1254
+ if (constant.findDirectExpression(Expressions.Integer) !== undefined) {
1255
+ const value = Number(text);
1256
+ return Number.isInteger(value) && Math.abs(value) <= 2147483647 ? basic_1.IntegerType.get() : undefined;
1257
+ }
1258
+ else if (text.startsWith("'") && text.endsWith("'") && text.length >= 2) {
1259
+ return new basic_1.CharacterType(Math.max(1, text.length - 2 - ((_b = (_a = text.match(/''/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0)));
1260
+ }
1261
+ else if (text.startsWith("`") && text.endsWith("`")) {
1262
+ return basic_1.StringType.get();
1263
+ }
1264
+ return undefined;
1265
+ }
1266
+ /** Static type of an expression whose type does not depend on where it is used: literals, string templates,
1267
+ * concatenations, xsdbool( ), boolc( ), data objects, method calls and attributes after method calls.
1268
+ * Undefined if not known, e.g. for constructor expressions, arithmetic or builtin functions typed by their argument */
1269
+ function expressionType(procedure, source) {
1270
+ var _a, _b, _c;
1271
+ const children = source.getChildren();
1272
+ const first = children[0];
1273
+ const keyword = first instanceof nodes_1.TokenNode ? first.getFirstToken().getStr().toUpperCase() : "";
1274
+ if (children.length === 4 && keyword === "XSDBOOL" && source.findDirectExpression(Expressions.Cond) !== undefined) {
1275
+ return new basic_1.CharacterType(1);
1276
+ }
1277
+ else if (children.length === 4 && keyword === "BOOLC" && source.findDirectExpression(Expressions.Cond) !== undefined) {
1278
+ return basic_1.StringType.get();
1279
+ }
1280
+ else if (children.length === 3 && children[1] instanceof nodes_1.TokenNode && children[1].getFirstToken().getStr() === "&&") {
1281
+ return basic_1.StringType.get();
1282
+ }
1283
+ else if (!(first instanceof nodes_1.ExpressionNode)) {
1284
+ return undefined;
1285
+ }
1286
+ if (children.length === 1 && first.get() instanceof Expressions.Constant) {
1287
+ return literalType(first);
1288
+ }
1289
+ else if (children.length === 1 && first.get() instanceof Expressions.StringTemplate) {
1290
+ return basic_1.StringType.get();
1291
+ }
1292
+ else if (children.length === 1 && first.get() instanceof Expressions.FieldChain) {
1293
+ return (_a = dataSource(procedure, source)) === null || _a === void 0 ? void 0 : _a.type;
1294
+ }
1295
+ else if (!(first.get() instanceof Expressions.MethodCallChain)) {
1296
+ return undefined;
1297
+ }
1298
+ // the last call of the chain, optionally followed by ->attribute
1299
+ let type;
1300
+ const last = first.getChildren()[first.getChildren().length - 1];
1301
+ if (last instanceof nodes_1.ExpressionNode && last.get() instanceof Expressions.MethodCall) {
1302
+ const name = (_b = last.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
1303
+ const method = name === undefined ? undefined : procedure.methodAt(name);
1304
+ if (name === undefined || method === undefined || exports.NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
1305
+ return undefined;
1306
+ }
1307
+ type = (_c = method.getParameters().getReturning()) === null || _c === void 0 ? void 0 : _c.getType();
1308
+ }
1309
+ else {
1310
+ return undefined;
1311
+ }
1312
+ if (children.length === 1) {
1313
+ return type;
1314
+ }
1315
+ const attribute = children[2];
1316
+ if (children.length === 3 && children[1].get() instanceof Expressions.Arrow && attribute instanceof nodes_1.ExpressionNode
1317
+ && attribute.get() instanceof Expressions.AttributeChain && attribute.getChildren().length === 1) {
1318
+ const identifier = procedure.identifierAt(attribute.getFirstToken());
1319
+ return identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType() : undefined;
1320
+ }
1321
+ return undefined;
1322
+ }
1323
+ ////////////////////////////////////////
1324
+ // classes and interfaces
1325
+ /** classes and interfaces by name: local ones in the scope of the procedure, global ones in the registry */
1326
+ class Hierarchy {
1327
+ constructor(reg, procedure) {
1328
+ this.reg = reg;
1329
+ this.procedure = procedure;
1330
+ }
1331
+ find(name) {
1332
+ var _a;
1333
+ const scope = this.procedure.analysis.spaghetti.lookupPosition(this.procedure.getStart(), this.procedure.file.getFilename());
1334
+ const local = (_a = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name)) !== null && _a !== void 0 ? _a : scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(name);
1335
+ if (local !== undefined) {
1336
+ return local;
1337
+ }
1338
+ const clas = this.reg.getObject("CLAS", name);
1339
+ if (clas instanceof class_1.Class) {
1340
+ return clas.getDefinition();
1341
+ }
1342
+ const intf = this.reg.getObject("INTF", name);
1343
+ return intf instanceof interface_1.Interface ? intf.getDefinition() : undefined;
1344
+ }
1345
+ /** the class or interface definition of an object reference type, undefined if it is not known */
1346
+ definition(type) {
1347
+ if (!(type instanceof basic_1.ObjectReferenceType)) {
1348
+ return undefined;
1349
+ }
1350
+ const identifier = type.getIdentifier();
1351
+ const found = identifier instanceof class_definition_1.ClassDefinition || identifier instanceof interface_definition_1.InterfaceDefinition
1352
+ ? identifier : this.find(identifier.getName());
1353
+ return found instanceof class_definition_1.ClassDefinition || found instanceof interface_definition_1.InterfaceDefinition ? found : undefined;
1354
+ }
1355
+ /** sub is sup, or inherits from it or implements it; false if a definition on the way is not known */
1356
+ isSubtype(sub, sup) {
1357
+ const target = sup.toUpperCase();
1358
+ const visited = new Set();
1359
+ const stack = [sub.toUpperCase()];
1360
+ while (stack.length > 0) {
1361
+ const name = stack.pop();
1362
+ if (name === target) {
1363
+ return true;
1364
+ }
1365
+ else if (visited.has(name)) {
1366
+ continue;
1367
+ }
1368
+ visited.add(name);
1369
+ const definition = this.find(name);
1370
+ const superClass = definition === null || definition === void 0 ? void 0 : definition.getSuperClass();
1371
+ if (superClass !== undefined) {
1372
+ stack.push(superClass.toUpperCase());
1373
+ }
1374
+ for (const implementing of (definition === null || definition === void 0 ? void 0 : definition.getImplementing()) || []) {
1375
+ stack.push(implementing.name.toUpperCase());
1376
+ }
1377
+ }
1378
+ return false;
1379
+ }
1380
+ }
1381
+ exports.Hierarchy = Hierarchy;
1020
1382
  ////////////////////////////////////////
1021
1383
  // edits
1022
1384
  const rowCache = new WeakMap();
@@ -161,14 +161,7 @@ ENDIF.`,
161
161
  return false;
162
162
  }
163
163
  const constant = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
164
- return (constant !== undefined && (0, _procedure_analysis_1.sameCharacters)(constant, "")) || this.initialValue(move.source);
165
- }
166
- /** VALUE type( ) */
167
- initialValue(source) {
168
- const tokens = source.getTokens();
169
- return tokens.length === 4 && tokens[0].getStr().toUpperCase() === "VALUE"
170
- && source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined
171
- && tokens[1].getStr() !== "#" && tokens[2].getStr() === "(" && tokens[3].getStr() === ")";
164
+ return (constant !== undefined && (0, _procedure_analysis_1.sameCharacters)(constant, "")) || (0, _procedure_analysis_1.initialValue)(move.source);
172
165
  }
173
166
  }
174
167
  exports.BooleanFlagViaIf = BooleanFlagViaIf;