@abaplint/runtime
Version:
Transpiler - Runtime
79 lines • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Integer8 = void 0;
const throw_error_1 = require("../throw_error");
const float_1 = require("./float");
const hex_1 = require("./hex");
const xstring_1 = require("./xstring");
const integer_1 = require("./integer");
const get_bit_1 = require("../statements/get_bit");
const character_1 = require("./character");
const hex_uint8_1 = require("./hex_uint8");
const digits = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
class Integer8 {
constructor(input) {
this.value = 0n;
this.qualifiedName = input?.qualifiedName;
}
clone() {
const n = new Integer8({ qualifiedName: this.qualifiedName });
// set without trigger checks and padding
n.value = this.value;
return n;
}
getQualifiedName() {
return this.qualifiedName;
}
set(value) {
if (typeof value === "number") {
this.value = BigInt(value);
}
else if (typeof value === "bigint") {
this.value = value;
}
else if (typeof value === "string") {
if (value.endsWith("-")) {
value = "-" + value.substring(0, value.length - 1);
}
if (value.trim().length === 0) {
value = "0";
}
else if (digits.test(value) === false) {
(0, throw_error_1.throwError)("CX_SY_CONVERSION_NO_NUMBER");
}
this.value = BigInt(value);
}
else if (value instanceof float_1.Float) {
this.set(Math.round(value.getRaw()));
}
else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
if (value.get().length === 16) {
const lv_bit = new character_1.Character();
(0, get_bit_1.getBit)(new integer_1.Integer().set(1), value, lv_bit);
if (lv_bit.get() === "1") {
const val = BigInt("0x" + value.get());
this.value = val - BigInt("0x10000000000000000");
}
else {
this.value = BigInt("0x" + value.get());
}
}
else {
// todo, what if the input is longer than 16 bytes?
this.value = BigInt("0x" + value.get());
}
}
else {
this.set(value.get());
}
return this;
}
clear() {
this.value = 0n;
}
get() {
return this.value;
}
}
exports.Integer8 = Integer8;
//# sourceMappingURL=integer8.js.map