UNPKG

@abaplint/core

Version:
99 lines 4.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InsertInternal = void 0; const Expressions = require("../../2_statements/expressions"); const inline_fs_1 = require("../expressions/inline_fs"); const source_1 = require("../expressions/source"); const target_1 = require("../expressions/target"); const fstarget_1 = require("../expressions/fstarget"); const basic_1 = require("../../types/basic"); const inline_data_1 = require("../expressions/inline_data"); const _type_utils_1 = require("../_type_utils"); const _syntax_input_1 = require("../_syntax_input"); class InsertInternal { runSyntax(node, input) { let targetType; const t = node.findDirectExpression(Expressions.Target); if (t) { targetType = target_1.Target.runSyntax(t, input); } if (!(targetType instanceof basic_1.TableType) && !(targetType instanceof basic_1.VoidType) && !(targetType instanceof basic_1.AnyType) && !(targetType instanceof basic_1.UnknownType) && targetType !== undefined) { const message = "INSERT target must be a table"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } else if (targetType instanceof basic_1.TableType && node.findDirectTokenByText("LINES") === undefined) { targetType = targetType.getRowType(); } let source = node.findDirectExpression(Expressions.SimpleSource4); if (source === undefined) { source = node.findDirectExpression(Expressions.Source); } const sourceType = source ? source_1.Source.runSyntax(source, input, targetType) : targetType; if (targetType === undefined && !(sourceType instanceof basic_1.TableType) && !(sourceType instanceof basic_1.VoidType) && !(sourceType instanceof basic_1.AnyType) && !(sourceType instanceof basic_1.UnknownType)) { const message = "INSERT target must be a table"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } const afterAssigning = node.findExpressionAfterToken("ASSIGNING"); if ((afterAssigning === null || afterAssigning === void 0 ? void 0 : afterAssigning.get()) instanceof Expressions.FSTarget) { const inlinefs = afterAssigning === null || afterAssigning === void 0 ? void 0 : afterAssigning.findDirectExpression(Expressions.InlineFS); if (inlinefs) { inline_fs_1.InlineFS.runSyntax(inlinefs, input, sourceType); } else { fstarget_1.FSTarget.runSyntax(afterAssigning, input, sourceType); } } if (node.findDirectTokenByText("INITIAL") === undefined) { let error = false; if (sourceType instanceof basic_1.IntegerType && targetType instanceof basic_1.Integer8Type) { error = true; } else if (new _type_utils_1.TypeUtils(input.scope).isAssignable(sourceType, targetType) === false) { error = true; } else if (sourceType instanceof basic_1.CharacterType && targetType instanceof basic_1.StringType) { // yea, well, INSERT doesnt convert the values automatically, like everything else? error = true; } if (error === true) { const message = "Types not compatible"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } const afterInto = node.findExpressionAfterToken("INTO"); if ((afterInto === null || afterInto === void 0 ? void 0 : afterInto.get()) instanceof Expressions.Target && sourceType) { const inline = afterInto.findDirectExpression(Expressions.InlineData); if (inline) { inline_data_1.InlineData.runSyntax(afterInto, input, new basic_1.DataReference(sourceType)); } else { const type = target_1.Target.runSyntax(afterInto, input); if (type instanceof basic_1.TableType && type.getAccessType() === basic_1.TableAccessType.hashed) { const message = "Implicit or explicit index operation on hashed table is not possible"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } } for (const s of node.findDirectExpressions(Expressions.Source)) { if (s === source) { continue; } source_1.Source.runSyntax(s, input, targetType); } } } exports.InsertInternal = InsertInternal; //# sourceMappingURL=insert_internal.js.map