Fix some backwards compatibility #6
@ -1,4 +1,4 @@
|
||||
import { formatType } from './common';
|
||||
import { formatType, toHex } from './common';
|
||||
|
||||
export class Method {
|
||||
readonly self: string;
|
||||
@ -30,8 +30,13 @@ export class Method {
|
||||
return `typedef ${returnType}(*${this.getType()})${this.args};\n`;
|
||||
}
|
||||
|
||||
// Generate Variable Definition
|
||||
// Generate Method Definition
|
||||
generateDefinition(nameSuffix?: string) {
|
||||
return `${this.getType()} ${this.getName()}${nameSuffix !== undefined ? nameSuffix : ''};\n`;
|
||||
}
|
||||
|
||||
// Generate Method Declaration
|
||||
generateDeclaration() {
|
||||
return `static ${this.getType()} ${this.getName()} = (${this.getType()}) ${toHex(this.address)};\n`;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { POINTER_SIZE } from './common';
|
||||
import { POINTER_SIZE, toHex } from './common';
|
||||
import { getStructure } from './map';
|
||||
|
||||
export interface Property {
|
||||
@ -124,9 +124,10 @@ export class StaticProperty {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Generate Variable Definition
|
||||
generateDefinition() {
|
||||
return `${this.getPointerType()}${this.getName()}_pointer;\n`;
|
||||
// Generate Variable Declaration
|
||||
generateDeclaration() {
|
||||
const type = this.getPointerType();
|
||||
return `${type}${this.getName()}_pointer = (${type}) ${toHex(this.address)};\n`;
|
||||
}
|
||||
|
||||
// Generate Macro
|
||||
|
@ -194,14 +194,14 @@ export class Struct {
|
||||
|
||||
// Static Properties
|
||||
for (const property of this.#staticProperties) {
|
||||
out += `extern ${property.generateDefinition()}`;
|
||||
out += `static ${property.generateDeclaration()}`;
|
||||
out += property.generateMacro();
|
||||
}
|
||||
|
||||
// Methods
|
||||
for (const method of this.#methods) {
|
||||
out += method.generateTypedef();
|
||||
out += `extern ${method.generateDefinition()}`;
|
||||
out += method.generateDeclaration();
|
||||
}
|
||||
|
||||
// Early Exit For Undefined Structures
|
||||
@ -272,18 +272,6 @@ export class Struct {
|
||||
// Check
|
||||
this.#check();
|
||||
|
||||
// Static Properties
|
||||
for (const property of this.#staticProperties) {
|
||||
init += `${INDENT}${property.getName()}_pointer = (${property.getPointerType()}) ${toHex(property.address)};\n`;
|
||||
declarations += property.generateDefinition();
|
||||
}
|
||||
|
||||
// Methods
|
||||
for (const method of this.#methods) {
|
||||
init += `${INDENT}${method.getName()} = (${method.getType()}) ${toHex(method.address)};\n`;
|
||||
declarations += method.generateDefinition();
|
||||
}
|
||||
|
||||
// VTable
|
||||
if (this.#vtable !== null) {
|
||||
const vtable = this.#vtable.generateCode();
|
||||
|
@ -115,13 +115,15 @@ export class VTable implements Property {
|
||||
// Pointers
|
||||
if (this.#address !== null) {
|
||||
// Base
|
||||
out += `extern ${this.#getName()} *${this.#getName()}_base;\n`;
|
||||
const name = this.#getName();
|
||||
out += `static ${name} *${name}_base = (${name} *) ${toHex(this.#address)};\n`;
|
||||
// Methods
|
||||
for (let i = 0; i < this.#methods.length; i++) {
|
||||
const info = this.#methods[i];
|
||||
if (info) {
|
||||
const type = `${info.getType()} *`;
|
||||
out += `extern ${type}${info.getName()}_vtable_addr;\n`;
|
||||
const vtableAddress = this.#address + (i * POINTER_SIZE);
|
||||
out += `static ${type}${info.getName()}_vtable_addr = (${type}) ${toHex(vtableAddress)};\n`;
|
||||
out += `extern ${info.generateDefinition('_non_virtual')}`;
|
||||
}
|
||||
}
|
||||
@ -147,16 +149,10 @@ export class VTable implements Property {
|
||||
// Pointers
|
||||
if (this.#address !== null) {
|
||||
// Base
|
||||
init += `${INDENT}${this.#getName()}_base = (${this.#getName()} *) ${toHex(this.#address)};\n`;
|
||||
declarations += `${this.#getName()} *${this.#getName()}_base;\n`;
|
||||
// Methods
|
||||
for (let i = 0; i < this.#methods.length; i++) {
|
||||
const info = this.#methods[i];
|
||||
if (info) {
|
||||
const vtableAddress = this.#address + (i * POINTER_SIZE);
|
||||
const type = `${info.getType()} *`;
|
||||
init += `${INDENT}${info.getName()}_vtable_addr = (${type}) ${toHex(vtableAddress)};\n`;
|
||||
declarations += `${type}${info.getName()}_vtable_addr;\n`;
|
||||
init += `${INDENT}${info.getName()}_non_virtual = *${info.getName()}_vtable_addr;\n`;
|
||||
declarations += info.generateDefinition('_non_virtual');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user