@abaplint/core
Version:
abaplint - Core API
98 lines • 5.03 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Data = 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 data_1 = require("../statements/data");
const _reference_1 = require("../_reference");
const _syntax_input_1 = require("../_syntax_input");
class Data {
runSyntax(node, input) {
var _a;
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 = new 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 typeToken = (_a = c.findFirstExpression(Expressions.TypeName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
const typeName = typeToken === null || typeToken === void 0 ? void 0 : typeToken.getStr();
let foundId = input.scope.findType(typeName);
if (foundId === undefined) {
foundId = input.scope.findVariable(typeName);
}
let found = foundId === null || foundId === void 0 ? void 0 : foundId.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;
}
}
else {
input.scope.addReference(typeToken, foundId, _reference_1.ReferenceType.TypeReference, input.filename);
}
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.TableType && found.isWithHeader()) {
found = found.getRowType();
}
if (!(found instanceof Basic.StructureType)) {
const message = "not structured, " + typeName;
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, typeToken, message));
return new _typed_identifier_1.TypedIdentifier(name, input.filename, new Basic.VoidType(_syntax_input_1.CheckSyntaxKey));
}
for (const c of found.getComponents()) {
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);
}
}
}
exports.Data = Data;
//# sourceMappingURL=data.js.map