@abaplint/core 2.85.20 → 2.85.21

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.
@@ -166,11 +166,7 @@ class CurrentScope {
166
166
  if (name === undefined) {
167
167
  return { found: false };
168
168
  }
169
- const def = (_a = this.current) === null || _a === void 0 ? void 0 : _a.findDeferred(name);
170
- if (def !== undefined) {
171
- return { found: true, id: def };
172
- }
173
- const findLocalClass = (_b = this.current) === null || _b === void 0 ? void 0 : _b.findClassDefinition(name);
169
+ const findLocalClass = (_a = this.current) === null || _a === void 0 ? void 0 : _a.findClassDefinition(name);
174
170
  if (findLocalClass) {
175
171
  return { found: true, id: findLocalClass, type: _reference_1.ReferenceType.ObjectOrientedReference, ooType: "CLAS" };
176
172
  }
@@ -178,7 +174,7 @@ class CurrentScope {
178
174
  if (globalClas) {
179
175
  return { found: true, id: globalClas.getIdentifier(), type: _reference_1.ReferenceType.ObjectOrientedReference, ooType: "CLAS" };
180
176
  }
181
- const findLocalInterface = (_c = this.current) === null || _c === void 0 ? void 0 : _c.findInterfaceDefinition(name);
177
+ const findLocalInterface = (_b = this.current) === null || _b === void 0 ? void 0 : _b.findInterfaceDefinition(name);
182
178
  if (findLocalInterface) {
183
179
  return { found: true, id: findLocalInterface, type: _reference_1.ReferenceType.ObjectOrientedReference, ooType: "INTF" };
184
180
  }
@@ -186,6 +182,10 @@ class CurrentScope {
186
182
  if (globalIntf) {
187
183
  return { found: true, id: globalIntf.getIdentifier(), type: _reference_1.ReferenceType.ObjectOrientedReference, ooType: "INTF" };
188
184
  }
185
+ const def = (_c = this.current) === null || _c === void 0 ? void 0 : _c.findDeferred(name);
186
+ if (def !== undefined) {
187
+ return { found: true, id: def };
188
+ }
189
189
  return { found: false };
190
190
  }
191
191
  ///////////////////////////
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TypeUtils = void 0;
4
+ const types_1 = require("../types");
4
5
  const basic_1 = require("../types/basic");
5
6
  class TypeUtils {
6
- static isCharLike(type) {
7
+ constructor(scope) {
8
+ this.scope = scope;
9
+ }
10
+ isCharLike(type) {
7
11
  if (type === undefined) {
8
12
  return false;
9
13
  }
@@ -40,7 +44,7 @@ class TypeUtils {
40
44
  }
41
45
  return false;
42
46
  }
43
- static isHexLike(type) {
47
+ isHexLike(type) {
44
48
  if (type === undefined) {
45
49
  return false;
46
50
  }
@@ -61,7 +65,96 @@ class TypeUtils {
61
65
  }
62
66
  return false;
63
67
  }
64
- static isAssignable(source, target) {
68
+ isOOAssignable(source, target) {
69
+ let sid = source.getIdentifier();
70
+ if (!(sid instanceof types_1.ClassDefinition || sid instanceof types_1.InterfaceDefinition)) {
71
+ const found = this.scope.findObjectDefinition(sid.getName());
72
+ if (found) {
73
+ sid = found;
74
+ }
75
+ else {
76
+ return false;
77
+ }
78
+ }
79
+ let tid = target.getIdentifier();
80
+ if (!(tid instanceof types_1.ClassDefinition || tid instanceof types_1.InterfaceDefinition)) {
81
+ const found = this.scope.findObjectDefinition(tid.getName());
82
+ if (found) {
83
+ tid = found;
84
+ }
85
+ else {
86
+ return false;
87
+ }
88
+ }
89
+ const tname = tid.getName().toUpperCase();
90
+ if (sid instanceof types_1.ClassDefinition && tid instanceof types_1.ClassDefinition) {
91
+ if (sid.getName().toUpperCase() === tname) {
92
+ return true;
93
+ }
94
+ const slist = this.listAllSupers(sid);
95
+ if (slist.indexOf(tname) >= 0) {
96
+ return true;
97
+ }
98
+ }
99
+ else if (sid instanceof types_1.ClassDefinition && tid instanceof types_1.InterfaceDefinition) {
100
+ if (sid.getImplementing().some(i => i.name === tname)) {
101
+ return true;
102
+ }
103
+ const slist = this.listAllInterfaces(sid);
104
+ if (slist.indexOf(tname) >= 0) {
105
+ return true;
106
+ }
107
+ }
108
+ else if (sid instanceof types_1.InterfaceDefinition && tid instanceof types_1.InterfaceDefinition) {
109
+ if (sid.getName().toUpperCase() === tname) {
110
+ return true;
111
+ }
112
+ if (sid.getImplementing().some(i => i.name === tname)) {
113
+ return true;
114
+ }
115
+ const slist = this.listAllInterfaces(sid);
116
+ if (slist.indexOf(tname) >= 0) {
117
+ return true;
118
+ }
119
+ }
120
+ return false;
121
+ }
122
+ listAllInterfaces(cdef) {
123
+ var _a;
124
+ const ret = new Set();
125
+ const stack = [];
126
+ // initialize
127
+ cdef.getImplementing().forEach(i => stack.push(i.name));
128
+ if (cdef instanceof types_1.ClassDefinition) {
129
+ const supers = this.listAllSupers(cdef);
130
+ for (const s of supers) {
131
+ (_a = this.scope.findClassDefinition(s)) === null || _a === void 0 ? void 0 : _a.getImplementing().forEach(i => stack.push(i.name));
132
+ }
133
+ }
134
+ // main loop
135
+ while (stack.length > 0) {
136
+ const intf = stack.pop().toUpperCase();
137
+ ret.add(intf);
138
+ const idef = this.scope.findInterfaceDefinition(intf);
139
+ idef === null || idef === void 0 ? void 0 : idef.getImplementing().forEach(i => stack.push(i.name));
140
+ }
141
+ return Array.from(ret.values());
142
+ }
143
+ listAllSupers(cdef) {
144
+ var _a, _b;
145
+ const ret = [];
146
+ let sup = cdef.getSuperClass();
147
+ while (sup !== undefined) {
148
+ ret.push(sup === null || sup === void 0 ? void 0 : sup.toUpperCase());
149
+ sup = (_b = (_a = this.scope.findClassDefinition(sup)) === null || _a === void 0 ? void 0 : _a.getSuperClass()) === null || _b === void 0 ? void 0 : _b.toUpperCase();
150
+ }
151
+ return ret;
152
+ }
153
+ isCastable(_source, _target) {
154
+ // todo
155
+ return true;
156
+ }
157
+ isAssignable(source, target) {
65
158
  /*
66
159
  console.dir(source);
67
160
  console.dir(target);
@@ -78,6 +171,9 @@ class TypeUtils {
78
171
  }
79
172
  return false;
80
173
  }
174
+ else if (target instanceof basic_1.ObjectReferenceType && source instanceof basic_1.ObjectReferenceType) {
175
+ return this.isOOAssignable(source, target);
176
+ }
81
177
  else if (target instanceof basic_1.ObjectReferenceType
82
178
  || target instanceof basic_1.GenericObjectReferenceType) {
83
179
  if (source instanceof basic_1.ObjectReferenceType
@@ -4,30 +4,42 @@ exports.Cast = void 0;
4
4
  const basic_1 = require("../../types/basic");
5
5
  const Expressions = require("../../2_statements/expressions");
6
6
  const source_1 = require("./source");
7
+ const _type_utils_1 = require("../_type_utils");
7
8
  class Cast {
8
9
  runSyntax(node, scope, targetType, filename) {
9
10
  var _a;
10
- for (const s of node.findAllExpressions(Expressions.Source)) {
11
- new source_1.Source().runSyntax(s, scope, filename);
11
+ const sourceNode = node.findDirectExpression(Expressions.Source);
12
+ if (sourceNode === undefined) {
13
+ throw new Error("Cast, source node not found");
12
14
  }
15
+ const sourceType = new source_1.Source().runSyntax(sourceNode, scope, filename);
16
+ let tt = undefined;
13
17
  const typeName = (_a = node.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr();
14
18
  if (typeName === undefined) {
15
19
  throw new Error("Cast, child TypeNameOrInfer not found");
16
20
  }
17
21
  else if (typeName === "#" && targetType) {
18
- return targetType;
22
+ tt = targetType;
19
23
  }
20
24
  else if (typeName === "#") {
21
25
  throw new Error("Cast, todo, infer type");
22
26
  }
23
- const found = scope.findObjectDefinition(typeName);
24
- if (found === undefined && scope.getDDIC().inErrorNamespace(typeName) === false) {
25
- return new basic_1.VoidType(typeName);
27
+ if (tt === undefined) {
28
+ const found = scope.findObjectDefinition(typeName);
29
+ if (found === undefined && scope.getDDIC().inErrorNamespace(typeName) === false) {
30
+ tt = new basic_1.VoidType(typeName);
31
+ }
32
+ else if (found === undefined) {
33
+ throw new Error("Type \"" + typeName + "\" not found in scope, Cast");
34
+ }
35
+ else {
36
+ tt = new basic_1.ObjectReferenceType(found);
37
+ }
26
38
  }
27
- else if (found === undefined) {
28
- throw new Error("Type \"" + typeName + "\" not found in scope, Cast");
39
+ if (new _type_utils_1.TypeUtils(scope).isCastable(sourceType, tt) === false) {
40
+ throw new Error("Cast, incompatible types");
29
41
  }
30
- return new basic_1.ObjectReferenceType(found);
42
+ return tt;
31
43
  }
32
44
  }
33
45
  exports.Cast = Cast;
@@ -50,7 +50,7 @@ class MethodCallParam {
50
50
  if (sourceType === undefined) {
51
51
  throw new Error("No source type determined, method source");
52
52
  }
53
- else if (_type_utils_1.TypeUtils.isAssignable(sourceType, targetType) === false) {
53
+ else if (new _type_utils_1.TypeUtils(scope).isAssignable(sourceType, targetType) === false) {
54
54
  throw new Error("Method parameter type not compatible");
55
55
  }
56
56
  }
@@ -65,7 +65,7 @@ class MethodParameters {
65
65
  }
66
66
  else if (target) {
67
67
  const targetType = new target_1.Target().runSyntax(target, scope, filename);
68
- if (targetType && _type_utils_1.TypeUtils.isAssignable(type, targetType) === false) {
68
+ if (targetType && new _type_utils_1.TypeUtils(scope).isAssignable(type, targetType) === false) {
69
69
  throw new Error("Method returning value not type compatible");
70
70
  }
71
71
  }
@@ -90,7 +90,7 @@ class MethodParameters {
90
90
  else if (item.targetType === undefined) {
91
91
  throw new Error("Could not determine target type");
92
92
  }
93
- else if (item.targetType && _type_utils_1.TypeUtils.isAssignable(parameterType, item.targetType) === false) {
93
+ else if (item.targetType && new _type_utils_1.TypeUtils(scope).isAssignable(parameterType, item.targetType) === false) {
94
94
  throw new Error("Method parameter type not compatible, " + item.name);
95
95
  }
96
96
  }
@@ -109,7 +109,7 @@ class MethodParameters {
109
109
  }
110
110
  parameterType = parameter.getType();
111
111
  }
112
- if (item.targetType && _type_utils_1.TypeUtils.isAssignable(parameterType, item.targetType) === false) {
112
+ if (item.targetType && new _type_utils_1.TypeUtils(scope).isAssignable(parameterType, item.targetType) === false) {
113
113
  throw new Error("Method parameter type not compatible, " + item.name);
114
114
  }
115
115
  (_a = this.requiredParameters) === null || _a === void 0 ? void 0 : _a.delete(item.name);
@@ -129,7 +129,7 @@ class MethodParameters {
129
129
  if (parameter === undefined) {
130
130
  throw new Error("Method importing parameter \"" + item.name + "\" does not exist");
131
131
  }
132
- else if (_type_utils_1.TypeUtils.isAssignable(parameter.getType(), item.sourceType) === false) {
132
+ else if (new _type_utils_1.TypeUtils(scope).isAssignable(item.sourceType, parameter.getType()) === false) {
133
133
  throw new Error("Method parameter type not compatible, " + item.name);
134
134
  }
135
135
  this.requiredParameters.delete(item.name);
@@ -30,7 +30,12 @@ class Move {
30
30
  new inline_data_1.InlineData().runSyntax(inline, scope, filename, sourceType);
31
31
  targetType = sourceType;
32
32
  }
33
- if (_type_utils_1.TypeUtils.isAssignable(sourceType, targetType) === false) {
33
+ if (node.findDirectTokenByText("?=")) {
34
+ if (new _type_utils_1.TypeUtils(scope).isCastable(sourceType, targetType) === false) {
35
+ throw new Error("Incompatible types");
36
+ }
37
+ }
38
+ else if (new _type_utils_1.TypeUtils(scope).isAssignable(sourceType, targetType) === false) {
34
39
  throw new Error("Incompatible types");
35
40
  }
36
41
  }
@@ -35,14 +35,14 @@ class ReadTable {
35
35
  const indexSource = node.findExpressionAfterToken("INDEX");
36
36
  if (indexSource) {
37
37
  const indexType = new source_1.Source().runSyntax(indexSource, scope, filename);
38
- if (_type_utils_1.TypeUtils.isAssignable(indexType, new basic_1.IntegerType()) === false) {
38
+ if (new _type_utils_1.TypeUtils(scope).isAssignable(indexType, new basic_1.IntegerType()) === false) {
39
39
  throw new Error("READ TABLE, INDEX must be simple");
40
40
  }
41
41
  }
42
42
  const fromSource = node.findExpressionAfterToken("FROM");
43
43
  if (fromSource) {
44
44
  const fromType = new source_1.Source().runSyntax(fromSource, scope, filename);
45
- if (_type_utils_1.TypeUtils.isAssignable(fromType, new basic_1.IntegerType()) === false) {
45
+ if (new _type_utils_1.TypeUtils(scope).isAssignable(fromType, new basic_1.IntegerType()) === false) {
46
46
  throw new Error("READ TABLE, FROM must be simple");
47
47
  }
48
48
  }
@@ -77,7 +77,7 @@ class ReadTable {
77
77
  const t = target.findFirstExpression(Expressions.Target);
78
78
  if (t) {
79
79
  const targetType = new target_1.Target().runSyntax(t, scope, filename);
80
- if (_type_utils_1.TypeUtils.isAssignable(rowType, targetType) === false) {
80
+ if (new _type_utils_1.TypeUtils(scope).isAssignable(rowType, targetType) === false) {
81
81
  throw new Error("Incompatible types");
82
82
  }
83
83
  return;
@@ -16,12 +16,12 @@ class Shift {
16
16
  }
17
17
  const targetType = new target_1.Target().runSyntax(target, scope, filename);
18
18
  if (node.concatTokens().toUpperCase().includes(" IN BYTE MODE")) {
19
- if (_type_utils_1.TypeUtils.isHexLike(targetType) === false) {
19
+ if (new _type_utils_1.TypeUtils(scope).isHexLike(targetType) === false) {
20
20
  throw new Error("Shift, Target not hex like");
21
21
  }
22
22
  }
23
23
  else {
24
- if (_type_utils_1.TypeUtils.isCharLike(targetType) === false) {
24
+ if (new _type_utils_1.TypeUtils(scope).isCharLike(targetType) === false) {
25
25
  throw new Error("Shift, Target not char like");
26
26
  }
27
27
  }
@@ -13,8 +13,8 @@ class Write {
13
13
  for (const s of node.findAllExpressions(Expressions.Source)) {
14
14
  const type = new source_1.Source().runSyntax(s, scope, filename);
15
15
  if (s === second
16
- && _type_utils_1.TypeUtils.isCharLike(type) === false
17
- && _type_utils_1.TypeUtils.isHexLike(type) === false) {
16
+ && new _type_utils_1.TypeUtils(scope).isCharLike(type) === false
17
+ && new _type_utils_1.TypeUtils(scope).isHexLike(type) === false) {
18
18
  throw new Error("Source not character like");
19
19
  }
20
20
  }
@@ -68,7 +68,7 @@ class Registry {
68
68
  }
69
69
  static abaplintVersion() {
70
70
  // magic, see build script "version.sh"
71
- return "2.85.20";
71
+ return "2.85.21";
72
72
  }
73
73
  getDDICReferences() {
74
74
  return this.references;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.85.20",
3
+ "version": "2.85.21",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",
@@ -48,7 +48,7 @@
48
48
  "@microsoft/api-extractor": "^7.19.4",
49
49
  "@types/chai": "^4.3.0",
50
50
  "@types/mocha": "^9.1.0",
51
- "@types/node": "^17.0.18",
51
+ "@types/node": "^17.0.19",
52
52
  "chai": "^4.3.6",
53
53
  "eslint": "^8.9.0",
54
54
  "mocha": "^9.2.1",