Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
27c4f4115b | |||
fa7446151e | |||
16ab0983a7 | |||
c803572e24 | |||
308a36b4ba | |||
f72c4f0567 | |||
5d2b146b08 | |||
2a63f1ff52 | |||
199eecda97 | |||
10026e9a04 | |||
b0814f257a | |||
6f792dfb16 | |||
46c486e56a | |||
346d4403df | |||
11342dbb78 | |||
be25749aa4 | |||
6098f57b03 | |||
8249a305df | |||
eb49f25fa4 | |||
fbb9b6d6da | |||
603010e3cc | |||
eca52455c3 | |||
9697b35de4 | |||
853481bd9a |
@ -1,2 +0,0 @@
|
||||
/build
|
||||
/node_modules
|
36
.eslintrc
36
.eslintrc
@ -1,36 +0,0 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"no-constant-condition": [
|
||||
"error",
|
||||
{
|
||||
"checkLoops": false
|
||||
}
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"allowTemplateLiterals": true
|
||||
}
|
||||
],
|
||||
"semi": "error",
|
||||
"indent": [
|
||||
"error",
|
||||
4,
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"eqeqeq": "error"
|
||||
}
|
||||
}
|
24
.gitea/workflows/build.yml
Normal file
24
.gitea/workflows/build.yml
Normal file
@ -0,0 +1,24 @@
|
||||
name: 'CI'
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
# Jobs
|
||||
jobs:
|
||||
# Build Project
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
# Dependencies
|
||||
- name: Install Dependencies
|
||||
run: npm ci
|
||||
# Test
|
||||
- name: Build
|
||||
run: npm test
|
||||
# Lint
|
||||
- name: Lint
|
||||
run: npm run lint
|
10
data/out.cpp
Normal file
10
data/out.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#define LEAN_SYMBOLS_HEADER
|
||||
#include "{{ headerPath }}"
|
||||
|
||||
// Thunk Template
|
||||
template <auto *const *func>
|
||||
decltype(auto) __thunk(auto... args) {
|
||||
return (*func)->get_thunk_target()(std::forward<decltype(args)>(args)...);
|
||||
}
|
||||
|
||||
{{ main }}
|
174
data/out.h
Normal file
174
data/out.h
Normal file
@ -0,0 +1,174 @@
|
||||
#pragma once
|
||||
|
||||
// Check Architecture
|
||||
#ifndef __arm__
|
||||
#error "Symbols Are ARM-Only"
|
||||
#endif
|
||||
|
||||
// Headers
|
||||
#include <variant>
|
||||
#include <functional>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
#include <cstring>
|
||||
|
||||
// Internal Macros
|
||||
#define __PREVENT_DESTRUCTION(self) \
|
||||
~self() = delete
|
||||
#define __PREVENT_CONSTRUCTION(self) \
|
||||
self() = delete; \
|
||||
__PREVENT_DESTRUCTION(self)
|
||||
#define __PREVENT_COPY(self) \
|
||||
self(const self &) = delete; \
|
||||
self &operator=(const self &) = delete
|
||||
|
||||
// Virtual Function Information
|
||||
struct __VirtualFunctionInfo {
|
||||
// Constructors
|
||||
template <typename Ret, typename Self, typename Super, typename... Args>
|
||||
__VirtualFunctionInfo(Ret (**const addr_)(Self, Args...), Ret (*const parent_)(Super, Args...)):
|
||||
addr((void **) addr_),
|
||||
parent((void *) parent_) {}
|
||||
template <typename T>
|
||||
__VirtualFunctionInfo(T **const addr_, const std::nullptr_t parent_):
|
||||
__VirtualFunctionInfo(addr_, (T *) parent_) {}
|
||||
// Method
|
||||
[[nodiscard]] bool can_overwrite() const {
|
||||
return *addr != parent;
|
||||
}
|
||||
// Properties
|
||||
void **const addr;
|
||||
void *const parent;
|
||||
};
|
||||
|
||||
// Thunks
|
||||
typedef void *(*thunk_enabler_t)(void *target, void *thunk);
|
||||
extern thunk_enabler_t thunk_enabler;
|
||||
|
||||
// Function Information
|
||||
template <typename T>
|
||||
class __Function;
|
||||
template <typename Ret, typename... Args>
|
||||
class __Function<Ret(Args...)> {
|
||||
// Prevent Copying
|
||||
__PREVENT_COPY(__Function);
|
||||
__PREVENT_DESTRUCTION(__Function);
|
||||
|
||||
public:
|
||||
// Types
|
||||
typedef Ret (*ptr_type)(Args...);
|
||||
typedef std::function<Ret(Args...)> type;
|
||||
typedef std::function<Ret(const type &, Args...)> overwrite_type;
|
||||
|
||||
// Normal Function
|
||||
__Function(const std::string name_, const ptr_type thunk_, const ptr_type func_):
|
||||
func(func_),
|
||||
enabled(true),
|
||||
name(name_),
|
||||
backup(func_),
|
||||
thunk(thunk_) {}
|
||||
// Virtual Function
|
||||
template <typename Parent>
|
||||
__Function(const std::string name_, const ptr_type thunk_, ptr_type *const func_, const Parent parent):
|
||||
func(__VirtualFunctionInfo(func_, parent)),
|
||||
enabled(std::get<__VirtualFunctionInfo>(func).can_overwrite()),
|
||||
name(name_),
|
||||
backup(*get_vtable_addr()),
|
||||
thunk(thunk_) {}
|
||||
|
||||
// Overwrite Function
|
||||
[[nodiscard]] bool overwrite(overwrite_type target) {
|
||||
// Check If Enabled
|
||||
if (!enabled) {
|
||||
return false;
|
||||
}
|
||||
// Enable Thunk
|
||||
enable_thunk();
|
||||
// Overwrite
|
||||
type original = get_thunk_target();
|
||||
thunk_target = [original, target](Args... args) {
|
||||
return target(original, std::forward<Args>(args)...);
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] ptr_type get(bool result_will_be_stored) {
|
||||
if (!enabled) {
|
||||
return nullptr;
|
||||
} else {
|
||||
if (result_will_be_stored) {
|
||||
enable_thunk();
|
||||
}
|
||||
if (is_virtual()) {
|
||||
return *get_vtable_addr();
|
||||
} else {
|
||||
return std::get<ptr_type>(func);
|
||||
}
|
||||
}
|
||||
}
|
||||
[[nodiscard]] ptr_type *get_vtable_addr() const {
|
||||
return (ptr_type *) std::get<__VirtualFunctionInfo>(func).addr;
|
||||
}
|
||||
[[nodiscard]] type get_thunk_target() const {
|
||||
if (thunk_target) {
|
||||
return thunk_target;
|
||||
} else {
|
||||
return backup;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Current Function
|
||||
std::variant<ptr_type, __VirtualFunctionInfo> func;
|
||||
[[nodiscard]] bool is_virtual() const {
|
||||
return func.index() == 1;
|
||||
}
|
||||
|
||||
public:
|
||||
// State
|
||||
const bool enabled;
|
||||
const std::string name;
|
||||
|
||||
// Backup Of Original Function Pointer
|
||||
const ptr_type backup;
|
||||
|
||||
private:
|
||||
// Thunk
|
||||
const ptr_type thunk;
|
||||
type thunk_target;
|
||||
bool thunk_enabled = false;
|
||||
void enable_thunk() {
|
||||
if (!thunk_enabled && enabled) {
|
||||
ptr_type real_thunk = (ptr_type) thunk_enabler((void *) backup, (void *) thunk);
|
||||
if (!is_virtual()) {
|
||||
func = real_thunk;
|
||||
}
|
||||
thunk_enabled = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Shortcuts
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned int uint;
|
||||
|
||||
// Forward Declarations
|
||||
{{ forwardDeclarations }}
|
||||
|
||||
// Extra Headers
|
||||
{{ extraHeaders }}
|
||||
|
||||
// Warnings
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
|
||||
{{ main }}
|
||||
|
||||
// Cleanup Warnings
|
||||
#pragma GCC diagnostic pop
|
61
eslint.config.mjs
Normal file
61
eslint.config.mjs
Normal file
@ -0,0 +1,61 @@
|
||||
// @ts-check
|
||||
import eslint from '@eslint/js';
|
||||
import tseslint from 'typescript-eslint';
|
||||
import * as path from 'node:path';
|
||||
import * as url from 'node:url';
|
||||
|
||||
export default tseslint.config(
|
||||
eslint.configs.recommended,
|
||||
tseslint.configs.strictTypeChecked,
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
{
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: {
|
||||
allowDefaultProject: [
|
||||
'eslint.config.mjs'
|
||||
]
|
||||
},
|
||||
tsconfigRootDir: path.dirname(url.fileURLToPath(import.meta.url))
|
||||
}
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/no-unnecessary-condition': [
|
||||
'error',
|
||||
{
|
||||
allowConstantLoopConditions: 'only-allowed-literals'
|
||||
}
|
||||
],
|
||||
quotes: [
|
||||
'error',
|
||||
'single',
|
||||
{
|
||||
allowTemplateLiterals: true
|
||||
}
|
||||
],
|
||||
semi: 'error',
|
||||
indent: [
|
||||
'error',
|
||||
4,
|
||||
{
|
||||
SwitchCase: 1
|
||||
}
|
||||
],
|
||||
eqeqeq: 'error'
|
||||
}
|
||||
},
|
||||
{
|
||||
ignores: [
|
||||
'build/',
|
||||
'node_modules/'
|
||||
]
|
||||
},
|
||||
{
|
||||
files: [
|
||||
'src/test/**/*'
|
||||
],
|
||||
rules: {
|
||||
'@typescript-eslint/no-floating-promises': 'off'
|
||||
}
|
||||
}
|
||||
);
|
1033
package-lock.json
generated
1033
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -4,18 +4,19 @@
|
||||
"description": "",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
"start": "tsc && node build/index.js",
|
||||
"lint": "eslint . --ext .ts"
|
||||
"build": "rm -rf build && tsc",
|
||||
"start": "npm run build && node build/index.js",
|
||||
"lint": "eslint .",
|
||||
"test": "npm run build && node --test build/test"
|
||||
},
|
||||
"author": "TheBrokenRail",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@tsconfig/node-lts": "^18.12.5",
|
||||
"@tsconfig/strictest": "^2.0.2",
|
||||
"@types/node": "^20.10.6",
|
||||
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
||||
"@typescript-eslint/parser": "^6.17.0",
|
||||
"eslint": "^8.56.0",
|
||||
"typescript": "^5.3.3"
|
||||
"@tsconfig/node18": "^18.2.4",
|
||||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@types/node": "^22.13.4",
|
||||
"eslint": "^9.20.1",
|
||||
"typescript": "^5.7.3",
|
||||
"typescript-eslint": "^8.24.0"
|
||||
}
|
||||
}
|
||||
|
116
src/common.ts
116
src/common.ts
@ -1,38 +1,61 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
|
||||
// Constants
|
||||
export const INDENT = ' ';
|
||||
export const POINTER_SIZE = 4;
|
||||
export const RTTI_SIZE = POINTER_SIZE;
|
||||
export const EXTENSION = '.def';
|
||||
export const STRUCTURE_FILES: {[id: string]: string} = {};
|
||||
export const STRUCTURE_FILES: Record<string, string> = {};
|
||||
export const COMMENT = '//';
|
||||
export const INTERNAL = '__';
|
||||
export const LEAN_HEADER_GUARD = '#ifndef LEAN_SYMBOLS_HEADER\n';
|
||||
// Read Definition File
|
||||
export function readDefinition(name: string) {
|
||||
if (!STRUCTURE_FILES[name]) {
|
||||
throw new Error(`Missing Definition File: ${name}${EXTENSION}`);
|
||||
}
|
||||
return fs.readFileSync(STRUCTURE_FILES[name]!, {encoding: 'utf8'});
|
||||
return fs.readFileSync(STRUCTURE_FILES[name], {encoding: 'utf8'});
|
||||
}
|
||||
export function syntaxError(message?: string) {
|
||||
throw new Error('Syntax Error' + (message ? `: ${message}` : ''));
|
||||
// Error Handling
|
||||
export function extendErrorMessage(e: unknown, message: string) {
|
||||
let extra: string | null = null;
|
||||
if (typeof e === 'string') {
|
||||
extra = e;
|
||||
} else if (e instanceof Error) {
|
||||
extra = e.message;
|
||||
}
|
||||
if (extra) {
|
||||
message += ': ' + extra;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
export function syntaxError(message?: string): never {
|
||||
throw new Error(extendErrorMessage(message, 'Syntax Error'));
|
||||
}
|
||||
// Convert 'int x' Into {type: 'int', name: 'x'}
|
||||
const POINTER_TOKENS = ['*', '&'];
|
||||
export function parseTypeAndName(piece: string) {
|
||||
// Split On Last Space
|
||||
const index = piece.lastIndexOf(' ');
|
||||
if (index === -1) {
|
||||
syntaxError('Unable To Find Name/Type Divider');
|
||||
}
|
||||
let name = piece.substring(index + 1)!;
|
||||
let type = piece.substring(0, index)!;
|
||||
let name = piece.substring(index + 1);
|
||||
let type = piece.substring(0, index);
|
||||
// Move Asterisks From Name To Type
|
||||
while (name.startsWith('*')) {
|
||||
while (POINTER_TOKENS.some(x => name.startsWith(x))) {
|
||||
const x = name.substring(0, 1);
|
||||
name = name.substring(1);
|
||||
if (!type.endsWith('*')) {
|
||||
if (!POINTER_TOKENS.some(x => type.endsWith(x))) {
|
||||
type += ' ';
|
||||
}
|
||||
type += '*';
|
||||
type += x;
|
||||
}
|
||||
// Return
|
||||
return {type, name};
|
||||
}
|
||||
// Convert To Uppercase-Snake-Case
|
||||
export function toUpperSnakeCase(str: string) {
|
||||
let wasUpper = false;
|
||||
let nextIsUpper = false;
|
||||
@ -55,26 +78,22 @@ export function toUpperSnakeCase(str: string) {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
// Convert 'int' To 'int ' But Leave 'int *' As Is
|
||||
export function formatType(type: string) {
|
||||
if (!type.endsWith('*')) {
|
||||
if (!POINTER_TOKENS.some(x => type.endsWith(x))) {
|
||||
type += ' ';
|
||||
}
|
||||
return type;
|
||||
}
|
||||
export const COMMENT = '//';
|
||||
// Convert Number To Hexadecimal
|
||||
export function toHex(x: number) {
|
||||
return '0x' + x.toString(16);
|
||||
}
|
||||
// Generate C++ Size Assertion
|
||||
export function assertSize(name: string, size: number) {
|
||||
let out = '';
|
||||
// Define Size Macro
|
||||
const macro = toUpperSnakeCase(name) + '_SIZE';
|
||||
out += `#define ${macro} ${toHex(size)}\n`;
|
||||
// Check Size
|
||||
out += `static_assert(sizeof(${name}) == ${macro}, "Invalid Size");\n`;
|
||||
// Return
|
||||
return out;
|
||||
return `static_assert(sizeof(${name}) == ${toHex(size)}, "Invalid Size");\n`;
|
||||
}
|
||||
// Parse Integer With Error Checking
|
||||
export function safeParseInt(str: string) {
|
||||
const x = parseInt(str);
|
||||
if (isNaN(x)) {
|
||||
@ -82,42 +101,45 @@ export function safeParseInt(str: string) {
|
||||
}
|
||||
return x;
|
||||
}
|
||||
// Generate "Self" Argument For Functions
|
||||
export function getSelfArg(type: string) {
|
||||
return `${type} *self`;
|
||||
}
|
||||
export function getArgNames(args: string) {
|
||||
// Remove Parentheses
|
||||
args = args.substring(1, args.length - 1);
|
||||
if (args.length === 0) {
|
||||
return [];
|
||||
}
|
||||
// Split
|
||||
const argsList = args.split(',');
|
||||
// Parse
|
||||
const out = [];
|
||||
for (let arg of argsList) {
|
||||
arg = arg.trim();
|
||||
// Remove Type
|
||||
const nameStart = Math.max(arg.lastIndexOf(' '), arg.lastIndexOf('*')) + 1;
|
||||
arg = arg.substring(nameStart);
|
||||
// Collect
|
||||
out.push(arg);
|
||||
}
|
||||
// Return
|
||||
return out;
|
||||
}
|
||||
// Prepend Argument To Function
|
||||
export function prependArg(args: string, arg: string) {
|
||||
if (args !== '()') {
|
||||
arg += ', ';
|
||||
}
|
||||
return '(' + arg + args.substring(1);
|
||||
}
|
||||
export function removeFirstArg(args: string) {
|
||||
let index = args.indexOf(',');
|
||||
if (index === -1) {
|
||||
index = args.indexOf(')');
|
||||
} else {
|
||||
index++;
|
||||
// Get Data Directory
|
||||
export function getDataDir() {
|
||||
return path.join(__dirname, '..', 'data');
|
||||
}
|
||||
// Format File From Data Directory
|
||||
export function formatFile(file: string, options: Record<string, string>) {
|
||||
// Include Other Files
|
||||
const dataDir = getDataDir();
|
||||
const otherFiles = fs.readdirSync(dataDir);
|
||||
for (let otherFile of otherFiles) {
|
||||
otherFile = path.join(dataDir, otherFile);
|
||||
options[`include ${otherFile}`] = fs.readFileSync(otherFile, 'utf8');
|
||||
}
|
||||
return '(' + args.substring(index).trim();
|
||||
// Format
|
||||
file = path.join(dataDir, file);
|
||||
let data = fs.readFileSync(file, 'utf8');
|
||||
for (const key in options) {
|
||||
const value = options[key];
|
||||
if (value) {
|
||||
data = data.replace(`{{ ${key} }}`, value);
|
||||
}
|
||||
}
|
||||
return data.trim() + '\n';
|
||||
}
|
||||
// Generate Code That Will Disable C++ Construction
|
||||
export function preventConstruction(self: string) {
|
||||
let out = '';
|
||||
out += `${INDENT}${INTERNAL}PREVENT_CONSTRUCTION(${self});\n`;
|
||||
out += `${INDENT}${INTERNAL}PREVENT_COPY(${self});\n`;
|
||||
return out;
|
||||
}
|
175
src/index.ts
175
src/index.ts
@ -1,45 +1,56 @@
|
||||
import * as fs from 'node:fs';
|
||||
import { STRUCTURE_FILES, EXTENSION, INDENT } from './common';
|
||||
import * as path from 'node:path';
|
||||
import { STRUCTURE_FILES, EXTENSION, formatFile, getDataDir, extendErrorMessage } from './common';
|
||||
import { getStructure } from './map';
|
||||
import { Struct } from './struct';
|
||||
|
||||
// Arguments
|
||||
if (process.argv.length < 5) {
|
||||
console.log('USAGE: npm start -- <Source Output File> <Header Output File> <Input Files...>');
|
||||
// Handle Errors
|
||||
process.on('uncaughtException', function (e) {
|
||||
console.error('Error: ' + e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
// Arguments
|
||||
function nextArgument() {
|
||||
const out = process.argv.shift();
|
||||
if (!out) {
|
||||
throw new Error('Not Enough Arguments!');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
process.argv.shift();
|
||||
process.argv.shift();
|
||||
nextArgument();
|
||||
nextArgument();
|
||||
// Output Files
|
||||
function invalidFileType(file: string) {
|
||||
throw new Error(`Invalid File Type: ${file}`);
|
||||
}
|
||||
const sourceOutput = process.argv.shift()!;
|
||||
if (!sourceOutput.endsWith('.cpp')) {
|
||||
invalidFileType(sourceOutput);
|
||||
}
|
||||
const headerOutput = process.argv.shift()!;
|
||||
const sourceOutput = nextArgument();
|
||||
fs.rmSync(sourceOutput, {force: true, recursive: true});
|
||||
fs.mkdirSync(sourceOutput, {recursive: true});
|
||||
const headerOutput = nextArgument();
|
||||
if (!headerOutput.endsWith('.h')) {
|
||||
invalidFileType(headerOutput);
|
||||
}
|
||||
const extraHeaders: string[] = [];
|
||||
// Input Files
|
||||
const extraHeaderFiles: string[] = [];
|
||||
while (process.argv.length > 0) {
|
||||
const file = process.argv.shift()!;
|
||||
if (file.endsWith(EXTENSION)) {
|
||||
const filePath = nextArgument();
|
||||
const file = path.parse(filePath);
|
||||
if (file.ext === EXTENSION) {
|
||||
// Get Class Name
|
||||
const parts = file.split('/');
|
||||
let name = parts[parts.length - 1]!;
|
||||
name = name.substring(0, name.length - EXTENSION.length);
|
||||
const fullName = file.base;
|
||||
const name = file.name;
|
||||
// Store
|
||||
if (name in STRUCTURE_FILES) {
|
||||
throw new Error(`Multiple Definition Files Provided: ${name}${EXTENSION}`);
|
||||
throw new Error(`Multiple Definition Files Provided: ${fullName}`);
|
||||
}
|
||||
STRUCTURE_FILES[name] = file;
|
||||
} else if (file.endsWith('.h')) {
|
||||
STRUCTURE_FILES[name] = filePath;
|
||||
} else if (file.ext === '.h') {
|
||||
// Extra Headers
|
||||
extraHeaders.push(file);
|
||||
extraHeaderFiles.push(filePath);
|
||||
} else {
|
||||
// Invalid File Type
|
||||
invalidFileType(file);
|
||||
invalidFileType(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,9 +63,9 @@ function loadSymbols() {
|
||||
}
|
||||
// Sort
|
||||
structureObjects.sort((a, b) => {
|
||||
if (a.getName() > b.getName()) {
|
||||
if (a.name > b.name) {
|
||||
return 1;
|
||||
} else if (a.getName() < b.getName()) {
|
||||
} else if (a.name < b.name) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
@ -67,7 +78,7 @@ function loadSymbols() {
|
||||
// Sort Structures By Dependency
|
||||
function dependencySort(structureObjects: Struct[]) {
|
||||
let loops = 0;
|
||||
const MAX_LOOPS = 100;
|
||||
const MAX_LOOPS = 1000;
|
||||
while (true) {
|
||||
if (loops > MAX_LOOPS) {
|
||||
throw new Error('Unable To Sort Dependencies');
|
||||
@ -112,105 +123,75 @@ function makeHeaderPart() {
|
||||
|
||||
// Generate Code
|
||||
let structures = '';
|
||||
let isFirst = true;
|
||||
for (const structure of structureObjects) {
|
||||
const name = structure.getName();
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
} else {
|
||||
structures += '\n';
|
||||
}
|
||||
const name = structure.name;
|
||||
structures += `// ${name}\n`;
|
||||
try {
|
||||
structures += structure.generate();
|
||||
} catch (e) {
|
||||
console.log(`Error Generating Header: ${name}: ${e instanceof Error ? e.stack : e}`);
|
||||
process.exit(1);
|
||||
throw new Error(extendErrorMessage(e, 'Error Generating Header: ' + name));
|
||||
}
|
||||
structures += '\n';
|
||||
}
|
||||
|
||||
// Return
|
||||
let result = '';
|
||||
result += '// Init\n';
|
||||
result += 'void init_symbols();\n\n';
|
||||
result += structures;
|
||||
return result;
|
||||
return structures;
|
||||
}
|
||||
|
||||
// Create Main Header
|
||||
function makeMainHeader(output: string) {
|
||||
let result = '';
|
||||
result += '#pragma once\n';
|
||||
result += '\n// Check Architecture\n';
|
||||
result += '#ifndef __arm__\n';
|
||||
result += '#error "Symbols Are ARM-Only"\n';
|
||||
result += '#endif\n';
|
||||
result += '\n// Shortcuts\n';
|
||||
result += 'typedef unsigned char uchar;\n';
|
||||
result += 'typedef unsigned short ushort;\n';
|
||||
result += 'typedef unsigned int uint;\n';
|
||||
result += '\n// Forward Declarations\n';
|
||||
// Forward Declarations
|
||||
let forwardDeclarations = '';
|
||||
for (const name in STRUCTURE_FILES) {
|
||||
result += `typedef struct ${name} ${name};\n`;
|
||||
forwardDeclarations += `typedef struct ${name} ${name};\n`;
|
||||
}
|
||||
result += '\n// Extra Headers\n';
|
||||
for (const file of extraHeaders) {
|
||||
result += fs.readFileSync(file, {encoding: 'utf8'});
|
||||
forwardDeclarations = forwardDeclarations.trim();
|
||||
// Extra Headers
|
||||
let extraHeaders = '';
|
||||
for (const file of extraHeaderFiles) {
|
||||
extraHeaders += fs.readFileSync(file, {encoding: 'utf8'});
|
||||
}
|
||||
result += '\n// Headers\n';
|
||||
result += '#include <cstddef>\n';
|
||||
result += '#include <string>\n';
|
||||
result += '#include <vector>\n';
|
||||
result += '#include <map>\n';
|
||||
result += '\n// Warnings\n';
|
||||
result += '#pragma GCC diagnostic push\n';
|
||||
result += '#pragma GCC diagnostic ignored "-Winvalid-offsetof"\n';
|
||||
result += '#pragma GCC diagnostic ignored "-Wshadow"\n\n';
|
||||
result += makeHeaderPart();
|
||||
result += '\n// Cleanup Warnings\n';
|
||||
result += '#pragma GCC diagnostic pop\n';
|
||||
extraHeaders = extraHeaders.trim();
|
||||
// Main
|
||||
const main = makeHeaderPart().trim();
|
||||
// Write
|
||||
const result = formatFile('out.h', {forwardDeclarations, extraHeaders, main, data: getDataDir()});
|
||||
fs.writeFileSync(output, result);
|
||||
}
|
||||
makeMainHeader(headerOutput);
|
||||
|
||||
// Generate Compiled Code
|
||||
function makeCompiledCode(output: string) {
|
||||
function makeCompiledCode(outputDir: string) {
|
||||
// Load Symbols
|
||||
const structureObjects = loadSymbols();
|
||||
|
||||
// Generate
|
||||
let declarations = '';
|
||||
let init = '';
|
||||
let isFirst = true;
|
||||
let first = true;
|
||||
for (const structure of structureObjects) {
|
||||
const name = structure.getName();
|
||||
if (isFirst) {
|
||||
isFirst = false;
|
||||
} else {
|
||||
declarations += '\n';
|
||||
init += '\n';
|
||||
// Thunks
|
||||
let declarations = '';
|
||||
if (first) {
|
||||
first = false;
|
||||
declarations += '// Thunk Enabler\n';
|
||||
declarations += 'thunk_enabler_t thunk_enabler;\n\n';
|
||||
}
|
||||
declarations += `// ${name}\n`;
|
||||
init += `${INDENT}// ${name}\n`;
|
||||
try {
|
||||
const code = structure.generateCode();
|
||||
declarations += code.functions;
|
||||
init += code.init;
|
||||
} catch (e) {
|
||||
console.log(`Error Generating Code: ${name}: ${e instanceof Error ? e.stack : e}`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Write
|
||||
let result = '';
|
||||
result += `#include "${fs.realpathSync(headerOutput)}"\n`;
|
||||
result += '\n#include <cstring>\n';
|
||||
result += '\n// Init\n';
|
||||
result += 'void init_symbols() {\n';
|
||||
result += init;
|
||||
result += '}\n\n';
|
||||
result += declarations;
|
||||
fs.writeFileSync(output, result);
|
||||
// Structure
|
||||
const name = structure.name;
|
||||
declarations += `// ${name}\n`;
|
||||
try {
|
||||
declarations += structure.generateCode().trim();
|
||||
} catch (e) {
|
||||
throw new Error(extendErrorMessage(e, 'Error Generating Code: ' + name));
|
||||
}
|
||||
declarations += '\n';
|
||||
|
||||
// Write
|
||||
const headerPath = fs.realpathSync(headerOutput);
|
||||
const main = declarations.trim();
|
||||
const result = formatFile('out.cpp', {headerPath, main, data: getDataDir()});
|
||||
const output = path.join(outputDir, name + '.cpp');
|
||||
fs.writeFileSync(output, result);
|
||||
}
|
||||
}
|
||||
makeCompiledCode(sourceOutput);
|
||||
|
@ -1,28 +1,32 @@
|
||||
import { COMMENT, EXTENSION, getSelfArg, parseTypeAndName, prependArg, readDefinition, safeParseInt, syntaxError } from './common';
|
||||
import { COMMENT, extendErrorMessage, EXTENSION, getSelfArg, parseTypeAndName, prependArg, readDefinition, safeParseInt, syntaxError } from './common';
|
||||
import { Method } from './method';
|
||||
import { Property, StaticProperty } from './property';
|
||||
import { Struct } from './struct';
|
||||
|
||||
// Error Handling
|
||||
export class ErrorOnLine {
|
||||
readonly error: unknown;
|
||||
readonly file: string;
|
||||
readonly line: number;
|
||||
constructor (error: unknown, file: string, line: number) {
|
||||
this.error = error;
|
||||
this.file = file;
|
||||
this.line = line;
|
||||
export class ErrorOnLine extends Error {
|
||||
constructor (e: unknown, file: string, line: number) {
|
||||
// Get Message
|
||||
let message: string;
|
||||
if (e instanceof ErrorOnLine) {
|
||||
message = e.message;
|
||||
} else {
|
||||
message = extendErrorMessage(e, file + ':' + line.toString());
|
||||
}
|
||||
// Call Constructor
|
||||
super(message);
|
||||
Object.setPrototypeOf(this, ErrorOnLine.prototype);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse Property
|
||||
function parseProperty(args: string) {
|
||||
const parts = args.split(' = ');
|
||||
if (parts.length !== 2) {
|
||||
const [a, b] = args.split(' = ');
|
||||
if (!a || !b) {
|
||||
syntaxError('Invalid Piece Count');
|
||||
}
|
||||
const {type, name} = parseTypeAndName(parts[0]!);
|
||||
const offset = safeParseInt(parts[1]!);
|
||||
const {type, name} = parseTypeAndName(a);
|
||||
const offset = safeParseInt(b);
|
||||
return {type, name, offset};
|
||||
}
|
||||
|
||||
@ -35,10 +39,10 @@ function parseMethod(args: string, self: string, insertSelfArg: boolean, isInher
|
||||
const start = args.substring(0, argsStart).trim();
|
||||
const {type, name} = parseTypeAndName(start);
|
||||
const end = args.substring(argsStart).trim().split(' = ');
|
||||
if (end.length !== 2) {
|
||||
if (!end[0] || !end[1]) {
|
||||
syntaxError('Invalid Piece Count');
|
||||
}
|
||||
let methodArgs = end[0]!;
|
||||
let methodArgs = end[0];
|
||||
if (!methodArgs.startsWith('(') || !methodArgs.endsWith(')')) {
|
||||
syntaxError('Invalid Method Arguments');
|
||||
}
|
||||
@ -46,7 +50,7 @@ function parseMethod(args: string, self: string, insertSelfArg: boolean, isInher
|
||||
const selfArg = getSelfArg(self);
|
||||
methodArgs = prependArg(methodArgs, selfArg);
|
||||
}
|
||||
const address = safeParseInt(end[1]!);
|
||||
const address = safeParseInt(end[1]);
|
||||
return new Method(self, name, type, methodArgs, address, isInherited, !insertSelfArg);
|
||||
}
|
||||
|
||||
@ -116,29 +120,29 @@ export function load(target: Struct, name: string, isExtended: boolean) {
|
||||
case 'vtable-size': {
|
||||
// Set VTable Size
|
||||
if (!isExtended) {
|
||||
target.setVTableSize(safeParseInt(args));
|
||||
target.getVTable().setSize(safeParseInt(args));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'vtable': {
|
||||
// Set VTable Address
|
||||
target.ensureVTable();
|
||||
const vtable = target.getVTable();
|
||||
if (!isExtended && args.length > 0) {
|
||||
target.setVTableAddress(safeParseInt(args));
|
||||
vtable.setAddress(safeParseInt(args));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'property': {
|
||||
// Add Property
|
||||
const info = parseProperty(args);
|
||||
target.addProperty(new Property(info.offset, info.type, info.name, target.getName()));
|
||||
target.addProperty(new Property(info.offset, info.type, info.name, target.name));
|
||||
break;
|
||||
}
|
||||
case 'static-property': {
|
||||
// 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.name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -150,14 +154,14 @@ export function load(target: Struct, name: string, isExtended: boolean) {
|
||||
}
|
||||
case 'virtual-method': {
|
||||
// Add Virtual Method
|
||||
const method = parseMethod(args, target.getName(), true, isExtended);
|
||||
const method = parseMethod(args, target.name, true, isExtended);
|
||||
target.addMethod(method, true);
|
||||
break;
|
||||
}
|
||||
case 'static-method': {
|
||||
// Add Static Method
|
||||
if (!isExtended) {
|
||||
const method = parseMethod(args, target.getName(), false, false);
|
||||
const method = parseMethod(args, target.name, false, false);
|
||||
target.addMethod(method, false);
|
||||
}
|
||||
break;
|
||||
@ -165,7 +169,7 @@ export function load(target: Struct, name: string, isExtended: boolean) {
|
||||
case 'constructor': {
|
||||
// Constructor
|
||||
if (!isExtended) {
|
||||
let data = `${target.getName()} *constructor`;
|
||||
let data = `${target.name} *constructor`;
|
||||
if (args.startsWith('(')) {
|
||||
// No Custom Name
|
||||
data += ' ';
|
||||
@ -174,14 +178,22 @@ export function load(target: Struct, name: string, isExtended: boolean) {
|
||||
data += '_';
|
||||
}
|
||||
data += args;
|
||||
const method = parseMethod(data, target.getName(), true, false);
|
||||
const method = parseMethod(data, target.name, true, false);
|
||||
target.addMethod(method, false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'vtable-destructor-offset': {
|
||||
// Set VTable Destructor Offset
|
||||
target.setVTableDestructorOffset(safeParseInt(args));
|
||||
target.getVTable().setDestructorOffset(safeParseInt(args));
|
||||
break;
|
||||
}
|
||||
case 'mark-as-simple': {
|
||||
// Mark As Simple
|
||||
if (isExtended) {
|
||||
throw new Error('Cannot Extend Simple Structure');
|
||||
}
|
||||
target.markAsSimple();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -189,9 +201,6 @@ export function load(target: Struct, name: string, isExtended: boolean) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof ErrorOnLine) {
|
||||
throw e;
|
||||
}
|
||||
// Find Line Number
|
||||
let lineNumber = 1;
|
||||
for (let i = 0; i <= startOfCommand; i++) {
|
||||
|
19
src/map.ts
19
src/map.ts
@ -1,14 +1,14 @@
|
||||
import { Struct } from './struct';
|
||||
import { ErrorOnLine, load } from './loader';
|
||||
import { load } from './loader';
|
||||
|
||||
// Store Loaded Structures
|
||||
const structures: {[id: string]: Struct} = {};
|
||||
const structures: Record<string, Struct> = {};
|
||||
|
||||
// Get Or Load Structure
|
||||
export function getStructure(name: string) {
|
||||
if (name in structures) {
|
||||
if (structures[name]) {
|
||||
// Already Loaded
|
||||
return structures[name]!;
|
||||
return structures[name];
|
||||
} else {
|
||||
// Load Structure
|
||||
try {
|
||||
@ -20,14 +20,11 @@ export function getStructure(name: string) {
|
||||
// Return
|
||||
return target;
|
||||
} catch (e) {
|
||||
let error = e;
|
||||
let extra = '';
|
||||
if (e instanceof ErrorOnLine) {
|
||||
extra = `${e.file}:${e.line}: `;
|
||||
error = e.error;
|
||||
let message = 'Error Loading ' + name;
|
||||
if (e instanceof Error) {
|
||||
message += ': ' + e.message;
|
||||
}
|
||||
console.log(`Error Loading ${name}: ${extra}${error instanceof Error ? error.stack : error}`);
|
||||
process.exit(1);
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { INDENT, formatType, getArgNames } from './common';
|
||||
import { INDENT, INTERNAL, formatType, toHex } from './common';
|
||||
|
||||
export class Method {
|
||||
readonly self: string;
|
||||
@ -7,7 +7,6 @@ export class Method {
|
||||
readonly args: string;
|
||||
readonly address: number;
|
||||
readonly isInherited: boolean;
|
||||
readonly hasVarargs: boolean;
|
||||
readonly isStatic: boolean;
|
||||
|
||||
// Constructor
|
||||
@ -18,56 +17,55 @@ export class Method {
|
||||
this.args = args;
|
||||
this.address = address;
|
||||
this.isInherited = isInherited;
|
||||
this.hasVarargs = this.args.includes('...');
|
||||
this.isStatic = isStatic;
|
||||
}
|
||||
|
||||
// Get Type
|
||||
getNameWithCustomSelf(self: string) {
|
||||
return `${self}_${this.shortName}`;
|
||||
}
|
||||
getName() {
|
||||
return this.getNameWithCustomSelf(this.self);
|
||||
// Getters
|
||||
getName(separator = '_') {
|
||||
return this.self + separator + this.shortName;
|
||||
}
|
||||
getType() {
|
||||
return `${this.getName()}_t`;
|
||||
return this.getName() + '_t';
|
||||
}
|
||||
#getRawType() {
|
||||
return INTERNAL + 'raw_' + this.getType();
|
||||
}
|
||||
getProperty() {
|
||||
return `${INDENT}${this.#getRawType()} *${this.shortName};\n`;
|
||||
}
|
||||
#getFullType() {
|
||||
return `${INTERNAL}Function<${this.#getRawType()}>`;
|
||||
}
|
||||
|
||||
// Generate Type Definition
|
||||
generateTypedef() {
|
||||
// Typedefs
|
||||
generateTypedefs() {
|
||||
let out = '';
|
||||
|
||||
// Normal Definition
|
||||
const returnType = formatType(this.returnType);
|
||||
out += `typedef ${returnType}(*${this.getType()})${this.args};\n`;
|
||||
|
||||
// Fancy Overwrite Does Not Support Varargs
|
||||
if (!this.hasVarargs) {
|
||||
// Overwrite Helper
|
||||
out += `#define __overwrite_helper_for_${this.getName()}(method, original) \\\n`;
|
||||
out += `${INDENT}[]${this.args} { \\\n`;
|
||||
out += `${INDENT}${INDENT}${returnType.trim() === 'void' ? '' : 'return '}method(${['original'].concat(getArgNames(this.args)).join(', ')}); \\\n`;
|
||||
out += `${INDENT}}\n`;
|
||||
}
|
||||
|
||||
// Return
|
||||
out += `typedef ${formatType(this.returnType.trim())}${this.#getRawType()}${this.args.trim()};\n`;
|
||||
out += `typedef const std::function<${this.#getRawType()}> &${this.getType()};\n`;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Generate Variable Definition
|
||||
generateDefinition(nameSuffix?: string) {
|
||||
return `${this.getType()} ${this.getName()}${nameSuffix !== undefined ? nameSuffix : ''};\n`;
|
||||
// Overwrite Helper
|
||||
#getVirtualCall(self: string = this.self) {
|
||||
return `${self}_vtable::base->${this.shortName}`;
|
||||
}
|
||||
|
||||
// Generate "New Method" Test
|
||||
generateNewMethodTest(parent: string | null, prefix: string, suffix: string) {
|
||||
let out = `#define __is_new_method_${this.getName()}() (`;
|
||||
if (!this.isInherited) {
|
||||
out += 'true';
|
||||
} else {
|
||||
out += `((void *) ${prefix}${this.getName()}${suffix}) != ((void *) ${prefix}${this.getNameWithCustomSelf(parent!)}${suffix})`;
|
||||
generate(code: boolean, isVirtual: boolean, parentSelf?: string) {
|
||||
let out = '';
|
||||
out += 'extern ';
|
||||
const type = this.#getFullType();
|
||||
out += `${type} *const ${this.getName()}`;
|
||||
if (code) {
|
||||
out += ` = new ${type}(${JSON.stringify(this.getName('::'))}, `;
|
||||
out += `${INTERNAL}thunk<&${this.getName()}>, `;
|
||||
if (isVirtual) {
|
||||
const parentMethod = parentSelf ? this.#getVirtualCall(parentSelf) : 'nullptr';
|
||||
out += `&${this.#getVirtualCall()}, ${parentMethod}`;
|
||||
} else {
|
||||
out += `(${this.#getRawType()} *) ${toHex(this.address)}`;
|
||||
}
|
||||
out += ')';
|
||||
}
|
||||
out += ')\n';
|
||||
out += ';\n';
|
||||
return out;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { formatType } from './common';
|
||||
import { INTERNAL, formatType } from './common';
|
||||
|
||||
export class Property {
|
||||
readonly offset: number;
|
||||
@ -16,7 +16,7 @@ export class Property {
|
||||
|
||||
// Getters
|
||||
type() {
|
||||
return `__type_${this.fullName()}`;
|
||||
return `${INTERNAL}type_${this.fullName()}`;
|
||||
}
|
||||
typedef() {
|
||||
let arrayInfo = '';
|
||||
@ -34,8 +34,14 @@ export class Property {
|
||||
}
|
||||
return name;
|
||||
}
|
||||
#fullName(separator: string) {
|
||||
return this.#self + separator + this.name();
|
||||
}
|
||||
fullName() {
|
||||
return `${this.#self}_${this.name()}`;
|
||||
return this.#fullName('_');
|
||||
}
|
||||
prettyName() {
|
||||
return this.#fullName('::');
|
||||
}
|
||||
rawType() {
|
||||
return this.#type;
|
||||
@ -43,18 +49,8 @@ export class Property {
|
||||
}
|
||||
|
||||
export class StaticProperty extends Property {
|
||||
// Constructor
|
||||
constructor(address: number, type: string, name: string, self: string) {
|
||||
super(address, type, name, self);
|
||||
}
|
||||
|
||||
// Generate Variable Definition
|
||||
globalPointerDefinition() {
|
||||
return `${this.type()} *${this.fullName()}_pointer;\n`;
|
||||
}
|
||||
|
||||
// Generate Macro
|
||||
macro() {
|
||||
return `#define ${this.fullName()} (*${this.fullName()}_pointer)\n`;
|
||||
// Reference
|
||||
referenceDefinition(addSelf: boolean) {
|
||||
return `${this.type()} &${addSelf ? this.prettyName() : this.name()}`;
|
||||
}
|
||||
}
|
217
src/struct.ts
217
src/struct.ts
@ -1,10 +1,10 @@
|
||||
import { INDENT, STRUCTURE_FILES, toHex, assertSize, formatType, getArgNames, removeFirstArg } from './common';
|
||||
import { INDENT, STRUCTURE_FILES, toHex, assertSize, INTERNAL, preventConstruction, LEAN_HEADER_GUARD } from './common';
|
||||
import { Method } from './method';
|
||||
import { Property, StaticProperty } from './property';
|
||||
import { VTable } from './vtable';
|
||||
|
||||
export class Struct {
|
||||
readonly #name: string;
|
||||
readonly name: string;
|
||||
#vtable: VTable | null;
|
||||
readonly #methods: Method[];
|
||||
readonly #properties: Property[];
|
||||
@ -12,10 +12,11 @@ export class Struct {
|
||||
readonly #dependencies: string[];
|
||||
readonly #staticProperties: StaticProperty[];
|
||||
#directParent: string | null;
|
||||
#isSimple: boolean;
|
||||
|
||||
// Constructor
|
||||
constructor(name: string) {
|
||||
this.#name = name;
|
||||
this.name = name;
|
||||
this.#methods = [];
|
||||
this.#properties = [];
|
||||
this.#vtable = null;
|
||||
@ -23,6 +24,7 @@ export class Struct {
|
||||
this.#dependencies = [];
|
||||
this.#staticProperties = [];
|
||||
this.#directParent = null;
|
||||
this.#isSimple = false;
|
||||
}
|
||||
|
||||
// Dependencies
|
||||
@ -34,39 +36,29 @@ export class Struct {
|
||||
}
|
||||
|
||||
// Ensure VTable Exists
|
||||
ensureVTable() {
|
||||
getVTable() {
|
||||
if (this.#vtable === null) {
|
||||
this.#vtable = new VTable(this.#name);
|
||||
this.#vtable = new VTable(this.name);
|
||||
this.addProperty(this.#vtable.property);
|
||||
}
|
||||
}
|
||||
|
||||
// Set VTable Destructor Offset
|
||||
setVTableDestructorOffset(offset: number) {
|
||||
this.ensureVTable();
|
||||
this.#vtable!.setDestructorOffset(offset);
|
||||
return this.#vtable;
|
||||
}
|
||||
|
||||
// Setters
|
||||
setSize(size: number) {
|
||||
this.#size = size;
|
||||
}
|
||||
// Getters
|
||||
getName() {
|
||||
return this.#name;
|
||||
}
|
||||
|
||||
// Add Method
|
||||
addMethod(method: Method, isVirtual: boolean) {
|
||||
if (method.returnType !== this.#name && method.returnType in STRUCTURE_FILES) {
|
||||
if (method.returnType !== this.name && method.returnType in STRUCTURE_FILES) {
|
||||
this.#addDependency(method.returnType);
|
||||
}
|
||||
if (isVirtual) {
|
||||
if (method.self !== this.#name) {
|
||||
if (method.self !== this.name) {
|
||||
throw new Error();
|
||||
}
|
||||
this.ensureVTable();
|
||||
this.#vtable!.add(method);
|
||||
this.getVTable().add(method);
|
||||
} else {
|
||||
if (method.isInherited) {
|
||||
this.#addDependency(method.self);
|
||||
@ -88,14 +80,21 @@ export class Struct {
|
||||
this.#staticProperties.push(property);
|
||||
}
|
||||
|
||||
// Configure VTable
|
||||
setVTableSize(size: number) {
|
||||
this.ensureVTable();
|
||||
this.#vtable!.setSize(size);
|
||||
// "Simple" Structures
|
||||
markAsSimple() {
|
||||
this.#isSimple = true;
|
||||
}
|
||||
setVTableAddress(address: number) {
|
||||
this.ensureVTable();
|
||||
this.#vtable!.setAddress(address);
|
||||
#checkSimple() {
|
||||
const checks: [string, boolean][] = [
|
||||
['Cannot Inherit', this.#directParent !== null],
|
||||
['Must Have A Defined Size', this.#size === null],
|
||||
['Cannot Have A VTable', this.#vtable !== null]
|
||||
];
|
||||
for (const check of checks) {
|
||||
if (check[1]) {
|
||||
throw new Error('Simple Structures ' + check[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate Properties
|
||||
@ -114,10 +113,9 @@ export class Struct {
|
||||
|
||||
// Add Properties
|
||||
let out = '';
|
||||
for (let i = 0; i < sortedProperties.length; i++) {
|
||||
const property = sortedProperties[i]!;
|
||||
const lastProperty = sortedProperties[i - 1];
|
||||
|
||||
let lastProperty: Property | null = null;
|
||||
let i = 0;
|
||||
for (const property of sortedProperties) {
|
||||
// Padding
|
||||
let offsetFromLastProperty = property.offset;
|
||||
if (lastProperty) {
|
||||
@ -127,62 +125,67 @@ export class Struct {
|
||||
if (lastProperty) {
|
||||
paddingSize += ` - sizeof(${lastProperty.type()})`;
|
||||
}
|
||||
out += `${INDENT}uchar __padding${i}[${paddingSize}];\n`;
|
||||
if (!this.#isSimple) {
|
||||
out += `${INDENT}uchar ${INTERNAL}padding${i.toString()}[${paddingSize}];\n`;
|
||||
}
|
||||
|
||||
// The Actual Property
|
||||
if (property !== sizeProperty) {
|
||||
out += `${INDENT}${property.type()} ${property.name()};\n`;
|
||||
}
|
||||
|
||||
// Advance
|
||||
lastProperty = property;
|
||||
i++;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// Generate C++ Method Shortcuts
|
||||
#generateMethod(method: Method, isVirtual: boolean) {
|
||||
let out = '';
|
||||
out += INDENT;
|
||||
if (method.isStatic) {
|
||||
out += 'static ';
|
||||
}
|
||||
out += `decltype(auto) ${method.shortName}(auto&&... args) {\n`;
|
||||
out += `${INDENT}${INDENT}return `;
|
||||
if (isVirtual) {
|
||||
out += `this->vtable->${method.shortName}`;
|
||||
} else {
|
||||
out += `${method.getName()}->get(false)`;
|
||||
}
|
||||
out += '(';
|
||||
if (!method.isStatic) {
|
||||
out += `(${method.self} *) this, `;
|
||||
}
|
||||
out += 'std::forward<decltype(args)>(args)...);\n';
|
||||
out += `${INDENT}}\n`;
|
||||
return out;
|
||||
}
|
||||
#generateMethods() {
|
||||
let out = '';
|
||||
out += LEAN_HEADER_GUARD;
|
||||
// Normal Methods
|
||||
const getArgsOuter = (method: Method) => {
|
||||
let out = method.args;
|
||||
if (!method.isStatic) {
|
||||
// Remove "self"
|
||||
out = removeFirstArg(out);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const getArgsInner = (method: Method) => {
|
||||
const list = getArgNames(method.args);
|
||||
if (!method.isStatic) {
|
||||
// Replace "self" With "this"
|
||||
list[0] = `(${method.self} *) this`;
|
||||
}
|
||||
return list.join(', ');
|
||||
};
|
||||
for (const method of this.#methods) {
|
||||
if (!method.hasVarargs) {
|
||||
const returnType = method.returnType;
|
||||
const shortName = method.shortName;
|
||||
const fullName = method.getName();
|
||||
const args = getArgsOuter(method);
|
||||
out += `${INDENT}inline ${formatType(returnType)}${shortName}${args} { \\\n`;
|
||||
out += `${INDENT}${INDENT}${returnType.trim() === 'void' ? '' : 'return '}${fullName}(${getArgsInner(method)});\n`;
|
||||
out += `${INDENT}}\n`;
|
||||
}
|
||||
out += this.#generateMethod(method, false);
|
||||
}
|
||||
// Virtual Methods
|
||||
if (this.#vtable !== null) {
|
||||
const virtualMethods = this.#vtable.getMethods();
|
||||
for (const method of virtualMethods) {
|
||||
if (method && !method.hasVarargs) {
|
||||
const returnType = method.returnType;
|
||||
const shortName = method.shortName;
|
||||
const args = getArgsOuter(method);
|
||||
out += `${INDENT}inline ${formatType(returnType)}${shortName}${args} { \\\n`;
|
||||
out += `${INDENT}${INDENT}${returnType.trim() === 'void' ? '' : 'return '}this->vtable->${shortName}(${getArgsInner(method)});\n`;
|
||||
out += `${INDENT}}\n`;
|
||||
}
|
||||
out += this.#generateMethod(method, true);
|
||||
}
|
||||
}
|
||||
// Allocation Method
|
||||
if (this.#size !== null) {
|
||||
// THIS DOES NOT CONSTRUCT THE OBJECT
|
||||
out += `${INDENT}static ${this.name} *allocate() {\n`;
|
||||
out += `${INDENT}${INDENT}return (${this.name} *) ::operator new(sizeof(${this.name}));\n`;
|
||||
out += `${INDENT}}\n`;
|
||||
}
|
||||
// Return
|
||||
out += '#endif\n';
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -190,26 +193,19 @@ export class Struct {
|
||||
generate() {
|
||||
let out = '';
|
||||
|
||||
// Static Properties
|
||||
for (const property of this.#staticProperties) {
|
||||
out += property.typedef();
|
||||
out += `extern ${property.globalPointerDefinition()}`;
|
||||
out += property.macro();
|
||||
}
|
||||
|
||||
// Methods
|
||||
for (const method of this.#methods) {
|
||||
if (!method.isInherited) {
|
||||
out += method.generateTypedef();
|
||||
out += `extern ${method.generateDefinition()}`;
|
||||
out += `extern ${method.generateDefinition('_unedited')}`;
|
||||
out += method.generateNewMethodTest(this.#directParent, '', '');
|
||||
}
|
||||
// Check "Simple" Status
|
||||
if (this.#isSimple) {
|
||||
this.#checkSimple();
|
||||
}
|
||||
|
||||
// VTable
|
||||
if (this.#vtable !== null) {
|
||||
out += this.#vtable.generate(this.#directParent);
|
||||
out += this.#vtable.generate();
|
||||
}
|
||||
|
||||
// Static Properties
|
||||
for (const property of this.#staticProperties) {
|
||||
out += property.typedef();
|
||||
}
|
||||
|
||||
// Property Typedefs
|
||||
@ -217,28 +213,44 @@ export class Struct {
|
||||
out += property.typedef();
|
||||
}
|
||||
|
||||
// Method Wrappers
|
||||
let typedefs = '';
|
||||
let methodsOut = '';
|
||||
for (const method of this.#methods) {
|
||||
if (!method.isInherited) {
|
||||
typedefs += method.generateTypedefs();
|
||||
methodsOut += method.generate(false, false);
|
||||
}
|
||||
}
|
||||
out += typedefs;
|
||||
out += LEAN_HEADER_GUARD;
|
||||
out += methodsOut;
|
||||
out += '#endif\n';
|
||||
|
||||
// Structure
|
||||
out += `struct ${this.#name} {\n`;
|
||||
out += `struct ${this.name} final {\n`;
|
||||
out += this.#generateProperties();
|
||||
out += this.#generateMethods();
|
||||
for (const property of this.#staticProperties) {
|
||||
// Static Property References
|
||||
out += `${INDENT}static ${property.referenceDefinition(false)};\n`;
|
||||
}
|
||||
if (!this.#isSimple) {
|
||||
// Disable Construction Of Complex Structures
|
||||
out += preventConstruction(this.name);
|
||||
}
|
||||
out += `};\n`;
|
||||
|
||||
// Sanity Check Offsets
|
||||
for (let i = 0; i < this.#properties.length; i++) {
|
||||
const property = this.#properties[i]!;
|
||||
for (const property of this.#properties) {
|
||||
const name = property.name();
|
||||
const offset = property.offset;
|
||||
out += `static_assert(offsetof(${this.#name}, ${name}) == ${toHex(offset)}, "Invalid Offset");\n`;
|
||||
out += `static_assert(offsetof(${this.name}, ${name}) == ${toHex(offset)}, "Invalid Offset");\n`;
|
||||
}
|
||||
|
||||
// Sanity Check Size
|
||||
if (this.#size !== null) {
|
||||
out += assertSize(this.#name, this.#size);
|
||||
}
|
||||
|
||||
// Allocation Function
|
||||
if (this.#size !== null) {
|
||||
out += `${this.#name} *alloc_${this.#name}();\n`;
|
||||
out += assertSize(this.name, this.#size);
|
||||
}
|
||||
|
||||
// Return
|
||||
@ -247,41 +259,28 @@ export class Struct {
|
||||
|
||||
// Generate Compiled Code
|
||||
generateCode() {
|
||||
let declarations = '';
|
||||
let init = '';
|
||||
let out = '';
|
||||
|
||||
// Static Properties
|
||||
for (const property of this.#staticProperties) {
|
||||
init += `${INDENT}${property.fullName()}_pointer = (${property.type()} *) ${toHex(property.offset)};\n`;
|
||||
declarations += property.globalPointerDefinition();
|
||||
out += `${property.referenceDefinition(true)} = *(${property.type()} *) ${toHex(property.offset)};\n`;
|
||||
}
|
||||
|
||||
// Methods
|
||||
for (const method of this.#methods) {
|
||||
if (!method.isInherited) {
|
||||
init += `${INDENT}${method.getName()} = (${method.getType()}) ${toHex(method.address)};\n`;
|
||||
declarations += method.generateDefinition();
|
||||
init += `${INDENT}${method.getName()}_unedited = (${method.getType()}) ${toHex(method.address)};\n`;
|
||||
declarations += method.generateDefinition('_unedited');
|
||||
out += method.generate(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
// VTable
|
||||
if (this.#vtable !== null) {
|
||||
const vtable = this.#vtable.generateCode();
|
||||
declarations += vtable.declarations;
|
||||
init += vtable.init;
|
||||
}
|
||||
|
||||
// Allocation Function
|
||||
if (this.#size !== null) {
|
||||
declarations += `${this.#name} *alloc_${this.#name}() {\n`;
|
||||
declarations += `${INDENT}return new ${this.#name};\n`;
|
||||
declarations += '}\n';
|
||||
const vtable = this.#vtable.generateCode(this.#directParent);
|
||||
out += vtable;
|
||||
}
|
||||
|
||||
// Return
|
||||
return {functions: declarations, init};
|
||||
return out;
|
||||
}
|
||||
|
||||
// Set Direct Parent (Used For "New Method" Testing)
|
||||
|
67
src/test/common.ts
Normal file
67
src/test/common.ts
Normal file
@ -0,0 +1,67 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { formatType, parseTypeAndName, prependArg, toUpperSnakeCase } from '../common';
|
||||
|
||||
describe('Parsing Variable Declarations', () => {
|
||||
const tests: [string, string, string, string][] = [
|
||||
['Simple', 'int x', 'int', 'x'],
|
||||
['Pointer', 'int *y', 'int *', 'y'],
|
||||
['Ugly Pointer', 'int* z', 'int*', 'z'],
|
||||
['Double Pointer', 'int **a', 'int **', 'a'],
|
||||
['Ugly Double Pointer', 'int* *b', 'int**', 'b'],
|
||||
['Reference', 'int &c', 'int &', 'c'],
|
||||
['Reference-To-Pointer', 'int *&d', 'int *&', 'd']
|
||||
];
|
||||
for (const test of tests) {
|
||||
it(test[0], () => {
|
||||
const obj = parseTypeAndName(test[1]);
|
||||
assert.strictEqual(obj.type, test[2]);
|
||||
assert.strictEqual(obj.name, test[3]);
|
||||
});
|
||||
}
|
||||
it('Invalid', () => {
|
||||
assert.throws(() => {
|
||||
parseTypeAndName('abc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Upper-Snake-Case', () => {
|
||||
const tests: [string, string, string][] = [
|
||||
['One Word', 'Hello', 'HELLO'],
|
||||
['Two Words', 'HelloWorld', 'HELLO_WORLD'],
|
||||
['Empty', '', ''],
|
||||
['All Uppercase', 'HELLO', 'HELLO'],
|
||||
['All Lowercase', 'hello', 'HELLO']
|
||||
];
|
||||
for (const test of tests) {
|
||||
it(test[0], () => {
|
||||
assert.strictEqual(toUpperSnakeCase(test[1]), test[2]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('Formatting Types For Concatenation', () => {
|
||||
const tests: [string, string, string][] = [
|
||||
['Value', 'int', 'int '],
|
||||
['Pointer', 'int *', 'int *'],
|
||||
['Reference', 'int &', 'int &']
|
||||
];
|
||||
for (const test of tests) {
|
||||
it(test[0], () => {
|
||||
assert.strictEqual(formatType(test[1]), test[2]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('Prepending Arguments To Functions', () => {
|
||||
const tests: [string, string, string, string][] = [
|
||||
['Empty', '()', 'int x', '(int x)'],
|
||||
['Non-Empty', '(int x)', 'int y', '(int y, int x)']
|
||||
];
|
||||
for (const test of tests) {
|
||||
it(test[0], () => {
|
||||
assert.strictEqual(prependArg(test[1], test[2]), test[3]);
|
||||
});
|
||||
}
|
||||
});
|
127
src/vtable.ts
127
src/vtable.ts
@ -1,7 +1,8 @@
|
||||
import { INDENT, POINTER_SIZE, RTTI_SIZE, assertSize, getSelfArg, toHex } from './common';
|
||||
import { INDENT, LEAN_HEADER_GUARD, POINTER_SIZE, assertSize, getSelfArg, preventConstruction, toHex } from './common';
|
||||
import { Method } from './method';
|
||||
import { Property } from './property';
|
||||
|
||||
const structuresWithVTableAddress: string[] = [];
|
||||
export class VTable {
|
||||
readonly #self: string;
|
||||
#address: number | null;
|
||||
@ -24,6 +25,7 @@ export class VTable {
|
||||
// Setters
|
||||
setAddress(address: number) {
|
||||
this.#address = address;
|
||||
structuresWithVTableAddress.push(this.#self);
|
||||
}
|
||||
setSize(size: number) {
|
||||
this.#size = size;
|
||||
@ -41,7 +43,7 @@ export class VTable {
|
||||
}
|
||||
// Add
|
||||
const index = offset / POINTER_SIZE;
|
||||
if (target[index]) {
|
||||
if (index in target) {
|
||||
throw new Error(`Duplicate Virtual Method At Offset: ${toHex(offset)}`);
|
||||
}
|
||||
target[index] = method;
|
||||
@ -84,34 +86,67 @@ export class VTable {
|
||||
return out;
|
||||
}
|
||||
|
||||
// Get Parent Method
|
||||
#getParentSelf(method: Method, parent: string | null) {
|
||||
if (method.isInherited && parent) {
|
||||
// Parent Exists
|
||||
let out: string;
|
||||
if (structuresWithVTableAddress.includes(parent)) {
|
||||
out = parent;
|
||||
} else {
|
||||
// Unable To Determine
|
||||
out = this.#self;
|
||||
}
|
||||
return out;
|
||||
} else {
|
||||
// Method Has No Parent
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate Header Code
|
||||
generate(directParent: string | null) {
|
||||
canGenerateWrappers() {
|
||||
return this.#address !== null;
|
||||
}
|
||||
generate() {
|
||||
let out = '';
|
||||
|
||||
// Check
|
||||
this.#check();
|
||||
|
||||
// Method Prototypes
|
||||
// Wrappers
|
||||
const methods = this.getMethods();
|
||||
for (let i = 0; i < methods.length; i++) {
|
||||
const info = methods[i];
|
||||
if (info) {
|
||||
out += info.generateTypedef();
|
||||
let typedefs = '';
|
||||
let methodsOut = '';
|
||||
for (const info of methods) {
|
||||
typedefs += info.generateTypedefs();
|
||||
if (this.canGenerateWrappers()) {
|
||||
methodsOut += info.generate(false, true);
|
||||
}
|
||||
}
|
||||
out += typedefs;
|
||||
out += LEAN_HEADER_GUARD;
|
||||
out += methodsOut;
|
||||
out += '#endif\n';
|
||||
|
||||
// Structure
|
||||
out += `typedef struct ${this.#getName()} ${this.#getName()};\n`;
|
||||
out += `struct ${this.#getName()} {\n`;
|
||||
out += `struct ${this.#getName()} final {\n`;
|
||||
for (let i = 0; i < methods.length; i++) {
|
||||
let name = `unknown${i}`;
|
||||
let type = 'void *';
|
||||
const info = methods[i];
|
||||
if (info) {
|
||||
name = info.shortName;
|
||||
type = info.getType() + ' ';
|
||||
out += info.getProperty();
|
||||
} else {
|
||||
out += `${INDENT}void *unknown${i.toString()};\n`;
|
||||
}
|
||||
out += `${INDENT}${type}${name};\n`;
|
||||
}
|
||||
if (this.#size === null) {
|
||||
// Prevent Construction
|
||||
out += preventConstruction(this.#getName());
|
||||
}
|
||||
if (this.#address !== null) {
|
||||
// Base
|
||||
out += `${INDENT}static ${this.#getName()} *base;\n`;
|
||||
}
|
||||
out += `};\n`;
|
||||
|
||||
@ -120,35 +155,13 @@ export class VTable {
|
||||
out += assertSize(this.#getName(), this.#size);
|
||||
}
|
||||
|
||||
// Pointers
|
||||
if (this.#address !== null) {
|
||||
// Base
|
||||
out += `extern ${this.#getName()} *${this.#getName()}_base;\n`;
|
||||
// Methods
|
||||
for (let i = 0; i < methods.length; i++) {
|
||||
const info = methods[i];
|
||||
if (info) {
|
||||
const type = `${info.getType()} *`;
|
||||
out += `extern ${type}${info.getName()}_vtable_addr;\n`;
|
||||
out += `extern ${info.generateDefinition('_non_virtual')}`;
|
||||
out += info.generateNewMethodTest(directParent, '*', '_vtable_addr');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Duplication Method
|
||||
if (this.#size !== null) {
|
||||
out += `${this.#getName()} *dup_${this.#getName()}(${this.#getName()} *vtable);\n`;
|
||||
}
|
||||
|
||||
// Return
|
||||
return out;
|
||||
}
|
||||
|
||||
// Generate Compiled Code
|
||||
generateCode() {
|
||||
let declarations = '';
|
||||
let init = '';
|
||||
generateCode(directParent: string | null) {
|
||||
let out = '';
|
||||
|
||||
// Check
|
||||
this.#check();
|
||||
@ -156,40 +169,18 @@ export class VTable {
|
||||
// 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
|
||||
out += `${this.#getName()} *${this.#getName()}::base = (${this.#getName()} *) ${toHex(this.#address)};\n`;
|
||||
}
|
||||
|
||||
// Method Wrappers
|
||||
if (this.canGenerateWrappers()) {
|
||||
const methods = this.getMethods();
|
||||
for (let i = 0; i < methods.length; i++) {
|
||||
const info = 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');
|
||||
}
|
||||
for (const info of methods) {
|
||||
out += info.generate(true, true, this.#getParentSelf(info, directParent));
|
||||
}
|
||||
}
|
||||
|
||||
// Duplication Method
|
||||
if (this.#size !== null) {
|
||||
declarations += `${this.#getName()} *dup_${this.#getName()}(${this.#getName()} *vtable) {\n`;
|
||||
declarations += `${INDENT}uchar *real_vtable = (uchar *) vtable;\n`;
|
||||
declarations += `${INDENT}real_vtable -= ${RTTI_SIZE};\n`;
|
||||
declarations += `${INDENT}size_t real_vtable_size = sizeof(${this.#getName()}) + ${RTTI_SIZE};\n`;
|
||||
declarations += `${INDENT}uchar *new_vtable = (uchar *) ::operator new(real_vtable_size);\n`;
|
||||
declarations += `${INDENT}if (new_vtable == NULL) {\n`;
|
||||
declarations += `${INDENT}${INDENT}return NULL;\n`;
|
||||
declarations += `${INDENT}}\n`;
|
||||
declarations += `${INDENT}memcpy((void *) new_vtable, (void *) real_vtable, real_vtable_size);\n`;
|
||||
declarations += `${INDENT}new_vtable += ${RTTI_SIZE};\n`;
|
||||
declarations += `${INDENT}return (${this.#getName()} *) new_vtable;\n`;
|
||||
declarations += '}\n';
|
||||
}
|
||||
|
||||
// Return
|
||||
return {declarations, init};
|
||||
return out;
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
syntax def "\.def$"
|
||||
comment "//"
|
||||
|
||||
# Mistakes
|
||||
# Missing semicolon
|
||||
color red "[^;]$"
|
||||
# Missing type
|
||||
color red "^(((static|virtual)-)?method|property|static-property(-array)?) [a-zA-Z_][a-zA-Z0-9_]* ?(\(|=)"
|
||||
# Missing prefix
|
||||
color red "^[^ ]+"
|
||||
# Missing vtable
|
||||
color red "^(vtable(-size|-destructor-offset))? .+$"
|
||||
|
||||
# Reset
|
||||
color normal "(\(|\))"
|
||||
|
||||
# Commands
|
||||
color magenta "^(extends|size|vtable(-size|-destructor-offset)?|property|static-property|((static|virtual)-)?method|constructor)\>"
|
||||
|
||||
# Types
|
||||
color green "\<((u?(char|short|int))|float|bool|void|std::(string|vector|map))\>"
|
||||
|
||||
# Numbers
|
||||
color yellow "0x[a-f0-9]+"
|
||||
# Non-hex numbers
|
||||
color red " [0-9][a-f0-9]+;"
|
||||
|
||||
# Comments
|
||||
color brightblue "//.*"
|
||||
|
||||
# Whitespace.
|
||||
color normal "[[:space:]]+"
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
@ -13,8 +13,10 @@
|
||||
<item>static-method</item>
|
||||
<item>constructor</item>
|
||||
<item>vtable-destructor-offset</item>
|
||||
<item>mark-as-simple</item>
|
||||
</list>
|
||||
<list name="types">
|
||||
<item>const</item>
|
||||
<item>char</item>
|
||||
<item>uchar</item>
|
||||
<item>short</item>
|
21
syntax-highlighting/nano/symbol-processor.nanorc
Normal file
21
syntax-highlighting/nano/symbol-processor.nanorc
Normal file
@ -0,0 +1,21 @@
|
||||
syntax def "\.def$"
|
||||
comment "//"
|
||||
|
||||
# Commands
|
||||
color magenta "\<(extends|size|vtable(-size|-destructor-offset)?|property|static-property|((static|virtual)-)?method|constructor|mark-as-simple)\>"
|
||||
|
||||
# Types
|
||||
color green "\<((u?(char|short|int))|float|bool|void|std::(string|vector|map))\>"
|
||||
|
||||
# Numbers
|
||||
color yellow "0x[a-f0-9]+"
|
||||
# Non-hex numbers
|
||||
color red " [0-9][a-f0-9]+;"
|
||||
|
||||
# Comments
|
||||
color brightblue "//.*"
|
||||
|
||||
# Whitespace.
|
||||
color normal "[[:space:]]+"
|
||||
# Trailing whitespace.
|
||||
color ,green "[[:space:]]+$"
|
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>Comments</string>
|
||||
<key>scope</key>
|
||||
<string>source.toml</string>
|
||||
<key>settings</key>
|
||||
<dict>
|
||||
<key>shellVariables</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>TM_COMMENT_START</string>
|
||||
<key>value</key>
|
||||
<string>//</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
<key>uuid</key>
|
||||
<string>C5C885D7-2733-4632-B709-B5B9DD518F90</string>
|
||||
</dict>
|
||||
</plist>
|
@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>fileTypes</key>
|
||||
<array>
|
||||
<string>def</string>
|
||||
</array>
|
||||
<key>scopeName</key>
|
||||
<string>source.symbol-processor</string>
|
||||
<key>name</key>
|
||||
<string>Symbol Processor Definition</string>
|
||||
<key>patterns</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>comment.line.double-slash.symbol-processor</string>
|
||||
<key>match</key>
|
||||
<string>//.*$</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>constant.numeric.symbol-processor.hex</string>
|
||||
<key>match</key>
|
||||
<string>\b0[xX][0-9a-fA-F]+</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>constant.numeric.symbol-processor.decimal</string>
|
||||
<key>match</key>
|
||||
<string>\b[0-9]+</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>keyword.control.symbol-processor</string>
|
||||
<key>match</key>
|
||||
<string>\b(extends|size|vtable-size|vtable-destructor-offset|vtable|property|static-property|method|virtual-method|static-method|constructor|mark-as-simple)\b</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>storage.type.symbol-processor</string>
|
||||
<key>match</key>
|
||||
<string>\b(const|char|uchar|short|ushort|int|uint|float|bool|void|std::string|std::vector|std::map|unsigned|long)\b</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>name</key>
|
||||
<string>keyword.operator.symbol-processor</string>
|
||||
<key>match</key>
|
||||
<string>(=|;)</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>uuid</key>
|
||||
<string>D44198D4-5AEB-40E5-B4E4-0E11C69FFA42</string>
|
||||
</dict>
|
||||
</plist>
|
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>contactEmailRot13</key>
|
||||
<string>connor24nolan@live.com</string>
|
||||
<key>contactName</key>
|
||||
<string>TheBrokenRail</string>
|
||||
<key>description</key>
|
||||
<string>Symbol Processor Definition File</string>
|
||||
<key>name</key>
|
||||
<string>Symbol Processor</string>
|
||||
<key>uuid</key>
|
||||
<string>8209EEB8-4193-4E63-BDBB-0407E47ADF50</string>
|
||||
</dict>
|
||||
</plist>
|
@ -1,11 +1,11 @@
|
||||
{
|
||||
"extends": [
|
||||
"@tsconfig/strictest/tsconfig",
|
||||
"@tsconfig/node-lts/tsconfig"
|
||||
"@tsconfig/node18/tsconfig"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./build"
|
||||
"outDir": "build",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
|
Loading…
x
Reference in New Issue
Block a user