@abaplint/core
Version:
abaplint - Core API
92 lines • 4.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValueBody = void 0;
const Expressions = require("../../2_statements/expressions");
const for_1 = require("./for");
const source_1 = require("./source");
const let_1 = require("./let");
const field_assignment_1 = require("./field_assignment");
const basic_1 = require("../../types/basic");
const _syntax_input_1 = require("../_syntax_input");
class ValueBody {
static runSyntax(node, input, targetType) {
var _a, _b;
if (node === undefined) {
return targetType;
}
let letScoped = false;
const letNode = node.findDirectExpression(Expressions.Let);
if (letNode) {
letScoped = let_1.Let.runSyntax(letNode, input);
}
let forScopes = 0;
for (const forNode of node.findDirectExpressions(Expressions.For) || []) {
const scoped = for_1.For.runSyntax(forNode, input);
if (scoped === true) {
forScopes++;
}
}
const fields = new Set();
for (const s of node.findDirectExpressions(Expressions.FieldAssignment)) {
field_assignment_1.FieldAssignment.runSyntax(s, input, targetType);
if (node.findDirectExpression(Expressions.ValueBodyLine) === undefined) {
// todo: refine, still needs to be checked when there are table lines
const fieldname = (_a = s.findDirectExpression(Expressions.FieldSub)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
if (fieldname) {
if (fields.has(fieldname)) {
const message = "Duplicate field assignment";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
fields.add(fieldname);
}
}
}
let type = undefined; // todo, this is only correct if there is a single source in the body
for (const s of node.findDirectExpressions(Expressions.Source)) {
type = source_1.Source.runSyntax(s, input, type);
}
for (const s of ((_b = node.findDirectExpression(Expressions.ValueBase)) === null || _b === void 0 ? void 0 : _b.findDirectExpressions(Expressions.Source)) || []) {
type = source_1.Source.runSyntax(s, input, type);
}
for (const foo of node.findDirectExpressions(Expressions.ValueBodyLine)) {
if (!(targetType instanceof basic_1.TableType)
&& !(targetType instanceof basic_1.UnknownType)
&& !(targetType instanceof basic_1.AnyType)
&& targetType !== undefined
&& !(targetType instanceof basic_1.VoidType)) {
const message = "Value, not a table type";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, foo.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
let rowType = targetType;
if (targetType instanceof basic_1.TableType) {
rowType = targetType.getRowType();
}
for (const l of foo.findDirectExpressions(Expressions.ValueBodyLines)) {
for (const s of l.findDirectExpressions(Expressions.Source)) {
// LINES OF ?? todo, pass type,
source_1.Source.runSyntax(s, input);
}
}
for (const s of foo.findDirectExpressions(Expressions.FieldAssignment)) {
field_assignment_1.FieldAssignment.runSyntax(s, input, rowType);
}
for (const s of foo.findDirectExpressions(Expressions.Source)) {
source_1.Source.runSyntax(s, input, rowType);
}
}
if (letScoped === true) {
input.scope.pop(node.getLastToken().getEnd());
}
for (let i = 0; i < forScopes; i++) {
input.scope.pop(node.getLastToken().getEnd());
}
if ((targetType === null || targetType === void 0 ? void 0 : targetType.isGeneric()) && type) {
return type;
}
return targetType ? targetType : type;
}
}
exports.ValueBody = ValueBody;
//# sourceMappingURL=value_body.js.map