UNPKG

@abaplint/core

Version:
101 lines 5.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ComponentChain = void 0; const Expressions = require("../../2_statements/expressions"); const void_type_1 = require("../../types/basic/void_type"); const structure_type_1 = require("../../types/basic/structure_type"); const basic_1 = require("../../types/basic"); const types_1 = require("../../types"); const _reference_1 = require("../_reference"); const _object_oriented_1 = require("../_object_oriented"); const _syntax_input_1 = require("../_syntax_input"); class ComponentChain { static runSyntax(context, node, input) { if (context === undefined) { return undefined; } const children = node.getChildren(); for (let i = 0; i < children.length; i++) { if (context instanceof void_type_1.VoidType || context instanceof basic_1.UnknownType) { return context; } const child = children[i]; if (i === 0 && child.concatTokens().toUpperCase() === "TABLE_LINE") { continue; } else if (child.get() instanceof Expressions.ArrowOrDash) { const concat = child.concatTokens(); if (concat === "-") { if (!(context instanceof structure_type_1.StructureType)) { const message = "ComponentChain, not a structure"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } } else if (concat === "=>") { if (!(context instanceof basic_1.ObjectReferenceType)) { const message = "ComponentChain, not a reference"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } } else if (concat === "->") { if (!(context instanceof basic_1.ObjectReferenceType) && !(context instanceof basic_1.DataReference)) { const message = "ComponentChain, not a reference"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } } } else if (child.get() instanceof Expressions.ComponentName) { const name = child.concatTokens(); if (context instanceof basic_1.DataReference) { context = context.getType(); if (name === "*") { continue; } } if (context instanceof structure_type_1.StructureType) { context = context.getComponentByName(name); if (context === undefined) { const message = "Component \"" + name + "\" not found in structure"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } } else if (context instanceof basic_1.ObjectReferenceType) { const id = context.getIdentifier(); const def = input.scope.findObjectDefinition(id.getName()); if (def === undefined) { const message = id.getName() + " not found in scope"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } const helper = new _object_oriented_1.ObjectOriented(input.scope); const found = helper.searchAttributeName(def, name); context = found === null || found === void 0 ? void 0 : found.getType(); if (context === undefined) { const message = "Attribute \"" + name + "\" not found"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } else { const extra = { ooName: id.getName(), ooType: id instanceof types_1.ClassDefinition ? "CLAS" : "INTF" }; input.scope.addReference(child.getFirstToken(), found, _reference_1.ReferenceType.DataWriteReference, input.filename, extra); } } else { const message = "ComponentChain, not a structure, " + (context === null || context === void 0 ? void 0 : context.constructor.name); input.issues.push((0, _syntax_input_1.syntaxIssue)(input, child.getFirstToken(), message)); return void_type_1.VoidType.get(_syntax_input_1.CheckSyntaxKey); } } } return context; } } exports.ComponentChain = ComponentChain; //# sourceMappingURL=component_chain.js.map