Change Static Property Handling

This commit is contained in:
TheBrokenRail 2024-01-07 02:41:08 -05:00
parent 1062e048c4
commit 00b223a6ad
3 changed files with 22 additions and 6 deletions

View File

@ -158,7 +158,15 @@ export function load(target: Struct, name: string, isExtended: boolean) {
// Add Static Property // Add Static Property
if (!isExtended) { if (!isExtended) {
const info = parseProperty(args); 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; break;
} }

View File

@ -98,22 +98,24 @@ export class StaticProperty {
readonly #type: string; readonly #type: string;
readonly #name: string; readonly #name: string;
readonly #self: string; readonly #self: string;
readonly #isArray: boolean;
// Constructor // 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.address = address;
this.#type = type; this.#type = type;
this.#name = name; this.#name = name;
this.#self = self; this.#self = self;
this.#isArray = isArray;
} }
// Name And Type // Name And Type
getName() { getName() {
return `${this.#self}_${this.#name}`; return `${this.#self}_${this.#name}`;
} }
getType() { getPointerType() {
let type = this.#type; let type = this.#type;
// Convert To Pointer // Convert Type To Pointer
if (!type.endsWith('*')) { if (!type.endsWith('*')) {
type += ' '; type += ' ';
} }
@ -124,6 +126,11 @@ export class StaticProperty {
// Generate Variable Definition // Generate Variable Definition
generateDefinition() { 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`;
} }
} }

View File

@ -150,6 +150,7 @@ export class Struct {
// Static Properties // Static Properties
for (const property of this.#staticProperties) { for (const property of this.#staticProperties) {
out += `extern ${property.generateDefinition()}`; out += `extern ${property.generateDefinition()}`;
out += property.generateMacro();
} }
// Methods // Methods
@ -257,7 +258,7 @@ export class Struct {
// Static Properties // Static Properties
for (const property of this.#staticProperties) { 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(); declarations += property.generateDefinition();
} }