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; this.#pointerAligned = pointerAligned;
} }
has() {
return this.#size !== null;
}
get() { get() {
if (this.#size === null) {
throw new Error('No Size Specified');
}
return this.#size; return this.#size;
} }
set(size: number, isExact: boolean) { set(size: number, isExact: boolean) {

View File

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

View File

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