Small Cleanup

This commit is contained in:
TheBrokenRail 2024-02-01 23:18:38 -05:00
parent 95e24d13fa
commit fbdd1e2798
3 changed files with 15 additions and 8 deletions

View File

@ -134,7 +134,13 @@ export class Size {
this.#pointerAligned = pointerAligned;
}
has() {
return this.#size !== null;
}
get() {
if (this.#size === null) {
throw new Error('No Size Specified');
}
return this.#size;
}
set(size: number, isExact: boolean) {

View File

@ -63,13 +63,15 @@ export class Struct {
let size;
if (this.#size.isExact()) {
// Exact Size Is Specified
size = this.#size.get()!;
size = this.#size.get();
} else {
// Specified Size Is A Lower Bound
size = this.#getRealSize();
const specifiedSize = this.#size.get();
if (specifiedSize !== null && specifiedSize > size) {
size = specifiedSize;
if (this.#size.has()) {
const specifiedSize = this.#size.get();
if (specifiedSize > size) {
size = specifiedSize;
}
}
}
if (round) {

View File

@ -69,8 +69,8 @@ export class VTable implements Property {
// Check
#check() {
// Check Size
const size = this.#size.get();
if (size !== null) {
if (this.#size.has()) {
const size = this.#size.get();
const maxMethodCount = size / POINTER_SIZE;
if (this.#size.isExact() && maxMethodCount < this.#methods.length) {
throw new Error(`VTable Size Too Small: ${toHex(size)}`);
@ -112,9 +112,8 @@ export class VTable implements Property {
out += `};\n`;
// Sanity Check Size
const rawSize = this.#size.get();
const isSizeDefined = this.#size.isExact();
const size = isSizeDefined ? rawSize! : (this.#methods.length * POINTER_SIZE);
const size = isSizeDefined ? this.#size.get() : (this.#methods.length * POINTER_SIZE);
out += assertSize(this.#getName(), size, isSizeDefined);
// Pointers