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
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;
}

View File

@ -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`;
}
}

View File

@ -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();
}