@abaplint/core 2.85.20 → 2.85.23
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.
- package/build/src/abap/5_syntax/_current_scope.js +6 -6
- package/build/src/abap/5_syntax/_type_utils.js +103 -3
- package/build/src/abap/5_syntax/expressions/cast.js +21 -9
- package/build/src/abap/5_syntax/expressions/method_call_param.js +1 -1
- package/build/src/abap/5_syntax/expressions/method_parameters.js +4 -4
- package/build/src/abap/5_syntax/expressions/method_source.js +6 -2
- package/build/src/abap/5_syntax/expressions/sql_for_all_entries.js +1 -1
- package/build/src/abap/5_syntax/statements/move.js +6 -1
- package/build/src/abap/5_syntax/statements/read_table.js +3 -3
- package/build/src/abap/5_syntax/statements/shift.js +2 -2
- package/build/src/abap/5_syntax/statements/write.js +2 -2
- package/build/src/registry.js +1 -1
- package/package.json +2 -2
|
@@ -166,11 +166,7 @@ class CurrentScope {
|
|
|
166
166
|
if (name === undefined) {
|
|
167
167
|
return { found: false };
|
|
168
168
|
}
|
|
169
|
-
const
|
|
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 = (
|
|
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
|
-
|
|
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
|
-
|
|
47
|
+
isHexLike(type) {
|
|
44
48
|
if (type === undefined) {
|
|
45
49
|
return false;
|
|
46
50
|
}
|
|
@@ -61,7 +65,100 @@ class TypeUtils {
|
|
|
61
65
|
}
|
|
62
66
|
return false;
|
|
63
67
|
}
|
|
64
|
-
|
|
68
|
+
isOOAssignable(source, target) {
|
|
69
|
+
let sid = source.getIdentifier();
|
|
70
|
+
let tid = target.getIdentifier();
|
|
71
|
+
const tname = tid.getName().toUpperCase();
|
|
72
|
+
const sname = sid.getName().toUpperCase();
|
|
73
|
+
if (tname === sname) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (!(sid instanceof types_1.ClassDefinition || sid instanceof types_1.InterfaceDefinition)) {
|
|
77
|
+
const found = this.scope.findObjectDefinition(sid.getName());
|
|
78
|
+
if (found) {
|
|
79
|
+
sid = found;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!(tid instanceof types_1.ClassDefinition || tid instanceof types_1.InterfaceDefinition)) {
|
|
86
|
+
const found = this.scope.findObjectDefinition(tid.getName());
|
|
87
|
+
if (found) {
|
|
88
|
+
tid = found;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (sid instanceof types_1.ClassDefinition && tid instanceof types_1.ClassDefinition) {
|
|
95
|
+
if (sname === tname) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
const slist = this.listAllSupers(sid);
|
|
99
|
+
if (slist.indexOf(tname) >= 0) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else if (sid instanceof types_1.ClassDefinition && tid instanceof types_1.InterfaceDefinition) {
|
|
104
|
+
if (sid.getImplementing().some(i => i.name === tname)) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
const slist = this.listAllInterfaces(sid);
|
|
108
|
+
if (slist.indexOf(tname) >= 0) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (sid instanceof types_1.InterfaceDefinition && tid instanceof types_1.InterfaceDefinition) {
|
|
113
|
+
if (sname === tname) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (sid.getImplementing().some(i => i.name === tname)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
const slist = this.listAllInterfaces(sid);
|
|
120
|
+
if (slist.indexOf(tname) >= 0) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
listAllInterfaces(cdef) {
|
|
127
|
+
var _a;
|
|
128
|
+
const ret = new Set();
|
|
129
|
+
const stack = [];
|
|
130
|
+
// initialize
|
|
131
|
+
cdef.getImplementing().forEach(i => stack.push(i.name));
|
|
132
|
+
if (cdef instanceof types_1.ClassDefinition) {
|
|
133
|
+
const supers = this.listAllSupers(cdef);
|
|
134
|
+
for (const s of supers) {
|
|
135
|
+
(_a = this.scope.findClassDefinition(s)) === null || _a === void 0 ? void 0 : _a.getImplementing().forEach(i => stack.push(i.name));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// main loop
|
|
139
|
+
while (stack.length > 0) {
|
|
140
|
+
const intf = stack.pop().toUpperCase();
|
|
141
|
+
ret.add(intf);
|
|
142
|
+
const idef = this.scope.findInterfaceDefinition(intf);
|
|
143
|
+
idef === null || idef === void 0 ? void 0 : idef.getImplementing().forEach(i => stack.push(i.name));
|
|
144
|
+
}
|
|
145
|
+
return Array.from(ret.values());
|
|
146
|
+
}
|
|
147
|
+
listAllSupers(cdef) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
const ret = [];
|
|
150
|
+
let sup = cdef.getSuperClass();
|
|
151
|
+
while (sup !== undefined) {
|
|
152
|
+
ret.push(sup === null || sup === void 0 ? void 0 : sup.toUpperCase());
|
|
153
|
+
sup = (_b = (_a = this.scope.findClassDefinition(sup)) === null || _a === void 0 ? void 0 : _a.getSuperClass()) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
154
|
+
}
|
|
155
|
+
return ret;
|
|
156
|
+
}
|
|
157
|
+
isCastable(_source, _target) {
|
|
158
|
+
// todo
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
isAssignable(source, target) {
|
|
65
162
|
/*
|
|
66
163
|
console.dir(source);
|
|
67
164
|
console.dir(target);
|
|
@@ -78,6 +175,9 @@ class TypeUtils {
|
|
|
78
175
|
}
|
|
79
176
|
return false;
|
|
80
177
|
}
|
|
178
|
+
else if (target instanceof basic_1.ObjectReferenceType && source instanceof basic_1.ObjectReferenceType) {
|
|
179
|
+
return this.isOOAssignable(source, target);
|
|
180
|
+
}
|
|
81
181
|
else if (target instanceof basic_1.ObjectReferenceType
|
|
82
182
|
|| target instanceof basic_1.GenericObjectReferenceType) {
|
|
83
183
|
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
|
-
|
|
11
|
-
|
|
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
|
-
|
|
22
|
+
tt = targetType;
|
|
19
23
|
}
|
|
20
24
|
else if (typeName === "#") {
|
|
21
25
|
throw new Error("Cast, todo, infer type");
|
|
22
26
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
28
|
-
throw new Error("
|
|
39
|
+
if (new _type_utils_1.TypeUtils(scope).isCastable(sourceType, tt) === false) {
|
|
40
|
+
throw new Error("Cast, incompatible types");
|
|
29
41
|
}
|
|
30
|
-
return
|
|
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()
|
|
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);
|
|
@@ -11,6 +11,7 @@ const _reference_1 = require("../_reference");
|
|
|
11
11
|
const _object_oriented_1 = require("../_object_oriented");
|
|
12
12
|
class MethodSource {
|
|
13
13
|
runSyntax(node, scope, filename) {
|
|
14
|
+
// todo, rewrite the context finding, and/or restructure the expression?
|
|
14
15
|
const context = new method_call_chain_1.MethodCallChain().runSyntax(node, scope, filename);
|
|
15
16
|
const last = node.getLastChild();
|
|
16
17
|
const first = node.getFirstChild();
|
|
@@ -19,8 +20,11 @@ class MethodSource {
|
|
|
19
20
|
}
|
|
20
21
|
else if (last instanceof nodes_1.ExpressionNode && last.get() instanceof Expressions.MethodName) {
|
|
21
22
|
if (context instanceof basic_1.ObjectReferenceType) {
|
|
22
|
-
|
|
23
|
-
if (id instanceof types_1.ClassDefinition) {
|
|
23
|
+
let id = context.getIdentifier();
|
|
24
|
+
if (!(id instanceof types_1.ClassDefinition)) {
|
|
25
|
+
id = scope.findObjectDefinition(id.getName());
|
|
26
|
+
}
|
|
27
|
+
if (id instanceof types_1.ClassDefinition) { // todo || id instanceof InterfaceDefinition) {
|
|
24
28
|
const methodName = last.concatTokens().toUpperCase();
|
|
25
29
|
const helper = new _object_oriented_1.ObjectOriented(scope);
|
|
26
30
|
const { method: foundMethod } = helper.searchMethodName(id, methodName);
|
|
@@ -18,7 +18,7 @@ class SQLForAllEntries {
|
|
|
18
18
|
if (!(type instanceof basic_1.TableType)) {
|
|
19
19
|
throw new Error("FAE parameter must be table type");
|
|
20
20
|
}
|
|
21
|
-
const name = s.concatTokens();
|
|
21
|
+
const name = s.concatTokens().replace("[]", "");
|
|
22
22
|
scope.setAllowHeaderUse(name);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -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 (
|
|
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
|
}
|
package/build/src/registry.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abaplint/core",
|
|
3
|
-
"version": "2.85.
|
|
3
|
+
"version": "2.85.23",
|
|
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.
|
|
51
|
+
"@types/node": "^17.0.21",
|
|
52
52
|
"chai": "^4.3.6",
|
|
53
53
|
"eslint": "^8.9.0",
|
|
54
54
|
"mocha": "^9.2.1",
|