@abaplint/core
Version:
abaplint - Core API
72 lines • 3.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cast = void 0;
const basic_1 = require("../../types/basic");
const Expressions = require("../../2_statements/expressions");
const source_1 = require("./source");
const _type_utils_1 = require("../_type_utils");
const basic_types_1 = require("../basic_types");
const _reference_1 = require("../_reference");
const _syntax_input_1 = require("../_syntax_input");
class Cast {
static runSyntax(node, input, targetType) {
const sourceNode = node.findDirectExpression(Expressions.Source);
if (sourceNode === undefined) {
const message = "Cast, source node not found";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
const sourceType = source_1.Source.runSyntax(sourceNode, input);
let tt = undefined;
const typeExpression = node.findDirectExpression(Expressions.TypeNameOrInfer);
const typeName = typeExpression === null || typeExpression === void 0 ? void 0 : typeExpression.concatTokens();
if (typeName === undefined) {
const message = "Cast, child TypeNameOrInfer not found";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
else if (typeName === "#" && targetType) {
tt = targetType;
}
else if (typeName === "#") {
const message = "Cast, todo, infer type";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
if (tt === undefined && typeExpression) {
const basic = new basic_types_1.BasicTypes(input);
tt = basic.parseType(typeExpression);
if (tt === undefined || tt instanceof basic_1.VoidType || tt instanceof basic_1.UnknownType) {
const found = input.scope.findObjectDefinition(typeName);
if (found) {
tt = new basic_1.ObjectReferenceType(found, { qualifiedName: typeName });
input.scope.addReference(typeExpression.getFirstToken(), found, _reference_1.ReferenceType.ObjectOrientedReference, input.filename);
}
}
else {
tt = new basic_1.DataReference(tt, typeName);
}
if (tt === undefined && input.scope.getDDIC().inErrorNamespace(typeName) === false) {
tt = basic_1.VoidType.get(typeName);
}
else if (typeName.toUpperCase() === "OBJECT") {
return new basic_1.GenericObjectReferenceType();
}
else if (tt === undefined) {
// todo, this should be an UnknownType instead?
const message = "Type \"" + typeName + "\" not found in scope, Cast";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, typeExpression.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
}
source_1.Source.addIfInferred(node, input, tt);
if (new _type_utils_1.TypeUtils(input.scope).isCastable(sourceType, tt) === false) {
const message = "Cast, incompatible types";
input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
}
return tt;
}
}
exports.Cast = Cast;
//# sourceMappingURL=cast.js.map