@abaplint/core 2.115.15 → 2.115.16
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/_type_utils.js +23 -0
- package/build/src/abap/5_syntax/expressions/compare.js +12 -2
- package/build/src/abap/5_syntax/expressions/string_template.js +64 -33
- package/build/src/abap/5_syntax/statements/move.js +1 -1
- package/build/src/registry.js +1 -1
- package/package.json +1 -1
|
@@ -214,6 +214,22 @@ class TypeUtils {
|
|
|
214
214
|
// todo
|
|
215
215
|
return true;
|
|
216
216
|
}
|
|
217
|
+
isCompareable(source1, source2, node1, node2) {
|
|
218
|
+
/*
|
|
219
|
+
console.dir(source1);
|
|
220
|
+
console.dir(source2);
|
|
221
|
+
*/
|
|
222
|
+
if (source1 === undefined || source2 === undefined) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
if (source1 instanceof basic_1.HexType && this.isCalculated(node1) && source2 instanceof basic_1.IntegerType) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (source2 instanceof basic_1.HexType && this.isCalculated(node2) && source1 instanceof basic_1.IntegerType) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
217
233
|
structureContainsString(structure) {
|
|
218
234
|
for (const c of structure.getComponents()) {
|
|
219
235
|
if (c.type instanceof basic_1.StringType) {
|
|
@@ -243,6 +259,13 @@ class TypeUtils {
|
|
|
243
259
|
|| node.findFirstExpression(Expressions.ArithOperator) !== undefined;
|
|
244
260
|
return calculated;
|
|
245
261
|
}
|
|
262
|
+
isAssignableNew(source, target, node) {
|
|
263
|
+
const calculated = (node === null || node === void 0 ? void 0 : node.findFirstExpression(Expressions.ArithOperator)) !== undefined;
|
|
264
|
+
if (calculated && source instanceof basic_1.HexType && target instanceof basic_1.IntegerType) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
return this.isAssignable(source, target);
|
|
268
|
+
}
|
|
246
269
|
isAssignableStrict(source, target, node) {
|
|
247
270
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
248
271
|
const calculated = node ? this.isCalculated(node) : false;
|
|
@@ -5,10 +5,14 @@ const Expressions = require("../../2_statements/expressions");
|
|
|
5
5
|
const source_1 = require("./source");
|
|
6
6
|
const method_call_chain_1 = require("./method_call_chain");
|
|
7
7
|
const source_field_symbol_1 = require("./source_field_symbol");
|
|
8
|
+
const _syntax_input_1 = require("../_syntax_input");
|
|
9
|
+
const _type_utils_1 = require("../_type_utils");
|
|
8
10
|
class Compare {
|
|
9
11
|
static runSyntax(node, input) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const sourceTypes = [];
|
|
13
|
+
const sources = node.findDirectExpressions(Expressions.Source);
|
|
14
|
+
for (const t of sources) {
|
|
15
|
+
sourceTypes.push(source_1.Source.runSyntax(t, input));
|
|
12
16
|
}
|
|
13
17
|
for (const t of node.findDirectExpressions(Expressions.SourceFieldSymbolChain)) {
|
|
14
18
|
source_field_symbol_1.SourceFieldSymbol.runSyntax(t, input);
|
|
@@ -16,6 +20,12 @@ class Compare {
|
|
|
16
20
|
for (const t of node.findDirectExpressions(Expressions.MethodCallChain)) {
|
|
17
21
|
method_call_chain_1.MethodCallChain.runSyntax(t, input);
|
|
18
22
|
}
|
|
23
|
+
if (node.findDirectExpression(Expressions.CompareOperator)
|
|
24
|
+
&& new _type_utils_1.TypeUtils(input.scope).isCompareable(sourceTypes[0], sourceTypes[1], sources[0], sources[1]) === false
|
|
25
|
+
&& sourceTypes.length === 2) {
|
|
26
|
+
const message = "Incompatible types for comparison";
|
|
27
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
28
|
+
}
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
exports.Compare = Compare;
|
|
@@ -1,53 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringTemplate = void 0;
|
|
4
|
+
const nodes_1 = require("../../nodes");
|
|
4
5
|
const basic_1 = require("../../types/basic");
|
|
5
6
|
const Expressions = require("../../2_statements/expressions");
|
|
6
7
|
const source_1 = require("./source");
|
|
7
8
|
const _type_utils_1 = require("../_type_utils");
|
|
8
9
|
const _syntax_input_1 = require("../_syntax_input");
|
|
10
|
+
const Tokens = require("../../1_lexer/tokens");
|
|
9
11
|
class StringTemplate {
|
|
10
12
|
static runSyntax(node, input) {
|
|
11
13
|
const typeUtils = new _type_utils_1.TypeUtils(input.scope);
|
|
12
14
|
const ret = basic_1.StringType.get();
|
|
13
|
-
for (const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
for (const child of node.getChildren()) {
|
|
16
|
+
if (child instanceof nodes_1.ExpressionNode && child.get() instanceof Expressions.StringTemplateSource) {
|
|
17
|
+
const s = child.findDirectExpression(Expressions.Source);
|
|
18
|
+
const type = source_1.Source.runSyntax(s, input, ret);
|
|
19
|
+
if (type === undefined) {
|
|
20
|
+
const message = "No target type determined";
|
|
21
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
22
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
23
|
+
}
|
|
24
|
+
else if ((typeUtils.isCharLike(type) === false
|
|
25
|
+
&& typeUtils.isHexLike(type) === false
|
|
26
|
+
&& !(type instanceof basic_1.UTCLongType))
|
|
27
|
+
|| type instanceof basic_1.StructureType) {
|
|
28
|
+
const message = "String template, not character like, " + type.constructor.name;
|
|
29
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
30
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
31
|
+
}
|
|
32
|
+
const format = child.findDirectExpression(Expressions.StringTemplateFormatting);
|
|
33
|
+
const formatConcat = format === null || format === void 0 ? void 0 : format.concatTokens();
|
|
34
|
+
for (const formatSource of (format === null || format === void 0 ? void 0 : format.findAllExpressions(Expressions.Source)) || []) {
|
|
35
|
+
source_1.Source.runSyntax(formatSource, input);
|
|
36
|
+
}
|
|
37
|
+
if (format
|
|
38
|
+
&& (formatConcat === null || formatConcat === void 0 ? void 0 : formatConcat.includes("ALPHA = "))
|
|
39
|
+
&& !(type instanceof basic_1.UnknownType)
|
|
40
|
+
&& !(type instanceof basic_1.VoidType)
|
|
41
|
+
&& !(type instanceof basic_1.StringType)
|
|
42
|
+
&& !(type instanceof basic_1.CLikeType)
|
|
43
|
+
&& !(type instanceof basic_1.CharacterType)
|
|
44
|
+
&& !(type instanceof basic_1.NumericGenericType)
|
|
45
|
+
&& !(type instanceof basic_1.NumericType)
|
|
46
|
+
&& !(type instanceof basic_1.AnyType)) {
|
|
47
|
+
const message = `Cannot apply ALPHA to this type (${type.constructor.name})`;
|
|
48
|
+
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, format.getFirstToken(), message));
|
|
49
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
50
|
+
}
|
|
20
51
|
}
|
|
21
|
-
else if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
if (format
|
|
35
|
-
&& (formatConcat === null || formatConcat === void 0 ? void 0 : formatConcat.includes("ALPHA = "))
|
|
36
|
-
&& !(type instanceof basic_1.UnknownType)
|
|
37
|
-
&& !(type instanceof basic_1.VoidType)
|
|
38
|
-
&& !(type instanceof basic_1.StringType)
|
|
39
|
-
&& !(type instanceof basic_1.CLikeType)
|
|
40
|
-
&& !(type instanceof basic_1.CharacterType)
|
|
41
|
-
&& !(type instanceof basic_1.NumericGenericType)
|
|
42
|
-
&& !(type instanceof basic_1.NumericType)
|
|
43
|
-
&& !(type instanceof basic_1.AnyType)) {
|
|
44
|
-
const message = `Cannot apply ALPHA to this type (${type.constructor.name})`;
|
|
45
|
-
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, format.getFirstToken(), message));
|
|
46
|
-
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
52
|
+
else if (child instanceof nodes_1.TokenNode) {
|
|
53
|
+
const token = child.get();
|
|
54
|
+
if (token instanceof Tokens.StringTemplate
|
|
55
|
+
|| token instanceof Tokens.StringTemplateBegin
|
|
56
|
+
|| token instanceof Tokens.StringTemplateMiddle
|
|
57
|
+
|| token instanceof Tokens.StringTemplateEnd) {
|
|
58
|
+
const issue = this.validateEscapeSequences(token.getStr(), input, child);
|
|
59
|
+
if (issue) {
|
|
60
|
+
input.issues.push(issue);
|
|
61
|
+
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
47
64
|
}
|
|
48
65
|
}
|
|
49
66
|
return ret;
|
|
50
67
|
}
|
|
68
|
+
static validateEscapeSequences(str, input, node) {
|
|
69
|
+
// Valid escape sequences in ABAP string templates: \|, \{, \}, \\, \n, \r, \t
|
|
70
|
+
const validEscapes = new Set(["\\|", "\\{", "\\}", "\\\\", "\\n", "\\r", "\\t"]);
|
|
71
|
+
for (let i = 0; i < str.length; i++) {
|
|
72
|
+
if (str[i] === "\\") {
|
|
73
|
+
const escape = str.substring(i, i + 2);
|
|
74
|
+
if (!validEscapes.has(escape)) {
|
|
75
|
+
return (0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), `Invalid escape sequence "${escape}" in string template`);
|
|
76
|
+
}
|
|
77
|
+
i++; // skip the next character as it's part of the escape sequence
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
51
82
|
}
|
|
52
83
|
exports.StringTemplate = StringTemplate;
|
|
53
84
|
//# sourceMappingURL=string_template.js.map
|
|
@@ -40,7 +40,7 @@ class Move {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
else if (new _type_utils_1.TypeUtils(input.scope).
|
|
43
|
+
else if (new _type_utils_1.TypeUtils(input.scope).isAssignableNew(sourceType, targetType, source) === false) {
|
|
44
44
|
const message = "Incompatible types";
|
|
45
45
|
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
|
|
46
46
|
return;
|
package/build/src/registry.js
CHANGED