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