antlr-ng
Version:
Next generation ANTLR Tool
66 lines (65 loc) • 1.81 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { SrcOp } from "./SrcOp.js";
class Bitset {
static {
__name(this, "Bitset");
}
shift;
tokens = [];
bits = 0n;
constructor(shift) {
this.shift = BigInt(shift);
}
addToken(type, name) {
this.tokens.push({ type, name });
this.bits |= 1n << BigInt(type) - this.shift;
}
getTokens() {
return this.tokens;
}
get calculated() {
return BigInt.asIntN(64, this.bits).toString();
}
}
;
class TestSetInline extends SrcOp {
static {
__name(this, "TestSetInline");
}
bitsetWordSize;
varName;
bitsets;
constructor(factory, ast, set, wordSize) {
super(factory, ast);
this.bitsetWordSize = wordSize;
const withZeroOffset = TestSetInline.createBitsets(factory, set, wordSize, true);
const withoutZeroOffset = TestSetInline.createBitsets(factory, set, wordSize, false);
this.bitsets = withZeroOffset.length <= withoutZeroOffset.length ? withZeroOffset : withoutZeroOffset;
this.varName = "_la";
}
static createBitsets(factory, set, wordSize, useZeroOffset) {
const bitsetList = [];
const target = factory.getGenerator().target;
const wSize = BigInt(wordSize);
let current;
for (const ttype of set.toArray()) {
const type = BigInt(ttype);
if (!current || type > current.shift + wSize - 1n) {
let shift;
if (useZeroOffset && type >= 0n && type < wSize - 1n) {
shift = 0;
} else {
shift = ttype;
}
current = new Bitset(shift);
bitsetList.push(current);
}
current.addToken(ttype, target.getTokenTypeAsTargetLabel(factory.g, ttype));
}
return bitsetList;
}
}
export {
TestSetInline
};