mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Compare commits
27 Commits
defines_n_
...
v0.23-Alph
Author | SHA1 | Date | |
---|---|---|---|
6d551e95b9 | |||
a7cb7b0411 | |||
46e816d7ce | |||
28aa2c4dec | |||
d410590a86 | |||
e271fa39e4 | |||
08dcc3152f | |||
0829603262 | |||
3133977b0f | |||
e4088185af | |||
c55151886f | |||
6689235691 | |||
6533a3be29 | |||
adbcb2a83b | |||
15847f10b9 | |||
8952cf5f1b | |||
2bdd49fd19 | |||
0f95c916dd | |||
527fb3b132 | |||
abffa74ad8 | |||
772d0de5c1 | |||
cb50f93af5 | |||
e4f564b165 | |||
0b78b74fbc | |||
5d8883ec45 | |||
c90c210e04 | |||
980d1d7134 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -39,3 +39,5 @@ gen_c_library/gen
|
||||
**/*.vcxproj
|
||||
**/*.vcxproj.filters
|
||||
**/*.vcxproj.user
|
||||
test/c_library/gen
|
||||
test/cpp_library/gen
|
||||
|
67
.vscode/c_cpp_properties.json
vendored
67
.vscode/c_cpp_properties.json
vendored
@ -28,27 +28,6 @@
|
||||
"/FC"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Win32 msvc c_library",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/gen_c_library/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 clang",
|
||||
"includePath": [
|
||||
@ -64,10 +43,56 @@
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "clang++.exe",
|
||||
"intelliSenseMode": "windows-clang-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 msvc c_library",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/gen_c_library/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 msvc c_library test",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/test/c_library/**",
|
||||
"${workspaceFolder}/gen_c_library/gen/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
16
LICENSE
16
LICENSE
@ -26,3 +26,19 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Source URL: https://github.com/Ed94/gencpp
|
||||
|
||||
Acknowledgements
|
||||
|
||||
* The dependencies for gencpp source are derived from the zpl library: https://github.com/zpl-c/zpl
|
||||
|
||||
Special thanks to:
|
||||
|
||||
* The Handmade Community.
|
||||
|
||||
* Casey Muratori, Ginger Bill (Bill Hall), Mr. 4th (Allen Webster), Ryan Fluery: Influnced conceptually how to handle staged metaprograming.
|
||||
|
||||
* Jonathan Blow: Jai's metaprogramming influenced the design of this library.
|
||||
|
||||
* My friends for putting up with discord spam on this library.
|
||||
|
19
Readme.md
19
Readme.md
@ -1,6 +1,9 @@
|
||||
# gencpp
|
||||
|
||||
An attempt at simple staged metaprogramming for C/C++.
|
||||
An attempt at simple staged metaprogramming for C/C++. Reflect and generate code for your codebase at runtime!
|
||||
|
||||

|
||||

|
||||
|
||||
The library API is a composition of code element constructors, and a non-standards-compliant single-pass C/C++ parser.
|
||||
These build up a code AST to then serialize with a file builder, or can be traversed for staged-reflection of C/C++ code.
|
||||
@ -49,7 +52,11 @@ Within `program.cpp` :
|
||||
|
||||
u32 gen_main()
|
||||
{
|
||||
gen::Context ctx;
|
||||
gen::init(& ctx);
|
||||
...
|
||||
gen::deinit(& ctx);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -140,3 +147,13 @@ struct ArrayHeader
|
||||
## Building
|
||||
|
||||
See the [scripts directory](scripts/).
|
||||
|
||||
## Gallery
|
||||
|
||||
### Listing definitions in the Cuik Compiler
|
||||
|
||||
https://github.com/user-attachments/assets/2302240c-01f1-4e1b-a4b5-292eb3186648
|
||||
|
||||
### Unreal: Generating a UAttributeSet from a UDataTable
|
||||
|
||||
https://github.com/user-attachments/assets/2a07b743-825d-4f9f-beaf-3559e8748a4d
|
||||
|
@ -8,7 +8,13 @@
|
||||
|
||||
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:
|
||||
If using the library's provided build scripts:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> base
|
||||
```
|
||||
|
||||
## Content Overview
|
||||
|
||||
* **base**: Files are in granular pieces separated into four directories:
|
||||
* **dependencies**: Originally from the c-zpl library and modified thereafter.
|
||||
@ -27,7 +33,7 @@ Standard formats:
|
||||
* **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.
|
||||
* **gen_c_library**: The library is heavily modifed into C11 compliant code. A segemented and single-header set of variants are generated.
|
||||
|
||||
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
|
||||
|
||||
@ -117,15 +123,15 @@ The vast majority of macros should be single-line subsitutions that either add:
|
||||
|
||||
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.
|
||||
* [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.
|
||||
[misc.hpp](./helpers/misc.hpp): Has shared functions used by the library generation meta-programs throughout this codebase.
|
||||
|
||||
If using the library's provided build scripts:
|
||||
|
||||
@ -154,9 +160,53 @@ Names or Content fields are interned strings and thus showed be cached using `ca
|
||||
|
||||
`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).
|
||||
The parser is documented under [`docs/Parsing.md`](../docs/Parsing.md) and [`docs/Parser_Algo.md`](../docs/Parser_Algo.md). Read that and the entire library if you want to extend it.
|
||||
|
||||
### Attributes
|
||||
|
||||
To add additional macro attributes, all that has to be done is modifying [`AttributeTokens.csv`](./enums/AttributeTokens.csv).
|
||||
|
||||
### Specifiers
|
||||
|
||||
To add additional macro specifiers, the following needs to be done:
|
||||
|
||||
1. Adjust [especifier.hpp](./components/gen/especifier.hpp)
|
||||
2. Adjust [etoktype.cpp](./components/gen/etoktype.cpp)
|
||||
3. Adjust [parser_case_macros.cpp](./components/parser_case_macros.cpp)
|
||||
|
||||
If the specifier is a new trailing specifier on function definitions:
|
||||
|
||||
Head into [base_codegen.hpp](./helpers/base_codegen.hpp): `gen_especifier`. There will be an `is_trailing` function that needs to be adjusted with an additional case for the user's new trailing specifier.
|
||||
|
||||
### Code Types
|
||||
|
||||
These require the following to be handled to the equivalent extent as the other types:
|
||||
|
||||
1. Adjust [ECodeTypes.csv](./enums/ECodeTypes.csv) with the new types
|
||||
2. Define a new `AST_<Name>` and `Code<Name>`. See
|
||||
* [ast.hpp](./components/ast.hpp): Initial forwards and user defined conversion for Code.
|
||||
* [ast_types.hpp](./components/ast_types.hpp): Define the `AST_<Name>` struct.
|
||||
* [code_types.hpp](./components/code_types.hpp): Defne the `CodeType` struct. If its needs an iterator see: `struct CodeBody` & `struct CodeParams`.
|
||||
3. [ast_case_macros.cpp](./components/ast_case_macros.cpp): Review cases here if the new code type needs to be considered.
|
||||
4. [ast.cpp](./components/ast.cpp): Need to review
|
||||
* `code_debug_str`
|
||||
* `code_is_equal`
|
||||
* `code_to_strbuilder_ptr`
|
||||
* `code_validate_body`
|
||||
5. [code_serialization.cpp](./components/code_serialization.cpp): Define serialization here.
|
||||
6. [inlines.hpp](./components/inlines.hpp): Any inline definitions for the `struct Code<Name>` are defined here.
|
||||
7. [interface.cpp](./components/interface.hpp): Define the `Code<Name>` upfront and parsing interface.
|
||||
8. [interface.upfront.cpp](./components/interface.upfront.cpp): Define the upfront constructor implementation.
|
||||
9. [interface.parsing.cpp](./components/interface.parsing.cpp): Define the parsing interface implementation.
|
||||
10. [lexer.cpp](./components/lexer.cpp): Adjust the lexer as needed.
|
||||
11. [parser.cpp](./components/parser.cpp): Adjust the parser as needed.
|
||||
|
||||
## 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.
|
||||
The library is designed to be fast to compile and generate code at runtime as fast as possible on a debug build.
|
||||
Its recommended that your metaprogam be compiled using a single translation unit (unity build).
|
||||
|
||||
## Whats with the expression / executions support #ifd and enums?
|
||||
|
||||
The library is a *work in progress* and those are unfinished hypotheticals for adding the ability to manage or parse the AST of expresions or execution scope code.
|
||||
They are entirely untested and not meant to be used yet, futher there is no parsing support or an upfront interface for what CodeTypes are defined so far.
|
||||
|
@ -1,6 +1,5 @@
|
||||
#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"
|
||||
|
@ -43,7 +43,7 @@ struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct AST_Expr;
|
||||
struct AST_Expr_Assign;
|
||||
struct AST_Expr_Alignof;
|
||||
@ -140,7 +140,7 @@ struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
#endif
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
|
||||
#if GEN_COMPILER_C
|
||||
typedef AST_Expr* CodeExpr;
|
||||
|
@ -29,16 +29,16 @@
|
||||
struct AST_Body
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
StrCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Body is not the same size as AST");
|
||||
|
||||
@ -47,7 +47,7 @@ struct AST_Attributes
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StrCached Content;
|
||||
StrCached Content;
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
@ -65,7 +65,7 @@ struct AST_BaseClass
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@ -82,7 +82,7 @@ struct AST_Comment
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StrCached Content;
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@ -100,14 +100,14 @@ struct AST_Class
|
||||
{
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeTypename ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeTypename Prev;
|
||||
CodeTypename Next;
|
||||
Token* Tok;
|
||||
@ -130,10 +130,10 @@ struct AST_Constructor
|
||||
Code InitializerList;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@ -155,13 +155,13 @@ struct AST_Define
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 1 ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Define) == sizeof(AST), "ERROR: AST_Define is not the same size as AST");
|
||||
|
||||
@ -176,7 +176,7 @@ struct AST_DefineParams
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_DefineParams) == sizeof(AST), "ERROR: AST_DefineParams is not the same size as AST");
|
||||
@ -192,10 +192,10 @@ struct AST_Destructor
|
||||
CodeSpecifiers Specs;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_3_ [ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_3_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@ -217,10 +217,10 @@ struct AST_Enum
|
||||
CodeTypename UnderlyingType;
|
||||
Code UnderlyingTypeMacro;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@ -237,7 +237,7 @@ struct AST_Exec
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StrCached Content;
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@ -247,7 +247,7 @@ struct AST_Exec
|
||||
};
|
||||
static_assert( sizeof(AST_Exec) == sizeof(AST), "ERROR: AST_Exec is not the same size as AST");
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct AST_Expr
|
||||
{
|
||||
union {
|
||||
@ -515,13 +515,13 @@ struct AST_Extern
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Extern) == sizeof(AST), "ERROR: AST_Extern is not the same size as AST");
|
||||
|
||||
@ -531,13 +531,13 @@ struct AST_Include
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StrCached Content;
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Include) == sizeof(AST), "ERROR: AST_Include is not the same size as AST");
|
||||
|
||||
@ -550,16 +550,16 @@ struct AST_Friend
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Friend) == sizeof(AST), "ERROR: AST_Friend is not the same size as AST");
|
||||
|
||||
@ -573,19 +573,19 @@ struct AST_Fn
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParams Params;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Fn) == sizeof(AST), "ERROR: AST_Fn is not the same size as AST");
|
||||
|
||||
@ -594,14 +594,14 @@ struct AST_Module
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Module) == sizeof(AST), "ERROR: AST_Module is not the same size as AST");
|
||||
|
||||
@ -610,45 +610,45 @@ struct AST_NS
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct {
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_NS) == sizeof(AST), "ERROR: AST_NS is not the same size as AST");
|
||||
|
||||
struct AST_Operator
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ReturnType;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
Operator Op;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
Operator Op;
|
||||
};
|
||||
static_assert( sizeof(AST_Operator) == sizeof(AST), "ERROR: AST_Operator is not the same size as AST");
|
||||
|
||||
@ -658,22 +658,22 @@ struct AST_OpCast
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ValueType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs;
|
||||
CodeTypename ValueType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
||||
|
||||
@ -684,7 +684,7 @@ struct AST_Params
|
||||
struct
|
||||
{
|
||||
// TODO(Ed): Support attributes for parameters (Some prefix macros can be converted to that...)
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
CodeTypename ValueType;
|
||||
Code Macro;
|
||||
Code Value;
|
||||
@ -692,14 +692,14 @@ struct AST_Params
|
||||
// char _PAD_PROPERTIES_3_[sizeof( AST* )];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
StrCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_Params) == sizeof(AST), "ERROR: AST_Params is not the same size as AST");
|
||||
|
||||
@ -709,13 +709,13 @@ struct AST_Pragma
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StrCached Content;
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Pragma) == sizeof(AST), "ERROR: AST_Pragma is not the same size as AST");
|
||||
|
||||
@ -723,40 +723,40 @@ struct AST_PreprocessCond
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StrCached Content;
|
||||
StrCached Content;
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_PreprocessCond) == sizeof(AST), "ERROR: AST_PreprocessCond is not the same size as AST");
|
||||
|
||||
struct AST_Specifiers
|
||||
{
|
||||
Specifier ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
Specifier ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
StrCached Name;
|
||||
CodeSpecifiers NextSpecs;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
CodeSpecifiers NextSpecs;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_Specifiers) == sizeof(AST), "ERROR: AST_Specifier is not the same size as AST");
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct AST_Stmt
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -771,7 +771,7 @@ struct AST_Stmt_Break
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -786,7 +786,7 @@ struct AST_Stmt_Case
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -801,7 +801,7 @@ struct AST_Stmt_Continue
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -816,7 +816,7 @@ struct AST_Stmt_Decl
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -831,7 +831,7 @@ struct AST_Stmt_Do
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -846,7 +846,7 @@ struct AST_Stmt_Expr
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -861,7 +861,7 @@ struct AST_Stmt_Else
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -876,7 +876,7 @@ struct AST_Stmt_If
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -891,7 +891,7 @@ struct AST_Stmt_For
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -906,7 +906,7 @@ struct AST_Stmt_Goto
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -921,7 +921,7 @@ struct AST_Stmt_Label
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -936,7 +936,7 @@ struct AST_Stmt_Switch
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -951,7 +951,7 @@ struct AST_Stmt_While
|
||||
union {
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeExpr Prev;
|
||||
CodeExpr Next;
|
||||
Token* Tok;
|
||||
@ -970,14 +970,14 @@ struct AST_Struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeTypename ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeTypename Prev;
|
||||
CodeTypename Next;
|
||||
Token* Tok;
|
||||
@ -994,20 +994,20 @@ struct AST_Template
|
||||
char _PAD_[ sizeof(Specifier) * AST_ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Template) == sizeof(AST), "ERROR: AST_Template is not the same size as AST");
|
||||
|
||||
@ -1029,13 +1029,13 @@ struct AST_Type
|
||||
// CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
b32 IsParamPack;
|
||||
};
|
||||
static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
|
||||
@ -1062,7 +1062,7 @@ struct AST_Typename
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
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)
|
||||
@ -1077,9 +1077,9 @@ struct AST_Typedef
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
Code UnderlyingType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
@ -1101,19 +1101,19 @@ struct AST_Union
|
||||
{
|
||||
char _PAD_INLINE_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Union) == sizeof(AST), "ERROR: AST_Union is not the same size as AST");
|
||||
|
||||
@ -1125,19 +1125,19 @@ struct AST_Using
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeTypename UnderlyingType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Using) == sizeof(AST), "ERROR: AST_Using is not the same size as AST");
|
||||
|
||||
@ -1153,17 +1153,17 @@ struct AST_Var
|
||||
CodeTypename ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
CodeVar NextVar;
|
||||
CodeVar NextVar;
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarParenthesizedInit;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarParenthesizedInit;
|
||||
};
|
||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||
|
||||
|
@ -1036,12 +1036,24 @@ void specifiers_to_strbuilder_ref( CodeSpecifiers self, StrBuilder* result )
|
||||
GEN_ASSERT(result);
|
||||
s32 idx = 0;
|
||||
s32 left = self->NumEntries;
|
||||
while ( left-- )
|
||||
while ( left -- )
|
||||
{
|
||||
Str spec = spec_to_str( self->ArrSpecs[idx] );
|
||||
strbuilder_append_fmt( result, "%.*s ", spec.Len, spec.Ptr );
|
||||
Specifier spec = self->ArrSpecs[idx];
|
||||
Str spec_str = spec_to_str( spec );
|
||||
if ( idx > 0 ) switch (spec) {
|
||||
case Spec_Ptr:
|
||||
case Spec_Ref:
|
||||
case Spec_RValue:
|
||||
break;
|
||||
|
||||
default:
|
||||
strbuilder_append_str(result, txt(" "));
|
||||
break;
|
||||
}
|
||||
strbuilder_append_fmt( result, "%S", spec_str );
|
||||
idx++;
|
||||
}
|
||||
strbuilder_append_str(result, txt(" "));
|
||||
}
|
||||
|
||||
StrBuilder struct_to_strbuilder(CodeStruct self)
|
||||
@ -1445,7 +1457,7 @@ void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
|
||||
if ( self->Specs )
|
||||
strbuilder_append_fmt( result, "%SB\n", specifiers_to_strbuilder(self->Specs) );
|
||||
strbuilder_append_fmt( result, "%SB", specifiers_to_strbuilder(self->Specs) );
|
||||
|
||||
strbuilder_append_fmt( result, "%SB %S", typename_to_strbuilder(self->ValueType), self->Name );
|
||||
|
||||
|
@ -362,7 +362,7 @@ struct CodeExec
|
||||
AST_Exec *ast;
|
||||
};
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct CodeExpr
|
||||
{
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
@ -689,7 +689,7 @@ struct CodePreprocessCond
|
||||
AST_PreprocessCond* ast;
|
||||
};
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
#ifdef GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct CodeStmt
|
||||
{
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
|
@ -23,6 +23,7 @@ enum Specifier : u32
|
||||
Spec_Ptr,
|
||||
Spec_Ref,
|
||||
Spec_Register,
|
||||
Spec_Restrict,
|
||||
Spec_RValue,
|
||||
Spec_Static,
|
||||
Spec_Thread_Local,
|
||||
@ -56,6 +57,7 @@ inline Str spec_to_str( Specifier type )
|
||||
{ "*", sizeof( "*" ) - 1 },
|
||||
{ "&", sizeof( "&" ) - 1 },
|
||||
{ "register", sizeof( "register" ) - 1 },
|
||||
{ "restrict", sizeof( "restrict" ) - 1 },
|
||||
{ "&&", sizeof( "&&" ) - 1 },
|
||||
{ "static", sizeof( "static" ) - 1 },
|
||||
{ "thread_local", sizeof( "thread_local" ) - 1 },
|
||||
@ -72,7 +74,18 @@ inline Str spec_to_str( Specifier type )
|
||||
|
||||
inline bool spec_is_trailing( Specifier specifier )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
switch ( specifier )
|
||||
{
|
||||
case Spec_Const :
|
||||
case Spec_Final :
|
||||
case Spec_NoExceptions :
|
||||
case Spec_Override :
|
||||
case Spec_Pure :
|
||||
case Spec_Volatile :
|
||||
return true;
|
||||
default :
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline Specifier str_to_specifier( Str str )
|
||||
|
@ -24,8 +24,8 @@ enum TokType : u32
|
||||
Tok_BraceCurly_Close,
|
||||
Tok_BraceSquare_Open,
|
||||
Tok_BraceSquare_Close,
|
||||
Tok_Capture_Start,
|
||||
Tok_Capture_End,
|
||||
Tok_Paren_Open,
|
||||
Tok_Paren_Close,
|
||||
Tok_Comment,
|
||||
Tok_Comment_End,
|
||||
Tok_Comment_Start,
|
||||
@ -83,6 +83,7 @@ enum TokType : u32
|
||||
Tok_Spec_Mutable,
|
||||
Tok_Spec_NeverInline,
|
||||
Tok_Spec_Override,
|
||||
Tok_Spec_Restrict,
|
||||
Tok_Spec_Static,
|
||||
Tok_Spec_ThreadLocal,
|
||||
Tok_Spec_Volatile,
|
||||
@ -188,6 +189,7 @@ inline Str toktype_to_str( TokType type )
|
||||
{ "mutable", sizeof( "mutable" ) - 1 },
|
||||
{ "neverinline", sizeof( "neverinline" ) - 1 },
|
||||
{ "override", sizeof( "override" ) - 1 },
|
||||
{ "restrict", sizeof( "restrict" ) - 1 },
|
||||
{ "static", sizeof( "static" ) - 1 },
|
||||
{ "thread_local", sizeof( "thread_local" ) - 1 },
|
||||
{ "volatile", sizeof( "volatile" ) - 1 },
|
||||
|
@ -15,7 +15,7 @@
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-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 |
|
||||
|
@ -503,7 +503,7 @@ void register_macros( s32 num, ... )
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void register_macros( s32 num, Macro* macros )
|
||||
void register_macros_arr( s32 num, Macro* macros )
|
||||
{
|
||||
GEN_ASSERT(num > 0);
|
||||
do
|
||||
|
@ -93,6 +93,9 @@ struct Context
|
||||
|
||||
// TODO(Ed): Active parse context vs a parse result need to be separated conceptually
|
||||
ParseContext parser;
|
||||
|
||||
// TODO(Ed): Formatting - This will eventually be in a separate struct when in the process of serialization of the builder.
|
||||
s32 temp_serialize_indent;
|
||||
};
|
||||
|
||||
// Initialize the library. There first ctx initialized must exist for lifetime of other contextes that come after as its the one that
|
||||
@ -121,7 +124,11 @@ GEN_API void register_macro( Macro macro );
|
||||
|
||||
// Ease of use batch registration
|
||||
GEN_API void register_macros( s32 num, ... );
|
||||
GEN_API void register_macros( s32 num, Macro* macros );
|
||||
GEN_API void register_macros_arr( s32 num, Macro* macros );
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline void register_macros( s32 num, Macro* macros ) { return register_macros_arr(num, macros); }
|
||||
#endif
|
||||
|
||||
// Used internally to retrive or make string allocations.
|
||||
// Strings are stored in a series of string arenas of fixed size (SizePer_StringArena)
|
||||
@ -276,37 +283,50 @@ GEN_API CodeBody def_body( CodeType type );
|
||||
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
||||
/// or provide as an array of Code objects.
|
||||
|
||||
GEN_API CodeBody def_class_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_class_body ( s32 num, Code* codes );
|
||||
GEN_API CodeDefineParams def_define_params ( s32 num, ... );
|
||||
GEN_API CodeDefineParams def_define_params ( s32 num, CodeDefineParams* codes );
|
||||
GEN_API CodeBody def_enum_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_enum_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_export_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_export_body ( s32 num, Code* codes);
|
||||
GEN_API CodeBody def_extern_link_body( s32 num, ... );
|
||||
GEN_API CodeBody def_extern_link_body( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_function_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_function_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_global_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_global_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_namespace_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_namespace_body ( s32 num, Code* codes );
|
||||
GEN_API CodeParams def_params ( s32 num, ... );
|
||||
GEN_API CodeParams def_params ( s32 num, CodeParams* params );
|
||||
GEN_API CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||
GEN_API CodeSpecifiers def_specifiers ( s32 num, Specifier* specs );
|
||||
GEN_API CodeBody def_struct_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_struct_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_union_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_union_body ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_class_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_class_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeDefineParams def_define_params ( s32 num, ... );
|
||||
GEN_API CodeDefineParams def_define_params_arr ( s32 num, CodeDefineParams* codes );
|
||||
GEN_API CodeBody def_enum_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_enum_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_export_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_export_body_arr ( s32 num, Code* codes);
|
||||
GEN_API CodeBody def_extern_link_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_extern_link_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_function_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_function_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_global_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_global_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_namespace_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_namespace_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeParams def_params ( s32 num, ... );
|
||||
GEN_API CodeParams def_params_arr ( s32 num, CodeParams* params );
|
||||
GEN_API CodeSpecifiers def_specifiers ( s32 num, ... );
|
||||
GEN_API CodeSpecifiers def_specifiers_arr ( s32 num, Specifier* specs );
|
||||
GEN_API CodeBody def_struct_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_struct_body_arr ( s32 num, Code* codes );
|
||||
GEN_API CodeBody def_union_body ( s32 num, ... );
|
||||
GEN_API CodeBody def_union_body_arr ( s32 num, Code* codes );
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline CodeBody def_class_body ( s32 num, Code* codes ) { return def_class_body_arr(num, codes); }
|
||||
forceinline CodeDefineParams def_define_params ( s32 num, CodeDefineParams* codes ) { return def_define_params_arr(num, codes); }
|
||||
forceinline CodeBody def_enum_body ( s32 num, Code* codes ) { return def_enum_body_arr(num, codes); }
|
||||
forceinline CodeBody def_export_body ( s32 num, Code* codes) { return def_export_body_arr(num, codes); }
|
||||
forceinline CodeBody def_extern_link_body( s32 num, Code* codes ) { return def_extern_link_body_arr(num, codes); }
|
||||
forceinline CodeBody def_function_body ( s32 num, Code* codes ) { return def_function_body_arr(num, codes); }
|
||||
forceinline CodeBody def_global_body ( s32 num, Code* codes ) { return def_global_body_arr(num, codes); }
|
||||
forceinline CodeBody def_namespace_body ( s32 num, Code* codes ) { return def_namespace_body_arr(num, codes); }
|
||||
forceinline CodeParams def_params ( s32 num, CodeParams* params ) { return def_params_arr(num, params); }
|
||||
forceinline CodeSpecifiers def_specifiers ( s32 num, Specifier* specs ) { return def_specifiers_arr(num, specs); }
|
||||
forceinline CodeBody def_struct_body ( s32 num, Code* codes ) { return def_struct_body_arr(num, codes); }
|
||||
forceinline CodeBody def_union_body ( s32 num, Code* codes ) { return def_union_body_arr(num, codes); }
|
||||
#endif
|
||||
|
||||
#pragma endregion Upfront
|
||||
|
||||
#pragma region Parsing
|
||||
|
||||
// TODO(Ed) : Implmeent the new parser API design.
|
||||
|
||||
#if 0
|
||||
struct StackNode
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ CodeConstructor parse_constructor( Str def )
|
||||
|
||||
while ( left && tok_is_specifier(currtok) )
|
||||
{
|
||||
Specifier spec = str_to_specifier( tok_to_str(currtok) );
|
||||
Specifier spec = str_to_specifier( currtok.Text );
|
||||
|
||||
b32 ignore_spec = false;
|
||||
|
||||
@ -73,7 +73,7 @@ CodeConstructor parse_constructor( Str def )
|
||||
|
||||
if ( NumSpecifiers )
|
||||
{
|
||||
specifiers = def_specifiers( NumSpecifiers, specs_found );
|
||||
specifiers = def_specifiers_arr( NumSpecifiers, specs_found );
|
||||
// <specifiers> ...
|
||||
}
|
||||
|
||||
|
@ -1369,7 +1369,7 @@ CodeBody def_class_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_class_body( s32 num, Code* codes )
|
||||
CodeBody def_class_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_class_body );
|
||||
|
||||
@ -1432,7 +1432,7 @@ CodeDefineParams def_define_params( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDefineParams def_define_params( s32 num, CodeDefineParams* codes )
|
||||
CodeDefineParams def_define_params_arr( s32 num, CodeDefineParams* codes )
|
||||
{
|
||||
def_body_code_array_start( def_define_params );
|
||||
|
||||
@ -1491,7 +1491,7 @@ CodeBody def_enum_body( s32 num, ... )
|
||||
return (CodeBody) result;
|
||||
}
|
||||
|
||||
CodeBody def_enum_body( s32 num, Code* codes )
|
||||
CodeBody def_enum_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_enum_body );
|
||||
|
||||
@ -1552,7 +1552,7 @@ CodeBody def_export_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_export_body( s32 num, Code* codes )
|
||||
CodeBody def_export_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_export_body );
|
||||
|
||||
@ -1618,7 +1618,7 @@ CodeBody def_extern_link_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_extern_link_body( s32 num, Code* codes )
|
||||
CodeBody def_extern_link_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_extern_linkage_body );
|
||||
|
||||
@ -1685,7 +1685,7 @@ CodeBody def_function_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_function_body( s32 num, Code* codes )
|
||||
CodeBody def_function_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_function_body );
|
||||
|
||||
@ -1756,7 +1756,7 @@ CodeBody def_global_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_global_body( s32 num, Code* codes )
|
||||
CodeBody def_global_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_global_body );
|
||||
|
||||
@ -1827,7 +1827,7 @@ CodeBody def_namespace_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_namespace_body( s32 num, Code* codes )
|
||||
CodeBody def_namespace_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_namespace_body );
|
||||
|
||||
@ -1889,7 +1889,7 @@ CodeParams def_params( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeParams def_params( s32 num, CodeParams* codes )
|
||||
CodeParams def_params_arr( s32 num, CodeParams* codes )
|
||||
{
|
||||
def_body_code_array_start( def_params );
|
||||
|
||||
@ -1945,7 +1945,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeSpecifiers def_specifiers( s32 num, Specifier* specs )
|
||||
CodeSpecifiers def_specifiers_arr( s32 num, Specifier* specs )
|
||||
{
|
||||
if ( num <= 0 ) {
|
||||
log_failure("gen::def_specifiers: num cannot be zero or less");
|
||||
@ -2004,7 +2004,7 @@ CodeBody def_struct_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_struct_body( s32 num, Code* codes )
|
||||
CodeBody def_struct_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_struct_body );
|
||||
|
||||
@ -2065,7 +2065,7 @@ CodeBody def_union_body( s32 num, ... )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody def_union_body( s32 num, Code* codes )
|
||||
CodeBody def_union_body_arr( s32 num, Code* codes )
|
||||
{
|
||||
def_body_code_array_start( def_union_body );
|
||||
|
||||
|
@ -151,7 +151,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
macro.Flags |= MF_Functional;
|
||||
}
|
||||
|
||||
Token opening_paren = { { ctx->scanner, 1 }, Tok_Capture_Start, ctx->line, ctx->column, TF_Preprocess };
|
||||
Token opening_paren = { { ctx->scanner, 1 }, Tok_Paren_Open, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append( _ctx->Lexer_Tokens, opening_paren );
|
||||
move_forward();
|
||||
|
||||
@ -242,7 +242,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
);
|
||||
return Lex_ReturnNull;
|
||||
}
|
||||
Token closing_paren = { { ctx->scanner, 1 }, Tok_Capture_End, ctx->line, ctx->column, TF_Preprocess };
|
||||
Token closing_paren = { { ctx->scanner, 1 }, Tok_Paren_Close, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append(_ctx->Lexer_Tokens, closing_paren);
|
||||
move_forward();
|
||||
}
|
||||
@ -281,7 +281,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
ctx->token.Text.Len++;
|
||||
}
|
||||
|
||||
ctx->token.Type = str_to_toktype( tok_to_str(ctx->token) );
|
||||
ctx->token.Type = str_to_toktype( ctx->token.Text );
|
||||
|
||||
bool is_preprocessor = ctx->token.Type >= Tok_Preprocess_Define && ctx->token.Type <= Tok_Preprocess_Pragma;
|
||||
if ( ! is_preprocessor )
|
||||
@ -488,7 +488,7 @@ void lex_found_token( LexContext* ctx )
|
||||
return;
|
||||
}
|
||||
|
||||
TokType type = str_to_toktype( tok_to_str(ctx->token) );
|
||||
TokType type = str_to_toktype( ctx->token.Text );
|
||||
|
||||
if (type <= Tok_Access_Public && type >= Tok_Access_Private ) {
|
||||
ctx->token.Flags |= TF_AccessSpecifier;
|
||||
@ -532,7 +532,7 @@ void lex_found_token( LexContext* ctx )
|
||||
ctx->token.Type = macrotype_to_toktype(macro->Type);
|
||||
b32 is_functional = macro_is_functional(* macro);
|
||||
resolved_to_macro = has_args ? is_functional : ! is_functional;
|
||||
if ( ! resolved_to_macro ) {
|
||||
if ( ! resolved_to_macro && GEN_BUILD_DEBUG ) {
|
||||
log_fmt("Info(%d, %d): %S identified as a macro but usage here does not resolve to one (interpreting as identifier)\n"
|
||||
, ctx->token.Line
|
||||
, ctx->token.Line
|
||||
@ -797,7 +797,7 @@ TokArray lex( Str content )
|
||||
{
|
||||
Str text = { c.scanner, 1 };
|
||||
c.token.Text = text;
|
||||
c.token.Type = Tok_Capture_Start;
|
||||
c.token.Type = Tok_Paren_Open;
|
||||
|
||||
if (c.left)
|
||||
move_forward();
|
||||
@ -807,7 +807,7 @@ TokArray lex( Str content )
|
||||
{
|
||||
Str text = { c.scanner, 1 };
|
||||
c.token.Text = text;
|
||||
c.token.Type = Tok_Capture_End;
|
||||
c.token.Type = Tok_Paren_Close;
|
||||
|
||||
if (c.left)
|
||||
move_forward();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
// These macros are used in the swtich cases within parser.cpp
|
||||
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_TOK_SPECIFIER_CASES \
|
||||
case Tok_Spec_Consteval: \
|
||||
case Tok_Spec_Constexpr: \
|
||||
case Tok_Spec_Constinit: \
|
||||
@ -13,7 +13,7 @@ case Tok_Spec_Static: \
|
||||
case Tok_Spec_Volatile: \
|
||||
case Tok_Spec_Virtual
|
||||
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_SPECIFIER_CASES \
|
||||
case Spec_Constexpr: \
|
||||
case Spec_Constinit: \
|
||||
case Spec_Explicit: \
|
||||
@ -50,12 +50,12 @@ case Spec_NeverInline: \
|
||||
case Spec_Static: \
|
||||
case Spec_Volatile
|
||||
|
||||
#define GEN_PARSER_FRIEND_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_FRIEND_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Inline: \
|
||||
case Spec_ForceInline
|
||||
|
||||
#define GEN_PARSER_FUNCTION_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_FUNCTION_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Consteval: \
|
||||
case Spec_Constexpr: \
|
||||
@ -66,7 +66,7 @@ case Spec_Inline: \
|
||||
case Spec_NeverInline: \
|
||||
case Spec_Static
|
||||
|
||||
#define GEN_PARSER_OPERATOR_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_OPERATOR_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Constexpr: \
|
||||
case Spec_ForceInline: \
|
||||
@ -74,7 +74,7 @@ case Spec_Inline: \
|
||||
case Spec_NeverInline: \
|
||||
case Spec_Static
|
||||
|
||||
#define GEN_PARSER_TEMPLATE_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_TEMPLATE_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Constexpr: \
|
||||
case Spec_Constinit: \
|
||||
@ -97,9 +97,16 @@ case Spec_Global: \
|
||||
case Spec_Inline: \
|
||||
case Spec_Local_Persist: \
|
||||
case Spec_Mutable: \
|
||||
case Spec_Restrict: \
|
||||
case Spec_Static: \
|
||||
case Spec_Thread_Local: \
|
||||
case Spec_Volatile
|
||||
|
||||
#define GEN_PARSER_TYPENAME_ALLOWED_SUFFIX_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Ptr: \
|
||||
case Spec_Restrict: \
|
||||
case Spec_Ref: \
|
||||
case Spec_RValue
|
||||
|
||||
|
||||
|
@ -43,11 +43,6 @@ AccessSpec tok_to_access_specifier(Token tok) {
|
||||
return scast(AccessSpec, tok.Type);
|
||||
}
|
||||
|
||||
forceinline
|
||||
Str tok_to_str(Token tok) {
|
||||
return tok.Text;
|
||||
}
|
||||
|
||||
forceinline
|
||||
bool tok_is_valid( Token tok ) {
|
||||
return tok.Text.Ptr && tok.Text.Len && tok.Type != Tok_Invalid;
|
||||
@ -132,8 +127,6 @@ enum MacroType : u16
|
||||
MT_Expression, // A macro is assumed to be a expression if not resolved.
|
||||
MT_Statement,
|
||||
MT_Typename,
|
||||
MT_Attribute, // More of a note to the parser than anythign else (attributes should be defined in the user attribues def).
|
||||
MT_Specifier, // More of a note to the parser than anythign else (specifiers should be defined in the user attribues def).
|
||||
MT_Block_Start, // Not Supported yet
|
||||
MT_Block_End, // Not Supported yet
|
||||
MT_Case_Statement, // Not Supported yet
|
||||
@ -160,8 +153,6 @@ Str macrotype_to_str( MacroType type )
|
||||
{ "Statement", sizeof("Statement") - 1 },
|
||||
{ "Expression", sizeof("Expression") - 1 },
|
||||
{ "Typename", sizeof("Typename") - 1 },
|
||||
{ "Attribute(Macro)", sizeof("Attribute(Macro)") - 1 },
|
||||
{ "Specifier(Macro)", sizeof("Specifier(Macro)") - 1 },
|
||||
{ "Block_Start", sizeof("Block_Start") - 1 },
|
||||
{ "Block_End", sizeof("Block_End") - 1 },
|
||||
{ "Case_Statement", sizeof("Case_Statement") - 1 },
|
||||
|
@ -5,10 +5,9 @@
|
||||
|
||||
#pragma region StaticData
|
||||
global Context* _ctx;
|
||||
global u32 context_counter;
|
||||
|
||||
#pragma region Constants
|
||||
global u32 context_counter;
|
||||
|
||||
global Macro enum_underlying_macro;
|
||||
|
||||
global Code Code_Global;
|
||||
|
@ -282,10 +282,9 @@ bool array_fill(Array<Type> array, usize begin, usize end, Type value)
|
||||
ArrayHeader* header = array_get_header(array);
|
||||
|
||||
if (begin < 0 || end > header->Num)
|
||||
return false;
|
||||
return false;
|
||||
|
||||
for (ssize idx = ssize(begin); idx < ssize(end); idx++)
|
||||
{
|
||||
for (ssize idx = ssize(begin); idx < ssize(end); idx++) {
|
||||
array[idx] = value;
|
||||
}
|
||||
|
||||
@ -754,7 +753,7 @@ HashTableFindResult hashtable__find(HashTable<Type> table, u64 key)
|
||||
if (table.Entries[result.EntryIndex].Key == key)
|
||||
break;
|
||||
|
||||
result.PrevIndex = result.EntryIndex;
|
||||
result.PrevIndex = result.EntryIndex;
|
||||
result.EntryIndex = table.Entries[result.EntryIndex].Next;
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@
|
||||
#if GEN_BUILD_DEBUG
|
||||
# if defined( GEN_COMPILER_MSVC )
|
||||
# if _MSC_VER < 1300
|
||||
#pragma message("GEN_BUILD_DEBUG: __asm int 3")
|
||||
// #pragma message("GEN_BUILD_DEBUG: __asm int 3")
|
||||
# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */
|
||||
# else
|
||||
#pragma message("GEN_BUILD_DEBUG: __debugbreak()")
|
||||
// #pragma message("GEN_BUILD_DEBUG: __debugbreak()")
|
||||
# define GEN_DEBUG_TRAP() __debugbreak()
|
||||
# endif
|
||||
# elif defined( GEN_COMPILER_TINYC )
|
||||
@ -23,7 +23,7 @@
|
||||
# define GEN_DEBUG_TRAP() __builtin_trap()
|
||||
# endif
|
||||
#else
|
||||
#pragma message("GEN_BUILD_DEBUG: omitted")
|
||||
// #pragma message("GEN_BUILD_DEBUG: omitted")
|
||||
# define GEN_DEBUG_TRAP()
|
||||
#endif
|
||||
|
||||
|
@ -89,13 +89,13 @@
|
||||
#define src_line_str stringize(__LINE__)
|
||||
|
||||
#ifndef do_once
|
||||
#define do_once() \
|
||||
static int __do_once_counter_##src_line_str = 0; \
|
||||
for(; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1 ) \
|
||||
#define do_once() \
|
||||
local_persist int __do_once_counter_##src_line_str = 0; \
|
||||
for(; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1 ) \
|
||||
|
||||
#define do_once_defer( expression ) \
|
||||
static int __do_once_counter_##src_line_str = 0; \
|
||||
for(; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1, (expression)) \
|
||||
#define do_once_defer( expression ) \
|
||||
local_persist int __do_once_counter_##src_line_str = 0; \
|
||||
for(;__do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1, (expression)) \
|
||||
|
||||
#define do_once_start \
|
||||
do \
|
||||
|
@ -14,6 +14,7 @@ NeverInline, neverinline
|
||||
Ptr, *
|
||||
Ref, &
|
||||
Register, register
|
||||
Restrict, restrict
|
||||
RValue, &&
|
||||
Static, static
|
||||
Thread_Local, thread_local
|
||||
|
|
@ -13,8 +13,8 @@ BraceCurly_Open, "{"
|
||||
BraceCurly_Close, "}"
|
||||
BraceSquare_Open, "["
|
||||
BraceSquare_Close, "]"
|
||||
Capture_Start, "("
|
||||
Capture_End, ")"
|
||||
Paren_Open, "("
|
||||
Paren_Close, ")"
|
||||
Comment, "__comment__"
|
||||
Comment_End, "__comment_end__"
|
||||
Comment_Start, "__comment_start__"
|
||||
@ -72,6 +72,7 @@ Spec_LocalPersist, "local_persist"
|
||||
Spec_Mutable, "mutable"
|
||||
Spec_NeverInline, "neverinline"
|
||||
Spec_Override, "override"
|
||||
Spec_Restrict, "restrict"
|
||||
Spec_Static, "static"
|
||||
Spec_ThreadLocal, "thread_local"
|
||||
Spec_Volatile, "volatile"
|
||||
|
|
@ -214,7 +214,18 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
||||
inline
|
||||
bool spec_is_trailing( Specifier specifier )
|
||||
{
|
||||
return specifier > Spec_Virtual;
|
||||
switch (specifier) {
|
||||
case Spec_Const:
|
||||
case Spec_Final:
|
||||
case Spec_NoExceptions:
|
||||
case Spec_Override:
|
||||
case Spec_Pure:
|
||||
case Spec_Volatile:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
)));
|
||||
|
||||
|
@ -53,6 +53,7 @@ StrBuilder <prefix>_to_strbuilder(Code code);
|
||||
|
||||
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_strbuilder_ptr` & `code_to_strbuilder`.
|
||||
Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ptr` & `code_to_strbuilder`.
|
||||
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.
|
||||
|
@ -25,13 +25,13 @@ These are containers representing a scope body of a definition that can be of th
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
StrCached Name;
|
||||
Code Front;
|
||||
Code Back;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
The `Front` member represents the start of the link list and `Back` the end.
|
||||
@ -56,13 +56,13 @@ Represent standard or vendor specific C/C++ attributes.
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -80,13 +80,13 @@ Stores a comment.
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -109,12 +109,12 @@ CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
CodeType ParentType;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeType Prev;
|
||||
CodeType Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
```
|
||||
@ -139,16 +139,16 @@ You'll notice that only one parent type is supported only with parent access. Th
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
Code InitializerList;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
Code InitializerList;
|
||||
CodeParams Params;
|
||||
Code Body;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -178,13 +178,14 @@ Represents a preprocessor define
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeDefineParams Params;
|
||||
Code Body;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -193,6 +194,28 @@ Serialization:
|
||||
#define <Name> <Content>
|
||||
```
|
||||
|
||||
## DefineParams
|
||||
|
||||
Preprocessor define's parameters.
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Name;
|
||||
Code Last;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Name>, <Next> ...
|
||||
```
|
||||
|
||||
## Destructor
|
||||
|
||||
Fields:
|
||||
@ -201,12 +224,12 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
Code Body;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -242,8 +265,8 @@ Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StrCached Name;
|
||||
CodeT Type;
|
||||
StrCached Name;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
@ -271,13 +294,13 @@ Will be obsolute when function body parsing is implemented.
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -286,18 +309,18 @@ Serialization:
|
||||
<Content>
|
||||
```
|
||||
|
||||
## External Linkage
|
||||
## External Linkage (Extern)
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -314,13 +337,13 @@ extern "<Name>"
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
Token* Tok;
|
||||
CodeT Type;
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
Token* Tok;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -336,14 +359,14 @@ This library (until its necessary become some third-party library to do otherwis
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code Declaration;
|
||||
CodeComment InlineCmt;
|
||||
Code Declaration;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -363,12 +386,12 @@ CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
@ -390,13 +413,13 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -410,14 +433,14 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -440,12 +463,12 @@ CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
OperatorT Op;
|
||||
```
|
||||
@ -472,12 +495,12 @@ CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -498,17 +521,17 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeType ValueType;
|
||||
Code Macro;
|
||||
Code Value;
|
||||
Code PostNameMacro;
|
||||
StrCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
CodeType ValueType;
|
||||
Code Macro;
|
||||
Code Value;
|
||||
Code PostNameMacro;
|
||||
StrCached Name;
|
||||
CodeParams Last;
|
||||
CodeParams Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -524,13 +547,13 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -544,13 +567,13 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
StrCached Content;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -566,12 +589,12 @@ Fields:
|
||||
```cpp
|
||||
SpecifierT ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
CodeSpecifiers NextSpecs;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
@ -586,15 +609,15 @@ Serialization:
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
CodeParams Params;
|
||||
Code Declaration;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -621,8 +644,8 @@ Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
StrCached Name;
|
||||
CodeT Type;
|
||||
StrCached Name;
|
||||
CodeType Type;
|
||||
b32 IsParamPack;
|
||||
ETypenameTag TypeTag;
|
||||
```
|
||||
@ -647,16 +670,16 @@ Those (macros) don't use the underlying type field as everything was serialized
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code UnderlyingType;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
CodeComment InlineCmt;
|
||||
Code UnderlyingType;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
@ -682,12 +705,12 @@ Fields:
|
||||
```cpp
|
||||
CodeAttributes Attributes;
|
||||
CodeBody Body;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
@ -708,12 +731,12 @@ Fields:
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
@ -740,13 +763,13 @@ CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
CodeVar NextVar;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
s32 VarParenthesizedInit;
|
||||
```
|
||||
|
1165
docs/Parser_Algo.md
1165
docs/Parser_Algo.md
File diff suppressed because it is too large
Load Diff
@ -6,9 +6,9 @@
|
||||
|
||||
# Parsing
|
||||
|
||||
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.
|
||||
The library features a naive single-pass parser, tailored for only what the library needs; for construction of C++ code into gencpp's 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 ~7000 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 10-15k loc worst case.
|
||||
|
||||
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.
|
||||
|
||||
@ -17,6 +17,7 @@ User exposed interface:
|
||||
```cpp
|
||||
CodeClass parse_class ( Str class_def );
|
||||
CodeConstructor parse_constructor ( Str constructor_def );
|
||||
CodeDefine parse_define ( Str define_def );
|
||||
CodeDestructor parse_destructor ( Str destructor_def );
|
||||
CodeEnum parse_enum ( Str enum_def );
|
||||
CodeBody parse_export_body ( Str export_def );
|
||||
@ -53,38 +54,98 @@ The keywords supported for the preprocessor are:
|
||||
* endif
|
||||
* pragma
|
||||
|
||||
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST.
|
||||
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST node.
|
||||
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 )
|
||||
***Again (Its not standard): These ASTs will be considered members or entries of braced scope they reside within***
|
||||
The preprocessor lines are stored as members of their associated scope they are parsed within ( Global, Namespace, Class/Struct ).
|
||||
***Again: These ASTs will be considered members or entries of braced scope they reside within***
|
||||
|
||||
Any preprocessor definition abuse that changes the syntax of the core language is unsupported and will fail to parse if not kept within an execution scope (function body, or expression assignment).
|
||||
Exceptions:
|
||||
|
||||
* function signatures are allowed for a preprocessed macro: `neverinline MACRO() { ... }`
|
||||
* varaible definitions are allowed for a preprocessed macro `extern MACRO();`
|
||||
* function definitions are allowed for a preprocessed macro: `neverinline MACRO() { ... }`
|
||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
|
||||
* typedefs allow for a preprocessed macro: `typedef MACRO();`
|
||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_TYPEDEF`
|
||||
* Macros can behave as typenames
|
||||
* There is some macro support in paramters for functions or templates *(Specifically added to support parsing Unreal Engine source)*.
|
||||
* There is some macro support in parameters for functions or templates *(Specifically added to support parsing Unreal Engine source)*.
|
||||
|
||||
*(Exceptions are added on an on-demand basis)*
|
||||
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
|
||||
|
||||
Adding your own exceptions is possible by simply modifying the parser to allow for the syntax you need.
|
||||
|
||||
*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 contains 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:
|
||||
Macros used within a file should be registered by the user before parsing. This can be done two ways:
|
||||
|
||||
* 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`.
|
||||
1. The register macro interface within [interface.hpp](../base/components/interface.hpp).
|
||||
2. Using `def_define` to create a CodeDefine and making sure to not set `opts.dont_register_to_preprocess_macros` to `true`.
|
||||
|
||||
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
## Registering macros
|
||||
|
||||
While the registeration of macros in the meta-program's side for parsing can be considered tedius, its necessary for the parser to accurately resolve the macros intent in one pass (and it provides some hygenics by verifying that they are used as intended).
|
||||
|
||||
The following can be used to register a macro:
|
||||
|
||||
```c
|
||||
GEN_API void register_macro( Macro macro );
|
||||
GEN_API void register_macros( s32 num, ... );
|
||||
GEN_API void register_macros_arr( s32 num, Macro* macros );
|
||||
```
|
||||
|
||||
The Macro typename is defined with the following in [parser_types.hpp](../base/components/parser_types.hpp):
|
||||
|
||||
```c
|
||||
struct Macro
|
||||
{
|
||||
StrCached Name;
|
||||
MacroType Type;
|
||||
MacroFlags Flags;
|
||||
};
|
||||
```
|
||||
|
||||
The macro can be designated one of the following types:
|
||||
|
||||
* `MT_Expression`: Intended to resolve to an expression expansion.
|
||||
* `MT_Statement`: Intended to resolve an statement expansion.
|
||||
* `MT_Typename`: Intended to resolve to a typename.
|
||||
|
||||
Additioonally tthe following flags may be set:
|
||||
|
||||
* `MF_Functional`: The macro intended to be passed arguments are at least have the calling `()` as part of its usage.
|
||||
* `MF_Expects_Body`: The parser should expect a braced-body `{ ... }` after the macro signature `<name> <params>`
|
||||
* `MF_Allow_As_Identifier`: Will allow the macro to be an acceptable token/s when an `Tok_Identifier` is expected.
|
||||
* `MF_Allow_As_Attribute`: Will allow the macro to be an acceptable token/s when an attribute token/s is expected.
|
||||
* `MF_Allow_As_Definition`: Will allow the macro be an acceptable token/s when the parser expects a declartion or definition to resolve after attributes or specifiers have been identified beforehand.
|
||||
* This flag requires that the macro is of type `MT_Statement` to make any sense of usage.
|
||||
|
||||
If a macro is not defined the following warning will be issued if `GEN_BUILD_DEBUG=1` during lexing within [lexer.cpp](../base/components/lexer.cpp) - `lex_preprocessor_define`:
|
||||
|
||||
```c
|
||||
log_fmt("Warning: '%S' was not registered before the lexer processed its #define directive, it will be registered as a expression macro\n"
|
||||
, name.Text
|
||||
);
|
||||
```
|
||||
|
||||
Further within the same scope, the lexer will issue a warning if it detects a macro was not flagged as function but has an open parenthesis `(` token right after is name with no whitespace:
|
||||
|
||||
```c
|
||||
log_fmt("Warning: %S registered macro is not flagged as functional yet the definition detects opening parenthesis '(' for arguments\n"
|
||||
, name.Text
|
||||
);
|
||||
```
|
||||
|
||||
Macros are tracked using a `MacroTable Macros;` defined as a member of the library's `Context`.
|
||||
|
||||
```c
|
||||
typedef HashTable(Macro) MacroTable;
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
* Empty lines used throughout the file are preserved for formatting purposes during ast serialization (they have a dedicated Token: `Tok_NewLine`).
|
||||
* 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. (There is a [todo](https://github.com/Ed94/gencpp/issues/49) to add support)
|
||||
* *This includes the assignment of variables.*
|
||||
@ -95,4 +156,4 @@ The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
* 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.
|
||||
**The lexer & parser do not gracefully attempt to continue when it comes across incorrect code, and doesn't properly track errors into a listing (yet).**
|
||||
|
110
docs/Readme.md
110
docs/Readme.md
@ -26,7 +26,7 @@ This means that the typename entry for the parameter AST would be either:
|
||||
***Concepts and Constraints are not supported***
|
||||
Its a [todo](https://github.com/Ed94/gencpp/issues/21)
|
||||
|
||||
### Feature Macros:
|
||||
### 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.
|
||||
@ -36,10 +36,41 @@ Its a [todo](https://github.com/Ed94/gencpp/issues/21)
|
||||
* `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
|
||||
* `GEN_C_LIKE_CPP` : 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 library's persistent state is managed tracked by a context struct: `global Context* _ctx;` defined within [static_data.cpp](../base/components/static_data.cpp)
|
||||
|
||||
https://github.com/Ed94/gencpp/blob/967a044637f1615c709cb723dc61118fcc08dcdb/base/components/interface.hpp#L39-L97
|
||||
|
||||
The interface for the context:
|
||||
|
||||
* `init`: Initializtion
|
||||
* `deinit`: De-initialization.
|
||||
* `reset`: Clears the allocations, but doesn't free the memoery, then calls `init()` on `_ctx` again.
|
||||
* `get_context`: Retreive the currently tracked context.
|
||||
* `set_context`: Swap out the current tracked context.
|
||||
|
||||
|
||||
#### Allocato usage
|
||||
|
||||
* `Allocator_DyanmicContainers`: Growing arrays, hash tables. (Unbounded sized containers)
|
||||
* `Allocator_Pool`: Fixed-sized object allocations (ASTs, etc)
|
||||
* `Allocator_StrCache`: StrCached allocations
|
||||
* `Allocator_Temp`: Temporary alloations mostly intended for StrBuilder usage. Manually cleared by the user by their own discretion.
|
||||
|
||||
The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
||||
|
||||
* Allocators are defined with the `AllocatorInfo` structure found in [`memory.hpp`](../base/dependencies/memory.hpp)
|
||||
* Most of the work is just defining the allocation procedure:
|
||||
|
||||
```cpp
|
||||
void* ( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
|
||||
```
|
||||
|
||||
For any allocator above that the user does not define before `init`, a fallback allocator will be assigned that utiizes the `fallback_allocator_proc` wtihin [interface.cpp](../base/components/interface.cpp).
|
||||
|
||||
As mentioned in root readme, the user is provided Code objects by calling the constructor's functions to generate them or find existing matches.
|
||||
|
||||
The AST is managed by the library and provided to the user via its interface.
|
||||
@ -47,14 +78,14 @@ However, the user may specifiy memory configuration.
|
||||
|
||||
[Data layout of AST struct (Subject to heavily change with upcoming todos)](../base/components/ast.hpp#L396-461)
|
||||
|
||||
https://github.com/Ed94/gencpp/blob/eea4ebf5c40d5d87baa465abfb1be30845b2377e/base/components/ast.hpp#L396-L461
|
||||
https://github.com/Ed94/gencpp/blob/967a044637f1615c709cb723dc61118fcc08dcdb/base/components/ast.hpp#L369-L435
|
||||
|
||||
*`StringCahced` is a typedef for `Str` (a string slice), to denote it is an interned string*
|
||||
*`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`*
|
||||
*`StrBuilder` is the dynamically allocated string type for the library*
|
||||
*`StrBuilder` is the dynamically allocating string builder type for the library*
|
||||
|
||||
AST widths are setup to be AST_POD_Size.
|
||||
AST widths are setup to be AST_POD_Size (128 bytes by default).
|
||||
The width dictates how much the static array can hold before it must give way to using an allocated array:
|
||||
|
||||
```cpp
|
||||
@ -73,41 +104,16 @@ int AST_ArrSpecs_Cap =
|
||||
)
|
||||
/ sizeof(Specifier) - 1;
|
||||
```
|
||||
|
||||
*Ex: If the AST_POD_Size is 128 the capacity of the static array is 20.*
|
||||
|
||||
Data Notes:
|
||||
|
||||
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
||||
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_strbuilder_allocator`, `cache_str`, `make_code`.
|
||||
* Allocators are defined with the `AllocatorInfo` structure found in [`memory.hpp`](../base/dependencies/memory.hpp)
|
||||
* Most of the work is just defining the allocation procedure:
|
||||
|
||||
```cpp
|
||||
void* ( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
|
||||
```
|
||||
|
||||
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
|
||||
* Code types have member symbols but their data layout is enforced to be POD types.
|
||||
* This library treats memory failures as fatal.
|
||||
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
|
||||
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
|
||||
* Strings used for serialization and file buffers are not contained by those used for cached strings.
|
||||
* They are currently using `FallbackAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
|
||||
* Memory within the buckets is not reused, so its inherently wasteful.
|
||||
* I will be augmenting the default allocator with virtual memory & a slab allocator in the [future](https://github.com/Ed94/gencpp/issues/12)
|
||||
* Intrusive linked lists used children nodes on bodies, and parameters.
|
||||
* `_ctx->Allocator_Temp` is used.
|
||||
* 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 (will be moved to runtime configuration in the future):
|
||||
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
|
||||
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
|
||||
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
|
||||
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
|
||||
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
||||
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
|
||||
* `TokenMap_FixedArena` : token_fmt_va uses local_persit memory of this arena type for the hashtable.
|
||||
* `GEN_LEX_ALLOCATOR_SIZE`
|
||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
||||
* Any modifcations to an existing AST should be to just construct another with the modifications done on-demand while traversing the AST (non-destructive).
|
||||
|
||||
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
|
||||
|
||||
@ -117,6 +123,7 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeClass
|
||||
* CodeConstructor
|
||||
* CodeDefine
|
||||
* CodeDefineParams
|
||||
* CodeDestructor
|
||||
* CodeEnum
|
||||
* CodeExec
|
||||
@ -127,7 +134,7 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeModule
|
||||
* CodeNS
|
||||
* CodeOperator
|
||||
* CodeOpCast
|
||||
* CodeOpCast : User defined member operator conversion
|
||||
* CodeParams : Has support for `for : range` iterating across parameters.
|
||||
* CodePreprocessCond
|
||||
* CodePragma
|
||||
@ -140,11 +147,15 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeUsing
|
||||
* CodeVar
|
||||
|
||||
Each Code boy has an associated "filtered AST" with the naming convention: `AST_<CodeName>`
|
||||
Each `struct Code<Name>` has an associated "filtered AST" with the naming convention: `AST_<CodeName>`
|
||||
Unrelated fields of the AST for that node type are omitted and only necessary padding members are defined otherwise.
|
||||
Retrieving a raw version of the ast can be done using the `raw()` function defined in each AST.
|
||||
|
||||
## There are three sets of interfaces for Code AST generation the library provides
|
||||
For the interface related to these code types see:
|
||||
|
||||
* [ast.hpp](../base/components/ast.hpp): Under the region pragma `Code C-Interface`
|
||||
* [code_types.hpp](../base/components/code_types.hpp): Under the region pragma `Code C-Interface`. Additional functionlity for c++ will be within the struct definitions or at the end of the file.
|
||||
|
||||
## There are three categories of interfaces for Code AST generation & reflection
|
||||
|
||||
* Upfront
|
||||
* Parsing
|
||||
@ -164,6 +175,7 @@ Interface :``
|
||||
* def_class
|
||||
* def_constructor
|
||||
* def_define
|
||||
* def_define_params
|
||||
* def_destructor
|
||||
* def_enum
|
||||
* def_execution
|
||||
@ -218,6 +230,27 @@ Code <name>
|
||||
|
||||
```
|
||||
|
||||
All optional parmeters are defined within `struct Opts_def_<functon name>`. This was done to setup a [macro trick](https://x.com/vkrajacic/status/1749816169736073295) for default optional parameers in the C library:
|
||||
|
||||
```cpp
|
||||
struct gen_Opts_def_struct
|
||||
{
|
||||
gen_CodeBody body;
|
||||
gen_CodeTypename parent;
|
||||
gen_AccessSpec parent_access;
|
||||
gen_CodeAttributes attributes;
|
||||
gen_CodeTypename* interfaces;
|
||||
gen_s32 num_interfaces;
|
||||
gen_ModuleFlag mflags;
|
||||
};
|
||||
typedef struct gen_Opts_def_struct gen_Opts_def_struct;
|
||||
|
||||
GEN_API gen_CodeClass gen_def__struct( gen_Str name, gen_Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
#define gen_def_struct( name, ... ) gen_def__struct( name, ( gen_Opts_def_struct ) { __VA_ARGS__ } )
|
||||
```
|
||||
|
||||
In the C++ library, the `def_<funtion name>` is not wrapped in a macro.
|
||||
|
||||
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
|
||||
|
||||
```cpp
|
||||
@ -228,7 +261,7 @@ def_global_body( 3, ht_entry, array_ht_entry, hashtable );
|
||||
```
|
||||
|
||||
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
|
||||
When the members have been populated use: `AST::validate_body` to verify that the members are valid entires for that type.
|
||||
When the members have been populated use: `code_validate_body` to verify that the members are valid entires for that type.
|
||||
|
||||
### Parse construction
|
||||
|
||||
@ -238,12 +271,12 @@ Interface :
|
||||
|
||||
* parse_class
|
||||
* parse_constructor
|
||||
* parse_define
|
||||
* parse_destructor
|
||||
* parse_enum
|
||||
* parse_export_body
|
||||
* parse_extern_link
|
||||
* parse_friend
|
||||
* Purposefully are only support forward declares with this constructor.
|
||||
* parse_function
|
||||
* parse_global_body
|
||||
* parse_namespace
|
||||
@ -322,6 +355,7 @@ Code <name> = parse_<function name>( gen_code_str );
|
||||
|
||||
The following are provided predefined by the library as they are commonly used:
|
||||
|
||||
* `enum_underlying_macro`
|
||||
* `access_public`
|
||||
* `access_protected`
|
||||
* `access_private`
|
||||
|
BIN
docs/assets/Code_-_Insiders_2024-12-15_22-52-13.gif
Normal file
BIN
docs/assets/Code_-_Insiders_2024-12-15_22-52-13.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 150 KiB |
BIN
docs/assets/Code_-_Insiders_2024-12-15_22-57-58.gif
Normal file
BIN
docs/assets/Code_-_Insiders_2024-12-15_22-57-58.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 250 KiB |
BIN
docs/assets/Code_-_Insiders_2024-12-15_23-04-07.gif
Normal file
BIN
docs/assets/Code_-_Insiders_2024-12-15_23-04-07.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 175 KiB |
@ -1,7 +1,5 @@
|
||||
## Navigation
|
||||
|
||||
# base
|
||||
|
||||
[Top](../Readme.md)
|
||||
|
||||
* [docs](../docs/Readme.md)
|
||||
@ -15,9 +13,133 @@ The output will be in the `gen_segmented/gen` directory (if the directory does n
|
||||
If using the library's provided build scripts:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> c_library
|
||||
.\build.ps1 <compiler> <debug or omit> c_lib
|
||||
```
|
||||
|
||||
To generate a static or dynamic library:
|
||||
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> c_lib_static c_lib_dyn
|
||||
```
|
||||
|
||||
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](./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.**
|
||||
|
||||
## Generation structure
|
||||
|
||||
1. Files are scanned in or parsed.
|
||||
* If they are parsed, its dude to requiring some changes to either naming, or adding additonal definitions (container generation, typedefs, etc).
|
||||
2. All scanned or parsed code is refactored (identifiers substs) and/or formatted.
|
||||
3. Singleheader generated.
|
||||
4. Segemented headers and source generated.
|
||||
|
||||
## Templated container generation
|
||||
|
||||
The array and hashtable containers used across this library are generated using the following implementatioon:
|
||||
|
||||
* [containers.array.hpp](./components/containers.array.hpp)
|
||||
* [containers.hashtable.hpp](./components/containers.hashtable.hpp)
|
||||
|
||||
These are functionally (and interface wise) equivalent to the library's `Array<Type>` `HashTable<Type>` within [containers.hpp](../base/dependencies/containers.hpp)
|
||||
|
||||
Both files follow the same patter of providing three procedures:
|
||||
|
||||
* `gen_<container>_base` : Intended to be called once, defines universal "base" definitions.
|
||||
* `gen_<container>` : Called per instatiation of the container for a given set of dependent args.
|
||||
* `gen_<container>_generic_selection_interface` : Intended to be called once after all of the instantiated containers have finished generating. It will generate a set of generic selection macros as described by Macro Usage section below.
|
||||
|
||||
A simple `<container>_DefinitionCounter` is used to know how many instantiations of the template have occured. This is used to determine how to define `GENERIC_SLOT_<ID>_<functionID>` for the generic interface along with how many slots the `_Generic` macro will need to have generated.
|
||||
|
||||
## Macro Usage
|
||||
|
||||
For the most part macros are kept minimal with exception to `_Generic`...
|
||||
*(I will be explaining this thing for the rest of this seciton along with gencpp c library's usage of it)*
|
||||
|
||||
The `_Generic` macro plays a key role in reducing direct need of the user to wrangle with mangled definition identifiers of 'templated' containers or for type coercion to map distinct data types to a common code path.
|
||||
|
||||
Because of its lack of use in many C11 libraries.. and, of those that do; they usually end up obfuscating it with excessive preprocessor abuse; Effort was put into minimizing how much of these macros are handled by the preprocessor vs gencpp itself.
|
||||
|
||||
The usual presentation (done bare) is the following:
|
||||
|
||||
```c
|
||||
#define macro_that_selects_typeof_arg(arg, y) \
|
||||
_Generic( (arg), \
|
||||
int : some expression, \
|
||||
double : some other expression, \
|
||||
struct Whatnot : something else again, \
|
||||
default : fallback expression \
|
||||
)
|
||||
```
|
||||
|
||||
Where `_Generic` can be considered the follwoing (psuedo-C):
|
||||
|
||||
```c
|
||||
#define type_expr_pair(type, expr) type: expr
|
||||
|
||||
C_Expression _Generic( selector_arg, a_type_expr_pair, ... ) {
|
||||
switch( typeof(selector_arg)) {
|
||||
case a_type_expr_pair:
|
||||
return a_type_expr_pari.expr;
|
||||
...
|
||||
default:
|
||||
return default.expr;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The first `arg` of _Generic behaves as the "controlling expression" or the expression that resolves to a type which will dictate which of the following expressions provided after to `_Generic` will be resolved as the one used inline for the implemenation.
|
||||
|
||||
|
||||
For this library's purposes we'll be using the functional macro equivalent *(if there is an exception I'll link it at the end of this section)*:
|
||||
|
||||
```c
|
||||
#define macro_that_uses_selector_arg_for_resolving_a_fucntion( selecting_exp) \
|
||||
_Generic( (arg), \
|
||||
int : func_use_int, \
|
||||
double : func_use_double, \
|
||||
struct Whatnot : func_use_Whatnot, \
|
||||
default : struct SIGNALS_FAILURE \
|
||||
) (selecting_exp)
|
||||
```
|
||||
|
||||
In this case, we directly added `(selecting_exp)` to the end there.. as we want to directly have the macro resolve to calling a resolved procedure. A default has been set to a struct as that leads to a neat compiler message that would otherwise be impossible beause static_assert is a statement and thus cannot be used within a slot.
|
||||
|
||||
Now, even with gencpp generating this type-expression table, we still need wrapper macros to achieve function 'overloading' for the templated containers as _Generic has a [significant drawback](https://www.chiark.greenend.org.uk/~sgtatham/quasiblog/c11-generic/):
|
||||
|
||||
> Discarded expressions still have to be semantically valid.
|
||||
|
||||
The only way to absolve this issue [(without resorting to nasty preprocessor hacks)](https://github.com/JacksonAllan/CC/blob/main/articles/Better_C_Generics_Part_1_The_Extendible_Generic.md) is with wrapping expressions in 'slot' resolving macros that do not expand if the slot is not defined:
|
||||
|
||||
```c
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_1__function_sig )
|
||||
```
|
||||
|
||||
`GENERIC_SLOT_1__function_sig` is our warpper of a "`int, func_use_int`" pair. The `GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT` is a verbse named macro to indicate that that pair will be expanded ***ONLY IF*** its defined.
|
||||
|
||||
So for any given templated container interface. Expect the follwoing (taken straight from generation, and just cleaned up formatting):
|
||||
|
||||
```c
|
||||
#define gen_array_append( selector_arg, ... ) _Generic( \
|
||||
(selector_arg ), \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_1__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_2__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_3__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_4__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_5__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_6__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_7__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_8__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_9__array_append ) \
|
||||
GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GEN_GENERIC_SLOT_10__array_append ) \
|
||||
default: gen_generic_selection_fail \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( &selector_arg, __VA_ARGS__ )
|
||||
|
||||
```
|
||||
|
||||
*Note(Ed): Unfortunately I cannot get clang-format to output these macros sanely like the above..*
|
||||
*Eventually I'll add some basic builtin formatting but if the user has suggestions for something better I'm open ears...*
|
||||
|
||||
`GEN_RESOLVED_FUNCTION_CALL` is an empty define, its just to indicate that its intended to expand to a function call.
|
||||
|
||||
To see the the actual macro definitions used - see: [generic_macros.h](./components/generic_macros.h). They'll be injected right after the usual macros in the generated header file.
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
@ -801,6 +800,9 @@ do \
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast, ast );
|
||||
if (found) break;
|
||||
|
||||
ast.append(entry);
|
||||
}
|
||||
break;
|
||||
@ -979,6 +981,9 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_code_types, code_types);
|
||||
if (found) break;
|
||||
|
||||
code_types.append(entry);
|
||||
}
|
||||
break;
|
||||
@ -1073,7 +1078,10 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast_types, ast_types );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast_types, ast_types);
|
||||
if (found) break;
|
||||
|
||||
ast_types.append(entry);
|
||||
@ -1121,11 +1129,18 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
CodeBody interface = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_interface.begin(); entry != parsed_interface.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_interface, interface );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("0"), entry, parsed_interface, interface);
|
||||
if (found) break;
|
||||
|
||||
interface.append(entry);
|
||||
}
|
||||
break;
|
||||
@ -1136,13 +1151,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
CodeFn fn = cast(CodeFn, entry);
|
||||
Code prev = entry->Prev;
|
||||
|
||||
if (prev && prev->Name.is_equal(entry->Name)) {
|
||||
// rename second definition so there isn't a symbol conflict
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", entry->Name);
|
||||
entry->Name = cache_str(postfix_arr.to_str());
|
||||
postfix_arr.free();
|
||||
}
|
||||
|
||||
b32 handled= false;
|
||||
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
{
|
||||
@ -1210,11 +1218,18 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
CodeBody inlines = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_inlines.begin(); entry != parsed_inlines.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_inlines, inlines );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("0"), entry, parsed_interface, interface);
|
||||
if (found) break;
|
||||
|
||||
inlines.append(entry);
|
||||
}
|
||||
break;
|
||||
@ -1368,15 +1383,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
CodeFn fn = cast(CodeFn, entry);
|
||||
Code prev = entry->Prev;
|
||||
for ( CodeParams arr_param : fn->Params )
|
||||
{
|
||||
b32 repeat_register_macros = fn->Name.is_equal(txt("register_macros")) && arr_param->Name.is_equal(txt("num")) && ! arr_param->Next->Name.is_equal(txt("..."));
|
||||
if ( repeat_register_macros ) {
|
||||
// rename second definition so there isn't a symbol conflict
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", fn->Name);
|
||||
fn->Name = cache_str(postfix_arr.to_str());
|
||||
}
|
||||
}
|
||||
src_interface.append(fn);
|
||||
}
|
||||
break;
|
||||
@ -1443,16 +1449,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
CodeFn fn = cast(CodeFn, entry);
|
||||
Code prev = entry->Prev;
|
||||
|
||||
for ( CodeParams arr_param : fn->Params )
|
||||
{
|
||||
b32 repeat_def_array = fn->Name.starts_with(txt("def_")) && arr_param->Name.is_equal(txt("num")) && ! arr_param->Next->Name.is_equal(txt("..."));
|
||||
if ( repeat_def_array ) {
|
||||
// rename second definition so there isn't a symbol conflict
|
||||
StrBuilder postfix_arr = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "%S_arr", fn->Name);
|
||||
fn->Name = cache_str(postfix_arr.to_str());
|
||||
}
|
||||
}
|
||||
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
{
|
||||
// The frontend names are warapped in macros so we need to give it the intenral symbol name
|
||||
|
@ -21,7 +21,7 @@ word global, gen_global
|
||||
word internal, gen_internal
|
||||
word local_persist, gen_local_persist
|
||||
word bit, gen_bit
|
||||
word bitfield_is_set, gen_bitfield_is_set
|
||||
word bitfield_is_set, gen_bitfield_is_set
|
||||
word cast, gen_cast
|
||||
word ccast, gen_ccast
|
||||
word pcast, gen_pcast
|
||||
@ -408,6 +408,8 @@ namespace var_, gen_var_
|
||||
|
||||
// Gen Interface
|
||||
|
||||
word _ctx, gen__ctx
|
||||
|
||||
word init, gen_init
|
||||
word deinit, gen_deinit
|
||||
word reset, gen_reset
|
||||
@ -418,6 +420,12 @@ word make_code, gen_make_code
|
||||
|
||||
namespace set_allocator_, gen_set_allocator_
|
||||
|
||||
word register_macro, gen_register_macro
|
||||
word register_macros, gen_register_macros
|
||||
word register_macros_arr, gen_register_macros_arr
|
||||
|
||||
namespace Opts_, gen_Opts_
|
||||
|
||||
namespace def_, gen_def_
|
||||
namespace parse_, gen_parse_
|
||||
namespace token_, gen_token_
|
||||
|
@ -238,10 +238,10 @@ CodeBody gen_array( Str type, Str array_name )
|
||||
GEN_ASSERT(begin <= end);
|
||||
ArrayHeader* header = array_get_header( self );
|
||||
|
||||
if ( begin < 0 || end >= header->Num )
|
||||
if ( begin < 0 || end > header->Num )
|
||||
return false;
|
||||
|
||||
for ( ssize idx = begin; idx < end; idx ++ )
|
||||
for ( ssize idx = (ssize)begin; idx < (ssize)end; idx ++ )
|
||||
self[ idx ] = value;
|
||||
|
||||
return true;
|
||||
|
@ -13,7 +13,7 @@
|
||||
| \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-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 |
|
||||
|
@ -28,10 +28,9 @@ b32 ignore_preprocess_cond_block( Str cond_sig, Code& entry_iter, CodeBody& pars
|
||||
//log_fmt("Preprocess cond found: %S\n", cond->Content);
|
||||
found = true;
|
||||
|
||||
s32 depth = 1;
|
||||
++ entry_iter;
|
||||
for(b32 continue_for = true; continue_for && entry_iter != parsed_body.end(); ) switch
|
||||
(entry_iter->Type) {
|
||||
s32 depth = 0;
|
||||
for(b32 continue_for = true; continue_for && entry_iter != parsed_body.end(); ) switch (entry_iter->Type)
|
||||
{
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
case CT_Preprocess_IfNotDef:
|
||||
@ -41,20 +40,18 @@ b32 ignore_preprocess_cond_block( Str cond_sig, Code& entry_iter, CodeBody& pars
|
||||
|
||||
case CT_Preprocess_Else:
|
||||
++ entry_iter;
|
||||
for(; continue_for && entry_iter != parsed_body.end(); ++ entry_iter)
|
||||
if (depth == 1) for(; entry_iter != parsed_body.end(); ++ entry_iter)
|
||||
{
|
||||
if (entry_iter->Type == CT_Preprocess_EndIf)
|
||||
{
|
||||
continue_for = false;
|
||||
if ( entry_iter->Type == CT_Preprocess_EndIf)
|
||||
break;
|
||||
}
|
||||
|
||||
body.append(entry_iter);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Preprocess_EndIf:
|
||||
{
|
||||
depth --;
|
||||
-- depth;
|
||||
if (depth == 0) {
|
||||
continue_for = false;
|
||||
break;
|
||||
|
@ -8,11 +8,13 @@
|
||||
|
||||
# Segemented Library Generation
|
||||
|
||||
Create a segemented library using `segemented.cpp`
|
||||
|
||||
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>`
|
||||
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`. The auxillary content (builder & scanner) is given their own files.
|
||||
|
||||
If using the library's provided build scripts:
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
#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"
|
||||
|
@ -15,7 +15,7 @@
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| Singleheader | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-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 |
|
||||
|
@ -1,6 +1,5 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
|
@ -15,3 +15,20 @@ If using the library's provided build scripts:
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> unreal
|
||||
```
|
||||
|
||||
## Notables
|
||||
|
||||
For the most part this follows the same conventions as `gen_segmented`.
|
||||
|
||||
This generator uses a separate enumeration definitions for the following:
|
||||
|
||||
* [AttributeTokens.csv](./enums/AttributeTokens.csv) : Add your own <MODULE>_API attributes, etc here that are encountered within the Engine.
|
||||
* [ESpecifier.csv](./enums/ESpecifier.csv) : Adds the `FORCEINLINE` & `FORCEINLINE_DEBUGGABLE` specfiers (additions are made as they are encountered)
|
||||
* [ETokType.csv](./enums/ETokType.csv) : Same modifications as ESpecifier.csv.
|
||||
|
||||
A separate [parser_case_macros.cpp](./components/parser_case_macros.cpp) is used to accomodate for the new forceinline specifiers.
|
||||
|
||||
The `global` macro the library uses is redefined as an empty substiution.
|
||||
|
||||
|
||||
The expected usage of this library is to put into into a third-party plugin module to then use either in editor modules or in shell script done in some stage of hot-reloading or building the Unreal Engine or Project.
|
||||
|
@ -16,7 +16,7 @@
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| Unreal Engine | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.20-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-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 |
|
||||
|
@ -1,6 +1,6 @@
|
||||
// These macros are used in the swtich cases within parser.cpp
|
||||
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_TOK_SPECIFIER_CASES \
|
||||
case Tok_Spec_Consteval: \
|
||||
case Tok_Spec_Constexpr: \
|
||||
case Tok_Spec_Constinit: \
|
||||
@ -14,7 +14,7 @@ case Tok_Spec_Static: \
|
||||
case Tok_Spec_Volatile: \
|
||||
case Tok_Spec_Virtual
|
||||
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_SPECIFIER_CASES \
|
||||
case Spec_Constexpr: \
|
||||
case Spec_Constinit: \
|
||||
case Spec_Explicit: \
|
||||
@ -54,12 +54,12 @@ case Spec_NeverInline: \
|
||||
case Spec_Static: \
|
||||
case Spec_Volatile
|
||||
|
||||
#define GEN_PARSER_FRIEND_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_FRIEND_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Inline: \
|
||||
case Spec_ForceInline
|
||||
|
||||
#define GEN_PARSER_FUNCTION_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_FUNCTION_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Consteval: \
|
||||
case Spec_Constexpr: \
|
||||
@ -71,7 +71,7 @@ case Spec_Inline: \
|
||||
case Spec_NeverInline: \
|
||||
case Spec_Static
|
||||
|
||||
#define GEN_PARSER_OPERATOR_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_OPERATOR_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Constexpr: \
|
||||
case Spec_ForceInline: \
|
||||
@ -79,7 +79,7 @@ case Spec_Inline: \
|
||||
case Spec_NeverInline: \
|
||||
case Spec_Static
|
||||
|
||||
#define GEN_PARSER_TEMPLATE_ALLOWED_SPECIFIERS_CASES \
|
||||
#define GEN_PARSER_TEMPLATE_ALLOWED_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Constexpr: \
|
||||
case Spec_Constinit: \
|
||||
@ -106,3 +106,9 @@ case Spec_Mutable: \
|
||||
case Spec_Static: \
|
||||
case Spec_Thread_Local: \
|
||||
case Spec_Volatile
|
||||
|
||||
#define GEN_PARSER_TYPENAME_ALLOWED_SUFFIX_SPECIFIER_CASES \
|
||||
case Spec_Const: \
|
||||
case Spec_Ptr: \
|
||||
case Spec_Ref: \
|
||||
case Spec_RValue
|
||||
|
@ -4,3 +4,4 @@ COREUOBJECT_API, COREUOBJECT_API
|
||||
ENGINE_API, ENGINE_API
|
||||
GAMEPLAYABILITIES_API, GAMEPLAYABILITIES_API
|
||||
UMG_API, UMG_API
|
||||
GASA_API, GASA_API
|
|
@ -13,8 +13,8 @@ BraceCurly_Open, "{"
|
||||
BraceCurly_Close, "}"
|
||||
BraceSquare_Open, "["
|
||||
BraceSquare_Close, "]"
|
||||
Capture_Start, "("
|
||||
Capture_End, ")"
|
||||
Paren_Open, "("
|
||||
Paren_Close, ")"
|
||||
Comment, "__comment__"
|
||||
Comment_End, "__comment_end__"
|
||||
Comment_Start, "__comment_start__"
|
||||
|
|
@ -1,6 +1,5 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
@ -100,7 +99,8 @@ int gen_main()
|
||||
(Macro { txt("GEN_PARAM_DEFAULT"), MT_Expression, MF_Null }),
|
||||
(Macro { txt("struct_init"), MT_Expression, MF_Functional }),
|
||||
(Macro { txt("GEN_OPTIMIZE_MAPPINGS_BEGIN"), MT_Statement, MF_Null }),
|
||||
(Macro { txt("GEN_OPITMIZE_MAPPINGS_END"), MT_Statement, MF_Null })
|
||||
(Macro { txt("GEN_OPITMIZE_MAPPINGS_END"), MT_Statement, MF_Null }),
|
||||
(Macro { txt("src_line_str"), MT_Expression, MF_Null })
|
||||
));
|
||||
|
||||
// gen_dep.hpp
|
||||
|
@ -15,11 +15,13 @@ Its main uage is the [c_library generation](../gen_c_library/).
|
||||
Remove any generated content from the repository.
|
||||
|
||||
**`build.ps1`**
|
||||
Build c_library, segmented, singleheader, unreal. Supports msvc or clang, release or debug.
|
||||
Build c library (segmented, singleheader, static, or dynamic), cpp library (segmented, singleheader, or unreal). Supports msvc or clang, release or debug.
|
||||
|
||||
```
|
||||
```erlang
|
||||
args:
|
||||
c_library
|
||||
c_lib : Build c11 library (singleheader & segmented)
|
||||
c_lib_static : Build static c11 library
|
||||
c_lib_dyn : Buidl dyanmic c11
|
||||
segemented
|
||||
singleheader
|
||||
unreal
|
||||
|
@ -325,18 +325,23 @@ if ( $unreal )
|
||||
. $refactor_unreal
|
||||
}
|
||||
|
||||
if ( $test )
|
||||
# C Library testing
|
||||
if ( $test -and $false )
|
||||
{
|
||||
$path_test_c_lib = join-path $path_test c_library
|
||||
$path_build = join-path $path_test_c_lib build
|
||||
|
||||
$path_test_c = join-path $path_test c_library
|
||||
$path_build = join-path $path_test_c build
|
||||
$path_gen = join-path $path_test_c gen
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$includes = @( $path_c_library )
|
||||
$unit = join-path $path_test_c_lib "gen.c"
|
||||
$executable = join-path $path_build "gen_c_library_test.exe"
|
||||
$path_singleheader_include = join-path $path_c_library gen
|
||||
$includes = @( $path_singleheader_include )
|
||||
$unit = join-path $path_test_c "test.c"
|
||||
$executable = join-path $path_build "test.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
@ -350,7 +355,7 @@ if ( $test )
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_test_c_lib
|
||||
Push-Location $path_test_c
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning c_library test"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
@ -362,6 +367,87 @@ if ( $test )
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if ( $test -and $true )
|
||||
{
|
||||
$path_test_c = join-path $path_test c_library
|
||||
$path_build = join-path $path_test_c build
|
||||
$path_gen = join-path $path_test_c gen
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$path_singleheader_include = join-path $path_c_library gen
|
||||
$includes = @( $path_singleheader_include )
|
||||
$unit = join-path $path_test_c "test_cuik.c"
|
||||
$executable = join-path $path_build "test_cuik.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
$compiler_args += $flag_all_c
|
||||
$compiler_args += $flag_updated_cpp_macro
|
||||
$compiler_args += $flag_c11
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_test_c
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning c_library test"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if ($test -and $false)
|
||||
{
|
||||
$path_test_cpp = join-path $path_test cpp_library
|
||||
$path_build = join-path $path_test_cpp build
|
||||
$path_gen = join-path $path_test_cpp gen
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$path_singleheader_include = join-path $path_singleheader gen
|
||||
$includes = @( $path_singleheader_include )
|
||||
$unit = join-path $path_test_cpp "test.cpp"
|
||||
$executable = join-path $path_build "test.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_test_cpp
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning cpp_library test"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
#endregion Building
|
||||
|
||||
Pop-Location # $path_root
|
||||
|
21
test/c_library/Cuik/LICENSE.txt
Normal file
21
test/c_library/Cuik/LICENSE.txt
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Yasser Arguelles Snape
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
454
test/c_library/Cuik/tb/opt/passes.h
Normal file
454
test/c_library/Cuik/tb/opt/passes.h
Normal file
@ -0,0 +1,454 @@
|
||||
#pragma once
|
||||
#include "../tb_internal.h"
|
||||
#include <arena_array.h>
|
||||
#include <limits.h>
|
||||
|
||||
enum {
|
||||
INT_WIDEN_LIMIT = 3,
|
||||
FAST_IDOM_LIMIT = 20
|
||||
};
|
||||
|
||||
#if TB_PACKED_USERS
|
||||
#define USERN(u) ((TB_Node*) ((u)->_n)) // node
|
||||
#define USERI(u) ((int) ((u)->_slot)) // index
|
||||
#else
|
||||
#define USERN(u) ((u)->_n) // node
|
||||
#define USERI(u) ((u)->_slot) // index
|
||||
#endif
|
||||
|
||||
#define FOR_USERS(u, n) for (TB_User *u = (n)->users, *_end_ = &u[(n)->user_count]; u != _end_; u++)
|
||||
|
||||
////////////////////////////////
|
||||
// Constant prop
|
||||
////////////////////////////////
|
||||
typedef struct {
|
||||
int64_t min, max;
|
||||
// for known bit analysis
|
||||
uint64_t known_zeros, known_ones;
|
||||
// we really don't wanna widen 18 quintillion times, it's never worth it
|
||||
uint64_t widen;
|
||||
} LatticeInt;
|
||||
|
||||
// Represents the fancier type system within the optimizer, it's
|
||||
// all backed by my shitty understanding of lattice theory
|
||||
struct Lattice {
|
||||
enum {
|
||||
LATTICE_BOT, // bot ^ x = bot
|
||||
LATTICE_TOP, // top ^ x = x
|
||||
|
||||
LATTICE_INT,
|
||||
LATTICE_TUPLE,
|
||||
|
||||
// float (each float type has it's own separate set of these btw):
|
||||
//
|
||||
// top
|
||||
// / \
|
||||
// / \
|
||||
// / \
|
||||
// / \
|
||||
// /|\ /|\
|
||||
// / | \ / | \
|
||||
// N N N 0.0 1.5 ... # fltcon
|
||||
// \ | / \ | /
|
||||
// \|/ \|/
|
||||
// nan ~nan
|
||||
// \ /
|
||||
// \ /
|
||||
// \ /
|
||||
// \ /
|
||||
// flt
|
||||
//
|
||||
// N means NaN it's just too long to write in the diagram
|
||||
LATTICE_FLT32, LATTICE_FLT64, // bottom types for floats
|
||||
LATTICE_NAN32, LATTICE_NAN64,
|
||||
LATTICE_XNAN32, LATTICE_XNAN64,
|
||||
LATTICE_FLTCON32, LATTICE_FLTCON64, // _f32 and _f64
|
||||
|
||||
// pointers:
|
||||
// anyptr
|
||||
// / \
|
||||
// / \
|
||||
// / /|\
|
||||
// | / | \
|
||||
// null a b ... # ptrcon
|
||||
// | \ | /
|
||||
// \ ~null
|
||||
// \ /
|
||||
// allptr
|
||||
LATTICE_ALLPTR,
|
||||
LATTICE_ANYPTR,
|
||||
LATTICE_NULL,
|
||||
LATTICE_XNULL,
|
||||
LATTICE_PTRCON,
|
||||
|
||||
// memory types
|
||||
LATTICE_MEMORY,
|
||||
|
||||
// control tokens:
|
||||
// top
|
||||
// |
|
||||
// dead
|
||||
// |
|
||||
// live
|
||||
// |
|
||||
// bot
|
||||
LATTICE_LIVE,
|
||||
LATTICE_DEAD,
|
||||
} tag;
|
||||
union {
|
||||
size_t _elem_count; // LATTICE_TUPLE
|
||||
LatticeInt _int; // LATTICE_INT
|
||||
TB_Symbol* _ptr; // LATTICE_PTRCON
|
||||
float _f32; // LATTICE_FLTCON32
|
||||
double _f64; // LATTICE_FLTCON64
|
||||
};
|
||||
union {
|
||||
Lattice* elems[0];
|
||||
};
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
// Cool properties
|
||||
////////////////////////////////
|
||||
uint32_t cfg_flags(TB_Node* n);
|
||||
bool cfg_is_region(TB_Node* n);
|
||||
bool cfg_is_natural_loop(TB_Node* n);
|
||||
bool cfg_is_branch(TB_Node* n);
|
||||
bool cfg_is_fork(TB_Node* n);
|
||||
bool cfg_is_terminator(TB_Node* n);
|
||||
bool cfg_is_endpoint(TB_Node* n);
|
||||
|
||||
bool tb_node_is_safepoint(TB_Node* n);
|
||||
bool tb_node_has_mem_out(TB_Node* n);
|
||||
TB_Node* tb_node_mem_in(TB_Node* n);
|
||||
|
||||
////////////////////////////////
|
||||
// CFG
|
||||
////////////////////////////////
|
||||
typedef struct {
|
||||
TB_Node *phi, *n;
|
||||
int dst, src;
|
||||
} PhiVal;
|
||||
|
||||
////////////////////////////////
|
||||
// Core optimizer
|
||||
////////////////////////////////
|
||||
typedef struct {
|
||||
TB_Module* mod;
|
||||
NL_HashSet visited;
|
||||
|
||||
size_t ws_cap;
|
||||
size_t ws_cnt;
|
||||
TB_Function** ws;
|
||||
} IPOSolver;
|
||||
|
||||
static bool cant_signed_overflow(TB_Node* n) {
|
||||
return TB_NODE_GET_EXTRA_T(n, TB_NodeBinopInt)->ab & TB_ARITHMATIC_NSW;
|
||||
}
|
||||
|
||||
static bool is_proj(TB_Node* n) {
|
||||
return n->type == TB_PROJ || n->type == TB_MACH_PROJ || n->type == TB_BRANCH_PROJ;
|
||||
}
|
||||
|
||||
static uint64_t tb__mask(uint64_t bits) {
|
||||
return ~UINT64_C(0) >> (64 - bits);
|
||||
}
|
||||
|
||||
static bool cfg_is_cproj(TB_Node* n) {
|
||||
return is_proj(n) && n->dt.type == TB_TAG_CONTROL;
|
||||
}
|
||||
|
||||
static bool cfg_is_mproj(TB_Node* n) {
|
||||
return n->type == TB_PROJ && n->dt.type == TB_TAG_MEMORY;
|
||||
}
|
||||
|
||||
// includes tuples which have control flow
|
||||
static bool cfg_is_control(TB_Node* n) {
|
||||
if (n->dt.type == TB_TAG_CONTROL) { return true; }
|
||||
if (n->dt.type == TB_TAG_TUPLE) {
|
||||
FOR_USERS(u, n) {
|
||||
if (cfg_is_cproj(USERN(u))) { return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cfg_is_bb_entry(TB_Node* n) {
|
||||
if (cfg_is_region(n)) {
|
||||
return true;
|
||||
} else if (cfg_is_cproj(n) && (n->inputs[0]->type == TB_ROOT || cfg_is_fork(n->inputs[0]))) {
|
||||
// Start's control proj or a branch target
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// returns a BranchProj's falsey proj, if it's an if-like TB_BRANCH
|
||||
static TB_NodeBranchProj* cfg_if_branch(TB_Node* n) {
|
||||
size_t succ_count = 0;
|
||||
if (n->type == TB_BRANCH || n->type == TB_AFFINE_LATCH) {
|
||||
TB_NodeBranch* br = TB_NODE_GET_EXTRA(n);
|
||||
succ_count = br->succ_count;
|
||||
} else if (cfg_is_branch(n)) {
|
||||
FOR_USERS(u, n) {
|
||||
if (USERN(u)->type == TB_BRANCH_PROJ) { succ_count++; }
|
||||
}
|
||||
} else {
|
||||
tb_todo();
|
||||
}
|
||||
|
||||
if (succ_count != 2) { return NULL; }
|
||||
FOR_USERS(u, n) {
|
||||
if (USERN(u)->type == TB_BRANCH_PROJ) {
|
||||
TB_NodeBranchProj* proj = TB_NODE_GET_EXTRA(USERN(u));
|
||||
if (proj->index == 1) { return proj; }
|
||||
}
|
||||
}
|
||||
|
||||
// shouldn't be reached wtf?
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool is_mem_out_op(TB_Node* n) {
|
||||
return n->dt.type == TB_TAG_MEMORY || (n->type >= TB_STORE && n->type <= TB_ATOMIC_CAS) || (n->type >= TB_CALL && n->type <= TB_TAILCALL) || n->type == TB_SPLITMEM || n->type == TB_MERGEMEM || n->type == TB_DEBUG_LOCATION;
|
||||
}
|
||||
|
||||
static bool is_mem_end_op(TB_Node* n) {
|
||||
return n->type == TB_RETURN || n->type == TB_TRAP || n->type == TB_UNREACHABLE;
|
||||
}
|
||||
|
||||
static bool is_mem_in_op(TB_Node* n) {
|
||||
return is_mem_out_op(n) || n->type == TB_SAFEPOINT || n->type == TB_LOAD;
|
||||
}
|
||||
|
||||
static bool is_mem_only_in_op(TB_Node* n) {
|
||||
return n->type == TB_SAFEPOINT || n->type == TB_LOAD;
|
||||
}
|
||||
|
||||
static bool single_use(TB_Node* n) {
|
||||
return n->user_count == 1;
|
||||
}
|
||||
|
||||
static TB_User* get_single_use(TB_Node* n) {
|
||||
return n->user_count == 1 ? &n->users[0] : NULL;
|
||||
}
|
||||
|
||||
static bool tb_node_is_pinned(TB_Node* n) {
|
||||
if ((n->type >= TB_ROOT && n->type <= TB_SAFEPOINT) || is_proj(n) || cfg_is_control(n)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return cfg_flags(n) & NODE_PINNED;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// CFG analysis
|
||||
////////////////////////////////
|
||||
// if we see a branch projection, it may either be a BB itself
|
||||
// or if it enters a REGION directly, then that region is the BB.
|
||||
static TB_Node* cfg_next_bb_after_cproj(TB_Node* proj) {
|
||||
return proj;
|
||||
}
|
||||
|
||||
static TB_User* proj_with_index(TB_Node* n, int i) {
|
||||
FOR_USERS(u, n) if (is_proj(USERN(u))) {
|
||||
TB_NodeProj* p = TB_NODE_GET_EXTRA(USERN(u));
|
||||
if (p->index == i) { return u; }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static TB_User* cfg_next_user(TB_Node* n) {
|
||||
FOR_USERS(u, n) {
|
||||
if (cfg_is_control(USERN(u))) { return u; }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool cfg_has_phis(TB_Node* n) {
|
||||
if (!cfg_is_region(n)) { return false; }
|
||||
FOR_USERS(u, n) {
|
||||
if (USERN(u)->type == TB_PHI) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool cfg_is_unreachable(TB_Node* n) {
|
||||
FOR_USERS(u, n) {
|
||||
if (USERN(u)->type == TB_UNREACHABLE) { return true; }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static TB_Node* cfg_next_control(TB_Node* n) {
|
||||
FOR_USERS(u, n) {
|
||||
if (cfg_is_control(USERN(u))) { return USERN(u); }
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static TB_Node* cfg_get_pred(TB_CFG* cfg, TB_Node* n, int i) {
|
||||
n = n->inputs[i];
|
||||
for (;;) {
|
||||
ptrdiff_t search = nl_map_get(cfg->node_to_block, n);
|
||||
if (search >= 0 || n->type == TB_DEAD || cfg_is_region(n)) {
|
||||
return n;
|
||||
}
|
||||
|
||||
n = n->inputs[0];
|
||||
}
|
||||
}
|
||||
|
||||
static TB_BasicBlock* cfg_get_pred_bb(TB_CFG* cfg, TB_Node* n, int i) {
|
||||
n = n->inputs[i];
|
||||
for (;;) {
|
||||
ptrdiff_t search = nl_map_get(cfg->node_to_block, n);
|
||||
if (search >= 0) {
|
||||
return cfg->node_to_block[search].v;
|
||||
} else if (n->type == TB_DEAD || cfg_is_region(n)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
n = n->inputs[0];
|
||||
}
|
||||
}
|
||||
|
||||
// shorthand because we use it a lot
|
||||
static TB_Node* idom(TB_CFG* cfg, TB_Node* n) {
|
||||
TB_ASSERT(cfg->node_to_block == NULL);
|
||||
ptrdiff_t search = nl_map_get(cfg->node_to_block, n);
|
||||
if (search < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TB_BasicBlock* dom = cfg->node_to_block[search].v->dom;
|
||||
return dom ? dom->start : NULL;
|
||||
}
|
||||
|
||||
static int dom_depth(TB_CFG* cfg, TB_Node* n) {
|
||||
return nl_map_get_checked(cfg->node_to_block, n)->dom_depth;
|
||||
}
|
||||
|
||||
static bool slow_dommy2(TB_BasicBlock* expected_dom, TB_BasicBlock* bb) {
|
||||
while (bb->dom_depth > expected_dom->dom_depth) {
|
||||
bb = bb->dom;
|
||||
}
|
||||
return bb == expected_dom;
|
||||
}
|
||||
|
||||
static bool slow_dommy(TB_CFG* cfg, TB_Node* expected_dom, TB_Node* bb) {
|
||||
TB_BasicBlock* a = nl_map_get_checked(cfg->node_to_block, expected_dom);
|
||||
TB_BasicBlock* b = nl_map_get_checked(cfg->node_to_block, bb);
|
||||
return slow_dommy2(a, b);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// Unordered SoN successor iterator
|
||||
////////////////////////////////
|
||||
#define FOR_SUCC(it, n) for (SuccIter it = succ_iter(n); succ_iter_next(&it);)
|
||||
|
||||
typedef struct {
|
||||
TB_Node* n;
|
||||
TB_Node* succ;
|
||||
int index; // -1 if we're not walking CProjs
|
||||
} SuccIter;
|
||||
|
||||
static SuccIter succ_iter(TB_Node* n) {
|
||||
if (n->dt.type == TB_TAG_TUPLE) {
|
||||
return (SuccIter){ n, NULL, 0 };
|
||||
} else if (!cfg_is_endpoint(n)) {
|
||||
return (SuccIter){ n, NULL, -1 };
|
||||
} else {
|
||||
return (SuccIter){ n, NULL, n->user_count };
|
||||
}
|
||||
}
|
||||
|
||||
static bool succ_iter_next(SuccIter* restrict it) {
|
||||
TB_Node* n = it->n;
|
||||
|
||||
// not branching? ok pick single next control
|
||||
if (it->index == -1) {
|
||||
it->index = n->user_count; // terminate
|
||||
it->succ = cfg_next_control(n);
|
||||
return true;
|
||||
}
|
||||
|
||||
// if we're in this loop, we know we're scanning for CProjs
|
||||
while (it->index < n->user_count) {
|
||||
TB_Node* un = USERN(&n->users[it->index++]);
|
||||
if (cfg_is_cproj(un)) {
|
||||
it->succ = un;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// lovely properties
|
||||
bool cfg_is_region(TB_Node* n);
|
||||
bool cfg_is_natural_loop(TB_Node* n);
|
||||
bool cfg_is_terminator(TB_Node* n);
|
||||
bool cfg_is_endpoint(TB_Node* n);
|
||||
|
||||
// internal debugging mostly
|
||||
void tb_print_dumb_node(Lattice** types, TB_Node* n);
|
||||
|
||||
// computes basic blocks but also dominators and loop nests if necessary.
|
||||
TB_CFG tb_compute_cfg(TB_Function* f, TB_Worklist* ws, TB_Arena* tmp_arena, bool dominators);
|
||||
void tb_free_cfg(TB_CFG* cfg);
|
||||
|
||||
// TB_Worklist API
|
||||
void worklist_alloc(TB_Worklist* restrict ws, size_t initial_cap);
|
||||
void worklist_free(TB_Worklist* restrict ws);
|
||||
void worklist_clear(TB_Worklist* restrict ws);
|
||||
void worklist_clear_visited(TB_Worklist* restrict ws);
|
||||
bool worklist_test(TB_Worklist* restrict ws, TB_Node* n);
|
||||
bool worklist_test_n_set(TB_Worklist* restrict ws, TB_Node* n);
|
||||
void worklist_push(TB_Worklist* restrict ws, TB_Node* restrict n);
|
||||
int worklist_count(TB_Worklist* ws);
|
||||
TB_Node* worklist_pop(TB_Worklist* ws);
|
||||
|
||||
void subsume_node(TB_Function* f, TB_Node* n, TB_Node* new_n);
|
||||
void subsume_node2(TB_Function* f, TB_Node* n, TB_Node* new_n);
|
||||
void subsume_node_without_phis(TB_Function* f, TB_Node* n, TB_Node* new_n);
|
||||
void tb__gvn_remove(TB_Function* f, TB_Node* n);
|
||||
|
||||
// Scheduler's cost model crap (talk about these in codegen_impl.h)
|
||||
typedef int (*TB_GetLatency)(TB_Function* f, TB_Node* n, TB_Node* end);
|
||||
typedef uint64_t (*TB_GetUnitMask)(TB_Function* f, TB_Node* n);
|
||||
|
||||
// Local scheduler
|
||||
void tb_list_scheduler(TB_Function* f, TB_CFG* cfg, TB_Worklist* ws, DynArray(PhiVal*) phi_vals, TB_BasicBlock* bb, TB_GetLatency get_lat, TB_GetUnitMask get_unit_mask, int unit_count);
|
||||
void tb_greedy_scheduler(TB_Function* f, TB_CFG* cfg, TB_Worklist* ws, DynArray(PhiVal*) phi_vals, TB_BasicBlock* bb);
|
||||
void tb_dataflow(TB_Function* f, TB_Arena* arena, TB_CFG cfg);
|
||||
|
||||
// Global scheduler
|
||||
void tb_clear_anti_deps(TB_Function* f, TB_Worklist* ws);
|
||||
void tb_renumber_nodes(TB_Function* f, TB_Worklist* ws);
|
||||
void tb_compact_nodes(TB_Function* f, TB_Worklist* ws);
|
||||
void tb_global_schedule(TB_Function* f, TB_Worklist* ws, TB_CFG cfg, bool early_only, bool dataflow, TB_GetLatency get_lat);
|
||||
void tb_compute_synthetic_loop_freq(TB_Function* f, TB_CFG* cfg);
|
||||
|
||||
// BB placement
|
||||
int bb_placement_rpo(TB_Arena* arena, TB_CFG* cfg, int* dst_order);
|
||||
int bb_placement_trace(TB_Arena* arena, TB_CFG* cfg, int* dst_order);
|
||||
|
||||
// makes arch-friendly IR
|
||||
void tb_opt_legalize(TB_Function* f, TB_Arch arch);
|
||||
int tb_opt_peeps(TB_Function* f);
|
||||
int tb_opt_locals(TB_Function* f);
|
||||
|
||||
// Integrated IR debugger
|
||||
void tb_integrated_dbg(TB_Function* f, TB_Node* n);
|
||||
|
||||
Lattice* latuni_get(TB_Function* f, TB_Node* n);
|
||||
|
||||
void tb__print_regmask(RegMask* mask);
|
||||
|
@ -1,9 +0,0 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#include "gen/gen_singleheader.h"
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
// init();
|
||||
__debugbreak();
|
||||
return 0;
|
||||
}
|
32
test/c_library/test.c
Normal file
32
test/c_library/test.c
Normal file
@ -0,0 +1,32 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#include "gen_singleheader.h"
|
||||
|
||||
#define gen_iterator( Type, container, iter ) \
|
||||
gen_begin_ ## Type(container); \
|
||||
iter != gen_end_ ## Type(container); \
|
||||
code = gen_next_ ## Type(container, iter)
|
||||
|
||||
int main()
|
||||
{
|
||||
gen_Context ctx = {0};
|
||||
gen_init(& ctx);
|
||||
|
||||
gen_Builder src_hello = gen_builder_open("gen/hello.c");
|
||||
gen_CodeVar hello_var = gen_parse_variable(code(
|
||||
char const* hello_gencpp_str = "HELLO GENCPP C11 !";
|
||||
));
|
||||
gen_builder_print( & src_hello, (gen_Code)hello_var );
|
||||
gen_builder_write(& src_hello);
|
||||
|
||||
gen_CodeBody body = gen_parse_file("gen/hello.c");
|
||||
for (gen_Code code = gen_iterator(CodeBody, body, code)) switch (code->Type) {
|
||||
case CT_Variable:
|
||||
gen_CodeVar var = (gen_CodeVar) code;
|
||||
gen_log_fmt("%S", var->Value);
|
||||
break;
|
||||
}
|
||||
|
||||
gen_deinit(& ctx);
|
||||
return 0;
|
||||
}
|
48
test/c_library/test_cuik.c
Normal file
48
test/c_library/test_cuik.c
Normal file
@ -0,0 +1,48 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#include "gen_singleheader.h"
|
||||
|
||||
#define gen_iterator( Type, container, iter ) \
|
||||
gen_begin_ ## Type(container); \
|
||||
iter != gen_end_ ## Type(container); \
|
||||
code = gen_next_ ## Type(container, iter)
|
||||
|
||||
int main()
|
||||
{
|
||||
gen_Context ctx = {0};
|
||||
gen_init(& ctx);
|
||||
|
||||
gen_register_macros( args(
|
||||
((gen_Macro){ txt("USERN"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro){ txt("USERI"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro){ txt("USERI"), MT_Expression, MF_Functional }),
|
||||
((gen_Macro){ txt("FOR_USERS"), MT_Statement, MF_Functional }),
|
||||
((gen_Macro){ txt("FOR_SUCC"), MT_Statement, MF_Functional })
|
||||
));
|
||||
|
||||
gen_CodeBody h_passes = gen_parse_file("Cuik/tb/opt/passes.h");
|
||||
for (gen_Code code = gen_iterator(CodeBody, h_passes, code)) switch (code->Type) {
|
||||
case CT_Function_Fwd:
|
||||
case CT_Function:
|
||||
gen_log_fmt("%S:\t%S RETURN_TYPE: %S PARAMS:%S\n"
|
||||
, gen_codetype_to_str(code->Type)
|
||||
, code->Name
|
||||
, gen_strbuilder_to_str( gen_typename_to_strbuilder((gen_CodeTypename) code->ReturnType))
|
||||
, gen_strbuilder_to_str( gen_params_to_strbuilder( (gen_CodeParams) code->Params))
|
||||
);
|
||||
break;
|
||||
|
||||
case CT_Variable:
|
||||
gen_log_fmt("%S:\t%S Type:%S\n", gen_codetype_to_str(code->Type), code->Name, code->ValueType);
|
||||
break;
|
||||
|
||||
case CT_Struct_Fwd:
|
||||
case CT_Struct:
|
||||
case CT_Typedef:
|
||||
gen_log_fmt("%S: %S\n", gen_codetype_to_str(code->Type), code->Name);
|
||||
break;
|
||||
}
|
||||
|
||||
gen_deinit(& ctx);
|
||||
return 0;
|
||||
}
|
29
test/cpp_library/test.cpp
Normal file
29
test/cpp_library/test.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#include "gen.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace gen;
|
||||
Context ctx = {};
|
||||
gen::init( & ctx);
|
||||
|
||||
Builder src_hello = builder_open("gen/hello.cpp");
|
||||
CodeVar hello_var = parse_variable( code(
|
||||
constexpr char const* hello_gencpp_str = "HELLO GENCPP !";
|
||||
));
|
||||
src_hello.print(hello_var);
|
||||
src_hello.write();
|
||||
|
||||
CodeBody body = parse_file("gen/hello.cpp");
|
||||
for ( Code code : body ) switch (code->Type) {
|
||||
case CT_Variable:
|
||||
CodeVar var = cast(CodeVar, code);
|
||||
log_fmt("%S", var->Value);
|
||||
break;
|
||||
}
|
||||
|
||||
gen::deinit(& ctx);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user