@abaplint/core
Version:
abaplint - Core API
145 lines (143 loc) • 6.85 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");
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() === "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 typeToken = c.findFirstExpression(Expressions.TypeName)?.getFirstToken();
const typeName = typeToken?.getStr();
let foundId = input.scope.findType(typeName);
if (foundId === undefined) {
foundId = input.scope.findVariable(typeName);
}
let found = foundId?.getType();
if (found === undefined) {
const f = input.scope.getDDIC().lookupTableOrView(typeName).type;
if (f instanceof TypedIdentifier) {
found = f.getType();
} else {
found = f;
}
} else {
input.scope.addReference(typeToken, foundId, 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 TypedIdentifier(name, input.filename, ttyp);
} else {
return new TypedIdentifier(name, input.filename, found);
}
}
if (found instanceof Basic.UnknownType) {
return new 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(syntaxIssue(input, typeToken!, message));
return new TypedIdentifier(name, input.filename, Basic.VoidType.get(CheckSyntaxKey));
}
*/
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);
}
}
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);
}
}
}
}
}
exports.Data = Data;
//# sourceMappingURL=data.js.map