UNPKG

@abaplint/core

Version:
94 lines 5.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Raise = void 0; const Expressions = require("../../2_statements/expressions"); const nodes_1 = require("../../nodes"); const source_1 = require("../expressions/source"); const _reference_1 = require("../_reference"); const basic_1 = require("../../types/basic"); const message_source_1 = require("../expressions/message_source"); const raise_with_1 = require("../expressions/raise_with"); const _object_oriented_1 = require("../_object_oriented"); const method_parameters_1 = require("../expressions/method_parameters"); const _syntax_input_1 = require("../_syntax_input"); class Raise { runSyntax(node, input) { // todo var _a, _b, _c, _d, _e, _f; const helper = new _object_oriented_1.ObjectOriented(input.scope); let method; const classTok = (_a = node.findDirectExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken(); const className = classTok === null || classTok === void 0 ? void 0 : classTok.getStr(); if (classTok && className) { const found = input.scope.existsObject(className); if (found === null || found === void 0 ? void 0 : found.id) { input.scope.addReference(classTok, found.id, _reference_1.ReferenceType.ObjectOrientedReference, input.filename); const def = input.scope.findObjectDefinition(className); method = (_b = helper.searchMethodName(def, "CONSTRUCTOR")) === null || _b === void 0 ? void 0 : _b.method; } else if (input.scope.getDDIC().inErrorNamespace(className) === false) { const extra = { ooName: className, ooType: "Void" }; input.scope.addReference(classTok, undefined, _reference_1.ReferenceType.ObjectOrientedVoidReference, input.filename, extra); method = basic_1.VoidType.get(className); } else { const message = "RAISE, unknown class " + className; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, classTok, message)); return; } if (method === undefined) { method = basic_1.VoidType.get(className); } } const c = node.findExpressionAfterToken("EXCEPTION"); if (c instanceof nodes_1.ExpressionNode && (c.get() instanceof Expressions.SimpleSource2 || c.get() instanceof Expressions.Source)) { const type = source_1.Source.runSyntax(c, input); if (type instanceof basic_1.VoidType) { method = type; } else if (type instanceof basic_1.ObjectReferenceType) { const def = input.scope.findObjectDefinition(type.getIdentifierName()); method = (_c = helper.searchMethodName(def, "CONSTRUCTOR")) === null || _c === void 0 ? void 0 : _c.method; } else if (type !== undefined) { const message = "RAISE EXCEPTION, must be object reference, got " + type.constructor.name; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, c.getFirstToken(), message)); return; } } if (method === undefined) { method = basic_1.VoidType.get("Exception"); } // check parameters vs constructor const param = node.findDirectExpression(Expressions.ParameterListS); if (param) { new method_parameters_1.MethodParameters().checkExporting(param, input, method, true); } for (const s of node.findDirectExpressions(Expressions.RaiseWith)) { raise_with_1.RaiseWith.runSyntax(s, input); } for (const s of node.findDirectExpressions(Expressions.Source)) { source_1.Source.runSyntax(s, input); } for (const s of node.findDirectExpressions(Expressions.SimpleSource2)) { source_1.Source.runSyntax(s, input); } for (const s of node.findDirectExpressions(Expressions.MessageSource)) { message_source_1.MessageSource.runSyntax(s, input); } const id = (_d = node.findExpressionAfterToken("ID")) === null || _d === void 0 ? void 0 : _d.concatTokens(); let number = (_e = node.findDirectExpression(Expressions.MessageNumber)) === null || _e === void 0 ? void 0 : _e.concatTokens(); if (number === undefined) { const num = (_f = node.findExpressionAfterToken("NUMBER")) === null || _f === void 0 ? void 0 : _f.concatTokens(); if (num === null || num === void 0 ? void 0 : num.startsWith("'")) { number = num.substring(1, num.length - 1).toUpperCase(); } } if ((id === null || id === void 0 ? void 0 : id.startsWith("'")) && number) { const messageClass = id.substring(1, id.length - 1).toUpperCase(); input.scope.getMSAGReferences().addUsing(input.filename, node.getFirstToken(), messageClass, number); } } } exports.Raise = Raise; //# sourceMappingURL=raise.js.map