UNPKG

@abaplint/core

Version:
131 lines 6.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReadTable = void 0; const Expressions = require("../../2_statements/expressions"); const basic_1 = require("../../types/basic"); const source_1 = require("../expressions/source"); const inline_data_1 = require("../expressions/inline_data"); const target_1 = require("../expressions/target"); const fstarget_1 = require("../expressions/fstarget"); const component_compare_simple_1 = require("../expressions/component_compare_simple"); const _type_utils_1 = require("../_type_utils"); const _syntax_input_1 = require("../_syntax_input"); class ReadTable { runSyntax(node, input) { const concat = node.concatTokens().toUpperCase(); const sources = node.findDirectExpressions(Expressions.Source); let firstSource = node.findDirectExpression(Expressions.SimpleSource2); if (firstSource === undefined) { firstSource = sources[0]; } const sourceType = firstSource ? source_1.Source.runSyntax(firstSource, input) : undefined; if (sourceType === undefined) { const message = "No source type determined, read table"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } else if (!(sourceType instanceof basic_1.TableType) && !(sourceType instanceof basic_1.VoidType)) { const message = "Read table, not a table type"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } let rowType = sourceType; if (rowType instanceof basic_1.TableType) { rowType = rowType.getRowType(); } const components = node.findDirectExpression(Expressions.ComponentCompareSimple); if (components !== undefined) { component_compare_simple_1.ComponentCompareSimple.runSyntax(components, input, rowType); } const indexSource = node.findExpressionAfterToken("INDEX"); if (indexSource) { const indexType = source_1.Source.runSyntax(indexSource, input); if (new _type_utils_1.TypeUtils(input.scope).isAssignable(indexType, basic_1.IntegerType.get()) === false) { const message = "READ TABLE, INDEX must be simple, got " + (indexType === null || indexType === void 0 ? void 0 : indexType.constructor.name); input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } const fromSource = node.findExpressionAfterToken("FROM"); if (fromSource) { const fromType = source_1.Source.runSyntax(fromSource, input); if (new _type_utils_1.TypeUtils(input.scope).isAssignable(fromType, rowType) === false) { const message = "READ TABLE, FROM must be compatible"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, fromSource.getFirstToken(), message)); return; } } const afterKey = node.findExpressionAfterToken("KEY"); for (const s of sources) { if (s === firstSource || s === indexSource || s === fromSource) { continue; } const type = source_1.Source.runSyntax(s, input); if (s === afterKey) { if (type instanceof basic_1.StringType || (type instanceof basic_1.TableType && type.isWithHeader() === false) || type instanceof basic_1.ObjectReferenceType) { const message = "Key cannot be string or table or reference"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message)); return; } } } const target = node.findDirectExpression(Expressions.ReadTableTarget); if (target) { if (concat.includes(" REFERENCE INTO ")) { rowType = new basic_1.DataReference(rowType); } const inline = target.findFirstExpression(Expressions.InlineData); const fst = target.findDirectExpression(Expressions.FSTarget); const t = target.findFirstExpression(Expressions.Target); if (inline) { inline_data_1.InlineData.runSyntax(inline, input, rowType); } else if (fst) { fstarget_1.FSTarget.runSyntax(fst, input, rowType); } else if (t) { const targetType = target_1.Target.runSyntax(t, input); if (new _type_utils_1.TypeUtils(input.scope).isAssignable(rowType, targetType) === false) { const message = "Incompatible types"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } } if (target === undefined && concat.includes(" TRANSPORTING NO FIELDS ") === false) { // if sourceType is void, assume its with header if (sourceType instanceof basic_1.TableType && sourceType.isWithHeader() === false) { const message = "READ TABLE, define INTO or TRANSPORTING NO FIELDS"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } const transporting = node.findDirectExpression(Expressions.TransportingFields); if (transporting && !(rowType instanceof basic_1.VoidType) && !(rowType instanceof basic_1.UnknownType) && !(rowType instanceof basic_1.AnyType)) { if (!(rowType instanceof basic_1.StructureType)) { const message = "READ TABLE, source not structured"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } for (const t of (transporting === null || transporting === void 0 ? void 0 : transporting.findDirectExpressions(Expressions.FieldSub)) || []) { const field = t.concatTokens(); if (field.includes("-")) { // todo continue; } if (rowType.getComponentByName(field) === undefined) { const message = "READ TABLE, field " + field + " not found in source"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } } } } exports.ReadTable = ReadTable; //# sourceMappingURL=read_table.js.map