mirror of
https://github.com/Ed94/gencpp.git
synced 2025-07-07 06:05:44 -07:00
Compare commits
36 Commits
c016e245eb
...
de_oop
Author | SHA1 | Date | |
---|---|---|---|
0e782cdf99 | |||
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 |
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": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
12
.vscode/c_cpp_properties.json
vendored
12
.vscode/c_cpp_properties.json
vendored
@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"name": "Bootstrap",
|
"name": "Bootstrap",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/project/**"
|
"${workspaceFolder}/base/**"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
@ -20,7 +20,7 @@
|
|||||||
"windowsSdkVersion": "10.0.19041.0",
|
"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",
|
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||||
"intelliSenseMode": "msvc-x64",
|
"intelliSenseMode": "msvc-x64",
|
||||||
"compileCommands": "C:\\projects\\gencpp\\.vscode\\tasks.json",
|
"compileCommands": "${workspaceFolder}/.vscode/tasks.json",
|
||||||
"compilerArgs": [
|
"compilerArgs": [
|
||||||
"/EHsc-",
|
"/EHsc-",
|
||||||
"/GR-",
|
"/GR-",
|
||||||
@ -47,12 +47,12 @@
|
|||||||
"windowsSdkVersion": "10.0.19041.0",
|
"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",
|
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||||
"intelliSenseMode": "msvc-x64",
|
"intelliSenseMode": "msvc-x64",
|
||||||
"compileCommands": "C:\\projects\\gencpp\\.vscode\\tasks.json"
|
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Win32 clang",
|
"name": "Win32 clang",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/base/**"
|
||||||
],
|
],
|
||||||
"defines": [
|
"defines": [
|
||||||
"_DEBUG",
|
"_DEBUG",
|
||||||
@ -65,9 +65,9 @@
|
|||||||
"INTELLISENSE_DIRECTIVES"
|
"INTELLISENSE_DIRECTIVES"
|
||||||
],
|
],
|
||||||
"windowsSdkVersion": "10.0.19041.0",
|
"windowsSdkVersion": "10.0.19041.0",
|
||||||
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
|
"compilerPath": "clang++.exe",
|
||||||
"intelliSenseMode": "windows-clang-x64",
|
"intelliSenseMode": "windows-clang-x64",
|
||||||
"compileCommands": ".vscode/tasks.json"
|
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": 4
|
"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
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
|
||||||
"type": "lldb",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Debug gentime lldb",
|
|
||||||
"program": "${workspaceFolder}/test/test.exe",
|
|
||||||
"args": [],
|
|
||||||
"cwd": "${workspaceFolder}/test/",
|
|
||||||
"postRunCommands": [
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "cppvsdbg",
|
"type": "cppvsdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Debug gentime vsdbg",
|
"name": "Debug base vsdbg",
|
||||||
"program": "${workspaceFolder}/test/build/test.exe",
|
"program": "${workspaceFolder}/base/build/base.exe",
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}/test/",
|
"cwd": "${workspaceFolder}/base/",
|
||||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "cppvsdbg",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Debug bootstrap vsdbg",
|
|
||||||
"program": "${workspaceFolder}/project/build/bootstrap.exe",
|
|
||||||
"args": [],
|
|
||||||
"cwd": "${workspaceFolder}/project/",
|
|
||||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "cppvsdbg",
|
"type": "cppvsdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Debug singleheader vsdbg",
|
"name": "Debug singleheader vsdbg",
|
||||||
"program": "${workspaceFolder}/singleheader/build/gencpp_singleheader.exe",
|
"program": "${workspaceFolder}/singleheader/build/singleheader.exe",
|
||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}/singleheader/",
|
"cwd": "${workspaceFolder}/singleheader/",
|
||||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||||
@ -49,24 +30,6 @@
|
|||||||
"args": [],
|
"args": [],
|
||||||
"cwd": "${workspaceFolder}/unreal_engine/",
|
"cwd": "${workspaceFolder}/unreal_engine/",
|
||||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
"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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -72,5 +72,5 @@
|
|||||||
},
|
},
|
||||||
"autoHide.autoHidePanel": false,
|
"autoHide.autoHidePanel": false,
|
||||||
"autoHide.autoHideSideBar": false,
|
"autoHide.autoHideSideBar": false,
|
||||||
"dimmer.enabled": true
|
"dimmer.enabled": false
|
||||||
}
|
}
|
||||||
|
17
Readme.md
17
Readme.md
@ -8,6 +8,19 @@ These build up a code AST to then serialize with a file builder, or can be trave
|
|||||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
|
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.
|
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
|
## Notes
|
||||||
|
|
||||||
**On Partial Hiatus: Life has got me tackling other issues..**
|
**On Partial Hiatus: Life has got me tackling other issues..**
|
||||||
@ -21,10 +34,6 @@ 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).
|
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
|
## 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.
|
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.
|
||||||
|
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"
|
# include "builder.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Builder Builder::open( char const* path )
|
#pragma region Builder
|
||||||
|
|
||||||
|
Builder builder_open( char const* path )
|
||||||
{
|
{
|
||||||
Builder result;
|
Builder result;
|
||||||
|
|
||||||
@ -19,41 +21,39 @@ Builder Builder::open( char const* path )
|
|||||||
return result;
|
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 = code_to_string(code);
|
String str = code_to_string(code);
|
||||||
// const ssize len = str.length();
|
// const ssize len = str.length();
|
||||||
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
// 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;
|
ssize res;
|
||||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
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;
|
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*) & (builder->Buffer), (char const*)buf, res);
|
||||||
string_append_c_str_len( (String*) & 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 )
|
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 );
|
log_fmt( "Generated: %s\n", builder->File.filename );
|
||||||
file_close( & File );
|
file_close( & builder->File );
|
||||||
string_free(& Buffer);
|
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
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# 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
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
@ -1,12 +1,9 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# include "scanner.hpp"
|
||||||
# include "gen.hpp"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This is a simple file reader that reads the entire file into memory.
|
#pragma region Scanner
|
||||||
// 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
|
|
||||||
Code scan_file( char const* path )
|
Code scan_file( char const* path )
|
||||||
{
|
{
|
||||||
FileInfo file;
|
FileInfo file;
|
||||||
@ -119,41 +116,33 @@ Code scan_file( char const* path )
|
|||||||
return untyped_str( string_to_strc(str) );
|
return untyped_str( string_to_strc(str) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
CodeBody parse_file( const char* path ) {
|
||||||
struct CodeFile
|
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
||||||
{
|
StrC content = { file.size, (char const*)file.data };
|
||||||
using namespace Parser;
|
CodeBody code = parse_global_body( content );
|
||||||
|
log_fmt("\nParsed: %s\n", path);
|
||||||
String FilePath;
|
return code;
|
||||||
TokArray Tokens;
|
|
||||||
Array<ParseFailure> ParseFailures;
|
|
||||||
Code CodeRoot;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Parser
|
|
||||||
{
|
|
||||||
struct ParseFailure
|
|
||||||
{
|
|
||||||
String Reason;
|
|
||||||
Code Node;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeFile scan_file( char const* path )
|
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path) {
|
||||||
{
|
FileContents content = file_read_contents( allocator, file_zero_terminate, path );
|
||||||
using namespace Parser;
|
Arena csv_arena = arena_init_from_memory(content.data, content.size);
|
||||||
|
|
||||||
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 result;
|
||||||
|
csv_parse( & result.ADT, rcast(char*, content.data), allocator, false );
|
||||||
|
result.Content = result.ADT.nodes[0].nodes;
|
||||||
return result;
|
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;
|
||||||
|
}
|
@ -7,20 +7,20 @@ global Code Code_Global;
|
|||||||
global Code Code_Invalid;
|
global Code Code_Invalid;
|
||||||
|
|
||||||
// This serializes all the data-members in a "debug" format, where each member is printed with its associated value.
|
// This serializes all the data-members in a "debug" format, where each member is printed with its associated value.
|
||||||
char const* code_debug_str(Code self)
|
StrC code_debug_str(Code self)
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self != nullptr);
|
GEN_ASSERT(self != nullptr);
|
||||||
String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
String result_stack = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||||
String* result = & result_stack;
|
String* result = & result_stack;
|
||||||
|
|
||||||
if ( self->Parent )
|
if ( self->Parent )
|
||||||
string_append_fmt( result, "\n\tParent : %S %S", code_type_str(self->Parent), self->Name ? self->Name : "" );
|
string_append_fmt( result, "\n\tParent : %SC %SC", code_type_str(self->Parent), self->Name.Len ? self->Name : txt("Null") );
|
||||||
else
|
else
|
||||||
string_append_fmt( result, "\n\tParent : %S", "Null" );
|
string_append_fmt( result, "\n\tParent : %SC", txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
|
string_append_fmt( result, "\n\tName : %SC", self->Name.Len ? self->Name : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tType : %S", code_type_str(self) );
|
string_append_fmt( result, "\n\tType : %SC", code_type_str(self) );
|
||||||
string_append_fmt( result, "\n\tModule Flags : %S", module_flag_to_str( self->ModuleFlags ) );
|
string_append_fmt( result, "\n\tModule Flags : %SC", module_flag_to_str( self->ModuleFlags ) );
|
||||||
|
|
||||||
switch ( self->Type )
|
switch ( self->Type )
|
||||||
{
|
{
|
||||||
@ -30,9 +30,9 @@ char const* code_debug_str(Code self)
|
|||||||
case CT_Access_Protected:
|
case CT_Access_Protected:
|
||||||
case CT_Access_Public:
|
case CT_Access_Public:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Untyped:
|
case CT_Untyped:
|
||||||
@ -48,74 +48,74 @@ char const* code_debug_str(Code self)
|
|||||||
case CT_Preprocess_IfDef:
|
case CT_Preprocess_IfDef:
|
||||||
case CT_Preprocess_IfNotDef:
|
case CT_Preprocess_IfNotDef:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tContent: %S", self->Content );
|
string_append_fmt( result, "\n\tContent: %SC", self->Content );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Class:
|
case CT_Class:
|
||||||
case CT_Struct:
|
case CT_Struct:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" );
|
string_append_fmt( result, "\n\tParentAccess: %SC", self->ParentType ? access_spec_to_str( self->ParentAccess ) : txt("No Parent") );
|
||||||
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
|
string_append_fmt( result, "\n\tParentType : %SC", self->ParentType ? code_type_str(self->ParentType) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Class_Fwd:
|
case CT_Class_Fwd:
|
||||||
case CT_Struct_Fwd:
|
case CT_Struct_Fwd:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" );
|
string_append_fmt( result, "\n\tParentAccess: %SC", self->ParentType ? access_spec_to_str( self->ParentAccess ) : txt("No Parent") );
|
||||||
string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" );
|
string_append_fmt( result, "\n\tParentType : %SC", self->ParentType ? code_type_str(self->ParentType) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Constructor:
|
case CT_Constructor:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? code_to_string(self->InitializerList) : "Null" );
|
string_append_fmt( result, "\n\tInitializerList: %SC", self->InitializerList ? string_to_strc( code_to_string(self->InitializerList) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Constructor_Fwd:
|
case CT_Constructor_Fwd:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? code_to_string(self->InitializerList) : "Null" );
|
string_append_fmt( result, "\n\tInitializerList: %SC", self->InitializerList ? string_to_strc( code_to_string(self->InitializerList) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params) ) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Destructor:
|
case CT_Destructor:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Destructor_Fwd:
|
case CT_Destructor_Fwd:
|
||||||
@ -124,142 +124,142 @@ char const* code_debug_str(Code self)
|
|||||||
case CT_Enum:
|
case CT_Enum:
|
||||||
case CT_Enum_Class:
|
case CT_Enum_Class:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
string_append_fmt( result, "\n\tUnderlying Type : %SC", self->UnderlyingType ? string_to_strc( code_to_string(self->UnderlyingType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Enum_Fwd:
|
case CT_Enum_Fwd:
|
||||||
case CT_Enum_Class_Fwd:
|
case CT_Enum_Class_Fwd:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
string_append_fmt( result, "\n\tUnderlying Type : %SC", self->UnderlyingType ? string_to_strc( code_to_string(self->UnderlyingType)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Extern_Linkage:
|
case CT_Extern_Linkage:
|
||||||
case CT_Namespace:
|
case CT_Namespace:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tBody: %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody: %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Friend:
|
case CT_Friend:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? code_to_string(self->Declaration) : "Null" );
|
string_append_fmt( result, "\n\tDeclaration: %SC", self->Declaration ? string_to_strc( code_to_string(self->Declaration)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Function:
|
case CT_Function:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes: %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
string_append_fmt( result, "\n\tReturnType: %SC", self->ReturnType ? string_to_strc( code_to_string(self->ReturnType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Function_Fwd:
|
case CT_Function_Fwd:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes: %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
string_append_fmt( result, "\n\tReturnType: %SC", self->ReturnType ? string_to_strc( code_to_string(self->ReturnType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Module:
|
case CT_Module:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Operator:
|
case CT_Operator:
|
||||||
case CT_Operator_Member:
|
case CT_Operator_Member:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes: %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
string_append_fmt( result, "\n\tReturnType: %SC", self->ReturnType ? string_to_strc( code_to_string(self->ReturnType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tOp : %S", operator_to_str( self->Op ) );
|
string_append_fmt( result, "\n\tOp : %SC", operator_to_str( self->Op ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Operator_Fwd:
|
case CT_Operator_Fwd:
|
||||||
case CT_Operator_Member_Fwd:
|
case CT_Operator_Member_Fwd:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes: %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
string_append_fmt( result, "\n\tReturnType: %SC", self->ReturnType ? string_to_strc( code_to_string(self->ReturnType) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tOp : %S", operator_to_str( self->Op ) );
|
string_append_fmt( result, "\n\tOp : %SC", operator_to_str( self->Op ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Operator_Cast:
|
case CT_Operator_Cast:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
string_append_fmt( result, "\n\tValueType : %SC", self->ValueType ? string_to_strc( code_to_string(self->ValueType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Operator_Cast_Fwd:
|
case CT_Operator_Cast_Fwd:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
string_append_fmt( result, "\n\tValueType : %SC", self->ValueType ? string_to_strc( code_to_string(self->ValueType)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Parameters:
|
case CT_Parameters:
|
||||||
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
|
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
|
||||||
string_append_fmt( result, "\n\tLast : %S", self->Last->Name );
|
string_append_fmt( result, "\n\tLast : %SC", self->Last->Name );
|
||||||
string_append_fmt( result, "\n\tNext : %S", self->Next->Name );
|
string_append_fmt( result, "\n\tNext : %SC", self->Next->Name );
|
||||||
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
string_append_fmt( result, "\n\tValueType : %SC", self->ValueType ? string_to_strc( code_to_string(self->ValueType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tValue : %S", self->Value ? code_to_string(self->Value) : "Null" );
|
string_append_fmt( result, "\n\tValue : %SC", self->Value ? string_to_strc( code_to_string(self->Value)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Specifiers:
|
case CT_Specifiers:
|
||||||
@ -275,57 +275,57 @@ char const* code_debug_str(Code self)
|
|||||||
string_append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
|
string_append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
string_append_fmt( result, "\n\tNextSpecs: %S", self->NextSpecs ? code_debug_str(self->NextSpecs) : "Null" );
|
string_append_fmt( result, "\n\tNextSpecs: %SC", self->NextSpecs ? code_debug_str(self->NextSpecs) : txt("Null") );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Template:
|
case CT_Template:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? code_to_string(self->Declaration) : "Null" );
|
string_append_fmt( result, "\n\tDeclaration: %SC", self->Declaration ? string_to_strc( code_to_string(self->Declaration)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Typedef:
|
case CT_Typedef:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
string_append_fmt( result, "\n\tUnderlyingType: %SC", self->UnderlyingType ? string_to_strc( code_to_string(self->UnderlyingType)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Typename:
|
case CT_Typename:
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? code_to_string(self->ReturnType) : "Null" );
|
string_append_fmt( result, "\n\tReturnType : %SC", self->ReturnType ? string_to_strc( code_to_string(self->ReturnType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tParams : %S", self->Params ? code_to_string(self->Params) : "Null" );
|
string_append_fmt( result, "\n\tParams : %SC", self->Params ? string_to_strc( code_to_string(self->Params)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? code_to_string(self->ArrExpr) : "Null" );
|
string_append_fmt( result, "\n\tArrExpr : %SC", self->ArrExpr ? string_to_strc( code_to_string(self->ArrExpr)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Union:
|
case CT_Union:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes: %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" );
|
string_append_fmt( result, "\n\tBody : %SC", self->Body ? code_debug_str(self->Body) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Using:
|
case CT_Using:
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? code_to_string(self->UnderlyingType) : "Null" );
|
string_append_fmt( result, "\n\tUnderlyingType: %SC", self->UnderlyingType ? string_to_strc( code_to_string(self->UnderlyingType)) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Variable:
|
case CT_Variable:
|
||||||
@ -333,29 +333,29 @@ char const* code_debug_str(Code self)
|
|||||||
if ( self->Parent && self->Parent->Type == CT_Variable )
|
if ( self->Parent && self->Parent->Type == CT_Variable )
|
||||||
{
|
{
|
||||||
// Its a NextVar
|
// Its a NextVar
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tValue : %S", self->Value ? code_to_string(self->Value) : "Null" );
|
string_append_fmt( result, "\n\tValue : %SC", self->Value ? string_to_strc( code_to_string(self->Value)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? code_to_string(self->BitfieldSize) : "Null" );
|
string_append_fmt( result, "\n\tBitfieldSize: %SC", self->BitfieldSize ? string_to_strc( code_to_string(self->BitfieldSize)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tNextVar : %S", self->NextVar ? code_debug_str(self->NextVar) : "Null" );
|
string_append_fmt( result, "\n\tNextVar : %SC", self->NextVar ? code_debug_str(self->NextVar) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self->Prev )
|
if ( self->Prev )
|
||||||
string_append_fmt( result, "\n\tPrev: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tPrev: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
if ( self->Next )
|
if ( self->Next )
|
||||||
string_append_fmt( result, "\n\tNext: %S %S", code_type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
|
string_append_fmt( result, "\n\tNext: %SC %SC", code_type_str(self->Prev), self->Prev->Name.Len ? self->Prev->Name : txt("Null") );
|
||||||
|
|
||||||
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
|
string_append_fmt( result, "\n\tInlineCmt : %SC", self->InlineCmt ? self->InlineCmt->Content : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" );
|
string_append_fmt( result, "\n\tAttributes : %SC", self->Attributes ? string_to_strc( code_to_string(self->Attributes) ) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? code_to_string(self->Specs) : "Null" );
|
string_append_fmt( result, "\n\tSpecs : %SC", self->Specs ? string_to_strc( code_to_string(self->Specs)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? code_to_string(self->ValueType) : "Null" );
|
string_append_fmt( result, "\n\tValueType : %SC", self->ValueType ? string_to_strc( code_to_string(self->ValueType)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? code_to_string(self->BitfieldSize) : "Null" );
|
string_append_fmt( result, "\n\tBitfieldSize: %SC", self->BitfieldSize ? string_to_strc( code_to_string(self->BitfieldSize)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tValue : %S", self->Value ? code_to_string(self->Value) : "Null" );
|
string_append_fmt( result, "\n\tValue : %SC", self->Value ? string_to_strc( code_to_string(self->Value)) : txt("Null") );
|
||||||
string_append_fmt( result, "\n\tNextVar : %S", self->NextVar ? code_debug_str(self->NextVar) : "Null" );
|
string_append_fmt( result, "\n\tNextVar : %SC", self->NextVar ? code_debug_str(self->NextVar) : txt("Null") );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return * result;
|
return string_to_strc( * result );
|
||||||
}
|
}
|
||||||
|
|
||||||
Code code_duplicate(Code self)
|
Code code_duplicate(Code self)
|
||||||
@ -366,7 +366,7 @@ Code code_duplicate(Code self)
|
|||||||
void* mem_self = rcast(void*, cast(AST*, self));
|
void* mem_self = rcast(void*, cast(AST*, self));
|
||||||
mem_copy( mem_result, mem_self, sizeof( AST ) );
|
mem_copy( mem_result, mem_self, sizeof( AST ) );
|
||||||
|
|
||||||
result->Parent = { nullptr };
|
result->Parent = NullCode;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +387,7 @@ void code_to_string_ptr( Code self, String* result )
|
|||||||
{
|
{
|
||||||
case CT_Invalid:
|
case CT_Invalid:
|
||||||
#ifdef GEN_DONT_ALLOW_INVALID_CODE
|
#ifdef GEN_DONT_ALLOW_INVALID_CODE
|
||||||
log_failure("Attempted to serialize invalid code! - %S", Parent ? Parent->code_debug_str() : Name );
|
log_failure("Attempted to serialize invalid code! - %SC", Parent ? Parent->code_debug_str() : Name );
|
||||||
#else
|
#else
|
||||||
string_append_fmt( result, "Invalid Code!" );
|
string_append_fmt( result, "Invalid Code!" );
|
||||||
#endif
|
#endif
|
||||||
@ -497,7 +497,7 @@ void code_to_string_ptr( Code self, String* result )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Parameters:
|
case CT_Parameters:
|
||||||
params_to_string_ref(cast(CodeParam, self), result );
|
params_to_string_ref(cast(CodeParams, self), result );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CT_Preprocess_Define:
|
case CT_Preprocess_Define:
|
||||||
@ -604,13 +604,13 @@ bool code_is_equal( Code self, Code other )
|
|||||||
*/
|
*/
|
||||||
if ( other == nullptr )
|
if ( other == nullptr )
|
||||||
{
|
{
|
||||||
log_fmt( "AST::is_equal: other is null\nAST: %S", code_debug_str(self) );
|
log_fmt( "AST::is_equal: other is null\nAST: %SC", code_debug_str(self) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self->Type != other->Type )
|
if ( self->Type != other->Type )
|
||||||
{
|
{
|
||||||
log_fmt("AST::is_equal: Type check failure with other\nAST: %S\nOther: %S"
|
log_fmt("AST::is_equal: Type check failure with other\nAST: %SC\nOther: %SC"
|
||||||
, code_debug_str(self)
|
, code_debug_str(self)
|
||||||
,code_debug_str(other)
|
,code_debug_str(other)
|
||||||
);
|
);
|
||||||
@ -624,8 +624,8 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( self->val != other->val ) \
|
if ( self->val != other->val ) \
|
||||||
{ \
|
{ \
|
||||||
log_fmt("\nAST::is_equal: Member - " #val " failed\n" \
|
log_fmt("\nAST::is_equal: Member - " #val " failed\n" \
|
||||||
"AST : %S\n" \
|
"AST : %SC\n" \
|
||||||
"Other: %S\n" \
|
"Other: %SC\n" \
|
||||||
, code_debug_str(self) \
|
, code_debug_str(self) \
|
||||||
,code_debug_str(other) \
|
,code_debug_str(other) \
|
||||||
); \
|
); \
|
||||||
@ -634,11 +634,11 @@ bool code_is_equal( Code self, Code other )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define check_member_str( str ) \
|
#define check_member_str( str ) \
|
||||||
if ( self->str != other->str ) \
|
if ( ! strc_are_equal( self->str, other->str ) ) \
|
||||||
{ \
|
{ \
|
||||||
log_fmt("\nAST::is_equal: Member string - "#str " failed\n" \
|
log_fmt("\nAST::is_equal: Member string - "#str " failed\n" \
|
||||||
"AST : %S\n" \
|
"AST : %SC\n" \
|
||||||
"Other: %S\n" \
|
"Other: %SC\n" \
|
||||||
, code_debug_str(self) \
|
, code_debug_str(self) \
|
||||||
,code_debug_str(other) \
|
,code_debug_str(other) \
|
||||||
); \
|
); \
|
||||||
@ -647,19 +647,19 @@ bool code_is_equal( Code self, Code other )
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define check_member_content( content ) \
|
#define check_member_content( content ) \
|
||||||
if ( self->content != other->content ) \
|
if ( ! strc_are_equal( self->content, other->content )) \
|
||||||
{ \
|
{ \
|
||||||
log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \
|
log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \
|
||||||
"AST : %S\n" \
|
"AST : %SC\n" \
|
||||||
"Other: %S\n" \
|
"Other: %SC\n" \
|
||||||
, code_debug_str(self) \
|
, code_debug_str(self) \
|
||||||
, code_debug_str(other) \
|
, code_debug_str(other) \
|
||||||
); \
|
); \
|
||||||
\
|
\
|
||||||
log_fmt("Content cannot be trusted to be unique with this check " \
|
log_fmt("Content cannot be trusted to be unique with this check " \
|
||||||
"so it must be verified by eye for now\n" \
|
"so it must be verified by eye for now\n" \
|
||||||
"AST Content:\n%S\n" \
|
"AST Content:\n%SC\n" \
|
||||||
"Other Content:\n%S\n" \
|
"Other Content:\n%SC\n" \
|
||||||
, strc_visualize_whitespace(self->content, GlobalAllocator) \
|
, strc_visualize_whitespace(self->content, GlobalAllocator) \
|
||||||
, strc_visualize_whitespace(other->content, GlobalAllocator) \
|
, strc_visualize_whitespace(other->content, GlobalAllocator) \
|
||||||
); \
|
); \
|
||||||
@ -671,9 +671,9 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( other->ast == nullptr ) \
|
if ( other->ast == nullptr ) \
|
||||||
{ \
|
{ \
|
||||||
log_fmt("\nAST::is_equal: Failed for member " #ast " other equivalent param is null\n" \
|
log_fmt("\nAST::is_equal: Failed for member " #ast " other equivalent param is null\n" \
|
||||||
"AST : %s\n" \
|
"AST : %SC\n" \
|
||||||
"Other: %s\n" \
|
"Other: %SC\n" \
|
||||||
"For ast member: %s\n" \
|
"For ast member: %SC\n" \
|
||||||
, code_debug_str(self) \
|
, code_debug_str(self) \
|
||||||
, code_debug_str(other) \
|
, code_debug_str(other) \
|
||||||
, code_debug_str(self->ast) \
|
, code_debug_str(self->ast) \
|
||||||
@ -685,10 +685,10 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( ! code_is_equal(self->ast, other->ast ) ) \
|
if ( ! code_is_equal(self->ast, other->ast ) ) \
|
||||||
{ \
|
{ \
|
||||||
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
|
log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \
|
||||||
"AST : %S\n" \
|
"AST : %SC\n" \
|
||||||
"Other: %S\n" \
|
"Other: %SC\n" \
|
||||||
"For ast member: %S\n" \
|
"For ast member: %SC\n" \
|
||||||
"other's ast member: %S\n" \
|
"other's ast member: %SC\n" \
|
||||||
, code_debug_str(self) \
|
, code_debug_str(self) \
|
||||||
, code_debug_str(other) \
|
, code_debug_str(other) \
|
||||||
, code_debug_str(self->ast) \
|
, code_debug_str(self->ast) \
|
||||||
@ -918,22 +918,22 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( curr_other == nullptr )
|
if ( curr_other == nullptr )
|
||||||
{
|
{
|
||||||
log_fmt("\nAST::is_equal: Failed for parameter, other equivalent param is null\n"
|
log_fmt("\nAST::is_equal: Failed for parameter, other equivalent param is null\n"
|
||||||
"AST : %S\n"
|
"AST : %SC\n"
|
||||||
"Other: %S\n"
|
"Other: %SC\n"
|
||||||
"For ast member: %S\n"
|
"For ast member: %SC\n"
|
||||||
, code_debug_str(curr)
|
, code_debug_str(curr)
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( curr->Name != curr_other->Name )
|
if ( strc_are_equal(curr->Name, curr_other->Name) )
|
||||||
{
|
{
|
||||||
log_fmt( "\nAST::is_equal: Failed for parameter name check\n"
|
log_fmt( "\nAST::is_equal: Failed for parameter name check\n"
|
||||||
"AST : %S\n"
|
"AST : %SC\n"
|
||||||
"Other: %S\n"
|
"Other: %SC\n"
|
||||||
"For ast member: %S\n"
|
"For ast member: %SC\n"
|
||||||
"other's ast member: %S\n"
|
"other's ast member: %SC\n"
|
||||||
, code_debug_str(self)
|
, code_debug_str(self)
|
||||||
, code_debug_str(other)
|
, code_debug_str(other)
|
||||||
, code_debug_str(curr)
|
, code_debug_str(curr)
|
||||||
@ -945,10 +945,10 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( curr->ValueType && ! code_is_equal(curr->ValueType, curr_other->ValueType) )
|
if ( curr->ValueType && ! code_is_equal(curr->ValueType, curr_other->ValueType) )
|
||||||
{
|
{
|
||||||
log_fmt( "\nAST::is_equal: Failed for parameter value type check\n"
|
log_fmt( "\nAST::is_equal: Failed for parameter value type check\n"
|
||||||
"AST : %S\n"
|
"AST : %SC\n"
|
||||||
"Other: %S\n"
|
"Other: %SC\n"
|
||||||
"For ast member: %S\n"
|
"For ast member: %SC\n"
|
||||||
"other's ast member: %S\n"
|
"other's ast member: %SC\n"
|
||||||
, code_debug_str(self)
|
, code_debug_str(self)
|
||||||
, code_debug_str(other)
|
, code_debug_str(other)
|
||||||
, code_debug_str(curr)
|
, code_debug_str(curr)
|
||||||
@ -960,10 +960,10 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( curr->Value && ! code_is_equal(curr->Value, curr_other->Value) )
|
if ( curr->Value && ! code_is_equal(curr->Value, curr_other->Value) )
|
||||||
{
|
{
|
||||||
log_fmt( "\nAST::is_equal: Failed for parameter value check\n"
|
log_fmt( "\nAST::is_equal: Failed for parameter value check\n"
|
||||||
"AST : %S\n"
|
"AST : %SC\n"
|
||||||
"Other: %S\n"
|
"Other: %SC\n"
|
||||||
"For ast member: %S\n"
|
"For ast member: %SC\n"
|
||||||
"other's ast member: %S\n"
|
"other's ast member: %SC\n"
|
||||||
, code_debug_str(self)
|
, code_debug_str(self)
|
||||||
, code_debug_str(other)
|
, code_debug_str(other)
|
||||||
, code_debug_str(curr)
|
, code_debug_str(curr)
|
||||||
@ -1117,10 +1117,10 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( curr_other == nullptr )
|
if ( curr_other == nullptr )
|
||||||
{
|
{
|
||||||
log_fmt("\nAST::is_equal: Failed for body, other equivalent param is null\n"
|
log_fmt("\nAST::is_equal: Failed for body, other equivalent param is null\n"
|
||||||
"AST : %S\n"
|
"AST : %SC\n"
|
||||||
"Other: %S\n"
|
"Other: %SC\n"
|
||||||
"For ast member: %S\n"
|
|
||||||
, code_debug_str(curr)
|
, code_debug_str(curr)
|
||||||
|
, code_debug_str(other)
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1129,10 +1129,10 @@ bool code_is_equal( Code self, Code other )
|
|||||||
if ( ! code_is_equal( curr, curr_other ) )
|
if ( ! code_is_equal( curr, curr_other ) )
|
||||||
{
|
{
|
||||||
log_fmt( "\nAST::is_equal: Failed for body\n"
|
log_fmt( "\nAST::is_equal: Failed for body\n"
|
||||||
"AST : %S\n"
|
"AST : %SC\n"
|
||||||
"Other: %S\n"
|
"Other: %SC\n"
|
||||||
"For ast member: %S\n"
|
"For ast member: %SC\n"
|
||||||
"other's ast member: %S\n"
|
"other's ast member: %SC\n"
|
||||||
, code_debug_str(self)
|
, code_debug_str(self)
|
||||||
, code_debug_str(other)
|
, code_debug_str(other)
|
||||||
, code_debug_str(curr)
|
, code_debug_str(curr)
|
||||||
@ -1170,7 +1170,7 @@ bool code_validate_body(Code self)
|
|||||||
switch ( code_entry->Type ) \
|
switch ( code_entry->Type ) \
|
||||||
{ \
|
{ \
|
||||||
Unallowed_Types \
|
Unallowed_Types \
|
||||||
log_failure( "AST::validate_body: Invalid entry in body %s", code_debug_str(code_entry) ); \
|
log_failure( "AST::validate_body: Invalid entry in body %SC", code_debug_str(code_entry) ); \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@ -1191,7 +1191,7 @@ bool code_validate_body(Code self)
|
|||||||
{
|
{
|
||||||
if ( entry->Type != CT_Untyped )
|
if ( entry->Type != CT_Untyped )
|
||||||
{
|
{
|
||||||
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", GEN_NS code_debug_str(entry) );
|
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %SC", code_debug_str(entry) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1236,7 +1236,7 @@ bool code_validate_body(Code self)
|
|||||||
case CT_Specifiers:
|
case CT_Specifiers:
|
||||||
case CT_Struct_Body:
|
case CT_Struct_Body:
|
||||||
case CT_Typename:
|
case CT_Typename:
|
||||||
log_failure("AST::validate_body: Invalid entry in body %s", GEN_NS code_debug_str(entry));
|
log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(entry));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1259,7 +1259,7 @@ bool code_validate_body(Code self)
|
|||||||
{
|
{
|
||||||
if ( entry->Type != CT_Untyped )
|
if ( entry->Type != CT_Untyped )
|
||||||
{
|
{
|
||||||
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", GEN_NS code_debug_str(entry) );
|
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %SC", code_debug_str(entry) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1267,7 +1267,7 @@ bool code_validate_body(Code self)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", code_debug_str(self) );
|
log_failure( "AST::validate_body: Invalid this AST does not have a body %SC", code_debug_str(self) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -6,6 +6,18 @@
|
|||||||
#include "gen/especifier.hpp"
|
#include "gen/especifier.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
______ ______ ________ __ __ ______ __
|
||||||
|
/ \ / \| \ | \ | \ / \ | \
|
||||||
|
| ▓▓▓▓▓▓\ ▓▓▓▓▓▓\\▓▓▓▓▓▓▓▓ | ▓▓\ | ▓▓ | ▓▓▓▓▓▓\ ______ ____| ▓▓ ______
|
||||||
|
| ▓▓__| ▓▓ ▓▓___\▓▓ | ▓▓ | ▓▓▓\| ▓▓ | ▓▓ \▓▓/ \ / ▓▓/ \
|
||||||
|
| ▓▓ ▓▓\▓▓ \ | ▓▓ | ▓▓▓▓\ ▓▓ | ▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\
|
||||||
|
| ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\ | ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓ __| ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ ▓▓
|
||||||
|
| ▓▓ | ▓▓ \__| ▓▓ | ▓▓ | ▓▓ \▓▓▓▓ | ▓▓__/ \ ▓▓__/ ▓▓ ▓▓__| ▓▓ ▓▓▓▓▓▓▓▓
|
||||||
|
| ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓ | ▓▓ \▓▓▓ \▓▓ ▓▓\▓▓ ▓▓\▓▓ ▓▓\▓▓ \
|
||||||
|
\▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
||||||
|
*/
|
||||||
|
|
||||||
struct AST;
|
struct AST;
|
||||||
struct AST_Body;
|
struct AST_Body;
|
||||||
struct AST_Attributes;
|
struct AST_Attributes;
|
||||||
@ -25,7 +37,7 @@ struct AST_Module;
|
|||||||
struct AST_NS;
|
struct AST_NS;
|
||||||
struct AST_Operator;
|
struct AST_Operator;
|
||||||
struct AST_OpCast;
|
struct AST_OpCast;
|
||||||
struct AST_Param;
|
struct AST_Params;
|
||||||
struct AST_Pragma;
|
struct AST_Pragma;
|
||||||
struct AST_PreprocessCond;
|
struct AST_PreprocessCond;
|
||||||
struct AST_Specifiers;
|
struct AST_Specifiers;
|
||||||
@ -73,84 +85,150 @@ struct AST_Union;
|
|||||||
struct AST_Using;
|
struct AST_Using;
|
||||||
struct AST_Var;
|
struct AST_Var;
|
||||||
|
|
||||||
#if GEN_COMPILER_C
|
|
||||||
#define Define_Code(Type) typedef AST_##Type* Code##Type
|
|
||||||
#else
|
|
||||||
#define Define_Code(Type) struct Code##Type
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if GEN_COMPILER_C
|
#if GEN_COMPILER_C
|
||||||
typedef AST* Code;
|
typedef AST* Code;
|
||||||
#else
|
#else
|
||||||
struct Code;
|
struct Code;
|
||||||
#endif
|
#endif
|
||||||
Define_Code(Body);
|
|
||||||
// These are to offer ease of use and optionally strong type safety for the AST.
|
|
||||||
Define_Code(Attributes);
|
|
||||||
// struct CodeBaseClass;
|
|
||||||
Define_Code(Comment);
|
|
||||||
Define_Code(Class);
|
|
||||||
Define_Code(Constructor);
|
|
||||||
Define_Code(Define);
|
|
||||||
Define_Code(Destructor);
|
|
||||||
Define_Code(Enum);
|
|
||||||
Define_Code(Exec);
|
|
||||||
Define_Code(Extern);
|
|
||||||
Define_Code(Include);
|
|
||||||
Define_Code(Friend);
|
|
||||||
Define_Code(Fn);
|
|
||||||
Define_Code(Module);
|
|
||||||
Define_Code(NS);
|
|
||||||
Define_Code(Operator);
|
|
||||||
Define_Code(OpCast);
|
|
||||||
Define_Code(Param);
|
|
||||||
Define_Code(PreprocessCond);
|
|
||||||
Define_Code(Pragma);
|
|
||||||
Define_Code(Specifiers);
|
|
||||||
|
|
||||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
#if GEN_COMPILER_C
|
||||||
Define_Code(Expr);
|
typedef AST_Body* CodeBody;
|
||||||
Define_Code(Expr_Assign);
|
typedef AST_Attributes* CodeAttributes;
|
||||||
Define_Code(Expr_Alignof);
|
typedef AST_Comment* CodeComment;
|
||||||
Define_Code(Expr_Binary);
|
typedef AST_Class* CodeClass;
|
||||||
Define_Code(Expr_CStyleCast);
|
typedef AST_Constructor* CodeConstructor;
|
||||||
Define_Code(Expr_FunctionalCast);
|
typedef AST_Define* CodeDefine;
|
||||||
Define_Code(Expr_CppCast);
|
typedef AST_Destructor* CodeDestructor;
|
||||||
Define_Code(Expr_Element);
|
typedef AST_Enum* CodeEnum;
|
||||||
Define_Code(Expr_ProcCall);
|
typedef AST_Exec* CodeExec;
|
||||||
Define_Code(Expr_Decltype);
|
typedef AST_Extern* CodeExtern;
|
||||||
Define_Code(Expr_Comma);
|
typedef AST_Include* CodeInclude;
|
||||||
Define_Code(Expr_AMS); // Access Member Symbol
|
typedef AST_Friend* CodeFriend;
|
||||||
Define_Code(Expr_Sizeof);
|
typedef AST_Fn* CodeFn;
|
||||||
Define_Code(Expr_Subscript);
|
typedef AST_Module* CodeModule;
|
||||||
Define_Code(Expr_Ternary);
|
typedef AST_NS* CodeNS;
|
||||||
Define_Code(Expr_UnaryPrefix);
|
typedef AST_Operator* CodeOperator;
|
||||||
Define_Code(Expr_UnaryPostfix);
|
typedef AST_OpCast* CodeOpCast;
|
||||||
|
typedef AST_Params* CodeParams;
|
||||||
Define_Code(Stmt);
|
typedef AST_PreprocessCond* CodePreprocessCond;
|
||||||
Define_Code(Stmt_Break);
|
typedef AST_Pragma* CodePragma;
|
||||||
Define_Code(Stmt_Case);
|
typedef AST_Specifiers* CodeSpecifiers;
|
||||||
Define_Code(Stmt_Continue);
|
#else
|
||||||
Define_Code(Stmt_Decl);
|
struct CodeBody;
|
||||||
Define_Code(Stmt_Do);
|
struct CodeAttributes;
|
||||||
Define_Code(Stmt_Expr);
|
struct CodeComment;
|
||||||
Define_Code(Stmt_Else);
|
struct CodeClass;
|
||||||
Define_Code(Stmt_If);
|
struct CodeConstructor;
|
||||||
Define_Code(Stmt_For);
|
struct CodeDefine;
|
||||||
Define_Code(Stmt_Goto);
|
struct CodeDestructor;
|
||||||
Define_Code(Stmt_Label);
|
struct CodeEnum;
|
||||||
Define_Code(Stmt_Switch);
|
struct CodeExec;
|
||||||
Define_Code(Stmt_While);
|
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
|
#endif
|
||||||
|
|
||||||
Define_Code(Struct);
|
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||||
Define_Code(Template);
|
|
||||||
Define_Code(Typename);
|
#if GEN_COMPILER_C
|
||||||
Define_Code(Typedef);
|
typedef AST_Expr* CodeExpr;
|
||||||
Define_Code(Union);
|
typedef AST_Expr_Assign* CodeExpr_Assign;
|
||||||
Define_Code(Using);
|
typedef AST_Expr_Alignof* CodeExpr_Alignof;
|
||||||
Define_Code(Var);
|
typedef AST_Expr_Binary* CodeExpr_Binary;
|
||||||
#undef Define_Code
|
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
|
GEN_NS_PARSER_BEGIN
|
||||||
|
|
||||||
@ -172,8 +250,9 @@ template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma region Code C-Interface
|
#pragma region Code C-Interface
|
||||||
|
|
||||||
void code_append (Code code, Code other );
|
void code_append (Code code, Code other );
|
||||||
char const* code_debug_str (Code code);
|
StrC code_debug_str (Code code);
|
||||||
Code code_duplicate (Code code);
|
Code code_duplicate (Code code);
|
||||||
Code* code_entry (Code code, u32 idx );
|
Code* code_entry (Code code, u32 idx );
|
||||||
bool code_has_entries (Code code);
|
bool code_has_entries (Code code);
|
||||||
@ -183,8 +262,9 @@ bool code_is_valid (Code code);
|
|||||||
void code_set_global (Code code);
|
void code_set_global (Code code);
|
||||||
String code_to_string (Code self );
|
String code_to_string (Code self );
|
||||||
void code_to_string_ptr(Code self, String* result );
|
void code_to_string_ptr(Code self, String* result );
|
||||||
char const* code_type_str (Code self );
|
StrC code_type_str (Code self );
|
||||||
bool code_validate_body(Code self );
|
bool code_validate_body(Code self );
|
||||||
|
|
||||||
#pragma endregion Code C-Interface
|
#pragma endregion Code C-Interface
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP
|
#if GEN_COMPILER_CPP
|
||||||
@ -198,7 +278,7 @@ struct Code
|
|||||||
AST* ast;
|
AST* ast;
|
||||||
|
|
||||||
# define Using_Code( Typename ) \
|
# define Using_Code( Typename ) \
|
||||||
forceinline char const* debug_str() { return code_debug_str(* this); } \
|
forceinline StrC debug_str() { return code_debug_str(* this); } \
|
||||||
forceinline Code duplicate() { return code_duplicate(* this); } \
|
forceinline Code duplicate() { return code_duplicate(* this); } \
|
||||||
forceinline bool is_equal( Code other ) { return code_is_equal(* this, other); } \
|
forceinline bool is_equal( Code other ) { return code_is_equal(* this, other); } \
|
||||||
forceinline bool is_body() { return code_is_body(* this); } \
|
forceinline bool is_body() { return code_is_body(* this); } \
|
||||||
@ -220,7 +300,7 @@ struct Code
|
|||||||
forceinline bool has_entries() { return code_has_entries(* this); }
|
forceinline bool has_entries() { return code_has_entries(* this); }
|
||||||
forceinline String to_string() { return code_to_string(* this); }
|
forceinline String to_string() { return code_to_string(* this); }
|
||||||
forceinline void to_string(String& result) { return code_to_string_ptr(* this, & result); }
|
forceinline void to_string(String& result) { return code_to_string_ptr(* this, & result); }
|
||||||
forceinline char const* type_str() { return code_type_str(* this); }
|
forceinline StrC type_str() { return code_type_str(* this); }
|
||||||
forceinline bool validate_body() { return code_validate_body(*this); }
|
forceinline bool validate_body() { return code_validate_body(*this); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -229,18 +309,6 @@ struct Code
|
|||||||
|
|
||||||
Code& operator ++();
|
Code& operator ++();
|
||||||
|
|
||||||
// TODO(Ed) : Remove this overload.
|
|
||||||
auto& operator*()
|
|
||||||
{
|
|
||||||
local_persist thread_local
|
|
||||||
Code NullRef = { nullptr };
|
|
||||||
|
|
||||||
if ( ast == nullptr )
|
|
||||||
return NullRef;
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||||
# define operator explicit operator
|
# define operator explicit operator
|
||||||
#endif
|
#endif
|
||||||
@ -262,7 +330,7 @@ struct Code
|
|||||||
operator CodeNS() const;
|
operator CodeNS() const;
|
||||||
operator CodeOperator() const;
|
operator CodeOperator() const;
|
||||||
operator CodeOpCast() const;
|
operator CodeOpCast() const;
|
||||||
operator CodeParam() const;
|
operator CodeParams() const;
|
||||||
operator CodePragma() const;
|
operator CodePragma() const;
|
||||||
operator CodePreprocessCond() const;
|
operator CodePreprocessCond() const;
|
||||||
operator CodeSpecifiers() const;
|
operator CodeSpecifiers() const;
|
||||||
@ -298,10 +366,11 @@ constexpr static
|
|||||||
int AST_ArrSpecs_Cap =
|
int AST_ArrSpecs_Cap =
|
||||||
(
|
(
|
||||||
AST_POD_Size
|
AST_POD_Size
|
||||||
|
- sizeof(Code)
|
||||||
- sizeof(StringCached)
|
- sizeof(StringCached)
|
||||||
- sizeof(AST*) * 3
|
- sizeof(Code) * 2
|
||||||
- sizeof(Token*)
|
- sizeof(Token*)
|
||||||
- sizeof(AST*)
|
- sizeof(Code)
|
||||||
- sizeof(CodeType)
|
- sizeof(CodeType)
|
||||||
- sizeof(ModuleFlag)
|
- sizeof(ModuleFlag)
|
||||||
- sizeof(u32)
|
- sizeof(u32)
|
||||||
@ -367,11 +436,14 @@ struct AST
|
|||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
union {
|
union {
|
||||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
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.
|
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;
|
Operator Op;
|
||||||
AccessSpec ParentAccess;
|
AccessSpec ParentAccess;
|
||||||
s32 NumEntries;
|
s32 NumEntries;
|
||||||
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
|
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" );
|
static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST is not size of AST_POD_Size" );
|
||||||
@ -382,7 +454,7 @@ static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST is not size of AST_POD_S
|
|||||||
struct InvalidCode_ImplictCaster;
|
struct InvalidCode_ImplictCaster;
|
||||||
#define InvalidCode (InvalidCode_ImplictCaster{})
|
#define InvalidCode (InvalidCode_ImplictCaster{})
|
||||||
#else
|
#else
|
||||||
#define InvalidCode { (void*)Code_Invalid }
|
#define InvalidCode (void*){ (void*)Code_Invalid }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP
|
#if GEN_COMPILER_CPP
|
@ -4,6 +4,22 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma region AST Types
|
#pragma region AST Types
|
||||||
|
|
||||||
|
/*
|
||||||
|
______ ______ ________ ________
|
||||||
|
/ \ / \| \ | \
|
||||||
|
| ▓▓▓▓▓▓\ ▓▓▓▓▓▓\\▓▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓▓__ __ ______ ______ _______
|
||||||
|
| ▓▓__| ▓▓ ▓▓___\▓▓ | ▓▓ | ▓▓ | \ | \/ \ / \ / \
|
||||||
|
| ▓▓ ▓▓\▓▓ \ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓
|
||||||
|
| ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\ | ▓▓ | ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ ▓▓\▓▓ \
|
||||||
|
| ▓▓ | ▓▓ \__| ▓▓ | ▓▓ | ▓▓ | ▓▓__/ ▓▓ ▓▓__/ ▓▓ ▓▓▓▓▓▓▓▓_\▓▓▓▓▓▓\
|
||||||
|
| ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓ | ▓▓ \▓▓ ▓▓ ▓▓ ▓▓\▓▓ \ ▓▓
|
||||||
|
\▓▓ \▓▓ \▓▓▓▓▓▓ \▓▓ \▓▓ _\▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓▓▓▓▓▓
|
||||||
|
| \__| ▓▓ ▓▓
|
||||||
|
\▓▓ ▓▓ ▓▓
|
||||||
|
\▓▓▓▓▓▓ \▓▓
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Show only relevant members of the AST for its type.
|
Show only relevant members of the AST for its type.
|
||||||
AST* fields are replaced with Code types.
|
AST* fields are replaced with Code types.
|
||||||
@ -12,7 +28,9 @@
|
|||||||
|
|
||||||
struct AST_Body
|
struct AST_Body
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||||
|
};
|
||||||
StringCached Name;
|
StringCached Name;
|
||||||
Code Front;
|
Code Front;
|
||||||
Code Back;
|
Code Back;
|
||||||
@ -109,7 +127,7 @@ struct AST_Constructor
|
|||||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
Code InitializerList;
|
Code InitializerList;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
Code Body;
|
Code Body;
|
||||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||||
};
|
};
|
||||||
@ -532,7 +550,7 @@ struct AST_Fn
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeTypename ReturnType;
|
CodeTypename ReturnType;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||||
};
|
};
|
||||||
@ -550,7 +568,9 @@ static_assert( sizeof(AST_Fn) == sizeof(AST), "ERROR: AST_Fn is not the same siz
|
|||||||
|
|
||||||
struct AST_Module
|
struct AST_Module
|
||||||
{
|
{
|
||||||
|
union {
|
||||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||||
|
};
|
||||||
StringCached Name;
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
@ -593,7 +613,7 @@ struct AST_Operator
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeTypename ReturnType;
|
CodeTypename ReturnType;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||||
};
|
};
|
||||||
@ -634,7 +654,7 @@ struct AST_OpCast
|
|||||||
};
|
};
|
||||||
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
||||||
|
|
||||||
struct AST_Param
|
struct AST_Params
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||||
@ -649,15 +669,15 @@ struct AST_Param
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
StringCached Name;
|
StringCached Name;
|
||||||
CodeParam Last;
|
CodeParams Last;
|
||||||
CodeParam Next;
|
CodeParams Next;
|
||||||
Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
CodeType Type;
|
CodeType Type;
|
||||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||||
s32 NumEntries;
|
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
|
struct AST_Pragma
|
||||||
{
|
{
|
||||||
@ -951,7 +971,7 @@ struct AST_Template
|
|||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
Code Declaration;
|
Code Declaration;
|
||||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||||
};
|
};
|
||||||
@ -980,7 +1000,7 @@ struct AST_Type
|
|||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
Code QualifierID;
|
Code QualifierID;
|
||||||
// CodeTypename ReturnType; // Only used for function signatures
|
// CodeTypename ReturnType; // Only used for function signatures
|
||||||
// CodeParam Params; // Only used for function signatures
|
// CodeParams Params; // Only used for function signatures
|
||||||
Code ArrExpr;
|
Code ArrExpr;
|
||||||
// CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
// CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||||
};
|
};
|
||||||
@ -1007,7 +1027,7 @@ struct AST_Typename
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeTypename ReturnType; // Only used for function signatures
|
CodeTypename ReturnType; // Only used for function signatures
|
||||||
CodeParam Params; // Only used for function signatures
|
CodeParams Params; // Only used for function signatures
|
||||||
Code ArrExpr;
|
Code ArrExpr;
|
||||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||||
};
|
};
|
||||||
@ -1019,7 +1039,10 @@ struct AST_Typename
|
|||||||
Code Parent;
|
Code Parent;
|
||||||
CodeType Type;
|
CodeType Type;
|
||||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
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");
|
static_assert( sizeof(AST_Typename) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
|
||||||
|
|
||||||
@ -1116,7 +1139,7 @@ struct AST_Var
|
|||||||
Code Parent;
|
Code Parent;
|
||||||
CodeType Type;
|
CodeType Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
s32 VarConstructorInit;
|
s32 VarParenthesizedInit;
|
||||||
};
|
};
|
||||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||||
|
|
@ -3,13 +3,15 @@
|
|||||||
#include "ast.cpp"
|
#include "ast.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
forceinline
|
inline
|
||||||
String attributes_to_string(CodeAttributes attributes) {
|
String attributes_to_string(CodeAttributes attributes) {
|
||||||
GEN_ASSERT(attributes);
|
GEN_ASSERT(attributes);
|
||||||
return {(char*) strc_duplicate( attributes->Content, GlobalAllocator ).Ptr};
|
char* raw = ccast(char*, strc_duplicate( attributes->Content, GlobalAllocator ).Ptr);
|
||||||
|
String result = { raw };
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
inline
|
||||||
void attributes_to_string_ref(CodeAttributes attributes, String* result) {
|
void attributes_to_string_ref(CodeAttributes attributes, String* result) {
|
||||||
GEN_ASSERT(attributes);
|
GEN_ASSERT(attributes);
|
||||||
GEN_ASSERT(result);
|
GEN_ASSERT(result);
|
||||||
@ -77,13 +79,15 @@ void body_to_string_export( CodeBody body, String* result )
|
|||||||
string_append_fmt( result, "};\n" );
|
string_append_fmt( result, "};\n" );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
inline
|
||||||
String comment_to_string(CodeComment comment) {
|
String comment_to_string(CodeComment comment) {
|
||||||
GEN_ASSERT(comment);
|
GEN_ASSERT(comment);
|
||||||
return {(char*) strc_duplicate( comment->Content, GlobalAllocator ).Ptr};
|
char* raw = ccast(char*, strc_duplicate( comment->Content, GlobalAllocator ).Ptr);
|
||||||
|
String result = { raw };
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
inline
|
||||||
void comment_to_string_ref(CodeComment comment, String* result) {
|
void comment_to_string_ref(CodeComment comment, String* result) {
|
||||||
GEN_ASSERT(comment);
|
GEN_ASSERT(comment);
|
||||||
GEN_ASSERT(result);
|
GEN_ASSERT(result);
|
||||||
@ -184,9 +188,8 @@ void class_to_string_def( CodeClass self, String* result )
|
|||||||
|
|
||||||
if ( self->ParentType )
|
if ( self->ParentType )
|
||||||
{
|
{
|
||||||
char const* access_level = access_spec_to_str( self->ParentAccess );
|
StrC access_level = access_spec_to_str( self->ParentAccess );
|
||||||
|
string_append_fmt( result, "%SC : %SC %S", self->Name, access_level, typename_to_string(self->ParentType) );
|
||||||
string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) );
|
|
||||||
|
|
||||||
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
||||||
if ( interface )
|
if ( interface )
|
||||||
@ -194,11 +197,11 @@ void class_to_string_def( CodeClass self, String* result )
|
|||||||
|
|
||||||
while ( interface )
|
while ( interface )
|
||||||
{
|
{
|
||||||
string_append_fmt( result, ", %S", typename_to_string(interface) );
|
string_append_fmt( result, ", public %S", typename_to_string(interface) );
|
||||||
interface = interface->Next ? cast(CodeTypename, interface->Next) : CodeTypename { nullptr };
|
interface = interface->Next ? cast(CodeTypename, interface->Next) : NullCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( self->Name )
|
else if ( self->Name.Len )
|
||||||
{
|
{
|
||||||
string_append_strc( result, self->Name );
|
string_append_strc( result, self->Name );
|
||||||
}
|
}
|
||||||
@ -263,7 +266,7 @@ String destructor_to_string(CodeDestructor self)
|
|||||||
|
|
||||||
void destructor_to_string_def(CodeDestructor self, String* result )
|
void destructor_to_string_def(CodeDestructor self, String* result )
|
||||||
{
|
{
|
||||||
if ( self->Name )
|
if ( self->Name.Len )
|
||||||
{
|
{
|
||||||
string_append_fmt( result, "%SC()", self->Name );
|
string_append_fmt( result, "%SC()", self->Name );
|
||||||
}
|
}
|
||||||
@ -343,7 +346,7 @@ void enum_to_string_def(CodeEnum self, String* result )
|
|||||||
, body_to_string(self->Body)
|
, body_to_string(self->Body)
|
||||||
);
|
);
|
||||||
else if ( self->UnderlyingTypeMacro )
|
else if ( self->UnderlyingTypeMacro )
|
||||||
string_append_fmt( result, "%SC %S\n\n{\n%S\n}"
|
string_append_fmt( result, "%SC %S\n{\n%S\n}"
|
||||||
, self->Name
|
, self->Name
|
||||||
, code_to_string(self->UnderlyingTypeMacro)
|
, code_to_string(self->UnderlyingTypeMacro)
|
||||||
, body_to_string(self->Body)
|
, body_to_string(self->Body)
|
||||||
@ -439,7 +442,10 @@ void enum_to_string_class_fwd(CodeEnum self, String* result )
|
|||||||
|
|
||||||
String exec_to_string(CodeExec exec)
|
String exec_to_string(CodeExec exec)
|
||||||
{
|
{
|
||||||
return {(char*) strc_duplicate( exec->Content, GlobalAllocator ).Ptr};
|
GEN_ASSERT(exec);
|
||||||
|
char* raw = ccast(char*, strc_duplicate( exec->Content, GlobalAllocator ).Ptr);
|
||||||
|
String result = { raw };
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void extern_to_string(CodeExtern self, String* result )
|
void extern_to_string(CodeExtern self, String* result )
|
||||||
@ -622,10 +628,10 @@ String module_to_string(CodeModule self)
|
|||||||
|
|
||||||
void module_to_string_ref(CodeModule self, String* result )
|
void module_to_string_ref(CodeModule self, String* result )
|
||||||
{
|
{
|
||||||
if (((u32(ModuleFlag_Export) & u32(self->ModuleFlags)) == u32(ModuleFlag_Export)))
|
if (((scast(u32, ModuleFlag_Export) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Export)))
|
||||||
string_append_strc( result, txt("export "));
|
string_append_strc( result, txt("export "));
|
||||||
|
|
||||||
if (((u32(ModuleFlag_Import) & u32(self->ModuleFlags)) == u32(ModuleFlag_Import)))
|
if (((scast(u32, ModuleFlag_Import) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Import)))
|
||||||
string_append_strc( result, txt("import "));
|
string_append_strc( result, txt("import "));
|
||||||
|
|
||||||
string_append_fmt( result, "%SC;\n", self->Name );
|
string_append_fmt( result, "%SC;\n", self->Name );
|
||||||
@ -796,7 +802,7 @@ void opcast_to_string_def(CodeOpCast self, String* result )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self->Name && self->Name.Len )
|
if ( self->Name.Ptr && self->Name.Len )
|
||||||
string_append_fmt( result, "%SC operator %S()", self->Name, typename_to_string(self->ValueType) );
|
string_append_fmt( result, "%SC operator %S()", self->Name, typename_to_string(self->ValueType) );
|
||||||
else
|
else
|
||||||
string_append_fmt( result, "operator %S()", typename_to_string(self->ValueType) );
|
string_append_fmt( result, "operator %S()", typename_to_string(self->ValueType) );
|
||||||
@ -814,7 +820,7 @@ void opcast_to_string_def(CodeOpCast self, String* result )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self->Name && self->Name.Len )
|
if ( self->Name.Ptr && self->Name.Len )
|
||||||
string_append_fmt( result, "%SC operator %S()\n{\n%S\n}\n", self->Name, typename_to_string(self->ValueType), body_to_string(self->Body) );
|
string_append_fmt( result, "%SC operator %S()\n{\n%S\n}\n", self->Name, typename_to_string(self->ValueType), body_to_string(self->Body) );
|
||||||
else
|
else
|
||||||
string_append_fmt( result, "operator %S()\n{\n%S\n}\n", typename_to_string(self->ValueType), body_to_string(self->Body) );
|
string_append_fmt( result, "operator %S()\n{\n%S\n}\n", typename_to_string(self->ValueType), body_to_string(self->Body) );
|
||||||
@ -857,7 +863,7 @@ void opcast_to_string_fwd(CodeOpCast self, String* result )
|
|||||||
string_append_fmt( result, "operator %S();\n", typename_to_string(self->ValueType) );
|
string_append_fmt( result, "operator %S();\n", typename_to_string(self->ValueType) );
|
||||||
}
|
}
|
||||||
|
|
||||||
String params_to_string(CodeParam self)
|
String params_to_string(CodeParams self)
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
@ -866,7 +872,7 @@ String params_to_string(CodeParam self)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void params_to_string_ref( CodeParam self, String* result )
|
void params_to_string_ref( CodeParams self, String* result )
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
GEN_ASSERT(result);
|
GEN_ASSERT(result);
|
||||||
@ -877,7 +883,7 @@ void params_to_string_ref( CodeParam self, String* result )
|
|||||||
// Could also be: ( <macro> <type <name>, ... )
|
// Could also be: ( <macro> <type <name>, ... )
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( self->Name )
|
if ( self->Name.Ptr && self->Name.Len )
|
||||||
{
|
{
|
||||||
if ( self->ValueType == nullptr )
|
if ( self->ValueType == nullptr )
|
||||||
string_append_fmt( result, " %SC", self->Name );
|
string_append_fmt( result, " %SC", self->Name );
|
||||||
@ -898,7 +904,7 @@ void params_to_string_ref( CodeParam self, String* result )
|
|||||||
|
|
||||||
if ( self->NumEntries - 1 > 0 )
|
if ( self->NumEntries - 1 > 0 )
|
||||||
{
|
{
|
||||||
for ( CodeParam param = begin_CodeParam(self->Next); param != end_CodeParam(self->Next); param = next_CodeParam(self->Next, param) )
|
for ( CodeParams param = begin_CodeParams(self->Next); param != end_CodeParams(self->Next); param = next_CodeParams(self->Next, param) )
|
||||||
{
|
{
|
||||||
string_append_fmt( result, ", %S", params_to_string(param) );
|
string_append_fmt( result, ", %S", params_to_string(param) );
|
||||||
}
|
}
|
||||||
@ -1036,9 +1042,9 @@ void struct_to_string_def( CodeStruct self, String* result )
|
|||||||
|
|
||||||
if ( self->ParentType )
|
if ( self->ParentType )
|
||||||
{
|
{
|
||||||
char const* access_level = access_spec_to_str( self->ParentAccess );
|
StrC access_level = access_spec_to_str( self->ParentAccess );
|
||||||
|
|
||||||
string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) );
|
string_append_fmt( result, "%SC : %SC %S", self->Name, access_level, typename_to_string(self->ParentType) );
|
||||||
|
|
||||||
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
||||||
if ( interface )
|
if ( interface )
|
||||||
@ -1047,10 +1053,10 @@ void struct_to_string_def( CodeStruct self, String* result )
|
|||||||
while ( interface )
|
while ( interface )
|
||||||
{
|
{
|
||||||
string_append_fmt( result, ", %S", typename_to_string(interface) );
|
string_append_fmt( result, ", %S", typename_to_string(interface) );
|
||||||
interface = interface->Next ? cast( CodeTypename, interface->Next) : CodeTypename { nullptr };
|
interface = interface->Next ? cast( CodeTypename, interface->Next) : NullCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( self->Name )
|
else if ( self->Name.Len )
|
||||||
{
|
{
|
||||||
string_append_strc( result, self->Name );
|
string_append_strc( result, self->Name );
|
||||||
}
|
}
|
||||||
@ -1194,6 +1200,16 @@ void typename_to_string_ref(CodeTypename self, String* result )
|
|||||||
if ( self->Attributes )
|
if ( self->Attributes )
|
||||||
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
|
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
|
||||||
|
|
||||||
|
switch ( self->TypeTag )
|
||||||
|
{
|
||||||
|
case Tag_Class : string_append_strc( result, txt("class ")); break;
|
||||||
|
case Tag_Enum : string_append_strc( result, txt("enum ")); break;
|
||||||
|
case Tag_Struct : string_append_strc( result, txt("struct ")); break;
|
||||||
|
case Tag_Union : string_append_strc( result, txt("union ")); break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if ( self->Specs )
|
if ( self->Specs )
|
||||||
string_append_fmt( result, "%SC %S", self->Name, specifiers_to_string(self->Specs) );
|
string_append_fmt( result, "%SC %S", self->Name, specifiers_to_string(self->Specs) );
|
||||||
else
|
else
|
||||||
@ -1228,7 +1244,7 @@ void union_to_string_def(CodeUnion self, String* result )
|
|||||||
if ( self->Attributes )
|
if ( self->Attributes )
|
||||||
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
|
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
|
||||||
|
|
||||||
if ( self->Name )
|
if ( self->Name.Len )
|
||||||
{
|
{
|
||||||
string_append_fmt( result, "%SC\n{\n%S\n}"
|
string_append_fmt( result, "%SC\n{\n%S\n}"
|
||||||
, self->Name
|
, self->Name
|
||||||
@ -1259,7 +1275,7 @@ void union_to_string_fwd(CodeUnion self, String* result )
|
|||||||
if ( self->Attributes )
|
if ( self->Attributes )
|
||||||
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
|
string_append_fmt( result, "%S ", attributes_to_string(self->Attributes) );
|
||||||
|
|
||||||
if ( self->Name )
|
if ( self->Name.Len )
|
||||||
{
|
{
|
||||||
string_append_fmt( result, "%SC", self->Name);
|
string_append_fmt( result, "%SC", self->Name);
|
||||||
}
|
}
|
||||||
@ -1321,7 +1337,7 @@ void using_to_string_ref(CodeUsing self, String* result )
|
|||||||
string_append_strc( result, txt("\n"));
|
string_append_strc( result, txt("\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
inline
|
||||||
void using_to_string_ns(CodeUsing self, String* result )
|
void using_to_string_ns(CodeUsing self, String* result )
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
@ -1332,7 +1348,7 @@ void using_to_string_ns(CodeUsing self, String* result )
|
|||||||
string_append_fmt( result, "using namespace %SC;\n", self->Name );
|
string_append_fmt( result, "using namespace %SC;\n", self->Name );
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
inline
|
||||||
String var_to_string(CodeVar self)
|
String var_to_string(CodeVar self)
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
@ -1369,7 +1385,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
|||||||
|
|
||||||
if ( self->Value )
|
if ( self->Value )
|
||||||
{
|
{
|
||||||
if ( self->VarConstructorInit )
|
if ( self->VarParenthesizedInit )
|
||||||
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
||||||
else
|
else
|
||||||
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
||||||
@ -1379,7 +1395,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
|||||||
if ( self->NextVar )
|
if ( self->NextVar )
|
||||||
string_append_fmt( result, ", %S", var_to_string(self->NextVar) );
|
string_append_fmt( result, ", %S", var_to_string(self->NextVar) );
|
||||||
|
|
||||||
if ( self->VarConstructorInit )
|
if ( self->VarParenthesizedInit )
|
||||||
string_append_strc( result, txt(" )"));
|
string_append_strc( result, txt(" )"));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -1415,7 +1431,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
|||||||
|
|
||||||
if ( self->Value )
|
if ( self->Value )
|
||||||
{
|
{
|
||||||
if ( self->VarConstructorInit )
|
if ( self->VarParenthesizedInit )
|
||||||
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
||||||
else
|
else
|
||||||
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
||||||
@ -1424,7 +1440,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
|||||||
if ( self->NextVar )
|
if ( self->NextVar )
|
||||||
string_append_fmt( result, ", %S", var_to_string(self->NextVar) );
|
string_append_fmt( result, ", %S", var_to_string(self->NextVar) );
|
||||||
|
|
||||||
if ( self->VarConstructorInit )
|
if ( self->VarParenthesizedInit )
|
||||||
string_append_strc( result, txt(" )"));
|
string_append_strc( result, txt(" )"));
|
||||||
|
|
||||||
if ( self->InlineCmt )
|
if ( self->InlineCmt )
|
||||||
@ -1455,7 +1471,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
|||||||
|
|
||||||
if ( self->Value )
|
if ( self->Value )
|
||||||
{
|
{
|
||||||
if ( self->VarConstructorInit )
|
if ( self->VarParenthesizedInit )
|
||||||
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
string_append_fmt( result, "( %S ", code_to_string(self->Value) );
|
||||||
else
|
else
|
||||||
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
string_append_fmt( result, " = %S", code_to_string(self->Value) );
|
||||||
@ -1464,7 +1480,7 @@ void var_to_string_ref(CodeVar self, String* result )
|
|||||||
if ( self->NextVar )
|
if ( self->NextVar )
|
||||||
string_append_fmt( result, ", %S", var_to_string( self->NextVar) );
|
string_append_fmt( result, ", %S", var_to_string( self->NextVar) );
|
||||||
|
|
||||||
if ( self->VarConstructorInit )
|
if ( self->VarParenthesizedInit )
|
||||||
string_append_strc( result, txt(" )"));
|
string_append_strc( result, txt(" )"));
|
||||||
|
|
||||||
string_append_strc( result, txt(";") );
|
string_append_strc( result, txt(";") );
|
@ -3,7 +3,20 @@
|
|||||||
#include "ast.hpp"
|
#include "ast.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
______ __ ______ __ ______
|
||||||
|
/ \ | \ | \ | \ / \
|
||||||
|
| ▓▓▓▓▓▓\ ______ ____| ▓▓ ______ \▓▓▓▓▓▓_______ _| ▓▓_ ______ ______ | ▓▓▓▓▓▓\ ______ _______ ______
|
||||||
|
| ▓▓ \▓▓/ \ / ▓▓/ \ | ▓▓ | \| ▓▓ \ / \ / \| ▓▓_ \▓▓| \ / \/ \
|
||||||
|
| ▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\ | ▓▓ | ▓▓▓▓▓▓▓\\▓▓▓▓▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓ \ \▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\
|
||||||
|
| ▓▓ __| ▓▓ | ▓▓ ▓▓ | ▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ __| ▓▓ ▓▓ ▓▓ \▓▓ ▓▓▓▓ / ▓▓ ▓▓ | ▓▓ ▓▓
|
||||||
|
| ▓▓__/ \ ▓▓__/ ▓▓ ▓▓__| ▓▓ ▓▓▓▓▓▓▓▓ _| ▓▓_| ▓▓ | ▓▓ | ▓▓| \ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ | ▓▓▓▓▓▓▓ ▓▓_____| ▓▓▓▓▓▓▓▓
|
||||||
|
\▓▓ ▓▓\▓▓ ▓▓\▓▓ ▓▓\▓▓ \ | ▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \\▓▓ \
|
||||||
|
\▓▓▓▓▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
||||||
|
*/
|
||||||
|
|
||||||
#pragma region Code Type C-Interface
|
#pragma region Code Type C-Interface
|
||||||
|
|
||||||
void body_append ( CodeBody body, Code other );
|
void body_append ( CodeBody body, Code other );
|
||||||
void body_append_body ( CodeBody body, CodeBody other );
|
void body_append_body ( CodeBody body, CodeBody other );
|
||||||
String body_to_string ( CodeBody body );
|
String body_to_string ( CodeBody body );
|
||||||
@ -14,20 +27,20 @@ Code begin_CodeBody( CodeBody body);
|
|||||||
Code end_CodeBody ( CodeBody body );
|
Code end_CodeBody ( CodeBody body );
|
||||||
Code next_CodeBody ( CodeBody body, Code entry_iter );
|
Code next_CodeBody ( CodeBody body, Code entry_iter );
|
||||||
|
|
||||||
void class_add_interface( CodeClass self, CodeType interface );
|
void class_add_interface( CodeClass self, CodeTypename interface );
|
||||||
String class_to_string ( CodeClass self );
|
String class_to_string ( CodeClass self );
|
||||||
void class_to_string_def( CodeClass self, String* result );
|
void class_to_string_def( CodeClass self, String* result );
|
||||||
void class_to_string_fwd( CodeClass self, String* result );
|
void class_to_string_fwd( CodeClass self, String* result );
|
||||||
|
|
||||||
void params_append (CodeParam params, CodeParam param );
|
void params_append (CodeParams params, CodeParams param );
|
||||||
CodeParam params_get (CodeParam params, s32 idx);
|
CodeParams params_get (CodeParams params, s32 idx);
|
||||||
bool params_has_entries (CodeParam params );
|
bool params_has_entries (CodeParams params );
|
||||||
String params_to_string (CodeParam params );
|
String params_to_string (CodeParams params );
|
||||||
void params_to_string_ref(CodeParam params, String* result );
|
void params_to_string_ref(CodeParams params, String* result );
|
||||||
|
|
||||||
CodeParam begin_CodeParam(CodeParam params);
|
CodeParams begin_CodeParams(CodeParams params);
|
||||||
CodeParam end_CodeParam (CodeParam params);
|
CodeParams end_CodeParams (CodeParams params);
|
||||||
CodeParam next_CodeParam (CodeParam params, CodeParam entry_iter);
|
CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
|
||||||
|
|
||||||
bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
||||||
s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
||||||
@ -39,7 +52,7 @@ Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers);
|
|||||||
Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
|
Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
|
||||||
Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
|
Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
|
||||||
|
|
||||||
void struct_add_interface(CodeStruct self, CodeType interface);
|
void struct_add_interface(CodeStruct self, CodeTypename interface);
|
||||||
String struct_to_string (CodeStruct self);
|
String struct_to_string (CodeStruct self);
|
||||||
void struct_to_string_fwd(CodeStruct self, String* result);
|
void struct_to_string_fwd(CodeStruct self, String* result);
|
||||||
void struct_to_string_def(CodeStruct self, String* result);
|
void struct_to_string_def(CodeStruct self, String* result);
|
||||||
@ -126,6 +139,7 @@ void using_to_string_ns (CodeUsing op_cast, String* result );
|
|||||||
|
|
||||||
String var_to_string (CodeVar self);
|
String var_to_string (CodeVar self);
|
||||||
void var_to_string_ref(CodeVar self, String* result);
|
void var_to_string_ref(CodeVar self, String* result);
|
||||||
|
|
||||||
#pragma endregion Code Type C-Interface
|
#pragma endregion Code Type C-Interface
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP
|
#if GEN_COMPILER_CPP
|
||||||
@ -174,25 +188,28 @@ struct CodeClass
|
|||||||
AST_Class* ast;
|
AST_Class* ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CodeParam
|
struct CodeParams
|
||||||
{
|
{
|
||||||
#if ! GEN_C_LIKE_CPP
|
#if ! GEN_C_LIKE_CPP
|
||||||
Using_Code( CodeParam );
|
Using_Code( CodeParams );
|
||||||
forceinline void append( CodeParam other );
|
forceinline void append( CodeParams other );
|
||||||
forceinline CodeParam get( s32 idx );
|
forceinline CodeParams get( s32 idx );
|
||||||
forceinline bool has_entries();
|
forceinline bool has_entries();
|
||||||
forceinline String to_string();
|
forceinline String to_string();
|
||||||
forceinline void to_string( String& result );
|
forceinline void to_string( String& result );
|
||||||
|
|
||||||
|
forceinline CodeParams begin() { return begin_CodeParams(* this); }
|
||||||
|
forceinline CodeParams end() { return end_CodeParams(* this); }
|
||||||
#endif
|
#endif
|
||||||
Using_CodeOps( CodeParam );
|
Using_CodeOps( CodeParams );
|
||||||
forceinline operator Code() { return { (AST*)ast }; }
|
forceinline operator Code() { return { (AST*)ast }; }
|
||||||
forceinline CodeParam operator*() { return * this; }
|
forceinline CodeParams operator*() { return * this; }
|
||||||
forceinline AST_Param* operator->() {
|
forceinline AST_Params* operator->() {
|
||||||
GEN_ASSERT(ast);
|
GEN_ASSERT(ast);
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
CodeParam& operator++();
|
CodeParams& operator++();
|
||||||
AST_Param* ast;
|
AST_Params* ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CodeSpecifiers
|
struct CodeSpecifiers
|
||||||
@ -214,24 +231,6 @@ struct CodeSpecifiers
|
|||||||
AST_Specifiers* ast;
|
AST_Specifiers* ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CodeStruct
|
|
||||||
{
|
|
||||||
#if ! GEN_C_LIKE_CPP
|
|
||||||
Using_Code( CodeStruct );
|
|
||||||
forceinline void add_interface( CodeType interface ) { return struct_add_interface(* this, interface); }
|
|
||||||
forceinline String to_string() { return struct_to_string(* this); }
|
|
||||||
forceinline void to_string_fwd( String& result ) { return struct_to_string_fwd(* this, & result); }
|
|
||||||
forceinline void to_string_def( String& result ) { return struct_to_string_def(* this, & result); }
|
|
||||||
#endif
|
|
||||||
Using_CodeOps( CodeStruct );
|
|
||||||
forceinline operator Code() { return * rcast( Code*, this ); }
|
|
||||||
forceinline AST_Struct* operator->() {
|
|
||||||
GEN_ASSERT(ast);
|
|
||||||
return ast;
|
|
||||||
}
|
|
||||||
AST_Struct* ast;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CodeAttributes
|
struct CodeAttributes
|
||||||
{
|
{
|
||||||
#if ! GEN_C_LIKE_CPP
|
#if ! GEN_C_LIKE_CPP
|
||||||
@ -907,6 +906,24 @@ struct CodeVar
|
|||||||
AST_Var* ast;
|
AST_Var* ast;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CodeStruct
|
||||||
|
{
|
||||||
|
#if ! GEN_C_LIKE_CPP
|
||||||
|
Using_Code( CodeStruct );
|
||||||
|
forceinline void add_interface( CodeTypename interface ) { return struct_add_interface(* this, interface); }
|
||||||
|
forceinline String to_string() { return struct_to_string(* this); }
|
||||||
|
forceinline void to_string_fwd( String& result ) { return struct_to_string_fwd(* this, & result); }
|
||||||
|
forceinline void to_string_def( String& result ) { return struct_to_string_def(* this, & result); }
|
||||||
|
#endif
|
||||||
|
Using_CodeOps( CodeStruct );
|
||||||
|
forceinline operator Code() { return * rcast( Code*, this ); }
|
||||||
|
forceinline AST_Struct* operator->() {
|
||||||
|
GEN_ASSERT(ast);
|
||||||
|
return ast;
|
||||||
|
}
|
||||||
|
AST_Struct* ast;
|
||||||
|
};
|
||||||
|
|
||||||
#undef Define_CodeType
|
#undef Define_CodeType
|
||||||
#undef Using_Code
|
#undef Using_Code
|
||||||
#undef Using_CodeOps
|
#undef Using_CodeOps
|
||||||
@ -934,7 +951,7 @@ struct InvalidCode_ImplictCaster
|
|||||||
operator CodeNS () const { return cast(CodeNS, Code_Invalid); }
|
operator CodeNS () const { return cast(CodeNS, Code_Invalid); }
|
||||||
operator CodeOperator () const { return cast(CodeOperator, Code_Invalid); }
|
operator CodeOperator () const { return cast(CodeOperator, Code_Invalid); }
|
||||||
operator CodeOpCast () const { return cast(CodeOpCast, Code_Invalid); }
|
operator CodeOpCast () const { return cast(CodeOpCast, Code_Invalid); }
|
||||||
operator CodeParam () const { return cast(CodeParam, Code_Invalid); }
|
operator CodeParams () const { return cast(CodeParams, Code_Invalid); }
|
||||||
operator CodePragma () const { return cast(CodePragma, Code_Invalid); }
|
operator CodePragma () const { return cast(CodePragma, Code_Invalid); }
|
||||||
operator CodePreprocessCond() const { return cast(CodePreprocessCond, Code_Invalid); }
|
operator CodePreprocessCond() const { return cast(CodePreprocessCond, Code_Invalid); }
|
||||||
operator CodeSpecifiers () const { return cast(CodeSpecifiers, Code_Invalid); }
|
operator CodeSpecifiers () const { return cast(CodeSpecifiers, Code_Invalid); }
|
||||||
@ -967,7 +984,7 @@ struct NullCode_ImplicitCaster
|
|||||||
operator CodeNS () const { return {nullptr}; }
|
operator CodeNS () const { return {nullptr}; }
|
||||||
operator CodeOperator () const { return {nullptr}; }
|
operator CodeOperator () const { return {nullptr}; }
|
||||||
operator CodeOpCast () const { return {nullptr}; }
|
operator CodeOpCast () const { return {nullptr}; }
|
||||||
operator CodeParam () const { return {nullptr}; }
|
operator CodeParams () const { return {nullptr}; }
|
||||||
operator CodePragma () const { return {nullptr}; }
|
operator CodePragma () const { return {nullptr}; }
|
||||||
operator CodePreprocessCond() const { return {nullptr}; }
|
operator CodePreprocessCond() const { return {nullptr}; }
|
||||||
operator CodeSpecifiers () const { return {nullptr}; }
|
operator CodeSpecifiers () const { return {nullptr}; }
|
||||||
@ -982,6 +999,7 @@ struct NullCode_ImplicitCaster
|
|||||||
|
|
||||||
#if ! GEN_C_LIKE_CPP
|
#if ! GEN_C_LIKE_CPP
|
||||||
GEN_OPTIMIZE_MAPPINGS_BEGIN
|
GEN_OPTIMIZE_MAPPINGS_BEGIN
|
||||||
|
|
||||||
forceinline void append ( CodeBody body, Code other ) { return body_append(body, other); }
|
forceinline void append ( CodeBody body, Code other ) { return body_append(body, other); }
|
||||||
forceinline void append ( CodeBody body, CodeBody other ) { return body_append_body(body, other); }
|
forceinline void append ( CodeBody body, CodeBody other ) { return body_append_body(body, other); }
|
||||||
forceinline String to_string ( CodeBody body ) { return body_to_string(body); }
|
forceinline String to_string ( CodeBody body ) { return body_to_string(body); }
|
||||||
@ -992,20 +1010,20 @@ forceinline Code begin( CodeBody body) { return begin_CodeBody
|
|||||||
forceinline Code end ( CodeBody body ) { return end_CodeBody(body); }
|
forceinline Code end ( CodeBody body ) { return end_CodeBody(body); }
|
||||||
forceinline Code next ( CodeBody body, Code entry_iter ) { return next_CodeBody(body, entry_iter); }
|
forceinline Code next ( CodeBody body, Code entry_iter ) { return next_CodeBody(body, entry_iter); }
|
||||||
|
|
||||||
forceinline void add_interface( CodeClass self, CodeType interface ) { return class_add_interface(self, interface); }
|
forceinline void add_interface( CodeClass self, CodeTypename interface ) { return class_add_interface(self, interface); }
|
||||||
forceinline String to_string ( CodeClass self ) { return class_to_string(self); }
|
forceinline String to_string ( CodeClass self ) { return class_to_string(self); }
|
||||||
forceinline void to_string_def( CodeClass self, String& result ) { return class_to_string_def(self, & result); }
|
forceinline void to_string_def( CodeClass self, String& result ) { return class_to_string_def(self, & result); }
|
||||||
forceinline void to_string_fwd( CodeClass self, String& result ) { return class_to_string_fwd(self, & result); }
|
forceinline void to_string_fwd( CodeClass self, String& result ) { return class_to_string_fwd(self, & result); }
|
||||||
|
|
||||||
forceinline void append (CodeParam params, CodeParam param ) { return params_append(params, param); }
|
forceinline void append (CodeParams params, CodeParams param ) { return params_append(params, param); }
|
||||||
forceinline CodeParam get (CodeParam params, s32 idx) { return params_get(params, idx); }
|
forceinline CodeParams get (CodeParams params, s32 idx) { return params_get(params, idx); }
|
||||||
forceinline bool has_entries(CodeParam params ) { return params_has_entries(params); }
|
forceinline bool has_entries(CodeParams params ) { return params_has_entries(params); }
|
||||||
forceinline String to_string (CodeParam params ) { return params_to_string(params); }
|
forceinline String to_string (CodeParams params ) { return params_to_string(params); }
|
||||||
forceinline void to_string (CodeParam params, String& result ) { return params_to_string_ref(params, & result); }
|
forceinline void to_string (CodeParams params, String& result ) { return params_to_string_ref(params, & result); }
|
||||||
|
|
||||||
forceinline CodeParam begin(CodeParam params) { return begin_CodeParam(params); }
|
forceinline CodeParams begin(CodeParams params) { return begin_CodeParams(params); }
|
||||||
forceinline CodeParam end (CodeParam params) { return end_CodeParam(params); }
|
forceinline CodeParams end (CodeParams params) { return end_CodeParams(params); }
|
||||||
forceinline CodeParam next (CodeParam params, CodeParam entry_iter) { return next_CodeParam(params, entry_iter); }
|
forceinline CodeParams next (CodeParams params, CodeParams entry_iter) { return next_CodeParams(params, entry_iter); }
|
||||||
|
|
||||||
forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); }
|
forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); }
|
||||||
forceinline s32 has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); }
|
forceinline s32 has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); }
|
||||||
@ -1017,7 +1035,7 @@ forceinline Specifier* begin(CodeSpecifiers specifiers) {
|
|||||||
forceinline Specifier* end (CodeSpecifiers specifiers) { return end_CodeSpecifiers(specifiers); }
|
forceinline Specifier* end (CodeSpecifiers specifiers) { return end_CodeSpecifiers(specifiers); }
|
||||||
forceinline Specifier* next (CodeSpecifiers specifiers, Specifier& spec_iter) { return next_CodeSpecifiers(specifiers, & spec_iter); }
|
forceinline Specifier* next (CodeSpecifiers specifiers, Specifier& spec_iter) { return next_CodeSpecifiers(specifiers, & spec_iter); }
|
||||||
|
|
||||||
forceinline void add_interface(CodeStruct self, CodeType interface) { return struct_add_interface(self, interface); }
|
forceinline void add_interface(CodeStruct self, CodeTypename interface) { return struct_add_interface(self, interface); }
|
||||||
forceinline String to_string (CodeStruct self) { return struct_to_string(self); }
|
forceinline String to_string (CodeStruct self) { return struct_to_string(self); }
|
||||||
forceinline void to_string_fwd(CodeStruct self, String& result) { return struct_to_string_fwd(self, & result); }
|
forceinline void to_string_fwd(CodeStruct self, String& result) { return struct_to_string_fwd(self, & result); }
|
||||||
forceinline void to_string_def(CodeStruct self, String& result) { return struct_to_string_def(self, & result); }
|
forceinline void to_string_def(CodeStruct self, String& result) { return struct_to_string_def(self, & result); }
|
||||||
@ -1104,6 +1122,7 @@ forceinline void to_string_ns(CodeUsing op_cast, String& result ) { return usi
|
|||||||
|
|
||||||
forceinline String to_string(CodeVar self) { return var_to_string(self); }
|
forceinline String to_string(CodeVar self) { return var_to_string(self); }
|
||||||
forceinline void to_string(CodeVar self, String& result) { return var_to_string_ref(self, & result); }
|
forceinline void to_string(CodeVar self, String& result) { return var_to_string_ref(self, & result); }
|
||||||
|
|
||||||
GEN_OPITMIZE_MAPPINGS_END
|
GEN_OPITMIZE_MAPPINGS_END
|
||||||
#endif //if GEN_C_LIKE_CPP
|
#endif //if GEN_C_LIKE_CPP
|
||||||
|
|
@ -520,7 +520,7 @@ inline AST_OpCast* CodeOpCast::operator->()
|
|||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CodeParam& CodeParam::operator=( Code other )
|
inline CodeParams& CodeParams::operator=( Code other )
|
||||||
{
|
{
|
||||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||||
{
|
{
|
||||||
@ -531,7 +531,7 @@ inline CodeParam& CodeParam::operator=( Code other )
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CodeParam::operator bool()
|
inline CodeParams::operator bool()
|
||||||
{
|
{
|
||||||
return ast != nullptr;
|
return ast != nullptr;
|
||||||
}
|
}
|
||||||
@ -906,9 +906,9 @@ forceinline Code::operator CodeOpCast() const
|
|||||||
return { (AST_OpCast*)ast };
|
return { (AST_OpCast*)ast };
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline Code::operator CodeParam() const
|
forceinline Code::operator CodeParams() const
|
||||||
{
|
{
|
||||||
return { (AST_Param*)ast };
|
return { (AST_Params*)ast };
|
||||||
}
|
}
|
||||||
|
|
||||||
forceinline Code::operator CodePragma() const
|
forceinline Code::operator CodePragma() const
|
@ -68,7 +68,8 @@ enum CodeType : u32
|
|||||||
CT_Using,
|
CT_Using,
|
||||||
CT_Using_Namespace,
|
CT_Using_Namespace,
|
||||||
CT_Variable,
|
CT_Variable,
|
||||||
CT_NumTypes
|
CT_NumTypes,
|
||||||
|
CT_UnderlyingType = GEN_U32_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
inline StrC codetype_to_str( CodeType type )
|
inline StrC codetype_to_str( CodeType type )
|
@ -54,7 +54,8 @@ enum Operator : u32
|
|||||||
Op_NewArray,
|
Op_NewArray,
|
||||||
Op_Delete,
|
Op_Delete,
|
||||||
Op_DeleteArray,
|
Op_DeleteArray,
|
||||||
NumOps
|
Op_NumOps,
|
||||||
|
Op_UnderlyingType = 0xffffffffu
|
||||||
};
|
};
|
||||||
|
|
||||||
inline StrC operator_to_str( Operator op )
|
inline StrC operator_to_str( Operator op )
|
@ -33,7 +33,8 @@ enum Specifier : u32
|
|||||||
Spec_Override,
|
Spec_Override,
|
||||||
Spec_Pure,
|
Spec_Pure,
|
||||||
Spec_Volatile,
|
Spec_Volatile,
|
||||||
Spec_NumSpecifiers
|
Spec_NumSpecifiers,
|
||||||
|
Spec_UnderlyingType = 0xffffffffu
|
||||||
};
|
};
|
||||||
|
|
||||||
inline StrC spec_to_str( Specifier type )
|
inline StrC spec_to_str( Specifier type )
|
@ -6,9 +6,10 @@
|
|||||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||||
|
|
||||||
GEN_NS_PARSER_BEGIN
|
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" )
|
#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_Invalid,
|
||||||
Tok_Access_Private,
|
Tok_Access_Private,
|
||||||
@ -109,11 +110,10 @@ enum TokType_Def : u32
|
|||||||
Tok_Attribute_API_Import,
|
Tok_Attribute_API_Import,
|
||||||
Tok_NumTokens
|
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( "__invalid__" ), "__invalid__" },
|
||||||
{ sizeof( "private" ), "private" },
|
{ sizeof( "private" ), "private" },
|
||||||
{ sizeof( "protected" ), "protected" },
|
{ sizeof( "protected" ), "protected" },
|
||||||
@ -215,12 +215,12 @@ inline StrC to_str( TokType type )
|
|||||||
return lookup[type];
|
return lookup[type];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline TokType to_toktype( StrC str )
|
inline TokType strc_to_toktype( StrC str )
|
||||||
{
|
{
|
||||||
local_persist u32 keymap[Tok_NumTokens];
|
local_persist u32 keymap[Tok_NumTokens];
|
||||||
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
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 );
|
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||||
}
|
}
|
||||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
@ -24,8 +24,8 @@
|
|||||||
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
||||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||||
#endif
|
#endif
|
||||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
#ifndef TokenMap_FixedArena
|
||||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8)
|
# define TokenMap_FixedArena FixedArena_8KB
|
||||||
#endif
|
#endif
|
||||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
||||||
@ -49,10 +49,12 @@ constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
|||||||
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
||||||
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
||||||
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_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 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||||
|
|
||||||
|
extern StrC enum_underlying_sig;
|
||||||
|
|
||||||
extern Code access_public;
|
extern Code access_public;
|
||||||
extern Code access_protected;
|
extern Code access_protected;
|
||||||
extern Code access_private;
|
extern Code access_private;
|
||||||
@ -67,7 +69,7 @@ extern Code fmt_newline;
|
|||||||
|
|
||||||
extern CodePragma pragma_once;
|
extern CodePragma pragma_once;
|
||||||
|
|
||||||
extern CodeParam param_varadic;
|
extern CodeParams param_varadic;
|
||||||
|
|
||||||
extern CodePreprocessCond preprocess_else;
|
extern CodePreprocessCond preprocess_else;
|
||||||
extern CodePreprocessCond preprocess_endif;
|
extern CodePreprocessCond preprocess_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
|
@ -101,7 +101,7 @@ Code& Code::operator ++()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
forceinline
|
forceinline
|
||||||
char const* code_type_str(Code self)
|
StrC code_type_str(Code self)
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self != nullptr);
|
GEN_ASSERT(self != nullptr);
|
||||||
return codetype_to_str( self->Type );
|
return codetype_to_str( self->Type );
|
||||||
@ -138,7 +138,8 @@ Code begin_CodeBody( CodeBody body) {
|
|||||||
GEN_ASSERT(body);
|
GEN_ASSERT(body);
|
||||||
if ( body != nullptr )
|
if ( body != nullptr )
|
||||||
return body->Front;
|
return body->Front;
|
||||||
return { nullptr };
|
|
||||||
|
return NullCode;
|
||||||
}
|
}
|
||||||
forceinline
|
forceinline
|
||||||
Code end_CodeBody(CodeBody body ){
|
Code end_CodeBody(CodeBody body ){
|
||||||
@ -170,16 +171,16 @@ void class_add_interface( CodeClass self, CodeTypename type )
|
|||||||
|
|
||||||
while ( possible_slot != nullptr )
|
while ( possible_slot != nullptr )
|
||||||
{
|
{
|
||||||
possible_slot = possible_slot->Next;
|
possible_slot = cast(CodeTypename, possible_slot->Next);
|
||||||
}
|
}
|
||||||
|
|
||||||
possible_slot = type;
|
possible_slot = type;
|
||||||
}
|
}
|
||||||
#pragma endregion CodeClass
|
#pragma endregion CodeClass
|
||||||
|
|
||||||
#pragma region CodeParam
|
#pragma region CodeParams
|
||||||
inline
|
inline
|
||||||
void params_append( CodeParam appendee, CodeParam other )
|
void params_append( CodeParams appendee, CodeParams other )
|
||||||
{
|
{
|
||||||
GEN_ASSERT(appendee);
|
GEN_ASSERT(appendee);
|
||||||
GEN_ASSERT(other);
|
GEN_ASSERT(other);
|
||||||
@ -205,37 +206,37 @@ void params_append( CodeParam appendee, CodeParam other )
|
|||||||
self->NumEntries++;
|
self->NumEntries++;
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
CodeParam params_get(CodeParam self, s32 idx )
|
CodeParams params_get(CodeParams self, s32 idx )
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
CodeParam param = self;
|
CodeParams param = self;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if ( ++ param != nullptr )
|
if ( ++ param != nullptr )
|
||||||
return { nullptr };
|
return NullCode;
|
||||||
|
|
||||||
param = cast(CodeParam, cast(Code, param)->Next);
|
param = cast(CodeParams, cast(Code, param)->Next);
|
||||||
}
|
}
|
||||||
while ( --idx );
|
while ( --idx );
|
||||||
|
|
||||||
return param;
|
return param;
|
||||||
}
|
}
|
||||||
forceinline
|
forceinline
|
||||||
bool params_has_entries(CodeParam self)
|
bool params_has_entries(CodeParams self)
|
||||||
{
|
{
|
||||||
GEN_ASSERT(self);
|
GEN_ASSERT(self);
|
||||||
return self->NumEntries > 0;
|
return self->NumEntries > 0;
|
||||||
}
|
}
|
||||||
#if GEN_COMPILER_CPP
|
#if GEN_COMPILER_CPP
|
||||||
forceinline
|
forceinline
|
||||||
CodeParam& CodeParam::operator ++()
|
CodeParams& CodeParams::operator ++()
|
||||||
{
|
{
|
||||||
* this = ast->Next;
|
* this = ast->Next;
|
||||||
return * this;
|
return * this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
forceinline
|
forceinline
|
||||||
CodeParam begin_CodeParam(CodeParam params)
|
CodeParams begin_CodeParams(CodeParams params)
|
||||||
{
|
{
|
||||||
if ( params != nullptr )
|
if ( params != nullptr )
|
||||||
return params;
|
return params;
|
||||||
@ -243,18 +244,18 @@ CodeParam begin_CodeParam(CodeParam params)
|
|||||||
return NullCode;
|
return NullCode;
|
||||||
}
|
}
|
||||||
forceinline
|
forceinline
|
||||||
CodeParam end_CodeParam(CodeParam params)
|
CodeParams end_CodeParams(CodeParams params)
|
||||||
{
|
{
|
||||||
// return { (AST_Param*) rcast( AST*, ast)->Last };
|
// return { (AST_Params*) rcast( AST*, ast)->Last };
|
||||||
return { nullptr };
|
return NullCode;
|
||||||
}
|
}
|
||||||
forceinline
|
forceinline
|
||||||
CodeParam next_CodeParam(CodeParam params, CodeParam param_iter)
|
CodeParams next_CodeParams(CodeParams params, CodeParams param_iter)
|
||||||
{
|
{
|
||||||
GEN_ASSERT(param_iter);
|
GEN_ASSERT(param_iter);
|
||||||
return param_iter->Next;
|
return param_iter->Next;
|
||||||
}
|
}
|
||||||
#pragma endregion CodeParam
|
#pragma endregion CodeParams
|
||||||
|
|
||||||
#pragma region CodeSpecifiers
|
#pragma region CodeSpecifiers
|
||||||
inline
|
inline
|
||||||
@ -347,7 +348,7 @@ Specifier* next_CodeSpecifiers(CodeSpecifiers self, Specifier* spec_iter)
|
|||||||
|
|
||||||
#pragma region CodeStruct
|
#pragma region CodeStruct
|
||||||
inline
|
inline
|
||||||
void add_interface(CodeStruct self, CodeTypename type )
|
void struct_add_interface(CodeStruct self, CodeTypename type )
|
||||||
{
|
{
|
||||||
CodeTypename possible_slot = self->ParentType;
|
CodeTypename possible_slot = self->ParentType;
|
||||||
if ( possible_slot != nullptr )
|
if ( possible_slot != nullptr )
|
||||||
@ -360,7 +361,7 @@ void add_interface(CodeStruct self, CodeTypename type )
|
|||||||
|
|
||||||
while ( possible_slot != nullptr )
|
while ( possible_slot != nullptr )
|
||||||
{
|
{
|
||||||
possible_slot = possible_slot->Next;
|
possible_slot = cast(CodeTypename, possible_slot->Next);
|
||||||
}
|
}
|
||||||
|
|
||||||
possible_slot = type;
|
possible_slot = type;
|
||||||
@ -385,7 +386,7 @@ CodeBody def_body( CodeType type )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log_failure( "def_body: Invalid type %s", (char const*)codetype_to_str(type) );
|
log_failure( "def_body: Invalid type %s", codetype_to_str(type).Ptr );
|
||||||
return (CodeBody)Code_Invalid;
|
return (CodeBody)Code_Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,6 +408,7 @@ StrC token_fmt_impl( ssize num, ... )
|
|||||||
ssize result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
ssize result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
return { result, buf };
|
StrC str = { result, buf };
|
||||||
|
return str;
|
||||||
}
|
}
|
||||||
#pragma endregion Interface
|
#pragma endregion Interface
|
@ -4,8 +4,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
GEN_NS_PARSER_BEGIN
|
GEN_NS_PARSER_BEGIN
|
||||||
internal void init();
|
internal void parser_init();
|
||||||
internal void deinit();
|
internal void parser_deinit();
|
||||||
GEN_NS_PARSER_END
|
GEN_NS_PARSER_END
|
||||||
|
|
||||||
internal
|
internal
|
||||||
@ -101,10 +101,12 @@ void define_constants()
|
|||||||
access_public->Name = get_cached_string( txt("public:\n") );
|
access_public->Name = get_cached_string( txt("public:\n") );
|
||||||
code_set_global(access_public);
|
code_set_global(access_public);
|
||||||
|
|
||||||
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
|
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));
|
code_set_global(cast(Code, attrib_api_export));
|
||||||
|
|
||||||
attrib_api_import = def_attributes( code(GEN_API_Import_Code));
|
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));
|
code_set_global(cast(Code, attrib_api_import));
|
||||||
|
|
||||||
module_global_fragment = make_code();
|
module_global_fragment = make_code();
|
||||||
@ -129,7 +131,7 @@ void define_constants()
|
|||||||
pragma_once->Content = pragma_once->Name;
|
pragma_once->Content = pragma_once->Name;
|
||||||
code_set_global((Code)pragma_once);
|
code_set_global((Code)pragma_once);
|
||||||
|
|
||||||
param_varadic = (CodeParam) make_code();
|
param_varadic = (CodeParams) make_code();
|
||||||
param_varadic->Type = CT_Parameters;
|
param_varadic->Type = CT_Parameters;
|
||||||
param_varadic->Name = get_cached_string( txt("...") );
|
param_varadic->Name = get_cached_string( txt("...") );
|
||||||
param_varadic->ValueType = t_empty;
|
param_varadic->ValueType = t_empty;
|
||||||
@ -144,8 +146,12 @@ void define_constants()
|
|||||||
code_set_global((Code)preprocess_endif);
|
code_set_global((Code)preprocess_endif);
|
||||||
|
|
||||||
# define def_constant_code_type( Type_ ) \
|
# define def_constant_code_type( Type_ ) \
|
||||||
t_##Type_ = def_type( name(Type_) ); \
|
do \
|
||||||
code_set_global( cast(Code, t_##Type_));
|
{ \
|
||||||
|
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( auto );
|
||||||
def_constant_code_type( void );
|
def_constant_code_type( void );
|
||||||
@ -177,58 +183,38 @@ void define_constants()
|
|||||||
#endif
|
#endif
|
||||||
# undef def_constant_code_type
|
# undef def_constant_code_type
|
||||||
|
|
||||||
|
spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const ));
|
||||||
# define def_constant_spec( Type_, ... ) \
|
spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval ));;
|
||||||
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
spec_constexpr = def_specifier( Spec_Constexpr); code_set_global( cast(Code, spec_constexpr ));;
|
||||||
code_set_global( cast(Code, spec_##Type_));
|
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 ));;
|
||||||
# pragma push_macro("forceinline")
|
spec_final = def_specifier( Spec_Final); code_set_global( cast(Code, spec_final ));;
|
||||||
# pragma push_macro("global")
|
spec_forceinline = def_specifier( Spec_ForceInline); code_set_global( cast(Code, spec_forceinline ));;
|
||||||
# pragma push_macro("internal")
|
spec_global = def_specifier( Spec_Global); code_set_global( cast(Code, spec_global ));;
|
||||||
# pragma push_macro("local_persist")
|
spec_inline = def_specifier( Spec_Inline); code_set_global( cast(Code, spec_inline ));;
|
||||||
# pragma push_macro("neverinline")
|
spec_internal_linkage = def_specifier( Spec_Internal_Linkage); code_set_global( cast(Code, spec_internal_linkage ));;
|
||||||
# undef forceinline
|
spec_local_persist = def_specifier( Spec_Local_Persist); code_set_global( cast(Code, spec_local_persist ));;
|
||||||
# undef global
|
spec_mutable = def_specifier( Spec_Mutable); code_set_global( cast(Code, spec_mutable ));;
|
||||||
# undef internal
|
spec_neverinline = def_specifier( Spec_NeverInline); code_set_global( cast(Code, spec_neverinline ));;
|
||||||
# undef local_persist
|
spec_noexcept = def_specifier( Spec_NoExceptions); code_set_global( cast(Code, spec_noexcept ));;
|
||||||
# undef neverinline
|
spec_override = def_specifier( Spec_Override); code_set_global( cast(Code, spec_override ));;
|
||||||
def_constant_spec( const, Spec_Const );
|
spec_ptr = def_specifier( Spec_Ptr); code_set_global( cast(Code, spec_ptr ));;
|
||||||
def_constant_spec( consteval, Spec_Consteval );
|
spec_pure = def_specifier( Spec_Pure); code_set_global( cast(Code, spec_pure ));
|
||||||
def_constant_spec( constexpr, Spec_Constexpr );
|
spec_ref = def_specifier( Spec_Ref); code_set_global( cast(Code, spec_ref ));;
|
||||||
def_constant_spec( constinit, Spec_Constinit );
|
spec_register = def_specifier( Spec_Register); code_set_global( cast(Code, spec_register ));;
|
||||||
def_constant_spec( extern_linkage, Spec_External_Linkage );
|
spec_rvalue = def_specifier( Spec_RValue); code_set_global( cast(Code, spec_rvalue ));;
|
||||||
def_constant_spec( final, Spec_Final );
|
spec_static_member = def_specifier( Spec_Static); code_set_global( cast(Code, spec_static_member ));;
|
||||||
def_constant_spec( forceinline, Spec_ForceInline );
|
spec_thread_local = def_specifier( Spec_Thread_Local); code_set_global( cast(Code, spec_thread_local ));;
|
||||||
def_constant_spec( global, Spec_Global );
|
spec_virtual = def_specifier( Spec_Virtual); code_set_global( cast(Code, spec_virtual ));;
|
||||||
def_constant_spec( inline, Spec_Inline );
|
spec_volatile = def_specifier( Spec_Volatile); code_set_global( cast(Code, spec_volatile ));
|
||||||
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_local_persist = def_specifiers( 1, Spec_Local_Persist );
|
spec_local_persist = def_specifiers( 1, Spec_Local_Persist );
|
||||||
code_set_global(cast(Code, spec_local_persist));
|
code_set_global(cast(Code, spec_local_persist));
|
||||||
|
|
||||||
# pragma pop_macro("forceinline")
|
if (enum_underlying_sig.Len == 0) {
|
||||||
# pragma pop_macro("global")
|
enum_underlying_sig = txt("enum_underlying(");
|
||||||
# pragma pop_macro("internal")
|
}
|
||||||
# pragma pop_macro("local_persist")
|
array_append(PreprocessorDefines, enum_underlying_sig);
|
||||||
# pragma pop_macro("neverinline")
|
|
||||||
|
|
||||||
# pragma push_macro("enum_underlying")
|
|
||||||
array_append(PreprocessorDefines, txt("enum_underlying("));
|
|
||||||
# pragma pop_macro("enum_underlying")
|
|
||||||
|
|
||||||
# undef def_constant_spec
|
# undef def_constant_spec
|
||||||
}
|
}
|
||||||
@ -237,9 +223,10 @@ void init()
|
|||||||
{
|
{
|
||||||
// Setup global allocator
|
// 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 )
|
if ( Global_AllocatorBuckets == nullptr )
|
||||||
GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets");
|
GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets");
|
||||||
@ -252,14 +239,33 @@ void init()
|
|||||||
array_append( Global_AllocatorBuckets, bucket );
|
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
|
// Setup the arrays
|
||||||
{
|
{
|
||||||
CodePools = array_init_reserve<Pool>( Allocator_DataArrays, InitSize_DataArrays );
|
CodePools = array_init_reserve(Pool, Allocator_DataArrays, InitSize_DataArrays );
|
||||||
|
|
||||||
if ( CodePools == nullptr )
|
if ( CodePools == nullptr )
|
||||||
GEN_FATAL( "gen::init: Failed to initialize the CodePools array" );
|
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 )
|
if ( StringArenas == nullptr )
|
||||||
GEN_FATAL( "gen::init: Failed to initialize the StringArenas array" );
|
GEN_FATAL( "gen::init: Failed to initialize the StringArenas array" );
|
||||||
@ -286,17 +292,17 @@ void init()
|
|||||||
|
|
||||||
// Setup the hash tables
|
// Setup the hash tables
|
||||||
{
|
{
|
||||||
StringCache = hashtable_init<StringCached>(Allocator_StringTable);
|
StringCache = hashtable_init(StringCached, Allocator_StringTable);
|
||||||
|
|
||||||
if ( StringCache.Entries == nullptr )
|
if ( StringCache.Entries == nullptr )
|
||||||
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preprocessor Defines
|
// Preprocessor Defines
|
||||||
PreprocessorDefines = array_init_reserve<StringCached>( GlobalAllocator, kilobytes(1) );
|
PreprocessorDefines = array_init_reserve(StringCached, GlobalAllocator, kilobytes(1) );
|
||||||
|
|
||||||
define_constants();
|
define_constants();
|
||||||
GEN_NS_PARSER init();
|
GEN_NS_PARSER parser_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit()
|
void deinit()
|
||||||
@ -341,7 +347,7 @@ void deinit()
|
|||||||
while ( left--, left );
|
while ( left--, left );
|
||||||
|
|
||||||
array_free(Global_AllocatorBuckets);
|
array_free(Global_AllocatorBuckets);
|
||||||
GEN_NS_PARSER deinit();
|
GEN_NS_PARSER parser_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset()
|
void reset()
|
||||||
@ -377,7 +383,7 @@ AllocatorInfo get_string_allocator( s32 str_length )
|
|||||||
|
|
||||||
usize size_req = str_length + sizeof(StringHeader) + sizeof(char*);
|
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 );
|
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 ));
|
StrC result = string_to_strc( string_make_strc( get_string_allocator( str.Len ), str ));
|
||||||
hashtable_set(StringCache, key, result );
|
hashtable_set(StringCache, key, result );
|
||||||
|
|
||||||
return { str.Len, result };
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used internally to retireve a Code object form the CodePool.
|
// Used internally to retireve a Code object form the CodePool.
|
||||||
@ -425,20 +431,8 @@ Code make_code()
|
|||||||
allocator = array_back( CodePools);
|
allocator = array_back( CodePools);
|
||||||
}
|
}
|
||||||
|
|
||||||
Code result { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) };
|
Code result = { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) };
|
||||||
mem_set( rcast(void*, cast(AST*, result)), 0, sizeof(AST) );
|
mem_set( rcast(void*, cast(AST*, result)), 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;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -4,9 +4,18 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma region Gen Interface
|
#pragma region Gen Interface
|
||||||
|
/*
|
||||||
|
/ \ | \ | \ / \
|
||||||
|
| ▓▓▓▓▓▓\ ______ _______ \▓▓▓▓▓▓_______ _| ▓▓_ ______ ______ | ▓▓▓▓▓▓\ ______ _______ ______
|
||||||
|
| ▓▓ __\▓▓/ \| \ | ▓▓ | \| ▓▓ \ / \ / \| ▓▓_ \▓▓| \ / \/ \
|
||||||
|
| ▓▓| \ ▓▓▓▓▓▓\ ▓▓▓▓▓▓▓\ | ▓▓ | ▓▓▓▓▓▓▓\\▓▓▓▓▓▓ | ▓▓▓▓▓▓\ ▓▓▓▓▓▓\ ▓▓ \ \▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓\
|
||||||
|
| ▓▓ \▓▓▓▓ ▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ | ▓▓ __| ▓▓ ▓▓ ▓▓ \▓▓ ▓▓▓▓ / ▓▓ ▓▓ | ▓▓ ▓▓
|
||||||
|
| ▓▓__| ▓▓ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ _| ▓▓_| ▓▓ | ▓▓ | ▓▓| \ ▓▓▓▓▓▓▓▓ ▓▓ | ▓▓ | ▓▓▓▓▓▓▓ ▓▓_____| ▓▓▓▓▓▓▓▓
|
||||||
|
\▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ | ▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \ ▓▓ | ▓▓ \▓▓ ▓▓\▓▓ \\▓▓ \
|
||||||
|
\▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
||||||
|
*/
|
||||||
|
|
||||||
// Initialize the library.
|
// Initialize the library.
|
||||||
// This currently just initializes the CodePool.
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
// Currently manually free's the arenas, code for checking for leaks.
|
// 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 );
|
CodeComment def_comment ( StrC content );
|
||||||
|
|
||||||
struct Opts_def_struct {
|
struct Opts_def_struct {
|
||||||
Code body;
|
CodeBody body;
|
||||||
CodeTypename parent;
|
CodeTypename parent;
|
||||||
AccessSpec parent_access;
|
AccessSpec parent_access;
|
||||||
CodeAttributes attributes;
|
CodeAttributes attributes;
|
||||||
ModuleFlag mflags;
|
|
||||||
CodeTypename* interfaces;
|
CodeTypename* interfaces;
|
||||||
s32 num_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 {
|
struct Opts_def_constructor {
|
||||||
CodeParam params;
|
CodeParams params;
|
||||||
Code initializer_list;
|
Code initializer_list;
|
||||||
Code body;
|
Code body;
|
||||||
};
|
};
|
||||||
CodeConstructor def_constructor( Opts_def_constructor opts GEN_PARAM_DEFAULT );
|
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 {
|
struct Opts_def_destructor {
|
||||||
Code body;
|
Code body;
|
||||||
@ -69,22 +81,23 @@ struct Opts_def_destructor {
|
|||||||
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
CodeDestructor def_destructor( Opts_def_destructor opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
struct Opts_def_enum {
|
struct Opts_def_enum {
|
||||||
Code body;
|
CodeBody body;
|
||||||
CodeTypename type;
|
CodeTypename type;
|
||||||
EnumT specifier;
|
EnumT specifier;
|
||||||
CodeAttributes attributes;
|
CodeAttributes attributes;
|
||||||
ModuleFlag mflags;
|
ModuleFlag mflags;
|
||||||
|
Code type_macro;
|
||||||
};
|
};
|
||||||
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
CodeEnum def_enum( StrC name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
CodeExec def_execution ( StrC content );
|
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 );
|
CodeFriend def_friend ( Code symbol );
|
||||||
|
|
||||||
struct Opts_def_function {
|
struct Opts_def_function {
|
||||||
CodeParam params;
|
CodeParams params;
|
||||||
CodeTypename ret_type;
|
CodeTypename ret_type;
|
||||||
Code body;
|
CodeBody body;
|
||||||
CodeSpecifiers specs;
|
CodeSpecifiers specs;
|
||||||
CodeAttributes attrs;
|
CodeAttributes attrs;
|
||||||
ModuleFlag mflags;
|
ModuleFlag mflags;
|
||||||
@ -96,12 +109,12 @@ struct Opts_def_module { ModuleFlag mflags; };
|
|||||||
struct Opts_def_namespace { ModuleFlag mflags; };
|
struct Opts_def_namespace { ModuleFlag mflags; };
|
||||||
CodeInclude def_include ( StrC content, Opts_def_include 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 );
|
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 );
|
CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
struct Opts_def_operator {
|
struct Opts_def_operator {
|
||||||
CodeParam params;
|
CodeParams params;
|
||||||
CodeTypename ret_type;
|
CodeTypename ret_type;
|
||||||
Code body;
|
CodeBody body;
|
||||||
CodeSpecifiers specifiers;
|
CodeSpecifiers specifiers;
|
||||||
CodeAttributes attributes;
|
CodeAttributes attributes;
|
||||||
ModuleFlag mflags;
|
ModuleFlag mflags;
|
||||||
@ -109,13 +122,13 @@ struct Opts_def_operator {
|
|||||||
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
struct Opts_def_operator_cast {
|
struct Opts_def_operator_cast {
|
||||||
Code body;
|
CodeBody body;
|
||||||
CodeSpecifiers specs;
|
CodeSpecifiers specs;
|
||||||
};
|
};
|
||||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
struct Opts_def_param { Code value; };
|
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 );
|
CodePragma def_pragma( StrC directive );
|
||||||
|
|
||||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
|
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 );
|
CodeStruct def_struct( StrC name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||||
|
|
||||||
struct Opts_def_template { ModuleFlag mflags; };
|
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 {
|
struct Opts_def_type {
|
||||||
|
ETypenameTag type_tag;
|
||||||
Code arrayexpr;
|
Code arrayexpr;
|
||||||
CodeSpecifiers specifiers;
|
CodeSpecifiers specifiers;
|
||||||
CodeAttributes attributes;
|
CodeAttributes attributes;
|
||||||
@ -144,13 +158,13 @@ struct Opts_def_union {
|
|||||||
CodeAttributes attributes;
|
CodeAttributes attributes;
|
||||||
ModuleFlag mflags;
|
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 {
|
struct Opts_def_using {
|
||||||
CodeAttributes attributes;
|
CodeAttributes attributes;
|
||||||
ModuleFlag mflags;
|
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 );
|
CodeUsing def_using_namespace( StrC name );
|
||||||
|
|
||||||
@ -164,7 +178,7 @@ struct Opts_def_variable
|
|||||||
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.
|
// 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,
|
// 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.
|
/// 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_global_body ( s32 num, Code* codes );
|
||||||
CodeBody def_namespace_body ( s32 num, ... );
|
CodeBody def_namespace_body ( s32 num, ... );
|
||||||
CodeBody def_namespace_body ( s32 num, Code* codes );
|
CodeBody def_namespace_body ( s32 num, Code* codes );
|
||||||
CodeParam def_params ( s32 num, ... );
|
CodeParams def_params ( s32 num, ... );
|
||||||
CodeParam def_params ( s32 num, CodeParam* params );
|
CodeParams def_params ( s32 num, CodeParams* params );
|
||||||
CodeSpecifiers def_specifiers ( s32 num, ... );
|
CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||||
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
||||||
CodeBody def_struct_body ( s32 num, ... );
|
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.
|
// TODO(Ed) : Implmeent the new parser API design.
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
namespace parser {
|
GEN_NS_PARSER_BEGIN
|
||||||
struct StackNode
|
struct StackNode
|
||||||
{
|
{
|
||||||
StackNode* Prev;
|
StackNode* Prev;
|
||||||
|
|
||||||
Token Start;
|
Token Start;
|
||||||
Token Name; // The name of the AST node (if parsed)
|
Token Name; // The name of the AST node (if parsed)
|
||||||
StrC FailedProc; // The name of the procedure that failed
|
StrC FailedProc; // The name of the procedure that failed
|
||||||
};
|
};
|
||||||
// Stack nodes are allocated the error's allocator
|
// Stack nodes are allocated the error's allocator
|
||||||
|
|
||||||
struct Error
|
struct Error
|
||||||
{
|
{
|
||||||
String message;
|
String message;
|
||||||
StackNode* context_stack;
|
StackNode* context_stack;
|
||||||
};
|
};
|
||||||
}
|
GEN_NS_PARSER_END
|
||||||
|
|
||||||
struct ParseInfo
|
struct ParseInfo
|
||||||
{
|
{
|
||||||
@ -224,8 +238,8 @@ struct ParseInfo
|
|||||||
Arena CodeMem;
|
Arena CodeMem;
|
||||||
|
|
||||||
FileContents FileContent;
|
FileContents FileContent;
|
||||||
Array<parser::Token> Tokens;
|
Array<Token> Tokens;
|
||||||
Array<parser::Error> Errors;
|
Array<Error> Errors;
|
||||||
// Errors are allocated to a dedicated general arena.
|
// Errors are allocated to a dedicated general arena.
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -262,57 +276,70 @@ StrC token_fmt_impl( ssize, ... );
|
|||||||
|
|
||||||
Code untyped_str ( StrC content);
|
Code untyped_str ( StrC content);
|
||||||
Code untyped_fmt ( char const* fmt, ... );
|
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 endregion Untyped text
|
||||||
|
|
||||||
#pragma region Macros
|
#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
|
#ifndef token_fmt
|
||||||
# define gen_main main
|
/*
|
||||||
|
Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||||
# define __ NullCode
|
Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brackets (you can change it in token_fmt_va)
|
||||||
|
---------------------------------------------------------
|
||||||
// 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__ ) }
|
|
||||||
|
|
||||||
// Provides the number of arguments while passing args inplace.
|
|
||||||
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
|
||||||
|
|
||||||
// Just wrappers over common untyped code definition constructions.
|
|
||||||
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
|
||||||
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
|
||||||
|
|
||||||
# define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) )
|
|
||||||
|
|
||||||
/*
|
|
||||||
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 brakcets (you can change it in token_fmt_va)
|
|
||||||
---------------------------------------------------------
|
|
||||||
Example - A string with:
|
Example - A string with:
|
||||||
typedef <type> <name> <name>;
|
typedef <type> <name> <name>;
|
||||||
Will have a token_fmt arguments populated with:
|
Will have a token_fmt arguments populated with:
|
||||||
"type", strc_for_type,
|
"type", strc_for_type,
|
||||||
"name", strc_for_name,
|
"name", strc_for_name,
|
||||||
and:
|
and:
|
||||||
stringize( typedef <type> <name> <name>; ) )
|
stringize( typedef <type> <name> <name>; )
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
So the full call for this example would be:
|
So the full call for this example would be:
|
||||||
token_fmt(
|
token_fmt(
|
||||||
"type", strc_for_type
|
"type", strc_for_type
|
||||||
, "name", strc_for_name
|
, "name", strc_for_name
|
||||||
, stringize(
|
, stringize(
|
||||||
typedef <type> <name> <name>
|
typedef <type> <name> <name>
|
||||||
));
|
));
|
||||||
!----------------------------------------------------------
|
!----------------------------------------------------------
|
||||||
! Note: token_fmt_va is whitespace sensitive for the tokens.
|
! 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.
|
! 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__ )
|
#define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma endregion Macros
|
#pragma endregion Macros
|
@ -19,8 +19,8 @@ CodeClass parse_class( StrC def )
|
|||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
push_scope();
|
push_scope();
|
||||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class );
|
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class, parser_not_inplace_def );
|
||||||
pop(& Context);
|
parser_pop(& Context);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ CodeConstructor parse_constructor( StrC def )
|
|||||||
|
|
||||||
// TODO(Ed): Constructors can have prefix attributes
|
// TODO(Ed): Constructors can have prefix attributes
|
||||||
|
|
||||||
CodeSpecifiers specifiers;
|
CodeSpecifiers specifiers = NullCode;
|
||||||
Specifier specs_found[ 16 ] { Spec_NumSpecifiers };
|
Specifier specs_found[ 16 ] = { Spec_NumSpecifiers };
|
||||||
s32 NumSpecifiers = 0;
|
s32 NumSpecifiers = 0;
|
||||||
|
|
||||||
while ( left && is_specifier(currtok) )
|
while ( left && tok_is_specifier(currtok) )
|
||||||
{
|
{
|
||||||
Specifier spec = strc_to_specifier( to_str(currtok) );
|
Specifier spec = strc_to_specifier( tok_to_str(currtok) );
|
||||||
|
|
||||||
b32 ignore_spec = false;
|
b32 ignore_spec = false;
|
||||||
|
|
||||||
@ -59,8 +59,8 @@ CodeConstructor parse_constructor( StrC def )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
log_failure( "Invalid specifier %s for variable\n%s", spec_to_str( spec ), to_string(Context) );
|
log_failure( "Invalid specifier %s for variable\n%s", spec_to_str( spec ), parser_to_string(Context) );
|
||||||
pop(& Context);
|
parser_pop(& Context);
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ CodeConstructor parse_constructor( StrC def )
|
|||||||
}
|
}
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
CodeConstructor result = parse_constructor( specifiers );
|
CodeConstructor result = parser_parse_constructor( specifiers );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ CodeDestructor parse_destructor( StrC def )
|
|||||||
// TODO(Ed): Destructors can have virtual
|
// TODO(Ed): Destructors can have virtual
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
CodeDestructor result = parse_destructor();
|
CodeDestructor result = parser_parse_destructor(NullCode);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,12 +109,12 @@ CodeEnum parse_enum( StrC def )
|
|||||||
TokArray toks = lex( def );
|
TokArray toks = lex( def );
|
||||||
if ( toks.Arr == nullptr )
|
if ( toks.Arr == nullptr )
|
||||||
{
|
{
|
||||||
pop(& Context);
|
parser_pop(& Context);
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_enum();
|
return parser_parse_enum( parser_not_inplace_def);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeBody parse_export_body( StrC def )
|
CodeBody parse_export_body( StrC def )
|
||||||
@ -127,7 +127,7 @@ CodeBody parse_export_body( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_export_body();
|
return parser_parse_export_body();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeExtern parse_extern_link( StrC def )
|
CodeExtern parse_extern_link( StrC def )
|
||||||
@ -140,7 +140,7 @@ CodeExtern parse_extern_link( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_extern_link();
|
return parser_parse_extern_link();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeFriend parse_friend( StrC def )
|
CodeFriend parse_friend( StrC def )
|
||||||
@ -153,7 +153,7 @@ CodeFriend parse_friend( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_friend();
|
return parser_parse_friend();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeFn parse_function( StrC def )
|
CodeFn parse_function( StrC def )
|
||||||
@ -166,7 +166,7 @@ CodeFn parse_function( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return (CodeFn) parse_function();
|
return (CodeFn) parser_parse_function();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeBody parse_global_body( StrC def )
|
CodeBody parse_global_body( StrC def )
|
||||||
@ -181,7 +181,7 @@ CodeBody parse_global_body( StrC def )
|
|||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
push_scope();
|
push_scope();
|
||||||
CodeBody result = parse_global_nspace( CT_Global_Body );
|
CodeBody result = parse_global_nspace( CT_Global_Body );
|
||||||
pop(& Context);
|
parser_pop(& Context);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ CodeNS parse_namespace( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_namespace();
|
return parser_parse_namespace();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeOperator parse_operator( StrC def )
|
CodeOperator parse_operator( StrC def )
|
||||||
@ -208,7 +208,7 @@ CodeOperator parse_operator( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return (CodeOperator) parse_operator();
|
return (CodeOperator) parser_parse_operator();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeOpCast parse_operator_cast( StrC def )
|
CodeOpCast parse_operator_cast( StrC def )
|
||||||
@ -221,7 +221,7 @@ CodeOpCast parse_operator_cast( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_operator_cast();
|
return parser_parse_operator_cast(NullCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeStruct parse_struct( StrC def )
|
CodeStruct parse_struct( StrC def )
|
||||||
@ -235,8 +235,8 @@ CodeStruct parse_struct( StrC def )
|
|||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
push_scope();
|
push_scope();
|
||||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct );
|
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct, parser_not_inplace_def );
|
||||||
pop(& Context);
|
parser_pop(& Context);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ CodeTemplate parse_template( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_template();
|
return parser_parse_template();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeTypename parse_type( StrC def )
|
CodeTypename parse_type( StrC def )
|
||||||
@ -263,7 +263,7 @@ CodeTypename parse_type( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_type();
|
return parser_parse_type( parser_not_from_template, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeTypedef parse_typedef( StrC def )
|
CodeTypedef parse_typedef( StrC def )
|
||||||
@ -276,7 +276,7 @@ CodeTypedef parse_typedef( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_typedef();
|
return parser_parse_typedef();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeUnion parse_union( StrC def )
|
CodeUnion parse_union( StrC def )
|
||||||
@ -289,7 +289,7 @@ CodeUnion parse_union( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_union();
|
return parser_parse_union( parser_not_inplace_def);
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeUsing parse_using( StrC def )
|
CodeUsing parse_using( StrC def )
|
||||||
@ -302,7 +302,7 @@ CodeUsing parse_using( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_using();
|
return parser_parse_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeVar parse_variable( StrC def )
|
CodeVar parse_variable( StrC def )
|
||||||
@ -315,15 +315,31 @@ CodeVar parse_variable( StrC def )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
|
|
||||||
Context.Tokens = toks;
|
Context.Tokens = toks;
|
||||||
return parse_variable();
|
return parser_parse_variable();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Undef helper macros
|
// Undef helper macros
|
||||||
# undef check_parse_args
|
#undef check_parse_args
|
||||||
# undef currtok
|
#undef currtok_noskip
|
||||||
# undef prevtok
|
#undef currtok
|
||||||
# undef nexttok
|
#undef peektok
|
||||||
# undef eat
|
#undef prevtok
|
||||||
# undef left
|
#undef nexttok
|
||||||
# undef check
|
#undef nexttok_noskip
|
||||||
# undef push_scope
|
#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;
|
ssize remaining = buf_size;
|
||||||
|
|
||||||
local_persist
|
local_persist
|
||||||
FixedArena<TokenFmt_TokenMap_MemSize> tok_map_arena;
|
TokenMap_FixedArena tok_map_arena;
|
||||||
fixed_arena_init( & tok_map_arena);
|
fixed_arena_init( & tok_map_arena);
|
||||||
|
|
||||||
local_persist
|
local_persist
|
||||||
HashTable(StrC) tok_map;
|
StringTable tok_map;
|
||||||
{
|
{
|
||||||
tok_map = hashtable_init(StrC, fixed_arena_allocator_info(& tok_map_arena) );
|
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->Type = CT_Untyped;
|
||||||
result->Content = result->Name;
|
result->Content = result->Name;
|
||||||
|
|
||||||
if ( result->Name == nullptr )
|
if ( result->Name.Len == 0 )
|
||||||
{
|
{
|
||||||
log_failure( "untyped_str: could not cache string" );
|
log_failure( "untyped_str: could not cache string" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
@ -138,13 +138,16 @@ Code untyped_fmt( char const* fmt, ...)
|
|||||||
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
ssize length = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
StrC buf_str = { str_len_capped(fmt, MaxNameLength), fmt };
|
||||||
|
StrC uncapped_str = { length, buf };
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_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->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" );
|
log_failure( "untyped_fmt: could not cache string" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
@ -153,7 +156,7 @@ Code untyped_fmt( char const* fmt, ...)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Code untyped_token_fmt( s32 num_tokens, ... )
|
Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||||
{
|
{
|
||||||
if ( num_tokens == 0 )
|
if ( num_tokens == 0 )
|
||||||
{
|
{
|
||||||
@ -165,17 +168,19 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
|||||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num_tokens);
|
va_start(va, fmt);
|
||||||
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
|
ssize length = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num_tokens, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
|
StrC buf_str = { length, buf };
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Name = get_cached_string( { length, buf } );
|
result->Name = get_cached_string( buf_str );
|
||||||
result->Type = CT_Untyped;
|
result->Type = CT_Untyped;
|
||||||
result->Content = result->Name;
|
result->Content = result->Name;
|
||||||
|
|
||||||
if ( result->Name == nullptr )
|
if ( result->Name.Len == 0 )
|
||||||
{
|
{
|
||||||
log_failure( "untyped_fmt: could not cache string" );
|
log_failure( "untyped_fmt: could not cache string" );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
@ -12,7 +12,8 @@ enum OpValidateResult : u32
|
|||||||
OpValResult_Member
|
OpValResult_Member
|
||||||
};
|
};
|
||||||
|
|
||||||
OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTypename ret_type, CodeSpecifiers specifier )
|
internal neverinline
|
||||||
|
OpValidateResult operator__validate( Operator op, CodeParams params_code, CodeTypename ret_type, CodeSpecifiers specifier )
|
||||||
{
|
{
|
||||||
if ( op == Op_Invalid )
|
if ( op == Op_Invalid )
|
||||||
{
|
{
|
||||||
@ -390,7 +391,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define null_check( Context_, Code_ ) \
|
#define null_check( Context_, Code_ ) \
|
||||||
if ( Code_ != nullptr ) \
|
if ( Code_ == nullptr ) \
|
||||||
{ \
|
{ \
|
||||||
log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \
|
log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \
|
||||||
return InvalidCode; \
|
return InvalidCode; \
|
||||||
@ -416,7 +417,6 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
#pragma endregion Helper Marcos
|
#pragma endregion Helper Marcos
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The implementaiton of the upfront constructors involves doing three things:
|
The implementaiton of the upfront constructors involves doing three things:
|
||||||
* Validate the arguments given to construct the intended type of AST is valid.
|
* Validate the arguments given to construct the intended type of AST is valid.
|
||||||
@ -482,10 +482,12 @@ CodeComment def_comment( StrC content )
|
|||||||
if ( * string_back(cmt_formatted) != '\n' )
|
if ( * string_back(cmt_formatted) != '\n' )
|
||||||
string_append_strc( & cmt_formatted, txt("\n") );
|
string_append_strc( & cmt_formatted, txt("\n") );
|
||||||
|
|
||||||
|
StrC name = { string_length(cmt_formatted), cmt_formatted };
|
||||||
|
|
||||||
Code
|
Code
|
||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = CT_Comment;
|
result->Type = CT_Comment;
|
||||||
result->Name = get_cached_string( { string_length(cmt_formatted), cmt_formatted } );
|
result->Name = get_cached_string( name );
|
||||||
result->Content = result->Name;
|
result->Content = result->Name;
|
||||||
|
|
||||||
string_free(& cmt_formatted);
|
string_free(& cmt_formatted);
|
||||||
@ -495,7 +497,7 @@ CodeComment def_comment( StrC content )
|
|||||||
|
|
||||||
CodeConstructor def_constructor( Opts_def_constructor p )
|
CodeConstructor def_constructor( Opts_def_constructor p )
|
||||||
{
|
{
|
||||||
CodeParam params = p.params;
|
CodeParams params = p.params;
|
||||||
Code initializer_list = p.initializer_list;
|
Code initializer_list = p.initializer_list;
|
||||||
Code body = p.body;
|
Code body = p.body;
|
||||||
|
|
||||||
@ -546,7 +548,7 @@ CodeClass def_class( StrC name, Opts_def_struct p )
|
|||||||
{
|
{
|
||||||
name_check( def_class, name );
|
name_check( def_class, name );
|
||||||
|
|
||||||
Code body = p.body;
|
CodeBody body = p.body;
|
||||||
CodeTypename parent = p.parent;
|
CodeTypename parent = p.parent;
|
||||||
AccessSpec parent_access = p.parent_access;
|
AccessSpec parent_access = p.parent_access;
|
||||||
CodeAttributes attributes = p.attributes;
|
CodeAttributes attributes = p.attributes;
|
||||||
@ -586,7 +588,7 @@ CodeClass def_class( StrC name, Opts_def_struct p )
|
|||||||
|
|
||||||
result->Type = CT_Class;
|
result->Type = CT_Class;
|
||||||
result->Body = body;
|
result->Body = body;
|
||||||
result->Body->Parent = result; // TODO(Ed): Review this?
|
result->Body->Parent = cast(Code, result); // TODO(Ed): Review this?
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -613,7 +615,7 @@ CodeClass def_class( StrC name, Opts_def_struct p )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeDefine def_define( StrC name, StrC content )
|
CodeDefine def_define( StrC name, StrC content, Opts_def_define p )
|
||||||
{
|
{
|
||||||
name_check( def_define, name );
|
name_check( def_define, name );
|
||||||
|
|
||||||
@ -637,6 +639,17 @@ CodeDefine def_define( StrC name, StrC content )
|
|||||||
else
|
else
|
||||||
result->Content = get_cached_string( string_to_strc(string_fmt_buf(GlobalAllocator, "%SC\n", content)) );
|
result->Content = get_cached_string( string_to_strc(string_fmt_buf(GlobalAllocator, "%SC\n", content)) );
|
||||||
|
|
||||||
|
b32 append_preprocess_defines = ! p.dont_append_preprocess_defines;
|
||||||
|
if ( append_preprocess_defines ) {
|
||||||
|
// Add the define to PreprocessorDefines for usage in parsing
|
||||||
|
s32 lex_id_len = 0;
|
||||||
|
for (; lex_id_len < result->Name.Len; ++ lex_id_len ) {
|
||||||
|
if ( result->Name.Ptr[lex_id_len] == '(' )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
StrC lex_id = { lex_id_len, result->Name.Ptr };
|
||||||
|
array_append(PreprocessorDefines, lex_id );
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -682,11 +695,12 @@ CodeDestructor def_destructor( Opts_def_destructor p )
|
|||||||
|
|
||||||
CodeEnum def_enum( StrC name, Opts_def_enum p )
|
CodeEnum def_enum( StrC name, Opts_def_enum p )
|
||||||
{
|
{
|
||||||
Code body = p.body;
|
CodeBody body = p.body;
|
||||||
CodeTypename type = p.type;
|
CodeTypename type = p.type;
|
||||||
EnumT specifier = p.specifier;
|
EnumT specifier = p.specifier;
|
||||||
CodeAttributes attributes = p.attributes;
|
CodeAttributes attributes = p.attributes;
|
||||||
ModuleFlag mflags = p.mflags;
|
ModuleFlag mflags = p.mflags;
|
||||||
|
Code type_macro = p.type_macro;
|
||||||
|
|
||||||
name_check( def_enum, name );
|
name_check( def_enum, name );
|
||||||
|
|
||||||
@ -738,6 +752,10 @@ CodeEnum def_enum( StrC name, Opts_def_enum p )
|
|||||||
{
|
{
|
||||||
result->UnderlyingType = type;
|
result->UnderlyingType = type;
|
||||||
}
|
}
|
||||||
|
else if ( type_macro )
|
||||||
|
{
|
||||||
|
result->UnderlyingTypeMacro = type_macro;
|
||||||
|
}
|
||||||
else if ( result->Type != CT_Enum_Class_Fwd && result->Type != CT_Enum_Fwd )
|
else if ( result->Type != CT_Enum_Class_Fwd && result->Type != CT_Enum_Fwd )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_enum: enum forward declaration must have an underlying type" );
|
log_failure( "gen::def_enum: enum forward declaration must have an underlying type" );
|
||||||
@ -764,7 +782,7 @@ CodeExec def_execution( StrC content )
|
|||||||
return (CodeExec) result;
|
return (CodeExec) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeExtern def_extern_link( StrC name, Code body )
|
CodeExtern def_extern_link( StrC name, CodeBody body )
|
||||||
{
|
{
|
||||||
name_check( def_extern_linkage, name );
|
name_check( def_extern_linkage, name );
|
||||||
null_check( def_extern_linkage, body );
|
null_check( def_extern_linkage, body );
|
||||||
@ -816,9 +834,9 @@ CodeFriend def_friend( Code declaration )
|
|||||||
|
|
||||||
CodeFn def_function( StrC name, Opts_def_function p )
|
CodeFn def_function( StrC name, Opts_def_function p )
|
||||||
{
|
{
|
||||||
CodeParam params = p.params;
|
CodeParams params = p.params;
|
||||||
CodeTypename ret_type = p.ret_type;
|
CodeTypename ret_type = p.ret_type;
|
||||||
Code body = p.body;
|
CodeBody body = p.body;
|
||||||
CodeSpecifiers specifiers = p.specs;
|
CodeSpecifiers specifiers = p.specs;
|
||||||
CodeAttributes attributes = p.attrs;
|
CodeAttributes attributes = p.attrs;
|
||||||
ModuleFlag mflags = p.mflags;
|
ModuleFlag mflags = p.mflags;
|
||||||
@ -934,7 +952,7 @@ CodeModule def_module( StrC name, Opts_def_module p )
|
|||||||
return (CodeModule) result;
|
return (CodeModule) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeNS def_namespace( StrC name, Code body, Opts_def_namespace p )
|
CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace p )
|
||||||
{
|
{
|
||||||
name_check( def_namespace, name );
|
name_check( def_namespace, name );
|
||||||
null_check( def_namespace, body);
|
null_check( def_namespace, body);
|
||||||
@ -956,9 +974,9 @@ CodeNS def_namespace( StrC name, Code body, Opts_def_namespace p )
|
|||||||
|
|
||||||
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
||||||
{
|
{
|
||||||
CodeParam params_code = p.params;
|
CodeParams params_code = p.params;
|
||||||
CodeTypename ret_type = p.ret_type;
|
CodeTypename ret_type = p.ret_type;
|
||||||
Code body = p.body;
|
CodeBody body = p.body;
|
||||||
CodeSpecifiers specifiers = p.specifiers;
|
CodeSpecifiers specifiers = p.specifiers;
|
||||||
CodeAttributes attributes = p.attributes;
|
CodeAttributes attributes = p.attributes;
|
||||||
ModuleFlag mflags = p.mflags;
|
ModuleFlag mflags = p.mflags;
|
||||||
@ -989,9 +1007,12 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
|||||||
name = str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
|
name = str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
|
||||||
else
|
else
|
||||||
name = str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
|
name = str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
|
||||||
|
|
||||||
|
StrC name_resolved = { str_len(name), name };
|
||||||
|
|
||||||
CodeOperator
|
CodeOperator
|
||||||
result = (CodeOperator) make_code();
|
result = (CodeOperator) make_code();
|
||||||
result->Name = get_cached_string( { str_len(name), name } );
|
result->Name = get_cached_string( name_resolved );
|
||||||
result->ModuleFlags = mflags;
|
result->ModuleFlags = mflags;
|
||||||
result->Op = op;
|
result->Op = op;
|
||||||
|
|
||||||
@ -1038,7 +1059,7 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
|
|||||||
|
|
||||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
||||||
{
|
{
|
||||||
Code body = p.body;
|
CodeBody body = p.body;
|
||||||
CodeSpecifiers const_spec = p.specs;
|
CodeSpecifiers const_spec = p.specs;
|
||||||
|
|
||||||
null_check( def_operator_cast, type );
|
null_check( def_operator_cast, type );
|
||||||
@ -1077,7 +1098,7 @@ CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeParam def_param( CodeTypename type, StrC name, Opts_def_param p )
|
CodeParams def_param( CodeTypename type, StrC name, Opts_def_param p )
|
||||||
{
|
{
|
||||||
name_check( def_param, name );
|
name_check( def_param, name );
|
||||||
null_check( def_param, type );
|
null_check( def_param, type );
|
||||||
@ -1094,8 +1115,8 @@ CodeParam def_param( CodeTypename type, StrC name, Opts_def_param p )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeParam
|
CodeParams
|
||||||
result = (CodeParam) make_code();
|
result = (CodeParams) make_code();
|
||||||
result->Type = CT_Parameters;
|
result->Type = CT_Parameters;
|
||||||
result->Name = get_cached_string( name );
|
result->Name = get_cached_string( name );
|
||||||
|
|
||||||
@ -1168,7 +1189,7 @@ CodeSpecifiers def_specifier( Specifier spec )
|
|||||||
|
|
||||||
CodeStruct def_struct( StrC name, Opts_def_struct p )
|
CodeStruct def_struct( StrC name, Opts_def_struct p )
|
||||||
{
|
{
|
||||||
Code body = p.body;
|
CodeBody body = p.body;
|
||||||
CodeTypename parent = p.parent;
|
CodeTypename parent = p.parent;
|
||||||
AccessSpec parent_access = p.parent_access;
|
AccessSpec parent_access = p.parent_access;
|
||||||
CodeAttributes attributes = p.attributes;
|
CodeAttributes attributes = p.attributes;
|
||||||
@ -1198,7 +1219,7 @@ CodeStruct def_struct( StrC name, Opts_def_struct p )
|
|||||||
result = (CodeStruct) make_code();
|
result = (CodeStruct) make_code();
|
||||||
result->ModuleFlags = mflags;
|
result->ModuleFlags = mflags;
|
||||||
|
|
||||||
if ( name )
|
if ( name.Len )
|
||||||
result->Name = get_cached_string( name );
|
result->Name = get_cached_string( name );
|
||||||
|
|
||||||
if ( body )
|
if ( body )
|
||||||
@ -1224,14 +1245,14 @@ CodeStruct def_struct( StrC name, Opts_def_struct p )
|
|||||||
{
|
{
|
||||||
for (s32 idx = 0; idx < num_interfaces; idx++ )
|
for (s32 idx = 0; idx < num_interfaces; idx++ )
|
||||||
{
|
{
|
||||||
add_interface(result, interfaces[idx] );
|
struct_add_interface(result, interfaces[idx] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeTemplate def_template( CodeParam params, Code declaration, Opts_def_template p )
|
CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template p )
|
||||||
{
|
{
|
||||||
null_check( def_template, declaration );
|
null_check( def_template, declaration );
|
||||||
|
|
||||||
@ -1303,6 +1324,8 @@ CodeTypename def_type( StrC name, Opts_def_type p )
|
|||||||
if ( arrayexpr )
|
if ( arrayexpr )
|
||||||
result->ArrExpr = arrayexpr;
|
result->ArrExpr = arrayexpr;
|
||||||
|
|
||||||
|
result->TypeTag = p.type_tag;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1336,7 +1359,7 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Registering the type.
|
// Registering the type.
|
||||||
Code registered_type = def_type( name );
|
CodeTypename registered_type = def_type( name );
|
||||||
|
|
||||||
if ( ! registered_type )
|
if ( ! registered_type )
|
||||||
{
|
{
|
||||||
@ -1371,7 +1394,7 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeUnion def_union( StrC name, Code body, Opts_def_union p )
|
CodeUnion def_union( StrC name, CodeBody body, Opts_def_union p )
|
||||||
{
|
{
|
||||||
null_check( def_union, body );
|
null_check( def_union, body );
|
||||||
|
|
||||||
@ -1403,12 +1426,12 @@ CodeUnion def_union( StrC name, Code body, Opts_def_union p )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeUsing def_using( StrC name, Code type, Opts_def_using p )
|
CodeUsing def_using( StrC name, CodeTypename type, Opts_def_using p )
|
||||||
{
|
{
|
||||||
name_check( def_using, name );
|
name_check( def_using, name );
|
||||||
null_check( def_using, type );
|
null_check( def_using, type );
|
||||||
|
|
||||||
Code register_type = def_type( name );
|
CodeTypename register_type = def_type( name );
|
||||||
|
|
||||||
if ( ! register_type )
|
if ( ! register_type )
|
||||||
{
|
{
|
||||||
@ -1449,7 +1472,7 @@ CodeUsing def_using_namespace( StrC name )
|
|||||||
return (CodeUsing) result;
|
return (CodeUsing) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeVar def_variable( CodeTypename type, StrC name, Code value, Opts_def_variable p )
|
CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable p )
|
||||||
{
|
{
|
||||||
name_check( def_variable, name );
|
name_check( def_variable, name );
|
||||||
null_check( def_variable, type );
|
null_check( def_variable, type );
|
||||||
@ -1472,9 +1495,9 @@ CodeVar def_variable( CodeTypename type, StrC name, Code value, Opts_def_variabl
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( value && value->Type != CT_Untyped )
|
if ( p.value && p.value->Type != CT_Untyped )
|
||||||
{
|
{
|
||||||
log_failure( "gen::def_variable: value was not a `Untyped` type - %s", code_debug_str(value) );
|
log_failure( "gen::def_variable: value was not a `Untyped` type - %s", code_debug_str(p.value) );
|
||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1492,8 +1515,8 @@ CodeVar def_variable( CodeTypename type, StrC name, Code value, Opts_def_variabl
|
|||||||
if ( p.specifiers )
|
if ( p.specifiers )
|
||||||
result->Specs = p.specifiers;
|
result->Specs = p.specifiers;
|
||||||
|
|
||||||
if ( value )
|
if ( p.value )
|
||||||
result->Value = value;
|
result->Value = p.value;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1913,7 +1936,7 @@ CodeBody def_global_body( s32 num, ... )
|
|||||||
{
|
{
|
||||||
case CT_Global_Body:
|
case CT_Global_Body:
|
||||||
// result.body_append( entry.code_cast<CodeBody>() ) ;
|
// result.body_append( entry.code_cast<CodeBody>() ) ;
|
||||||
body_append( result, cast(CodeBody, entry) );
|
body_append_body( result, cast(CodeBody, entry) );
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||||
@ -1954,7 +1977,7 @@ CodeBody def_global_body( s32 num, Code* codes )
|
|||||||
switch (entry->Type)
|
switch (entry->Type)
|
||||||
{
|
{
|
||||||
case CT_Global_Body:
|
case CT_Global_Body:
|
||||||
body_append(result, cast(CodeBody, entry) );
|
body_append_body(result, cast(CodeBody, entry) );
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||||
@ -2046,7 +2069,7 @@ CodeBody def_namespace_body( s32 num, Code* codes )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeParam def_params( s32 num, ... )
|
CodeParams def_params( s32 num, ... )
|
||||||
{
|
{
|
||||||
def_body_start( def_params );
|
def_body_start( def_params );
|
||||||
|
|
||||||
@ -2054,7 +2077,7 @@ CodeParam def_params( s32 num, ... )
|
|||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
|
|
||||||
Code_POD pod = va_arg(va, Code_POD);
|
Code_POD pod = va_arg(va, Code_POD);
|
||||||
CodeParam param = pcast( CodeParam, pod );
|
CodeParams param = pcast( CodeParams, pod );
|
||||||
|
|
||||||
null_check( def_params, param );
|
null_check( def_params, param );
|
||||||
|
|
||||||
@ -2064,12 +2087,12 @@ CodeParam def_params( s32 num, ... )
|
|||||||
return InvalidCode;
|
return InvalidCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeParam result = (CodeParam) code_duplicate(param);
|
CodeParams result = (CodeParams) code_duplicate(param);
|
||||||
|
|
||||||
while ( -- num )
|
while ( -- num )
|
||||||
{
|
{
|
||||||
pod = va_arg(va, Code_POD);
|
pod = va_arg(va, Code_POD);
|
||||||
param = pcast( CodeParam, pod );
|
param = pcast( CodeParams, pod );
|
||||||
|
|
||||||
if ( param->Type != CT_Parameters )
|
if ( param->Type != CT_Parameters )
|
||||||
{
|
{
|
||||||
@ -2084,12 +2107,12 @@ CodeParam def_params( s32 num, ... )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeParam def_params( s32 num, CodeParam* codes )
|
CodeParams def_params( s32 num, CodeParams* codes )
|
||||||
{
|
{
|
||||||
def_body_code_array_start( def_params );
|
def_body_code_array_start( def_params );
|
||||||
|
|
||||||
# define check_current() \
|
# define check_current(current) \
|
||||||
if ( current.ast == nullptr ) \
|
if ( current == nullptr ) \
|
||||||
{ \
|
{ \
|
||||||
log_failure("gen::def_params: Provide a null code in codes array"); \
|
log_failure("gen::def_params: Provide a null code in codes array"); \
|
||||||
return InvalidCode; \
|
return InvalidCode; \
|
||||||
@ -2101,18 +2124,18 @@ CodeParam def_params( s32 num, CodeParam* codes )
|
|||||||
return InvalidCode; \
|
return InvalidCode; \
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeParam current = (CodeParam)code_duplicate(* codes);
|
CodeParams current = (CodeParams)code_duplicate(* codes);
|
||||||
check_current();
|
check_current(current);
|
||||||
|
|
||||||
CodeParam
|
CodeParams
|
||||||
result = (CodeParam) make_code();
|
result = (CodeParams) make_code();
|
||||||
result->Name = current->Name;
|
result->Name = current->Name;
|
||||||
result->Type = current->Type;
|
result->Type = current->Type;
|
||||||
result->ValueType = current->ValueType;
|
result->ValueType = current->ValueType;
|
||||||
|
|
||||||
while( codes++, current = * codes, num--, num > 0 )
|
while( codes++, current = * codes, num--, num > 0 )
|
||||||
{
|
{
|
||||||
check_current();
|
check_current(current);
|
||||||
params_append(result, current );
|
params_append(result, current );
|
||||||
}
|
}
|
||||||
# undef check_current
|
# undef check_current
|
||||||
@ -2291,7 +2314,7 @@ CodeBody def_union_body( s32 num, ... )
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeBody def_union_body( s32 num, CodeUnion* codes )
|
CodeBody def_union_body( s32 num, Code* codes )
|
||||||
{
|
{
|
||||||
def_body_code_array_start( def_union_body );
|
def_body_code_array_start( def_union_body );
|
||||||
|
|
@ -21,6 +21,7 @@ enum TokFlags : u32
|
|||||||
TF_Literal = bit( 12 ),
|
TF_Literal = bit( 12 ),
|
||||||
|
|
||||||
TF_Null = 0,
|
TF_Null = 0,
|
||||||
|
TF_UnderlyingType = GEN_U32_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Token
|
struct Token
|
||||||
@ -35,66 +36,67 @@ struct Token
|
|||||||
|
|
||||||
constexpr Token NullToken { nullptr, 0, Tok_Invalid, false, 0, TF_Null };
|
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);
|
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;
|
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 );
|
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 );
|
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 );
|
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 );
|
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 );
|
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 );
|
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 );
|
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 );
|
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) );
|
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"
|
string_append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
|
||||||
, tok.Line, tok.Column
|
, tok.Line, tok.Column
|
||||||
@ -111,9 +113,9 @@ struct TokArray
|
|||||||
s32 Idx;
|
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 )
|
if ( skip_formatting )
|
||||||
{
|
{
|
||||||
@ -124,7 +126,7 @@ Token* current(TokArray* self, bool skip_formatting )
|
|||||||
return & self->Arr[self->Idx];
|
return & self->Arr[self->Idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* peek(TokArray self, bool skip_formatting)
|
Token* lex_peek(TokArray self, bool skip_formatting)
|
||||||
{
|
{
|
||||||
s32 idx = self.Idx;
|
s32 idx = self.Idx;
|
||||||
|
|
||||||
@ -139,7 +141,7 @@ Token* peek(TokArray self, bool skip_formatting)
|
|||||||
return & self.Arr[idx];
|
return & self.Arr[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* previous(TokArray self, bool skip_formatting)
|
Token* lex_previous(TokArray self, bool skip_formatting)
|
||||||
{
|
{
|
||||||
s32 idx = self.Idx;
|
s32 idx = self.Idx;
|
||||||
|
|
||||||
@ -154,7 +156,7 @@ Token* previous(TokArray self, bool skip_formatting)
|
|||||||
return & self.Arr[idx - 1];
|
return & self.Arr[idx - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
Token* next(TokArray self, bool skip_formatting)
|
Token* lex_next(TokArray self, bool skip_formatting)
|
||||||
{
|
{
|
||||||
s32 idx = self.Idx;
|
s32 idx = self.Idx;
|
||||||
|
|
||||||
@ -169,9 +171,9 @@ Token* next(TokArray self, bool skip_formatting)
|
|||||||
return & self.Arr[idx + 1];
|
return & self.Arr[idx + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
global Arena_256KB defines_map_arena;
|
global FixedArena_256KB Lexer_defines_map_arena;
|
||||||
global HashTable(StrC) defines;
|
global StringTable Lexer_defines;
|
||||||
global Array(Token) Tokens;
|
global Array(Token) Lexer_Tokens;
|
||||||
|
|
||||||
#define current ( * ctx->scanner )
|
#define current ( * ctx->scanner )
|
||||||
|
|
||||||
@ -190,7 +192,7 @@ global Array(Token) Tokens;
|
|||||||
ctx->scanner++; \
|
ctx->scanner++; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SkipWhitespace() \
|
#define skip_whitespace() \
|
||||||
while ( ctx->left && char_is_space( current ) ) \
|
while ( ctx->left && char_is_space( current ) ) \
|
||||||
{ \
|
{ \
|
||||||
move_forward(); \
|
move_forward(); \
|
||||||
@ -228,7 +230,7 @@ struct LexContext
|
|||||||
char const* scanner;
|
char const* scanner;
|
||||||
s32 line;
|
s32 line;
|
||||||
s32 column;
|
s32 column;
|
||||||
HashTable(StrC) defines;
|
StringTable defines;
|
||||||
Token token;
|
Token token;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -237,10 +239,10 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
|||||||
{
|
{
|
||||||
char const* hash = ctx->scanner;
|
char const* hash = ctx->scanner;
|
||||||
Token hash_tok = { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess };
|
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();
|
move_forward();
|
||||||
SkipWhitespace();
|
skip_whitespace();
|
||||||
|
|
||||||
ctx->token.Text = ctx->scanner;
|
ctx->token.Text = ctx->scanner;
|
||||||
while (ctx->left && ! char_is_space(current) )
|
while (ctx->left && ! char_is_space(current) )
|
||||||
@ -249,7 +251,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
|||||||
ctx->token.Length++;
|
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;
|
bool is_preprocessor = ctx->token.Type >= Tok_Preprocess_Define && ctx->token.Type <= Tok_Preprocess_Pragma;
|
||||||
if ( ! is_preprocessor )
|
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.Length = ctx->token.Length + ctx->token.Text - hash;
|
||||||
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.
|
return Lex_Continue; // Skip found token, its all handled here.
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf )
|
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf )
|
||||||
{
|
{
|
||||||
ctx->token.Flags |= TF_Preprocess_Cond;
|
ctx->token.Flags |= TF_Preprocess_Cond;
|
||||||
array_append( Tokens, ctx->token );
|
array_append( Lexer_Tokens, ctx->token );
|
||||||
end_line();
|
end_line();
|
||||||
return Lex_Continue;
|
return Lex_Continue;
|
||||||
}
|
}
|
||||||
@ -329,9 +331,9 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
|||||||
ctx->token.Flags |= TF_Preprocess_Cond;
|
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 )
|
if ( ctx->token.Type == Tok_Preprocess_Define )
|
||||||
{
|
{
|
||||||
@ -353,10 +355,10 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
|||||||
name.Length++;
|
name.Length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
array_append( Tokens, name );
|
array_append( Lexer_Tokens, name );
|
||||||
|
|
||||||
u64 key = crc32( name.Text, name.Length );
|
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 };
|
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();
|
move_forward();
|
||||||
}
|
}
|
||||||
|
|
||||||
array_append( Tokens, preprocess_content );
|
array_append( Lexer_Tokens, preprocess_content );
|
||||||
return Lex_Continue; // Skip found token, its all handled here.
|
return Lex_Continue; // Skip found token, its all handled here.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,7 +464,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
|||||||
preprocess_content.Length++;
|
preprocess_content.Length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
array_append( Tokens, preprocess_content );
|
array_append( Lexer_Tokens, preprocess_content );
|
||||||
return Lex_Continue; // Skip found token, its all handled here.
|
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 )
|
if ( ctx->token.Type != Tok_Invalid )
|
||||||
{
|
{
|
||||||
array_append( Tokens, ctx->token );
|
array_append( Lexer_Tokens, ctx->token );
|
||||||
return;
|
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 )
|
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 )
|
if ( type == Tok_Decl_Extern_Linkage )
|
||||||
{
|
{
|
||||||
SkipWhitespace();
|
skip_whitespace();
|
||||||
|
|
||||||
if ( current != '"' )
|
if ( current != '"' )
|
||||||
{
|
{
|
||||||
@ -498,7 +500,7 @@ void lex_found_token( LexContext* ctx )
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx->token.Type = type;
|
ctx->token.Type = type;
|
||||||
array_append( Tokens, ctx->token );
|
array_append( Lexer_Tokens, ctx->token );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,7 +510,7 @@ void lex_found_token( LexContext* ctx )
|
|||||||
{
|
{
|
||||||
ctx->token.Type = type;
|
ctx->token.Type = type;
|
||||||
ctx->token.Flags |= TF_Specifier;
|
ctx->token.Flags |= TF_Specifier;
|
||||||
array_append( Tokens, ctx->token );
|
array_append( Lexer_Tokens, ctx->token );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,7 +518,7 @@ void lex_found_token( LexContext* ctx )
|
|||||||
if ( type != Tok_Invalid )
|
if ( type != Tok_Invalid )
|
||||||
{
|
{
|
||||||
ctx->token.Type = type;
|
ctx->token.Type = type;
|
||||||
array_append( Tokens, ctx->token );
|
array_append( Lexer_Tokens, ctx->token );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,7 +572,7 @@ void lex_found_token( LexContext* ctx )
|
|||||||
ctx->token.Type = Tok_Identifier;
|
ctx->token.Type = Tok_Identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
array_append( Tokens, ctx->token );
|
array_append( Lexer_Tokens, ctx->token );
|
||||||
}
|
}
|
||||||
|
|
||||||
neverinline
|
neverinline
|
||||||
@ -581,7 +583,7 @@ TokArray lex( StrC content )
|
|||||||
c.content = content;
|
c.content = content;
|
||||||
c.left = content.Len;
|
c.left = content.Len;
|
||||||
c.scanner = content.Ptr;
|
c.scanner = content.Ptr;
|
||||||
c.defines = defines;
|
c.defines = Lexer_defines;
|
||||||
|
|
||||||
char const* word = c.scanner;
|
char const* word = c.scanner;
|
||||||
s32 word_length = 0;
|
s32 word_length = 0;
|
||||||
@ -589,17 +591,18 @@ TokArray lex( StrC content )
|
|||||||
c.line = 1;
|
c.line = 1;
|
||||||
c.column = 1;
|
c.column = 1;
|
||||||
|
|
||||||
SkipWhitespace();
|
skip_whitespace();
|
||||||
if ( c.left <= 0 )
|
if ( c.left <= 0 )
|
||||||
{
|
{
|
||||||
log_failure( "gen::lex: no tokens found (only whitespace provided)" );
|
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))
|
for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); entry = array_next(PreprocessorDefines, entry))
|
||||||
{
|
{
|
||||||
s32 length = 0;
|
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 == '_') )
|
while ( entry->Len > length && (char_is_alphanumeric( *entry_scanner ) || *entry_scanner == '_') )
|
||||||
{
|
{
|
||||||
entry_scanner++;
|
entry_scanner++;
|
||||||
@ -610,11 +613,11 @@ TokArray lex( StrC content )
|
|||||||
length++;
|
length++;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 key = crc32( * entry, length );
|
u64 key = crc32( entry->Ptr, length );
|
||||||
hashtable_set(c.defines, key, (StrC) * entry );
|
hashtable_set(c.defines, key, * entry );
|
||||||
}
|
}
|
||||||
|
|
||||||
array_clear(Tokens);
|
array_clear(Lexer_Tokens);
|
||||||
|
|
||||||
while (c.left )
|
while (c.left )
|
||||||
{
|
{
|
||||||
@ -625,7 +628,10 @@ TokArray lex( StrC content )
|
|||||||
}
|
}
|
||||||
#endif
|
#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;
|
bool is_define = false;
|
||||||
|
|
||||||
@ -644,19 +650,23 @@ TokArray lex( StrC content )
|
|||||||
c.token.Type = Tok_NewLine;
|
c.token.Type = Tok_NewLine;
|
||||||
c.token.Length++;
|
c.token.Length++;
|
||||||
|
|
||||||
array_append( Tokens, c.token );
|
array_append( Lexer_Tokens, c.token );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.token.Length = 0;
|
c.token.Length = 0;
|
||||||
|
|
||||||
SkipWhitespace();
|
skip_whitespace();
|
||||||
if ( c.left <= 0 )
|
if ( c.left <= 0 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
switch ( current )
|
switch ( current )
|
||||||
{
|
{
|
||||||
|
if (array_back(Lexer_Tokens)->Length > 100 ) {
|
||||||
|
__debugbreak();
|
||||||
|
}
|
||||||
|
|
||||||
case '#':
|
case '#':
|
||||||
{
|
{
|
||||||
s32 result = lex_preprocessor_directive( ctx );
|
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;
|
//TokType last_type = Tokens[array_get_header(Tokens)->Num - 2].Type;
|
||||||
//if ( last_type == Tok_Preprocess_Pragma )
|
//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')
|
if ( current == '\r')
|
||||||
{
|
{
|
||||||
move_forward();
|
move_forward();
|
||||||
@ -680,7 +693,7 @@ TokArray lex( StrC content )
|
|||||||
c.token.Length++;
|
c.token.Length++;
|
||||||
move_forward();
|
move_forward();
|
||||||
|
|
||||||
array_append( Tokens, c.token );
|
array_append( Lexer_Tokens, c.token );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,7 +701,10 @@ TokArray lex( StrC content )
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Lex_ReturnNull:
|
case Lex_ReturnNull:
|
||||||
return { {}, 0 };
|
{
|
||||||
|
TokArray tok_array = {};
|
||||||
|
return tok_array;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '.':
|
case '.':
|
||||||
@ -1135,7 +1151,7 @@ TokArray lex( StrC content )
|
|||||||
move_forward();
|
move_forward();
|
||||||
c.token.Length++;
|
c.token.Length++;
|
||||||
}
|
}
|
||||||
array_append( Tokens, c.token );
|
array_append( Lexer_Tokens, c.token );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if ( current == '*' )
|
else if ( current == '*' )
|
||||||
@ -1171,7 +1187,7 @@ TokArray lex( StrC content )
|
|||||||
move_forward();
|
move_forward();
|
||||||
c.token.Length++;
|
c.token.Length++;
|
||||||
}
|
}
|
||||||
array_append( Tokens, c.token );
|
array_append( Lexer_Tokens, c.token );
|
||||||
// end_line();
|
// end_line();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1264,14 +1280,14 @@ TokArray lex( StrC content )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s32 start = max( 0, array_num(Tokens) - 100 );
|
s32 start = max( 0, array_num(Lexer_Tokens) - 100 );
|
||||||
log_fmt("\n%d\n", start);
|
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"
|
log_fmt( "Token %d Type: %s : %.*s\n"
|
||||||
, idx
|
, idx
|
||||||
, to_str( Tokens[ idx ].Type ).Ptr
|
, toktype_to_str( Lexer_Tokens[ idx ].Type ).Ptr
|
||||||
, Tokens[ idx ].Length, Tokens[ idx ].Text
|
, Lexer_Tokens[ idx ].Length, Lexer_Tokens[ idx ].Text
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1288,10 +1304,11 @@ TokArray lex( StrC content )
|
|||||||
FoundToken:
|
FoundToken:
|
||||||
{
|
{
|
||||||
lex_found_token( ctx );
|
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 )
|
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')
|
if ( current == '\r')
|
||||||
{
|
{
|
||||||
move_forward();
|
move_forward();
|
||||||
@ -1304,22 +1321,26 @@ TokArray lex( StrC content )
|
|||||||
c.token.Length++;
|
c.token.Length++;
|
||||||
move_forward();
|
move_forward();
|
||||||
|
|
||||||
array_append( Tokens, c.token );
|
array_append( Lexer_Tokens, c.token );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( array_num(Tokens) == 0 )
|
if ( array_num(Lexer_Tokens) == 0 )
|
||||||
{
|
{
|
||||||
log_failure( "Failed to lex any tokens" );
|
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();
|
// defines_map_arena.free();
|
||||||
return { Tokens, 0 };
|
TokArray result = { Lexer_Tokens, 0 };
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#undef current
|
#undef current
|
||||||
#undef move_forward
|
#undef move_forward
|
File diff suppressed because it is too large
Load Diff
@ -1,33 +1,35 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "gen.hpp"
|
#include "../gen.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma region StaticData
|
#pragma region StaticData
|
||||||
|
|
||||||
// TODO : Convert global allocation strategy to use a slab allocation strategy.
|
// TODO : Convert global allocation strategy to use a slab allocation strategy.
|
||||||
global AllocatorInfo GlobalAllocator;
|
global AllocatorInfo GlobalAllocator;
|
||||||
global Array<Arena> Global_AllocatorBuckets;
|
global Array( Arena ) Global_AllocatorBuckets;
|
||||||
|
|
||||||
// TODO(Ed) : Make the code pool a dynamic arena
|
// TODO(Ed) : Make the code pool a dynamic arena
|
||||||
global Array< Pool > CodePools = { nullptr };
|
global Array( Pool ) CodePools = { nullptr };
|
||||||
global Array< Arena > StringArenas = { nullptr };
|
global Array( Arena ) StringArenas = { nullptr };
|
||||||
|
|
||||||
global StringTable StringCache;
|
global StringTable StringCache;
|
||||||
|
|
||||||
global Arena LexArena;
|
global Arena LexArena;
|
||||||
|
|
||||||
global AllocatorInfo Allocator_DataArrays = heap();
|
global AllocatorInfo Allocator_DataArrays = {0};
|
||||||
global AllocatorInfo Allocator_CodePool = heap();
|
global AllocatorInfo Allocator_CodePool = {0};
|
||||||
global AllocatorInfo Allocator_Lexer = heap();
|
global AllocatorInfo Allocator_Lexer = {0};
|
||||||
global AllocatorInfo Allocator_StringArena = heap();
|
global AllocatorInfo Allocator_StringArena = {0};
|
||||||
global AllocatorInfo Allocator_StringTable = heap();
|
global AllocatorInfo Allocator_StringTable = {0};
|
||||||
global AllocatorInfo Allocator_TypeTable = heap();
|
global AllocatorInfo Allocator_TypeTable = {0};
|
||||||
|
|
||||||
#pragma endregion StaticData
|
#pragma endregion StaticData
|
||||||
|
|
||||||
#pragma region Constants
|
#pragma region Constants
|
||||||
|
|
||||||
|
global StrC enum_underlying_sig;
|
||||||
|
|
||||||
global Code access_public;
|
global Code access_public;
|
||||||
global Code access_protected;
|
global Code access_protected;
|
||||||
global Code access_private;
|
global Code access_private;
|
||||||
@ -40,7 +42,7 @@ global Code module_private_fragment;
|
|||||||
|
|
||||||
global Code fmt_newline;
|
global Code fmt_newline;
|
||||||
|
|
||||||
global CodeParam param_varadic;
|
global CodeParams param_varadic;
|
||||||
|
|
||||||
global CodePragma pragma_once;
|
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,6 +1,5 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
# include "platform.hpp"
|
|
||||||
# include "macros.hpp"
|
# include "macros.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -440,8 +440,6 @@ bool array_set_capacity(Array<Type>* array, usize new_capacity)
|
|||||||
|
|
||||||
#pragma endregion Array
|
#pragma endregion Array
|
||||||
|
|
||||||
// TODO(Ed) : This thing needs ALOT of work.
|
|
||||||
|
|
||||||
#pragma region HashTable
|
#pragma region HashTable
|
||||||
#define HashTable(Type) HashTable<Type>
|
#define HashTable(Type) HashTable<Type>
|
||||||
|
|
@ -1,7 +1,5 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
# include "debug.hpp"
|
|
||||||
# include "basic_types.hpp"
|
|
||||||
# include "src_start.cpp"
|
# include "src_start.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,6 +1,9 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
|
# include "dependencies/platform.hpp"
|
||||||
|
# include "dependencies/macros.hpp"
|
||||||
# include "basic_types.hpp"
|
# include "basic_types.hpp"
|
||||||
|
# include "macros.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma region Debug
|
#pragma region Debug
|
@ -459,6 +459,7 @@ FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct _memory_fd _memory_fd;
|
||||||
struct _memory_fd
|
struct _memory_fd
|
||||||
{
|
{
|
||||||
u8 magic;
|
u8 magic;
|
||||||
@ -505,7 +506,7 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator )
|
|||||||
d->allocator = allocator;
|
d->allocator = allocator;
|
||||||
d->flags = EFileStream_CLONE_WRITABLE;
|
d->flags = EFileStream_CLONE_WRITABLE;
|
||||||
d->cap = 0;
|
d->cap = 0;
|
||||||
d->buf = array_init<u8>( allocator );
|
d->buf = array_init( u8, allocator );
|
||||||
|
|
||||||
if ( ! d->buf )
|
if ( ! d->buf )
|
||||||
return false;
|
return false;
|
||||||
@ -531,7 +532,7 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize
|
|||||||
d->flags = flags;
|
d->flags = flags;
|
||||||
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
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;
|
d->buf = arr;
|
||||||
|
|
||||||
if ( ! d->buf )
|
if ( ! d->buf )
|
||||||
@ -608,9 +609,9 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
|
|||||||
|
|
||||||
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
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 ) ) )
|
if ( ! array_grow( & arr, ( s64 )( new_cap ) ) )
|
||||||
return false;
|
return false;
|
||||||
@ -622,7 +623,7 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
|
|||||||
|
|
||||||
if ( ( d->flags & EFileStream_CLONE_WRITABLE ) && extralen > 0 )
|
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 );
|
mem_copy( d->buf + offset + rwlen, pointer_add_const( buffer, rwlen ), extralen );
|
||||||
d->cap = new_cap;
|
d->cap = new_cap;
|
||||||
@ -646,7 +647,7 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
|
|||||||
|
|
||||||
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
if ( d->flags & EFileStream_CLONE_WRITABLE )
|
||||||
{
|
{
|
||||||
Array<u8> arr = { d->buf };
|
Array(u8) arr = { d->buf };
|
||||||
array_free(arr);
|
array_free(arr);
|
||||||
}
|
}
|
||||||
|
|
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
|
@ -46,6 +46,7 @@ void const* mem_find( void const* data, u8 c, ssize n )
|
|||||||
|
|
||||||
#define GEN_HEAP_STATS_MAGIC 0xDEADC0DE
|
#define GEN_HEAP_STATS_MAGIC 0xDEADC0DE
|
||||||
|
|
||||||
|
typedef struct _heap_stats _heap_stats;
|
||||||
struct _heap_stats
|
struct _heap_stats
|
||||||
{
|
{
|
||||||
u32 magic;
|
u32 magic;
|
||||||
@ -80,6 +81,7 @@ void heap_stats_check( void )
|
|||||||
GEN_ASSERT( _heap_stats_info.alloc_count == 0 );
|
GEN_ASSERT( _heap_stats_info.alloc_count == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct _heap_alloc_info _heap_alloc_info;
|
||||||
struct _heap_alloc_info
|
struct _heap_alloc_info
|
||||||
{
|
{
|
||||||
ssize size;
|
ssize size;
|
@ -208,14 +208,14 @@ struct Arena
|
|||||||
// This id is defined by Unreal for asserts
|
// This id is defined by Unreal for asserts
|
||||||
#pragma push_macro("check")
|
#pragma push_macro("check")
|
||||||
#undef check
|
#undef check
|
||||||
forceinline void check() { GEN_NS arena_check(this); }
|
forceinline void check() { arena_check(this); }
|
||||||
#pragma pop_macro("check")
|
#pragma pop_macro("check")
|
||||||
|
|
||||||
#pragma endregion Member Mapping
|
#pragma endregion Member Mapping
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP
|
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||||
forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); }
|
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 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); }
|
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); }
|
||||||
@ -319,6 +319,7 @@ struct FixedArena;
|
|||||||
template<s32 Size> FixedArena<Size> fixed_arena_init();
|
template<s32 Size> FixedArena<Size> fixed_arena_init();
|
||||||
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
|
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> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
|
||||||
|
template<s32 Size> void fixed_arena_free(FixedArena<Size>* fixed_arena);
|
||||||
|
|
||||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
#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> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
|
||||||
@ -335,7 +336,7 @@ struct FixedArena
|
|||||||
|
|
||||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||||
#pragma region Member Mapping
|
#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; fixed_arena_init<Size>(result); return result; }
|
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); }
|
forceinline ssize size_remaining(ssize alignment) { fixed_arena_size_remaining(this, alignment); }
|
||||||
@ -365,18 +366,18 @@ ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment)
|
|||||||
return size_remaining(fixed_arena->arena, alignment);
|
return size_remaining(fixed_arena->arena, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
using Arena_1KB = FixedArena< kilobytes( 1 ) >;
|
using FixedArena_1KB = FixedArena< kilobytes( 1 ) >;
|
||||||
using Arena_4KB = FixedArena< kilobytes( 4 ) >;
|
using FixedArena_4KB = FixedArena< kilobytes( 4 ) >;
|
||||||
using Arena_8KB = FixedArena< kilobytes( 8 ) >;
|
using FixedArena_8KB = FixedArena< kilobytes( 8 ) >;
|
||||||
using Arena_16KB = FixedArena< kilobytes( 16 ) >;
|
using FixedArena_16KB = FixedArena< kilobytes( 16 ) >;
|
||||||
using Arena_32KB = FixedArena< kilobytes( 32 ) >;
|
using FixedArena_32KB = FixedArena< kilobytes( 32 ) >;
|
||||||
using Arena_64KB = FixedArena< kilobytes( 64 ) >;
|
using FixedArena_64KB = FixedArena< kilobytes( 64 ) >;
|
||||||
using Arena_128KB = FixedArena< kilobytes( 128 ) >;
|
using FixedArena_128KB = FixedArena< kilobytes( 128 ) >;
|
||||||
using Arena_256KB = FixedArena< kilobytes( 256 ) >;
|
using FixedArena_256KB = FixedArena< kilobytes( 256 ) >;
|
||||||
using Arena_512KB = FixedArena< kilobytes( 512 ) >;
|
using FixedArena_512KB = FixedArena< kilobytes( 512 ) >;
|
||||||
using Arena_1MB = FixedArena< megabytes( 1 ) >;
|
using FixedArena_1MB = FixedArena< megabytes( 1 ) >;
|
||||||
using Arena_2MB = FixedArena< megabytes( 2 ) >;
|
using FixedArena_2MB = FixedArena< megabytes( 2 ) >;
|
||||||
using Arena_4MB = FixedArena< megabytes( 4 ) >;
|
using FixedArena_4MB = FixedArena< megabytes( 4 ) >;
|
||||||
#pragma endregion FixedArena
|
#pragma endregion FixedArena
|
||||||
|
|
||||||
#pragma region Pool
|
#pragma region Pool
|
@ -24,7 +24,7 @@ u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32
|
|||||||
node->type = type;
|
node->type = type;
|
||||||
node->name = name;
|
node->name = name;
|
||||||
node->parent = parent;
|
node->parent = parent;
|
||||||
node->nodes = array_init<ADT_Node>( backing );
|
node->nodes = array_init(ADT_Node, backing );
|
||||||
|
|
||||||
if ( ! node->nodes )
|
if ( ! node->nodes )
|
||||||
return EADT_ERROR_OUT_OF_MEMORY;
|
return EADT_ERROR_OUT_OF_MEMORY;
|
||||||
@ -1111,4 +1111,6 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef _adt_fprintf
|
||||||
|
|
||||||
#pragma endregion CSV
|
#pragma endregion CSV
|
@ -1,5 +1,6 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
|
# include "timing.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#pragma region ADT
|
#pragma region ADT
|
@ -29,12 +29,6 @@
|
|||||||
# ifndef GEN_SYSTEM_MACOS
|
# ifndef GEN_SYSTEM_MACOS
|
||||||
# define GEN_SYSTEM_MACOS 1
|
# define GEN_SYSTEM_MACOS 1
|
||||||
# endif
|
# 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__ )
|
#elif defined( __unix__ )
|
||||||
# ifndef GEN_SYSTEM_UNIX
|
# ifndef GEN_SYSTEM_UNIX
|
||||||
# define GEN_SYSTEM_UNIX 1
|
# define GEN_SYSTEM_UNIX 1
|
@ -1,7 +1,5 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
# include "filesystem.hpp"
|
|
||||||
# include "strings.hpp"
|
|
||||||
# include "string_ops.cpp"
|
# include "string_ops.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -33,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
|
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
|
struct _format_info
|
||||||
{
|
{
|
||||||
s32 base;
|
s32 base;
|
||||||
@ -429,7 +428,7 @@ neverinline ssize str_fmt_va( char* text, ssize max_len, char const* fmt, va_lis
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
String gen_str = String { va_arg( va, char*) };
|
String gen_str = { va_arg( va, char*) };
|
||||||
|
|
||||||
info.precision = string_length(gen_str);
|
info.precision = string_length(gen_str);
|
||||||
len = _print_string( text, remaining, &info, gen_str );
|
len = _print_string( text, remaining, &info, gen_str );
|
@ -1,4 +1,5 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
|
# pragma once
|
||||||
# include "header_start.hpp"
|
# include "header_start.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
# include "string_ops.hpp"
|
|
||||||
# include "debug.cpp"
|
# include "debug.cpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -7,17 +7,21 @@
|
|||||||
|
|
||||||
String string_make_length( AllocatorInfo allocator, char const* str, ssize length )
|
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;
|
s32 alloc_size = header_size + length + 1;
|
||||||
void* allocation = alloc( allocator, alloc_size );
|
void* allocation = alloc( allocator, alloc_size );
|
||||||
|
|
||||||
if ( allocation == nullptr )
|
if ( allocation == nullptr ) {
|
||||||
return { nullptr };
|
String null_string = {nullptr};
|
||||||
|
return null_string;
|
||||||
|
}
|
||||||
|
|
||||||
StringHeader&
|
StringHeader*
|
||||||
header = * rcast(StringHeader*, allocation);
|
header = rcast(StringHeader*, allocation);
|
||||||
header = { allocator, length, length };
|
header->Allocator = allocator;
|
||||||
|
header->Capacity = length;
|
||||||
|
header->Length = length;
|
||||||
|
|
||||||
String result = { rcast( char*, allocation) + header_size };
|
String result = { rcast( char*, allocation) + header_size };
|
||||||
|
|
||||||
@ -33,14 +37,15 @@ String string_make_length( AllocatorInfo allocator, char const* str, ssize lengt
|
|||||||
|
|
||||||
String string_make_reserve( AllocatorInfo allocator, ssize capacity )
|
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;
|
s32 alloc_size = header_size + capacity + 1;
|
||||||
void* allocation = alloc( allocator, alloc_size );
|
void* allocation = alloc( allocator, alloc_size );
|
||||||
|
|
||||||
if ( allocation == nullptr )
|
if ( allocation == nullptr ) {
|
||||||
return { nullptr };
|
String null_string = {nullptr};
|
||||||
|
return null_string;
|
||||||
|
}
|
||||||
mem_set( allocation, 0, alloc_size );
|
mem_set( allocation, 0, alloc_size );
|
||||||
|
|
||||||
StringHeader*
|
StringHeader*
|
@ -7,12 +7,12 @@
|
|||||||
|
|
||||||
struct StrC;
|
struct StrC;
|
||||||
|
|
||||||
|
StrC to_strc_from_c_str (char const* bad_string);
|
||||||
bool strc_are_equal (StrC lhs, StrC rhs);
|
bool strc_are_equal (StrC lhs, StrC rhs);
|
||||||
char const* strc_back (StrC str);
|
char const* strc_back (StrC str);
|
||||||
bool strc_contains (StrC str, StrC substring);
|
bool strc_contains (StrC str, StrC substring);
|
||||||
StrC strc_duplicate (StrC str, AllocatorInfo allocator);
|
StrC strc_duplicate (StrC str, AllocatorInfo allocator);
|
||||||
b32 strc_starts_with (StrC str, StrC substring);
|
b32 strc_starts_with (StrC str, StrC substring);
|
||||||
StrC strc_to_str (char const* bad_string);
|
|
||||||
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
|
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
|
||||||
|
|
||||||
// Constant string with length.
|
// Constant string with length.
|
||||||
@ -626,7 +626,7 @@ StrC string_to_strc(String str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
void trim(String str, char const* cut_set)
|
void string_trim(String str, char const* cut_set)
|
||||||
{
|
{
|
||||||
ssize len = 0;
|
ssize len = 0;
|
||||||
|
|
||||||
@ -650,12 +650,12 @@ void trim(String str, char const* cut_set)
|
|||||||
}
|
}
|
||||||
|
|
||||||
forceinline
|
forceinline
|
||||||
void trim_space(String str) {
|
void string_trim_space(String str) {
|
||||||
trim(str, " \t\r\n\v\f");
|
string_trim(str, " \t\r\n\v\f");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
String visualize_whitespace(String const str)
|
String string_visualize_whitespace(String const str)
|
||||||
{
|
{
|
||||||
StringHeader* header = (StringHeader*)(scast(char const*, str) - sizeof(StringHeader));
|
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.
|
String result = string_make_reserve(header->Allocator, string_length(str) * 2); // Assume worst case for space requirements.
|
@ -37,6 +37,9 @@ GEN_NS_BEGIN
|
|||||||
#include "components/interface.parsing.cpp"
|
#include "components/interface.parsing.cpp"
|
||||||
#include "components/interface.untyped.cpp"
|
#include "components/interface.untyped.cpp"
|
||||||
|
|
||||||
|
#include "auxillary/builder.cpp"
|
||||||
|
#include "auxillary/scanner.cpp"
|
||||||
|
|
||||||
GEN_NS_END
|
GEN_NS_END
|
||||||
|
|
||||||
#include "helpers/pop_container_defines.inline.hpp"
|
#include "helpers/pop_container_defines.inline.hpp"
|
@ -13,5 +13,6 @@ GEN_NS_BEGIN
|
|||||||
#include "dependencies/strings.cpp"
|
#include "dependencies/strings.cpp"
|
||||||
#include "dependencies/filesystem.cpp"
|
#include "dependencies/filesystem.cpp"
|
||||||
#include "dependencies/timing.cpp"
|
#include "dependencies/timing.cpp"
|
||||||
|
#include "dependencies/parsing.cpp"
|
||||||
|
|
||||||
GEN_NS_END
|
GEN_NS_END
|
@ -16,5 +16,6 @@ GEN_NS_BEGIN
|
|||||||
#include "dependencies/strings.hpp"
|
#include "dependencies/strings.hpp"
|
||||||
#include "dependencies/filesystem.hpp"
|
#include "dependencies/filesystem.hpp"
|
||||||
#include "dependencies/timing.hpp"
|
#include "dependencies/timing.hpp"
|
||||||
|
#include "dependencies/parsing.hpp"
|
||||||
|
|
||||||
GEN_NS_END
|
GEN_NS_END
|
@ -17,7 +17,7 @@
|
|||||||
GEN_NS_BEGIN
|
GEN_NS_BEGIN
|
||||||
|
|
||||||
#include "components/types.hpp"
|
#include "components/types.hpp"
|
||||||
#include "components/gen/ecode.hpp"
|
#include "components/gen/ecodetypes.hpp"
|
||||||
#include "components/gen/eoperator.hpp"
|
#include "components/gen/eoperator.hpp"
|
||||||
#include "components/gen/especifier.hpp"
|
#include "components/gen/especifier.hpp"
|
||||||
|
|
||||||
@ -31,6 +31,9 @@ GEN_NS_BEGIN
|
|||||||
#include "components/gen/ast_inlines.hpp"
|
#include "components/gen/ast_inlines.hpp"
|
||||||
#include "components/header_end.hpp"
|
#include "components/header_end.hpp"
|
||||||
|
|
||||||
|
#include "auxillary/builder.hpp"
|
||||||
|
#include "auxillary/scanner.hpp"
|
||||||
|
|
||||||
GEN_NS_END
|
GEN_NS_END
|
||||||
|
|
||||||
#include "helpers/pop_container_defines.inline.hpp"
|
#include "helpers/pop_container_defines.inline.hpp"
|
@ -18,6 +18,8 @@
|
|||||||
// Precedence (highest to lowest):
|
// Precedence (highest to lowest):
|
||||||
// word, namespace, regex
|
// word, namespace, regex
|
||||||
|
|
||||||
|
// TODO(ED): THIS IS VERY OUTDATED
|
||||||
|
|
||||||
// Gen Macro namespace
|
// Gen Macro namespace
|
||||||
// namespace GEN_, new_namespace_
|
// namespace GEN_, new_namespace_
|
||||||
|
|
@ -1,59 +1,46 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "gen.hpp"
|
#if GEN_INTELLISENSE_DIRECTIVES
|
||||||
|
# include "../gen.hpp"
|
||||||
GEN_NS_BEGIN
|
# include "misc.hpp"
|
||||||
#include "dependencies/parsing.hpp"
|
|
||||||
GEN_NS_END
|
|
||||||
|
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
#endif
|
||||||
|
|
||||||
CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
||||||
{
|
{
|
||||||
char scratch_mem[kilobytes(4)];
|
FixedArena_32KB scratch; fixed_arena_init(& scratch);
|
||||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||||
|
|
||||||
file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path );
|
|
||||||
|
|
||||||
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> keyword_strs = csv_nodes.nodes[1].nodes;
|
|
||||||
|
|
||||||
|
CSV_Columns2 csv_enum = parse_csv_two_columns( scratch_info, path );
|
||||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||||
String to_str_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) );
|
String to_keyword_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
|
||||||
|
|
||||||
for ( ssize idx = 0; idx < array_num(enum_strs); ++ idx )
|
for ( ssize idx = 0; idx < array_num(csv_enum.Col_1); ++ idx ) {
|
||||||
{
|
char const* code = csv_enum.Col_1[idx].string;
|
||||||
char const* code = enum_strs [idx].string;
|
char const* keyword = csv_enum.Col_2[idx].string;
|
||||||
char const* keyword = keyword_strs[idx].string;
|
|
||||||
|
|
||||||
// TODO(Ed): to_str_entries and the others in here didn't have proper sizing of the StrC slice.
|
// 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( & enum_entries, "CT_%s,\n", code );
|
||||||
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, 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 );
|
string_append_fmt( & to_keyword_str_entries, "{ sizeof(\"%s\") - 1, \"%s\" },\n", keyword, keyword );
|
||||||
}
|
}
|
||||||
|
|
||||||
CodeEnum enum_code;
|
CodeEnum enum_code;
|
||||||
if (use_c_definition)
|
if (use_c_definition) {
|
||||||
{
|
|
||||||
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
||||||
"enum CodeType enum_underlying(u32) { <entries> CT_NumTypes };"
|
"enum CodeType enum_underlying(u32) { <entries> CT_NumTypes, CT_UnderlyingType = GEN_U32_MAX };"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
|
||||||
"enum CodeType : u32 { <entries> CT_NumTypes };"
|
"enum CodeType : u32 { <entries> CT_NumTypes, CT_UnderlyingType = GEN_U32_MAX };"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma push_macro("local_persist")
|
#pragma push_macro("local_persist")
|
||||||
#undef local_persist
|
#undef local_persist
|
||||||
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
|
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(
|
CodeBody to_str_fns = parse_global_body( token_fmt(
|
||||||
"entries", string_to_strc(to_str_entries)
|
"entries", string_to_strc(to_str_entries)
|
||||||
, "keywords", string_to_strc(to_keyword_str_entries)
|
, "keywords", string_to_strc(to_keyword_str_entries)
|
||||||
@ -84,16 +71,14 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
|||||||
CodeBody result = def_body(CT_Global_Body);
|
CodeBody result = def_body(CT_Global_Body);
|
||||||
body_append(result, enum_code);
|
body_append(result, enum_code);
|
||||||
|
|
||||||
if (use_c_definition)
|
if (use_c_definition) {
|
||||||
{
|
|
||||||
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; ));
|
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; ));
|
||||||
body_append(result, code_t);
|
body_append(result, code_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
body_append(result, to_str_fns);
|
body_append(result, to_str_fns);
|
||||||
|
|
||||||
if (! use_c_definition)
|
if (! use_c_definition) {
|
||||||
{
|
|
||||||
#pragma push_macro("forceinline")
|
#pragma push_macro("forceinline")
|
||||||
#undef forceinline
|
#undef forceinline
|
||||||
CodeBody alias_mappings = parse_global_body(code(
|
CodeBody alias_mappings = parse_global_body(code(
|
||||||
@ -108,24 +93,16 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
|
|||||||
|
|
||||||
CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
||||||
{
|
{
|
||||||
char scratch_mem[kilobytes(4)];
|
FixedArena_16KB scratch; fixed_arena_init(& scratch);
|
||||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
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;
|
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++) {
|
||||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
char const* enum_str = csv_enum.Col_1[idx].string;
|
||||||
|
char const* entry_to_str = csv_enum.Col_2[idx].string;
|
||||||
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;
|
|
||||||
|
|
||||||
string_append_fmt( & enum_entries, "Op_%s,\n", enum_str );
|
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);
|
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||||
@ -140,7 +117,8 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
|||||||
enum Operator enum_underlying(u32)
|
enum Operator enum_underlying(u32)
|
||||||
{
|
{
|
||||||
<entries>
|
<entries>
|
||||||
NumOps
|
Op_NumOps,
|
||||||
|
Op_UnderlyingType = GEN_U32_MAX
|
||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
#pragma pop_macro("enum_underlying")
|
#pragma pop_macro("enum_underlying")
|
||||||
@ -151,14 +129,15 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
|||||||
enum Operator : u32
|
enum Operator : u32
|
||||||
{
|
{
|
||||||
<entries>
|
<entries>
|
||||||
NumOps
|
Op_NumOps,
|
||||||
|
Op_UnderlyingType = GEN_U32_MAX
|
||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma push_macro("local_persist")
|
#pragma push_macro("local_persist")
|
||||||
#undef local_persist
|
#undef local_persist
|
||||||
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
|
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(csv_enum.Col_1) ));
|
||||||
CodeFn to_str = parse_function(token_fmt(
|
CodeFn to_str = parse_function(token_fmt(
|
||||||
"entries", string_to_strc(to_str_entries)
|
"entries", string_to_strc(to_str_entries)
|
||||||
, "num", lookup_size
|
, "num", lookup_size
|
||||||
@ -178,8 +157,7 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
|||||||
|
|
||||||
CodeBody result = def_body(CT_Global_Body);
|
CodeBody result = def_body(CT_Global_Body);
|
||||||
body_append(result, enum_code);
|
body_append(result, enum_code);
|
||||||
if ( use_c_definition )
|
if ( use_c_definition ) {
|
||||||
{
|
|
||||||
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; ));
|
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; ));
|
||||||
body_append(result, operator_t);
|
body_append(result, operator_t);
|
||||||
}
|
}
|
||||||
@ -201,24 +179,17 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
|
|||||||
|
|
||||||
CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
||||||
{
|
{
|
||||||
char scratch_mem[kilobytes(4)];
|
FixedArena_16KB scratch; fixed_arena_init(& scratch);
|
||||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
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;
|
for (usize idx = 0; idx < array_num(csv_enum.Col_1); idx++)
|
||||||
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* enum_str = csv_enum.Col_1[idx].string;
|
||||||
char const* entry_to_str = str_strs [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( & enum_entries, "Spec_%s,\n", enum_str );
|
||||||
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||||
@ -233,7 +204,8 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
|||||||
enum Specifier enum_underlying(u32)
|
enum Specifier enum_underlying(u32)
|
||||||
{
|
{
|
||||||
<entries>
|
<entries>
|
||||||
Spec_NumSpecifiers
|
Spec_NumSpecifiers,
|
||||||
|
Spec_UnderlyingType = GEN_U32_MAX
|
||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
#pragma pop_macro("enum_underlying")
|
#pragma pop_macro("enum_underlying")
|
||||||
@ -244,7 +216,8 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
|||||||
enum Specifier : u32
|
enum Specifier : u32
|
||||||
{
|
{
|
||||||
<entries>
|
<entries>
|
||||||
Spec_NumSpecifiers
|
Spec_NumSpecifiers,
|
||||||
|
Spec_UnderlyingType = GEN_U32_MAX
|
||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
@ -267,7 +240,7 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
|||||||
#undef do_once_end
|
#undef do_once_end
|
||||||
#undef forceinline
|
#undef forceinline
|
||||||
#undef neverinline
|
#undef neverinline
|
||||||
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
|
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(csv_enum.Col_1) ));
|
||||||
CodeFn to_str = parse_function(token_fmt(
|
CodeFn to_str = parse_function(token_fmt(
|
||||||
"entries", string_to_strc(to_str_entries)
|
"entries", string_to_strc(to_str_entries)
|
||||||
, "num", lookup_size
|
, "num", lookup_size
|
||||||
@ -345,33 +318,31 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
|||||||
return result;
|
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)];
|
FixedArena_64KB scratch; fixed_arena_init(& scratch);
|
||||||
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
AllocatorInfo scratch_info = fixed_arena_allocator_info(& scratch);
|
||||||
|
|
||||||
AllocatorInfo scratch_info = arena_allocator_info(& scratch);
|
|
||||||
|
|
||||||
FileContents enum_content = file_read_contents( scratch_info, file_zero_terminate, etok_path );
|
FileContents enum_content = file_read_contents( scratch_info, file_zero_terminate, etok_path );
|
||||||
|
|
||||||
CSV_Object csv_enum_nodes;
|
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 );
|
FileContents attrib_content = file_read_contents( scratch_info, file_zero_terminate, attr_path );
|
||||||
|
|
||||||
CSV_Object csv_attr_nodes;
|
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_strs = csv_enum_nodes.nodes[0].nodes;
|
||||||
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].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_strs = csv_attr_nodes.nodes[0].nodes;
|
||||||
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
||||||
|
|
||||||
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
String enum_entries = string_make_reserve( scratch_info, kilobytes(2) );
|
||||||
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
String to_str_entries = string_make_reserve( scratch_info, kilobytes(4) );
|
||||||
String attribute_entries = string_make_reserve( GlobalAllocator, kilobytes(2) );
|
String attribute_entries = string_make_reserve( scratch_info, kilobytes(2) );
|
||||||
String to_str_attributes = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
String to_str_attributes = string_make_reserve( scratch_info, kilobytes(4) );
|
||||||
String attribute_define_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
|
String attribute_define_entries = string_make_reserve( scratch_info, kilobytes(4) );
|
||||||
|
|
||||||
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
for (usize idx = 0; idx < array_num(enum_strs); idx++)
|
||||||
{
|
{
|
||||||
@ -403,14 +374,30 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
|||||||
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
|
||||||
|
|
||||||
// We cannot parse this enum, it has Attribute names as enums
|
// 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(
|
CodeEnum enum_code;
|
||||||
enum TokType_Def : u32
|
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>
|
<entries>
|
||||||
<attribute_toks>
|
<attribute_toks>
|
||||||
Tok_NumTokens
|
Tok_NumTokens
|
||||||
};
|
};
|
||||||
)));
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
#pragma push_macro("local_persist")
|
#pragma push_macro("local_persist")
|
||||||
#pragma push_macro("do_once_start")
|
#pragma push_macro("do_once_start")
|
||||||
@ -420,10 +407,10 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
|||||||
#undef do_once_end
|
#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(
|
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), "attribute_toks", string_to_strc(to_str_attributes), stringize(
|
||||||
inline
|
inline
|
||||||
StrC to_str( TokType type )
|
StrC toktype_to_str( TokType type )
|
||||||
{
|
{
|
||||||
local_persist
|
local_persist
|
||||||
StrC lookup[] {
|
StrC lookup[] = {
|
||||||
<entries>
|
<entries>
|
||||||
<attribute_toks>
|
<attribute_toks>
|
||||||
};
|
};
|
||||||
@ -434,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(
|
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
|
||||||
inline
|
inline
|
||||||
TokType to_toktype( StrC str )
|
TokType strc_to_toktype( StrC str )
|
||||||
{
|
{
|
||||||
local_persist
|
local_persist
|
||||||
u32 keymap[ Tok_NumTokens ];
|
u32 keymap[ Tok_NumTokens ];
|
||||||
do_once_start
|
do_once_start
|
||||||
for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
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
|
// We subtract 1 to remove the null terminator
|
||||||
// This is because the tokens lexed are not null terminated.
|
// This is because the tokens lexed are not null terminated.
|
||||||
@ -464,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_start")
|
||||||
#pragma pop_macro("do_once_end")
|
#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 ) ) );
|
CodeBody result = def_body(CT_Global_Body);
|
||||||
CodeTypedef td_toktype = parse_typedef( code( typedef enum TokType_Def TokType; ));
|
body_append(result, untyped_str(txt("GEN_NS_PARSER_BEGIN\n\n")));
|
||||||
|
body_append(result, attribute_entires_def);
|
||||||
return def_global_body( args(
|
body_append(result, enum_code);
|
||||||
attribute_entires_def,
|
if (use_c_definition)
|
||||||
enum_code,
|
{
|
||||||
td_toktype,
|
CodeTypedef td_toktype = parse_typedef( code( typedef enum TokType TokType; ));
|
||||||
to_str,
|
body_append(result, td_toktype);
|
||||||
to_type
|
}
|
||||||
));
|
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()
|
CodeBody gen_ast_inlines()
|
||||||
@ -546,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_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_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_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_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_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 ));
|
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl ));
|
||||||
@ -609,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_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_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_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_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_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 ));
|
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl ));
|
||||||
@ -642,7 +632,7 @@ CodeBody gen_ast_inlines()
|
|||||||
impl_code_ns,
|
impl_code_ns,
|
||||||
impl_code_op,
|
impl_code_op,
|
||||||
impl_code_opcast,
|
impl_code_opcast,
|
||||||
impl_code_param,
|
impl_code_params,
|
||||||
impl_code_pragma,
|
impl_code_pragma,
|
||||||
impl_code_precond,
|
impl_code_precond,
|
||||||
impl_code_specs,
|
impl_code_specs,
|
||||||
@ -676,7 +666,7 @@ CodeBody gen_ast_inlines()
|
|||||||
impl_cast_ns,
|
impl_cast_ns,
|
||||||
impl_cast_op,
|
impl_cast_op,
|
||||||
impl_cast_opcast,
|
impl_cast_opcast,
|
||||||
impl_cast_param,
|
impl_cast_params,
|
||||||
impl_cast_pragma,
|
impl_cast_pragma,
|
||||||
impl_cast_precond,
|
impl_cast_precond,
|
||||||
impl_cast_specs,
|
impl_cast_specs,
|
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 "-Wunused-function"
|
||||||
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
||||||
# pragma clang diagnostic ignored "-W#pragma-messages"
|
# pragma clang diagnostic ignored "-W#pragma-messages"
|
||||||
|
# pragma clang diagnostic ignored "-Wstatic-in-inline"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#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
|
## Current Design
|
||||||
|
|
||||||
`AST` is the actual managed node object for the library.
|
`AST` is the actual managed node object for the library.
|
||||||
Its raw and really not meant to be used directly.
|
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*`.
|
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.
|
When its the [C generated variant of the library](../gen_c_library/)
|
||||||
|
```c
|
||||||
The simpliest being just a type alias.
|
typedef AST* Code;
|
||||||
|
tyepdef AST_<name>* Code<name>;
|
||||||
```cpp
|
...
|
||||||
using Code = AST*;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This is what the genc library would have to use due to its constraints of a langauge.
|
**or**
|
||||||
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.
|
|
||||||
|
|
||||||
|
For C++:
|
||||||
```cpp
|
```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.
|
The full definitions of all asts are within:
|
||||||
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 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)
|
The C/C++ interface procedures are located with `ast.hpp` (for the Code type), and `code_types.hpp` for all others.
|
||||||
* [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)
|
|
||||||
|
|
||||||
|
## 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
|
# 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.
|
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
|
||||||
|
|
||||||
## Body
|
## 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
|
* Class_Body
|
||||||
* Enum_Body
|
* Enum_Body
|
||||||
@ -19,11 +25,11 @@ These are containers representing a scope body of a definition that can be of th
|
|||||||
Fields:
|
Fields:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
StringCached Name;
|
||||||
Code Front;
|
Code Front;
|
||||||
Code Back;
|
Code Back;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
s32 NumEntries;
|
s32 NumEntries;
|
||||||
```
|
```
|
||||||
@ -31,14 +37,15 @@ s32 NumEntries;
|
|||||||
The `Front` member represents the start of the link list and `Back` the end.
|
The `Front` member represents the start of the link list and `Back` the end.
|
||||||
NumEntries is the number of entries in the body.
|
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:
|
Serialization:
|
||||||
|
|
||||||
Will output only the entries, the braces are handled by the parent.
|
Will output only the entries, the braces are handled by the parent.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
<Front>...
|
<Front>
|
||||||
|
...
|
||||||
<Back>
|
<Back>
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -50,11 +57,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -74,11 +81,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -102,11 +109,11 @@ CodeComment InlineCmt; // Only supported by forward declarations
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeType ParentType;
|
CodeType ParentType;
|
||||||
CodeBody Body;
|
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;
|
StringCached Name;
|
||||||
|
CodeType Prev;
|
||||||
|
CodeType Next;
|
||||||
|
Token* Tok;
|
||||||
|
Code Parent;
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
AccessSpec ParentAccess;
|
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
|
## Constructor
|
||||||
|
|
||||||
@ -134,13 +141,13 @@ Fields:
|
|||||||
```cpp
|
```cpp
|
||||||
CodeComment InlineCmt; // Only supported by forward declarations
|
CodeComment InlineCmt; // Only supported by forward declarations
|
||||||
Code InitializerList;
|
Code InitializerList;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
Code Body;
|
Code Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -172,11 +179,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -194,11 +201,11 @@ Fields:
|
|||||||
CodeComment InlineCmt;
|
CodeComment InlineCmt;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
Code Body;
|
Code Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -229,24 +236,28 @@ Fields:
|
|||||||
CodeComment InlineCmt;
|
CodeComment InlineCmt;
|
||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeType UnderlyingType;
|
CodeType UnderlyingType;
|
||||||
|
Code UnderlyingTypeMacro;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
StringCached Name;
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
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:
|
Serialization:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Enum_Fwd
|
// Enum_Fwd
|
||||||
<ModuleFlags> enum class <Name> : <UnderlyingType>; <InlineCmt>
|
<ModuleFlags> enum class <Name> : <UnderlyingType> or <UnderlyingTypeMacro> ; <InlineCmt>
|
||||||
|
|
||||||
// Enum
|
// Enum
|
||||||
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType>
|
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType> or <UnderlyingTypeMacro>
|
||||||
{
|
{
|
||||||
<Body>
|
<Body>
|
||||||
};
|
};
|
||||||
@ -261,11 +272,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -281,11 +292,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -304,11 +315,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -327,11 +338,11 @@ Fields:
|
|||||||
```cpp
|
```cpp
|
||||||
CodeComment InlineCmt;
|
CodeComment InlineCmt;
|
||||||
Code Declaration;
|
Code Declaration;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -350,13 +361,13 @@ CodeComment InlineCmt;
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeType ReturnType;
|
CodeType ReturnType;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
```
|
```
|
||||||
@ -379,11 +390,11 @@ Serialization:
|
|||||||
Fields:
|
Fields:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
```
|
```
|
||||||
@ -400,11 +411,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
```
|
```
|
||||||
@ -418,7 +429,7 @@ Serialization:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Operator Overload
|
## Operator Overload (Operator)
|
||||||
|
|
||||||
Fields:
|
Fields:
|
||||||
|
|
||||||
@ -427,13 +438,13 @@ CodeComment InlineCmt;
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeType ReturnType;
|
CodeType ReturnType;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
OperatorT Op;
|
OperatorT Op;
|
||||||
@ -452,7 +463,7 @@ Serialization:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Operator Cast Overload ( User-Defined Type Conversion )
|
## Operator Cast Overload ( User-Defined Type Conversion, OpCast )
|
||||||
|
|
||||||
Fields:
|
Fields:
|
||||||
|
|
||||||
@ -461,11 +472,11 @@ CodeComment InlineCmt;
|
|||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeType ValueType;
|
CodeType ValueType;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -482,7 +493,7 @@ Serialization:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Parameters (AST_Param)
|
## Parameters (AST_Params)
|
||||||
|
|
||||||
Fields:
|
Fields:
|
||||||
|
|
||||||
@ -490,11 +501,12 @@ Fields:
|
|||||||
CodeType ValueType;
|
CodeType ValueType;
|
||||||
Code Macro;
|
Code Macro;
|
||||||
Code Value;
|
Code Value;
|
||||||
CodeParam Last;
|
Code PostNameMacro;
|
||||||
CodeParam Next;
|
|
||||||
parser::Token* Tok;
|
|
||||||
Code Parent;
|
|
||||||
StringCached Name;
|
StringCached Name;
|
||||||
|
CodeParams Last;
|
||||||
|
CodeParams Next;
|
||||||
|
Token* Tok;
|
||||||
|
Code Parent;
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
s32 NumEntries;
|
s32 NumEntries;
|
||||||
```
|
```
|
||||||
@ -504,7 +516,7 @@ Serialization:
|
|||||||
```cpp
|
```cpp
|
||||||
<Macro>, <Next> ... <Last>
|
<Macro>, <Next> ... <Last>
|
||||||
|
|
||||||
<Macro> <ValueType> <Name>, <Next>... <Last>
|
<Macro> <ValueType> <Name> <PostNameMacro> = <Value>, <Next>... <Last>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Pragma
|
## Pragma
|
||||||
@ -513,11 +525,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -533,11 +545,11 @@ Fields:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
StringCached Content;
|
StringCached Content;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
paser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -554,11 +566,11 @@ Fields:
|
|||||||
```cpp
|
```cpp
|
||||||
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
|
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||||
CodeSpecifiers NextSpecs;
|
CodeSpecifiers NextSpecs;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
s32 NumEntries;
|
s32 NumEntries;
|
||||||
```
|
```
|
||||||
@ -574,13 +586,13 @@ Serialization:
|
|||||||
Fields:
|
Fields:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
Code Declaration;
|
Code Declaration;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
```
|
```
|
||||||
@ -603,23 +615,30 @@ Fields:
|
|||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeSpecifiers Specs;
|
CodeSpecifiers Specs;
|
||||||
CodeReturnType ReturnType;
|
CodeReturnType ReturnType;
|
||||||
CodeParam Params;
|
CodeParams Params;
|
||||||
Code ArrExpr;
|
Code ArrExpr;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
StringCached Name;
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
b32 IsParamPack;
|
b32 IsParamPack;
|
||||||
|
ETypenameTag TypeTag;
|
||||||
```
|
```
|
||||||
|
|
||||||
Serialization:
|
Serialization:
|
||||||
|
|
||||||
```cpp
|
```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
|
## Typedef
|
||||||
|
|
||||||
Behave as usual except function or macro typedefs.
|
Behave as usual except function or macro typedefs.
|
||||||
@ -630,11 +649,11 @@ Fields:
|
|||||||
```cpp
|
```cpp
|
||||||
CodeComment InlineCmt;
|
CodeComment InlineCmt;
|
||||||
Code UnderlyingType;
|
Code UnderlyingType;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parse::Token* Tok
|
Token* Tok
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
b32 IsFunction;
|
b32 IsFunction;
|
||||||
@ -644,11 +663,16 @@ Serialization:
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// Regular
|
// Regular
|
||||||
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
|
<ModuleFlags> typedef <UnderlyingType> <Name> <UnderlyingType-ArrExpr>; <InlineCmt>
|
||||||
|
|
||||||
// Functions
|
// 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
|
## Union
|
||||||
@ -658,11 +682,11 @@ Fields:
|
|||||||
```cpp
|
```cpp
|
||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeBody Body;
|
CodeBody Body;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
```
|
```
|
||||||
@ -684,11 +708,11 @@ Fields:
|
|||||||
CodeComment InlineCmt;
|
CodeComment InlineCmt;
|
||||||
CodeAttributes Attributes;
|
CodeAttributes Attributes;
|
||||||
CodeType UnderlyingType;
|
CodeType UnderlyingType;
|
||||||
|
StringCached Name;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
```
|
```
|
||||||
@ -716,14 +740,15 @@ CodeSpecifiers Specs;
|
|||||||
CodeType ValueType;
|
CodeType ValueType;
|
||||||
Code BitfieldSize;
|
Code BitfieldSize;
|
||||||
Code Value;
|
Code Value;
|
||||||
|
StringCached Name;
|
||||||
CodeVar NextVar;
|
CodeVar NextVar;
|
||||||
Code Prev;
|
Code Prev;
|
||||||
Code Next;
|
Code Next;
|
||||||
parser::Token* Tok;
|
Token* Tok;
|
||||||
Code Parent;
|
Code Parent;
|
||||||
StringCached Name;
|
|
||||||
CodeT Type;
|
CodeT Type;
|
||||||
ModuleFlag ModuleFlags;
|
ModuleFlag ModuleFlags;
|
||||||
|
s32 VarParenthesizedInit;
|
||||||
```
|
```
|
||||||
|
|
||||||
Serialization:
|
Serialization:
|
||||||
@ -734,4 +759,7 @@ Serialization:
|
|||||||
|
|
||||||
// Bitfield
|
// Bitfield
|
||||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>, NextVar ...; <InlineCmt>
|
<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
|
# 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.
|
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
|
### Lexer
|
||||||
|
|
||||||
The lex procedure does the lexical pass of content provided as a `StrC` type.
|
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:
|
Fields:
|
||||||
|
|
||||||
@ -16,7 +22,7 @@ Array<Token> Arr;
|
|||||||
s32 Idx;
|
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`:
|
Tokens are defined with the struct `gen::parser::Token`:
|
||||||
|
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
|
## Navigation
|
||||||
|
|
||||||
|
[Top](../Readme.md)
|
||||||
|
|
||||||
|
<- [docs - General](Readme.md)
|
||||||
|
|
||||||
# Parsing
|
# 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:
|
User exposed interface:
|
||||||
|
|
||||||
@ -47,10 +53,11 @@ The keywords supported for the preprocessor are:
|
|||||||
* endif
|
* endif
|
||||||
* pragma
|
* 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.
|
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).
|
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:
|
Exceptions:
|
||||||
@ -59,6 +66,8 @@ Exceptions:
|
|||||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
|
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
|
||||||
* typedefs allow for a preprocessed macro: `typedef MACRO();`
|
* typedefs allow for a preprocessed macro: `typedef MACRO();`
|
||||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_TYPEDEF`
|
* 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)*
|
*(Exceptions are added on an on-demand basis)*
|
||||||
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
|
*(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.*
|
*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.
|
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||||
|
|
||||||
* Numeric literals are not checked for validity.
|
* 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.*
|
* *This includes the assignment of variables.*
|
||||||
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
|
* 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.
|
* 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*)
|
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
|
||||||
* typedefs have attributes with the type (`parse_type`)
|
* 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)
|
* 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.
|
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.
|
||||||
|
180
docs/Readme.md
180
docs/Readme.md
@ -1,50 +1,18 @@
|
|||||||
## Documentation
|
# General Docs
|
||||||
|
|
||||||
The project has no external dependencies beyond:
|
[Top](../Readme.md)
|
||||||
|
|
||||||
* `errno.h`
|
Contains:
|
||||||
* `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)
|
|
||||||
|
|
||||||
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
|
* [AST_Design](./AST_Design.md): Overvie of ASTs
|
||||||
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
|
* [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:
|
### *CURRENTLY UNSUPPORTED*
|
||||||
|
|
||||||
* 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*
|
|
||||||
|
|
||||||
**There is no support for validating expressions.**
|
**There is no support for validating expressions.**
|
||||||
Its difficult to parse without enough benefits (At the metaprogramming level).
|
Its a [todo](https://github.com/Ed94/gencpp/issues/49)
|
||||||
I plan to add this only at the tail of the project parsing milestone.
|
|
||||||
|
|
||||||
**Only trivial template support is provided.**
|
**Only trivial template support is provided.**
|
||||||
The intention is for only simple, non-recursive substitution.
|
The intention is for only simple, non-recursive substitution.
|
||||||
@ -55,10 +23,20 @@ This means that the typename entry for the parameter AST would be either:
|
|||||||
* `typename`
|
* `typename`
|
||||||
* A fundamental type, function, or pointer type.
|
* A fundamental type, function, or pointer type.
|
||||||
|
|
||||||
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
|
***Concepts and Constraints are not supported***
|
||||||
Use at your own mental peril.
|
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
|
### The Data & Interface
|
||||||
|
|
||||||
@ -67,68 +45,11 @@ 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.
|
The AST is managed by the library and provided to the user via its interface.
|
||||||
However, the user may specifiy memory configuration.
|
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
|
https://github.com/Ed94/gencpp/blob/eea4ebf5c40d5d87baa465abfb1be30845b2377e/base/components/ast.hpp#L396-L461
|
||||||
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)
|
|
||||||
```
|
|
||||||
|
|
||||||
*`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`*
|
*`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*
|
*`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*
|
||||||
@ -138,16 +59,19 @@ The width dictates how much the static array can hold before it must give way to
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
constexpr static
|
constexpr static
|
||||||
usize ArrSpecs_Cap =
|
int AST_ArrSpecs_Cap =
|
||||||
(
|
(
|
||||||
AST_POD_Size
|
AST_POD_Size
|
||||||
- sizeof(AST*) * 3
|
- sizeof(Code)
|
||||||
- sizeof(StringCached)
|
- sizeof(StringCached)
|
||||||
- sizeof(CodeT)
|
- sizeof(Code) * 2
|
||||||
|
- sizeof(Token*)
|
||||||
|
- sizeof(Code)
|
||||||
|
- sizeof(CodeType)
|
||||||
- sizeof(ModuleFlag)
|
- sizeof(ModuleFlag)
|
||||||
- sizeof(u32)
|
- 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.*
|
*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
|
* 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`.
|
* 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:
|
* Most of the work is just defining the allocation procedure:
|
||||||
|
|
||||||
```cpp
|
```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.
|
* 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.
|
* 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.
|
* 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.
|
* `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.
|
* 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).
|
* 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.
|
* Memory within the buckets is not reused, so its inherently wasteful.
|
||||||
* I will be augmenting the single arena with a simple slag allocator.
|
* I will be augmenting the default allocator with virtual memory & a slab allocator in the [future](https://github.com/Ed94/gencpp/issues/12)
|
||||||
* Linked lists used children nodes on bodies, and parameters.
|
* 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.
|
* 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_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_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_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_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
|
||||||
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
||||||
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
|
* `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_LEX_ALLOCATOR_SIZE`
|
||||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
* `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`
|
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
|
* CodeAttributes
|
||||||
* CodeComment
|
* CodeComment
|
||||||
* CodeClass
|
* CodeClass
|
||||||
@ -204,13 +128,13 @@ The following CodeTypes are used which the user may optionally use strong typing
|
|||||||
* CodeNS
|
* CodeNS
|
||||||
* CodeOperator
|
* CodeOperator
|
||||||
* CodeOpCast
|
* CodeOpCast
|
||||||
* CodeParam : Has support for `for-range` iterating across parameters.
|
* CodeParams : Has support for `for : range` iterating across parameters.
|
||||||
* CodePreprocessCond
|
* CodePreprocessCond
|
||||||
* CodePragma
|
* CodePragma
|
||||||
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
|
* CodeSpecifiers : Has support for `for : range` iterating across specifiers.
|
||||||
* CodeStruct
|
* CodeStruct
|
||||||
* CodeTemplate
|
* CodeTemplate
|
||||||
* CodeType
|
* CodeTypename
|
||||||
* CodeTypedef
|
* CodeTypedef
|
||||||
* CodeUnion
|
* CodeUnion
|
||||||
* CodeUsing
|
* 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:
|
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||||
|
|
||||||
@ -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:
|
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
Code <name> = code_str( <some code without "" quotes > )
|
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_global_fragment`
|
||||||
* `module_private_fragment`
|
* `module_private_fragment`
|
||||||
* `fmt_newline`
|
* `fmt_newline`
|
||||||
* `param_varaidc` (Used for varadic definitions)
|
|
||||||
* `pragma_once`
|
* `pragma_once`
|
||||||
|
* `param_varaidc` (Used for varadic definitions)
|
||||||
* `preprocess_else`
|
* `preprocess_else`
|
||||||
* `preprocess_endif`
|
* `preprocess_endif`
|
||||||
* `spec_const`
|
* `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_local_persist` (local_persist macro)
|
||||||
* `spec_mutable`
|
* `spec_mutable`
|
||||||
* `spec_neverinline`
|
* `spec_neverinline`
|
||||||
|
* `spec_noexcept`
|
||||||
* `spec_override`
|
* `spec_override`
|
||||||
* `spec_ptr`
|
* `spec_ptr`
|
||||||
* `spec_pure`
|
* `spec_pure`
|
||||||
@ -452,8 +379,8 @@ Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` i
|
|||||||
* `t_u16`
|
* `t_u16`
|
||||||
* `t_u32`
|
* `t_u32`
|
||||||
* `t_u64`
|
* `t_u64`
|
||||||
* `t_sw` (ssize_t)
|
* `t_ssize` (ssize_t)
|
||||||
* `t_uw` (size_t)
|
* `t_usize` (size_t)
|
||||||
* `t_f32`
|
* `t_f32`
|
||||||
* `t_f64`
|
* `t_f64`
|
||||||
|
|
||||||
@ -471,14 +398,11 @@ and have the desired specifiers assigned to them beforehand.
|
|||||||
|
|
||||||
## Code generation and modification
|
## Code generation and modification
|
||||||
|
|
||||||
There are three provided auxillary interfaces:
|
There are two provided auxillary interfaces:
|
||||||
|
|
||||||
* Builder
|
* Builder
|
||||||
* Editor
|
|
||||||
* Scanner
|
* 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
|
### Builder is a similar object to the jai language's string_builder
|
||||||
|
|
||||||
* The purpose of it is to generate a file.
|
* 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
|
### 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
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
|
#pragma once
|
||||||
|
#include "gen.hpp"
|
||||||
#include "../project/gen.hpp"
|
|
||||||
|
|
||||||
using namespace gen;
|
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 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 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 )
|
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 )
|
<array_type> <fn>_init( AllocatorInfo allocator )
|
||||||
{
|
{
|
||||||
size_t initial_size = array_grow_formula(0);
|
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
|
inline
|
||||||
@ -362,24 +377,24 @@ CodeBody gen_array( StrC type, StrC array_name )
|
|||||||
++ Array_DefinitionCounter;
|
++ Array_DefinitionCounter;
|
||||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_strc();
|
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,
|
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_delimiter>, <type_delimiter>_init
|
R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_init
|
||||||
#define GENERIC_SLOT_<slot>__array_init_reserve <type_delimiter>, <type_delimiter>_init_reserve
|
#define GENERIC_SLOT_<slot>__array_init_reserve <type>, <array_type>_init_reserve
|
||||||
#define GENERIC_SLOT_<slot>__array_append <type_delimiter>, <type_delimiter>_append
|
#define GENERIC_SLOT_<slot>__array_append <array_type>, <array_type>_append
|
||||||
#define GENERIC_SLOT_<slot>__array_append_items <type_delimiter>, <type_delimiter>_append_items
|
#define GENERIC_SLOT_<slot>__array_append_items <array_type>, <array_type>_append_items
|
||||||
#define GENERIC_SLOT_<slot>__array_append_at <type_delimiter>, <type_delimiter>_append_at
|
#define GENERIC_SLOT_<slot>__array_append_at <array_type>, <array_type>_append_at
|
||||||
#define GENERIC_SLOT_<slot>__array_append_items_at <type_delimiter>, <type_delimiter>_append_items_at
|
#define GENERIC_SLOT_<slot>__array_append_items_at <array_type>, <array_type>_append_items_at
|
||||||
#define GENERIC_SLOT_<slot>__array_back <type_delimiter>, <type_delimiter>_back
|
#define GENERIC_SLOT_<slot>__array_back <array_type>, <array_type>_back
|
||||||
#define GENERIC_SLOT_<slot>__array_clear <type_delimiter>, <type_delimiter>_clear
|
#define GENERIC_SLOT_<slot>__array_clear <array_type>, <array_type>_clear
|
||||||
#define GENERIC_SLOT_<slot>__array_fill <type_delimiter>, <type_delimiter>_fill
|
#define GENERIC_SLOT_<slot>__array_fill <array_type>, <array_type>_fill
|
||||||
#define GENERIC_SLOT_<slot>__array_free <type_delimiter>, <type_delimiter>_free
|
#define GENERIC_SLOT_<slot>__array_free <array_type>, <array_type>_free
|
||||||
#define GENERIC_SLOT_<slot>__array_grow <type_delimiter>*, <type_delimiter>_grow
|
#define GENERIC_SLOT_<slot>__array_grow <array_type>*, <array_type>_grow
|
||||||
#define GENERIC_SLOT_<slot>__array_num <type_delimiter>, <type_delimiter>_num
|
#define GENERIC_SLOT_<slot>__array_num <array_type>, <array_type>_num
|
||||||
#define GENERIC_SLOT_<slot>__array_pop <type_delimiter>, <type_delimiter>_pop
|
#define GENERIC_SLOT_<slot>__array_pop <array_type>, <array_type>_pop
|
||||||
#define GENERIC_SLOT_<slot>__array_remove_at <type_delimiter>, <type_delimiter>_remove_at
|
#define GENERIC_SLOT_<slot>__array_remove_at <array_type>, <array_type>_remove_at
|
||||||
#define GENERIC_SLOT_<slot>__array_reserve <type_delimiter>, <type_delimiter>_reserve
|
#define GENERIC_SLOT_<slot>__array_reserve <array_type>, <array_type>_reserve
|
||||||
#define GENERIC_SLOT_<slot>__array_resize <type_delimiter>, <type_delimiter>_resize
|
#define GENERIC_SLOT_<slot>__array_resize <array_type>, <array_type>_resize
|
||||||
#define GENERIC_SLOT_<slot>__array_set_capacity <type_delimiter>*, <type_delimiter>_set_capacity
|
#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"), 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_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"), 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"), 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_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_clear"), GenericSel_Default, GenericSel_One_Arg ));
|
||||||
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_fill")) );
|
interface_defines.append( gen_generic_selection_function_macro( Array_DefinitionCounter, txt("array_fill")) );
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "gen.hpp"
|
||||||
#include "../project/gen.hpp"
|
|
||||||
#include "containers.array.hpp"
|
#include "containers.array.hpp"
|
||||||
|
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
@ -107,21 +106,21 @@ CodeBody gen_hashtable( StrC type, StrC hashtable_name )
|
|||||||
HT_FindResult <fn>__find ( <tbl_type> self, u64 key );
|
HT_FindResult <fn>__find ( <tbl_type> self, u64 key );
|
||||||
b32 <fn>__full ( <tbl_type> self );
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
<tbl_type> <fn>_init_reserve( AllocatorInfo allocator, ssize num )
|
<tbl_type> <fn>_init_reserve( AllocatorInfo allocator, ssize num )
|
||||||
{
|
{
|
||||||
<tbl_type> result = { NULL, NULL };
|
<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_get_header(result.Hashes)->Num = num;
|
||||||
array_resize(result.Hashes, num);
|
array_resize(result.Hashes, num);
|
||||||
array_fill(result.Hashes, 0, num, -1);
|
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;
|
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_hash_header = array_get_header( self->Hashes );
|
||||||
ArrayHeader* old_entries_header = array_get_header( self->Entries );
|
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 );
|
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" )
|
#pragma pop_macro( "forceinline" )
|
||||||
|
|
||||||
++ HashTable_DefinitionCounter;
|
++ 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,
|
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_delimiter>, <type_delimiter>_init
|
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_init
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_init_reserve <type_delimiter>, <type_delimiter>_init_reserve
|
#define GENERIC_SLOT_<slot>__hashtable_init_reserve <type>, <tbl_type>_init_reserve
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_clear <type_delimiter>, <type_delimiter>_clear
|
#define GENERIC_SLOT_<slot>__hashtable_clear <tbl_type>, <tbl_type>_clear
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_destroy <type_delimiter>*, <type_delimiter>_destroy
|
#define GENERIC_SLOT_<slot>__hashtable_destroy <tbl_type>, <tbl_type>_destroy
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_get <type_delimiter>, <type_delimiter>_get
|
#define GENERIC_SLOT_<slot>__hashtable_get <tbl_type>, <tbl_type>_get
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_map <type_delimiter>, <type_delimiter>_map
|
#define GENERIC_SLOT_<slot>__hashtable_map <tbl_type>, <tbl_type>_map
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_map_mut <type_delimiter>, <type_delimiter>_map_mut
|
#define GENERIC_SLOT_<slot>__hashtable_map_mut <tbl_type>, <tbl_type>_map_mut
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_grow <type_delimiter>*, <type_delimiter>_grow
|
#define GENERIC_SLOT_<slot>__hashtable_grow <tbl_type>*, <tbl_type>_grow
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_rehash <type_delimiter>*, <type_delimiter>_rehash
|
#define GENERIC_SLOT_<slot>__hashtable_rehash <tbl_type>*, <tbl_type>_rehash
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_rehash_fast <type_delimiter>, <type_delimiter>_rehash_fast
|
#define GENERIC_SLOT_<slot>__hashtable_rehash_fast <tbl_type>, <tbl_type>_rehash_fast
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_remove_entry <type_delimiter>, <type_delimiter>_remove_entry
|
#define GENERIC_SLOT_<slot>__hashtable_remove_entry <tbl_type>, <tbl_type>_remove_entry
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_set <type_delimiter>*, <type_delimiter>_set
|
#define GENERIC_SLOT_<slot>__hashtable_set <tbl_type>, <tbl_type>_set
|
||||||
#define GENERIC_SLOT_<slot>__hashtable_slot <type_delimiter>, <type_delimiter>_slot
|
#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__add_entry <tbl_type>*, <tbl_type>__add_entry
|
||||||
#define GENERIC_SLOT_<slot>__hashtable__find <type_delimiter>, <type_delimiter>__find
|
#define GENERIC_SLOT_<slot>__hashtable__find <tbl_type>, <tbl_type>__find
|
||||||
#define GENERIC_SLOT_<slot>__hashtable__full <type_delimiter>, <type_delimiter>__full
|
#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.
|
See Readme.md for more information from the project repository.
|
||||||
|
|
||||||
Public Address:
|
Public Address:
|
||||||
https://github.com/Ed94/gencpp
|
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.
|
| | / ___ ___ _ __ ___ _ __ _ __ | {___ | l_ __ _ __ _, ___ __| | | | '-l | '-l | |
|
||||||
|
| | |{_ \/ __\ '_ \ / __} '_ l| '_ l \___ \| __/ _` |/ _` |/ __\/ _` | | | | | | | |
|
||||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha !
|
| | l__j | ___/ | | | {__; ;_l } ;_l } ____} | l| (_} | {_| | ___j {_; | | l___ _J l_ _J l_ |
|
||||||
! ============================================================================================ !
|
| \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} |
|
||||||
! 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 !
|
| 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)
|
#if ! defined(GEN_DONT_ENFORCE_GEN_TIME_GUARD) && ! defined(GEN_TIME)
|
||||||
# error Gen.hpp : GEN_TIME not defined
|
# error Gen.hpp : GEN_TIME not defined
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../project/gen.hpp"
|
#include "gen.hpp"
|
||||||
|
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
@ -9,12 +9,12 @@ CodeBody gen_fixed_arenas()
|
|||||||
result.append(def_pragma(txt("region FixedArena")));
|
result.append(def_pragma(txt("region FixedArena")));
|
||||||
|
|
||||||
char const* template_struct = stringize(
|
char const* template_struct = stringize(
|
||||||
struct FixedArena_<Name>_Def
|
struct FixedArena_<Name>
|
||||||
{
|
{
|
||||||
char memory[<Size>];
|
char memory[<Size>];
|
||||||
Arena arena;
|
Arena arena;
|
||||||
};
|
};
|
||||||
typedef struct FixedArena_<Name>_Def FixedArena_<Name>;
|
typedef struct FixedArena_<Name> FixedArena_<Name>;
|
||||||
);
|
);
|
||||||
|
|
||||||
char const* template_interface = stringize(
|
char const* template_interface = stringize(
|
||||||
@ -29,6 +29,11 @@ CodeBody gen_fixed_arenas()
|
|||||||
{
|
{
|
||||||
return arena_size_remaining( & fixed_arena->arena, alignment);
|
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 ));
|
CodeBody arena_struct_1kb = parse_global_body( token_fmt_impl( 3, "Name", txt("1KB"), "Size", txt("kilobytes(1)"), template_struct ));
|
||||||
@ -84,7 +89,7 @@ CodeBody gen_fixed_arenas()
|
|||||||
result.append(arena_interface_2mb);
|
result.append(arena_interface_2mb);
|
||||||
result.append(arena_interface_4mb);
|
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(def);
|
||||||
result.append(fmt_newline);
|
result.append(fmt_newline);
|
||||||
|
|
||||||
@ -101,8 +106,25 @@ CodeBody gen_fixed_arenas()
|
|||||||
FixedArena_512KB* : fixed_arena_init_512KB, \
|
FixedArena_512KB* : fixed_arena_init_512KB, \
|
||||||
FixedArena_1MB* : fixed_arena_init_1MB, \
|
FixedArena_1MB* : fixed_arena_init_1MB, \
|
||||||
FixedArena_2MB* : fixed_arena_init_2MB, \
|
FixedArena_2MB* : fixed_arena_init_2MB, \
|
||||||
FixedArena_4MB* : fixed_arena_init_4MB \
|
FixedArena_4MB* : fixed_arena_init_4MB, \
|
||||||
) GEN_RESOLVED_FUNCTION_CALL(& expr)
|
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), \
|
#define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \
|
||||||
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
FixedArena_1KB* : fixed_arena_size_remaining_1KB, \
|
||||||
@ -116,8 +138,9 @@ CodeBody gen_fixed_arenas()
|
|||||||
FixedArena_512KB* : fixed_arena_size_remaining_512KB, \
|
FixedArena_512KB* : fixed_arena_size_remaining_512KB, \
|
||||||
FixedArena_1MB* : fixed_arena_size_remaining_1MB, \
|
FixedArena_1MB* : fixed_arena_size_remaining_1MB, \
|
||||||
FixedArena_2MB* : fixed_arena_size_remaining_2MB, \
|
FixedArena_2MB* : fixed_arena_size_remaining_2MB, \
|
||||||
FixedArena_4MB* : fixed_arena_size_remaining_4MB \
|
FixedArena_4MB* : fixed_arena_size_remaining_4MB, \
|
||||||
) GEN_RESOLVED_FUNCTION_CALL(& expr, alignment)
|
default : gen_generic_selection_fail \
|
||||||
|
) GEN_RESOLVED_FUNCTION_CALL(expr, alignment)
|
||||||
)"
|
)"
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../project/gen.hpp"
|
#include "gen.hpp"
|
||||||
|
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& par
|
|||||||
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
|
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
|
||||||
if ( cond->Content.is_equal(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;
|
found = true;
|
||||||
|
|
||||||
s32 depth = 1;
|
s32 depth = 1;
|
||||||
@ -105,7 +105,7 @@ R"(#define <macro_name>(selector_arg, ...) _Generic( (selector_arg), \
|
|||||||
for ( s32 slot = 1; slot <= num_slots; ++ slot )
|
for ( s32 slot = 1; slot <= num_slots; ++ slot )
|
||||||
{
|
{
|
||||||
StrC slot_str = String::fmt_buf(GlobalAllocator, "%d", slot).to_strc();
|
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,
|
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> ) \
|
R"( GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( GENERIC_SLOT_<slot>__<macro_name> ) \
|
||||||
@ -128,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 ( ! one_arg )
|
||||||
{
|
{
|
||||||
if (opts == GenericSel_By_Ref)
|
if (opts == GenericSel_By_Ref)
|
||||||
@ -172,7 +174,7 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""
|
|||||||
|
|
||||||
// Add parameter types to create a unique signature
|
// Add parameter types to create a unique signature
|
||||||
bool first_param = true;
|
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)
|
if (param->ValueType)
|
||||||
{
|
{
|
||||||
|
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
|
#define GEN_IMPLEMENTATION
|
||||||
#include "gen/gen.h"
|
#include "gen/gen.c"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// init();
|
// 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
|
# Singleheader
|
||||||
|
|
||||||
Creates a single header file version of the library using `singleheader.cpp`.
|
Creates a single header file version of the library using `singleheader.cpp`.
|
||||||
Follows the same convention seen in the gb, stb, and zpl libraries.
|
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