@abaplint/core
Version:
abaplint - Core API
134 lines • 6.46 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Data = void 0;
const data_1 = require("../statements/data");
const nodes_1 = require("../../nodes");
const type_1 = require("../statements/type");
const _typed_identifier_1 = require("../../types/_typed_identifier");
const types_1 = require("./types");
const Basic = require("../../types/basic");
const Expressions = require("../../2_statements/expressions");
const Statements = require("../../2_statements/statements");
const Structures = require("../../3_structures/structures");
const include_type_1 = require("../statements/include_type");
const constant_1 = require("../statements/constant");
const constants_1 = require("./constants");
const ranges_1 = require("../statements/ranges");
const selectoption_1 = require("../statements/selectoption");
const parameter_1 = require("../statements/parameter");
class Data {
static runSyntax(node, input) {
var _a;
const fouth = (_a = node.getFirstChild()) === null || _a === void 0 ? void 0 : _a.getChildren()[3];
const isCommonPart = fouth instanceof nodes_1.TokenNode && fouth.concatTokens().toUpperCase() === "COMMON";
if (isCommonPart) {
this.runCommonPartSyntax(node, input);
return undefined;
}
const name = node.findFirstExpression(Expressions.DefinitionName).getFirstToken();
let table = false;
const values = {};
const components = [];
for (const c of node.getChildren()) {
const ctyp = c.get();
if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Data) {
const found = new data_1.Data().runSyntax(c, input);
if (found) {
components.push({ name: found.getName(), type: found.getType() });
if (found.getValue() !== undefined) {
values[found.getName()] = found.getValue();
}
}
}
else if (c instanceof nodes_1.StructureNode && ctyp instanceof Structures.Data) {
const found = Data.runSyntax(c, input);
if (found) {
components.push({ name: found.getName(), type: found.getType() });
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.DataBegin) {
if (c.findDirectTokenByText("OCCURS")) {
table = true;
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.IncludeType) {
// INCLUDES
const found = new include_type_1.IncludeType().runSyntax(c, input);
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);
}
}
else if (found instanceof Basic.UnknownType) {
return new _typed_identifier_1.TypedIdentifier(name, input.filename, found);
}
for (const c of found) {
components.push(c);
}
}
}
if (table === true) {
return new _typed_identifier_1.TypedIdentifier(name, input.filename, new Basic.TableType(new Basic.StructureType(components), { withHeader: true, keyType: Basic.TableKeyType.default }));
}
else {
const val = Object.keys(values).length > 0 ? values : undefined;
return new _typed_identifier_1.TypedIdentifier(name, input.filename, new Basic.StructureType(components), undefined, val);
}
}
static runCommonPartSyntax(node, input) {
for (const c of node.getChildren()) {
const ctyp = c.get();
if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Data) {
const found = new data_1.Data().runSyntax(c, input);
if (found) {
input.scope.addIdentifier(found);
}
}
else if (c instanceof nodes_1.StructureNode && ctyp instanceof Structures.Data) {
const found = Data.runSyntax(c, input);
if (found) {
input.scope.addIdentifier(found);
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Type) {
const found = new type_1.Type().runSyntax(c, input);
if (found) {
input.scope.addType(found);
}
}
else if (c instanceof nodes_1.StructureNode && ctyp instanceof Structures.Types) {
const found = new types_1.Types().runSyntax(c, input);
if (found) {
input.scope.addType(found);
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Constant) {
const found = new constant_1.Constant().runSyntax(c, input);
if (found) {
input.scope.addIdentifier(found);
}
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Ranges) {
new ranges_1.Ranges().runSyntax(c, input);
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.SelectOption) {
new selectoption_1.SelectOption().runSyntax(c, input);
}
else if (c instanceof nodes_1.StatementNode && ctyp instanceof Statements.Parameter) {
new parameter_1.Parameter().runSyntax(c, input);
}
else if (c instanceof nodes_1.StructureNode && ctyp instanceof Structures.Constants) {
const { type: found, values: _ } = new constants_1.Constants().runSyntax(c, input);
if (found) {
input.scope.addIdentifier(found);
}
}
}
}
}
exports.Data = Data;
//# sourceMappingURL=data.js.map