Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 68x 68x 68x 68x 1x 1x 1x 67x 67x 68x 68x 68x 1x 68x 67x 68x 57x 56x 56x 56x 56x 56x 56x 2x 2x 2x 2x 56x 57x 1x 1x 55x 65x 68x 37x 37x 68x 68x 32x 32x 65x 65x 65x 65x 68x 68x 68x 183x 8x 8x 183x 57x 1x 1x 1x 46x 46x 38x 38x 8x 8x 8x 8x 1x 1x 46x 46x 39x 39x 7x 7x 46x 1x 1x 6x 46x 46x 46x 46x 3x 3x 3x 46x 3x 3x 46x 3x 3x 3x 3x 1x 1x 49x 41x 49x 1x 1x 7x 7x 1x | import * as Expressions from "../../2_statements/expressions";
import {InlineData} from "../expressions/inline_data";
import {CharacterType, StringType} from "../../types/basic";
import {Source} from "../expressions/source";
import {Target} from "../expressions/target";
import {StatementSyntax} from "../_statement_syntax";
import {MessageSource} from "../expressions/message_source";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {ObjectOriented} from "../_object_oriented";
import {BuiltInCall} from "../_builtin_call";
import {ExpressionNode, StatementNode} from "../../nodes";
import {IdentifierMeta} from "../../types/_typed_identifier";
export class Message implements StatementSyntax {
public runSyntax(node: StatementNode, input: SyntaxInput): void {
const exceptionName = node.findDirectExpression(Expressions.ExceptionName);
const classicMessage = exceptionName ? new ObjectOriented(input.scope).checkClassicException() : undefined;
if (exceptionName && classicMessage) {
input.issues.push(syntaxIssue(input, exceptionName.getFirstToken(), classicMessage));
return;
}
const found = node.findExpressionAfterToken("INTO");
const inline = found?.findDirectExpression(Expressions.InlineData);
if (inline) {
InlineData.runSyntax(inline, input, StringType.get());
} else if (found) {
Target.runSyntax(found, input);
}
for (const mss of node.findDirectExpressions(Expressions.MessageSourceSource)) {
for (const s of mss.findDirectExpressions(Expressions.Source)) {
const issueCount = input.issues.length;
Source.runSyntax(s, input);
// "Arithmetic calculation not permitted here" on a system, whatever the argument
const call = issueCount === input.issues.length && input.scope.getOpenABAP() === false
? BuiltInCall.fromSource(s, input) : undefined;
if (call !== undefined && BuiltInCall.isNumeric(call)) {
const message = `Numeric function "${BuiltInCall.callName(call)}" cannot be used in MESSAGE WITH`;
input.issues.push(syntaxIssue(input, s.getFirstToken(), message));
return;
}
}
for (const s of mss.findDirectExpressions(Expressions.SimpleSource3)) {
Source.runSyntax(s, input);
}
}
for (const s of node.findDirectExpressions(Expressions.Source)) {
Source.runSyntax(s, input);
}
for (const s of node.findDirectExpressions(Expressions.SimpleSource3)) {
Source.runSyntax(s, input);
}
for (const s of node.findDirectExpressions(Expressions.MessageSource)) {
MessageSource.runSyntax(s, input);
}
const messageTypes = [
node.findExpressionAfterToken("TYPE"),
node.findExpressionAfterToken("LIKE"),
node.findDirectExpression(Expressions.MessageSource)?.findExpressionAfterToken("TYPE"),
];
for (const messageType of messageTypes) {
if (messageType !== undefined && this.checkMessageType(messageType, input) === false) {
return;
}
}
}
// the message type is checked when it is known statically, ie. a literal or a constant
private checkMessageType(node: ExpressionNode, input: SyntaxInput): boolean {
const value = this.staticValue(node, input);
if (value === undefined || /^[AEISWX]$/i.test(value.trimEnd())) {
return true;
}
const message = `Message type "${value}" is not valid, expected A, E, I, S, W or X`;
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return false;
}
private staticValue(node: ExpressionNode, input: SyntaxInput): string | undefined {
const literal = this.literalValue(node.concatTokens());
if (literal !== undefined) {
return literal;
}
const name = node.concatTokens();
if (/^[\w\/]+$/.test(name) === false) {
return undefined;
}
const found = input.scope.findVariable(name);
const meta = found?.getMeta() ?? [];
if (found === undefined
|| meta.includes(IdentifierMeta.ReadOnly) === false
|| meta.includes(IdentifierMeta.Static) === false) {
return undefined;
}
const value = found.getValue();
if (typeof value !== "string") {
return undefined;
}
let constant = this.literalValue(value);
const type = found.getType();
if (constant !== undefined && type instanceof CharacterType) {
constant = constant.substring(0, type.getLength());
}
return constant;
}
private literalValue(code: string): string | undefined {
if (/^'([^']|'')*'$/.test(code)) {
return code.substring(1, code.length - 1).replace(/''/g, "'");
} else if (/^`([^`]|``)*`$/.test(code)) {
return code.substring(1, code.length - 1).replace(/``/g, "`");
}
return undefined;
}
}
|