2024-07-15 02:10:04 +00:00
|
|
|
import { INTERNAL, formatType } from './common';
|
2024-01-04 20:27:02 +00:00
|
|
|
|
2024-05-03 04:46:21 +00:00
|
|
|
export class Property {
|
|
|
|
readonly offset: number;
|
2024-01-04 20:27:02 +00:00
|
|
|
readonly #type: string;
|
|
|
|
readonly #name: string;
|
2024-05-03 04:46:21 +00:00
|
|
|
readonly #self: string;
|
2024-01-04 20:27:02 +00:00
|
|
|
|
|
|
|
// Constructor
|
2024-05-03 04:46:21 +00:00
|
|
|
constructor(offset: number, type: string, name: string, self: string) {
|
|
|
|
this.offset = offset;
|
2024-01-04 20:27:02 +00:00
|
|
|
this.#type = type;
|
|
|
|
this.#name = name;
|
2024-05-03 04:46:21 +00:00
|
|
|
this.#self = self;
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Getters
|
2024-05-03 04:46:21 +00:00
|
|
|
type() {
|
2024-07-15 02:10:04 +00:00
|
|
|
return `${INTERNAL}type_${this.fullName()}`;
|
2024-05-03 04:46:21 +00:00
|
|
|
}
|
|
|
|
typedef() {
|
|
|
|
let arrayInfo = '';
|
|
|
|
const arrayInfoIndex = this.#name.indexOf('[');
|
|
|
|
if (arrayInfoIndex !== -1) {
|
|
|
|
arrayInfo = this.#name.substring(arrayInfoIndex);
|
|
|
|
}
|
|
|
|
return `typedef ${formatType(this.#type)}${this.type()}${arrayInfo};\n`;
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
2024-05-03 04:46:21 +00:00
|
|
|
name() {
|
|
|
|
let name = this.#name;
|
|
|
|
const arrayInfoIndex = this.#name.indexOf('[');
|
|
|
|
if (arrayInfoIndex !== -1) {
|
|
|
|
name = name.substring(0, arrayInfoIndex);
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
2024-05-03 04:46:21 +00:00
|
|
|
return name;
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
2024-05-17 06:52:31 +00:00
|
|
|
#fullName(separator: string) {
|
|
|
|
return this.#self + separator + this.name();
|
|
|
|
}
|
2024-05-03 04:46:21 +00:00
|
|
|
fullName() {
|
2024-05-17 06:52:31 +00:00
|
|
|
return this.#fullName('_');
|
|
|
|
}
|
|
|
|
prettyName() {
|
|
|
|
return this.#fullName('::');
|
2024-02-01 03:12:12 +00:00
|
|
|
}
|
2024-05-03 04:46:21 +00:00
|
|
|
rawType() {
|
|
|
|
return this.#type;
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-03 04:46:21 +00:00
|
|
|
export class StaticProperty extends Property {
|
2024-01-04 20:27:02 +00:00
|
|
|
// Constructor
|
2024-05-03 04:46:21 +00:00
|
|
|
constructor(address: number, type: string, name: string, self: string) {
|
|
|
|
super(address, type, name, self);
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
|
|
|
|
2024-05-17 06:52:31 +00:00
|
|
|
// Reference
|
|
|
|
referenceDefinition(addSelf: boolean) {
|
|
|
|
return `${this.type()} &${addSelf ? this.prettyName() : this.name()}`;
|
2024-01-04 20:27:02 +00:00
|
|
|
}
|
|
|
|
}
|