@abaplint/core
Version:
abaplint - Core API
83 lines • 4.25 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Statics = void 0;
const Expressions = require("../../2_statements/expressions");
const Statements = require("../../2_statements/statements");
const Structures = require("../../3_structures/structures");
const nodes_1 = require("../../nodes");
const _typed_identifier_1 = require("../../types/_typed_identifier");
const Basic = require("../../types/basic");
const static_1 = require("../statements/static");
const _syntax_input_1 = require("../_syntax_input");
// todo, this is much like DATA, refactor?
class Statics {
runSyntax(node, input) {
var _a, _b;
const name = node.findFirstExpression(Expressions.DefinitionName).getFirstToken();
let table = false;
const components = [];
for (const c of node.getChildren()) {
const ctyp = c.get();
if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Static) {
const found = new static_1.Static().runSyntax(c, input);
if (found) {
components.push({ name: found.getName(), type: found.getType() });
}
}
else if (c instanceof nodes_1.StructureNode && ctyp instanceof Structures.Statics) {
const found = new Statics().runSyntax(c, input);
if (found) {
components.push({ name: found.getName(), type: found.getType() });
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.StaticBegin) {
if (c.findDirectTokenByText("OCCURS")) {
table = true;
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.IncludeType) {
// INCLUDES
const typeName = (_a = c.findFirstExpression(Expressions.TypeName)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr();
let found = (_b = input.scope.findType(typeName)) === null || _b === void 0 ? void 0 : _b.getType();
if (found === undefined) {
const f = input.scope.getDDIC().lookupTableOrView(typeName).type;
if (f instanceof _typed_identifier_1.TypedIdentifier) {
found = f.getType();
}
else {
found = f;
}
}
if (found instanceof Basic.VoidType) {
if (table === true) {
const ttyp = new Basic.TableType(found, { withHeader: true, keyType: Basic.TableKeyType.default });
return new _typed_identifier_1.TypedIdentifier(name, input.filename, ttyp);
}
else {
return new _typed_identifier_1.TypedIdentifier(name, input.filename, found);
}
}
if (found instanceof Basic.UnknownType) {
return new _typed_identifier_1.TypedIdentifier(name, input.filename, new Basic.UnknownType("unknown type, " + typeName));
}
if (!(found instanceof Basic.StructureType)) {
const message = "not structured, " + typeName;
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return new _typed_identifier_1.TypedIdentifier(name, input.filename, Basic.VoidType.get(_syntax_input_1.CheckSyntaxKey));
}
for (const c of found.getComponents()) {
components.push(c);
}
}
}
if (table === true) {
const ttyp = new Basic.TableType(new Basic.StructureType(components), { withHeader: true, keyType: Basic.TableKeyType.default });
return new _typed_identifier_1.TypedIdentifier(name, input.filename, ttyp);
}
else {
return new _typed_identifier_1.TypedIdentifier(name, input.filename, new Basic.StructureType(components));
}
}
}
exports.Statics = Statics;
//# sourceMappingURL=statics.js.map