From 00b223a6adb8808b34f49371b6f2f30c182f147a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 7 Jan 2024 02:41:08 -0500 Subject: [PATCH] Change Static Property Handling --- src/loader.ts | 10 +++++++++- src/property.ts | 15 +++++++++++---- src/struct.ts | 3 ++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/loader.ts b/src/loader.ts index 2f1b720..af0fcef 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -158,7 +158,15 @@ export function load(target: Struct, name: string, isExtended: boolean) { // Add Static Property if (!isExtended) { const info = parseProperty(args); - target.addStaticProperty(new StaticProperty(info.offset, info.type, info.name, target.getName())); + target.addStaticProperty(new StaticProperty(info.offset, info.type, info.name, target.getName(), false)); + } + break; + } + case 'static-property-array': { + // Add Static Array Property + if (!isExtended) { + const info = parseProperty(args); + target.addStaticProperty(new StaticProperty(info.offset, info.type, info.name, target.getName(), true)); } break; } diff --git a/src/property.ts b/src/property.ts index 12a3796..6c1014a 100644 --- a/src/property.ts +++ b/src/property.ts @@ -98,22 +98,24 @@ export class StaticProperty { readonly #type: string; readonly #name: string; readonly #self: string; + readonly #isArray: boolean; // Constructor - constructor(address: number, type: string, name: string, self: string) { + constructor(address: number, type: string, name: string, self: string, isArray: boolean) { this.address = address; this.#type = type; this.#name = name; this.#self = self; + this.#isArray = isArray; } // Name And Type getName() { return `${this.#self}_${this.#name}`; } - getType() { + getPointerType() { let type = this.#type; - // Convert To Pointer + // Convert Type To Pointer if (!type.endsWith('*')) { type += ' '; } @@ -124,6 +126,11 @@ export class StaticProperty { // Generate Variable Definition generateDefinition() { - return `${this.getType()}${this.getName()};\n`; + return `${this.getPointerType()}${this.getName()}_pointer;\n`; + } + + // Generate Macro + generateMacro() { + return `#define ${this.getName()} (${this.#isArray ? '' : '*'}${this.getName()}_pointer)\n`; } } \ No newline at end of file diff --git a/src/struct.ts b/src/struct.ts index f89fd96..d01d2ab 100644 --- a/src/struct.ts +++ b/src/struct.ts @@ -150,6 +150,7 @@ export class Struct { // Static Properties for (const property of this.#staticProperties) { out += `extern ${property.generateDefinition()}`; + out += property.generateMacro(); } // Methods @@ -257,7 +258,7 @@ export class Struct { // Static Properties for (const property of this.#staticProperties) { - init += `${INDENT}${property.getName()} = (${property.getType()}) ${toHex(property.address)};\n`; + init += `${INDENT}${property.getName()}_pointer = (${property.getPointerType()}) ${toHex(property.address)};\n`; declarations += property.generateDefinition(); }