mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Compare commits
63 Commits
v0.7-Alpha
...
v0.11-Alph
Author | SHA1 | Date | |
---|---|---|---|
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 |
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,6 +1,6 @@
|
||||
.idea
|
||||
|
||||
build/*
|
||||
**/build/*
|
||||
.vs
|
||||
|
||||
**/*.gen.*
|
||||
@ -30,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
|
||||
|
26
.vscode/c_cpp_properties.json
vendored
26
.vscode/c_cpp_properties.json
vendored
@ -1,7 +1,7 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"name": "Win32 msvc",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
@ -9,7 +9,29 @@
|
||||
"_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",
|
||||
|
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,
|
||||
|
@ -6,7 +6,7 @@ The library API is a composition of code element constructors.
|
||||
These build up a code AST to then serialize with a file builder.
|
||||
|
||||
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 their project domain.
|
||||
its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
|
||||
|
||||
## Notes
|
||||
|
||||
|
687
docs/ASTs.md
Normal file
687
docs/ASTs.md
Normal file
@ -0,0 +1,687 @@
|
||||
# ASTs 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 Last; // 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 <Next>, ...<Last>
|
||||
{
|
||||
<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> ): <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
|
||||
|
@ -1,9 +1,12 @@
|
||||
# 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) under 5000 loc.
|
||||
The library features a naive parser tailored for only what the library needs to construct the supported syntax of C++ into its AST.
|
||||
|
||||
The parsing implementation supports the following for the user:
|
||||
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 5000 loc.
|
||||
|
||||
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 );
|
||||
@ -27,10 +30,12 @@ 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***, and ***includes***, and ***pragmas**.
|
||||
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:
|
||||
|
||||
@ -40,7 +45,6 @@ The keywords supported for the preprocessor are:
|
||||
* ifdef
|
||||
* elif
|
||||
* endif
|
||||
* undef
|
||||
* 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*.
|
||||
@ -52,10 +56,17 @@ Any preprocessor definition abuse that changes the syntax of the core language i
|
||||
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`
|
||||
|
||||
*(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.
|
||||
@ -65,8 +76,7 @@ The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
* 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)
|
||||
|
||||
Empty lines used throughout the file are preserved for formatting purposes for ast serialization.
|
||||
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.
|
||||
|
||||
|
@ -40,15 +40,6 @@ Otherwise the library is free of any templates.
|
||||
|
||||
### *WHAT IS NOT PROVIDED*
|
||||
|
||||
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 : ^^
|
||||
|
||||
**There is no support for validating expressions.**
|
||||
Its difficult to parse without enough benefits (At the metaprogramming level).
|
||||
|
||||
@ -70,7 +61,7 @@ Use at your own mental peril.
|
||||
|
||||
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 the user via its interface.
|
||||
The AST is managed by the library and provided to the user via its interface.
|
||||
However, the user may specifiy memory configuration.
|
||||
|
||||
Data layout of AST struct:
|
||||
@ -369,7 +360,7 @@ 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");
|
||||
StrC value = txt("Something");
|
||||
|
||||
char const* template_str = txt(
|
||||
Code with <key> to replace with token_values
|
||||
@ -456,7 +447,7 @@ and have the desired specifiers assigned to them beforehand.
|
||||
|
||||
## Code generation and modification
|
||||
|
||||
There are three provided file interfaces:
|
||||
There are three provided auxillary interfaces:
|
||||
|
||||
* Builder
|
||||
* Editor
|
||||
@ -471,11 +462,12 @@ Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FE
|
||||
* 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
|
||||
### Editor is for editing a series of files/asts 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.
|
||||
* If editing an AST it will generate a new ast as a result (ASTs are not edited).
|
||||
* Requests are populated using the following interface:
|
||||
* add : Add code.
|
||||
* remove : Remove code.
|
||||
@ -495,7 +487,7 @@ Additionally if `GEN_FEATURE_EDITOR_REFACTOR` is defined, refactor( file_path, s
|
||||
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
|
||||
### Scanner allows the user to sift through a series of files/asts based on a set of requests provided to it
|
||||
|
||||
**Note: Not implemented yet**
|
||||
|
||||
@ -504,8 +496,6 @@ It will on call add a request to the queue to run the refactor script on the fil
|
||||
|
||||
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().
|
||||
|
@ -40,6 +40,7 @@
|
||||
</AdditionalIncludePaths>
|
||||
<Defines>
|
||||
<Define>GEN_TIME</Define>
|
||||
<Define>GEN_SYSTEM_WINDOWS</Define>
|
||||
</Defines>
|
||||
<ConfigProperties>
|
||||
<ConfigAndPlatform>
|
||||
|
142
gencpp.vcxproj
142
gencpp.vcxproj
@ -98,49 +98,61 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".editorconfig" />
|
||||
<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="Readme.md" />
|
||||
<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.ecode.hpp" />
|
||||
<ClInclude Include="project\components\gen.eoperator.hpp" />
|
||||
<ClInclude Include="project\components\gen.especifier.hpp" />
|
||||
<ClInclude Include="project\components\gen.header_end.hpp" />
|
||||
<ClInclude Include="project\components\gen.header_start.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.debug.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.file_handling.hpp" />
|
||||
<ClInclude Include="project\dependencies\gen.hashing.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\dependencies\gen.timing.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\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\temp\ast_inlines.hpp" />
|
||||
<ClInclude Include="project\components\temp\ecode.hpp" />
|
||||
<ClInclude Include="project\components\temp\eoperator.hpp" />
|
||||
<ClInclude Include="project\components\temp\especifier.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.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="singleheader\components\gen.header_start.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\DummyInclude.hpp" />
|
||||
<ClInclude Include="test\Parsed\Buffer.Parsed.hpp" />
|
||||
<ClInclude Include="test\Parsed\HashTable.Parsed.hpp" />
|
||||
@ -157,57 +169,59 @@
|
||||
<ClInclude Include="test\Parsed\Sanity.Parsed.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="project\components\gen.ast.cpp" />
|
||||
<ClCompile Include="project\components\gen.ast_case_macros.cpp" />
|
||||
<ClCompile Include="project\components\gen.data.cpp" />
|
||||
<ClCompile Include="project\components\gen.etoktype.cpp" />
|
||||
<ClCompile Include="project\components\gen.impl_start.cpp" />
|
||||
<ClCompile Include="project\components\gen.interface.cpp" />
|
||||
<ClCompile Include="project\components\gen.interface.parsing.cpp" />
|
||||
<ClCompile Include="project\components\gen.interface.upfront.cpp" />
|
||||
<ClCompile Include="project\components\gen.untyped.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.debug.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.file_handling.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.hashing.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.impl_start.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\dependencies\gen.string.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.string_ops.cpp" />
|
||||
<ClCompile Include="project\dependencies\gen.timing.cpp" />
|
||||
<ClCompile Include="project\gen.bootstrap.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\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\components\temp\etoktype.cpp" />
|
||||
<ClCompile Include="project\components\untyped.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.singleheader.cpp" />
|
||||
<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\components\AttributeTokens.csv" />
|
||||
<Content Include="project\components\ECode.csv" />
|
||||
<Content Include="project\components\EOperator.csv" />
|
||||
<Content Include="project\components\ESpecifier.csv" />
|
||||
<Content Include="project\components\ETokType.csv" />
|
||||
<Content Include="project\meson.build" />
|
||||
<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\bootstrap.ci.ps1" />
|
||||
<Content Include="scripts\bootstrap.ps1" />
|
||||
<Content Include="scripts\msvc\build_msvc.ps1" />
|
||||
<Content Include="scripts\msvc\devshell.ps1" />
|
||||
<Content Include="scripts\helpers\devshell.ps1" />
|
||||
<Content Include="scripts\helpers\target_arch.psm1" />
|
||||
<Content Include="scripts\refactor.ps1" />
|
||||
<Content Include="scripts\singleheader.ci.ps1" />
|
||||
<Content Include="scripts\singleheader.ps1" />
|
||||
<Content Include="singleheader\meson.build" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -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,91 @@
|
||||
<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>
|
||||
</ItemGroup>
|
||||
@ -80,27 +134,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 +173,106 @@
|
||||
<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>
|
||||
</ItemGroup>
|
||||
@ -222,13 +282,21 @@
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include=".vscode\gencpp.natvis" />
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "builder.hpp"
|
||||
#endif
|
||||
|
||||
Builder Builder::open( char const* path )
|
||||
{
|
||||
Builder result;
|
||||
@ -12,6 +16,7 @@ Builder Builder::open( char const* path )
|
||||
|
||||
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
||||
|
||||
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -22,7 +27,10 @@ void Builder::pad_lines( s32 num )
|
||||
|
||||
void Builder::print( Code code )
|
||||
{
|
||||
Buffer.append( code->to_string() );
|
||||
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, ... )
|
||||
@ -35,6 +43,7 @@ void Builder::print_fmt( char const* 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 );
|
||||
}
|
||||
|
||||
@ -43,8 +52,9 @@ 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 ) );
|
||||
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();
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "gen.hpp"
|
||||
#endif
|
||||
|
||||
struct Builder
|
||||
{
|
||||
FileInfo File;
|
1
project/auxillary/scanner.cpp
Normal file
1
project/auxillary/scanner.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "scanner.hpp"
|
164
project/auxillary/scanner.hpp
Normal file
164
project/auxillary/scanner.hpp
Normal file
@ -0,0 +1,164 @@
|
||||
#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 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 );
|
||||
};
|
||||
#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();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_str(generation_notice) )
|
||||
));
|
||||
|
||||
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_fmt( generation_notice );
|
||||
src_etoktype.print( pragma_once );
|
||||
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;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,11 @@
|
||||
#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;
|
||||
@ -74,7 +82,7 @@ struct Code
|
||||
static Code Invalid;
|
||||
# pragma endregion Statics
|
||||
|
||||
#define Using_Code( Typename ) \
|
||||
# define Using_Code( Typename ) \
|
||||
char const* debug_str(); \
|
||||
Code duplicate(); \
|
||||
bool is_equal( Code other ); \
|
||||
@ -163,10 +171,11 @@ struct AST
|
||||
Code& entry ( u32 idx );
|
||||
bool has_entries();
|
||||
bool is_equal ( AST* other );
|
||||
String to_string ();
|
||||
char const* type_str();
|
||||
bool validate_body();
|
||||
|
||||
neverinline String to_string();
|
||||
|
||||
template< class Type >
|
||||
Type cast()
|
||||
{
|
||||
@ -213,33 +222,39 @@ struct AST
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(u32)
|
||||
- sizeof(s32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes
|
||||
/ sizeof(SpecifierT) - 1; // -1 for 4 extra bytes
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
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, Destructor
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
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; // Varaiable (Class/Struct Data Member)
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
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
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
@ -256,11 +271,13 @@ struct AST
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
|
||||
};
|
||||
|
||||
struct AST_POD
|
||||
@ -268,27 +285,32 @@ struct AST_POD
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typename, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
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, Destructor
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
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; // Varaiable (Class/Struct Data Member)
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
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
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
};
|
||||
union {
|
||||
@ -305,11 +327,13 @@ struct AST_POD
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
|
||||
};
|
||||
|
||||
// Its intended for the AST to have equivalent size to its POD.
|
||||
@ -574,4 +598,3 @@ Define_CodeType( Var );
|
||||
#undef Using_Code
|
||||
|
||||
#pragma endregion Code Types
|
||||
|
||||
|
@ -76,4 +76,3 @@
|
||||
case Specifiers: \
|
||||
case Struct_Body: \
|
||||
case Typename:
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "ast.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region AST Types
|
||||
/*
|
||||
Show only relevant members of the AST for its type.
|
||||
@ -15,6 +20,7 @@ struct AST_Body
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Body) == sizeof(AST), "ERROR: AST_Filtered is not the same size as AST");
|
||||
|
||||
@ -30,6 +36,7 @@ struct AST_Attributes
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Attributes) == sizeof(AST), "ERROR: AST_Attributes is not the same size as AST");
|
||||
|
||||
@ -45,6 +52,7 @@ struct AST_Comment
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Comment) == sizeof(AST), "ERROR: AST_Comment is not the same size as AST");
|
||||
|
||||
@ -54,11 +62,13 @@ struct AST_Class
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
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 Last;
|
||||
@ -68,6 +78,7 @@ struct AST_Class
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Class) == sizeof(AST), "ERROR: AST_Class is not the same size as AST");
|
||||
|
||||
@ -77,18 +88,22 @@ struct AST_Constructor
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 3 ];
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
Code Body;
|
||||
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;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
char _PAD_NAME_[ sizeof(StringCached) ];
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Constructor) == sizeof(AST), "ERROR: AST_Constructor is not the same size as AST");
|
||||
|
||||
@ -104,6 +119,7 @@ struct AST_Define
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Define) == sizeof(AST), "ERROR: AST_Define is not the same size as AST");
|
||||
|
||||
@ -113,18 +129,21 @@ struct AST_Destructor
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
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;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
char _PAD_NAME_[ sizeof(StringCached) ];
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Destructor) == sizeof(AST), "ERROR: AST_Destructor is not the same size as AST");
|
||||
|
||||
@ -134,11 +153,13 @@ struct AST_Enum
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
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;
|
||||
@ -148,6 +169,7 @@ struct AST_Enum
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Enum) == sizeof(AST), "ERROR: AST_Enum is not the same size as AST");
|
||||
|
||||
@ -155,10 +177,7 @@ struct AST_Exec
|
||||
{
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
};
|
||||
StringCached Content;
|
||||
};
|
||||
Code Prev;
|
||||
Code Next;
|
||||
@ -166,6 +185,7 @@ struct AST_Exec
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Exec) == sizeof(AST), "ERROR: AST_Exec is not the same size as AST");
|
||||
|
||||
@ -175,8 +195,9 @@ struct AST_Extern
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -185,6 +206,7 @@ struct AST_Extern
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Extern) == sizeof(AST), "ERROR: AST_Extern is not the same size as AST");
|
||||
|
||||
@ -200,6 +222,7 @@ struct AST_Include
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Include) == sizeof(AST), "ERROR: AST_Include is not the same size as AST");
|
||||
|
||||
@ -209,8 +232,10 @@ struct AST_Friend
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
Code Declaration;
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -219,6 +244,7 @@ struct AST_Friend
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Friend) == sizeof(AST), "ERROR: AST_Friend is not the same size as AST");
|
||||
|
||||
@ -228,11 +254,13 @@ struct AST_Fn
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -242,6 +270,7 @@ struct AST_Fn
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Fn) == sizeof(AST), "ERROR: AST_Fn is not the same size as AST");
|
||||
|
||||
@ -255,6 +284,7 @@ struct AST_Module
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Module) == sizeof(AST), "ERROR: AST_Module is not the same size as AST");
|
||||
|
||||
@ -263,8 +293,9 @@ struct AST_NS
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct {
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -274,6 +305,7 @@ struct AST_NS
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_NS) == sizeof(AST), "ERROR: AST_NS is not the same size as AST");
|
||||
|
||||
@ -283,11 +315,13 @@ struct AST_Operator
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -297,6 +331,7 @@ struct AST_Operator
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
OperatorT Op;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Operator) == sizeof(AST), "ERROR: AST_Operator is not the same size as AST");
|
||||
|
||||
@ -306,11 +341,13 @@ struct AST_OpCast
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
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;
|
||||
@ -319,6 +356,7 @@ struct AST_OpCast
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_OpCast) == sizeof(AST), "ERROR: AST_OpCast is not the same size as AST");
|
||||
|
||||
@ -328,10 +366,11 @@ struct AST_Param
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
CodeType ValueType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
Code Value;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeParam Last;
|
||||
@ -341,6 +380,7 @@ struct AST_Param
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Param) == sizeof(AST), "ERROR: AST_Param is not the same size as AST");
|
||||
|
||||
@ -356,6 +396,7 @@ struct AST_Pragma
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Pragma) == sizeof(AST), "ERROR: AST_Pragma is not the same size as AST");
|
||||
|
||||
@ -371,6 +412,7 @@ struct AST_PreprocessCond
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_PreprocessCond) == sizeof(AST), "ERROR: AST_PreprocessCond is not the same size as AST");
|
||||
|
||||
@ -384,6 +426,7 @@ struct AST_Specifiers
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
s32 NumEntries;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Specifiers) == sizeof(AST), "ERROR: AST_Specifier is not the same size as AST");
|
||||
|
||||
@ -393,11 +436,13 @@ struct AST_Struct
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
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 Last;
|
||||
@ -407,6 +452,7 @@ struct AST_Struct
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Struct) == sizeof(AST), "ERROR: AST_Struct is not the same size as AST");
|
||||
|
||||
@ -416,9 +462,10 @@ struct AST_Template
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParam Params;
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -428,6 +475,7 @@ struct AST_Template
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Template) == sizeof(AST), "ERROR: AST_Template is not the same size as AST");
|
||||
|
||||
@ -437,10 +485,13 @@ struct AST_Type
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_INLINE_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
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;
|
||||
@ -448,7 +499,9 @@ struct AST_Type
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) ];
|
||||
b32 IsParamPack;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Type) == sizeof(AST), "ERROR: AST_Type is not the same size as AST");
|
||||
|
||||
@ -458,9 +511,10 @@ struct AST_Typedef
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
Code UnderlyingType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -470,6 +524,7 @@ struct AST_Typedef
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Typedef) == sizeof(AST), "ERROR: AST_Typedef is not the same size as AST");
|
||||
|
||||
@ -479,9 +534,11 @@ struct AST_Union
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
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;
|
||||
@ -491,6 +548,7 @@ struct AST_Union
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Union) == sizeof(AST), "ERROR: AST_Union is not the same size as AST");
|
||||
|
||||
@ -500,10 +558,11 @@ struct AST_Using
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType UnderlyingType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -513,6 +572,7 @@ struct AST_Using
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Using) == sizeof(AST), "ERROR: AST_Using is not the same size as AST");
|
||||
|
||||
@ -522,11 +582,13 @@ struct AST_Var
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
CodeVar NextVar;
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -536,7 +598,8 @@ struct AST_Var
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
s32 Token;
|
||||
};
|
||||
static_assert( sizeof(AST_Var) == sizeof(AST), "ERROR: AST_Var is not the same size as AST");
|
||||
#pragma endregion AST Types
|
||||
|
||||
#pragma endregion AST Types
|
||||
|
3015
project/components/gen/ast_inlines.hpp
Normal file
3015
project/components/gen/ast_inlines.hpp
Normal file
File diff suppressed because it is too large
Load Diff
143
project/components/gen/ecode.hpp
Normal file
143
project/components/gen/ecode.hpp
Normal file
@ -0,0 +1,143 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#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;
|
109
project/components/gen/eoperator.hpp
Normal file
109
project/components/gen/eoperator.hpp
Normal file
@ -0,0 +1,109 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#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;
|
97
project/components/gen/especifier.hpp
Normal file
97
project/components/gen/especifier.hpp
Normal file
@ -0,0 +1,97 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#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;
|
234
project/components/gen/etoktype.cpp
Normal file
234
project/components/gen/etoktype.cpp
Normal file
@ -0,0 +1,234 @@
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
#pragma once
|
||||
|
||||
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
|
@ -1,10 +1,16 @@
|
||||
#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(10)
|
||||
# define GEN_GLOBAL_BUCKET_SIZE megabytes(4)
|
||||
#endif
|
||||
#ifndef GEN_CODEPOOL_NUM_BLOCKS
|
||||
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(64)
|
||||
# define GEN_CODEPOOL_NUM_BLOCKS kilobytes(16)
|
||||
#endif
|
||||
#ifndef GEN_SIZE_PER_STRING_ARENA
|
||||
# define GEN_SIZE_PER_STRING_ARENA megabytes(1)
|
||||
@ -22,7 +28,7 @@
|
||||
# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4)
|
||||
#endif
|
||||
#ifndef GEN_LEX_ALLOCATOR_SIZE
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(10)
|
||||
# define GEN_LEX_ALLOCATOR_SIZE megabytes(4)
|
||||
#endif
|
||||
#ifndef GEN_BUILDER_STR_BUFFER_RESERVE
|
||||
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(1)
|
||||
@ -73,6 +79,7 @@ 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;
|
||||
@ -139,11 +146,11 @@ extern CodeType t_typename;
|
||||
|
||||
# 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__ ) )
|
||||
# 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::token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ )
|
||||
|
||||
#pragma endregion Macros
|
||||
|
||||
@ -168,4 +175,3 @@ extern CodeType t_typename;
|
||||
extern AllocatorInfo Allocator_TypeTable;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
|
||||
|
||||
@ -16,11 +18,14 @@
|
||||
# include "gen.dep.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#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
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.hpp"
|
||||
#endif
|
||||
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
@ -22,43 +27,6 @@ void AST::append( AST* other )
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
char const* AST::debug_str()
|
||||
{
|
||||
if ( Parent )
|
||||
{
|
||||
char const* fmt = stringize(
|
||||
\nType : %s
|
||||
\nParent : %s %s
|
||||
\nName : %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->Name
|
||||
, Parent->type_str()
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
char const* fmt = stringize(
|
||||
\nType : %s
|
||||
\nName : %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()
|
||||
, Name ? Name : ""
|
||||
);
|
||||
}
|
||||
|
||||
Code& AST::entry( u32 idx )
|
||||
{
|
||||
AST** current = & Front;
|
||||
@ -99,15 +67,21 @@ Code& Code::operator ++()
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
return;
|
||||
// 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.
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
@ -161,14 +135,21 @@ CodeParam& CodeParam::operator ++()
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
// 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.
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
@ -211,4 +192,3 @@ StrC token_fmt_impl( sw num, ... )
|
||||
|
||||
return { result, buf };
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast.cpp"
|
||||
#endif
|
||||
|
||||
internal void init_parser();
|
||||
internal void deinit_parser();
|
||||
|
||||
@ -15,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();
|
||||
}
|
||||
@ -42,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();
|
||||
}
|
||||
@ -68,7 +73,7 @@ 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();
|
||||
@ -76,22 +81,22 @@ void define_constants()
|
||||
|
||||
t_empty = (CodeType) make_code();
|
||||
t_empty->Type = ECode::Typename;
|
||||
t_empty->Name = get_cached_string( txt_StrC("") );
|
||||
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_StrC("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_StrC("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_StrC("public:") );
|
||||
access_public->Name = get_cached_string( txt("public:") );
|
||||
access_public.set_global();
|
||||
|
||||
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
|
||||
@ -102,13 +107,13 @@ void define_constants()
|
||||
|
||||
module_global_fragment = make_code();
|
||||
module_global_fragment->Type = ECode::Untyped;
|
||||
module_global_fragment->Name = get_cached_string( txt_StrC("module;") );
|
||||
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_StrC("module : private;") );
|
||||
module_private_fragment->Name = get_cached_string( txt("module : private;") );
|
||||
module_private_fragment->Content = module_private_fragment->Name;
|
||||
module_private_fragment.set_global();
|
||||
|
||||
@ -117,14 +122,14 @@ void define_constants()
|
||||
fmt_newline.set_global();
|
||||
|
||||
pragma_once = (CodePragma) make_code();
|
||||
pragma_once->Type = ECode::Untyped;
|
||||
pragma_once->Name = get_cached_string( txt_StrC("once") );
|
||||
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_StrC("...") );
|
||||
param_varadic->Name = get_cached_string( txt("...") );
|
||||
param_varadic->ValueType = t_empty;
|
||||
param_varadic.set_global();
|
||||
|
||||
@ -170,10 +175,12 @@ void define_constants()
|
||||
#endif
|
||||
# undef def_constant_code_type
|
||||
|
||||
# pragma push_macro( "forceinline" )
|
||||
# pragma push_macro( "global" )
|
||||
# pragma push_macro( "internal" )
|
||||
# pragma push_macro( "local_persist" )
|
||||
# pragma push_macro( "neverinline" )
|
||||
# undef forceinline
|
||||
# undef global
|
||||
# undef internal
|
||||
# undef local_persist
|
||||
@ -189,6 +196,7 @@ 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 );
|
||||
@ -209,6 +217,7 @@ 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" )
|
||||
@ -226,12 +235,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 );
|
||||
|
||||
@ -242,12 +251,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.
|
||||
@ -255,7 +264,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 );
|
||||
|
||||
@ -264,7 +273,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 );
|
||||
}
|
||||
@ -274,7 +283,7 @@ 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();
|
||||
@ -362,7 +371,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();
|
||||
}
|
||||
@ -397,15 +406,17 @@ 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 };
|
||||
@ -415,6 +426,7 @@ Code make_code()
|
||||
result->Type = ECode::Invalid;
|
||||
result->ModuleFlags = ModuleFlag::Invalid;
|
||||
result->NumEntries = 0;
|
||||
result->Token = -1;
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -443,4 +455,3 @@ void set_allocator_string_table( AllocatorInfo allocator )
|
||||
{
|
||||
Allocator_StringArena = allocator;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast_types.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Gen Interface
|
||||
|
||||
// Initialize the library.
|
||||
@ -65,7 +70,7 @@ 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 );
|
||||
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
@ -175,4 +180,3 @@ Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... );
|
||||
#pragma endregion Untyped text
|
||||
|
||||
#pragma endregion Gen Interface
|
||||
|
||||
|
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;
|
||||
@ -181,4 +186,3 @@ Code untyped_token_fmt( s32 num_tokens, ... )
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Upfront
|
||||
|
||||
enum class OpValidateResult : u32
|
||||
@ -7,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;
|
||||
@ -413,12 +417,42 @@ 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;
|
||||
}
|
||||
|
||||
@ -818,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 )
|
||||
{
|
||||
@ -826,10 +860,14 @@ CodeInclude def_include ( StrC path )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
StrC content = foreign ?
|
||||
to_str( str_fmt_buf( "<%.*s>\n", path.Len, path.Ptr ))
|
||||
: to_str( str_fmt_buf( "\"%.*s\"\n", path.Len, path.Ptr ));
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = ECode::Preprocess_Include;
|
||||
result->Name = get_cached_string( path );
|
||||
result->Name = get_cached_string( content );
|
||||
result->Content = result->Name;
|
||||
|
||||
return (CodeInclude) result;
|
||||
@ -1059,13 +1097,17 @@ CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr )
|
||||
switch (type)
|
||||
{
|
||||
case EPreprocessCond::If:
|
||||
result->Type = ECode::Preprocess_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;
|
||||
@ -2249,6 +2291,4 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
|
||||
# undef def_body_start
|
||||
# undef def_body_code_array_start
|
||||
|
||||
|
||||
#pragma endregion Upfront
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "gen.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region StaticData
|
||||
|
||||
// TODO : Convert global allocation strategy to use a slab allocation strategy.
|
||||
@ -47,6 +52,7 @@ 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;
|
||||
@ -95,4 +101,3 @@ global CodeType t_f64;
|
||||
#endif
|
||||
|
||||
#pragma endregion Constants
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
# Temporary Code
|
||||
|
||||
These are heavy macro code used throughout the library thats intended to be replaced with codegen done with the library itself.
|
||||
|
||||
The reason for this is to minimize macro generation to only trivial cases.
|
||||
This makes the library more verbose but makes it easier to debug which is of higher priority.
|
||||
|
||||
Any sort of verbosity cost will be mitigated with better docs and heavy usage of pragma regions.
|
@ -1,230 +0,0 @@
|
||||
// This is the non-bootstraped version of the Common AST Implementation. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
#pragma region AST 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; \
|
||||
} \
|
||||
Typename::operator bool() \
|
||||
{ \
|
||||
return ast != nullptr; \
|
||||
}
|
||||
|
||||
#define Define_CodeType_Impl( Typename ) \
|
||||
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; \
|
||||
} \
|
||||
|
||||
Define_CodeImpl( Code );
|
||||
Define_CodeImpl( CodeBody );
|
||||
Define_CodeImpl( CodeAttributes );
|
||||
Define_CodeImpl( CodeComment );
|
||||
Define_CodeImpl( CodeClass );
|
||||
Define_CodeImpl( CodeConstructor );
|
||||
Define_CodeImpl( CodeDefine );
|
||||
Define_CodeImpl( CodeDestructor );
|
||||
Define_CodeImpl( CodeEnum );
|
||||
Define_CodeImpl( CodeExec );
|
||||
Define_CodeImpl( CodeExtern );
|
||||
Define_CodeImpl( CodeInclude );
|
||||
Define_CodeImpl( CodeFriend );
|
||||
Define_CodeImpl( CodeFn );
|
||||
Define_CodeImpl( CodeModule );
|
||||
Define_CodeImpl( CodeNS );
|
||||
Define_CodeImpl( CodeOperator );
|
||||
Define_CodeImpl( CodeOpCast );
|
||||
Define_CodeImpl( CodeParam );
|
||||
Define_CodeImpl( CodePragma );
|
||||
Define_CodeImpl( CodePreprocessCond );
|
||||
Define_CodeImpl( CodeSpecifiers );
|
||||
Define_CodeImpl( CodeStruct );
|
||||
Define_CodeImpl( CodeTemplate );
|
||||
Define_CodeImpl( CodeType );
|
||||
Define_CodeImpl( CodeTypedef );
|
||||
Define_CodeImpl( CodeUnion );
|
||||
Define_CodeImpl( CodeUsing );
|
||||
Define_CodeImpl( CodeVar );
|
||||
|
||||
Define_CodeType_Impl( Attributes );
|
||||
Define_CodeType_Impl( Comment );
|
||||
Define_CodeType_Impl( Constructor );
|
||||
Define_CodeType_Impl( Define );
|
||||
Define_CodeType_Impl( Destructor );
|
||||
Define_CodeType_Impl( Enum );
|
||||
Define_CodeType_Impl( Exec );
|
||||
Define_CodeType_Impl( Extern );
|
||||
Define_CodeType_Impl( Include );
|
||||
Define_CodeType_Impl( Friend );
|
||||
Define_CodeType_Impl( Fn );
|
||||
Define_CodeType_Impl( Module );
|
||||
Define_CodeType_Impl( NS );
|
||||
Define_CodeType_Impl( Operator );
|
||||
Define_CodeType_Impl( OpCast );
|
||||
Define_CodeType_Impl( Pragma );
|
||||
Define_CodeType_Impl( PreprocessCond );
|
||||
Define_CodeType_Impl( Template );
|
||||
Define_CodeType_Impl( Type );
|
||||
Define_CodeType_Impl( Typedef );
|
||||
Define_CodeType_Impl( Union );
|
||||
Define_CodeType_Impl( Using );
|
||||
Define_CodeType_Impl( Var );
|
||||
|
||||
#undef Define_CodeImpl
|
||||
#undef Define_CodeType_Impl
|
||||
|
||||
#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( Constructor );
|
||||
Define_AST_Cast( Class );
|
||||
Define_AST_Cast( Define );
|
||||
Define_AST_Cast( Destructor );
|
||||
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( NS );
|
||||
Define_AST_Cast( Operator );
|
||||
Define_AST_Cast( OpCast );
|
||||
Define_AST_Cast( Param );
|
||||
Define_AST_Cast( Pragma );
|
||||
Define_AST_Cast( PreprocessCond );
|
||||
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( Constructor );
|
||||
Define_CodeCast( Class );
|
||||
Define_CodeCast( Define );
|
||||
Define_CodeCast( Destructor );
|
||||
Define_CodeCast( Exec );
|
||||
Define_CodeCast( Enum );
|
||||
Define_CodeCast( Extern );
|
||||
Define_CodeCast( Include );
|
||||
Define_CodeCast( Friend );
|
||||
Define_CodeCast( Fn );
|
||||
Define_CodeCast( Module );
|
||||
Define_CodeCast( NS );
|
||||
Define_CodeCast( Operator );
|
||||
Define_CodeCast( OpCast );
|
||||
Define_CodeCast( Param );
|
||||
Define_CodeCast( Pragma );
|
||||
Define_CodeCast( PreprocessCond );
|
||||
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 Common
|
||||
|
@ -1,92 +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( NewLine ) \
|
||||
Entry( Comment ) \
|
||||
Entry( Access_Private ) \
|
||||
Entry( Access_Protected ) \
|
||||
Entry( Access_Public ) \
|
||||
Entry( PlatformAttributes ) \
|
||||
Entry( Class ) \
|
||||
Entry( Class_Fwd ) \
|
||||
Entry( Class_Body ) \
|
||||
Entry( Constructor ) \
|
||||
Entry( Constructor_Fwd ) \
|
||||
Entry( Destructor ) \
|
||||
Entry( Destructor_Fwd ) \
|
||||
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( Preprocess_Define ) \
|
||||
Entry( Preprocess_If ) \
|
||||
Entry( Preprocess_IfDef ) \
|
||||
Entry( Preprocess_IfNotDef ) \
|
||||
Entry( Preprocess_ElIf ) \
|
||||
Entry( Preprocess_Else ) \
|
||||
Entry( Preprocess_EndIf ) \
|
||||
Entry( Preprocess_Include ) \
|
||||
Entry( Preprocess_Pragma ) \
|
||||
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,76 +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
|
||||
StrC to_str( Type op )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ Num_Ops ] = {
|
||||
# define Entry( Type_, Token_ ) { sizeof(stringize(Token_)), stringize(Token_) },
|
||||
Define_Operators
|
||||
# undef Entry
|
||||
txt_StrC(",")
|
||||
};
|
||||
|
||||
return lookup[ op ];
|
||||
}
|
||||
|
||||
# undef Define_Operators
|
||||
}
|
||||
using OperatorT = EOperator::Type;
|
||||
|
@ -1,110 +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( NeverInline, neverinline ) \
|
||||
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 ) \
|
||||
Entry( Pure, = 0 )
|
||||
|
||||
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" )
|
||||
# pragma push_macro( "neverinline" )
|
||||
# undef global
|
||||
# undef internal
|
||||
# undef local_persist
|
||||
# undef neverinline
|
||||
|
||||
# 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" )
|
||||
# pragma pop_macro( "neverinline" )
|
||||
};
|
||||
|
||||
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,170 +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.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
||||
# 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( Comment_End, "__comment_end__" ) \
|
||||
Entry( Comment_Start, "__comment start__" ) \
|
||||
Entry( Char, "__character__" ) \
|
||||
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( NewLine, "__NewLine__" ) \
|
||||
Entry( Number, "__number__" ) \
|
||||
Entry( Operator, "__operator__" ) \
|
||||
Entry( Preprocess_Hash, "#" ) \
|
||||
Entry( Preprocess_Define, "define") \
|
||||
Entry( Preprocess_If, "if") \
|
||||
Entry( Preprocess_IfDef, "ifdef") \
|
||||
Entry( Preprocess_IfNotDef, "ifndef") \
|
||||
Entry( Preprocess_ElIf, "elif") \
|
||||
Entry( Preprocess_Else, "else") \
|
||||
Entry( Preprocess_EndIf, "endif") \
|
||||
Entry( Preprocess_Include, "include" ) \
|
||||
Entry( Preprocess_Pragma, "pragma") \
|
||||
Entry( Preprocess_Content, "__macro_content__") \
|
||||
Entry( Preprocess_Macro, "__macro__") \
|
||||
Entry( Preprocess_Unsupported, "__unsupported__" ) \
|
||||
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_NeverInline, "neverinline" ) \
|
||||
Entry( Spec_Override, "override" ) \
|
||||
Entry( Spec_Static, "static" ) \
|
||||
Entry( Spec_ThreadLocal, "thread_local" ) \
|
||||
Entry( Spec_Virtual, "virtual" ) \
|
||||
Entry( Spec_Volatile, "volatile") \
|
||||
Entry( Star, "*" ) \
|
||||
Entry( Statement_End, ";" ) \
|
||||
Entry( StaticAssert, "static_assert" ) \
|
||||
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( Type_MS_int8, "__int8" ) \
|
||||
Entry( Type_MS_int16, "__int16" ) \
|
||||
Entry( Type_MS_int32, "__int32" ) \
|
||||
Entry( Type_MS_int64, "__int64" ) \
|
||||
Entry( Type_MS_W64, "_W64" ) \
|
||||
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
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[(u32)NumTokens] =
|
||||
{
|
||||
# define Entry( Name_, Str_ ) { sizeof(Str_), Str_ },
|
||||
Define_TokType
|
||||
GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||
# undef Entry
|
||||
};
|
||||
|
||||
return lookup[(u32)type];
|
||||
}
|
||||
# undef Define_TokType
|
||||
};
|
||||
|
||||
using TokType = ETokType::Type;
|
||||
|
||||
} // Parser
|
||||
|
@ -1,11 +1,16 @@
|
||||
#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 fatal, fatal will still be used for memory failures as the library is unusable when they occur.
|
||||
// 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 fatal
|
||||
#define log_failure GEN_FATAL
|
||||
#endif
|
||||
|
||||
enum class AccessSpec : u32
|
||||
@ -46,7 +51,6 @@ enum class EnumT : u8
|
||||
constexpr EnumT EnumClass = EnumT::Class;
|
||||
constexpr EnumT EnumRegular = EnumT::Regular;
|
||||
|
||||
|
||||
enum class ModuleFlag : u32
|
||||
{
|
||||
None = 0,
|
||||
@ -75,51 +79,3 @@ constexpr EPreprocessCond PreprocessCond_If = EPreprocessCond::If;
|
||||
constexpr EPreprocessCond PreprocessCond_IfDef = EPreprocessCond::IfDef;
|
||||
constexpr EPreprocessCond PreprocessCond_IfNotDef = EPreprocessCond::IfNotDef;
|
||||
constexpr EPreprocessCond PreprocessCond_ElIf = EPreprocessCond::ElIf;
|
||||
|
||||
/*
|
||||
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
|
||||
|
||||
// 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;
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Basic Types
|
||||
|
||||
#define GEN_U8_MIN 0u
|
||||
@ -118,4 +123,3 @@ typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
|
||||
#pragma endregion Basic Types
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Containers
|
||||
|
||||
template<class Type>
|
||||
@ -540,4 +545,3 @@ protected:
|
||||
};
|
||||
|
||||
#pragma endregion Containers
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
@ -39,4 +43,3 @@ s32 assert_crash( char const* condition )
|
||||
#endif
|
||||
|
||||
#pragma endregion Debug
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVESj
|
||||
# pragma once
|
||||
# include "basic_types.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
@ -34,26 +39,25 @@ s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
|
||||
#if Build_Debug
|
||||
#define fatal( fmt, ... ) \
|
||||
#define GEN_FATAL( ... ) \
|
||||
do \
|
||||
{ \
|
||||
local_persist thread_local \
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
|
||||
\
|
||||
str_fmt(buf, GEN_PRINTF_MAXLEN, fmt, __VA_ARGS__); \
|
||||
str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
|
||||
GEN_PANIC(buf); \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
|
||||
# define fatal( fmt, ... ) \
|
||||
do \
|
||||
{ \
|
||||
str_fmt_out_err_va( fmt, __VA_ARGS__ ); \
|
||||
process_exit(1); \
|
||||
} \
|
||||
# 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 )
|
||||
@ -634,4 +639,3 @@ internal GEN_FILE_CLOSE_PROC( _memory_file_close )
|
||||
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
|
||||
|
||||
#pragma endregion File Handling
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
|
||||
typedef u32 FileMode;
|
||||
@ -370,4 +375,3 @@ u8* file_stream_buf( FileInfo* file, sw* size );
|
||||
extern FileOperations const memory_file_operations;
|
||||
|
||||
#pragma endregion File Handling
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
global u32 const _crc32_table[ 256 ] = {
|
||||
@ -83,4 +88,3 @@ u64 crc64( void const* data, sw len )
|
||||
}
|
||||
|
||||
#pragma endregion Hashing
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "containers.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
u32 crc32( void const* data, sw len );
|
||||
u64 crc64( void const* data, sw len );
|
||||
|
||||
#pragma endregion Hashing
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#pragma region Platform Detection
|
||||
|
||||
/* Platform architecture */
|
||||
@ -100,25 +102,6 @@
|
||||
#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
|
||||
@ -133,10 +116,11 @@
|
||||
#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
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#define zpl_cast( Type ) ( Type )
|
||||
@ -8,6 +13,25 @@
|
||||
#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 )
|
||||
@ -21,7 +45,7 @@
|
||||
#define scast( Type, Value ) static_cast< Type >( Value )
|
||||
|
||||
// Num Arguments (Varadics)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
// #if defined(__GNUC__) || defined(__clang__)
|
||||
// Supports 0-50 arguments
|
||||
#define num_args_impl( _0, \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
@ -53,37 +77,39 @@
|
||||
0 \
|
||||
)
|
||||
|
||||
#else
|
||||
// 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
|
||||
// #else
|
||||
// This doesn't work on latest msvc so I had to use /Zc:preprocessor flag.
|
||||
|
||||
#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
|
||||
// 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__
|
||||
@ -125,6 +151,12 @@
|
||||
#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 )
|
||||
{
|
||||
@ -134,4 +166,3 @@ void swap( Type& a, Type& b )
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@ -387,4 +518,3 @@ void Pool::clear()
|
||||
}
|
||||
|
||||
#pragma endregion Memory
|
||||
|
||||
|
@ -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
|
||||
@ -484,4 +555,3 @@ struct Pool
|
||||
};
|
||||
|
||||
#pragma endregion Memory
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
#define _adt_fprintf( s_, fmt_, ... ) \
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
enum ADT_Type : u32
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
enum
|
||||
@ -47,7 +52,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 +416,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;
|
||||
@ -572,4 +587,3 @@ sw str_fmt_out_err( char const* fmt, ... )
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
struct FileInfo;
|
||||
@ -34,4 +39,3 @@ sw log_fmt(char const* fmt, ...)
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
||||
|
||||
|
@ -78,4 +78,3 @@
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros and Includes
|
||||
|
||||
|
@ -1,40 +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 "debug.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
internal
|
||||
@ -207,4 +212,3 @@ f64 str_to_f64( const char* str, char** end_ptr )
|
||||
}
|
||||
|
||||
#pragma endregion String Ops
|
||||
|
||||
|
@ -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 );
|
||||
@ -260,4 +265,3 @@ GEN_IMPL_INLINE void str_to_upper( char* str )
|
||||
}
|
||||
|
||||
#pragma endregion String Ops
|
||||
|
||||
|
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,19 +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
|
||||
@ -160,4 +165,3 @@
|
||||
#endif
|
||||
|
||||
#pragma endregion Timing
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
@ -12,4 +17,3 @@ u64 time_rel_ms( void );
|
||||
#endif
|
||||
|
||||
#pragma endregion Timing
|
||||
|
||||
|
@ -4,6 +4,7 @@ Constexpr, constexpr
|
||||
Constinit, constinit
|
||||
Explicit, explicit
|
||||
External_Linkage, extern
|
||||
ForceInline, forceinline
|
||||
Global, global
|
||||
Inline, inline
|
||||
Internal_Linkage, internal
|
||||
@ -20,5 +21,6 @@ Volatile, volatile
|
||||
Virtual, virtual
|
||||
Const, const
|
||||
Final, final
|
||||
NoExceptions, noexcept
|
||||
Override, override
|
||||
Pure, = 0
|
||||
|
|
@ -15,7 +15,7 @@ BraceSquare_Open, "["
|
||||
BraceSquare_Close, "]"
|
||||
Capture_Start, "("
|
||||
Capture_End, ")"
|
||||
Comment, "__comemnt__"
|
||||
Comment, "__comment__"
|
||||
Comment_End, "__comment_end__"
|
||||
Comment_Start, "__comment_start__"
|
||||
Char, "__character__"
|
||||
@ -61,6 +61,7 @@ Spec_Constinit, "constinit"
|
||||
Spec_Explicit, "explicit"
|
||||
Spec_Extern, "extern"
|
||||
Spec_Final, "final"
|
||||
Spec_ForceInline, "forceinline"
|
||||
Spec_Global, "global"
|
||||
Spec_Inline, "inline"
|
||||
Spec_Internal_Linkage, "internal"
|
||||
|
|
@ -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,69 +0,0 @@
|
||||
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 );
|
||||
}
|
||||
|
||||
#if 0
|
||||
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 );
|
||||
};
|
||||
#endif
|
||||
|
@ -1,254 +0,0 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.cpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "file_processors/builder.hpp"
|
||||
#include "file_processors/builder.cpp"
|
||||
#include "file_processors/scanner.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gen.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 string = scan_file( "dependencies/string.hpp" );
|
||||
Code file_handling = scan_file( "dependencies/file_handling.hpp" );
|
||||
Code timing = scan_file( "dependencies/timing.hpp" );
|
||||
|
||||
Builder
|
||||
deps_header = Builder::open("gen/gen.dep.hpp");
|
||||
deps_header.print_fmt( generation_notice );
|
||||
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( header_start );
|
||||
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( timing );
|
||||
|
||||
deps_header.print_fmt( "GEN_NS_END\n\n" );
|
||||
deps_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 string = scan_file( "dependencies/string.cpp" );
|
||||
Code file_handling = scan_file( "dependencies/file_handling.cpp" );
|
||||
Code timing = scan_file( "dependencies/timing.cpp" );
|
||||
|
||||
Builder
|
||||
deps_impl = Builder::open( "gen/gen.dep.cpp" );
|
||||
deps_impl.print_fmt( generation_notice );
|
||||
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( src_start );
|
||||
deps_impl.print_fmt( "GEN_NS_BEGIN\n\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( string );
|
||||
deps_impl.print( file_handling );
|
||||
deps_impl.print( timing );
|
||||
|
||||
deps_impl.print_fmt( "GEN_NS_END\n\n" );
|
||||
deps_impl.write();
|
||||
}
|
||||
|
||||
// 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( "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_fmt( "#pragma region AST\n\n" );
|
||||
header.print( ast );
|
||||
header.print( ast_types );
|
||||
header.print_fmt( "#pragma endregion AST\n\n" );
|
||||
|
||||
header.print( interface );
|
||||
|
||||
header.print_fmt( "#pragma region Inlines\n\n" );
|
||||
header.print( inlines );
|
||||
header.print( ast_inlines );
|
||||
header.print_fmt( "#pragma endregion Inlines\n\n" );
|
||||
|
||||
header.print( header_end );
|
||||
header.print_fmt( "GEN_NS_END\n\n" );
|
||||
header.print( pop_ignores );
|
||||
header.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/untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
|
||||
CodeNS parser_nspace = 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( "\nGEN_NS_BEGIN\n\n");
|
||||
|
||||
src.print( static_data );
|
||||
|
||||
src.print_fmt( "#pragma region AST\n\n" );
|
||||
src.print( ast_case_macros );
|
||||
src.print( ast );
|
||||
src.print_fmt( "#pragma endregion AST\n\n" );
|
||||
|
||||
src.print_fmt( "#pragma region Interface\n\n" );
|
||||
src.print( interface );
|
||||
src.print( upfront );
|
||||
src.print_fmt( "#pragma region Parsing\n\n" );
|
||||
src.print( parser_nspace );
|
||||
src.print( parsing );
|
||||
src.print( untyped );
|
||||
src.print_fmt( "#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();
|
||||
}
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( "file_processors/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_StrC("gen.hpp") ));
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
header.print( builder );
|
||||
header.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( "file_processors/builder.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.builder.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( def_include( txt_StrC("gen.builder.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
src.print( builder );
|
||||
src.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( "file_processors/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_StrC("gen.hpp") ) );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
header.print( parsing );
|
||||
header.print( scanner );
|
||||
header.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_scanner.cpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.cpp" );
|
||||
// Code scanner = scan_file( "file_processors/scanner.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.scanner.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( def_include( txt_StrC("gen.scanner.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n\n" );
|
||||
src.print( parsing );
|
||||
// src.print( scanner );
|
||||
src.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
}
|
@ -23,9 +23,9 @@ GEN_NS_BEGIN
|
||||
|
||||
#include "components/interface.cpp"
|
||||
#include "components/interface.upfront.cpp"
|
||||
#include "components/temp/etoktype.cpp"
|
||||
#include "components/gen/etoktype.cpp"
|
||||
#include "components/interface.parsing.cpp"
|
||||
#include "components/untyped.cpp"
|
||||
#include "components/interface.untyped.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
|
@ -6,16 +6,12 @@
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "dependencies/debug.cpp"
|
||||
|
||||
#include "dependencies/string_ops.cpp"
|
||||
#include "dependencies/printing.cpp"
|
||||
#include "dependencies/memory.cpp"
|
||||
|
||||
#include "dependencies/hashing.cpp"
|
||||
#include "dependencies/string.cpp"
|
||||
|
||||
#include "dependencies/strings.cpp"
|
||||
#include "dependencies/filesystem.cpp"
|
||||
#include "dependencies/timing.cpp"
|
||||
|
||||
#include "dependencies/file_handling.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
@ -8,17 +8,13 @@ GEN_NS_BEGIN
|
||||
#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/string.hpp"
|
||||
|
||||
#include "dependencies/strings.hpp"
|
||||
#include "dependencies/filesystem.hpp"
|
||||
#include "dependencies/timing.hpp"
|
||||
|
||||
#include "dependencies/file_handling.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
@ -14,9 +14,9 @@
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/types.hpp"
|
||||
#include "components/temp/ecode.hpp"
|
||||
#include "components/temp/eoperator.hpp"
|
||||
#include "components/temp/especifier.hpp"
|
||||
#include "components/gen/ecode.hpp"
|
||||
#include "components/gen/eoperator.hpp"
|
||||
#include "components/gen/especifier.hpp"
|
||||
|
||||
#include "components/ast.hpp"
|
||||
#include "components/ast_types.hpp"
|
||||
@ -24,7 +24,7 @@ GEN_NS_BEGIN
|
||||
#include "components/interface.hpp"
|
||||
|
||||
#include "components/inlines.hpp"
|
||||
#include "components/temp/ast_inlines.hpp"
|
||||
#include "components/gen/ast_inlines.hpp"
|
||||
#include "components/header_end.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
@ -30,13 +30,7 @@ CodeBody gen_ecode( char const* path )
|
||||
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
|
||||
};
|
||||
)));
|
||||
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
|
||||
@ -53,15 +47,15 @@ CodeBody gen_ecode( char const* path )
|
||||
)));
|
||||
#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) ) );
|
||||
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 ) );
|
||||
return def_global_body( args( nspace, code_t, fmt_newline ) );
|
||||
}
|
||||
|
||||
CodeBody gen_eoperator( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
char scratch_mem[kilobytes(4)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
@ -111,12 +105,12 @@ CodeBody gen_eoperator( char const* path )
|
||||
|
||||
CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
|
||||
|
||||
return def_global_body( args( nspace, operator_t ) );
|
||||
return def_global_body( args( nspace, operator_t, fmt_newline ) );
|
||||
}
|
||||
|
||||
CodeBody gen_especifier( char const* path )
|
||||
{
|
||||
char scratch_mem[kilobytes(1)];
|
||||
char scratch_mem[kilobytes(4)];
|
||||
Arena scratch = Arena::init_from_memory( scratch_mem, sizeof(scratch_mem) );
|
||||
|
||||
file_read_contents( scratch, zero_terminate, path );
|
||||
@ -157,9 +151,13 @@ CodeBody gen_especifier( char const* path )
|
||||
#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 )
|
||||
{
|
||||
@ -202,12 +200,14 @@ CodeBody gen_especifier( char const* path )
|
||||
#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 ) );
|
||||
return def_global_body( args( nspace, specifier_t, fmt_newline ) );
|
||||
}
|
||||
|
||||
CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
@ -324,8 +324,8 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
#pragma pop_macro( "do_once_start" )
|
||||
#pragma pop_macro( "do_once_end" )
|
||||
|
||||
CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) );
|
||||
CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) );
|
||||
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 ) );
|
||||
}
|
||||
@ -333,7 +333,9 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
|
||||
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()
|
||||
@ -529,7 +531,7 @@ CodeBody gen_ast_inlines()
|
||||
CodeBody impl_cast_var = parse_global_body( token_fmt( "typename", StrC name(Var), cast_tmpl ));
|
||||
|
||||
CodeBody result = def_global_body( args(
|
||||
def_pragma( txt_StrC("region generated code inline implementation")),
|
||||
def_pragma( txt("region generated code inline implementation")),
|
||||
fmt_newline,
|
||||
impl_code,
|
||||
impl_code_body,
|
||||
@ -561,9 +563,9 @@ CodeBody gen_ast_inlines()
|
||||
impl_code_using,
|
||||
impl_code_var,
|
||||
fmt_newline,
|
||||
def_pragma( txt_StrC("endregion generated code inline implementation")),
|
||||
def_pragma( txt("endregion generated code inline implementation")),
|
||||
fmt_newline,
|
||||
def_pragma( txt_StrC("region generated AST/Code cast implementation")),
|
||||
def_pragma( txt("region generated AST/Code cast implementation")),
|
||||
fmt_newline,
|
||||
impl_cast_body,
|
||||
impl_cast_attribute,
|
||||
@ -594,10 +596,11 @@ CodeBody gen_ast_inlines()
|
||||
impl_cast_using,
|
||||
impl_cast_var,
|
||||
fmt_newline,
|
||||
def_pragma( txt_StrC("endregion generated AST/Code cast implementation")),
|
||||
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 )
|
@ -8,27 +8,40 @@ Generation, testing, and cleanup scripts for the test directory are found here a
|
||||
|
||||
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.
|
||||
|
||||
**`bootstrap.ps1`**
|
||||
Generate a version of gencpp where components are inlined directly to `gen.<hpp/cpp>` and `gen. <hpp/cpp>`
|
||||
Any heavily preprocessed code is not inlined and are instead generated using the code in the `helpers` directory.
|
||||
**`build.ps1`**
|
||||
Build bootstrap, singleheader, or tests. Supports MSVC or clang, release or debug.
|
||||
|
||||
**`singlheader.build.ps1`**
|
||||
Generate a single-header version of the library where all code that would normally good in the usual four files (see bootstrap) are inlined into a single `gen.hpp` file.
|
||||
As with the bootstrap, any heavily preprocessed code is not inlined and instead generated with helper code.
|
||||
```
|
||||
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.
|
||||
```
|
||||
|
||||
**`test.gen.build.ps1`**
|
||||
Build the metaprogram for generating the test code.
|
||||
**`package_release.ps1`**
|
||||
Will build the project as fast as possible, then package the release into a zip file.
|
||||
|
||||
**`test.gen.ps1`**
|
||||
Build (if not already) the metaprogram for generating test code, then run it to generate code.
|
||||
|
||||
**`test.build.ps1`**
|
||||
Build and run metaprogram, build test program.
|
||||
|
||||
**`test.run.ps1`**
|
||||
Build and run metaprogram, build and run test program.
|
||||
*Note: My env is Windows 11 with MSVC 2022 and clang 16.0.6*
|
||||
|
@ -1,78 +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 bootstrap
|
||||
Push-Location $path_project
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
$args_meson += $path_project_build
|
||||
|
||||
& meson $args_meson
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Compile bootstrap
|
||||
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 bootstrap
|
||||
$gencpp_bootstrap = Join-Path $path_project_build gencpp_bootstrap.exe
|
||||
|
||||
Write-Host `nRunning gencpp bootstrap...
|
||||
& $gencpp_bootstrap
|
||||
|
||||
# Format generated gencpp
|
||||
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',
|
||||
'gen.builder.hpp', 'gen.builder.cpp'
|
||||
'gen.scanner.hpp', 'gen.scanner.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
|
||||
|
||||
# Build and run validation
|
||||
|
@ -1,2 +0,0 @@
|
||||
cls
|
||||
Invoke-Expression "& $(Join-Path $PSScriptRoot 'bootstrap.ci.ps1') $args"
|
473
scripts/build.ci.ps1
Normal file
473
scripts/build.ci.ps1
Normal file
@ -0,0 +1,473 @@
|
||||
# This build script was written to build on windows, however I did setup some generalization to allow for cross platform building.
|
||||
# It will most likely need a partial rewrite to segment the build process into separate script invocations based on the OS.
|
||||
# That or just rewrite it in an sh script and call it a day.
|
||||
|
||||
Import-Module ./helpers/target_arch.psm1
|
||||
$devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1'
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
|
||||
Push-Location $path_root
|
||||
|
||||
#region Arguments
|
||||
$vendor = $null
|
||||
$release = $null
|
||||
[bool] $bootstrap = $false
|
||||
[bool] $singleheader = $false
|
||||
[bool] $test = $false
|
||||
|
||||
[array] $vendors = @( "clang", "msvc" )
|
||||
|
||||
# This is a really lazy way of parsing the args, could use actual params down the line...
|
||||
|
||||
if ( $args ) { $args | ForEach-Object {
|
||||
switch ($_){
|
||||
{ $_ -in $vendors } { $vendor = $_; break }
|
||||
"release" { $release = $true }
|
||||
"debug" { $release = $false }
|
||||
"bootstrap" { $bootstrap = $true }
|
||||
"singleheader" { $singleheader = $true }
|
||||
"test" { $test = $true }
|
||||
}
|
||||
}}
|
||||
#endregion Arguments
|
||||
|
||||
#region Configuration
|
||||
if ($IsWindows) {
|
||||
# This library was really designed to only run on 64-bit systems.
|
||||
# (Its a development tool after all)
|
||||
& $devshell -arch amd64
|
||||
}
|
||||
|
||||
if ( $vendor -eq $null ) {
|
||||
write-host "No vendor specified, assuming clang available"
|
||||
$compiler = "clang"
|
||||
}
|
||||
|
||||
if ( $release -eq $null ) {
|
||||
write-host "No build type specified, assuming debug"
|
||||
$release = $false
|
||||
}
|
||||
|
||||
if ( $bootstrap -eq $false -and $singleheader -eq $false -and $test -eq $false ) {
|
||||
throw "No build target specified. One must be specified, this script will not assume one"
|
||||
}
|
||||
|
||||
write-host "Building gencpp with $vendor"
|
||||
write-host "Build Type: $(if ($release) {"Release"} else {"Debug"} )"
|
||||
|
||||
function run-compiler
|
||||
{
|
||||
param( $compiler, $unit, $compiler_args )
|
||||
|
||||
write-host "`Compiling $unit"
|
||||
write-host "Compiler config:"
|
||||
$compiler_args | ForEach-Object {
|
||||
write-host $_ -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
$time_taken = Measure-Command {
|
||||
& $compiler $compiler_args 2>&1 | ForEach-Object {
|
||||
$color = 'White'
|
||||
switch ($_){
|
||||
{ $_ -match "error" } { $color = 'Red' ; break }
|
||||
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
||||
}
|
||||
write-host `t $_ -ForegroundColor $color
|
||||
}
|
||||
}
|
||||
|
||||
if ( Test-Path($unit) ) {
|
||||
write-host "$unit compile finished in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
else {
|
||||
write-host "Compile failed for $unit" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
function run-linker
|
||||
{
|
||||
param( $linker, $binary, $linker_args )
|
||||
|
||||
write-host "`Linking $binary"
|
||||
write-host "Linker config:"
|
||||
$linker_args | ForEach-Object {
|
||||
write-host $_ -ForegroundColor Cyan
|
||||
}
|
||||
|
||||
$time_taken = Measure-Command {
|
||||
& $linker $linker_args 2>&1 | ForEach-Object {
|
||||
$color = 'White'
|
||||
switch ($_){
|
||||
{ $_ -match "error" } { $color = 'Red' ; break }
|
||||
{ $_ -match "warning" } { $color = 'Yellow'; break }
|
||||
}
|
||||
write-host `t $_ -ForegroundColor $color
|
||||
}
|
||||
}
|
||||
|
||||
if ( Test-Path($binary) ) {
|
||||
write-host "$binary linking finished in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
else {
|
||||
write-host "Linking failed for $binary" -ForegroundColor Red
|
||||
}
|
||||
}
|
||||
|
||||
if ( $vendor -match "clang" )
|
||||
{
|
||||
# https://clang.llvm.org/docs/ClangCommandLineReference.html
|
||||
$flag_compile = '-c'
|
||||
$flag_color_diagnostics = '-fcolor-diagnostics'
|
||||
$flag_no_color_diagnostics = '-fno-color-diagnostics'
|
||||
$flag_debug = '-g'
|
||||
$flag_debug_codeview = '-gcodeview'
|
||||
$flag_define = '-D'
|
||||
$flag_preprocess = '-E'
|
||||
$flag_include = '-I'
|
||||
$flag_library = '-l'
|
||||
$flag_library_path = '-L'
|
||||
$flag_link_win = '-Wl,'
|
||||
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||
$flag_link_win_machine_32 = '/MACHINE:X86'
|
||||
$flag_link_win_machine_64 = '/MACHINE:X64'
|
||||
$flag_link_win_debug = '/DEBUG'
|
||||
$flag_link_win_pdb = '/PDB:'
|
||||
$flag_link_win_path_output = '/OUT:'
|
||||
$flag_no_optimization = '-O0'
|
||||
$flag_path_output = '-o'
|
||||
$flag_preprocess_non_intergrated = '-no-integrated-cpp'
|
||||
$flag_profiling_debug = '-fdebug-info-for-profiling'
|
||||
$flag_target_arch = '-target'
|
||||
$flag_wall = '-Wall'
|
||||
$flag_warning = '-W'
|
||||
$flag_warning_as_error = '-Werror'
|
||||
$flag_win_nologo = '/nologo'
|
||||
|
||||
$ignore_warning_ms_include = 'no-microsoft-include'
|
||||
|
||||
$target_arch = Get-TargetArchClang
|
||||
|
||||
$warning_ignores = @(
|
||||
$ignore_warning_ms_include
|
||||
)
|
||||
|
||||
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
|
||||
$libraries = @(
|
||||
'Kernel32' # For Windows API
|
||||
# 'msvcrt', # For the C Runtime (Dynamically Linked)
|
||||
# 'libucrt',
|
||||
'libcmt' # For the C Runtime (Static Linkage)
|
||||
)
|
||||
|
||||
function build-simple
|
||||
{
|
||||
param( $includes, $unit, $executable )
|
||||
Write-Host "build-simple: clang"
|
||||
|
||||
$object = $executable -replace '\.exe', '.obj'
|
||||
$pdb = $executable -replace '\.exe', '.pdb'
|
||||
|
||||
$compiler_args = @(
|
||||
$flag_no_color_diagnostics,
|
||||
$flag_target_arch, $target_arch,
|
||||
$flag_wall,
|
||||
$flag_preprocess_non_intergrated,
|
||||
( $flag_define + 'GEN_TIME' ),
|
||||
( $flag_path_output + $object ),
|
||||
( $flag_include + $includes )
|
||||
)
|
||||
if ( $release -eq $false ) {
|
||||
$compiler_args += ( $flag_define + 'Build_Debug' )
|
||||
$compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug
|
||||
$compiler_args += $flag_no_optimization
|
||||
}
|
||||
|
||||
$warning_ignores | ForEach-Object {
|
||||
$compiler_args += $flag_warning + $_
|
||||
}
|
||||
|
||||
# $compiler_args += $flag_preprocess
|
||||
|
||||
$compiler_args += $flag_compile, $unit
|
||||
run-compiler $compiler $unit $compiler_args
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console,
|
||||
$flag_link_win_machine_64,
|
||||
$( $flag_link_win_path_output + $executable )
|
||||
)
|
||||
if ( $release -eq $false ) {
|
||||
$linker_args += $flag_link_win_debug
|
||||
$linker_args += $flag_link_win_pdb + $pdb
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
$libraries | ForEach-Object {
|
||||
$linker_args += $_ + '.lib'
|
||||
}
|
||||
|
||||
$linker_args += $object
|
||||
run-linker $linker $executable $linker_args
|
||||
}
|
||||
|
||||
$compiler = 'clang++'
|
||||
$linker = 'lld-link'
|
||||
}
|
||||
|
||||
if ( $vendor -match "msvc" )
|
||||
{
|
||||
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
|
||||
$flag_compile = '/c'
|
||||
$flag_debug = '/Zi'
|
||||
$flag_define = '/D'
|
||||
$flag_include = '/I'
|
||||
$flag_full_src_path = '/FC'
|
||||
$flag_nologo = '/nologo'
|
||||
$flag_dll = '/LD'
|
||||
$flag_dll_debug = '/LDd'
|
||||
$flag_linker = '/link'
|
||||
$flag_link_debug = '/DEBUG'
|
||||
$flag_link_pdb = '/PDB:'
|
||||
$flag_link_machine_32 = '/MACHINE:X86'
|
||||
$flag_link_machine_64 = '/MACHINE:X64'
|
||||
$flag_link_path_output = '/OUT:'
|
||||
$flag_link_rt_dll = '/MD'
|
||||
$flag_link_rt_dll_debug = '/MDd'
|
||||
$flag_link_rt_static = '/MT'
|
||||
$flag_link_rt_static_debug = '/MTd'
|
||||
$flag_link_subsystem_console = '/SUBSYSTEM:CONSOLE'
|
||||
$flag_link_subsystem_windows = '/SUBSYSTEM:WINDOWS'
|
||||
$flag_no_optimization = '/Od'
|
||||
$flag_out_name = '/OUT:'
|
||||
$flag_path_interm = '/Fo'
|
||||
$flag_path_debug = '/Fd'
|
||||
$flag_path_output = '/Fe'
|
||||
$flag_preprocess_conform = '/Zc:preprocessor'
|
||||
|
||||
# This works because this project uses a single unit to build
|
||||
function build-simple
|
||||
{
|
||||
param( $includes, $unit, $executable )
|
||||
Write-Host "build-simple: msvc"
|
||||
|
||||
$object = $executable -replace '\.exe', '.obj'
|
||||
$pdb = $executable -replace '\.exe', '.pdb'
|
||||
|
||||
$compiler_args = @(
|
||||
$flag_nologo,
|
||||
$flag_preprocess_conform,
|
||||
$flag_debug,
|
||||
( $flag_define + 'GEN_TIME' ),
|
||||
$flag_full_src_path,
|
||||
( $flag_path_interm + $path_build + '\' ),
|
||||
( $flag_path_output + $path_build + '\' )
|
||||
)
|
||||
if ( $release -eq $false ) {
|
||||
$compiler_args += ( $flag_define + 'Build_Debug' )
|
||||
$compiler_args += ( $flag_path_debug + $path_build + '\' )
|
||||
$compiler_args += $flag_link_rt_static_debug
|
||||
$compiler_args += $flag_no_optimization
|
||||
}
|
||||
else {
|
||||
$compiler_args += $flag_link_rt_static
|
||||
}
|
||||
$compiler_args += $includes | ForEach-Object { $flag_include + $_ }
|
||||
$compiler_args += $flag_compile, $unit
|
||||
run-compiler $compiler $unit $compiler_args
|
||||
|
||||
$linker_args = @(
|
||||
$flag_nologo,
|
||||
$flag_link_machine_64,
|
||||
$flag_link_subsystem_console,
|
||||
( $flag_link_path_output + $executable )
|
||||
)
|
||||
if ( $release -eq $false ) {
|
||||
$linker_args += $flag_link_debug
|
||||
$linker_args += $flag_link_pdb + $pdb
|
||||
}
|
||||
else {
|
||||
}
|
||||
|
||||
$linker_args += $object
|
||||
run-linker $linker $executable $linker_args
|
||||
}
|
||||
|
||||
$compiler = 'cl'
|
||||
$linker = 'link'
|
||||
}
|
||||
#endregion Configuration
|
||||
|
||||
#region Building
|
||||
$path_build = Join-Path $path_root build
|
||||
$path_project = Join-Path $path_root project
|
||||
$path_scripts = Join-Path $path_root scripts
|
||||
$path_singleheader = Join-Path $path_root singleheader
|
||||
$path_test = Join-Path $path_root test
|
||||
|
||||
if ( $bootstrap )
|
||||
{
|
||||
$path_build = join-path $path_project build
|
||||
$path_gen = join-path $path_project gen
|
||||
$path_comp_gen = join-path $path_project components/gen
|
||||
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
if ( -not(Test-Path($path_comp_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_comp_gen
|
||||
}
|
||||
|
||||
$includes = @( $path_project)
|
||||
$unit = join-path $path_project "bootstrap.cpp"
|
||||
$executable = join-path $path_build "bootstrap.exe"
|
||||
|
||||
build-simple $includes $unit $executable
|
||||
|
||||
Push-Location $path_project
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning bootstrap"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if ( $singleheader )
|
||||
{
|
||||
$path_build = join-path $path_singleheader build
|
||||
$path_gen = join-path $path_singleheader gen
|
||||
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$includes = @( $path_project )
|
||||
$unit = join-path $path_singleheader "singleheader.cpp"
|
||||
$executable = join-path $path_build "singleheader.exe"
|
||||
|
||||
build-simple $includes $unit $executable
|
||||
|
||||
Push-Location $path_singleheader
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning singleheader generator"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if ( $test )
|
||||
{
|
||||
$path_gen = join-path $path_test gen
|
||||
$path_gen_build = join-path $path_gen build
|
||||
$path_build = join-path $path_test build
|
||||
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
if ( -not(Test-Path($path_gen_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen_build
|
||||
}
|
||||
|
||||
$path_bootstrap = join-path $path_project gen
|
||||
|
||||
$includes = @( $path_bootstrap )
|
||||
$unit = join-path $path_test "test.cpp"
|
||||
$executable = join-path $path_build "test.exe"
|
||||
|
||||
build-simple $includes $unit $executable
|
||||
|
||||
Push-Location $path_test
|
||||
Write-Host $path_test
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning test generator"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nTest generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
#endregion Building
|
||||
|
||||
#region Formatting
|
||||
function format-cpp
|
||||
{
|
||||
param( $path, $include, $exclude )
|
||||
|
||||
# Format generated gencpp
|
||||
Write-Host "`nBeginning format"
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:./scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
$targetFiles = @(
|
||||
Get-ChildItem -Recurse -Path $path -Include $include -Exclude $exclude
|
||||
| Select-Object -ExpandProperty FullName
|
||||
)
|
||||
|
||||
$time_taken = Measure-Command {
|
||||
clang-format $formatParams $targetFiles
|
||||
}
|
||||
Write-Host "`nFormatting complete in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
|
||||
if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
|
||||
{
|
||||
$path_gen = join-path $path_project gen
|
||||
$path_comp_gen = join-path $path_project components/gen
|
||||
$include = @(
|
||||
'gen.hpp', 'gen.cpp',
|
||||
'gen.dep.hpp', 'gen.dep.cpp',
|
||||
'gen.builder.hpp', 'gen.builder.cpp'
|
||||
'gen.scanner.hpp', 'gen.scanner.cpp'
|
||||
)
|
||||
$exclude = $null
|
||||
format-cpp $path_gen $include $exclude
|
||||
format-cpp $path_comp_gen @( 'ast_inlines.hpp', 'ecode.hpp', 'especifier.hpp', 'eoperator.hpp', 'etoktype.cpp' ) $null
|
||||
}
|
||||
|
||||
if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) )
|
||||
{
|
||||
$path_gen = join-path $path_singleheader gen
|
||||
$include = @(
|
||||
'gen.hpp'
|
||||
)
|
||||
$exclude = $null
|
||||
format-cpp $path_gen $include $exclude
|
||||
}
|
||||
|
||||
if ( $test -and $false )
|
||||
{
|
||||
$path_gen = join-path $path_test gen
|
||||
$include = @(
|
||||
'*.gen.hpp'
|
||||
)
|
||||
$exclude = $null
|
||||
format-cpp $path_gen $include $exclude
|
||||
}
|
||||
#endregion Formatting
|
||||
|
||||
Pop-Location # $path_root
|
3
scripts/build.ps1
Normal file
3
scripts/build.ps1
Normal file
@ -0,0 +1,3 @@
|
||||
cls
|
||||
$build = Join-Path $PSScriptRoot 'build.ci.ps1'
|
||||
& $build @args
|
@ -7,9 +7,9 @@ $path_singleheader_build = Join-Path $path_singleheader build
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_test = Join-Path $path_root test
|
||||
$path_test_build = Join-Path $path_test build
|
||||
$path_gen = Join-Path $path_test gen
|
||||
$path_gen_build = Join-Path $path_gen build
|
||||
$path_test_gen = Join-Path $path_test gen
|
||||
$path_x64 = Join-Path $path_root x64
|
||||
$path_release = Join-Path $path_root release
|
||||
|
||||
if ( Test-Path $path_project_build)
|
||||
{
|
||||
@ -36,9 +36,9 @@ if ( Test-Path $path_test_build )
|
||||
Remove-Item $path_test_build -Recurse
|
||||
}
|
||||
|
||||
if ( Test-Path $path_gen_build )
|
||||
if ( Test-Path $path_test_gen )
|
||||
{
|
||||
Remove-Item $path_gen_build -Recurse
|
||||
Remove-Item $path_test_gen -Recurse
|
||||
}
|
||||
|
||||
if ( Test-Path $path_x64)
|
||||
@ -46,22 +46,10 @@ if ( Test-Path $path_x64)
|
||||
Remove-Item $path_x64 -Recurse
|
||||
}
|
||||
|
||||
# [string[]] $include = 'gen.hpp', 'gen.cpp', 'gen_dep.hpp', 'gen_dep.cpp'
|
||||
# [string[]] $exclude =
|
||||
|
||||
# $files = Get-ChildItem -Recurse -Path $path_project_gen -Include $include -Exclude $exclude
|
||||
|
||||
# if ( $files )
|
||||
# {
|
||||
# Remove-Item $files
|
||||
# }
|
||||
|
||||
# $files = Get-ChildItem -Recurse -Path $path_singleheader_gen -Include $include -Exclude $exclude
|
||||
|
||||
# if ( $files )
|
||||
# {
|
||||
# Remove-Item $files
|
||||
# }
|
||||
if ( Test-Path $path_release )
|
||||
{
|
||||
Remove-Item $path_release -Recurse
|
||||
}
|
||||
|
||||
$include = '*.h', '*.hpp', '*.cpp'
|
||||
$exclude =
|
||||
|
@ -48,8 +48,8 @@
|
||||
<DisplayString>{(Header*)((char*)Data - sizeof(Header))}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="Allocator">((Header*)((char*)Data - sizeof(Header)))->Allocator</Item>
|
||||
<Item Name="Length">((Header*)((char*)Data - sizeof(Header)))->Length</Item>
|
||||
<Item Name="Capacity">((Header*)((char*)Data - sizeof(Header)))->Capacity</Item>
|
||||
<Item Name="Length">((Header*)((char*)Data - sizeof(Header)))->Length</Item>
|
||||
</Expand>
|
||||
</Synthetic>
|
||||
</Expand>
|
||||
|
@ -21,8 +21,8 @@
|
||||
// Gen Macro namespace
|
||||
// namespace GEN_, new_namespace_
|
||||
|
||||
// ---------- ZPL Macros
|
||||
|
||||
// ---------- Dependency Macros
|
||||
// Platform
|
||||
// word GEN_ARCH_64_BIT, new_name
|
||||
// word GEN_ARCH_32_BIT, new_name
|
||||
|
||||
@ -43,20 +43,86 @@
|
||||
// word GEN_COMPILER_MINGW, new_name
|
||||
// word GEN_COMPILER_MSVC, new_name
|
||||
|
||||
// word forceinline, new_name
|
||||
// word neverinline, new_name
|
||||
|
||||
// General
|
||||
// word zpl_cast, new_name
|
||||
|
||||
// word global, new_name
|
||||
// word internal, new_name
|
||||
// word local_persist, new_name
|
||||
// word forceinline, new_name
|
||||
// word neverinline, new_name
|
||||
|
||||
// word bit, new_name
|
||||
// word bitfield_is_equal, new_name
|
||||
|
||||
// word ccast, new_name
|
||||
// word pcast, new_name
|
||||
// word rcast, new_name
|
||||
// word scast, new_name
|
||||
|
||||
// word num_args, new_name
|
||||
// word num_args_impl, new_name
|
||||
|
||||
// word stringize, new_name
|
||||
// word stringize_va, new_name
|
||||
|
||||
// word do_once, new_name
|
||||
// word do_once_start, new_name
|
||||
// word do_once_end, new_name
|
||||
// word label_scope_start, new_name
|
||||
// word label_scope_end, new_name
|
||||
|
||||
// word count_of, new_name
|
||||
// word is_between, new_name
|
||||
// word min, new_name
|
||||
// word size_of, new_name
|
||||
// word offset_of, new_name
|
||||
// word swap, new_name
|
||||
|
||||
// Basic Types
|
||||
// word GEN_U8_MIN, new_name
|
||||
// word GEN_U8_MAX, new_name
|
||||
// word GEN_I8_MIN, new_name
|
||||
// word GEN_I8_MAX, new_name
|
||||
|
||||
// word GEN_U16_MIN, new_name
|
||||
// word GEN_U16_MAX, new_name
|
||||
// word GEN_I16_MIN, new_name
|
||||
// word GEN_I16_MAX, new_name
|
||||
|
||||
// word GEN_U32_MIN, new_name
|
||||
// word GEN_U32_MAX, new_name
|
||||
// word GEN_I32_MIN, new_name
|
||||
// word GEN_I32_MAX, new_name
|
||||
|
||||
// word GEN_U64_MIN, new_name
|
||||
// word GEN_U64_MAX, new_name
|
||||
// word GEN_I64_MIN, new_name
|
||||
// word GEN_I64_MAX, new_name
|
||||
|
||||
// word GEN_USIZE_MIN, new_name
|
||||
// word GEN_USIZE_MAX, new_name
|
||||
// word GEN_ISIZE_MIN, new_name
|
||||
// word GEN_ISIZE_MAX, new_name
|
||||
|
||||
// word GEN_F32_MIN, new_name
|
||||
// word GEN_F32_MAX, new_name
|
||||
// word GEN_F64_MIN, new_name
|
||||
// word GEN_F64_MAX, new_name
|
||||
|
||||
// Debug
|
||||
// word GEN_DEBUG_TRAP, new_name
|
||||
// word GEN_ASSERT, new_name
|
||||
// word GEN_ASSERT_MSG, new_name
|
||||
// word GEN_ASSERT_NOT_NULL, new_name
|
||||
// word GEN_PANIC, new_name
|
||||
// word GEN_FATAL, new_name
|
||||
|
||||
// Memory
|
||||
// word kilobytes, new_name
|
||||
// word megabytes, new_name
|
||||
// word gigabytes, new_name
|
||||
// word terabytes, new_name
|
||||
|
||||
// word zero_item, new_name
|
||||
// word zero_array, new_name
|
||||
@ -67,13 +133,11 @@
|
||||
// word malloc, new_name
|
||||
// word mfree, new_name
|
||||
|
||||
// word count_of, new_name
|
||||
// word is_between, new_name
|
||||
// word min, new_name
|
||||
// word size_of, new_name
|
||||
// word swap, new_name
|
||||
// Strings
|
||||
// word txt, new_name
|
||||
// word cast_to_strc, new_name
|
||||
|
||||
// ---------- ZPL Types
|
||||
// ---------- Dependency Types
|
||||
|
||||
// word b8, new_name
|
||||
// word b16, new_name
|
||||
@ -114,11 +178,11 @@
|
||||
// word FileStandardType, new_name
|
||||
// word SeekWhenceType, new_name
|
||||
|
||||
// ---------- ZPL Data
|
||||
// ---------- Dependency Data
|
||||
|
||||
// word default_file_operations, new_name
|
||||
|
||||
// ---------- ZPL Procedures
|
||||
// ---------- Dependency Procedures
|
||||
|
||||
// word align_forward, new_name
|
||||
// word align_fordward_i64, new_name
|
||||
@ -158,6 +222,7 @@
|
||||
// word hex_digit_to_int, new_name
|
||||
// word i64_to_str, new_name
|
||||
// word is_power_of_two, new_name
|
||||
// word log_fmt, new_name
|
||||
// word mem_copy, new_name
|
||||
// word mem_move, new_name
|
||||
// word mem_set, new_name
|
||||
@ -189,22 +254,10 @@
|
||||
|
||||
// ---------- gencpp Macros
|
||||
|
||||
// word bit, new_name
|
||||
// word bitfield_is_equal, new_name
|
||||
// word log_failure, new_name
|
||||
|
||||
// word ccast, new_name
|
||||
// word pcast, new_name
|
||||
// word rcast, new_name
|
||||
// word scast, new_name
|
||||
|
||||
// word do_once, new_name
|
||||
// word do_once_start, new_name
|
||||
// word do_once_end, new_name
|
||||
// word num_args, new_name
|
||||
// word num_args_impl, new_name
|
||||
// word stringize, new_name
|
||||
// word stringize_va, new_name
|
||||
// word txt_StrC, new_name
|
||||
// word NoCode, new_name
|
||||
// word CodeInvalid, new_name
|
||||
|
||||
// ------------ gencpp common
|
||||
|
||||
@ -215,16 +268,13 @@
|
||||
// word StrC, new_name
|
||||
// word String, new_name
|
||||
|
||||
// word log_fmt, new_name
|
||||
// word fatal, new_name
|
||||
// word to_str, new_name
|
||||
// word to_StrC, new_name
|
||||
// word to_type, new_name
|
||||
// word to_str, new_name
|
||||
// word to_str, new_name
|
||||
// word to_type, new_name
|
||||
|
||||
// ------------ gencpp Types & Constants
|
||||
|
||||
// word LogFailType, new_name
|
||||
// word log_failure, new_name
|
||||
|
||||
// word AccessSpec, new_name
|
||||
// word ECode, new_name
|
||||
@ -251,7 +301,6 @@
|
||||
// word Code, new_name
|
||||
// word Code_POD, new_name
|
||||
// word Keyword, new_name
|
||||
// word NoCode, new_name
|
||||
|
||||
// ------------ gencpp API
|
||||
|
||||
@ -277,6 +326,9 @@
|
||||
// word def_attributes, new_name
|
||||
// word def_comment, new_name
|
||||
// word def_class, new_name
|
||||
// word def_constructor, new_name
|
||||
// word def_destructor, new_name
|
||||
// word def_define, new_name
|
||||
// word def_enum, new_name
|
||||
// word def_execution, new_name
|
||||
// word def_extern_link, new_name
|
||||
@ -286,7 +338,10 @@
|
||||
// word def_module, new_name
|
||||
// word def_namespace, new_name
|
||||
// word def_operator, new_name
|
||||
// word def_operator_cast, new_name
|
||||
// word def_param, new_name
|
||||
// word def_pargma, new_name
|
||||
// word def_preprocess_cond, new_name
|
||||
// word def_specifier, new_name
|
||||
// word def_struct, new_name
|
||||
// word def_template, new_name
|
||||
@ -343,22 +398,24 @@
|
||||
// word untyped_fmt, new_name
|
||||
// word untyped_token_fmt, new_name
|
||||
|
||||
// ------------ File Handling
|
||||
// ------------ File Ops
|
||||
|
||||
// word Builder, new_name
|
||||
// word Editor, new_name
|
||||
// word Scanner, new_name
|
||||
|
||||
// ------------ gencpp macros
|
||||
// ------------ gencpp user macros
|
||||
|
||||
// word gen_main, new_name
|
||||
// word GEN_TIME, new_name
|
||||
|
||||
// word __, new_name
|
||||
// word code, new_name
|
||||
// word name, new_name
|
||||
// word args, new_name
|
||||
// word token_fmt, new_name
|
||||
// word __, new_name
|
||||
// word name, new_name
|
||||
// word code, new_name
|
||||
// word args, new_name
|
||||
// word code_str, new_name
|
||||
// word code_fmt, new_name
|
||||
// word token_fmt, new_name
|
||||
|
||||
// ------------ Type AST namespace
|
||||
// namespace t_, new_namespace_
|
||||
|
@ -1,3 +1,7 @@
|
||||
if ($env:VCINSTALLDIR) {
|
||||
return
|
||||
}
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# Use vswhere to find the latest Visual Studio installation
|
25
scripts/helpers/target_arch.psm1
Normal file
25
scripts/helpers/target_arch.psm1
Normal file
@ -0,0 +1,25 @@
|
||||
# target_arch.psm1
|
||||
|
||||
function Get-TargetArchClang {
|
||||
# Get the target architecture by querying clang itself
|
||||
$output = & clang -v 2>&1
|
||||
foreach ($line in $output) {
|
||||
if ($line -like "*Target:*") {
|
||||
$clangTarget = ($line -split ':')[1].Trim()
|
||||
return $clangTarget
|
||||
}
|
||||
}
|
||||
throw "Clang target architecture could not be determined."
|
||||
}
|
||||
|
||||
function Get-TargetArchMSVC {
|
||||
# Assuming you've set the Visual Studio environment variables using `vcvarsall.bat`
|
||||
# This looks for the `VSCMD_ARG_TGT_ARCH` environment variable which Visual Studio sets to indicate the target architecture.
|
||||
$arch = $env:VSCMD_ARG_TGT_ARCH
|
||||
if (-not $arch) {
|
||||
throw "MSVC target architecture could not be determined. Ensure you've initialized the Visual Studio environment."
|
||||
}
|
||||
return $arch
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Get-TargetArchClang, Get-TargetArchMSVC
|
@ -1,16 +0,0 @@
|
||||
cls
|
||||
|
||||
if ( -not( Test-Path $path_build ) ) {
|
||||
New-Item -ItemType Directory -Path $path_build | Out-Null
|
||||
}
|
||||
if ( -not( Test-Path $path_build_interm ) ) {
|
||||
New-Item -ItemType Directory -Path $path_build_interm | Out-Null
|
||||
}
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_build = Join-Path $path_root build
|
||||
$path_gen = Join-Path $path_test gen
|
||||
$path_gen_build = Join-Path $path_gen build
|
||||
$path_scripts = Join-Path $path_root scripts
|
||||
$path_test = Join-Path $path_root test
|
||||
$path_test_build = Join-Path $path_test build
|
48
scripts/package_release.ps1
Normal file
48
scripts/package_release.ps1
Normal file
@ -0,0 +1,48 @@
|
||||
cls
|
||||
|
||||
$build = Join-Path $PSScriptRoot 'build.ci.ps1'
|
||||
|
||||
if ( $IsWindows ) {
|
||||
& $build release msvc bootstrap singleheader
|
||||
}
|
||||
else {
|
||||
& $build release clang bootstrap singleheader
|
||||
}
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_docs = Join-Path $path_root docs
|
||||
$path_project = Join-Path $path_root project
|
||||
$path_project_gen = Join-Path $path_project gen
|
||||
$path_singleheader = Join-Path $path_root singleheader
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_release = Join-Path $path_root release
|
||||
$path_release_content = Join-Path $path_release content
|
||||
|
||||
if ( -not(Test-Path $path_release) ) {
|
||||
New-Item -ItemType Directory -Path $path_release
|
||||
}
|
||||
|
||||
if ( -not(Test-Path $path_release_content) ) {
|
||||
New-Item -ItemType Directory -Path $path_release_content
|
||||
}
|
||||
|
||||
$license = Join-Path $path_root LICENSE
|
||||
$readme_root = Join-Path $path_root Readme.md
|
||||
$readme_docs = Join-Path $path_docs Readme.md
|
||||
$readme_parsing = Join-Path $path_docs Parsing.md
|
||||
|
||||
Copy-Item $license -Destination (Join-Path $path_release_content "LICENSE")
|
||||
Copy-Item $readme_root -Destination (Join-Path $path_release_content "Readme.md")
|
||||
Copy-Item $readme_docs -Destination (Join-Path $path_release_content "Readme_Docs.md")
|
||||
Copy-Item $readme_parsing -Destination (Join-Path $path_release_content "Parsing.md")
|
||||
|
||||
# Singleheader
|
||||
Copy-Item -Path $path_singleheader_gen\gen.hpp -Destination $path_release_content\gen.hpp
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_singleheader.zip -Force
|
||||
Remove-Item -Path $path_release_content\gen.hpp
|
||||
|
||||
# Segmented
|
||||
Copy-Item -Path $path_project_gen\* -Destination $path_release_content
|
||||
Compress-Archive -Path $path_release_content\* -DestinationPath $path_release\gencpp_segmented.zip -Force
|
||||
|
||||
Remove-Item -Path $path_release_content -Recurse
|
@ -1,73 +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_singleheader = Join-Path $path_root singleheader
|
||||
$path_singleheader_build = Join-Path $path_singleheader build
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
|
||||
write-host "`n`nBuilding gencpp singleheader`n"
|
||||
|
||||
if ( -not( Test-Path $path_singleheader_build) )
|
||||
{
|
||||
# Generate build files for meta-program
|
||||
Push-Location $path_singleheader
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
$args_meson += $path_singleheader_build
|
||||
|
||||
& meson $args_meson
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Compile meta-program
|
||||
Push-Location $path_root
|
||||
$args_ninja = @()
|
||||
$args_ninja += "-C"
|
||||
$args_ninja += $path_singleheader_build
|
||||
|
||||
& ninja $args_ninja
|
||||
Pop-Location
|
||||
|
||||
Push-location $path_singleheader
|
||||
if ( -not(Test-Path($path_singleheader_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_singleheader_gen
|
||||
}
|
||||
|
||||
# Run meta-program
|
||||
$gencpp_singleheader = Join-Path $path_singleheader_build gencpp_singleheader.exe
|
||||
|
||||
Write-Host `nRunning gencpp singleheader...
|
||||
& $gencpp_singleheader
|
||||
|
||||
# Format generated files
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
'-style=file:../scripts/.clang-format'
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
$include = @('gen.hpp')
|
||||
$exclude = $null
|
||||
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_project -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
Pop-Location
|
||||
|
||||
# Build and run validation
|
||||
|
@ -1,2 +0,0 @@
|
||||
cls
|
||||
Invoke-Expression "& $(Join-Path $PSScriptRoot 'singleheader.ci.ps1') $args"
|
@ -1,45 +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_build = Join-Path $path_root build
|
||||
$path_scripts = Join-Path $path_root scripts
|
||||
$path_test = Join-Path $path_root test
|
||||
$path_gen = Join-Path $path_test gen
|
||||
$path_test_build = Join-Path $path_test build
|
||||
$path_gen_build = Join-Path $path_gen build
|
||||
|
||||
write-host "`n`nBuilding Test`n"
|
||||
|
||||
if ( -not( Test-Path $path_gen_build ) )
|
||||
{
|
||||
# Generate build files for meta-program
|
||||
Push-Location $path_gen
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
$args_meson += $path_gen_build
|
||||
|
||||
& meson $args_meson
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Compile meta-program
|
||||
Push-Location $path_root
|
||||
$args_ninja = @()
|
||||
$args_ninja += "-C"
|
||||
$args_ninja += $path_gen_build
|
||||
|
||||
& ninja $args_ninja
|
||||
Pop-Location
|
@ -1,2 +0,0 @@
|
||||
cls
|
||||
Invoke-Expression "& $(Join-Path $PSScriptRoot 'test.gen_build.ci.ps1') $args"
|
@ -1,99 +0,0 @@
|
||||
cls
|
||||
|
||||
[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_build = Join-Path $path_root build
|
||||
$path_scripts = Join-Path $path_root scripts
|
||||
$path_test = Join-Path $path_root test
|
||||
$path_gen = Join-Path $path_test gen
|
||||
$path_test_build = Join-Path $path_test build
|
||||
$path_gen_build = Join-Path $path_gen build
|
||||
|
||||
write-host "`n`nBuilding Test`n"
|
||||
|
||||
if ( -not( Test-Path $path_gen_build ) )
|
||||
{
|
||||
# Generate build files for meta-program
|
||||
Push-Location $path_gen
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
$args_meson += $path_gen_build
|
||||
|
||||
& meson $args_meson
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Compile meta-program
|
||||
Push-Location $path_root
|
||||
$args_ninja = @()
|
||||
$args_ninja += "-C"
|
||||
$args_ninja += $path_gen_build
|
||||
|
||||
& ninja $args_ninja
|
||||
Pop-Location
|
||||
|
||||
Push-location $path_gen
|
||||
# Run meta-program
|
||||
$gencpp = Join-Path $path_gen_build gencpp.exe
|
||||
|
||||
Write-Host `nRunning tests...
|
||||
& $gencpp
|
||||
|
||||
# Format generated files
|
||||
$path_clang_format = Join-Path $path_scripts .clang-format
|
||||
|
||||
Write-Host `nBeginning format...
|
||||
$formatParams = @(
|
||||
'-i' # In-place
|
||||
"-style=file:$path_clang_format" # Search for a .clang-format file in the parent directory of the source file.
|
||||
'-verbose'
|
||||
)
|
||||
|
||||
$include = @('*.gen.hpp', '*.gen.cpp')
|
||||
$exclude = $null
|
||||
|
||||
$targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
|
||||
|
||||
clang-format $formatParams $targetFiles
|
||||
Write-Host "`nFormatting complete"
|
||||
Pop-Location
|
||||
|
||||
# Build the program depending on generated files.
|
||||
if ( -not( Test-Path $path_test_build ) )
|
||||
{
|
||||
Push-Location $path_test
|
||||
$args_meson = @()
|
||||
$args_meson += "setup"
|
||||
$args_meson += $path_test_build
|
||||
|
||||
# & meson $args_meson
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Push-Location $path_root
|
||||
$args_ninja = @()
|
||||
$args_ninja += "-C"
|
||||
$args_ninja += $path_test_build
|
||||
|
||||
# ninja $args_ninja
|
||||
Pop-Location
|
||||
|
||||
Push-Location $path_test
|
||||
$testcpp = Join-Path $path_test_build testcpp.exe
|
||||
|
||||
# & $testcpp
|
||||
Pop-Location
|
@ -1,6 +1,4 @@
|
||||
# Singleheader
|
||||
|
||||
`gen.singleheader.cpp` with its own `meson.build` generates the library as a single header `gen.hpp`.
|
||||
Following the same convention seen in the gb, stb, and zpl libraries.
|
||||
|
||||
( Currently WIP )
|
||||
Creates a single header file version of the library using `gen.singleheader.cpp`.
|
||||
Follows the same convention seen in the gb, stb, and zpl libraries.
|
||||
|
@ -1,18 +0,0 @@
|
||||
project( 'gencpp_singleheader', 'c', 'cpp', default_options : ['buildtype=debug'] )
|
||||
|
||||
includes = include_directories(
|
||||
[
|
||||
'../project',
|
||||
])
|
||||
|
||||
sources = [ 'gen.singleheader.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_singleheader', sources, include_directories : includes )
|
@ -3,41 +3,42 @@
|
||||
#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 "file_processors/builder.hpp"
|
||||
#include "file_processors/builder.cpp"
|
||||
#include "file_processors/scanner.hpp"
|
||||
#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 gen.bootstrap.cpp "
|
||||
"// This file was generated automatially by gencpp's singleheader.cpp"
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
constexpr StrC implementation_guard_start = txt_StrC(R"(
|
||||
constexpr StrC implementation_guard_start = txt(R"(
|
||||
#pragma region GENCPP IMPLEMENTATION GUARD
|
||||
#if defined(GEN_IMPLEMENTATION) && ! defined(GEN_IMPLEMENTED)
|
||||
# define GEN_IMPLEMENTED
|
||||
)");
|
||||
|
||||
constexpr StrC implementation_guard_end = txt_StrC(R"(
|
||||
constexpr StrC implementation_guard_end = txt(R"(
|
||||
#endif
|
||||
#pragma endregion GENCPP IMPLEMENTATION GUARD
|
||||
)");
|
||||
|
||||
constexpr StrC roll_own_dependencies_guard_start = txt_StrC(R"(
|
||||
constexpr StrC roll_own_dependencies_guard_start = txt(R"(
|
||||
//! 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
|
||||
|
||||
)");
|
||||
|
||||
constexpr StrC roll_own_dependencies_guard_end = txt_StrC(R"(
|
||||
constexpr StrC roll_own_dependencies_guard_end = txt(R"(
|
||||
// GEN_ROLL_OWN_DEPENDENCIES
|
||||
#endif
|
||||
)");
|
||||
@ -68,22 +69,22 @@ int gen_main()
|
||||
|
||||
if ( generate_gen_dep )
|
||||
{
|
||||
Code header_start = scan_file( project_dir "dependencies/header_start.hpp" );
|
||||
Code macros = scan_file( project_dir "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( project_dir "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
Code string = scan_file( project_dir "dependencies/string.hpp" );
|
||||
Code file_handling = scan_file( project_dir "dependencies/file_handling.hpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
Code header_start = scan_file( project_dir "dependencies/header_start.hpp" );
|
||||
Code macros = scan_file( project_dir "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( project_dir "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( project_dir "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.hpp" );
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print( header_start );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n" );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( macros );
|
||||
header.print( basic_types );
|
||||
@ -93,19 +94,20 @@ int gen_main()
|
||||
header.print( printing );
|
||||
header.print( containers );
|
||||
header.print( hashing );
|
||||
header.print( string );
|
||||
header.print( file_handling );
|
||||
header.print( strings );
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "#pragma region Parsing\n\n" );
|
||||
header.print_fmt( "\n#pragma region Parsing\n" );
|
||||
header.print( scan_file( project_dir "dependencies/parsing.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
||||
}
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
header.print_fmt( roll_own_dependencies_guard_end );
|
||||
header.print( fmt_newline );
|
||||
}
|
||||
|
||||
Code types = scan_file( project_dir "components/types.hpp" );
|
||||
@ -122,39 +124,32 @@ int gen_main()
|
||||
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n" );
|
||||
|
||||
header.print_fmt("#pragma region Types\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\n");
|
||||
header.print_fmt("#pragma region AST\n");
|
||||
header.print( ast );
|
||||
header.print( ast_types );
|
||||
header.print_fmt("#pragma endregion AST\n\n");
|
||||
header.print_fmt("\n#pragma endregion AST\n");
|
||||
|
||||
header.print( interface );
|
||||
|
||||
header.print_fmt( "#pragma region Inlines\n\n" );
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( ast_inlines );
|
||||
header.print_fmt( "#pragma endregion Inlines\n\n" );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
|
||||
if ( generate_builder )
|
||||
{
|
||||
header.print_fmt( "#pragma region Builder\n\n" );
|
||||
header.print( scan_file( project_dir "file_processors/builder.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Builder\n\n" );
|
||||
}
|
||||
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "#pragma region Scanner\n\n" );
|
||||
header.print( scan_file( project_dir "file_processors/scanner.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
||||
header.print_fmt( "\n#pragma region Builder\n" );
|
||||
header.print( scan_file( project_dir "auxillary/builder.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Builder\n" );
|
||||
}
|
||||
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
@ -166,15 +161,15 @@ int gen_main()
|
||||
|
||||
if ( generate_gen_dep )
|
||||
{
|
||||
Code impl_start = scan_file( project_dir "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code string = scan_file( project_dir "dependencies/string.cpp" );
|
||||
Code file_handling = scan_file( project_dir "dependencies/file_handling.cpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
Code impl_start = scan_file( project_dir "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( project_dir "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( project_dir "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( project_dir "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( project_dir "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( project_dir "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( project_dir "dependencies/timing.cpp" );
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
@ -185,14 +180,14 @@ int gen_main()
|
||||
header.print( printing );
|
||||
header.print( memory );
|
||||
header.print( hashing );
|
||||
header.print( string );
|
||||
header.print( file_handling );
|
||||
header.print( strings );
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "#pragma region Parsing\n\n" );
|
||||
header.print( scan_file( project_dir "dependencies/parsing.cpp" ) );
|
||||
header.print_fmt( "\n#pragma region Parsing\n" );
|
||||
header.print( scan_file( project_dir "dependencies/parsing.cpp" ) );
|
||||
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
||||
}
|
||||
|
||||
@ -206,12 +201,12 @@ int gen_main()
|
||||
Code interface = scan_file( project_dir "components/interface.cpp" );
|
||||
Code upfront = scan_file( project_dir "components/interface.upfront.cpp" );
|
||||
Code parsing = scan_file( project_dir "components/interface.parsing.cpp" );
|
||||
Code untyped = scan_file( project_dir "components/untyped.cpp" );
|
||||
Code untyped = scan_file( project_dir "components/interface.untyped.cpp" );
|
||||
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" );
|
||||
CodeNS parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
|
||||
CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" );
|
||||
CodeNS parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
|
||||
|
||||
header.print_fmt( "GEN_NS_BEGIN\n\n");
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
header.print( static_data );
|
||||
|
||||
header.print_fmt( "#pragma region AST\n\n" );
|
||||
@ -219,28 +214,36 @@ int gen_main()
|
||||
header.print( ast );
|
||||
header.print_fmt( "#pragma endregion AST\n\n" );
|
||||
|
||||
header.print_fmt( "#pragma region Interface\n\n" );
|
||||
header.print_fmt( "#pragma region Interface\n" );
|
||||
header.print( interface );
|
||||
header.print( upfront );
|
||||
header.print_fmt( "#pragma region Parsing\n\n" );
|
||||
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
header.print( parser_nspace );
|
||||
header.print( parsing );
|
||||
header.print_fmt( "#pragma endregion Parsing\n\n" );
|
||||
header.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
header.print( untyped );
|
||||
header.print_fmt( "#pragma endregion Interface\n\n");
|
||||
header.print_fmt( "\n#pragma endregion Interface\n\n");
|
||||
|
||||
if ( generate_builder )
|
||||
{
|
||||
header.print_fmt( "#pragma region Builder\n\n" );
|
||||
header.print( scan_file( project_dir "file_processors/builder.cpp" ) );
|
||||
header.print_fmt( "#pragma endregion Builder\n\n" );
|
||||
header.print_fmt( "#pragma region Builder\n" );
|
||||
header.print( scan_file( project_dir "auxillary/builder.cpp" ) );
|
||||
header.print_fmt( "\n#pragma endregion Builder\n\n" );
|
||||
}
|
||||
|
||||
// Scanner header depends on implementation
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "\n#pragma region Scanner\n" );
|
||||
header.print( scan_file( project_dir "auxillary/scanner.hpp" ) );
|
||||
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ( generate_scanner )
|
||||
{
|
||||
header.print_fmt( "#pragma region Scanner\n\n" );
|
||||
header.print( scan_file( project_dir "file_processors/scanner.cpp" ) );
|
||||
header.print( scan_file( project_dir "auxillary/scanner.cpp" ) );
|
||||
header.print_fmt( "#pragma endregion Scanner\n\n" );
|
||||
}
|
||||
#endif
|
35
test/CURSED_TYPEDEF.h
Normal file
35
test/CURSED_TYPEDEF.h
Normal file
@ -0,0 +1,35 @@
|
||||
#include <functional>
|
||||
|
||||
class MyClass;
|
||||
|
||||
enum class MyEnum : short { VAL1, VAL2 };
|
||||
|
||||
struct OuterStruct {
|
||||
union NamedUnion {
|
||||
struct InnerStruct {
|
||||
double d;
|
||||
char c;
|
||||
} inner;
|
||||
int i;
|
||||
} unionInstance;
|
||||
};
|
||||
|
||||
template<typename T, int N = alignof(double)>
|
||||
struct TemplateStruct {
|
||||
T member[N];
|
||||
};
|
||||
|
||||
template<>
|
||||
struct TemplateStruct<int, 10> {
|
||||
int specialMember[10];
|
||||
};
|
||||
|
||||
typedef decltype(nullptr) (MyClass::*InsaneComplexTypeDef)(
|
||||
decltype((MyEnum::VAL1 == MyEnum::VAL2) ? 1 : 2.0)
|
||||
(TemplateStruct<decltype(OuterStruct().unionInstance.inner), 5>::*ptr)[5][alignof(double)],
|
||||
std::function<void *(TemplateStruct<int, 10>&&,
|
||||
void (MyClass::*memFnPtr)(TemplateStruct<decltype(OuterStruct().unionInstance.inner)>))>,
|
||||
int (MyClass::*&refToMemFnPtr)(TemplateStruct<int, 10>),
|
||||
int (TemplateStruct<int, 10>::*memberPointer)[10],
|
||||
char&&...
|
||||
) volatile const && noexcept;
|
13
test/GamePipeline/Readme.md
Normal file
13
test/GamePipeline/Readme.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Test : Eskil Steenberg's Game Pipeline
|
||||
|
||||
***Note: This validation test has not been implemented yet.***
|
||||
|
||||
Repo : https://github.com/valiet/quel_solaar
|
||||
|
||||
This is a AST reconstruction test of the gamepipeline library.
|
||||
|
||||
1. Download the library
|
||||
2. Grab all header and source file paths
|
||||
3. Generate an ast for each file and serialize it to a file called <name of file>.gen.<h/c>
|
||||
4. Reconstruct the ast from the generated file
|
||||
5. Compare the original ast to the reconstructed ast
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user