mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Compare commits
103 Commits
v0.5-alpha
...
v0.12-Alph
Author | SHA1 | Date | |
---|---|---|---|
729c891cbd | |||
754bcfb31e | |||
a8708abf8b | |||
4b48b96a79 | |||
9495fc2985 | |||
378de73a7d | |||
35ac0c1048 | |||
2c893d5e35 | |||
6ea40094ee | |||
0a8d3bfc6a | |||
212b4e6d16 | |||
d606c790ca | |||
2bfbef1d0c | |||
f1fb75cc1c | |||
2200bcde9a | |||
3e249d9bc5 | |||
3868e1e811 | |||
543427dfe5 | |||
f2d4ec96f0 | |||
1076818250 | |||
c4c308c8ba | |||
a4d9a63d71 | |||
0197afd543 | |||
7249a7317d | |||
abf51e4aa9 | |||
9b6dc3cbd8 | |||
9edcbad907 | |||
a6766cf0b1 | |||
8635b0fd1b | |||
30eec99628 | |||
f9117a2353 | |||
c81f4b34ee | |||
c97762ac16 | |||
5e79e8ba65 | |||
49a2cd7b2c | |||
a6c6574390 | |||
c4846dad26 | |||
a61a28b778 | |||
d0c995893d | |||
a42e241afb | |||
6d85dd8fe8 | |||
db6e8b33eb | |||
7be3617083 | |||
5c47777972 | |||
4a2ed6de4e | |||
9f64760b7a | |||
68f34e6fab | |||
1f9bbddbb7 | |||
050b00f28a | |||
1241f44fd4 | |||
7d1c499e7b | |||
b3f0c2734f | |||
eaeb8acee4 | |||
12bf878cb3 | |||
52ae431ad6 | |||
05fa62eced | |||
2f7836b191 | |||
f574a9ba9a | |||
a6bf60a51e | |||
37d9782cf2 | |||
11679ba8b4 | |||
8985f0a4d9 | |||
32a910515e | |||
aa928ff446 | |||
5aff89262b | |||
b5fa864318 | |||
bb35444be9 | |||
67d02c1f62 | |||
c7647ab00f | |||
d2fc1d0a56 | |||
ed3246c6b0 | |||
c4d5637a64 | |||
c2f8c8aeb1 | |||
c2319b9651 | |||
a4f9596d3b | |||
97750388ad | |||
00f6c45f15 | |||
34f286d218 | |||
d36c3fa847 | |||
5d7dfaf666 | |||
114f678f1b | |||
a8a9b681f0 | |||
b96b0821c1 | |||
4c8a0f0005 | |||
684569750d | |||
0f16d1131e | |||
528ef72a51 | |||
21a8f3bb39 | |||
2b63fc27cd | |||
bfbfae466f | |||
3d7cb85e71 | |||
03df940085 | |||
b9064fba9d | |||
4e8d6456cb | |||
d704f11c81 | |||
50a10c901f | |||
0a5885495f | |||
f09bb99fdf | |||
108b16739f | |||
689646c393 | |||
c5afede7b5 | |||
31e1c38c18 | |||
3f0b7e7fc6 |
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,13 +1,17 @@
|
||||
.idea
|
||||
|
||||
build/*
|
||||
**/build/*
|
||||
.vs
|
||||
|
||||
**/*.gen.*
|
||||
**/gen/gen.hpp
|
||||
**/gen/gen.cpp
|
||||
**/gen/gen_dep.hpp
|
||||
**/gen/gen_dep.cpp
|
||||
**/gen/gen.dep.hpp
|
||||
**/gen/gen.dep.cpp
|
||||
**/gen/gen.builder.hpp
|
||||
**/gen/gen.builder.cpp
|
||||
**/gen/gen.scanner.hpp
|
||||
**/gen/gen.scanner.cpp
|
||||
|
||||
gencpp.hpp
|
||||
gencpp.cpp
|
||||
@ -26,4 +30,11 @@ bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
[Ll]ogs/
|
||||
vc140.pdb
|
||||
|
||||
|
||||
# Unreal
|
||||
**/Unreal/*.h
|
||||
**/Unreal/*.cpp
|
||||
! **/Unreal/validate.unreal.cpp
|
||||
|
27
.vscode/c_cpp_properties.json
vendored
27
.vscode/c_cpp_properties.json
vendored
@ -1,7 +1,7 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"name": "Win32 msvc",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
@ -9,11 +9,34 @@
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME"
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 clang",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
|
||||
"intelliSenseMode": "windows-clang-x64",
|
||||
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -8,9 +8,9 @@
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"name": "Debug gentime lldb",
|
||||
"program": "${workspaceFolder}/test/gen/build/gencpp.exe",
|
||||
"program": "${workspaceFolder}/test/test.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/test/gen/",
|
||||
"cwd": "${workspaceFolder}/test/",
|
||||
"postRunCommands": [
|
||||
]
|
||||
},
|
||||
@ -18,16 +18,16 @@
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug gentime vsdbg",
|
||||
"program": "${workspaceFolder}/test/gen/build/gencpp.exe",
|
||||
"program": "${workspaceFolder}/test/build/test.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/test/gen/",
|
||||
"cwd": "${workspaceFolder}/test/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug bootstrap vsdbg",
|
||||
"program": "${workspaceFolder}/project/build/gencpp_bootstrap.exe",
|
||||
"program": "${workspaceFolder}/project/build/bootstrap.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/project/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
|
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@ -18,7 +18,17 @@
|
||||
"algorithm": "cpp",
|
||||
"limits": "cpp",
|
||||
"concepts": "cpp",
|
||||
"*.rh": "cpp"
|
||||
"*.rh": "cpp",
|
||||
"chrono": "cpp",
|
||||
"string": "cpp",
|
||||
"filesystem": "cpp",
|
||||
"format": "cpp",
|
||||
"ratio": "cpp",
|
||||
"xstring": "cpp",
|
||||
"functional": "cpp",
|
||||
"vector": "cpp",
|
||||
"list": "cpp",
|
||||
"xhash": "cpp"
|
||||
},
|
||||
"C_Cpp.intelliSenseEngineFallback": "disabled",
|
||||
"mesonbuild.configureOnOpen": true,
|
||||
|
647
Readme.md
647
Readme.md
@ -5,64 +5,21 @@ An attempt at simple staged metaprogramming for c/c++.
|
||||
The library API is a composition of code element constructors.
|
||||
These build up a code AST to then serialize with a file builder.
|
||||
|
||||
General goal is to have a less than 15k sloc library that takes at most a couple of hours to learn and make use of.
|
||||
|
||||
*Why 15k ?* Assuming a seasoned coder of C++ can read and understand around 1000-2000 lines of code per hour, 15,000 could be understood in under 16-18 hours
|
||||
and have confidence in modifying for their use case.
|
||||
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto),
|
||||
its not meant to be a black box metaprogramming utility, its meant for the user to extend for their project domain.
|
||||
|
||||
### TOC
|
||||
|
||||
* [Notes](#notes)
|
||||
* [Usage](#usage)
|
||||
* [Building](#notes)
|
||||
* [Outline](#outline)
|
||||
* [What is not provided](#what-is-not-provided)
|
||||
* [The three constructors ](#there-are-three-sets-of-interfaces-for-code-ast-generation-the-library-provides)
|
||||
* [Predefined Codes](#predefined-codes)
|
||||
* [Code generation and modification](#code-generation-and-modification)
|
||||
* [On multithreading](#on-multi-threading)
|
||||
* [Extending the library](#extending-the-library)
|
||||
* [TODO](#todo)
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
|
||||
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
|
||||
|
||||
## Notes
|
||||
|
||||
The project has reached an *alpha* state, all the current functionality works for the test cases but it will most likely break in many other cases.
|
||||
This project is still in development (very much an alpha state), so expect bugs and missing features.
|
||||
See [issues](https://github.com/Ed94/gencpp/issues) for a list of known bugs or todos.
|
||||
|
||||
The project has no external dependencies beyond:
|
||||
The library can already be used to generate code just fine, but the parser is where the most work is needed. If your C++ isn't "down to earth" expect issues.
|
||||
|
||||
* `errno.h` (gen.dep.cpp)
|
||||
* `stat.h` (gen.dep.cpp)
|
||||
* `stdarg.h` (gen.dep.hpp)
|
||||
* `stddef.h` (gen.dep.hpp
|
||||
* `stdio.h` (gen.dep.cpp)
|
||||
* `copyfile.h` (Mac, gen.dep.cpp)
|
||||
* `types.h` (Linux, gen.dep.cpp)
|
||||
* `unistd.h` (Linux/Mac, gen.dep.cpp)
|
||||
* `intrin.h` (Windows, gen.dep.hpp)
|
||||
* `io.h` (Windows with gcc, gen.dep.cpp)
|
||||
* `windows.h` (Windows, gen.dep.cpp)
|
||||
|
||||
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
|
||||
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
|
||||
|
||||
This library was written a subset of C++ where the following are not used at all:
|
||||
|
||||
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
|
||||
* Language provide dynamic dispatch, RTTI
|
||||
* Object-Oriented Inheritance
|
||||
* Exceptions
|
||||
|
||||
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
|
||||
There are only 4 template definitions in the entire library. (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `AST/Code::cast<Type>`)
|
||||
|
||||
A `natvis` and `natstepfilter` are provided in the scripts directory.
|
||||
A `natvis` and `natstepfilter` are provided in the scripts directory (its outdated, I'll update this readme when its not).
|
||||
|
||||
***The editor and scanner have not been implemented yet. The scanner will come first, then the editor.***
|
||||
|
||||
A C variant is hosted [here](https://github.com/Ed94/genc); I haven't gotten headwind on it, should be easier to make than this...
|
||||
A C variant is hosted [here](https://github.com/Ed94/genc); I will complete it when this library is feature complete, it should be easier to make than this...
|
||||
|
||||
## Usage
|
||||
|
||||
@ -70,7 +27,7 @@ A metaprogram is built to generate files before the main program is built. We'll
|
||||
|
||||
`gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated.
|
||||
|
||||
In order to keep the locality of this code within the same files the following pattern may be used:
|
||||
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't required at all):
|
||||
|
||||
Within `program.cpp` :
|
||||
|
||||
@ -86,6 +43,8 @@ u32 gen_main()
|
||||
}
|
||||
#endif
|
||||
|
||||
// "Stage" agnostic code.
|
||||
|
||||
#ifndef GEN_TIME
|
||||
#include "program.gen.cpp"
|
||||
|
||||
@ -95,12 +54,13 @@ u32 gen_main()
|
||||
```
|
||||
|
||||
The design uses a constructive builder API for the code to generate.
|
||||
The user is given `Code` objects that are used to build up the AST.
|
||||
The user is provided `Code` objects that are used to build up the AST.
|
||||
|
||||
Example using each construction interface:
|
||||
|
||||
### Upfront
|
||||
|
||||
Validation and construction through a functional interface.
|
||||
|
||||
```cpp
|
||||
Code t_uw = def_type( name(uw) );
|
||||
@ -120,6 +80,8 @@ Code header;
|
||||
|
||||
### Parse
|
||||
|
||||
Validation through ast construction.
|
||||
|
||||
```cpp
|
||||
Code header = parse_struct( code(
|
||||
struct ArrayHeader
|
||||
@ -134,6 +96,8 @@ Code header = parse_struct( code(
|
||||
|
||||
### Untyped
|
||||
|
||||
No validation, just glorified text injection.
|
||||
|
||||
```cpp
|
||||
Code header = code_str(
|
||||
struct ArrayHeader
|
||||
@ -162,583 +126,8 @@ struct ArrayHeader
|
||||
```
|
||||
|
||||
**Note: The formatting shown here is not how it will look. For your desired formatting its recommended to run a pass through the files with an auto-formatter.**
|
||||
*(The library currently uses clang-format for formatting, beware its pretty slow...)*
|
||||
|
||||
## Building
|
||||
|
||||
An example of building is provided within project, singleheader, and test.
|
||||
|
||||
(All generated files go to a corresponding `*/gen` directory)
|
||||
|
||||
**Project**
|
||||
|
||||
`gen.bootstrap.cpp` generates a segmented version of the library where code is divided into `gen.hpp`, `gen.cpp`, `gen_dep.hpp`, and `gen_dep.cpp`.
|
||||
(Similar whats there already, but with the includes injected)
|
||||
|
||||
**Singleheader**
|
||||
|
||||
`gen.singleheader.cpp` generates a single-header version of the library following the convention shown in popular libraries such as: gb, stb, and zpl.
|
||||
|
||||
**Test**
|
||||
|
||||
There are two meson build files the one within test is the program's build specification.
|
||||
The other one in the gen directory within test is the metaprogram's build specification.
|
||||
|
||||
Both of them build the same source file: `test.cpp`. The only differences are that gen needs a different relative path to the include directories and defines the macro definition: `GEN_TIME`.
|
||||
|
||||
This method is setup where all the metaprogram's code are the within the same files as the regular program's code.
|
||||
|
||||
## Outline
|
||||
|
||||
### *WHAT IS NOT PROVIDED*
|
||||
|
||||
* Exceptions
|
||||
* Execution statement validation : Execution expressions are defined using the untyped API.
|
||||
* Lambdas (This naturally means its unsupported)
|
||||
* RAII : This needs support for constructors/destructor parsing
|
||||
* Haven't gotten around to yet, only useful (to me) for third-party scanning
|
||||
|
||||
Keywords kept from "Modern C++":
|
||||
|
||||
* constexpr : Great to store compile-time constants.
|
||||
* consteval : Technically fine, need to make sure to execute in moderation.
|
||||
* constinit : Better than constexpr at doing its job, however, its only c++ 20.
|
||||
* export : Useful if c++ modules ever come around to actually being usable.
|
||||
* import : ^^
|
||||
* module : ^^
|
||||
|
||||
When it comes to expressions:
|
||||
|
||||
**There is no support for validating expressions.**
|
||||
Its difficult to parse without enough benefits (At the metaprogramming level).
|
||||
|
||||
When it comes to templates:
|
||||
|
||||
Only trivial template support is provided. the intention is for only simple, non-recursive substitution.
|
||||
The parameters of the template are treated like regular parameter AST entries.
|
||||
This means that the typename entry for the parameter AST would be either:
|
||||
|
||||
* `class`
|
||||
* `typename`
|
||||
* A fundamental type, function, or pointer type.
|
||||
|
||||
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
|
||||
Use at your own mental peril.
|
||||
|
||||
*Concepts and Constraints are not supported, its usage is non-trivial substitution.*
|
||||
|
||||
### The Data & Interface
|
||||
|
||||
As mentioned in [Usage](#usage), 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 the user via its interface.
|
||||
However, the user may specifiy memory configuration.
|
||||
|
||||
Data layout of AST struct:
|
||||
|
||||
```cpp
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
AST* Params; // Function, Operator, Template
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front; // Used by CodeBody
|
||||
AST* Last; // Used by CodeParam
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back; // Used by CodeBody
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
```
|
||||
|
||||
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
|
||||
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
|
||||
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
|
||||
*`String` is the dynamically allocated string type for the library*
|
||||
|
||||
AST widths are setup to be AST_POD_Size.
|
||||
The width dictates how much the static array can hold before it must give way to using an allocated array:
|
||||
|
||||
```cpp
|
||||
constexpr static
|
||||
uw ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(s32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
|
||||
```
|
||||
|
||||
*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`, `gen_string_allocator`, `get_cached_string`, `make_code`.
|
||||
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
|
||||
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
||||
* This library treats memory failures as fatal.
|
||||
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
|
||||
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
|
||||
* Strings used for serialization and file buffers are not contained by those used for cached strings.
|
||||
* They are currently using `GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
|
||||
* Memory within the buckets is not reused, so its inherently wasteful.
|
||||
* I will be augmenting the single arena with a simple slag allocator.
|
||||
* Linked lists used children nodes on bodies, and parameters.
|
||||
* 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:
|
||||
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
|
||||
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
|
||||
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
|
||||
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
|
||||
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
||||
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
|
||||
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
|
||||
* `GEN_LEX_ALLOCATOR_SIZE`
|
||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
||||
|
||||
Two generic templated containers are used throughout the library:
|
||||
|
||||
* `template< class Type> struct Array`
|
||||
* `template< class Type> struct HashTable`
|
||||
|
||||
Both Code and AST definitions have a `template< class Type> Code/AST cast()`. Its just an alternative way to explicitly cast to each other.
|
||||
|
||||
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
|
||||
|
||||
Otherwise the library is free of any templates.
|
||||
|
||||
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
|
||||
|
||||
* CodeBody : Has support for `for-range` iterating across Code objects.
|
||||
* CodeAttributes
|
||||
* CodeComment
|
||||
* CodeClass
|
||||
* CodeEnum
|
||||
* CodeExec
|
||||
* CodeExtern
|
||||
* CodeInclude
|
||||
* CodeFriend
|
||||
* CodeFn
|
||||
* CodeModule
|
||||
* CodeNamespace
|
||||
* CodeOperator
|
||||
* CodeOpCast
|
||||
* CodeParam : Has support for `for-range` iterating across parameters.
|
||||
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
|
||||
* CodeStruct
|
||||
* CodeTemplate
|
||||
* CodeType
|
||||
* CodeTypedef
|
||||
* CodeUnion
|
||||
* CodeUsing
|
||||
* CodeUsingNamespace
|
||||
* CodeVar
|
||||
|
||||
Each Code boy 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
|
||||
|
||||
* Upfront
|
||||
* Parsing
|
||||
* Untyped
|
||||
|
||||
### Upfront Construction
|
||||
|
||||
All component ASTs must be previously constructed, and provided on creation of the code AST.
|
||||
The construction will fail and return Code::Invalid otherwise.
|
||||
|
||||
Interface :``
|
||||
|
||||
* def_attributes
|
||||
* *This is pre-appended right before the function symbol, or placed after the class or struct keyword for any flavor of attributes used.*
|
||||
* *Its up to the user to use the desired attribute formatting: `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU).*
|
||||
* def_comment
|
||||
* def_class
|
||||
* def_enum
|
||||
* def_execution
|
||||
* *This is equivalent to untyped_str, except that its intended for use only in execution scopes.*
|
||||
* def_extern_link
|
||||
* def_friend
|
||||
* def_function
|
||||
* def_include
|
||||
* def_module
|
||||
* def_namespace
|
||||
* def_operator
|
||||
* def_operator_cast
|
||||
* def_param
|
||||
* def_params
|
||||
* def_specifier
|
||||
* def_specifiers
|
||||
* def_struct
|
||||
* def_template
|
||||
* def_type
|
||||
* def_typedef
|
||||
* def_union
|
||||
* def_using
|
||||
* def_using_namespace
|
||||
* def_variable
|
||||
|
||||
Bodies:
|
||||
|
||||
* def_body
|
||||
* def_class_body
|
||||
* def_enum_body
|
||||
* def_export_body
|
||||
* def_extern_link_body
|
||||
* def_function_body
|
||||
* *Use this for operator bodies as well*
|
||||
* def_global_body
|
||||
* def_namespace_body
|
||||
* def_struct_body
|
||||
* def_union_body
|
||||
|
||||
Usage:
|
||||
|
||||
```cpp
|
||||
<name> = def_<function type>( ... );
|
||||
|
||||
Code <name>
|
||||
{
|
||||
...
|
||||
<name> = def_<function name>( ... );
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
|
||||
```cpp
|
||||
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||
|
||||
// instead of:
|
||||
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.
|
||||
|
||||
### Parse construction
|
||||
|
||||
A string provided to the API is parsed for the intended language construct.
|
||||
|
||||
Interface :
|
||||
|
||||
* parse_class
|
||||
* 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
|
||||
* parse_operator
|
||||
* parse_operator_cast
|
||||
* parse_struct
|
||||
* parse_template
|
||||
* parse_type
|
||||
* parse_typedef
|
||||
* parse_union
|
||||
* parse_using
|
||||
* parse_variable
|
||||
|
||||
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
|
||||
* Numeric literals are not check for validity.
|
||||
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
||||
* *This includes the assignment of variables.*
|
||||
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
|
||||
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function
|
||||
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
|
||||
* typedefs have attributes with the type (`parse_type`)
|
||||
* As a general rule; if its not available from the upfront constructors, its not available in the parsing constructors.
|
||||
* *Upfront constructors are not necessarily used in the parsing constructors, this is just a good metric to know what can be parsed.*
|
||||
* Parsing attributes can be extended to support user defined macros by defining `GEN_Define_Attribute_Tokens` (see `gen.hpp` for the formatting)
|
||||
|
||||
Usage:
|
||||
|
||||
```cpp
|
||||
Code <name> = parse_<function name>( string with code );
|
||||
|
||||
Code <name> = def_<function name>( ..., parse_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
|
||||
Code <name> = make_<function name>( ... )
|
||||
{
|
||||
<name>->add( parse_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
### Untyped constructions
|
||||
|
||||
Code ASTs are constructed using unvalidated strings.
|
||||
|
||||
Interface :
|
||||
|
||||
* token_fmt_va
|
||||
* token_fmt
|
||||
* untyped_str
|
||||
* untyped_fmt
|
||||
* untyped_token_fmt
|
||||
|
||||
During serialization any untyped Code AST has its string value directly injected inline of whatever context the content existed as an entry within.
|
||||
Even though these are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that Untyped code can be added as any component of a Code AST:
|
||||
|
||||
* Untyped code cannot have children, thus there cannot be recursive injection this way.
|
||||
* Untyped code can only be a child of a parent of body AST, or for values of an assignment (ex: variable assignment).
|
||||
|
||||
These restrictions help prevent abuse of untyped code to some extent.
|
||||
|
||||
Usage Conventions:
|
||||
|
||||
```cpp
|
||||
Code <name> = def_variable( <type>, <name>, untyped_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
|
||||
Code <name> = untyped_str( code(
|
||||
<some code without "" quotes>
|
||||
));
|
||||
```
|
||||
|
||||
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
|
||||
```cpp
|
||||
Code <name> = code_str( <some code without "" quotes > )
|
||||
```
|
||||
|
||||
Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors:
|
||||
|
||||
```cpp
|
||||
StrC value = txt_StrC("Something");
|
||||
|
||||
char const* template_str = txt(
|
||||
Code with <key> to replace with token_values
|
||||
...
|
||||
);
|
||||
char const* gen_code_str = token_fmt( "key", value, template_str );
|
||||
Code <name> = parse_<function name>( gen_code_str );
|
||||
```
|
||||
|
||||
## Predefined Codes
|
||||
|
||||
The following are provided predefined by the library as they are commonly used:
|
||||
|
||||
* `access_public`
|
||||
* `access_protected`
|
||||
* `access_private`
|
||||
* `module_global_fragment`
|
||||
* `module_private_fragment`
|
||||
* `pragma_once`
|
||||
* `spec_const`
|
||||
* `spec_consteval`
|
||||
* `spec_constexpr`
|
||||
* `spec_constinit`
|
||||
* `spec_extern_linkage` (extern)
|
||||
* `spec_final`
|
||||
* `spec_global` (global macro)
|
||||
* `spec_inline`
|
||||
* `spec_internal_linkage` (internal macro)
|
||||
* `spec_local_persist` (local_persist macro)
|
||||
* `spec_mutable`
|
||||
* `spec_override`
|
||||
* `spec_ptr`
|
||||
* `spec_ref`
|
||||
* `spec_register`
|
||||
* `spec_rvalue`
|
||||
* `spec_static_member` (static)
|
||||
* `spec_thread_local`
|
||||
* `spec_virtual`
|
||||
* `spec_volatile`
|
||||
* `spec_type_signed`
|
||||
* `spec_type_unsigned`
|
||||
* `spec_type_short`
|
||||
* `spec_type_long`
|
||||
* `t_auto`
|
||||
* `t_void`
|
||||
* `t_int`
|
||||
* `t_bool`
|
||||
* `t_char`
|
||||
* `t_wchar_t`
|
||||
* `t_class`
|
||||
* `t_typename`
|
||||
|
||||
Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` is defined
|
||||
|
||||
* `t_b32`
|
||||
* `t_s8`
|
||||
* `t_s16`
|
||||
* `t_s32`
|
||||
* `t_s64`
|
||||
* `t_u8`
|
||||
* `t_u16`
|
||||
* `t_u32`
|
||||
* `t_u64`
|
||||
* `t_sw`
|
||||
* `t_uw`
|
||||
* `t_f32`
|
||||
* `t_f64`
|
||||
|
||||
## Extent of operator overload validation
|
||||
|
||||
The AST and constructors will be able to validate that the arguments provided for the operator type match the expected form:
|
||||
|
||||
* If return type must match a parameter
|
||||
* If number of parameters is correct
|
||||
* If added as a member symbol to a class or struct, that operator matches the requirements for the class (types match up)
|
||||
|
||||
The user is responsible for making sure the code types provided are correct
|
||||
and have the desired specifiers assigned to them beforehand.
|
||||
|
||||
## Code generation and modification
|
||||
|
||||
There are three provided file interfaces:
|
||||
|
||||
* Builder
|
||||
* Editor
|
||||
* Scanner
|
||||
|
||||
Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FEATURE_SCANNER` to enable them.
|
||||
|
||||
### Builder is a similar object to the jai language's string_builder
|
||||
|
||||
* The purpose of it is to generate a file.
|
||||
* A file is specified and opened for writing using the open( file_path) ) function.
|
||||
* The code is provided via print( code ) function will be serialized to its buffer.
|
||||
* When all serialization is finished, use the write() command to write the buffer to the file.
|
||||
|
||||
### Editor is for editing a series of files based on a set of requests provided to it
|
||||
|
||||
**Note: Not implemented yet**
|
||||
|
||||
* The purpose is to overrite a specific file, it places its contents in a buffer to scan.
|
||||
* Requests are populated using the following interface:
|
||||
* add : Add code.
|
||||
* remove : Remove code.
|
||||
* replace: Replace code.
|
||||
|
||||
All three have the same parameters with exception to remove which only has SymbolInfo and Policy:
|
||||
|
||||
* SymbolInfo:
|
||||
* File : The file the symbol resides in. Leave null to indicate to search all files. Leave null to indicated all-file search.
|
||||
* Marker : #define symbol that indicates a location or following signature is valid to manipulate. Leave null to indicate the signature should only be used.
|
||||
* Signature : Use a Code symbol to find a valid location to manipulate, can be further filtered with the marker. Leave null to indicate the marker should only be used.
|
||||
|
||||
* Policy : Additional policy info for completing the request (empty for now)
|
||||
* Code : Code to inject if adding, or replace existing code with.
|
||||
|
||||
Additionally if `GEN_FEATURE_EDITOR_REFACTOR` is defined, refactor( file_path, specification_path ) wil be made available.
|
||||
Refactor is based of the refactor library and uses its interface.
|
||||
It will on call add a request to the queue to run the refactor script on the file.
|
||||
|
||||
### Scanner allows the user to generate Code ASTs by reading files
|
||||
|
||||
**Note: Not implemented yet**
|
||||
|
||||
* The purpose is to grab definitions to generate metadata or generate new code from these definitions.
|
||||
* Requests are populated using the add( SymbolInfo, Policy ) function. The symbol info is the same as the one used for the editor. So is the case with Policy.
|
||||
|
||||
The file will only be read from, no writing supported.
|
||||
|
||||
One great use case is for example: generating the single-header library for gencpp!
|
||||
|
||||
### Additional Info (Editor and Scanner)
|
||||
|
||||
When all requests have been populated, call process_requests().
|
||||
It will provide an output of receipt data of the results when it completes.
|
||||
|
||||
Files may be added to the Editor and Scanner additionally with add_files( num, files ).
|
||||
This is intended for when you have requests that are for multiple files.
|
||||
|
||||
Request queue in both Editor and Scanner are cleared once process_requests completes.
|
||||
|
||||
## On multi-threading
|
||||
|
||||
Currently unsupported. The following changes would have to be made:
|
||||
|
||||
* Setup static data access with fences if more than one thread will generate ASTs ( or keep a different set for each thread)
|
||||
* Make sure local persistent data of functions are also thread local.
|
||||
* The builder should be done on a per-thread basis.
|
||||
* Due to the design of the editor and scanner, it will most likely be best to make each file a job to process request entries on. Receipts should have an an array to store per thread. They can be combined to the final receipts array when all files have been processed.
|
||||
|
||||
## Extending the library
|
||||
|
||||
This library is relatively very small, and can be extended without much hassle.
|
||||
|
||||
The convention you'll see used throughout the API of the library is as follows:
|
||||
|
||||
1. Check name or parameters to make sure they are valid for the construction requested
|
||||
2. Create a code object using `make_code`.
|
||||
3. Populate immediate fields (Name, Type, ModuleFlags, etc)
|
||||
4. Populate sub-entires using `add_entry`. If using the default serialization function `to_string`, follow the order at which entires are expected to appear (there is a strong ordering expected).
|
||||
|
||||
Names or Content fields are interned strings and thus showed be cached using `get_cached_string` if its desired to preserve that behavior.
|
||||
|
||||
`def_operator` is the most sophisticated constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
|
||||
|
||||
The library has its code segmented into component files, use it to help create a derived version without needing to have to rewrite a generated file directly or build on top of the header via composition or inheritance.
|
||||
When the scanner is implemented, this will be even easier to customize.
|
||||
|
||||
# TODO
|
||||
|
||||
* Implement a context stack for the parsing, allows for accurate scope validation for the AST types. (Better errors)
|
||||
* Right now the parsing errors require a debugger in most cases.
|
||||
* Make a more robust test suite.
|
||||
* Generate a single-header library
|
||||
* Componetize the library, make a metaprogram using gencpp to bootstrap itself.
|
||||
* Implement the Scanner
|
||||
* Implement the Editor
|
||||
* Should the builder be an "extension" header?
|
||||
* Technically the library doesn't require it and the user can use their own filesystem library.
|
||||
* It would allow me to remove the filesystem dependencies and related functions outside of gen base headers. ( At least 1k loc reduced )
|
||||
* ADT and the CSV parser depend on it as well. The `str_fmt_file` related functions do as well but they can be ommited.
|
||||
* Scanner and editor will also depend on it so they would need to include w/e the depency header for all three file-interacting interfaces.
|
||||
* `gen.files_handling.hpp`
|
||||
* Convert GlobalAllocator to a slab allocator:
|
||||
|
||||
```md
|
||||
Slab classes (for 100 mb arena)
|
||||
|
||||
1KB slab: 5MB ( 5MB / 1KB ~ 5,000 blocks )
|
||||
4KB slab: 10MB ( 10MB / 4KB ~ 2,500 blocks )
|
||||
16KB slab: 15MB ( 15MB / 16KB ~ 960 blocks )
|
||||
64KB slab: 15MB ( 15MB / 64KB ~ 240 blocks )
|
||||
256KB slab: 20MB ( 20MB / 256KB ~ 80 blocks )
|
||||
512KB slab: 20MB ( 20MB / 512KB ~ 40 blocks )
|
||||
1MB slab: 15MB ( 15MB / 1MB ~ 15 blocks )
|
||||
```
|
||||
See the [scripts directory](scripts/).
|
||||
|
37
docs/AST_Design.md
Normal file
37
docs/AST_Design.md
Normal file
@ -0,0 +1,37 @@
|
||||
# Forward
|
||||
|
||||
Was never satisfied with how I did the wrap of the management of the AST.
|
||||
For C++, the current design may be as good as it gets for the limitations of the langauge.
|
||||
|
||||
I'll at least try in this issue to brainstorm something simpiler without losing ergonomics.
|
||||
This will also be a good place to document the current design.
|
||||
|
||||
## Current Design
|
||||
|
||||
`AST` is the actual managed node object for the library.
|
||||
Its raw and really not meant to be used directly.
|
||||
|
||||
All user interaction must be with its pointer so the type they deal with is `AST*`.
|
||||
For user-facing code, they should never be giveen a nullptr. Instead, they should be given a designated `Invalid` AST node.
|
||||
|
||||
In order to abstract away constant use of `AST*`, I wanted to provide a wrapper for it.
|
||||
|
||||
The simpliest being just a type alias.
|
||||
|
||||
```cpp
|
||||
using Code = AST*;
|
||||
```
|
||||
|
||||
This is what the genc library would have to use due to its constraints of a langauge.
|
||||
Anything else and it would either be an unergonomic mess of struct wrapping with a mess of macros & procedures to interface with it.
|
||||
|
||||
Further, to provide intuitive filters on the AST, there are AST types (covered in [AST_Types.md](AST_Types.md)).
|
||||
|
||||
These are pure PODS that just have the lay members relevant to the type of AST node they represent.
|
||||
Each of them has a Code type alias specific to it.
|
||||
|
||||
Again, the simpliest case for these would be a type alias.
|
||||
|
||||
```cpp
|
||||
using struct AST_Typedef CodeTypedef;
|
||||
```
|
688
docs/AST_Types.md
Normal file
688
docs/AST_Types.md
Normal file
@ -0,0 +1,688 @@
|
||||
# AST Types Documentation
|
||||
|
||||
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
|
||||
|
||||
## Body
|
||||
|
||||
These are containers representing a scope body of a definition that can be of the following `ECode` type:
|
||||
|
||||
* Class_Body
|
||||
* Enum_Body
|
||||
* Export_Body
|
||||
* Extern_Linkage_Body
|
||||
* Function_Body
|
||||
* Global_Body
|
||||
* Namespace_Body
|
||||
* Struct_Body
|
||||
* Union_Body
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
Code Front;
|
||||
Code Back;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
The `Front` member represents the start of the link list and `Back` the end.
|
||||
NumEntries is the number of entries in the body.
|
||||
|
||||
Parent should have a compatible ECode type for the type of defintion used.
|
||||
|
||||
Serialization:
|
||||
|
||||
Will output only the entries, the braces are handled by the parent.
|
||||
|
||||
```cpp
|
||||
<Front>...
|
||||
<Back>
|
||||
```
|
||||
|
||||
## Attributes
|
||||
|
||||
Represent standard or vendor specific C/C++ attributes.
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Content>
|
||||
```
|
||||
|
||||
While the parser supports the `__declspec` and `__attribute__` syntax, the upfront constructor ( def_attributes ) must have the user specify the entire attribute, including the `[[]]`, `__declspec` or `__attribute__` parts.
|
||||
|
||||
## Comment
|
||||
|
||||
Stores a comment.
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Content>
|
||||
```
|
||||
|
||||
The parser will perserve comments found if residing with a body or in accepted inline-to-definition locations.
|
||||
Otherwise they will be skipped by the TokArray::__eat and TokArray::current( skip foramtting enabled ) functions.
|
||||
|
||||
The upfront constructor: `def_comment` expects to recieve a comment without the `//` or `/* */` parts. It will add them during construction.
|
||||
|
||||
## Class & Struct
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
CodeType ParentType;
|
||||
CodeBody Body;
|
||||
CodeType Prev; // Used to store references to interfaces
|
||||
CodeType Next; // Used to store references to interfaces
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Class_Fwd
|
||||
<ModuleFlags> <class/struct> <Name>; <InlineCmt>
|
||||
|
||||
// Class
|
||||
<ModuleFlags> <class/struct> <Attributes> <Name> : <ParentAccess> <ParentType>, public <ParentType->Next>, ... <InlineCmt>
|
||||
{
|
||||
<Body>
|
||||
};
|
||||
```
|
||||
|
||||
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest must be done through interfaces.
|
||||
|
||||
## Constructor
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
Code Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Constructor_Fwd
|
||||
<Specs> <Parent->Name>( <Params> ); <InlineCmt>
|
||||
|
||||
// Constructor
|
||||
<Specs> <Parent->Name>( <Params> ) <InlineCmt>
|
||||
: <InitializerList>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Define
|
||||
|
||||
Represents a preprocessor define
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#define <Name> <Content>
|
||||
```
|
||||
|
||||
## Destructor
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
Code Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Destructor_Fwd
|
||||
<Specs> ~<Parent->Name>( <Params> ) <Specs>; <InlineCmt>
|
||||
|
||||
// Destructor
|
||||
<Specs> ~<Parent->Name>( <Params> ) <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Enum
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Enum_Fwd
|
||||
<ModuleFlags> enum class <Name> : <UnderlyingType>; <InlineCmt>
|
||||
|
||||
// Enum
|
||||
<ModuleFlags> <enum or enum class> <Name> : <UnderlyingType>
|
||||
{
|
||||
<Body>
|
||||
};
|
||||
```
|
||||
|
||||
## Execution
|
||||
|
||||
Just represents an execution body. Equivalent to an untyped body.
|
||||
Will be obsolute when function body parsing is implemented.
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Content>
|
||||
```
|
||||
|
||||
## External Linkage
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
extern "<Name>"
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Include
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#include <Content>
|
||||
```
|
||||
|
||||
## Friend
|
||||
|
||||
This library (until its necessary become some third-party library to do otherwise) does not support friend declarations with in-statment function definitions.
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code Declaration;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
friend <Declaration>; <InlineCmt>
|
||||
```
|
||||
|
||||
## Function
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Parent;
|
||||
Code Next;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Function_Fwd
|
||||
<ModuleFlags> <Attributes> <Specs> <ReturnType> <Name>( <Params> ) <Specs>; <InlineCmt>
|
||||
|
||||
// Function
|
||||
<ModuleFlags> <Attributes> <Specs> <ReturnType> <Name>( <Params> ) <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Module
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<ModuleFlags> module <Name>;
|
||||
```
|
||||
|
||||
## Namespace
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<ModuleFlags> namespace <Name>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Operator Overload
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
OperatorT Op;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Operator_Fwd
|
||||
<ModuleFlags> <Attributes> <Specs> <ReturnType> operator <Op>( <Params> ) <Specs>; <InlineCmt>
|
||||
|
||||
// Operator
|
||||
<ModuleFlags> <Attributes> <Specs> <ReturnType> <Name>operator <Op>( <Params> ) <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Operator Cast Overload ( User-Defined Type Conversion )
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Operator_Cast_Fwd
|
||||
<Specs> operator <ValueType>() <Specs>; <InlineCmt>
|
||||
|
||||
// Operator_Cast
|
||||
<Specs> <Name>operator <ValueType>() <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeType ValueType;
|
||||
Code Value;
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<ValueType> <Name>, <Next>... <Last>
|
||||
```
|
||||
|
||||
## Pragma
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#pragma <Content>
|
||||
```
|
||||
|
||||
## Preprocessor Conditional
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#<based off Type> <Content>
|
||||
```
|
||||
|
||||
## Specifiers
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ];
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Spec>, ...
|
||||
```
|
||||
|
||||
## Template
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeParam Params;
|
||||
Code Declaration;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<ModuleFlags>
|
||||
template< <Params> >
|
||||
<Declaration>
|
||||
```
|
||||
|
||||
## Typename
|
||||
|
||||
Typenames represent the type "symbol".
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeReturnType ReturnType;
|
||||
CodeParam Params;
|
||||
Code ArrExpr;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
b32 IsParamPack;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Attributes> <Name> <Specs> <IsParamPack ?: ...>
|
||||
```
|
||||
|
||||
## Typedef
|
||||
|
||||
Behave as usual except function or macro typedefs.
|
||||
Those don't use the underlying type field as everything was serialized under the Name field.
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
Code UnderlyingType;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
|
||||
|
||||
// Functions
|
||||
<ModuleFlags> typedef <Name>; <InlineCmt>
|
||||
```
|
||||
|
||||
## Union
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeAttributes Attributes;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<ModuleFlags> union <Attributes> <Name>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Using
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> using <Attributes> <Name> = <UnderlyingType>; <InlineCmt>
|
||||
|
||||
// Namespace
|
||||
<ModuleFlags> using namespace <Name>; <InlineCmt>
|
||||
```
|
||||
|
||||
## Variable
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> = <Value>; <InlineCmt>
|
||||
|
||||
// Bitfield
|
||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>; <InlineCmt>
|
||||
```
|
89
docs/Parser_Algo.md
Normal file
89
docs/Parser_Algo.md
Normal file
@ -0,0 +1,89 @@
|
||||
# Parser's Algorithim
|
||||
|
||||
gencpp uses a hand-written recursive descent parser. Both the lexer and parser handle a full C/C++ file in a single pass.
|
||||
|
||||
## Notable implementation background
|
||||
|
||||
### Lexer
|
||||
|
||||
The lex procedure does the lexical pass of content provided as a `StrC` type.
|
||||
The tokens are stored (for now) in `gen::Parser::Tokens`.
|
||||
|
||||
Fields:
|
||||
```cpp
|
||||
Array<Token> Arr;
|
||||
s32 Idx;
|
||||
```
|
||||
|
||||
|
||||
What token types are supported can be found in [ETokType.csv](../project/enums/ETokType.csv) you can also find the token types in [ETokType.h](../project/components/gen/etoktype.cpp) , which is the generated enum from the csv file.
|
||||
|
||||
Tokens are defined with the struct `gen::Parser::Token`:
|
||||
|
||||
Fields:
|
||||
```cpp
|
||||
char const* Text;
|
||||
sptr Length;
|
||||
TokType Type;
|
||||
s32 Line;
|
||||
s32 Column;
|
||||
bool IsAssign;
|
||||
```
|
||||
|
||||
`IsAssign` is a flag that is set when the token is an assignment operator. Which is used for various purposes:
|
||||
|
||||
* Using statment assignment
|
||||
* Parameter argument default value assignment
|
||||
* Variable declaration initialization assignment
|
||||
|
||||
I plan to replace IsAssign with a general flags field and properly keep track of all operator types instead of abstracting it away to `ETokType::Operator`.
|
||||
|
||||
Traversing the tokens is done with the following interface macros:
|
||||
|
||||
| Macro | Description |
|
||||
| --- | --- |
|
||||
| `currtok_noskip` | Get the current token without skipping whitespace |
|
||||
| `currtok` | Get the current token, skip any whitespace tokens |
|
||||
| `prevtok` | Get the previous token (does not skip whitespace) |
|
||||
| `nexttok` | Get the next token (does not skip whitespace) |
|
||||
| `eat( Token Type )` | Check to see if the current token is of the given type, if so, advance Token's index to the next token |
|
||||
| `left` | Get the number of tokens left in the token array |
|
||||
| `check_noskip` | Check to see if the current token is of the given type, without skipping whitespace |
|
||||
| `check` | Check to see if the current token is of the given type, skip any whitespace tokens |
|
||||
|
||||
### Parser
|
||||
|
||||
The parser has a limited user interface, only specific types of definitions or statements are expected to be provided by the user directly when using to construct an AST dynamically (See SOA for example). It however does attempt to provide capability to parse a full C/C++ from production codebases.
|
||||
|
||||
Each public user interface procedure has the following format:
|
||||
|
||||
```cpp
|
||||
CodeStruct parse_<definition type>( StrC def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
using namespace Parser;
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return CodeInvalid;
|
||||
|
||||
// Parse the tokens and return a constructed AST using internal procedures
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
The most top-level parsing procedure used for C/C++ file parsing is `parse_global_body`:
|
||||
|
||||
It uses a helper procedure called `parse_global_nspace`.
|
||||
|
||||
Each internal procedure will be
|
||||
|
||||
## parse_global_nspace
|
||||
|
||||
1. Make sure the type provided to the helper function is a `Namespace_Body`, `Global_Body`, `Export_Body`, `Extern_Linkage_body`.
|
||||
2. If its not a `Global_Body` eat the opening brace for the scope.
|
||||
3.
|
||||
|
||||
|
||||
## parse_type
|
||||
|
81
docs/Parsing.md
Normal file
81
docs/Parsing.md
Normal file
@ -0,0 +1,81 @@
|
||||
# Parsing
|
||||
|
||||
The library features a naive parser tailored for only what the library needs to construct the supported syntax of C++ into its AST.
|
||||
|
||||
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 5500 loc. I hope to keep it under 10k loc worst case.
|
||||
|
||||
You can think of this parser of a frontend parser vs a semantic parser. Its intuitively similar to WYSIWYG. What you precerive as the syntax from the user-side before the compiler gets a hold of it, is what you get.
|
||||
|
||||
User exposed interface:
|
||||
|
||||
```cpp
|
||||
CodeClass parse_class ( StrC class_def );
|
||||
CodeConstructor parse_constructor ( StrC constructor_def );
|
||||
CodeDestructor parse_destructor ( StrC destructor_def );
|
||||
CodeEnum parse_enum ( StrC enum_def );
|
||||
CodeBody parse_export_body ( StrC export_def );
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def );
|
||||
CodeFriend parse_friend ( StrC friend_def );
|
||||
CodeFn parse_function ( StrC fn_def );
|
||||
CodeBody parse_global_body ( StrC body_def );
|
||||
CodeNS parse_namespace ( StrC namespace_def );
|
||||
CodeOperator parse_operator ( StrC operator_def );
|
||||
CodeOpCast parse_operator_cast( StrC operator_def );
|
||||
CodeStruct parse_struct ( StrC struct_def );
|
||||
CodeTemplate parse_template ( StrC template_def );
|
||||
CodeType parse_type ( StrC type_def );
|
||||
CodeTypedef parse_typedef ( StrC typedef_def );
|
||||
CodeUnion parse_union ( StrC union_def );
|
||||
CodeUsing parse_using ( StrC using_def );
|
||||
CodeVar parse_variable ( StrC var_def );
|
||||
```
|
||||
|
||||
To parse file buffers, use the `parse_global_body` function.
|
||||
|
||||
***Parsing will aggregate any tokens within a function body or expression statement to an untyped Code AST.***
|
||||
|
||||
Everything is done in one pass for both the preprocessor directives and the rest of the language.
|
||||
The parser performs no macro expansion as the scope of gencpp feature-set is to only support the preprocessor for the goal of having rudimentary awareness of preprocessor ***conditionals***, ***defines***, ***includes***, and ***pragmas***.
|
||||
|
||||
The keywords supported for the preprocessor are:
|
||||
|
||||
* include
|
||||
* define
|
||||
* if
|
||||
* ifdef
|
||||
* elif
|
||||
* endif
|
||||
* pragma
|
||||
|
||||
Each directive `#` line is considered one preproecessor unit, and will be treated as one Preprocessor AST. *These ASTs will be considered members or entries of braced scope they reside within*.
|
||||
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 )
|
||||
|
||||
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() { ... }`
|
||||
* 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`
|
||||
|
||||
*(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.*
|
||||
|
||||
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
|
||||
* Numeric literals are not checked for validity.
|
||||
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
||||
* *This includes the assignment of variables.*
|
||||
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
|
||||
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function
|
||||
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
|
||||
* typedefs have attributes with the type (`parse_type`)
|
||||
* Parsing attributes can be extended to support user defined macros by defining `GEN_DEFINE_ATTRIBUTE_TOKENS` (see `gen.hpp` for the formatting)
|
||||
|
||||
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.
|
487
docs/Readme.md
Normal file
487
docs/Readme.md
Normal file
@ -0,0 +1,487 @@
|
||||
## Documentation
|
||||
|
||||
The project has no external dependencies beyond:
|
||||
|
||||
* `errno.h`
|
||||
* `stat.h`
|
||||
* `stdarg.h`
|
||||
* `stddef.h`
|
||||
* `stdio.h`
|
||||
* `copyfile.h` (Mac)
|
||||
* `types.h` (Linux)
|
||||
* `unistd.h` (Linux/Mac)
|
||||
* `intrin.h` (Windows)
|
||||
* `io.h` (Windows with gcc)
|
||||
* `windows.h` (Windows)
|
||||
|
||||
Dependencies for the project are wrapped within `GENCPP_ROLL_OWN_DEPENDENCIES` (Defining it will disable them).
|
||||
The majority of the dependency's implementation was derived from the [c-zpl library](https://github.com/zpl-c/zpl).
|
||||
|
||||
This library was written in a subset of C++ where the following are not used at all:
|
||||
|
||||
* RAII (Constructors/Destructors), lifetimes are managed using named static or regular functions.
|
||||
* Language provide dynamic dispatch, RTTI
|
||||
* Object-Oriented Inheritance
|
||||
* Exceptions
|
||||
|
||||
Polymorphic & Member-functions are used as an ergonomic choice, along with a conserative use of operator overloads.
|
||||
There are only 4 template definitions in the entire library. (`Array<Type>`, `Hashtable<Type>`, `swap<Type>`, and `AST/Code::cast<Type>`)
|
||||
|
||||
Two generic templated containers are used throughout the library:
|
||||
|
||||
* `template< class Type> struct Array`
|
||||
* `template< class Type> struct HashTable`
|
||||
|
||||
Both Code and AST definitions have a `template< class Type> Code/AST :: cast()`. Its just an alternative way to explicitly cast to each other.
|
||||
|
||||
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
|
||||
|
||||
Otherwise the library is free of any templates.
|
||||
|
||||
### *WHAT IS NOT PROVIDED*
|
||||
|
||||
**There is no support for validating expressions.**
|
||||
Its difficult to parse without enough benefits (At the metaprogramming level).
|
||||
I plan to add this only at the tail of the project parsing milestone.
|
||||
|
||||
**Only trivial template support is provided.**
|
||||
The intention is for only simple, non-recursive substitution.
|
||||
The parameters of the template are treated like regular parameter AST entries.
|
||||
This means that the typename entry for the parameter AST would be either:
|
||||
|
||||
* `class`
|
||||
* `typename`
|
||||
* A fundamental type, function, or pointer type.
|
||||
|
||||
Anything beyond this usage is not supported by parse_template for arguments (at least not intentionally).
|
||||
Use at your own mental peril.
|
||||
|
||||
*Concepts and Constraints are not supported, its usage is non-trivial substitution.*
|
||||
|
||||
### The Data & Interface
|
||||
|
||||
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.
|
||||
However, the user may specifiy memory configuration.
|
||||
|
||||
Data layout of AST struct:
|
||||
|
||||
```cpp
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
|
||||
```
|
||||
|
||||
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
|
||||
*`OperatorT` is a typedef for `EOperator::Type` which has an underlying type of `u32`*
|
||||
*`StringCahced` is a typedef for `String const`, to denote it is an interned string*
|
||||
*`String` is the dynamically allocated string type for the library*
|
||||
|
||||
AST widths are setup to be AST_POD_Size.
|
||||
The width dictates how much the static array can hold before it must give way to using an allocated array:
|
||||
|
||||
```cpp
|
||||
constexpr static
|
||||
uw ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(u32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
|
||||
```
|
||||
|
||||
*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_string_allocator`, `get_cached_string`, `make_code`.
|
||||
* Allocators are defined with the `AllocatorInfo` structure found in `dependencies\memory.hpp`
|
||||
* Most of the work is just defining the allocation procedure:
|
||||
|
||||
```cpp
|
||||
void* ( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags );
|
||||
```
|
||||
|
||||
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
|
||||
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
||||
* This library treats memory failures as fatal.
|
||||
* Cached Strings are stored in their own set of arenas. AST constructors use cached strings for names, and content.
|
||||
* `StringArenas`, `StringCache`, `Allocator_StringArena`, and `Allocator_StringTable` are the associated containers or allocators.
|
||||
* Strings used for serialization and file buffers are not contained by those used for cached strings.
|
||||
* They are currently using `GlobalAllocator`, which are tracked array of arenas that grows as needed (adds buckets when one runs out).
|
||||
* Memory within the buckets is not reused, so its inherently wasteful.
|
||||
* I will be augmenting the single arena with a simple slag allocator.
|
||||
* Linked lists used children nodes on bodies, and parameters.
|
||||
* 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:
|
||||
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
|
||||
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
|
||||
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
|
||||
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
|
||||
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
||||
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
|
||||
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
|
||||
* `GEN_LEX_ALLOCATOR_SIZE`
|
||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
||||
|
||||
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
|
||||
|
||||
* CodeBody : Has support for `for-range` iterating across Code objects.
|
||||
* CodeAttributes
|
||||
* CodeComment
|
||||
* CodeClass
|
||||
* CodeConstructor
|
||||
* CodeDefine
|
||||
* CodeDestructor
|
||||
* CodeEnum
|
||||
* CodeExec
|
||||
* CodeExtern
|
||||
* CodeInclude
|
||||
* CodeFriend
|
||||
* CodeFn
|
||||
* CodeModule
|
||||
* CodeNS
|
||||
* CodeOperator
|
||||
* CodeOpCast
|
||||
* CodeParam : Has support for `for-range` iterating across parameters.
|
||||
* CodePreprocessCond
|
||||
* CodePragma
|
||||
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
|
||||
* CodeStruct
|
||||
* CodeTemplate
|
||||
* CodeType
|
||||
* CodeTypedef
|
||||
* CodeUnion
|
||||
* CodeUsing
|
||||
* CodeVar
|
||||
|
||||
Each Code boy 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
|
||||
|
||||
* Upfront
|
||||
* Parsing
|
||||
* Untyped
|
||||
|
||||
### Upfront Construction
|
||||
|
||||
All component ASTs must be previously constructed, and provided on creation of the code AST.
|
||||
The construction will fail and return CodeInvalid otherwise.
|
||||
|
||||
Interface :``
|
||||
|
||||
* def_attributes
|
||||
* *This is pre-appended right before the function symbol, or placed after the class or struct keyword for any flavor of attributes used.*
|
||||
* *Its up to the user to use the desired attribute formatting: `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU).*
|
||||
* def_comment
|
||||
* def_class
|
||||
* def_constructor
|
||||
* def_define
|
||||
* def_destructor
|
||||
* def_enum
|
||||
* def_execution
|
||||
* *This is equivalent to untyped_str, except that its intended for use only in execution scopes.*
|
||||
* def_extern_link
|
||||
* def_friend
|
||||
* def_function
|
||||
* def_include
|
||||
* def_module
|
||||
* def_namespace
|
||||
* def_operator
|
||||
* def_operator_cast
|
||||
* def_param
|
||||
* def_params
|
||||
* def_pragma
|
||||
* def_preprocess_cond
|
||||
* def_specifier
|
||||
* def_specifiers
|
||||
* def_struct
|
||||
* def_template
|
||||
* def_type
|
||||
* def_typedef
|
||||
* def_union
|
||||
* def_using
|
||||
* def_using_namespace
|
||||
* def_variable
|
||||
|
||||
Bodies:
|
||||
|
||||
* def_body
|
||||
* def_class_body
|
||||
* def_enum_body
|
||||
* def_export_body
|
||||
* def_extern_link_body
|
||||
* def_function_body
|
||||
* *Use this for operator bodies as well*
|
||||
* def_global_body
|
||||
* def_namespace_body
|
||||
* def_struct_body
|
||||
* def_union_body
|
||||
|
||||
Usage:
|
||||
|
||||
```cpp
|
||||
<name> = def_<function type>( ... );
|
||||
|
||||
Code <name>
|
||||
{
|
||||
...
|
||||
<name> = def_<function name>( ... );
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
When using the body functions, its recommended to use the args macro to auto determine the number of arguments for the varadic:
|
||||
```cpp
|
||||
def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||
|
||||
// instead of:
|
||||
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.
|
||||
|
||||
### Parse construction
|
||||
|
||||
A string provided to the API is parsed for the intended language construct.
|
||||
|
||||
Interface :
|
||||
|
||||
* parse_class
|
||||
* parse_constructor
|
||||
* 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
|
||||
* parse_operator
|
||||
* parse_operator_cast
|
||||
* parse_struct
|
||||
* parse_template
|
||||
* parse_type
|
||||
* parse_typedef
|
||||
* parse_union
|
||||
* parse_using
|
||||
* parse_variable
|
||||
|
||||
Usage:
|
||||
|
||||
```cpp
|
||||
Code <name> = parse_<function name>( string with code );
|
||||
|
||||
Code <name> = def_<function name>( ..., parse_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
```
|
||||
|
||||
### Untyped constructions
|
||||
|
||||
Code ASTs are constructed using unvalidated strings.
|
||||
|
||||
Interface :
|
||||
|
||||
* token_fmt_va
|
||||
* token_fmt
|
||||
* untyped_str
|
||||
* untyped_fmt
|
||||
* untyped_token_fmt
|
||||
|
||||
During serialization any untyped Code AST has its string value directly injected inline of whatever context the content existed as an entry within.
|
||||
Even though these are not validated from somewhat correct c/c++ syntax or components, it doesn't mean that Untyped code can be added as any component of a Code AST:
|
||||
|
||||
* Untyped code cannot have children, thus there cannot be recursive injection this way.
|
||||
* Untyped code can only be a child of a parent of body AST, or for values of an assignment (ex: variable assignment).
|
||||
|
||||
These restrictions help prevent abuse of untyped code to some extent.
|
||||
|
||||
Usage Conventions:
|
||||
|
||||
```cpp
|
||||
Code <name> = def_variable( <type>, <name>, untyped_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
|
||||
Code <name> = untyped_str( code(
|
||||
<some code without "" quotes>
|
||||
));
|
||||
```
|
||||
|
||||
Optionally, `code_str`, and `code_fmt` macros can be used so that the code macro doesn't have to be used:
|
||||
```cpp
|
||||
Code <name> = code_str( <some code without "" quotes > )
|
||||
```
|
||||
|
||||
Template metaprogramming in the traditional sense becomes possible with the use of `token_fmt` and parse constructors:
|
||||
|
||||
```cpp
|
||||
StrC value = txt("Something");
|
||||
|
||||
char const* template_str = txt(
|
||||
Code with <key> to replace with token_values
|
||||
...
|
||||
);
|
||||
char const* gen_code_str = token_fmt( "key", value, template_str );
|
||||
Code <name> = parse_<function name>( gen_code_str );
|
||||
```
|
||||
|
||||
## Predefined Codes
|
||||
|
||||
The following are provided predefined by the library as they are commonly used:
|
||||
|
||||
* `access_public`
|
||||
* `access_protected`
|
||||
* `access_private`
|
||||
* `attrib_api_export`
|
||||
* `attrib_api_import`
|
||||
* `module_global_fragment`
|
||||
* `module_private_fragment`
|
||||
* `fmt_newline`
|
||||
* `param_varaidc` (Used for varadic definitions)
|
||||
* `pragma_once`
|
||||
* `preprocess_else`
|
||||
* `preprocess_endif`
|
||||
* `spec_const`
|
||||
* `spec_consteval`
|
||||
* `spec_constexpr`
|
||||
* `spec_constinit`
|
||||
* `spec_extern_linkage` (extern)
|
||||
* `spec_final`
|
||||
* `spec_forceinline`
|
||||
* `spec_global` (global macro)
|
||||
* `spec_inline`
|
||||
* `spec_internal_linkage` (internal macro)
|
||||
* `spec_local_persist` (local_persist macro)
|
||||
* `spec_mutable`
|
||||
* `spec_neverinline`
|
||||
* `spec_override`
|
||||
* `spec_ptr`
|
||||
* `spec_pure`
|
||||
* `spec_ref`
|
||||
* `spec_register`
|
||||
* `spec_rvalue`
|
||||
* `spec_static_member` (static)
|
||||
* `spec_thread_local`
|
||||
* `spec_virtual`
|
||||
* `spec_volatile`
|
||||
* `t_empty` (Used for varaidc macros)
|
||||
* `t_auto`
|
||||
* `t_void`
|
||||
* `t_int`
|
||||
* `t_bool`
|
||||
* `t_char`
|
||||
* `t_wchar_t`
|
||||
* `t_class`
|
||||
* `t_typename`
|
||||
|
||||
Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` is defined
|
||||
|
||||
* `t_b32`
|
||||
* `t_s8`
|
||||
* `t_s16`
|
||||
* `t_s32`
|
||||
* `t_s64`
|
||||
* `t_u8`
|
||||
* `t_u16`
|
||||
* `t_u32`
|
||||
* `t_u64`
|
||||
* `t_sw` (ssize_t)
|
||||
* `t_uw` (size_t)
|
||||
* `t_f32`
|
||||
* `t_f64`
|
||||
|
||||
## Extent of operator overload validation
|
||||
|
||||
The AST and constructors will be able to validate that the arguments provided for the operator type match the expected form:
|
||||
|
||||
* If return type must match a parameter
|
||||
* If number of parameters is correct
|
||||
* If added as a member symbol to a class or struct, that operator matches the requirements for the class (types match up)
|
||||
|
||||
The user is responsible for making sure the code types provided are correct
|
||||
and have the desired specifiers assigned to them beforehand.
|
||||
|
||||
## Code generation and modification
|
||||
|
||||
There are three provided auxillary interfaces:
|
||||
|
||||
* Builder
|
||||
* Editor
|
||||
* Scanner
|
||||
|
||||
Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FEATURE_SCANNER` to enable them.
|
||||
|
||||
### Builder is a similar object to the jai language's string_builder
|
||||
|
||||
* The purpose of it is to generate a file.
|
||||
* A file is specified and opened for writing using the open( file_path) function.
|
||||
* The code is provided via print( code ) function will be serialized to its buffer.
|
||||
* When all serialization is finished, use the write() command to write the buffer to the file.
|
||||
|
||||
### Scanner Auxillary Interface
|
||||
|
||||
Provides *(eventually)* `scan_file` to automatically populate a CodeFile which contains a parsed AST (`Code`) of the file, with any contextual failures that are reported from the parser.
|
38
gencpp.10x
38
gencpp.10x
@ -8,21 +8,22 @@
|
||||
<ShowEmptyFolders>true</ShowEmptyFolders>
|
||||
<IsVirtual>false</IsVirtual>
|
||||
<IsFolder>false</IsFolder>
|
||||
<BuildCommand>powershell ./scripts/build.ps1</BuildCommand>
|
||||
<RebuildCommand>powershell ./scripts/rebuild.ps1</RebuildCommand>
|
||||
<BuildCommand>pwsh ./scripts/build.ps1 msvc debug bootstrap</BuildCommand>
|
||||
<RebuildCommand></RebuildCommand>
|
||||
<BuildFileCommand></BuildFileCommand>
|
||||
<CleanCommand>powershell ./scripts/clean.ps1</CleanCommand>
|
||||
<CleanCommand>psh ./scripts/clean.ps1</CleanCommand>
|
||||
<BuildWorkingDirectory></BuildWorkingDirectory>
|
||||
<CancelBuild></CancelBuild>
|
||||
<RunCommand>./test/gen/build/gencpp.exe</RunCommand>
|
||||
<RunCommandWorkingDirectory></RunCommandWorkingDirectory>
|
||||
<DebugCommand>powershell ./scripts/build.ps1</DebugCommand>
|
||||
<DebugCommand>pwsh ./scripts/build.ps1</DebugCommand>
|
||||
<ExePathCommand>./test/gen/build/gencpp.exe</ExePathCommand>
|
||||
<DebugSln>gencpp.sln</DebugSln>
|
||||
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
||||
<DebugSln></DebugSln>
|
||||
<UseVisualStudioEnvBat>true</UseVisualStudioEnvBat>
|
||||
<Configurations>
|
||||
<Configuration>Debug</Configuration>
|
||||
<Configuration>Release</Configuration>
|
||||
<Configuration>bootstrap debug</Configuration>
|
||||
</Configurations>
|
||||
<Platforms>
|
||||
<Platform>x64</Platform>
|
||||
@ -31,24 +32,37 @@
|
||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\ATLMFC\include</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\VS\include</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
|
||||
</AdditionalIncludePaths>
|
||||
<Defines></Defines>
|
||||
<Defines>
|
||||
<Define>GEN_TIME</Define>
|
||||
<Define>GEN_SYSTEM_WINDOWS</Define>
|
||||
<Define>GEN_INTELLISENSE_DIRECTIVES</Define>
|
||||
</Defines>
|
||||
<ConfigProperties>
|
||||
<ConfigAndPlatform>
|
||||
<Name>Debug:x64</Name>
|
||||
<Defines></Defines>
|
||||
<ForceIncludes></ForceIncludes>
|
||||
</ConfigAndPlatform>
|
||||
<ConfigAndPlatform>
|
||||
<Name>bootstrap debug:x64</Name>
|
||||
<Defines></Defines>
|
||||
<ForceIncludes></ForceIncludes>
|
||||
</ConfigAndPlatform>
|
||||
<Config>
|
||||
<Name>Debug</Name>
|
||||
<Defines></Defines>
|
||||
</Config>
|
||||
<Config>
|
||||
<Name>bootstrap debug</Name>
|
||||
<Defines></Defines>
|
||||
</Config>
|
||||
<Platform>
|
||||
<Name>x64</Name>
|
||||
<Defines></Defines>
|
||||
|
41
gencpp.sln
41
gencpp.sln
@ -7,20 +7,37 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gencpp", "gencpp.vcxproj",
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
bootstrap debug|x64 = bootstrap debug|x64
|
||||
bootstrap debug|x86 = bootstrap debug|x86
|
||||
bootstrap release|x64 = bootstrap release|x64
|
||||
bootstrap release|x86 = bootstrap release|x86
|
||||
singleheader debug|x64 = singleheader debug|x64
|
||||
singleheader debug|x86 = singleheader debug|x86
|
||||
singleheader release|x64 = singleheader release|x64
|
||||
singleheader release|x86 = singleheader release|x86
|
||||
test debug|x64 = test debug|x64
|
||||
test debug|x86 = test debug|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x64.Build.0 = Debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x86.Build.0 = Debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x64.ActiveCfg = Release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x64.Build.0 = Release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x86.ActiveCfg = Release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x86.Build.0 = Release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x64.ActiveCfg = bootstrap release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x64.Build.0 = bootstrap release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x86.ActiveCfg = bootstrap debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x86.Build.0 = bootstrap debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x64.ActiveCfg = bootstrap release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x86.ActiveCfg = bootstrap release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x86.Build.0 = bootstrap release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x64.ActiveCfg = singleheader debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x64.Build.0 = singleheader debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x86.ActiveCfg = singleheader debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x86.Build.0 = singleheader debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x64.ActiveCfg = bootstrap debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x64.Build.0 = bootstrap debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x86.ActiveCfg = singleheader release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x86.Build.0 = singleheader release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x64.ActiveCfg = test debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x64.Build.0 = test debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x86.ActiveCfg = test debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x86.Build.0 = test debug|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
345
gencpp.vcxproj
345
gencpp.vcxproj
@ -1,20 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<ProjectConfiguration Include="bootstrap debug|Win32">
|
||||
<Configuration>bootstrap debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<ProjectConfiguration Include="bootstrap debug|x64">
|
||||
<Configuration>bootstrap debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<ProjectConfiguration Include="bootstrap release|Win32">
|
||||
<Configuration>bootstrap release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="bootstrap release|x64">
|
||||
<Configuration>bootstrap release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader debug|Win32">
|
||||
<Configuration>singleheader debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader debug|x64">
|
||||
<Configuration>singleheader debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader release|Win32">
|
||||
<Configuration>singleheader release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader release|x64">
|
||||
<Configuration>singleheader release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="test debug|Win32">
|
||||
<Configuration>test debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="test debug|x64">
|
||||
<Configuration>test debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
@ -25,24 +49,54 @@
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
@ -50,100 +104,195 @@
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<NMakeBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_TIME;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)thirdparty;$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(ProjectDir)test;$(SourcePath)</SourcePath>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<NMakeBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_TIME;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)thirdparty;$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(ProjectDir)test;$(SourcePath)</SourcePath>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug bootstrap</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug test</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine />
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug singleheader</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc release singleheader</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc release bootstrap</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".editorconfig" />
|
||||
<None Include="project\enums\AttributeTokens.csv" />
|
||||
<None Include="project\enums\ECode.csv" />
|
||||
<None Include="project\enums\EOperator.csv" />
|
||||
<None Include="project\enums\ESpecifier.csv" />
|
||||
<None Include="project\enums\ETokType.csv" />
|
||||
<None Include="Readme.md" />
|
||||
<None Include="scripts\.clang-format" />
|
||||
<None Include="scripts\build.ci.ps1" />
|
||||
<None Include="scripts\build.ps1" />
|
||||
<None Include="scripts\clean.ps1" />
|
||||
<None Include="scripts\gen.ps1" />
|
||||
<None Include="scripts\genccp.natstepfilter" />
|
||||
<None Include="scripts\gencpp.refactor" />
|
||||
<None Include="scripts\get_sources.ps1" />
|
||||
<None Include="scripts\helpers\devshell.ps1" />
|
||||
<None Include="scripts\helpers\target_arch.psm1" />
|
||||
<None Include="scripts\package_release.ps1" />
|
||||
<None Include="scripts\refactor.ps1" />
|
||||
<None Include="test\gen\meson.build" />
|
||||
<None Include="test\meson.build" />
|
||||
<None Include="test\Readme.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="project\components\gen.data_structures.hpp" />
|
||||
<ClInclude Include="project\components\gen.interface.hpp" />
|
||||
<ClInclude Include="project\components\gen.types.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.basic_types.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.containers.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.dep.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.file_handling.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.header_start.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.macros.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.memory.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.parsing.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.printing.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.string.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.string_ops.hpp" />
|
||||
<ClInclude Include="project\filesystem\gen.builder.hpp" />
|
||||
<ClInclude Include="project\filesystem\gen.editor.hpp" />
|
||||
<ClInclude Include="project\filesystem\gen.scanner.hpp" />
|
||||
<ClInclude Include="project\auxillary\builder.hpp" />
|
||||
<ClInclude Include="project\auxillary\editor.hpp" />
|
||||
<ClInclude Include="project\auxillary\scanner.hpp" />
|
||||
<ClInclude Include="project\components\ast.hpp" />
|
||||
<ClInclude Include="project\components\ast_types.hpp" />
|
||||
<ClInclude Include="project\components\gen\ast_inlines.hpp" />
|
||||
<ClInclude Include="project\components\gen\ecode.hpp" />
|
||||
<ClInclude Include="project\components\gen\eoperator.hpp" />
|
||||
<ClInclude Include="project\components\gen\especifier.hpp" />
|
||||
<ClInclude Include="project\components\header_end.hpp" />
|
||||
<ClInclude Include="project\components\header_start.hpp" />
|
||||
<ClInclude Include="project\components\inlines.hpp" />
|
||||
<ClInclude Include="project\components\interface.hpp" />
|
||||
<ClInclude Include="project\components\types.hpp" />
|
||||
<ClInclude Include="project\dependencies\basic_types.hpp" />
|
||||
<ClInclude Include="project\dependencies\containers.hpp" />
|
||||
<ClInclude Include="project\dependencies\debug.hpp" />
|
||||
<ClInclude Include="project\dependencies\filesystem.hpp" />
|
||||
<ClInclude Include="project\dependencies\hashing.hpp" />
|
||||
<ClInclude Include="project\dependencies\header_start.hpp" />
|
||||
<ClInclude Include="project\dependencies\macros.hpp" />
|
||||
<ClInclude Include="project\dependencies\memory.hpp" />
|
||||
<ClInclude Include="project\dependencies\parsing.hpp" />
|
||||
<ClInclude Include="project\dependencies\printing.hpp" />
|
||||
<ClInclude Include="project\dependencies\strings.hpp" />
|
||||
<ClInclude Include="project\dependencies\string_ops.hpp" />
|
||||
<ClInclude Include="project\dependencies\timing.hpp" />
|
||||
<ClInclude Include="project\gen.dep.hpp" />
|
||||
<ClInclude Include="project\gen.editor.hpp" />
|
||||
<ClInclude Include="project\gen.hpp" />
|
||||
<ClInclude Include="project\gen.pop_ignores.inline.hpp" />
|
||||
<ClInclude Include="project\gen.push_ignores.inline.hpp" />
|
||||
<ClInclude Include="project\gen.scanner.hpp" />
|
||||
<ClInclude Include="project\gen.undef.macros.hpp" />
|
||||
<ClInclude Include="project\helpers\gen.pop_ignores.inline.hpp" />
|
||||
<ClInclude Include="project\helpers\gen.push_ignores.inline.hpp" />
|
||||
<ClInclude Include="project\helpers\gen.undef.macros.hpp" />
|
||||
<ClInclude Include="project\helpers\helper.hpp" />
|
||||
<ClInclude Include="project\helpers\pop_ignores.inline.hpp" />
|
||||
<ClInclude Include="project\helpers\push_ignores.inline.hpp" />
|
||||
<ClInclude Include="project\helpers\undef.macros.hpp" />
|
||||
<ClInclude Include="singleheader\components\header_start.hpp" />
|
||||
<ClInclude Include="test\CURSED_TYPEDEF.h" />
|
||||
<ClInclude Include="test\DummyInclude.hpp" />
|
||||
<ClInclude Include="test\gen\array.Upfront.gen.hpp" />
|
||||
<ClInclude Include="test\gen\buffer.Upfront.gen.hpp" />
|
||||
<ClInclude Include="test\gen\hashtable.Upfront.gen.hpp" />
|
||||
<ClInclude Include="test\gen\ring.Upfront.gen.hpp" />
|
||||
<ClInclude Include="test\gen\sanity.Upfront.gen.hpp" />
|
||||
<ClInclude Include="test\Parsed\Buffer.Parsed.hpp" />
|
||||
<ClInclude Include="test\Parsed\HashTable.Parsed.hpp" />
|
||||
<ClInclude Include="test\Parsed\Ring.Parsed.hpp" />
|
||||
@ -159,31 +308,59 @@
|
||||
<ClInclude Include="test\Parsed\Sanity.Parsed.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="project\components\gen.ast.cpp" />
|
||||
<ClCompile Include="project\components\gen.interface.parsing.cpp" />
|
||||
<ClCompile Include="project\components\gen.interface.upfront.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.dep.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.file_handling.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.memory.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.parsing.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.printing.cpp" />
|
||||
<ClCompile Include="project\auxillary\builder.cpp" />
|
||||
<ClCompile Include="project\auxillary\scanner.cpp" />
|
||||
<ClCompile Include="project\bootstrap.cpp" />
|
||||
<ClCompile Include="project\components\ast.cpp" />
|
||||
<ClCompile Include="project\components\ast_case_macros.cpp" />
|
||||
<ClCompile Include="project\components\gen\etoktype.cpp" />
|
||||
<ClCompile Include="project\components\interface.cpp" />
|
||||
<ClCompile Include="project\components\interface.parsing.cpp" />
|
||||
<ClCompile Include="project\components\interface.untyped.cpp" />
|
||||
<ClCompile Include="project\components\interface.upfront.cpp" />
|
||||
<ClCompile Include="project\components\src_start.cpp" />
|
||||
<ClCompile Include="project\components\static_data.cpp" />
|
||||
<ClCompile Include="project\dependencies\debug.cpp" />
|
||||
<ClCompile Include="project\dependencies\filesystem.cpp" />
|
||||
<ClCompile Include="project\dependencies\hashing.cpp" />
|
||||
<ClCompile Include="project\dependencies\memory.cpp" />
|
||||
<ClCompile Include="project\dependencies\parsing.cpp" />
|
||||
<ClCompile Include="project\dependencies\printing.cpp" />
|
||||
<ClCompile Include="project\dependencies\src_start.cpp" />
|
||||
<ClCompile Include="project\dependencies\strings.cpp" />
|
||||
<ClCompile Include="project\dependencies\string_ops.cpp" />
|
||||
<ClCompile Include="project\dependencies\timing.cpp" />
|
||||
<ClCompile Include="project\gen.cpp" />
|
||||
<ClCompile Include="project\gen.dep.cpp" />
|
||||
<ClCompile Include="singleheader\gen\gen.singleheader.cpp" />
|
||||
<ClCompile Include="test\gen\build\meson-private\sanitycheckc.c" />
|
||||
<ClCompile Include="test\gen\build\meson-private\sanitycheckcpp.cc" />
|
||||
<ClCompile Include="singleheader\singleheader.cpp" />
|
||||
<ClCompile Include="test\parsed\test.parsing.cpp" />
|
||||
<ClCompile Include="test\parsing.cpp" />
|
||||
<ClCompile Include="test\sanity.cpp" />
|
||||
<ClCompile Include="test\SOA.cpp" />
|
||||
<ClCompile Include="test\test.cpp" />
|
||||
<ClCompile Include="test\test.parsing.cpp" />
|
||||
<ClCompile Include="test\test.singleheader_ast.cpp" />
|
||||
<ClCompile Include="test\test.Upfront.cpp" />
|
||||
<ClCompile Include="test\upfront.cpp" />
|
||||
<ClCompile Include="test\upfront\test.upfront.cpp" />
|
||||
<ClCompile Include="test\validate_bootstrap.cpp" />
|
||||
<ClCompile Include="test\validate_singleheader.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include=".vscode\gencpp.natvis" />
|
||||
<Natvis Include="scripts\gencpp.natvis" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="project\enums\AttributeTokens.csv" />
|
||||
<Content Include="project\enums\ECode.csv" />
|
||||
<Content Include="project\enums\EOperator.csv" />
|
||||
<Content Include="project\enums\ESpecifier.csv" />
|
||||
<Content Include="project\enums\ETokType.csv" />
|
||||
<Content Include="scripts\.clang-format" />
|
||||
<Content Include="scripts\helpers\devshell.ps1" />
|
||||
<Content Include="scripts\helpers\target_arch.psm1" />
|
||||
<Content Include="scripts\refactor.ps1" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -18,18 +18,9 @@
|
||||
<ClCompile Include="project\gen.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\gen\build\meson-private\sanitycheckc.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\gen\build\meson-private\sanitycheckcpp.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\test.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="singleheader\gen\gen.singleheader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\test.Upfront.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@ -51,28 +42,94 @@
|
||||
<ClCompile Include="test\test.parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen.ast.cpp">
|
||||
<ClCompile Include="project\components\temp\etoktype.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen.interface.parsing.cpp">
|
||||
<ClCompile Include="project\components\ast.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen.interface.upfront.cpp">
|
||||
<ClCompile Include="project\components\ast_case_macros.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.dep.cpp">
|
||||
<ClCompile Include="project\components\interface.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.file_handling.cpp">
|
||||
<ClCompile Include="project\components\interface.parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.memory.cpp">
|
||||
<ClCompile Include="project\components\interface.upfront.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.parsing.cpp">
|
||||
<ClCompile Include="project\components\src_start.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.printing.cpp">
|
||||
<ClCompile Include="project\components\static_data.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\untyped.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\bootstrap.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\debug.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\filesystem.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\hashing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\memory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\printing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\src_start.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\string_ops.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\strings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\timing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\auxillary\builder.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\auxillary\scanner.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="singleheader\singleheader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\test.singleheader_ast.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\parsed\test.parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\upfront\test.upfront.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\validate_singleheader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\validate_bootstrap.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\interface.untyped.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen\etoktype.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@ -80,27 +137,9 @@
|
||||
<ClInclude Include="project\gen.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\gen.undef.macros.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\DummyInclude.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\gen\array.Upfront.gen.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\gen\buffer.Upfront.gen.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\gen\hashtable.Upfront.gen.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\gen\ring.Upfront.gen.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\gen\sanity.Upfront.gen.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\Parsed\Buffer.Parsed.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -137,82 +176,121 @@
|
||||
<ClInclude Include="project\gen.dep.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\gen.editor.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\gen.pop_ignores.inline.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\gen.push_ignores.inline.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\gen.scanner.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\parsing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\upfront.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen.data_structures.hpp">
|
||||
<ClInclude Include="project\components\temp\ast_inlines.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen.interface.hpp">
|
||||
<ClInclude Include="project\components\temp\ecode.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen.types.hpp">
|
||||
<ClInclude Include="project\components\temp\eoperator.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.basic_types.hpp">
|
||||
<ClInclude Include="project\components\temp\especifier.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.containers.hpp">
|
||||
<ClInclude Include="project\components\ast.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.dep.hpp">
|
||||
<ClInclude Include="project\components\ast_types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.file_handling.hpp">
|
||||
<ClInclude Include="project\components\header_end.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.header_start.hpp">
|
||||
<ClInclude Include="project\components\header_start.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.macros.hpp">
|
||||
<ClInclude Include="project\components\inlines.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.memory.hpp">
|
||||
<ClInclude Include="project\components\interface.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.parsing.hpp">
|
||||
<ClInclude Include="project\components\types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.printing.hpp">
|
||||
<ClInclude Include="project\helpers\helper.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.string.hpp">
|
||||
<ClInclude Include="project\helpers\pop_ignores.inline.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.string_ops.hpp">
|
||||
<ClInclude Include="project\helpers\push_ignores.inline.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\filesystem\gen.builder.hpp">
|
||||
<ClInclude Include="project\helpers\undef.macros.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\filesystem\gen.editor.hpp">
|
||||
<ClInclude Include="project\dependencies\basic_types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\filesystem\gen.scanner.hpp">
|
||||
<ClInclude Include="project\dependencies\containers.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\helpers\gen.pop_ignores.inline.hpp">
|
||||
<ClInclude Include="project\dependencies\debug.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\helpers\gen.push_ignores.inline.hpp">
|
||||
<ClInclude Include="project\dependencies\filesystem.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\helpers\gen.undef.macros.hpp">
|
||||
<ClInclude Include="project\dependencies\hashing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\header_start.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\macros.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\memory.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\parsing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\printing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\string_ops.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\strings.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\timing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\auxillary\builder.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\auxillary\editor.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\auxillary\scanner.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="singleheader\components\header_start.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\ast_inlines.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\ecode.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\eoperator.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\especifier.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\CURSED_TYPEDEF.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
@ -222,13 +300,22 @@
|
||||
<None Include="scripts\build.ci.ps1" />
|
||||
<None Include="scripts\build.ps1" />
|
||||
<None Include="scripts\clean.ps1" />
|
||||
<None Include="scripts\get_sources.ps1" />
|
||||
<None Include="test\gen\meson.build" />
|
||||
<None Include="test\meson.build" />
|
||||
<None Include="test\Readme.md" />
|
||||
<None Include="scripts\gen.ps1" />
|
||||
<None Include="scripts\genccp.natstepfilter" />
|
||||
<None Include="scripts\gencpp.refactor" />
|
||||
<None Include="project\components\temp\Readme.md" />
|
||||
<None Include="project\enums\AttributeTokens.csv" />
|
||||
<None Include="project\enums\ECode.csv" />
|
||||
<None Include="project\enums\EOperator.csv" />
|
||||
<None Include="project\enums\ESpecifier.csv" />
|
||||
<None Include="project\enums\ETokType.csv" />
|
||||
<None Include="scripts\helpers\devshell.ps1" />
|
||||
<None Include="scripts\helpers\target_arch.psm1" />
|
||||
<None Include="scripts\package_release.ps1" />
|
||||
<None Include="scripts\refactor.ps1" />
|
||||
<None Include="scripts\.clang-format" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include=".vscode\gencpp.natvis" />
|
||||
|
@ -3,14 +3,29 @@
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>C:\projects\gencpp\test\gen\build\gencpp.exe</LocalDebuggerCommand>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>C:\projects\gencpp\test\gen\build\gencpp.exe</LocalDebuggerCommand>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -1,34 +1,60 @@
|
||||
# Documentation
|
||||
|
||||
The core library is contained within `gen.hpp` and `gen.cpp`.
|
||||
Things related to the editor and scanner are in their own respective files. (Ex: `gen.scanner.<hpp/cpp>` )
|
||||
The library is fragmented into a series of headers and source files meant to be scanned in and then generated to a tailored format for the target `gen` files.
|
||||
|
||||
Dependencies are within `gen.dep.<hpp/cpp>`
|
||||
The principal (user) files are `gen.hpp` and `gen.cpp`.
|
||||
They contain includes for its various components: `components/<component_name>.<hpp/cpp>`
|
||||
|
||||
The library is fragmented into a series of headers and sources files meant to be scanned in and then generated to a tailored format for the target
|
||||
`gen` files.
|
||||
Dependencies are bundled into `gen.dep.<hpp/cpp>`.
|
||||
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`
|
||||
|
||||
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
|
||||
|
||||
**TODO : Right now the library is not finished, as such the first self-hosting iteration is still WIP**
|
||||
Both libraries use *pre-generated* (self-hosting I guess) version of the library to then generate the latest version of itself.
|
||||
(sort of a verification that the generated version is equivalent)
|
||||
|
||||
The default `gen.bootstrap.cpp` located in the project folder is meant to be produce a standard segmeneted library (WIP), where the components of the library
|
||||
have relatively dedicated header and source files. With dependencies included at the top of the file and each header starting with a pragma once.
|
||||
This will overwrite the existing library implementation in the immediate directory.
|
||||
The default `gen.bootstrap.cpp` located in the project folder is meant to be produce a standard segmented library, where the components of the library
|
||||
have relatively dedicated header and source files. Dependencies included at the top of the file and each header starting with a pragma once.
|
||||
The output will be in the `project/gen` directory (if the directory does not exist, it will create it).
|
||||
|
||||
Use those to get a general idea of how to make your own tailored version.
|
||||
|
||||
If the naming convention is undesired, the `gencpp.refactor` script can be used with the [refactor]()
|
||||
|
||||
Feature Macros:
|
||||
|
||||
* `GEN_DONT_USE_NAMESPACE` : By default, the library is wrapped in a `gen` namespace, this will disable that expose it to the global scope.
|
||||
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
|
||||
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
|
||||
* `GEN_DEFINE_ATTRIBUTE_TOKENS` : Allows user to define their own attribute macros for use in parsing.
|
||||
* This is auto-generated if using the bootstrap or single-header generation
|
||||
* *Note: The user will use the `AttributeTokens.csv` when the library is fully self-hosting.*
|
||||
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
|
||||
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
|
||||
* `GEN_ENFORCE_STRONG_CODE_TYPES` : Enforces casts to filtered code types.
|
||||
* `GEN_EXPOSE_BACKEND` : Will expose symbols meant for internal use only.
|
||||
* `GEN_Define_Attribute_Tokens` : Allows user to define their own attribute macros for use in parsing.
|
||||
* `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_USE_RECURSIVE_AST_DUPLICATION` is available but its not well tested and should not need to be used.
|
||||
If constructing ASTs properly. There should be no modification of ASTs, and thus this would never become an issue.
|
||||
(I will probably remove down the line...)
|
||||
## On multi-threading
|
||||
|
||||
Currently unsupported. I want the library to be *stable* and *correct*, with the addition of exhausting all basic single-threaded optimizations before I consider multi-threading.
|
||||
|
||||
## Extending the library
|
||||
|
||||
This library is relatively very small, and can be extended without much hassle.
|
||||
|
||||
The convention you'll see used throughout the interface of the library is as follows:
|
||||
|
||||
1. Check name or parameters to make sure they are valid for the construction requested
|
||||
2. Create a code object using `make_code`.
|
||||
3. Populate immediate fields (Name, Type, ModuleFlags, etc)
|
||||
4. Populate sub-entires using `add_entry`. If using the default serialization function `to_string`, follow the order at which entires are expected to appear (there is a strong ordering expected).
|
||||
|
||||
Names or Content fields are interned strings and thus showed be cached using `get_cached_string` if its desired to preserve that behavior.
|
||||
|
||||
`def_operator` is the most sophisticated constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
|
||||
|
||||
The library has its code segmented into component files, use it to help create a derived version without needing to have to rewrite a generated file directly or build on top of the header via composition or inheritance.
|
||||
|
||||
The parser is documented under `docs/Parsing.md` and `docs/Parser_Algo.md`.
|
||||
|
||||
## A note on compilation and runtime generation speed
|
||||
|
||||
The library is designed to be fast to compile and generate code at runtime as fast as resonable possible on a debug build.
|
||||
Its recommended that your metaprogam be compiled using a single translation unit (unity build).
|
||||
|
60
project/auxillary/builder.cpp
Normal file
60
project/auxillary/builder.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "builder.hpp"
|
||||
#endif
|
||||
|
||||
Builder Builder::open( char const* path )
|
||||
{
|
||||
Builder result;
|
||||
|
||||
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
|
||||
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
||||
|
||||
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
|
||||
return result;
|
||||
}
|
||||
|
||||
void Builder::pad_lines( s32 num )
|
||||
{
|
||||
Buffer.append( "\n" );
|
||||
}
|
||||
|
||||
void Builder::print( Code code )
|
||||
{
|
||||
String str = code->to_string();
|
||||
// const sw len = str.length();
|
||||
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
||||
Buffer.append( str );
|
||||
}
|
||||
|
||||
void Builder::print_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
|
||||
Buffer.append( buf, res );
|
||||
}
|
||||
|
||||
void Builder::write()
|
||||
{
|
||||
bool result = file_write( & File, Buffer, Buffer.length() );
|
||||
|
||||
if ( result == false )
|
||||
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
|
||||
|
||||
log_fmt( "Generated: %s\n", File.filename );
|
||||
file_close( & File );
|
||||
Buffer.free();
|
||||
}
|
20
project/auxillary/builder.hpp
Normal file
20
project/auxillary/builder.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "gen.hpp"
|
||||
#endif
|
||||
|
||||
struct Builder
|
||||
{
|
||||
FileInfo File;
|
||||
String Buffer;
|
||||
|
||||
static Builder open( char const* path );
|
||||
|
||||
void pad_lines( s32 num );
|
||||
|
||||
void print( Code );
|
||||
void print_fmt( char const* fmt, ... );
|
||||
|
||||
void write();
|
||||
};
|
||||
|
1
project/auxillary/scanner.cpp
Normal file
1
project/auxillary/scanner.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "scanner.hpp"
|
159
project/auxillary/scanner.hpp
Normal file
159
project/auxillary/scanner.hpp
Normal file
@ -0,0 +1,159 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "gen.hpp"
|
||||
#endif
|
||||
|
||||
// This is a simple file reader that reads the entire file into memory.
|
||||
// It has an extra option to skip the first few lines for undesired includes.
|
||||
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
||||
Code scan_file( char const* path )
|
||||
{
|
||||
FileInfo file;
|
||||
|
||||
FileError error = file_open_mode( & file, EFileMode_READ, path );
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
GEN_FATAL( "scan_file: Could not open: %s", path );
|
||||
}
|
||||
|
||||
sw fsize = file_size( & file );
|
||||
if ( fsize <= 0 )
|
||||
{
|
||||
GEN_FATAL("scan_file: %s is empty", path );
|
||||
}
|
||||
|
||||
String str = String::make_reserve( GlobalAllocator, fsize );
|
||||
file_read( & file, str, fsize );
|
||||
str.get_header().Length = fsize;
|
||||
|
||||
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
|
||||
// Its designed so that the directive should be the first thing in the file.
|
||||
// Anything that comes before it will also be omitted.
|
||||
{
|
||||
#define current (*scanner)
|
||||
#define matched 0
|
||||
#define move_fwd() do { ++ scanner; -- left; } while (0)
|
||||
const StrC directive_start = txt( "ifdef" );
|
||||
const StrC directive_end = txt( "endif" );
|
||||
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
|
||||
|
||||
bool found_directive = false;
|
||||
char const* scanner = str.Data;
|
||||
s32 left = fsize;
|
||||
while ( left )
|
||||
{
|
||||
// Processing directive.
|
||||
if ( current == '#' )
|
||||
{
|
||||
move_fwd();
|
||||
while ( left && char_is_space( current ) )
|
||||
move_fwd();
|
||||
|
||||
if ( ! found_directive )
|
||||
{
|
||||
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
|
||||
{
|
||||
scanner += directive_start.Len;
|
||||
left -= directive_start.Len;
|
||||
|
||||
while ( left && char_is_space( current ) )
|
||||
move_fwd();
|
||||
|
||||
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
|
||||
{
|
||||
scanner += def_intellisense.Len;
|
||||
left -= def_intellisense.Len;
|
||||
|
||||
found_directive = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip to end of line
|
||||
while ( left && current != '\r' && current != '\n' )
|
||||
move_fwd();
|
||||
move_fwd();
|
||||
|
||||
if ( left && current == '\n' )
|
||||
move_fwd();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
|
||||
{
|
||||
scanner += directive_end.Len;
|
||||
left -= directive_end.Len;
|
||||
|
||||
// Skip to end of line
|
||||
while ( left && current != '\r' && current != '\n' )
|
||||
move_fwd();
|
||||
move_fwd();
|
||||
|
||||
if ( left && current == '\n' )
|
||||
move_fwd();
|
||||
|
||||
// sptr skip_size = fsize - left;
|
||||
if ( (scanner + 2) >= ( str.Data + fsize ) )
|
||||
{
|
||||
mem_move( str, scanner, left );
|
||||
str.get_header().Length = left;
|
||||
break;
|
||||
}
|
||||
|
||||
mem_move( str, scanner, left );
|
||||
str.get_header().Length = left;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
move_fwd();
|
||||
}
|
||||
#undef move_fwd
|
||||
#undef matched
|
||||
#undef current
|
||||
}
|
||||
|
||||
file_close( & file );
|
||||
return untyped_str( str );
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct CodeFile
|
||||
{
|
||||
using namespace Parser;
|
||||
|
||||
String FilePath;
|
||||
TokArray Tokens;
|
||||
Array<ParseFailure> ParseFailures;
|
||||
Code CodeRoot;
|
||||
};
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
struct ParseFailure
|
||||
{
|
||||
String Reason;
|
||||
Code Node;
|
||||
};
|
||||
}
|
||||
|
||||
CodeFile scan_file( char const* path )
|
||||
{
|
||||
using namespace Parser;
|
||||
|
||||
CodeFile
|
||||
result = {};
|
||||
result.FilePath = String::make( GlobalAllocator, path );
|
||||
|
||||
Code code = scan_file( path );
|
||||
result.CodeRoot = code;
|
||||
|
||||
ParseContext context = parser_get_last_context();
|
||||
result.Tokens = context.Tokens;
|
||||
result.ParseFailures = context.Failures;
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
295
project/bootstrap.cpp
Normal file
295
project/bootstrap.cpp
Normal file
@ -0,0 +1,295 @@
|
||||
#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"
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.cpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp" );
|
||||
|
||||
// gen_dep.hpp
|
||||
{
|
||||
Code header_start = scan_file( "dependencies/header_start.hpp" );
|
||||
Code macros = scan_file( "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( "dependencies/timing.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open("gen/gen.dep.hpp");
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n" );
|
||||
header.print( header_start );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( macros );
|
||||
header.print( basic_types );
|
||||
header.print( debug );
|
||||
header.print( memory );
|
||||
header.print( string_ops );
|
||||
header.print( printing );
|
||||
header.print( containers );
|
||||
header.print( hashing );
|
||||
header.print( strings );
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
Code src_start = scan_file( "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( "dependencies/timing.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.dep.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print_fmt( "// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n\n" );
|
||||
src.print( src_start );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
src.print( debug );
|
||||
src.print( string_ops );
|
||||
src.print( printing );
|
||||
src.print( hashing );
|
||||
src.print( memory );
|
||||
src.print( strings );
|
||||
src.print( filesystem );
|
||||
src.print( timing );
|
||||
|
||||
src.print_fmt( "\nGEN_NS_END\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_str(generation_notice) )
|
||||
));
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code types = scan_file( "components/types.hpp" );
|
||||
Code ast = scan_file( "components/ast.hpp" );
|
||||
Code ast_types = scan_file( "components/ast_types.hpp" );
|
||||
Code interface = scan_file( "components/interface.hpp" );
|
||||
Code inlines = scan_file( "components/inlines.hpp" );
|
||||
Code header_end = scan_file( "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( "enums/ECode.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" );
|
||||
CodeBody ast_inlines = gen_ast_inlines();
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "#pragma once\n\n" );
|
||||
header.print( push_ignores );
|
||||
header.print( header_start );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
|
||||
header.print_fmt( "#pragma region Types\n" );
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
header.print_fmt( "#pragma endregion Types\n\n" );
|
||||
|
||||
header.print_fmt( "#pragma region AST\n" );
|
||||
header.print( ast );
|
||||
header.print( ast_types );
|
||||
header.print_fmt( "\n#pragma endregion AST\n" );
|
||||
|
||||
header.print( interface );
|
||||
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( fmt_newline );
|
||||
header.print( ast_inlines );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
header.print_fmt( "GEN_NS_END\n\n" );
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
|
||||
Builder
|
||||
header_ecode = Builder::open( "components/gen/ecode.hpp" );
|
||||
header_ecode.print( gen_component_header );
|
||||
header_ecode.print( ecode );
|
||||
header_ecode.write();
|
||||
|
||||
Builder
|
||||
header_eoperator = Builder::open( "components/gen/eoperator.hpp" );
|
||||
header_eoperator.print( gen_component_header );
|
||||
header_eoperator.print( eoperator );
|
||||
header_eoperator.write();
|
||||
|
||||
Builder
|
||||
header_especifier = Builder::open( "components/gen/especifier.hpp" );
|
||||
header_especifier.print( gen_component_header );
|
||||
header_especifier.print( especifier );
|
||||
header_especifier.write();
|
||||
|
||||
Builder
|
||||
header_ast_inlines = Builder::open( "components/gen/ast_inlines.hpp" );
|
||||
header_ast_inlines.print( gen_component_header );
|
||||
header_ast_inlines.print( ast_inlines );
|
||||
header_ast_inlines.write();
|
||||
}
|
||||
|
||||
// gen.cpp
|
||||
{
|
||||
Code src_start = scan_file( "components/src_start.cpp" );
|
||||
Code static_data = scan_file( "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( "components/ast.cpp" );
|
||||
Code interface = scan_file( "components/interface.cpp" );
|
||||
Code upfront = scan_file( "components/interface.upfront.cpp" );
|
||||
Code parsing = scan_file( "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( "components/interface.untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
CodeNS nspaced_etoktype = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( push_ignores );
|
||||
src.print( src_start );
|
||||
src.print_fmt( "GEN_NS_BEGIN\n");
|
||||
|
||||
src.print( static_data );
|
||||
|
||||
src.print_fmt( "\n#pragma region AST\n\n" );
|
||||
src.print( ast_case_macros );
|
||||
src.print( ast );
|
||||
src.print_fmt( "\n#pragma endregion AST\n" );
|
||||
|
||||
src.print_fmt( "\n#pragma region Interface\n" );
|
||||
src.print( interface );
|
||||
src.print( upfront );
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( nspaced_etoktype );
|
||||
src.print( parsing );
|
||||
src.print( untyped );
|
||||
src.print_fmt( "\n#pragma endregion Parsing\n\n" );
|
||||
src.print_fmt( "#pragma endregion Interface\n\n" );
|
||||
|
||||
src.print_fmt( "GEN_NS_END\n\n");
|
||||
src.print( pop_ignores );
|
||||
src.write();
|
||||
|
||||
Builder
|
||||
src_etoktype = Builder::open( "components/gen/etoktype.cpp" );
|
||||
src_etoktype.print( gen_component_header );
|
||||
src_etoktype.print( nspaced_etoktype );
|
||||
src_etoktype.write();
|
||||
}
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( "auxillary/builder.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.builder.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "#pragma once\n\n" );
|
||||
header.print( def_include( txt("gen.hpp") ));
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
header.print( builder );
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( "auxillary/builder.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.builder.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( def_include( txt("gen.builder.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
src.print( builder );
|
||||
src.print_fmt( "\nGEN_NS_END\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( "auxillary/scanner.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.scanner.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "#pragma once\n\n" );
|
||||
header.print( def_include( txt("gen.hpp") ) );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
header.print( parsing );
|
||||
header.print( scanner );
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_scanner.cpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.cpp" );
|
||||
Code scanner = scan_file( "auxillary/scanner.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.scanner.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( def_include( txt("gen.scanner.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
src.print( parsing );
|
||||
src.print( scanner );
|
||||
src.print_fmt( "GEN_NS_END\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
}
|
2072
project/components/ast.cpp
Normal file
2072
project/components/ast.cpp
Normal file
File diff suppressed because it is too large
Load Diff
619
project/components/ast.hpp
Normal file
619
project/components/ast.hpp
Normal file
@ -0,0 +1,619 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "gen/ecode.hpp"
|
||||
#include "gen/eoperator.hpp"
|
||||
#include "gen/especifier.hpp"
|
||||
#endif
|
||||
|
||||
struct AST;
|
||||
struct AST_Body;
|
||||
struct AST_Attributes;
|
||||
struct AST_Comment;
|
||||
struct AST_Constructor;
|
||||
struct AST_Class;
|
||||
struct AST_Define;
|
||||
struct AST_Destructor;
|
||||
struct AST_Enum;
|
||||
struct AST_Exec;
|
||||
struct AST_Extern;
|
||||
struct AST_Include;
|
||||
struct AST_Friend;
|
||||
struct AST_Fn;
|
||||
struct AST_Module;
|
||||
struct AST_NS;
|
||||
struct AST_Operator;
|
||||
struct AST_OpCast;
|
||||
struct AST_Param;
|
||||
struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
struct AST_Struct;
|
||||
struct AST_Template;
|
||||
struct AST_Type;
|
||||
struct AST_Typedef;
|
||||
struct AST_Union;
|
||||
struct AST_Using;
|
||||
struct AST_Var;
|
||||
|
||||
struct Code;
|
||||
struct CodeBody;
|
||||
// These are to offer ease of use and optionally strong type safety for the AST.
|
||||
struct CodeAttributes;
|
||||
struct CodeComment;
|
||||
struct CodeClass;
|
||||
struct CodeConstructor;
|
||||
struct CodeDefine;
|
||||
struct CodeDestructor;
|
||||
struct CodeEnum;
|
||||
struct CodeExec;
|
||||
struct CodeExtern;
|
||||
struct CodeInclude;
|
||||
struct CodeFriend;
|
||||
struct CodeFn;
|
||||
struct CodeModule;
|
||||
struct CodeNS;
|
||||
struct CodeOperator;
|
||||
struct CodeOpCast;
|
||||
struct CodeParam;
|
||||
struct CodePreprocessCond;
|
||||
struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
struct CodeStruct;
|
||||
struct CodeTemplate;
|
||||
struct CodeType;
|
||||
struct CodeTypedef;
|
||||
struct CodeUnion;
|
||||
struct CodeUsing;
|
||||
struct CodeVar;
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
struct Token;
|
||||
}
|
||||
|
||||
/*
|
||||
AST* wrapper
|
||||
- Not constantly have to append the '*' as this is written often..
|
||||
- Allows for implicit conversion to any of the ASTs (raw or filtered).
|
||||
*/
|
||||
struct Code
|
||||
{
|
||||
# pragma region Statics
|
||||
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
|
||||
static Code Global;
|
||||
|
||||
// Used to identify invalid generated code.
|
||||
static Code Invalid;
|
||||
# pragma endregion Statics
|
||||
|
||||
# define Using_Code( Typename ) \
|
||||
char const* debug_str(); \
|
||||
Code duplicate(); \
|
||||
bool is_equal( Code other ); \
|
||||
bool is_valid(); \
|
||||
void set_global(); \
|
||||
String to_string(); \
|
||||
Typename& operator = ( AST* other ); \
|
||||
Typename& operator = ( Code other ); \
|
||||
bool operator ==( Code other ); \
|
||||
bool operator !=( Code other ); \
|
||||
operator bool();
|
||||
|
||||
Using_Code( Code );
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
return * rcast( Type*, this );
|
||||
}
|
||||
|
||||
AST* operator ->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
Code& operator ++();
|
||||
auto& operator*()
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
AST* ast;
|
||||
|
||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define operator explicit operator
|
||||
#endif
|
||||
operator CodeAttributes() const;
|
||||
operator CodeComment() const;
|
||||
operator CodeConstructor() const;
|
||||
operator CodeDestructor() const;
|
||||
operator CodeClass() const;
|
||||
operator CodeDefine() const;
|
||||
operator CodeExec() const;
|
||||
operator CodeEnum() const;
|
||||
operator CodeExtern() const;
|
||||
operator CodeInclude() const;
|
||||
operator CodeFriend() const;
|
||||
operator CodeFn() const;
|
||||
operator CodeModule() const;
|
||||
operator CodeNS() const;
|
||||
operator CodeOperator() const;
|
||||
operator CodeOpCast() const;
|
||||
operator CodeParam() const;
|
||||
operator CodePragma() const;
|
||||
operator CodePreprocessCond() const;
|
||||
operator CodeSpecifiers() const;
|
||||
operator CodeStruct() const;
|
||||
operator CodeTemplate() const;
|
||||
operator CodeType() const;
|
||||
operator CodeTypedef() const;
|
||||
operator CodeUnion() const;
|
||||
operator CodeUsing() const;
|
||||
operator CodeVar() const;
|
||||
operator CodeBody() const;
|
||||
#undef operator
|
||||
};
|
||||
|
||||
struct Code_POD
|
||||
{
|
||||
AST* ast;
|
||||
};
|
||||
|
||||
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
||||
|
||||
// Desired width of the AST data structure.
|
||||
constexpr int const AST_POD_Size = 128;
|
||||
|
||||
/*
|
||||
Simple AST POD with functionality to seralize into C++ syntax.
|
||||
*/
|
||||
struct AST
|
||||
{
|
||||
# pragma region Member Functions
|
||||
void append ( AST* other );
|
||||
char const* debug_str ();
|
||||
AST* duplicate ();
|
||||
Code& entry ( u32 idx );
|
||||
bool has_entries();
|
||||
bool is_equal ( AST* other );
|
||||
char const* type_str();
|
||||
bool validate_body();
|
||||
|
||||
neverinline String to_string();
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
|
||||
operator Code();
|
||||
operator CodeBody();
|
||||
operator CodeAttributes();
|
||||
operator CodeComment();
|
||||
operator CodeConstructor();
|
||||
operator CodeDestructor();
|
||||
operator CodeClass();
|
||||
operator CodeDefine();
|
||||
operator CodeEnum();
|
||||
operator CodeExec();
|
||||
operator CodeExtern();
|
||||
operator CodeInclude();
|
||||
operator CodeFriend();
|
||||
operator CodeFn();
|
||||
operator CodeModule();
|
||||
operator CodeNS();
|
||||
operator CodeOperator();
|
||||
operator CodeOpCast();
|
||||
operator CodeParam();
|
||||
operator CodePragma();
|
||||
operator CodePreprocessCond();
|
||||
operator CodeSpecifiers();
|
||||
operator CodeStruct();
|
||||
operator CodeTemplate();
|
||||
operator CodeType();
|
||||
operator CodeTypedef();
|
||||
operator CodeUnion();
|
||||
operator CodeUsing();
|
||||
operator CodeVar();
|
||||
# pragma endregion Member Functions
|
||||
|
||||
constexpr static
|
||||
int ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(Parser::Token*)
|
||||
- sizeof(AST*)
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(int)
|
||||
)
|
||||
/ sizeof(int) - 1; // -1 for 4 extra bytes
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
Parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
struct AST_POD
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
Parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
struct test {
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
|
||||
constexpr int pls = sizeof(test);
|
||||
|
||||
// Its intended for the AST to have equivalent size to its POD.
|
||||
// All extra functionality within the AST namespace should just be syntatic sugar.
|
||||
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );
|
||||
static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
|
||||
|
||||
// Used when the its desired when omission is allowed in a definition.
|
||||
#define NoCode { nullptr }
|
||||
#define CodeInvalid (* Code::Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.
|
||||
|
||||
#pragma region Code Types
|
||||
|
||||
struct CodeBody
|
||||
{
|
||||
Using_Code( CodeBody );
|
||||
|
||||
void append( Code other )
|
||||
{
|
||||
raw()->append( other.ast );
|
||||
}
|
||||
void append( CodeBody body )
|
||||
{
|
||||
for ( Code entry : body )
|
||||
{
|
||||
append( entry );
|
||||
}
|
||||
}
|
||||
bool has_entries()
|
||||
{
|
||||
return rcast( AST*, ast )->has_entries();
|
||||
}
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Body* operator->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
#pragma region Iterator
|
||||
Code begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { rcast( AST*, ast)->Front };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
Code end()
|
||||
{
|
||||
return { rcast(AST*, ast)->Back->Next };
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Body* ast;
|
||||
};
|
||||
|
||||
struct CodeClass
|
||||
{
|
||||
Using_Code( CodeClass );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Class* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Class* ast;
|
||||
};
|
||||
|
||||
struct CodeParam
|
||||
{
|
||||
Using_Code( CodeParam );
|
||||
|
||||
void append( CodeParam other );
|
||||
|
||||
CodeParam get( s32 idx );
|
||||
bool has_entries();
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Param* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*)ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
CodeParam begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { ast };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
CodeParam end()
|
||||
{
|
||||
return { (AST_Param*) rcast( AST*, ast)->Last };
|
||||
}
|
||||
CodeParam& operator++();
|
||||
CodeParam operator*()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Param* ast;
|
||||
};
|
||||
|
||||
struct CodeSpecifiers
|
||||
{
|
||||
Using_Code( CodeSpecifiers );
|
||||
|
||||
bool append( SpecifierT spec )
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( raw()->NumEntries == AST::ArrSpecs_Cap )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap );
|
||||
return false;
|
||||
}
|
||||
|
||||
raw()->ArrSpecs[ raw()->NumEntries ] = spec;
|
||||
raw()->NumEntries++;
|
||||
return true;
|
||||
}
|
||||
s32 has( SpecifierT spec )
|
||||
{
|
||||
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
|
||||
{
|
||||
if ( raw()->ArrSpecs[ raw()->NumEntries ] == spec )
|
||||
return idx;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Specifiers* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*) ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
SpecifierT* begin()
|
||||
{
|
||||
if ( ast )
|
||||
return & raw()->ArrSpecs[0];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
SpecifierT* end()
|
||||
{
|
||||
return raw()->ArrSpecs + raw()->NumEntries;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Specifiers* ast;
|
||||
};
|
||||
|
||||
struct CodeStruct
|
||||
{
|
||||
Using_Code( CodeStruct );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Struct* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Struct* ast;
|
||||
};
|
||||
|
||||
#define Define_CodeType( Typename ) \
|
||||
struct Code##Typename \
|
||||
{ \
|
||||
Using_Code( Code ## Typename ); \
|
||||
AST* raw(); \
|
||||
operator Code(); \
|
||||
AST_##Typename* operator->(); \
|
||||
AST_##Typename* ast; \
|
||||
}
|
||||
|
||||
Define_CodeType( Attributes );
|
||||
Define_CodeType( Comment );
|
||||
Define_CodeType( Constructor );
|
||||
Define_CodeType( Define );
|
||||
Define_CodeType( Destructor );
|
||||
Define_CodeType( Enum );
|
||||
Define_CodeType( Exec );
|
||||
Define_CodeType( Extern );
|
||||
Define_CodeType( Include );
|
||||
Define_CodeType( Friend );
|
||||
Define_CodeType( Fn );
|
||||
Define_CodeType( Module );
|
||||
Define_CodeType( NS );
|
||||
Define_CodeType( Operator );
|
||||
Define_CodeType( OpCast );
|
||||
Define_CodeType( Pragma );
|
||||
Define_CodeType( PreprocessCond );
|
||||
Define_CodeType( Template );
|
||||
Define_CodeType( Type );
|
||||
Define_CodeType( Typedef );
|
||||
Define_CodeType( Union );
|
||||
Define_CodeType( Using );
|
||||
Define_CodeType( Var );
|
||||
|
||||
#undef Define_CodeType
|
||||
#undef Using_Code
|
||||
|
||||
#pragma endregion Code Types
|
78
project/components/ast_case_macros.cpp
Normal file
78
project/components/ast_case_macros.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Extern_Linkage: \
|
||||
case Function_Body: \
|
||||
case Function_Fwd: \
|
||||
case Global_Body: \
|
||||
case Namespace: \
|
||||
case Namespace_Body: \
|
||||
case Operator: \
|
||||
case Operator_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
# define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
|
||||
# define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \
|
||||
case Access_Public: \
|
||||
case Access_Protected: \
|
||||
case Access_Private: \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Extern_Linkage: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Function_Fwd: \
|
||||
case Global_Body: \
|
||||
case Namespace: \
|
||||
case Namespace_Body: \
|
||||
case Operator: \
|
||||
case Operator_Fwd: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
# define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \
|
||||
case Access_Public: \
|
||||
case Access_Protected: \
|
||||
case Access_Private: \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Execution: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Namespace_Body: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
# define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
# define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
|
||||
# define GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES \
|
||||
case Access_Public: \
|
||||
case Access_Protected: \
|
||||
case Access_Private: \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Execution: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Namespace_Body: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
606
project/components/ast_types.hpp
Normal file
606
project/components/ast_types.hpp
Normal file
@ -0,0 +1,606 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "ast.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region AST Types
|
||||
/*
|
||||
Show only relevant members of the AST for its type.
|
||||
AST* fields are replaced with Code types.
|
||||
- Guards assignemnts to AST* fields to ensure the AST is duplicated if assigned to another parent.
|
||||
*/
|
||||
|
||||
struct AST_Body
|
||||
{
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
Code Front;
|
||||
Code Back;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Attributes
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Attributes) == sizeof(AST), "ERROR: AST_Attributes is not the same size as AST");
|
||||
|
||||
struct AST_Comment
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Comment) == sizeof(AST), "ERROR: AST_Comment is not the same size as AST");
|
||||
|
||||
struct AST_Class
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeType Prev;
|
||||
CodeType Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
};
|
||||
static_assert( sizeof(AST_Class) == sizeof(AST), "ERROR: AST_Class is not the same size as AST");
|
||||
|
||||
struct AST_Constructor
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
||||
CodeSpecifiers Specs;
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
char _PAD_NAME_[ sizeof(StringCached) ];
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Constructor) == sizeof(AST), "ERROR: AST_Constructor is not the same size as AST");
|
||||
|
||||
struct AST_Define
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Destructor
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
||||
CodeSpecifiers Specs;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_3_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
char _PAD_NAME_[ sizeof(StringCached) ];
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Destructor) == sizeof(AST), "ERROR: AST_Destructor is not the same size as AST");
|
||||
|
||||
struct AST_Enum
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPEC_ [ sizeof(AST*) ];
|
||||
CodeType UnderlyingType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Enum) == sizeof(AST), "ERROR: AST_Enum is not the same size as AST");
|
||||
|
||||
struct AST_Exec
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Exec) == sizeof(AST), "ERROR: AST_Exec is not the same size as AST");
|
||||
|
||||
struct AST_Extern
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Extern) == sizeof(AST), "ERROR: AST_Extern is not the same size as AST");
|
||||
|
||||
struct AST_Include
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Friend
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Fn
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Module
|
||||
{
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Module) == sizeof(AST), "ERROR: AST_Module is not the same size as AST");
|
||||
|
||||
struct AST_NS
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct {
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
OperatorT Op;
|
||||
};
|
||||
static_assert( sizeof(AST_Operator) == sizeof(AST), "ERROR: AST_Operator is not the same size as AST");
|
||||
|
||||
struct AST_OpCast
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
||||
|
||||
struct AST_Param
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
CodeType ValueType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
Code Value;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
};
|
||||
static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the same size as AST");
|
||||
|
||||
struct AST_Pragma
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_PreprocessCond
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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
|
||||
{
|
||||
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ];
|
||||
CodeSpecifiers NextSpecs;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Struct
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeType Prev;
|
||||
CodeType Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
};
|
||||
static_assert( sizeof(AST_Struct) == sizeof(AST), "ERROR: AST_Struct is not the same size as AST");
|
||||
|
||||
struct AST_Template
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParam Params;
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Type
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
char _PAD_INLINE_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType; // Only used for function signatures
|
||||
CodeParam Params; // Only used for function signatures
|
||||
Code ArrExpr;
|
||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
b32 IsParamPack;
|
||||
};
|
||||
static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
|
||||
|
||||
struct AST_Typedef
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
Code UnderlyingType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
};
|
||||
static_assert( sizeof(AST_Typedef) == sizeof(AST), "ERROR: AST_Typedef is not the same size as AST");
|
||||
|
||||
struct AST_Union
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
char _PAD_INLINE_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Using
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType UnderlyingType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT 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");
|
||||
|
||||
struct AST_Var
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap + sizeof(AST*) ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
CodeVar NextVar;
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Parser::Token* Token;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||
|
||||
#pragma endregion AST Types
|
@ -1,830 +0,0 @@
|
||||
#pragma region AST
|
||||
|
||||
Code Code::Global;
|
||||
Code Code::Invalid;
|
||||
|
||||
AST* AST::duplicate()
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
AST* result = make_code().ast;
|
||||
|
||||
mem_copy( result, this, sizeof( AST ) );
|
||||
|
||||
result->Parent = nullptr;
|
||||
return result;
|
||||
}
|
||||
|
||||
String AST::to_string()
|
||||
{
|
||||
# define ProcessModuleFlags() \
|
||||
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export )) \
|
||||
result.append( "export " ); \
|
||||
\
|
||||
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Import )) \
|
||||
result.append( "import " ); \
|
||||
|
||||
local_persist thread_local
|
||||
char SerializationLevel = 0;
|
||||
|
||||
#if defined(GEN_BENCHMARK) && defined(GEN_BENCHMARK_SERIALIZATION)
|
||||
u64 time_start = time_rel_ms();
|
||||
#endif
|
||||
|
||||
// TODO : Need to refactor so that intermeidate strings are freed conviently.
|
||||
String result = String::make( GlobalAllocator, "" );
|
||||
|
||||
switch ( Type )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
case Invalid:
|
||||
log_failure("Attempted to serialize invalid code! - %s", Parent ? Parent->debug_str() : Name );
|
||||
break;
|
||||
|
||||
case Untyped:
|
||||
case Execution:
|
||||
result.append( Content );
|
||||
break;
|
||||
|
||||
case Comment:
|
||||
{
|
||||
static char line[MaxCommentLineLength];
|
||||
|
||||
s32 left = Content.length();
|
||||
s32 index = 0;
|
||||
do
|
||||
{
|
||||
s32 length = 0;
|
||||
while ( left && Content[index] != '\n' )
|
||||
{
|
||||
length++;
|
||||
left--;
|
||||
}
|
||||
|
||||
str_copy( line, Content, length );
|
||||
line[length] = '\0';
|
||||
|
||||
result.append_fmt( "// %s", line );
|
||||
}
|
||||
while ( left--, left > 0 );
|
||||
}
|
||||
break;
|
||||
|
||||
case Access_Private:
|
||||
case Access_Protected:
|
||||
case Access_Public:
|
||||
result.append( Name );
|
||||
break;
|
||||
|
||||
case PlatformAttributes:
|
||||
result.append( Content );
|
||||
|
||||
case Class:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes || ParentType )
|
||||
{
|
||||
result.append( "class " );
|
||||
|
||||
if ( Attributes )
|
||||
{
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
}
|
||||
|
||||
if ( ParentType )
|
||||
{
|
||||
char const* access_level = to_str( ParentAccess );
|
||||
|
||||
result.append_fmt( "%s : %s %s\n{\n%s\n};"
|
||||
, Name
|
||||
, access_level
|
||||
, ParentType->to_string()
|
||||
, Body->to_string()
|
||||
);
|
||||
|
||||
CodeType interface = Next->cast<CodeType>();
|
||||
if ( interface )
|
||||
result.append("\n");
|
||||
|
||||
while ( interface )
|
||||
{
|
||||
result.append_fmt( ", %s", interface.to_string() );
|
||||
|
||||
interface = interface->Next->cast<CodeType>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append_fmt( "%s \n{\n%s\n};", Name, Body->to_string() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append_fmt( "class %s\n{\n%s\n};", Name, Body->to_string() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Class_Fwd:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "class %s %s;", Attributes->to_string(), Name );
|
||||
|
||||
else result.append_fmt( "class %s;", Name );
|
||||
}
|
||||
break;
|
||||
|
||||
case Enum:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes || UnderlyingType )
|
||||
{
|
||||
result.append( "enum " );
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( UnderlyingType )
|
||||
result.append_fmt( "%s : %s\n{\n%s\n};"
|
||||
, Name
|
||||
, UnderlyingType->to_string()
|
||||
, Body->to_string()
|
||||
);
|
||||
|
||||
else result.append_fmt( "%s\n{\n%s\n};"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
else result.append_fmt( "enum %s\n{\n%s\n};"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case Enum_Fwd:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
result.append_fmt( "enum %s : %s;", Name, UnderlyingType->to_string() );
|
||||
}
|
||||
break;
|
||||
|
||||
case Enum_Class:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes || UnderlyingType )
|
||||
{
|
||||
result.append( "enum class " );
|
||||
|
||||
if ( Attributes )
|
||||
{
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
}
|
||||
|
||||
if ( UnderlyingType )
|
||||
{
|
||||
result.append_fmt( "%s : %s\n{\n%s\n};"
|
||||
, Name
|
||||
, UnderlyingType->to_string()
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append_fmt( "%s\n{\n%s\n};"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append_fmt( "enum class %s\n{\n%s\n};"
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Enum_Class_Fwd:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
result.append( "enum class " );
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
result.append_fmt( "%s : %s;", Name, UnderlyingType->to_string() );
|
||||
}
|
||||
break;
|
||||
|
||||
case Export_Body:
|
||||
{
|
||||
result.append_fmt( "export\n{\n" );
|
||||
|
||||
Code curr = { this };
|
||||
s32 left = NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
result.append_fmt( "%s\n", curr.to_string() );
|
||||
++curr;
|
||||
}
|
||||
|
||||
result.append_fmt( "};" );
|
||||
}
|
||||
break;
|
||||
|
||||
case Extern_Linkage:
|
||||
result.append_fmt( "extern \"%s\"\n{\n%s\n}"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
break;
|
||||
|
||||
case Friend:
|
||||
result.append_fmt( "friend %s", Declaration->to_string() );
|
||||
|
||||
if ( result[ result.length() -1 ] != ';' )
|
||||
result.append( ";" );
|
||||
break;
|
||||
|
||||
case Function:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( Specs )
|
||||
result.append_fmt( "%s\n", Specs->to_string() );
|
||||
|
||||
if ( ReturnType )
|
||||
result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
|
||||
|
||||
else
|
||||
result.append_fmt( "%s(", Name );
|
||||
|
||||
if ( Params )
|
||||
result.append_fmt( "%s)", Params->to_string() );
|
||||
|
||||
else
|
||||
result.append( "void)" );
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
}
|
||||
}
|
||||
|
||||
result.append_fmt( "\n{\n%s\n}"
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case Function_Fwd:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( Specs )
|
||||
result.append_fmt( "%s\n", Specs->to_string() );
|
||||
|
||||
if ( ReturnType )
|
||||
result.append_fmt( "%s %s(", ReturnType->to_string(), Name );
|
||||
|
||||
else
|
||||
result.append_fmt( "%s(", Name );
|
||||
|
||||
if ( Params )
|
||||
result.append_fmt( "%s)", Params->to_string() );
|
||||
|
||||
else
|
||||
result.append( "void)" );
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
}
|
||||
}
|
||||
|
||||
result.append( ";" );
|
||||
}
|
||||
break;
|
||||
|
||||
case Module:
|
||||
if (((u32(ModuleFlag::Export) & u32(ModuleFlags)) == u32(ModuleFlag::Export)))
|
||||
result.append("export ");
|
||||
|
||||
if (((u32(ModuleFlag::Import) & u32(ModuleFlags)) == u32(ModuleFlag::Import)))
|
||||
result.append("import ");
|
||||
|
||||
result.append_fmt( "%s;", Name );
|
||||
break;
|
||||
|
||||
case Namespace:
|
||||
ProcessModuleFlags();
|
||||
|
||||
result.append_fmt( "namespace %s\n{\n%s}"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
break;
|
||||
|
||||
case Operator:
|
||||
case Operator_Member:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s\n", Attributes->to_string() );
|
||||
|
||||
if ( ReturnType )
|
||||
result.append_fmt( "%s %s (", ReturnType->to_string(), Name );
|
||||
|
||||
if ( Params )
|
||||
result.append_fmt( "%s)", Params->to_string() );
|
||||
|
||||
else
|
||||
result.append( "void)" );
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
}
|
||||
}
|
||||
|
||||
result.append_fmt( "\n{\n%s\n}"
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case Operator_Fwd:
|
||||
case Operator_Member_Fwd:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( Specs )
|
||||
result.append_fmt( "%s", Specs->to_string() );
|
||||
|
||||
result.append_fmt( "%s %s (", ReturnType->to_string(), Name );
|
||||
|
||||
if ( Params )
|
||||
result.append_fmt( "%s)", Params->to_string() );
|
||||
|
||||
else
|
||||
result.append_fmt( "void)" );
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
}
|
||||
}
|
||||
|
||||
result.append( ";" );
|
||||
}
|
||||
break;
|
||||
|
||||
case Operator_Cast:
|
||||
{
|
||||
if ( Specs )
|
||||
{
|
||||
result.append_fmt( "operator %s()" );
|
||||
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
}
|
||||
|
||||
result.append_fmt( "\n{\n%s\n}", Body->to_string() );
|
||||
break;
|
||||
}
|
||||
|
||||
result.append_fmt("operator %s()\n{\n%s\n}", ValueType->to_string(), Body->to_string() );
|
||||
}
|
||||
break;
|
||||
|
||||
case Operator_Cast_Fwd:
|
||||
if ( Specs )
|
||||
{
|
||||
result.append_fmt( "operator %s()" );
|
||||
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
}
|
||||
|
||||
result.append_fmt( ";", Body->to_string() );
|
||||
break;
|
||||
}
|
||||
|
||||
result.append_fmt("operator %s();", ValueType->to_string() );
|
||||
break;
|
||||
|
||||
case Parameters:
|
||||
{
|
||||
if ( Name )
|
||||
result.append_fmt( "%s %s", ValueType->to_string(), Name );
|
||||
|
||||
else
|
||||
result.append_fmt( "%s", ValueType->to_string() );
|
||||
|
||||
if ( Value )
|
||||
result.append_fmt( "= %s", Value->to_string() );
|
||||
|
||||
if ( NumEntries - 1 > 0)
|
||||
{
|
||||
for ( CodeParam param : CodeParam { (AST_Param*) Next } )
|
||||
{
|
||||
result.append_fmt( ", %s", param.to_string() );
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Preprocessor_Include:
|
||||
result.append_fmt( "#include \"%s\"", Name );
|
||||
break;
|
||||
|
||||
case Specifiers:
|
||||
{
|
||||
s32 idx = 0;
|
||||
s32 left = NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( ArrSpecs[idx]) )
|
||||
{
|
||||
idx++;
|
||||
continue;
|
||||
}
|
||||
|
||||
result.append_fmt( "%s ", (char const*)ESpecifier::to_str( ArrSpecs[idx]) );
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Struct:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Name == nullptr)
|
||||
{
|
||||
result.append( "struct\n{\n%s\n};", Body->to_string() );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( Attributes || ParentType )
|
||||
{
|
||||
result.append( "struct " );
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( ParentType )
|
||||
{
|
||||
char const* access_level = to_str( ParentAccess );
|
||||
|
||||
result.append_fmt( "%s : %s %s\n{\n%s\n};"
|
||||
, Name
|
||||
, access_level
|
||||
, ParentType->to_string()
|
||||
, Body->to_string()
|
||||
);
|
||||
|
||||
CodeType interface = Next->cast<CodeType>();
|
||||
if ( interface )
|
||||
result.append("\n");
|
||||
|
||||
while ( interface )
|
||||
{
|
||||
result.append_fmt( ", public %s", interface.to_string() );
|
||||
|
||||
interface = interface->Next->cast<CodeType>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Name )
|
||||
|
||||
result.append_fmt( "%s \n{\n%s\n};", Name, Body->to_string() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append_fmt( "struct %s\n{\n%s\n};", Name, Body->to_string() );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Struct_Fwd:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "struct %s %s;", Attributes->to_string(), Name );
|
||||
|
||||
else result.append_fmt( "struct %s;", Name );
|
||||
}
|
||||
break;
|
||||
|
||||
case Template:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
result.append_fmt( "template< %s >\n%s", Params->to_string(), Declaration->to_string() );
|
||||
}
|
||||
break;
|
||||
|
||||
case Typedef:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
result.append( "typedef ");
|
||||
|
||||
result.append_fmt( "%s %s", UnderlyingType->to_string(), Name );
|
||||
|
||||
if ( UnderlyingType->Type == Typename && UnderlyingType->ArrExpr )
|
||||
{
|
||||
result.append_fmt( "[%s];", UnderlyingType->ArrExpr->to_string() );
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append( ";" );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Typename:
|
||||
{
|
||||
if ( Attributes || Specs )
|
||||
{
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( Specs )
|
||||
result.append_fmt( "%s %s", Name, Specs->to_string() );
|
||||
|
||||
else
|
||||
result.append_fmt( "%s", Name );
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append_fmt( "%s", Name );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Union:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
result.append( "union " );
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( Name )
|
||||
{
|
||||
result.append_fmt( "%s\n{\n%s\n};"
|
||||
, Name
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Anonymous union
|
||||
result.append_fmt( "\n{\n%s\n};"
|
||||
, Body->to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Using:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Attributes->to_string() );
|
||||
|
||||
if ( UnderlyingType )
|
||||
{
|
||||
result.append_fmt( "using %s = %s", Name, UnderlyingType->to_string() );
|
||||
|
||||
if ( UnderlyingType->ArrExpr )
|
||||
result.append_fmt( "[%s]", UnderlyingType->ArrExpr->to_string() );
|
||||
|
||||
result.append( ";" );
|
||||
}
|
||||
else
|
||||
result.append_fmt( "using %s;", Name );
|
||||
}
|
||||
break;
|
||||
|
||||
case Using_Namespace:
|
||||
result.append_fmt( "using namespace %s;", Name );
|
||||
break;
|
||||
|
||||
case Variable:
|
||||
{
|
||||
ProcessModuleFlags();
|
||||
|
||||
if ( Attributes || Specs )
|
||||
{
|
||||
if ( Attributes )
|
||||
result.append_fmt( "%s ", Specs->to_string() );
|
||||
|
||||
if ( Specs )
|
||||
result.append_fmt( "%s\n", Specs->to_string() );
|
||||
|
||||
result.append_fmt( "%s %s", ValueType->to_string(), Name );
|
||||
|
||||
if ( ValueType->ArrExpr )
|
||||
result.append_fmt( "[%s]", ValueType->ArrExpr->to_string() );
|
||||
|
||||
if ( Value )
|
||||
result.append_fmt( " = %s", Value->to_string() );
|
||||
|
||||
result.append( ";" );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ( UnderlyingType->ArrExpr )
|
||||
result.append_fmt( "%s %s[%s];", UnderlyingType->to_string(), Name, UnderlyingType->ArrExpr->to_string() );
|
||||
|
||||
else
|
||||
result.append_fmt( "%s %s;", UnderlyingType->to_string(), Name );
|
||||
}
|
||||
break;
|
||||
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Extern_Linkage_Body:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
{
|
||||
Code curr = Front->cast<Code>();
|
||||
s32 left = NumEntries;
|
||||
while ( left -- )
|
||||
{
|
||||
result.append_fmt( "%s\n", curr.to_string() );
|
||||
++curr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(GEN_BENCHMARK) && defined(GEN_BENCHMARK_SERIALIZATION)
|
||||
log_fmt("AST::to_string() time taken: %llu for: %s\n", time_rel_ms() - time_start, result );
|
||||
#endif
|
||||
return result;
|
||||
#undef ProcessModuleFlags
|
||||
}
|
||||
|
||||
bool AST::is_equal( AST* other )
|
||||
{
|
||||
if ( Type != other->Type )
|
||||
return false;
|
||||
|
||||
switch ( Type )
|
||||
{
|
||||
case ECode::Typedef:
|
||||
case ECode::Typename:
|
||||
{
|
||||
if ( Name != other->Name )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( Name != other->Name )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AST::validate_body()
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
#define CheckEntries( Unallowed_Types ) \
|
||||
do \
|
||||
{ \
|
||||
for ( Code entry : cast<CodeBody>() ) \
|
||||
{ \
|
||||
switch ( entry->Type ) \
|
||||
{ \
|
||||
Unallowed_Types \
|
||||
log_failure( "AST::validate_body: Invalid entry in body %s", entry.debug_str() ); \
|
||||
return false; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
while (0);
|
||||
|
||||
switch ( Type )
|
||||
{
|
||||
case Class_Body:
|
||||
CheckEntries( AST_BODY_CLASS_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Enum_Body:
|
||||
for ( Code entry : cast<CodeBody>() )
|
||||
{
|
||||
if ( entry->Type != Untyped )
|
||||
{
|
||||
log_failure( "AST::validate_body: Invalid entry in enum body (needs to be untyped or comment) %s", entry.debug_str() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Export_Body:
|
||||
CheckEntries( AST_BODY_CLASS_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Extern_Linkage:
|
||||
CheckEntries( AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Function_Body:
|
||||
CheckEntries( AST_BODY_FUNCTION_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Global_Body:
|
||||
CheckEntries( AST_BODY_GLOBAL_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Namespace_Body:
|
||||
CheckEntries( AST_BODY_NAMESPACE_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Struct_Body:
|
||||
CheckEntries( AST_BODY_STRUCT_UNALLOWED_TYPES );
|
||||
break;
|
||||
case Union_Body:
|
||||
for ( Code entry : Body->cast<CodeBody>() )
|
||||
{
|
||||
if ( entry->Type != Untyped )
|
||||
{
|
||||
log_failure( "AST::validate_body: Invalid entry in union body (needs to be untyped or comment) %s", entry.debug_str() );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "AST::validate_body: Invalid this AST does not have a body %s", debug_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#pragma endregion AST
|
@ -1,81 +0,0 @@
|
||||
# define AST_BODY_CLASS_UNALLOWED_TYPES \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Extern_Linkage: \
|
||||
case Function_Body: \
|
||||
case Function_Fwd: \
|
||||
case Global_Body: \
|
||||
case Namespace: \
|
||||
case Namespace_Body: \
|
||||
case Operator: \
|
||||
case Operator_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
# define AST_BODY_FUNCTION_UNALLOWED_TYPES \
|
||||
case Access_Public: \
|
||||
case Access_Protected: \
|
||||
case Access_Private: \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Extern_Linkage: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Function_Fwd: \
|
||||
case Global_Body: \
|
||||
case Namespace: \
|
||||
case Namespace_Body: \
|
||||
case Operator: \
|
||||
case Operator_Fwd: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
# define AST_BODY_GLOBAL_UNALLOWED_TYPES \
|
||||
case Access_Public: \
|
||||
case Access_Protected: \
|
||||
case Access_Private: \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Execution: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Global_Body: \
|
||||
case Namespace_Body: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
# define AST_BODY_EXPORT_UNALLOWED_TYPES AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
# define AST_BODY_NAMESPACE_UNALLOWED_TYPES \
|
||||
case Access_Public: \
|
||||
case Access_Protected: \
|
||||
case Access_Private: \
|
||||
case PlatformAttributes: \
|
||||
case Class_Body: \
|
||||
case Enum_Body: \
|
||||
case Execution: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Namespace_Body: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
case Parameters: \
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
# define AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
|
||||
# define AST_BODY_STRUCT_UNALLOWED_TYPES AST_BODY_CLASS_UNALLOWED_TYPES
|
File diff suppressed because it is too large
Load Diff
@ -1,78 +0,0 @@
|
||||
// This is the non-bootstraped version of the ECode. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
namespace ECode
|
||||
{
|
||||
# define Define_Types \
|
||||
Entry( Invalid ) \
|
||||
Entry( Untyped ) \
|
||||
Entry( Comment ) \
|
||||
Entry( Access_Private ) \
|
||||
Entry( Access_Protected ) \
|
||||
Entry( Access_Public ) \
|
||||
Entry( PlatformAttributes ) \
|
||||
Entry( Class ) \
|
||||
Entry( Class_Fwd ) \
|
||||
Entry( Class_Body ) \
|
||||
Entry( Enum ) \
|
||||
Entry( Enum_Fwd ) \
|
||||
Entry( Enum_Body ) \
|
||||
Entry( Enum_Class ) \
|
||||
Entry( Enum_Class_Fwd ) \
|
||||
Entry( Execution ) \
|
||||
Entry( Export_Body ) \
|
||||
Entry( Extern_Linkage ) \
|
||||
Entry( Extern_Linkage_Body ) \
|
||||
Entry( Friend ) \
|
||||
Entry( Function ) \
|
||||
Entry( Function_Fwd ) \
|
||||
Entry( Function_Body ) \
|
||||
Entry( Global_Body ) \
|
||||
Entry( Module ) \
|
||||
Entry( Namespace ) \
|
||||
Entry( Namespace_Body ) \
|
||||
Entry( Operator ) \
|
||||
Entry( Operator_Fwd ) \
|
||||
Entry( Operator_Member ) \
|
||||
Entry( Operator_Member_Fwd ) \
|
||||
Entry( Operator_Cast ) \
|
||||
Entry( Operator_Cast_Fwd ) \
|
||||
Entry( Parameters ) \
|
||||
Entry( Preprocessor_Include ) \
|
||||
Entry( Specifiers ) \
|
||||
Entry( Struct ) \
|
||||
Entry( Struct_Fwd ) \
|
||||
Entry( Struct_Body ) \
|
||||
Entry( Template ) \
|
||||
Entry( Typedef ) \
|
||||
Entry( Typename ) \
|
||||
Entry( Union ) \
|
||||
Entry( Union_Body) \
|
||||
Entry( Using ) \
|
||||
Entry( Using_Namespace ) \
|
||||
Entry( Variable )
|
||||
|
||||
enum Type : u32
|
||||
{
|
||||
# define Entry( Type ) Type,
|
||||
Define_Types
|
||||
# undef Entry
|
||||
|
||||
Num_Types
|
||||
};
|
||||
|
||||
inline
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
static
|
||||
StrC lookup[Num_Types] = {
|
||||
# define Entry( Type ) { sizeof(stringize(Type)), stringize(Type) },
|
||||
Define_Types
|
||||
# undef Entry
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
|
||||
# undef Define_Types
|
||||
}
|
||||
using CodeT = ECode::Type;
|
@ -1,75 +0,0 @@
|
||||
// This is the non-bootstraped version of the EOperator. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
namespace EOperator
|
||||
{
|
||||
# define Define_Operators \
|
||||
Entry( Invalid, INVALID ) \
|
||||
Entry( Assign, = ) \
|
||||
Entry( Assign_Add, += ) \
|
||||
Entry( Assign_Subtract, -= ) \
|
||||
Entry( Assign_Multiply, *= ) \
|
||||
Entry( Assign_Divide, /= ) \
|
||||
Entry( Assign_Modulo, %= ) \
|
||||
Entry( Assign_BAnd, &= ) \
|
||||
Entry( Assign_BOr, |= ) \
|
||||
Entry( Assign_BXOr, ^= ) \
|
||||
Entry( Assign_LShift, <<= ) \
|
||||
Entry( Assign_RShift, >>= ) \
|
||||
Entry( Increment, ++ ) \
|
||||
Entry( Decrement, -- ) \
|
||||
Entry( Unary_Plus, + ) \
|
||||
Entry( Unary_Minus, - ) \
|
||||
Entry( UnaryNot, ! ) \
|
||||
Entry( Add, + ) \
|
||||
Entry( Subtract, - ) \
|
||||
Entry( Multiply, * ) \
|
||||
Entry( Divide, / ) \
|
||||
Entry( Modulo, % ) \
|
||||
Entry( BNot, ~ ) \
|
||||
Entry( BAnd, & ) \
|
||||
Entry( BOr, | ) \
|
||||
Entry( BXOr, ^ ) \
|
||||
Entry( LShift, << ) \
|
||||
Entry( RShift, >> ) \
|
||||
Entry( LAnd, && ) \
|
||||
Entry( LOr, || ) \
|
||||
Entry( LEqual, == ) \
|
||||
Entry( LNot, != ) \
|
||||
Entry( Lesser, < ) \
|
||||
Entry( Greater, > ) \
|
||||
Entry( LesserEqual, <= ) \
|
||||
Entry( GreaterEqual, >= ) \
|
||||
Entry( Subscript, [] ) \
|
||||
Entry( Indirection, * ) \
|
||||
Entry( AddressOf, & ) \
|
||||
Entry( MemberOfPointer, -> ) \
|
||||
Entry( PtrToMemOfPtr, ->* ) \
|
||||
Entry( FunctionCall, () )
|
||||
|
||||
enum Type : u32
|
||||
{
|
||||
# define Entry( Type_, Token_ ) Type_,
|
||||
Define_Operators
|
||||
# undef Entry
|
||||
Comma,
|
||||
|
||||
Num_Ops,
|
||||
};
|
||||
|
||||
inline
|
||||
char const* to_str( Type op )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[ Num_Ops ] = {
|
||||
# define Entry( Type_, Token_ ) stringize(Token_),
|
||||
Define_Operators
|
||||
# undef Entry
|
||||
","
|
||||
};
|
||||
|
||||
return lookup[ op ];
|
||||
}
|
||||
|
||||
# undef Define_Operators
|
||||
}
|
||||
using OperatorT = EOperator::Type;
|
@ -1,105 +0,0 @@
|
||||
// This is the non-bootstraped version of the ESpecifier. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
namespace ESpecifier
|
||||
{
|
||||
/*
|
||||
Note: The following are handled separately:
|
||||
attributes
|
||||
alignas
|
||||
*/
|
||||
|
||||
# define Define_Specifiers \
|
||||
Entry( Invalid, INVALID ) \
|
||||
Entry( Consteval, consteval ) \
|
||||
Entry( Constexpr, constexpr ) \
|
||||
Entry( Constinit, constinit ) \
|
||||
Entry( Explicit, explicit ) \
|
||||
Entry( External_Linkage, extern ) \
|
||||
Entry( Global, global ) \
|
||||
Entry( Inline, inline ) \
|
||||
Entry( Internal_Linkage, internal ) \
|
||||
Entry( Local_Persist, local_persist ) \
|
||||
Entry( Mutable, mutable ) \
|
||||
Entry( Ptr, * ) \
|
||||
Entry( Ref, & ) \
|
||||
Entry( Register, register ) \
|
||||
Entry( RValue, && ) \
|
||||
Entry( Static, static ) \
|
||||
Entry( Thread_Local, thread_local ) \
|
||||
Entry( Volatile, volatile ) \
|
||||
Entry( Virtual, virtual ) \
|
||||
Entry( Const, const ) \
|
||||
Entry( Final, final ) \
|
||||
Entry( Override, override )
|
||||
|
||||
enum Type : u32
|
||||
{
|
||||
# define Entry( Specifier, Code ) Specifier,
|
||||
Define_Specifiers
|
||||
# undef Entry
|
||||
|
||||
NumSpecifiers,
|
||||
};
|
||||
|
||||
inline
|
||||
bool is_trailing( Type specifier )
|
||||
{
|
||||
return specifier > Virtual;
|
||||
}
|
||||
|
||||
// Specifier to string
|
||||
inline
|
||||
StrC to_str( Type specifier )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ NumSpecifiers ] = {
|
||||
# pragma push_macro( "global" )
|
||||
# pragma push_macro( "internal" )
|
||||
# pragma push_macro( "local_persist" )
|
||||
# undef global
|
||||
# undef internal
|
||||
# undef local_persist
|
||||
|
||||
# define Entry( Spec_, Code_ ) { sizeof(stringize(Code_)), stringize(Code_) },
|
||||
Define_Specifiers
|
||||
# undef Entry
|
||||
|
||||
# pragma pop_macro( "global" )
|
||||
# pragma pop_macro( "internal" )
|
||||
# pragma pop_macro( "local_persist" )
|
||||
};
|
||||
|
||||
return lookup[ specifier ];
|
||||
}
|
||||
|
||||
inline
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ NumSpecifiers ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Type)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
||||
}
|
||||
do_once_end
|
||||
|
||||
u32 hash = crc32( str.Ptr, str.Len );
|
||||
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (Type)index;
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
# undef Define_Specifiers
|
||||
}
|
||||
|
||||
using SpecifierT = ESpecifier::Type;
|
@ -1,141 +0,0 @@
|
||||
namespace Parser
|
||||
{
|
||||
/*
|
||||
This is a simple lexer that focuses on tokenizing only tokens relevant to the library.
|
||||
It will not be capable of lexing C++ code with unsupported features.
|
||||
|
||||
For the sake of scanning files, it can scan preprocessor directives
|
||||
|
||||
Attributes_Start is only used to indicate the start of the user_defined attribute list.
|
||||
*/
|
||||
|
||||
# define Define_TokType \
|
||||
Entry( Invalid, "INVALID" ) \
|
||||
Entry( Access_Private, "private" ) \
|
||||
Entry( Access_Protected, "protected" ) \
|
||||
Entry( Access_Public, "public" ) \
|
||||
Entry( Access_MemberSymbol, "." ) \
|
||||
Entry( Access_StaticSymbol, "::") \
|
||||
Entry( Ampersand, "&" ) \
|
||||
Entry( Ampersand_DBL, "&&" ) \
|
||||
Entry( Assign_Classifer, ":" ) \
|
||||
Entry( Attribute_Open, "[[" ) \
|
||||
Entry( Attribute_Close, "]]" ) \
|
||||
Entry( BraceCurly_Open, "{" ) \
|
||||
Entry( BraceCurly_Close, "}" ) \
|
||||
Entry( BraceSquare_Open, "[" ) \
|
||||
Entry( BraceSquare_Close, "]" ) \
|
||||
Entry( Capture_Start, "(" ) \
|
||||
Entry( Capture_End, ")" ) \
|
||||
Entry( Comment, "__comment__" ) \
|
||||
Entry( Char, "__char__" ) \
|
||||
Entry( Comma, "," ) \
|
||||
Entry( Decl_Class, "class" ) \
|
||||
Entry( Decl_GNU_Attribute, "__attribute__" ) \
|
||||
Entry( Decl_MSVC_Attribute, "__declspec" ) \
|
||||
Entry( Decl_Enum, "enum" ) \
|
||||
Entry( Decl_Extern_Linkage, "extern" ) \
|
||||
Entry( Decl_Friend, "friend" ) \
|
||||
Entry( Decl_Module, "module" ) \
|
||||
Entry( Decl_Namespace, "namespace" ) \
|
||||
Entry( Decl_Operator, "operator" ) \
|
||||
Entry( Decl_Struct, "struct" ) \
|
||||
Entry( Decl_Template, "template" ) \
|
||||
Entry( Decl_Typedef, "typedef" ) \
|
||||
Entry( Decl_Using, "using" ) \
|
||||
Entry( Decl_Union, "union" ) \
|
||||
Entry( Identifier, "__identifier__" ) \
|
||||
Entry( Module_Import, "import" ) \
|
||||
Entry( Module_Export, "export" ) \
|
||||
Entry( Number, "number" ) \
|
||||
Entry( Operator, "operator" ) \
|
||||
Entry( Preprocessor_Directive, "#") \
|
||||
Entry( Preprocessor_Include, "include" ) \
|
||||
Entry( Spec_Alignas, "alignas" ) \
|
||||
Entry( Spec_Const, "const" ) \
|
||||
Entry( Spec_Consteval, "consteval" ) \
|
||||
Entry( Spec_Constexpr, "constexpr" ) \
|
||||
Entry( Spec_Constinit, "constinit" ) \
|
||||
Entry( Spec_Explicit, "explicit" ) \
|
||||
Entry( Spec_Extern, "extern" ) \
|
||||
Entry( Spec_Final, "final" ) \
|
||||
Entry( Spec_Global, "global" ) \
|
||||
Entry( Spec_Inline, "inline" ) \
|
||||
Entry( Spec_Internal_Linkage, "internal" ) \
|
||||
Entry( Spec_LocalPersist, "local_persist" ) \
|
||||
Entry( Spec_Mutable, "mutable" ) \
|
||||
Entry( Spec_Override, "override" ) \
|
||||
Entry( Spec_Static, "static" ) \
|
||||
Entry( Spec_ThreadLocal, "thread_local" ) \
|
||||
Entry( Spec_Volatile, "volatile") \
|
||||
Entry( Star, "*" ) \
|
||||
Entry( Statement_End, ";" ) \
|
||||
Entry( String, "__string__" ) \
|
||||
Entry( Type_Unsigned, "unsigned" ) \
|
||||
Entry( Type_Signed, "signed" ) \
|
||||
Entry( Type_Short, "short" ) \
|
||||
Entry( Type_Long, "long" ) \
|
||||
Entry( Type_char, "char" ) \
|
||||
Entry( Type_int, "int" ) \
|
||||
Entry( Type_double, "double" ) \
|
||||
Entry( Varadic_Argument, "..." ) \
|
||||
Entry( Attributes_Start, "__attrib_start__" )
|
||||
|
||||
namespace ETokType
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
# define Entry( Name_, Str_ ) Name_,
|
||||
Define_TokType
|
||||
GEN_Define_Attribute_Tokens
|
||||
# undef Entry
|
||||
NumTokens,
|
||||
};
|
||||
|
||||
internal inline
|
||||
Type to_type( StrC str_tok )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[(u32)NumTokens] =
|
||||
{
|
||||
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
|
||||
Define_TokType
|
||||
GEN_Define_Attribute_Tokens
|
||||
# undef Entry
|
||||
};
|
||||
|
||||
for ( u32 index = 0; index < (u32)NumTokens; index++ )
|
||||
{
|
||||
s32 lookup_len = lookup[index].Len - 1;
|
||||
char const* lookup_str = lookup[index].Ptr;
|
||||
|
||||
if ( lookup_len != str_tok.Len )
|
||||
continue;
|
||||
|
||||
if ( str_compare( str_tok.Ptr, lookup_str, lookup_len ) == 0 )
|
||||
return scast(Type, index);
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
internal inline
|
||||
char const* to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[(u32)NumTokens] =
|
||||
{
|
||||
# define Entry( Name_, Str_ ) Str_,
|
||||
Define_TokType
|
||||
GEN_Define_Attribute_Tokens
|
||||
# undef Entry
|
||||
};
|
||||
|
||||
return lookup[(u32)type];
|
||||
}
|
||||
# undef Define_TokType
|
||||
};
|
||||
|
||||
using TokType = ETokType::Type;
|
||||
|
||||
} // Parser
|
@ -1,520 +0,0 @@
|
||||
#pragma region Inlines
|
||||
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
other = other->duplicate();
|
||||
|
||||
other->Parent = this;
|
||||
|
||||
if ( Front == nullptr )
|
||||
{
|
||||
Front = other;
|
||||
Back = other;
|
||||
|
||||
NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
AST*
|
||||
Current = Back;
|
||||
Current->Next = other;
|
||||
other->Prev = Current;
|
||||
Back = other;
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
char const* AST::debug_str()
|
||||
{
|
||||
char const* fmt = stringize(
|
||||
\nCode Debug:
|
||||
\nType : %s
|
||||
\nParent : %s
|
||||
\nName : %s
|
||||
\nComment : %s
|
||||
);
|
||||
|
||||
// These should be used immediately in a log.
|
||||
// Thus if its desired to keep the debug str
|
||||
// for multiple calls to bprintf,
|
||||
// allocate this to proper string.
|
||||
return str_fmt_buf( fmt
|
||||
, type_str()
|
||||
, Parent ? Parent->Name : ""
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
Code& AST::entry( u32 idx )
|
||||
{
|
||||
AST** current = & Front;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
if ( idx == 0 )
|
||||
return * rcast( Code*, current);
|
||||
|
||||
current = & ( * current )->Next;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return * rcast( Code*, current);
|
||||
}
|
||||
|
||||
bool AST::has_entries()
|
||||
{
|
||||
return NumEntries;
|
||||
}
|
||||
|
||||
char const* AST::type_str()
|
||||
{
|
||||
return ECode::to_str( Type );
|
||||
}
|
||||
|
||||
AST::operator Code()
|
||||
{
|
||||
return { this };
|
||||
}
|
||||
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
ast = ast->Next;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma region AST & Code Gen Common
|
||||
#define Define_CodeImpl( Typename ) \
|
||||
char const* Typename::debug_str() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
return "Code::debug_str: AST is null!"; \
|
||||
\
|
||||
return rcast(AST*, ast)->debug_str(); \
|
||||
} \
|
||||
Code Typename::duplicate() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); \
|
||||
return Code::Invalid; \
|
||||
} \
|
||||
\
|
||||
return { rcast(AST*, ast)->duplicate() }; \
|
||||
} \
|
||||
bool Typename::is_equal( Code other ) \
|
||||
{ \
|
||||
if ( ast == nullptr || other.ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::is_equal: Cannot compare code, AST is null!"); \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->is_equal( other.ast ); \
|
||||
} \
|
||||
bool Typename::is_valid() \
|
||||
{ \
|
||||
return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid; \
|
||||
} \
|
||||
void Typename::set_global() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::set_global: Cannot set code as global, AST is null!"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
rcast(AST*, ast)->Parent = Code::Global.ast; \
|
||||
} \
|
||||
String Typename::to_string() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::to_string: Cannot convert code to string, AST is null!"); \
|
||||
return { nullptr }; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->to_string(); \
|
||||
} \
|
||||
Typename& Typename::operator =( Code other ) \
|
||||
{ \
|
||||
if ( other.ast && other->Parent ) \
|
||||
{ \
|
||||
ast = rcast( decltype(ast), other.ast->duplicate() ); \
|
||||
rcast( AST*, ast)->Parent = nullptr; \
|
||||
} \
|
||||
\
|
||||
ast = rcast( decltype(ast), other.ast ); \
|
||||
return *this; \
|
||||
} \
|
||||
bool Typename::operator ==( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast == other.ast; \
|
||||
} \
|
||||
bool Typename::operator !=( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast != other.ast; \
|
||||
}
|
||||
|
||||
Define_CodeImpl( Code );
|
||||
Define_CodeImpl( CodeBody );
|
||||
Define_CodeImpl( CodeAttributes );
|
||||
Define_CodeImpl( CodeComment );
|
||||
Define_CodeImpl( CodeClass );
|
||||
Define_CodeImpl( CodeEnum );
|
||||
Define_CodeImpl( CodeExec );
|
||||
Define_CodeImpl( CodeExtern );
|
||||
Define_CodeImpl( CodeInclude );
|
||||
Define_CodeImpl( CodeFriend );
|
||||
Define_CodeImpl( CodeFn );
|
||||
Define_CodeImpl( CodeModule );
|
||||
Define_CodeImpl( CodeNamespace );
|
||||
Define_CodeImpl( CodeOperator );
|
||||
Define_CodeImpl( CodeOpCast );
|
||||
Define_CodeImpl( CodeParam );
|
||||
Define_CodeImpl( CodeSpecifiers );
|
||||
Define_CodeImpl( CodeStruct );
|
||||
Define_CodeImpl( CodeTemplate );
|
||||
Define_CodeImpl( CodeType );
|
||||
Define_CodeImpl( CodeTypedef );
|
||||
Define_CodeImpl( CodeUnion );
|
||||
Define_CodeImpl( CodeUsing );
|
||||
Define_CodeImpl( CodeVar );
|
||||
#undef Define_CodeImpl
|
||||
|
||||
#define Define_AST_Cast( typename ) \
|
||||
AST::operator Code ## typename() \
|
||||
{ \
|
||||
return { rcast( AST_ ## typename*, this ) }; \
|
||||
}
|
||||
|
||||
Define_AST_Cast( Body );
|
||||
Define_AST_Cast( Attributes );
|
||||
Define_AST_Cast( Comment );
|
||||
Define_AST_Cast( Class );
|
||||
Define_AST_Cast( Enum );
|
||||
Define_AST_Cast( Exec );
|
||||
Define_AST_Cast( Extern );
|
||||
Define_AST_Cast( Include );
|
||||
Define_AST_Cast( Friend );
|
||||
Define_AST_Cast( Fn );
|
||||
Define_AST_Cast( Module );
|
||||
Define_AST_Cast( Namespace );
|
||||
Define_AST_Cast( Operator );
|
||||
Define_AST_Cast( OpCast );
|
||||
Define_AST_Cast( Param );
|
||||
Define_AST_Cast( Struct );
|
||||
Define_AST_Cast( Specifiers );
|
||||
Define_AST_Cast( Template );
|
||||
Define_AST_Cast( Type );
|
||||
Define_AST_Cast( Typedef );
|
||||
Define_AST_Cast( Union );
|
||||
Define_AST_Cast( Using );
|
||||
Define_AST_Cast( Var );
|
||||
#undef Define_AST_Cast
|
||||
|
||||
#define Define_CodeCast( type ) \
|
||||
Code::operator Code ## type() const \
|
||||
{ \
|
||||
return { (AST_ ## type*) ast }; \
|
||||
}
|
||||
|
||||
Define_CodeCast( Attributes );
|
||||
Define_CodeCast( Comment );
|
||||
Define_CodeCast( Class );
|
||||
Define_CodeCast( Exec );
|
||||
Define_CodeCast( Enum );
|
||||
Define_CodeCast( Extern );
|
||||
Define_CodeCast( Include );
|
||||
Define_CodeCast( Friend );
|
||||
Define_CodeCast( Fn );
|
||||
Define_CodeCast( Module );
|
||||
Define_CodeCast( Namespace );
|
||||
Define_CodeCast( Operator );
|
||||
Define_CodeCast( OpCast );
|
||||
Define_CodeCast( Param );
|
||||
Define_CodeCast( Specifiers );
|
||||
Define_CodeCast( Struct );
|
||||
Define_CodeCast( Template );
|
||||
Define_CodeCast( Type );
|
||||
Define_CodeCast( Typedef );
|
||||
Define_CodeCast( Union );
|
||||
Define_CodeCast( Using );
|
||||
Define_CodeCast( Var );
|
||||
Define_CodeCast( Body);
|
||||
#undef Define_CodeCast
|
||||
#pragma endregion AST & Code Gen Common
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
return;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = entry->duplicate();
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
if ( self->Last == nullptr )
|
||||
{
|
||||
self->Last = entry;
|
||||
self->Next = entry;
|
||||
self->NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
self->Last->Next = entry;
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
return { (AST_Param*) param.raw()->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
bool CodeParam::has_entries()
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
}
|
||||
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Export_Body:
|
||||
case Extern_Linkage:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
||||
return (CodeBody)Code::Invalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = type;
|
||||
return (CodeBody)result;
|
||||
}
|
||||
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
||||
|
||||
va_list va;
|
||||
va_start(va, num );
|
||||
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
}
|
||||
#pragma endregion Inlines
|
||||
|
||||
#pragma region Constants
|
||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
// Predefined typename codes. Are set to readonly and are setup during gen::init()
|
||||
|
||||
extern CodeType t_b32;
|
||||
|
||||
extern CodeType t_s8;
|
||||
extern CodeType t_s16;
|
||||
extern CodeType t_s32;
|
||||
extern CodeType t_s64;
|
||||
|
||||
extern CodeType t_u8;
|
||||
extern CodeType t_u16;
|
||||
extern CodeType t_u32;
|
||||
extern CodeType t_u64;
|
||||
|
||||
extern CodeType t_sw;
|
||||
extern CodeType t_uw;
|
||||
|
||||
extern CodeType t_f32;
|
||||
extern CodeType t_f64;
|
||||
#endif
|
||||
|
||||
#ifndef GEN_GLOBAL_BUCKET_SIZE
|
||||
# define GEN_GLOBAL_BUCKET_SIZE megabytes(10)
|
||||
#endif
|
||||
#ifndef GEN_CODEPOOL_NUM_BLOCKS
|
||||
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(64)
|
||||
#endif
|
||||
#ifndef GEN_SIZE_PER_STRING_ARENA
|
||||
# define GEN_SIZE_PER_STRING_ARENA megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_MAX_COMMENT_LINE_LENGTH
|
||||
# define GEN_MAX_COMMENT_LINE_LENGTH 1024
|
||||
#endif
|
||||
#ifndef GEN_MAX_NAME_LENGTH
|
||||
# define GEN_MAX_NAME_LENGTH 128
|
||||
#endif
|
||||
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
|
||||
#endif
|
||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(10)
|
||||
#endif
|
||||
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
|
||||
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(1)
|
||||
#endif
|
||||
|
||||
// These constexprs are used for allocation behavior of data structures
|
||||
// or string handling while constructing or serializing.
|
||||
// Change them to suit your needs.
|
||||
|
||||
constexpr s32 InitSize_DataArrays = 16;
|
||||
|
||||
// NOTE: This limits the maximum size of an allocation
|
||||
// If you are generating a string larger than this, increase the size of the bucket here.
|
||||
constexpr uw Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
||||
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
|
||||
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
||||
|
||||
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
||||
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
||||
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
|
||||
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
||||
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||
|
||||
extern CodeType t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
|
||||
extern CodeType t_auto;
|
||||
extern CodeType t_void;
|
||||
extern CodeType t_int;
|
||||
extern CodeType t_bool;
|
||||
extern CodeType t_char;
|
||||
extern CodeType t_wchar_t;
|
||||
extern CodeType t_class;
|
||||
extern CodeType t_typename;
|
||||
|
||||
extern CodeParam param_varadic;
|
||||
|
||||
extern CodeAttributes attrib_api_export;
|
||||
extern CodeAttributes attrib_api_import;
|
||||
|
||||
extern Code access_public;
|
||||
extern Code access_protected;
|
||||
extern Code access_private;
|
||||
|
||||
extern Code module_global_fragment;
|
||||
extern Code module_private_fragment;
|
||||
|
||||
extern Code pragma_once;
|
||||
|
||||
extern CodeSpecifiers spec_const;
|
||||
extern CodeSpecifiers spec_consteval;
|
||||
extern CodeSpecifiers spec_constexpr;
|
||||
extern CodeSpecifiers spec_constinit;
|
||||
extern CodeSpecifiers spec_extern_linkage;
|
||||
extern CodeSpecifiers spec_final;
|
||||
extern CodeSpecifiers spec_global;
|
||||
extern CodeSpecifiers spec_inline;
|
||||
extern CodeSpecifiers spec_internal_linkage;
|
||||
extern CodeSpecifiers spec_local_persist;
|
||||
extern CodeSpecifiers spec_mutable;
|
||||
extern CodeSpecifiers spec_override;
|
||||
extern CodeSpecifiers spec_ptr;
|
||||
extern CodeSpecifiers spec_ref;
|
||||
extern CodeSpecifiers spec_register;
|
||||
extern CodeSpecifiers spec_rvalue;
|
||||
extern CodeSpecifiers spec_static_member;
|
||||
extern CodeSpecifiers spec_thread_local;
|
||||
extern CodeSpecifiers spec_virtual;
|
||||
extern CodeSpecifiers spec_volatile;
|
||||
#pragma endregion Constants
|
||||
|
||||
#pragma region Macros
|
||||
# define gen_main main
|
||||
|
||||
# define __ NoCode
|
||||
|
||||
// Convienence for defining any name used with the gen api.
|
||||
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
||||
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
||||
|
||||
// Same as name just used to indicate intention of literal for code instead of names.
|
||||
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
||||
|
||||
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
||||
|
||||
# define code_str( ... ) gen::untyped_str( code( __VA_ARGS__ ) )
|
||||
# define code_fmt( ... ) gen::untyped_str( token_fmt( __VA_ARGS__ ) )
|
||||
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
# define token_fmt( ... ) gen::token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
#pragma endregion Macros
|
||||
|
||||
#ifdef GEN_EXPOSE_BACKEND
|
||||
// Global allocator used for data with process lifetime.
|
||||
extern AllocatorInfo GlobalAllocator;
|
||||
extern Array< Arena > Global_AllocatorBuckets;
|
||||
extern Array< Pool > CodePools;
|
||||
extern Array< Arena > StringArenas;
|
||||
|
||||
extern StringTable StringCache;
|
||||
|
||||
extern Arena LexArena;
|
||||
|
||||
extern AllocatorInfo Allocator_DataArrays;
|
||||
extern AllocatorInfo Allocator_CodePool;
|
||||
extern AllocatorInfo Allocator_Lexer;
|
||||
extern AllocatorInfo Allocator_StringArena;
|
||||
extern AllocatorInfo Allocator_StringTable;
|
||||
extern AllocatorInfo Allocator_TypeTable;
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,109 +0,0 @@
|
||||
using LogFailType = sw(*)(char const*, ...);
|
||||
|
||||
// By default this library will either crash or exit if an error is detected while generating codes.
|
||||
// Even if set to not use fatal, fatal will still be used for memory failures as the library is unusable when they occur.
|
||||
#ifdef GEN_DONT_USE_FATAL
|
||||
constexpr LogFailType log_failure = log_fmt;
|
||||
#else
|
||||
constexpr LogFailType log_failure = fatal;
|
||||
#endif
|
||||
|
||||
// Used to indicate if enum definitoin is an enum class or regular enum.
|
||||
enum class EnumT : u8
|
||||
{
|
||||
Regular,
|
||||
Class
|
||||
};
|
||||
|
||||
constexpr EnumT EnumClass = EnumT::Class;
|
||||
constexpr EnumT EnumRegular = EnumT::Regular;
|
||||
|
||||
enum class AccessSpec : u32
|
||||
{
|
||||
Default,
|
||||
Public,
|
||||
Protected,
|
||||
Private,
|
||||
|
||||
Num_AccessSpec,
|
||||
Invalid,
|
||||
};
|
||||
|
||||
inline
|
||||
char const* to_str( AccessSpec type )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
|
||||
"",
|
||||
"public",
|
||||
"protected",
|
||||
"private",
|
||||
};
|
||||
|
||||
if ( type > AccessSpec::Public )
|
||||
return "Invalid";
|
||||
|
||||
return lookup[ (u32)type ];
|
||||
}
|
||||
|
||||
enum class ModuleFlag : u32
|
||||
{
|
||||
None = 0,
|
||||
Export = bit(0),
|
||||
Import = bit(1),
|
||||
// Private = bit(2),
|
||||
|
||||
Num_ModuleFlags,
|
||||
Invalid,
|
||||
};
|
||||
|
||||
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
|
||||
{
|
||||
return (ModuleFlag)( (u32)A | (u32)B );
|
||||
}
|
||||
|
||||
/*
|
||||
Predefined attributes
|
||||
Used for the parser constructors to identify non-standard attributes
|
||||
|
||||
Override these to change the attribute to your own unique identifier convention.
|
||||
|
||||
The tokenizer identifies attribute defines with the GEN_Define_Attribute_Tokens macros.
|
||||
See the example below and the Define_TokType macro used in gen.cpp to know the format.
|
||||
While the library can parse raw attributes, most projects use defines to wrap them for compiler
|
||||
platform indendence. The token define allows support for them without having to modify the library.
|
||||
*/
|
||||
#if defined(GEN_SYSTEM_WINDOWS) || defined( __CYGWIN__ )
|
||||
#ifndef GEN_Attribute_Keyword
|
||||
# define GEN_API_Export_Code __declspec(dllexport)
|
||||
# define GEN_API_Import_Code __declspec(dllimport)
|
||||
# define GEN_Attribute_Keyword __declspec
|
||||
#endif
|
||||
|
||||
constexpr char const* Attribute_Keyword = stringize( GEN_Attribute_Keyword);
|
||||
|
||||
#elif GEN_HAS_ATTRIBUTE( visibility ) || GEN_GCC_VERSION_CHECK( 3, 3, 0 )
|
||||
#ifndef GEN_Attribute_Keyword
|
||||
# define GEN_API_Export_Code __attribute__ ((visibility ("default")))
|
||||
# define GEN_API_Import_Code __attribute__ ((visibility ("default")))
|
||||
# define GEN_Attribute_Keyword __attribute__
|
||||
#endif
|
||||
|
||||
constexpr char const* Attribute_Keyword = stringize( GEN_Attribute_Keyword );
|
||||
|
||||
#else
|
||||
#ifndef GEN_Attribute_Keyword
|
||||
# define GEN_API_Export_Code
|
||||
# define GEN_API_Import_Code
|
||||
# define GEN_Attribute_Keyword
|
||||
#endif
|
||||
|
||||
constexpr char const* Attribute_Keyword = "";
|
||||
#endif
|
||||
|
||||
#ifndef GEN_Define_Attribute_Tokens
|
||||
# define GEN_Define_Attribute_Tokens \
|
||||
Entry( API_Export, "GEN_API_Export_Code" ) \
|
||||
Entry( API_Import, "GEN_API_Import_Code" )
|
||||
#endif
|
||||
|
3016
project/components/gen/ast_inlines.hpp
Normal file
3016
project/components/gen/ast_inlines.hpp
Normal file
File diff suppressed because it is too large
Load Diff
144
project/components/gen/ecode.hpp
Normal file
144
project/components/gen/ecode.hpp
Normal file
@ -0,0 +1,144 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace ECode
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Untyped,
|
||||
NewLine,
|
||||
Comment,
|
||||
Access_Private,
|
||||
Access_Protected,
|
||||
Access_Public,
|
||||
PlatformAttributes,
|
||||
Class,
|
||||
Class_Fwd,
|
||||
Class_Body,
|
||||
Constructor,
|
||||
Constructor_Fwd,
|
||||
Destructor,
|
||||
Destructor_Fwd,
|
||||
Enum,
|
||||
Enum_Fwd,
|
||||
Enum_Body,
|
||||
Enum_Class,
|
||||
Enum_Class_Fwd,
|
||||
Execution,
|
||||
Export_Body,
|
||||
Extern_Linkage,
|
||||
Extern_Linkage_Body,
|
||||
Friend,
|
||||
Function,
|
||||
Function_Fwd,
|
||||
Function_Body,
|
||||
Global_Body,
|
||||
Module,
|
||||
Namespace,
|
||||
Namespace_Body,
|
||||
Operator,
|
||||
Operator_Fwd,
|
||||
Operator_Member,
|
||||
Operator_Member_Fwd,
|
||||
Operator_Cast,
|
||||
Operator_Cast_Fwd,
|
||||
Parameters,
|
||||
Preprocess_Define,
|
||||
Preprocess_Include,
|
||||
Preprocess_If,
|
||||
Preprocess_IfDef,
|
||||
Preprocess_IfNotDef,
|
||||
Preprocess_ElIf,
|
||||
Preprocess_Else,
|
||||
Preprocess_EndIf,
|
||||
Preprocess_Pragma,
|
||||
Specifiers,
|
||||
Struct,
|
||||
Struct_Fwd,
|
||||
Struct_Body,
|
||||
Template,
|
||||
Typedef,
|
||||
Typename,
|
||||
Union,
|
||||
Union_Body,
|
||||
Using,
|
||||
Using_Namespace,
|
||||
Variable,
|
||||
NumTypes
|
||||
};
|
||||
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
{sizeof( "Invalid" ), "Invalid" },
|
||||
{ sizeof( "Untyped" ), "Untyped" },
|
||||
{ sizeof( "NewLine" ), "NewLine" },
|
||||
{ sizeof( "Comment" ), "Comment" },
|
||||
{ sizeof( "Access_Private" ), "Access_Private" },
|
||||
{ sizeof( "Access_Protected" ), "Access_Protected" },
|
||||
{ sizeof( "Access_Public" ), "Access_Public" },
|
||||
{ sizeof( "PlatformAttributes" ), "PlatformAttributes" },
|
||||
{ sizeof( "Class" ), "Class" },
|
||||
{ sizeof( "Class_Fwd" ), "Class_Fwd" },
|
||||
{ sizeof( "Class_Body" ), "Class_Body" },
|
||||
{ sizeof( "Constructor" ), "Constructor" },
|
||||
{ sizeof( "Constructor_Fwd" ), "Constructor_Fwd" },
|
||||
{ sizeof( "Destructor" ), "Destructor" },
|
||||
{ sizeof( "Destructor_Fwd" ), "Destructor_Fwd" },
|
||||
{ sizeof( "Enum" ), "Enum" },
|
||||
{ sizeof( "Enum_Fwd" ), "Enum_Fwd" },
|
||||
{ sizeof( "Enum_Body" ), "Enum_Body" },
|
||||
{ sizeof( "Enum_Class" ), "Enum_Class" },
|
||||
{ sizeof( "Enum_Class_Fwd" ), "Enum_Class_Fwd" },
|
||||
{ sizeof( "Execution" ), "Execution" },
|
||||
{ sizeof( "Export_Body" ), "Export_Body" },
|
||||
{ sizeof( "Extern_Linkage" ), "Extern_Linkage" },
|
||||
{ sizeof( "Extern_Linkage_Body" ), "Extern_Linkage_Body"},
|
||||
{ sizeof( "Friend" ), "Friend" },
|
||||
{ sizeof( "Function" ), "Function" },
|
||||
{ sizeof( "Function_Fwd" ), "Function_Fwd" },
|
||||
{ sizeof( "Function_Body" ), "Function_Body" },
|
||||
{ sizeof( "Global_Body" ), "Global_Body" },
|
||||
{ sizeof( "Module" ), "Module" },
|
||||
{ sizeof( "Namespace" ), "Namespace" },
|
||||
{ sizeof( "Namespace_Body" ), "Namespace_Body" },
|
||||
{ sizeof( "Operator" ), "Operator" },
|
||||
{ sizeof( "Operator_Fwd" ), "Operator_Fwd" },
|
||||
{ sizeof( "Operator_Member" ), "Operator_Member" },
|
||||
{ sizeof( "Operator_Member_Fwd" ), "Operator_Member_Fwd"},
|
||||
{ sizeof( "Operator_Cast" ), "Operator_Cast" },
|
||||
{ sizeof( "Operator_Cast_Fwd" ), "Operator_Cast_Fwd" },
|
||||
{ sizeof( "Parameters" ), "Parameters" },
|
||||
{ sizeof( "Preprocess_Define" ), "Preprocess_Define" },
|
||||
{ sizeof( "Preprocess_Include" ), "Preprocess_Include" },
|
||||
{ sizeof( "Preprocess_If" ), "Preprocess_If" },
|
||||
{ sizeof( "Preprocess_IfDef" ), "Preprocess_IfDef" },
|
||||
{ sizeof( "Preprocess_IfNotDef" ), "Preprocess_IfNotDef"},
|
||||
{ sizeof( "Preprocess_ElIf" ), "Preprocess_ElIf" },
|
||||
{ sizeof( "Preprocess_Else" ), "Preprocess_Else" },
|
||||
{ sizeof( "Preprocess_EndIf" ), "Preprocess_EndIf" },
|
||||
{ sizeof( "Preprocess_Pragma" ), "Preprocess_Pragma" },
|
||||
{ sizeof( "Specifiers" ), "Specifiers" },
|
||||
{ sizeof( "Struct" ), "Struct" },
|
||||
{ sizeof( "Struct_Fwd" ), "Struct_Fwd" },
|
||||
{ sizeof( "Struct_Body" ), "Struct_Body" },
|
||||
{ sizeof( "Template" ), "Template" },
|
||||
{ sizeof( "Typedef" ), "Typedef" },
|
||||
{ sizeof( "Typename" ), "Typename" },
|
||||
{ sizeof( "Union" ), "Union" },
|
||||
{ sizeof( "Union_Body" ), "Union_Body" },
|
||||
{ sizeof( "Using" ), "Using" },
|
||||
{ sizeof( "Using_Namespace" ), "Using_Namespace" },
|
||||
{ sizeof( "Variable" ), "Variable" },
|
||||
};
|
||||
return lookup[ type ];
|
||||
}
|
||||
|
||||
} // namespace ECode
|
||||
|
||||
using CodeT = ECode::Type;
|
110
project/components/gen/eoperator.hpp
Normal file
110
project/components/gen/eoperator.hpp
Normal file
@ -0,0 +1,110 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace EOperator
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Assign,
|
||||
Assign_Add,
|
||||
Assign_Subtract,
|
||||
Assign_Multiply,
|
||||
Assign_Divide,
|
||||
Assign_Modulo,
|
||||
Assign_BAnd,
|
||||
Assign_BOr,
|
||||
Assign_BXOr,
|
||||
Assign_LShift,
|
||||
Assign_RShift,
|
||||
Increment,
|
||||
Decrement,
|
||||
Unary_Plus,
|
||||
Unary_Minus,
|
||||
UnaryNot,
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Modulo,
|
||||
BNot,
|
||||
BAnd,
|
||||
BOr,
|
||||
BXOr,
|
||||
LShift,
|
||||
RShift,
|
||||
LAnd,
|
||||
LOr,
|
||||
LEqual,
|
||||
LNot,
|
||||
Lesser,
|
||||
Greater,
|
||||
LesserEqual,
|
||||
GreaterEqual,
|
||||
Subscript,
|
||||
Indirection,
|
||||
AddressOf,
|
||||
MemberOfPointer,
|
||||
PtrToMemOfPtr,
|
||||
FunctionCall,
|
||||
Comma,
|
||||
NumOps
|
||||
};
|
||||
|
||||
StrC to_str( Type op )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
{sizeof( "INVALID" ), "INVALID"},
|
||||
{ sizeof( "=" ), "=" },
|
||||
{ sizeof( "+=" ), "+=" },
|
||||
{ sizeof( "-=" ), "-=" },
|
||||
{ sizeof( "*=" ), "*=" },
|
||||
{ sizeof( "/=" ), "/=" },
|
||||
{ sizeof( "%=" ), "%=" },
|
||||
{ sizeof( "&=" ), "&=" },
|
||||
{ sizeof( "|=" ), "|=" },
|
||||
{ sizeof( "^=" ), "^=" },
|
||||
{ sizeof( "<<=" ), "<<=" },
|
||||
{ sizeof( ">>=" ), ">>=" },
|
||||
{ sizeof( "++" ), "++" },
|
||||
{ sizeof( "--" ), "--" },
|
||||
{ sizeof( "+" ), "+" },
|
||||
{ sizeof( "-" ), "-" },
|
||||
{ sizeof( "!" ), "!" },
|
||||
{ sizeof( "+" ), "+" },
|
||||
{ sizeof( "-" ), "-" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( "/" ), "/" },
|
||||
{ sizeof( "%" ), "%" },
|
||||
{ sizeof( "~" ), "~" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "|" ), "|" },
|
||||
{ sizeof( "^" ), "^" },
|
||||
{ sizeof( "<<" ), "<<" },
|
||||
{ sizeof( ">>" ), ">>" },
|
||||
{ sizeof( "&&" ), "&&" },
|
||||
{ sizeof( "||" ), "||" },
|
||||
{ sizeof( "==" ), "==" },
|
||||
{ sizeof( "!=" ), "!=" },
|
||||
{ sizeof( "<" ), "<" },
|
||||
{ sizeof( ">" ), ">" },
|
||||
{ sizeof( "<=" ), "<=" },
|
||||
{ sizeof( ">=" ), ">=" },
|
||||
{ sizeof( "[]" ), "[]" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "->" ), "->" },
|
||||
{ sizeof( "->*" ), "->*" },
|
||||
{ sizeof( "()" ), "()" },
|
||||
{ sizeof( "," ), "," },
|
||||
};
|
||||
return lookup[ op ];
|
||||
}
|
||||
|
||||
} // namespace EOperator
|
||||
|
||||
using OperatorT = EOperator::Type;
|
98
project/components/gen/especifier.hpp
Normal file
98
project/components/gen/especifier.hpp
Normal file
@ -0,0 +1,98 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace ESpecifier
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Consteval,
|
||||
Constexpr,
|
||||
Constinit,
|
||||
Explicit,
|
||||
External_Linkage,
|
||||
ForceInline,
|
||||
Global,
|
||||
Inline,
|
||||
Internal_Linkage,
|
||||
Local_Persist,
|
||||
Mutable,
|
||||
NeverInline,
|
||||
Ptr,
|
||||
Ref,
|
||||
Register,
|
||||
RValue,
|
||||
Static,
|
||||
Thread_Local,
|
||||
Volatile,
|
||||
Virtual,
|
||||
Const,
|
||||
Final,
|
||||
NoExceptions,
|
||||
Override,
|
||||
Pure,
|
||||
NumSpecifiers
|
||||
};
|
||||
|
||||
bool is_trailing( Type specifier )
|
||||
{
|
||||
return specifier > Virtual;
|
||||
}
|
||||
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
{sizeof( "INVALID" ), "INVALID" },
|
||||
{ sizeof( "consteval" ), "consteval" },
|
||||
{ sizeof( "constexpr" ), "constexpr" },
|
||||
{ sizeof( "constinit" ), "constinit" },
|
||||
{ sizeof( "explicit" ), "explicit" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "forceinline" ), "forceinline" },
|
||||
{ sizeof( "global" ), "global" },
|
||||
{ sizeof( "inline" ), "inline" },
|
||||
{ sizeof( "internal" ), "internal" },
|
||||
{ sizeof( "local_persist" ), "local_persist"},
|
||||
{ sizeof( "mutable" ), "mutable" },
|
||||
{ sizeof( "neverinline" ), "neverinline" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "register" ), "register" },
|
||||
{ sizeof( "&&" ), "&&" },
|
||||
{ sizeof( "static" ), "static" },
|
||||
{ sizeof( "thread_local" ), "thread_local" },
|
||||
{ sizeof( "volatile" ), "volatile" },
|
||||
{ sizeof( "virtual" ), "virtual" },
|
||||
{ sizeof( "const" ), "const" },
|
||||
{ sizeof( "final" ), "final" },
|
||||
{ sizeof( "noexcept" ), "noexcept" },
|
||||
{ sizeof( "override" ), "override" },
|
||||
{ sizeof( "= 0" ), "= 0" },
|
||||
};
|
||||
return lookup[ type ];
|
||||
}
|
||||
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[ NumSpecifiers ];
|
||||
do_once_start for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( ( Type )index );
|
||||
keymap[ index ] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
if ( keymap[ index ] == hash )
|
||||
return ( Type )index;
|
||||
}
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
} // namespace ESpecifier
|
||||
|
||||
using SpecifierT = ESpecifier::Type;
|
237
project/components/gen/etoktype.cpp
Normal file
237
project/components/gen/etoktype.cpp
Normal file
@ -0,0 +1,237 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
namespace ETokType
|
||||
{
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( API_Export, GEN_API_Export_Code ) Entry( API_Import, GEN_API_Import_Code )
|
||||
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Access_Private,
|
||||
Access_Protected,
|
||||
Access_Public,
|
||||
Access_MemberSymbol,
|
||||
Access_StaticSymbol,
|
||||
Ampersand,
|
||||
Ampersand_DBL,
|
||||
Assign_Classifer,
|
||||
Attribute_Open,
|
||||
Attribute_Close,
|
||||
BraceCurly_Open,
|
||||
BraceCurly_Close,
|
||||
BraceSquare_Open,
|
||||
BraceSquare_Close,
|
||||
Capture_Start,
|
||||
Capture_End,
|
||||
Comment,
|
||||
Comment_End,
|
||||
Comment_Start,
|
||||
Char,
|
||||
Comma,
|
||||
Decl_Class,
|
||||
Decl_GNU_Attribute,
|
||||
Decl_MSVC_Attribute,
|
||||
Decl_Enum,
|
||||
Decl_Extern_Linkage,
|
||||
Decl_Friend,
|
||||
Decl_Module,
|
||||
Decl_Namespace,
|
||||
Decl_Operator,
|
||||
Decl_Struct,
|
||||
Decl_Template,
|
||||
Decl_Typedef,
|
||||
Decl_Using,
|
||||
Decl_Union,
|
||||
Identifier,
|
||||
Module_Import,
|
||||
Module_Export,
|
||||
NewLine,
|
||||
Number,
|
||||
Operator,
|
||||
Preprocess_Hash,
|
||||
Preprocess_Define,
|
||||
Preprocess_If,
|
||||
Preprocess_IfDef,
|
||||
Preprocess_IfNotDef,
|
||||
Preprocess_ElIf,
|
||||
Preprocess_Else,
|
||||
Preprocess_EndIf,
|
||||
Preprocess_Include,
|
||||
Preprocess_Pragma,
|
||||
Preprocess_Content,
|
||||
Preprocess_Macro,
|
||||
Preprocess_Unsupported,
|
||||
Spec_Alignas,
|
||||
Spec_Const,
|
||||
Spec_Consteval,
|
||||
Spec_Constexpr,
|
||||
Spec_Constinit,
|
||||
Spec_Explicit,
|
||||
Spec_Extern,
|
||||
Spec_Final,
|
||||
Spec_ForceInline,
|
||||
Spec_Global,
|
||||
Spec_Inline,
|
||||
Spec_Internal_Linkage,
|
||||
Spec_LocalPersist,
|
||||
Spec_Mutable,
|
||||
Spec_NeverInline,
|
||||
Spec_Override,
|
||||
Spec_Static,
|
||||
Spec_ThreadLocal,
|
||||
Spec_Volatile,
|
||||
Spec_Virtual,
|
||||
Star,
|
||||
Statement_End,
|
||||
StaticAssert,
|
||||
String,
|
||||
Type_Unsigned,
|
||||
Type_Signed,
|
||||
Type_Short,
|
||||
Type_Long,
|
||||
Type_char,
|
||||
Type_int,
|
||||
Type_double,
|
||||
Type_MS_int8,
|
||||
Type_MS_int16,
|
||||
Type_MS_int32,
|
||||
Type_MS_int64,
|
||||
Type_MS_W64,
|
||||
Varadic_Argument,
|
||||
__Attributes_Start,
|
||||
API_Export,
|
||||
API_Import,
|
||||
NumTokens
|
||||
};
|
||||
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
{sizeof( "__invalid__" ), "__invalid__" },
|
||||
{ sizeof( "private" ), "private" },
|
||||
{ sizeof( "protected" ), "protected" },
|
||||
{ sizeof( "public" ), "public" },
|
||||
{ sizeof( "." ), "." },
|
||||
{ sizeof( "::" ), "::" },
|
||||
{ sizeof( "&" ), "&" },
|
||||
{ sizeof( "&&" ), "&&" },
|
||||
{ sizeof( ":" ), ":" },
|
||||
{ sizeof( "[[" ), "[[" },
|
||||
{ sizeof( "]]" ), "]]" },
|
||||
{ sizeof( "{" ), "{" },
|
||||
{ sizeof( "}" ), "}" },
|
||||
{ sizeof( "[" ), "[" },
|
||||
{ sizeof( "]" ), "]" },
|
||||
{ sizeof( "(" ), "(" },
|
||||
{ sizeof( ")" ), ")" },
|
||||
{ sizeof( "__comment__" ), "__comment__" },
|
||||
{ sizeof( "__comment_end__" ), "__comment_end__" },
|
||||
{ sizeof( "__comment_start__" ), "__comment_start__" },
|
||||
{ sizeof( "__character__" ), "__character__" },
|
||||
{ sizeof( "," ), "," },
|
||||
{ sizeof( "class" ), "class" },
|
||||
{ sizeof( "__attribute__" ), "__attribute__" },
|
||||
{ sizeof( "__declspec" ), "__declspec" },
|
||||
{ sizeof( "enum" ), "enum" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "friend" ), "friend" },
|
||||
{ sizeof( "module" ), "module" },
|
||||
{ sizeof( "namespace" ), "namespace" },
|
||||
{ sizeof( "operator" ), "operator" },
|
||||
{ sizeof( "struct" ), "struct" },
|
||||
{ sizeof( "template" ), "template" },
|
||||
{ sizeof( "typedef" ), "typedef" },
|
||||
{ sizeof( "using" ), "using" },
|
||||
{ sizeof( "union" ), "union" },
|
||||
{ sizeof( "__identifier__" ), "__identifier__" },
|
||||
{ sizeof( "import" ), "import" },
|
||||
{ sizeof( "export" ), "export" },
|
||||
{ sizeof( "__new_line__" ), "__new_line__" },
|
||||
{ sizeof( "__number__" ), "__number__" },
|
||||
{ sizeof( "__operator__" ), "__operator__" },
|
||||
{ sizeof( "#" ), "#" },
|
||||
{ sizeof( "define" ), "define" },
|
||||
{ sizeof( "if" ), "if" },
|
||||
{ sizeof( "ifdef" ), "ifdef" },
|
||||
{ sizeof( "ifndef" ), "ifndef" },
|
||||
{ sizeof( "elif" ), "elif" },
|
||||
{ sizeof( "else" ), "else" },
|
||||
{ sizeof( "endif" ), "endif" },
|
||||
{ sizeof( "include" ), "include" },
|
||||
{ sizeof( "pragma" ), "pragma" },
|
||||
{ sizeof( "__macro_content__" ), "__macro_content__" },
|
||||
{ sizeof( "__macro__" ), "__macro__" },
|
||||
{ sizeof( "__unsupported__" ), "__unsupported__" },
|
||||
{ sizeof( "alignas" ), "alignas" },
|
||||
{ sizeof( "const" ), "const" },
|
||||
{ sizeof( "consteval" ), "consteval" },
|
||||
{ sizeof( "constexpr" ), "constexpr" },
|
||||
{ sizeof( "constinit" ), "constinit" },
|
||||
{ sizeof( "explicit" ), "explicit" },
|
||||
{ sizeof( "extern" ), "extern" },
|
||||
{ sizeof( "final" ), "final" },
|
||||
{ sizeof( "forceinline" ), "forceinline" },
|
||||
{ sizeof( "global" ), "global" },
|
||||
{ sizeof( "inline" ), "inline" },
|
||||
{ sizeof( "internal" ), "internal" },
|
||||
{ sizeof( "local_persist" ), "local_persist" },
|
||||
{ sizeof( "mutable" ), "mutable" },
|
||||
{ sizeof( "neverinline" ), "neverinline" },
|
||||
{ sizeof( "override" ), "override" },
|
||||
{ sizeof( "static" ), "static" },
|
||||
{ sizeof( "thread_local" ), "thread_local" },
|
||||
{ sizeof( "volatile" ), "volatile" },
|
||||
{ sizeof( "virtual" ), "virtual" },
|
||||
{ sizeof( "*" ), "*" },
|
||||
{ sizeof( ";" ), ";" },
|
||||
{ sizeof( "static_assert" ), "static_assert" },
|
||||
{ sizeof( "__string__" ), "__string__" },
|
||||
{ sizeof( "unsigned" ), "unsigned" },
|
||||
{ sizeof( "signed" ), "signed" },
|
||||
{ sizeof( "short" ), "short" },
|
||||
{ sizeof( "long" ), "long" },
|
||||
{ sizeof( "char" ), "char" },
|
||||
{ sizeof( "int" ), "int" },
|
||||
{ sizeof( "double" ), "double" },
|
||||
{ sizeof( "__int8" ), "__int8" },
|
||||
{ sizeof( "__int16" ), "__int16" },
|
||||
{ sizeof( "__int32" ), "__int32" },
|
||||
{ sizeof( "__int64" ), "__int64" },
|
||||
{ sizeof( "_W64" ), "_W64" },
|
||||
{ sizeof( "..." ), "..." },
|
||||
{ sizeof( "__attrib_start__" ), "__attrib_start__" },
|
||||
{ sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code"},
|
||||
{ sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code"},
|
||||
};
|
||||
return lookup[ type ];
|
||||
}
|
||||
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist u32 keymap[ NumTokens ];
|
||||
do_once_start for ( u32 index = 0; index < NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( ( Type )index );
|
||||
keymap[ index ] = crc32( enum_str.Ptr, enum_str.Len - 1 );
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
for ( u32 index = 0; index < NumTokens; index++ )
|
||||
{
|
||||
if ( keymap[ index ] == hash )
|
||||
return ( Type )index;
|
||||
}
|
||||
return Invalid;
|
||||
}
|
||||
|
||||
} // namespace ETokType
|
||||
|
||||
using TokType = ETokType::Type;
|
||||
|
||||
} // namespace Parser
|
178
project/components/header_end.hpp
Normal file
178
project/components/header_end.hpp
Normal file
@ -0,0 +1,178 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "inlines.hpp"
|
||||
#include "gen/ast_inlines.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Constants
|
||||
|
||||
#ifndef GEN_GLOBAL_BUCKET_SIZE
|
||||
# define GEN_GLOBAL_BUCKET_SIZE megabytes(4)
|
||||
#endif
|
||||
#ifndef GEN_CODEPOOL_NUM_BLOCKS
|
||||
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(16)
|
||||
#endif
|
||||
#ifndef GEN_SIZE_PER_STRING_ARENA
|
||||
# define GEN_SIZE_PER_STRING_ARENA megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_MAX_COMMENT_LINE_LENGTH
|
||||
# define GEN_MAX_COMMENT_LINE_LENGTH 1024
|
||||
#endif
|
||||
#ifndef GEN_MAX_NAME_LENGTH
|
||||
# define GEN_MAX_NAME_LENGTH 128
|
||||
#endif
|
||||
#ifndef GEN_MAX_UNTYPED_STR_LENGTH
|
||||
# define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1)
|
||||
#endif
|
||||
#ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
|
||||
#endif
|
||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
||||
#endif
|
||||
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
|
||||
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(1)
|
||||
#endif
|
||||
|
||||
// These constexprs are used for allocation behavior of data structures
|
||||
// or string handling while constructing or serializing.
|
||||
// Change them to suit your needs.
|
||||
|
||||
constexpr s32 InitSize_DataArrays = 16;
|
||||
|
||||
// NOTE: This limits the maximum size of an allocation
|
||||
// If you are generating a string larger than this, increase the size of the bucket here.
|
||||
constexpr uw Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE;
|
||||
constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS;
|
||||
constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA;
|
||||
|
||||
constexpr s32 MaxCommentLineLength = GEN_MAX_COMMENT_LINE_LENGTH;
|
||||
constexpr s32 MaxNameLength = GEN_MAX_NAME_LENGTH;
|
||||
constexpr s32 MaxUntypedStrLength = GEN_MAX_UNTYPED_STR_LENGTH;
|
||||
constexpr s32 TokenFmt_TokenMap_MemSize = GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE;
|
||||
constexpr s32 LexAllocator_Size = GEN_LEX_ALLOCATOR_SIZE;
|
||||
constexpr s32 Builder_StrBufferReserve = GEN_BUILDER_STR_BUFFER_RESERVE;
|
||||
|
||||
extern Code access_public;
|
||||
extern Code access_protected;
|
||||
extern Code access_private;
|
||||
|
||||
extern CodeAttributes attrib_api_export;
|
||||
extern CodeAttributes attrib_api_import;
|
||||
|
||||
extern Code module_global_fragment;
|
||||
extern Code module_private_fragment;
|
||||
|
||||
// Exposed, but this is really used for parsing.
|
||||
extern Code fmt_newline;
|
||||
|
||||
extern CodePragma pragma_once;
|
||||
|
||||
extern CodeParam param_varadic;
|
||||
|
||||
extern CodePreprocessCond preprocess_else;
|
||||
extern CodePreprocessCond preprocess_endif;
|
||||
|
||||
extern CodeSpecifiers spec_const;
|
||||
extern CodeSpecifiers spec_consteval;
|
||||
extern CodeSpecifiers spec_constexpr;
|
||||
extern CodeSpecifiers spec_constinit;
|
||||
extern CodeSpecifiers spec_extern_linkage;
|
||||
extern CodeSpecifiers spec_final;
|
||||
extern CodeSpecifiers spec_forceinline;
|
||||
extern CodeSpecifiers spec_global;
|
||||
extern CodeSpecifiers spec_inline;
|
||||
extern CodeSpecifiers spec_internal_linkage;
|
||||
extern CodeSpecifiers spec_local_persist;
|
||||
extern CodeSpecifiers spec_mutable;
|
||||
extern CodeSpecifiers spec_neverinline;
|
||||
extern CodeSpecifiers spec_noexcept;
|
||||
extern CodeSpecifiers spec_override;
|
||||
extern CodeSpecifiers spec_ptr;
|
||||
extern CodeSpecifiers spec_pure;
|
||||
extern CodeSpecifiers spec_ref;
|
||||
extern CodeSpecifiers spec_register;
|
||||
extern CodeSpecifiers spec_rvalue;
|
||||
extern CodeSpecifiers spec_static_member;
|
||||
extern CodeSpecifiers spec_thread_local;
|
||||
extern CodeSpecifiers spec_virtual;
|
||||
extern CodeSpecifiers spec_volatile;
|
||||
|
||||
extern CodeType t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
|
||||
extern CodeType t_auto;
|
||||
extern CodeType t_void;
|
||||
extern CodeType t_int;
|
||||
extern CodeType t_bool;
|
||||
extern CodeType t_char;
|
||||
extern CodeType t_wchar_t;
|
||||
extern CodeType t_class;
|
||||
extern CodeType t_typename;
|
||||
|
||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
// Predefined typename codes. Are set to readonly and are setup during gen::init()
|
||||
|
||||
extern CodeType t_b32;
|
||||
|
||||
extern CodeType t_s8;
|
||||
extern CodeType t_s16;
|
||||
extern CodeType t_s32;
|
||||
extern CodeType t_s64;
|
||||
|
||||
extern CodeType t_u8;
|
||||
extern CodeType t_u16;
|
||||
extern CodeType t_u32;
|
||||
extern CodeType t_u64;
|
||||
|
||||
extern CodeType t_sw;
|
||||
extern CodeType t_uw;
|
||||
|
||||
extern CodeType t_f32;
|
||||
extern CodeType t_f64;
|
||||
#endif
|
||||
|
||||
#pragma endregion Constants
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
# define gen_main main
|
||||
|
||||
# define __ NoCode
|
||||
|
||||
// Convienence for defining any name used with the gen api.
|
||||
// Lets you provide the length and string literal to the functions without the need for the DSL.
|
||||
# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) }
|
||||
|
||||
// Same as name just used to indicate intention of literal for code instead of names.
|
||||
# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) }
|
||||
|
||||
# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
|
||||
|
||||
# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) )
|
||||
# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) )
|
||||
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
#ifdef GEN_EXPOSE_BACKEND
|
||||
|
||||
// Global allocator used for data with process lifetime.
|
||||
extern AllocatorInfo GlobalAllocator;
|
||||
extern Array< Arena > Global_AllocatorBuckets;
|
||||
|
||||
extern Array< Pool > CodePools;
|
||||
extern Array< Arena > StringArenas;
|
||||
|
||||
extern StringTable StringCache;
|
||||
|
||||
extern Arena LexArena;
|
||||
|
||||
extern AllocatorInfo Allocator_DataArrays;
|
||||
extern AllocatorInfo Allocator_CodePool;
|
||||
extern AllocatorInfo Allocator_Lexer;
|
||||
extern AllocatorInfo Allocator_StringArena;
|
||||
extern AllocatorInfo Allocator_StringTable;
|
||||
extern AllocatorInfo Allocator_TypeTable;
|
||||
|
||||
#endif
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
|
||||
|
||||
@ -15,3 +17,15 @@
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.hpp"
|
||||
#endif
|
||||
|
||||
#ifndef GEN_NS_BEGIN
|
||||
# ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
# else
|
||||
# define GEN_NS gen::
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
# endif
|
||||
#endif
|
194
project/components/inlines.hpp
Normal file
194
project/components/inlines.hpp
Normal file
@ -0,0 +1,194 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.hpp"
|
||||
#endif
|
||||
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
other = other->duplicate();
|
||||
|
||||
other->Parent = this;
|
||||
|
||||
if ( Front == nullptr )
|
||||
{
|
||||
Front = other;
|
||||
Back = other;
|
||||
|
||||
NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
AST*
|
||||
Current = Back;
|
||||
Current->Next = other;
|
||||
other->Prev = Current;
|
||||
Back = other;
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
Code& AST::entry( u32 idx )
|
||||
{
|
||||
AST** current = & Front;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
if ( idx == 0 )
|
||||
return * rcast( Code*, current);
|
||||
|
||||
current = & ( * current )->Next;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return * rcast( Code*, current);
|
||||
}
|
||||
|
||||
bool AST::has_entries()
|
||||
{
|
||||
return NumEntries;
|
||||
}
|
||||
|
||||
char const* AST::type_str()
|
||||
{
|
||||
return ECode::to_str( Type );
|
||||
}
|
||||
|
||||
AST::operator Code()
|
||||
{
|
||||
return { this };
|
||||
}
|
||||
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
ast = ast->Next;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
ast->ParentAccess = AccessSpec::Public;
|
||||
// If your planning on adding a proper parent,
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = entry->duplicate();
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
if ( self->Last == nullptr )
|
||||
{
|
||||
self->Last = entry;
|
||||
self->Next = entry;
|
||||
self->NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
self->Last->Next = entry;
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
return { (AST_Param*) param.raw()->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
bool CodeParam::has_entries()
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
}
|
||||
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
ast->ParentAccess = AccessSpec::Public;
|
||||
// If your planning on adding a proper parent,
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Export_Body:
|
||||
case Extern_Linkage:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
||||
return (CodeBody)Code::Invalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = type;
|
||||
return (CodeBody)result;
|
||||
}
|
||||
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
||||
|
||||
va_list va;
|
||||
va_start(va, num );
|
||||
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
}
|
@ -1,3 +1,11 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast.cpp"
|
||||
#endif
|
||||
|
||||
internal void init_parser();
|
||||
internal void deinit_parser();
|
||||
|
||||
internal
|
||||
void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
|
||||
{
|
||||
@ -12,10 +20,10 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw a
|
||||
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
|
||||
|
||||
if ( bucket.PhysicalStart == nullptr )
|
||||
fatal( "Failed to create bucket for Global_AllocatorBuckets");
|
||||
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
|
||||
|
||||
if ( ! Global_AllocatorBuckets.append( bucket ) )
|
||||
fatal( "Failed to append bucket to Global_AllocatorBuckets");
|
||||
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
|
||||
|
||||
last = & Global_AllocatorBuckets.back();
|
||||
}
|
||||
@ -39,10 +47,10 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw a
|
||||
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
|
||||
|
||||
if ( bucket.PhysicalStart == nullptr )
|
||||
fatal( "Failed to create bucket for Global_AllocatorBuckets");
|
||||
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
|
||||
|
||||
if ( ! Global_AllocatorBuckets.append( bucket ) )
|
||||
fatal( "Failed to append bucket to Global_AllocatorBuckets");
|
||||
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
|
||||
|
||||
last = & Global_AllocatorBuckets.back();
|
||||
}
|
||||
@ -65,12 +73,74 @@ internal
|
||||
void define_constants()
|
||||
{
|
||||
Code::Global = make_code();
|
||||
Code::Global->Name = get_cached_string( txt_StrC("Global Code") );
|
||||
Code::Global->Name = get_cached_string( txt("Global Code") );
|
||||
Code::Global->Content = Code::Global->Name;
|
||||
|
||||
Code::Invalid = make_code();
|
||||
Code::Invalid.set_global();
|
||||
|
||||
t_empty = (CodeType) make_code();
|
||||
t_empty->Type = ECode::Typename;
|
||||
t_empty->Name = get_cached_string( txt("") );
|
||||
t_empty.set_global();
|
||||
|
||||
access_private = make_code();
|
||||
access_private->Type = ECode::Access_Private;
|
||||
access_private->Name = get_cached_string( txt("private:") );
|
||||
access_private.set_global();
|
||||
|
||||
access_protected = make_code();
|
||||
access_protected->Type = ECode::Access_Protected;
|
||||
access_protected->Name = get_cached_string( txt("protected:") );
|
||||
access_protected.set_global();
|
||||
|
||||
access_public = make_code();
|
||||
access_public->Type = ECode::Access_Public;
|
||||
access_public->Name = get_cached_string( txt("public:") );
|
||||
access_public.set_global();
|
||||
|
||||
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
|
||||
attrib_api_export.set_global();
|
||||
|
||||
attrib_api_import = def_attributes( code(GEN_API_Import_Code));
|
||||
attrib_api_import.set_global();
|
||||
|
||||
module_global_fragment = make_code();
|
||||
module_global_fragment->Type = ECode::Untyped;
|
||||
module_global_fragment->Name = get_cached_string( txt("module;") );
|
||||
module_global_fragment->Content = module_global_fragment->Name;
|
||||
module_global_fragment.set_global();
|
||||
|
||||
module_private_fragment = make_code();
|
||||
module_private_fragment->Type = ECode::Untyped;
|
||||
module_private_fragment->Name = get_cached_string( txt("module : private;") );
|
||||
module_private_fragment->Content = module_private_fragment->Name;
|
||||
module_private_fragment.set_global();
|
||||
|
||||
fmt_newline = make_code();
|
||||
fmt_newline->Type = ECode::NewLine;
|
||||
fmt_newline.set_global();
|
||||
|
||||
pragma_once = (CodePragma) make_code();
|
||||
pragma_once->Type = ECode::Preprocess_Pragma;
|
||||
pragma_once->Name = get_cached_string( txt("once") );
|
||||
pragma_once->Content = pragma_once->Name;
|
||||
pragma_once.set_global();
|
||||
|
||||
param_varadic = (CodeType) make_code();
|
||||
param_varadic->Type = ECode::Parameters;
|
||||
param_varadic->Name = get_cached_string( txt("...") );
|
||||
param_varadic->ValueType = t_empty;
|
||||
param_varadic.set_global();
|
||||
|
||||
preprocess_else = (CodePreprocessCond) make_code();
|
||||
preprocess_else->Type = ECode::Preprocess_Else;
|
||||
preprocess_else.set_global();
|
||||
|
||||
preprocess_endif = (CodePreprocessCond) make_code();
|
||||
preprocess_endif->Type = ECode::Preprocess_EndIf;
|
||||
preprocess_endif.set_global();
|
||||
|
||||
# define def_constant_code_type( Type_ ) \
|
||||
t_##Type_ = def_type( name(Type_) ); \
|
||||
t_##Type_.set_global();
|
||||
@ -105,62 +175,16 @@ void define_constants()
|
||||
#endif
|
||||
# undef def_constant_code_type
|
||||
|
||||
t_empty = (CodeType) make_code();
|
||||
t_empty->Type = ECode::Typename;
|
||||
t_empty->Name = get_cached_string( txt_StrC("") );
|
||||
t_empty.set_global();
|
||||
|
||||
param_varadic = (CodeType) make_code();
|
||||
param_varadic->Type = ECode::Parameters;
|
||||
param_varadic->Name = get_cached_string( txt_StrC("...") );
|
||||
param_varadic->ValueType = t_empty;
|
||||
param_varadic.set_global();
|
||||
|
||||
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
|
||||
attrib_api_export.set_global();
|
||||
|
||||
attrib_api_import = def_attributes( code(GEN_API_Import_Code));
|
||||
attrib_api_import.set_global();
|
||||
|
||||
access_private = make_code();
|
||||
access_private->Type = ECode::Access_Private;
|
||||
access_private->Name = get_cached_string( txt_StrC("private:") );
|
||||
access_private.set_global();
|
||||
|
||||
access_protected = make_code();
|
||||
access_protected->Type = ECode::Access_Protected;
|
||||
access_protected->Name = get_cached_string( txt_StrC("protected:") );
|
||||
access_protected.set_global();
|
||||
|
||||
access_public = make_code();
|
||||
access_public->Type = ECode::Access_Public;
|
||||
access_public->Name = get_cached_string( txt_StrC("public:") );
|
||||
access_public.set_global();
|
||||
|
||||
module_global_fragment = make_code();
|
||||
module_global_fragment->Type = ECode::Untyped;
|
||||
module_global_fragment->Name = get_cached_string( txt_StrC("module;") );
|
||||
module_global_fragment->Content = module_global_fragment->Name;
|
||||
module_global_fragment.set_global();
|
||||
|
||||
module_private_fragment = make_code();
|
||||
module_private_fragment->Type = ECode::Untyped;
|
||||
module_private_fragment->Name = get_cached_string( txt_StrC("module : private;") );
|
||||
module_private_fragment->Content = module_private_fragment->Name;
|
||||
module_private_fragment.set_global();
|
||||
|
||||
pragma_once = make_code();
|
||||
pragma_once->Type = ECode::Untyped;
|
||||
pragma_once->Name = get_cached_string( txt_StrC("#pragma once") );
|
||||
pragma_once->Content = pragma_once->Name;
|
||||
pragma_once.set_global();
|
||||
|
||||
# pragma push_macro( "forceinline" )
|
||||
# pragma push_macro( "global" )
|
||||
# pragma push_macro( "internal" )
|
||||
# pragma push_macro( "local_persist" )
|
||||
# pragma push_macro( "neverinline" )
|
||||
# undef forceinline
|
||||
# undef global
|
||||
# undef internal
|
||||
# undef local_persist
|
||||
# undef neverinline
|
||||
|
||||
# define def_constant_spec( Type_, ... ) \
|
||||
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||
@ -172,13 +196,17 @@ void define_constants()
|
||||
def_constant_spec( constinit, ESpecifier::Constinit );
|
||||
def_constant_spec( extern_linkage, ESpecifier::External_Linkage );
|
||||
def_constant_spec( final, ESpecifier::Final );
|
||||
def_constant_spec( forceinline, ESpecifier::ForceInline );
|
||||
def_constant_spec( global, ESpecifier::Global );
|
||||
def_constant_spec( inline, ESpecifier::Inline );
|
||||
def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage );
|
||||
def_constant_spec( local_persist, ESpecifier::Local_Persist );
|
||||
def_constant_spec( mutable, ESpecifier::Mutable );
|
||||
def_constant_spec( neverinline, ESpecifier::NeverInline );
|
||||
def_constant_spec( noexcept, ESpecifier::NoExceptions );
|
||||
def_constant_spec( override, ESpecifier::Override );
|
||||
def_constant_spec( ptr, ESpecifier::Ptr );
|
||||
def_constant_spec( pure, ESpecifier::Pure )
|
||||
def_constant_spec( ref, ESpecifier::Ref );
|
||||
def_constant_spec( register, ESpecifier::Register );
|
||||
def_constant_spec( rvalue, ESpecifier::RValue );
|
||||
@ -190,9 +218,11 @@ void define_constants()
|
||||
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
|
||||
spec_local_persist.set_global();
|
||||
|
||||
# pragma pop_macro( "forceinline" )
|
||||
# pragma pop_macro( "global" )
|
||||
# pragma pop_macro( "internal" )
|
||||
# pragma pop_macro( "local_persist" )
|
||||
# pragma pop_macro( "neverinline" )
|
||||
|
||||
# undef def_constant_spec
|
||||
}
|
||||
@ -206,12 +236,12 @@ void init()
|
||||
Global_AllocatorBuckets = Array<Arena>::init_reserve( heap(), 128 );
|
||||
|
||||
if ( Global_AllocatorBuckets == nullptr )
|
||||
fatal( "Failed to reserve memory for Global_AllocatorBuckets");
|
||||
GEN_FATAL( "Failed to reserve memory for Global_AllocatorBuckets");
|
||||
|
||||
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
|
||||
|
||||
if ( bucket.PhysicalStart == nullptr )
|
||||
fatal( "Failed to create first bucket for Global_AllocatorBuckets");
|
||||
GEN_FATAL( "Failed to create first bucket for Global_AllocatorBuckets");
|
||||
|
||||
Global_AllocatorBuckets.append( bucket );
|
||||
|
||||
@ -222,12 +252,12 @@ void init()
|
||||
CodePools = Array<Pool>::init_reserve( Allocator_DataArrays, InitSize_DataArrays );
|
||||
|
||||
if ( CodePools == nullptr )
|
||||
fatal( "gen::init: Failed to initialize the CodePools array" );
|
||||
GEN_FATAL( "gen::init: Failed to initialize the CodePools array" );
|
||||
|
||||
StringArenas = Array<Arena>::init_reserve( Allocator_DataArrays, InitSize_DataArrays );
|
||||
|
||||
if ( StringArenas == nullptr )
|
||||
fatal( "gen::init: Failed to initialize the StringArenas array" );
|
||||
GEN_FATAL( "gen::init: Failed to initialize the StringArenas array" );
|
||||
}
|
||||
|
||||
// Setup the code pool and code entries arena.
|
||||
@ -235,7 +265,7 @@ void init()
|
||||
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
|
||||
|
||||
if ( code_pool.PhysicalStart == nullptr )
|
||||
fatal( "gen::init: Failed to initialize the code pool" );
|
||||
GEN_FATAL( "gen::init: Failed to initialize the code pool" );
|
||||
|
||||
CodePools.append( code_pool );
|
||||
|
||||
@ -244,7 +274,7 @@ void init()
|
||||
Arena string_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
|
||||
|
||||
if ( string_arena.PhysicalStart == nullptr )
|
||||
fatal( "gen::init: Failed to initialize the string arena" );
|
||||
GEN_FATAL( "gen::init: Failed to initialize the string arena" );
|
||||
|
||||
StringArenas.append( string_arena );
|
||||
}
|
||||
@ -254,10 +284,11 @@ void init()
|
||||
StringCache = StringTable::init( Allocator_StringTable );
|
||||
|
||||
if ( StringCache.Entries == nullptr )
|
||||
fatal( "gen::init: Failed to initialize the StringCache");
|
||||
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
||||
}
|
||||
|
||||
define_constants();
|
||||
init_parser();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
@ -300,6 +331,7 @@ void deinit()
|
||||
while ( left--, left );
|
||||
|
||||
Global_AllocatorBuckets.free();
|
||||
deinit_parser();
|
||||
}
|
||||
|
||||
void reset()
|
||||
@ -340,7 +372,7 @@ AllocatorInfo get_string_allocator( s32 str_length )
|
||||
Arena new_arena = Arena::init_from_allocator( Allocator_StringArena, SizePer_StringArena );
|
||||
|
||||
if ( ! StringArenas.append( new_arena ) )
|
||||
fatal( "gen::get_string_allocator: Failed to allocate a new string arena" );
|
||||
GEN_FATAL( "gen::get_string_allocator: Failed to allocate a new string arena" );
|
||||
|
||||
last = & StringArenas.back();
|
||||
}
|
||||
@ -366,9 +398,7 @@ StringCached get_cached_string( StrC str )
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Used internally to retireve a Code object form the CodePool.
|
||||
*/
|
||||
// Used internally to retireve a Code object form the CodePool.
|
||||
Code make_code()
|
||||
{
|
||||
Pool* allocator = & CodePools.back();
|
||||
@ -377,24 +407,27 @@ Code make_code()
|
||||
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
|
||||
|
||||
if ( code_pool.PhysicalStart == nullptr )
|
||||
fatal( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
|
||||
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
|
||||
|
||||
if ( ! CodePools.append( code_pool ) )
|
||||
fatal( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
|
||||
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
|
||||
|
||||
allocator = & CodePools.back();
|
||||
}
|
||||
|
||||
Code result { rcast( AST*, alloc( * allocator, sizeof(AST) )) };
|
||||
// mem_set( result.ast, 0, sizeof(AST) );
|
||||
result->Type = ECode::Invalid;
|
||||
|
||||
result->Content = { nullptr };
|
||||
result->Prev = { nullptr };
|
||||
result->Next = { nullptr };
|
||||
result->Parent = { nullptr };
|
||||
result->Name = { nullptr };
|
||||
result->Type = ECode::Invalid;
|
||||
result->ModuleFlags = ModuleFlag::Invalid;
|
||||
result->NumEntries = 0;
|
||||
result->Content = { nullptr };
|
||||
result->Prev = { nullptr };
|
||||
result->Next = { nullptr };
|
||||
result->Token = nullptr;
|
||||
result->Parent = { nullptr };
|
||||
result->Name = { nullptr };
|
||||
result->Type = ECode::Invalid;
|
||||
result->ModuleFlags = ModuleFlag::Invalid;
|
||||
result->NumEntries = 0;
|
||||
|
||||
return result;
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast_types.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Gen Interface
|
||||
|
||||
// Initialize the library.
|
||||
@ -45,6 +50,12 @@ CodeClass def_class( StrC name
|
||||
, ModuleFlag mflags = ModuleFlag::None
|
||||
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 );
|
||||
|
||||
CodeConstructor def_constructor( CodeParam params = NoCode, Code initializer_list = NoCode, Code body = NoCode );
|
||||
|
||||
CodeDefine def_define( StrC name, StrC content );
|
||||
|
||||
CodeDestructor def_destructor( Code body = NoCode, CodeSpecifiers specifiers = NoCode );
|
||||
|
||||
CodeEnum def_enum( StrC name
|
||||
, Code body = NoCode, CodeType type = NoCode
|
||||
, EnumT specifier = EnumRegular, CodeAttributes attributes = NoCode
|
||||
@ -59,18 +70,22 @@ CodeFn def_function( StrC name
|
||||
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
|
||||
, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
CodeInclude def_include ( StrC content );
|
||||
CodeInclude def_include ( StrC content, bool foreign = false );
|
||||
CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None );
|
||||
CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
||||
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
CodeOperator def_operator( OperatorT op
|
||||
CodeOperator def_operator( OperatorT op, StrC nspace
|
||||
, CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode
|
||||
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
|
||||
, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
CodeOpCast def_operator_cast( CodeType type, Code body = NoCode, CodeSpecifiers specs = NoCode );
|
||||
|
||||
CodeParam def_param ( CodeType type, StrC name, Code value = NoCode );
|
||||
CodeParam def_param ( CodeType type, StrC name, Code value = NoCode );
|
||||
CodePragma def_pragma( StrC directive );
|
||||
|
||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC content );
|
||||
|
||||
CodeSpecifiers def_specifier( SpecifierT specifier );
|
||||
|
||||
CodeStruct def_struct( StrC name
|
||||
@ -130,29 +145,32 @@ CodeBody def_union_body ( s32 num, Code* codes );
|
||||
|
||||
#pragma region Parsing
|
||||
|
||||
CodeClass parse_class ( StrC class_def );
|
||||
CodeEnum parse_enum ( StrC enum_def );
|
||||
CodeBody parse_export_body ( StrC export_def );
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def);
|
||||
CodeFriend parse_friend ( StrC friend_def );
|
||||
CodeFn parse_function ( StrC fn_def );
|
||||
CodeBody parse_global_body ( StrC body_def );
|
||||
CodeNamespace parse_namespace ( StrC namespace_def );
|
||||
CodeOperator parse_operator ( StrC operator_def );
|
||||
CodeOpCast parse_operator_cast( StrC operator_def );
|
||||
CodeStruct parse_struct ( StrC struct_def );
|
||||
CodeTemplate parse_template ( StrC template_def );
|
||||
CodeType parse_type ( StrC type_def );
|
||||
CodeTypedef parse_typedef ( StrC typedef_def );
|
||||
CodeUnion parse_union ( StrC union_def );
|
||||
CodeUsing parse_using ( StrC using_def );
|
||||
CodeVar parse_variable ( StrC var_def );
|
||||
CodeClass parse_class ( StrC class_def );
|
||||
CodeConstructor parse_constructor ( StrC constructor_def );
|
||||
CodeDestructor parse_destructor ( StrC destructor_def );
|
||||
CodeEnum parse_enum ( StrC enum_def );
|
||||
CodeBody parse_export_body ( StrC export_def );
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def );
|
||||
CodeFriend parse_friend ( StrC friend_def );
|
||||
CodeFn parse_function ( StrC fn_def );
|
||||
CodeBody parse_global_body ( StrC body_def );
|
||||
CodeNS parse_namespace ( StrC namespace_def );
|
||||
CodeOperator parse_operator ( StrC operator_def );
|
||||
CodeOpCast parse_operator_cast( StrC operator_def );
|
||||
CodeStruct parse_struct ( StrC struct_def );
|
||||
CodeTemplate parse_template ( StrC template_def );
|
||||
CodeType parse_type ( StrC type_def );
|
||||
CodeTypedef parse_typedef ( StrC typedef_def );
|
||||
CodeUnion parse_union ( StrC union_def );
|
||||
CodeUsing parse_using ( StrC using_def );
|
||||
CodeVar parse_variable ( StrC var_def );
|
||||
|
||||
#pragma endregion Parsing
|
||||
|
||||
#pragma region Untyped text
|
||||
|
||||
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va );
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
StrC token_fmt_impl( sw, ... );
|
||||
|
||||
Code untyped_str ( StrC content);
|
5669
project/components/interface.parsing.cpp
Normal file
5669
project/components/interface.parsing.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.parsing.cpp"
|
||||
#endif
|
||||
|
||||
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
|
||||
{
|
||||
char const* buf_begin = buf;
|
||||
@ -12,8 +17,7 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
|
||||
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
|
||||
|
||||
tok_map_arena = Arena::init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
|
||||
|
||||
tok_map = HashTable<StrC>::init( tok_map_arena );
|
||||
tok_map = HashTable<StrC>::init( tok_map_arena );
|
||||
|
||||
s32 left = num_tokens - 1;
|
||||
|
||||
@ -100,17 +104,35 @@ sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va )
|
||||
|
||||
Code untyped_str( StrC content )
|
||||
{
|
||||
if ( content.Len == 0 )
|
||||
{
|
||||
log_failure( "untyped_str: empty string" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Name = get_cached_string( content );
|
||||
result->Type = ECode::Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
{
|
||||
log_failure( "untyped_str: could not cache string" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Code untyped_fmt( char const* fmt, ...)
|
||||
{
|
||||
if ( fmt == nullptr )
|
||||
{
|
||||
log_failure( "untyped_fmt: null format string" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
@ -125,11 +147,23 @@ Code untyped_fmt( char const* fmt, ...)
|
||||
result->Type = ECode::Untyped;
|
||||
result->Content = get_cached_string( { length, buf } );
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
{
|
||||
if ( num_tokens == 0 )
|
||||
{
|
||||
log_failure( "untyped_token_fmt: zero tokens" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
@ -144,5 +178,11 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
result->Type = ECode::Untyped;
|
||||
result->Content = result->Name;
|
||||
|
||||
if ( result->Name == nullptr )
|
||||
{
|
||||
log_failure( "untyped_fmt: could not cache string" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -1,3 +1,10 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Upfront
|
||||
|
||||
enum class OpValidateResult : u32
|
||||
{
|
||||
Fail,
|
||||
@ -5,7 +12,6 @@ enum class OpValidateResult : u32
|
||||
Member
|
||||
};
|
||||
|
||||
inline
|
||||
OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeType ret_type, CodeSpecifiers specifier )
|
||||
{
|
||||
using namespace EOperator;
|
||||
@ -375,7 +381,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
|
||||
|
||||
/*
|
||||
The implementaiton of the upfront constructors involves bascially doing three things:
|
||||
The implementaiton of the upfront constructors involves doing three things:
|
||||
* Validate the arguments given to construct the intended type of AST is valid.
|
||||
* Construct said AST type.
|
||||
* Lock the AST (set to readonly) and return the valid object.
|
||||
@ -411,15 +417,92 @@ CodeComment def_comment( StrC content )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
static char line[ MaxCommentLineLength ];
|
||||
|
||||
String cmt_formatted = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
char const* end = content.Ptr + content.Len;
|
||||
char const* scanner = content.Ptr;
|
||||
s32 curr = 0;
|
||||
do
|
||||
{
|
||||
char const* next = scanner;
|
||||
s32 length = 0;
|
||||
while ( next != end && scanner[ length ] != '\n' )
|
||||
{
|
||||
next = scanner + length;
|
||||
length++;
|
||||
}
|
||||
length++;
|
||||
|
||||
str_copy( line, scanner, length );
|
||||
cmt_formatted.append_fmt( "//%.*s", length, line );
|
||||
mem_set( line, 0, MaxCommentLineLength );
|
||||
|
||||
scanner += length;
|
||||
}
|
||||
while ( scanner <= end );
|
||||
|
||||
if ( cmt_formatted.back() != '\n' )
|
||||
cmt_formatted.append( "\n" );
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = ECode::Comment;
|
||||
result->Name = get_cached_string( content );
|
||||
result->Name = get_cached_string( cmt_formatted );
|
||||
result->Content = result->Name;
|
||||
|
||||
cmt_formatted.free();
|
||||
|
||||
return (CodeComment) result;
|
||||
}
|
||||
|
||||
CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code body )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
if ( params && params->Type != Parameters )
|
||||
{
|
||||
log_failure("gen::def_constructor: params must be of Parameters type - %s", params.debug_str());
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeConstructor
|
||||
result = (CodeConstructor) make_code();
|
||||
|
||||
if ( params )
|
||||
{
|
||||
result->Params = params;
|
||||
}
|
||||
|
||||
if ( initializer_list )
|
||||
{
|
||||
result->InitializerList = initializer_list;
|
||||
}
|
||||
|
||||
if ( body )
|
||||
{
|
||||
switch ( body->Type )
|
||||
{
|
||||
case Function_Body:
|
||||
case Untyped:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", body.debug_str());
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
result->Type = Constructor;
|
||||
result->Body = body;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->Type = Constructor_Fwd;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeClass def_class( StrC name
|
||||
, Code body
|
||||
, CodeType parent, AccessSpec parent_access
|
||||
@ -489,6 +572,66 @@ CodeClass def_class( StrC name
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDefine def_define( StrC name, StrC content )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
name_check( def_define, name );
|
||||
|
||||
if ( content.Len <= 0 || content.Ptr == nullptr )
|
||||
{
|
||||
log_failure( "gen::def_define: Invalid value provided" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeDefine
|
||||
result = (CodeDefine) make_code();
|
||||
result->Type = Preprocess_Define;
|
||||
result->Name = get_cached_string( name );
|
||||
result->Content = get_cached_string( content );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
if ( specifiers && specifiers->Type != Specifiers )
|
||||
{
|
||||
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", specifiers.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeDestructor result = (CodeDestructor) make_code();
|
||||
|
||||
if ( specifiers )
|
||||
result->Specs = specifiers;
|
||||
|
||||
if ( body )
|
||||
{
|
||||
switch ( body->Type )
|
||||
{
|
||||
case Function_Body:
|
||||
case Untyped:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", body.debug_str());
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
result->Type = Destructor;
|
||||
result->Body = body;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->Type = Destructor_Fwd;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeEnum def_enum( StrC name
|
||||
, Code body, CodeType type
|
||||
, EnumT specifier, CodeAttributes attributes
|
||||
@ -709,7 +852,7 @@ CodeFn def_function( StrC name
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeInclude def_include ( StrC path )
|
||||
CodeInclude def_include( StrC path, bool foreign )
|
||||
{
|
||||
if ( path.Len <= 0 || path.Ptr == nullptr )
|
||||
{
|
||||
@ -717,10 +860,14 @@ CodeInclude def_include ( StrC path )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
StrC content = foreign ?
|
||||
to_str( str_fmt_buf( "<%.*s>", path.Len, path.Ptr ))
|
||||
: to_str( str_fmt_buf( "\"%.*s\"", path.Len, path.Ptr ));
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = ECode::Preprocessor_Include;
|
||||
result->Name = get_cached_string( path );
|
||||
result->Type = ECode::Preprocess_Include;
|
||||
result->Name = get_cached_string( content );
|
||||
result->Content = result->Name;
|
||||
|
||||
return (CodeInclude) result;
|
||||
@ -740,7 +887,7 @@ CodeModule def_module( StrC name, ModuleFlag mflags )
|
||||
return (CodeModule) result;
|
||||
}
|
||||
|
||||
CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
@ -753,8 +900,8 @@ CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeNamespace
|
||||
result = (CodeNamespace) make_code();
|
||||
CodeNS
|
||||
result = (CodeNS) make_code();
|
||||
result->Type = Namespace;
|
||||
result->Name = get_cached_string( name );
|
||||
result->ModuleFlags = mflags;
|
||||
@ -763,7 +910,7 @@ CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeOperator def_operator( OperatorT op
|
||||
CodeOperator def_operator( OperatorT op, StrC nspace
|
||||
, CodeParam params_code, CodeType ret_type, Code body
|
||||
, CodeSpecifiers specifiers, CodeAttributes attributes
|
||||
, ModuleFlag mflags )
|
||||
@ -789,8 +936,13 @@ CodeOperator def_operator( OperatorT op
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
char const* name = str_fmt_buf( "operator %s", to_str(op) );
|
||||
char const* name = nullptr;
|
||||
|
||||
StrC op_str = to_str( op );
|
||||
if ( nspace.Len > 0 )
|
||||
name = str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
|
||||
else
|
||||
name = str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
|
||||
CodeOperator
|
||||
result = (CodeOperator) make_code();
|
||||
result->Name = get_cached_string( { str_len(name), name } );
|
||||
@ -910,6 +1062,57 @@ CodeParam def_param( CodeType type, StrC name, Code value )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodePragma def_pragma( StrC directive )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
if ( directive.Len <= 0 || directive.Ptr == nullptr )
|
||||
{
|
||||
log_failure( "gen::def_comment: Invalid comment provided:" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodePragma
|
||||
result = (CodePragma) make_code();
|
||||
result->Type = Preprocess_Pragma;
|
||||
result->Content = get_cached_string( directive );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
if ( expr.Len <= 0 || expr.Ptr == nullptr )
|
||||
{
|
||||
log_failure( "gen::def_comment: Invalid comment provided:" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodePreprocessCond
|
||||
result = (CodePreprocessCond) make_code();
|
||||
result->Content = get_cached_string( expr );
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case EPreprocessCond::If:
|
||||
result->Type = Preprocess_If;
|
||||
break;
|
||||
case EPreprocessCond::IfDef:
|
||||
result->Type = Preprocess_IfDef;
|
||||
break;
|
||||
case EPreprocessCond::IfNotDef:
|
||||
result->Type = Preprocess_IfNotDef;
|
||||
break;
|
||||
case EPreprocessCond::ElIf:
|
||||
result->Type = Preprocess_ElIf;
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeSpecifiers def_specifier( SpecifierT spec )
|
||||
{
|
||||
CodeSpecifiers
|
||||
@ -1060,7 +1263,6 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
name_check( def_typedef, name );
|
||||
null_check( def_typedef, type );
|
||||
|
||||
switch ( type->Type )
|
||||
@ -1099,12 +1301,28 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
|
||||
|
||||
CodeTypedef
|
||||
result = (CodeTypedef) make_code();
|
||||
result->Name = get_cached_string( name );
|
||||
result->Type = ECode::Typedef;
|
||||
result->ModuleFlags = mflags;
|
||||
|
||||
result->UnderlyingType = type;
|
||||
|
||||
if ( name.Len <= 0 )
|
||||
{
|
||||
if (type->Type != Untyped)
|
||||
{
|
||||
log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", type.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
result->Name = get_cached_string( type->Name );
|
||||
result->IsFunction = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->Name = get_cached_string( name );
|
||||
result->IsFunction = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1239,27 +1457,6 @@ CodeVar def_variable( CodeType type, StrC name, Code value
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Body related functions typically follow the same implementation pattern.
|
||||
Opted to use inline helper macros to get the implementaiton done.
|
||||
|
||||
The implementation pattern is as follows:
|
||||
* Validate a valid parameter num was provided, or code array
|
||||
def_body_start or def_body_code_array_start( <name of function >)
|
||||
|
||||
* Begin the code entry do-while loop, make sure each entry is valid processing its type in the switc
|
||||
def_body_code_validation_start( <name of function> )
|
||||
|
||||
* Define the switch case statements between the macros.
|
||||
|
||||
* Add the code entry, finish the closing implemenation for the do-while loop.
|
||||
def_body_code_validation_end( <name of function> )
|
||||
|
||||
* Lock the body AST and return it.
|
||||
|
||||
If a function's implementation deviates from the macros then its just writen it out.
|
||||
*/
|
||||
|
||||
#pragma region Helper Macros for def_**_body functions
|
||||
#define def_body_start( Name_ ) \
|
||||
using namespace ECode; \
|
||||
@ -1285,61 +1482,43 @@ if ( codes == nullptr ) \
|
||||
return CodeInvalid; \
|
||||
}
|
||||
|
||||
#define def_body_code_validation_start( Name_ ) \
|
||||
do \
|
||||
{ \
|
||||
Code_POD pod = va_arg(va, Code_POD); \
|
||||
Code entry = pcast(Code, pod); \
|
||||
\
|
||||
if ( ! entry ) \
|
||||
{ \
|
||||
log_failure("gen::" stringize(Name_) ": Provided an null entry"); \
|
||||
return CodeInvalid; \
|
||||
} \
|
||||
\
|
||||
switch ( entry->Type ) \
|
||||
{
|
||||
|
||||
#define def_body_code_array_validation_start( Name_ ) \
|
||||
do \
|
||||
{ \
|
||||
Code entry = *codes; codes++; \
|
||||
\
|
||||
if ( ! entry ) \
|
||||
{ \
|
||||
log_failure("gen::" stringize(Name_) ": Provided an null entry"); \
|
||||
return CodeInvalid; \
|
||||
} \
|
||||
\
|
||||
switch ( entry->Type ) \
|
||||
{
|
||||
|
||||
#define def_body_code_validation_end( Name_ ) \
|
||||
log_failure("gen::" stringize(Name_) ": Entry type is not allowed: %s", entry.debug_str() ); \
|
||||
return CodeInvalid; \
|
||||
\
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
result.append( entry ); \
|
||||
} \
|
||||
while ( num--, num > 0 )
|
||||
#pragma endregion Helper Macros for def_**_body functions
|
||||
|
||||
CodeBody def_class_body( s32 num, ... )
|
||||
{
|
||||
def_body_start( def_class_body );
|
||||
|
||||
CodeBody
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Class_Body;
|
||||
CodeBody result = ( CodeBody )make_code();
|
||||
result->Type = Class_Body;
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_class_body );
|
||||
AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_class_body );
|
||||
va_start( va, num );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::"
|
||||
"def_class_body"
|
||||
": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1353,9 +1532,30 @@ CodeBody def_class_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Function_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_class_body );
|
||||
AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_class_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_class_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1383,7 +1583,7 @@ CodeBody def_enum_body( s32 num, ... )
|
||||
|
||||
if ( entry->Type != Untyped && entry->Type != Comment )
|
||||
{
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() ); \
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
@ -1415,7 +1615,7 @@ CodeBody def_enum_body( s32 num, Code* codes )
|
||||
|
||||
if ( entry->Type != Untyped && entry->Type != Comment )
|
||||
{
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed: %s", entry.debug_str() ); \
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
@ -1436,9 +1636,30 @@ CodeBody def_export_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_export_body );
|
||||
AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_export_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1452,9 +1673,30 @@ CodeBody def_export_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Export_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_export_body );
|
||||
AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_export_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1469,9 +1711,30 @@ CodeBody def_extern_link_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_extern_linkage_body );
|
||||
AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_extern_linkage_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1485,9 +1748,31 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Extern_Linkage_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_extern_linkage_body );
|
||||
AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_extern_linkage_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1502,9 +1787,31 @@ CodeBody def_function_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_function_body );
|
||||
AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_function_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" stringize(def_function_body) ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1518,9 +1825,29 @@ CodeBody def_function_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Function_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_function_body );
|
||||
AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_function_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_function_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1535,9 +1862,34 @@ CodeBody def_global_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_global_body );
|
||||
AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_global_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
case Global_Body:
|
||||
result.append( entry.cast<CodeBody>() ) ;
|
||||
continue;
|
||||
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return (*Code::Invalid.ast);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1551,9 +1903,34 @@ CodeBody def_global_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Global_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_global_body );
|
||||
AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_global_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
case Global_Body:
|
||||
result.append( entry.cast<CodeBody>() ) ;
|
||||
continue;
|
||||
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1568,9 +1945,30 @@ CodeBody def_namespace_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_namespace_body );
|
||||
AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_namespace_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1584,9 +1982,29 @@ CodeBody def_namespace_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Global_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_namespace_body );
|
||||
AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_namespace_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1736,9 +2154,30 @@ CodeBody def_struct_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_struct_body );
|
||||
AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_struct_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1752,9 +2191,30 @@ CodeBody def_struct_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Struct_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_struct_body );
|
||||
AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_struct_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1782,7 +2242,7 @@ CodeBody def_union_body( s32 num, ... )
|
||||
|
||||
if ( entry->Type != Untyped && entry->Type != Comment )
|
||||
{
|
||||
log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() ); \
|
||||
log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
@ -1828,3 +2288,7 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
|
||||
# undef name_check
|
||||
# undef null_check
|
||||
# undef null_or_invalid_check
|
||||
# undef def_body_start
|
||||
# undef def_body_code_array_start
|
||||
|
||||
#pragma endregion Upfront
|
@ -2,8 +2,11 @@
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.cpp"
|
||||
#endif
|
||||
|
@ -1,4 +1,10 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "gen.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region StaticData
|
||||
|
||||
// TODO : Convert global allocation strategy to use a slab allocation strategy.
|
||||
global AllocatorInfo GlobalAllocator;
|
||||
global Array<Arena> Global_AllocatorBuckets;
|
||||
@ -16,9 +22,55 @@ global AllocatorInfo Allocator_Lexer = heap();
|
||||
global AllocatorInfo Allocator_StringArena = heap();
|
||||
global AllocatorInfo Allocator_StringTable = heap();
|
||||
global AllocatorInfo Allocator_TypeTable = heap();
|
||||
|
||||
#pragma endregion StaticData
|
||||
|
||||
#pragma region Constants
|
||||
|
||||
global Code access_public;
|
||||
global Code access_protected;
|
||||
global Code access_private;
|
||||
|
||||
global CodeAttributes attrib_api_export;
|
||||
global CodeAttributes attrib_api_import;
|
||||
|
||||
global Code module_global_fragment;
|
||||
global Code module_private_fragment;
|
||||
|
||||
global Code fmt_newline;
|
||||
|
||||
global CodeParam param_varadic;
|
||||
|
||||
global CodePragma pragma_once;
|
||||
|
||||
global CodePreprocessCond preprocess_else;
|
||||
global CodePreprocessCond preprocess_endif;
|
||||
|
||||
global CodeSpecifiers spec_const;
|
||||
global CodeSpecifiers spec_consteval;
|
||||
global CodeSpecifiers spec_constexpr;
|
||||
global CodeSpecifiers spec_constinit;
|
||||
global CodeSpecifiers spec_extern_linkage;
|
||||
global CodeSpecifiers spec_final;
|
||||
global CodeSpecifiers spec_forceinline;
|
||||
global CodeSpecifiers spec_global;
|
||||
global CodeSpecifiers spec_inline;
|
||||
global CodeSpecifiers spec_internal_linkage;
|
||||
global CodeSpecifiers spec_local_persist;
|
||||
global CodeSpecifiers spec_mutable;
|
||||
global CodeSpecifiers spec_noexcept;
|
||||
global CodeSpecifiers spec_neverinline;
|
||||
global CodeSpecifiers spec_override;
|
||||
global CodeSpecifiers spec_ptr;
|
||||
global CodeSpecifiers spec_pure;
|
||||
global CodeSpecifiers spec_ref;
|
||||
global CodeSpecifiers spec_register;
|
||||
global CodeSpecifiers spec_rvalue;
|
||||
global CodeSpecifiers spec_static_member;
|
||||
global CodeSpecifiers spec_thread_local;
|
||||
global CodeSpecifiers spec_virtual;
|
||||
global CodeSpecifiers spec_volatile;
|
||||
|
||||
global CodeType t_empty;
|
||||
global CodeType t_auto;
|
||||
global CodeType t_void;
|
||||
@ -49,38 +101,4 @@ global CodeType t_f32;
|
||||
global CodeType t_f64;
|
||||
#endif
|
||||
|
||||
global CodeParam param_varadic;
|
||||
|
||||
global CodeAttributes attrib_api_export;
|
||||
global CodeAttributes attrib_api_import;
|
||||
|
||||
global Code access_public;
|
||||
global Code access_protected;
|
||||
global Code access_private;
|
||||
|
||||
global Code module_global_fragment;
|
||||
global Code module_private_fragment;
|
||||
|
||||
global Code pragma_once;
|
||||
|
||||
global CodeSpecifiers spec_const;
|
||||
global CodeSpecifiers spec_consteval;
|
||||
global CodeSpecifiers spec_constexpr;
|
||||
global CodeSpecifiers spec_constinit;
|
||||
global CodeSpecifiers spec_extern_linkage;
|
||||
global CodeSpecifiers spec_final;
|
||||
global CodeSpecifiers spec_global;
|
||||
global CodeSpecifiers spec_inline;
|
||||
global CodeSpecifiers spec_internal_linkage;
|
||||
global CodeSpecifiers spec_local_persist;
|
||||
global CodeSpecifiers spec_mutable;
|
||||
global CodeSpecifiers spec_override;
|
||||
global CodeSpecifiers spec_ptr;
|
||||
global CodeSpecifiers spec_ref;
|
||||
global CodeSpecifiers spec_register;
|
||||
global CodeSpecifiers spec_rvalue;
|
||||
global CodeSpecifiers spec_static_member;
|
||||
global CodeSpecifiers spec_thread_local;
|
||||
global CodeSpecifiers spec_virtual;
|
||||
global CodeSpecifiers spec_volatile;
|
||||
#pragma endregion Constants
|
104
project/components/types.hpp
Normal file
104
project/components/types.hpp
Normal file
@ -0,0 +1,104 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
using LogFailType = sw(*)(char const*, ...);
|
||||
|
||||
// By default this library will either crash or exit if an error is detected while generating codes.
|
||||
// Even if set to not use GEN_FATAL, GEN_FATAL will still be used for memory failures as the library is unusable when they occur.
|
||||
#ifdef GEN_DONT_USE_FATAL
|
||||
#define log_failure log_fmt
|
||||
#else
|
||||
#define log_failure GEN_FATAL
|
||||
#endif
|
||||
|
||||
enum class AccessSpec : u32
|
||||
{
|
||||
Default,
|
||||
Public,
|
||||
Protected,
|
||||
Private,
|
||||
|
||||
Num_AccessSpec,
|
||||
Invalid,
|
||||
};
|
||||
|
||||
inline
|
||||
char const* to_str( AccessSpec type )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
|
||||
"",
|
||||
"public",
|
||||
"protected",
|
||||
"private",
|
||||
};
|
||||
|
||||
if ( type > AccessSpec::Public )
|
||||
return "Invalid";
|
||||
|
||||
return lookup[ (u32)type ];
|
||||
}
|
||||
|
||||
|
||||
enum CodeFlag : u32
|
||||
{
|
||||
FunctionType = bit(0),
|
||||
ParamPack = bit(1),
|
||||
Module_Export = bit(2),
|
||||
Module_Import = bit(3),
|
||||
};
|
||||
|
||||
// Used to indicate if enum definitoin is an enum class or regular enum.
|
||||
enum class EnumT : u8
|
||||
{
|
||||
Regular,
|
||||
Class
|
||||
};
|
||||
|
||||
constexpr EnumT EnumClass = EnumT::Class;
|
||||
constexpr EnumT EnumRegular = EnumT::Regular;
|
||||
|
||||
enum class ModuleFlag : u32
|
||||
{
|
||||
None = 0,
|
||||
Export = bit(0),
|
||||
Import = bit(1),
|
||||
|
||||
Num_ModuleFlags,
|
||||
Invalid,
|
||||
};
|
||||
|
||||
StrC to_str( ModuleFlag flag )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ (u32)ModuleFlag::Num_ModuleFlags ] = {
|
||||
{ sizeof("__none__"), "__none__" },
|
||||
{ sizeof("export"), "export" },
|
||||
{ sizeof("import"), "import" },
|
||||
};
|
||||
|
||||
if ( flag > ModuleFlag::Import )
|
||||
return { sizeof("invalid"), "invalid" };
|
||||
|
||||
return lookup[ (u32)flag ];
|
||||
}
|
||||
|
||||
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
|
||||
{
|
||||
return (ModuleFlag)( (u32)A | (u32)B );
|
||||
}
|
||||
|
||||
enum class EPreprocessCond : u32
|
||||
{
|
||||
If,
|
||||
IfDef,
|
||||
IfNotDef,
|
||||
ElIf
|
||||
};
|
||||
|
||||
constexpr EPreprocessCond PreprocessCond_If = EPreprocessCond::If;
|
||||
constexpr EPreprocessCond PreprocessCond_IfDef = EPreprocessCond::IfDef;
|
||||
constexpr EPreprocessCond PreprocessCond_IfNotDef = EPreprocessCond::IfNotDef;
|
||||
constexpr EPreprocessCond PreprocessCond_ElIf = EPreprocessCond::ElIf;
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Basic Types
|
||||
|
||||
#define GEN_U8_MIN 0u
|
||||
@ -117,4 +122,4 @@ typedef s8 b8;
|
||||
typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
|
||||
#pragma region Basic Types
|
||||
#pragma endregion Basic Types
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Containers
|
||||
|
||||
template<class Type>
|
||||
@ -424,9 +429,16 @@ struct HashTable
|
||||
|
||||
for ( idx = 0; idx < Entries.num(); idx++ )
|
||||
{
|
||||
Entry* entry;
|
||||
|
||||
Entry* entry;
|
||||
FindResult find_result;
|
||||
|
||||
entry = & Entries[ idx ];
|
||||
find_result = find( entry->Key );
|
||||
|
||||
if ( find_result.PrevIndex < 0 )
|
||||
Hashes[ find_result.HashIndex ] = idx;
|
||||
else
|
||||
Entries[ find_result.PrevIndex ].Next = idx;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,18 @@
|
||||
#pragma endregion Debug
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.hpp"
|
||||
# include "basic_types.hpp"
|
||||
# include "src_start.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
{
|
||||
_printf_err( "%s:(%d): Assert Failure: ", file, line );
|
||||
|
||||
if ( condition )
|
||||
_printf_err( "`%s` ", condition );
|
||||
_printf_err( "`%s` \n", condition );
|
||||
|
||||
if ( msg )
|
||||
{
|
@ -1,4 +1,9 @@
|
||||
#pragma endregion Debug
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "basic_types.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# if _MSC_VER < 1300
|
||||
@ -33,4 +38,26 @@ void assert_handler( char const* condition, char const* file, s32 line, char con
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
|
||||
#if Build_Debug
|
||||
#define GEN_FATAL( ... ) \
|
||||
do \
|
||||
{ \
|
||||
local_persist thread_local \
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
|
||||
\
|
||||
str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
|
||||
GEN_PANIC(buf); \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
|
||||
# define GEN_FATAL( ... ) \
|
||||
do \
|
||||
{ \
|
||||
str_fmt_out_err( __VA_ARGS__ ); \
|
||||
process_exit(1); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
#pragma endregion Debug
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
|
||||
@ -224,7 +229,7 @@ internal GEN_FILE_CLOSE_PROC( _posix_file_close )
|
||||
|
||||
FileOperations const default_file_operations = { _posix_file_read, _posix_file_write, _posix_file_seek, _posix_file_close };
|
||||
|
||||
GEN_NEVER_INLINE GEN_FILE_OPEN_PROC( _posix_file_open )
|
||||
neverinline GEN_FILE_OPEN_PROC( _posix_file_open )
|
||||
{
|
||||
s32 os_mode;
|
||||
switch ( mode & GEN_FILE_MODES )
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
|
||||
typedef u32 FileMode;
|
@ -1,104 +0,0 @@
|
||||
#pragma region Macros
|
||||
|
||||
#define zpl_cast( Type ) ( Type )
|
||||
|
||||
// Keywords
|
||||
|
||||
#define global static // Global variables
|
||||
#define internal static // Internal linkage
|
||||
#define local_persist static // Local Persisting variables
|
||||
|
||||
// Bits
|
||||
|
||||
#define bit( Value ) ( 1 << Value )
|
||||
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
|
||||
|
||||
// Casting
|
||||
#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) )
|
||||
#define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) )
|
||||
#define rcast( Type, Value ) reinterpret_cast< Type >( Value )
|
||||
#define scast( Type, Value ) static_cast< Type >( Value )
|
||||
|
||||
// Num Arguments (Varadics)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
// Supports 0-10 arguments
|
||||
#define num_args_impl( _0, \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
N, ... \
|
||||
) N
|
||||
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,
|
||||
|
||||
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
||||
#define num_args(...) \
|
||||
num_args_impl(_, ## __VA_ARGS__, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
||||
0 \
|
||||
)
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
|
||||
#else
|
||||
// Supports 1-10 arguments
|
||||
#define num_args_impl( \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
N, ... \
|
||||
) N
|
||||
|
||||
#define num_args(...) \
|
||||
num_args_impl( __VA_ARGS__, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
|
||||
)
|
||||
#endif
|
||||
|
||||
// Stringizing
|
||||
#define stringize_va( ... ) #__VA_ARGS__
|
||||
#define stringize( ... ) stringize_va( __VA_ARGS__ )
|
||||
|
||||
// Function do once
|
||||
|
||||
#define do_once() \
|
||||
do \
|
||||
{ \
|
||||
static \
|
||||
bool Done = false; \
|
||||
if ( Done ) \
|
||||
return; \
|
||||
Done = true; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define do_once_start \
|
||||
do \
|
||||
{ \
|
||||
static \
|
||||
bool Done = false; \
|
||||
if ( Done ) \
|
||||
break; \
|
||||
Done = true;
|
||||
|
||||
#define do_once_end \
|
||||
} \
|
||||
while(0);
|
||||
|
||||
#define clamp( x, lower, upper ) min( max( ( x ), ( lower ) ), ( upper ) )
|
||||
#define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( sw )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
|
||||
#define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
|
||||
#define max( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
|
||||
#define min( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
|
||||
#define size_of( x ) ( sw )( sizeof( x ) )
|
||||
|
||||
template< class Type >
|
||||
void swap( Type& a, Type& b )
|
||||
{
|
||||
Type tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
#pragma endregion Macros
|
@ -1,39 +0,0 @@
|
||||
#pragma region String
|
||||
|
||||
String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, buf_size, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
bool String::append_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
return append( buf, res );
|
||||
}
|
||||
|
||||
#pragma endregion String
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
global u32 const _crc32_table[ 256 ] = {
|
||||
@ -82,4 +87,4 @@ u64 crc64( void const* data, sw len )
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma region Hashing
|
||||
#pragma endregion Hashing
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "containers.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
u32 crc32( void const* data, sw len );
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#pragma region Platform Detection
|
||||
|
||||
/* Platform architecture */
|
||||
@ -100,32 +102,25 @@
|
||||
#define GEN_DEF_INLINE static
|
||||
#define GEN_IMPL_INLINE static inline
|
||||
|
||||
#ifdef GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
# define neverinline __declspec( noinline )
|
||||
#elif defined(GEN_COMPILER_GCC)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#elif defined(GEN_COMPILER_CLANG)
|
||||
#if __has_attribute(__always_inline__)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
|
||||
#pragma endregion Platform Detection
|
||||
|
||||
#pragma region Mandatory Includes
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stddef.h>
|
||||
|
||||
# if defined( GEN_SYSTEM_WINDOWS )
|
||||
# include <intrin.h>
|
||||
# endif
|
||||
|
||||
#pragma endregion Mandatory Includes
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS gen::
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
168
project/dependencies/macros.hpp
Normal file
168
project/dependencies/macros.hpp
Normal file
@ -0,0 +1,168 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#define zpl_cast( Type ) ( Type )
|
||||
|
||||
// Keywords
|
||||
|
||||
#define global static // Global variables
|
||||
#define internal static // Internal linkage
|
||||
#define local_persist static // Local Persisting variables
|
||||
|
||||
#ifdef GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
# define neverinline __declspec( noinline )
|
||||
#elif defined(GEN_COMPILER_GCC)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#elif defined(GEN_COMPILER_CLANG)
|
||||
#if __has_attribute(__always_inline__)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
|
||||
// Bits
|
||||
|
||||
#define bit( Value ) ( 1 << Value )
|
||||
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
|
||||
|
||||
// Casting
|
||||
|
||||
#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) )
|
||||
#define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) )
|
||||
#define rcast( Type, Value ) reinterpret_cast< Type >( Value )
|
||||
#define scast( Type, Value ) static_cast< Type >( Value )
|
||||
|
||||
// Num Arguments (Varadics)
|
||||
// #if defined(__GNUC__) || defined(__clang__)
|
||||
// Supports 0-50 arguments
|
||||
#define num_args_impl( _0, \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
||||
_61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
|
||||
_71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
|
||||
_81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
|
||||
_91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
|
||||
N, ... \
|
||||
) N
|
||||
|
||||
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
||||
#define num_args(...) \
|
||||
num_args_impl(_, ## __VA_ARGS__, \
|
||||
100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
|
||||
90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
|
||||
80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
|
||||
70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
|
||||
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
|
||||
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
||||
0 \
|
||||
)
|
||||
|
||||
// #else
|
||||
// This doesn't work on latest msvc so I had to use /Zc:preprocessor flag.
|
||||
|
||||
// Supports 1-50 arguments
|
||||
// #define num_args_impl( \
|
||||
// _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
// _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
// _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
||||
// _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
|
||||
// _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
|
||||
// _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
|
||||
// _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
|
||||
// N, ... \
|
||||
// ) N
|
||||
|
||||
// #define num_args(...) \
|
||||
// num_args_impl( __VA_ARGS__, \
|
||||
// 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
|
||||
// 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
|
||||
// 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
|
||||
// 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
|
||||
// 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
// 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
// 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
|
||||
// )
|
||||
// #endif
|
||||
|
||||
// Stringizing
|
||||
#define stringize_va( ... ) #__VA_ARGS__
|
||||
#define stringize( ... ) stringize_va( __VA_ARGS__ )
|
||||
|
||||
// Function do once
|
||||
|
||||
#define do_once() \
|
||||
do \
|
||||
{ \
|
||||
static \
|
||||
bool Done = false; \
|
||||
if ( Done ) \
|
||||
return; \
|
||||
Done = true; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#define do_once_start \
|
||||
do \
|
||||
{ \
|
||||
static \
|
||||
bool Done = false; \
|
||||
if ( Done ) \
|
||||
break; \
|
||||
Done = true;
|
||||
|
||||
#define do_once_end \
|
||||
} \
|
||||
while(0);
|
||||
|
||||
#define labeled_scope_start if ( false ) {
|
||||
#define labeled_scope_end }
|
||||
|
||||
#define clamp( x, lower, upper ) min( max( ( x ), ( lower ) ), ( upper ) )
|
||||
#define count_of( x ) ( ( size_of( x ) / size_of( 0 [ x ] ) ) / ( ( sw )( ! ( size_of( x ) % size_of( 0 [ x ] ) ) ) ) )
|
||||
#define is_between( x, lower, upper ) ( ( ( lower ) <= ( x ) ) && ( ( x ) <= ( upper ) ) )
|
||||
#define max( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
|
||||
#define min( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
|
||||
#define size_of( x ) ( sw )( sizeof( x ) )
|
||||
|
||||
#if defined( _MSC_VER ) || defined( GEN_COMPILER_TINYC )
|
||||
# define offset_of( Type, element ) ( ( GEN_NS( gen_sw ) ) & ( ( ( Type* )0 )->element ) )
|
||||
#else
|
||||
# define offset_of( Type, element ) __builtin_offsetof( Type, element )
|
||||
#endif
|
||||
|
||||
template< class Type >
|
||||
void swap( Type& a, Type& b )
|
||||
{
|
||||
Type tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
|
||||
#pragma endregion Macros
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
|
||||
void* mem_copy( void* dest, void const* source, sw n )
|
||||
@ -203,6 +208,132 @@ void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw ali
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#pragma region VirtualMemory
|
||||
VirtualMemory vm_from_memory( void* data, sw size )
|
||||
{
|
||||
VirtualMemory vm;
|
||||
vm.data = data;
|
||||
vm.size = size;
|
||||
return vm;
|
||||
}
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS )
|
||||
VirtualMemory vm_alloc( void* addr, sw size )
|
||||
{
|
||||
VirtualMemory vm;
|
||||
GEN_ASSERT( size > 0 );
|
||||
vm.data = VirtualAlloc( addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE );
|
||||
vm.size = size;
|
||||
return vm;
|
||||
}
|
||||
|
||||
b32 vm_free( VirtualMemory vm )
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION info;
|
||||
while ( vm.size > 0 )
|
||||
{
|
||||
if ( VirtualQuery( vm.data, &info, size_of( info ) ) == 0 )
|
||||
return false;
|
||||
if ( info.BaseAddress != vm.data || info.AllocationBase != vm.data || info.State != MEM_COMMIT || info.RegionSize > zpl_cast( uw ) vm.size )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( VirtualFree( vm.data, 0, MEM_RELEASE ) == 0 )
|
||||
return false;
|
||||
vm.data = pointer_add( vm.data, info.RegionSize );
|
||||
vm.size -= info.RegionSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualMemory vm_trim( VirtualMemory vm, sw lead_size, sw size )
|
||||
{
|
||||
VirtualMemory new_vm = { 0 };
|
||||
void* ptr;
|
||||
GEN_ASSERT( vm.size >= lead_size + size );
|
||||
|
||||
ptr = pointer_add( vm.data, lead_size );
|
||||
|
||||
vm_free( vm );
|
||||
new_vm = vm_alloc( ptr, size );
|
||||
if ( new_vm.data == ptr )
|
||||
return new_vm;
|
||||
if ( new_vm.data )
|
||||
vm_free( new_vm );
|
||||
return new_vm;
|
||||
}
|
||||
|
||||
b32 vm_purge( VirtualMemory vm )
|
||||
{
|
||||
VirtualAlloc( vm.data, vm.size, MEM_RESET, PAGE_READWRITE );
|
||||
// NOTE: Can this really fail?
|
||||
return true;
|
||||
}
|
||||
|
||||
sw virtual_memory_page_size( sw* alignment_out )
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
GetSystemInfo( &info );
|
||||
if ( alignment_out )
|
||||
*alignment_out = info.dwAllocationGranularity;
|
||||
return info.dwPageSize;
|
||||
}
|
||||
|
||||
#else
|
||||
# include <sys/mman.h>
|
||||
|
||||
# ifndef MAP_ANONYMOUS
|
||||
# define MAP_ANONYMOUS MAP_ANON
|
||||
# endif
|
||||
VirtualMemory vm_alloc( void* addr, sw size )
|
||||
{
|
||||
VirtualMemory vm;
|
||||
GEN_ASSERT( size > 0 );
|
||||
vm.data = mmap( addr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0 );
|
||||
vm.size = size;
|
||||
return vm;
|
||||
}
|
||||
|
||||
b32 vm_free( VirtualMemory vm )
|
||||
{
|
||||
munmap( vm.data, vm.size );
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualMemory vm_trim( VirtualMemory vm, sw lead_size, sw size )
|
||||
{
|
||||
void* ptr;
|
||||
sw trail_size;
|
||||
GEN_ASSERT( vm.size >= lead_size + size );
|
||||
|
||||
ptr = pointer_add( vm.data, lead_size );
|
||||
trail_size = vm.size - lead_size - size;
|
||||
|
||||
if ( lead_size != 0 )
|
||||
vm_free( vm_from_memory(( vm.data, lead_size ) );
|
||||
if ( trail_size != 0 )
|
||||
vm_free( vm_from_memory( ptr, trail_size ) );
|
||||
return vm_from_memory( ptr, size );
|
||||
}
|
||||
|
||||
b32 vm_purge( VirtualMemory vm )
|
||||
{
|
||||
int err = madvise( vm.data, vm.size, MADV_DONTNEED );
|
||||
return err != 0;
|
||||
}
|
||||
|
||||
sw virtual_memory_page_size( sw* alignment_out )
|
||||
{
|
||||
// TODO: Is this always true?
|
||||
sw result = zpl_cast( sw ) sysconf( _SC_PAGE_SIZE );
|
||||
if ( alignment_out )
|
||||
*alignment_out = result;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma endregion VirtualMemory
|
||||
|
||||
void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
|
||||
{
|
||||
Arena* arena = rcast(Arena*, allocator_data);
|
||||
@ -221,7 +352,7 @@ void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw a
|
||||
if ( arena->TotalUsed + total_size > (sw) arena->TotalSize )
|
||||
{
|
||||
// zpl__printf_err("%s", "Arena out of memory\n");
|
||||
fatal("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
|
||||
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
|
||||
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
|
||||
@ -360,6 +365,33 @@ GEN_IMPL_INLINE void zero_size( void* ptr, sw size )
|
||||
mem_set( ptr, 0, size );
|
||||
}
|
||||
|
||||
struct VirtualMemory
|
||||
{
|
||||
void* data;
|
||||
sw size;
|
||||
};
|
||||
|
||||
//! Initialize virtual memory from existing data.
|
||||
VirtualMemory vm_from_memory( void* data, sw size );
|
||||
|
||||
//! Allocate virtual memory at address with size.
|
||||
|
||||
//! @param addr The starting address of the region to reserve. If NULL, it lets operating system to decide where to allocate it.
|
||||
//! @param size The size to serve.
|
||||
VirtualMemory vm_alloc( void* addr, sw size );
|
||||
|
||||
//! Release the virtual memory.
|
||||
b32 vm_free( VirtualMemory vm );
|
||||
|
||||
//! Trim virtual memory.
|
||||
VirtualMemory vm_trim( VirtualMemory vm, sw lead_size, sw size );
|
||||
|
||||
//! Purge virtual memory.
|
||||
b32 gen_vm_purge( VirtualMemory vm );
|
||||
|
||||
//! Retrieve VM's page size and alignment.
|
||||
sw gen_virtual_memory_page_size( sw* alignment_out );
|
||||
|
||||
struct Arena
|
||||
{
|
||||
static
|
||||
@ -445,6 +477,45 @@ struct Arena
|
||||
}
|
||||
};
|
||||
|
||||
// Just a wrapper around using an arena with memory associated with its scope instead of from an allocator.
|
||||
// Used for static segment or stack allocations.
|
||||
template< s32 Size >
|
||||
struct FixedArena
|
||||
{
|
||||
static
|
||||
FixedArena init()
|
||||
{
|
||||
FixedArena result = { Arena::init_from_memory( result.memory, Size ), {0} };
|
||||
return result;
|
||||
}
|
||||
|
||||
sw size_remaining( sw alignment )
|
||||
{
|
||||
return arena.size_remaining( alignment );
|
||||
}
|
||||
|
||||
operator AllocatorInfo()
|
||||
{
|
||||
return { Arena::allocator_proc, &arena };
|
||||
}
|
||||
|
||||
Arena arena;
|
||||
char memory[ Size ];
|
||||
};
|
||||
|
||||
using Arena_1KB = FixedArena< kilobytes( 1 ) >;
|
||||
using Arena_4KB = FixedArena< kilobytes( 4 ) >;
|
||||
using Arena_8KB = FixedArena< kilobytes( 8 ) >;
|
||||
using Arena_16KB = FixedArena< kilobytes( 16 ) >;
|
||||
using Arena_32KB = FixedArena< kilobytes( 32 ) >;
|
||||
using Arena_64KB = FixedArena< kilobytes( 64 ) >;
|
||||
using Arena_128KB = FixedArena< kilobytes( 128 ) >;
|
||||
using Arena_256KB = FixedArena< kilobytes( 256 ) >;
|
||||
using Arena_512KB = FixedArena< kilobytes( 512 ) >;
|
||||
using Arena_1MB = FixedArena< megabytes( 1 ) >;
|
||||
using Arena_2MB = FixedArena< megabytes( 2 ) >;
|
||||
using Arena_4MB = FixedArena< megabytes( 4 ) >;
|
||||
|
||||
struct Pool
|
||||
{
|
||||
static
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
#define _adt_fprintf( s_, fmt_, ... ) \
|
||||
@ -799,7 +803,6 @@ ADT_Error adt_str_to_number_strict( ADT_Node* node )
|
||||
# define GEN_CSV_ASSERT( msg )
|
||||
#endif
|
||||
|
||||
|
||||
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim )
|
||||
{
|
||||
CSV_Error error = ECSV_Error__NONE;
|
||||
@ -1104,3 +1107,4 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
enum ADT_Type : u32
|
||||
@ -423,3 +427,4 @@ GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
@ -1,3 +1,10 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
# include "strings.hpp"
|
||||
# include "string_ops.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
enum
|
||||
@ -47,7 +54,8 @@ internal sw _print_string( char* text, sw max_len, _format_info* info, char cons
|
||||
}
|
||||
|
||||
if ( info && info->precision >= 0 )
|
||||
len = str_len( str, info->precision );
|
||||
// Made the design decision for this library that precision is the length of the string.
|
||||
len = info->precision;
|
||||
else
|
||||
len = str_len( str );
|
||||
|
||||
@ -410,6 +418,15 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
|
||||
len = _print_string( text, remaining, &info, va_arg( va, char* ) );
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
{
|
||||
String gen_str = String { va_arg( va, char*) };
|
||||
|
||||
info.precision = gen_str.length();
|
||||
len = _print_string( text, remaining, &info, gen_str );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r' :
|
||||
len = _print_repeated_char( text, remaining, &info, va_arg( va, int ) );
|
||||
break;
|
||||
@ -541,6 +558,16 @@ sw str_fmt_file( struct FileInfo* f, char const* fmt, ... )
|
||||
return res;
|
||||
}
|
||||
|
||||
sw str_fmt( char* str, sw n, char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( str, n, fmt, va );
|
||||
va_end( va );
|
||||
return res;
|
||||
}
|
||||
|
||||
sw str_fmt_out_va( char const* fmt, va_list va )
|
||||
{
|
||||
return str_fmt_file_va( file_get_standard( EFileStandard_OUTPUT ), fmt, va );
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
struct FileInfo;
|
||||
@ -9,12 +14,13 @@ struct FileInfo;
|
||||
// NOTE: A locally persisting buffer is used internally
|
||||
char* str_fmt_buf ( char const* fmt, ... );
|
||||
char* str_fmt_buf_va ( char const* fmt, va_list va );
|
||||
sw str_fmt ( char* str, sw n, char const* fmt, ... );
|
||||
sw str_fmt_va ( char* str, sw n, char const* fmt, va_list va );
|
||||
sw str_fmt_file ( FileInfo* f, char const* fmt, ... );
|
||||
sw str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
|
||||
sw str_fmt_out_va ( char const* fmt, va_list va );
|
||||
sw str_fmt_out_err ( char const* fmt, ... );
|
||||
sw str_fmt_out_err_va( char const* fmt, va_list va );
|
||||
sw str_fmt_file ( FileInfo* f, char const* fmt, ... );
|
||||
sw str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
|
||||
|
||||
constexpr
|
||||
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
|
||||
@ -32,29 +38,4 @@ sw log_fmt(char const* fmt, ...)
|
||||
return res;
|
||||
}
|
||||
|
||||
inline
|
||||
sw fatal(char const* fmt, ...)
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
va_list va;
|
||||
|
||||
#if Build_Debug
|
||||
va_start(va, fmt);
|
||||
str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
assert_crash(buf);
|
||||
return -1;
|
||||
#else
|
||||
va_start(va, fmt);
|
||||
str_fmt_out_err_va( fmt, va);
|
||||
va_end(va);
|
||||
|
||||
exit(1);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros and Includes
|
||||
|
||||
# include <stdio.h>
|
@ -1,3 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.hpp"
|
||||
# include "debug.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
internal
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
GEN_DEF_INLINE const char* char_first_occurence( const char* str, char c );
|
130
project/dependencies/strings.cpp
Normal file
130
project/dependencies/strings.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "hashing.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region String
|
||||
|
||||
String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, buf_size, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
String String::make_length( AllocatorInfo allocator, char const* str, sw length )
|
||||
{
|
||||
constexpr sw header_size = sizeof( Header );
|
||||
|
||||
s32 alloc_size = header_size + length + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
Header&
|
||||
header = * rcast(Header*, allocation);
|
||||
header = { allocator, length, length };
|
||||
|
||||
String result = { rcast( char*, allocation) + header_size };
|
||||
|
||||
if ( length && str )
|
||||
mem_copy( result, str, length );
|
||||
else
|
||||
mem_set( result, 0, alloc_size - header_size );
|
||||
|
||||
result[ length ] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
String String::make_reserve( AllocatorInfo allocator, sw capacity )
|
||||
{
|
||||
constexpr sw header_size = sizeof( Header );
|
||||
|
||||
s32 alloc_size = header_size + capacity + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
mem_set( allocation, 0, alloc_size );
|
||||
|
||||
Header*
|
||||
header = rcast(Header*, allocation);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = capacity;
|
||||
header->Length = 0;
|
||||
|
||||
String result = { rcast(char*, allocation) + header_size };
|
||||
return result;
|
||||
}
|
||||
|
||||
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
bool String::append_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
return append( buf, res );
|
||||
}
|
||||
|
||||
bool String::make_space_for( char const* str, sw add_len )
|
||||
{
|
||||
sw available = avail_space();
|
||||
|
||||
// NOTE: Return if there is enough space left
|
||||
if ( available >= add_len )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sw new_len, old_size, new_size;
|
||||
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = get_header().Allocator;
|
||||
Header* header = nullptr;
|
||||
|
||||
new_len = grow_formula( length() + add_len );
|
||||
ptr = & get_header();
|
||||
old_size = size_of( Header ) + length() + 1;
|
||||
new_size = size_of( Header ) + new_len + 1;
|
||||
|
||||
new_ptr = resize( allocator, ptr, old_size, new_size );
|
||||
|
||||
if ( new_ptr == nullptr )
|
||||
return false;
|
||||
|
||||
header = zpl_cast( Header* ) new_ptr;
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
Data = rcast( char*, header + 1 );
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
#pragma endregion String
|
@ -1,4 +1,9 @@
|
||||
#pragma region String
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "hashing.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Strings
|
||||
|
||||
// Constant string with length.
|
||||
struct StrC
|
||||
@ -12,18 +17,14 @@ struct StrC
|
||||
}
|
||||
};
|
||||
|
||||
#define txt_StrC( text ) StrC { sizeof( text ) - 1, text }
|
||||
#define cast_to_strc( str ) * rcast( StrC*, str - sizeof(sw) )
|
||||
#define txt( text ) StrC { sizeof( text ) - 1, text }
|
||||
|
||||
StrC to_StrC( char const* str )
|
||||
StrC to_str( char const* str )
|
||||
{
|
||||
return { str_len( str ), str };
|
||||
}
|
||||
|
||||
sw StrC_len( char const* str )
|
||||
{
|
||||
return (sw) ( str - 1 );
|
||||
}
|
||||
|
||||
// Dynamic String
|
||||
// This is directly based off the ZPL string api.
|
||||
// They used a header pattern
|
||||
@ -33,8 +34,8 @@ struct String
|
||||
struct Header
|
||||
{
|
||||
AllocatorInfo Allocator;
|
||||
sw Length;
|
||||
sw Capacity;
|
||||
sw Length;
|
||||
};
|
||||
|
||||
static
|
||||
@ -58,54 +59,10 @@ struct String
|
||||
}
|
||||
|
||||
static
|
||||
String make_reserve( AllocatorInfo allocator, sw capacity )
|
||||
{
|
||||
constexpr sw header_size = sizeof( Header );
|
||||
|
||||
s32 alloc_size = header_size + capacity + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
mem_set( allocation, 0, alloc_size );
|
||||
|
||||
Header*
|
||||
header = rcast(Header*, allocation);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = capacity;
|
||||
header->Length = 0;
|
||||
|
||||
String result = { (char*)allocation + header_size };
|
||||
return result;
|
||||
}
|
||||
String make_reserve( AllocatorInfo allocator, sw capacity );
|
||||
|
||||
static
|
||||
String make_length( AllocatorInfo allocator, char const* str, sw length )
|
||||
{
|
||||
constexpr sw header_size = sizeof( Header );
|
||||
|
||||
s32 alloc_size = header_size + length + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
Header&
|
||||
header = * rcast(Header*, allocation);
|
||||
header = { allocator, length, length };
|
||||
|
||||
String result = { rcast( char*, allocation) + header_size };
|
||||
|
||||
if ( length && str )
|
||||
mem_copy( result, str, length );
|
||||
else
|
||||
mem_set( result, 0, alloc_size - header_size );
|
||||
|
||||
result[ length ] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
String make_length( AllocatorInfo allocator, char const* str, sw length );
|
||||
|
||||
static
|
||||
String fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... );
|
||||
@ -142,43 +99,11 @@ struct String
|
||||
return true;
|
||||
}
|
||||
|
||||
bool make_space_for( char const* str, sw add_len )
|
||||
bool make_space_for( char const* str, sw add_len );
|
||||
|
||||
bool append( char c )
|
||||
{
|
||||
sw available = avail_space();
|
||||
|
||||
// NOTE: Return if there is enough space left
|
||||
if ( available >= add_len )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sw new_len, old_size, new_size;
|
||||
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = get_header().Allocator;
|
||||
Header* header = nullptr;
|
||||
|
||||
new_len = grow_formula( length() + add_len );
|
||||
ptr = & get_header();
|
||||
old_size = size_of( Header ) + length() + 1;
|
||||
new_size = size_of( Header ) + new_len + 1;
|
||||
|
||||
new_ptr = resize( allocator, ptr, old_size, new_size );
|
||||
|
||||
if ( new_ptr == nullptr )
|
||||
return false;
|
||||
|
||||
header = zpl_cast( Header* ) new_ptr;
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
Data = rcast( char*, header + 1 );
|
||||
|
||||
return str;
|
||||
}
|
||||
return append( & c, 1 );
|
||||
}
|
||||
|
||||
bool append( char const* str )
|
||||
@ -213,7 +138,7 @@ struct String
|
||||
|
||||
bool append( const String other )
|
||||
{
|
||||
return append( other.Data, other.length() );;
|
||||
return append( other.Data, other.length() );
|
||||
}
|
||||
|
||||
bool append_fmt( char const* fmt, ... );
|
||||
@ -226,6 +151,11 @@ struct String
|
||||
return header.Capacity - header.Length;
|
||||
}
|
||||
|
||||
char& back()
|
||||
{
|
||||
return Data[ length() - 1 ];
|
||||
}
|
||||
|
||||
sw capacity() const
|
||||
{
|
||||
Header const&
|
||||
@ -267,6 +197,50 @@ struct String
|
||||
return header.Length;
|
||||
}
|
||||
|
||||
void skip_line()
|
||||
{
|
||||
#define current (*scanner)
|
||||
char* scanner = Data;
|
||||
while ( current != '\r' && current != '\n' )
|
||||
{
|
||||
++ scanner;
|
||||
}
|
||||
|
||||
s32 new_length = scanner - Data;
|
||||
|
||||
if ( current == '\r' )
|
||||
{
|
||||
new_length += 1;
|
||||
}
|
||||
|
||||
mem_move( Data, scanner, new_length );
|
||||
|
||||
Header* header = & get_header();
|
||||
header->Length = new_length;
|
||||
#undef current
|
||||
}
|
||||
|
||||
void strip_space()
|
||||
{
|
||||
char* write_pos = Data;
|
||||
char* read_pos = Data;
|
||||
|
||||
while ( * read_pos)
|
||||
{
|
||||
if ( ! char_is_space( *read_pos ))
|
||||
{
|
||||
*write_pos = *read_pos;
|
||||
write_pos++;
|
||||
}
|
||||
read_pos++;
|
||||
}
|
||||
|
||||
write_pos[0] = '\0'; // Null-terminate the modified string
|
||||
|
||||
// Update the length if needed
|
||||
get_header().Length = write_pos - Data;
|
||||
}
|
||||
|
||||
void trim( char const* cut_set )
|
||||
{
|
||||
sw len = 0;
|
||||
@ -295,14 +269,52 @@ struct String
|
||||
return trim( " \t\r\n\v\f" );
|
||||
}
|
||||
|
||||
// Debug function that provides a copy of the string with whitespace characters visualized.
|
||||
String visualize_whitespace() const
|
||||
{
|
||||
Header* header = (Header*)(Data - sizeof(Header));
|
||||
|
||||
String result = make_reserve(header->Allocator, length() * 2); // Assume worst case for space requirements.
|
||||
|
||||
for ( char c : *this )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case ' ':
|
||||
result.append( txt("·") );
|
||||
break;
|
||||
case '\t':
|
||||
result.append( txt("→") );
|
||||
break;
|
||||
case '\n':
|
||||
result.append( txt("↵") );
|
||||
break;
|
||||
case '\r':
|
||||
result.append( txt("⏎") );
|
||||
break;
|
||||
case '\v':
|
||||
result.append( txt("⇕") );
|
||||
break;
|
||||
case '\f':
|
||||
result.append( txt("⌂") );
|
||||
break;
|
||||
default:
|
||||
result.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// For-range support
|
||||
|
||||
char* begin()
|
||||
char* begin() const
|
||||
{
|
||||
return Data;
|
||||
}
|
||||
|
||||
char* end()
|
||||
char* end() const
|
||||
{
|
||||
Header const&
|
||||
header = * rcast( Header const*, Data - sizeof( Header ));
|
||||
@ -327,11 +339,7 @@ struct String
|
||||
|
||||
operator StrC() const
|
||||
{
|
||||
return
|
||||
{
|
||||
length(),
|
||||
Data
|
||||
};
|
||||
return { length(), Data };
|
||||
}
|
||||
|
||||
// Used with cached strings
|
||||
@ -358,18 +366,20 @@ struct String
|
||||
return Data[ index ];
|
||||
}
|
||||
|
||||
char* Data = nullptr;
|
||||
char* Data;
|
||||
};
|
||||
|
||||
struct String_POD
|
||||
{
|
||||
char* Data;
|
||||
|
||||
operator String()
|
||||
{
|
||||
return * rcast(String*, this);
|
||||
}
|
||||
};
|
||||
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
|
||||
|
||||
#pragma endregion String
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
using StringTable = HashTable<String const>;
|
||||
|
||||
// Represents strings cached with the string table.
|
||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||
using StringCached = String const;
|
||||
|
||||
#pragma endregion Strings
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
@ -1,5 +1,6 @@
|
||||
Invalid
|
||||
Untyped
|
||||
NewLine
|
||||
Comment
|
||||
Access_Private
|
||||
Access_Protected
|
||||
@ -8,6 +9,10 @@ PlatformAttributes
|
||||
Class
|
||||
Class_Fwd
|
||||
Class_Body
|
||||
Constructor
|
||||
Constructor_Fwd
|
||||
Destructor
|
||||
Destructor_Fwd
|
||||
Enum
|
||||
Enum_Fwd
|
||||
Enum_Body
|
||||
@ -32,7 +37,15 @@ Operator_Member_Fwd
|
||||
Operator_Cast
|
||||
Operator_Cast_Fwd
|
||||
Parameters
|
||||
Preprocessor_Include
|
||||
Preprocess_Define
|
||||
Preprocess_Include
|
||||
Preprocess_If
|
||||
Preprocess_IfDef
|
||||
Preprocess_IfNotDef
|
||||
Preprocess_ElIf
|
||||
Preprocess_Else
|
||||
Preprocess_EndIf
|
||||
Preprocess_Pragma
|
||||
Specifiers
|
||||
Struct
|
||||
Struct_Fwd
|
|
@ -4,11 +4,13 @@ Constexpr, constexpr
|
||||
Constinit, constinit
|
||||
Explicit, explicit
|
||||
External_Linkage, extern
|
||||
ForceInline, forceinline
|
||||
Global, global
|
||||
Inline, inline
|
||||
Internal_Linkage, internal
|
||||
Local_Persist, local_persist
|
||||
Mutable, mutable
|
||||
NeverInline, neverinline
|
||||
Ptr, *
|
||||
Ref, &
|
||||
Register, register
|
||||
@ -19,4 +21,6 @@ Volatile, volatile
|
||||
Virtual, virtual
|
||||
Const, const
|
||||
Final, final
|
||||
NoExceptions, noexcept
|
||||
Override, override
|
||||
Pure, = 0
|
|
@ -7,8 +7,8 @@ Access_StaticSymbol, "::"
|
||||
Ampersand, "&"
|
||||
Ampersand_DBL, "&&"
|
||||
Assign_Classifer, ":"
|
||||
Attribute_Open, "[["
|
||||
Attribute_Close, "]]"
|
||||
Attribute_Open, "[["
|
||||
Attribute_Close, "]]"
|
||||
BraceCurly_Open, "{"
|
||||
BraceCurly_Close, "}"
|
||||
BraceSquare_Open, "["
|
||||
@ -16,7 +16,9 @@ BraceSquare_Close, "]"
|
||||
Capture_Start, "("
|
||||
Capture_End, ")"
|
||||
Comment, "__comment__"
|
||||
Char, "__char__"
|
||||
Comment_End, "__comment_end__"
|
||||
Comment_Start, "__comment_start__"
|
||||
Char, "__character__"
|
||||
Comma, ","
|
||||
Decl_Class, "class"
|
||||
Decl_GNU_Attribute, "__attribute__"
|
||||
@ -35,36 +37,57 @@ Decl_Union, "union"
|
||||
Identifier, "__identifier__"
|
||||
Module_Import, "import"
|
||||
Module_Export, "export"
|
||||
Number, "number"
|
||||
Operator, "operator"
|
||||
Preprocessor_Directive, "#"
|
||||
Preprocessor_Include, "include"
|
||||
NewLine, "__new_line__"
|
||||
Number, "__number__"
|
||||
Operator, "__operator__"
|
||||
Preprocess_Hash, "#"
|
||||
Preprocess_Define, "define"
|
||||
Preprocess_If, "if"
|
||||
Preprocess_IfDef, "ifdef"
|
||||
Preprocess_IfNotDef, "ifndef"
|
||||
Preprocess_ElIf, "elif"
|
||||
Preprocess_Else, "else"
|
||||
Preprocess_EndIf, "endif"
|
||||
Preprocess_Include, "include"
|
||||
Preprocess_Pragma, "pragma"
|
||||
Preprocess_Content, "__macro_content__"
|
||||
Preprocess_Macro, "__macro__"
|
||||
Preprocess_Unsupported, "__unsupported__"
|
||||
Spec_Alignas, "alignas"
|
||||
Spec_Const, "const"
|
||||
Spec_Consteval, "consteval"
|
||||
Spec_Constexpr, "constexpr"
|
||||
Spec_Constinit, "constinit"
|
||||
Spec_Explicit, "explicit"
|
||||
Spec_Explicit, "explicit"
|
||||
Spec_Extern, "extern"
|
||||
Spec_Final, "final"
|
||||
Spec_Global, "global"
|
||||
Spec_Final, "final"
|
||||
Spec_ForceInline, "forceinline"
|
||||
Spec_Global, "global"
|
||||
Spec_Inline, "inline"
|
||||
Spec_Internal_Linkage, "internal"
|
||||
Spec_LocalPersist, "local_persist"
|
||||
Spec_Mutable, "mutable"
|
||||
Spec_NeverInline, "neverinline"
|
||||
Spec_Override, "override"
|
||||
Spec_Static, "static"
|
||||
Spec_ThreadLocal, "thread_local"
|
||||
Spec_Volatile, "volatile"
|
||||
Spec_Virtual, "virtual"
|
||||
Star, "*"
|
||||
Statement_End, ";"
|
||||
StaticAssert, "static_assert"
|
||||
String, "__string__"
|
||||
Type_Unsigned, "unsigned"
|
||||
Type_Unsigned, "unsigned"
|
||||
Type_Signed, "signed"
|
||||
Type_Short, "short"
|
||||
Type_Long, "long"
|
||||
Type_char, "char"
|
||||
Type_int, "int"
|
||||
Type_double, "double"
|
||||
Type_char, "char"
|
||||
Type_int, "int"
|
||||
Type_double, "double"
|
||||
Type_MS_int8, "__int8"
|
||||
Type_MS_int16, "__int16"
|
||||
Type_MS_int32, "__int32"
|
||||
Type_MS_int64, "__int64"
|
||||
Type_MS_W64, "_W64"
|
||||
Varadic_Argument, "..."
|
||||
Attributes_Start, "__attrib_start__"
|
||||
__Attributes_Start, "__attrib_start__"
|
|
@ -1,43 +0,0 @@
|
||||
void Builder::print( Code code )
|
||||
{
|
||||
Buffer.append_fmt( "%s\n", code->to_string() );
|
||||
}
|
||||
|
||||
void Builder::print_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
Buffer.append( buf, res );
|
||||
}
|
||||
|
||||
bool Builder::open( char const* path )
|
||||
{
|
||||
FileError error = file_open_mode( & File, EFileMode_WRITE, path );
|
||||
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Builder::write()
|
||||
{
|
||||
bool result = file_write( & File, Buffer, Buffer.length() );
|
||||
|
||||
if ( result == false )
|
||||
log_failure("gen::File::write - Failed to write to file: %s", file_name( & File ) );
|
||||
|
||||
file_close( & File );
|
||||
Buffer.free();
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
struct Builder
|
||||
{
|
||||
FileInfo File;
|
||||
String Buffer;
|
||||
|
||||
void print( Code );
|
||||
void print_fmt( char const* fmt, ... );
|
||||
|
||||
bool open( char const* path );
|
||||
void write();
|
||||
};
|
@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "gen.scanner.hpp"
|
||||
|
||||
namespace gen {
|
||||
|
||||
struct Policy
|
||||
{
|
||||
// Nothing for now.
|
||||
};
|
||||
|
||||
enum class SymbolType : u32
|
||||
{
|
||||
Code,
|
||||
Line,
|
||||
Marker
|
||||
};
|
||||
|
||||
struct Editor
|
||||
{
|
||||
enum RequestType : u32
|
||||
{
|
||||
Add,
|
||||
Replace,
|
||||
Remove
|
||||
};
|
||||
|
||||
struct SymbolData
|
||||
{
|
||||
Policy Policy;
|
||||
SymbolInfo Info;
|
||||
};
|
||||
|
||||
struct RequestEntry
|
||||
{
|
||||
union {
|
||||
SymbolData Symbol;
|
||||
String Specification;
|
||||
};
|
||||
RequestType Type;
|
||||
};
|
||||
|
||||
struct Receipt
|
||||
{
|
||||
StringCached File;
|
||||
Code Found;
|
||||
Code Written;
|
||||
bool Result;
|
||||
};
|
||||
|
||||
static AllocatorInfo Allocator;
|
||||
|
||||
static void set_allocator( AllocatorInfo allocator );
|
||||
|
||||
Array<FileInfo> Files;
|
||||
String Buffer;
|
||||
Array<RequestEntry> Requests;
|
||||
|
||||
void add_files( s32 num, char const** files );
|
||||
|
||||
void add ( SymbolInfo definition, Policy policy, Code to_inject );
|
||||
void remove ( SymbolInfo definition, Policy policy );
|
||||
void replace( SymbolInfo definition, Policy policy, Code to_replace);
|
||||
|
||||
# ifdef GEN_FEATURE_EDITOR_REFACTOR
|
||||
void refactor( char const* file_path, char const* specification_path );
|
||||
# endif
|
||||
|
||||
bool process_requests( Array<Receipt> out_receipts );
|
||||
};
|
||||
|
||||
// namespace gen
|
||||
};
|
@ -1,73 +0,0 @@
|
||||
#pragma once
|
||||
#include "gen.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
Code scan_file( char const* path )
|
||||
{
|
||||
FileInfo file;
|
||||
|
||||
FileError error = file_open_mode( & file, EFileMode_READ, path );
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
fatal( "scan_file: Could not open: %s", path );
|
||||
}
|
||||
|
||||
sw fsize = file_size( & file );
|
||||
if ( fsize <= 0 )
|
||||
{
|
||||
fatal("scan_file: %s is empty", path );
|
||||
}
|
||||
|
||||
String str = String::make_reserve( GlobalAllocator, fsize );
|
||||
file_read( & file, str, fsize );
|
||||
str.get_header().Length = fsize;
|
||||
|
||||
file_close( & file );
|
||||
|
||||
return untyped_str( str );
|
||||
}
|
||||
|
||||
struct Policy
|
||||
{
|
||||
// Nothing for now.
|
||||
};
|
||||
|
||||
struct SymbolInfo
|
||||
{
|
||||
StringCached File;
|
||||
char const* Marker;
|
||||
Code Signature;
|
||||
};
|
||||
|
||||
|
||||
struct Scanner
|
||||
{
|
||||
struct RequestEntry
|
||||
{
|
||||
SymbolInfo Info;
|
||||
};
|
||||
|
||||
struct Receipt
|
||||
{
|
||||
StringCached File;
|
||||
Code Defintion;
|
||||
bool Result;
|
||||
};
|
||||
|
||||
AllocatorInfo MemAlloc;
|
||||
|
||||
static void set_allocator( AllocatorInfo allocator );
|
||||
|
||||
Array<FileInfo> Files;
|
||||
String Buffer;
|
||||
Array<RequestEntry> Requests;
|
||||
|
||||
void add_files( s32 num, char const** files );
|
||||
|
||||
void add( SymbolInfo signature, Policy policy );
|
||||
|
||||
bool process_requests( Array<Receipt> out_receipts );
|
||||
};
|
||||
|
||||
GEN_NS_END
|
@ -1,200 +0,0 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
#include "filesystem/gen.scanner.hpp"
|
||||
#include "helpers/gen.helper.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
bool namespace_by_default = true;
|
||||
|
||||
constexpr StrC nspace_default = txt_StrC(R"(
|
||||
#if defined(GEN_DONT_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#elif ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
)");
|
||||
|
||||
constexpr StrC nspace_non_default = txt_StrC(R"(
|
||||
#if ! defined(GEN_USE_NAMESPACE) && ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#elif ! defined(GEN_NS_BEGIN)
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
)");
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( "helpers/gen.push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( "helpers/gen.pop_ignores.inline.hpp" );
|
||||
|
||||
// gen_dep.hpp
|
||||
{
|
||||
Code header_start = scan_file( "dependencies/gen.header_start.hpp" );
|
||||
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
|
||||
Code macros = scan_file( "dependencies/gen.macros.hpp" );
|
||||
Code basic_types = scan_file( "dependencies/gen.basic_types.hpp" );
|
||||
Code debug = scan_file( "dependencies/gen.debug.hpp" );
|
||||
Code memory = scan_file( "dependencies/gen.memory.hpp" );
|
||||
Code string_ops = scan_file( "dependencies/gen.string_ops.hpp" );
|
||||
Code printing = scan_file( "dependencies/gen.printing.hpp" );
|
||||
Code containers = scan_file( "dependencies/gen.containers.hpp" );
|
||||
Code hashing = scan_file( "dependencies/gen.hashing.hpp" );
|
||||
Code string = scan_file( "dependencies/gen.string.hpp" );
|
||||
Code file_handling = scan_file( "dependencies/gen.file_handling.hpp" );
|
||||
Code parsing = scan_file( "dependencies/gen.parsing.hpp" );
|
||||
Code timing = scan_file( "dependencies/gen.timing.hpp" );
|
||||
|
||||
Builder
|
||||
deps_header;
|
||||
deps_header.open("gen/gen_dep.hpp");
|
||||
deps_header.print_fmt("// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n");
|
||||
deps_header.print_fmt("#pragma once\n\n");
|
||||
deps_header.print( header_start );
|
||||
deps_header.print( nspace_macro );
|
||||
deps_header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
|
||||
deps_header.print( macros );
|
||||
deps_header.print( basic_types );
|
||||
deps_header.print( debug );
|
||||
deps_header.print( memory );
|
||||
deps_header.print( string_ops );
|
||||
deps_header.print( printing );
|
||||
deps_header.print( containers );
|
||||
deps_header.print( hashing );
|
||||
deps_header.print( string );
|
||||
deps_header.print( file_handling );
|
||||
deps_header.print( parsing );
|
||||
deps_header.print( timing );
|
||||
|
||||
deps_header.print_fmt( "GEN_NS_END\n\n");
|
||||
deps_header.write();
|
||||
}
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
CodeInclude header = def_include( txt_StrC("gen_dep.hpp") );
|
||||
Code impl_start = scan_file( "dependencies/gen.impl_start.cpp" );
|
||||
Code debug = scan_file( "dependencies/gen.debug.cpp" );
|
||||
Code string_ops = scan_file( "dependencies/gen.string_ops.cpp" );
|
||||
Code printing = scan_file( "dependencies/gen.printing.cpp" );
|
||||
Code memory = scan_file( "dependencies/gen.memory.cpp" );
|
||||
Code parsing = scan_file( "dependencies/gen.parsing.cpp" );
|
||||
Code hashing = scan_file( "dependencies/gen.hashing.cpp" );
|
||||
Code string = scan_file( "dependencies/gen.string.cpp" );
|
||||
Code timing = scan_file( "dependencies/gen.timing.cpp" );
|
||||
|
||||
Builder
|
||||
deps_impl;
|
||||
deps_impl.open("gen/gen_dep.cpp");
|
||||
deps_impl.print_fmt("// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n\n");
|
||||
deps_impl.print( impl_start );
|
||||
deps_impl.print( header );
|
||||
deps_impl.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
|
||||
deps_impl.print( debug );
|
||||
deps_impl.print( string_ops );
|
||||
deps_impl.print( printing );
|
||||
deps_impl.print( hashing );
|
||||
deps_impl.print( memory );
|
||||
deps_impl.print( parsing );
|
||||
deps_impl.print( string );
|
||||
deps_impl.print( timing );
|
||||
|
||||
deps_impl.print_fmt( "GEN_NS_END\n\n");
|
||||
deps_impl.write();
|
||||
}
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( "components/gen.header_start.hpp" );
|
||||
Code nspace_macro = untyped_str( namespace_by_default ? nspace_default : nspace_non_default );
|
||||
Code types = scan_file( "components/gen.types.hpp" );
|
||||
Code data_structs = scan_file( "components/gen.data_structures.hpp" );
|
||||
Code interface = scan_file( "components/gen.interface.hpp" );
|
||||
Code header_end = scan_file( "components/gen.header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode( "./components/ECode.csv" );
|
||||
CodeBody eoperator = gen_eoperator( "./components/EOperator.csv" );
|
||||
CodeBody especifier = gen_especifier( "./components/ESpecifier.csv" );
|
||||
|
||||
Code builder = scan_file( "filesystem/gen.builder.hpp" );
|
||||
|
||||
Builder
|
||||
header;
|
||||
header.open( "gen/gen.hpp" );
|
||||
header.print_fmt("#pragma once\n\n");
|
||||
header.print( push_ignores );
|
||||
header.print( header_start );
|
||||
header.print( nspace_macro );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
|
||||
header.print_fmt("#pragma region Types\n\n");
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
header.print_fmt("#pragma endregion Types\n\n");
|
||||
|
||||
header.print( data_structs );
|
||||
header.print( interface );
|
||||
header.print( header_end );
|
||||
|
||||
header.print( builder );
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n\n");
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen.cpp
|
||||
{
|
||||
Code impl_start = scan_file( "components/gen.impl_start.cpp" );
|
||||
CodeInclude header = def_include( txt_StrC("gen.hpp") );
|
||||
Code data = scan_file( "components/gen.data.cpp" );
|
||||
Code ast_case_macros = scan_file( "components/gen.ast_case_macros.cpp" );
|
||||
Code ast = scan_file( "components/gen.ast.cpp" );
|
||||
Code interface = scan_file( "components/gen.interface.cpp" );
|
||||
Code upfront = scan_file( "components/gen.interface.upfront.cpp" );
|
||||
Code parsing = scan_file( "components/gen.interface.parsing.cpp" );
|
||||
Code untyped = scan_file( "components/gen.untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( "components/ETokType.csv", "components/AttributeTokens.csv" );
|
||||
CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
|
||||
|
||||
Code builder = scan_file( "filesystem/gen.builder.cpp" );
|
||||
|
||||
Builder
|
||||
impl;
|
||||
impl.open( "gen/gen.cpp" );
|
||||
impl.print( push_ignores );
|
||||
impl.print( impl_start );
|
||||
impl.print( header );
|
||||
impl.print_fmt( "\nGEN_NS_BEGIN\n\n");
|
||||
|
||||
impl.print( data );
|
||||
impl.print( ast_case_macros );
|
||||
impl.print( ast );
|
||||
impl.print( interface );
|
||||
impl.print( upfront );
|
||||
impl.print( parser_nspace );
|
||||
impl.print( parsing );
|
||||
impl.print( untyped );
|
||||
|
||||
impl.print( builder );
|
||||
impl.print_fmt( "GEN_NS_END\n\n");
|
||||
impl.print( pop_ignores );
|
||||
impl.write();
|
||||
}
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
#include "helpers/gen.push_ignores.inline.hpp"
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
|
||||
// ReSharper disable CppClangTidyClangDiagnosticSwitchEnum
|
||||
|
||||
@ -6,29 +6,27 @@
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.cpp"
|
||||
#endif
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/gen.data.cpp"
|
||||
#include "components/static_data.cpp"
|
||||
|
||||
#include "components/gen.ast_case_macros.cpp"
|
||||
#include "components/gen.ast.cpp"
|
||||
#include "components/ast_case_macros.cpp"
|
||||
#include "components/ast.cpp"
|
||||
|
||||
#include "components/gen.interface.cpp"
|
||||
#include "components/gen.interface.upfront.cpp"
|
||||
#include "components/gen.etoktype.cpp"
|
||||
#include "components/gen.interface.parsing.cpp"
|
||||
#include "components/gen.untyped.cpp"
|
||||
|
||||
#include "filesystem/gen.builder.cpp"
|
||||
#include "components/interface.cpp"
|
||||
#include "components/interface.upfront.cpp"
|
||||
#include "components/gen/etoktype.cpp"
|
||||
#include "components/interface.parsing.cpp"
|
||||
#include "components/interface.untyped.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
#include "helpers/gen.pop_ignores.inline.hpp"
|
||||
#include "helpers/pop_ignores.inline.hpp"
|
||||
|
@ -1,19 +1,17 @@
|
||||
// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)
|
||||
#include "gen.dep.hpp"
|
||||
|
||||
#include "dependencies/gen.impl_start.cpp"
|
||||
#include "dependencies/src_start.cpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "dependencies/gen.debug.cpp"
|
||||
#include "dependencies/gen.string_ops.cpp"
|
||||
#include "dependencies/gen.printing.cpp"
|
||||
#include "dependencies/gen.memory.cpp"
|
||||
#include "dependencies/gen.parsing.cpp"
|
||||
#include "dependencies/gen.hashing.cpp"
|
||||
#include "dependencies/gen.string.cpp"
|
||||
#include "dependencies/gen.timing.cpp"
|
||||
|
||||
#include "dependencies/gen.file_handling.cpp"
|
||||
#include "dependencies/debug.cpp"
|
||||
#include "dependencies/string_ops.cpp"
|
||||
#include "dependencies/printing.cpp"
|
||||
#include "dependencies/memory.cpp"
|
||||
#include "dependencies/hashing.cpp"
|
||||
#include "dependencies/strings.cpp"
|
||||
#include "dependencies/filesystem.cpp"
|
||||
#include "dependencies/timing.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
@ -1,28 +1,20 @@
|
||||
// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)
|
||||
#pragma once
|
||||
|
||||
#include "dependencies/gen.header_start.hpp"
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
#include "dependencies/header_start.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "dependencies/gen.macros.hpp"
|
||||
#include "dependencies/gen.basic_types.hpp"
|
||||
#include "dependencies/gen.debug.hpp"
|
||||
#include "dependencies/gen.memory.hpp"
|
||||
#include "dependencies/gen.string_ops.hpp"
|
||||
#include "dependencies/gen.printing.hpp"
|
||||
#include "dependencies/gen.containers.hpp"
|
||||
#include "dependencies/gen.string.hpp"
|
||||
#include "dependencies/gen.file_handling.hpp"
|
||||
#include "dependencies/gen.parsing.hpp"
|
||||
#include "dependencies/gen.timing.hpp"
|
||||
#include "dependencies/macros.hpp"
|
||||
#include "dependencies/basic_types.hpp"
|
||||
#include "dependencies/debug.hpp"
|
||||
#include "dependencies/memory.hpp"
|
||||
#include "dependencies/string_ops.hpp"
|
||||
#include "dependencies/printing.hpp"
|
||||
#include "dependencies/containers.hpp"
|
||||
#include "dependencies/hashing.hpp"
|
||||
#include "dependencies/strings.hpp"
|
||||
#include "dependencies/filesystem.hpp"
|
||||
#include "dependencies/timing.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
@ -8,29 +8,25 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "helpers/gen.push_ignores.inline.hpp"
|
||||
#include "components/gen.header_start.hpp"
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "components/header_start.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/gen.types.hpp"
|
||||
#include "components/gen.ecode.hpp"
|
||||
#include "components/gen.eoperator.hpp"
|
||||
#include "components/gen.especifier.hpp"
|
||||
#include "components/gen.data_structures.hpp"
|
||||
#include "components/gen.interface.hpp"
|
||||
#include "components/gen.header_end.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "components/gen/ecode.hpp"
|
||||
#include "components/gen/eoperator.hpp"
|
||||
#include "components/gen/especifier.hpp"
|
||||
|
||||
#include "filesystem/gen.builder.hpp"
|
||||
#include "components/ast.hpp"
|
||||
#include "components/ast_types.hpp"
|
||||
|
||||
#include "components/interface.hpp"
|
||||
|
||||
#include "components/inlines.hpp"
|
||||
#include "components/gen/ast_inlines.hpp"
|
||||
#include "components/header_end.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
#include "helpers/gen.pop_ignores.inline.hpp"
|
||||
#include "helpers/pop_ignores.inline.hpp"
|
||||
|
@ -1,318 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
CodeBody gen_ecode( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for ( ADT_Node node : enum_strs )
|
||||
{
|
||||
char const* code = node.string;
|
||||
enum_entries.append_fmt( "%s,\n", code );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum( token_fmt( "entries", (StrC)enum_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
NumTypes
|
||||
};
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#undef local_persist
|
||||
CodeFn to_str = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
|
||||
CodeNamespace nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
|
||||
|
||||
CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, code_t ) );
|
||||
}
|
||||
|
||||
CodeBody gen_eoperator( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = str_strs [idx].string;
|
||||
|
||||
enum_entries.append_fmt( "%s,\n", enum_str );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
NumOps
|
||||
};
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#undef local_persist
|
||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
|
||||
StrC to_str( Type op )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
};
|
||||
|
||||
return lookup[ op ];
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
|
||||
CodeNamespace nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
|
||||
|
||||
CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, operator_t ) );
|
||||
}
|
||||
|
||||
CodeBody gen_especifier( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = str_strs [idx].string;
|
||||
|
||||
enum_entries.append_fmt( "%s,\n", enum_str );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
NumSpecifiers
|
||||
};
|
||||
)));
|
||||
|
||||
CodeFn is_trailing = parse_function(token_fmt("specifier", (StrC)to_str_entries, stringize(
|
||||
bool is_trailing( Type specifier )
|
||||
{
|
||||
return specifier > Virtual;
|
||||
}
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#pragma push_macro( "do_once_start" )
|
||||
#pragma push_macro( "do_once_end" )
|
||||
#undef local_persist
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
|
||||
CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ NumSpecifiers ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Type)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
||||
}
|
||||
do_once_end
|
||||
|
||||
u32 hash = crc32( str.Ptr, str.Len );
|
||||
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (Type)index;
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
#pragma pop_macro( "do_once_start" )
|
||||
#pragma pop_macro( "do_once_end" )
|
||||
|
||||
CodeNamespace nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
|
||||
|
||||
CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, specifier_t ) );
|
||||
}
|
||||
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
{
|
||||
char scratch_mem[kilobytes(64)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
FileContents enum_content = file_read_contents( scratch, zero_terminate, etok_path );
|
||||
|
||||
CSV_Object csv_enum_nodes;
|
||||
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
|
||||
|
||||
// memset( scratch_mem, 0, sizeof(scratch_mem) );
|
||||
// scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
FileContents attrib_content = file_read_contents( scratch, zero_terminate, attr_path );
|
||||
|
||||
CSV_Object csv_attr_nodes;
|
||||
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
|
||||
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_attributes = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = enum_str_strs [idx].string;
|
||||
|
||||
enum_entries.append_fmt( "%s,\n", enum_str );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
for ( uw idx = 0; idx < attribute_strs.num(); idx++ )
|
||||
{
|
||||
char const* attribute_str = attribute_strs[idx].string;
|
||||
char const* entry_to_str = attribute_str_strs [idx].string;
|
||||
|
||||
attribute_entries.append_fmt( "%s,\n", attribute_str );
|
||||
to_str_attributes.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
NumTokens
|
||||
};
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#pragma push_macro( "do_once_start" )
|
||||
#pragma push_macro( "do_once_end" )
|
||||
#undef local_persist
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, "attribute_toks", (StrC)to_str_attributes, stringize(
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
|
||||
CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ NumTokens ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Type)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
||||
}
|
||||
do_once_end
|
||||
|
||||
u32 hash = crc32( str.Ptr, str.Len );
|
||||
|
||||
for ( u32 index = 0; index < NumTokens; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (Type)index;
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
#pragma pop_macro( "do_once_start" )
|
||||
#pragma pop_macro( "do_once_end" )
|
||||
|
||||
CodeNamespace nspace = def_namespace( name(ETokType), def_namespace_body( args( enum_code, to_str, to_type ) ) );
|
||||
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, td_toktype ) );
|
||||
}
|
606
project/helpers/helper.hpp
Normal file
606
project/helpers/helper.hpp
Normal file
@ -0,0 +1,606 @@
|
||||
#pragma once
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.hpp"
|
||||
GEN_NS_END
|
||||
|
||||
using namespace gen;
|
||||
|
||||
CodeBody gen_ecode( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for ( ADT_Node node : enum_strs )
|
||||
{
|
||||
char const* code = node.string;
|
||||
enum_entries.append_fmt( "%s,\n", code );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", (StrC)enum_entries, "enum Type : u32 { <entries> NumTypes };"));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#undef local_persist
|
||||
CodeFn to_str = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
|
||||
CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
|
||||
CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, code_t, fmt_newline ) );
|
||||
}
|
||||
|
||||
CodeBody gen_eoperator( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(4)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = str_strs [idx].string;
|
||||
|
||||
enum_entries.append_fmt( "%s,\n", enum_str );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
NumOps
|
||||
};
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#undef local_persist
|
||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
|
||||
StrC to_str( Type op )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
};
|
||||
|
||||
return lookup[ op ];
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
|
||||
CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
|
||||
|
||||
CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, operator_t, fmt_newline ) );
|
||||
}
|
||||
|
||||
CodeBody gen_especifier( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(4)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
|
||||
CSV_Object csv_nodes;
|
||||
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> str_strs = csv_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = str_strs [idx].string;
|
||||
|
||||
enum_entries.append_fmt( "%s,\n", enum_str );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
NumSpecifiers
|
||||
};
|
||||
)));
|
||||
|
||||
CodeFn is_trailing = parse_function(token_fmt("specifier", (StrC)to_str_entries, stringize(
|
||||
bool is_trailing( Type specifier )
|
||||
{
|
||||
return specifier > Virtual;
|
||||
}
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#pragma push_macro( "do_once_start" )
|
||||
#pragma push_macro( "do_once_end" )
|
||||
#pragma push_macro( "forceinline" )
|
||||
#pragma push_macro( "neverinline" )
|
||||
#undef local_persist
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
#undef forceinline
|
||||
#undef neverinline
|
||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
|
||||
CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ NumSpecifiers ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Type)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
||||
}
|
||||
do_once_end
|
||||
|
||||
u32 hash = crc32( str.Ptr, str.Len );
|
||||
|
||||
for ( u32 index = 0; index < NumSpecifiers; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (Type)index;
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
#pragma pop_macro( "do_once_start" )
|
||||
#pragma pop_macro( "do_once_end" )
|
||||
#pragma pop_macro( "forceinline" )
|
||||
#pragma pop_macro( "neverinline" )
|
||||
|
||||
CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
|
||||
|
||||
CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, specifier_t, fmt_newline ) );
|
||||
}
|
||||
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
{
|
||||
char scratch_mem[kilobytes(16)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
FileContents enum_content = file_read_contents( scratch, zero_terminate, etok_path );
|
||||
|
||||
CSV_Object csv_enum_nodes;
|
||||
csv_parse( &csv_enum_nodes, rcast(char*, enum_content.data), GlobalAllocator, false );
|
||||
|
||||
FileContents attrib_content = file_read_contents( scratch, zero_terminate, attr_path );
|
||||
|
||||
CSV_Object csv_attr_nodes;
|
||||
csv_parse( &csv_attr_nodes, rcast(char*, attrib_content.data), GlobalAllocator, false );
|
||||
|
||||
Array<ADT_Node> enum_strs = csv_enum_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> enum_str_strs = csv_enum_nodes.nodes[1].nodes;
|
||||
Array<ADT_Node> attribute_strs = csv_attr_nodes.nodes[0].nodes;
|
||||
Array<ADT_Node> attribute_str_strs = csv_attr_nodes.nodes[1].nodes;
|
||||
|
||||
String enum_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_entries = String::make_reserve( GlobalAllocator, kilobytes(2) );
|
||||
String to_str_attributes = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
String attribute_define_entries = String::make_reserve( GlobalAllocator, kilobytes(4) );
|
||||
|
||||
for (uw idx = 0; idx < enum_strs.num(); idx++)
|
||||
{
|
||||
char const* enum_str = enum_strs[idx].string;
|
||||
char const* entry_to_str = enum_str_strs [idx].string;
|
||||
|
||||
enum_entries.append_fmt( "%s,\n", enum_str );
|
||||
to_str_entries.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
}
|
||||
|
||||
for ( uw idx = 0; idx < attribute_strs.num(); idx++ )
|
||||
{
|
||||
char const* attribute_str = attribute_strs[idx].string;
|
||||
char const* entry_to_str = attribute_str_strs [idx].string;
|
||||
|
||||
attribute_entries.append_fmt( "%s,\n", attribute_str );
|
||||
to_str_attributes.append_fmt( "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
|
||||
attribute_define_entries.append_fmt( "Entry( %s, %s )", attribute_str, entry_to_str );
|
||||
|
||||
if ( idx < attribute_strs.num() - 1 )
|
||||
attribute_define_entries.append( " \\\n");
|
||||
else
|
||||
attribute_define_entries.append( "\n");
|
||||
}
|
||||
|
||||
#pragma push_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )
|
||||
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), attribute_define_entries );
|
||||
#pragma pop_macro( "GEN_DEFINE_ATTRIBUTE_TOKENS" )
|
||||
|
||||
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, "attribute_toks", (StrC)attribute_entries, stringize(
|
||||
enum Type : u32
|
||||
{
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
NumTokens
|
||||
};
|
||||
)));
|
||||
|
||||
#pragma push_macro( "local_persist" )
|
||||
#pragma push_macro( "do_once_start" )
|
||||
#pragma push_macro( "do_once_end" )
|
||||
#undef local_persist
|
||||
#undef do_once_start
|
||||
#undef do_once_end
|
||||
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, "attribute_toks", (StrC)to_str_attributes, stringize(
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[] {
|
||||
<entries>
|
||||
<attribute_toks>
|
||||
};
|
||||
|
||||
return lookup[ type ];
|
||||
}
|
||||
)));
|
||||
|
||||
CodeFn to_type = parse_function( token_fmt( "entries", (StrC)to_str_entries, stringize(
|
||||
Type to_type( StrC str )
|
||||
{
|
||||
local_persist
|
||||
u32 keymap[ NumTokens ];
|
||||
do_once_start
|
||||
for ( u32 index = 0; index < NumTokens; index++ )
|
||||
{
|
||||
StrC enum_str = to_str( (Type)index );
|
||||
|
||||
// We subtract 1 to remove the null terminator
|
||||
// This is because the tokens lexed are not null terminated.
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1);
|
||||
}
|
||||
do_once_end
|
||||
|
||||
u32 hash = crc32( str.Ptr, str.Len );
|
||||
|
||||
for ( u32 index = 0; index < NumTokens; index++ )
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
return (Type)index;
|
||||
}
|
||||
|
||||
return Invalid;
|
||||
}
|
||||
)));
|
||||
#pragma pop_macro( "local_persist" )
|
||||
#pragma pop_macro( "do_once_start" )
|
||||
#pragma pop_macro( "do_once_end" )
|
||||
|
||||
CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
||||
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, td_toktype ) );
|
||||
}
|
||||
|
||||
CodeBody gen_ast_inlines()
|
||||
{
|
||||
#pragma push_macro("rcast")
|
||||
#pragma push_macro("log_failure")
|
||||
#undef rcast
|
||||
#undef log_failure
|
||||
char const* code_impl_tmpl = stringize(
|
||||
\n
|
||||
char const* <typename>::debug_str()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
return "Code::debug_str: AST is null!";
|
||||
|
||||
return rcast(AST*, ast)->debug_str();
|
||||
}
|
||||
Code <typename>::duplicate()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Code::duplicate: Cannot duplicate code, AST is null!");
|
||||
return Code::Invalid;
|
||||
}
|
||||
|
||||
return { rcast(AST*, ast)->duplicate() };
|
||||
}
|
||||
bool <typename>::is_equal( Code other )
|
||||
{
|
||||
if ( ast == nullptr || other.ast == nullptr )
|
||||
{
|
||||
log_failure("Code::is_equal: Cannot compare code, AST is null!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return rcast(AST*, ast)->is_equal( other.ast );
|
||||
}
|
||||
bool <typename>::is_valid()
|
||||
{
|
||||
return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid;
|
||||
}
|
||||
void <typename>::set_global()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Code::set_global: Cannot set code as global, AST is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
rcast(AST*, ast)->Parent = Code::Global.ast;
|
||||
}
|
||||
String <typename>::to_string()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Code::to_string: Cannot convert code to string, AST is null!");
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
return rcast(AST*, ast)->to_string();
|
||||
}
|
||||
<typename>& <typename>::operator =( Code other )
|
||||
{
|
||||
if ( other.ast && other->Parent )
|
||||
{
|
||||
ast = rcast( decltype(ast), other.ast->duplicate() );
|
||||
rcast( AST*, ast)->Parent = nullptr;
|
||||
}
|
||||
|
||||
ast = rcast( decltype(ast), other.ast );
|
||||
return *this;
|
||||
}
|
||||
bool <typename>::operator ==( Code other )
|
||||
{
|
||||
return (AST*) ast == other.ast;
|
||||
}
|
||||
bool <typename>::operator !=( Code other )
|
||||
{
|
||||
return (AST*) ast != other.ast;
|
||||
}
|
||||
<typename>::operator bool()
|
||||
{
|
||||
return ast != nullptr;
|
||||
}
|
||||
);
|
||||
|
||||
char const* codetype_impl_tmpl = stringize(
|
||||
AST* Code<typename>::raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
Code<typename>::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
}
|
||||
AST_<typename>* Code<typename>::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!" );
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
\n
|
||||
);
|
||||
|
||||
CodeBody impl_code = parse_global_body( token_fmt( "typename", StrC name(Code), code_impl_tmpl ));
|
||||
CodeBody impl_code_body = parse_global_body( token_fmt( "typename", StrC name(CodeBody), code_impl_tmpl ));
|
||||
CodeBody impl_code_attr = parse_global_body( token_fmt( "typename", StrC name(CodeAttributes), code_impl_tmpl ));
|
||||
CodeBody impl_code_cmt = parse_global_body( token_fmt( "typename", StrC name(CodeComment), code_impl_tmpl ));
|
||||
CodeBody impl_code_constr = parse_global_body( token_fmt( "typename", StrC name(CodeConstructor), code_impl_tmpl ));
|
||||
CodeBody impl_code_class = parse_global_body( token_fmt( "typename", StrC name(CodeClass), code_impl_tmpl ));
|
||||
CodeBody impl_code_define = parse_global_body( token_fmt( "typename", StrC name(CodeDefine), code_impl_tmpl ));
|
||||
CodeBody impl_code_destruct = parse_global_body( token_fmt( "typename", StrC name(CodeDestructor), code_impl_tmpl ));
|
||||
CodeBody impl_code_enum = parse_global_body( token_fmt( "typename", StrC name(CodeEnum), code_impl_tmpl ));
|
||||
CodeBody impl_code_exec = parse_global_body( token_fmt( "typename", StrC name(CodeExec), code_impl_tmpl ));
|
||||
CodeBody impl_code_extern = parse_global_body( token_fmt( "typename", StrC name(CodeExtern), code_impl_tmpl ));
|
||||
CodeBody impl_code_include = parse_global_body( token_fmt( "typename", StrC name(CodeInclude), code_impl_tmpl ));
|
||||
CodeBody impl_code_friend = parse_global_body( token_fmt( "typename", StrC name(CodeFriend), code_impl_tmpl ));
|
||||
CodeBody impl_code_fn = parse_global_body( token_fmt( "typename", StrC name(CodeFn), code_impl_tmpl ));
|
||||
CodeBody impl_code_module = parse_global_body( token_fmt( "typename", StrC name(CodeModule), code_impl_tmpl ));
|
||||
CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", StrC name(CodeNS), code_impl_tmpl ));
|
||||
CodeBody impl_code_op = parse_global_body( token_fmt( "typename", StrC name(CodeOperator), code_impl_tmpl ));
|
||||
CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", StrC name(CodeOpCast), code_impl_tmpl ));
|
||||
CodeBody impl_code_param = parse_global_body( token_fmt( "typename", StrC name(CodeParam), code_impl_tmpl ));
|
||||
CodeBody impl_code_pragma = parse_global_body( token_fmt( "typename", StrC name(CodePragma), code_impl_tmpl ));
|
||||
CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", StrC name(CodePreprocessCond), code_impl_tmpl ));
|
||||
CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl ));
|
||||
CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", StrC name(CodeStruct), code_impl_tmpl ));
|
||||
CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", StrC name(CodeTemplate), code_impl_tmpl ));
|
||||
CodeBody impl_code_type = parse_global_body( token_fmt( "typename", StrC name(CodeType), code_impl_tmpl ));
|
||||
CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", StrC name(CodeTypedef), code_impl_tmpl ));
|
||||
CodeBody impl_code_union = parse_global_body( token_fmt( "typename", StrC name(CodeUnion), code_impl_tmpl ));
|
||||
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl ));
|
||||
CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl ));
|
||||
|
||||
impl_code_attr. append( parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
|
||||
impl_code_cmt. append( parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
|
||||
impl_code_constr. append( parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
|
||||
impl_code_define. append( parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
|
||||
impl_code_destruct.append( parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
|
||||
impl_code_enum. append( parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
|
||||
impl_code_exec. append( parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
|
||||
impl_code_extern. append( parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
|
||||
impl_code_include. append( parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
|
||||
impl_code_friend. append( parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
|
||||
impl_code_fn. append( parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
|
||||
impl_code_module. append( parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
|
||||
impl_code_ns. append( parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
|
||||
impl_code_op. append( parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
|
||||
impl_code_opcast. append( parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
|
||||
impl_code_pragma . append( parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
|
||||
impl_code_precond. append( parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
|
||||
impl_code_tmpl. append( parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
|
||||
impl_code_type. append( parse_global_body( token_fmt( "typename", StrC name(Type), codetype_impl_tmpl )));
|
||||
impl_code_typedef. append( parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
|
||||
impl_code_union. append( parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
|
||||
impl_code_using. append( parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
|
||||
impl_code_var. append( parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
|
||||
|
||||
char const* cast_tmpl = stringize(
|
||||
AST::operator Code<typename>()
|
||||
{
|
||||
return { rcast( AST_<typename>*, this ) };
|
||||
}
|
||||
|
||||
Code::operator Code<typename>() const
|
||||
{
|
||||
return { (AST_<typename>*) ast };
|
||||
}
|
||||
);
|
||||
|
||||
CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", StrC name(Body), cast_tmpl ));
|
||||
CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", StrC name(Attributes), cast_tmpl ));
|
||||
CodeBody impl_cast_cmt = parse_global_body( token_fmt( "typename", StrC name(Comment), cast_tmpl ));
|
||||
CodeBody impl_cast_constr = parse_global_body( token_fmt( "typename", StrC name(Constructor), cast_tmpl ));
|
||||
CodeBody impl_cast_class = parse_global_body( token_fmt( "typename", StrC name(Class), cast_tmpl ));
|
||||
CodeBody impl_cast_define = parse_global_body( token_fmt( "typename", StrC name(Define), cast_tmpl ));
|
||||
CodeBody impl_cast_destruct = parse_global_body( token_fmt( "typename", StrC name(Destructor), cast_tmpl ));
|
||||
CodeBody impl_cast_enum = parse_global_body( token_fmt( "typename", StrC name(Enum), cast_tmpl ));
|
||||
CodeBody impl_cast_exec = parse_global_body( token_fmt( "typename", StrC name(Exec), cast_tmpl ));
|
||||
CodeBody impl_cast_extern = parse_global_body( token_fmt( "typename", StrC name(Extern), cast_tmpl ));
|
||||
CodeBody impl_cast_friend = parse_global_body( token_fmt( "typename", StrC name(Friend), cast_tmpl ));
|
||||
CodeBody impl_cast_fn = parse_global_body( token_fmt( "typename", StrC name(Fn), cast_tmpl ));
|
||||
CodeBody impl_cast_include = parse_global_body( token_fmt( "typename", StrC name(Include), cast_tmpl ));
|
||||
CodeBody impl_cast_module = parse_global_body( token_fmt( "typename", StrC name(Module), cast_tmpl ));
|
||||
CodeBody impl_cast_ns = parse_global_body( token_fmt( "typename", StrC name(NS), cast_tmpl ));
|
||||
CodeBody impl_cast_op = parse_global_body( token_fmt( "typename", StrC name(Operator), cast_tmpl ));
|
||||
CodeBody impl_cast_opcast = parse_global_body( token_fmt( "typename", StrC name(OpCast), cast_tmpl ));
|
||||
CodeBody impl_cast_param = parse_global_body( token_fmt( "typename", StrC name(Param), cast_tmpl ));
|
||||
CodeBody impl_cast_pragma = parse_global_body( token_fmt( "typename", StrC name(Pragma), cast_tmpl ));
|
||||
CodeBody impl_cast_precond = parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), cast_tmpl ));
|
||||
CodeBody impl_cast_specs = parse_global_body( token_fmt( "typename", StrC name(Specifiers), cast_tmpl ));
|
||||
CodeBody impl_cast_struct = parse_global_body( token_fmt( "typename", StrC name(Struct), cast_tmpl ));
|
||||
CodeBody impl_cast_tmpl = parse_global_body( token_fmt( "typename", StrC name(Template), cast_tmpl ));
|
||||
CodeBody impl_cast_type = parse_global_body( token_fmt( "typename", StrC name(Type), cast_tmpl ));
|
||||
CodeBody impl_cast_typedef = parse_global_body( token_fmt( "typename", StrC name(Typedef), cast_tmpl ));
|
||||
CodeBody impl_cast_union = parse_global_body( token_fmt( "typename", StrC name(Union), cast_tmpl ));
|
||||
CodeBody impl_cast_using = parse_global_body( token_fmt( "typename", StrC name(Using), cast_tmpl ));
|
||||
CodeBody impl_cast_var = parse_global_body( token_fmt( "typename", StrC name(Var), cast_tmpl ));
|
||||
|
||||
CodeBody result = def_global_body( args(
|
||||
def_pragma( txt("region generated code inline implementation")),
|
||||
fmt_newline,
|
||||
impl_code,
|
||||
impl_code_body,
|
||||
impl_code_attr,
|
||||
impl_code_cmt,
|
||||
impl_code_constr,
|
||||
impl_code_class,
|
||||
impl_code_define,
|
||||
impl_code_destruct,
|
||||
impl_code_enum,
|
||||
impl_code_exec,
|
||||
impl_code_extern,
|
||||
impl_code_friend,
|
||||
impl_code_fn,
|
||||
impl_code_include,
|
||||
impl_code_module,
|
||||
impl_code_ns,
|
||||
impl_code_op,
|
||||
impl_code_opcast,
|
||||
impl_code_param,
|
||||
impl_code_pragma,
|
||||
impl_code_precond,
|
||||
impl_code_specs,
|
||||
impl_code_struct,
|
||||
impl_code_tmpl,
|
||||
impl_code_type,
|
||||
impl_code_typedef,
|
||||
impl_code_union,
|
||||
impl_code_using,
|
||||
impl_code_var,
|
||||
fmt_newline,
|
||||
def_pragma( txt("endregion generated code inline implementation")),
|
||||
fmt_newline,
|
||||
def_pragma( txt("region generated AST/Code cast implementation")),
|
||||
fmt_newline,
|
||||
impl_cast_body,
|
||||
impl_cast_attribute,
|
||||
impl_cast_cmt,
|
||||
impl_cast_constr,
|
||||
impl_cast_class,
|
||||
impl_cast_define,
|
||||
impl_cast_destruct,
|
||||
impl_cast_enum,
|
||||
impl_cast_exec,
|
||||
impl_cast_extern,
|
||||
impl_cast_friend,
|
||||
impl_cast_fn,
|
||||
impl_cast_include,
|
||||
impl_cast_module,
|
||||
impl_cast_ns,
|
||||
impl_cast_op,
|
||||
impl_cast_opcast,
|
||||
impl_cast_param,
|
||||
impl_cast_pragma,
|
||||
impl_cast_precond,
|
||||
impl_cast_specs,
|
||||
impl_cast_struct,
|
||||
impl_cast_tmpl,
|
||||
impl_cast_type,
|
||||
impl_cast_typedef,
|
||||
impl_cast_union,
|
||||
impl_cast_using,
|
||||
impl_cast_var,
|
||||
fmt_newline,
|
||||
def_pragma( txt("endregion generated AST/Code cast implementation")),
|
||||
fmt_newline
|
||||
));
|
||||
|
||||
return result;
|
||||
#pragma pop_macro("rcast")
|
||||
#pragma pop_macro("log_failure")
|
||||
}
|
@ -64,7 +64,7 @@
|
||||
#undef stringize
|
||||
#undef stringize
|
||||
#undef stringize_va
|
||||
#undef txt_StrC
|
||||
#undef txt
|
||||
|
||||
#undef GEN_TIME
|
||||
#undef gen_main
|
@ -1,18 +0,0 @@
|
||||
project( 'gencpp_bootstrap', 'c', 'cpp', default_options : ['buildtype=debug'] )
|
||||
|
||||
includes = include_directories(
|
||||
[
|
||||
'../project',
|
||||
])
|
||||
|
||||
sources = [ 'gen.bootstrap.cpp' ]
|
||||
|
||||
if get_option('buildtype').startswith('debug')
|
||||
|
||||
add_project_arguments('-DBuild_Debug', language : ['c', 'cpp'])
|
||||
|
||||
endif
|
||||
|
||||
add_project_arguments('-DGEN_TIME', language : ['c', 'cpp'])
|
||||
|
||||
executable( 'gencpp_bootstrap', sources, include_directories : includes )
|
@ -3,19 +3,25 @@
|
||||
AccessModifierOffset: -4
|
||||
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignArrayOfStructures: Right
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignCompound: true
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields: AcrossComments
|
||||
AlignConsecutiveDeclarations: AcrossComments
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: true
|
||||
AcrossEmptyLines: true
|
||||
AcrossComments: true
|
||||
AcrossComments: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: DontAlign
|
||||
|
||||
@ -61,8 +67,8 @@ BraceWrapping:
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
|
||||
# BreakAfterAttributes: Always
|
||||
# BreakArrays: false
|
||||
BreakAfterAttributes: Always
|
||||
BreakArrays: true
|
||||
# BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Allman
|
||||
@ -73,7 +79,7 @@ BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakStringLiterals: true
|
||||
|
||||
ColumnLimit: 180
|
||||
ColumnLimit: 160
|
||||
|
||||
CompactNamespaces: true
|
||||
|
||||
@ -92,18 +98,17 @@ FixNamespaceComments: true
|
||||
|
||||
IncludeBlocks: Preserve
|
||||
|
||||
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: false
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentRequires: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
IndentWrappedFunctionNames: true
|
||||
|
||||
# InsertNewlineAtEOF: true
|
||||
InsertTrailingCommas: Wrapped
|
||||
# InsertTrailingCommas: Wrapped
|
||||
|
||||
LambdaBodyIndentation: OuterScope
|
||||
|
||||
@ -127,8 +132,8 @@ SeparateDefinitionBlocks: Always
|
||||
|
||||
ShortNamespaceLines: 40
|
||||
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: false
|
||||
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: true
|
||||
|
@ -1,12 +1,47 @@
|
||||
# Scripts
|
||||
|
||||
Build and cleanup scripts for the test directory are found here along with `natvis` and `natstepfilter` files for debugging.
|
||||
Generation, testing, and cleanup scripts for the test directory are found here along with `natvis` and `natstepfilter` files for debugging.
|
||||
|
||||
The build works as follows:
|
||||
## Refactoring
|
||||
|
||||
* Compile and run the meta-program, it will dump files to the `test/gen` directory.
|
||||
* Format the files using clang-format
|
||||
* Build a program that uses some the generated definitions. (Have not done yet)
|
||||
`refactor.ps1` Provides a way to run the [refactor](github.com/Ed94/refactor) program. It uses the `gencpp.refactor` script to complete a mass refactor of all content within the files of the specified within the script.
|
||||
|
||||
The `test/gen` directory has the meson.build config for the meta-program
|
||||
The `test` directory has the one for the dependent-program.
|
||||
Currently `refactor` only supports naive sort of *find and replace* feature set and will not be able to rename identifiers excluisvely to a specific context (such as only renaming member names of a specific struct, etc).
|
||||
|
||||
**Note: The following macros are used with specifiers and token parsing within the library:**
|
||||
|
||||
* global
|
||||
* internal
|
||||
* local_persist
|
||||
* forceinline
|
||||
* neverinline
|
||||
|
||||
IF they are changed the following files would need adjustment:
|
||||
|
||||
* `./project/enums/ESpecifier.csv`
|
||||
* `./project/enums/ETokType.csv`
|
||||
* `./project/helpers/helper.hpp`
|
||||
|
||||
## Build & Run Scripts
|
||||
|
||||
**`clean.ps1`**
|
||||
Remove any generated content from the repository.
|
||||
|
||||
**`build.ps1`**
|
||||
Build bootstrap, singleheader, or tests. Supports MSVC or clang, release or debug.
|
||||
|
||||
```
|
||||
args:
|
||||
bootstrap
|
||||
singleheader
|
||||
test
|
||||
clang
|
||||
msvc : By default this project builds with clang, specifying msvc will build with MSVC.
|
||||
debug
|
||||
release : By default this project builds in debug mode, specifying release will build with optimizations.
|
||||
```
|
||||
|
||||
**`package_release.ps1`**
|
||||
Will build the project as fast as possible, then package the release into a zip file.
|
||||
|
||||
*Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6*
|
||||
|
@ -1,70 +0,0 @@
|
||||
[string] $type = $null
|
||||
[string] $test = $false
|
||||
|
||||
foreach ( $arg in $args )
|
||||
{
|
||||
if ( $arg -eq "test" )
|
||||
{
|
||||
$test = $true
|
||||
}
|
||||
else
|
||||
{
|
||||
$type = $arg
|
||||
}
|
||||
}
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_project = Join-Path $path_root project
|
||||
$path_project_build = Join-Path $path_project build
|
||||
$path_project_gen = Join-Path $path_project gen
|
||||
|
||||
write-host "`n`nBuilding gencpp bootstrap`n"
|
||||
|
||||
if ( -not( Test-Path $path_project_build) )
|
||||
{
|
||||
# Generate build files for meta-program
|
||||
Push-Location $path_project
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
$args_meson += $path_project_build
|
||||
|
||||
& meson $args_meson
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Compile meta-program
|
||||
Push-Location $path_root
|
||||
$args_ninja = @()
|
||||
$args_ninja += "-C"
|
||||
$args_ninja += $path_project_build
|
||||
|
||||
& ninja $args_ninja
|
||||
Pop-Location
|
||||
|
||||
Push-location $path_project
|
||||
if ( -not(Test-Path($path_project_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_project_gen
|
||||
}
|
||||
|
||||
# Run meta-program
|
||||
$gencpp_bootstrap = Join-Path $path_project_build gencpp_bootstrap.exe
|
||||
|
||||
Write-Host `nRunning gencpp bootstrap...
|
||||
& $gencpp_bootstrap
|
||||
|
||||
# Format generated files
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:../scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
$include = @('gen.hpp', 'gen.cpp', 'gen_dep.hpp', 'gen_dep.cpp')
|
||||
$exclude = $null
|
||||
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
Pop-Location
|
@ -1,2 +0,0 @@
|
||||
cls
|
||||
Invoke-Expression "& $(Join-Path $PSScriptRoot 'bootstrap.ci.ps1') $args"
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user