mirror of
https://github.com/Ed94/gencpp.git
synced 2025-07-01 11:21:04 -07:00
Compare commits
45 Commits
9b059dca47
...
v0.20-Alph
Author | SHA1 | Date | |
---|---|---|---|
2a025cb073 | |||
0e782cdf99 | |||
a390e7f895 | |||
65427bd0f1 | |||
cb898595b0 | |||
9b86d84dd6 | |||
4dfb9031d7 | |||
401f85f673 | |||
caec5d8dfc | |||
44d0a9cf9d | |||
c0aa4fee95 | |||
913d9bf26b | |||
c8d6c27f07 | |||
aecc2c59dd | |||
0e32838da1 | |||
ef78772278 | |||
8891657eb1 | |||
a18b5b97aa | |||
0ea88a263d | |||
eea4ebf5c4 | |||
7351ba6175 | |||
8e3e66b3c1 | |||
2c51a2f9c8 | |||
e3b3882443 | |||
0046c4a223 | |||
5aaef0f1a2 | |||
abdad1a436 | |||
a4143b537d | |||
0ccffe3f80 | |||
cd7548c3d4 | |||
79a1951861 | |||
e786d7c3b6 | |||
e6f30c7e1d | |||
6147912783 | |||
ed9f719a07 | |||
500f216da2 | |||
12e31276eb | |||
65c3fabc52 | |||
c016e245eb | |||
99dbc499fa | |||
1c133bfc8d | |||
451b71884c | |||
4d638a7255 | |||
ceea184d5a | |||
92e0d3ab8b |
14
.vscode/bookmarks.json
vendored
14
.vscode/bookmarks.json
vendored
@ -1,14 +0,0 @@
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"path": "project/auxillary/vis_ast/dependencies/temp/raylib-master/src/rcamera.h",
|
||||
"bookmarks": [
|
||||
{
|
||||
"line": 140,
|
||||
"column": 14,
|
||||
"label": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
41
.vscode/c_cpp_properties.json
vendored
41
.vscode/c_cpp_properties.json
vendored
@ -1,9 +1,9 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32 msvc",
|
||||
"name": "Bootstrap",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
"${workspaceFolder}/base/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
@ -15,15 +15,44 @@
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json",
|
||||
"compilerArgs": [
|
||||
"/EHsc-",
|
||||
"/GR-",
|
||||
"/Zc:preprocessor",
|
||||
"/FC"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Win32 msvc c_library",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/gen_c_library/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 clang",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
"${workspaceFolder}/base/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
@ -36,9 +65,9 @@
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
|
||||
"compilerPath": "clang++.exe",
|
||||
"intelliSenseMode": "windows-clang-x64",
|
||||
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
45
.vscode/launch.json
vendored
45
.vscode/launch.json
vendored
@ -4,39 +4,20 @@
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug gentime lldb",
|
||||
"program": "${workspaceFolder}/test/test.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/test/",
|
||||
"postRunCommands": [
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug gentime vsdbg",
|
||||
"program": "${workspaceFolder}/test/build/test.exe",
|
||||
"name": "Debug base vsdbg",
|
||||
"program": "${workspaceFolder}/base/build/base.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/test/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug bootstrap vsdbg",
|
||||
"program": "${workspaceFolder}/project/build/bootstrap.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/project/",
|
||||
"cwd": "${workspaceFolder}/base/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug singleheader vsdbg",
|
||||
"program": "${workspaceFolder}/singleheader/build/gencpp_singleheader.exe",
|
||||
"program": "${workspaceFolder}/singleheader/build/singleheader.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/singleheader/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
@ -49,24 +30,6 @@
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/unreal_engine/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug raylib refactor vsdbg",
|
||||
"program": "${workspaceFolder}/project/auxillary/vis_ast/dependencies/raylib/build/raylib_refactor.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/project/auxillary/vis_ast/dependencies/temp/raylib-master/src/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug VIS AST",
|
||||
"program": "${workspaceFolder}/project/auxillary/vis_ast/binaries/vis_ast.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/project/auxillary/vis_ast/binaries/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -67,8 +67,10 @@
|
||||
"C_Cpp.files.exclude": {
|
||||
"**/.vscode": true,
|
||||
"**/.vs": true,
|
||||
"**/sanity.gen.hpp": true
|
||||
"**/sanity.gen.hpp": true,
|
||||
"test/**":true,
|
||||
},
|
||||
"autoHide.autoHidePanel": false,
|
||||
"autoHide.autoHideSideBar": false
|
||||
"autoHide.autoHideSideBar": false,
|
||||
"dimmer.enabled": false
|
||||
}
|
||||
|
144
.vscode/tasks.json
vendored
Normal file
144
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build Bootstrap",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"bootstrap",
|
||||
"msvc"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"relative",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(warning|error)\\s*(\\w+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build C Library",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"c_library",
|
||||
"msvc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"relative",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(warning|error)\\s*(\\w+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build Singleheader (MSVC)",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"singleheader",
|
||||
"msvc",
|
||||
"debug"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(error|warning|info|note)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build Unreal (MSVC)",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"unreal",
|
||||
"msvc",
|
||||
"debug"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(error|warning|info|note)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
36
Readme.md
36
Readme.md
@ -1,16 +1,29 @@
|
||||
# gencpp
|
||||
|
||||
An attempt at simple staged metaprogramming for c/c++.
|
||||
An attempt at simple staged metaprogramming for C/C++.
|
||||
|
||||
The library API is a composition of code element constructors.
|
||||
These build up a code AST to then serialize with a file builder.
|
||||
The library API is a composition of code element constructors, and a non-standards-compliant single-pass C/C++ parser.
|
||||
These build up a code AST to then serialize with a file builder, or can be traversed for staged-reflection of C/C++ code.
|
||||
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
|
||||
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
|
||||
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
|
||||
|
||||
## Documentation
|
||||
|
||||
* [docs - General](./docs/Readme.md): Overview and additional docs
|
||||
* [AST_Design](./docs/AST_Design.md): Overvie of ASTs
|
||||
* [AST Types](./docs/AST_Types.md): Listing of all AST types along with their Code type interface.
|
||||
* [Parsing](./docs/Parsing.md): Overview of the parsing interface.
|
||||
* [Parser Algo](./docs/Parser_Algo.md): In-depth breakdown of the parser's implementation.
|
||||
* [base](./base/Readme.md): Essential (base) library.
|
||||
* [gen_c_library](./gen_c_library/): C11 library variant generation (single header and segmeented).
|
||||
* [gen_segmented](./gen_segmented/): Segemented C++ (`gen.<hpp/cpp>`, `gen.dep.<hpp/cpp>`) generation
|
||||
* [gen_singleheader](./gen_singleheader/): Singlehader C++ generation `gen.hpp`
|
||||
* [gen_unreal_engine](./gen_unreal_engine/): Unreal Engine thirdparty code generation.
|
||||
|
||||
## Notes
|
||||
|
||||
**On Partial Hiatus: Life has got me tackling other issues..**
|
||||
**On Partial Hiatus: Life has got me tackling other issues..**
|
||||
I will be passively updating the library with bug fixes and minor improvements as I use it for my personal projects.
|
||||
There won't be any major reworks or features to this thing for a while.
|
||||
|
||||
@ -21,17 +34,13 @@ The library can already be used to generate code just fine, but the parser is wh
|
||||
|
||||
A `natvis` and `natstepfilter` are provided in the scripts directory (its outdated, I'll update this readme when its not).
|
||||
|
||||
***The editor and scanner have not been implemented yet. The scanner will come first, then the editor.***
|
||||
|
||||
A C variant is hosted [here](https://github.com/Ed94/genc); I will complete it when this library is feature complete, it should be easier to make than this...
|
||||
|
||||
## Usage
|
||||
|
||||
A metaprogram is built to generate files before the main program is built. We'll term runtime for this program as `GEN_TIME`. The metaprogram's core implementation are within `gen.hpp` and `gen.cpp` in the project directory.
|
||||
|
||||
`gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated.
|
||||
|
||||
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't required at all):
|
||||
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't the best to use):
|
||||
|
||||
Within `program.cpp` :
|
||||
|
||||
@ -54,7 +63,6 @@ u32 gen_main()
|
||||
|
||||
// Regular runtime dependent on the generated code here.
|
||||
#endif
|
||||
|
||||
```
|
||||
|
||||
The design uses a constructive builder API for the code to generate.
|
||||
@ -115,7 +123,7 @@ Code header = code_str(
|
||||
|
||||
`name` is a helper macro for providing a string literal with its size, intended for the name parameter of functions.
|
||||
`code` is a helper macro for providing a string literal with its size, but intended for code string parameters.
|
||||
`args` is a helper macro for providing the number of arguments to varadic constructors.
|
||||
`args` is a helper macro for providing the number of arguments to varadic constructors.
|
||||
`code_str` is a helper macro for writting `untyped_str( code( <content> ))`
|
||||
|
||||
All three constrcuton interfaces will generate the following C code:
|
||||
@ -129,7 +137,7 @@ struct ArrayHeader
|
||||
};
|
||||
```
|
||||
|
||||
**Note: The formatting shown here is not how it will look. For your desired formatting its recommended to run a pass through the files with an auto-formatter.**
|
||||
**Note: The formatting shown here is not how it will look. For your desired formatting its recommended to run a pass through the files with an auto-formatter.**
|
||||
*(The library currently uses clang-format for formatting, beware its pretty slow...)*
|
||||
|
||||
## Building
|
||||
|
154
base/Readme.md
Normal file
154
base/Readme.md
Normal file
@ -0,0 +1,154 @@
|
||||
## Navigation
|
||||
|
||||
# base
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
* [docs](../docs/Readme.md)
|
||||
|
||||
The library is fragmented into a series of headers and source files meant to be scanned in and then generated to a standard target format, or a user's desires.
|
||||
|
||||
Standard formats:
|
||||
|
||||
* **base**: Files are in granular pieces separated into four directories:
|
||||
* **dependencies**: Originally from the c-zpl library and modified thereafter.
|
||||
* **components**: The essential definitions of the library.
|
||||
* **helpers**: Contains helper functionality used by base and other libraries to regenerate or generate the other library formats.
|
||||
* `base_codegen.hpp`: Helps with self-hosted code generation of enums, and operator overload inlines of the code types.
|
||||
* `<push/pop>.<name>.inline.<hpp>`: macros that are meant to be injected at specific locations of the library.
|
||||
* `misc.hpp`: Misc functionality used by the library generation metaprograms.
|
||||
* `undef.macros.h`: Undefines all macros from library that original were intended to leak into user code.
|
||||
* **auxillary**: Non-essential tooling:
|
||||
* `Builder`: Similar conceptually to Jai programming language's *builder*, just opens a file and prepares a string buffer to serialize code into (`builder_print`, `builder_print_fmt`). Then write & close the file when completed (`builder_write`).
|
||||
* **`Scanner`**: Interface to load up `Code` from files two basic funcctions are currently provided.
|
||||
* `scan_file`: Used mainly by the library format generators to directly scan files into untyped `Code` (raw string content, pre-formatted no AST parsed).
|
||||
* `parse_file`: Used to read file and then parsed to populate a `CodeBody` AST.
|
||||
* CSV parsing via one or two columns simplified.
|
||||
* **gen_segemetned**: Dependencies go into gen.dep.{hpp/cpp} and components into gen.{hpp/cpp}
|
||||
* **gen_singleheader**: Everything into a single file: gen.hpp
|
||||
* **gen_unreal_engine**: Like gen_segemented but the library is modified slightly to compile as a thirdparty library within an Unreal Engine plugin or module.
|
||||
* **gen_c_library**: The library is heavily modifed into C11 compliant code. A segemented and single-header set of variants are generatd.
|
||||
|
||||
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
|
||||
|
||||
## Dependencies
|
||||
|
||||
The project has no external dependencies beyond:
|
||||
|
||||
* `errno.h`
|
||||
* `stat.h`
|
||||
* `stdarg.h`
|
||||
* `stddef.h`
|
||||
* `stdio.h`
|
||||
* `copyfile.h` (Mac)
|
||||
* `types.h` (Linux)
|
||||
* `sys/man.h` (Linux)
|
||||
* `fcntl.h` (POSXIX Filesystem)
|
||||
* `unistd.h` (Linux/Mac)
|
||||
* `intrin.h` (Windows)
|
||||
* `io.h` (Windows with gcc)
|
||||
* `windows.h` (Windows)
|
||||
|
||||
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
|
||||
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
|
||||
|
||||
See the following files for any updates:
|
||||
|
||||
* [`platform.hpp`](./dependencies/platform.hpp)
|
||||
* [`src_start.cpp`](./dependencies/src_start.cpp)
|
||||
* [`filesystem.cpp`](./dependencies/filesystem.cpp)
|
||||
* [`memory.cpp`](./dependencies/memory.cpp)
|
||||
|
||||
## Conventions
|
||||
|
||||
This library was written in a subset of C++ where the following are not used at all:
|
||||
|
||||
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
|
||||
* Language provide dynamic dispatch, RTTI
|
||||
* Object-Oriented Inheritance
|
||||
* Exceptions
|
||||
|
||||
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
|
||||
The base library itself does not use anything but C-like features to allow for generating a derviative compatiable with C.
|
||||
|
||||
Member function support or free-functions with reference object passing are wrapped in `! GEN_C_LIKE CPP` preprocess conditionals.
|
||||
|
||||
## C++ template usage
|
||||
|
||||
There are only 4 template definitions in the entire library (C++ versions). (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `tmpl_cast<CodeT>(CodeT code)`)
|
||||
|
||||
Two generic templated containers are used throughout the library:
|
||||
|
||||
* `template< class Type> struct Array`
|
||||
* `template< class Type> struct HashTable`
|
||||
|
||||
`tmpl_cast<CodeT>(CodeT code)` is just an alternative way to explicitly cast to code. Its usage is wrapped in a macro called `cast` for the base library (needed for interoperability with C).
|
||||
|
||||
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
|
||||
|
||||
Otherwise the library is free of any templates.
|
||||
|
||||
## Macro usage
|
||||
|
||||
Since this is a meta-programming library, it was desired to keep both templates and macros (especially macros) usage very limited.
|
||||
|
||||
Most macros are defined within [macros.hpp](./dependencies/macros.hpp).
|
||||
|
||||
The most advanced macro usage is `num_args` which is a helper for counting the number of arguments of another macro.
|
||||
|
||||
Any large macros used implementing the gen interface or parser are going to be phased out in favor of just forcinlined functions.
|
||||
*(Unless there is a hot-path that requires them)*
|
||||
|
||||
The vast majority of macros should be single-line subsitutions that either add:
|
||||
|
||||
* Improvements to searching
|
||||
* Inteniality of keyword usage
|
||||
* A feature that only the preprocessor has (ex: function name reflection or stringifying)
|
||||
* Compatibility of statements or expressions bewteen C & C++ that cannot be parsed by gencpp itself.
|
||||
* Masking highly verbose syntax (the latter is getting phased out).
|
||||
|
||||
[gen_c_library](../gen_c_library/) has the most advanced set of macros for c11's generic selection.
|
||||
|
||||
* A significant amount of explicit code geneeration is utilized to keep abuse of the preprocessor to the absolute minimum.
|
||||
* There is a heavy set of documentation inlined wth them; their naming is also highly verbose and explicit.
|
||||
* See its documentation for more information.
|
||||
|
||||
## On base code generation
|
||||
|
||||
There are ***five*** header files which are automatically generated using [base_codegen.hpp](./helpers/base_codegen.hpp) by [base.cpp](./base.cpp). They are all located in [components/gen](./components/gen/).
|
||||
|
||||
* [`ecodetypes.hpp`](./components/gen/ecode.hpp): `CodeType` enum definition and related implementaiton. Generation is based off of [`ECodeType.csv](./enums/ECodeTypes.csv).
|
||||
* [`especifier.hpp`](./components/gen/especifier.hpp): `Specifier` enum definition, etc. Generated using [`ESpecifier.csv`](./enums/ESpecifier.csv).
|
||||
* [`eoperator.hpp`](./components/gen/eoperator.hpp): `Operator` enum definition, etc. Generated using [`EOperator.hpp`](./enums/EOperator.csv).
|
||||
* [`etoktype.cpp`](./components/gen/etoktype.cpp): `TokType` enum defininition, etc. Used by the lexer and parser backend. Uses two csvs:
|
||||
* [`ETokType.csv`](./enums/ETokType.csv): Provides the enum entries and their strinng ids.
|
||||
* [`AttributeTokens.csv`](./enums/AttributeTokens.csv): Provides tokens entries that should be considered as attributes by the lexer and parser. Sspecfiically macro attributes such as those use for exporting symbols.
|
||||
* [`ast_inlines.hpp`](./components/gen/ast_inlines.hpp): Member trivial `operator` definitions for C++ code types. Does not use a csv.
|
||||
|
||||
[`misc.hpp`](./helpers/misc.hpp): Has shared functions used by the library generation meta-programs throughout this codebase.
|
||||
|
||||
## On multi-threading
|
||||
|
||||
Currently unsupported. I want the library to be *stable* and *correct*, with the addition of exhausting all basic single-threaded optimizations before I consider multi-threading.
|
||||
|
||||
## Extending the library
|
||||
|
||||
This library is relatively very small (for parsing C++), and can be extended without much hassle.
|
||||
|
||||
The convention you'll see used throughout the upfront interface of the library is as follows:
|
||||
|
||||
1. Check name or parameters to make sure they are valid for the construction requested
|
||||
2. Create a code object using `make_code`.
|
||||
3. Populate immediate fields (Name, Type, ModuleFlags, etc)
|
||||
4. Populate sub-entires using `add_entry`. If using the default serialization function `to_string`, follow the order at which entires are expected to appear (there is a strong ordering expected).
|
||||
|
||||
Names or Content fields are interned strings and thus showed be cached using `get_cached_string` if its desired to preserve that behavior.
|
||||
|
||||
`def_operator` is the most sophisticated upfront constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
|
||||
|
||||
The parser is documented under [`docs/Parsing.md`](../docs/Parsing.md) and [`docs/Parser_Algo.md`](../docs/Parser_Algo.md). Extending it is more serious.
|
||||
|
||||
## A note on compilation and runtime generation speed
|
||||
|
||||
The library is designed to be fast to compile and generate code at runtime as fast as resonable possible on a debug build.
|
||||
Its recommended that your metaprogam be compiled using a single translation unit (unity build).
|
@ -2,7 +2,9 @@
|
||||
# include "builder.hpp"
|
||||
#endif
|
||||
|
||||
Builder Builder::open( char const* path )
|
||||
#pragma region Builder
|
||||
|
||||
Builder builder_open( char const* path )
|
||||
{
|
||||
Builder result;
|
||||
|
||||
@ -19,41 +21,39 @@ Builder Builder::open( char const* path )
|
||||
return result;
|
||||
}
|
||||
|
||||
void Builder::pad_lines( s32 num )
|
||||
void builder_pad_lines( Builder* builder, s32 num )
|
||||
{
|
||||
string_append_strc( & Buffer, txt("\n") );
|
||||
string_append_strc( & builder->Buffer, txt("\n") );
|
||||
}
|
||||
|
||||
void Builder::print( Code code )
|
||||
void builder_print( Builder* builder, Code code )
|
||||
{
|
||||
String str = to_string(code);
|
||||
String str = code_to_string(code);
|
||||
// const ssize len = str.length();
|
||||
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
||||
string_append_string( & Buffer, str );
|
||||
string_append_string( & builder->Buffer, str );
|
||||
}
|
||||
|
||||
void Builder::print_fmt( char const* fmt, ... )
|
||||
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va )
|
||||
{
|
||||
ssize res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
|
||||
string_append_c_str_len( (String*) & Buffer, (char const*)buf, res);
|
||||
string_append_c_str_len( (String*) & (builder->Buffer), (char const*)buf, res);
|
||||
}
|
||||
|
||||
void Builder::write()
|
||||
void builder_write(Builder* builder)
|
||||
{
|
||||
b32 result = file_write( & File, Buffer, string_length(Buffer) );
|
||||
b32 result = file_write( & builder->File, builder->Buffer, string_length(builder->Buffer) );
|
||||
|
||||
if ( result == false )
|
||||
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
|
||||
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & builder->File ) );
|
||||
|
||||
log_fmt( "Generated: %s\n", File.filename );
|
||||
file_close( & File );
|
||||
string_free(& Buffer);
|
||||
log_fmt( "Generated: %s\n", builder->File.filename );
|
||||
file_close( & builder->File );
|
||||
string_free(& builder->Buffer);
|
||||
}
|
||||
|
||||
#pragma endregion Builder
|
70
base/auxillary/builder.hpp
Normal file
70
base/auxillary/builder.hpp
Normal file
@ -0,0 +1,70 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "components/header_start.hpp"
|
||||
# include "components/types.hpp"
|
||||
# include "components/gen/ecode.hpp"
|
||||
# include "components/gen/eoperator.hpp"
|
||||
# include "components/gen/especifier.hpp"
|
||||
# include "components/ast.hpp"
|
||||
# include "components/code_types.hpp"
|
||||
# include "components/ast_types.hpp"
|
||||
# include "components/interface.hpp"
|
||||
# include "components/inlines.hpp"
|
||||
# include "components/gen/ast_inlines.hpp"
|
||||
# include "components/header_end.hpp"
|
||||
using namespace gen;
|
||||
#endif
|
||||
|
||||
#pragma region Builder
|
||||
|
||||
struct Builder;
|
||||
typedef struct Builder Builder;
|
||||
|
||||
Builder builder_open ( char const* path );
|
||||
void builder_pad_lines ( Builder* builder, s32 num );
|
||||
void builder_print ( Builder* builder, Code code );
|
||||
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
|
||||
void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
builder_print_fmt_va( builder, fmt, va );
|
||||
va_end( va );
|
||||
}
|
||||
void builder_write( Builder* builder );
|
||||
|
||||
struct Builder
|
||||
{
|
||||
FileInfo File;
|
||||
String Buffer;
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline static Builder open( char const* path ) { return builder_open(path); }
|
||||
|
||||
forceinline void pad_lines( s32 num ) { return builder_pad_lines(this, num); }
|
||||
|
||||
forceinline void print( Code code ) { return builder_print(this, code); }
|
||||
forceinline void print_fmt( char const* fmt, ... ) {
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
builder_print_fmt_va( this, fmt, va );
|
||||
va_end( va );
|
||||
}
|
||||
|
||||
forceinline void write() { return builder_write(this); }
|
||||
#endif
|
||||
};
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
void builder_pad_lines( Builder& builder, s32 num ) { return builder_pad_lines(& builder, num); }
|
||||
void builder_print ( Builder& builder, Code code ) { return builder_print(& builder, code); }
|
||||
void builder_write ( Builder& builder ) { return builder_write(& builder ); }
|
||||
void builder_print_fmt( Builder& builder, char const* fmt, ...) {
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
builder_print_fmt_va( & builder, fmt, va );
|
||||
va_end( va );
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma endregion Builder
|
@ -1,6 +1,18 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "../gen.hpp"
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "components/header_start.hpp"
|
||||
# include "components/types.hpp"
|
||||
# include "components/gen/ecode.hpp"
|
||||
# include "components/gen/eoperator.hpp"
|
||||
# include "components/gen/especifier.hpp"
|
||||
# include "components/ast.hpp"
|
||||
# include "components/code_types.hpp"
|
||||
# include "components/ast_types.hpp"
|
||||
# include "components/interface.hpp"
|
||||
# include "components/inlines.hpp"
|
||||
# include "components/gen/ast_inlines.hpp"
|
||||
# include "components/header_end.hpp"
|
||||
#endif
|
||||
|
||||
/*
|
@ -1,12 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "gen.hpp"
|
||||
# include "scanner.hpp"
|
||||
#endif
|
||||
|
||||
// This is a simple file reader that reads the entire file into memory.
|
||||
// It has an extra option to skip the first few lines for undesired includes.
|
||||
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
||||
inline
|
||||
#pragma region Scanner
|
||||
|
||||
Code scan_file( char const* path )
|
||||
{
|
||||
FileInfo file;
|
||||
@ -119,41 +116,33 @@ Code scan_file( char const* path )
|
||||
return untyped_str( string_to_strc(str) );
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct CodeFile
|
||||
{
|
||||
using namespace Parser;
|
||||
|
||||
String FilePath;
|
||||
TokArray Tokens;
|
||||
Array<ParseFailure> ParseFailures;
|
||||
Code CodeRoot;
|
||||
};
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
struct ParseFailure
|
||||
{
|
||||
String Reason;
|
||||
Code Node;
|
||||
};
|
||||
CodeBody parse_file( const char* path ) {
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
||||
StrC content = { file.size, (char const*)file.data };
|
||||
CodeBody code = parse_global_body( content );
|
||||
log_fmt("\nParsed: %s\n", path);
|
||||
return code;
|
||||
}
|
||||
|
||||
CodeFile scan_file( char const* path )
|
||||
{
|
||||
using namespace Parser;
|
||||
|
||||
CodeFile
|
||||
result = {};
|
||||
result.FilePath = String::make( GlobalAllocator, path );
|
||||
|
||||
Code code = scan_file( path );
|
||||
result.CodeRoot = code;
|
||||
|
||||
ParseContext context = parser_get_last_context();
|
||||
result.Tokens = context.Tokens;
|
||||
result.ParseFailures = context.Failures;
|
||||
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
|
||||
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
||||
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
||||
|
||||
CSV_Column result;
|
||||
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
||||
result.Content = result.ADT.nodes[0].nodes;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path) {
|
||||
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
||||
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
||||
|
||||
CSV_Columns2 result;
|
||||
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
||||
result.Col_1 = result.ADT.nodes[0].nodes;
|
||||
result.Col_2 = result.ADT.nodes[1].nodes;
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma endregion Scanner
|
46
base/auxillary/scanner.hpp
Normal file
46
base/auxillary/scanner.hpp
Normal file
@ -0,0 +1,46 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "components/header_start.hpp"
|
||||
# include "components/types.hpp"
|
||||
# include "components/gen/ecode.hpp"
|
||||
# include "components/gen/eoperator.hpp"
|
||||
# include "components/gen/especifier.hpp"
|
||||
# include "components/ast.hpp"
|
||||
# include "components/code_types.hpp"
|
||||
# include "components/ast_types.hpp"
|
||||
# include "components/interface.hpp"
|
||||
# include "components/inlines.hpp"
|
||||
# include "components/gen/ast_inlines.hpp"
|
||||
# include "components/header_end.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Scanner
|
||||
|
||||
// This is a simple file reader that reads the entire file into memory.
|
||||
// It has an extra option to skip the first few lines for undesired includes.
|
||||
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
||||
Code scan_file( char const* path );
|
||||
|
||||
CodeBody parse_file( const char* path );
|
||||
|
||||
// The follow is basic support for light csv parsing (use it as an example)
|
||||
// Make something robust if its more serious.
|
||||
|
||||
typedef struct CSV_Column CSV_Column;
|
||||
struct CSV_Column {
|
||||
CSV_Object ADT;
|
||||
Array(ADT_Node) Content;
|
||||
};
|
||||
|
||||
typedef struct CSV_Columns2 CSV_Columns2;
|
||||
struct CSV_Columns2 {
|
||||
CSV_Object ADT;
|
||||
Array(ADT_Node) Col_1;
|
||||
Array(ADT_Node) Col_2;
|
||||
};
|
||||
|
||||
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path);
|
||||
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path);
|
||||
|
||||
#pragma endregion Scanner
|
68
base/base.cpp
Normal file
68
base/base.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#define GEN_C_LIKE_CPP 1
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "helpers/base_codegen.hpp"
|
||||
#include "helpers/misc.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* path_format_style = "../scripts/.clang-format";
|
||||
constexpr char const* scratch_file = "build/scratch.hpp";
|
||||
|
||||
Code format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
|
||||
}
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_strc_from_c_str(generation_notice) )
|
||||
));
|
||||
|
||||
CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
Builder header_ecode = builder_open( "components/gen/ecodetypes.hpp" );
|
||||
builder_print( & header_ecode, gen_component_header );
|
||||
builder_print( & header_ecode, format(ecode) );
|
||||
builder_write( & header_ecode);
|
||||
|
||||
Builder header_eoperator = builder_open( "components/gen/eoperator.hpp" );
|
||||
builder_print( & header_eoperator, gen_component_header );
|
||||
builder_print( & header_eoperator, format(eoperator) );
|
||||
builder_write( & header_eoperator );
|
||||
|
||||
Builder header_especifier = builder_open( "components/gen/especifier.hpp" );
|
||||
builder_print( & header_especifier, gen_component_header );
|
||||
builder_print( & header_especifier, format(especifier) );
|
||||
builder_write( & header_especifier);
|
||||
|
||||
Builder header_ast_inlines = builder_open( "components/gen/ast_inlines.hpp" );
|
||||
builder_print( & header_ast_inlines, gen_component_header );
|
||||
builder_print( & header_ast_inlines, format(ast_inlines) );
|
||||
builder_write( & header_ast_inlines);
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
}
|
1277
base/components/ast.cpp
Normal file
1277
base/components/ast.cpp
Normal file
File diff suppressed because it is too large
Load Diff
466
base/components/ast.hpp
Normal file
466
base/components/ast.hpp
Normal file
@ -0,0 +1,466 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "gen/ecode.hpp"
|
||||
#include "gen/eoperator.hpp"
|
||||
#include "gen/especifier.hpp"
|
||||
#endif
|
||||
|
||||
/*
|
||||
______ ______ ________ __ __ ______ __
|
||||
/ \ / \| \ | \ | \ / \ | \
|
||||
| ▓▓▓▓▓▓\ ▓▓▓▓▓▓\\▓▓▓▓▓▓▓▓ | ▓▓\ | ▓▓ | ▓▓▓▓▓▓\ ______ ____| ▓▓ ______
|
||||
| ▓▓__| ▓▓ ▓▓___\▓▓ | ▓▓ | ▓▓▓\| ▓▓ | ▓▓ \▓▓/ \ / ▓▓/ \
|
||||
| ▓▓ ▓▓\▓▓ \ | ▓▓ | ▓▓▓▓\ ▓▓ | ▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\
|
||||
| ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\ | ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓ __| ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ ▓▓
|
||||
| ▓▓ | ▓▓ \__| ▓▓ | ▓▓ | ▓▓ \▓▓▓▓ | ▓▓__/ \ ▓▓__/ ▓▓ ▓▓__| ▓▓ ▓▓▓▓▓▓▓▓
|
||||
| ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓ | ▓▓ \▓▓▓ \▓▓ ▓▓\▓▓ ▓▓\▓▓ ▓▓\▓▓ \
|
||||
\▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
||||
*/
|
||||
|
||||
struct AST;
|
||||
struct AST_Body;
|
||||
struct AST_Attributes;
|
||||
struct AST_Comment;
|
||||
struct AST_Constructor;
|
||||
// struct AST_BaseClass;
|
||||
struct AST_Class;
|
||||
struct AST_Define;
|
||||
struct AST_Destructor;
|
||||
struct AST_Enum;
|
||||
struct AST_Exec;
|
||||
struct AST_Extern;
|
||||
struct AST_Include;
|
||||
struct AST_Friend;
|
||||
struct AST_Fn;
|
||||
struct AST_Module;
|
||||
struct AST_NS;
|
||||
struct AST_Operator;
|
||||
struct AST_OpCast;
|
||||
struct AST_Params;
|
||||
struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct AST_Expr;
|
||||
struct AST_Expr_Assign;
|
||||
struct AST_Expr_Alignof;
|
||||
struct AST_Expr_Binary;
|
||||
struct AST_Expr_CStyleCast;
|
||||
struct AST_Expr_FunctionalCast;
|
||||
struct AST_Expr_CppCast;
|
||||
struct AST_Expr_ProcCall;
|
||||
struct AST_Expr_Decltype;
|
||||
struct AST_Expr_Comma; // TODO(Ed) : This is a binary op not sure if it needs its own AST...
|
||||
struct AST_Expr_AMS; // Access Member Symbol
|
||||
struct AST_Expr_Sizeof;
|
||||
struct AST_Expr_Subscript;
|
||||
struct AST_Expr_Ternary;
|
||||
struct AST_Expr_UnaryPrefix;
|
||||
struct AST_Expr_UnaryPostfix;
|
||||
struct AST_Expr_Element;
|
||||
|
||||
struct AST_Stmt;
|
||||
struct AST_Stmt_Break;
|
||||
struct AST_Stmt_Case;
|
||||
struct AST_Stmt_Continue;
|
||||
struct AST_Stmt_Decl;
|
||||
struct AST_Stmt_Do;
|
||||
struct AST_Stmt_Expr; // TODO(Ed) : Is this distinction needed? (Should it be a flag instead?)
|
||||
struct AST_Stmt_Else;
|
||||
struct AST_Stmt_If;
|
||||
struct AST_Stmt_For;
|
||||
struct AST_Stmt_Goto;
|
||||
struct AST_Stmt_Label;
|
||||
struct AST_Stmt_Switch;
|
||||
struct AST_Stmt_While;
|
||||
#endif
|
||||
|
||||
struct AST_Struct;
|
||||
struct AST_Template;
|
||||
struct AST_Typename;
|
||||
struct AST_Typedef;
|
||||
struct AST_Union;
|
||||
struct AST_Using;
|
||||
struct AST_Var;
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef AST* Code;
|
||||
#else
|
||||
struct Code;
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef AST_Body* CodeBody;
|
||||
typedef AST_Attributes* CodeAttributes;
|
||||
typedef AST_Comment* CodeComment;
|
||||
typedef AST_Class* CodeClass;
|
||||
typedef AST_Constructor* CodeConstructor;
|
||||
typedef AST_Define* CodeDefine;
|
||||
typedef AST_Destructor* CodeDestructor;
|
||||
typedef AST_Enum* CodeEnum;
|
||||
typedef AST_Exec* CodeExec;
|
||||
typedef AST_Extern* CodeExtern;
|
||||
typedef AST_Include* CodeInclude;
|
||||
typedef AST_Friend* CodeFriend;
|
||||
typedef AST_Fn* CodeFn;
|
||||
typedef AST_Module* CodeModule;
|
||||
typedef AST_NS* CodeNS;
|
||||
typedef AST_Operator* CodeOperator;
|
||||
typedef AST_OpCast* CodeOpCast;
|
||||
typedef AST_Params* CodeParams;
|
||||
typedef AST_PreprocessCond* CodePreprocessCond;
|
||||
typedef AST_Pragma* CodePragma;
|
||||
typedef AST_Specifiers* CodeSpecifiers;
|
||||
#else
|
||||
struct CodeBody;
|
||||
struct CodeAttributes;
|
||||
struct CodeComment;
|
||||
struct CodeClass;
|
||||
struct CodeConstructor;
|
||||
struct CodeDefine;
|
||||
struct CodeDestructor;
|
||||
struct CodeEnum;
|
||||
struct CodeExec;
|
||||
struct CodeExtern;
|
||||
struct CodeInclude;
|
||||
struct CodeFriend;
|
||||
struct CodeFn;
|
||||
struct CodeModule;
|
||||
struct CodeNS;
|
||||
struct CodeOperator;
|
||||
struct CodeOpCast;
|
||||
struct CodeParams;
|
||||
struct CodePreprocessCond;
|
||||
struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
#endif
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef AST_Expr* CodeExpr;
|
||||
typedef AST_Expr_Assign* CodeExpr_Assign;
|
||||
typedef AST_Expr_Alignof* CodeExpr_Alignof;
|
||||
typedef AST_Expr_Binary* CodeExpr_Binary;
|
||||
typedef AST_Expr_CStyleCast* CodeExpr_CStyleCast;
|
||||
typedef AST_Expr_FunctionalCast* CodeExpr_FunctionalCast;
|
||||
typedef AST_Expr_CppCast* CodeExpr_CppCast;
|
||||
typedef AST_Expr_Element* CodeExpr_Element;
|
||||
typedef AST_Expr_ProcCall* CodeExpr_ProcCall;
|
||||
typedef AST_Expr_Decltype* CodeExpr_Decltype;
|
||||
typedef AST_Expr_Comma* CodeExpr_Comma;
|
||||
typedef AST_Expr_AMS* CodeExpr_AMS; // Access Member Symbol
|
||||
typedef AST_Expr_Sizeof* CodeExpr_Sizeof;
|
||||
typedef AST_Expr_Subscript* CodeExpr_Subscript;
|
||||
typedef AST_Expr_Ternary* CodeExpr_Ternary;
|
||||
typedef AST_Expr_UnaryPrefix* CodeExpr_UnaryPrefix;
|
||||
typedef AST_Expr_UnaryPostfix* CodeExpr_UnaryPostfix;
|
||||
#else
|
||||
struct CodeExpr;
|
||||
struct CodeExpr_Assign;
|
||||
struct CodeExpr_Alignof;
|
||||
struct CodeExpr_Binary;
|
||||
struct CodeExpr_CStyleCast;
|
||||
struct CodeExpr_FunctionalCast;
|
||||
struct CodeExpr_CppCast;
|
||||
struct CodeExpr_Element;
|
||||
struct CodeExpr_ProcCall;
|
||||
struct CodeExpr_Decltype;
|
||||
struct CodeExpr_Comma;
|
||||
struct CodeExpr_AMS; // Access Member Symbol
|
||||
struct CodeExpr_Sizeof;
|
||||
struct CodeExpr_Subscript;
|
||||
struct CodeExpr_Ternary;
|
||||
struct CodeExpr_UnaryPrefix;
|
||||
struct CodeExpr_UnaryPostfix;
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef AST_Stmt* CodeStmt;
|
||||
typedef AST_Stmt_Break* CodeStmt_Break;
|
||||
typedef AST_Stmt_Case* CodeStmt_Case;
|
||||
typedef AST_Stmt_Continue* CodeStmt_Continue;
|
||||
typedef AST_Stmt_Decl* CodeStmt_Decl;
|
||||
typedef AST_Stmt_Do* CodeStmt_Do;
|
||||
typedef AST_Stmt_Expr* CodeStmt_Expr;
|
||||
typedef AST_Stmt_Else* CodeStmt_Else;
|
||||
typedef AST_Stmt_If* CodeStmt_If;
|
||||
typedef AST_Stmt_For* CodeStmt_For;
|
||||
typedef AST_Stmt_Goto* CodeStmt_Goto;
|
||||
typedef AST_Stmt_Label* CodeStmt_Label;
|
||||
typedef AST_Stmt_Switch* CodeStmt_Switch;
|
||||
typedef AST_Stmt_While* CodeStmt_While;
|
||||
#else
|
||||
struct CodeStmt;
|
||||
struct CodeStmt_Break;
|
||||
struct CodeStmt_Case;
|
||||
struct CodeStmt_Continue;
|
||||
struct CodeStmt_Decl;
|
||||
struct CodeStmt_Do;
|
||||
struct CodeStmt_Expr;
|
||||
struct CodeStmt_Else;
|
||||
struct CodeStmt_If;
|
||||
struct CodeStmt_For;
|
||||
struct CodeStmt_Goto;
|
||||
struct CodeStmt_Label;
|
||||
struct CodeStmt_Switch;
|
||||
struct CodeStmt_While;
|
||||
#endif
|
||||
|
||||
// GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef AST_Struct* CodeStruct;
|
||||
typedef AST_Template* CodeTemplate;
|
||||
typedef AST_Typename* CodeTypename;
|
||||
typedef AST_Typedef* CodeTypedef;
|
||||
typedef AST_Union* CodeUnion;
|
||||
typedef AST_Using* CodeUsing;
|
||||
typedef AST_Var* CodeVar;
|
||||
#else
|
||||
struct CodeStruct;
|
||||
struct CodeTemplate;
|
||||
struct CodeTypename;
|
||||
struct CodeTypedef;
|
||||
struct CodeUnion;
|
||||
struct CodeUsing;
|
||||
struct CodeVar;
|
||||
#endif
|
||||
|
||||
GEN_NS_PARSER_BEGIN
|
||||
|
||||
struct Token;
|
||||
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
// Note(Ed): This is to alleviate an edge case with parsing usings or typedefs where I don't really have it setup
|
||||
// to parse a 'namespace' macro or a type with a macro.
|
||||
// I have ideas for ways to pack that into the typedef/using ast, but for now just keeping it like this
|
||||
#define ParserTokenType GEN_NS_PARSER Token
|
||||
typedef ParserTokenType Token;
|
||||
#undef ParserTokenType
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); }
|
||||
#endif
|
||||
|
||||
#pragma region Code C-Interface
|
||||
|
||||
void code_append (Code code, Code other );
|
||||
StrC code_debug_str (Code code);
|
||||
Code code_duplicate (Code code);
|
||||
Code* code_entry (Code code, u32 idx );
|
||||
bool code_has_entries (Code code);
|
||||
bool code_is_body (Code code);
|
||||
bool code_is_equal (Code code, Code other);
|
||||
bool code_is_valid (Code code);
|
||||
void code_set_global (Code code);
|
||||
String code_to_string (Code self );
|
||||
void code_to_string_ptr(Code self, String* result );
|
||||
StrC code_type_str (Code self );
|
||||
bool code_validate_body(Code self );
|
||||
|
||||
#pragma endregion Code C-Interface
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
/*
|
||||
AST* wrapper
|
||||
- Not constantly have to append the '*' as this is written often..
|
||||
- Allows for implicit conversion to any of the ASTs (raw or filtered).
|
||||
*/
|
||||
struct Code
|
||||
{
|
||||
AST* ast;
|
||||
|
||||
# define Using_Code( Typename ) \
|
||||
forceinline StrC debug_str() { return code_debug_str(* this); } \
|
||||
forceinline Code duplicate() { return code_duplicate(* this); } \
|
||||
forceinline bool is_equal( Code other ) { return code_is_equal(* this, other); } \
|
||||
forceinline bool is_body() { return code_is_body(* this); } \
|
||||
forceinline bool is_valid() { return code_is_valid(* this); } \
|
||||
forceinline void set_global() { return code_set_global(* this); }
|
||||
|
||||
# define Using_CodeOps( Typename ) \
|
||||
forceinline Typename& operator = ( Code other ); \
|
||||
forceinline bool operator ==( Code other ) { return (AST*)ast == other.ast; } \
|
||||
forceinline bool operator !=( Code other ) { return (AST*)ast != other.ast; } \
|
||||
forceinline bool operator ==(std::nullptr_t) const { return ast == nullptr; } \
|
||||
forceinline bool operator !=(std::nullptr_t) const { return ast != nullptr; } \
|
||||
operator bool();
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
Using_Code( Code );
|
||||
forceinline void append(Code other) { return code_append(* this, other); }
|
||||
forceinline Code* entry(u32 idx) { return code_entry(* this, idx); }
|
||||
forceinline bool has_entries() { return code_has_entries(* this); }
|
||||
forceinline String to_string() { return code_to_string(* this); }
|
||||
forceinline void to_string(String& result) { return code_to_string_ptr(* this, & result); }
|
||||
forceinline StrC type_str() { return code_type_str(* this); }
|
||||
forceinline bool validate_body() { return code_validate_body(*this); }
|
||||
#endif
|
||||
|
||||
Using_CodeOps( Code );
|
||||
forceinline AST* operator ->() { return ast; }
|
||||
|
||||
Code& operator ++();
|
||||
|
||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define operator explicit operator
|
||||
#endif
|
||||
operator CodeBody() const;
|
||||
operator CodeAttributes() const;
|
||||
// operator CodeBaseClass() const;
|
||||
operator CodeComment() const;
|
||||
operator CodeClass() const;
|
||||
operator CodeConstructor() const;
|
||||
operator CodeDefine() const;
|
||||
operator CodeDestructor() const;
|
||||
operator CodeExec() const;
|
||||
operator CodeEnum() const;
|
||||
operator CodeExtern() const;
|
||||
operator CodeInclude() const;
|
||||
operator CodeFriend() const;
|
||||
operator CodeFn() const;
|
||||
operator CodeModule() const;
|
||||
operator CodeNS() const;
|
||||
operator CodeOperator() const;
|
||||
operator CodeOpCast() const;
|
||||
operator CodeParams() const;
|
||||
operator CodePragma() const;
|
||||
operator CodePreprocessCond() const;
|
||||
operator CodeSpecifiers() const;
|
||||
operator CodeStruct() const;
|
||||
operator CodeTemplate() const;
|
||||
operator CodeTypename() const;
|
||||
operator CodeTypedef() const;
|
||||
operator CodeUnion() const;
|
||||
operator CodeUsing() const;
|
||||
operator CodeVar() const;
|
||||
#undef operator
|
||||
};
|
||||
#endif
|
||||
|
||||
#pragma region Statics
|
||||
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
|
||||
extern Code Code_Global;
|
||||
|
||||
// Used to identify invalid generated code.
|
||||
extern Code Code_Invalid;
|
||||
#pragma endregion Statics
|
||||
|
||||
struct Code_POD
|
||||
{
|
||||
AST* ast;
|
||||
};
|
||||
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
||||
|
||||
// Desired width of the AST data structure.
|
||||
constexpr int const AST_POD_Size = 128;
|
||||
|
||||
constexpr static
|
||||
int AST_ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(Code)
|
||||
- sizeof(StringCached)
|
||||
- sizeof(Code) * 2
|
||||
- sizeof(Token*)
|
||||
- sizeof(Code)
|
||||
- sizeof(CodeType)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(u32)
|
||||
)
|
||||
/ sizeof(Specifier) - 1;
|
||||
|
||||
/*
|
||||
Simple AST POD with functionality to seralize into C++ syntax.
|
||||
*/
|
||||
struct AST
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
Code Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
Code InitializerList; // Constructor
|
||||
Code ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
Code ReturnType; // Function, Operator, Typename
|
||||
Code UnderlyingType; // Enum, Typedef
|
||||
Code ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
Code Macro; // Parameter
|
||||
Code BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
Code Params; // Constructor, Function, Operator, Template, Typename
|
||||
Code UnderlyingTypeMacro; // Enum
|
||||
};
|
||||
union {
|
||||
Code ArrExpr; // Typename
|
||||
Code Body; // Class, Constructor, Destructor, Enum, Friend, Function, Namespace, Struct, Union
|
||||
Code Declaration; // Friend, Template
|
||||
Code Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
Code SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
Specifier ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
|
||||
Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
union {
|
||||
Code Prev;
|
||||
Code Front;
|
||||
Code Last;
|
||||
};
|
||||
union {
|
||||
Code Next;
|
||||
Code Back;
|
||||
};
|
||||
Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
// CodeFlag CodeFlags;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
struct {
|
||||
b16 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
ETypenameTag TypeTag; // Used by typename to keep track of explicitly declared tags for the identifier (enum, struct, union)
|
||||
};
|
||||
Operator Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
s32 VarParenthesizedInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
|
||||
};
|
||||
};
|
||||
static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST is not size of AST_POD_Size" );
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
// Uses an implicitly overloaded cast from the AST to the desired code type.
|
||||
// Necessary if the user wants GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
struct InvalidCode_ImplictCaster;
|
||||
#define InvalidCode (InvalidCode_ImplictCaster{})
|
||||
#else
|
||||
#define InvalidCode (void*){ (void*)Code_Invalid }
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
struct NullCode_ImplicitCaster;
|
||||
// Used when the its desired when omission is allowed in a definition.
|
||||
#define NullCode (NullCode_ImplicitCaster{})
|
||||
#else
|
||||
#define NullCode nullptr
|
||||
#endif
|
@ -4,6 +4,22 @@
|
||||
#endif
|
||||
|
||||
#pragma region AST Types
|
||||
|
||||
/*
|
||||
______ ______ ________ ________
|
||||
/ \ / \| \ | \
|
||||
| ▓▓▓▓▓▓\ ▓▓▓▓▓▓\\▓▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓▓__ __ ______ ______ _______
|
||||
| ▓▓__| ▓▓ ▓▓___\▓▓ | ▓▓ | ▓▓ | \ | \/ \ / \ / \
|
||||
| ▓▓ ▓▓\▓▓ \ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓
|
||||
| ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ ▓▓\▓▓ \
|
||||
| ▓▓ | ▓▓ \__| ▓▓ | ▓▓ | ▓▓ | ▓▓__/ ▓▓ ▓▓__/ ▓▓ ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\
|
||||
| ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓ | ▓▓ \▓▓ ▓▓ ▓▓ ▓▓\▓▓ \ ▓▓
|
||||
\▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓ _\▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓▓▓▓▓▓
|
||||
| \__| ▓▓ ▓▓
|
||||
\▓▓ ▓▓ ▓▓
|
||||
\▓▓▓▓▓▓ \▓▓
|
||||
*/
|
||||
|
||||
/*
|
||||
Show only relevant members of the AST for its type.
|
||||
AST* fields are replaced with Code types.
|
||||
@ -12,12 +28,14 @@
|
||||
|
||||
struct AST_Body
|
||||
{
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
@ -30,11 +48,11 @@ struct AST_Attributes
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -46,11 +64,11 @@ struct AST_BaseClass
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -63,11 +81,11 @@ struct AST_Comment
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -88,11 +106,11 @@ struct AST_Class
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
CodeTypename Prev;
|
||||
CodeTypename Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
@ -109,16 +127,16 @@ struct AST_Constructor
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
||||
CodeSpecifiers Specs;
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -130,11 +148,11 @@ struct AST_Define
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -154,11 +172,11 @@ struct AST_Destructor
|
||||
char _PAD_PROPERTIES_3_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -179,11 +197,11 @@ struct AST_Enum
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
@ -196,11 +214,11 @@ struct AST_Exec
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -212,11 +230,11 @@ struct AST_Expr
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -227,11 +245,11 @@ struct AST_Expr_Assign
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -242,11 +260,11 @@ struct AST_Expr_Alignof
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -257,11 +275,11 @@ struct AST_Expr_Binary
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -272,11 +290,11 @@ struct AST_Expr_CStyleCast
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -287,11 +305,11 @@ struct AST_Expr_FunctionalCast
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -302,11 +320,11 @@ struct AST_Expr_CppCast
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -317,11 +335,11 @@ struct AST_Expr_ProcCall
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -332,11 +350,11 @@ struct AST_Expr_Decltype
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -347,11 +365,11 @@ struct AST_Expr_Comma
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -362,11 +380,11 @@ struct AST_Expr_AMS
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -377,11 +395,11 @@ struct AST_Expr_Sizeof
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -392,11 +410,11 @@ struct AST_Expr_Subscript
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -407,11 +425,11 @@ struct AST_Expr_Ternary
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -422,11 +440,11 @@ struct AST_Expr_UnaryPrefix
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -437,11 +455,11 @@ struct AST_Expr_UnaryPostfix
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -452,11 +470,11 @@ struct AST_Expr_Element
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -474,11 +492,11 @@ struct AST_Extern
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -490,11 +508,11 @@ struct AST_Include
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -512,11 +530,11 @@ struct AST_Friend
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -532,16 +550,16 @@ struct AST_Fn
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
@ -550,12 +568,14 @@ static_assert( sizeof(AST_Fn) == sizeof(AST), "ERROR: AST_Fn is not the same siz
|
||||
|
||||
struct AST_Module
|
||||
{
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
@ -572,11 +592,11 @@ struct AST_NS
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
@ -593,16 +613,16 @@ struct AST_Operator
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
Operator Op;
|
||||
@ -619,22 +639,22 @@ struct AST_OpCast
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ValueType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
||||
|
||||
struct AST_Param
|
||||
struct AST_Params
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
@ -648,16 +668,16 @@ struct AST_Param
|
||||
// char _PAD_PROPERTIES_3_[sizeof( AST* )];
|
||||
};
|
||||
};
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
StringCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the same size as AST");
|
||||
static_assert( sizeof(AST_Params) == sizeof(AST), "ERROR: AST_Params is not the same size as AST");
|
||||
|
||||
struct AST_Pragma
|
||||
{
|
||||
@ -665,11 +685,11 @@ struct AST_Pragma
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -681,11 +701,11 @@ struct AST_PreprocessCond
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -693,13 +713,13 @@ static_assert( sizeof(AST_PreprocessCond) == sizeof(AST), "ERROR: AST_Preprocess
|
||||
|
||||
struct AST_Specifiers
|
||||
{
|
||||
Specifier ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
Specifier ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
StringCached Name;
|
||||
CodeSpecifiers NextSpecs;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
@ -712,11 +732,11 @@ struct AST_Stmt
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -727,11 +747,11 @@ struct AST_Stmt_Break
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -742,11 +762,11 @@ struct AST_Stmt_Case
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -757,11 +777,11 @@ struct AST_Stmt_Continue
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -772,11 +792,11 @@ struct AST_Stmt_Decl
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -787,11 +807,11 @@ struct AST_Stmt_Do
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -802,11 +822,11 @@ struct AST_Stmt_Expr
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -817,11 +837,11 @@ struct AST_Stmt_Else
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -832,11 +852,11 @@ struct AST_Stmt_If
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -847,11 +867,11 @@ struct AST_Stmt_For
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -862,11 +882,11 @@ struct AST_Stmt_Goto
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -877,11 +897,11 @@ struct AST_Stmt_Label
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -892,11 +912,11 @@ struct AST_Stmt_Switch
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -907,11 +927,11 @@ struct AST_Stmt_While
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StringCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
@ -933,11 +953,11 @@ struct AST_Struct
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
CodeTypename Prev;
|
||||
CodeTypename Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
@ -951,16 +971,16 @@ struct AST_Template
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
@ -980,16 +1000,16 @@ struct AST_Type
|
||||
CodeSpecifiers Specs;
|
||||
Code QualifierID;
|
||||
// CodeTypename ReturnType; // Only used for function signatures
|
||||
// CodeParam Params; // Only used for function signatures
|
||||
// CodeParams Params; // Only used for function signatures
|
||||
Code ArrExpr;
|
||||
// CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
b32 IsParamPack;
|
||||
@ -1007,19 +1027,22 @@ struct AST_Typename
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType; // Only used for function signatures
|
||||
CodeParam Params; // Only used for function signatures
|
||||
CodeParams Params; // Only used for function signatures
|
||||
Code ArrExpr;
|
||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
b32 IsParamPack;
|
||||
struct {
|
||||
b16 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
ETypenameTag TypeTag; // Used by typename to keep track of explicitly declared tags for the identifier (enum, struct, union)
|
||||
};
|
||||
};
|
||||
static_assert( sizeof(AST_Typename) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
|
||||
|
||||
@ -1035,11 +1058,11 @@ struct AST_Typedef
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
@ -1059,11 +1082,11 @@ struct AST_Union
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
@ -1083,11 +1106,11 @@ struct AST_Using
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
@ -1109,14 +1132,14 @@ struct AST_Var
|
||||
CodeVar NextVar;
|
||||
};
|
||||
};
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarConstructorInit;
|
||||
s32 VarParenthesizedInit;
|
||||
};
|
||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||
|
1492
base/components/code_serialization.cpp
Normal file
1492
base/components/code_serialization.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1130
base/components/code_types.hpp
Normal file
1130
base/components/code_types.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -9,9 +9,9 @@
|
||||
|
||||
inline Code& Code::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -25,9 +25,9 @@ inline Code::operator bool()
|
||||
|
||||
inline CodeBody& CodeBody::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -41,9 +41,9 @@ inline CodeBody::operator bool()
|
||||
|
||||
inline CodeAttributes& CodeAttributes::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -72,9 +72,9 @@ inline AST_Attributes* CodeAttributes::operator->()
|
||||
|
||||
inline CodeComment& CodeComment::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -103,9 +103,9 @@ inline AST_Comment* CodeComment::operator->()
|
||||
|
||||
inline CodeConstructor& CodeConstructor::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -134,9 +134,9 @@ inline AST_Constructor* CodeConstructor::operator->()
|
||||
|
||||
inline CodeClass& CodeClass::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -150,9 +150,9 @@ inline CodeClass::operator bool()
|
||||
|
||||
inline CodeDefine& CodeDefine::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -181,9 +181,9 @@ inline AST_Define* CodeDefine::operator->()
|
||||
|
||||
inline CodeDestructor& CodeDestructor::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -212,9 +212,9 @@ inline AST_Destructor* CodeDestructor::operator->()
|
||||
|
||||
inline CodeEnum& CodeEnum::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -243,9 +243,9 @@ inline AST_Enum* CodeEnum::operator->()
|
||||
|
||||
inline CodeExec& CodeExec::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -274,9 +274,9 @@ inline AST_Exec* CodeExec::operator->()
|
||||
|
||||
inline CodeExtern& CodeExtern::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -305,9 +305,9 @@ inline AST_Extern* CodeExtern::operator->()
|
||||
|
||||
inline CodeFriend& CodeFriend::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -336,9 +336,9 @@ inline AST_Friend* CodeFriend::operator->()
|
||||
|
||||
inline CodeFn& CodeFn::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -367,9 +367,9 @@ inline AST_Fn* CodeFn::operator->()
|
||||
|
||||
inline CodeInclude& CodeInclude::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -398,9 +398,9 @@ inline AST_Include* CodeInclude::operator->()
|
||||
|
||||
inline CodeModule& CodeModule::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -429,9 +429,9 @@ inline AST_Module* CodeModule::operator->()
|
||||
|
||||
inline CodeNS& CodeNS::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -460,9 +460,9 @@ inline AST_NS* CodeNS::operator->()
|
||||
|
||||
inline CodeOperator& CodeOperator::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -491,9 +491,9 @@ inline AST_Operator* CodeOperator::operator->()
|
||||
|
||||
inline CodeOpCast& CodeOpCast::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -520,27 +520,27 @@ inline AST_OpCast* CodeOpCast::operator->()
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeParam& CodeParam::operator=( Code other )
|
||||
inline CodeParams& CodeParams::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline CodeParam::operator bool()
|
||||
inline CodeParams::operator bool()
|
||||
{
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodePragma& CodePragma::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -569,9 +569,9 @@ inline AST_Pragma* CodePragma::operator->()
|
||||
|
||||
inline CodePreprocessCond& CodePreprocessCond::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -600,9 +600,9 @@ inline AST_PreprocessCond* CodePreprocessCond::operator->()
|
||||
|
||||
inline CodeSpecifiers& CodeSpecifiers::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -616,9 +616,9 @@ inline CodeSpecifiers::operator bool()
|
||||
|
||||
inline CodeStruct& CodeStruct::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -632,9 +632,9 @@ inline CodeStruct::operator bool()
|
||||
|
||||
inline CodeTemplate& CodeTemplate::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -663,9 +663,9 @@ inline AST_Template* CodeTemplate::operator->()
|
||||
|
||||
inline CodeTypename& CodeTypename::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -694,9 +694,9 @@ inline AST_Typename* CodeTypename::operator->()
|
||||
|
||||
inline CodeTypedef& CodeTypedef::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -725,9 +725,9 @@ inline AST_Typedef* CodeTypedef::operator->()
|
||||
|
||||
inline CodeUnion& CodeUnion::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -756,9 +756,9 @@ inline AST_Union* CodeUnion::operator->()
|
||||
|
||||
inline CodeUsing& CodeUsing::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -787,9 +787,9 @@ inline AST_Using* CodeUsing::operator->()
|
||||
|
||||
inline CodeVar& CodeVar::operator=( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype( ast ), GEN_NS duplicate( other ).ast );
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
@ -819,145 +819,147 @@ inline AST_Var* CodeVar::operator->()
|
||||
#pragma endregion generated code inline implementation
|
||||
|
||||
#pragma region generated AST/Code cast implementation
|
||||
GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
|
||||
inline Code::operator CodeBody() const
|
||||
forceinline Code::operator CodeBody() const
|
||||
{
|
||||
return { (AST_Body*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeAttributes() const
|
||||
forceinline Code::operator CodeAttributes() const
|
||||
{
|
||||
return { (AST_Attributes*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeComment() const
|
||||
forceinline Code::operator CodeComment() const
|
||||
{
|
||||
return { (AST_Comment*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeConstructor() const
|
||||
forceinline Code::operator CodeConstructor() const
|
||||
{
|
||||
return { (AST_Constructor*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeClass() const
|
||||
forceinline Code::operator CodeClass() const
|
||||
{
|
||||
return { (AST_Class*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeDefine() const
|
||||
forceinline Code::operator CodeDefine() const
|
||||
{
|
||||
return { (AST_Define*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeDestructor() const
|
||||
forceinline Code::operator CodeDestructor() const
|
||||
{
|
||||
return { (AST_Destructor*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeEnum() const
|
||||
forceinline Code::operator CodeEnum() const
|
||||
{
|
||||
return { (AST_Enum*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeExec() const
|
||||
forceinline Code::operator CodeExec() const
|
||||
{
|
||||
return { (AST_Exec*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeExtern() const
|
||||
forceinline Code::operator CodeExtern() const
|
||||
{
|
||||
return { (AST_Extern*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeFriend() const
|
||||
forceinline Code::operator CodeFriend() const
|
||||
{
|
||||
return { (AST_Friend*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeFn() const
|
||||
forceinline Code::operator CodeFn() const
|
||||
{
|
||||
return { (AST_Fn*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeInclude() const
|
||||
forceinline Code::operator CodeInclude() const
|
||||
{
|
||||
return { (AST_Include*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeModule() const
|
||||
forceinline Code::operator CodeModule() const
|
||||
{
|
||||
return { (AST_Module*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeNS() const
|
||||
forceinline Code::operator CodeNS() const
|
||||
{
|
||||
return { (AST_NS*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeOperator() const
|
||||
forceinline Code::operator CodeOperator() const
|
||||
{
|
||||
return { (AST_Operator*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeOpCast() const
|
||||
forceinline Code::operator CodeOpCast() const
|
||||
{
|
||||
return { (AST_OpCast*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeParam() const
|
||||
forceinline Code::operator CodeParams() const
|
||||
{
|
||||
return { (AST_Param*)ast };
|
||||
return { (AST_Params*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodePragma() const
|
||||
forceinline Code::operator CodePragma() const
|
||||
{
|
||||
return { (AST_Pragma*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodePreprocessCond() const
|
||||
forceinline Code::operator CodePreprocessCond() const
|
||||
{
|
||||
return { (AST_PreprocessCond*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeSpecifiers() const
|
||||
forceinline Code::operator CodeSpecifiers() const
|
||||
{
|
||||
return { (AST_Specifiers*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeStruct() const
|
||||
forceinline Code::operator CodeStruct() const
|
||||
{
|
||||
return { (AST_Struct*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeTemplate() const
|
||||
forceinline Code::operator CodeTemplate() const
|
||||
{
|
||||
return { (AST_Template*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeTypename() const
|
||||
forceinline Code::operator CodeTypename() const
|
||||
{
|
||||
return { (AST_Typename*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeTypedef() const
|
||||
forceinline Code::operator CodeTypedef() const
|
||||
{
|
||||
return { (AST_Typedef*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeUnion() const
|
||||
forceinline Code::operator CodeUnion() const
|
||||
{
|
||||
return { (AST_Union*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeUsing() const
|
||||
forceinline Code::operator CodeUsing() const
|
||||
{
|
||||
return { (AST_Using*)ast };
|
||||
}
|
||||
|
||||
inline Code::operator CodeVar() const
|
||||
forceinline Code::operator CodeVar() const
|
||||
{
|
||||
return { (AST_Var*)ast };
|
||||
}
|
||||
|
||||
GEN_OPITMIZE_MAPPINGS_END
|
||||
#pragma endregion generated AST / Code cast implementation
|
@ -5,7 +5,7 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
enum CodeType_Def : u32
|
||||
enum CodeType : u32
|
||||
{
|
||||
CT_Invalid,
|
||||
CT_Untyped,
|
||||
@ -68,13 +68,13 @@ enum CodeType_Def : u32
|
||||
CT_Using,
|
||||
CT_Using_Namespace,
|
||||
CT_Variable,
|
||||
CT_NumTypes
|
||||
CT_NumTypes,
|
||||
CT_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
typedef enum CodeType_Def CodeType;
|
||||
|
||||
inline StrC to_str( CodeType type )
|
||||
inline StrC codetype_to_str( CodeType type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
local_persist StrC lookup[61] = {
|
||||
{ sizeof( "Invalid" ), "Invalid" },
|
||||
{ sizeof( "Untyped" ), "Untyped" },
|
||||
{ sizeof( "NewLine" ), "NewLine" },
|
||||
@ -139,3 +139,81 @@ inline StrC to_str( CodeType type )
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline StrC codetype_to_keyword_str( CodeType type )
|
||||
{
|
||||
local_persist StrC lookup[61] = {
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "//" ) - 1, "//" },
|
||||
{ sizeof( "private" ) - 1, "private" },
|
||||
{ sizeof( "protected" ) - 1, "protected" },
|
||||
{ sizeof( "public" ) - 1, "public" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "class" ) - 1, "class" },
|
||||
{ sizeof( "clsss" ) - 1, "clsss" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "enum" ) - 1, "enum" },
|
||||
{ sizeof( "enum" ) - 1, "enum" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "enum class" ) - 1, "enum class" },
|
||||
{ sizeof( "enum class" ) - 1, "enum class" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "extern" ) - 1, "extern" },
|
||||
{ sizeof( "extern" ) - 1, "extern" },
|
||||
{ sizeof( "friend" ) - 1, "friend" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "module" ) - 1, "module" },
|
||||
{ sizeof( "namespace" ) - 1, "namespace" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "operator" ) - 1, "operator" },
|
||||
{ sizeof( "operator" ) - 1, "operator" },
|
||||
{ sizeof( "operator" ) - 1, "operator" },
|
||||
{ sizeof( "operator" ) - 1, "operator" },
|
||||
{ sizeof( "operator" ) - 1, "operator" },
|
||||
{ sizeof( "operator" ) - 1, "operator" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "define" ) - 1, "define" },
|
||||
{ sizeof( "include" ) - 1, "include" },
|
||||
{ sizeof( "if" ) - 1, "if" },
|
||||
{ sizeof( "ifdef" ) - 1, "ifdef" },
|
||||
{ sizeof( "ifndef" ) - 1, "ifndef" },
|
||||
{ sizeof( "elif" ) - 1, "elif" },
|
||||
{ sizeof( "else" ) - 1, "else" },
|
||||
{ sizeof( "endif" ) - 1, "endif" },
|
||||
{ sizeof( "pragma" ) - 1, "pragma" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "struct" ) - 1, "struct" },
|
||||
{ sizeof( "struct" ) - 1, "struct" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "template" ) - 1, "template" },
|
||||
{ sizeof( "typedef" ) - 1, "typedef" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "union" ) - 1, "union" },
|
||||
{ sizeof( "union" ) - 1, "union" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
{ sizeof( "using" ) - 1, "using" },
|
||||
{ sizeof( "using namespace" ) - 1, "using namespace" },
|
||||
{ sizeof( "__NA__" ) - 1, "__NA__" },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
forceinline StrC to_str( CodeType type )
|
||||
{
|
||||
return codetype_to_str( type );
|
||||
}
|
||||
|
||||
forceinline StrC to_keyword_str( CodeType type )
|
||||
{
|
||||
return codetype_to_keyword_str( type );
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
enum Operator_Def : u32
|
||||
enum Operator : u32
|
||||
{
|
||||
Op_Invalid,
|
||||
Op_Assign,
|
||||
@ -54,13 +54,13 @@ enum Operator_Def : u32
|
||||
Op_NewArray,
|
||||
Op_Delete,
|
||||
Op_DeleteArray,
|
||||
NumOps
|
||||
Op_NumOps,
|
||||
Op_UnderlyingType = 0xffffffffu
|
||||
};
|
||||
typedef enum Operator_Def Operator;
|
||||
|
||||
inline StrC to_str( Operator op )
|
||||
inline StrC operator_to_str( Operator op )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
local_persist StrC lookup[47] = {
|
||||
{ sizeof( "INVALID" ), "INVALID" },
|
||||
{ sizeof( "=" ), "=" },
|
||||
{ sizeof( "+=" ), "+=" },
|
||||
@ -111,3 +111,8 @@ inline StrC to_str( Operator op )
|
||||
};
|
||||
return lookup[op];
|
||||
}
|
||||
|
||||
forceinline StrC to_str( Operator op )
|
||||
{
|
||||
return operator_to_str( op );
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
enum Specifier_Def : u32
|
||||
enum Specifier : u32
|
||||
{
|
||||
Spec_Invalid,
|
||||
Spec_Consteval,
|
||||
@ -33,18 +33,13 @@ enum Specifier_Def : u32
|
||||
Spec_Override,
|
||||
Spec_Pure,
|
||||
Spec_Volatile,
|
||||
Spec_NumSpecifiers
|
||||
Spec_NumSpecifiers,
|
||||
Spec_UnderlyingType = 0xffffffffu
|
||||
};
|
||||
typedef enum Specifier_Def Specifier;
|
||||
|
||||
inline bool is_trailing( Specifier specifier )
|
||||
inline StrC spec_to_str( Specifier type )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
}
|
||||
|
||||
inline StrC to_str( Specifier type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
local_persist StrC lookup[26] = {
|
||||
{ sizeof( "INVALID" ), "INVALID" },
|
||||
{ sizeof( "consteval" ), "consteval" },
|
||||
{ sizeof( "constexpr" ), "constexpr" },
|
||||
@ -75,12 +70,17 @@ inline StrC to_str( Specifier type )
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline Specifier to_specifier( StrC str )
|
||||
inline bool spec_is_trailing( Specifier specifier )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
}
|
||||
|
||||
inline Specifier strc_to_specifier( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[Spec_NumSpecifiers];
|
||||
do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Specifier)index );
|
||||
StrC enum_str = spec_to_str( (Specifier)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
@ -91,3 +91,18 @@ inline Specifier to_specifier( StrC str )
|
||||
}
|
||||
return Spec_Invalid;
|
||||
}
|
||||
|
||||
forceinline StrC to_str( Specifier spec )
|
||||
{
|
||||
return spec_to_str( spec );
|
||||
}
|
||||
|
||||
forceinline Specifier to_type( StrC str )
|
||||
{
|
||||
return strc_to_specifier( str );
|
||||
}
|
||||
|
||||
forceinline bool is_trailing( Specifier specifier )
|
||||
{
|
||||
return spec_is_trailing( specifier );
|
||||
}
|
@ -6,9 +6,10 @@
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
GEN_NS_PARSER_BEGIN
|
||||
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
|
||||
|
||||
enum TokType_Def : u32
|
||||
enum TokType : u32
|
||||
{
|
||||
Tok_Invalid,
|
||||
Tok_Access_Private,
|
||||
@ -109,11 +110,10 @@ enum TokType_Def : u32
|
||||
Tok_Attribute_API_Import,
|
||||
Tok_NumTokens
|
||||
};
|
||||
typedef enum TokType_Def TokType;
|
||||
|
||||
inline StrC to_str( TokType type )
|
||||
inline StrC toktype_to_str( TokType type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
local_persist StrC lookup[] = {
|
||||
{ sizeof( "__invalid__" ), "__invalid__" },
|
||||
{ sizeof( "private" ), "private" },
|
||||
{ sizeof( "protected" ), "protected" },
|
||||
@ -215,12 +215,12 @@ inline StrC to_str( TokType type )
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline TokType to_toktype( StrC str )
|
||||
inline TokType strc_to_toktype( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[Tok_NumTokens];
|
||||
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (TokType)index );
|
||||
StrC enum_str = toktype_to_str( (TokType)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
@ -24,8 +24,8 @@
|
||||
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
|
||||
#ifndef TokenMap_FixedArena
|
||||
# define TokenMap_FixedArena FixedArena_8KB
|
||||
#endif
|
||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
||||
@ -42,17 +42,19 @@ constexpr s32 InitSize_DataArrays = 16;
|
||||
|
||||
// NOTE: This limits the maximum size of an allocation
|
||||
// If you are generating a string larger than this, increase the size of the bucket here.
|
||||
constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
||||
constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
||||
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
|
||||
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
||||
|
||||
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
||||
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
||||
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
|
||||
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
||||
// constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
||||
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||
|
||||
extern StrC enum_underlying_sig;
|
||||
|
||||
extern Code access_public;
|
||||
extern Code access_protected;
|
||||
extern Code access_private;
|
||||
@ -67,7 +69,7 @@ extern Code fmt_newline;
|
||||
|
||||
extern CodePragma pragma_once;
|
||||
|
||||
extern CodeParam param_varadic;
|
||||
extern CodeParams param_varadic;
|
||||
|
||||
extern CodePreprocessCond preprocess_else;
|
||||
extern CodePreprocessCond preprocess_endif;
|
||||
@ -131,38 +133,12 @@ extern CodeTypename t_typename;
|
||||
|
||||
#pragma endregion Constants
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#ifndef token_fmt
|
||||
# define gen_main main
|
||||
|
||||
# define __ NullCode
|
||||
|
||||
// Convienence for defining any name used with the gen api.
|
||||
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
||||
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
||||
|
||||
// Same as name just used to indicate intention of literal for code instead of names.
|
||||
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
||||
|
||||
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
||||
|
||||
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
||||
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
||||
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
|
||||
// Populate with strings via gen::get_cached_string.
|
||||
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
|
||||
extern Array(StringCached) PreprocessorDefines;
|
||||
|
||||
#ifdef GEN_EXPOSE_BACKEND
|
||||
|
||||
// Global allocator used for data with process lifetime.
|
||||
extern AllocatorInfo GlobalAllocator;
|
||||
extern Array(Arena) Global_AllocatorBuckets;
|
||||
@ -180,5 +156,4 @@ extern Array(StringCached) PreprocessorDefines;
|
||||
extern AllocatorInfo Allocator_StringArena;
|
||||
extern AllocatorInfo Allocator_StringTable;
|
||||
extern AllocatorInfo Allocator_TypeTable;
|
||||
|
||||
#endif
|
32
base/components/header_start.hpp
Normal file
32
base/components/header_start.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
|
||||
|
||||
See Readme.md for more information from the project repository.
|
||||
|
||||
Public Address:
|
||||
https://github.com/Ed94/gencpp --------------------------------------------------------------.
|
||||
| _____ _____ _ _ |
|
||||
| / ____) / ____} | | | |
|
||||
| | / ___ ___ _ __ ___ _ __ _ __ | {___ | |__ _ _, __ _, ___ __| | |
|
||||
| | |{_ |/ _ \ '_ \ / __} '_ l| '_ l `\___ \| __/ _` |/ _` |/ _ \/ _` | |
|
||||
| | l__j | ___/ | | | {__; |+l } |+l | ____) | l| (_| | {_| | ___/ (_| | |
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ============================================================================================ |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
! ============================================================================================ /
|
||||
*/
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.hpp"
|
||||
#endif
|
@ -5,13 +5,14 @@
|
||||
|
||||
#pragma region Code
|
||||
inline
|
||||
void append( Code self, Code other )
|
||||
void code_append( Code self, Code other )
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
GEN_ASSERT(other.ast != nullptr);
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(other);
|
||||
GEN_ASSERT_MSG(self != other, "Attempted to recursively append Code AST to itself.");
|
||||
|
||||
if ( other->Parent )
|
||||
other = duplicate(other);
|
||||
if ( other->Parent != nullptr )
|
||||
other = code_duplicate(other);
|
||||
|
||||
other->Parent = self;
|
||||
|
||||
@ -32,9 +33,9 @@ void append( Code self, Code other )
|
||||
self->NumEntries++;
|
||||
}
|
||||
inline
|
||||
bool is_body(Code self)
|
||||
bool code_is_body(Code self)
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
GEN_ASSERT(self);
|
||||
switch (self->Type)
|
||||
{
|
||||
case CT_Enum_Body:
|
||||
@ -51,9 +52,9 @@ bool is_body(Code self)
|
||||
return false;
|
||||
}
|
||||
inline
|
||||
Code* entry( Code self, u32 idx )
|
||||
Code* code_entry( Code self, u32 idx )
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
GEN_ASSERT(self != nullptr);
|
||||
Code* current = & self->Front;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
@ -66,29 +67,31 @@ Code* entry( Code self, u32 idx )
|
||||
|
||||
return rcast( Code*, current);
|
||||
}
|
||||
inline
|
||||
bool is_valid(Code self)
|
||||
forceinline
|
||||
bool code_is_valid(Code self)
|
||||
{
|
||||
return self.ast != nullptr && self.ast->Type != CT_Invalid;
|
||||
GEN_ASSERT(self);
|
||||
return self != nullptr && self->Type != CT_Invalid;
|
||||
}
|
||||
inline
|
||||
bool has_entries(AST* self)
|
||||
forceinline
|
||||
bool code_has_entries(AST* self)
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
GEN_ASSERT(self);
|
||||
return self->NumEntries > 0;
|
||||
}
|
||||
inline
|
||||
void set_global(Code self)
|
||||
forceinline
|
||||
void code_set_global(Code self)
|
||||
{
|
||||
if ( self.ast == nullptr )
|
||||
if ( self == nullptr )
|
||||
{
|
||||
log_failure("Code::set_global: Cannot set code as global, AST is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
self->Parent.ast = Code_Global.ast;
|
||||
self->Parent = Code_Global;
|
||||
}
|
||||
inline
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
@ -96,55 +99,69 @@ Code& Code::operator ++()
|
||||
|
||||
return * this;
|
||||
}
|
||||
inline
|
||||
char const* type_str(Code self)
|
||||
#endif
|
||||
forceinline
|
||||
StrC code_type_str(Code self)
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
return to_str( self->Type );
|
||||
return codetype_to_str( self->Type );
|
||||
}
|
||||
#pragma endregion Code
|
||||
|
||||
#pragma region CodeBody
|
||||
inline
|
||||
void append( CodeBody self, Code other )
|
||||
void body_append( CodeBody self, Code other )
|
||||
{
|
||||
GEN_ASSERT(other.ast != nullptr);
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(other);
|
||||
|
||||
if (is_body(other)) {
|
||||
append( self, cast(CodeBody, other) );
|
||||
if (code_is_body(other)) {
|
||||
body_append_body( self, cast(CodeBody, other) );
|
||||
return;
|
||||
}
|
||||
|
||||
append( cast(Code, self), other );
|
||||
code_append( cast(Code, self), other );
|
||||
}
|
||||
inline
|
||||
void append( CodeBody self, CodeBody body )
|
||||
void body_append_body( CodeBody self, CodeBody body )
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(body);
|
||||
GEN_ASSERT_MSG(self != body, "Attempted to append body to itself.");
|
||||
|
||||
for ( Code entry : body ) {
|
||||
append( self, entry );
|
||||
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); entry = next_CodeBody(body, entry) ) {
|
||||
body_append( self, entry );
|
||||
}
|
||||
}
|
||||
inline
|
||||
Code begin( CodeBody body) {
|
||||
if ( body.ast )
|
||||
return { rcast( AST*, body.ast)->Front };
|
||||
return { nullptr };
|
||||
Code begin_CodeBody( CodeBody body) {
|
||||
GEN_ASSERT(body);
|
||||
if ( body != nullptr )
|
||||
return body->Front;
|
||||
|
||||
return NullCode;
|
||||
}
|
||||
forceinline
|
||||
Code end_CodeBody(CodeBody body ){
|
||||
GEN_ASSERT(body);
|
||||
return body->Back->Next;
|
||||
}
|
||||
inline
|
||||
Code end(CodeBody body ){
|
||||
return { rcast(AST*, body.ast)->Back->Next };
|
||||
Code next_CodeBody(CodeBody body, Code entry) {
|
||||
GEN_ASSERT(body);
|
||||
GEN_ASSERT(entry);
|
||||
return entry->Next;
|
||||
}
|
||||
#pragma endregion CodeBody
|
||||
|
||||
#pragma region CodeClass
|
||||
inline
|
||||
void add_interface( CodeClass self, CodeTypename type )
|
||||
void class_add_interface( CodeClass self, CodeTypename type )
|
||||
{
|
||||
GEN_ASSERT(self.ast !=nullptr);
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(type);
|
||||
CodeTypename possible_slot = self->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
if ( possible_slot != nullptr )
|
||||
{
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
self->ParentAccess = AccessSpec_Public;
|
||||
@ -152,25 +169,27 @@ void add_interface( CodeClass self, CodeTypename type )
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot.ast != nullptr )
|
||||
while ( possible_slot != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Typename*) possible_slot->Next.ast;
|
||||
possible_slot = cast(CodeTypename, possible_slot->Next);
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
possible_slot = type;
|
||||
}
|
||||
#pragma endregion CodeClass
|
||||
|
||||
#pragma region CodeParam
|
||||
#pragma region CodeParams
|
||||
inline
|
||||
void append( CodeParam appendee, CodeParam other )
|
||||
void params_append( CodeParams appendee, CodeParams other )
|
||||
{
|
||||
GEN_ASSERT(appendee.ast != nullptr);
|
||||
GEN_ASSERT(appendee);
|
||||
GEN_ASSERT(other);
|
||||
GEN_ASSERT_MSG(appendee != other, "Attempted to append parameter to itself.");
|
||||
Code self = cast(Code, appendee);
|
||||
Code entry = cast(Code, other);
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = GEN_NS duplicate( entry );
|
||||
if ( entry->Parent != nullptr )
|
||||
entry = code_duplicate( entry );
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
@ -187,54 +206,62 @@ void append( CodeParam appendee, CodeParam other )
|
||||
self->NumEntries++;
|
||||
}
|
||||
inline
|
||||
CodeParam get(CodeParam self, s32 idx )
|
||||
CodeParams params_get(CodeParams self, s32 idx )
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
CodeParam param = * self;
|
||||
GEN_ASSERT(self);
|
||||
CodeParams param = self;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
if ( ++ param != nullptr )
|
||||
return NullCode;
|
||||
|
||||
param = cast(Code, param)->Next;
|
||||
param = cast(CodeParams, cast(Code, param)->Next);
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return param;
|
||||
}
|
||||
inline
|
||||
bool has_entries(CodeParam self)
|
||||
forceinline
|
||||
bool params_has_entries(CodeParams self)
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
GEN_ASSERT(self);
|
||||
return self->NumEntries > 0;
|
||||
}
|
||||
inline
|
||||
CodeParam& CodeParam::operator ++()
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline
|
||||
CodeParams& CodeParams::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
* this = ast->Next;
|
||||
return * this;
|
||||
}
|
||||
inline
|
||||
CodeParam begin(CodeParam params)
|
||||
#endif
|
||||
forceinline
|
||||
CodeParams begin_CodeParams(CodeParams params)
|
||||
{
|
||||
if ( params.ast )
|
||||
return { params.ast };
|
||||
if ( params != nullptr )
|
||||
return params;
|
||||
|
||||
return { nullptr };
|
||||
return NullCode;
|
||||
}
|
||||
inline
|
||||
CodeParam end(CodeParam params)
|
||||
forceinline
|
||||
CodeParams end_CodeParams(CodeParams params)
|
||||
{
|
||||
// return { (AST_Param*) rcast( AST*, ast)->Last };
|
||||
return { nullptr };
|
||||
// return { (AST_Params*) rcast( AST*, ast)->Last };
|
||||
return NullCode;
|
||||
}
|
||||
#pragma endregion CodeParam
|
||||
forceinline
|
||||
CodeParams next_CodeParams(CodeParams params, CodeParams param_iter)
|
||||
{
|
||||
GEN_ASSERT(param_iter);
|
||||
return param_iter->Next;
|
||||
}
|
||||
#pragma endregion CodeParams
|
||||
|
||||
#pragma region CodeSpecifiers
|
||||
inline
|
||||
bool append(CodeSpecifiers self, Specifier spec )
|
||||
bool specifiers_append(CodeSpecifiers self, Specifier spec )
|
||||
{
|
||||
if ( self.ast == nullptr )
|
||||
if ( self == nullptr )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
|
||||
return false;
|
||||
@ -250,9 +277,9 @@ bool append(CodeSpecifiers self, Specifier spec )
|
||||
return true;
|
||||
}
|
||||
inline
|
||||
s32 has(CodeSpecifiers self, Specifier spec)
|
||||
s32 specifiers_has(CodeSpecifiers self, Specifier spec)
|
||||
{
|
||||
GEN_ASSERT(self.ast != nullptr);
|
||||
GEN_ASSERT(self != nullptr);
|
||||
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
|
||||
if ( self->ArrSpecs[ idx ] == spec )
|
||||
return idx;
|
||||
@ -260,10 +287,9 @@ s32 has(CodeSpecifiers self, Specifier spec)
|
||||
return -1;
|
||||
}
|
||||
inline
|
||||
s32 remove( CodeSpecifiers self, Specifier to_remove )
|
||||
s32 specifiers_remove( CodeSpecifiers self, Specifier to_remove )
|
||||
{
|
||||
AST_Specifiers* ast = self.ast;
|
||||
if ( ast == nullptr )
|
||||
if ( self == nullptr )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
|
||||
return -1;
|
||||
@ -300,27 +326,32 @@ s32 remove( CodeSpecifiers self, Specifier to_remove )
|
||||
}
|
||||
return result;
|
||||
}
|
||||
inline
|
||||
Specifier* begin(CodeSpecifiers self)
|
||||
forceinline
|
||||
Specifier* begin_CodeSpecifiers(CodeSpecifiers self)
|
||||
{
|
||||
if ( self.ast )
|
||||
if ( self != nullptr )
|
||||
return & self->ArrSpecs[0];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
inline
|
||||
Specifier* end(CodeSpecifiers self)
|
||||
forceinline
|
||||
Specifier* end_CodeSpecifiers(CodeSpecifiers self)
|
||||
{
|
||||
return self->ArrSpecs + self->NumEntries;
|
||||
}
|
||||
forceinline
|
||||
Specifier* next_CodeSpecifiers(CodeSpecifiers self, Specifier* spec_iter)
|
||||
{
|
||||
return spec_iter + 1;
|
||||
}
|
||||
#pragma endregion CodeSpecifiers
|
||||
|
||||
#pragma region CodeStruct
|
||||
inline
|
||||
void add_interface(CodeStruct self, CodeTypename type )
|
||||
void struct_add_interface(CodeStruct self, CodeTypename type )
|
||||
{
|
||||
CodeTypename possible_slot = self->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
if ( possible_slot != nullptr )
|
||||
{
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
self->ParentAccess = AccessSpec_Public;
|
||||
@ -328,12 +359,12 @@ void add_interface(CodeStruct self, CodeTypename type )
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot.ast != nullptr )
|
||||
while ( possible_slot != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Typename*) possible_slot->Next.ast;
|
||||
possible_slot = cast(CodeTypename, possible_slot->Next);
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
possible_slot = type;
|
||||
}
|
||||
#pragma endregion Code
|
||||
|
||||
@ -355,7 +386,7 @@ CodeBody def_body( CodeType type )
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)to_str(type) );
|
||||
log_failure( "def_body: Invalid type %s", codetype_to_str(type).Ptr );
|
||||
return (CodeBody)Code_Invalid;
|
||||
}
|
||||
|
||||
@ -377,6 +408,7 @@ StrC token_fmt_impl( ssize num, ... )
|
||||
ssize result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
StrC str = { result, buf };
|
||||
return str;
|
||||
}
|
||||
#pragma endregion Interface
|
@ -3,10 +3,10 @@
|
||||
#include "code_serialization.cpp"
|
||||
#endif
|
||||
|
||||
namespace parser {
|
||||
internal void init();
|
||||
internal void deinit();
|
||||
}
|
||||
GEN_NS_PARSER_BEGIN
|
||||
internal void parser_init();
|
||||
internal void parser_deinit();
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
internal
|
||||
void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
|
||||
@ -79,73 +79,79 @@ void define_constants()
|
||||
Code_Global->Content = Code_Global->Name;
|
||||
|
||||
Code_Invalid = make_code();
|
||||
set_global(Code_Invalid);
|
||||
code_set_global(Code_Invalid);
|
||||
|
||||
t_empty = (CodeTypename) make_code();
|
||||
t_empty->Type = CT_Typename;
|
||||
t_empty->Name = get_cached_string( txt("") );
|
||||
set_global(t_empty);
|
||||
code_set_global(cast(Code, t_empty));
|
||||
|
||||
access_private = make_code();
|
||||
access_private->Type = CT_Access_Private;
|
||||
access_private->Name = get_cached_string( txt("private:\n") );
|
||||
set_global(access_private);
|
||||
code_set_global(cast(Code, access_private));
|
||||
|
||||
access_protected = make_code();
|
||||
access_protected->Type = CT_Access_Protected;
|
||||
access_protected->Name = get_cached_string( txt("protected:\n") );
|
||||
set_global(access_protected);
|
||||
code_set_global(access_protected);
|
||||
|
||||
access_public = make_code();
|
||||
access_public->Type = CT_Access_Public;
|
||||
access_public->Name = get_cached_string( txt("public:\n") );
|
||||
set_global(access_public);
|
||||
code_set_global(access_public);
|
||||
|
||||
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
|
||||
set_global(attrib_api_export);
|
||||
StrC api_export_str = code(GEN_API_Export_Code);
|
||||
attrib_api_export = def_attributes( api_export_str );
|
||||
code_set_global(cast(Code, attrib_api_export));
|
||||
|
||||
attrib_api_import = def_attributes( code(GEN_API_Import_Code));
|
||||
set_global(attrib_api_import);
|
||||
StrC api_import_str = code(GEN_API_Import_Code);
|
||||
attrib_api_import = def_attributes( api_import_str );
|
||||
code_set_global(cast(Code, attrib_api_import));
|
||||
|
||||
module_global_fragment = make_code();
|
||||
module_global_fragment->Type = CT_Untyped;
|
||||
module_global_fragment->Name = get_cached_string( txt("module;") );
|
||||
module_global_fragment->Content = module_global_fragment->Name;
|
||||
set_global(module_global_fragment);
|
||||
code_set_global(cast(Code, module_global_fragment));
|
||||
|
||||
module_private_fragment = make_code();
|
||||
module_private_fragment->Type = CT_Untyped;
|
||||
module_private_fragment->Name = get_cached_string( txt("module : private;") );
|
||||
module_private_fragment->Content = module_private_fragment->Name;
|
||||
set_global(module_private_fragment);
|
||||
code_set_global(cast(Code, module_private_fragment));
|
||||
|
||||
fmt_newline = make_code();
|
||||
fmt_newline->Type = CT_NewLine;
|
||||
set_global(fmt_newline);
|
||||
|
||||
code_set_global((Code)fmt_newline);
|
||||
|
||||
pragma_once = (CodePragma) make_code();
|
||||
pragma_once->Type = CT_Preprocess_Pragma;
|
||||
pragma_once->Name = get_cached_string( txt("once") );
|
||||
pragma_once->Content = pragma_once->Name;
|
||||
set_global(pragma_once);
|
||||
code_set_global((Code)pragma_once);
|
||||
|
||||
param_varadic = (CodeTypename) make_code();
|
||||
param_varadic = (CodeParams) make_code();
|
||||
param_varadic->Type = CT_Parameters;
|
||||
param_varadic->Name = get_cached_string( txt("...") );
|
||||
param_varadic->ValueType = t_empty;
|
||||
set_global(param_varadic);
|
||||
code_set_global((Code)param_varadic);
|
||||
|
||||
preprocess_else = (CodePreprocessCond) make_code();
|
||||
preprocess_else->Type = CT_Preprocess_Else;
|
||||
set_global(preprocess_else);
|
||||
code_set_global((Code)preprocess_else);
|
||||
|
||||
preprocess_endif = (CodePreprocessCond) make_code();
|
||||
preprocess_endif->Type = CT_Preprocess_EndIf;
|
||||
set_global(preprocess_endif);
|
||||
code_set_global((Code)preprocess_endif);
|
||||
|
||||
# define def_constant_code_type( Type_ ) \
|
||||
t_##Type_ = def_type( name(Type_) ); \
|
||||
set_global(t_##Type_);
|
||||
# define def_constant_code_type( Type_ ) \
|
||||
do \
|
||||
{ \
|
||||
StrC name_str = name(Type_); \
|
||||
t_##Type_ = def_type( name_str ); \
|
||||
code_set_global( cast(Code, t_##Type_)); \
|
||||
} while(0)
|
||||
|
||||
def_constant_code_type( auto );
|
||||
def_constant_code_type( void );
|
||||
@ -177,58 +183,38 @@ void define_constants()
|
||||
#endif
|
||||
# undef def_constant_code_type
|
||||
|
||||
|
||||
# define def_constant_spec( Type_, ... ) \
|
||||
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||
set_global(spec_##Type_);
|
||||
|
||||
# pragma push_macro("forceinline")
|
||||
# pragma push_macro("global")
|
||||
# pragma push_macro("internal")
|
||||
# pragma push_macro("local_persist")
|
||||
# pragma push_macro("neverinline")
|
||||
# undef forceinline
|
||||
# undef global
|
||||
# undef internal
|
||||
# undef local_persist
|
||||
# undef neverinline
|
||||
def_constant_spec( const, Spec_Const );
|
||||
def_constant_spec( consteval, Spec_Consteval );
|
||||
def_constant_spec( constexpr, Spec_Constexpr );
|
||||
def_constant_spec( constinit, Spec_Constinit );
|
||||
def_constant_spec( extern_linkage, Spec_External_Linkage );
|
||||
def_constant_spec( final, Spec_Final );
|
||||
def_constant_spec( forceinline, Spec_ForceInline );
|
||||
def_constant_spec( global, Spec_Global );
|
||||
def_constant_spec( inline, Spec_Inline );
|
||||
def_constant_spec( internal_linkage, Spec_Internal_Linkage );
|
||||
def_constant_spec( local_persist, Spec_Local_Persist );
|
||||
def_constant_spec( mutable, Spec_Mutable );
|
||||
def_constant_spec( neverinline, Spec_NeverInline );
|
||||
def_constant_spec( noexcept, Spec_NoExceptions );
|
||||
def_constant_spec( override, Spec_Override );
|
||||
def_constant_spec( ptr, Spec_Ptr );
|
||||
def_constant_spec( pure, Spec_Pure )
|
||||
def_constant_spec( ref, Spec_Ref );
|
||||
def_constant_spec( register, Spec_Register );
|
||||
def_constant_spec( rvalue, Spec_RValue );
|
||||
def_constant_spec( static_member, Spec_Static );
|
||||
def_constant_spec( thread_local, Spec_Thread_Local );
|
||||
def_constant_spec( virtual, Spec_Virtual );
|
||||
def_constant_spec( volatile, Spec_Volatile)
|
||||
spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const ));
|
||||
spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval ));;
|
||||
spec_constexpr = def_specifier( Spec_Constexpr); code_set_global( cast(Code, spec_constexpr ));;
|
||||
spec_constinit = def_specifier( Spec_Constinit); code_set_global( cast(Code, spec_constinit ));;
|
||||
spec_extern_linkage = def_specifier( Spec_External_Linkage); code_set_global( cast(Code, spec_extern_linkage ));;
|
||||
spec_final = def_specifier( Spec_Final); code_set_global( cast(Code, spec_final ));;
|
||||
spec_forceinline = def_specifier( Spec_ForceInline); code_set_global( cast(Code, spec_forceinline ));;
|
||||
spec_global = def_specifier( Spec_Global); code_set_global( cast(Code, spec_global ));;
|
||||
spec_inline = def_specifier( Spec_Inline); code_set_global( cast(Code, spec_inline ));;
|
||||
spec_internal_linkage = def_specifier( Spec_Internal_Linkage); code_set_global( cast(Code, spec_internal_linkage ));;
|
||||
spec_local_persist = def_specifier( Spec_Local_Persist); code_set_global( cast(Code, spec_local_persist ));;
|
||||
spec_mutable = def_specifier( Spec_Mutable); code_set_global( cast(Code, spec_mutable ));;
|
||||
spec_neverinline = def_specifier( Spec_NeverInline); code_set_global( cast(Code, spec_neverinline ));;
|
||||
spec_noexcept = def_specifier( Spec_NoExceptions); code_set_global( cast(Code, spec_noexcept ));;
|
||||
spec_override = def_specifier( Spec_Override); code_set_global( cast(Code, spec_override ));;
|
||||
spec_ptr = def_specifier( Spec_Ptr); code_set_global( cast(Code, spec_ptr ));;
|
||||
spec_pure = def_specifier( Spec_Pure); code_set_global( cast(Code, spec_pure ));
|
||||
spec_ref = def_specifier( Spec_Ref); code_set_global( cast(Code, spec_ref ));;
|
||||
spec_register = def_specifier( Spec_Register); code_set_global( cast(Code, spec_register ));;
|
||||
spec_rvalue = def_specifier( Spec_RValue); code_set_global( cast(Code, spec_rvalue ));;
|
||||
spec_static_member = def_specifier( Spec_Static); code_set_global( cast(Code, spec_static_member ));;
|
||||
spec_thread_local = def_specifier( Spec_Thread_Local); code_set_global( cast(Code, spec_thread_local ));;
|
||||
spec_virtual = def_specifier( Spec_Virtual); code_set_global( cast(Code, spec_virtual ));;
|
||||
spec_volatile = def_specifier( Spec_Volatile); code_set_global( cast(Code, spec_volatile ));
|
||||
|
||||
spec_local_persist = def_specifiers( 1, Spec_Local_Persist );
|
||||
set_global(spec_local_persist);
|
||||
code_set_global(cast(Code, spec_local_persist));
|
||||
|
||||
# pragma pop_macro("forceinline")
|
||||
# pragma pop_macro("global")
|
||||
# pragma pop_macro("internal")
|
||||
# pragma pop_macro("local_persist")
|
||||
# pragma pop_macro("neverinline")
|
||||
|
||||
# pragma push_macro("enum_underlying")
|
||||
array_append(PreprocessorDefines, txt("enum_underlying("));
|
||||
# pragma pop_macro("enum_underlying")
|
||||
if (enum_underlying_sig.Len == 0) {
|
||||
enum_underlying_sig = txt("enum_underlying(");
|
||||
}
|
||||
array_append(PreprocessorDefines, enum_underlying_sig);
|
||||
|
||||
# undef def_constant_spec
|
||||
}
|
||||
@ -237,9 +223,10 @@ void init()
|
||||
{
|
||||
// Setup global allocator
|
||||
{
|
||||
GlobalAllocator = AllocatorInfo { & Global_Allocator_Proc, nullptr };
|
||||
AllocatorInfo becasue_C = { & Global_Allocator_Proc, nullptr };
|
||||
GlobalAllocator = becasue_C;
|
||||
|
||||
Global_AllocatorBuckets = array_init_reserve<Arena>( heap(), 128 );
|
||||
Global_AllocatorBuckets = array_init_reserve(Arena, heap(), 128 );
|
||||
|
||||
if ( Global_AllocatorBuckets == nullptr )
|
||||
GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets");
|
||||
@ -252,14 +239,33 @@ void init()
|
||||
array_append( Global_AllocatorBuckets, bucket );
|
||||
}
|
||||
|
||||
if (Allocator_DataArrays.Proc == nullptr) {
|
||||
Allocator_DataArrays = GlobalAllocator;
|
||||
}
|
||||
if (Allocator_CodePool.Proc == nullptr ) {
|
||||
Allocator_CodePool = GlobalAllocator;
|
||||
}
|
||||
if (Allocator_Lexer.Proc == nullptr) {
|
||||
Allocator_Lexer = GlobalAllocator;
|
||||
}
|
||||
if (Allocator_StringArena.Proc == nullptr) {
|
||||
Allocator_StringArena = GlobalAllocator;
|
||||
}
|
||||
if (Allocator_StringTable.Proc == nullptr) {
|
||||
Allocator_StringTable = GlobalAllocator;
|
||||
}
|
||||
if (Allocator_TypeTable.Proc == nullptr) {
|
||||
Allocator_TypeTable = GlobalAllocator;
|
||||
}
|
||||
|
||||
// Setup the arrays
|
||||
{
|
||||
CodePools = array_init_reserve<Pool>( Allocator_DataArrays, InitSize_DataArrays );
|
||||
CodePools = array_init_reserve(Pool, Allocator_DataArrays, InitSize_DataArrays );
|
||||
|
||||
if ( CodePools == nullptr )
|
||||
GEN_FATAL( "gen::init: Failed to initialize the CodePools array" );
|
||||
|
||||
StringArenas = array_init_reserve<Arena>( Allocator_DataArrays, InitSize_DataArrays );
|
||||
StringArenas = array_init_reserve(Arena, Allocator_DataArrays, InitSize_DataArrays );
|
||||
|
||||
if ( StringArenas == nullptr )
|
||||
GEN_FATAL( "gen::init: Failed to initialize the StringArenas array" );
|
||||
@ -286,17 +292,17 @@ void init()
|
||||
|
||||
// Setup the hash tables
|
||||
{
|
||||
StringCache = hashtable_init<StringCached>(Allocator_StringTable);
|
||||
StringCache = hashtable_init(StringCached, Allocator_StringTable);
|
||||
|
||||
if ( StringCache.Entries == nullptr )
|
||||
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
||||
}
|
||||
|
||||
// Preprocessor Defines
|
||||
PreprocessorDefines = array_init_reserve<StringCached>( GlobalAllocator, kilobytes(1) );
|
||||
PreprocessorDefines = array_init_reserve(StringCached, GlobalAllocator, kilobytes(1) );
|
||||
|
||||
define_constants();
|
||||
GEN_NS_PARSER init();
|
||||
GEN_NS_PARSER parser_init();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
@ -341,7 +347,7 @@ void deinit()
|
||||
while ( left--, left );
|
||||
|
||||
array_free(Global_AllocatorBuckets);
|
||||
GEN_NS_PARSER deinit();
|
||||
GEN_NS_PARSER parser_deinit();
|
||||
}
|
||||
|
||||
void reset()
|
||||
@ -377,7 +383,7 @@ AllocatorInfo get_string_allocator( s32 str_length )
|
||||
|
||||
usize size_req = str_length + sizeof(StringHeader) + sizeof(char*);
|
||||
|
||||
if ( last->TotalUsed + ssize(size_req) > last->TotalSize )
|
||||
if ( last->TotalUsed + scast(ssize, size_req) > last->TotalSize )
|
||||
{
|
||||
Arena new_arena = arena_init_from_allocator( Allocator_StringArena, SizePer_StringArena );
|
||||
|
||||
@ -405,7 +411,7 @@ StringCached get_cached_string( StrC str )
|
||||
StrC result = string_to_strc( string_make_strc( get_string_allocator( str.Len ), str ));
|
||||
hashtable_set(StringCache, key, result );
|
||||
|
||||
return { str.Len, result };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Used internally to retireve a Code object form the CodePool.
|
||||
@ -425,20 +431,8 @@ Code make_code()
|
||||
allocator = array_back( CodePools);
|
||||
}
|
||||
|
||||
Code result { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) };
|
||||
mem_set( result.ast, 0, sizeof(AST) );
|
||||
// result->Type = ECode::Invalid;
|
||||
|
||||
// result->Content = { nullptr };
|
||||
// result->Prev = { nullptr };
|
||||
// result->Next = { nullptr };
|
||||
// result->Token = nullptr;
|
||||
// result->Parent = { nullptr };
|
||||
// result->Name = { nullptr };
|
||||
// result->Type = ECode::Invalid;
|
||||
// result->ModuleFlags = ModuleFlag::Invalid;
|
||||
// result->NumEntries = 0;
|
||||
|
||||
Code result = { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) };
|
||||
mem_set( rcast(void*, cast(AST*, result)), 0, sizeof(AST) );
|
||||
return result;
|
||||
}
|
||||
|
@ -4,9 +4,18 @@
|
||||
#endif
|
||||
|
||||
#pragma region Gen Interface
|
||||
/*
|
||||
/ \ | \ | \ / \
|
||||
| ▓▓▓▓▓▓\ ______ _______ \▓▓▓▓▓▓_______ _| ▓▓_ ______ ______ | ▓▓▓▓▓▓\ ______ _______ ______
|
||||
| ▓▓ __\▓▓/ \| \ | ▓▓ | \| ▓▓ \ / \ / \| ▓▓_ \▓▓| \ / \/ \
|
||||
| ▓▓| \ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\ | ▓▓ | ▓▓▓▓▓▓▓\\▓▓▓▓▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓ \ \▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\
|
||||
| ▓▓ \▓▓▓▓ ▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ __| ▓▓ ▓▓ ▓▓ \▓▓ ▓▓▓▓ / ▓▓ ▓▓ | ▓▓ ▓▓
|
||||
| ▓▓__| ▓▓ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ _| ▓▓_| ▓▓ | ▓▓ | ▓▓| \ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ | ▓▓▓▓▓▓▓ ▓▓_____| ▓▓▓▓▓▓▓▓
|
||||
\▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ | ▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \\▓▓ \
|
||||
\▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
||||
*/
|
||||
|
||||
// Initialize the library.
|
||||
// This currently just initializes the CodePool.
|
||||
void init();
|
||||
|
||||
// Currently manually free's the arenas, code for checking for leaks.
|
||||
@ -43,24 +52,27 @@ CodeAttributes def_attributes( StrC content );
|
||||
CodeComment def_comment ( StrC content );
|
||||
|
||||
struct Opts_def_struct {
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeTypename parent;
|
||||
AccessSpec parent_access;
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
CodeTypename* interfaces;
|
||||
s32 num_interfaces;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeClass def_class( StrC name, Opts_def_struct otps GEN_PARAM_DEFAULT );
|
||||
CodeClass def_class( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_constructor {
|
||||
CodeParam params;
|
||||
CodeParams params;
|
||||
Code initializer_list;
|
||||
Code body;
|
||||
};
|
||||
CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeDefine def_define( StrC name, StrC content );
|
||||
struct Opts_def_define {
|
||||
b32 dont_append_preprocess_defines;
|
||||
};
|
||||
CodeDefine def_define( StrC name, StrC content, Opts_def_define opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_destructor {
|
||||
Code body;
|
||||
@ -69,22 +81,23 @@ struct Opts_def_destructor {
|
||||
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_enum {
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeTypename type;
|
||||
EnumT specifier;
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
Code type_macro;
|
||||
};
|
||||
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeExec def_execution ( StrC content );
|
||||
CodeExtern def_extern_link( StrC name, Code body );
|
||||
CodeExtern def_extern_link( StrC name, CodeBody body );
|
||||
CodeFriend def_friend ( Code symbol );
|
||||
|
||||
struct Opts_def_function {
|
||||
CodeParam params;
|
||||
CodeParams params;
|
||||
CodeTypename ret_type;
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specs;
|
||||
CodeAttributes attrs;
|
||||
ModuleFlag mflags;
|
||||
@ -94,14 +107,14 @@ CodeFn def_function( StrC name, Opts_def_function opts GEN_PARAM_DEFAULT );
|
||||
struct Opts_def_include { b32 foreign; };
|
||||
struct Opts_def_module { ModuleFlag mflags; };
|
||||
struct Opts_def_namespace { ModuleFlag mflags; };
|
||||
CodeInclude def_include ( StrC content, Opts_def_include opts GEN_PARAM_DEFAULT );
|
||||
CodeModule def_module ( StrC name, Opts_def_module opts GEN_PARAM_DEFAULT );
|
||||
CodeNS def_namespace( StrC name, Code body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||
CodeInclude def_include ( StrC content, Opts_def_include opts GEN_PARAM_DEFAULT );
|
||||
CodeModule def_module ( StrC name, Opts_def_module opts GEN_PARAM_DEFAULT );
|
||||
CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_operator {
|
||||
CodeParam params;
|
||||
CodeParams params;
|
||||
CodeTypename ret_type;
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specifiers;
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
@ -109,13 +122,13 @@ struct Opts_def_operator {
|
||||
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_operator_cast {
|
||||
Code body;
|
||||
CodeBody body;
|
||||
CodeSpecifiers specs;
|
||||
};
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_param { Code value; };
|
||||
CodeParam def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
CodeParams def_param ( CodeTypename type, StrC name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
CodePragma def_pragma( StrC directive );
|
||||
|
||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
|
||||
@ -125,9 +138,10 @@ CodeSpecifiers def_specifier( Specifier specifier );
|
||||
CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_template { ModuleFlag mflags; };
|
||||
CodeTemplate def_template( CodeParam params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
||||
CodeTemplate def_template( CodeParams params, Code definition, Opts_def_template opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_type {
|
||||
ETypenameTag type_tag;
|
||||
Code arrayexpr;
|
||||
CodeSpecifiers specifiers;
|
||||
CodeAttributes attributes;
|
||||
@ -144,13 +158,13 @@ struct Opts_def_union {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeUnion def_union( StrC name, Code body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
||||
CodeUnion def_union( StrC name, CodeBody body, Opts_def_union opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_using {
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeUsing def_using( StrC name, Code type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
||||
CodeUsing def_using( StrC name, CodeTypename type, Opts_def_using opts GEN_PARAM_DEFAULT );
|
||||
|
||||
CodeUsing def_using_namespace( StrC name );
|
||||
|
||||
@ -161,10 +175,10 @@ struct Opts_def_variable
|
||||
CodeAttributes attributes;
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
||||
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
||||
|
||||
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
|
||||
CodeBody def_body( CodeTypename type );
|
||||
CodeBody def_body( CodeType type );
|
||||
|
||||
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
||||
/// or provide as an array of Code objects.
|
||||
@ -183,8 +197,8 @@ CodeBody def_global_body ( s32 num, ... );
|
||||
CodeBody def_global_body ( s32 num, Code* codes );
|
||||
CodeBody def_namespace_body ( s32 num, ... );
|
||||
CodeBody def_namespace_body ( s32 num, Code* codes );
|
||||
CodeParam def_params ( s32 num, ... );
|
||||
CodeParam def_params ( s32 num, CodeParam* params );
|
||||
CodeParams def_params ( s32 num, ... );
|
||||
CodeParams def_params ( s32 num, CodeParams* params );
|
||||
CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
||||
CodeBody def_struct_body ( s32 num, ... );
|
||||
@ -199,23 +213,23 @@ CodeBody def_union_body ( s32 num, Code* codes );
|
||||
// TODO(Ed) : Implmeent the new parser API design.
|
||||
|
||||
#if 0
|
||||
namespace parser {
|
||||
struct StackNode
|
||||
{
|
||||
StackNode* Prev;
|
||||
GEN_NS_PARSER_BEGIN
|
||||
struct StackNode
|
||||
{
|
||||
StackNode* Prev;
|
||||
|
||||
Token Start;
|
||||
Token Name; // The name of the AST node (if parsed)
|
||||
StrC FailedProc; // The name of the procedure that failed
|
||||
};
|
||||
// Stack nodes are allocated the error's allocator
|
||||
Token Start;
|
||||
Token Name; // The name of the AST node (if parsed)
|
||||
StrC FailedProc; // The name of the procedure that failed
|
||||
};
|
||||
// Stack nodes are allocated the error's allocator
|
||||
|
||||
struct Error
|
||||
{
|
||||
String message;
|
||||
StackNode* context_stack;
|
||||
};
|
||||
}
|
||||
struct Error
|
||||
{
|
||||
String message;
|
||||
StackNode* context_stack;
|
||||
};
|
||||
GEN_NS_PARSER_END
|
||||
|
||||
struct ParseInfo
|
||||
{
|
||||
@ -223,9 +237,9 @@ struct ParseInfo
|
||||
Arena TokMem;
|
||||
Arena CodeMem;
|
||||
|
||||
FileContents FileContent;
|
||||
Array<parser::Token> Tokens;
|
||||
Array<parser::Error> Errors;
|
||||
FileContents FileContent;
|
||||
Array<Token> Tokens;
|
||||
Array<Error> Errors;
|
||||
// Errors are allocated to a dedicated general arena.
|
||||
};
|
||||
|
||||
@ -262,8 +276,72 @@ StrC token_fmt_impl( ssize, ... );
|
||||
|
||||
Code untyped_str ( StrC content);
|
||||
Code untyped_fmt ( char const* fmt, ... );
|
||||
Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
|
||||
|
||||
#pragma endregion Untyped text
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#ifndef gen_main
|
||||
#define gen_main main
|
||||
#endif
|
||||
|
||||
#ifndef name
|
||||
// Convienence for defining any name used with the gen api.
|
||||
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
||||
#define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
||||
#endif
|
||||
|
||||
#ifndef code
|
||||
// Same as name just used to indicate intention of literal for code instead of names.
|
||||
#define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
||||
#endif
|
||||
|
||||
#ifndef args
|
||||
// Provides the number of arguments while passing args inplace.
|
||||
#define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
||||
#endif
|
||||
|
||||
#ifndef code_str
|
||||
// Just wrappers over common untyped code definition constructions.
|
||||
#define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
||||
#endif
|
||||
|
||||
#ifndef code_fmt
|
||||
#define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
||||
#endif
|
||||
|
||||
#ifndef parse_fmt
|
||||
#define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) )
|
||||
#endif
|
||||
|
||||
#ifndef token_fmt
|
||||
/*
|
||||
Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brackets (you can change it in token_fmt_va)
|
||||
---------------------------------------------------------
|
||||
Example - A string with:
|
||||
typedef <type> <name> <name>;
|
||||
Will have a token_fmt arguments populated with:
|
||||
"type", strc_for_type,
|
||||
"name", strc_for_name,
|
||||
and:
|
||||
stringize( typedef <type> <name> <name>; )
|
||||
-----------------------------------------------------------
|
||||
So the full call for this example would be:
|
||||
token_fmt(
|
||||
"type", strc_for_type
|
||||
, "name", strc_for_name
|
||||
, stringize(
|
||||
typedef <type> <name> <name>
|
||||
));
|
||||
!----------------------------------------------------------
|
||||
! Note: token_fmt_va is whitespace sensitive for the tokens.
|
||||
! This can be alleviated by skipping whitespace between brackets but it was choosen to not have that implementation by default.
|
||||
*/
|
||||
#define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
#pragma endregion Gen Interface
|
@ -12,15 +12,15 @@ CodeClass parse_class( StrC def )
|
||||
{
|
||||
GEN_USING_NS_PARSER;
|
||||
check_parse_args( def );
|
||||
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
push_scope();
|
||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class );
|
||||
pop(& Context);
|
||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class, parser_not_inplace_def );
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -35,13 +35,13 @@ CodeConstructor parse_constructor( StrC def )
|
||||
|
||||
// TODO(Ed): Constructors can have prefix attributes
|
||||
|
||||
CodeSpecifiers specifiers;
|
||||
Specifier specs_found[ 16 ] { Spec_NumSpecifiers };
|
||||
CodeSpecifiers specifiers = NullCode;
|
||||
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
||||
s32 NumSpecifiers = 0;
|
||||
|
||||
while ( left && is_specifier(currtok) )
|
||||
while ( left && tok_is_specifier(currtok) )
|
||||
{
|
||||
Specifier spec = to_specifier( to_str(currtok) );
|
||||
Specifier spec = strc_to_specifier( tok_to_str(currtok) );
|
||||
|
||||
b32 ignore_spec = false;
|
||||
|
||||
@ -59,8 +59,8 @@ CodeConstructor parse_constructor( StrC def )
|
||||
break;
|
||||
|
||||
default :
|
||||
log_failure( "Invalid specifier %s for variable\n%s", to_str( spec ), to_string(Context) );
|
||||
pop(& Context);
|
||||
log_failure( "Invalid specifier %s for variable\n%s", spec_to_str( spec ), parser_to_string(Context) );
|
||||
parser_pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ CodeConstructor parse_constructor( StrC def )
|
||||
}
|
||||
|
||||
Context.Tokens = toks;
|
||||
CodeConstructor result = parse_constructor( specifiers );
|
||||
CodeConstructor result = parser_parse_constructor( specifiers );
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ CodeDestructor parse_destructor( StrC def )
|
||||
// TODO(Ed): Destructors can have virtual
|
||||
|
||||
Context.Tokens = toks;
|
||||
CodeDestructor result = parse_destructor();
|
||||
CodeDestructor result = parser_parse_destructor(NullCode);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -109,12 +109,12 @@ CodeEnum parse_enum( StrC def )
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
{
|
||||
pop(& Context);
|
||||
parser_pop(& Context);
|
||||
return InvalidCode;
|
||||
}
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_enum();
|
||||
return parser_parse_enum( parser_not_inplace_def);
|
||||
}
|
||||
|
||||
CodeBody parse_export_body( StrC def )
|
||||
@ -127,7 +127,7 @@ CodeBody parse_export_body( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_export_body();
|
||||
return parser_parse_export_body();
|
||||
}
|
||||
|
||||
CodeExtern parse_extern_link( StrC def )
|
||||
@ -140,7 +140,7 @@ CodeExtern parse_extern_link( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_extern_link();
|
||||
return parser_parse_extern_link();
|
||||
}
|
||||
|
||||
CodeFriend parse_friend( StrC def )
|
||||
@ -153,7 +153,7 @@ CodeFriend parse_friend( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_friend();
|
||||
return parser_parse_friend();
|
||||
}
|
||||
|
||||
CodeFn parse_function( StrC def )
|
||||
@ -166,7 +166,7 @@ CodeFn parse_function( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return (CodeFn) parse_function();
|
||||
return (CodeFn) parser_parse_function();
|
||||
}
|
||||
|
||||
CodeBody parse_global_body( StrC def )
|
||||
@ -181,7 +181,7 @@ CodeBody parse_global_body( StrC def )
|
||||
Context.Tokens = toks;
|
||||
push_scope();
|
||||
CodeBody result = parse_global_nspace( CT_Global_Body );
|
||||
pop(& Context);
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ CodeNS parse_namespace( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_namespace();
|
||||
return parser_parse_namespace();
|
||||
}
|
||||
|
||||
CodeOperator parse_operator( StrC def )
|
||||
@ -208,7 +208,7 @@ CodeOperator parse_operator( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return (CodeOperator) parse_operator();
|
||||
return (CodeOperator) parser_parse_operator();
|
||||
}
|
||||
|
||||
CodeOpCast parse_operator_cast( StrC def )
|
||||
@ -221,7 +221,7 @@ CodeOpCast parse_operator_cast( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_operator_cast();
|
||||
return parser_parse_operator_cast(NullCode);
|
||||
}
|
||||
|
||||
CodeStruct parse_struct( StrC def )
|
||||
@ -235,8 +235,8 @@ CodeStruct parse_struct( StrC def )
|
||||
|
||||
Context.Tokens = toks;
|
||||
push_scope();
|
||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct );
|
||||
pop(& Context);
|
||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct, parser_not_inplace_def );
|
||||
parser_pop(& Context);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -250,7 +250,7 @@ CodeTemplate parse_template( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_template();
|
||||
return parser_parse_template();
|
||||
}
|
||||
|
||||
CodeTypename parse_type( StrC def )
|
||||
@ -263,7 +263,7 @@ CodeTypename parse_type( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_type();
|
||||
return parser_parse_type( parser_not_from_template, nullptr);
|
||||
}
|
||||
|
||||
CodeTypedef parse_typedef( StrC def )
|
||||
@ -276,7 +276,7 @@ CodeTypedef parse_typedef( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_typedef();
|
||||
return parser_parse_typedef();
|
||||
}
|
||||
|
||||
CodeUnion parse_union( StrC def )
|
||||
@ -289,7 +289,7 @@ CodeUnion parse_union( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_union();
|
||||
return parser_parse_union( parser_not_inplace_def);
|
||||
}
|
||||
|
||||
CodeUsing parse_using( StrC def )
|
||||
@ -302,7 +302,7 @@ CodeUsing parse_using( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_using();
|
||||
return parser_parse_using();
|
||||
}
|
||||
|
||||
CodeVar parse_variable( StrC def )
|
||||
@ -315,15 +315,31 @@ CodeVar parse_variable( StrC def )
|
||||
return InvalidCode;
|
||||
|
||||
Context.Tokens = toks;
|
||||
return parse_variable();
|
||||
return parser_parse_variable();
|
||||
}
|
||||
|
||||
// Undef helper macros
|
||||
# undef check_parse_args
|
||||
# undef currtok
|
||||
# undef prevtok
|
||||
# undef nexttok
|
||||
# undef eat
|
||||
# undef left
|
||||
# undef check
|
||||
# undef push_scope
|
||||
#undef check_parse_args
|
||||
#undef currtok_noskip
|
||||
#undef currtok
|
||||
#undef peektok
|
||||
#undef prevtok
|
||||
#undef nexttok
|
||||
#undef nexttok_noskip
|
||||
#undef eat
|
||||
#undef left
|
||||
#undef check
|
||||
#undef push_scope
|
||||
#undef def_assign
|
||||
|
||||
// Here for C Variant
|
||||
#undef lex_dont_skip_formatting
|
||||
#undef lex_skip_formatting
|
||||
|
||||
#undef parser_inplace_def
|
||||
#undef parser_not_inplace_def
|
||||
#undef parser_dont_consume_braces
|
||||
#undef parser_consume_braces
|
||||
#undef parser_not_from_template
|
||||
#undef parser_use_parenthesis
|
||||
#undef parser_strip_formatting_dont_preserve_newlines
|
@ -9,11 +9,11 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
|
||||
ssize remaining = buf_size;
|
||||
|
||||
local_persist
|
||||
FixedArena<TokenFmt_TokenMap_MemSize> tok_map_arena;
|
||||
TokenMap_FixedArena tok_map_arena;
|
||||
fixed_arena_init( & tok_map_arena);
|
||||
|
||||
local_persist
|
||||
HashTable(StrC) tok_map;
|
||||
StringTable tok_map;
|
||||
{
|
||||
tok_map = hashtable_init(StrC, fixed_arena_allocator_info(& tok_map_arena) );
|
||||
|
||||
@ -113,7 +113,7 @@ Code untyped_str( StrC content )
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
if ( result->Name.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_str: could not cache string" );
|
||||
return InvalidCode;
|
||||
@ -138,13 +138,16 @@ Code untyped_fmt( char const* fmt, ...)
|
||||
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
StrC buf_str = { str_len_capped(fmt, MaxNameLength), fmt };
|
||||
StrC uncapped_str = { length, buf };
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Name = get_cached_string( { str_len_capped(fmt, MaxNameLength), fmt } );
|
||||
result->Name = get_cached_string( buf_str );
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = get_cached_string( { length, buf } );
|
||||
result->Content = get_cached_string( uncapped_str );
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
if ( result->Name.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return InvalidCode;
|
||||
@ -153,7 +156,7 @@ Code untyped_fmt( char const* fmt, ...)
|
||||
return result;
|
||||
}
|
||||
|
||||
Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||
{
|
||||
if ( num_tokens == 0 )
|
||||
{
|
||||
@ -165,17 +168,19 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start(va, num_tokens);
|
||||
va_start(va, fmt);
|
||||
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
|
||||
va_end(va);
|
||||
|
||||
StrC buf_str = { length, buf };
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Name = get_cached_string( { length, buf } );
|
||||
result->Name = get_cached_string( buf_str );
|
||||
result->Type = CT_Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
if ( result->Name.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return InvalidCode;
|
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,7 @@ enum TokFlags : u32
|
||||
TF_Literal = bit( 12 ),
|
||||
|
||||
TF_Null = 0,
|
||||
TF_UnderlyingType = GEN_U32_MAX,
|
||||
};
|
||||
|
||||
struct Token
|
||||
@ -35,66 +36,67 @@ struct Token
|
||||
|
||||
constexpr Token NullToken { nullptr, 0, Tok_Invalid, false, 0, TF_Null };
|
||||
|
||||
AccessSpec to_access_specifier(Token tok)
|
||||
AccessSpec tok_to_access_specifier(Token tok)
|
||||
{
|
||||
return scast(AccessSpec, tok.Type);
|
||||
}
|
||||
|
||||
StrC to_str(Token tok)
|
||||
StrC tok_to_str(Token tok)
|
||||
{
|
||||
return { tok.Length, tok.Text };
|
||||
StrC str = { tok.Length, tok.Text };
|
||||
return str;
|
||||
}
|
||||
|
||||
bool is_valid( Token tok )
|
||||
bool tok_is_valid( Token tok )
|
||||
{
|
||||
return tok.Text && tok.Length && tok.Type != Tok_Invalid;
|
||||
}
|
||||
|
||||
bool is_access_operator(Token tok)
|
||||
bool tok_is_access_operator(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_AccessOperator );
|
||||
}
|
||||
|
||||
bool is_access_specifier(Token tok)
|
||||
bool tok_is_access_specifier(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_AccessSpecifier );
|
||||
}
|
||||
|
||||
bool is_attribute(Token tok)
|
||||
bool tok_is_attribute(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_Attribute );
|
||||
}
|
||||
|
||||
bool is_operator(Token tok)
|
||||
bool tok_is_operator(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_Operator );
|
||||
}
|
||||
|
||||
bool is_preprocessor(Token tok)
|
||||
bool tok_is_preprocessor(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_Preprocess );
|
||||
}
|
||||
|
||||
bool is_preprocess_cond(Token tok)
|
||||
bool tok_is_preprocess_cond(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_Preprocess_Cond );
|
||||
}
|
||||
|
||||
bool is_specifier(Token tok)
|
||||
bool tok_is_specifier(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_Specifier );
|
||||
}
|
||||
|
||||
bool is_end_definition(Token tok)
|
||||
bool tok_is_end_definition(Token tok)
|
||||
{
|
||||
return bitfield_is_equal( u32, tok.Flags, TF_EndDefinition );
|
||||
}
|
||||
|
||||
String to_string(Token tok)
|
||||
String tok_to_string(Token tok)
|
||||
{
|
||||
String result = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
|
||||
StrC type_str = to_str( tok.Type );
|
||||
StrC type_str = toktype_to_str( tok.Type );
|
||||
|
||||
string_append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
|
||||
, tok.Line, tok.Column
|
||||
@ -111,9 +113,9 @@ struct TokArray
|
||||
s32 Idx;
|
||||
};
|
||||
|
||||
bool __eat( TokType type );
|
||||
bool lex__eat( TokArray* self, TokType type );
|
||||
|
||||
Token* current(TokArray* self, bool skip_formatting )
|
||||
Token* lex_current(TokArray* self, bool skip_formatting )
|
||||
{
|
||||
if ( skip_formatting )
|
||||
{
|
||||
@ -124,7 +126,7 @@ Token* current(TokArray* self, bool skip_formatting )
|
||||
return & self->Arr[self->Idx];
|
||||
}
|
||||
|
||||
Token* peek(TokArray self, bool skip_formatting)
|
||||
Token* lex_peek(TokArray self, bool skip_formatting)
|
||||
{
|
||||
s32 idx = self.Idx;
|
||||
|
||||
@ -139,7 +141,7 @@ Token* peek(TokArray self, bool skip_formatting)
|
||||
return & self.Arr[idx];
|
||||
}
|
||||
|
||||
Token* previous(TokArray self, bool skip_formatting)
|
||||
Token* lex_previous(TokArray self, bool skip_formatting)
|
||||
{
|
||||
s32 idx = self.Idx;
|
||||
|
||||
@ -154,7 +156,7 @@ Token* previous(TokArray self, bool skip_formatting)
|
||||
return & self.Arr[idx - 1];
|
||||
}
|
||||
|
||||
Token* next(TokArray self, bool skip_formatting)
|
||||
Token* lex_next(TokArray self, bool skip_formatting)
|
||||
{
|
||||
s32 idx = self.Idx;
|
||||
|
||||
@ -169,9 +171,9 @@ Token* next(TokArray self, bool skip_formatting)
|
||||
return & self.Arr[idx + 1];
|
||||
}
|
||||
|
||||
global Arena_256KB defines_map_arena;
|
||||
global HashTable(StrC) defines;
|
||||
global Array(Token) Tokens;
|
||||
global FixedArena_256KB Lexer_defines_map_arena;
|
||||
global StringTable Lexer_defines;
|
||||
global Array(Token) Lexer_Tokens;
|
||||
|
||||
#define current ( * ctx->scanner )
|
||||
|
||||
@ -190,7 +192,7 @@ global Array(Token) Tokens;
|
||||
ctx->scanner++; \
|
||||
}
|
||||
|
||||
#define SkipWhitespace() \
|
||||
#define skip_whitespace() \
|
||||
while ( ctx->left && char_is_space( current ) ) \
|
||||
{ \
|
||||
move_forward(); \
|
||||
@ -228,7 +230,7 @@ struct LexContext
|
||||
char const* scanner;
|
||||
s32 line;
|
||||
s32 column;
|
||||
HashTable(StrC) defines;
|
||||
StringTable defines;
|
||||
Token token;
|
||||
};
|
||||
|
||||
@ -237,10 +239,10 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
{
|
||||
char const* hash = ctx->scanner;
|
||||
Token hash_tok = { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append( Tokens, hash_tok );
|
||||
array_append( Lexer_Tokens, hash_tok );
|
||||
|
||||
move_forward();
|
||||
SkipWhitespace();
|
||||
skip_whitespace();
|
||||
|
||||
ctx->token.Text = ctx->scanner;
|
||||
while (ctx->left && ! char_is_space(current) )
|
||||
@ -249,7 +251,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
ctx->token.Length++;
|
||||
}
|
||||
|
||||
ctx->token.Type = to_toktype( to_str(ctx->token) );
|
||||
ctx->token.Type = strc_to_toktype( tok_to_str(ctx->token) );
|
||||
|
||||
bool is_preprocessor = ctx->token.Type >= Tok_Preprocess_Define && ctx->token.Type <= Tok_Preprocess_Pragma;
|
||||
if ( ! is_preprocessor )
|
||||
@ -313,14 +315,14 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
|
||||
ctx->token.Length = ctx->token.Length + ctx->token.Text - hash;
|
||||
ctx->token.Text = hash;
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
return Lex_Continue; // Skip found token, its all handled here.
|
||||
}
|
||||
|
||||
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf )
|
||||
{
|
||||
ctx->token.Flags |= TF_Preprocess_Cond;
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
end_line();
|
||||
return Lex_Continue;
|
||||
}
|
||||
@ -329,9 +331,9 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
ctx->token.Flags |= TF_Preprocess_Cond;
|
||||
}
|
||||
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
|
||||
SkipWhitespace();
|
||||
skip_whitespace();
|
||||
|
||||
if ( ctx->token.Type == Tok_Preprocess_Define )
|
||||
{
|
||||
@ -353,10 +355,10 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
name.Length++;
|
||||
}
|
||||
|
||||
array_append( Tokens, name );
|
||||
array_append( Lexer_Tokens, name );
|
||||
|
||||
u64 key = crc32( name.Text, name.Length );
|
||||
hashtable_set(ctx->defines, key, to_str(name) );
|
||||
hashtable_set(ctx->defines, key, tok_to_str(name) );
|
||||
}
|
||||
|
||||
Token preprocess_content = { ctx->scanner, 0, Tok_Preprocess_Content, ctx->line, ctx->column, TF_Preprocess };
|
||||
@ -399,7 +401,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
move_forward();
|
||||
}
|
||||
|
||||
array_append( Tokens, preprocess_content );
|
||||
array_append( Lexer_Tokens, preprocess_content );
|
||||
return Lex_Continue; // Skip found token, its all handled here.
|
||||
}
|
||||
|
||||
@ -462,7 +464,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
preprocess_content.Length++;
|
||||
}
|
||||
|
||||
array_append( Tokens, preprocess_content );
|
||||
array_append( Lexer_Tokens, preprocess_content );
|
||||
return Lex_Continue; // Skip found token, its all handled here.
|
||||
}
|
||||
|
||||
@ -471,11 +473,11 @@ void lex_found_token( LexContext* ctx )
|
||||
{
|
||||
if ( ctx->token.Type != Tok_Invalid )
|
||||
{
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
return;
|
||||
}
|
||||
|
||||
TokType type = to_toktype( to_str(ctx->token) );
|
||||
TokType type = strc_to_toktype( tok_to_str(ctx->token) );
|
||||
|
||||
if (type <= Tok_Access_Public && type >= Tok_Access_Private )
|
||||
{
|
||||
@ -489,7 +491,7 @@ void lex_found_token( LexContext* ctx )
|
||||
|
||||
if ( type == Tok_Decl_Extern_Linkage )
|
||||
{
|
||||
SkipWhitespace();
|
||||
skip_whitespace();
|
||||
|
||||
if ( current != '"' )
|
||||
{
|
||||
@ -498,7 +500,7 @@ void lex_found_token( LexContext* ctx )
|
||||
}
|
||||
|
||||
ctx->token.Type = type;
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -508,7 +510,7 @@ void lex_found_token( LexContext* ctx )
|
||||
{
|
||||
ctx->token.Type = type;
|
||||
ctx->token.Flags |= TF_Specifier;
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -516,7 +518,7 @@ void lex_found_token( LexContext* ctx )
|
||||
if ( type != Tok_Invalid )
|
||||
{
|
||||
ctx->token.Type = type;
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -570,7 +572,7 @@ void lex_found_token( LexContext* ctx )
|
||||
ctx->token.Type = Tok_Identifier;
|
||||
}
|
||||
|
||||
array_append( Tokens, ctx->token );
|
||||
array_append( Lexer_Tokens, ctx->token );
|
||||
}
|
||||
|
||||
neverinline
|
||||
@ -581,7 +583,7 @@ TokArray lex( StrC content )
|
||||
c.content = content;
|
||||
c.left = content.Len;
|
||||
c.scanner = content.Ptr;
|
||||
c.defines = defines;
|
||||
c.defines = Lexer_defines;
|
||||
|
||||
char const* word = c.scanner;
|
||||
s32 word_length = 0;
|
||||
@ -589,17 +591,18 @@ TokArray lex( StrC content )
|
||||
c.line = 1;
|
||||
c.column = 1;
|
||||
|
||||
SkipWhitespace();
|
||||
skip_whitespace();
|
||||
if ( c.left <= 0 )
|
||||
{
|
||||
log_failure( "gen::lex: no tokens found (only whitespace provided)" );
|
||||
return { {}, 0 };
|
||||
TokArray null_array = {};
|
||||
return null_array;
|
||||
}
|
||||
|
||||
for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); entry = array_next(PreprocessorDefines, entry))
|
||||
{
|
||||
s32 length = 0;
|
||||
char const* entry_scanner = * entry;
|
||||
char const* entry_scanner = (*entry).Ptr;
|
||||
while ( entry->Len > length && (char_is_alphanumeric( *entry_scanner ) || *entry_scanner == '_') )
|
||||
{
|
||||
entry_scanner++;
|
||||
@ -610,11 +613,11 @@ TokArray lex( StrC content )
|
||||
length++;
|
||||
}
|
||||
|
||||
u64 key = crc32( * entry, length );
|
||||
hashtable_set(c.defines, key, (StrC) * entry );
|
||||
u64 key = crc32( entry->Ptr, length );
|
||||
hashtable_set(c.defines, key, * entry );
|
||||
}
|
||||
|
||||
array_clear(Tokens);
|
||||
array_clear(Lexer_Tokens);
|
||||
|
||||
while (c.left )
|
||||
{
|
||||
@ -625,7 +628,10 @@ TokArray lex( StrC content )
|
||||
}
|
||||
#endif
|
||||
|
||||
c.token = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
{
|
||||
Token thanks_c = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
c.token = thanks_c;
|
||||
}
|
||||
|
||||
bool is_define = false;
|
||||
|
||||
@ -644,19 +650,23 @@ TokArray lex( StrC content )
|
||||
c.token.Type = Tok_NewLine;
|
||||
c.token.Length++;
|
||||
|
||||
array_append( Tokens, c.token );
|
||||
array_append( Lexer_Tokens, c.token );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
c.token.Length = 0;
|
||||
|
||||
SkipWhitespace();
|
||||
skip_whitespace();
|
||||
if ( c.left <= 0 )
|
||||
break;
|
||||
|
||||
switch ( current )
|
||||
{
|
||||
if (array_back(Lexer_Tokens)->Length > 100 ) {
|
||||
__debugbreak();
|
||||
}
|
||||
|
||||
case '#':
|
||||
{
|
||||
s32 result = lex_preprocessor_directive( ctx );
|
||||
@ -667,7 +677,10 @@ TokArray lex( StrC content )
|
||||
//TokType last_type = Tokens[array_get_header(Tokens)->Num - 2].Type;
|
||||
//if ( last_type == Tok_Preprocess_Pragma )
|
||||
{
|
||||
c.token = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
{
|
||||
Token thanks_c = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
c.token = thanks_c;
|
||||
}
|
||||
if ( current == '\r')
|
||||
{
|
||||
move_forward();
|
||||
@ -680,7 +693,7 @@ TokArray lex( StrC content )
|
||||
c.token.Length++;
|
||||
move_forward();
|
||||
|
||||
array_append( Tokens, c.token );
|
||||
array_append( Lexer_Tokens, c.token );
|
||||
}
|
||||
}
|
||||
|
||||
@ -688,7 +701,10 @@ TokArray lex( StrC content )
|
||||
}
|
||||
|
||||
case Lex_ReturnNull:
|
||||
return { {}, 0 };
|
||||
{
|
||||
TokArray tok_array = {};
|
||||
return tok_array;
|
||||
}
|
||||
}
|
||||
}
|
||||
case '.':
|
||||
@ -1135,7 +1151,7 @@ TokArray lex( StrC content )
|
||||
move_forward();
|
||||
c.token.Length++;
|
||||
}
|
||||
array_append( Tokens, c.token );
|
||||
array_append( Lexer_Tokens, c.token );
|
||||
continue;
|
||||
}
|
||||
else if ( current == '*' )
|
||||
@ -1171,7 +1187,7 @@ TokArray lex( StrC content )
|
||||
move_forward();
|
||||
c.token.Length++;
|
||||
}
|
||||
array_append( Tokens, c.token );
|
||||
array_append( Lexer_Tokens, c.token );
|
||||
// end_line();
|
||||
continue;
|
||||
}
|
||||
@ -1264,14 +1280,14 @@ TokArray lex( StrC content )
|
||||
}
|
||||
else
|
||||
{
|
||||
s32 start = max( 0, array_num(Tokens) - 100 );
|
||||
s32 start = max( 0, array_num(Lexer_Tokens) - 100 );
|
||||
log_fmt("\n%d\n", start);
|
||||
for ( s32 idx = start; idx < array_num(Tokens); idx++ )
|
||||
for ( s32 idx = start; idx < array_num(Lexer_Tokens); idx++ )
|
||||
{
|
||||
log_fmt( "Token %d Type: %s : %.*s\n"
|
||||
, idx
|
||||
, to_str( Tokens[ idx ].Type ).Ptr
|
||||
, Tokens[ idx ].Length, Tokens[ idx ].Text
|
||||
, toktype_to_str( Lexer_Tokens[ idx ].Type ).Ptr
|
||||
, Lexer_Tokens[ idx ].Length, Lexer_Tokens[ idx ].Text
|
||||
);
|
||||
}
|
||||
|
||||
@ -1288,10 +1304,11 @@ TokArray lex( StrC content )
|
||||
FoundToken:
|
||||
{
|
||||
lex_found_token( ctx );
|
||||
TokType last_type = array_back(Tokens)->Type;
|
||||
TokType last_type = array_back(Lexer_Tokens)->Type;
|
||||
if ( last_type == Tok_Preprocess_Macro )
|
||||
{
|
||||
c.token = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
Token thanks_c = { c.scanner, 0, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
c.token = thanks_c;
|
||||
if ( current == '\r')
|
||||
{
|
||||
move_forward();
|
||||
@ -1304,22 +1321,26 @@ TokArray lex( StrC content )
|
||||
c.token.Length++;
|
||||
move_forward();
|
||||
|
||||
array_append( Tokens, c.token );
|
||||
array_append( Lexer_Tokens, c.token );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( array_num(Tokens) == 0 )
|
||||
if ( array_num(Lexer_Tokens) == 0 )
|
||||
{
|
||||
log_failure( "Failed to lex any tokens" );
|
||||
return { {}, 0 };
|
||||
{
|
||||
TokArray tok_array = {};
|
||||
return tok_array;
|
||||
}
|
||||
}
|
||||
|
||||
hashtable_clear(defines);
|
||||
hashtable_clear(Lexer_defines);
|
||||
// defines_map_arena.free();
|
||||
return { Tokens, 0 };
|
||||
TokArray result = { Lexer_Tokens, 0 };
|
||||
return result;
|
||||
}
|
||||
#undef current
|
||||
#undef move_forward
|
File diff suppressed because it is too large
Load Diff
@ -1,33 +1,35 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "gen.hpp"
|
||||
#include "../gen.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region StaticData
|
||||
|
||||
// TODO : Convert global allocation strategy to use a slab allocation strategy.
|
||||
global AllocatorInfo GlobalAllocator;
|
||||
global Array<Arena> Global_AllocatorBuckets;
|
||||
global Array( Arena ) Global_AllocatorBuckets;
|
||||
|
||||
// TODO(Ed) : Make the code pool a dynamic arena
|
||||
global Array< Pool > CodePools = { nullptr };
|
||||
global Array< Arena > StringArenas = { nullptr };
|
||||
global Array( Pool ) CodePools = { nullptr };
|
||||
global Array( Arena ) StringArenas = { nullptr };
|
||||
|
||||
global StringTable StringCache;
|
||||
|
||||
global Arena LexArena;
|
||||
|
||||
global AllocatorInfo Allocator_DataArrays = heap();
|
||||
global AllocatorInfo Allocator_CodePool = heap();
|
||||
global AllocatorInfo Allocator_Lexer = heap();
|
||||
global AllocatorInfo Allocator_StringArena = heap();
|
||||
global AllocatorInfo Allocator_StringTable = heap();
|
||||
global AllocatorInfo Allocator_TypeTable = heap();
|
||||
global AllocatorInfo Allocator_DataArrays = {0};
|
||||
global AllocatorInfo Allocator_CodePool = {0};
|
||||
global AllocatorInfo Allocator_Lexer = {0};
|
||||
global AllocatorInfo Allocator_StringArena = {0};
|
||||
global AllocatorInfo Allocator_StringTable = {0};
|
||||
global AllocatorInfo Allocator_TypeTable = {0};
|
||||
|
||||
#pragma endregion StaticData
|
||||
|
||||
#pragma region Constants
|
||||
|
||||
global StrC enum_underlying_sig;
|
||||
|
||||
global Code access_public;
|
||||
global Code access_protected;
|
||||
global Code access_private;
|
||||
@ -40,7 +42,7 @@ global Code module_private_fragment;
|
||||
|
||||
global Code fmt_newline;
|
||||
|
||||
global CodeParam param_varadic;
|
||||
global CodeParams param_varadic;
|
||||
|
||||
global CodePragma pragma_once;
|
||||
|
138
base/components/types.hpp
Normal file
138
base/components/types.hpp
Normal file
@ -0,0 +1,138 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
/*
|
||||
________ __ __ ________
|
||||
| \ | \ | \ | \
|
||||
| ▓▓▓▓▓▓▓▓_______ __ __ ______ ____ _______ | ▓▓\ | ▓▓ \▓▓▓▓▓▓▓▓__ __ ______ ______ _______
|
||||
| ▓▓__ | \| \ | \ \ \ / \ | ▓▓▓\| ▓▓ | ▓▓ | \ | \/ \ / \ / \
|
||||
| ▓▓ \ | ▓▓▓▓▓▓▓\ ▓▓ | ▓▓ ▓▓▓▓▓▓\▓▓▓▓\ ▓▓▓▓▓▓▓ | ▓▓▓▓\ ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓
|
||||
| ▓▓▓▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓\▓▓ \ | ▓▓\▓▓ ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ ▓▓\▓▓ \
|
||||
| ▓▓_____| ▓▓ | ▓▓ ▓▓__/ ▓▓ ▓▓ | ▓▓ | ▓▓_\▓▓▓▓▓▓\ | ▓▓ \▓▓▓▓ | ▓▓ | ▓▓__/ ▓▓ ▓▓__/ ▓▓ ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\
|
||||
| ▓▓ \ ▓▓ | ▓▓\▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ \▓▓▓ | ▓▓ \▓▓ ▓▓ ▓▓ ▓▓\▓▓ \ ▓▓
|
||||
\▓▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓ \▓▓\▓▓▓▓▓▓▓ \▓▓ \▓▓ \▓▓ _\▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓▓▓▓▓▓
|
||||
| \__| ▓▓ ▓▓
|
||||
\▓▓ ▓▓ ▓▓
|
||||
\▓▓▓▓▓▓ \▓▓
|
||||
|
||||
*/
|
||||
|
||||
using LogFailType = ssize(*)(char const*, ...);
|
||||
|
||||
// By default this library will either crash or exit if an error is detected while generating codes.
|
||||
// Even if set to not use GEN_FATAL, GEN_FATAL will still be used for memory failures as the library is unusable when they occur.
|
||||
#ifdef GEN_DONT_USE_FATAL
|
||||
#define log_failure log_fmt
|
||||
#else
|
||||
#define log_failure GEN_FATAL
|
||||
#endif
|
||||
|
||||
enum AccessSpec : u32
|
||||
{
|
||||
AccessSpec_Default,
|
||||
AccessSpec_Private,
|
||||
AccessSpec_Protected,
|
||||
AccessSpec_Public,
|
||||
|
||||
AccessSpec_Num_AccessSpec,
|
||||
AccessSpec_Invalid,
|
||||
|
||||
AccessSpec_SizeDef = GEN_U32_MAX,
|
||||
};
|
||||
static_assert( size_of(AccessSpec) == size_of(u32), "AccessSpec not u32 size" );
|
||||
|
||||
inline
|
||||
StrC access_spec_to_str( AccessSpec type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ (u32)AccessSpec_Num_AccessSpec ] = {
|
||||
{ sizeof("") - 1, "" },
|
||||
{ sizeof("prviate") - 1, "private" },
|
||||
{ sizeof("protected") - 1, "private" },
|
||||
{ sizeof("public") - 1, "public" },
|
||||
};
|
||||
|
||||
StrC invalid = { sizeof("Invalid") - 1, "Invalid" };
|
||||
if ( type > AccessSpec_Public )
|
||||
return invalid;
|
||||
|
||||
return lookup[ (u32)type ];
|
||||
}
|
||||
|
||||
enum CodeFlag : u32
|
||||
{
|
||||
CodeFlag_None = 0,
|
||||
CodeFlag_FunctionType = bit(0),
|
||||
CodeFlag_ParamPack = bit(1),
|
||||
CodeFlag_Module_Export = bit(2),
|
||||
CodeFlag_Module_Import = bit(3),
|
||||
|
||||
CodeFlag_SizeDef = GEN_U32_MAX,
|
||||
};
|
||||
static_assert( size_of(CodeFlag) == size_of(u32), "CodeFlag not u32 size" );
|
||||
|
||||
// Used to indicate if enum definitoin is an enum class or regular enum.
|
||||
enum EnumDecl : u8
|
||||
{
|
||||
EnumDecl_Regular,
|
||||
EnumDecl_Class,
|
||||
|
||||
EnumT_SizeDef = GEN_U8_MAX,
|
||||
};
|
||||
typedef u8 EnumT;
|
||||
|
||||
enum ModuleFlag : u32
|
||||
{
|
||||
ModuleFlag_None = 0,
|
||||
ModuleFlag_Export = bit(0),
|
||||
ModuleFlag_Import = bit(1),
|
||||
|
||||
Num_ModuleFlags,
|
||||
ModuleFlag_Invalid,
|
||||
|
||||
ModuleFlag_SizeDef = GEN_U32_MAX,
|
||||
};
|
||||
static_assert( size_of(ModuleFlag) == size_of(u32), "ModuleFlag not u32 size" );
|
||||
|
||||
inline
|
||||
StrC module_flag_to_str( ModuleFlag flag )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ (u32)Num_ModuleFlags ] = {
|
||||
{ sizeof("__none__"), "__none__" },
|
||||
{ sizeof("export"), "export" },
|
||||
{ sizeof("import"), "import" },
|
||||
};
|
||||
|
||||
local_persist
|
||||
StrC invalid_flag = { sizeof("invalid"), "invalid" };
|
||||
if ( flag > ModuleFlag_Import )
|
||||
return invalid_flag;
|
||||
|
||||
return lookup[ (u32)flag ];
|
||||
}
|
||||
|
||||
enum EPreprocessCond : u32
|
||||
{
|
||||
PreprocessCond_If,
|
||||
PreprocessCond_IfDef,
|
||||
PreprocessCond_IfNotDef,
|
||||
PreprocessCond_ElIf,
|
||||
|
||||
EPreprocessCond_SizeDef = GEN_U32_MAX,
|
||||
};
|
||||
static_assert( size_of(EPreprocessCond) == size_of(u32), "EPreprocessCond not u32 size" );
|
||||
|
||||
enum ETypenameTag : u16
|
||||
{
|
||||
Tag_None,
|
||||
Tag_Class,
|
||||
Tag_Enum,
|
||||
Tag_Struct,
|
||||
Tag_Union,
|
||||
|
||||
Tag_UnderlyingType = GEN_U16_MAX,
|
||||
};
|
||||
static_assert( size_of(ETypenameTag) == size_of(u16), "ETypenameTag is not u16 size");
|
@ -1,11 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "platform.hpp"
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Basic Types
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#define GEN_U8_MIN 0u
|
||||
#define GEN_U8_MAX 0xffu
|
||||
@ -127,14 +125,12 @@ typedef s32 b32;
|
||||
typedef void* mem_ptr;
|
||||
typedef void const* mem_ptr_const ;
|
||||
|
||||
#if ! GEN_COMPILER_C
|
||||
GEN_API_C_END
|
||||
#if GEN_COMPILER_CPP
|
||||
template<typename Type> uptr to_uptr( Type* ptr ) { return (uptr)ptr; }
|
||||
template<typename Type> sptr to_sptr( Type* ptr ) { return (sptr)ptr; }
|
||||
|
||||
template<typename Type> mem_ptr to_mem_ptr ( Type ptr ) { return (mem_ptr) ptr; }
|
||||
template<typename Type> mem_ptr_const to_mem_ptr_const( Type ptr ) { return (mem_ptr_const)ptr; }
|
||||
GEN_API_C_BEGIN
|
||||
#else
|
||||
#define to_uptr( ptr ) ((uptr)(ptr))
|
||||
#define to_sptr( ptr ) ((sptr)(ptr))
|
||||
@ -143,5 +139,4 @@ GEN_API_C_BEGIN
|
||||
#define to_mem_ptr_const( ptr) ((mem_ptr)ptr)
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Basic Types
|
@ -26,12 +26,9 @@ template <class TType> using TRemovePtr = typename RemovePtr<TType>::Type;
|
||||
|
||||
struct ArrayHeader;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
template<class Type> struct Array;
|
||||
# define get_array_underlying_type(array) typename TRemovePtr<typeof(array)>:: DataType
|
||||
#else
|
||||
template<class Type> using Array = Type*;
|
||||
# define get_array_underlying_type(array) TRemovePtr<typeof(array)>
|
||||
#endif
|
||||
|
||||
usize array_grow_formula(ssize value);
|
||||
@ -62,34 +59,34 @@ struct ArrayHeader {
|
||||
usize Num;
|
||||
};
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
template<class Type>
|
||||
struct Array
|
||||
{
|
||||
Type* Data;
|
||||
|
||||
#pragma region Member Mapping
|
||||
forceinline static Array init(AllocatorInfo allocator) { return GEN_NS array_init<Type>(allocator); }
|
||||
forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return GEN_NS array_init_reserve<Type>(allocator, capacity); }
|
||||
forceinline static usize grow_formula(ssize value) { return GEN_NS array_grow_formula<Type>(value); }
|
||||
forceinline static Array init(AllocatorInfo allocator) { return array_init<Type>(allocator); }
|
||||
forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return array_init_reserve<Type>(allocator, capacity); }
|
||||
forceinline static usize grow_formula(ssize value) { return array_grow_formula<Type>(value); }
|
||||
|
||||
forceinline bool append(Array other) { return GEN_NS array_append_array<Type>(this, other); }
|
||||
forceinline bool append(Type value) { return GEN_NS array_append<Type>(this, value); }
|
||||
forceinline bool append(Type* items, usize item_num) { return GEN_NS array_append_items<Type>(this, items, item_num); }
|
||||
forceinline bool append_at(Type item, usize idx) { return GEN_NS array_append_at<Type>(this, item, idx); }
|
||||
forceinline bool append_at(Type* items, usize item_num, usize idx) { return GEN_NS array_append_items_at<Type>(this, items, item_num, idx); }
|
||||
forceinline Type* back() { return GEN_NS array_back<Type>(* this); }
|
||||
forceinline void clear() { GEN_NS array_clear<Type>(* this); }
|
||||
forceinline bool fill(usize begin, usize end, Type value) { return GEN_NS array_fill<Type>(* this, begin, end, value); }
|
||||
forceinline void free() { GEN_NS array_free<Type>(this); }
|
||||
forceinline ArrayHeader* get_header() { return GEN_NS array_get_header<Type>(* this); }
|
||||
forceinline bool grow(usize min_capacity) { return GEN_NS array_grow<Type>(this, min_capacity); }
|
||||
forceinline usize num() { return GEN_NS array_num<Type>(*this); }
|
||||
forceinline void pop() { GEN_NS array_pop<Type>(* this); }
|
||||
forceinline void remove_at(usize idx) { GEN_NS array_remove_at<Type>(* this, idx); }
|
||||
forceinline bool reserve(usize new_capacity) { return GEN_NS array_reserve<Type>(this, new_capacity); }
|
||||
forceinline bool resize(usize num) { return GEN_NS array_resize<Type>(this, num); }
|
||||
forceinline bool set_capacity(usize new_capacity) { return GEN_NS array_set_capacity<Type>(this, new_capacity); }
|
||||
forceinline bool append(Array other) { return array_append_array<Type>(this, other); }
|
||||
forceinline bool append(Type value) { return array_append<Type>(this, value); }
|
||||
forceinline bool append(Type* items, usize item_num) { return array_append_items<Type>(this, items, item_num); }
|
||||
forceinline bool append_at(Type item, usize idx) { return array_append_at<Type>(this, item, idx); }
|
||||
forceinline bool append_at(Type* items, usize item_num, usize idx) { return array_append_items_at<Type>(this, items, item_num, idx); }
|
||||
forceinline Type* back() { return array_back<Type>(* this); }
|
||||
forceinline void clear() { array_clear<Type>(* this); }
|
||||
forceinline bool fill(usize begin, usize end, Type value) { return array_fill<Type>(* this, begin, end, value); }
|
||||
forceinline void free() { array_free<Type>(this); }
|
||||
forceinline ArrayHeader* get_header() { return array_get_header<Type>(* this); }
|
||||
forceinline bool grow(usize min_capacity) { return array_grow<Type>(this, min_capacity); }
|
||||
forceinline usize num() { return array_num<Type>(*this); }
|
||||
forceinline void pop() { array_pop<Type>(* this); }
|
||||
forceinline void remove_at(usize idx) { array_remove_at<Type>(* this, idx); }
|
||||
forceinline bool reserve(usize new_capacity) { return array_reserve<Type>(this, new_capacity); }
|
||||
forceinline bool resize(usize num) { return array_resize<Type>(this, num); }
|
||||
forceinline bool set_capacity(usize new_capacity) { return array_set_capacity<Type>(this, new_capacity); }
|
||||
#pragma endregion Member Mapping
|
||||
|
||||
forceinline operator Type*() { return Data; }
|
||||
@ -104,17 +101,17 @@ struct Array
|
||||
};
|
||||
#endif
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return GEN_NS append( & array, other ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type value) { return GEN_NS append( & array, value ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return GEN_NS append( & array, items, item_num ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type item, usize idx) { return GEN_NS append_at( & array, item, idx ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type* items, usize item_num, usize idx) { return GEN_NS append_at( & array, items, item_num, idx ); }
|
||||
template<class Type> void free(Array<Type>& array) { return GEN_NS free( & array ); }
|
||||
template<class Type> bool grow(Array<Type>& array, usize min_capacity) { return GEN_NS grow( & array, min_capacity); }
|
||||
template<class Type> bool reserve(Array<Type>& array, usize new_capacity) { return GEN_NS reserve( & array, new_capacity); }
|
||||
template<class Type> bool resize(Array<Type>& array, usize num) { return GEN_NS resize( & array, num); }
|
||||
template<class Type> bool set_capacity(Array<Type>& array, usize new_capacity) { return GEN_NS set_capacity( & array, new_capacity); }
|
||||
#if GEN_COMPILER_CPP && 0
|
||||
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return append( & array, other ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type value) { return append( & array, value ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return append( & array, items, item_num ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type item, usize idx) { return append_at( & array, item, idx ); }
|
||||
template<class Type> bool append_at(Array<Type>& array, Type* items, usize item_num, usize idx) { return append_at( & array, items, item_num, idx ); }
|
||||
template<class Type> void free(Array<Type>& array) { return free( & array ); }
|
||||
template<class Type> bool grow(Array<Type>& array, usize min_capacity) { return grow( & array, min_capacity); }
|
||||
template<class Type> bool reserve(Array<Type>& array, usize new_capacity) { return reserve( & array, new_capacity); }
|
||||
template<class Type> bool resize(Array<Type>& array, usize num) { return resize( & array, num); }
|
||||
template<class Type> bool set_capacity(Array<Type>& array, usize new_capacity) { return set_capacity( & array, new_capacity); }
|
||||
|
||||
template<class Type> forceinline Type* begin(Array<Type>& array) { return array; }
|
||||
template<class Type> forceinline Type* end(Array<Type>& array) { return array + array_get_header(array)->Num; }
|
||||
@ -137,7 +134,7 @@ Array<Type> array_init_reserve(AllocatorInfo allocator, ssize capacity)
|
||||
ArrayHeader* header = rcast(ArrayHeader*, alloc(allocator, sizeof(ArrayHeader) + sizeof(Type) * capacity));
|
||||
|
||||
if (header == nullptr)
|
||||
return {nullptr};
|
||||
return {nullptr};
|
||||
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = capacity;
|
||||
@ -206,10 +203,10 @@ bool array_append_at(Array<Type>* array, Type item, usize idx)
|
||||
|
||||
ssize slot = idx;
|
||||
if (slot >= header->Num)
|
||||
slot = header->Num - 1;
|
||||
slot = header->Num - 1;
|
||||
|
||||
if (slot < 0)
|
||||
slot = 0;
|
||||
slot = 0;
|
||||
|
||||
if (header->Capacity < header->Num + 1)
|
||||
{
|
||||
@ -237,7 +234,7 @@ bool array_append_items_at(Array<Type>* array, Type* items, usize item_num, usiz
|
||||
if (idx >= header->Num)
|
||||
{
|
||||
return array_append_items(array, items, item_num);
|
||||
}
|
||||
}
|
||||
|
||||
if (item_num > header->Capacity)
|
||||
{
|
||||
@ -361,7 +358,7 @@ bool array_reserve(Array<Type>* array, usize new_capacity)
|
||||
ArrayHeader* header = array_get_header(array);
|
||||
|
||||
if (header->Capacity < new_capacity)
|
||||
return set_capacity(array, new_capacity);
|
||||
return set_capacity(array, new_capacity);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -380,7 +377,7 @@ bool array_resize(Array<Type>* array, usize num)
|
||||
}
|
||||
|
||||
header->Num = num;
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Type> inline
|
||||
@ -443,8 +440,6 @@ bool array_set_capacity(Array<Type>* array, usize new_capacity)
|
||||
|
||||
#pragma endregion Array
|
||||
|
||||
// TODO(Ed) : This thing needs ALOT of work.
|
||||
|
||||
#pragma region HashTable
|
||||
#define HashTable(Type) HashTable<Type>
|
||||
|
||||
@ -496,23 +491,23 @@ struct HashTable
|
||||
Array<ssize> Hashes;
|
||||
Array<HashTableEntry<Type>> Entries;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline static HashTable init(AllocatorInfo allocator) { return GEN_NS hashtable_init<Type>(allocator); }
|
||||
forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return GEN_NS hashtable_init_reserve<Type>(allocator, num); }
|
||||
forceinline static HashTable init(AllocatorInfo allocator) { return hashtable_init<Type>(allocator); }
|
||||
forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return hashtable_init_reserve<Type>(allocator, num); }
|
||||
|
||||
forceinline void clear() { GEN_NS clear<Type>(*this); }
|
||||
forceinline void destroy() { GEN_NS destroy<Type>(*this); }
|
||||
forceinline Type* get(u64 key) { return GEN_NS get<Type>(*this, key); }
|
||||
forceinline void grow() { GEN_NS grow<Type>(*this); }
|
||||
forceinline void rehash(ssize new_num) { GEN_NS rehash<Type>(*this, new_num); }
|
||||
forceinline void rehash_fast() { GEN_NS rehash_fast<Type>(*this); }
|
||||
forceinline void remove(u64 key) { GEN_NS remove<Type>(*this, key); }
|
||||
forceinline void remove_entry(ssize idx) { GEN_NS remove_entry<Type>(*this, idx); }
|
||||
forceinline void set(u64 key, Type value) { GEN_NS set<Type>(*this, key, value); }
|
||||
forceinline ssize slot(u64 key) { return GEN_NS slot<Type>(*this, key); }
|
||||
forceinline void map(void (*proc)(u64, Type)) { GEN_NS map<Type>(*this, proc); }
|
||||
forceinline void map_mut(void (*proc)(u64, Type*)) { GEN_NS map_mut<Type>(*this, proc); }
|
||||
forceinline void clear() { clear<Type>(*this); }
|
||||
forceinline void destroy() { destroy<Type>(*this); }
|
||||
forceinline Type* get(u64 key) { return get<Type>(*this, key); }
|
||||
forceinline void grow() { grow<Type>(*this); }
|
||||
forceinline void rehash(ssize new_num) { rehash<Type>(*this, new_num); }
|
||||
forceinline void rehash_fast() { rehash_fast<Type>(*this); }
|
||||
forceinline void remove(u64 key) { remove<Type>(*this, key); }
|
||||
forceinline void remove_entry(ssize idx) { remove_entry<Type>(*this, idx); }
|
||||
forceinline void set(u64 key, Type value) { set<Type>(*this, key, value); }
|
||||
forceinline ssize slot(u64 key) { return slot<Type>(*this, key); }
|
||||
forceinline void map(void (*proc)(u64, Type)) { map<Type>(*this, proc); }
|
||||
forceinline void map_mut(void (*proc)(u64, Type*)) { map_mut<Type>(*this, proc); }
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
|
@ -1,16 +1,13 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.hpp"
|
||||
# include "basic_types.hpp"
|
||||
# include "src_start.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... )
|
||||
{
|
||||
_printf_err( "%s:(%d): Assert Failure: ", file, line );
|
||||
_printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line );
|
||||
|
||||
if ( condition )
|
||||
_printf_err( "`%s` \n", condition );
|
||||
@ -46,5 +43,4 @@ s32 assert_crash( char const* condition )
|
||||
}
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Debug
|
@ -1,6 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "dependencies/platform.hpp"
|
||||
# include "dependencies/macros.hpp"
|
||||
# include "basic_types.hpp"
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
@ -19,14 +22,14 @@
|
||||
|
||||
#define GEN_ASSERT( cond ) GEN_ASSERT_MSG( cond, NULL )
|
||||
|
||||
#define GEN_ASSERT_MSG( cond, msg, ... ) \
|
||||
do \
|
||||
{ \
|
||||
if ( ! ( cond ) ) \
|
||||
{ \
|
||||
assert_handler( #cond, __FILE__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
||||
GEN_DEBUG_TRAP(); \
|
||||
} \
|
||||
#define GEN_ASSERT_MSG( cond, msg, ... ) \
|
||||
do \
|
||||
{ \
|
||||
if ( ! ( cond ) ) \
|
||||
{ \
|
||||
assert_handler( #cond, __FILE__, __func__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \
|
||||
GEN_DEBUG_TRAP(); \
|
||||
} \
|
||||
} while ( 0 )
|
||||
|
||||
#define GEN_ASSERT_NOT_NULL( ptr ) GEN_ASSERT_MSG( ( ptr ) != NULL, #ptr " must not be NULL" )
|
||||
@ -56,10 +59,8 @@
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... );
|
||||
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... );
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Debug
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
|
||||
|
||||
@ -460,6 +459,7 @@ FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct _memory_fd _memory_fd;
|
||||
struct _memory_fd
|
||||
{
|
||||
u8 magic;
|
||||
@ -506,7 +506,7 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator )
|
||||
d->allocator = allocator;
|
||||
d->flags = EFileStream_CLONE_WRITABLE;
|
||||
d->cap = 0;
|
||||
d->buf = array_init<u8>( allocator );
|
||||
d->buf = array_init( u8, allocator );
|
||||
|
||||
if ( ! d->buf )
|
||||
return false;
|
||||
@ -532,7 +532,7 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize
|
||||
d->flags = flags;
|
||||
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
||||
{
|
||||
Array<u8> arr = array_init_reserve<u8>( allocator, size );
|
||||
Array(u8) arr = array_init_reserve(u8, allocator, size );
|
||||
d->buf = arr;
|
||||
|
||||
if ( ! d->buf )
|
||||
@ -609,9 +609,9 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
|
||||
|
||||
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
||||
{
|
||||
Array<u8> arr = { d->buf };
|
||||
Array(u8) arr = { d->buf };
|
||||
|
||||
if ( array_get_header(arr)->Capacity < usize(new_cap) )
|
||||
if ( array_get_header(arr)->Capacity < scast(usize, new_cap) )
|
||||
{
|
||||
if ( ! array_grow( & arr, ( s64 )( new_cap ) ) )
|
||||
return false;
|
||||
@ -623,7 +623,7 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
|
||||
|
||||
if ( ( d->flags & EFileStream_CLONE_WRITABLE ) && extralen > 0 )
|
||||
{
|
||||
Array<u8> arr = { d->buf };
|
||||
Array(u8) arr = { d->buf };
|
||||
|
||||
mem_copy( d->buf + offset + rwlen, pointer_add_const( buffer, rwlen ), extralen );
|
||||
d->cap = new_cap;
|
||||
@ -647,7 +647,7 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
|
||||
|
||||
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
||||
{
|
||||
Array<u8> arr = { d->buf };
|
||||
Array(u8) arr = { d->buf };
|
||||
array_free(arr);
|
||||
}
|
||||
|
||||
@ -656,5 +656,4 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
|
||||
|
||||
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion File Handling
|
@ -4,11 +4,8 @@
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
typedef u32 FileMode;
|
||||
|
||||
enum FileModeFlag_Def
|
||||
enum FileModeFlag
|
||||
{
|
||||
EFileMode_READ = bit( 0 ),
|
||||
EFileMode_WRITE = bit( 1 ),
|
||||
@ -16,18 +13,16 @@ enum FileModeFlag_Def
|
||||
EFileMode_RW = bit( 3 ),
|
||||
GEN_FILE_MODES = EFileMode_READ | EFileMode_WRITE | EFileMode_APPEND | EFileMode_RW,
|
||||
};
|
||||
typedef enum FileModeFlag_Def FileModeFlag;
|
||||
|
||||
// NOTE: Only used internally and for the file operations
|
||||
enum SeekWhenceType_Def
|
||||
enum SeekWhenceType
|
||||
{
|
||||
ESeekWhence_BEGIN = 0,
|
||||
ESeekWhence_CURRENT = 1,
|
||||
ESeekWhence_END = 2,
|
||||
};
|
||||
typedef enum SeekWhenceType_Def SeekWhenceType;
|
||||
|
||||
enum FileError_Def
|
||||
enum FileError
|
||||
{
|
||||
EFileError_NONE,
|
||||
EFileError_INVALID,
|
||||
@ -40,17 +35,16 @@ enum FileError_Def
|
||||
EFileError_NAME_TOO_LONG,
|
||||
EFileError_UNKNOWN,
|
||||
};
|
||||
typedef enum FileError_Def FileError;
|
||||
|
||||
union FileDescriptor_Def
|
||||
union FileDescriptor
|
||||
{
|
||||
void* p;
|
||||
sptr i;
|
||||
uptr u;
|
||||
};
|
||||
typedef union FileDescriptor_Def FileDescriptor;
|
||||
|
||||
typedef struct FileOperations_Def FileOperations;
|
||||
typedef u32 FileMode;
|
||||
typedef struct FileOperations FileOperations;
|
||||
|
||||
#define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename )
|
||||
#define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, ssize size, s64 offset, ssize* bytes_read, b32 stop_at_newline )
|
||||
@ -64,39 +58,35 @@ typedef GEN_FILE_WRITE_AT_PROC( FileWriteProc );
|
||||
typedef GEN_FILE_SEEK_PROC( FileSeekProc );
|
||||
typedef GEN_FILE_CLOSE_PROC( FileCloseProc );
|
||||
|
||||
struct FileOperations_Def
|
||||
struct FileOperations
|
||||
{
|
||||
FileReadProc* read_at;
|
||||
FileWriteProc* write_at;
|
||||
FileSeekProc* seek;
|
||||
FileCloseProc* close;
|
||||
};
|
||||
typedef struct FileOperations_Def FileOperations;
|
||||
|
||||
extern FileOperations const default_file_operations;
|
||||
|
||||
typedef u64 FileTime;
|
||||
|
||||
enum DirType_Def
|
||||
enum DirType
|
||||
{
|
||||
GEN_DIR_TYPE_FILE,
|
||||
GEN_DIR_TYPE_FOLDER,
|
||||
GEN_DIR_TYPE_UNKNOWN,
|
||||
};
|
||||
typedef enum DirType_Def DirType;
|
||||
|
||||
struct DirInfo_Def;
|
||||
typedef struct DirInfo_Def DirInfo;
|
||||
struct DirInfo;
|
||||
|
||||
struct DirEntry_Def
|
||||
struct DirEntry
|
||||
{
|
||||
char const* filename;
|
||||
DirInfo* dir_info;
|
||||
u8 type;
|
||||
};
|
||||
typedef struct DirEntry_Def DirEntry;
|
||||
|
||||
struct DirInfo_Def
|
||||
struct DirInfo
|
||||
{
|
||||
char const* fullpath;
|
||||
DirEntry* entries; // zpl_array
|
||||
@ -106,7 +96,7 @@ struct DirInfo_Def
|
||||
String buf;
|
||||
};
|
||||
|
||||
struct FileInfo_Def
|
||||
struct FileInfo
|
||||
{
|
||||
FileOperations ops;
|
||||
FileDescriptor fd;
|
||||
@ -116,9 +106,8 @@ struct FileInfo_Def
|
||||
FileTime last_write_time;
|
||||
DirEntry* dir;
|
||||
};
|
||||
typedef struct FileInfo_Def FileInfo;
|
||||
|
||||
enum FileStandardType_Def
|
||||
enum FileStandardType
|
||||
{
|
||||
EFileStandard_INPUT,
|
||||
EFileStandard_OUTPUT,
|
||||
@ -126,7 +115,6 @@ enum FileStandardType_Def
|
||||
|
||||
EFileStandard_COUNT,
|
||||
};
|
||||
typedef enum FileStandardType_Def FileStandardType;
|
||||
|
||||
/**
|
||||
* Get standard file I/O.
|
||||
@ -269,7 +257,7 @@ b32 file_write_at( FileInfo* file, void const* buffer, ssize size, s64 offset );
|
||||
*/
|
||||
b32 file_write_at_check( FileInfo* file, void const* buffer, ssize size, s64 offset, ssize* bytes_written );
|
||||
|
||||
enum FileStreamFlags_Def enum_underlying(u32)
|
||||
enum FileStreamFlags : u32
|
||||
{
|
||||
/* Allows us to write to the buffer directly. Beware: you can not append a new data! */
|
||||
EFileStream_WRITABLE = bit( 0 ),
|
||||
@ -280,7 +268,6 @@ enum FileStreamFlags_Def enum_underlying(u32)
|
||||
|
||||
EFileStream_UNDERLYING = GEN_U32_MAX,
|
||||
};
|
||||
typedef enum FileStreamFlags_Def FileStreamFlags;
|
||||
|
||||
/**
|
||||
* Opens a new memory stream
|
||||
@ -396,5 +383,4 @@ b32 file_write_at_check( FileInfo* f, void const* buffer, ssize size, s64 offset
|
||||
return f->ops.write_at( f->fd, buffer, size, offset, bytes_written );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion File Handling
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
global u32 const _crc32_table[ 256 ] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd,
|
||||
@ -88,5 +87,4 @@ u64 crc64( void const* data, ssize len )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Hashing
|
@ -4,10 +4,8 @@
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
u32 crc32( void const* data, ssize len );
|
||||
u64 crc64( void const* data, ssize len );
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Hashing
|
287
base/dependencies/macros.hpp
Normal file
287
base/dependencies/macros.hpp
Normal file
@ -0,0 +1,287 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "platform.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#ifndef global
|
||||
#define global static // Global variables
|
||||
#endif
|
||||
#ifndef internal
|
||||
#define internal static // Internal linkage
|
||||
#endif
|
||||
#ifndef local_persist
|
||||
#define local_persist static // Local Persisting variables
|
||||
#endif
|
||||
|
||||
#ifndef bit
|
||||
#define bit( Value ) ( 1 << Value )
|
||||
#define bitfield_is_equal( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) )
|
||||
#endif
|
||||
|
||||
// Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion
|
||||
#ifndef GEN_C_LIKE_CPP
|
||||
#define GEN_C_LIKE_CPP 0
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
# ifndef cast
|
||||
# define cast( type, value ) (tmpl_cast<type>( value ))
|
||||
# endif
|
||||
#else
|
||||
# ifndef cast
|
||||
# define cast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
# ifndef ccast
|
||||
# define ccast( type, value ) ( const_cast< type >( (value) ) )
|
||||
# endif
|
||||
# ifndef pcast
|
||||
# define pcast( type, value ) ( * reinterpret_cast< type* >( & ( value ) ) )
|
||||
# endif
|
||||
# ifndef rcast
|
||||
# define rcast( type, value ) reinterpret_cast< type >( value )
|
||||
# endif
|
||||
# ifndef scast
|
||||
# define scast( type, value ) static_cast< type >( value )
|
||||
# endif
|
||||
#else
|
||||
# ifndef ccast
|
||||
# define ccast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
# ifndef pcast
|
||||
# define pcast( type, value ) ( * (type*)(& value) )
|
||||
# endif
|
||||
# ifndef rcast
|
||||
# define rcast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
# ifndef scast
|
||||
# define scast( type, value ) ( (type)(value) )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef stringize
|
||||
#define stringize_va( ... ) #__VA_ARGS__
|
||||
#define stringize( ... ) stringize_va( __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#ifndef do_once
|
||||
#define do_once( statement ) for ( local_persist b32 once = true; once; once = false, (statement) )
|
||||
|
||||
#define do_once_start \
|
||||
do \
|
||||
{ \
|
||||
local_persist \
|
||||
bool done = false; \
|
||||
if ( done ) \
|
||||
break; \
|
||||
done = true;
|
||||
|
||||
#define do_once_end \
|
||||
} \
|
||||
while(0);
|
||||
#endif
|
||||
|
||||
#ifndef labeled_scope_start
|
||||
#define labeled_scope_start if ( false ) {
|
||||
#define labeled_scope_end }
|
||||
#endif
|
||||
|
||||
#ifndef compiler_decorated_func_name
|
||||
# ifdef COMPILER_CLANG
|
||||
# define compiler_decorated_func_name __PRETTY_NAME__
|
||||
# elif defined(COMPILER_MSVC)
|
||||
# define compiler_decorated_func_name __FUNCDNAME__
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef num_args_impl
|
||||
|
||||
// This is essentially an arg couneter version of GEN_SELECT_ARG macros
|
||||
// See section : _Generic function overloading for that usage (explains this heavier case)
|
||||
|
||||
#define num_args_impl( _0, \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
||||
_61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
|
||||
_71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
|
||||
_81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
|
||||
_91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
|
||||
N, ... \
|
||||
) N
|
||||
|
||||
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
||||
#define num_args(...) \
|
||||
num_args_impl(_, ## __VA_ARGS__, \
|
||||
100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
|
||||
90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
|
||||
80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
|
||||
70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
|
||||
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
|
||||
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
||||
0 \
|
||||
)
|
||||
#endif
|
||||
|
||||
#ifndef clamp
|
||||
#define clamp( x, lower, upper ) min( max( ( x ), ( lower ) ), ( upper ) )
|
||||
#endif
|
||||
#ifndef count_of
|
||||
#define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( ssize )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
|
||||
#endif
|
||||
#ifndef is_between
|
||||
#define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
|
||||
#endif
|
||||
#ifndef size_of
|
||||
#define size_of( x ) ( ssize )( sizeof( x ) )
|
||||
#endif
|
||||
|
||||
#ifndef max
|
||||
#define max( a, b ) ( (a > b) ? (a) : (b) )
|
||||
#endif
|
||||
#ifndef min
|
||||
#define min( a, b ) ( (a < b) ? (a) : (b) )
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_MSVC || GEN_COMPILER_TINYC
|
||||
# define offset_of( Type, element ) ( ( GEN_NS( ssize ) ) & ( ( ( Type* )0 )->element ) )
|
||||
#else
|
||||
# define offset_of( Type, element ) __builtin_offsetof( Type, element )
|
||||
#endif
|
||||
|
||||
#ifndef forceinline
|
||||
# if GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
# define neverinline __declspec( noinline )
|
||||
# elif GEN_COMPILER_GCC
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
# elif GEN_COMPILER_CLANG
|
||||
# if __has_attribute(__always_inline__)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
# else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
# endif
|
||||
# else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef neverinline
|
||||
# if GEN_COMPILER_MSVC
|
||||
# define neverinline __declspec( noinline )
|
||||
# elif GEN_COMPILER_GCC
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
# elif GEN_COMPILER_CLANG
|
||||
# if __has_attribute(__always_inline__)
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
# else
|
||||
# define neverinline
|
||||
# endif
|
||||
# else
|
||||
# define neverinline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
#ifndef static_assert
|
||||
#undef static_assert
|
||||
#if GEN_COMPILER_C && __STDC_VERSION__ >= 201112L
|
||||
#define static_assert(condition, message) _Static_assert(condition, message)
|
||||
#else
|
||||
#define static_assert(condition, message) typedef char static_assertion_##__LINE__[(condition)?1:-1]
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
// Already Defined
|
||||
#elif GEN_COMPILER_C && __STDC_VERSION__ >= 201112L
|
||||
# define thread_local _Thread_local
|
||||
#elif GEN_COMPILER_MSVC
|
||||
# define thread_local __declspec(thread)
|
||||
#elif GEN_COMPILER_CLANG
|
||||
# define thread_local __thread
|
||||
#else
|
||||
# error "No thread local support"
|
||||
#endif
|
||||
|
||||
#if ! defined(typeof) && (!GEN_COMPILER_C || __STDC_VERSION__ < 202311L)
|
||||
# if ! GEN_COMPILER_C
|
||||
# define typeof decltype
|
||||
# elif defined(_MSC_VER)
|
||||
# define typeof(x) __typeof__(x)
|
||||
# elif defined(__GNUC__) || defined(__clang__)
|
||||
# define typeof(x) __typeof__(x)
|
||||
# else
|
||||
# error "Compiler not supported"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef GEN_API_C_BEGIN
|
||||
# if GEN_COMPILER_C
|
||||
# define GEN_API_C_BEGIN
|
||||
# define GEN_API_C_END
|
||||
# else
|
||||
# define GEN_API_C_BEGIN extern "C" {
|
||||
# define GEN_API_C_END }
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
# if __STDC_VERSION__ >= 202311L
|
||||
# define enum_underlying(type) : type
|
||||
# else
|
||||
# define enum_underlying(type)
|
||||
# endif
|
||||
#else
|
||||
# define enum_underlying(type) : type
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
# ifndef nullptr
|
||||
# define nullptr NULL
|
||||
# endif
|
||||
|
||||
# ifndef GEN_REMOVE_PTR
|
||||
# define GEN_REMOVE_PTR(type) typeof(* ( (type) NULL) )
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if ! defined(GEN_PARAM_DEFAULT) && GEN_COMPILER_CPP
|
||||
# define GEN_PARAM_DEFAULT = {}
|
||||
#else
|
||||
# define GEN_PARAM_DEFAULT
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
#define struct_init(type, value) {value}
|
||||
#else
|
||||
#define struct_init(type, value) {value}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#ifndef GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
# define GEN_OPTIMIZE_MAPPINGS_BEGIN _pragma(optimize("gt", on))
|
||||
# define GEN_OPITMIZE_MAPPINGS_END _pragma(optimize("", on))
|
||||
#endif
|
||||
#else
|
||||
# define GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
# define GEN_OPITMIZE_MAPPINGS_END
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
@ -4,13 +4,12 @@
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
void* mem_copy( void* dest, void const* source, ssize n )
|
||||
{
|
||||
if ( dest == NULL )
|
||||
if ( dest == nullptr )
|
||||
{
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return memcpy( dest, source, n );
|
||||
@ -47,6 +46,7 @@ void const* mem_find( void const* data, u8 c, ssize n )
|
||||
|
||||
#define GEN_HEAP_STATS_MAGIC 0xDEADC0DE
|
||||
|
||||
typedef struct _heap_stats _heap_stats;
|
||||
struct _heap_stats
|
||||
{
|
||||
u32 magic;
|
||||
@ -81,6 +81,7 @@ void heap_stats_check( void )
|
||||
GEN_ASSERT( _heap_stats_info.alloc_count == 0 );
|
||||
}
|
||||
|
||||
typedef struct _heap_alloc_info _heap_alloc_info;
|
||||
struct _heap_alloc_info
|
||||
{
|
||||
ssize size;
|
||||
@ -518,5 +519,4 @@ void pool_clear(Pool* pool)
|
||||
pool->FreeList = pool->PhysicalStart;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Memory
|
@ -22,8 +22,6 @@ void swap( Type& a, Type& b )
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
//! Checks if value is power of 2.
|
||||
b32 is_power_of_two( ssize x );
|
||||
|
||||
@ -64,23 +62,21 @@ void zero_size( void* ptr, ssize size );
|
||||
//! Clears up an array.
|
||||
#define zero_array( a, count ) zero_size( ( a ), size_of( *( a ) ) * count )
|
||||
|
||||
enum AllocType_Def //enum_underlying(u8)
|
||||
enum AllocType : u8
|
||||
{
|
||||
EAllocation_ALLOC,
|
||||
EAllocation_FREE,
|
||||
EAllocation_FREE_ALL,
|
||||
EAllocation_RESIZE,
|
||||
};
|
||||
typedef enum AllocType_Def AllocType;
|
||||
|
||||
typedef void*(AllocatorProc)( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
|
||||
|
||||
struct AllocatorInfo_Def
|
||||
struct AllocatorInfo
|
||||
{
|
||||
AllocatorProc* Proc;
|
||||
void* Data;
|
||||
};
|
||||
typedef struct AllocatorInfo_Def AllocatorInfo;
|
||||
|
||||
enum AllocFlag
|
||||
{
|
||||
@ -144,12 +140,11 @@ constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocato
|
||||
//! Helper to free memory allocated by heap allocator.
|
||||
#define mfree( ptr ) free( heap(), ptr )
|
||||
|
||||
struct VirtualMemory_Def
|
||||
struct VirtualMemory
|
||||
{
|
||||
void* data;
|
||||
ssize size;
|
||||
};
|
||||
typedef struct VirtualMemory_Def VirtualMemory;
|
||||
|
||||
//! Initialize virtual memory from existing data.
|
||||
VirtualMemory vm_from_memory( void* data, ssize size );
|
||||
@ -173,8 +168,7 @@ b32 vm_purge( VirtualMemory vm );
|
||||
ssize virtual_memory_page_size( ssize* alignment_out );
|
||||
|
||||
#pragma region Arena
|
||||
struct Arena_Def;
|
||||
typedef struct Arena_Def Arena;
|
||||
struct Arena;
|
||||
|
||||
AllocatorInfo arena_allocator_info( Arena* arena );
|
||||
|
||||
@ -191,7 +185,7 @@ void arena_check (Arena* arena);
|
||||
void arena_free (Arena* arena);
|
||||
ssize arena_size_remaining(Arena* arena, ssize alignment);
|
||||
|
||||
struct Arena_Def
|
||||
struct Arena
|
||||
{
|
||||
AllocatorInfo Backing;
|
||||
void* PhysicalStart;
|
||||
@ -199,30 +193,29 @@ struct Arena_Def
|
||||
ssize TotalUsed;
|
||||
ssize TempCount;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS arena_allocator_info(this); }
|
||||
forceinline operator AllocatorInfo() { return arena_allocator_info(this); }
|
||||
|
||||
forceinline static void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) { return GEN_NS arena_allocator_proc( allocator_data, type, size, alignment, old_memory, old_size, flags ); }
|
||||
forceinline static Arena init_from_memory( void* start, ssize size ) { return GEN_NS arena_init_from_memory( start, size ); }
|
||||
forceinline static Arena init_from_allocator( AllocatorInfo backing, ssize size ) { return GEN_NS arena_init_from_allocator( backing, size ); }
|
||||
forceinline static Arena init_sub( Arena& parent, ssize size ) { return GEN_NS arena_init_from_allocator( parent.Backing, size ); }
|
||||
forceinline ssize alignment_of( ssize alignment ) { return GEN_NS arena_alignment_of(this, alignment); }
|
||||
forceinline void free() { return GEN_NS arena_free(this); }
|
||||
forceinline ssize size_remaining( ssize alignment ) { return GEN_NS arena_size_remaining(this, alignment); }
|
||||
forceinline static void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) { return arena_allocator_proc( allocator_data, type, size, alignment, old_memory, old_size, flags ); }
|
||||
forceinline static Arena init_from_memory( void* start, ssize size ) { return arena_init_from_memory( start, size ); }
|
||||
forceinline static Arena init_from_allocator( AllocatorInfo backing, ssize size ) { return arena_init_from_allocator( backing, size ); }
|
||||
forceinline static Arena init_sub( Arena& parent, ssize size ) { return arena_init_from_allocator( parent.Backing, size ); }
|
||||
forceinline ssize alignment_of( ssize alignment ) { return arena_alignment_of(this, alignment); }
|
||||
forceinline void free() { return arena_free(this); }
|
||||
forceinline ssize size_remaining( ssize alignment ) { return arena_size_remaining(this, alignment); }
|
||||
|
||||
// This id is defined by Unreal for asserts
|
||||
#pragma push_macro("check")
|
||||
#undef check
|
||||
forceinline void check() { GEN_NS arena_check(this); }
|
||||
forceinline void check() { arena_check(this); }
|
||||
#pragma pop_macro("check")
|
||||
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
};
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
GEN_API_C_END
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); }
|
||||
forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); }
|
||||
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); }
|
||||
@ -234,7 +227,6 @@ forceinline ssize size_remaining(Arena& arena, ssize alignment) { return
|
||||
#undef check
|
||||
forceinline void check(Arena& arena) { return arena_check(& arena); };
|
||||
#pragma pop_macro("check")
|
||||
GEN_API_C_BEGIN
|
||||
#endif
|
||||
|
||||
|
||||
@ -320,8 +312,6 @@ ssize arena_size_remaining(Arena* arena, ssize alignment)
|
||||
}
|
||||
#pragma endregion Arena
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma region FixedArena
|
||||
template<s32 Size>
|
||||
struct FixedArena;
|
||||
@ -329,8 +319,9 @@ struct FixedArena;
|
||||
template<s32 Size> FixedArena<Size> fixed_arena_init();
|
||||
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
||||
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
||||
template<s32 Size> void fixed_arena_free(FixedArena<Size>* fixed_arena);
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
||||
template<s32 Size> ssize size_remaining(FixedArena<Size>& fixed_arena, ssize alignment) { return size_remaining( & fixed_arena, alignment); }
|
||||
#endif
|
||||
@ -343,12 +334,12 @@ struct FixedArena
|
||||
char memory[Size];
|
||||
Arena arena;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); }
|
||||
forceinline operator AllocatorInfo() { return fixed_arena_allocator_info(this); }
|
||||
|
||||
forceinline static FixedArena init() { FixedArena result; GEN_NS fixed_arena_init<Size>(result); return result; }
|
||||
forceinline ssize size_remaining(ssize alignment) { GEN_NS size_remaining(this, alignment); }
|
||||
forceinline static FixedArena init() { FixedArena result; fixed_arena_init<Size>(result); return result; }
|
||||
forceinline ssize size_remaining(ssize alignment) { fixed_arena_size_remaining(this, alignment); }
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
};
|
||||
@ -375,25 +366,22 @@ ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment)
|
||||
return size_remaining(fixed_arena->arena, alignment);
|
||||
}
|
||||
|
||||
using Arena_1KB = FixedArena< kilobytes( 1 ) >;
|
||||
using Arena_4KB = FixedArena< kilobytes( 4 ) >;
|
||||
using Arena_8KB = FixedArena< kilobytes( 8 ) >;
|
||||
using Arena_16KB = FixedArena< kilobytes( 16 ) >;
|
||||
using Arena_32KB = FixedArena< kilobytes( 32 ) >;
|
||||
using Arena_64KB = FixedArena< kilobytes( 64 ) >;
|
||||
using Arena_128KB = FixedArena< kilobytes( 128 ) >;
|
||||
using Arena_256KB = FixedArena< kilobytes( 256 ) >;
|
||||
using Arena_512KB = FixedArena< kilobytes( 512 ) >;
|
||||
using Arena_1MB = FixedArena< megabytes( 1 ) >;
|
||||
using Arena_2MB = FixedArena< megabytes( 2 ) >;
|
||||
using Arena_4MB = FixedArena< megabytes( 4 ) >;
|
||||
using FixedArena_1KB = FixedArena< kilobytes( 1 ) >;
|
||||
using FixedArena_4KB = FixedArena< kilobytes( 4 ) >;
|
||||
using FixedArena_8KB = FixedArena< kilobytes( 8 ) >;
|
||||
using FixedArena_16KB = FixedArena< kilobytes( 16 ) >;
|
||||
using FixedArena_32KB = FixedArena< kilobytes( 32 ) >;
|
||||
using FixedArena_64KB = FixedArena< kilobytes( 64 ) >;
|
||||
using FixedArena_128KB = FixedArena< kilobytes( 128 ) >;
|
||||
using FixedArena_256KB = FixedArena< kilobytes( 256 ) >;
|
||||
using FixedArena_512KB = FixedArena< kilobytes( 512 ) >;
|
||||
using FixedArena_1MB = FixedArena< megabytes( 1 ) >;
|
||||
using FixedArena_2MB = FixedArena< megabytes( 2 ) >;
|
||||
using FixedArena_4MB = FixedArena< megabytes( 4 ) >;
|
||||
#pragma endregion FixedArena
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#pragma region Pool
|
||||
struct Pool_Def;
|
||||
typedef struct Pool_Def Pool;
|
||||
struct Pool;
|
||||
|
||||
void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
|
||||
|
||||
@ -403,15 +391,13 @@ AllocatorInfo pool_allocator_info(Pool* pool);
|
||||
void pool_clear(Pool* pool);
|
||||
void pool_free(Pool* pool);
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
GEN_API_C_END
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
|
||||
void clear(Pool& pool) { return pool_clear(& pool); }
|
||||
void free(Pool& pool) { return pool_free(& pool); }
|
||||
GEN_API_C_BEGIN
|
||||
#endif
|
||||
|
||||
struct Pool_Def
|
||||
struct Pool
|
||||
{
|
||||
AllocatorInfo Backing;
|
||||
void* PhysicalStart;
|
||||
@ -421,15 +407,15 @@ struct Pool_Def
|
||||
ssize TotalSize;
|
||||
ssize NumBlocks;
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline operator AllocatorInfo() { return GEN_NS pool_allocator_info(this); }
|
||||
forceinline operator AllocatorInfo() { return pool_allocator_info(this); }
|
||||
|
||||
forceinline static void* allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags) { return GEN_NS pool_allocator_proc(allocator_data, type, size, alignment, old_memory, old_size, flags); }
|
||||
forceinline static Pool init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { return GEN_NS pool_init(backing, num_blocks, block_size); }
|
||||
forceinline static Pool init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align) { return GEN_NS pool_init_align(backing, num_blocks, block_size, block_align); }
|
||||
forceinline void clear() { GEN_NS pool_clear( this); }
|
||||
forceinline void free() { GEN_NS pool_free( this); }
|
||||
forceinline static void* allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags) { return pool_allocator_proc(allocator_data, type, size, alignment, old_memory, old_size, flags); }
|
||||
forceinline static Pool init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { return pool_init(backing, num_blocks, block_size); }
|
||||
forceinline static Pool init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align) { return pool_init_align(backing, num_blocks, block_size, block_align); }
|
||||
forceinline void clear() { pool_clear( this); }
|
||||
forceinline void free() { pool_free( this); }
|
||||
#pragma endregion
|
||||
#endif
|
||||
};
|
||||
@ -442,14 +428,14 @@ AllocatorInfo pool_allocator_info(Pool* pool) {
|
||||
|
||||
inline
|
||||
Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size) {
|
||||
return pool_init_align(backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT);
|
||||
return pool_init_align(backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT);
|
||||
}
|
||||
|
||||
inline
|
||||
void pool_free(Pool* pool) {
|
||||
if(pool->Backing.Proc) {
|
||||
allocator_free(pool->Backing, pool->PhysicalStart);
|
||||
}
|
||||
if(pool->Backing.Proc) {
|
||||
allocator_free(pool->Backing, pool->PhysicalStart);
|
||||
}
|
||||
}
|
||||
#pragma endregion Pool
|
||||
|
||||
@ -684,6 +670,4 @@ void zero_size( void* ptr, ssize size ) {
|
||||
mem_set( ptr, 0, size );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Memory
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#define _adt_fprintf( s_, fmt_, ... ) \
|
||||
do \
|
||||
@ -25,7 +24,7 @@ u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32
|
||||
node->type = type;
|
||||
node->name = name;
|
||||
node->parent = parent;
|
||||
node->nodes = array_init<ADT_Node>( backing );
|
||||
node->nodes = array_init(ADT_Node, backing );
|
||||
|
||||
if ( ! node->nodes )
|
||||
return EADT_ERROR_OUT_OF_MEMORY;
|
||||
@ -1112,5 +1111,6 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
return output;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#undef _adt_fprintf
|
||||
|
||||
#pragma endregion CSV
|
@ -1,9 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "timing.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
enum ADT_Type : u32
|
||||
{
|
||||
@ -430,5 +430,4 @@ String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
return csv_write_string_delimiter( a, obj, ',' );
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion CSV
|
@ -29,12 +29,6 @@
|
||||
# ifndef GEN_SYSTEM_MACOS
|
||||
# define GEN_SYSTEM_MACOS 1
|
||||
# endif
|
||||
# include <TargetConditionals.h>
|
||||
# if TARGET_IPHONE_SIMULATOR == 1 || TARGET_OS_IPHONE == 1
|
||||
# ifndef GEN_SYSTEM_IOS
|
||||
# define GEN_SYSTEM_IOS 1
|
||||
# endif
|
||||
# endif
|
||||
#elif defined( __unix__ )
|
||||
# ifndef GEN_SYSTEM_UNIX
|
||||
# define GEN_SYSTEM_UNIX 1
|
||||
@ -76,17 +70,20 @@
|
||||
/* Platform compiler */
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# define GEN_COMPILER_CLANG 0
|
||||
# pragma message("Detected MSVC")
|
||||
// # define GEN_COMPILER_CLANG 0
|
||||
# define GEN_COMPILER_MSVC 1
|
||||
# define GEN_COMPILER_GCC 0
|
||||
// # define GEN_COMPILER_GCC 0
|
||||
#elif defined( __GNUC__ )
|
||||
# define GEN_COMPILER_CLANG 0
|
||||
# define GEN_COMPILER_MSVC 0
|
||||
# pragma message("Detected GCC")
|
||||
// # define GEN_COMPILER_CLANG 0
|
||||
// # define GEN_COMPILER_MSVC 0
|
||||
# define GEN_COMPILER_GCC 1
|
||||
#elif defined( __clang__ )
|
||||
# pragma message("Detected CLANG")
|
||||
# define GEN_COMPILER_CLANG 1
|
||||
# define GEN_COMPILER_MSVC 0
|
||||
# define GEN_COMPILER_GCC 1
|
||||
// # define GEN_COMPILER_MSVC 0
|
||||
// # define GEN_COMPILER_GCC 0
|
||||
#else
|
||||
# error Unknown compiler
|
||||
#endif
|
@ -1,12 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
# include "strings.hpp"
|
||||
# include "string_ops.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
enum
|
||||
{
|
||||
@ -34,6 +31,7 @@ enum
|
||||
GEN_FMT_INTS = GEN_FMT_CHAR | GEN_FMT_SHORT | GEN_FMT_INT | GEN_FMT_LONG | GEN_FMT_LLONG | GEN_FMT_SIZE | GEN_FMT_INTPTR
|
||||
};
|
||||
|
||||
typedef struct _format_info _format_info;
|
||||
struct _format_info
|
||||
{
|
||||
s32 base;
|
||||
@ -430,7 +428,7 @@ neverinline ssize str_fmt_va( char* text, ssize max_len, char const* fmt, va_lis
|
||||
break;
|
||||
}
|
||||
|
||||
String gen_str = String { va_arg( va, char*) };
|
||||
String gen_str = { va_arg( va, char*) };
|
||||
|
||||
info.precision = string_length(gen_str);
|
||||
len = _print_string( text, remaining, &info, gen_str );
|
||||
@ -598,5 +596,4 @@ ssize str_fmt_out_err( char const* fmt, ... )
|
||||
return res;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Printing
|
@ -5,9 +5,7 @@
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
typedef struct FileInfo_Def FileInfo;
|
||||
typedef struct FileInfo FileInfo;
|
||||
|
||||
#ifndef GEN_PRINTF_MAXLEN
|
||||
# define GEN_PRINTF_MAXLEN kilobytes(128)
|
||||
@ -41,6 +39,4 @@ ssize log_fmt(char const* fmt, ...)
|
||||
return res;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Printing
|
@ -1,4 +1,5 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
@ -1,11 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.hpp"
|
||||
# include "debug.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
internal
|
||||
ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
|
||||
@ -213,5 +211,4 @@ f64 str_to_f64( const char* str, char** end_ptr )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion String Ops
|
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
const char* char_first_occurence( const char* str, char c );
|
||||
|
||||
b32 char_is_alpha( char c );
|
||||
@ -286,6 +284,4 @@ void str_to_upper( char* str )
|
||||
}
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion String Ops
|
@ -4,21 +4,24 @@
|
||||
#endif
|
||||
|
||||
#pragma region String
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
String string_make_length( AllocatorInfo allocator, char const* str, ssize length )
|
||||
{
|
||||
constexpr ssize header_size = sizeof( StringHeader );
|
||||
ssize const header_size = sizeof( StringHeader );
|
||||
|
||||
s32 alloc_size = header_size + length + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
if ( allocation == nullptr ) {
|
||||
String null_string = {nullptr};
|
||||
return null_string;
|
||||
}
|
||||
|
||||
StringHeader&
|
||||
header = * rcast(StringHeader*, allocation);
|
||||
header = { allocator, length, length };
|
||||
StringHeader*
|
||||
header = rcast(StringHeader*, allocation);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = length;
|
||||
header->Length = length;
|
||||
|
||||
String result = { rcast( char*, allocation) + header_size };
|
||||
|
||||
@ -34,14 +37,15 @@ String string_make_length( AllocatorInfo allocator, char const* str, ssize lengt
|
||||
|
||||
String string_make_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
{
|
||||
constexpr ssize header_size = sizeof( StringHeader );
|
||||
ssize const header_size = sizeof( StringHeader );
|
||||
|
||||
s32 alloc_size = header_size + capacity + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
if ( allocation == nullptr ) {
|
||||
String null_string = {nullptr};
|
||||
return null_string;
|
||||
}
|
||||
mem_set( allocation, 0, alloc_size );
|
||||
|
||||
StringHeader*
|
||||
@ -54,5 +58,4 @@ String string_make_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
return result;
|
||||
}
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion String
|
@ -5,23 +5,18 @@
|
||||
|
||||
#pragma region Strings
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
struct StrC_Def;
|
||||
typedef struct StrC_Def StrC;
|
||||
struct StrC;
|
||||
|
||||
StrC to_strc_from_c_str (char const* bad_string);
|
||||
bool strc_are_equal (StrC lhs, StrC rhs);
|
||||
char const* strc_back (StrC str);
|
||||
bool strc_contains (StrC str, StrC substring);
|
||||
StrC strc_duplicate (StrC str, AllocatorInfo allocator);
|
||||
b32 strc_starts_with (StrC str, StrC substring);
|
||||
StrC strc_to_str (char const* bad_string);
|
||||
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
// Constant string with length.
|
||||
struct StrC_Def
|
||||
struct StrC
|
||||
{
|
||||
ssize Len;
|
||||
char const* Ptr;
|
||||
@ -30,13 +25,13 @@ struct StrC_Def
|
||||
forceinline operator char const* () const { return Ptr; }
|
||||
forceinline char const& operator[]( ssize index ) const { return Ptr[index]; }
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
forceinline bool is_equal (StrC rhs) const { return GEN_NS strc_are_equal(* this, rhs); }
|
||||
forceinline char const* back () const { return GEN_NS strc_back(* this); }
|
||||
forceinline bool contains (StrC substring) const { return GEN_NS strc_contains(* this, substring); }
|
||||
forceinline StrC duplicate (AllocatorInfo allocator) const { return GEN_NS strc_duplicate(* this, allocator); }
|
||||
forceinline b32 starts_with (StrC substring) const { return GEN_NS strc_starts_with(* this, substring); }
|
||||
forceinline StrC visualize_whitespace(AllocatorInfo allocator) const { return GEN_NS strc_visualize_whitespace(* this, allocator); }
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
forceinline bool is_equal (StrC rhs) const { return strc_are_equal(* this, rhs); }
|
||||
forceinline char const* back () const { return strc_back(* this); }
|
||||
forceinline bool contains (StrC substring) const { return strc_contains(* this, substring); }
|
||||
forceinline StrC duplicate (AllocatorInfo allocator) const { return strc_duplicate(* this, allocator); }
|
||||
forceinline b32 starts_with (StrC substring) const { return strc_starts_with(* this, substring); }
|
||||
forceinline StrC visualize_whitespace(AllocatorInfo allocator) const { return strc_visualize_whitespace(* this, allocator); }
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
@ -63,8 +58,6 @@ forceinline char const* end (StrC str) { return str.Ptr + str
|
||||
forceinline char const* next (StrC str, char const* iter) { return iter + 1; }
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
inline
|
||||
bool strc_are_equal(StrC lhs, StrC rhs)
|
||||
{
|
||||
@ -113,24 +106,20 @@ StrC to_strc_from_c_str( char const* bad_str ) {
|
||||
StrC result = { str_len( bad_str ), bad_str };
|
||||
return result;
|
||||
}
|
||||
GEN_API_C_END
|
||||
|
||||
// Dynamic String
|
||||
// This is directly based off the ZPL string api.
|
||||
// They used a header pattern
|
||||
// I kept it for simplicty of porting but its not necessary to keep it that way.
|
||||
#pragma region String
|
||||
struct StringHeader_Def;
|
||||
typedef struct StringHeader_Def StringHeader;
|
||||
struct StringHeader;
|
||||
|
||||
#if GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_C
|
||||
typedef char* String;
|
||||
#else
|
||||
struct String;
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
forceinline usize string_grow_formula(usize value);
|
||||
|
||||
String string_make_c_str (AllocatorInfo allocator, char const* str);
|
||||
@ -168,15 +157,13 @@ void string_trim (String str, char const* cut_set)
|
||||
void string_trim_space (String str);
|
||||
String string_visualize_whitespace(String const str);
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
struct StringHeader_Def {
|
||||
struct StringHeader {
|
||||
AllocatorInfo Allocator;
|
||||
ssize Capacity;
|
||||
ssize Length;
|
||||
};
|
||||
|
||||
#if GEN_COMPILER_CPP && GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
#if GEN_COMPILER_CPP
|
||||
struct String
|
||||
{
|
||||
char* Data;
|
||||
@ -203,6 +190,7 @@ struct String
|
||||
friend forceinline bool operator==(std::nullptr_t, const String str) { return str.Data == nullptr; }
|
||||
friend forceinline bool operator!=(std::nullptr_t, const String str) { return str.Data != nullptr; }
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
forceinline char* begin() const { return Data; }
|
||||
forceinline char* end() const { return Data + string_length(* this); }
|
||||
|
||||
@ -273,22 +261,21 @@ struct String
|
||||
return string_append_c_str_len(this, buf, res);
|
||||
}
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
forceinline char* string_begin(String str) { return ((char*) str); }
|
||||
forceinline char* string_end (String str) { return ((char*) str + string_length(str)); }
|
||||
forceinline char* string_next (String str, char const* iter) { return ((char*) iter + 1); }
|
||||
GEN_API_C_END
|
||||
|
||||
#if GEN_COMPILER_CPP && 0
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline char* begin(String str) { return ((char*) str); }
|
||||
forceinline char* end (String str) { return ((char*) str + string_length(str)); }
|
||||
forceinline char* next (String str, char* iter) { return ((char*) iter + 1); }
|
||||
#endif
|
||||
|
||||
#if GEN_SUPPORT_CPP_REFERENCES
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline bool make_space_for(String& str, char const* to_append, ssize add_len);
|
||||
forceinline bool append(String& str, char c);
|
||||
forceinline bool append(String& str, char const* str_to_append);
|
||||
@ -301,8 +288,6 @@ forceinline void clear(String& str);
|
||||
forceinline void free(String& str);
|
||||
#endif
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
forceinline
|
||||
usize string_grow_formula(usize value) {
|
||||
// Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library.
|
||||
@ -499,18 +484,18 @@ bool string_contains_string(String const str, String const substring)
|
||||
|
||||
forceinline
|
||||
ssize string_capacity(String const str) {
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Capacity;
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Capacity;
|
||||
}
|
||||
|
||||
forceinline
|
||||
void string_clear(String str) {
|
||||
string_get_header(str)->Length = 0;
|
||||
string_get_header(str)->Length = 0;
|
||||
}
|
||||
|
||||
forceinline
|
||||
String string_duplicate(String const str, AllocatorInfo allocator) {
|
||||
return string_make_length(allocator, str, string_length(str));
|
||||
return string_make_length(allocator, str, string_length(str));
|
||||
}
|
||||
|
||||
forceinline
|
||||
@ -525,14 +510,14 @@ void string_free(String* str) {
|
||||
|
||||
forceinline
|
||||
StringHeader* string_get_header(String str) {
|
||||
return (StringHeader*)(scast(char*, str) - sizeof(StringHeader));
|
||||
return (StringHeader*)(scast(char*, str) - sizeof(StringHeader));
|
||||
}
|
||||
|
||||
forceinline
|
||||
ssize string_length(String const str)
|
||||
{
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Length;
|
||||
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
|
||||
return header->Length;
|
||||
}
|
||||
|
||||
inline
|
||||
@ -597,7 +582,7 @@ void string_skip_line(String str)
|
||||
#define current (*scanner)
|
||||
char* scanner = str;
|
||||
while (current != '\r' && current != '\n') {
|
||||
++scanner;
|
||||
++scanner;
|
||||
}
|
||||
|
||||
s32 new_length = scanner - str;
|
||||
@ -616,23 +601,22 @@ void string_skip_line(String str)
|
||||
inline
|
||||
void strip_space(String str)
|
||||
{
|
||||
char* write_pos = str;
|
||||
char* read_pos = str;
|
||||
|
||||
while (* read_pos)
|
||||
{
|
||||
if (! char_is_space(* read_pos))
|
||||
{
|
||||
* write_pos = * read_pos;
|
||||
write_pos++;
|
||||
}
|
||||
read_pos++;
|
||||
}
|
||||
char* write_pos = str;
|
||||
char* read_pos = str;
|
||||
|
||||
while (* read_pos)
|
||||
{
|
||||
if (! char_is_space(* read_pos))
|
||||
{
|
||||
* write_pos = * read_pos;
|
||||
write_pos++;
|
||||
}
|
||||
read_pos++;
|
||||
}
|
||||
write_pos[0] = '\0'; // Null-terminate the modified string
|
||||
|
||||
// Update the length if needed
|
||||
string_get_header(str)->Length = write_pos - str;
|
||||
// Update the length if needed
|
||||
string_get_header(str)->Length = write_pos - str;
|
||||
}
|
||||
|
||||
forceinline
|
||||
@ -642,7 +626,7 @@ StrC string_to_strc(String str) {
|
||||
}
|
||||
|
||||
inline
|
||||
void trim(String str, char const* cut_set)
|
||||
void string_trim(String str, char const* cut_set)
|
||||
{
|
||||
ssize len = 0;
|
||||
|
||||
@ -662,16 +646,16 @@ void trim(String str, char const* cut_set)
|
||||
|
||||
str[len] = '\0';
|
||||
|
||||
string_get_header(str)->Length = len;
|
||||
string_get_header(str)->Length = len;
|
||||
}
|
||||
|
||||
forceinline
|
||||
void trim_space(String str) {
|
||||
trim(str, " \t\r\n\v\f");
|
||||
void string_trim_space(String str) {
|
||||
string_trim(str, " \t\r\n\v\f");
|
||||
}
|
||||
|
||||
inline
|
||||
String visualize_whitespace(String const str)
|
||||
String string_visualize_whitespace(String const str)
|
||||
{
|
||||
StringHeader* header = (StringHeader*)(scast(char const*, str) - sizeof(StringHeader));
|
||||
String result = string_make_reserve(header->Allocator, string_length(str) * 2); // Assume worst case for space requirements.
|
||||
@ -723,7 +707,7 @@ inline
|
||||
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator)
|
||||
{
|
||||
String result = string_make_reserve(allocator, str.Len * 2); // Assume worst case for space requirements.
|
||||
for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c))
|
||||
for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c))
|
||||
switch ( * c )
|
||||
{
|
||||
case ' ':
|
||||
@ -755,8 +739,6 @@ StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator)
|
||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||
typedef StrC StringCached;
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
typedef HashTable(StringCached) StringTable;
|
||||
#pragma endregion Strings
|
@ -4,7 +4,6 @@
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
#if defined( GEN_COMPILER_MSVC ) && ! defined( __clang__ )
|
||||
@ -165,5 +164,4 @@ GEN_API_C_BEGIN
|
||||
}
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
#pragma endregion Timing
|
@ -5,8 +5,6 @@
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
GEN_API_C_BEGIN
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
//! Return CPU timestamp.
|
||||
u64 read_cpu_time_stamp_counter( void );
|
||||
@ -18,6 +16,4 @@ f64 time_rel( void );
|
||||
u64 time_rel_ms( void );
|
||||
#endif
|
||||
|
||||
GEN_API_C_END
|
||||
|
||||
#pragma endregion Timing
|
61
base/enums/ECodeTypes.csv
Normal file
61
base/enums/ECodeTypes.csv
Normal file
@ -0,0 +1,61 @@
|
||||
Invalid, "__NA__"
|
||||
Untyped, "__NA__"
|
||||
NewLine, "__NA__"
|
||||
Comment, "//"
|
||||
Access_Private, "private"
|
||||
Access_Protected, "protected"
|
||||
Access_Public, "public"
|
||||
PlatformAttributes, "__NA__"
|
||||
Class, "class"
|
||||
Class_Fwd, "clsss"
|
||||
Class_Body, "__NA__"
|
||||
Constructor, "__NA__"
|
||||
Constructor_Fwd, "__NA__"
|
||||
Destructor, "__NA__"
|
||||
Destructor_Fwd, "__NA__"
|
||||
Enum, "enum"
|
||||
Enum_Fwd, "enum"
|
||||
Enum_Body, "__NA__"
|
||||
Enum_Class, "enum class"
|
||||
Enum_Class_Fwd, "enum class"
|
||||
Execution, "__NA__"
|
||||
Export_Body, "__NA__"
|
||||
Extern_Linkage, "extern"
|
||||
Extern_Linkage_Body, "extern"
|
||||
Friend, "friend"
|
||||
Function, "__NA__"
|
||||
Function_Fwd, "__NA__"
|
||||
Function_Body, "__NA__"
|
||||
Global_Body, "__NA__"
|
||||
Module, "module"
|
||||
Namespace, "namespace"
|
||||
Namespace_Body, "__NA__"
|
||||
Operator, "operator"
|
||||
Operator_Fwd, "operator"
|
||||
Operator_Member, "operator"
|
||||
Operator_Member_Fwd, "operator"
|
||||
Operator_Cast, "operator"
|
||||
Operator_Cast_Fwd, "operator"
|
||||
Parameters, "__NA__"
|
||||
Preprocess_Define, "define"
|
||||
Preprocess_Include, "include"
|
||||
Preprocess_If, "if"
|
||||
Preprocess_IfDef, "ifdef"
|
||||
Preprocess_IfNotDef, "ifndef"
|
||||
Preprocess_ElIf, "elif"
|
||||
Preprocess_Else, "else"
|
||||
Preprocess_EndIf, "endif"
|
||||
Preprocess_Pragma, "pragma"
|
||||
Specifiers, "__NA__"
|
||||
Struct, "struct"
|
||||
Struct_Fwd, "struct"
|
||||
Struct_Body, "__NA__"
|
||||
Template, "template"
|
||||
Typedef, "typedef"
|
||||
Typename, "__NA__"
|
||||
Union, "union"
|
||||
Union_Fwd, "union"
|
||||
Union_Body, "__NA__"
|
||||
Using, "using"
|
||||
Using_Namespace, "using namespace"
|
||||
Variable, "__NA__"
|
|
@ -37,6 +37,9 @@ GEN_NS_BEGIN
|
||||
#include "components/interface.parsing.cpp"
|
||||
#include "components/interface.untyped.cpp"
|
||||
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
#include "helpers/pop_container_defines.inline.hpp"
|
@ -13,5 +13,6 @@ GEN_NS_BEGIN
|
||||
#include "dependencies/strings.cpp"
|
||||
#include "dependencies/filesystem.cpp"
|
||||
#include "dependencies/timing.cpp"
|
||||
#include "dependencies/parsing.cpp"
|
||||
|
||||
GEN_NS_END
|
@ -16,5 +16,6 @@ GEN_NS_BEGIN
|
||||
#include "dependencies/strings.hpp"
|
||||
#include "dependencies/filesystem.hpp"
|
||||
#include "dependencies/timing.hpp"
|
||||
#include "dependencies/parsing.hpp"
|
||||
|
||||
GEN_NS_END
|
@ -17,7 +17,7 @@
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/types.hpp"
|
||||
#include "components/gen/ecode.hpp"
|
||||
#include "components/gen/ecodetypes.hpp"
|
||||
#include "components/gen/eoperator.hpp"
|
||||
#include "components/gen/especifier.hpp"
|
||||
|
||||
@ -31,6 +31,9 @@ GEN_NS_BEGIN
|
||||
#include "components/gen/ast_inlines.hpp"
|
||||
#include "components/header_end.hpp"
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
#include "helpers/pop_container_defines.inline.hpp"
|
@ -18,6 +18,8 @@
|
||||
// Precedence (highest to lowest):
|
||||
// word, namespace, regex
|
||||
|
||||
// TODO(ED): THIS IS VERY OUTDATED
|
||||
|
||||
// Gen Macro namespace
|
||||
// namespace GEN_, new_namespace_
|
||||
|
@ -1,104 +1,152 @@
|
||||
#pragma once
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.hpp"
|
||||
GEN_NS_END
|
||||
#if GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "../gen.hpp"
|
||||
# include "misc.hpp"
|
||||
|
||||
using namespace gen;
|
||||
#endif
|
||||
|
||||
CodeBody gen_ecode( char const* path )
|
||||
CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
FixedArena_32KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_keyword_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for ( ADT_Node* node = array_begin(enum_strs); node != array_end(enum_strs); node = array_next(enum_strs, node) )
|
||||
{
|
||||
char const* code = node->string;
|
||||
|
||||
string_append_fmt( & enum_entries, "CT_%s,\n", code );
|
||||
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
|
||||
for ( ssize idx = 0; idx < array_num(csv_enum.Col_1); ++ idx ) {
|
||||
char const* code = csv_enum.Col_1[idx].string;
|
||||
char const* keyword = csv_enum.Col_2[idx].string;
|
||||
// TODO(Ed): to_str_entries and the others in here didn't have proper sizing of the StrC slice.
|
||||
string_append_fmt( & enum_entries, "CT_%s,\n", code );
|
||||
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
|
||||
string_append_fmt( & to_keyword_str_entries, "{ sizeof(\"%s\") - 1, \"%s\" },\n", keyword, keyword );
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
||||
"enum CodeType_Def : u32 { <entries> CT_NumTypes };"
|
||||
));
|
||||
CodeEnum enum_code;
|
||||
if (use_c_definition) {
|
||||
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
||||
"enum CodeType enum_underlying(u32) { <entries> CT_NumTypes, CT_UnderlyingType = GEN_U32_MAX };"
|
||||
));
|
||||
}
|
||||
else {
|
||||
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
||||
"enum CodeType : u32 { <entries> CT_NumTypes, CT_UnderlyingType = GEN_U32_MAX };"
|
||||
));
|
||||
}
|
||||
|
||||
#pragma push_macro("local_persist")
|
||||
#undef local_persist
|
||||
CodeFn to_str = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
|
||||
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(csv_enum.Col_1) ));
|
||||
CodeBody to_str_fns = parse_global_body( token_fmt(
|
||||
"entries", string_to_strc(to_str_entries)
|
||||
, "keywords", string_to_strc(to_keyword_str_entries)
|
||||
, "num", lookup_size
|
||||
, stringize(
|
||||
inline
|
||||
StrC to_str( CodeType type )
|
||||
StrC codetype_to_str( CodeType type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
StrC lookup[<num>] = {
|
||||
<entries>
|
||||
};
|
||||
return lookup[ type ];
|
||||
}
|
||||
|
||||
inline
|
||||
StrC codetype_to_keyword_str( CodeType type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ <num> ] = {
|
||||
<keywords>
|
||||
};
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro("local_persist")
|
||||
|
||||
//CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
|
||||
//CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
|
||||
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType_Def CodeType; ));
|
||||
CodeBody result = def_body(CT_Global_Body);
|
||||
body_append(result, enum_code);
|
||||
|
||||
return def_global_body( args( enum_code, code_t, to_str, fmt_newline ) );
|
||||
if (use_c_definition) {
|
||||
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; ));
|
||||
body_append(result, code_t);
|
||||
}
|
||||
|
||||
body_append(result, to_str_fns);
|
||||
|
||||
if (! use_c_definition) {
|
||||
#pragma push_macro("forceinline")
|
||||
#undef forceinline
|
||||
CodeBody alias_mappings = parse_global_body(code(
|
||||
forceinline StrC to_str (CodeType type) { return codetype_to_str(type); }
|
||||
forceinline StrC to_keyword_str(CodeType type) { return codetype_to_keyword_str(type); }
|
||||
));
|
||||
#pragma pop_macro("forceinline")
|
||||
body_append(result, alias_mappings);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody gen_eoperator( char const* path )
|
||||
CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
||||
{
|
||||
char scratch_mem[kilobytes(4)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
FixedArena_16KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
file_read_contents( arena_allocator_info(& scratch), file_zero_terminate, path );
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, 32 );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, 32 );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = str_strs [idx].string;
|
||||
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++) {
|
||||
char const* enum_str = csv_enum.Col_1[idx].string;
|
||||
char const* entry_to_str = csv_enum.Col_2[idx].string;
|
||||
|
||||
string_append_fmt( & enum_entries, "Op_%s,\n", enum_str );
|
||||
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
||||
enum Operator_Def : u32
|
||||
{
|
||||
<entries>
|
||||
NumOps
|
||||
};
|
||||
)));
|
||||
CodeEnum enum_code;
|
||||
if (use_c_definition)
|
||||
{
|
||||
#pragma push_macro("enum_underlying")
|
||||
#undef enum_underlying
|
||||
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
||||
enum Operator enum_underlying(u32)
|
||||
{
|
||||
<entries>
|
||||
Op_NumOps,
|
||||
Op_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
)));
|
||||
#pragma pop_macro("enum_underlying")
|
||||
}
|
||||
else
|
||||
{
|
||||
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
||||
enum Operator : u32
|
||||
{
|
||||
<entries>
|
||||
Op_NumOps,
|
||||
Op_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
)));
|
||||
}
|
||||
|
||||
#pragma push_macro("local_persist")
|
||||
#undef local_persist
|
||||
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), stringize(
|
||||
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(csv_enum.Col_1) ));
|
||||
CodeFn to_str = parse_function(token_fmt(
|
||||
"entries", string_to_strc(to_str_entries)
|
||||
, "num", lookup_size
|
||||
, stringize(
|
||||
inline
|
||||
StrC to_str( Operator op )
|
||||
StrC operator_to_str( Operator op )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
StrC lookup[<num>] = {
|
||||
<entries>
|
||||
};
|
||||
|
||||
@ -107,49 +155,76 @@ CodeBody gen_eoperator( char const* path )
|
||||
)));
|
||||
#pragma pop_macro("local_persist")
|
||||
|
||||
//CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
|
||||
//CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
|
||||
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator_Def Operator; ));
|
||||
CodeBody result = def_body(CT_Global_Body);
|
||||
body_append(result, enum_code);
|
||||
if ( use_c_definition ) {
|
||||
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; ));
|
||||
body_append(result, operator_t);
|
||||
}
|
||||
|
||||
return def_global_body( args( enum_code, operator_t, to_str, fmt_newline ) );
|
||||
body_append(result, to_str);
|
||||
|
||||
if (! use_c_definition)
|
||||
{
|
||||
#pragma push_macro("forceinline")
|
||||
#undef forceinline
|
||||
CodeBody alias_mappings = parse_global_body(code(
|
||||
forceinline StrC to_str(Operator op) { return operator_to_str(op); }
|
||||
));
|
||||
#pragma pop_macro("forceinline")
|
||||
body_append(result, alias_mappings);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody gen_especifier( char const* path )
|
||||
CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
||||
{
|
||||
char scratch_mem[kilobytes(4)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
FixedArena_16KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
file_read_contents( arena_allocator_info(& scratch), file_zero_terminate, path );
|
||||
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||
String enum_entries = string_make_reserve( scratch_info, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( scratch_info, kilobytes(1) );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
||||
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = str_strs [idx].string;
|
||||
char const* enum_str = csv_enum.Col_1[idx].string;
|
||||
char const* entry_to_str = csv_enum.Col_2[idx].string;
|
||||
|
||||
string_append_fmt( & enum_entries, "Spec_%s,\n", enum_str );
|
||||
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
||||
enum Specifier_Def : u32
|
||||
{
|
||||
<entries>
|
||||
Spec_NumSpecifiers
|
||||
};
|
||||
)));
|
||||
CodeEnum enum_code;
|
||||
if (use_c_definition)
|
||||
{
|
||||
#pragma push_macro("enum_underlying")
|
||||
#undef enum_underlying
|
||||
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
||||
enum Specifier enum_underlying(u32)
|
||||
{
|
||||
<entries>
|
||||
Spec_NumSpecifiers,
|
||||
Spec_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
)));
|
||||
#pragma pop_macro("enum_underlying")
|
||||
}
|
||||
else
|
||||
{
|
||||
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
|
||||
enum Specifier : u32
|
||||
{
|
||||
<entries>
|
||||
Spec_NumSpecifiers,
|
||||
Spec_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
)));
|
||||
}
|
||||
|
||||
CodeFn is_trailing = parse_function(token_fmt("specifier", string_to_strc(to_str_entries), stringize(
|
||||
inline
|
||||
bool is_trailing( Specifier specifier )
|
||||
bool spec_is_trailing( Specifier specifier )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
}
|
||||
@ -165,12 +240,16 @@ CodeBody gen_especifier( char const* path )
|
||||
#undef do_once_end
|
||||
#undef forceinline
|
||||
#undef neverinline
|
||||
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), stringize(
|
||||
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(csv_enum.Col_1) ));
|
||||
CodeFn to_str = parse_function(token_fmt(
|
||||
"entries", string_to_strc(to_str_entries)
|
||||
, "num", lookup_size
|
||||
, stringize(
|
||||
inline
|
||||
StrC to_str( Specifier type )
|
||||
StrC spec_to_str( Specifier type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
StrC lookup[<num>] = {
|
||||
<entries>
|
||||
};
|
||||
|
||||
@ -180,14 +259,14 @@ CodeBody gen_especifier( char const* path )
|
||||
|
||||
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
|
||||
inline
|
||||
Specifier to_specifier( StrC str )
|
||||
Specifier strc_to_specifier( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ Spec_NumSpecifiers ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Specifier)index );
|
||||
StrC enum_str = spec_to_str( (Specifier)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
@ -212,40 +291,58 @@ CodeBody gen_especifier( char const* path )
|
||||
#pragma pop_macro("forceinline")
|
||||
#pragma pop_macro("neverinline")
|
||||
|
||||
//CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
|
||||
//CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) );
|
||||
CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier_Def Specifier; ));
|
||||
CodeBody result = def_body(CT_Global_Body);
|
||||
body_append(result, enum_code);
|
||||
if (use_c_definition)
|
||||
{
|
||||
CodeTypedef specifier_t = parse_typedef( code(typedef u32 Specifier; ));
|
||||
body_append(result, specifier_t);
|
||||
}
|
||||
|
||||
return def_global_body( args( enum_code, specifier_t, is_trailing, to_str, to_type, fmt_newline ) );
|
||||
body_append(result, to_str);
|
||||
body_append(result, is_trailing);
|
||||
body_append(result, to_type);
|
||||
|
||||
if (! use_c_definition)
|
||||
{
|
||||
#pragma push_macro("forceinline")
|
||||
#undef forceinline
|
||||
CodeBody alias_mappings = parse_global_body(code(
|
||||
forceinline StrC to_str (Specifier spec) { return spec_to_str(spec); }
|
||||
forceinline Specifier to_type( StrC str ) { return strc_to_specifier(str); }
|
||||
forceinline bool is_trailing( Specifier specifier ) { return spec_is_trailing(specifier); }
|
||||
));
|
||||
#pragma pop_macro("forceinline")
|
||||
body_append(result, alias_mappings);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path, bool use_c_definition = false )
|
||||
{
|
||||
char scratch_mem[kilobytes(16)];
|
||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
AllocatorInfo scratch_info = arena_allocator_info(& scratch);
|
||||
FixedArena_64KB scratch; fixed_arena_init(& scratch);
|
||||
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||
|
||||
FileContents enum_content = file_read_contents( scratch_info, file_zero_terminate, etok_path );
|
||||
|
||||
CSV_Object csv_enum_nodes;
|
||||
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
|
||||
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), scratch_info, false );
|
||||
|
||||
FileContents attrib_content = file_read_contents( scratch_info, file_zero_terminate, attr_path );
|
||||
|
||||
CSV_Object csv_attr_nodes;
|
||||
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
|
||||
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), scratch_info, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
|
||||
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_attributes = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_define_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String enum_entries = string_make_reserve( scratch_info, kilobytes(2) );
|
||||
String to_str_entries = string_make_reserve( scratch_info, kilobytes(4) );
|
||||
String attribute_entries = string_make_reserve( scratch_info, kilobytes(2) );
|
||||
String to_str_attributes = string_make_reserve( scratch_info, kilobytes(4) );
|
||||
String attribute_define_entries = string_make_reserve( scratch_info, kilobytes(4) );
|
||||
|
||||
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
||||
{
|
||||
@ -277,14 +374,30 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
||||
|
||||
// We cannot parse this enum, it has Attribute names as enums
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), "attribute_toks", string_to_strc(attribute_entries), stringize(
|
||||
enum TokType_Def : u32
|
||||
{
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
Tok_NumTokens
|
||||
};
|
||||
)));
|
||||
CodeEnum enum_code;
|
||||
if (use_c_definition)
|
||||
{
|
||||
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), "attribute_toks", string_to_strc(attribute_entries), stringize(
|
||||
enum TokType
|
||||
{
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
Tok_NumTokens,
|
||||
Tok_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
)));
|
||||
}
|
||||
else
|
||||
{
|
||||
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), "attribute_toks", string_to_strc(attribute_entries), stringize(
|
||||
enum TokType : u32
|
||||
{
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
Tok_NumTokens
|
||||
};
|
||||
)));
|
||||
}
|
||||
|
||||
#pragma push_macro("local_persist")
|
||||
#pragma push_macro("do_once_start")
|
||||
@ -294,10 +407,10 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
#undef do_once_end
|
||||
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), "attribute_toks", string_to_strc(to_str_attributes), stringize(
|
||||
inline
|
||||
StrC to_str( TokType type )
|
||||
StrC toktype_to_str( TokType type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
StrC lookup[] = {
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
};
|
||||
@ -308,14 +421,14 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
|
||||
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
|
||||
inline
|
||||
TokType to_toktype( StrC str )
|
||||
TokType strc_to_toktype( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ Tok_NumTokens ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (TokType)index );
|
||||
StrC enum_str = toktype_to_str( (TokType)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
@ -338,16 +451,19 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
#pragma pop_macro("do_once_start")
|
||||
#pragma pop_macro("do_once_end")
|
||||
|
||||
//CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
||||
CodeTypedef td_toktype = parse_typedef( code( typedef enum TokType_Def TokType; ));
|
||||
|
||||
return def_global_body( args(
|
||||
attribute_entires_def,
|
||||
enum_code,
|
||||
td_toktype,
|
||||
to_str,
|
||||
to_type
|
||||
));
|
||||
CodeBody result = def_body(CT_Global_Body);
|
||||
body_append(result, untyped_str(txt("GEN_NS_PARSER_BEGIN\n\n")));
|
||||
body_append(result, attribute_entires_def);
|
||||
body_append(result, enum_code);
|
||||
if (use_c_definition)
|
||||
{
|
||||
CodeTypedef td_toktype = parse_typedef( code( typedef enum TokType TokType; ));
|
||||
body_append(result, td_toktype);
|
||||
}
|
||||
body_append(result, to_str);
|
||||
body_append(result, to_type);
|
||||
body_append(result, untyped_str(txt("\nGEN_NS_PARSER_END\n\n")));
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody gen_ast_inlines()
|
||||
@ -365,9 +481,9 @@ CodeBody gen_ast_inlines()
|
||||
inline
|
||||
<typename>& <typename>::operator =( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
{
|
||||
ast = rcast( decltype(ast), GEN_NS duplicate(other).ast);
|
||||
ast = rcast( decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
|
||||
@ -420,7 +536,7 @@ CodeBody gen_ast_inlines()
|
||||
CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", StrC name(CodeNS), code_impl_tmpl ));
|
||||
CodeBody impl_code_op = parse_global_body( token_fmt( "typename", StrC name(CodeOperator), code_impl_tmpl ));
|
||||
CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", StrC name(CodeOpCast), code_impl_tmpl ));
|
||||
CodeBody impl_code_param = parse_global_body( token_fmt( "typename", StrC name(CodeParam), code_impl_tmpl ));
|
||||
CodeBody impl_code_params = parse_global_body( token_fmt( "typename", StrC name(CodeParams), code_impl_tmpl ));
|
||||
CodeBody impl_code_pragma = parse_global_body( token_fmt( "typename", StrC name(CodePragma), code_impl_tmpl ));
|
||||
CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", StrC name(CodePreprocessCond), code_impl_tmpl ));
|
||||
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl ));
|
||||
@ -432,36 +548,39 @@ CodeBody gen_ast_inlines()
|
||||
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl ));
|
||||
CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl ));
|
||||
|
||||
append(impl_code_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
|
||||
append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
|
||||
append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
|
||||
append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
|
||||
append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
|
||||
append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
|
||||
append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
|
||||
append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
|
||||
append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
|
||||
append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
|
||||
append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
|
||||
append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
|
||||
append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
|
||||
append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
|
||||
append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
|
||||
append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
|
||||
append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
|
||||
append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
|
||||
append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Typename), codetype_impl_tmpl )));
|
||||
append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
|
||||
append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
|
||||
append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
|
||||
append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
|
||||
body_append(impl_code_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
|
||||
body_append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
|
||||
body_append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
|
||||
body_append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
|
||||
body_append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
|
||||
body_append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
|
||||
body_append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
|
||||
body_append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
|
||||
body_append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
|
||||
body_append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
|
||||
body_append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
|
||||
body_append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
|
||||
body_append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
|
||||
body_append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
|
||||
body_append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
|
||||
body_append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
|
||||
body_append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
|
||||
body_append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
|
||||
body_append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Typename), codetype_impl_tmpl )));
|
||||
body_append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
|
||||
body_append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
|
||||
body_append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
|
||||
body_append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
|
||||
|
||||
#pragma push_macro("forceinline")
|
||||
#undef forceinline
|
||||
char const* cast_tmpl = stringize(
|
||||
inline Code::operator Code<typename>() const
|
||||
forceinline Code::operator Code<typename>() const
|
||||
{
|
||||
return { (AST_<typename>*) ast };
|
||||
}
|
||||
);
|
||||
#pragma pop_macro("forceinline")
|
||||
|
||||
CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", StrC name(Body), cast_tmpl ));
|
||||
CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", StrC name(Attributes), cast_tmpl ));
|
||||
@ -480,7 +599,7 @@ CodeBody gen_ast_inlines()
|
||||
CodeBody impl_cast_ns = parse_global_body( token_fmt( "typename", StrC name(NS), cast_tmpl ));
|
||||
CodeBody impl_cast_op = parse_global_body( token_fmt( "typename", StrC name(Operator), cast_tmpl ));
|
||||
CodeBody impl_cast_opcast = parse_global_body( token_fmt( "typename", StrC name(OpCast), cast_tmpl ));
|
||||
CodeBody impl_cast_param = parse_global_body( token_fmt( "typename", StrC name(Param), cast_tmpl ));
|
||||
CodeBody impl_cast_params = parse_global_body( token_fmt( "typename", StrC name(Params), cast_tmpl ));
|
||||
CodeBody impl_cast_pragma = parse_global_body( token_fmt( "typename", StrC name(Pragma), cast_tmpl ));
|
||||
CodeBody impl_cast_precond = parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), cast_tmpl ));
|
||||
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl ));
|
||||
@ -513,7 +632,7 @@ CodeBody gen_ast_inlines()
|
||||
impl_code_ns,
|
||||
impl_code_op,
|
||||
impl_code_opcast,
|
||||
impl_code_param,
|
||||
impl_code_params,
|
||||
impl_code_pragma,
|
||||
impl_code_precond,
|
||||
impl_code_specs,
|
||||
@ -528,6 +647,7 @@ CodeBody gen_ast_inlines()
|
||||
def_pragma( txt("endregion generated code inline implementation")),
|
||||
fmt_newline,
|
||||
def_pragma( txt("region generated AST/Code cast implementation")),
|
||||
untyped_str(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN\n")),
|
||||
fmt_newline,
|
||||
impl_cast_body,
|
||||
impl_cast_attribute,
|
||||
@ -546,7 +666,7 @@ CodeBody gen_ast_inlines()
|
||||
impl_cast_ns,
|
||||
impl_cast_op,
|
||||
impl_cast_opcast,
|
||||
impl_cast_param,
|
||||
impl_cast_params,
|
||||
impl_cast_pragma,
|
||||
impl_cast_precond,
|
||||
impl_cast_specs,
|
||||
@ -558,6 +678,7 @@ CodeBody gen_ast_inlines()
|
||||
impl_cast_using,
|
||||
impl_cast_var,
|
||||
fmt_newline,
|
||||
untyped_str(txt("GEN_OPITMIZE_MAPPINGS_END\n")),
|
||||
def_pragma( txt("endregion generated AST/Code cast implementation")),
|
||||
fmt_newline
|
||||
));
|
80
base/helpers/misc.hpp
Normal file
80
base/helpers/misc.hpp
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
# define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define GEN_EXPOSE_BACKEND
|
||||
# include "gen.hpp"
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "helpers/helper.hpp"
|
||||
# include "auxillary/builder.hpp"
|
||||
# include "auxillary/builder.cpp"
|
||||
# include "auxillary/scanner.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace gen;
|
||||
#endif
|
||||
|
||||
// Will format a file with the given style at the provided path.
|
||||
// Assumes clang-format is defined in an user-exposed or system enviornment PATH.
|
||||
void clang_format_file( char const* path, char const* style_path )
|
||||
{
|
||||
GEN_ASSERT_NOT_NULL(path);
|
||||
String resolved_path = string_make_strc(GlobalAllocator, to_strc_from_c_str(path));
|
||||
String style_arg;
|
||||
if (style_path) {
|
||||
style_arg = string_make_strc(GlobalAllocator, txt("-style=file:"));
|
||||
string_append_fmt( & style_arg, "%s ", style_path );
|
||||
}
|
||||
|
||||
StrC clang_format = txt("clang-format ");
|
||||
StrC cf_format_inplace = txt("-i ");
|
||||
StrC cf_verbose = txt("-verbose ");
|
||||
|
||||
String command = string_make_strc( GlobalAllocator, clang_format );
|
||||
string_append_strc( & command, cf_format_inplace );
|
||||
string_append_strc( & command, cf_verbose );
|
||||
string_append_string( & command, style_arg );
|
||||
string_append_string( & command, resolved_path );
|
||||
system( command );
|
||||
}
|
||||
|
||||
// Will refactor a file with the given script at the provided path.
|
||||
// Assumes refactor is defined in an user-exposed or system enviornment PATH.
|
||||
// (See: ./gencpp/scripts/build.ci.ps1 for how)
|
||||
void refactor_file( char const* path, char const* refactor_script )
|
||||
{
|
||||
GEN_ASSERT_NOT_NULL(path);
|
||||
GEN_ASSERT_NOT_NULL(refactor_script);
|
||||
|
||||
String command = string_make_strc(GlobalAllocator, txt("refactor "));
|
||||
// string_append_strc( & command, txt("-debug ") );
|
||||
string_append_strc( & command, txt("-num=1 ") );
|
||||
string_append_fmt( & command, "-src=%s ", path );
|
||||
string_append_fmt( & command,"-spec=%s ", refactor_script );
|
||||
system(command);
|
||||
log_fmt("\n");
|
||||
}
|
||||
|
||||
// Does either of the above or both to the provided code.
|
||||
// Code returned will be untyped content (its be serialized)
|
||||
Code code_refactor_and_format( Code code, char const* scratch_path, char const* refactor_script, char const* clang_format_sytle_path )
|
||||
{
|
||||
GEN_ASSERT(code);
|
||||
GEN_ASSERT_NOT_NULL(scratch_path);
|
||||
Builder scratch_file = builder_open( scratch_path );
|
||||
builder_print( & scratch_file, code);
|
||||
builder_write(& scratch_file);
|
||||
|
||||
if (refactor_script) {
|
||||
refactor_file(scratch_path, refactor_script);
|
||||
}
|
||||
if ( clang_format_sytle_path ) {
|
||||
clang_format_file(scratch_path, clang_format_sytle_path);
|
||||
}
|
||||
|
||||
Code result = scan_file( scratch_path );
|
||||
::remove(scratch_path);
|
||||
return result;
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
# pragma clang diagnostic ignored "-Wunused-function"
|
||||
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
||||
# pragma clang diagnostic ignored "-W#pragma-messages"
|
||||
# pragma clang diagnostic ignored "-Wstatic-in-inline"
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
203
base/helpers/undef.macros.h
Normal file
203
base/helpers/undef.macros.h
Normal file
@ -0,0 +1,203 @@
|
||||
// This undefines the macros used by the gen library
|
||||
#undef GEN_TIME
|
||||
|
||||
#undef GEN_ARCH_64_BIT
|
||||
#undef GEN_ARCH_32_BIT
|
||||
|
||||
#undef GEN_SYSTEM_ANDROID
|
||||
#undef GEN_SYSTEM_CYGWIN
|
||||
#undef GEN_SYSTEM_EMSCRIPTEN
|
||||
#undef GEN_SYSTEM_FREEBSD
|
||||
#undef GEN_SYSTEM_IOS
|
||||
#undef GEN_SYSTEM_LINUX
|
||||
#undef GEN_SYSTEM_MACOS
|
||||
#undef GEN_SYSTEM_OPENBSD
|
||||
#undef GEN_SYSTEM_OSX
|
||||
#undef GEN_SYSTEM_UNIX
|
||||
#undef GEN_SYSTEM_WINDOWS
|
||||
|
||||
#undef GEN_COMPILER_CLANG
|
||||
#undef GEN_COMPILER_GCC
|
||||
#undef GEN_COMPILER_MSVC
|
||||
|
||||
#undef GEN_HAS_ATTRIBUTE
|
||||
|
||||
#undef GEN_COMPILER_C
|
||||
#undef GEN_COMPILER_CPP
|
||||
|
||||
#undef GEN_DONT_USE_NAMESPACE
|
||||
#undef GEN_NS_PARSER_BEGIN
|
||||
#undef GEN_NS_PARSER_END
|
||||
#undef GEN_USING_NS_PARSER
|
||||
#undef GEN_NS_PARSER
|
||||
#undef GEN_NS
|
||||
#undef GEN_NS_BEGIN
|
||||
#undef GEN_NS_END
|
||||
|
||||
#undef GEN_C_LIKE_CPP
|
||||
|
||||
#undef global
|
||||
#undef internal
|
||||
#undef local_persist
|
||||
|
||||
#undef bit
|
||||
#undef bitfield_is_equal
|
||||
|
||||
#undef cast
|
||||
|
||||
#undef ccast
|
||||
#undef scast
|
||||
#undef rcast
|
||||
#undef pcast
|
||||
|
||||
#undef stringize
|
||||
#undef do_once
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
#undef labeled_scope_start
|
||||
#undef labeled_scope_end
|
||||
#undef compiler_decorated_func_name
|
||||
#undef num_args_impl
|
||||
#undef num_args
|
||||
#undef clamp
|
||||
#undef count_of
|
||||
#undef is_between
|
||||
#undef size_of
|
||||
#undef max
|
||||
#undef min
|
||||
#undef offset_of
|
||||
#undef forceinline
|
||||
#undef neverinline
|
||||
#undef static_assert
|
||||
#undef thread_local
|
||||
#undef typeof
|
||||
|
||||
#undef GEN_API_C_BEGIN
|
||||
#undef GEN_API_C_END
|
||||
|
||||
#undef enum_underlying
|
||||
#undef nullptr
|
||||
#undef GEN_PARAM_DEFAULT
|
||||
#undef struct_init
|
||||
|
||||
#undef GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||
#undef GEN_OPITMIZE_MAPPINGS_END
|
||||
|
||||
#undef GEN_U8_MIN
|
||||
#undef GEN_U8_MAX
|
||||
#undef GEN_I8_MIN
|
||||
#undef GEN_I8_MAX
|
||||
#undef GEN_U16_MIN
|
||||
#undef GEN_U16_MAX
|
||||
#undef GEN_I16_MIN
|
||||
#undef GEN_I16_MAX
|
||||
#undef GEN_U32_MIN
|
||||
#undef GEN_U32_MAX
|
||||
#undef GEN_I32_MIN
|
||||
#undef GEN_I32_MAX
|
||||
#undef GEN_U64_MIN
|
||||
#undef GEN_U64_MAX
|
||||
#undef GEN_I64_MIN
|
||||
#undef GEN_I64_MAX
|
||||
#undef GEN_USIZE_MIN
|
||||
#undef GEN_USIZE_MAX
|
||||
#undef GEN_ISIZE_MIN
|
||||
#undef GEN_ISIZE_MAX
|
||||
#undef GEN_USIZE_MIN
|
||||
#undef GEN_USIZE_MAX
|
||||
#undef GEN_ISIZE_MIN
|
||||
#undef GEN_ISIZE_MAX
|
||||
#undef GEN_F32_MIN
|
||||
#undef GEN_F32_MAX
|
||||
#undef GEN_F64_MIN
|
||||
#undef GEN_F64_MAX
|
||||
|
||||
#undef to_uptr
|
||||
#undef to_sptr
|
||||
#undef to_mem_ptr
|
||||
#undef to_mem_ptr_const
|
||||
|
||||
#undef kilobytes
|
||||
#undef megabytes
|
||||
#undef gigabytes
|
||||
#undef terabytes
|
||||
|
||||
#undef GEN__ONES
|
||||
#undef GEN__HIGHS
|
||||
#undef GEN__HAS_ZERO
|
||||
#undef GEN_DEFAULT_MEMORY_ALIGNMENT
|
||||
#undef GEN_DEFAULT_ALLOCATOR_FLAGS
|
||||
|
||||
#undef zero_item
|
||||
#undef zero_array
|
||||
|
||||
#undef alloc_item
|
||||
#undef alloc_array
|
||||
|
||||
#undef malloc
|
||||
#undef mfree
|
||||
|
||||
#undef GEN_DEBUG_TRAP
|
||||
#undef GEN_ASSERT
|
||||
#undef GEN_ASSERT_MSG
|
||||
#undef GEN_ASSERT_NOT_NULL
|
||||
#undef GEN_PANIC
|
||||
#undef GEN_FATAL
|
||||
|
||||
#undef GEN_FILE_OPEN_PROC
|
||||
#undef GEN_FILE_READ_AT_PROC
|
||||
#undef GEN_FILE_WRITE_AT_PROC
|
||||
#undef GEN_FILE_SEEK_PROC
|
||||
#undef GEN_FILE_CLOSE_PROC
|
||||
|
||||
#undef GEN_PRINTF_MAXLEN
|
||||
|
||||
#undef _strlen
|
||||
#undef _printf_err
|
||||
#undef _printf_err_va
|
||||
#undef _strlen
|
||||
#undef _printf_err
|
||||
#undef _printf_err_va
|
||||
|
||||
#undef Array
|
||||
#undef get_array_underlying_type
|
||||
#undef HashTable
|
||||
#undef get_hashtable_underlying_type
|
||||
|
||||
#undef txt
|
||||
|
||||
#undef NOMINMAX
|
||||
#undef VC_EXTRALEAN
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
#undef WIN32_MEAN_AND_LEAN
|
||||
|
||||
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||
|
||||
#undef GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
#undef GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
|
||||
#undef GEN_GLOBAL_BUCKET_SIZE
|
||||
#undef GEN_CODEPOOL_NUM_BLOCKS
|
||||
#undef GEN_SIZE_PER_STRING_ARENA
|
||||
#undef GEN_MAX_COMMENT_LINE_LENGTH
|
||||
#undef GEN_MAX_NAME_LENGTH
|
||||
#undef GEN_MAX_UNTYPED_STR_LENGTH
|
||||
#undef TokenMap_FixedArena
|
||||
#undef GEN_LEX_ALLOCATOR_SIZE
|
||||
#undef GEN_BUILDER_STR_BUFFER_RESERVE
|
||||
|
||||
#undef log_failure
|
||||
|
||||
#undef gen_main
|
||||
#undef name
|
||||
#undef code
|
||||
#undef args
|
||||
#undef code_str
|
||||
#undef code_fmt
|
||||
#undef token_fmt
|
||||
#undef parse_fmt
|
||||
#undef token_fmt
|
@ -1,44 +1,58 @@
|
||||
## Navigation
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
<- [docs - General](Readme.md)
|
||||
|
||||
## Current Design
|
||||
|
||||
`AST` is the actual managed node object for the library.
|
||||
Its raw and really not meant to be used directly.
|
||||
|
||||
All user interaction must be with its pointer so the type they deal with is `AST*`.
|
||||
For user-facing code, they should never be giveen a nullptr. Instead, they should be given a designated `Invalid` AST node.
|
||||
In order to abstract away constant use of `AST*` its wrapped in a Code type which can be either:
|
||||
|
||||
In order to abstract away constant use of `AST*`, I wanted to provide a wrapper for it.
|
||||
|
||||
The simpliest being just a type alias.
|
||||
|
||||
```cpp
|
||||
using Code = AST*;
|
||||
When its the [C generated variant of the library](../gen_c_library/)
|
||||
```c
|
||||
typedef AST* Code;
|
||||
tyepdef AST_<name>* Code<name>;
|
||||
...
|
||||
```
|
||||
|
||||
This is what the genc library would have to use due to its constraints of a langauge.
|
||||
The actual content per type of AST is covered within [AST_Types.md](AST_Types.md).
|
||||
|
||||
These are pure PODS that just have the lay members relevant to the type of AST node they represent.
|
||||
Each of them has a Code type alias specific to it.
|
||||
|
||||
Again, the simpliest case for these would be a type alias.
|
||||
**or**
|
||||
|
||||
For C++:
|
||||
```cpp
|
||||
using struct AST_Typedef CodeTypedef;
|
||||
struct Code {
|
||||
AST* ast;
|
||||
};
|
||||
struct Code<name> {
|
||||
...
|
||||
|
||||
AST_<name>* ast;
|
||||
};
|
||||
```
|
||||
|
||||
As of November 21st, 2023, the AST has had a strict layout for how its content is laid out.
|
||||
This will be abandoned during its redesign that will occur starting with support for statments & expressions for either execution and type declarations.
|
||||
Having a strict layout is too resctrictive vs allowing each AST type to have maximum control over the layout.
|
||||
The full definitions of all asts are within:
|
||||
|
||||
The redesign will occur after the following todos are addressed:
|
||||
* [`ast.hpp`](../base/components/ast.hpp)
|
||||
* [`ast_types.hpp`](../base/components/ast_types.hpp)
|
||||
* [`code_types.hpp`](../base/components/ast_types.hpp)
|
||||
|
||||
* [Improvements Lexer & Token struct#27](https://github.com/Ed94/gencpp/issues/27)
|
||||
* [Generalize AST Flags to a single 4-byte flag#42](https://github.com/Ed94/gencpp/issues/42)
|
||||
* [AST-Code Object Redesign.#38](https://github.com/Ed94/gencpp/issues/38)
|
||||
* [Code-AST Documentation#40](https://github.com/Ed94/gencpp/issues/40)
|
||||
* [AST::debug_str() improvements#33](https://github.com/Ed94/gencpp/issues/33)
|
||||
* [AST::is_equal implemented and works with singleheader-test#31](https://github.com/Ed94/gencpp/issues/31)
|
||||
* [Parser : Add ability to have a parse failure and continue with errors recorded.#35](https://github.com/Ed94/gencpp/issues/35)
|
||||
* [Scanner : Add CodeFile#29](https://github.com/Ed94/gencpp/issues/29)
|
||||
* [Auxiliary : AST visual debugger#36](https://github.com/Ed94/gencpp/issues/36)
|
||||
The C/C++ interface procedures are located with `ast.hpp` (for the Code type), and `code_types.hpp` for all others.
|
||||
|
||||
## Serialization
|
||||
|
||||
All code types can either serialize using a function of the pattern:
|
||||
|
||||
```c
|
||||
String <prefix>_to_string(Code code);
|
||||
// or
|
||||
<prefix>_to_string(Code code, String& result);
|
||||
```
|
||||
|
||||
Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator.
|
||||
|
||||
Serialization of for the AST is defined for `Code` in [`ast.chpp`](../base/components/ast.cpp) with `code_to_string_ptr` & `code_to_string`.
|
||||
Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp).
|
||||
Gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after serializing.
|
||||
|
@ -1,10 +1,16 @@
|
||||
## Navigation
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
<- [docs - General](Readme.md)
|
||||
|
||||
# AST Types Documentation
|
||||
|
||||
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
|
||||
|
||||
## Body
|
||||
|
||||
These are containers representing a scope body of a definition that can be of the following `ECode` type:
|
||||
These are containers representing a scope body of a definition that can be of the following `CodeType` type:
|
||||
|
||||
* Class_Body
|
||||
* Enum_Body
|
||||
@ -19,11 +25,11 @@ These are containers representing a scope body of a definition that can be of th
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
@ -31,14 +37,15 @@ s32 NumEntries;
|
||||
The `Front` member represents the start of the link list and `Back` the end.
|
||||
NumEntries is the number of entries in the body.
|
||||
|
||||
Parent should have a compatible ECode type for the type of defintion used.
|
||||
Parent should have a compatible CodeType type for the type of defintion used.
|
||||
|
||||
Serialization:
|
||||
|
||||
Will output only the entries, the braces are handled by the parent.
|
||||
|
||||
```cpp
|
||||
<Front>...
|
||||
<Front>
|
||||
...
|
||||
<Back>
|
||||
```
|
||||
|
||||
@ -50,11 +57,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -74,11 +81,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -102,11 +109,11 @@ CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
CodeType ParentType;
|
||||
CodeBody Body;
|
||||
CodeType Prev; // Used to store references to interfaces
|
||||
CodeType Next; // Used to store references to interfaces
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeType Prev;
|
||||
CodeType Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
@ -125,7 +132,7 @@ Serialization:
|
||||
};
|
||||
```
|
||||
|
||||
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest must be done through interfaces.
|
||||
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest are assumed to be interfaces and are given public acess specifiers.
|
||||
|
||||
## Constructor
|
||||
|
||||
@ -134,13 +141,13 @@ Fields:
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -172,11 +179,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -194,11 +201,11 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
Code Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -229,24 +236,28 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
Code UnderlyingTypeMacro;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
UnderlyingTypeMacro is a macro the library natively supports: `enum_underlying(type)` that is meant to behave as a wrapper for underlying type assignment.
|
||||
The `enum_underlying_sig` is a `StrC` global var that can be set which will be defined within `PreprocessorDefines` and used in `parser_parse_enum` to identify a valid macro.
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Enum_Fwd
|
||||
<ModuleFlags> enum class <Name> : <UnderlyingType>; <InlineCmt>
|
||||
<ModuleFlags> enum class <Name> : <UnderlyingType> or <UnderlyingTypeMacro> ; <InlineCmt>
|
||||
|
||||
// Enum
|
||||
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType>
|
||||
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType> or <UnderlyingTypeMacro>
|
||||
{
|
||||
<Body>
|
||||
};
|
||||
@ -261,11 +272,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -281,11 +292,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -304,11 +315,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
parser::Token* Tok;
|
||||
StringCached Name;
|
||||
Token* Tok;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -327,11 +338,11 @@ Fields:
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code Declaration;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -350,13 +361,13 @@ CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -379,11 +390,11 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -400,11 +411,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -418,7 +429,7 @@ Serialization:
|
||||
}
|
||||
```
|
||||
|
||||
## Operator Overload
|
||||
## Operator Overload (Operator)
|
||||
|
||||
Fields:
|
||||
|
||||
@ -427,13 +438,13 @@ CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
OperatorT Op;
|
||||
@ -452,7 +463,7 @@ Serialization:
|
||||
}
|
||||
```
|
||||
|
||||
## Operator Cast Overload ( User-Defined Type Conversion )
|
||||
## Operator Cast Overload ( User-Defined Type Conversion, OpCast )
|
||||
|
||||
Fields:
|
||||
|
||||
@ -461,11 +472,11 @@ CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -482,7 +493,7 @@ Serialization:
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters (AST_Param)
|
||||
## Parameters (AST_Params)
|
||||
|
||||
Fields:
|
||||
|
||||
@ -490,11 +501,12 @@ Fields:
|
||||
CodeType ValueType;
|
||||
Code Macro;
|
||||
Code Value;
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
Code PostNameMacro;
|
||||
StringCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
@ -504,7 +516,7 @@ Serialization:
|
||||
```cpp
|
||||
<Macro>, <Next> ... <Last>
|
||||
|
||||
<Macro> <ValueType> <Name>, <Next>... <Last>
|
||||
<Macro> <ValueType> <Name> <PostNameMacro> = <Value>, <Next>... <Last>
|
||||
```
|
||||
|
||||
## Pragma
|
||||
@ -513,11 +525,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -533,11 +545,11 @@ Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
paser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
@ -554,11 +566,11 @@ Fields:
|
||||
```cpp
|
||||
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
CodeSpecifiers NextSpecs;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
@ -574,13 +586,13 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -603,23 +615,30 @@ Fields:
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeReturnType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeParams Params;
|
||||
Code ArrExpr;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
b32 IsParamPack;
|
||||
ETypenameTag TypeTag;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Attributes> <Name> <Specs> <IsParamPack ?: ...>
|
||||
<Attributes> <TypeTag> <Name> <Specs> <IsParamPack ?: ...>
|
||||
// Function
|
||||
<Attributes> <ReturnType> <Name> <Params> <Specs>
|
||||
```
|
||||
|
||||
`<Name>` currently has the full serialization of anything with
|
||||
|
||||
*Note: ArrExpr is not used in serialization by `typename_to_string_ref` its instead handled by a parent AST's serailization (variable, typedef, using).*
|
||||
|
||||
## Typedef
|
||||
|
||||
Behave as usual except function or macro typedefs.
|
||||
@ -630,11 +649,11 @@ Fields:
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code UnderlyingType;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parse::Token* Tok
|
||||
Token* Tok
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
@ -644,11 +663,16 @@ Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
|
||||
<ModuleFlags> typedef <UnderlyingType> <Name> <UnderlyingType-ArrExpr>; <InlineCmt>
|
||||
|
||||
// Functions
|
||||
<ModuleFlags> typedef <ReturnType> <Name>( <Parameters> ); <InlineCmt>
|
||||
<ModuleFlags> typedef <ReturnType> ( <Expression that yeilds an Identifier signature> )( <Parameters> ); <InlineCmt>
|
||||
|
||||
// Currently:
|
||||
<ModuleFlags> typedef <UnderlyingType (Serialized expression)>; <InlineCmt>
|
||||
|
||||
// Desired: Not handled yet
|
||||
<ModuleFlags> typedef <UnderlyingType->ReturnType> UnderlyingType->Name> <UnderlyingType-ArrExpr> ( <UnderlyingType->Parameters> ); <InlineCmt>
|
||||
<ModuleFlags> typedef <UnderlyingType->ReturnType> ( <Name->Namespace> for<Specs->has(Spec_Ptr) ?: *> <UnderlyingType->Name> <UnderlyingType-ArrExpr> ) ( <UnderlyingType->Parameters> ); <InlineCmt>
|
||||
```
|
||||
|
||||
## Union
|
||||
@ -658,11 +682,11 @@ Fields:
|
||||
```cpp
|
||||
CodeAttributes Attributes;
|
||||
CodeBody Body;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -684,11 +708,11 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
StringCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
@ -716,14 +740,15 @@ CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
StringCached Name;
|
||||
CodeVar NextVar;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarParenthesizedInit;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -734,4 +759,7 @@ Serialization:
|
||||
|
||||
// Bitfield
|
||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>, NextVar ...; <InlineCmt>
|
||||
|
||||
// VarParenthesizedInit
|
||||
<Attributes> <Specs> <ValueType> <Name>( <Value>, NextVar ... ); <InlineCmt>
|
||||
```
|
||||
|
@ -1,3 +1,9 @@
|
||||
## Navigation
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
<- [docs - General](Readme.md)
|
||||
|
||||
# Parser's Algorithim
|
||||
|
||||
gencpp uses a hand-written recursive descent parser. Both the lexer and parser currently handle a full C/C++ file in a single pass.
|
||||
@ -7,7 +13,7 @@ gencpp uses a hand-written recursive descent parser. Both the lexer and parser c
|
||||
### Lexer
|
||||
|
||||
The lex procedure does the lexical pass of content provided as a `StrC` type.
|
||||
The tokens are stored (for now) in `gen::parser::Tokens`.
|
||||
The tokens are stored (for now) in `gen::parser::Lexer_Tokens`.
|
||||
|
||||
Fields:
|
||||
|
||||
@ -16,7 +22,7 @@ Array<Token> Arr;
|
||||
s32 Idx;
|
||||
```
|
||||
|
||||
What token types are supported can be found in [ETokType.csv](../project/enums/ETokType.csv) you can also find the token types in [ETokType.h](../project/components/gen/etoktype.cpp) , which is the generated enum from the csv file.
|
||||
What token types are supported can be found in [ETokType.csv](../base/enums/ETokType.csv) you can also find the token types in [ETokType.h](../base/components/gen/etoktype.cpp) , which is the generated enum from the csv file.
|
||||
|
||||
Tokens are defined with the struct `gen::parser::Token`:
|
||||
|
||||
|
@ -1,10 +1,16 @@
|
||||
## Navigation
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
<- [docs - General](Readme.md)
|
||||
|
||||
# Parsing
|
||||
|
||||
The library features a naive parser tailored for only what the library needs to construct the supported syntax of C++ into its AST.
|
||||
The library features a naive single-pass parser tailored for only what the library needs to construct the supported syntax of C++ into its AST for *"front-end"* meta-programming purposes.
|
||||
|
||||
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept (so far) around ~5600 loc. I hope to keep it under 10k loc worst case.
|
||||
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept (so far) around ~7000 loc. I hope to keep it under 10k loc worst case.
|
||||
|
||||
You can think of this parser of a frontend parser vs a semantic parser. Its intuitively similar to WYSIWYG. What you precerive as the syntax from the user-side before the compiler gets a hold of it, is what you get.
|
||||
You can think of this parser as *frontend parser* vs a *semantic parser*. Its intuitively similar to WYSIWYG. What you ***precerive*** as the syntax from the user-side before the compiler gets a hold of it, is what you get.
|
||||
|
||||
User exposed interface:
|
||||
|
||||
@ -47,10 +53,11 @@ The keywords supported for the preprocessor are:
|
||||
* endif
|
||||
* pragma
|
||||
|
||||
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST. *These ASTs will be considered members or entries of braced scope they reside within*.
|
||||
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST.
|
||||
If a directive is used with an unsupported keyword its will be processed as an untyped AST.
|
||||
|
||||
The preprocessor lines are stored as members of their associated scope they are parsed within. ( Global, Namespace, Class/Struct )
|
||||
The preprocessor lines are stored as members of their associated scope they are parsed within. ( Global, Namespace, Class/Struct )
|
||||
***Again (Its not standard): These ASTs will be considered members or entries of braced scope they reside within***
|
||||
|
||||
Any preprocessor definition abuse that changes the syntax of the core language is unsupported and will fail to parse if not kept within an execution scope (function body, or expression assignment).
|
||||
Exceptions:
|
||||
@ -59,6 +66,8 @@ Exceptions:
|
||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
|
||||
* typedefs allow for a preprocessed macro: `typedef MACRO();`
|
||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_TYPEDEF`
|
||||
* Macros can behave as typenames
|
||||
* There is some macro support in paramters for functions or templates *(Specifically added to support parsing Unreal Engine source)*.
|
||||
|
||||
*(Exceptions are added on an on-demand basis)*
|
||||
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
|
||||
@ -67,15 +76,23 @@ Adding your own exceptions is possible by simply modifying the parser to allow f
|
||||
|
||||
*Note: You could interpret this strictness as a feature. This would allow the user to see if their codebase or a third-party's codebase some some egregious preprocessor abuse.*
|
||||
|
||||
If a macro is not defined withint e scope of parsing a set of files, it can be defined beforehand by:
|
||||
|
||||
* Appending the [`PreprocessorDefines`](https://github.com/Ed94/gencpp/blob/a18b5b97aa5cfd20242065cbf53462a623cd18fa/base/components/header_end.hpp#L137) array.
|
||||
* For functional macros a "(" just needs to be added after the name like: `<name>(` so that it will tokenize its arguments as part of the token during lexing.
|
||||
* Defining a CodeDefine using `def_define`. The definition will be processed by the interface for user into `PreprocessorDefines`.
|
||||
* This can be prevented by setting the optional prameter `dont_append_preprocess_defines`.
|
||||
|
||||
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
|
||||
* Numeric literals are not checked for validity.
|
||||
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
||||
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs. (There is a [todo](https://github.com/Ed94/gencpp/issues/49) to add support)
|
||||
* *This includes the assignment of variables.*
|
||||
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
|
||||
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function or right afterthe return type.
|
||||
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
|
||||
* typedefs have attributes with the type (`parse_type`)
|
||||
* Parsing attributes can be extended to support user defined macros by defining `GEN_DEFINE_ATTRIBUTE_TOKENS` (see `gen.hpp` for the formatting)
|
||||
* This is useful for example: parsing Unreal `Module_API` macros.
|
||||
|
||||
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.
|
||||
|
194
docs/Readme.md
194
docs/Readme.md
@ -1,64 +1,42 @@
|
||||
## Documentation
|
||||
# General Docs
|
||||
|
||||
The project has no external dependencies beyond:
|
||||
[Top](../Readme.md)
|
||||
|
||||
* `errno.h`
|
||||
* `stat.h`
|
||||
* `stdarg.h`
|
||||
* `stddef.h`
|
||||
* `stdio.h`
|
||||
* `copyfile.h` (Mac)
|
||||
* `types.h` (Linux)
|
||||
* `unistd.h` (Linux/Mac)
|
||||
* `intrin.h` (Windows)
|
||||
* `io.h` (Windows with gcc)
|
||||
* `windows.h` (Windows)
|
||||
Contains:
|
||||
|
||||
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
|
||||
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
|
||||
* [AST_Design](./AST_Design.md): Overvie of ASTs
|
||||
* [AST Types](./AST_Types.md): Listing of all AST types along with their Code type interface.
|
||||
* [Parsing](./Parsing.md): Overview of the parsing interface.
|
||||
* [Parser Algo](./Parser_Algo.md): In-depth breakdown of the parser's implementation.
|
||||
|
||||
This library was written in a subset of C++ where the following are not used at all:
|
||||
|
||||
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
|
||||
* Language provide dynamic dispatch, RTTI
|
||||
* Object-Oriented Inheritance
|
||||
* Exceptions
|
||||
|
||||
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
|
||||
The base library itself does not use anything but C-like features to allow for generating a derviative compatiable with C (WIP).
|
||||
|
||||
There are only 4 template definitions in the entire library. (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `AST/Code::cast<Type>`)
|
||||
|
||||
Two generic templated containers are used throughout the library:
|
||||
|
||||
* `template< class Type> struct Array`
|
||||
* `template< class Type> struct HashTable`
|
||||
|
||||
Both Code and AST definitions have a `template< class Type> Code/AST :: cast()`. Its just an alternative way to explicitly cast to each other.
|
||||
|
||||
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
|
||||
|
||||
Otherwise the library is free of any templates.
|
||||
|
||||
### *WHAT IS NOT PROVIDED*
|
||||
### *CURRENTLY UNSUPPORTED*
|
||||
|
||||
**There is no support for validating expressions.**
|
||||
Its difficult to parse without enough benefits (At the metaprogramming level).
|
||||
I plan to add this only at the tail of the project parsing milestone.
|
||||
Its a [todo](https://github.com/Ed94/gencpp/issues/49)
|
||||
|
||||
**Only trivial template support is provided.**
|
||||
The intention is for only simple, non-recursive substitution.
|
||||
The parameters of the template are treated like regular parameter AST entries.
|
||||
**Only trivial template support is provided.**
|
||||
The intention is for only simple, non-recursive substitution.
|
||||
The parameters of the template are treated like regular parameter AST entries.
|
||||
This means that the typename entry for the parameter AST would be either:
|
||||
|
||||
* `class`
|
||||
* `typename`
|
||||
* A fundamental type, function, or pointer type.
|
||||
|
||||
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
|
||||
Use at your own mental peril.
|
||||
***Concepts and Constraints are not supported***
|
||||
Its a [todo](https://github.com/Ed94/gencpp/issues/21)
|
||||
|
||||
*Concepts and Constraints are not supported, its usage is non-trivial substitution.*
|
||||
### Feature Macros:
|
||||
|
||||
* `GEN_DEFINE_ATTRIBUTE_TOKENS` : Allows user to define their own attribute macros for use in parsing.
|
||||
* This can be generated using base.cpp.
|
||||
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
|
||||
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
|
||||
* `GEN_ENFORCE_STRONG_CODE_TYPES` : Enforces casts to filtered code types.
|
||||
* `GEN_EXPOSE_BACKEND` : Will expose symbols meant for internal use only.
|
||||
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
|
||||
* `GEN_DONT_ALLOW_INVALID_CODE` (Not implemented yet) : Will fail when an invalid code is constructed, parsed, or serialized.
|
||||
* `GEN_C_LIKE_PP` : Setting to `<true or 1>` Will prevent usage of function defnitions using references and structs with member functions. Structs will still have user-defined operator conversions, for-range support, and other operator overloads
|
||||
|
||||
### The Data & Interface
|
||||
|
||||
@ -67,87 +45,33 @@ As mentioned in root readme, the user is provided Code objects by calling the co
|
||||
The AST is managed by the library and provided to the user via its interface.
|
||||
However, the user may specifiy memory configuration.
|
||||
|
||||
Data layout of AST struct (Subject to heavily change with upcoming redesign):
|
||||
[Data layout of AST struct (Subject to heavily change with upcoming todos)](../base/components/ast.hpp#L396-461)
|
||||
|
||||
```cpp
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Macro; // Parameters
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
|
||||
```
|
||||
https://github.com/Ed94/gencpp/blob/eea4ebf5c40d5d87baa465abfb1be30845b2377e/base/components/ast.hpp#L396-L461
|
||||
|
||||
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
|
||||
*`CodeType` is enum taggin the type of code. Has an underlying type of `u32`*
|
||||
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
|
||||
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
|
||||
*`String` is the dynamically allocated string type for the library*
|
||||
*`String` is the dynamically allocated string type for the library*
|
||||
|
||||
AST widths are setup to be AST_POD_Size.
|
||||
AST widths are setup to be AST_POD_Size.
|
||||
The width dictates how much the static array can hold before it must give way to using an allocated array:
|
||||
|
||||
```cpp
|
||||
constexpr static
|
||||
usize ArrSpecs_Cap =
|
||||
int AST_ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(Code)
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(Code) * 2
|
||||
- sizeof(Token*)
|
||||
- sizeof(Code)
|
||||
- sizeof(CodeType)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(u32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
|
||||
/ sizeof(Specifier) - 1;
|
||||
```
|
||||
|
||||
*Ex: If the AST_POD_Size is 128 the capacity of the static array is 20.*
|
||||
@ -156,7 +80,7 @@ Data Notes:
|
||||
|
||||
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
||||
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_string_allocator`, `get_cached_string`, `make_code`.
|
||||
* Allocators are defined with the `AllocatorInfo` structure found in `dependencies\memory.hpp`
|
||||
* Allocators are defined with the `AllocatorInfo` structure found in [`memory.hpp`](../base/dependencies/memory.hpp)
|
||||
* Most of the work is just defining the allocation procedure:
|
||||
|
||||
```cpp
|
||||
@ -164,30 +88,30 @@ Data Notes:
|
||||
```
|
||||
|
||||
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
|
||||
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
||||
* Code types have member symbols but their data layout is enforced to be POD types.
|
||||
* This library treats memory failures as fatal.
|
||||
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
|
||||
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
|
||||
* Strings used for serialization and file buffers are not contained by those used for cached strings.
|
||||
* They are currently using `GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
|
||||
* Memory within the buckets is not reused, so its inherently wasteful.
|
||||
* I will be augmenting the single arena with a simple slag allocator.
|
||||
* Linked lists used children nodes on bodies, and parameters.
|
||||
* I will be augmenting the default allocator with virtual memory & a slab allocator in the [future](https://github.com/Ed94/gencpp/issues/12)
|
||||
* Intrusive linked lists used children nodes on bodies, and parameters.
|
||||
* Its intended to generate the AST in one go and serialize after. The constructors and serializer are designed to be a "one pass, front to back" setup.
|
||||
* Allocations can be tuned by defining the folloiwng macros:
|
||||
* Allocations can be tuned by defining the folloiwng macros (will be moved to runtime configuration in the future):
|
||||
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
|
||||
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
|
||||
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
|
||||
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
|
||||
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
||||
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
|
||||
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
|
||||
* `TokenMap_FixedArena` : token_fmt_va uses local_persit memory of this arena type for the hashtable.
|
||||
* `GEN_LEX_ALLOCATOR_SIZE`
|
||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
||||
|
||||
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
|
||||
|
||||
* CodeBody : Has support for `for-range` iterating across Code objects.
|
||||
* CodeBody : Has support for `for : range` iterating across Code objects.
|
||||
* CodeAttributes
|
||||
* CodeComment
|
||||
* CodeClass
|
||||
@ -204,13 +128,13 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeNS
|
||||
* CodeOperator
|
||||
* CodeOpCast
|
||||
* CodeParam : Has support for `for-range` iterating across parameters.
|
||||
* CodeParams : Has support for `for : range` iterating across parameters.
|
||||
* CodePreprocessCond
|
||||
* CodePragma
|
||||
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
|
||||
* CodeSpecifiers : Has support for `for : range` iterating across specifiers.
|
||||
* CodeStruct
|
||||
* CodeTemplate
|
||||
* CodeType
|
||||
* CodeTypename
|
||||
* CodeTypedef
|
||||
* CodeUnion
|
||||
* CodeUsing
|
||||
@ -295,6 +219,7 @@ Code <name>
|
||||
```
|
||||
|
||||
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
|
||||
|
||||
```cpp
|
||||
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||
|
||||
@ -302,7 +227,7 @@ def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||
def_global_body( 3, ht_entry, array_ht_entry, hashtable );
|
||||
```
|
||||
|
||||
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
|
||||
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
|
||||
When the members have been populated use: `AST::validate_body` to verify that the members are valid entires for that type.
|
||||
|
||||
### Parse construction
|
||||
@ -354,7 +279,7 @@ Interface :
|
||||
* untyped_fmt
|
||||
* untyped_token_fmt
|
||||
|
||||
During serialization any untyped Code AST has its string value directly injected inline of whatever context the content existed as an entry within.
|
||||
During serialization any untyped Code AST has its string value directly injected inline of whatever context the content existed as an entry within.
|
||||
Even though these are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that Untyped code can be added as any component of a Code AST:
|
||||
|
||||
* Untyped code cannot have children, thus there cannot be recursive injection this way.
|
||||
@ -375,6 +300,7 @@ Code <name> = untyped_str( code(
|
||||
```
|
||||
|
||||
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
|
||||
|
||||
```cpp
|
||||
Code <name> = code_str( <some code without "" quotes > )
|
||||
```
|
||||
@ -404,8 +330,8 @@ The following are provided predefined by the library as they are commonly used:
|
||||
* `module_global_fragment`
|
||||
* `module_private_fragment`
|
||||
* `fmt_newline`
|
||||
* `param_varaidc` (Used for varadic definitions)
|
||||
* `pragma_once`
|
||||
* `param_varaidc` (Used for varadic definitions)
|
||||
* `preprocess_else`
|
||||
* `preprocess_endif`
|
||||
* `spec_const`
|
||||
@ -421,6 +347,7 @@ The following are provided predefined by the library as they are commonly used:
|
||||
* `spec_local_persist` (local_persist macro)
|
||||
* `spec_mutable`
|
||||
* `spec_neverinline`
|
||||
* `spec_noexcept`
|
||||
* `spec_override`
|
||||
* `spec_ptr`
|
||||
* `spec_pure`
|
||||
@ -452,8 +379,8 @@ Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` i
|
||||
* `t_u16`
|
||||
* `t_u32`
|
||||
* `t_u64`
|
||||
* `t_sw` (ssize_t)
|
||||
* `t_uw` (size_t)
|
||||
* `t_ssize` (ssize_t)
|
||||
* `t_usize` (size_t)
|
||||
* `t_f32`
|
||||
* `t_f64`
|
||||
|
||||
@ -471,14 +398,11 @@ and have the desired specifiers assigned to them beforehand.
|
||||
|
||||
## Code generation and modification
|
||||
|
||||
There are three provided auxillary interfaces:
|
||||
There are two provided auxillary interfaces:
|
||||
|
||||
* Builder
|
||||
* Editor
|
||||
* Scanner
|
||||
|
||||
Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FEATURE_SCANNER` to enable them.
|
||||
|
||||
### Builder is a similar object to the jai language's string_builder
|
||||
|
||||
* The purpose of it is to generate a file.
|
||||
@ -488,4 +412,8 @@ Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FE
|
||||
|
||||
### Scanner Auxillary Interface
|
||||
|
||||
Provides *(eventually)* `scan_file` to automatically populate a CodeFile which contains a parsed AST (`Code`) of the file, with any contextual failures that are reported from the parser.
|
||||
* The purpose is to scan or parse files
|
||||
* Some with two basic functions to convert a fil to code: `scan_file` and `parse_file`
|
||||
* `scan_file`: Merely grabs the file and stores it in an untyped Code.
|
||||
* `parse_file`: Will parse the file using `parse_global_body` and return a `CodeBody`.
|
||||
* Two basic functions for grabbing columns from a CSV: `parse_csv_one_column` and `parse_csv_two_columns`
|
||||
|
8
gen_c_library/.editorconfig
Normal file
8
gen_c_library/.editorconfig
Normal file
@ -0,0 +1,8 @@
|
||||
[*.c]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
|
||||
[*.cpp]
|
||||
indent_style = tab
|
||||
indent_size = 2
|
||||
|
23
gen_c_library/Readme.md
Normal file
23
gen_c_library/Readme.md
Normal file
@ -0,0 +1,23 @@
|
||||
## Navigation
|
||||
|
||||
# base
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
* [docs](../docs/Readme.md)
|
||||
|
||||
# C Library Generation
|
||||
|
||||
`c_library.cpp` generates both *segemnted* and *singleheader* variants of the library compliant with C11.
|
||||
|
||||
The output will be in the `gen_segmented/gen` directory (if the directory does not exist, it will create it).
|
||||
|
||||
If using the library's provided build scripts:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> c_library
|
||||
```
|
||||
|
||||
All free from tag identifiers will be prefixed with `gen_` or `GEN_` as the namespace. This can either be changed after generation with a `.refactor` script (or your preferred subst method), OR by modifying c_library.refactor.
|
||||
|
||||
**If c_library.refactor is modified you may need to modify c_library.cpp and its [components](./components/). As some of the container generation relies on that prefix.**
|
File diff suppressed because it is too large
Load Diff
543
gen_c_library/c_library.refactor
Normal file
543
gen_c_library/c_library.refactor
Normal file
@ -0,0 +1,543 @@
|
||||
__VERSION 1
|
||||
|
||||
// not : Ignore
|
||||
// include : #includes
|
||||
// word : Alphanumeric or underscore
|
||||
// namespace : Prefix search and replace (c-namspaces).
|
||||
// regex : Unavailable in __VERSION 1.
|
||||
|
||||
// Precedence (highest to lowest):
|
||||
// word, namespace, regex
|
||||
|
||||
// Gen Macro namespace
|
||||
// namespace GEN_, new_namespace_
|
||||
|
||||
// c_library.refactor
|
||||
// Used to prefix all exposed identifiers with the gen_namespace by c_library.cpp using ./gencpp/scripts/helpers/refactor.exe
|
||||
|
||||
// Macros
|
||||
|
||||
word global, gen_global
|
||||
word internal, gen_internal
|
||||
word local_persist, gen_local_persist
|
||||
word bit, gen_bit
|
||||
word bitfield_is_equal, gen_bitfield_is_equal
|
||||
word cast, gen_cast
|
||||
word ccast, gen_ccast
|
||||
word pcast, gen_pcast
|
||||
word rcast, gen_rcast
|
||||
word scast, gen_scast
|
||||
word stringize_va, gen_stringize_va
|
||||
word stringize, gen_stringize
|
||||
word do_once, gen_do_once
|
||||
word do_once_start, gen_do_once_start
|
||||
word do_once_end, gen_do_once_end
|
||||
word labeled_scope_start, gen_labeled_scope_start
|
||||
word labeled_scope_end, gen_labeled_scope_end
|
||||
word compiler_decorated_func_name, gen_compiler_decorated_func_name
|
||||
word num_args_impl, gen_num_args_impl
|
||||
word num_args, gen_num_args
|
||||
word clamp, gen_clamp
|
||||
word count_of, gen_count_of
|
||||
word is_between, gen_is_between
|
||||
word size_of, gen_size_of
|
||||
word max, gen_max
|
||||
word min, gen_min
|
||||
word offset_of, gen_offset_of
|
||||
word forceinline, gen_forceinline
|
||||
word neverinline, gen_neverinline
|
||||
word static_assert, gen_static_assert
|
||||
word thread_local, gen_thread_local
|
||||
word typeof, gen_typeof
|
||||
word enum_underlying, gen_enum_underlying
|
||||
word nullptr, gen_nullptr
|
||||
word struct_init, gen_struct_init
|
||||
word hash, gen_hash
|
||||
|
||||
// Basic Types
|
||||
|
||||
word u8, gen_u8
|
||||
word s8, gen_s8
|
||||
word u16, gen_u16
|
||||
word s16, gen_s16
|
||||
word u32, gen_u32
|
||||
word s32, gen_s32
|
||||
word u64, gen_u64
|
||||
word s64, gen_s64
|
||||
word usize, gen_usize
|
||||
word ssize, gen_ssize
|
||||
word sptr, gen_sptr
|
||||
word uptr, gen_uptr
|
||||
word f32, gen_f32
|
||||
word f64, gen_f64
|
||||
word b8, gen_b8
|
||||
word b16, gen_b16
|
||||
word b32, gen_b32
|
||||
word mem_ptr, gen_mem_ptr
|
||||
word mem_ptr_const, gen_mem_ptr_const
|
||||
word to_uptr, gen_to_uptr
|
||||
word to_sptr, gen_to_sptr
|
||||
word to_mem_ptr, gen_to_mem_ptr
|
||||
word to_mem_ptr_const, gen_to_mem_ptr_const
|
||||
|
||||
// Debug
|
||||
|
||||
word assert_handler, gen_assert_handler
|
||||
word assert_crash, gen_assert_crash
|
||||
word process_exit, gen_process_exit
|
||||
|
||||
// Memory
|
||||
|
||||
word kilobytes, gen_kilobytes
|
||||
word megabytes, gen_megabytes
|
||||
word gigabytes, gen_gigabytes
|
||||
word terabytes, gen_terabytes
|
||||
|
||||
word swap, gen_swap
|
||||
|
||||
word is_power_of_two, gen_is_power_of_two
|
||||
word align_forward, gen_align_forward
|
||||
word align_forward_by_value, gen_align_forward_by_value
|
||||
word pointer_add, gen_pointer_add
|
||||
word pointer_add_const, gen_pointer_add_const
|
||||
word pointer_diff, gen_pointer_diff
|
||||
word mem_copy, gen_mem_copy
|
||||
word mem_find, gen_mem_find
|
||||
word mem_move, gen_mem_move
|
||||
word mem_set, gen_mem_set
|
||||
word zero_size, gen_zero_size
|
||||
word zero_item, gen_zero_item
|
||||
word zero_array, gen_zero_array
|
||||
|
||||
word AllocType, gen_AllocType
|
||||
word AllocatorProc, gen_AllocatorProc
|
||||
word AllocatorInfo, gen_AllocatorInfo
|
||||
word AllocFlag, gen_AllocFlag
|
||||
|
||||
word alloc, gen_alloc
|
||||
word alloc_align, gen_alloc_align
|
||||
word allocator_free, gen_allocator_free
|
||||
word free_all, gen_free_all
|
||||
word resize, gen_resize
|
||||
word resize_align, gen_resize_align
|
||||
word alloc_item, gen_alloc_item
|
||||
word alloc_array, gen_alloc_array
|
||||
|
||||
word heap_stats_init, gen_heap_stats_init
|
||||
word heap_stats_used_memory, gen_heap_stats_used_memory
|
||||
word heap_stats_alloc_count, gen_heap_stats_alloc_count
|
||||
word heap_stats_check, gen_heap_stats_check
|
||||
word default_resize_align, gen_default_resize_align
|
||||
|
||||
word heap_allocator_proc, gen_heap_allocator_proc
|
||||
word heap, gen_heap
|
||||
word malloc, gen_malloc
|
||||
word mfree, gen_mfree
|
||||
|
||||
word VirtualMemory, gen_VirtualMemory
|
||||
word vm_from_memory, gen_vm_from_memory
|
||||
word vm_alloc, gen_vm_alloc
|
||||
word vm_free, gen_vm_free
|
||||
word vm_trim, gen_vm_trim
|
||||
word vm_purge, gen_vm_purge
|
||||
word virtual_memory_page_size, gen_virtual_memory_page_size
|
||||
|
||||
// Memory: Arena
|
||||
|
||||
word Arena, gen_Arena
|
||||
namespace arena_, gen_arena_
|
||||
|
||||
// word arena_allocator_info
|
||||
// word arena_init_from_memory
|
||||
// word arena_init_from_allocator
|
||||
// word arena_init_sub
|
||||
// word arena_alignment_of
|
||||
// word arena_check
|
||||
// word arena_size_remaining
|
||||
|
||||
// Memory: FixedArena
|
||||
|
||||
namespace FixedArena_, gen_FixedArena_
|
||||
namespace fixed_arena_, gen_fixed_arena_
|
||||
|
||||
// Memory: Pool
|
||||
|
||||
word Pool, gen_Pool
|
||||
namespace pool_, gen_pool_
|
||||
|
||||
// Printing
|
||||
|
||||
namespace str_, gen_str_
|
||||
|
||||
word PrintF_Buffer, gen_PrintF_Buffer
|
||||
word Msg_Invalid_Value, gen_Msg_Invalid_Value
|
||||
word log_fmt, gen_log_fmt
|
||||
|
||||
// String Ops
|
||||
|
||||
namespace char_, gen_char_
|
||||
|
||||
word digit_to_int, gen_digit_to_int
|
||||
word hex_digit_to_init, gen_hex_digit_to_init
|
||||
word i64_to_str, gen_i64_to_str
|
||||
word u64_to_str, gen_u64_to_str
|
||||
|
||||
// Containers
|
||||
|
||||
namespace GENERIC_SLOT_, GEN_GENERIC_SLOT_
|
||||
|
||||
word Array, gen_Array
|
||||
word Array_ssize, gen_Array_gen_ssize
|
||||
|
||||
word ArrayHeader, gen_ArrayHeader
|
||||
|
||||
namespace Array_, gen_Array_
|
||||
namespace array_, gen_array_
|
||||
|
||||
word HashTable, gen_HashTable
|
||||
|
||||
namespace HashTable_, gen_HashTable_
|
||||
namespace hashtable_, gen_hashtable_
|
||||
|
||||
namespace HT_, gen_HT_
|
||||
namespace HTE_, gen_HTE_
|
||||
namespace arr_hte_, gen_arr_hte_
|
||||
namespace Arr_HTE_, gen_Arr_HTE_
|
||||
|
||||
// Hashing
|
||||
|
||||
word crc32, gen_crc32
|
||||
word crc64, gen_crc64
|
||||
|
||||
// Strings
|
||||
|
||||
word StrC, gen_StrC
|
||||
|
||||
word to_strc_from_c_str, gen_to_strc_from_c_str
|
||||
|
||||
namespace strc_, gen_strc_
|
||||
|
||||
word cast_to_strc, gen_cast_to_strc
|
||||
|
||||
word StringHeader, gen_StringHeader
|
||||
word String, gen_String
|
||||
|
||||
namespace string_, gen_string_
|
||||
|
||||
word StringCached, gen_StringCached
|
||||
|
||||
word StringTable, gen_StringTable
|
||||
|
||||
namespace StringTable_, gen_StringTable_
|
||||
|
||||
// File Handling
|
||||
|
||||
word FileModeFlag, gen_FileModeFlag
|
||||
word SeekWhenceType, gen_SeekWhenceType
|
||||
word FileError, gen_FileError
|
||||
word FileDescriptor, gen_FileDescriptor
|
||||
word FileMode, gen_FileMode
|
||||
word FileOperations, gen_FileOperations
|
||||
word FileOperations, gen_FileOperations
|
||||
|
||||
default_file_operations
|
||||
|
||||
word FileTime, word FileTime
|
||||
|
||||
word DirType, gen_DirType
|
||||
word DirInfo, gen_DirInfo
|
||||
word DirEntry, gen_DirEntry
|
||||
word DirInfo, gen_DirInfo
|
||||
word FileInfo, gen_FileInfo
|
||||
word FileStandardType, gen_FileStandardType
|
||||
|
||||
namespace file_, gen_file_
|
||||
|
||||
word gen_FileContents, gen_FileContents
|
||||
|
||||
// Timing
|
||||
|
||||
word read_cpu_time_stamp_counter, gen_read_cpu_time_stamp_counter
|
||||
word time_rel, gen_time_rel
|
||||
word time_rel_ms, gen_time_rel_ms
|
||||
|
||||
// Parsing
|
||||
|
||||
// Parsing: ADT
|
||||
|
||||
word ADT_Node, gen_ADT_Node
|
||||
word ADT_Type, gen_ADT_Type
|
||||
word ADT_Props, gen_ADT_Props
|
||||
word ADT_NamingStyle, gen_ADT_NamingStyle
|
||||
word ADT_AssignStyle, gen_ADT_AssignStyle
|
||||
word ADT_DelimStyle, gen_ADT_DelimStyle
|
||||
word ADT_Error, gen_ADT_Error
|
||||
word ADT_Node, gen_ADT_Node
|
||||
|
||||
namespace adt_, gen_adt_
|
||||
|
||||
word CSV_Error, gen_CSV_Error
|
||||
word CSV_Object, gen_CSV_Object
|
||||
|
||||
namespace csv_, gen_csv_
|
||||
|
||||
// Types.hpp
|
||||
|
||||
word log_failure, gen_log_failure
|
||||
|
||||
word AccessSpec, gen_AccessSpec
|
||||
word access_spec_to_str, gen_access_spec_to_str
|
||||
|
||||
word CodeFlag, gen_CodeFlag
|
||||
word EnumDecl, gen_EnumDecl
|
||||
|
||||
word ModuleFlag, gen_ModuleFlag
|
||||
word module_flag_to_str, gen_module_flag_to_str
|
||||
|
||||
word EPreprocessCond, gen_EPreprocessCOnd
|
||||
word ETypenameTag, gen_ETypenameTag
|
||||
|
||||
word CodeType, gen_CodeType
|
||||
|
||||
word codetype_to_str, gen_codetype_to_str
|
||||
word codetype_to_keyword_str, gen_codetype_to_keyword_str
|
||||
|
||||
word Operator, gen_Operator
|
||||
word operator_to_str, gen_operator_to_str
|
||||
|
||||
word Specifier, gen_Specifier
|
||||
word spec_to_str, gen_spec_to_str
|
||||
word spec_is_trailing, gen_spec_is_trailing
|
||||
// word strc_to_specifier, gen_strc_to_specifier
|
||||
|
||||
// AST
|
||||
|
||||
word AST, gen_AST
|
||||
|
||||
namespace AST_, gen_AST_
|
||||
|
||||
word Code, gen_Code
|
||||
word Token, gen_Token
|
||||
|
||||
word CodeBody, gen_CodeBody
|
||||
word CodeAttributes, gen_CodeAttributes
|
||||
word CodeComment, gen_CodeComment
|
||||
word CodeClass, gen_CodeClass
|
||||
word CodeConstructor, gen_CodeConstructor
|
||||
word CodeDefine, gen_CodeDefine
|
||||
word CodeDestructor, gen_CodeDestructor
|
||||
word CodeEnum, gen_CodeEnum
|
||||
word CodeExec, gen_CodeExec
|
||||
word CodeExtern, gen_CodeExtern
|
||||
word CodeInclude, gen_CodeInclude
|
||||
word CodeFriend, gen_CodeFriend
|
||||
word CodeFn, gen_CodeFn
|
||||
word CodeModule, gen_CodeModule
|
||||
word CodeNS, gen_CodeNS
|
||||
word CodeOperator, gen_CodeOperator
|
||||
word CodeOpCast, gen_CodeOpCast
|
||||
word CodePragma, gen_CodePragma
|
||||
word CodeParams, gen_CodeParams
|
||||
word CodePreprocessCond, gen_CodePreprocessCond
|
||||
word CodeSpecifiers, gen_CodeSpecifiers
|
||||
word CodeTemplate, gen_CodeTemplate
|
||||
word CodeTypename, gen_CodeTypename
|
||||
word CodeTypedef, gen_CodeTypedef
|
||||
word CodeUnion, gen_CodeUnion
|
||||
word CodeUsing, gen_CodeUsing
|
||||
word CodeVar, gen_CodeVar
|
||||
|
||||
// Code Interface
|
||||
|
||||
namespace code_, gen_code_
|
||||
|
||||
word Code_Global, gen_Code_Global
|
||||
word Code_Invalid, gen_Code_Invalid
|
||||
|
||||
word Code_POD, gen_Code_POD
|
||||
|
||||
word AST_POD_Size, gen_AST_POD_Size
|
||||
word AST_ArrSpecs_Cap, gen_AST_ArrSpecs_Cap
|
||||
|
||||
word InvalidCode, gen_InvalidCode
|
||||
word NullCode, gen_NullCode
|
||||
|
||||
namespace begin_, gen_begin_
|
||||
namespace end_, gen_end_
|
||||
namespace next_, gen_next_
|
||||
|
||||
namespace body_, gen_body_
|
||||
namespace class_, gen_class_
|
||||
namespace params_, gen_params_
|
||||
namespace specifiers_, gen_specifiers_
|
||||
namespace struct_, gen_struct_
|
||||
namespace attributes_, gen_attributes_
|
||||
namespace comment_, gen_comment_
|
||||
namespace constructor, gen_constructor_
|
||||
namespace define_, gen_define_
|
||||
namespace destructor, gen_destructor_
|
||||
namespace enum_, gen_enum_
|
||||
namespace exec_, gen_exec_
|
||||
namespace extern_, gen_extern_
|
||||
namespace include_, gen_include_
|
||||
namespace friend_, gen_friend_
|
||||
namespace fn_, gen_fn_
|
||||
namespace module_, gen_module_
|
||||
namespace code_op, gen_code_op_
|
||||
namespace opcast_, gen_opcast_
|
||||
namespace pragma_, gen_pragma_
|
||||
namespace preprocess_, gen_preprocess_
|
||||
namespace template_, gen_template_
|
||||
namespace typename_, gen_typename_
|
||||
namespace typedef_, gen_typedef_
|
||||
namesapce union_, gen_union_
|
||||
namespace using_, gen_using_
|
||||
namespace var_, gen_var_
|
||||
|
||||
// Gen Interface
|
||||
|
||||
word init, gen_init
|
||||
word deinit, gen_deinit
|
||||
word reset, gen_reset
|
||||
|
||||
word get_cached_string, gen_get_cached_string
|
||||
|
||||
word make_code, gen_make_code
|
||||
|
||||
namespace set_allocator_, gen_set_allocator_
|
||||
|
||||
namespace def_, gen_def_
|
||||
namespace parse_, gen_parse_
|
||||
namespace token_, gen_token_
|
||||
namespace untyped_, gen_untyped_
|
||||
|
||||
// Constants
|
||||
|
||||
word TokenMap_FixedArena, gen_TokenMap_FixedArena
|
||||
word InitSize_DataArrays, gen_InitSize_DataArrays
|
||||
|
||||
word Global_BucketSize, gen_Global_BucketSize
|
||||
word CodePool_NumBlocks, gen_CodePool_NumBlocks
|
||||
word SizePer_StringArena, gen_SizePer_StringArena
|
||||
|
||||
word MaxCommentLineLength, gen_MaxCommentLineLength
|
||||
word MaxNameLength, gen_MaxNameLength
|
||||
word MaxUntypedStrLength, gen_MaxUntypedStrLength
|
||||
|
||||
word LexAllocator_Size, gen_LexAllocator_Size
|
||||
word Builder_StrBufferReserve, gen_Builder_StrBufferReserve
|
||||
|
||||
word access_public, gen_access_public
|
||||
word access_protected, gen_access_protected
|
||||
word access_private, gen_access_private
|
||||
|
||||
word attrib_api_export, gen_attrib_api_export
|
||||
word attrib_api_import, gen_attrib_api_import
|
||||
|
||||
word module_global_fragment, gen_module_global_fragment
|
||||
word module_private_fragment, gen_module_private_fragment
|
||||
|
||||
word fmt_newline, gen_fmt_newline
|
||||
word pragma_once, gen_pragma_once
|
||||
word param_varadic, gen_param_varadic
|
||||
word preprocess_else, gen_preprocess_else
|
||||
|
||||
namespace spec_, gen_spec_
|
||||
namespace t_, gen_t_
|
||||
|
||||
word PreprocessorDefines, gen_PreprocessorDefines
|
||||
|
||||
// Backend
|
||||
|
||||
word GlobalAllocator, gen_GlobalAllocator
|
||||
word Global_AllocatorBuckets, gen_Global_AllocatorBuckets
|
||||
word CodePools, gen_CodePools
|
||||
word StringArenas, gen_StringArenas
|
||||
word StringCache, gen_StringCache
|
||||
word LexArena, gen_LexArena
|
||||
word Allocator_DataArrays, gen_Allocator_DataArrays
|
||||
word Allocator_CodePool, gen_Allocator_CodePool
|
||||
word Allocator_Lexer, gen_Allocator_Lexer
|
||||
word Allocator_StringArena, gen_Allocator_StringArena
|
||||
word Allocator_StringTable, gen_Allocator_StringTable
|
||||
word Allocator_TypeTable, gen_Allocator_TypeTable
|
||||
|
||||
// Builder
|
||||
|
||||
word Builder, gen_Builder
|
||||
namespace builder_, gen_builder_
|
||||
|
||||
// Implementation (prviate)
|
||||
|
||||
word _format_info, gen__format_info
|
||||
|
||||
namespace _print_, gen__print_
|
||||
word _heap_stats, gen__heap_stats
|
||||
word _heap_alloc_info, gen__heap_alloc_info
|
||||
|
||||
word _crc32_table, gen__crc32_table
|
||||
word _crc64_table, gen__crc64_table
|
||||
|
||||
word _alloc_utf8_to_ucs2, gen__alloc_utf8_to_ucs2
|
||||
|
||||
word _win32_file_seek, gen__win32_file_seek
|
||||
word _win32_file_read, gen__win32_file_read
|
||||
word _win32_file_write, gen__win32_file_write
|
||||
word _win32_file_close, gen__win32_file_close
|
||||
word _win32_file_open, gen__win32_file_open
|
||||
|
||||
word _posix_file_seek, gen__posix_file_seek
|
||||
word _posix_file_read, gen__posix_file_read
|
||||
word _posix_file_write, gen__posix_file_write
|
||||
word _posix_file_close, gen__posix_file_close
|
||||
word _posix_file_open, gen__posix_file_open
|
||||
|
||||
word _dirinfo_free_entry, gen__dirinfo_free_entry
|
||||
word _std_file_set, gen__std_file_set
|
||||
|
||||
word _memory_fd, gen__memory_fd
|
||||
|
||||
word _file_stream_fd_make, gen__file_stream_fd_make
|
||||
word _file_stream_from_fd, gen__file_stream_from_fd
|
||||
word _memory_file_seek, gen__memory_file_seek
|
||||
word _memory_file_read, gen__memory_file_read
|
||||
word _memory_file_write, gen__memory_file_write
|
||||
word _memory_file_close, gen__memory_file_close
|
||||
|
||||
word _unix_gettime, gen__unix_gettime
|
||||
word _adt_fprintf, gen__adt_fprintf
|
||||
|
||||
word _adt_get_value, gen__adt_get_value
|
||||
word _adt_get_field, gen__adt_get_field
|
||||
|
||||
word _csv_write_record, gen__csv_write_record
|
||||
word _csv_write_header, gen__csv_write_header
|
||||
|
||||
word Global_Allocator_Proc, gen_Global_Allocator_Proc
|
||||
word define_constants, gen_define_constants
|
||||
word operator__validate, gen_operator__validate
|
||||
|
||||
word parser_init, gen_parser_init
|
||||
word parser_deinit, gen_parser_deinit
|
||||
|
||||
word TokType, gen_TokType
|
||||
word toktype_to_str, gen_toktype_to_str
|
||||
// word strc_to_toktype, gen_strc_to_toktype
|
||||
word NullToken, gen_NullToken
|
||||
|
||||
namespace tok_, gen_tok_
|
||||
|
||||
word TokArray, gen_TokArray
|
||||
|
||||
namespace lex_, gen_lex_
|
||||
namespace Lexer_, gen_Lexer_
|
||||
|
||||
word LexContext, gen_LexContext
|
||||
word lex, gen_lex
|
||||
|
||||
word StackNode, gen_StackNode
|
||||
word ParseContext, gen_ParseContext
|
||||
|
||||
// namespace parse_, gen_parse_
|
||||
|
||||
namespace parser_, gen_parser_
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
@ -21,8 +20,24 @@ CodeBody gen_array_base()
|
||||
|
||||
Code grow_formula = untyped_str( txt( "#define array_grow_formula( value ) ( 2 * value + 8 )\n" ));
|
||||
Code get_header = untyped_str( txt( "#define array_get_header( self ) ( (ArrayHeader*)( self ) - 1)\n" ));
|
||||
Code type_define = untyped_str( txt( "#define Array(Type) gen_Array_##Type\n"));
|
||||
|
||||
return def_global_body( args( fmt_newline, td_header, header, grow_formula, get_header, fmt_newline ) );
|
||||
Code array_begin = def_define(txt("array_begin(array)"), code( (array) ));
|
||||
Code array_end = def_define(txt("array_end(array)"), code( (array + array_get_header(array)->Num ) ));
|
||||
Code array_next = def_define(txt("array_next(array, entry)"), code( (entry + 1) ));
|
||||
|
||||
return def_global_body( args(
|
||||
fmt_newline,
|
||||
td_header,
|
||||
header,
|
||||
type_define,
|
||||
grow_formula,
|
||||
get_header,
|
||||
array_begin,
|
||||
array_end,
|
||||
array_next,
|
||||
fmt_newline
|
||||
));
|
||||
};
|
||||
|
||||
CodeBody gen_array( StrC type, StrC array_name )
|
||||
@ -68,7 +83,7 @@ CodeBody gen_array( StrC type, StrC array_name )
|
||||
<array_type> <fn>_init( AllocatorInfo allocator )
|
||||
{
|
||||
size_t initial_size = array_grow_formula(0);
|
||||
return array_init_reserve( <array_type>, allocator, initial_size );
|
||||
return array_init_reserve( <type>, allocator, initial_size );
|
||||
}
|
||||
|
||||
inline
|
||||
@ -362,24 +377,24 @@ CodeBody gen_array( StrC type, StrC array_name )
|
||||
++ Array_DefinitionCounter;
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_strc();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type_delimiter", (StrC)array_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__array_init <type_delimiter>, <type_delimiter>_init
|
||||
#define GENERIC_SLOT_<slot>__array_init_reserve <type_delimiter>, <type_delimiter>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_append <type_delimiter>, <type_delimiter>_append
|
||||
#define GENERIC_SLOT_<slot>__array_append_items <type_delimiter>, <type_delimiter>_append_items
|
||||
#define GENERIC_SLOT_<slot>__array_append_at <type_delimiter>, <type_delimiter>_append_at
|
||||
#define GENERIC_SLOT_<slot>__array_append_items_at <type_delimiter>, <type_delimiter>_append_items_at
|
||||
#define GENERIC_SLOT_<slot>__array_back <type_delimiter>, <type_delimiter>_back
|
||||
#define GENERIC_SLOT_<slot>__array_clear <type_delimiter>, <type_delimiter>_clear
|
||||
#define GENERIC_SLOT_<slot>__array_fill <type_delimiter>, <type_delimiter>_fill
|
||||
#define GENERIC_SLOT_<slot>__array_free <type_delimiter>, <type_delimiter>_free
|
||||
#define GENERIC_SLOT_<slot>__array_grow <type_delimiter>*, <type_delimiter>_grow
|
||||
#define GENERIC_SLOT_<slot>__array_num <type_delimiter>, <type_delimiter>_num
|
||||
#define GENERIC_SLOT_<slot>__array_pop <type_delimiter>, <type_delimiter>_pop
|
||||
#define GENERIC_SLOT_<slot>__array_remove_at <type_delimiter>, <type_delimiter>_remove_at
|
||||
#define GENERIC_SLOT_<slot>__array_reserve <type_delimiter>, <type_delimiter>_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_resize <type_delimiter>, <type_delimiter>_resize
|
||||
#define GENERIC_SLOT_<slot>__array_set_capacity <type_delimiter>*, <type_delimiter>_set_capacity
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "array_type", (StrC)array_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_init
|
||||
#define GENERIC_SLOT_<slot>__array_init_reserve <type>, <array_type>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_append <array_type>, <array_type>_append
|
||||
#define GENERIC_SLOT_<slot>__array_append_items <array_type>, <array_type>_append_items
|
||||
#define GENERIC_SLOT_<slot>__array_append_at <array_type>, <array_type>_append_at
|
||||
#define GENERIC_SLOT_<slot>__array_append_items_at <array_type>, <array_type>_append_items_at
|
||||
#define GENERIC_SLOT_<slot>__array_back <array_type>, <array_type>_back
|
||||
#define GENERIC_SLOT_<slot>__array_clear <array_type>, <array_type>_clear
|
||||
#define GENERIC_SLOT_<slot>__array_fill <array_type>, <array_type>_fill
|
||||
#define GENERIC_SLOT_<slot>__array_free <array_type>, <array_type>_free
|
||||
#define GENERIC_SLOT_<slot>__array_grow <array_type>*, <array_type>_grow
|
||||
#define GENERIC_SLOT_<slot>__array_num <array_type>, <array_type>_num
|
||||
#define GENERIC_SLOT_<slot>__array_pop <array_type>, <array_type>_pop
|
||||
#define GENERIC_SLOT_<slot>__array_remove_at <array_type>, <array_type>_remove_at
|
||||
#define GENERIC_SLOT_<slot>__array_reserve <array_type>, <array_type>_reserve
|
||||
#define GENERIC_SLOT_<slot>__array_resize <array_type>, <array_type>_resize
|
||||
#define GENERIC_SLOT_<slot>__array_set_capacity <array_type>*, <array_type>_set_capacity
|
||||
)"
|
||||
));
|
||||
|
||||
@ -401,7 +416,9 @@ CodeBody gen_array_generic_selection_interface()
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_init"), GenericSel_Direct_Type ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_init_reserve"), GenericSel_Direct_Type ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_append"), GenericSel_By_Ref ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_append_at"), GenericSel_By_Ref ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_append_items"), GenericSel_By_Ref ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_append_items_at"), GenericSel_By_Ref ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_back"), GenericSel_Default, GenericSel_One_Arg ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_clear"), GenericSel_Default, GenericSel_One_Arg ));
|
||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_fill")) );
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
#include "containers.array.hpp"
|
||||
|
||||
using namespace gen;
|
||||
@ -107,21 +106,21 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
HT_FindResult <fn>__find ( <tbl_type> self, u64 key );
|
||||
b32 <fn>__full ( <tbl_type> self );
|
||||
|
||||
<tbl_type> <fn>init( AllocatorInfo allocator )
|
||||
<tbl_type> <fn>_init( AllocatorInfo allocator )
|
||||
{
|
||||
<tbl_type> result = hashtable_init_reserve(<tbl_type>, allocator, 8);
|
||||
<tbl_type> result = hashtable_init_reserve(<type>, allocator, 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
<tbl_type> <fn>_init_reserve( AllocatorInfo allocator, ssize num )
|
||||
{
|
||||
<tbl_type> result = { NULL, NULL };
|
||||
result.Hashes = array_init_reserve(Array_ssize, allocator, num );
|
||||
result.Hashes = array_init_reserve(ssize, allocator, num );
|
||||
array_get_header(result.Hashes)->Num = num;
|
||||
array_resize(result.Hashes, num);
|
||||
array_fill(result.Hashes, 0, num, -1);
|
||||
|
||||
result.Entries = array_init_reserve(<array_entry>, allocator, num );
|
||||
result.Entries = array_init_reserve(<entry_type>, allocator, num );
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -199,7 +198,7 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
ArrayHeader* old_hash_header = array_get_header( self->Hashes );
|
||||
ArrayHeader* old_entries_header = array_get_header( self->Entries );
|
||||
|
||||
<tbl_type> new_tbl = hashtable_init_reserve( <tbl_type>, old_hash_header->Allocator, old_hash_header->Num );
|
||||
<tbl_type> new_tbl = hashtable_init_reserve( <type>, old_hash_header->Allocator, old_hash_header->Num );
|
||||
|
||||
ArrayHeader* new_hash_header = array_get_header( new_tbl.Hashes );
|
||||
|
||||
@ -373,26 +372,26 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
||||
#pragma pop_macro( "forceinline" )
|
||||
|
||||
++ HashTable_DefinitionCounter;
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_strc();
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", HashTable_DefinitionCounter).to_strc();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type_delimiter", (StrC)tbl_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type_delimiter>, <type_delimiter>_init
|
||||
#define GENERIC_SLOT_<slot>__hashtable_init_reserve <type_delimiter>, <type_delimiter>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__hashtable_clear <type_delimiter>, <type_delimiter>_clear
|
||||
#define GENERIC_SLOT_<slot>__hashtable_destroy <type_delimiter>*, <type_delimiter>_destroy
|
||||
#define GENERIC_SLOT_<slot>__hashtable_get <type_delimiter>, <type_delimiter>_get
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map <type_delimiter>, <type_delimiter>_map
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map_mut <type_delimiter>, <type_delimiter>_map_mut
|
||||
#define GENERIC_SLOT_<slot>__hashtable_grow <type_delimiter>*, <type_delimiter>_grow
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash <type_delimiter>*, <type_delimiter>_rehash
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash_fast <type_delimiter>, <type_delimiter>_rehash_fast
|
||||
#define GENERIC_SLOT_<slot>__hashtable_remove_entry <type_delimiter>, <type_delimiter>_remove_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable_set <type_delimiter>*, <type_delimiter>_set
|
||||
#define GENERIC_SLOT_<slot>__hashtable_slot <type_delimiter>, <type_delimiter>_slot
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "tbl_type", (StrC)tbl_type, "slot", (StrC)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_init
|
||||
#define GENERIC_SLOT_<slot>__hashtable_init_reserve <type>, <tbl_type>_init_reserve
|
||||
#define GENERIC_SLOT_<slot>__hashtable_clear <tbl_type>, <tbl_type>_clear
|
||||
#define GENERIC_SLOT_<slot>__hashtable_destroy <tbl_type>, <tbl_type>_destroy
|
||||
#define GENERIC_SLOT_<slot>__hashtable_get <tbl_type>, <tbl_type>_get
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map <tbl_type>, <tbl_type>_map
|
||||
#define GENERIC_SLOT_<slot>__hashtable_map_mut <tbl_type>, <tbl_type>_map_mut
|
||||
#define GENERIC_SLOT_<slot>__hashtable_grow <tbl_type>*, <tbl_type>_grow
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash <tbl_type>*, <tbl_type>_rehash
|
||||
#define GENERIC_SLOT_<slot>__hashtable_rehash_fast <tbl_type>, <tbl_type>_rehash_fast
|
||||
#define GENERIC_SLOT_<slot>__hashtable_remove_entry <tbl_type>, <tbl_type>_remove_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable_set <tbl_type>, <tbl_type>_set
|
||||
#define GENERIC_SLOT_<slot>__hashtable_slot <tbl_type>, <tbl_type>_slot
|
||||
|
||||
#define GENERIC_SLOT_<slot>__hashtable__add_entry <type_delimiter>*, <type_delimiter>__add_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable__find <type_delimiter>, <type_delimiter>__find
|
||||
#define GENERIC_SLOT_<slot>__hashtable__full <type_delimiter>, <type_delimiter>__full
|
||||
#define GENERIC_SLOT_<slot>__hashtable__add_entry <tbl_type>*, <tbl_type>__add_entry
|
||||
#define GENERIC_SLOT_<slot>__hashtable__find <tbl_type>, <tbl_type>__find
|
||||
#define GENERIC_SLOT_<slot>__hashtable__full <tbl_type>, <tbl_type>__full
|
||||
)"
|
||||
));
|
||||
|
||||
|
115
gen_c_library/components/generic_macros.hpp
Normal file
115
gen_c_library/components/generic_macros.hpp
Normal file
@ -0,0 +1,115 @@
|
||||
|
||||
#pragma region _Generic Macros
|
||||
// ____ _ ______ _ _ ____ _ __ _
|
||||
// / ___} (_) | ____} | | (_) / __ \ | | | |(_)
|
||||
// | | ___ ___ _ __ ___ _ __ _ ___ | |__ _ _ _ __ ___| |_ _ ___ _ __ | | | |_ _____ _ __ | | ___ __ _ __| | _ _ __ __ _
|
||||
// | |{__ |/ _ \ '_ \ / _ \ '__} |/ __| | __} | | | '_ \ / __} __} |/ _ \| '_ \ | | | \ \ / / _ \ '_ \| |/ _ \ / _` |/ _` || | '_ \ / _` |
|
||||
// | |__j | __/ | | | __/ | | | (__ | | | |_| | | | | (__| l_| | (_) | | | | | l__| |\ V / __/ | | | | (_) | (_| | (_| || | | | | (_| |
|
||||
// \____/ \___}_l l_l\___}_l l_l\___| l_l \__,_l_l l_l\___}\__}_l\___/l_l l_l \____/ \_/ \___}_l l_l_l\___/ \__,_l\__,_l|_|_| |_|\__, |
|
||||
// This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in: __| |
|
||||
// https://github.com/JacksonAllan/CC/blob/main/articles/Better_C_Generics_Part_1_The_Extendible_Generic.md {___/
|
||||
// Since gencpp is used to generate the c-library, it was choosen over the more novel implementations to keep the macros as easy to understand and unobfuscated as possible.
|
||||
|
||||
#define GEN_COMMA_OPERATOR , // The comma operator is used by preprocessor macros to delimit arguments, so we have to represent it via a macro to prevent parsing incorrectly.
|
||||
|
||||
// Helper macros for argument selection
|
||||
#define GEN_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
|
||||
#define GEN_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
|
||||
#define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc..
|
||||
|
||||
#define GEN_GENERIC_SEL_ENTRY_TYPE GEN_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type.
|
||||
#define GEN_GENERIC_SEL_ENTRY_FUNCTION GEN_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function.
|
||||
#define GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER GEN_SELECT_ARG_3 // Use the arg expansion macro to select arg 3 which should have the comma delimiter ','.
|
||||
|
||||
#define GEN_RESOLVED_FUNCTION_CALL // Just used to indicate where the call "occurs"
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
// GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( macro ) includes a _Generic slot only if the specified macro is defined (as type, function_name).
|
||||
// It takes advantage of the fact that if the macro is defined, then the expanded text will contain a comma.
|
||||
// Expands to ',' if it can find (type): (function) <comma_operator: ',' >
|
||||
// Where GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> ,
|
||||
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) GEN_COMMA_OPERATOR, , )
|
||||
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
|
||||
// The slot won't exist if that comma is not found. |
|
||||
|
||||
// For the occastion where an expression didn't resolve to a selection option the "default: <value>" will be set to:
|
||||
typedef struct GENCPP_NO_RESOLVED_GENERIC_SELECTION GENCPP_NO_RESOLVED_GENERIC_SELECTION;
|
||||
struct GENCPP_NO_RESOLVED_GENERIC_SELECTION {
|
||||
void* _THE_VOID_SLOT_;
|
||||
};
|
||||
GENCPP_NO_RESOLVED_GENERIC_SELECTION const gen_generic_selection_fail = {0};
|
||||
// Which will provide the message: error: called object type 'struct NO_RESOLVED_GENERIC_SELECTION' is not a function or function pointer
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Below are generated on demand for an overlaod depdendent on a type:
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \
|
||||
(selector_arg), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg )
|
||||
// ----------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Then each definiton of a function has an associated define:
|
||||
#// #define GENERIC_SLOT_<#>_<generic identifier> <typename>, <function_to_resolve>
|
||||
|
||||
// Then somehwere later on
|
||||
// <etc> <return_type> <function_id> ( <arguments> ) { <implementation> }
|
||||
|
||||
// Concrete example:
|
||||
|
||||
// To add support for long:
|
||||
#define GENERIC_SLOT_1_gen_example_hash long, gen_example_hash__P_long
|
||||
size_t gen_example_hash__P_long( long val ) { return val * 2654435761ull; }
|
||||
|
||||
// To add support for long long:
|
||||
#define GENERIC_SLOT_2_gen_example_hash long long, gen_example_hash__P_long_long
|
||||
size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761ull; }
|
||||
|
||||
// If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled,
|
||||
// or, "defined" for usage during the compilation pass that handles the _Generic instrinsic.
|
||||
#define gen_hash_example( function_arguments ) _Generic( \
|
||||
(function_arguments), /* Select Via Expression*/ \
|
||||
/* Extendibility slots: */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_8 ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( function_arguments )
|
||||
|
||||
// Additional Variations:
|
||||
|
||||
// If the function takes more than one argument the following is used:
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE_VARADIC( selector_arg, ... ) _Generic( \
|
||||
(selector_arg), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_2 ) \
|
||||
/* ... */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(FunctionID__ARGS_SIG_N ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg, __VA_ARG__ )
|
||||
|
||||
// If the function does not take the arugment as a parameter:
|
||||
#define GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( selector_arg ) _Generic( \
|
||||
( GEN_TYPE_TO_EXP(selector_arg) ), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_2 ) \
|
||||
/* ... */ \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT(FunctionID__ARGS_SIG_N ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL()
|
||||
|
||||
// Used to keep the _Generic keyword happy as bare types are not considered "expressions"
|
||||
#define GEN_TYPE_TO_EXP(type) (* (type*)NULL)
|
||||
// Instead of using this macro, you'll see it directly expanded by the code generation.
|
||||
|
||||
// typedef void* GEN_GenericExampleType;
|
||||
// GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType );
|
||||
#pragma endregion _Generic Macros
|
9
gen_c_library/components/header_seg_includes.h
Normal file
9
gen_c_library/components/header_seg_includes.h
Normal file
@ -0,0 +1,9 @@
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.h : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
// Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.h"
|
||||
#endif
|
@ -4,16 +4,20 @@
|
||||
See Readme.md for more information from the project repository.
|
||||
|
||||
Public Address:
|
||||
https://github.com/Ed94/gencpp
|
||||
|
||||
This is a single header C-Library variant.
|
||||
Define GEN_IMPLEMENTATION before including this file in a single compilation unit.
|
||||
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha !
|
||||
! ============================================================================================ !
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION !
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL !
|
||||
! ============================================================================================ !
|
||||
https://github.com/Ed94/gencpp ---------------------------------------------------------------.
|
||||
| _____ _____ _ _ ___ __ __ |
|
||||
| / ____) / ____} | | | / ,__} / | / | |
|
||||
| | / ___ ___ _ __ ___ _ __ _ __ | {___ | l_ __ _ __ _, ___ __| | | | '-l | '-l | |
|
||||
| | |{_ \/ __\ '_ \ / __} '_ l| '_ l \___ \| __/ _` |/ _` |/ __\/ _` | | | | | | | |
|
||||
| | l__j | ___/ | | | {__; ;_l } ;_l } ____} | l| (_} | {_| | ___j {_; | | l___ _J l_ _J l_ |
|
||||
| \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ============================================================================================= |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
! ============================================================================================= /
|
||||
*/
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
@ -9,12 +9,12 @@ CodeBody gen_fixed_arenas()
|
||||
result.append(def_pragma(txt("region FixedArena")));
|
||||
|
||||
char const* template_struct = stringize(
|
||||
struct FixedArena_<Name>_Def
|
||||
struct FixedArena_<Name>
|
||||
{
|
||||
char memory[<Size>];
|
||||
Arena arena;
|
||||
};
|
||||
typedef struct FixedArena_<Name>_Def FixedArena_<Name>;
|
||||
typedef struct FixedArena_<Name> FixedArena_<Name>;
|
||||
);
|
||||
|
||||
char const* template_interface = stringize(
|
||||
@ -29,6 +29,11 @@ CodeBody gen_fixed_arenas()
|
||||
{
|
||||
return arena_size_remaining( & fixed_arena->arena, alignment);
|
||||
}
|
||||
|
||||
inline
|
||||
void fixed_arena_free_<Name>(FixedArena_<Name>* fixed_arena) {
|
||||
arena_free( & fixed_arena->arena);
|
||||
}
|
||||
);
|
||||
|
||||
CodeBody arena_struct_1kb = parse_global_body( token_fmt_impl( 3, "Name", txt("1KB"), "Size", txt("kilobytes(1)"), template_struct ));
|
||||
@ -84,25 +89,42 @@ CodeBody gen_fixed_arenas()
|
||||
result.append(arena_interface_2mb);
|
||||
result.append(arena_interface_4mb);
|
||||
|
||||
CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), code({ arena_allocator_proc, & fixed_arena.arena }) );
|
||||
CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), txt("( (AllocatorInfo) { arena_allocator_proc, & (fixed_arena)->arena } )"));
|
||||
result.append(def);
|
||||
result.append(fmt_newline);
|
||||
|
||||
result.append(parse_global_body(txt(R"(
|
||||
#define fixed_arena_init(expr) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_init_1KB, \
|
||||
FixedArena_4KB* : fixed_arena_init_4KB, \
|
||||
FixedArena_8KB* : fixed_arena_init_8KB, \
|
||||
FixedArena_16KB* : fixed_arena_init_16KB, \
|
||||
FixedArena_32KB* : fixed_arena_init_32KB, \
|
||||
FixedArena_64KB* : fixed_arena_init_64KB, \
|
||||
FixedArena_128KB* : fixed_arena_init_128KB, \
|
||||
FixedArena_256KB* : fixed_arena_init_256KB, \
|
||||
FixedArena_512KB* : fixed_arena_init_512KB, \
|
||||
FixedArena_1MB* : fixed_arena_init_1MB, \
|
||||
FixedArena_2MB* : fixed_arena_init_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_init_4MB \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(& expr)
|
||||
#define fixed_arena_init(expr) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_init_1KB, \
|
||||
FixedArena_4KB* : fixed_arena_init_4KB, \
|
||||
FixedArena_8KB* : fixed_arena_init_8KB, \
|
||||
FixedArena_16KB* : fixed_arena_init_16KB, \
|
||||
FixedArena_32KB* : fixed_arena_init_32KB, \
|
||||
FixedArena_64KB* : fixed_arena_init_64KB, \
|
||||
FixedArena_128KB* : fixed_arena_init_128KB, \
|
||||
FixedArena_256KB* : fixed_arena_init_256KB, \
|
||||
FixedArena_512KB* : fixed_arena_init_512KB, \
|
||||
FixedArena_1MB* : fixed_arena_init_1MB, \
|
||||
FixedArena_2MB* : fixed_arena_init_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_init_4MB, \
|
||||
default : gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(expr)
|
||||
|
||||
#define fixed_arena_free(expr) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_free_1KB, \
|
||||
FixedArena_4KB* : fixed_arena_free_4KB, \
|
||||
FixedArena_8KB* : fixed_arena_free_8KB, \
|
||||
FixedArena_16KB* : fixed_arena_free_16KB, \
|
||||
FixedArena_32KB* : fixed_arena_free_32KB, \
|
||||
FixedArena_64KB* : fixed_arena_free_64KB, \
|
||||
FixedArena_128KB* : fixed_arena_free_128KB, \
|
||||
FixedArena_256KB* : fixed_arena_free_256KB, \
|
||||
FixedArena_512KB* : fixed_arena_free_512KB, \
|
||||
FixedArena_1MB* : fixed_arena_free_1MB, \
|
||||
FixedArena_2MB* : fixed_arena_free_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_free_4MB, \
|
||||
default : gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(expr)
|
||||
|
||||
#define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \
|
||||
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
||||
@ -116,8 +138,9 @@ CodeBody gen_fixed_arenas()
|
||||
FixedArena_512KB* : fixed_arena_size_remaining_512KB, \
|
||||
FixedArena_1MB* : fixed_arena_size_remaining_1MB, \
|
||||
FixedArena_2MB* : fixed_arena_size_remaining_2MB, \
|
||||
FixedArena_4MB* : fixed_arena_size_remaining_4MB \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(& expr, alignment)
|
||||
FixedArena_4MB* : fixed_arena_size_remaining_4MB, \
|
||||
default : gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL(expr, alignment)
|
||||
)"
|
||||
)));
|
||||
|
||||
|
@ -1,15 +1,30 @@
|
||||
#pragma once
|
||||
#include "../project/gen.hpp"
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
void convert_cpp_enum_to_c( CodeEnum to_convert, CodeBody to_append )
|
||||
{
|
||||
#pragma push_macro("enum_underlying")
|
||||
#undef enum_underlying
|
||||
if (to_convert->UnderlyingType)
|
||||
{
|
||||
to_convert->UnderlyingTypeMacro = untyped_str(token_fmt("type", to_convert->UnderlyingType->Name, stringize(enum_underlying(<type>))));
|
||||
to_convert->UnderlyingType = CodeTypename{nullptr};
|
||||
}
|
||||
CodeTypedef tdef = parse_typedef(token_fmt("name", to_convert->Name, stringize( typedef enum <name> <name>; )));
|
||||
to_append.append(to_convert);
|
||||
to_append.append(tdef);
|
||||
#pragma pop_macro("enum_underlying")
|
||||
}
|
||||
|
||||
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& parsed_body, CodeBody& body )
|
||||
{
|
||||
b32 found = false;
|
||||
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
|
||||
if ( cond->Content.contains(cond_sig) )
|
||||
if ( cond->Content.is_equal(cond_sig) )
|
||||
{
|
||||
log_fmt("Preprocess cond found: %SC\n", cond->Content);
|
||||
//log_fmt("Preprocess cond found: %SC\n", cond->Content);
|
||||
found = true;
|
||||
|
||||
s32 depth = 1;
|
||||
@ -90,7 +105,7 @@ R"(#define <macro_name>(selector_arg, ...) _Generic( (selector_arg), \
|
||||
for ( s32 slot = 1; slot <= num_slots; ++ slot )
|
||||
{
|
||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", slot).to_strc();
|
||||
if (slot == num_slots)
|
||||
if (slot == num_slots && false)
|
||||
{
|
||||
define_builder.append( token_fmt( "macro_name", macro_name, "slot", slot_str,
|
||||
R"( GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( GENERIC_SLOT_<slot>__<macro_name> ) \
|
||||
@ -113,6 +128,8 @@ R"( GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_<slot>__<macro_name> )
|
||||
));
|
||||
}
|
||||
|
||||
define_builder.append( txt("default: gen_generic_selection_fail") );
|
||||
|
||||
if ( ! one_arg )
|
||||
{
|
||||
if (opts == GenericSel_By_Ref)
|
||||
@ -157,7 +174,7 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""
|
||||
|
||||
// Add parameter types to create a unique signature
|
||||
bool first_param = true;
|
||||
for (CodeParam param = fn->Params; param.ast; param = param->Next)
|
||||
for (CodeParams param = fn->Params; param.ast; param = param->Next)
|
||||
{
|
||||
if (param->ValueType)
|
||||
{
|
||||
@ -181,7 +198,7 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""
|
||||
continue;
|
||||
}
|
||||
|
||||
new_name.append_fmt("%SC_", to_str(spec));
|
||||
new_name.append_fmt("%SC_", spec_to_str(spec));
|
||||
}
|
||||
}
|
||||
|
||||
@ -193,11 +210,11 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""
|
||||
if (fn->Specs && fn->Specs->NumEntries > 0)
|
||||
{
|
||||
new_name.append("_S_");
|
||||
for (Specifier* spec = begin(fn->Specs);
|
||||
spec != end(fn->Specs);
|
||||
for (Specifier* spec = begin(fn->Specs);
|
||||
spec != end(fn->Specs);
|
||||
++spec)
|
||||
{
|
||||
new_name.append_fmt("%SC_", to_str(*spec));
|
||||
new_name.append_fmt("%SC_", spec_to_str(*spec));
|
||||
}
|
||||
}
|
||||
|
||||
|
11
gen_c_library/components/src_start.c
Normal file
11
gen_c_library/components/src_start.c
Normal file
@ -0,0 +1,11 @@
|
||||
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
#include "gen.h"
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.c"
|
||||
#endif
|
@ -1,7 +1,8 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#include "gen/gen.h"
|
||||
#include "gen/gen.c"
|
||||
|
||||
int main()
|
||||
{
|
||||
// init();
|
||||
__debugbreak();
|
||||
}
|
||||
|
21
gen_segmented/Readme.md
Normal file
21
gen_segmented/Readme.md
Normal file
@ -0,0 +1,21 @@
|
||||
## Navigation
|
||||
|
||||
# base
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
* [docs](../docs/Readme.md)
|
||||
|
||||
# Segemented Library Generation
|
||||
|
||||
The principal (user) files are `gen.hpp` and `gen.cpp`.
|
||||
They contain includes for its various components: `components/<component_name>.<hpp/cpp>`
|
||||
|
||||
Dependencies are bundled into `gen.dep.<hpp/cpp>`. They are included in `gen.<hpp/cpp>` before component includes.
|
||||
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`
|
||||
|
||||
If using the library's provided build scripts:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> segmented
|
||||
```
|
287
gen_segmented/segmented.cpp
Normal file
287
gen_segmented/segmented.cpp
Normal file
@ -0,0 +1,287 @@
|
||||
// Includes are exposed to base directory
|
||||
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#define GEN_C_LIKE_CPP 1
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "helpers/base_codegen.hpp"
|
||||
#include "helpers/misc.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
#include <cstdlib> // for system()
|
||||
|
||||
#define path_format_style "../scripts/.clang-format "
|
||||
#define scratch_file "gen/scratch.hpp"
|
||||
#define path_base "../base/"
|
||||
|
||||
Code format( Code code ) {
|
||||
return code_refactor_and_format(code, scratch_file, nullptr, path_format_style );
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( (path_base "helpers/push_ignores.inline.hpp") );
|
||||
Code pop_ignores = scan_file( (path_base "helpers/pop_ignores.inline.hpp") );
|
||||
|
||||
// gen_dep.hpp
|
||||
{
|
||||
Code platform = scan_file( path_base "dependencies/platform.hpp" );
|
||||
Code macros = scan_file( path_base "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( path_base "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( path_base "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.hpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.hpp" );
|
||||
|
||||
Builder _header = builder_open( "gen/gen.dep.hpp");
|
||||
Builder* header = & _header;
|
||||
builder_print_fmt( header, generation_notice );
|
||||
builder_print_fmt( header, "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n" );
|
||||
builder_print( header, platform );
|
||||
builder_print_fmt( header, "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
builder_print( header, macros );
|
||||
builder_print( header, basic_types );
|
||||
builder_print( header, debug );
|
||||
builder_print( header, memory );
|
||||
builder_print( header, string_ops );
|
||||
builder_print( header, printing );
|
||||
builder_print( header, containers );
|
||||
builder_print( header, hashing );
|
||||
builder_print( header, strings );
|
||||
builder_print( header, filesystem );
|
||||
builder_print( header, timing );
|
||||
builder_print( header, parsing );
|
||||
|
||||
builder_print_fmt( header, "\nGEN_NS_END\n" );
|
||||
builder_write(header);
|
||||
}
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
Code src_start = scan_file( path_base "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( path_base "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( path_base "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( path_base "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( path_base "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( path_base "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( path_base "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( path_base "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( path_base "dependencies/timing.cpp" );
|
||||
Code parsing = scan_file( path_base "dependencies/parsing.cpp" );
|
||||
|
||||
Builder _src = builder_open( "gen/gen.dep.cpp" );
|
||||
Builder* src = & _src;
|
||||
builder_print_fmt(src, generation_notice );
|
||||
builder_print_fmt( src, "// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n" );
|
||||
builder_print( src, src_start );
|
||||
builder_print_fmt( src, "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
builder_print( src, debug );
|
||||
builder_print( src, string_ops );
|
||||
builder_print( src, printing );
|
||||
builder_print( src, hashing );
|
||||
builder_print( src, memory );
|
||||
builder_print( src, strings );
|
||||
builder_print( src, filesystem );
|
||||
builder_print( src, timing );
|
||||
builder_print( src, parsing );
|
||||
|
||||
builder_print_fmt( src, "\nGEN_NS_END\n" );
|
||||
builder_write(src);
|
||||
}
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_strc_from_c_str(generation_notice) )
|
||||
));
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( path_base "components/header_start.hpp" );
|
||||
Code types = scan_file( path_base "components/types.hpp" );
|
||||
Code ast = scan_file( path_base "components/ast.hpp" );
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( path_base "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
Builder _header = builder_open( "gen/gen.hpp" );
|
||||
Builder* header = & _header;
|
||||
builder_print_fmt( header, generation_notice );
|
||||
builder_print_fmt( header, "#pragma once\n\n" );
|
||||
builder_print( header, push_ignores );
|
||||
builder_print( header, header_start );
|
||||
builder_print_fmt( header, "\nGEN_NS_BEGIN\n\n" );
|
||||
|
||||
builder_print_fmt(header, "#pragma region Types\n" );
|
||||
builder_print( header, types );
|
||||
builder_print( header, fmt_newline);
|
||||
builder_print( header, format(ecode) );
|
||||
builder_print( header, fmt_newline);
|
||||
builder_print( header, format(eoperator) );
|
||||
builder_print( header, fmt_newline);
|
||||
builder_print( header, format(especifier) );
|
||||
builder_print( header, fmt_newline);
|
||||
builder_print_fmt( header, "#pragma endregion Types\n\n" );
|
||||
|
||||
builder_print_fmt( header, "#pragma region AST\n" );
|
||||
builder_print( header, ast );
|
||||
builder_print( header, code_types );
|
||||
builder_print( header, ast_types );
|
||||
builder_print_fmt( header, "\n#pragma endregion AST\n" );
|
||||
|
||||
builder_print( header, interface );
|
||||
|
||||
builder_print_fmt( header, "\n#pragma region Inlines\n" );
|
||||
builder_print( header, inlines );
|
||||
builder_print( header, fmt_newline );
|
||||
builder_print( header, format(ast_inlines) );
|
||||
builder_print( header, fmt_newline );
|
||||
builder_print_fmt( header, "#pragma endregion Inlines\n" );
|
||||
|
||||
builder_print( header, header_end );
|
||||
builder_print_fmt( header, "GEN_NS_END\n\n" );
|
||||
builder_print( header, pop_ignores );
|
||||
builder_write(header);
|
||||
}
|
||||
|
||||
// gen.cpp
|
||||
{
|
||||
Code src_start = scan_file( path_base "components/src_start.cpp" );
|
||||
Code static_data = scan_file( path_base "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( path_base "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( path_base "components/ast.cpp" );
|
||||
Code code_serialization = scan_file( path_base "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( path_base "components/interface.cpp" );
|
||||
Code upfront = scan_file( path_base "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( path_base "components/lexer.cpp" );
|
||||
Code parser = scan_file( path_base "components/parser.cpp" );
|
||||
Code parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv" );
|
||||
CodeBody nspaced_etoktype = def_global_body( args(
|
||||
etoktype
|
||||
));
|
||||
Code formatted_toktype = format(nspaced_etoktype);
|
||||
|
||||
Builder _src = builder_open( "gen/gen.cpp" );
|
||||
Builder* src = & _src;
|
||||
builder_print_fmt( src, generation_notice );
|
||||
builder_print( src, push_ignores );
|
||||
builder_print( src, src_start );
|
||||
builder_print_fmt( src, "\nGEN_NS_BEGIN\n");
|
||||
|
||||
builder_print( src, static_data );
|
||||
|
||||
builder_print_fmt( src, "\n#pragma region AST\n\n" );
|
||||
builder_print( src, ast_case_macros );
|
||||
builder_print( src, ast );
|
||||
builder_print( src, code_serialization );
|
||||
builder_print_fmt( src, "\n#pragma endregion AST\n" );
|
||||
|
||||
builder_print_fmt( src, "\n#pragma region Interface\n" );
|
||||
builder_print( src, interface );
|
||||
builder_print( src, upfront );
|
||||
builder_print_fmt( src, "\n#pragma region Parsing\n\n" );
|
||||
builder_print( src, formatted_toktype );
|
||||
builder_print( src, lexer );
|
||||
builder_print( src, parser );
|
||||
builder_print( src, parsing_interface );
|
||||
builder_print_fmt( src, "\n#pragma endregion Parsing\n\n" );
|
||||
builder_print( src, untyped );
|
||||
builder_print_fmt( src, "#pragma endregion Interface\n\n" );
|
||||
|
||||
builder_print_fmt( src, "GEN_NS_END\n\n");
|
||||
builder_print( src, pop_ignores );
|
||||
builder_write(src);
|
||||
}
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.hpp" );
|
||||
|
||||
Builder header = builder_open( "gen/gen.builder.hpp" );
|
||||
builder_print_fmt( & header, generation_notice );
|
||||
builder_print_fmt( & header, "#pragma once\n\n" );
|
||||
builder_print( & header, def_include( txt("gen.hpp") ));
|
||||
builder_print_fmt( & header, "\nGEN_NS_BEGIN\n" );
|
||||
builder_print( & header, builder );
|
||||
builder_print_fmt( & header, "GEN_NS_END\n" );
|
||||
builder_write( & header);
|
||||
}
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.cpp" );
|
||||
|
||||
Builder src = builder_open( "gen/gen.builder.cpp" );
|
||||
builder_print_fmt( & src, generation_notice );
|
||||
builder_print( & src, def_include( txt("gen.builder.hpp") ) );
|
||||
builder_print_fmt( & src, "\nGEN_NS_BEGIN\n" );
|
||||
builder_print( & src, builder );
|
||||
builder_print_fmt( & src, "\nGEN_NS_END\n" );
|
||||
builder_write( & src);
|
||||
}
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
|
||||
|
||||
Builder header = builder_open( "gen/gen.scanner.hpp" );
|
||||
builder_print_fmt( & header, generation_notice );
|
||||
builder_print_fmt( & header, "#pragma once\n\n" );
|
||||
builder_print( & header, def_include( txt("gen.hpp") ) );
|
||||
builder_print_fmt( & header, "\nGEN_NS_BEGIN\n" );
|
||||
builder_print( & header, scanner );
|
||||
builder_print_fmt( & header, "\nGEN_NS_END\n" );
|
||||
builder_write(& header);
|
||||
}
|
||||
|
||||
// gen_scanner.cpp
|
||||
{
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
|
||||
|
||||
Builder src = builder_open( "gen/gen.scanner.cpp" );
|
||||
builder_print_fmt( & src, generation_notice );
|
||||
builder_print( & src, def_include( txt("gen.scanner.hpp") ) );
|
||||
builder_print_fmt( & src, "\nGEN_NS_BEGIN\n" );
|
||||
builder_print( & src, scanner );
|
||||
builder_print_fmt( & src, "GEN_NS_END\n" );
|
||||
builder_write( & src);
|
||||
}
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,18 @@
|
||||
## Navigation
|
||||
|
||||
# base
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
* [docs](../docs/Readme.md)
|
||||
|
||||
# Singleheader
|
||||
|
||||
Creates a single header file version of the library using `singleheader.cpp`.
|
||||
Follows the same convention seen in the gb, stb, and zpl libraries.
|
||||
|
||||
If using the library's provided build scripts:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> singleheader
|
||||
```
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user