@abaplint/core
Version:
abaplint - Core API
407 lines • 16.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DDIC = void 0;
const Types = require("./abap/types/basic");
const basic_1 = require("./abap/types/basic");
class DDIC {
constructor(reg) {
this.reg = reg;
}
// the class might be local with a local super class with a global exception class as super
// todo: returns true for both local and global exception classes
isException(def, _obj) {
var _a;
if (def === undefined) {
return false;
}
if (def.name.toUpperCase() === "CX_ROOT") {
return true;
}
let superClassName = def.superClassName;
if (superClassName === undefined) {
return false;
}
let i = 0;
// max depth, make sure not to hit cyclic super class defintions
while (i++ < 10 && superClassName !== undefined) {
const found = this.reg.getObject("CLAS", superClassName);
if (found === undefined) {
break;
}
const superDef = (_a = found.getMainABAPFile()) === null || _a === void 0 ? void 0 : _a.getInfo().getClassDefinitionByName(superClassName);
if (superDef === undefined) {
break;
}
if (superDef.superClassName) {
superClassName = superDef.superClassName;
}
else {
break;
}
}
// todo, this should check for "CX_ROOT"
const isException = ((superClassName === null || superClassName === void 0 ? void 0 : superClassName.match(/^.?cx_.*$/i)) || (superClassName === null || superClassName === void 0 ? void 0 : superClassName.match(/^\/.+\/cx_.*$/i))) ? true : false;
return isException;
}
lookupBuiltinType(name, length, decimals, qualifiedName) {
switch (name) {
case "STRING":
return Types.StringType.get({ qualifiedName: qualifiedName || name });
case "XSTRING":
return Types.XStringType.get({ qualifiedName: qualifiedName || name });
case "D":
return new Types.DateType({ qualifiedName: qualifiedName || name });
case "T":
return new Types.TimeType({ qualifiedName: qualifiedName || name });
case "XSEQUENCE":
return new Types.XSequenceType({ qualifiedName: qualifiedName });
case "CLIKE":
return Types.CLikeType.get();
case "DECFLOAT":
return new Types.DecFloatType({ qualifiedName: qualifiedName });
case "ANY":
return Types.AnyType.get({ qualifiedName: qualifiedName });
case "SIMPLE":
return new Types.SimpleType({ qualifiedName: qualifiedName });
case "%_C_POINTER":
return new Types.HexType(8, qualifiedName);
case "TABLE":
return new Types.TableType(Types.AnyType.get(), { withHeader: false, keyType: Types.TableKeyType.default });
case "DATA":
return new Types.DataType({ qualifiedName: qualifiedName });
case "NUMERIC":
return new Types.NumericGenericType({ qualifiedName: qualifiedName });
case "UTCLONG": // todo, take version into account
return new Types.UTCLongType({ qualifiedName: qualifiedName });
case "DECFLOAT16":
return new Types.DecFloat16Type({ qualifiedName: qualifiedName });
case "DECFLOAT34":
return new Types.DecFloat34Type({ qualifiedName: qualifiedName });
case "CSEQUENCE":
return new Types.CSequenceType({ qualifiedName: qualifiedName });
case "I":
return Types.IntegerType.get({ qualifiedName: qualifiedName || name });
case "INT8": // todo, take version into account
return new Types.Integer8Type({ qualifiedName: qualifiedName || name });
case "F":
return new Types.FloatType({ qualifiedName: qualifiedName || name });
case "P":
if (length && decimals) {
return new Types.PackedType(length, decimals, { qualifiedName: qualifiedName });
}
else if (length) {
return new Types.PackedType(length, 0, { qualifiedName: qualifiedName });
}
else {
return new Types.PackedType(1, 0, { qualifiedName: qualifiedName });
}
case "C":
if (length) {
return new Types.CharacterType(length, { qualifiedName: qualifiedName });
}
else {
return new Types.CharacterType(1, { qualifiedName: qualifiedName });
}
case "X":
if (length) {
return new Types.HexType(length, qualifiedName);
}
else {
return new Types.HexType(1, qualifiedName);
}
case "N":
if (length) {
return new Types.NumericType(length, qualifiedName);
}
else {
return new Types.NumericType(1, qualifiedName);
}
}
return undefined;
}
inErrorNamespace(name) {
if (name === undefined) {
return true;
}
return this.reg.inErrorNamespace(name);
}
lookupObject(name) {
const clas = this.reg.getObject("CLAS", name);
const globalClas = clas === null || clas === void 0 ? void 0 : clas.getIdentifier();
if (globalClas) {
return {
type: new basic_1.ObjectReferenceType(globalClas, { qualifiedName: name, RTTIName: "\\CLASS=" + name }),
object: clas,
};
}
const intf = this.reg.getObject("INTF", name);
const globalIntf = intf === null || intf === void 0 ? void 0 : intf.getIdentifier();
if (globalIntf) {
return {
type: new basic_1.ObjectReferenceType(globalIntf, { qualifiedName: name, RTTIName: "\\INTERFACE=" + name }),
object: intf,
};
}
if (this.inErrorNamespace(name) === true) {
return { type: new basic_1.UnknownType(name) };
}
else {
return { type: basic_1.VoidType.get(name) };
}
}
lookupNoVoid(name) {
const foundTABL = this.reg.getObject("TABL", name);
if (foundTABL) {
return { type: foundTABL.parseType(this.reg), object: foundTABL };
}
const foundVIEW = this.reg.getObject("VIEW", name);
if (foundVIEW) {
return { type: foundVIEW.parseType(this.reg), object: foundVIEW };
}
const foundTTYP = this.reg.getObject("TTYP", name);
if (foundTTYP) {
return { type: foundTTYP.parseType(this.reg), object: foundTTYP };
}
const foundDTEL = this.reg.getObject("DTEL", name);
if (foundDTEL) {
return { type: foundDTEL.parseType(this.reg), object: foundDTEL };
}
const foundDDLS = this.lookupDDLS(name);
if (foundDDLS) {
return foundDDLS;
}
return undefined;
}
lookupDDLS(name) {
var _a;
if (name === undefined) {
return undefined;
}
const upper = name.toUpperCase();
for (const obj of this.reg.getObjectsByType("DDLS")) {
const ddls = obj;
if (ddls.getSQLViewName() === upper || ((_a = ddls.getDefinitionName()) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === upper) {
return { type: ddls.parseType(this.reg), object: ddls };
}
}
return undefined;
}
/** lookup with voiding and unknown types */
lookup(name) {
const found = this.lookupNoVoid(name);
if (found) {
return found;
}
if (this.reg.inErrorNamespace(name)) {
return { type: new Types.UnknownType(name + " not found, lookup") };
}
else {
return { type: Types.VoidType.get(name) };
}
}
lookupDomain(name, dataElement, description) {
const found = this.reg.getObject("DOMA", name);
if (found) {
return { type: found.parseType(this.reg, dataElement, description), object: found };
}
else if (this.reg.inErrorNamespace(name)) {
return { type: new Types.UnknownType(name + ", lookupDomain"), object: undefined };
}
else {
return { type: Types.VoidType.get(name), object: undefined };
}
}
lookupDataElement(name) {
if (name === undefined) {
return { type: new Types.UnknownType("undefined, lookupDataElement") };
}
const found = this.reg.getObject("DTEL", name);
if (found) {
return { type: found.parseType(this.reg), object: found };
}
else if (this.reg.inErrorNamespace(name)) {
return { type: new Types.UnknownType(name + " not found, lookupDataElement") };
}
else {
return { type: Types.VoidType.get(name) };
}
}
lookupTableOrView(name) {
if (name === undefined) {
return { type: new Types.UnknownType("undefined, lookupTableOrView") };
}
const foundTABL = this.reg.getObject("TABL", name);
if (foundTABL) {
return { type: foundTABL.parseType(this.reg), object: foundTABL };
}
const foundDDLS = this.lookupDDLS(name);
if (foundDDLS) {
return foundDDLS;
}
return this.lookupView(name);
}
/** this method only looks up the object, does not parse the type */
lookupTableOrView2(name) {
if (name === undefined) {
return undefined;
}
const foundTABL = this.reg.getObject("TABL", name);
if (foundTABL) {
return foundTABL;
}
const foundVIEW = this.reg.getObject("VIEW", name);
if (foundVIEW) {
return foundVIEW;
}
const foundDDLS = this.lookupDDLS(name);
if (foundDDLS) {
return foundDDLS.object;
}
return undefined;
}
lookupTable(name) {
if (name === undefined) {
return new Types.UnknownType("undefined, lookupTable");
}
const found = this.reg.getObject("TABL", name);
if (found) {
return found.parseType(this.reg);
}
else if (this.reg.inErrorNamespace(name)) {
return new Types.UnknownType(name + " not found, lookupTable");
}
else {
return Types.VoidType.get(name);
}
}
lookupView(name) {
if (name === undefined) {
return { type: new Types.UnknownType("undefined, lookupView") };
}
const found = this.reg.getObject("VIEW", name);
if (found) {
return { type: found.parseType(this.reg), object: found };
}
else if (this.reg.inErrorNamespace(name)) {
return { type: new Types.UnknownType(name + " not found, lookupView") };
}
else {
return { type: Types.VoidType.get(name) };
}
}
lookupTableType(name) {
if (name === undefined) {
return { type: new Types.UnknownType("undefined, lookupTableType") };
}
const found = this.reg.getObject("TTYP", name);
if (found) {
return { type: found.parseType(this.reg), object: found };
}
else if (this.reg.inErrorNamespace(name)) {
return { type: new Types.UnknownType(name + " not found, lookupTableType") };
}
else {
return { type: Types.VoidType.get(name) };
}
}
textToType(input) {
// todo: support short strings, and length of different integers, NUMC vs CHAR, min/max length
const extra = {
qualifiedName: input.qualifiedName,
conversionExit: input.conversionExit,
ddicName: input.ddicName,
description: input.description,
};
switch (input.text) {
case "DEC": // 1 <= len <= 31
case "D16F": // 1 <= len <= 31
case "D16D":
case "D34D":
case "D34F": // 1 <= len <= 31
case "DF16_DEC": // 1 <= len <= 31
case "DF34_DEC": // 1 <= len <= 31
case "CURR": // 1 <= len <= 31
case "QUAN": // 1 <= len <= 31
if (input.length === undefined) {
return new Types.UnknownType(input.text + " unknown length, " + input.infoText, input.infoText);
}
else if (input.decimals === undefined) {
return new Types.PackedType(parseInt(input.length, 10), 0, extra);
}
return new Types.PackedType(parseInt(input.length, 10), parseInt(input.decimals, 10), extra);
case "ACCP":
return new Types.CharacterType(6, extra); // YYYYMM
case "LANG":
return new Types.CharacterType(1, extra);
case "CLNT":
return new Types.CharacterType(3, extra);
case "CUKY":
return new Types.CharacterType(5, extra);
case "UNIT": // 2 <= len <= 3
return new Types.CharacterType(3, extra);
case "UTCL":
case "UTCLONG":
return new Types.CharacterType(27, extra);
case "NUMC": // 1 <= len <= 255
if (input.length === undefined) {
return new Types.UnknownType(input.text + " unknown length", input.infoText);
}
return new Types.NumericType(parseInt(input.length, 10), input.qualifiedName);
case "CHAR": // 1 <= len <= 30000 (1333 for table fields)
case "LCHR": // 256 <= len <= 32000
if (input.length === undefined) {
return new Types.UnknownType(input.text + " unknown length", input.infoText);
}
return new Types.CharacterType(parseInt(input.length, 10), extra);
case "RAW": // 1 <= len <= 32000
case "LRAW": // 256 <= len <= 32000
if (input.length === undefined) {
return new Types.UnknownType(input.text + " unknown length", input.infoText);
}
return new Types.HexType(parseInt(input.length, 10), input.qualifiedName);
case "TIMN": // Native HANA
case "TIMS":
return new Types.TimeType({ qualifiedName: input.qualifiedName }); //HHMMSS
case "DECFLOAT16": // len = 16
case "DECFLOAT34": // len = 34
case "D16R": // len = 16
case "D34R": // len = 34
case "DF16_RAW": // len = 16
case "DF34_RAW": // len = 34
case "FLTP": // len = 16
if (input.length === undefined) {
return new Types.UnknownType(input.text + " unknown length", input.infoText);
}
return new Types.FloatingPointType(parseInt(input.length, 10), input.qualifiedName);
case "DATN": // Native HANA
case "DATS":
return new Types.DateType({ qualifiedName: input.qualifiedName }); //YYYYMMDD
case "INT1":
case "INT2":
case "INT4":
return Types.IntegerType.get({ qualifiedName: input.qualifiedName });
case "INT8":
return new Types.Integer8Type({ qualifiedName: input.qualifiedName });
case "SSTR": // 1 <= len <= 1333
case "SSTRING": // 1 <= len <= 1333
case "STRG": // 256 <= len
case "STRING": // 256 <= len
return Types.StringType.get({ qualifiedName: input.qualifiedName });
case "RSTR": // 256 <= len
case "RAWSTRING": // 256 <= len
case "GEOM_EWKB":
return Types.XStringType.get({ qualifiedName: input.qualifiedName });
case "D16S":
case "D34S":
case "DF16_SCL":
case "DF34_SCL":
case "PREC":
case "VARC":
return new Types.UnknownType(input.text + " is an obsolete data type", input.infoText);
default:
return new Types.UnknownType(input.text + " unknown basic ddic type", input.infoText);
}
}
}
exports.DDIC = DDIC;
//# sourceMappingURL=ddic.js.map