@abaplint/core
Version:
abaplint - Core API
182 lines • 10.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Target = void 0;
const Expressions = require("../../2_statements/expressions");
const nodes_1 = require("../../nodes");
const unknown_type_1 = require("../../types/basic/unknown_type");
const tokens_1 = require("../../1_lexer/tokens");
const basic_1 = require("../../types/basic");
const component_name_1 = require("./component_name");
const attribute_name_1 = require("./attribute_name");
const field_offset_1 = require("./field_offset");
const _reference_1 = require("../_reference");
const table_expression_1 = require("./table_expression");
const expressions_1 = require("../../2_statements/expressions");
const field_length_1 = require("./field_length");
const cast_1 = require("./cast");
const _syntax_input_1 = require("../_syntax_input");
class Target {
static runSyntax(node, input) {
const concat = node.concatTokens();
if (concat.includes("-")) {
// workaround for names with dashes
const found = input.scope.findVariable(concat);
if (found) {
input.scope.addReference(node.getFirstToken(), found, _reference_1.ReferenceType.DataWriteReference, input.filename);
return found.getType();
}
}
const children = node.getChildren();
const first = children[0];
if (first === undefined || !(first instanceof nodes_1.ExpressionNode)) {
return undefined;
}
let context = this.findTop(first, input);
if (context === undefined) {
const message = `"${first.getFirstToken().getStr()}" not found, Target`;
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
let currentIndex = 1;
while (currentIndex <= children.length) {
const current = children[currentIndex];
if (current === undefined) {
break;
}
currentIndex++;
if (current.get() instanceof tokens_1.Dash) {
if (context instanceof unknown_type_1.UnknownType) {
const message = "Not a structure, type unknown, target";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
else if (!(context instanceof basic_1.StructureType)
&& !(context instanceof basic_1.TableType && context.isWithHeader() && context.getRowType() instanceof basic_1.StructureType)
&& !(context instanceof basic_1.TableType && context.isWithHeader() && context.getRowType() instanceof basic_1.VoidType)
&& !(context instanceof basic_1.VoidType)) {
const message = "Not a structure, target, " + (context === null || context === void 0 ? void 0 : context.constructor.name) + ", " + current.concatTokens();
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
}
else if (current.get() instanceof tokens_1.InstanceArrow) {
if (!(context instanceof basic_1.ObjectReferenceType)
&& !(context instanceof basic_1.DataReference)
&& !(context instanceof basic_1.VoidType)) {
const message = "Not an object reference, target";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
}
else if (current.get() instanceof expressions_1.Dereference) {
if (!(context instanceof basic_1.DataReference) && !(context instanceof basic_1.VoidType)) {
const message = "Not an object reference, target";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
if (!(context instanceof basic_1.VoidType)) {
context = context.getType();
}
}
else if (current.get() instanceof Expressions.ComponentName) {
context = component_name_1.ComponentName.runSyntax(context, current, input);
}
else if (current.get() instanceof Expressions.TableBody) {
if (!(context instanceof basic_1.TableType)
&& !(context instanceof basic_1.VoidType)
&& !(context instanceof unknown_type_1.UnknownType)
&& !(context instanceof unknown_type_1.UnknownType)) {
const message = "Not a internal table, \"[]\"";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
if (context instanceof basic_1.TableType && context.isWithHeader()) {
context = new basic_1.TableType(context.getRowType(), Object.assign(Object.assign({}, context.getOptions()), { withHeader: false }));
}
}
else if (current instanceof nodes_1.ExpressionNode
&& current.get() instanceof Expressions.TableExpression) {
if (!(context instanceof basic_1.TableType) && !(context instanceof basic_1.VoidType)) {
const message = "Table expression, expected table";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
table_expression_1.TableExpression.runSyntax(current, input, context);
if (!(context instanceof basic_1.VoidType)) {
context = context.getRowType();
}
}
else if (current.get() instanceof Expressions.AttributeName) {
const type = children.length === 0 ? _reference_1.ReferenceType.DataWriteReference : _reference_1.ReferenceType.DataReadReference;
context = attribute_name_1.AttributeName.runSyntax(context, current, input, type);
}
}
const offset = node.findDirectExpression(Expressions.FieldOffset);
if (offset) {
if (context instanceof basic_1.XStringType || context instanceof basic_1.StringType) {
const message = "xstring/string offset/length in writer position not possible";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
field_offset_1.FieldOffset.runSyntax(offset, input);
}
const length = node.findDirectExpression(Expressions.FieldLength);
if (length) {
if (context instanceof basic_1.XStringType || context instanceof basic_1.StringType) {
const message = "xstring/string offset/length in writer position not possible";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
field_length_1.FieldLength.runSyntax(length, input);
}
return context;
}
/////////////////////////////////
static findTop(node, input) {
if (node === undefined) {
return undefined;
}
const token = node.getFirstToken();
const name = token.getStr();
if (node.get() instanceof Expressions.TargetField
|| node.get() instanceof Expressions.TargetFieldSymbol) {
const found = input.scope.findVariable(name);
if (found) {
input.scope.addReference(token, found, _reference_1.ReferenceType.DataWriteReference, input.filename);
}
if (name.includes("~")) {
const idef = input.scope.findInterfaceDefinition(name.split("~")[0]);
if (idef) {
input.scope.addReference(token, idef, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
}
}
return found === null || found === void 0 ? void 0 : found.getType();
}
else if (node.get() instanceof Expressions.ClassName) {
const found = input.scope.findObjectDefinition(name);
if (found) {
input.scope.addReference(token, found, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
return new basic_1.ObjectReferenceType(found);
}
else if (input.scope.getDDIC().inErrorNamespace(name) === false) {
input.scope.addReference(token, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, { ooName: name, ooType: "CLAS" });
return basic_1.VoidType.get(name);
}
else {
return new unknown_type_1.UnknownType(name + " unknown, Target");
}
}
else if (node.get() instanceof Expressions.Cast && node instanceof nodes_1.ExpressionNode) {
const ret = cast_1.Cast.runSyntax(node, input, undefined);
if (ret instanceof unknown_type_1.UnknownType) {
const message = "CAST, uknown type";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
return ret;
}
return new unknown_type_1.UnknownType("unknown target type");
}
}
exports.Target = Target;
//# sourceMappingURL=target.js.map