mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 11:11:46 -07:00
Compare commits
120 Commits
preprocess
...
v0.18-Alph
Author | SHA1 | Date | |
---|---|---|---|
e1592ba410 | |||
4a2a93d41b | |||
36260f6edb | |||
83d691c65c | |||
626ab703a7 | |||
6b10cd2b3e | |||
91a3250d4c | |||
a667eb4afe | |||
f67f9547df | |||
772db608be | |||
be023325a9 | |||
a0ee683f82 | |||
6ad0ae97bc | |||
3319bfcaa9 | |||
9d27c7d37e | |||
5c73fbee83 | |||
36ebbfe29b | |||
053daaf877 | |||
040ec00606 | |||
919166efa1 | |||
9bd6dac783 | |||
212d907d73 | |||
c1ab233686 | |||
b42b224c0d | |||
041671762b | |||
d0f3b6187e | |||
b22f589203 | |||
4af85f8612 | |||
e9c151f85d | |||
a900e86b65 | |||
d5a4b77033 | |||
eaba60f80b | |||
912cc6b538 | |||
3dd5482a46 | |||
632fa10027 | |||
6498b13658 | |||
7f562cd77f | |||
3a0e971ebf | |||
4997cb5878 | |||
729c891cbd | |||
754bcfb31e | |||
a8708abf8b | |||
4b48b96a79 | |||
9495fc2985 | |||
378de73a7d | |||
35ac0c1048 | |||
2c893d5e35 | |||
6ea40094ee | |||
0a8d3bfc6a | |||
212b4e6d16 | |||
d606c790ca | |||
2bfbef1d0c | |||
f1fb75cc1c | |||
2200bcde9a | |||
3e249d9bc5 | |||
3868e1e811 | |||
543427dfe5 | |||
f2d4ec96f0 | |||
1076818250 | |||
c4c308c8ba | |||
a4d9a63d71 | |||
0197afd543 | |||
7249a7317d | |||
abf51e4aa9 | |||
9b6dc3cbd8 | |||
9edcbad907 | |||
a6766cf0b1 | |||
8635b0fd1b | |||
30eec99628 | |||
f9117a2353 | |||
c81f4b34ee | |||
c97762ac16 | |||
5e79e8ba65 | |||
49a2cd7b2c | |||
a6c6574390 | |||
c4846dad26 | |||
a61a28b778 | |||
d0c995893d | |||
a42e241afb | |||
6d85dd8fe8 | |||
db6e8b33eb | |||
7be3617083 | |||
5c47777972 | |||
4a2ed6de4e | |||
9f64760b7a | |||
68f34e6fab | |||
1f9bbddbb7 | |||
050b00f28a | |||
1241f44fd4 | |||
7d1c499e7b | |||
b3f0c2734f | |||
eaeb8acee4 | |||
12bf878cb3 | |||
52ae431ad6 | |||
05fa62eced | |||
2f7836b191 | |||
f574a9ba9a | |||
a6bf60a51e | |||
37d9782cf2 | |||
11679ba8b4 | |||
8985f0a4d9 | |||
32a910515e | |||
aa928ff446 | |||
5aff89262b | |||
b5fa864318 | |||
bb35444be9 | |||
67d02c1f62 | |||
c7647ab00f | |||
d2fc1d0a56 | |||
ed3246c6b0 | |||
c4d5637a64 | |||
c2f8c8aeb1 | |||
c2319b9651 | |||
a4f9596d3b | |||
97750388ad | |||
00f6c45f15 | |||
34f286d218 | |||
d36c3fa847 | |||
5d7dfaf666 | |||
114f678f1b |
38
.gitignore
vendored
38
.gitignore
vendored
@ -1,29 +1,31 @@
|
||||
.idea
|
||||
|
||||
build/*
|
||||
**/build/*
|
||||
.vs
|
||||
|
||||
**/*.gen.*
|
||||
**/gen/gen.hpp
|
||||
**/gen/gen.cpp
|
||||
**/gen/gen_dep.hpp
|
||||
**/gen/gen_dep.cpp
|
||||
**/gen/gen.dep.hpp
|
||||
**/gen/gen.dep.cpp
|
||||
**/gen/gen.builder.hpp
|
||||
**/gen/gen.builder.cpp
|
||||
**/gen/gen.scanner.hpp
|
||||
**/gen/gen.scanner.cpp
|
||||
|
||||
gencpp.hpp
|
||||
gencpp.cpp
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
[Ww][Ii][Nn]32/
|
||||
[Aa][Rr][Mm]/
|
||||
[Aa][Rr][Mm]64/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
[Ll]ogs/
|
||||
**/*.lib
|
||||
**/*.pdb
|
||||
**/*.exe
|
||||
**/*.dll
|
||||
|
||||
release/**
|
||||
|
||||
# Unreal
|
||||
**/Unreal/*.h
|
||||
**/Unreal/*.cpp
|
||||
! **/Unreal/validate.unreal.cpp
|
||||
project/auxillary/vis_ast/dependencies/temp
|
||||
test/gen/original
|
||||
|
14
.vscode/bookmarks.json
vendored
Normal file
14
.vscode/bookmarks.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"files": [
|
||||
{
|
||||
"path": "project/auxillary/vis_ast/dependencies/temp/raylib-master/src/rcamera.h",
|
||||
"bookmarks": [
|
||||
{
|
||||
"line": 140,
|
||||
"column": 14,
|
||||
"label": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
29
.vscode/c_cpp_properties.json
vendored
29
.vscode/c_cpp_properties.json
vendored
@ -1,7 +1,7 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Win32",
|
||||
"name": "Win32 msvc",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
@ -9,11 +9,36 @@
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME"
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"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",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
|
||||
"intelliSenseMode": "windows-clang-x64",
|
||||
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
28
.vscode/launch.json
vendored
28
.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"
|
||||
@ -40,6 +40,24 @@
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/singleheader/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug raylib refactor vsdbg",
|
||||
"program": "${workspaceFolder}/project/auxillary/vis_ast/dependencies/raylib/build/raylib_refactor.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/project/auxillary/vis_ast/dependencies/temp/raylib-master/src/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug VIS AST",
|
||||
"program": "${workspaceFolder}/project/auxillary/vis_ast/binaries/vis_ast.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/project/auxillary/vis_ast/binaries/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
25
.vscode/settings.json
vendored
25
.vscode/settings.json
vendored
@ -18,7 +18,26 @@
|
||||
"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",
|
||||
"glfw3.h": "c",
|
||||
"stdbool.h": "c",
|
||||
"objbase.h": "c",
|
||||
"mmreg.h": "c",
|
||||
"mmsystem.h": "c",
|
||||
"propidl.h": "c",
|
||||
"android_native_app_glue.h": "c",
|
||||
"raylib.h": "c",
|
||||
"*.m": "cpp"
|
||||
},
|
||||
"C_Cpp.intelliSenseEngineFallback": "disabled",
|
||||
"mesonbuild.configureOnOpen": true,
|
||||
@ -30,5 +49,7 @@
|
||||
"**/.vscode": true,
|
||||
"**/.vs": true,
|
||||
"**/sanity.gen.hpp": true
|
||||
}
|
||||
},
|
||||
"autoHide.autoHidePanel": false,
|
||||
"autoHide.autoHideSideBar": false
|
||||
}
|
||||
|
27
Readme.md
27
Readme.md
@ -5,15 +5,21 @@ An attempt at simple staged metaprogramming for c/c++.
|
||||
The library API is a composition of code element constructors.
|
||||
These build up a code AST to then serialize with a file builder.
|
||||
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto),
|
||||
its not meant to be a black box metaprogramming utility, its meant for the user to extend for their project domain.
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
|
||||
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
|
||||
|
||||
## Notes
|
||||
|
||||
The project has reached an *alpha* state, all the current functionality works for the test cases but it will most likely break in many other cases.
|
||||
The [issues](https://github.com/Ed94/gencpp/issues) marked with v1.0 Feature indicate whats left before the library is considered feature complete.
|
||||
**On Partial Hiatus: Life has got me tackling other issues..**
|
||||
I will be passively updating the library with bug fixes and minor improvements as I use it for my personal projects.
|
||||
There won't be any major reworks or features to this thing for a while.
|
||||
|
||||
A `natvis` and `natstepfilter` are provided in the scripts directory.
|
||||
This project is still in development (very much an alpha state), so expect bugs and missing features.
|
||||
See [issues](https://github.com/Ed94/gencpp/issues) for a list of known bugs or todos.
|
||||
|
||||
The library can already be used to generate code just fine, but the parser is where the most work is needed. If your C++ isn't "down to earth" expect issues.
|
||||
|
||||
A `natvis` and `natstepfilter` are provided in the scripts directory (its outdated, I'll update this readme when its not).
|
||||
|
||||
***The editor and scanner have not been implemented yet. The scanner will come first, then the editor.***
|
||||
|
||||
@ -25,7 +31,7 @@ A metaprogram is built to generate files before the main program is built. We'll
|
||||
|
||||
`gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated.
|
||||
|
||||
In order to keep the locality of this code within the same files the following pattern may be used:
|
||||
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't required at all):
|
||||
|
||||
Within `program.cpp` :
|
||||
|
||||
@ -41,6 +47,8 @@ u32 gen_main()
|
||||
}
|
||||
#endif
|
||||
|
||||
// "Stage" agnostic code.
|
||||
|
||||
#ifndef GEN_TIME
|
||||
#include "program.gen.cpp"
|
||||
|
||||
@ -56,6 +64,7 @@ Example using each construction interface:
|
||||
|
||||
### Upfront
|
||||
|
||||
Validation and construction through a functional interface.
|
||||
|
||||
```cpp
|
||||
Code t_uw = def_type( name(uw) );
|
||||
@ -75,6 +84,8 @@ Code header;
|
||||
|
||||
### Parse
|
||||
|
||||
Validation through ast construction.
|
||||
|
||||
```cpp
|
||||
Code header = parse_struct( code(
|
||||
struct ArrayHeader
|
||||
@ -89,6 +100,8 @@ Code header = parse_struct( code(
|
||||
|
||||
### Untyped
|
||||
|
||||
No validation, just glorified text injection.
|
||||
|
||||
```cpp
|
||||
Code header = code_str(
|
||||
struct ArrayHeader
|
||||
@ -117,7 +130,7 @@ struct ArrayHeader
|
||||
```
|
||||
|
||||
**Note: The formatting shown here is not how it will look. For your desired formatting its recommended to run a pass through the files with an auto-formatter.**
|
||||
*(The library currently uses clang-format for formatting, beaware its pretty slow...)*
|
||||
*(The library currently uses clang-format for formatting, beware its pretty slow...)*
|
||||
|
||||
## Building
|
||||
|
||||
|
44
docs/AST_Design.md
Normal file
44
docs/AST_Design.md
Normal file
@ -0,0 +1,44 @@
|
||||
## Current Design
|
||||
|
||||
`AST` is the actual managed node object for the library.
|
||||
Its raw and really not meant to be used directly.
|
||||
|
||||
All user interaction must be with its pointer so the type they deal with is `AST*`.
|
||||
For user-facing code, they should never be giveen a nullptr. Instead, they should be given a designated `Invalid` AST node.
|
||||
|
||||
In order to abstract away constant use of `AST*`, I wanted to provide a wrapper for it.
|
||||
|
||||
The simpliest being just a type alias.
|
||||
|
||||
```cpp
|
||||
using Code = AST*;
|
||||
```
|
||||
|
||||
This is what the genc library would have to use due to its constraints of a langauge.
|
||||
The actual content per type of AST is covered within [AST_Types.md](AST_Types.md).
|
||||
|
||||
These are pure PODS that just have the lay members relevant to the type of AST node they represent.
|
||||
Each of them has a Code type alias specific to it.
|
||||
|
||||
Again, the simpliest case for these would be a type alias.
|
||||
|
||||
```cpp
|
||||
using struct AST_Typedef CodeTypedef;
|
||||
```
|
||||
|
||||
As of November 21st, 2023, the AST has had a strict layout for how its content is laid out.
|
||||
This will be abandoned during its redesign that will occur starting with support for statments & expressions for either execution and type declarations.
|
||||
Having a strict layout is too resctrictive vs allowing each AST type to have maximum control over the layout.
|
||||
|
||||
The redesign will occur after the following todos are addressed:
|
||||
|
||||
* [Improvements Lexer & Token struct#27](https://github.com/Ed94/gencpp/issues/27)
|
||||
* [Generalize AST Flags to a single 4-byte flag#42](https://github.com/Ed94/gencpp/issues/42)
|
||||
* [AST-Code Object Redesign.#38](https://github.com/Ed94/gencpp/issues/38)
|
||||
* [Code-AST Documentation#40](https://github.com/Ed94/gencpp/issues/40)
|
||||
* [AST::debug_str() improvements#33](https://github.com/Ed94/gencpp/issues/33)
|
||||
* [AST::is_equal implemented and works with singleheader-test#31](https://github.com/Ed94/gencpp/issues/31)
|
||||
* [Parser : Add ability to have a parse failure and continue with errors recorded.#35](https://github.com/Ed94/gencpp/issues/35)
|
||||
* [Scanner : Add CodeFile#29](https://github.com/Ed94/gencpp/issues/29)
|
||||
* [Auxiliary : AST visual debugger#36](https://github.com/Ed94/gencpp/issues/36)
|
||||
|
737
docs/AST_Types.md
Normal file
737
docs/AST_Types.md
Normal file
@ -0,0 +1,737 @@
|
||||
# AST Types Documentation
|
||||
|
||||
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
|
||||
|
||||
## Body
|
||||
|
||||
These are containers representing a scope body of a definition that can be of the following `ECode` type:
|
||||
|
||||
* Class_Body
|
||||
* Enum_Body
|
||||
* Export_Body
|
||||
* Extern_Linkage_Body
|
||||
* Function_Body
|
||||
* Global_Body
|
||||
* Namespace_Body
|
||||
* Struct_Body
|
||||
* Union_Body
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
Code Front;
|
||||
Code Back;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Content>
|
||||
```
|
||||
|
||||
The parser will perserve comments found if residing with a body or in accepted inline-to-definition locations.
|
||||
Otherwise they will be skipped by the TokArray::__eat and TokArray::current( skip foramtting enabled ) functions.
|
||||
|
||||
The upfront constructor: `def_comment` expects to recieve a comment without the `//` or `/* */` parts. It will add them during construction.
|
||||
|
||||
## Class & Struct
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
CodeType ParentType;
|
||||
CodeBody Body;
|
||||
CodeType Prev; // Used to store references to interfaces
|
||||
CodeType Next; // Used to store references to interfaces
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
AccessSpec ParentAccess;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Class_Fwd
|
||||
<ModuleFlags> <class/struct> <Name>; <InlineCmt>
|
||||
|
||||
// Class
|
||||
<ModuleFlags> <class/struct> <Attributes> <Name> : <ParentAccess> <ParentType>, public <ParentType->Next>, ... <InlineCmt>
|
||||
{
|
||||
<Body>
|
||||
};
|
||||
```
|
||||
|
||||
You'll notice that only one parent type is supported only with parent access. This library only supports single inheritance, the rest must be done through interfaces.
|
||||
|
||||
## Constructor
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
Code Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Constructor_Fwd
|
||||
<Specs> <Parent->Name>( <Params> ); <InlineCmt>
|
||||
|
||||
// Constructor
|
||||
<Specs> <Parent->Name>( <Params> ) <InlineCmt>
|
||||
: <InitializerList>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
|
||||
// Constructor Source Implementation
|
||||
<Specs> <Parent>::~<Parent->Name>( <Params> ) <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Define
|
||||
|
||||
Represents a preprocessor define
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#define <Name> <Content>
|
||||
```
|
||||
|
||||
## Destructor
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeSpecifiers Specs;
|
||||
Code Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Destructor_Fwd
|
||||
<Specs> ~<Parent->Name>( <Params> ) <Specs>; <InlineCmt>
|
||||
|
||||
// Destructor
|
||||
<Specs> ~<Parent->Name>( <Params> ) <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
|
||||
// Destructor Source Implementation
|
||||
<Specs> <Parent>::~<Parent->Name>( <Params> ) <Specs>
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Enum
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeType UnderlyingType;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Content>
|
||||
```
|
||||
|
||||
## External Linkage
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
extern "<Name>"
|
||||
{
|
||||
<Body>
|
||||
}
|
||||
```
|
||||
|
||||
## Include
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Code Parent;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
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 Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<ModuleFlags> module <Name>;
|
||||
```
|
||||
|
||||
## Namespace
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
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 (AST_Param)
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeType ValueType;
|
||||
Code Macro;
|
||||
Code Value;
|
||||
CodeParam Last;
|
||||
CodeParam Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Macro>, <Next> ... <Last>
|
||||
|
||||
<Macro> <ValueType> <Name>, <Next>... <Last>
|
||||
```
|
||||
|
||||
## Pragma
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#pragma <Content>
|
||||
```
|
||||
|
||||
## Preprocessor Conditional
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
StringCached Content;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
paser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
#<based off Type> <Content>
|
||||
```
|
||||
|
||||
## Specifiers
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
SpecifierT ArrSpecs[ AST::ArrSpecs_Cap ];
|
||||
CodeSpecifiers NextSpecs;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
s32 NumEntries;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Spec>, ...
|
||||
```
|
||||
|
||||
## Template
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeParam Params;
|
||||
Code Declaration;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
b32 IsParamPack;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
<Attributes> <Name> <Specs> <IsParamPack ?: ...>
|
||||
```
|
||||
|
||||
## Typedef
|
||||
|
||||
Behave as usual except function or macro typedefs.
|
||||
Those (macros) 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;
|
||||
parse::Token* Tok
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
b32 IsFunction;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> typedef <UnderlyingType> <Name>; <InlineCmt>
|
||||
|
||||
// Functions
|
||||
<ModuleFlags> typedef <ReturnType> <Name>( <Parameters> ); <InlineCmt>
|
||||
<ModuleFlags> typedef <ReturnType> ( <Expression that yeilds an Identifier signature> )( <Parameters> ); <InlineCmt>
|
||||
```
|
||||
|
||||
## Union
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeAttributes Attributes;
|
||||
CodeBody Body;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
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;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> using <Attributes> <Name> = <UnderlyingType>; <InlineCmt>
|
||||
|
||||
// Namespace
|
||||
<ModuleFlags> using namespace <Name>; <InlineCmt>
|
||||
```
|
||||
|
||||
## Variable
|
||||
|
||||
[Algo](./Parser_Algo.md:)
|
||||
|
||||
Fields:
|
||||
|
||||
```cpp
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
CodeVar NextVar;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
parser::Token* Tok;
|
||||
Code Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
```
|
||||
|
||||
Serialization:
|
||||
|
||||
```cpp
|
||||
// Regular
|
||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> = <Value>, NextVar ...; <InlineCmt>
|
||||
|
||||
// Bitfield
|
||||
<ModuleFlags> <Attributes> <Specs> <ValueType> <Name> : <BitfieldSize> = <Value>, NextVar ...; <InlineCmt>
|
||||
```
|
702
docs/Parser_Algo.md
Normal file
702
docs/Parser_Algo.md
Normal file
@ -0,0 +1,702 @@
|
||||
# Parser's Algorithim
|
||||
|
||||
gencpp uses a hand-written recursive descent parser. Both the lexer and parser currently handle a full C/C++ file in a single pass.
|
||||
|
||||
## 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;
|
||||
u32 Flags;
|
||||
```
|
||||
|
||||
Flags is a bitfield made up of TokFlags (Token Flags):
|
||||
|
||||
* `TF_Operator` : Any operator token used in expressions
|
||||
* `TF_Assign`
|
||||
* Using statment assignment
|
||||
* Parameter argument default value assignment
|
||||
* Variable declaration initialization assignment
|
||||
* `TF_Preprocess` : Related to a preprocessing directive
|
||||
* `TF_Preprocess_Cond` : A preprocess conditional
|
||||
* `TF_Attribute` : An attribute token
|
||||
* `TF_AccessSpecifier` : An accesor operation token
|
||||
* `TF_Specifier` : One of the specifier tokens
|
||||
* `TF_EndDefinition` : Can be interpreted as an end definition for a scope.
|
||||
* `TF_Formatting` : Considered a part of the formatting
|
||||
* `TF_Literal` : Anything considered a literal by C++.
|
||||
|
||||
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
|
||||
<code type> 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 have the following format:
|
||||
|
||||
```cpp
|
||||
internal
|
||||
<code type> parse_<definition_type>( <empty or contextual params> )
|
||||
{
|
||||
push_scope();
|
||||
|
||||
...
|
||||
|
||||
<code type> result = (<code type>) make_code();
|
||||
...
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
Below is an outline of the general alogirithim used for these internal procedures. The intention is to provide a basic briefing to aid the user in traversing the actual code definitions. These appear in the same order as they are in the `parser.cpp` file
|
||||
|
||||
***NOTE: This is still heavily in an alpha state. A large swaph of this can change, make sure these docs are up to date before considering them 1:1 with the repo commit your considering.***
|
||||
|
||||
## `parse_array_decl`
|
||||
|
||||
1. Check if its an array declaration with no expression.
|
||||
1. Consume and return empty array declaration
|
||||
2. Opening square bracket
|
||||
3. Consume expression
|
||||
4. Closing square bracket
|
||||
5. If adjacent opening bracket
|
||||
1. Repeat array declaration parse until no brackets remain
|
||||
|
||||
## `parse_assignment_expression`
|
||||
|
||||
1. Eat the assignment operator
|
||||
2. Make sure there is content or at least an end statement after.
|
||||
3. Flatten the assignment expression to an untyped Code string.
|
||||
|
||||
## `parse_attributes`
|
||||
|
||||
1. Check for standard attribute
|
||||
2. Check for GNU attribute
|
||||
3. Check for MSVC attribute
|
||||
4. Check for a token registered as an attribute
|
||||
a. Check and grab the arguments of a token registered of an attribute if it has any.
|
||||
5. Repeat for chained attributes. Flatten them to a single attribute AST node.
|
||||
|
||||
## `parse_class_struct`
|
||||
|
||||
1. Check for export module specifier
|
||||
2. class or struct keyword
|
||||
3. `parse_attributes`
|
||||
4. If identifier : `parse_identifier`
|
||||
5. Parse inherited parent or interfaces
|
||||
6. If opening curly brace : `parse_class_struct_body`
|
||||
7. If not an inplace definition
|
||||
1. End statement
|
||||
2. Check for inline comment
|
||||
|
||||
## `parse_class_struct_body`
|
||||
|
||||
1. Opening curly brace
|
||||
2. Parse the body (Possible options):
|
||||
1. Ignore dangling end statements
|
||||
2. Newline : ast constant
|
||||
3. Comment : `parse_comment`
|
||||
4. Access_Public : ast constant
|
||||
5. Access_Protected : ast constant
|
||||
6. Access_Private : ast constant
|
||||
7. Decl_Class : `parse_complicated_definition`
|
||||
8. Decl_Enum : `parse_complicated_definition`
|
||||
9. Decl_Friend : `parse_friend`
|
||||
10. Decl_Operator : `parse_operator_cast`
|
||||
11. Decl_Struct : `parse_complicated_definition`
|
||||
12. Decl_Template : `parse_template`
|
||||
13. Decl_Typedef : `parse_typedef`
|
||||
14. Decl_Union : `parse_complicated_definition`
|
||||
15. Decl_Using : `parse_using`
|
||||
16. Operator == '~'
|
||||
1. `parse_destructor`
|
||||
17. Preprocess_Define : `parse_define`
|
||||
18. Preprocess_Include : `parse_include`
|
||||
19. Preprocess_Conditional (if, ifdef, ifndef, elif, else, endif) : `parse_preprocess_cond` or else/endif ast constant
|
||||
20. Preprocess_Macro : `parse_simple_preprocess`
|
||||
21. Preprocess_Pragma : `parse_pragma`
|
||||
22. Preprocess_Unsupported : `parse_simple_preprocess`
|
||||
23. StaticAssert : `parse_static_assert`
|
||||
24. The following compound into a resolved definition or declaration:
|
||||
1. Attributes (Standard, GNU, MSVC) : `parse_attributes`
|
||||
2. Specifiers (consteval, constexpr, constinit, explicit, forceinline, inline, mutable, neverinline, static, volatile, virtual)
|
||||
3. Possible Destructor : `parse_destructor`
|
||||
4. Possible User defined operator cast : `parse_operator_cast`
|
||||
5. Possible Constructor : `parse_constructor`
|
||||
6. Something that has the following: (identifier, const, unsigned, signed, short, long, bool, char, int, double)
|
||||
1. Possible Constructor `parse_constructor`
|
||||
2. Possible Operator, Function, or varaible : `parse_operator_function_or_variable`
|
||||
25. Something completely unknown (will just make untyped...) : `parse_untyped`
|
||||
|
||||
## `parse_comment`
|
||||
|
||||
1. Just wrap the token into a cached string ( the lexer did the processing )
|
||||
|
||||
## `parse_compilcated_definition`
|
||||
|
||||
This is a helper function used by the following functions to help resolve a declaration or definition:
|
||||
|
||||
* `parse_class_struct_body`
|
||||
* `parse_global_nspace`
|
||||
* `parse_union`
|
||||
|
||||
A portion of the code in `parse_typedef` is very similar to this as both have to resolve a similar issue.
|
||||
|
||||
1. Look ahead to the termination token (End statement)
|
||||
2. Check to see if it fits the pattern for a forward declare
|
||||
3. If the previous token was an identifier ( `token[-1]` ):
|
||||
1. Look back one more token : `[-2]`
|
||||
2. If the token has a closing brace its an inplace definition
|
||||
3. If the `token[-2]` is an identifier & `token[-3]` is the declaration type, its a variable using a namespaced type.
|
||||
4. If the `token[-2]` is an indirection, then its a variable using a namespaced/forwarded type.
|
||||
5. If the `token[-2]` is an assign classifier, and the starting tokens were the which type with possible `class` token after, its an enum forward declaration.
|
||||
6. If any of the above is the case, `parse_operator_function_or_variable`
|
||||
4. If the `token[2]` is a vendor fundamental type (builtin) then it is an enum forward declaration.
|
||||
5. If the previous token was a closing curly brace, its a definition : `parse_forward_or_definition`
|
||||
6. If the previous token was a closing square brace, its an array definition : `parse_operator_function_or_variable`
|
||||
|
||||
## `parse_define`
|
||||
|
||||
1. Define directive
|
||||
2. Get identifier
|
||||
3. Get Content (Optional)
|
||||
|
||||
## `parse_forward_or_definition`
|
||||
|
||||
* Parse any of the following for either a forward declaration or definition:
|
||||
1. Decl_Class : `parse_class`
|
||||
2. Decl_Enum : `parse_enum`
|
||||
3. Decl_Struct : `parse_struct`
|
||||
4. Decl_Union : `parse_union`
|
||||
|
||||
## `parse_function_after_name`
|
||||
|
||||
This is needed as a function defintion is not easily resolvable early on, as such this function handles resolving a function
|
||||
after its been made ceratin that the type of declaration or definition is indeed for a function signature.
|
||||
|
||||
By the point this function is called the following are known : export module flag, attributes, specifiers, return type, & name
|
||||
|
||||
1. `parse_parameters`
|
||||
2. parse postfix specifiers (we do not check if the specifier here is correct or not to be here... yet)
|
||||
3. If there is a body : `parse_body`
|
||||
4. Otherwise :
|
||||
1. Statment end
|
||||
2. Check for inline comment
|
||||
|
||||
## `parse_function_body`
|
||||
|
||||
Currently there is no actual parsing of the function body. Any content with the braces is shoved into an execution AST node.
|
||||
In the future statements and expressions will be parsed.
|
||||
|
||||
1. Open curly brace
|
||||
2. Grab all tokens between the brace and the closing brace, shove them in a execution AST node.
|
||||
3. Closing curly brace
|
||||
|
||||
## `parse_global_nspace`
|
||||
|
||||
1. Make sure this is being called for a valid type (namespace, global body, export body, linkage body)
|
||||
2. If its not a global body, consume the opening curly brace
|
||||
3. Parse the body (Possible options):
|
||||
1. Ignore dangling end statements
|
||||
2. NewLine : ast constant
|
||||
3. Comment : `parse_comment`
|
||||
4. Decl_Cass : `parse_complicated_definition`
|
||||
5. Decl_Enum : `parse_complicated_definition`
|
||||
6. Decl_Extern_Linkage : `parse_extern_link`
|
||||
7. Decl_Namespace : `parse_namespace`
|
||||
8. Decl_Struct : `parse_complicated_definition`
|
||||
9. Decl_Template : `parse_template`
|
||||
10. Decl_Typedef : `parse_typedef`
|
||||
11. Decl_Union : `parse_complicated_definition`
|
||||
12. Decl_Using : `parse_using`
|
||||
13. Preprocess_Define : `parse_define`
|
||||
14. Preprocess_Include : `parse_include`
|
||||
15. Preprocess_If, IfDef, IfNotDef, Elif : `parse_preprocess_cond`
|
||||
16. Preprocess_Else : ast constant
|
||||
17. Preprocess_Endif : ast constant
|
||||
18. Preprocess_Macro : `parse_simple_preprocess`
|
||||
19. Preprocess_Pragma : `parse_pragma`
|
||||
20. Preprocess_Unsupported : `parse_simple_preprocess`
|
||||
21. StaticAssert : `parse_static_assert`
|
||||
22. Module_Export : `parse_export_body`
|
||||
23. Module_Import : NOT_IMPLEMENTED
|
||||
24. The following compound into a resolved definition or declaration:
|
||||
1. Attributes ( Standard, GNU, MSVC, Macro ) : `parse_attributes`
|
||||
2. Specifiers ( consteval, constexpr, constinit, extern, forceinline, global, inline, internal_linkage, neverinline, static )
|
||||
3. Is either ( identifier, const specifier, long, short, signed, unsigned, bool, char, double, int)
|
||||
1. Attempt to parse as constrcutor or destructor : `parse_global_nspace_constructor_destructor`
|
||||
2. If its an operator cast (definition outside class) : `parse_operator_cast`
|
||||
3. Its an operator, function, or varaible : `parse_operator_function_or_varaible`
|
||||
4. If its not a global body, consume the closing curly brace
|
||||
|
||||
## `parse_global_nspace_constructor_destructor`
|
||||
|
||||
1. Look ahead for the start of the arguments for a possible constructor/destructor
|
||||
2. Go back past the identifier
|
||||
3. Check to see if its a destructor by checking for the `~`
|
||||
4. Continue the next token should be a `::`
|
||||
5. Determine if the next valid identifier (ignoring possible template parameters) is the same as the first identifier of the function.
|
||||
6. If it is we have either a constructor or destructor so parse using their respective functions (`parse_constructor`, `parse_destructor`).
|
||||
|
||||
## `parse_identifier`
|
||||
|
||||
This is going to get heavily changed down the line to have a more broken down "identifier expression" so that the qualifier, template args, etc, can be distinguished between the targeted identifier.
|
||||
The function can parse all of them, however the AST node compresses them all into a string.
|
||||
|
||||
1. Consume first identifier
|
||||
2. `parse_template_args`
|
||||
3. While there is a static symbol accessor ( `::` )
|
||||
1. Consume `::`
|
||||
2. Consume member identifier
|
||||
3. `parse_template args` (for member identifier)
|
||||
4. If a `~` is encounted and the scope is for a destructor's identifier, do not consume it and return with what parsed.
|
||||
|
||||
## `parse_include`
|
||||
|
||||
1. Consume include directive
|
||||
2. Consume the path
|
||||
|
||||
## `parse_operator_after_ret_type`
|
||||
|
||||
This is needed as a operator defintion is not easily resolvable early on, as such this function handles resolving a operator after its been made ceratin that the type of declaration or definition is indeed for a operator signature.
|
||||
|
||||
By the point this function is called the following are known : export module flag, attributes, specifiers, return type
|
||||
|
||||
1. If there is any qualifiers for the operator, parse them
|
||||
2. Consume operator keyword
|
||||
3. Determine the operator type (This will be offloaded to the lexer moreso than how it is now) & consume
|
||||
4. `parse_params`
|
||||
5. If there is no parameters this is operator is a member of pointer if its symbols is a *.
|
||||
6. Parse postfix specifiers
|
||||
7. If there is a opening curly brace, `parse function_body`
|
||||
8. Otherwise: consume end statement, check for inline comment.
|
||||
|
||||
## `parse_operator_function_or_variable`
|
||||
|
||||
When this function is called, attribute and specifiers may have been resolved, however what comes next can still be either an operator, function, or varaible.
|
||||
|
||||
1. Check for preprocessor macro, if there is one : `parse_simple_preprocess`
|
||||
2. `parse_type` (Does the bulk of the work)
|
||||
3. Begin lookahead to see if we get qualifiers or we eventually find the operator declaration
|
||||
4. If we find an operator keyword : `parse_operator_after_ret_type`
|
||||
5. otherwise :
|
||||
1. `parse_identifier`
|
||||
2. If we se a opening parenthesis (capture start), its a function : `parse_function_after_name`
|
||||
3. Its a variable : `parse_variable_after_name`
|
||||
|
||||
## `parse_pragma`
|
||||
|
||||
1. Consume pragma directive
|
||||
2. Process the token content into cached string
|
||||
|
||||
## `parse_params`
|
||||
|
||||
1. Consume either a `(` or `<` based on `use_template_capture` arg
|
||||
2. If the we immdiately find a closing token, consume it and finish.
|
||||
3. If we encounter a varadic argument, consume it and return a `param_varadic` ast constant
|
||||
4. `parse_type`
|
||||
5. If we have a macro, parse it (Unreal has macros as tags to parameters and or as entire arguments).
|
||||
6. So long as next token isn't a comma
|
||||
a. If we have an identifier
|
||||
1. Consume it
|
||||
2. Check for assignment:
|
||||
a. Consume assign operator
|
||||
b. Parse the expression
|
||||
7. While we continue to encounter commas
|
||||
a. Consume them
|
||||
b. Repeat steps 3 to 6.2.b
|
||||
8. Consume the closing token
|
||||
|
||||
## `parse_preprocess_cond`
|
||||
|
||||
1. Parse conditional directive
|
||||
2. Process directive's content expression
|
||||
|
||||
## `parse_simple_preprocess`
|
||||
|
||||
There is still decent room for improvement in this setup. Right now the entire macro's relevant tokens are shoved into an untyped AST. It would be better to store it instead in an `AST_Macro` node instead down the line.
|
||||
|
||||
1. Consume the macro token
|
||||
2. Check for an opening curly brace
|
||||
1. Consume opening curly brace
|
||||
2. Until the closing curly is encountered consume all tokens.
|
||||
3. If the parent context is a typedef
|
||||
1. Check for end stement
|
||||
1. Consume it
|
||||
2. Consume potential inline comment
|
||||
3. Otherwise do steps 3 to 3.1.2
|
||||
4. Shove it all in an untyped string
|
||||
|
||||
## `parse_static_assert`
|
||||
|
||||
1. Consume static assert and opening curly brace
|
||||
2. Consume all tokens until the the closing brace is reached.
|
||||
3. Consume curly brace and end statement
|
||||
4. Place all tokens within braces into a content for the assert.
|
||||
|
||||
## `parse_template_args`
|
||||
|
||||
This will get changed heavily once we have better support for typename expressions
|
||||
|
||||
1. Consume opening angle bracket
|
||||
2. Consume all tokens until closing angle bracket
|
||||
3. Consme closing angle bracket
|
||||
4. Return the currtok with the ammended length.
|
||||
|
||||
## `parse_variable_after_name`
|
||||
|
||||
This is needed as a variable defintion is not easily resolvable early on, it takes a long evaluation period before its known that the declaration or definition is a variable. As such this function handles resolving a variable.
|
||||
|
||||
By the point this function is called the following are known : export module flag, attributes, specifiers, value type, name
|
||||
|
||||
1. If its an assignment, parse the assignment expression (currently to an untyped string)
|
||||
2. If its an opening curly brace, parse the expression within (currnelty to an untyped stirng).
|
||||
1. Consume the closing curly brace
|
||||
3. If its a `:`, we're dealing with bitfield definition:
|
||||
1. Consume the assign classifier
|
||||
2. Consume the expression (currently to an untyped string)
|
||||
4. If a comma is encountered : `parse_variable declaration_list`
|
||||
5. Consume statement end
|
||||
6. Check for inline comment
|
||||
|
||||
## `parse_variable_declaration_list`
|
||||
|
||||
1. Consume the comma
|
||||
2. Parse specifiers
|
||||
3. `parse_variable_after_name`
|
||||
|
||||
## `parse_class`
|
||||
|
||||
1. `parse_class_struct`
|
||||
|
||||
## `parse_constructor`
|
||||
|
||||
This currently doesn't support postfix specifiers (planning to in the future)
|
||||
|
||||
1. `parse_identifier`
|
||||
2. `parse_parameters`
|
||||
3. If currtok is a `:`
|
||||
1. Consume `:`
|
||||
2. Parse the initializer list
|
||||
3. `parse_function_body`
|
||||
4. If currtok is an opening curly brace
|
||||
1. `parse_function_body`
|
||||
5. Otherwise:
|
||||
1. Consume statement end
|
||||
2. Check for inline comment
|
||||
|
||||
## `parse_destructor`
|
||||
|
||||
1. Check for and consume virtual specifier
|
||||
2. Check for the `~` operator
|
||||
3. `parse_identifier`
|
||||
4. Consume opening and closing parenthesis
|
||||
5. Check for assignment operator:
|
||||
1. Consume assignment op
|
||||
2. Consume pure specifier `0`
|
||||
6. If not pure virtual & currtok is opening curly brace:
|
||||
1. `parse_function_body`
|
||||
7. Otherwise:
|
||||
1. Consume end statement
|
||||
2. If currtok is comment : `parse_comment`
|
||||
|
||||
## `parse_enum`
|
||||
|
||||
1. Consume enum token
|
||||
2. Check for and consume class token
|
||||
3. `parse_attributes`
|
||||
4. If there is an identifier consume it
|
||||
5. Check for a `:`
|
||||
1. Consume `:`
|
||||
2. `parse_type`
|
||||
6. If there is a body parse it (Consume `{`):
|
||||
1. Newline : ast constant
|
||||
2. Comment : `parse_comment`
|
||||
3. Preprocess_Define : `parse_define`
|
||||
4. Preprocess_Conditional (if, ifdef, ifndef, elif ) : `parse_preprocess_cond`
|
||||
5. Preprocess_Else : ast constant
|
||||
6. Preprocess_Endif : ast constant
|
||||
7. Preprocess_Macro : `parse_simple_preprocess`
|
||||
8. Preprocess_Pragma : `parse_pragma`
|
||||
9. Preprocess_Unsupported : `parse_smple_preprocess`
|
||||
10. An actual enum entry
|
||||
1. Consume identifier
|
||||
2. If there is an assignment operator:
|
||||
1. Consume operator
|
||||
2. Consume the expression (assigned to untyped string for now)
|
||||
3. If a macro is encountered consume it (Unreal UMETA macro support)
|
||||
3. If there is a comma, consume it
|
||||
|
||||
## `parse_export_body`
|
||||
|
||||
1. `parse_global_nspace`
|
||||
|
||||
## `parse_extern_link_body`
|
||||
|
||||
1. `parse_global_nspace`
|
||||
|
||||
## `parse_extern_link`
|
||||
|
||||
1. Consume Decl_Extern_Linkage
|
||||
2. Consume the linkage identifier
|
||||
3. `parse_extern_link_body`
|
||||
|
||||
## `parse_friend`
|
||||
|
||||
1. Consume `friend`
|
||||
2. `parse_type`
|
||||
3. If the currok is an identifier its a function declaration or definition
|
||||
1. `parse_function_after_name`
|
||||
4. Consume end statement so long as its not a function definion
|
||||
5. Check for inline comment, `parse_comment` if exists
|
||||
|
||||
## `parse_function`
|
||||
|
||||
1. Check and parse for `export`
|
||||
2. `parse_attributes`
|
||||
3. Parse specifiers
|
||||
4. `parse_type`
|
||||
5. `parse_identifier`
|
||||
6. `parse_function_after_name`
|
||||
|
||||
## `parse_namespace`
|
||||
|
||||
1. Consume namespace declaration
|
||||
2. Parse identifier
|
||||
3. `parse_global_namespace`
|
||||
|
||||
## `parse_operator`
|
||||
|
||||
1. Check for and parse export declaration
|
||||
2. `parse_attributes`
|
||||
3. Parse specifiers
|
||||
4. `parse_type`
|
||||
5. `parse_operator_after_ret_type`
|
||||
|
||||
## `parse_operator_cast`
|
||||
|
||||
1. Look for and parse a qualifier namespace for the cast (in-case this is defined outside the class's scope)
|
||||
2. Consume operator declaration
|
||||
3. `parse_type`
|
||||
4. Consume opening and closing parethesis
|
||||
5. Check for a const qualifiying specifier
|
||||
6. Check to see if this is a definition (`{`)
|
||||
1. Consume `{`
|
||||
2. Parse body to untyped string (parsing statement and expressions not supported yet)
|
||||
3. Consume `}`
|
||||
7. Otherwise:
|
||||
1. Consume end statement
|
||||
2. Check for and consume comment : `parse_comment`
|
||||
|
||||
|
||||
## `parse_struct`
|
||||
|
||||
1. `parse_class_struct`
|
||||
|
||||
## `parse_template`
|
||||
|
||||
Note: This currently doesn't support templated operator casts (going to need to add support for it)
|
||||
|
||||
1. Check for and parse export declaration
|
||||
2. Consume template declaration
|
||||
3. `parse_params`
|
||||
4. Parse for any of the following:
|
||||
1. Decl_Class : `parse_class`
|
||||
2. Decl_Struct : `parse_struct`
|
||||
3. Decl_Union : `parse_union`
|
||||
4. Decl_Using : `parse_using`
|
||||
5. The following compound into a resolved definition or declaration:
|
||||
1. `parse_attributes`
|
||||
2. Parse specifiers
|
||||
3. Attempt to parse as constructor or destructor: `parse_global_nspace_constructor_destructor`
|
||||
4. Otherwise: `parse_operator_function_or_variable`
|
||||
|
||||
## `parse_type`
|
||||
|
||||
This function's implementation is awful and not done correctly. It will most likely be overhauled in the future as I plan to segement the AST_Type into several AST varaints along with sub-types to help produce robust type expressions.
|
||||
Hopefully I won't need to make authentic type expressions as I was hopeing to avoid that...
|
||||
|
||||
### Current Algorithim
|
||||
|
||||
Anything that is in the qualifier capture of the function typename is treated as an expression abstracted as an untyped string
|
||||
|
||||
1. `parse_attributes`
|
||||
2. Parse specifiers
|
||||
3. If the `parse_type` was called from a template parse, check to see if class was used instead of typname and consume as name.
|
||||
4. This is where things get ugly for each of these depend on what the next token is.
|
||||
1. If its an in-place definition of a class, enum, struct, or union:
|
||||
2. If its a decltype (Not supported yet but draft impl there)
|
||||
3. If its a compound native type expression (unsigned, char, short, long, int, float, dobule, etc )
|
||||
4. Ends up being a regular type alias of an identifier
|
||||
5. Parse specifiers (postfix)
|
||||
6. We need to now look ahead to see If we're dealing with a function typename
|
||||
7. If wer're dealing with a function typename:
|
||||
1. Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
|
||||
1. Reset the specifiers code for the top-level typeanme
|
||||
2. Check to see if the next token is an identifier:
|
||||
1. `parse_identifier`
|
||||
3. Check to see if the next token is capture start and is not the last capture ("qualifier capture"):
|
||||
1. Consume `(`
|
||||
2. Consume expresssion between capture
|
||||
3. Consume `)`
|
||||
4. `parse_params`
|
||||
5. Parse postfix specifiers
|
||||
8. Check for varaidic argument (param pack) token:
|
||||
1. Consume varadic argument token
|
||||
|
||||
### WIP - Alternative Algorithim
|
||||
|
||||
Currently wrapped up via macro: `GEN_USE_NEW_TYPENAME_PARSING`
|
||||
Anything that is in the qualifier capture of the function typename is treated as an expression abstracted as an untyped string
|
||||
|
||||
1. `parse_attributes`
|
||||
2. Parse specifiers (prefix)
|
||||
3. This is where things get ugly for each of these depend on what the next token is.
|
||||
1. If its an in-place definition of a class, enum, struct, or union:
|
||||
2. If its a decltype (Not supported yet but draft impl there)
|
||||
3. If its a compound native type expression (unsigned, char, short, long, int, float, dobule, etc )
|
||||
4. Ends up being a regular type alias of an identifier
|
||||
4. Parse specifiers (postfix)
|
||||
1. If any specifiers are found populate specifiers code with them.
|
||||
5. We need to now look ahead to see If we're dealing with a function typename
|
||||
6. If wer're dealing with a function typename:
|
||||
1. Shove the specifiers, and identifier code we have so far into a return type typename's Name (untyped string)
|
||||
1. Reset the specifiers code for the top-level typename
|
||||
2. Check to see if the next token is an identifier:
|
||||
1. `parse_identifier`
|
||||
3. Check to see if the next token is capture start and is not the last capture ("qualifier capture"):
|
||||
1. Consume `(`
|
||||
2. Parse binding specifiers
|
||||
3. `parse_identifier`
|
||||
4. `parse_parameters` -> params_nested
|
||||
5. Consume `)`
|
||||
6. Construct a nested function typename definition for the qualifier `Name`
|
||||
4. `parse_params` - > params
|
||||
5. Parse postfix specifiers
|
||||
7. Check for varaidic argument (param pack) token:
|
||||
1. Consume varadic argument token
|
||||
|
||||
### **Later: Algorithim based on typename expressions**
|
||||
|
||||
## `parse_typedef`
|
||||
|
||||
1. Check for export module specifier
|
||||
2. typedef keyword
|
||||
3. If its a preprocess macro: Get the macro name
|
||||
4. Else:
|
||||
1. Check to see if its a complicated definition (in-place enum, class, struct, union)
|
||||
2. If its a complicated definition:
|
||||
1. Perform the look ahead similar to `parse_complicated_definition`'s implementation
|
||||
2. Check to see if its a forward declaration : `parse_forward_declaration`
|
||||
3. If end[-1] is an identifier:
|
||||
1. Its either an in-place, varaible type qualified identifier, or indirection type:
|
||||
1. `parse_foward_or_definition`
|
||||
4. else if end[-1] is a closing curly brace
|
||||
1. Its a definition: `parse_forward_or_definition`
|
||||
5. else if end[-1] is a closing square brace
|
||||
2. Its an array definition: `parse_type`
|
||||
3. Else : `parse-type`
|
||||
4. Check for identifier : Consume the token
|
||||
5. `parse_array_decl`
|
||||
5. Consume end statement
|
||||
6. Check for inline comment : `parse_comment`
|
||||
|
||||
## `parse_union`
|
||||
|
||||
1. Check for export module specifier
|
||||
2. union keyword
|
||||
3. `parse_attributes`
|
||||
4. Check for identifier
|
||||
5. Parse the body (Possible options):
|
||||
1. Newline
|
||||
2. Comment
|
||||
3. Decl_Class
|
||||
4. Decl_Enum
|
||||
5. Decl_Struct
|
||||
6. Decl_Union
|
||||
7. Preprocess_Define
|
||||
8. Preprocess_Conditional (if, ifdef, ifndef, elif, else, endif)
|
||||
9. Preprocess_Macro
|
||||
10. Preprocess_Pragma
|
||||
11. Unsupported preprocess directive
|
||||
12. Variable
|
||||
6. If its not an inplace definiton: End Statement
|
||||
|
||||
## `parse_using`
|
||||
|
||||
1. Check for export module specifier
|
||||
2. using keyword
|
||||
3. Check to see if its a using namespace
|
||||
4. Get the identifier
|
||||
5. If its a regular using declaration:
|
||||
1. `parse_attributes`
|
||||
2. `parse_type`
|
||||
3. `parse_array_decl`
|
||||
6. End statement
|
||||
7. Check for inline comment
|
||||
|
||||
## `parse_variable`
|
||||
|
||||
1. Check for export module specifier
|
||||
2. `parse_attributes`
|
||||
3. `parse specifiers`
|
||||
4. `parse_type`
|
||||
5. `parse_identifier`
|
||||
6. `parse_variable_after_name`
|
@ -1,19 +1,24 @@
|
||||
# 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 under 5000 loc.
|
||||
|
||||
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 ~5600 loc. I hope to keep it under 10k loc worst case.
|
||||
|
||||
You can think of this parser of a frontend parser vs a semantic parser. Its intuitively similar to WYSIWYG. What you precerive as the syntax from the user-side before the compiler gets a hold of it, is what you get.
|
||||
|
||||
User exposed interface:
|
||||
|
||||
```cpp
|
||||
CodeClass parse_class ( StrC class_def );
|
||||
CodeConstructor parse_constructor ( StrC constructor_def );
|
||||
CodeDestructor parse_destructor ( StrC destructor_def );
|
||||
CodeEnum parse_enum ( StrC enum_def );
|
||||
CodeBody parse_export_body ( StrC export_def );
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def);
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def );
|
||||
CodeFriend parse_friend ( StrC friend_def );
|
||||
CodeFn parse_function ( StrC fn_def );
|
||||
CodeBody parse_global_body ( StrC body_def );
|
||||
CodeNamespace parse_namespace ( StrC namespace_def );
|
||||
CodeNS parse_namespace ( StrC namespace_def );
|
||||
CodeOperator parse_operator ( StrC operator_def );
|
||||
CodeOpCast parse_operator_cast( StrC operator_def );
|
||||
CodeStruct parse_struct ( StrC struct_def );
|
||||
@ -25,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:
|
||||
|
||||
@ -38,15 +45,37 @@ 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*.
|
||||
All keywords except *include* are suppported as members of a scope for a class/struct, global, or namespace body.
|
||||
If a directive is used with an unsupported keyword its will be processed as an untyped AST.
|
||||
|
||||
The preprocessor lines are stored as members of their associated scope they are parsed within. ( Global, Namespace, Class/Struct )
|
||||
|
||||
Any preprocessor definition abuse that changes the syntax of the core language is unsupported and will fail to parse if not kept within an execution scope (function body, or expression assignment).
|
||||
Exceptions:
|
||||
|
||||
Exceptions to the above rule (If its too hard to keep track of just follow the above notion):
|
||||
* 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`
|
||||
|
||||
* Typedefs allow of a macro exansion to be defined after the keyword; Ex: `typedef GEN_FILE_OPEN_PROC( file_open_proc );`
|
||||
*(Exceptions are added on an on-demand basis)*
|
||||
*(See functions `parse_operator_function_or_variable` and `parse_typedef` )*
|
||||
|
||||
Adding your own exceptions is possible by simply modifying the parser to allow for the syntax you need.
|
||||
|
||||
*Note: You could interpret this strictness as a feature. This would allow the user to see if their codebase or a third-party's codebase some some egregious preprocessor abuse.*
|
||||
|
||||
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
|
||||
* Numeric literals are not checked for validity.
|
||||
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
||||
* *This includes the assignment of variables.*
|
||||
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
|
||||
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function or right afterthe return type.
|
||||
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
|
||||
* typedefs have attributes with the type (`parse_type`)
|
||||
* Parsing attributes can be extended to support user defined macros by defining `GEN_DEFINE_ATTRIBUTE_TOKENS` (see `gen.hpp` for the formatting)
|
||||
|
||||
Empty lines used throughout the file are preserved for formatting purposes during ast serialization.
|
||||
|
179
docs/Readme.md
179
docs/Readme.md
@ -32,7 +32,7 @@ Two generic templated containers are used throughout the library:
|
||||
* `template< class Type> struct Array`
|
||||
* `template< class Type> struct HashTable`
|
||||
|
||||
Both Code and AST definitions have a `template< class Type> Code/AST cast()`. Its just an alternative way to explicitly cast to each other.
|
||||
Both Code and AST definitions have a `template< class Type> Code/AST :: cast()`. Its just an alternative way to explicitly cast to each other.
|
||||
|
||||
`template< class Type> swap( Type& a, Type& b)` is used over a macro.
|
||||
|
||||
@ -40,27 +40,9 @@ Otherwise the library is free of any templates.
|
||||
|
||||
### *WHAT IS NOT PROVIDED*
|
||||
|
||||
* Execution statement validation : Execution expressions are defined using the untyped AST.
|
||||
* Lambdas (This naturally means its unsupported)
|
||||
* Non-trivial template validation support.
|
||||
* RAII : This needs support for constructors/destructor parsing
|
||||
* Haven't gotten around to yet (its in the github issues)
|
||||
|
||||
Keywords kept from "Modern C++":
|
||||
|
||||
* constexpr : Great to store compile-time constants.
|
||||
* consteval : Technically fine, need to make sure to execute in moderation.
|
||||
* constinit : Better than constexpr at doing its job, however, its only c++ 20.
|
||||
* export : Useful if c++ modules ever come around to actually being usable.
|
||||
* import : ^^
|
||||
* module : ^^
|
||||
|
||||
When it comes to expressions:
|
||||
|
||||
**There is no support for validating expressions.**
|
||||
Its difficult to parse without enough benefits (At the metaprogramming level).
|
||||
|
||||
When it comes to templates:
|
||||
I plan to add this only at the tail of the project parsing milestone.
|
||||
|
||||
**Only trivial template support is provided.**
|
||||
The intention is for only simple, non-recursive substitution.
|
||||
@ -78,54 +60,70 @@ Use at your own mental peril.
|
||||
|
||||
### The Data & Interface
|
||||
|
||||
As mentioned in [Usage](#usage), the user is provided Code objects by calling the constructor's functions to generate them or find existing matches.
|
||||
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:
|
||||
Data layout of AST struct (Subject to heavily change with upcoming redesign):
|
||||
|
||||
```cpp
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
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
|
||||
};
|
||||
AST* Params; // Function, Operator, Template
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Enum, Function, Namespace, Struct, Union
|
||||
AST* Macro; // Parameters
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front; // Used by CodeBody
|
||||
AST* Last; // Used by CodeParam
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back; // Used by CodeBody
|
||||
AST* Back;
|
||||
};
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
s32 Token; // Handle to the token, stored in the CodeFile (Otherwise unretrivable)
|
||||
```
|
||||
|
||||
*`CodeT` is a typedef for `ECode::Type` which has an underlying type of `u32`*
|
||||
@ -145,7 +143,7 @@ uw ArrSpecs_Cap =
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(s32)
|
||||
- sizeof(u32)
|
||||
)
|
||||
/ sizeof(SpecifierT) -1; // -1 for 4 extra bytes (Odd num of AST*)
|
||||
```
|
||||
@ -155,7 +153,14 @@ uw ArrSpecs_Cap =
|
||||
Data Notes:
|
||||
|
||||
* The allocator definitions used are exposed to the user incase they want to dictate memory usage
|
||||
* You'll find the memory handling in `init`, `gen_string_allocator`, `get_cached_string`, `make_code`.
|
||||
* You'll find the memory handling in `init`, `deinit`, `reset`, `gen_string_allocator`, `get_cached_string`, `make_code`.
|
||||
* Allocators are defined with the `AllocatorInfo` structure found in `dependencies\memory.hpp`
|
||||
* Most of the work is just defining the allocation procedure:
|
||||
|
||||
```cpp
|
||||
void* ( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags );
|
||||
```
|
||||
|
||||
* ASTs are wrapped for the user in a Code struct which is a wrapper for a AST* type.
|
||||
* Both AST and Code have member symbols but their data layout is enforced to be POD types.
|
||||
* This library treats memory failures as fatal.
|
||||
@ -168,15 +173,15 @@ Data Notes:
|
||||
* Linked lists used children nodes on bodies, and parameters.
|
||||
* Its intended to generate the AST in one go and serialize after. The constructors and serializer are designed to be a "one pass, front to back" setup.
|
||||
* Allocations can be tuned by defining the folloiwng macros:
|
||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
||||
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
|
||||
* `GEN_GLOBAL_BUCKET_SIZE` : Size of each bucket area for the global allocator
|
||||
* `GEN_LEX_ALLOCATOR_SIZE`
|
||||
* `GEN_CODEPOOL_NUM_BLOCKS` : Number of blocks per code pool in the code allocator
|
||||
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
|
||||
* `GEN_MAX_COMMENT_LINE_LENGTH` : Longest length a comment can have per line.
|
||||
* `GEN_MAX_NAME_LENGTH` : Max length of any identifier.
|
||||
* `GEN_MAX_UNTYPED_STR_LENGTH` : Max content length for any untyped code.
|
||||
* `GEN_SIZE_PER_STRING_ARENA` : Size per arena used with string caching.
|
||||
* `GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE` : token_fmt_va uses local_persit memory of this size for the hashtable.
|
||||
* `GEN_LEX_ALLOCATOR_SIZE`
|
||||
* `GEN_BUILDER_STR_BUFFER_RESERVE`
|
||||
|
||||
The following CodeTypes are used which the user may optionally use strong typing with if they enable: `GEN_ENFORCE_STRONG_CODE_TYPES`
|
||||
|
||||
@ -187,7 +192,6 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeConstructor
|
||||
* CodeDefine
|
||||
* CodeDestructor
|
||||
* CodePreprocessCond
|
||||
* CodeEnum
|
||||
* CodeExec
|
||||
* CodeExtern
|
||||
@ -195,10 +199,12 @@ The following CodeTypes are used which the user may optionally use strong typing
|
||||
* CodeFriend
|
||||
* CodeFn
|
||||
* CodeModule
|
||||
* CodeNamespace
|
||||
* CodeNS
|
||||
* CodeOperator
|
||||
* CodeOpCast
|
||||
* CodeParam : Has support for `for-range` iterating across parameters.
|
||||
* CodePreprocessCond
|
||||
* CodePragma
|
||||
* CodeSpecifiers : Has support for `for-range` iterating across specifiers.
|
||||
* CodeStruct
|
||||
* CodeTemplate
|
||||
@ -221,7 +227,7 @@ Retrieving a raw version of the ast can be done using the `raw()` function defin
|
||||
### Upfront Construction
|
||||
|
||||
All component ASTs must be previously constructed, and provided on creation of the code AST.
|
||||
The construction will fail and return Code::Invalid otherwise.
|
||||
The construction will fail and return CodeInvalid otherwise.
|
||||
|
||||
Interface :``
|
||||
|
||||
@ -231,6 +237,7 @@ Interface :``
|
||||
* def_comment
|
||||
* def_class
|
||||
* def_constructor
|
||||
* def_define
|
||||
* def_destructor
|
||||
* def_enum
|
||||
* def_execution
|
||||
@ -245,6 +252,8 @@ Interface :``
|
||||
* def_operator_cast
|
||||
* def_param
|
||||
* def_params
|
||||
* def_pragma
|
||||
* def_preprocess_cond
|
||||
* def_specifier
|
||||
* def_specifiers
|
||||
* def_struct
|
||||
@ -321,19 +330,6 @@ Interface :
|
||||
* parse_using
|
||||
* parse_variable
|
||||
|
||||
The lexing and parsing takes shortcuts from whats expected in the standard.
|
||||
|
||||
* Numeric literals are not check for validity.
|
||||
* The parse API treats any execution scope definitions with no validation and are turned into untyped Code ASTs.
|
||||
* *This includes the assignment of variables.*
|
||||
* Attributes ( `[[]]` (standard), `__declspec` (Microsoft), or `__attribute__` (GNU) )
|
||||
* Assumed to *come before specifiers* (`const`, `constexpr`, `extern`, `static`, etc) for a function
|
||||
* Or in the usual spot for class, structs, (*right after the declaration keyword*)
|
||||
* typedefs have attributes with the type (`parse_type`)
|
||||
* As a general rule; if its not available from the upfront constructors, its not available in the parsing constructors.
|
||||
* *Upfront constructors are not necessarily used in the parsing constructors, this is just a good metric to know what can be parsed.*
|
||||
* Parsing attributes can be extended to support user defined macros by defining `GEN_DEFINE_ATTRIBUTE_TOKENS` (see `gen.hpp` for the formatting)
|
||||
|
||||
Usage:
|
||||
|
||||
```cpp
|
||||
@ -342,13 +338,6 @@ Code <name> = parse_<function name>( string with code );
|
||||
Code <name> = def_<function name>( ..., parse_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
|
||||
Code <name> = make_<function name>( ... )
|
||||
{
|
||||
<name>->add( parse_<function name>(
|
||||
<string with code>
|
||||
));
|
||||
}
|
||||
```
|
||||
|
||||
### Untyped constructions
|
||||
@ -391,7 +380,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
|
||||
@ -408,25 +397,31 @@ The following are provided predefined by the library as they are commonly used:
|
||||
* `access_public`
|
||||
* `access_protected`
|
||||
* `access_private`
|
||||
* `attrib_api_export`
|
||||
* `attrib_api_import`
|
||||
* `module_global_fragment`
|
||||
* `module_private_fragment`
|
||||
* `fmt_newline`
|
||||
* `param_varaidc` (Used for varadic definitions)
|
||||
* `pragma_once`
|
||||
* `preprocess_else`
|
||||
* `preprocess_endif`
|
||||
* `pragma_once`
|
||||
* `spec_const`
|
||||
* `spec_consteval`
|
||||
* `spec_constexpr`
|
||||
* `spec_constinit`
|
||||
* `spec_extern_linkage` (extern)
|
||||
* `spec_final`
|
||||
* `spec_forceinline`
|
||||
* `spec_global` (global macro)
|
||||
* `spec_inline`
|
||||
* `spec_internal_linkage` (internal macro)
|
||||
* `spec_local_persist` (local_persist macro)
|
||||
* `spec_mutable`
|
||||
* `spec_neverinline`
|
||||
* `spec_override`
|
||||
* `spec_ptr`
|
||||
* `spec_pure`
|
||||
* `spec_ref`
|
||||
* `spec_register`
|
||||
* `spec_rvalue`
|
||||
@ -434,10 +429,6 @@ The following are provided predefined by the library as they are commonly used:
|
||||
* `spec_thread_local`
|
||||
* `spec_virtual`
|
||||
* `spec_volatile`
|
||||
* `spec_type_signed`
|
||||
* `spec_type_unsigned`
|
||||
* `spec_type_short`
|
||||
* `spec_type_long`
|
||||
* `t_empty` (Used for varaidc macros)
|
||||
* `t_auto`
|
||||
* `t_void`
|
||||
@ -459,8 +450,8 @@ Optionally the following may be defined if `GEN_DEFINE_LIBRARY_CODE_CONSTANTS` i
|
||||
* `t_u16`
|
||||
* `t_u32`
|
||||
* `t_u64`
|
||||
* `t_sw`
|
||||
* `t_uw`
|
||||
* `t_sw` (ssize_t)
|
||||
* `t_uw` (size_t)
|
||||
* `t_f32`
|
||||
* `t_f64`
|
||||
|
||||
@ -471,13 +462,14 @@ The AST and constructors will be able to validate that the arguments provided fo
|
||||
* If return type must match a parameter
|
||||
* If number of parameters is correct
|
||||
* If added as a member symbol to a class or struct, that operator matches the requirements for the class (types match up)
|
||||
* There is no support for validating new & delete operations (yet)
|
||||
|
||||
The user is responsible for making sure the code types provided are correct
|
||||
and have the desired specifiers assigned to them beforehand.
|
||||
|
||||
## Code generation and modification
|
||||
|
||||
There are three provided file interfaces:
|
||||
There are three provided auxillary interfaces:
|
||||
|
||||
* Builder
|
||||
* Editor
|
||||
@ -488,51 +480,10 @@ Editor and Scanner are disabled by default, use `GEN_FEATURE_EDITOR` and `GEN_FE
|
||||
### Builder is a similar object to the jai language's string_builder
|
||||
|
||||
* The purpose of it is to generate a file.
|
||||
* A file is specified and opened for writing using the open( file_path) ) function.
|
||||
* A file is specified and opened for writing using the open( file_path) function.
|
||||
* The code is provided via print( code ) function will be serialized to its buffer.
|
||||
* When all serialization is finished, use the write() command to write the buffer to the file.
|
||||
|
||||
### Editor is for editing a series of files based on a set of requests provided to it
|
||||
### Scanner Auxillary Interface
|
||||
|
||||
**Note: Not implemented yet**
|
||||
|
||||
* The purpose is to overrite a specific file, it places its contents in a buffer to scan.
|
||||
* Requests are populated using the following interface:
|
||||
* add : Add code.
|
||||
* remove : Remove code.
|
||||
* replace: Replace code.
|
||||
|
||||
All three have the same parameters with exception to remove which only has SymbolInfo and Policy:
|
||||
|
||||
* SymbolInfo:
|
||||
* File : The file the symbol resides in. Leave null to indicate to search all files. Leave null to indicated all-file search.
|
||||
* Marker : #define symbol that indicates a location or following signature is valid to manipulate. Leave null to indicate the signature should only be used.
|
||||
* Signature : Use a Code symbol to find a valid location to manipulate, can be further filtered with the marker. Leave null to indicate the marker should only be used.
|
||||
|
||||
* Policy : Additional policy info for completing the request (empty for now)
|
||||
* Code : Code to inject if adding, or replace existing code with.
|
||||
|
||||
Additionally if `GEN_FEATURE_EDITOR_REFACTOR` is defined, refactor( file_path, specification_path ) wil be made available.
|
||||
Refactor is based of the refactor library and uses its interface.
|
||||
It will on call add a request to the queue to run the refactor script on the file.
|
||||
|
||||
### Scanner allows the user to generate Code ASTs by reading files
|
||||
|
||||
**Note: Not implemented yet**
|
||||
|
||||
* The purpose is to grab definitions to generate metadata or generate new code from these definitions.
|
||||
* Requests are populated using the add( SymbolInfo, Policy ) function. The symbol info is the same as the one used for the editor. So is the case with Policy.
|
||||
|
||||
The file will only be read from, no writing supported.
|
||||
|
||||
One great use case is for example: generating the single-header library for gencpp!
|
||||
|
||||
### Additional Info (Editor and Scanner)
|
||||
|
||||
When all requests have been populated, call process_requests().
|
||||
It will provide an output of receipt data of the results when it completes.
|
||||
|
||||
Files may be added to the Editor and Scanner additionally with add_files( num, files ).
|
||||
This is intended for when you have requests that are for multiple files.
|
||||
|
||||
Request queue in both Editor and Scanner are cleared once process_requests completes.
|
||||
Provides *(eventually)* `scan_file` to automatically populate a CodeFile which contains a parsed AST (`Code`) of the file, with any contextual failures that are reported from the parser.
|
||||
|
33
gencpp.10x
33
gencpp.10x
@ -8,21 +8,22 @@
|
||||
<ShowEmptyFolders>true</ShowEmptyFolders>
|
||||
<IsVirtual>false</IsVirtual>
|
||||
<IsFolder>false</IsFolder>
|
||||
<BuildCommand>powershell ./scripts/test.gen_run.ps1</BuildCommand>
|
||||
<BuildCommand>pwsh ./scripts/build.ps1 msvc debug bootstrap</BuildCommand>
|
||||
<RebuildCommand></RebuildCommand>
|
||||
<BuildFileCommand></BuildFileCommand>
|
||||
<CleanCommand>powershell ./scripts/clean.ps1</CleanCommand>
|
||||
<CleanCommand>pwsh ./scripts/clean.ps1</CleanCommand>
|
||||
<BuildWorkingDirectory></BuildWorkingDirectory>
|
||||
<CancelBuild></CancelBuild>
|
||||
<RunCommand>./test/gen/build/gencpp.exe</RunCommand>
|
||||
<RunCommandWorkingDirectory></RunCommandWorkingDirectory>
|
||||
<DebugCommand>powershell ./scripts/build.ps1</DebugCommand>
|
||||
<DebugCommand>pwsh ./scripts/build.ps1</DebugCommand>
|
||||
<ExePathCommand>./test/gen/build/gencpp.exe</ExePathCommand>
|
||||
<DebugSln>gencpp.sln</DebugSln>
|
||||
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
||||
<DebugSln></DebugSln>
|
||||
<UseVisualStudioEnvBat>true</UseVisualStudioEnvBat>
|
||||
<Configurations>
|
||||
<Configuration>Debug</Configuration>
|
||||
<Configuration>Release</Configuration>
|
||||
<Configuration>bootstrap debug</Configuration>
|
||||
</Configurations>
|
||||
<Platforms>
|
||||
<Platform>x64</Platform>
|
||||
@ -31,15 +32,18 @@
|
||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\ATLMFC\include</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\VS\include</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
|
||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
|
||||
</AdditionalIncludePaths>
|
||||
<Defines>
|
||||
<Define>GEN_TIME</Define>
|
||||
<Define>GEN_SYSTEM_WINDOWS</Define>
|
||||
<Define>GEN_INTELLISENSE_DIRECTIVES</Define>
|
||||
<Define>GEN_EXECUTION_EXPRESSION_SUPPORT</Define>
|
||||
</Defines>
|
||||
<ConfigProperties>
|
||||
<ConfigAndPlatform>
|
||||
@ -47,10 +51,19 @@
|
||||
<Defines></Defines>
|
||||
<ForceIncludes></ForceIncludes>
|
||||
</ConfigAndPlatform>
|
||||
<ConfigAndPlatform>
|
||||
<Name>bootstrap debug:x64</Name>
|
||||
<Defines></Defines>
|
||||
<ForceIncludes></ForceIncludes>
|
||||
</ConfigAndPlatform>
|
||||
<Config>
|
||||
<Name>Debug</Name>
|
||||
<Defines></Defines>
|
||||
</Config>
|
||||
<Config>
|
||||
<Name>bootstrap debug</Name>
|
||||
<Defines></Defines>
|
||||
</Config>
|
||||
<Platform>
|
||||
<Name>x64</Name>
|
||||
<Defines></Defines>
|
||||
|
41
gencpp.sln
41
gencpp.sln
@ -7,20 +7,37 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gencpp", "gencpp.vcxproj",
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
bootstrap debug|x64 = bootstrap debug|x64
|
||||
bootstrap debug|x86 = bootstrap debug|x86
|
||||
bootstrap release|x64 = bootstrap release|x64
|
||||
bootstrap release|x86 = bootstrap release|x86
|
||||
singleheader debug|x64 = singleheader debug|x64
|
||||
singleheader debug|x86 = singleheader debug|x86
|
||||
singleheader release|x64 = singleheader release|x64
|
||||
singleheader release|x86 = singleheader release|x86
|
||||
test debug|x64 = test debug|x64
|
||||
test debug|x86 = test debug|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x64.Build.0 = Debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Debug|x86.Build.0 = Debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x64.ActiveCfg = Release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x64.Build.0 = Release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x86.ActiveCfg = Release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.Release|x86.Build.0 = Release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x64.ActiveCfg = bootstrap release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x64.Build.0 = bootstrap release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x86.ActiveCfg = bootstrap debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap debug|x86.Build.0 = bootstrap debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x64.ActiveCfg = bootstrap release|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x86.ActiveCfg = bootstrap release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.bootstrap release|x86.Build.0 = bootstrap release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x64.ActiveCfg = singleheader debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x64.Build.0 = singleheader debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x86.ActiveCfg = singleheader debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader debug|x86.Build.0 = singleheader debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x64.ActiveCfg = bootstrap debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x64.Build.0 = bootstrap debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x86.ActiveCfg = singleheader release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.singleheader release|x86.Build.0 = singleheader release|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x64.ActiveCfg = test debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x64.Build.0 = test debug|x64
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x86.ActiveCfg = test debug|Win32
|
||||
{53AF600D-C09C-4F39-83E0-E022AA9479F2}.test debug|x86.Build.0 = test debug|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
370
gencpp.vcxproj
370
gencpp.vcxproj
@ -1,20 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<ProjectConfiguration Include="bootstrap debug|Win32">
|
||||
<Configuration>bootstrap debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<ProjectConfiguration Include="bootstrap debug|x64">
|
||||
<Configuration>bootstrap debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<ProjectConfiguration Include="bootstrap release|Win32">
|
||||
<Configuration>bootstrap release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="bootstrap release|x64">
|
||||
<Configuration>bootstrap release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader debug|Win32">
|
||||
<Configuration>singleheader debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader debug|x64">
|
||||
<Configuration>singleheader debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader release|Win32">
|
||||
<Configuration>singleheader release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="singleheader release|x64">
|
||||
<Configuration>singleheader release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="test debug|Win32">
|
||||
<Configuration>test debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="test debug|x64">
|
||||
<Configuration>test debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
@ -25,24 +49,54 @@
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Makefile</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
@ -50,97 +104,195 @@
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;NDEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<NMakeBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_TIME;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)thirdparty;$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(ProjectDir)test;$(SourcePath)</SourcePath>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<NMakeBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1"</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>powershell.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_TIME;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)thirdparty;$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(ProjectDir)test;$(SourcePath)</SourcePath>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|Win32'">
|
||||
<NMakeBuildCommandLine>./scripts/build.ps1</NMakeBuildCommandLine>
|
||||
<NMakeCleanCommandLine>./scripts/clean.ps1</NMakeCleanCommandLine>
|
||||
<NMakeReBuildCommandLine>./scripts/build.ps1</NMakeReBuildCommandLine>
|
||||
<NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug bootstrap</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug test</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine />
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc debug singleheader</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc release singleheader</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
|
||||
<NMakeBuildCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\build.ps1" msvc release bootstrap</NMakeBuildCommandLine>
|
||||
<NMakeReBuildCommandLine>
|
||||
</NMakeReBuildCommandLine>
|
||||
<NMakeCleanCommandLine>pwsh.exe -ExecutionPolicy Unrestricted -File "$(ProjectDir)scripts\clean.ps1"</NMakeCleanCommandLine>
|
||||
<NMakePreprocessorDefinitions>GEN_INTELLISENSE_DIRECTIVES;GEN_TIME;GEN_BENCHMARK;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
|
||||
<IncludePath>$(ProjectDir)project;$(ProjectDir)test;$(IncludePath)</IncludePath>
|
||||
<SourcePath>$(ProjectDir)project;$(SourcePath)</SourcePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
|
||||
<ClCompile>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include=".editorconfig" />
|
||||
<None Include="project\enums\AttributeTokens.csv" />
|
||||
<None Include="project\enums\ECode.csv" />
|
||||
<None Include="project\enums\EOperator.csv" />
|
||||
<None Include="project\enums\ESpecifier.csv" />
|
||||
<None Include="project\enums\ETokType.csv" />
|
||||
<None Include="Readme.md" />
|
||||
<None Include="scripts\.clang-format" />
|
||||
<None Include="scripts\build.ci.ps1" />
|
||||
<None Include="scripts\build.ps1" />
|
||||
<None Include="scripts\clean.ps1" />
|
||||
<None Include="scripts\gen.ps1" />
|
||||
<None Include="scripts\genccp.natstepfilter" />
|
||||
<None Include="scripts\gencpp.refactor" />
|
||||
<None Include="scripts\get_sources.ps1" />
|
||||
<None Include="scripts\helpers\devshell.ps1" />
|
||||
<None Include="scripts\helpers\target_arch.psm1" />
|
||||
<None Include="scripts\package_release.ps1" />
|
||||
<None Include="scripts\refactor.ps1" />
|
||||
<None Include="test\gen\meson.build" />
|
||||
<None Include="test\meson.build" />
|
||||
<None Include="test\Readme.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="project\components\gen.data_structures.hpp" />
|
||||
<ClInclude Include="project\components\gen.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\code_types.hpp" />
|
||||
<ClInclude Include="project\components\gen\ast_inlines.hpp" />
|
||||
<ClInclude Include="project\components\gen\ecode.hpp" />
|
||||
<ClInclude Include="project\components\gen\eoperator.hpp" />
|
||||
<ClInclude Include="project\components\gen\especifier.hpp" />
|
||||
<ClInclude Include="project\components\header_end.hpp" />
|
||||
<ClInclude Include="project\components\header_start.hpp" />
|
||||
<ClInclude Include="project\components\inlines.hpp" />
|
||||
<ClInclude Include="project\components\interface.hpp" />
|
||||
<ClInclude Include="project\components\types.hpp" />
|
||||
<ClInclude Include="project\dependencies\basic_types.hpp" />
|
||||
<ClInclude Include="project\dependencies\containers.hpp" />
|
||||
<ClInclude Include="project\dependencies\debug.hpp" />
|
||||
<ClInclude Include="project\dependencies\filesystem.hpp" />
|
||||
<ClInclude Include="project\dependencies\hashing.hpp" />
|
||||
<ClInclude Include="project\dependencies\header_start.hpp" />
|
||||
<ClInclude Include="project\dependencies\macros.hpp" />
|
||||
<ClInclude Include="project\dependencies\memory.hpp" />
|
||||
<ClInclude Include="project\dependencies\parsing.hpp" />
|
||||
<ClInclude Include="project\dependencies\printing.hpp" />
|
||||
<ClInclude Include="project\dependencies\strings.hpp" />
|
||||
<ClInclude Include="project\dependencies\string_ops.hpp" />
|
||||
<ClInclude Include="project\dependencies\timing.hpp" />
|
||||
<ClInclude Include="project\gen.dep.hpp" />
|
||||
<ClInclude Include="project\gen.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\CURSED_TYPEDEF.h" />
|
||||
<ClInclude Include="test\DummyInclude.hpp" />
|
||||
<ClInclude Include="test\Parsed\Buffer.Parsed.hpp" />
|
||||
<ClInclude Include="test\Parsed\HashTable.Parsed.hpp" />
|
||||
@ -157,57 +309,65 @@
|
||||
<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\code_serialization.cpp" />
|
||||
<ClCompile Include="project\components\gen\etoktype.cpp" />
|
||||
<ClCompile Include="project\components\interface.cpp" />
|
||||
<ClCompile Include="project\components\interface.parsing.cpp" />
|
||||
<ClCompile Include="project\components\interface.untyped.cpp" />
|
||||
<ClCompile Include="project\components\interface.upfront.cpp" />
|
||||
<ClCompile Include="project\components\lexer.cpp" />
|
||||
<ClCompile Include="project\components\parser.cpp" />
|
||||
<ClCompile Include="project\components\src_start.cpp" />
|
||||
<ClCompile Include="project\components\static_data.cpp" />
|
||||
<ClCompile Include="project\dependencies\debug.cpp" />
|
||||
<ClCompile Include="project\dependencies\filesystem.cpp" />
|
||||
<ClCompile Include="project\dependencies\hashing.cpp" />
|
||||
<ClCompile Include="project\dependencies\memory.cpp" />
|
||||
<ClCompile Include="project\dependencies\parsing.cpp" />
|
||||
<ClCompile Include="project\dependencies\printing.cpp" />
|
||||
<ClCompile Include="project\dependencies\src_start.cpp" />
|
||||
<ClCompile Include="project\dependencies\strings.cpp" />
|
||||
<ClCompile Include="project\dependencies\string_ops.cpp" />
|
||||
<ClCompile Include="project\dependencies\timing.cpp" />
|
||||
<ClCompile Include="project\Example.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>
|
||||
<ItemGroup>
|
||||
<Folder Include="singleheader\gen\" />
|
||||
</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,100 @@
|
||||
<ClCompile Include="test\test.parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen.ast.cpp">
|
||||
<ClCompile Include="project\components\ast.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen.interface.parsing.cpp">
|
||||
<ClCompile Include="project\components\ast_case_macros.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen.interface.upfront.cpp">
|
||||
<ClCompile Include="project\components\interface.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.dep.cpp">
|
||||
<ClCompile Include="project\components\interface.parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.file_handling.cpp">
|
||||
<ClCompile Include="project\components\interface.upfront.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.memory.cpp">
|
||||
<ClCompile Include="project\components\src_start.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.parsing.cpp">
|
||||
<ClCompile Include="project\components\static_data.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\gen.printing.cpp">
|
||||
<ClCompile Include="project\bootstrap.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\debug.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\filesystem.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\hashing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\memory.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\printing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\src_start.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\string_ops.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\strings.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\dependencies\timing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\auxillary\builder.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\auxillary\scanner.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="singleheader\singleheader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\test.singleheader_ast.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\parsed\test.parsing.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\upfront\test.upfront.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\validate_singleheader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="test\validate_bootstrap.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\interface.untyped.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\gen\etoktype.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\Example.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\parser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\lexer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="project\components\code_serialization.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@ -80,27 +143,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 +182,112 @@
|
||||
<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\ast.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen.interface.hpp">
|
||||
<ClInclude Include="project\components\ast_types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen.types.hpp">
|
||||
<ClInclude Include="project\components\header_end.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.basic_types.hpp">
|
||||
<ClInclude Include="project\components\header_start.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.containers.hpp">
|
||||
<ClInclude Include="project\components\inlines.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.dep.hpp">
|
||||
<ClInclude Include="project\components\interface.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.file_handling.hpp">
|
||||
<ClInclude Include="project\components\types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.header_start.hpp">
|
||||
<ClInclude Include="project\helpers\helper.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.macros.hpp">
|
||||
<ClInclude Include="project\helpers\pop_ignores.inline.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.memory.hpp">
|
||||
<ClInclude Include="project\helpers\push_ignores.inline.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.parsing.hpp">
|
||||
<ClInclude Include="project\helpers\undef.macros.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.printing.hpp">
|
||||
<ClInclude Include="project\dependencies\basic_types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.string.hpp">
|
||||
<ClInclude Include="project\dependencies\containers.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\gen.string_ops.hpp">
|
||||
<ClInclude Include="project\dependencies\debug.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\filesystem\gen.builder.hpp">
|
||||
<ClInclude Include="project\dependencies\filesystem.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\filesystem\gen.editor.hpp">
|
||||
<ClInclude Include="project\dependencies\hashing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\filesystem\gen.scanner.hpp">
|
||||
<ClInclude Include="project\dependencies\header_start.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\helpers\gen.pop_ignores.inline.hpp">
|
||||
<ClInclude Include="project\dependencies\macros.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\helpers\gen.push_ignores.inline.hpp">
|
||||
<ClInclude Include="project\dependencies\memory.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\helpers\gen.undef.macros.hpp">
|
||||
<ClInclude Include="project\dependencies\parsing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\printing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\string_ops.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\strings.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\dependencies\timing.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\auxillary\builder.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\auxillary\editor.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\auxillary\scanner.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="singleheader\components\header_start.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\ast_inlines.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\ecode.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\eoperator.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\gen\especifier.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="test\CURSED_TYPEDEF.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="project\components\code_types.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
@ -222,13 +297,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\enums\AttributeTokens.csv" />
|
||||
<None Include="project\enums\ECode.csv" />
|
||||
<None Include="project\enums\EOperator.csv" />
|
||||
<None Include="project\enums\ESpecifier.csv" />
|
||||
<None Include="project\enums\ETokType.csv" />
|
||||
<None Include="scripts\helpers\devshell.ps1" />
|
||||
<None Include="scripts\helpers\target_arch.psm1" />
|
||||
<None Include="scripts\package_release.ps1" />
|
||||
<None Include="scripts\refactor.ps1" />
|
||||
<None Include="scripts\.clang-format" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include=".vscode\gencpp.natvis" />
|
||||
|
@ -3,14 +3,29 @@
|
||||
<PropertyGroup>
|
||||
<ShowAllFiles>true</ShowAllFiles>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap debug|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>C:\projects\gencpp\test\gen\build\gencpp.exe</LocalDebuggerCommand>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='test debug|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>C:\projects\gencpp\test\gen\build\gencpp.exe</LocalDebuggerCommand>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader debug|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='singleheader release|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='bootstrap release|x64'">
|
||||
<LocalDebuggerAttach>false</LocalDebuggerAttach>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
<LocalDebuggerCommand>$(ProjectDir)project\build\bootstrap.exe</LocalDebuggerCommand>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -1,7 +1,6 @@
|
||||
# Documentation
|
||||
|
||||
The library is fragmented into a series of headers and sources files meant to be scanned in and then generated to a tailored format for the target
|
||||
`gen` files.
|
||||
The library is fragmented into a series of headers and source files meant to be scanned in and then generated to a tailored format for the target `gen` files.
|
||||
|
||||
The principal (user) files are `gen.hpp` and `gen.cpp`.
|
||||
They contain includes for its various components: `components/<component_name>.<hpp/cpp>`
|
||||
@ -9,12 +8,9 @@ They contain includes for its various components: `components/<component_name>.<
|
||||
Dependencies are bundled into `gen.dep.<hpp/cpp>`.
|
||||
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`
|
||||
|
||||
The fle processors are in their own respective files. (Ex: `file_processors/<file_processor>.<hpp/cpp>` )
|
||||
They directly include `depedencies/file_handling.<hpp/cpp>` as the core library does not include file processing by defualt.
|
||||
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
|
||||
|
||||
**TODO : Right now the library is not finished, as such the first self-hosting iteration is still WIP**
|
||||
Both libraries use *pre-generated* (self-hosting I guess) version of the library to then generate the latest version of itself.
|
||||
(sort of a verification that the generated version is equivalent).
|
||||
|
||||
The default `gen.bootstrap.cpp` located in the project folder is meant to be produce a standard segmented library, where the components of the library
|
||||
have relatively dedicated header and source files. Dependencies included at the top of the file and each header starting with a pragma once.
|
||||
@ -28,21 +24,21 @@ Feature Macros:
|
||||
* This is auto-generated if using the bootstrap or single-header generation
|
||||
* *Note: The user will use the `AttributeTokens.csv` when the library is fully self-hosting.*
|
||||
* `GEN_DEFINE_LIBRARY_CORE_CONSTANTS` : Optional typename codes as they are non-standard to C/C++ and not necessary to library usage
|
||||
* `GEN_DONT_USE_NAMESPACE` : By default, the library is wrapped in a `gen` namespace, this will disable that expose it to the global scope.
|
||||
* `GEN_DONT_ENFORCE_GEN_TIME_GUARD` : By default, the library ( gen.hpp/ gen.cpp ) expects the macro `GEN_TIME` to be defined, this disables that.
|
||||
* `GEN_ENFORCE_STRONG_CODE_TYPES` : Enforces casts to filtered code types.
|
||||
* `GEN_EXPOSE_BACKEND` : Will expose symbols meant for internal use only.
|
||||
* `GEN_ROLL_OWN_DEPENDENCIES` : Optional override so that user may define the dependencies themselves.
|
||||
* `GEN_DONT_ALLOW_INVALID_CODE` (Not implemented yet) : Will fail when an invalid code is constructed, parsed, or serialized.
|
||||
|
||||
## On multi-threading
|
||||
|
||||
Currently unsupported. The following changes would have to be made:
|
||||
Currently unsupported. I want the library to be *stable* and *correct*, with the addition of exhausting all basic single-threaded optimizations before I consider multi-threading.
|
||||
|
||||
## Extending the library
|
||||
|
||||
This library is relatively very small, and can be extended without much hassle.
|
||||
|
||||
The convention you'll see used throughout the API of the library is as follows:
|
||||
The convention you'll see used throughout the interface of the library is as follows:
|
||||
|
||||
1. Check name or parameters to make sure they are valid for the construction requested
|
||||
2. Create a code object using `make_code`.
|
||||
@ -54,4 +50,10 @@ Names or Content fields are interned strings and thus showed be cached using `ge
|
||||
`def_operator` is the most sophisticated constructor as it has multiple permutations of definitions that could be created that are not trivial to determine if valid.
|
||||
|
||||
The library has its code segmented into component files, use it to help create a derived version without needing to have to rewrite a generated file directly or build on top of the header via composition or inheritance.
|
||||
When the scanner is implemented, this will be even easier to customize.
|
||||
|
||||
The parser is documented under `docs/Parsing.md` and `docs/Parser_Algo.md`.
|
||||
|
||||
## A note on compilation and runtime generation speed
|
||||
|
||||
The library is designed to be fast to compile and generate code at runtime as fast as resonable possible on a debug build.
|
||||
Its recommended that your metaprogam be compiled using a single translation unit (unity build).
|
||||
|
59
project/auxillary/builder.cpp
Normal file
59
project/auxillary/builder.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "builder.hpp"
|
||||
#endif
|
||||
|
||||
Builder Builder::open( char const* path )
|
||||
{
|
||||
Builder result;
|
||||
|
||||
FileError error = file_open_mode( & result.File, EFileMode_WRITE, path );
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
log_failure( "gen::File::open - Could not open file: %s", path);
|
||||
return result;
|
||||
}
|
||||
|
||||
result.Buffer = String::make_reserve( GlobalAllocator, Builder_StrBufferReserve );
|
||||
|
||||
// log_fmt("$Builder - Opened file: %s\n", result.File.filename );
|
||||
return result;
|
||||
}
|
||||
|
||||
void Builder::pad_lines( s32 num )
|
||||
{
|
||||
Buffer.append( "\n" );
|
||||
}
|
||||
|
||||
void Builder::print( Code code )
|
||||
{
|
||||
String str = code->to_string();
|
||||
// const sw len = str.length();
|
||||
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
|
||||
Buffer.append( str );
|
||||
}
|
||||
|
||||
void Builder::print_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
|
||||
Buffer.append( buf, res );
|
||||
}
|
||||
|
||||
void Builder::write()
|
||||
{
|
||||
bool result = file_write( & File, Buffer, Buffer.length() );
|
||||
|
||||
if ( result == false )
|
||||
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
|
||||
|
||||
log_fmt( "Generated: %s\n", File.filename );
|
||||
file_close( & File );
|
||||
Buffer.free();
|
||||
}
|
20
project/auxillary/builder.hpp
Normal file
20
project/auxillary/builder.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "gen.hpp"
|
||||
#endif
|
||||
|
||||
struct Builder
|
||||
{
|
||||
FileInfo File;
|
||||
String Buffer;
|
||||
|
||||
static Builder open( char const* path );
|
||||
|
||||
void pad_lines( s32 num );
|
||||
|
||||
void print( Code );
|
||||
void print_fmt( char const* fmt, ... );
|
||||
|
||||
void write();
|
||||
};
|
||||
|
3
project/auxillary/scanner.cpp
Normal file
3
project/auxillary/scanner.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "scanner.hpp"
|
||||
#endif
|
159
project/auxillary/scanner.hpp
Normal file
159
project/auxillary/scanner.hpp
Normal file
@ -0,0 +1,159 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "gen.hpp"
|
||||
#endif
|
||||
|
||||
// This is a simple file reader that reads the entire file into memory.
|
||||
// It has an extra option to skip the first few lines for undesired includes.
|
||||
// This is done so that includes can be kept in dependency and component files so that intellisense works.
|
||||
Code scan_file( char const* path )
|
||||
{
|
||||
FileInfo file;
|
||||
|
||||
FileError error = file_open_mode( & file, EFileMode_READ, path );
|
||||
if ( error != EFileError_NONE )
|
||||
{
|
||||
GEN_FATAL( "scan_file: Could not open: %s", path );
|
||||
}
|
||||
|
||||
sw fsize = file_size( & file );
|
||||
if ( fsize <= 0 )
|
||||
{
|
||||
GEN_FATAL("scan_file: %s is empty", path );
|
||||
}
|
||||
|
||||
String str = String::make_reserve( GlobalAllocator, fsize );
|
||||
file_read( & file, str, fsize );
|
||||
str.get_header().Length = fsize;
|
||||
|
||||
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
|
||||
// Its designed so that the directive should be the first thing in the file.
|
||||
// Anything that comes before it will also be omitted.
|
||||
{
|
||||
#define current (*scanner)
|
||||
#define matched 0
|
||||
#define move_fwd() do { ++ scanner; -- left; } while (0)
|
||||
const StrC directive_start = txt( "ifdef" );
|
||||
const StrC directive_end = txt( "endif" );
|
||||
const StrC def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
|
||||
|
||||
bool found_directive = false;
|
||||
char const* scanner = str.Data;
|
||||
s32 left = fsize;
|
||||
while ( left )
|
||||
{
|
||||
// Processing directive.
|
||||
if ( current == '#' )
|
||||
{
|
||||
move_fwd();
|
||||
while ( left && char_is_space( current ) )
|
||||
move_fwd();
|
||||
|
||||
if ( ! found_directive )
|
||||
{
|
||||
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
|
||||
{
|
||||
scanner += directive_start.Len;
|
||||
left -= directive_start.Len;
|
||||
|
||||
while ( left && char_is_space( current ) )
|
||||
move_fwd();
|
||||
|
||||
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
|
||||
{
|
||||
scanner += def_intellisense.Len;
|
||||
left -= def_intellisense.Len;
|
||||
|
||||
found_directive = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip to end of line
|
||||
while ( left && current != '\r' && current != '\n' )
|
||||
move_fwd();
|
||||
move_fwd();
|
||||
|
||||
if ( left && current == '\n' )
|
||||
move_fwd();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
|
||||
{
|
||||
scanner += directive_end.Len;
|
||||
left -= directive_end.Len;
|
||||
|
||||
// Skip to end of line
|
||||
while ( left && current != '\r' && current != '\n' )
|
||||
move_fwd();
|
||||
move_fwd();
|
||||
|
||||
if ( left && current == '\n' )
|
||||
move_fwd();
|
||||
|
||||
// sptr skip_size = fsize - left;
|
||||
if ( (scanner + 2) >= ( str.Data + fsize ) )
|
||||
{
|
||||
mem_move( str, scanner, left );
|
||||
str.get_header().Length = left;
|
||||
break;
|
||||
}
|
||||
|
||||
mem_move( str, scanner, left );
|
||||
str.get_header().Length = left;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
move_fwd();
|
||||
}
|
||||
#undef move_fwd
|
||||
#undef matched
|
||||
#undef current
|
||||
}
|
||||
|
||||
file_close( & file );
|
||||
return untyped_str( str );
|
||||
}
|
||||
|
||||
#if 0
|
||||
struct CodeFile
|
||||
{
|
||||
using namespace Parser;
|
||||
|
||||
String FilePath;
|
||||
TokArray Tokens;
|
||||
Array<ParseFailure> ParseFailures;
|
||||
Code CodeRoot;
|
||||
};
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
struct ParseFailure
|
||||
{
|
||||
String Reason;
|
||||
Code Node;
|
||||
};
|
||||
}
|
||||
|
||||
CodeFile scan_file( char const* path )
|
||||
{
|
||||
using namespace Parser;
|
||||
|
||||
CodeFile
|
||||
result = {};
|
||||
result.FilePath = String::make( GlobalAllocator, path );
|
||||
|
||||
Code code = scan_file( path );
|
||||
result.CodeRoot = code;
|
||||
|
||||
ParseContext context = parser_get_last_context();
|
||||
result.Tokens = context.Tokens;
|
||||
result.ParseFailures = context.Failures;
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
126
project/auxillary/vis_ast/build.ps1
Normal file
126
project/auxillary/vis_ast/build.ps1
Normal file
@ -0,0 +1,126 @@
|
||||
Clear-Host
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_scripts = Join-Path $path_root 'scripts'
|
||||
|
||||
$target_arch = Join-Path $path_scripts 'helpers/target_arch.psm1'
|
||||
$devshell = Join-Path $path_scripts 'helpers/devshell.ps1'
|
||||
$format_cpp = Join-Path $path_scripts 'helpers/format_cpp.psm1'
|
||||
$incremental_checks = Join-Path $path_scripts 'helpers/incremental_checks.ps1'
|
||||
$vendor_toolchain = Join-Path $path_scripts 'helpers/vendor_toolchain.ps1'
|
||||
|
||||
$path_project = Join-Path $path_root 'project'
|
||||
$path_aux = Join-Path $path_project 'auxillary'
|
||||
$path_vis_root = Join-Path $path_aux 'vis_ast'
|
||||
$path_binaries = Join-Path $path_vis_root 'binaries'
|
||||
$path_build = Join-Path $path_vis_root 'build'
|
||||
$path_code = Join-Path $path_vis_root 'code'
|
||||
$path_deps = Join-Path $path_vis_root 'dependencies'
|
||||
$path_win32 = Join-Path $path_code 'win32'
|
||||
|
||||
Import-Module $target_arch
|
||||
Import-Module $format_cpp
|
||||
|
||||
#region Arguments
|
||||
$vendor = $null
|
||||
$optimize = $null
|
||||
$debug = $null
|
||||
$analysis = $false
|
||||
$dev = $false
|
||||
$verbose = $null
|
||||
$platform = $null
|
||||
$module_specified = $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 }
|
||||
"optimize" { $optimize = $true }
|
||||
"debug" { $debug = $true }
|
||||
"analysis" { $analysis = $true }
|
||||
"dev" { $dev = $true }
|
||||
"verbose" { $verbose = $true }
|
||||
"platform" { $platform = $true; $module_specified = $true }
|
||||
}
|
||||
}}
|
||||
#endregion Argument
|
||||
|
||||
if ( -not $module_specified )
|
||||
{
|
||||
$platform = $true
|
||||
}
|
||||
|
||||
# Load up toolchain configuraion
|
||||
. $vendor_toolchain
|
||||
. $incremental_checks
|
||||
|
||||
write-host "Building Vis AST with $vendor"
|
||||
|
||||
if ( (Test-Path $path_build) -eq $false ) {
|
||||
New-Item $path_build -ItemType Directory
|
||||
}
|
||||
|
||||
if ( (Test-Path $path_binaries) -eq $false ) {
|
||||
New-Item $path_binaries -ItemType Directory
|
||||
}
|
||||
|
||||
$path_raylib = join-path $path_deps 'raylib'
|
||||
$path_raylib_inc = join-path $path_raylib 'include'
|
||||
$path_raylib_lib = join-path $path_raylib 'lib'
|
||||
|
||||
$path_raylib_dll = join-path $path_raylib_lib 'raylib.dll'
|
||||
$path_raylib_dll_bin = join-path $path_binaries 'raylib.dll'
|
||||
|
||||
Copy-Item $path_raylib_dll $path_raylib_dll_bin -Force
|
||||
|
||||
$includes = @(
|
||||
$path_code,
|
||||
$path_deps
|
||||
)
|
||||
|
||||
write-host $path_code
|
||||
|
||||
foreach ( $include in $includes ) {
|
||||
Write-Host 'include: ' $include
|
||||
}
|
||||
|
||||
# Microsoft
|
||||
$lib_gdi32 = 'Gdi32.lib'
|
||||
$lib_xinput = 'Xinput.lib'
|
||||
$lib_user32 = 'User32.lib'
|
||||
$lib_winmm = 'Winmm.lib'
|
||||
|
||||
$stack_size = 1024 * 1024 * 4
|
||||
|
||||
$compiler_args = @(
|
||||
( $flag_define + 'UNICODE'),
|
||||
( $flag_define + '_UNICODE')
|
||||
( $flag_define + 'INTELLISENSE_DIRECTIVES=0'),
|
||||
( $flag_define + 'RL_USE_LIBTYPE_SHARED')
|
||||
# ($flag_set_stack_size + $stack_size)
|
||||
$flag_wall
|
||||
$flag_warnings_as_errors
|
||||
$flag_optimize_intrinsics
|
||||
)
|
||||
|
||||
if ( $dev ) {
|
||||
$compiler_args += ( $flag_define + 'Build_Development=1' )
|
||||
}
|
||||
else {
|
||||
$compiler_args += ( $flag_define + 'Build_Development=0' )
|
||||
}
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_windows,
|
||||
$flag_link_optiiize_references,
|
||||
|
||||
( join-path $path_raylib_lib 'raylib.lib' )
|
||||
)
|
||||
|
||||
$unit = join-path $path_code 'vis_ast_windows.cpp'
|
||||
$executable = join-path $path_binaries 'vis_ast.exe'
|
||||
|
||||
$build_result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
22
project/auxillary/vis_ast/clean.ps1
Normal file
22
project/auxillary/vis_ast/clean.ps1
Normal file
@ -0,0 +1,22 @@
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_scripts = Join-Path $path_root 'scripts'
|
||||
|
||||
$target_arch = Join-Path $path_scripts 'helpers/target_arch.psm1'
|
||||
$devshell = Join-Path $path_scripts 'helpers/devshell.ps1'
|
||||
$format_cpp = Join-Path $path_scripts 'helpers/format_cpp.psm1'
|
||||
$incremental_checks = Join-Path $path_scripts 'helpers/incremental_checks.ps1'
|
||||
$vendor_toolchain = Join-Path $path_scripts 'helpers/vendor_toolchain.ps1'
|
||||
|
||||
$path_project = Join-Path $path_root 'project'
|
||||
$path_aux = Join-Path $path_project 'auxillary'
|
||||
$path_vis_root = Join-Path $path_aux 'vis_ast'
|
||||
$path_binaries = Join-Path $path_vis_root 'binaries'
|
||||
$path_build = Join-Path $path_vis_root 'build'
|
||||
|
||||
if ( test-path $path_build ) {
|
||||
remove-item $path_build -Recurse
|
||||
}
|
||||
|
||||
if ( test-path $path_binaries ) {
|
||||
remove-item $path_binaries -recurse
|
||||
}
|
25
project/auxillary/vis_ast/code/platform/macros.hpp
Normal file
25
project/auxillary/vis_ast/code/platform/macros.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#if INTELLISENSE_DIRECTIVES
|
||||
#include "vendor/compiler.hpp"
|
||||
#endif
|
||||
|
||||
#define global static // Global variables
|
||||
#define internal static // Internal linkage
|
||||
#define local_persist static // Local Persisting variables
|
||||
|
||||
#define api_c extern "C"
|
||||
|
||||
#define ccast( type, value ) ( const_cast< type >( (value) ) )
|
||||
#define pcast( type, value ) ( * reinterpret_cast< type* >( & ( value ) ) )
|
||||
#define rcast( type, value ) reinterpret_cast< type >( value )
|
||||
#define scast( type, value ) static_cast< type >( value )
|
||||
|
||||
#define do_once() for ( local_persist b32 once = true; once; once = false )
|
||||
#define stmt( ... ) do { __VA_ARGS__; } while ( 0 )
|
||||
|
||||
#define array_count( array ) ( sizeof( array ) / sizeof( ( array )[0] ) )
|
||||
|
||||
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
|
||||
#define megabytes( x ) ( kilobytes( x ) * ( s64 )( 1024 ) )
|
||||
#define gigabytes( x ) ( megabytes( x ) * ( s64 )( 1024 ) )
|
||||
#define terabytes( x ) ( gigabytes( x ) * ( s64 )( 1024 ) )
|
10
project/auxillary/vis_ast/code/platform/vendor/arch.hpp
vendored
Normal file
10
project/auxillary/vis_ast/code/platform/vendor/arch.hpp
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// Platform architecture
|
||||
#pragma once
|
||||
|
||||
#if defined( _WIN64 ) || defined( __x86_64__ ) || defined( _M_X64 ) || defined( __64BIT__ ) || defined( __powerpc64__ ) || defined( __ppc64__ ) || defined( __aarch64__ )
|
||||
# ifndef ARCH_64_BIT
|
||||
# define ARCH_64_BIT 1
|
||||
# endif
|
||||
#else
|
||||
# error A 32-bit architecture is not supported
|
||||
#endif
|
22
project/auxillary/vis_ast/code/platform/vendor/compiler.hpp
vendored
Normal file
22
project/auxillary/vis_ast/code/platform/vendor/compiler.hpp
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// Platform compiler
|
||||
#pragma once
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# define Compiler_MSVC 1
|
||||
#elif defined( __clang__ )
|
||||
# define Compiler_Clang 1
|
||||
#else
|
||||
# error "Unknown compiler"
|
||||
#endif
|
||||
|
||||
#if defined( __has_attribute )
|
||||
# define HAS_ATTRIBUTE( attribute ) __has_attribute( attribute )
|
||||
#else
|
||||
# define HAS_ATTRIBUTE( attribute ) ( 0 )
|
||||
#endif
|
||||
|
||||
#ifdef Compiler_Clang
|
||||
# define compiler_decorated_func_name __PRETTY_NAME__
|
||||
#elif defined(Compiler_MSVC)
|
||||
# define compiler_decorated_func_name __FUNCDNAME__
|
||||
#endif
|
34
project/auxillary/vis_ast/code/platform/vendor/compiler_ignores.hpp
vendored
Normal file
34
project/auxillary/vis_ast/code/platform/vendor/compiler_ignores.hpp
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#if INTELLISENSE_DIRECTIVES
|
||||
#include "compiler.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef Compiler_MSVC
|
||||
#pragma warning( disable: 4201 ) // Support for non-standard nameless struct or union extesnion
|
||||
#pragma warning( disable: 4100 ) // Support for unreferenced formal parameters
|
||||
#pragma warning( disable: 4800 ) // Support implicit conversion to bools
|
||||
#pragma warning( disable: 4365 ) // Support for signed/unsigned mismatch auto-conversion
|
||||
#pragma warning( disable: 4189 ) // Support for unused variables
|
||||
#pragma warning( disable: 4514 ) // Support for unused inline functions
|
||||
#pragma warning( disable: 4505 ) // Support for unused static functions
|
||||
#pragma warning( disable: 5045 ) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
|
||||
#pragma warning( disable: 5264 ) // Support for 'const' variables unused
|
||||
#pragma warning( disable: 4820 ) // Support auto-adding padding to structs
|
||||
#pragma warning( disable: 4711 ) // Support automatic inline expansion
|
||||
#pragma warning( disable: 4710 ) // Support automatic inline expansion
|
||||
#pragma warning( disable: 4805 ) // Support comparisons of s32 to bool.
|
||||
#pragma warning( disable: 5246 ) // Support for initialization of subobject without braces.
|
||||
#endif
|
||||
|
||||
#ifdef Compiler_Clang
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-const-variable"
|
||||
#pragma clang diagnostic ignored "-Wswitch"
|
||||
#pragma clang diagnostic ignored "-Wunused-variable"
|
||||
#pragma clang diagnostic ignored "-Wunused-local-typedef"
|
||||
#pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||
#pragma clang diagnostic ignored "-Wvarargs"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
|
||||
#pragma clang diagnostic ignored "-Wmissing-braces"
|
||||
#endif
|
22
project/auxillary/vis_ast/code/platform/vendor/os.hpp
vendored
Normal file
22
project/auxillary/vis_ast/code/platform/vendor/os.hpp
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// Platform OS detection
|
||||
#pragma once
|
||||
|
||||
#if defined( _WIN32 ) || defined( _WIN64 )
|
||||
# ifndef System_Windows
|
||||
# define System_Windows 1
|
||||
# endif
|
||||
#elif defined( __APPLE__ ) && defined( __MACH__ )
|
||||
# ifndef System_MacOS
|
||||
# define System_MacOS 1
|
||||
# endif
|
||||
#elif defined( __unix__ )
|
||||
# if defined( __linux__ )
|
||||
# ifndef System_Linux
|
||||
# define System_linux 1
|
||||
# endif
|
||||
# else
|
||||
# error This UNIX operating system is not supported
|
||||
# endif
|
||||
#else
|
||||
# error This operating system is not supported
|
||||
#endif
|
45
project/auxillary/vis_ast/code/platform/win32/launch.cpp
Normal file
45
project/auxillary/vis_ast/code/platform/win32/launch.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#if INTELLISENSE_DIRECTIVES
|
||||
#include "win32.hpp"
|
||||
#include "raylib/include/raylib.h"
|
||||
#endif
|
||||
|
||||
int __stdcall WinMain( HINSTANCE instance, HINSTANCE prev_instance, char* commandline, int num_cmd_show)
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 800;
|
||||
const int screenHeight = 450;
|
||||
|
||||
rl::init_window(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||
|
||||
rl::set_target_fps(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!rl::window_should_close()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl::begin_drawing();
|
||||
|
||||
rl::clear_background(RL_RAYWHITE);
|
||||
|
||||
rl::draw_text("Congrats! You created your first window!", 190, 200, 20, RL_LIGHTGRAY);
|
||||
|
||||
rl::end_drawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl::close_window(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
3
project/auxillary/vis_ast/code/platform/win32/types.hpp
Normal file
3
project/auxillary/vis_ast/code/platform/win32/types.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
using HINSTANCE = void*;
|
14
project/auxillary/vis_ast/code/vis_ast_windows.cpp
Normal file
14
project/auxillary/vis_ast/code/vis_ast_windows.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
#include "platform/vendor/arch.hpp"
|
||||
#include "platform/vendor/compiler.hpp"
|
||||
#include "platform/vendor/compiler_ignores.hpp"
|
||||
#include "platform/vendor/os.hpp"
|
||||
|
||||
#include "platform/macros.hpp"
|
||||
|
||||
#include "platform/win32/types.hpp"
|
||||
|
||||
#include "raylib/include/raylib.h"
|
||||
|
||||
#include "platform/win32/launch.cpp"
|
285
project/auxillary/vis_ast/dependencies/raylib/include/config.h
Normal file
285
project/auxillary/vis_ast/dependencies/raylib/include/config.h
Normal file
@ -0,0 +1,285 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib configuration flags
|
||||
*
|
||||
* This file defines all the configuration flags for the different raylib modules
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2018-2023 Ahmad Fatoum & Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module selection - Some modules could be avoided
|
||||
// Mandatory modules: rcore, rlgl, utils
|
||||
//------------------------------------------------------------------------------------
|
||||
#define RL_SUPPORT_MODULE_RSHAPES 1
|
||||
#define RL_SUPPORT_MODULE_RTEXTURES 1
|
||||
#define RL_SUPPORT_MODULE_RTEXT 1 // WARNING: It requires RL_SUPPORT_MODULE_RTEXTURES to load sprite font textures
|
||||
#define RL_SUPPORT_MODULE_RMODELS 1
|
||||
#define RL_SUPPORT_MODULE_RAUDIO 1
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rcore - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Camera module is included (rcamera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
|
||||
#define RL_SUPPORT_CAMERA_SYSTEM 1
|
||||
// Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
|
||||
#define RL_SUPPORT_GESTURES_SYSTEM 1
|
||||
// Include pseudo-random numbers generator (rprand.h), based on Xoshiro128** and SplitMix64
|
||||
#define RL_SUPPORT_RPRAND_GENERATOR 1
|
||||
// Mouse gestures are directly mapped like touches and processed by gestures system
|
||||
#define RL_SUPPORT_MOUSE_GESTURES 1
|
||||
// Reconfigure standard input to receive key inputs, works with SSH connection.
|
||||
#define RL_SUPPORT_SSH_KEYBOARD_RPI 1
|
||||
// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions.
|
||||
// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often.
|
||||
#define RL_SUPPORT_WINMM_HIGHRES_TIMER 1
|
||||
// Use busy wait loop for timing sync, if not defined, a high-resolution timer is set up and used
|
||||
//#define RL_SUPPORT_BUSY_WAIT_LOOP 1
|
||||
// Use a partial-busy wait loop, in this case frame sleeps for most of the time, but then runs a busy loop at the end for accuracy
|
||||
#define RL_SUPPORT_PARTIALBUSY_WAIT_LOOP 1
|
||||
// Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()
|
||||
#define RL_SUPPORT_SCREEN_CAPTURE 1
|
||||
// Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()
|
||||
#define RL_SUPPORT_GIF_RECORDING 1
|
||||
// Support CompressData() and DecompressData() functions
|
||||
#define RL_SUPPORT_COMPRESSION_API 1
|
||||
// Support automatic generated events, loading and recording of those events when required
|
||||
#define RL_SUPPORT_AUTOMATION_EVENTS 1
|
||||
// Support custom frame control, only for advance users
|
||||
// By default end_drawing() does this job: draws everything + swap_screen_buffer() + manage frame timing + poll_input_events()
|
||||
// Enabling this flag allows manual control of the frame processes, use at your own risk
|
||||
//#define RL_SUPPORT_CUSTOM_FRAME_CONTROL 1
|
||||
|
||||
// rcore: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define RL_MAX_FILEPATH_CAPACITY 8192 // Maximum file paths capacity
|
||||
#define RL_MAX_FILEPATH_LENGTH 4096 // Maximum length for filepaths (Linux PATH_MAX default value)
|
||||
|
||||
#define RL_MAX_KEYBOARD_KEYS 512 // Maximum number of keyboard keys supported
|
||||
#define RL_MAX_MOUSE_BUTTONS 8 // Maximum number of mouse buttons supported
|
||||
#define RL_MAX_GAMEPADS 4 // Maximum number of gamepads supported
|
||||
#define RL_MAX_GAMEPAD_AXIS 8 // Maximum number of axis supported (per gamepad)
|
||||
#define RL_MAX_GAMEPAD_BUTTONS 32 // Maximum number of buttons supported (per gamepad)
|
||||
#define RL_MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||
#define RL_MAX_KEY_PRESSED_QUEUE 16 // Maximum number of keys in the key input queue
|
||||
#define RL_MAX_CHAR_PRESSED_QUEUE 16 // Maximum number of characters in the char input queue
|
||||
|
||||
#define RL_MAX_DECOMPRESSION_SIZE 64 // Max size allocated for decompression in MB
|
||||
|
||||
#define RL_MAX_AUTOMATION_EVENTS 16384 // Maximum number of automation events to record
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rlgl - Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Enable OpenGL Debug Context (only available on OpenGL 4.3)
|
||||
//#define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT 1
|
||||
|
||||
// Show OpenGL extensions and capabilities detailed logs on init
|
||||
//#define RLGL_SHOW_GL_DETAILS_INFO 1
|
||||
|
||||
//#define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 4096 // Default internal render batch elements limits
|
||||
#define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
|
||||
#define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
|
||||
#define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (set_shader_value_texture())
|
||||
|
||||
#define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
|
||||
|
||||
#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
||||
|
||||
#define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
|
||||
#define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
|
||||
|
||||
// Default shader vertex attribute names to set location points
|
||||
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5
|
||||
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rshapes - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Use QUADS instead of TRIANGLES for drawing when possible
|
||||
// Some lines-based shapes could still use lines
|
||||
#define RL_SUPPORT_QUADS_DRAW_MODE 1
|
||||
|
||||
// rshapes: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define SPLINE_SEGMENT_DIVISIONS 24 // Spline segments subdivisions
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rtextures - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Selecte desired fileformats to be supported for image data loading
|
||||
#define RL_SUPPORT_FILEFORMAT_PNG 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_BMP 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_TGA 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_JPG 1
|
||||
#define RL_SUPPORT_FILEFORMAT_GIF 1
|
||||
#define RL_SUPPORT_FILEFORMAT_QOI 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_PSD 1
|
||||
#define RL_SUPPORT_FILEFORMAT_DDS 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_HDR 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_PIC 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_KTX 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_ASTC 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_PKM 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_PVR 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_SVG 1
|
||||
|
||||
// Support image export functionality (.png, .bmp, .tga, .jpg, .qoi)
|
||||
#define RL_SUPPORT_IMAGE_EXPORT 1
|
||||
// Support procedural image generation functionality (gradient, spot, perlin-noise, cellular)
|
||||
#define RL_SUPPORT_IMAGE_GENERATION 1
|
||||
// Support multiple image editing functions to scale, adjust colors, flip, draw on images, crop...
|
||||
// If not defined, still some functions are supported: image_format(), image_crop(), image_to_pot()
|
||||
#define RL_SUPPORT_IMAGE_MANIPULATION 1
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rtext - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Default font is loaded on window initialization to be available for the user to render simple text
|
||||
// NOTE: If enabled, uses external module functions to load default raylib font
|
||||
#define RL_SUPPORT_DEFAULT_FONT 1
|
||||
// Selected desired font fileformats to be supported for loading
|
||||
#define RL_SUPPORT_FILEFORMAT_FNT 1
|
||||
#define RL_SUPPORT_FILEFORMAT_TTF 1
|
||||
|
||||
// Support text management functions
|
||||
// If not defined, still some functions are supported: text_length(), TextFormat()
|
||||
#define RL_SUPPORT_TEXT_MANIPULATION 1
|
||||
|
||||
// On font atlas image generation [gen_image_font_atlas()], add a 3x3 pixels white rectangle
|
||||
// at the bottom-right corner of the atlas. It can be useful to for shapes drawing, to allow
|
||||
// drawing text and shapes with a single draw call [set_shapes_texture()].
|
||||
#define RL_SUPPORT_FONT_ATLAS_WHITE_REC 1
|
||||
|
||||
// rtext: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define RL_MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions:
|
||||
// TextFormat(), TextSubtext(), TextToUpper(), TextToLower(), TextToPascal(), TextSplit()
|
||||
#define RL_MAX_TEXTSPLIT_COUNT 128 // Maximum number of substrings to split: TextSplit()
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: rmodels - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Selected desired model fileformats to be supported for loading
|
||||
#define RL_SUPPORT_FILEFORMAT_OBJ 1
|
||||
#define RL_SUPPORT_FILEFORMAT_MTL 1
|
||||
#define RL_SUPPORT_FILEFORMAT_IQM 1
|
||||
#define RL_SUPPORT_FILEFORMAT_GLTF 1
|
||||
#define RL_SUPPORT_FILEFORMAT_VOX 1
|
||||
#define RL_SUPPORT_FILEFORMAT_M3D 1
|
||||
// Support procedural mesh generation functions, uses external par_shapes.h library
|
||||
// NOTE: Some generated meshes DO NOT include generated texture coordinates
|
||||
#define RL_SUPPORT_MESH_GENERATION 1
|
||||
|
||||
// rmodels: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define RL_MAX_MATERIAL_MAPS 12 // Maximum number of shader maps supported
|
||||
#define RL_MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: raudio - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Desired audio fileformats to be supported for loading
|
||||
#define RL_SUPPORT_FILEFORMAT_WAV 1
|
||||
#define RL_SUPPORT_FILEFORMAT_OGG 1
|
||||
#define RL_SUPPORT_FILEFORMAT_MP3 1
|
||||
#define RL_SUPPORT_FILEFORMAT_QOA 1
|
||||
//#define RL_SUPPORT_FILEFORMAT_FLAC 1
|
||||
#define RL_SUPPORT_FILEFORMAT_XM 1
|
||||
#define RL_SUPPORT_FILEFORMAT_MOD 1
|
||||
|
||||
// raudio: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define RL_AUDIO_DEVICE_FORMAT ma_format_f32 // Device output format (miniaudio: float-32bit)
|
||||
#define RL_AUDIO_DEVICE_CHANNELS 2 // Device output channels: stereo
|
||||
#define RL_AUDIO_DEVICE_SAMPLE_RATE 0 // Device sample rate (device default)
|
||||
|
||||
#define RL_MAX_AUDIO_BUFFER_POOL_CHANNELS 16 // Maximum number of audio pool channels
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: utils - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Standard file io library (stdio.h) included
|
||||
#define RL_SUPPORT_STANDARD_FILEIO 1
|
||||
// Show RL_TRACELOG() output messages
|
||||
// NOTE: By default LOG_DEBUG traces not shown
|
||||
#define RL_SUPPORT_TRACELOG 1
|
||||
//#define RL_SUPPORT_TRACELOG_DEBUG 1
|
||||
|
||||
// utils: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define RL_MAX_TRACELOG_MSG_LENGTH 256 // Max length of one trace-log message
|
||||
|
||||
#endif // CONFIG_H
|
||||
|
||||
// Indicates of raylib has been refactored
|
||||
#ifndef RL_REFACTORED_CPP
|
||||
#define RL_REFACTORED_CPP
|
||||
#endif
|
||||
|
||||
#define RL_USE_CPP_NAMESPACE 1
|
||||
#define RL_USE_CPP_MANGLING 1
|
||||
|
||||
#if RL_USE_CPP_NAMESPACE && defined(__cplusplus)
|
||||
#pragma message("USING CPP NAMESPACE")
|
||||
#define RL_NS_BEGIN namespace rl {
|
||||
#define RL_NS_END }
|
||||
#else
|
||||
#define RL_NS_BEGIN
|
||||
#define RL_NS_END
|
||||
#endif
|
||||
|
||||
#if RL_USE_CPP_MANGLING && defined(__cplusplus)
|
||||
#pragma message("USING CPP MANGLING")
|
||||
#define RL_EXTERN_C_BEGIN
|
||||
#define RL_EXTERN_C_END
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
#define RL_EXTERN_C_BEGIN extern "C" {
|
||||
#define RL_EXTERN_C_END }
|
||||
#else
|
||||
#define RL_EXTERN_C_BEGIN
|
||||
#define RL_EXTERN_C_END
|
||||
#endif
|
||||
#endif
|
1676
project/auxillary/vis_ast/dependencies/raylib/include/raylib.h
Normal file
1676
project/auxillary/vis_ast/dependencies/raylib/include/raylib.h
Normal file
File diff suppressed because it is too large
Load Diff
2206
project/auxillary/vis_ast/dependencies/raylib/include/raymath.h
Normal file
2206
project/auxillary/vis_ast/dependencies/raylib/include/raymath.h
Normal file
File diff suppressed because it is too large
Load Diff
562
project/auxillary/vis_ast/dependencies/raylib/include/rcamera.h
Normal file
562
project/auxillary/vis_ast/dependencies/raylib/include/rcamera.h
Normal file
@ -0,0 +1,562 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* rcamera - Basic camera system with support for multiple camera modes
|
||||
*
|
||||
* CONFIGURATION:
|
||||
* #define RCAMERA_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* #define RCAMERA_STANDALONE
|
||||
* If defined, the library can be used as standalone as a camera system but some
|
||||
* functions must be redefined to manage inputs accordingly.
|
||||
*
|
||||
* CONTRIBUTORS:
|
||||
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||
* Christoph Wagner: Complete redesign, using raymath (2022)
|
||||
* Marc Palau: Initial implementation (2014)
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2022-2023 Christoph Wagner (@Crydsch) & Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef RCAMERA_H
|
||||
#define RCAMERA_H
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
// Function specifiers definition
|
||||
|
||||
// Function specifiers in case library is build/used as a shared library (Windows)
|
||||
// NOTE: Microsoft specifiers to tell compiler that symbols are imported/exported from a .dll
|
||||
#if defined(_WIN32)
|
||||
#if defined(RL_BUILD_LIBTYPE_SHARED)
|
||||
#if defined(__TINYC__)
|
||||
#define __declspec(x) __attribute__((x))
|
||||
#endif
|
||||
#define RLAPI __declspec(dllexport) // We are building the library as a Win32 shared library (.dll)
|
||||
#elif defined(RL_USE_LIBTYPE_SHARED)
|
||||
#define RLAPI __declspec(dllimport) // We are using the library as a Win32 shared library (.dll)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RLAPI
|
||||
#define RLAPI // Functions defined as 'extern' by default (implicit specifiers)
|
||||
#endif
|
||||
|
||||
#if defined(RCAMERA_STANDALONE)
|
||||
#define RL_CAMERA_CULL_DISTANCE_NEAR 0.01
|
||||
#define RL_CAMERA_CULL_DISTANCE_FAR 1000.0
|
||||
#else
|
||||
#define RL_CAMERA_CULL_DISTANCE_NEAR RL_CULL_DISTANCE_NEAR
|
||||
#define RL_CAMERA_CULL_DISTANCE_FAR RL_CULL_DISTANCE_FAR
|
||||
#endif
|
||||
|
||||
RL_NS_BEGIN
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
// NOTE: Below types are required for standalone usage
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(RCAMERA_STANDALONE)
|
||||
// Vector2, 2 components
|
||||
typedef struct Vector2 {
|
||||
float x; // Vector x component
|
||||
float y; // Vector y component
|
||||
} Vector2;
|
||||
|
||||
// Vector3, 3 components
|
||||
typedef struct Vector3 {
|
||||
float x; // Vector x component
|
||||
float y; // Vector y component
|
||||
float z; // Vector z component
|
||||
} Vector3;
|
||||
|
||||
// Matrix, 4x4 components, column major, OpenGL style, right-handed
|
||||
typedef struct Matrix {
|
||||
float m0, m4, m8, m12; // Matrix first row (4 components)
|
||||
float m1, m5, m9, m13; // Matrix second row (4 components)
|
||||
float m2, m6, m10, m14; // Matrix third row (4 components)
|
||||
float m3, m7, m11, m15; // Matrix fourth row (4 components)
|
||||
} Matrix;
|
||||
|
||||
// Camera type, defines a camera position/orientation in 3d space
|
||||
typedef struct Camera3D {
|
||||
Vector3 position; // Camera position
|
||||
Vector3 target; // Camera target it looks-at
|
||||
Vector3 up; // Camera up vector (rotation over its axis)
|
||||
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
|
||||
int projection; // Camera projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
|
||||
} Camera3D;
|
||||
|
||||
typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D
|
||||
|
||||
// Camera projection
|
||||
typedef enum {
|
||||
CAMERA_PERSPECTIVE = 0, // Perspective projection
|
||||
CAMERA_ORTHOGRAPHIC // Orthographic projection
|
||||
} CameraProjection;
|
||||
|
||||
// Camera system modes
|
||||
typedef enum {
|
||||
CAMERA_CUSTOM = 0, // Camera custom, controlled by user (update_camera() does nothing)
|
||||
CAMERA_FREE, // Camera free mode
|
||||
CAMERA_ORBITAL, // Camera orbital, around target, zoom supported
|
||||
CAMERA_FIRST_PERSON, // Camera first person
|
||||
CAMERA_THIRD_PERSON // Camera third person
|
||||
} CameraMode;
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
RL_EXTERN_C_BEGIN
|
||||
|
||||
RLAPI Vector3 get_camera_forward(Camera *camera);
|
||||
RLAPI Vector3 get_camera_up(Camera *camera);
|
||||
RLAPI Vector3 get_camera_right(Camera *camera);
|
||||
|
||||
// Camera movement
|
||||
RLAPI void camera_move_forward(Camera *camera, float distance, bool moveInWorldPlane);
|
||||
RLAPI void camera_move_up(Camera *camera, float distance);
|
||||
RLAPI void camera_move_right(Camera *camera, float distance, bool moveInWorldPlane);
|
||||
RLAPI void camera_move_to_target(Camera *camera, float delta);
|
||||
|
||||
// Camera rotation
|
||||
RLAPI void camera_yaw(Camera *camera, float angle, bool rotateAroundTarget);
|
||||
RLAPI void camera_pitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp);
|
||||
RLAPI void camera_roll(Camera *camera, float angle);
|
||||
|
||||
RLAPI Matrix get_camera_view_matrix(Camera *camera);
|
||||
RLAPI Matrix get_camera_projection_matrix(Camera* camera, float aspect);
|
||||
|
||||
RL_EXTERN_C_END
|
||||
|
||||
RL_NS_END
|
||||
|
||||
#endif // RCAMERA_H
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
*
|
||||
* CAMERA IMPLEMENTATION
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(RCAMERA_IMPLEMENTATION)
|
||||
|
||||
#include "raymath.h" // Required for vector maths:
|
||||
// vector3_add()
|
||||
// vector3_subtract()
|
||||
// vector3_scale()
|
||||
// vector3_normalize()
|
||||
// vector3_distance()
|
||||
// vector3_cross_product()
|
||||
// vector3_rotate_by_axis_angle()
|
||||
// vector3_angle()
|
||||
// vector3_negate()
|
||||
// matrix_look_at()
|
||||
// matrix_perspective()
|
||||
// matrix_ortho()
|
||||
// matrix_identity()
|
||||
|
||||
// raylib required functionality:
|
||||
// get_mouse_delta()
|
||||
// get_mouse_wheel_move()
|
||||
// is_key_down()
|
||||
// is_key_pressed()
|
||||
// get_frame_time()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define CAMERA_MOVE_SPEED 0.09f
|
||||
#define CAMERA_ROTATION_SPEED 0.03f
|
||||
#define CAMERA_PAN_SPEED 0.2f
|
||||
|
||||
// Camera mouse movement sensitivity
|
||||
#define CAMERA_MOUSE_MOVE_SENSITIVITY 0.003f // TODO: it should be independant of framerate
|
||||
#define CAMERA_MOUSE_SCROLL_SENSITIVITY 1.5f
|
||||
|
||||
#define CAMERA_ORBITAL_SPEED 0.5f // Radians per second
|
||||
|
||||
|
||||
#define CAMERA_FIRST_PERSON_STEP_TRIGONOMETRIC_DIVIDER 8.0f
|
||||
#define CAMERA_FIRST_PERSON_STEP_DIVIDER 30.0f
|
||||
#define CAMERA_FIRST_PERSON_WAVING_DIVIDER 200.0f
|
||||
|
||||
// PLAYER (used by camera)
|
||||
#define PLAYER_MOVEMENT_SENSITIVITY 20.0f
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
|
||||
RL_NS_BEGIN
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// Returns the cameras forward vector (normalized)
|
||||
Vector3 get_camera_forward(Camera *camera)
|
||||
{
|
||||
return vector3_normalize(vector3_subtract(camera->target, camera->position));
|
||||
}
|
||||
|
||||
// Returns the cameras up vector (normalized)
|
||||
// Note: The up vector might not be perpendicular to the forward vector
|
||||
Vector3 get_camera_up(Camera *camera)
|
||||
{
|
||||
return vector3_normalize(camera->up);
|
||||
}
|
||||
|
||||
// Returns the cameras right vector (normalized)
|
||||
Vector3 get_camera_right(Camera *camera)
|
||||
{
|
||||
Vector3 forward = get_camera_forward(camera);
|
||||
Vector3 up = get_camera_up(camera);
|
||||
|
||||
return vector3_cross_product(forward, up);
|
||||
}
|
||||
|
||||
// Moves the camera in its forward direction
|
||||
void camera_move_forward(Camera *camera, float distance, bool moveInWorldPlane)
|
||||
{
|
||||
Vector3 forward = get_camera_forward(camera);
|
||||
|
||||
if (moveInWorldPlane)
|
||||
{
|
||||
// Project vector onto world plane
|
||||
forward.y = 0;
|
||||
forward = vector3_normalize(forward);
|
||||
}
|
||||
|
||||
// Scale by distance
|
||||
forward = vector3_scale(forward, distance);
|
||||
|
||||
// Move position and target
|
||||
camera->position = vector3_add(camera->position, forward);
|
||||
camera->target = vector3_add(camera->target, forward);
|
||||
}
|
||||
|
||||
// Moves the camera in its up direction
|
||||
void camera_move_up(Camera *camera, float distance)
|
||||
{
|
||||
Vector3 up = get_camera_up(camera);
|
||||
|
||||
// Scale by distance
|
||||
up = vector3_scale(up, distance);
|
||||
|
||||
// Move position and target
|
||||
camera->position = vector3_add(camera->position, up);
|
||||
camera->target = vector3_add(camera->target, up);
|
||||
}
|
||||
|
||||
// Moves the camera target in its current right direction
|
||||
void camera_move_right(Camera *camera, float distance, bool moveInWorldPlane)
|
||||
{
|
||||
Vector3 right = get_camera_right(camera);
|
||||
|
||||
if (moveInWorldPlane)
|
||||
{
|
||||
// Project vector onto world plane
|
||||
right.y = 0;
|
||||
right = vector3_normalize(right);
|
||||
}
|
||||
|
||||
// Scale by distance
|
||||
right = vector3_scale(right, distance);
|
||||
|
||||
// Move position and target
|
||||
camera->position = vector3_add(camera->position, right);
|
||||
camera->target = vector3_add(camera->target, right);
|
||||
}
|
||||
|
||||
// Moves the camera position closer/farther to/from the camera target
|
||||
void camera_move_to_target(Camera *camera, float delta)
|
||||
{
|
||||
float distance = vector3_distance(camera->position, camera->target);
|
||||
|
||||
// Apply delta
|
||||
distance += delta;
|
||||
|
||||
// Distance must be greater than 0
|
||||
if (distance <= 0) distance = 0.001f;
|
||||
|
||||
// Set new distance by moving the position along the forward vector
|
||||
Vector3 forward = get_camera_forward(camera);
|
||||
camera->position = vector3_add(camera->target, vector3_scale(forward, -distance));
|
||||
}
|
||||
|
||||
// Rotates the camera around its up vector
|
||||
// Yaw is "looking left and right"
|
||||
// If rotateAroundTarget is false, the camera rotates around its position
|
||||
// Note: angle must be provided in radians
|
||||
void camera_yaw(Camera *camera, float angle, bool rotateAroundTarget)
|
||||
{
|
||||
// Rotation axis
|
||||
Vector3 up = get_camera_up(camera);
|
||||
|
||||
// View vector
|
||||
Vector3 targetPosition = vector3_subtract(camera->target, camera->position);
|
||||
|
||||
// Rotate view vector around up axis
|
||||
targetPosition = vector3_rotate_by_axis_angle(targetPosition, up, angle);
|
||||
|
||||
if (rotateAroundTarget)
|
||||
{
|
||||
// Move position relative to target
|
||||
camera->position = vector3_subtract(camera->target, targetPosition);
|
||||
}
|
||||
else // rotate around camera.position
|
||||
{
|
||||
// Move target relative to position
|
||||
camera->target = vector3_add(camera->position, targetPosition);
|
||||
}
|
||||
}
|
||||
|
||||
// Rotates the camera around its right vector, pitch is "looking up and down"
|
||||
// - lockView prevents camera overrotation (aka "somersaults")
|
||||
// - rotateAroundTarget defines if rotation is around target or around its position
|
||||
// - rotateUp rotates the up direction as well (typically only usefull in CAMERA_FREE)
|
||||
// NOTE: angle must be provided in radians
|
||||
void camera_pitch(Camera *camera, float angle, bool lockView, bool rotateAroundTarget, bool rotateUp)
|
||||
{
|
||||
// Up direction
|
||||
Vector3 up = get_camera_up(camera);
|
||||
|
||||
// View vector
|
||||
Vector3 targetPosition = vector3_subtract(camera->target, camera->position);
|
||||
|
||||
if (lockView)
|
||||
{
|
||||
// In these camera modes we clamp the Pitch angle
|
||||
// to allow only viewing straight up or down.
|
||||
|
||||
// clamp view up
|
||||
float maxAngleUp = vector3_angle(up, targetPosition);
|
||||
maxAngleUp -= 0.001f; // avoid numerical errors
|
||||
if (angle > maxAngleUp) angle = maxAngleUp;
|
||||
|
||||
// clamp view down
|
||||
float maxAngleDown = vector3_angle(vector3_negate(up), targetPosition);
|
||||
maxAngleDown *= -1.0f; // downwards angle is negative
|
||||
maxAngleDown += 0.001f; // avoid numerical errors
|
||||
if (angle < maxAngleDown) angle = maxAngleDown;
|
||||
}
|
||||
|
||||
// Rotation axis
|
||||
Vector3 right = get_camera_right(camera);
|
||||
|
||||
// Rotate view vector around right axis
|
||||
targetPosition = vector3_rotate_by_axis_angle(targetPosition, right, angle);
|
||||
|
||||
if (rotateAroundTarget)
|
||||
{
|
||||
// Move position relative to target
|
||||
camera->position = vector3_subtract(camera->target, targetPosition);
|
||||
}
|
||||
else // rotate around camera.position
|
||||
{
|
||||
// Move target relative to position
|
||||
camera->target = vector3_add(camera->position, targetPosition);
|
||||
}
|
||||
|
||||
if (rotateUp)
|
||||
{
|
||||
// Rotate up direction around right axis
|
||||
camera->up = vector3_rotate_by_axis_angle(camera->up, right, angle);
|
||||
}
|
||||
}
|
||||
|
||||
// Rotates the camera around its forward vector
|
||||
// Roll is "turning your head sideways to the left or right"
|
||||
// Note: angle must be provided in radians
|
||||
void camera_roll(Camera *camera, float angle)
|
||||
{
|
||||
// Rotation axis
|
||||
Vector3 forward = get_camera_forward(camera);
|
||||
|
||||
// Rotate up direction around forward axis
|
||||
camera->up = vector3_rotate_by_axis_angle(camera->up, forward, angle);
|
||||
}
|
||||
|
||||
// Returns the camera view matrix
|
||||
Matrix get_camera_view_matrix(Camera *camera)
|
||||
{
|
||||
return matrix_look_at(camera->position, camera->target, camera->up);
|
||||
}
|
||||
|
||||
// Returns the camera projection matrix
|
||||
Matrix get_camera_projection_matrix(Camera *camera, float aspect)
|
||||
{
|
||||
if (camera->projection == CAMERA_PERSPECTIVE)
|
||||
{
|
||||
return matrix_perspective(camera->fovy*RL_DEG2RAD, aspect, RL_CAMERA_CULL_DISTANCE_NEAR, RL_CAMERA_CULL_DISTANCE_FAR);
|
||||
}
|
||||
else if (camera->projection == CAMERA_ORTHOGRAPHIC)
|
||||
{
|
||||
double top = camera->fovy/2.0;
|
||||
double right = top*aspect;
|
||||
|
||||
return matrix_ortho(-right, right, -top, top, RL_CAMERA_CULL_DISTANCE_NEAR, RL_CAMERA_CULL_DISTANCE_FAR);
|
||||
}
|
||||
|
||||
return matrix_identity();
|
||||
}
|
||||
|
||||
#if !defined(RCAMERA_STANDALONE)
|
||||
// Update camera position for selected mode
|
||||
// Camera mode: CAMERA_FREE, CAMERA_FIRST_PERSON, CAMERA_THIRD_PERSON, CAMERA_ORBITAL or CUSTOM
|
||||
void update_camera(Camera *camera, int mode)
|
||||
{
|
||||
Vector2 mousePositionDelta = get_mouse_delta();
|
||||
|
||||
bool moveInWorldPlane = ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON));
|
||||
bool rotateAroundTarget = ((mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||
bool lockView = ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL));
|
||||
bool rotateUp = false;
|
||||
|
||||
if (mode == CAMERA_ORBITAL)
|
||||
{
|
||||
// Orbital can just orbit
|
||||
Matrix rotation = matrix_rotate(get_camera_up(camera), CAMERA_ORBITAL_SPEED*get_frame_time());
|
||||
Vector3 view = vector3_subtract(camera->position, camera->target);
|
||||
view = vector3_transform(view, rotation);
|
||||
camera->position = vector3_add(camera->target, view);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Camera rotation
|
||||
if (is_key_down(KEY_DOWN)) camera_pitch(camera, -CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
||||
if (is_key_down(KEY_UP)) camera_pitch(camera, CAMERA_ROTATION_SPEED, lockView, rotateAroundTarget, rotateUp);
|
||||
if (is_key_down(KEY_RIGHT)) camera_yaw(camera, -CAMERA_ROTATION_SPEED, rotateAroundTarget);
|
||||
if (is_key_down(KEY_LEFT)) camera_yaw(camera, CAMERA_ROTATION_SPEED, rotateAroundTarget);
|
||||
if (is_key_down(KEY_Q)) camera_roll(camera, -CAMERA_ROTATION_SPEED);
|
||||
if (is_key_down(KEY_E)) camera_roll(camera, CAMERA_ROTATION_SPEED);
|
||||
|
||||
// Camera movement
|
||||
if (!is_gamepad_available(0))
|
||||
{
|
||||
// Camera pan (for CAMERA_FREE)
|
||||
if ((mode == CAMERA_FREE) && (is_mouse_button_down(MOUSE_BUTTON_MIDDLE)))
|
||||
{
|
||||
const Vector2 mouseDelta = get_mouse_delta();
|
||||
if (mouseDelta.x > 0.0f) camera_move_right(camera, CAMERA_PAN_SPEED, moveInWorldPlane);
|
||||
if (mouseDelta.x < 0.0f) camera_move_right(camera, -CAMERA_PAN_SPEED, moveInWorldPlane);
|
||||
if (mouseDelta.y > 0.0f) camera_move_up(camera, -CAMERA_PAN_SPEED);
|
||||
if (mouseDelta.y < 0.0f) camera_move_up(camera, CAMERA_PAN_SPEED);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Mouse support
|
||||
camera_yaw(camera, -mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||
camera_pitch(camera, -mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||
}
|
||||
|
||||
// Keyboard support
|
||||
if (is_key_down(KEY_W)) camera_move_forward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (is_key_down(KEY_A)) camera_move_right(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (is_key_down(KEY_S)) camera_move_forward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (is_key_down(KEY_D)) camera_move_right(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Gamepad controller support
|
||||
camera_yaw(camera, -(get_gamepad_axis_movement(0, GAMEPAD_AXIS_RIGHT_X) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, rotateAroundTarget);
|
||||
camera_pitch(camera, -(get_gamepad_axis_movement(0, GAMEPAD_AXIS_RIGHT_Y) * 2)*CAMERA_MOUSE_MOVE_SENSITIVITY, lockView, rotateAroundTarget, rotateUp);
|
||||
|
||||
if (get_gamepad_axis_movement(0, GAMEPAD_AXIS_LEFT_Y) <= -0.25f) camera_move_forward(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (get_gamepad_axis_movement(0, GAMEPAD_AXIS_LEFT_X) <= -0.25f) camera_move_right(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (get_gamepad_axis_movement(0, GAMEPAD_AXIS_LEFT_Y) >= 0.25f) camera_move_forward(camera, -CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
if (get_gamepad_axis_movement(0, GAMEPAD_AXIS_LEFT_X) >= 0.25f) camera_move_right(camera, CAMERA_MOVE_SPEED, moveInWorldPlane);
|
||||
}
|
||||
|
||||
if (mode == CAMERA_FREE)
|
||||
{
|
||||
if (is_key_down(KEY_SPACE)) camera_move_up(camera, CAMERA_MOVE_SPEED);
|
||||
if (is_key_down(KEY_LEFT_CONTROL)) camera_move_up(camera, -CAMERA_MOVE_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
if ((mode == CAMERA_THIRD_PERSON) || (mode == CAMERA_ORBITAL) || (mode == CAMERA_FREE))
|
||||
{
|
||||
// Zoom target distance
|
||||
camera_move_to_target(camera, -get_mouse_wheel_move());
|
||||
if (is_key_pressed(KEY_KP_SUBTRACT)) camera_move_to_target(camera, 2.0f);
|
||||
if (is_key_pressed(KEY_KP_ADD)) camera_move_to_target(camera, -2.0f);
|
||||
}
|
||||
}
|
||||
#endif // !RCAMERA_STANDALONE
|
||||
|
||||
// Update camera movement, movement/rotation values should be provided by user
|
||||
void update_camera_pro(Camera *camera, Vector3 movement, Vector3 rotation, float zoom)
|
||||
{
|
||||
// Required values
|
||||
// movement.x - Move forward/backward
|
||||
// movement.y - Move right/left
|
||||
// movement.z - Move up/down
|
||||
// rotation.x - yaw
|
||||
// rotation.y - pitch
|
||||
// rotation.z - roll
|
||||
// zoom - Move towards target
|
||||
|
||||
bool lockView = true;
|
||||
bool rotateAroundTarget = false;
|
||||
bool rotateUp = false;
|
||||
bool moveInWorldPlane = true;
|
||||
|
||||
// Camera rotation
|
||||
camera_pitch(camera, -rotation.y*RL_DEG2RAD, lockView, rotateAroundTarget, rotateUp);
|
||||
camera_yaw(camera, -rotation.x*RL_DEG2RAD, rotateAroundTarget);
|
||||
camera_roll(camera, rotation.z*RL_DEG2RAD);
|
||||
|
||||
// Camera movement
|
||||
camera_move_forward(camera, movement.x, moveInWorldPlane);
|
||||
camera_move_right(camera, movement.y, moveInWorldPlane);
|
||||
camera_move_up(camera, movement.z);
|
||||
|
||||
// Zoom target distance
|
||||
camera_move_to_target(camera, zoom);
|
||||
}
|
||||
|
||||
RL_NS_END
|
||||
|
||||
#endif // RCAMERA_IMPLEMENTATION
|
@ -0,0 +1,579 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* rgestures - Gestures system, gestures processing based on input events (touch/mouse)
|
||||
*
|
||||
* CONFIGURATION:
|
||||
* #define RGESTURES_IMPLEMENTATION
|
||||
* Generates the implementation of the library into the included file.
|
||||
* If not defined, the library is in header only mode and can be included in other headers
|
||||
* or source files without problems. But only ONE file should hold the implementation.
|
||||
*
|
||||
* #define RGESTURES_STANDALONE
|
||||
* If defined, the library can be used as standalone to process gesture events with
|
||||
* no external dependencies.
|
||||
*
|
||||
* CONTRIBUTORS:
|
||||
* Marc Palau: Initial implementation (2014)
|
||||
* Albert Martos: Complete redesign and testing (2015)
|
||||
* Ian Eito: Complete redesign and testing (2015)
|
||||
* Ramon Santamaria: Supervision, review, update and maintenance
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef RGESTURES_H
|
||||
#define RGESTURES_H
|
||||
|
||||
#ifndef RL_PI
|
||||
#define RL_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifndef RL_MAX_TOUCH_POINTS
|
||||
#define RL_MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
// NOTE: Below types are required for standalone usage
|
||||
//----------------------------------------------------------------------------------
|
||||
// Boolean type
|
||||
#if (defined(__STDC__) && __STDC_VERSION__ >= 199901L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||
#include <stdbool.h>
|
||||
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
||||
typedef enum bool { false = 0, true = !false } bool;
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
||||
RL_NS_BEGIN
|
||||
|
||||
#if !defined(RL_VECTOR2_TYPE)
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
#endif
|
||||
|
||||
#if defined(RGESTURES_STANDALONE)
|
||||
// Gestures type
|
||||
// NOTE: It could be used as flags to enable only some gestures
|
||||
typedef enum {
|
||||
GESTURE_NONE = 0,
|
||||
GESTURE_TAP = 1,
|
||||
GESTURE_DOUBLETAP = 2,
|
||||
GESTURE_HOLD = 4,
|
||||
GESTURE_DRAG = 8,
|
||||
GESTURE_SWIPE_RIGHT = 16,
|
||||
GESTURE_SWIPE_LEFT = 32,
|
||||
GESTURE_SWIPE_UP = 64,
|
||||
GESTURE_SWIPE_DOWN = 128,
|
||||
GESTURE_PINCH_IN = 256,
|
||||
GESTURE_PINCH_OUT = 512
|
||||
} Gesture;
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TOUCH_ACTION_UP = 0,
|
||||
TOUCH_ACTION_DOWN,
|
||||
TOUCH_ACTION_MOVE,
|
||||
TOUCH_ACTION_CANCEL
|
||||
} TouchAction;
|
||||
|
||||
// Gesture event
|
||||
typedef struct {
|
||||
int touchAction;
|
||||
int pointCount;
|
||||
int pointId[RL_MAX_TOUCH_POINTS];
|
||||
Vector2 position[RL_MAX_TOUCH_POINTS];
|
||||
} GestureEvent;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
RL_EXTERN_C_BEGIN
|
||||
|
||||
void process_gesture_event(GestureEvent event); // Process gesture event and translate it into gestures
|
||||
void update_gestures(void); // Update gestures detected (must be called every frame)
|
||||
|
||||
#if defined(RGESTURES_STANDALONE)
|
||||
void set_gestures_enabled(unsigned int flags); // Enable a set of gestures using flags
|
||||
bool is_gesture_detected(int gesture); // Check if a gesture have been detected
|
||||
int get_gesture_detected(void); // Get latest detected gesture
|
||||
|
||||
float get_gesture_hold_duration(void); // Get gesture hold time in seconds
|
||||
Vector2 get_gesture_drag_vector(void); // Get gesture drag vector
|
||||
float get_gesture_drag_angle(void); // Get gesture drag angle
|
||||
Vector2 get_gesture_pinch_vector(void); // Get gesture pinch delta
|
||||
float get_gesture_pinch_angle(void); // Get gesture pinch angle
|
||||
#endif
|
||||
|
||||
RL_EXTERN_C_END
|
||||
|
||||
RL_NS_END
|
||||
|
||||
#endif // RGESTURES_H
|
||||
|
||||
/***********************************************************************************
|
||||
*
|
||||
* RGESTURES IMPLEMENTATION
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(RGESTURES_IMPLEMENTATION)
|
||||
|
||||
#if defined(RGESTURES_STANDALONE)
|
||||
#if defined(_WIN32)
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
// Functions required to query time on Windows
|
||||
int __stdcall query_performance_counter(unsigned long long int *lpPerformanceCount);
|
||||
int __stdcall query_performance_frequency(unsigned long long int *lpFrequency);
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#elif defined(__linux__)
|
||||
#if _POSIX_C_SOURCE < 199309L
|
||||
#undef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 199309L // Required for CLOCK_MONOTONIC if compiled with c99 without gnu ext.
|
||||
#endif
|
||||
#include <sys/time.h> // Required for: timespec
|
||||
#include <time.h> // Required for: clock_gettime()
|
||||
|
||||
#include <math.h> // Required for: sqrtf(), atan2f()
|
||||
#endif
|
||||
#if defined(__APPLE__) // macOS also defines __MACH__
|
||||
#include <mach/clock.h> // Required for: clock_get_time()
|
||||
#include <mach/mach.h> // Required for: mach_timespec_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
#define RL_FORCE_TO_SWIPE 0.2f // Swipe force, measured in normalized screen units/time
|
||||
#define RL_MINIMUM_DRAG 0.015f // Drag minimum force, measured in normalized screen units (0.0f to 1.0f)
|
||||
#define RL_DRAG_TIMEOUT 0.3f // Drag minimum time for web, measured in seconds
|
||||
#define RL_MINIMUM_PINCH 0.005f // Pinch minimum force, measured in normalized screen units (0.0f to 1.0f)
|
||||
#define RL_TAP_TIMEOUT 0.3f // Tap minimum time, measured in seconds
|
||||
#define RL_PINCH_TIMEOUT 0.3f // Pinch minimum time, measured in seconds
|
||||
#define RL_DOUBLETAP_RANGE 0.03f // DoubleTap range, measured in normalized screen units (0.0f to 1.0f)
|
||||
|
||||
RL_NS_BEGIN
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Gestures module state context [136 bytes]
|
||||
typedef struct {
|
||||
unsigned int current; // Current detected gesture
|
||||
unsigned int enabledFlags; // Enabled gestures flags
|
||||
struct {
|
||||
int firstId; // Touch id for first touch point
|
||||
int pointCount; // Touch points counter
|
||||
double eventTime; // Time stamp when an event happened
|
||||
Vector2 upPosition; // Touch up position
|
||||
Vector2 downPositionA; // First touch down position
|
||||
Vector2 downPositionB; // Second touch down position
|
||||
Vector2 downDragPosition; // Touch drag position
|
||||
Vector2 moveDownPositionA; // First touch down position on move
|
||||
Vector2 moveDownPositionB; // Second touch down position on move
|
||||
Vector2 previousPositionA; // Previous position A to compare for pinch gestures
|
||||
Vector2 previousPositionB; // Previous position B to compare for pinch gestures
|
||||
int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions)
|
||||
} Touch;
|
||||
struct {
|
||||
bool resetRequired; // HOLD reset to get first touch point again
|
||||
double timeDuration; // HOLD duration in seconds
|
||||
} Hold;
|
||||
struct {
|
||||
Vector2 vector; // DRAG vector (between initial and current position)
|
||||
float angle; // DRAG angle (relative to x-axis)
|
||||
float distance; // DRAG distance (from initial touch point to final) (normalized [0..1])
|
||||
float intensity; // DRAG intensity, how far why did the DRAG (pixels per frame)
|
||||
} Drag;
|
||||
struct {
|
||||
double startTime; // SWIPE start time to calculate drag intensity
|
||||
} Swipe;
|
||||
struct {
|
||||
Vector2 vector; // PINCH vector (between first and second touch points)
|
||||
float angle; // PINCH angle (relative to x-axis)
|
||||
float distance; // PINCH displacement distance (normalized [0..1])
|
||||
} Pinch;
|
||||
} GesturesData;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
static GesturesData GESTURES = {
|
||||
#ifdef __cplusplus
|
||||
(unsigned int)-1,
|
||||
GESTURE_NONE,
|
||||
0b0000001111111111
|
||||
#else
|
||||
.Touch.firstId = -1,
|
||||
.current = GESTURE_NONE, // No current gesture detected
|
||||
.enabledFlags = 0b0000001111111111 // All gestures supported by default
|
||||
#endif
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
static float rg_vector2_angle(Vector2 initialPosition, Vector2 finalPosition);
|
||||
static float rg_vector2_distance(Vector2 v1, Vector2 v2);
|
||||
static double rg_get_current_time(void);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Enable only desired gestures to be detected
|
||||
void set_gestures_enabled(unsigned int flags)
|
||||
{
|
||||
GESTURES.enabledFlags = flags;
|
||||
}
|
||||
|
||||
// Check if a gesture have been detected
|
||||
bool is_gesture_detected(unsigned int gesture)
|
||||
{
|
||||
if ((GESTURES.enabledFlags & GESTURES.current) == gesture) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
// Process gesture event and translate it into gestures
|
||||
void process_gesture_event(GestureEvent event)
|
||||
{
|
||||
// Reset required variables
|
||||
GESTURES.Touch.pointCount = event.pointCount; // Required on update_gestures()
|
||||
|
||||
if (GESTURES.Touch.pointCount == 1) // One touch point
|
||||
{
|
||||
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||
{
|
||||
GESTURES.Touch.tapCounter++; // Tap counter
|
||||
|
||||
// Detect GESTURE_DOUBLE_TAP
|
||||
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((rg_get_current_time() - GESTURES.Touch.eventTime) < RL_TAP_TIMEOUT) && (rg_vector2_distance(GESTURES.Touch.downPositionA, event.position[0]) < RL_DOUBLETAP_RANGE))
|
||||
{
|
||||
GESTURES.current = GESTURE_DOUBLETAP;
|
||||
GESTURES.Touch.tapCounter = 0;
|
||||
}
|
||||
else // Detect GESTURE_TAP
|
||||
{
|
||||
GESTURES.Touch.tapCounter = 1;
|
||||
GESTURES.current = GESTURE_TAP;
|
||||
}
|
||||
|
||||
GESTURES.Touch.downPositionA = event.position[0];
|
||||
GESTURES.Touch.downDragPosition = event.position[0];
|
||||
|
||||
GESTURES.Touch.upPosition = GESTURES.Touch.downPositionA;
|
||||
GESTURES.Touch.eventTime = rg_get_current_time();
|
||||
|
||||
GESTURES.Swipe.startTime = rg_get_current_time();
|
||||
|
||||
#ifdef __cplusplus
|
||||
GESTURES.Drag.vector = Vector2{ 0.0f, 0.0f };
|
||||
#else
|
||||
GESTURES.Drag.vector = (Vector2){ 0.0f, 0.0f };
|
||||
#endif
|
||||
}
|
||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||
{
|
||||
// A swipe can happen while the current gesture is drag, but (specially for web) also hold, so set upPosition for both cases
|
||||
if (GESTURES.current == GESTURE_DRAG || GESTURES.current == GESTURE_HOLD) GESTURES.Touch.upPosition = event.position[0];
|
||||
|
||||
// NOTE: GESTURES.Drag.intensity dependent on the resolution of the screen
|
||||
GESTURES.Drag.distance = rg_vector2_distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rg_get_current_time() - GESTURES.Swipe.startTime));
|
||||
|
||||
// Detect GESTURE_SWIPE
|
||||
if ((GESTURES.Drag.intensity > RL_FORCE_TO_SWIPE) && (GESTURES.current != GESTURE_DRAG))
|
||||
{
|
||||
// NOTE: Angle should be inverted in Y
|
||||
GESTURES.Drag.angle = 360.0f - rg_vector2_angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
|
||||
if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right
|
||||
else if ((GESTURES.Drag.angle >= 30) && (GESTURES.Drag.angle <= 150)) GESTURES.current = GESTURE_SWIPE_UP; // Up
|
||||
else if ((GESTURES.Drag.angle > 150) && (GESTURES.Drag.angle < 210)) GESTURES.current = GESTURE_SWIPE_LEFT; // Left
|
||||
else if ((GESTURES.Drag.angle >= 210) && (GESTURES.Drag.angle <= 330)) GESTURES.current = GESTURE_SWIPE_DOWN; // Down
|
||||
else GESTURES.current = GESTURE_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
GESTURES.Drag.distance = 0.0f;
|
||||
GESTURES.Drag.intensity = 0.0f;
|
||||
GESTURES.Drag.angle = 0.0f;
|
||||
|
||||
GESTURES.current = GESTURE_NONE;
|
||||
}
|
||||
|
||||
#if __cplusplus
|
||||
GESTURES.Touch.downDragPosition = Vector2{ 0.0f, 0.0f };
|
||||
#else
|
||||
GESTURES.Touch.downDragPosition = (Vector2){ 0.0f, 0.0f };
|
||||
#endif
|
||||
GESTURES.Touch.pointCount = 0;
|
||||
}
|
||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||
{
|
||||
GESTURES.Touch.moveDownPositionA = event.position[0];
|
||||
|
||||
if (GESTURES.current == GESTURE_HOLD)
|
||||
{
|
||||
if (GESTURES.Hold.resetRequired) GESTURES.Touch.downPositionA = event.position[0];
|
||||
|
||||
GESTURES.Hold.resetRequired = false;
|
||||
|
||||
// Detect GESTURE_DRAG
|
||||
if ((rg_get_current_time() - GESTURES.Touch.eventTime) > RL_DRAG_TIMEOUT)
|
||||
{
|
||||
GESTURES.Touch.eventTime = rg_get_current_time();
|
||||
GESTURES.current = GESTURE_DRAG;
|
||||
}
|
||||
}
|
||||
|
||||
GESTURES.Drag.vector.x = GESTURES.Touch.moveDownPositionA.x - GESTURES.Touch.downDragPosition.x;
|
||||
GESTURES.Drag.vector.y = GESTURES.Touch.moveDownPositionA.y - GESTURES.Touch.downDragPosition.y;
|
||||
}
|
||||
}
|
||||
else if (GESTURES.Touch.pointCount == 2) // Two touch points
|
||||
{
|
||||
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||
{
|
||||
GESTURES.Touch.downPositionA = event.position[0];
|
||||
GESTURES.Touch.downPositionB = event.position[1];
|
||||
|
||||
GESTURES.Touch.previousPositionA = GESTURES.Touch.downPositionA;
|
||||
GESTURES.Touch.previousPositionB = GESTURES.Touch.downPositionB;
|
||||
|
||||
//GESTURES.Pinch.distance = rg_vector2_distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
|
||||
|
||||
GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x;
|
||||
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
|
||||
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = rg_get_current_time();
|
||||
}
|
||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||
{
|
||||
GESTURES.Pinch.distance = rg_vector2_distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
|
||||
GESTURES.Touch.moveDownPositionA = event.position[0];
|
||||
GESTURES.Touch.moveDownPositionB = event.position[1];
|
||||
|
||||
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
|
||||
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
|
||||
|
||||
if ((rg_vector2_distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.moveDownPositionA) >= RL_MINIMUM_PINCH) || (rg_vector2_distance(GESTURES.Touch.previousPositionB, GESTURES.Touch.moveDownPositionB) >= RL_MINIMUM_PINCH))
|
||||
{
|
||||
if ( rg_vector2_distance(GESTURES.Touch.previousPositionA, GESTURES.Touch.previousPositionB) > rg_vector2_distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) ) GESTURES.current = GESTURE_PINCH_IN;
|
||||
else GESTURES.current = GESTURE_PINCH_OUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = rg_get_current_time();
|
||||
}
|
||||
|
||||
// NOTE: Angle should be inverted in Y
|
||||
GESTURES.Pinch.angle = 360.0f - rg_vector2_angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
}
|
||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||
{
|
||||
GESTURES.Pinch.distance = 0.0f;
|
||||
GESTURES.Pinch.angle = 0.0f;
|
||||
#if __cplusplus
|
||||
GESTURES.Pinch.vector = Vector2{ 0.0f, 0.0f };
|
||||
#else
|
||||
GESTURES.Pinch.vector = (Vector2){ 0.0f, 0.0f };
|
||||
#endif
|
||||
GESTURES.Touch.pointCount = 0;
|
||||
|
||||
GESTURES.current = GESTURE_NONE;
|
||||
}
|
||||
}
|
||||
else if (GESTURES.Touch.pointCount > 2) // More than two touch points
|
||||
{
|
||||
// TODO: Process gesture events for more than two points
|
||||
}
|
||||
}
|
||||
|
||||
// Update gestures detected (must be called every frame)
|
||||
void update_gestures(void)
|
||||
{
|
||||
// NOTE: Gestures are processed through system callbacks on touch events
|
||||
|
||||
// Detect GESTURE_HOLD
|
||||
if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) && (GESTURES.Touch.pointCount < 2))
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = rg_get_current_time();
|
||||
}
|
||||
|
||||
// Detect GESTURE_NONE
|
||||
if ((GESTURES.current == GESTURE_SWIPE_RIGHT) || (GESTURES.current == GESTURE_SWIPE_UP) || (GESTURES.current == GESTURE_SWIPE_LEFT) || (GESTURES.current == GESTURE_SWIPE_DOWN))
|
||||
{
|
||||
GESTURES.current = GESTURE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
// Get latest detected gesture
|
||||
int get_gesture_detected(void)
|
||||
{
|
||||
// Get current gesture only if enabled
|
||||
return (GESTURES.enabledFlags & GESTURES.current);
|
||||
}
|
||||
|
||||
// Hold time measured in ms
|
||||
float get_gesture_hold_duration(void)
|
||||
{
|
||||
// NOTE: time is calculated on current gesture HOLD
|
||||
|
||||
double time = 0.0;
|
||||
|
||||
if (GESTURES.current == GESTURE_HOLD) time = rg_get_current_time() - GESTURES.Hold.timeDuration;
|
||||
|
||||
return (float)time;
|
||||
}
|
||||
|
||||
// Get drag vector (between initial touch point to current)
|
||||
Vector2 get_gesture_drag_vector(void)
|
||||
{
|
||||
// NOTE: drag vector is calculated on one touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Drag.vector;
|
||||
}
|
||||
|
||||
// Get drag angle
|
||||
// NOTE: Angle in degrees, horizontal-right is 0, counterclockwise
|
||||
float get_gesture_drag_angle(void)
|
||||
{
|
||||
// NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP
|
||||
|
||||
return GESTURES.Drag.angle;
|
||||
}
|
||||
|
||||
// Get distance between two pinch points
|
||||
Vector2 get_gesture_pinch_vector(void)
|
||||
{
|
||||
// NOTE: Pinch distance is calculated on two touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Pinch.vector;
|
||||
}
|
||||
|
||||
// Get angle between two pinch points
|
||||
// NOTE: Angle in degrees, horizontal-right is 0, counterclockwise
|
||||
float get_gesture_pinch_angle(void)
|
||||
{
|
||||
// NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Pinch.angle;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// Get angle from two-points vector with X-axis
|
||||
static float rg_vector2_angle(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/RL_PI);
|
||||
|
||||
if (angle < 0) angle += 360.0f;
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
// Calculate distance between two Vector2
|
||||
static float rg_vector2_distance(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float result;
|
||||
|
||||
float dx = v2.x - v1.x;
|
||||
float dy = v2.y - v1.y;
|
||||
|
||||
result = (float)sqrt(dx*dx + dy*dy);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Time measure returned are seconds
|
||||
static double rg_get_current_time(void)
|
||||
{
|
||||
double time = 0;
|
||||
|
||||
#if !defined(RGESTURES_STANDALONE)
|
||||
time = get_time();
|
||||
#else
|
||||
#if defined(_WIN32)
|
||||
unsigned long long int clockFrequency, currentTime;
|
||||
|
||||
query_performance_frequency(&clockFrequency); // BE CAREFUL: Costly operation!
|
||||
query_performance_counter(¤tTime);
|
||||
|
||||
time = (double)currentTime/clockFrequency; // Time in seconds
|
||||
#endif
|
||||
|
||||
#if defined(__linux__)
|
||||
// NOTE: Only for Linux-based systems
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
|
||||
|
||||
time = ((double)nowTime*1e-9); // Time in seconds
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
//#define CLOCK_REALTIME CALENDAR_CLOCK // returns UTC time since 1970-01-01
|
||||
//#define CLOCK_MONOTONIC SYSTEM_CLOCK // returns the time since boot time
|
||||
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t now;
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
|
||||
// NOTE: OS X does not have clock_gettime(), using clock_get_time()
|
||||
clock_get_time(cclock, &now);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
unsigned long long int nowTime = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec; // Time in nanoseconds
|
||||
|
||||
time = ((double)nowTime*1e-9); // Time in seconds
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
RL_NS_END
|
||||
|
||||
#endif // RGESTURES_IMPLEMENTATION
|
4910
project/auxillary/vis_ast/dependencies/raylib/include/rlgl.h
Normal file
4910
project/auxillary/vis_ast/dependencies/raylib/include/rlgl.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,81 @@
|
||||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.utils - Some common utility functions
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
* applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||
* wrote the original software. If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||
* as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#include <stdio.h> // Required for: FILE
|
||||
#include <android/asset_manager.h> // Required for: AAssetManager
|
||||
#endif
|
||||
|
||||
#if defined(RL_SUPPORT_TRACELOG)
|
||||
#define RL_TRACELOG(level, ...) RL_NS(trace_log)(level, __VA_ARGS__)
|
||||
|
||||
#if defined(RL_SUPPORT_TRACELOG_DEBUG)
|
||||
#define TRACELOGD(...) RL_NS(trace_log)(LOG_DEBUG, __VA_ARGS__)
|
||||
#else
|
||||
#define TRACELOGD(...) (void)0
|
||||
#endif
|
||||
#else
|
||||
#define RL_TRACELOG(level, ...) (void)0
|
||||
#define TRACELOGD(...) (void)0
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some basic Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
#define fopen(name, mode) android_fopen(name, mode)
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
// Nop...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
void init_asset_manager(AAssetManager *manager, const char *dataPath); // Initialize asset manager from android app
|
||||
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() -> Read-only!
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // UTILS_H
|
BIN
project/auxillary/vis_ast/dependencies/raylib/lib/raylib.exp
Normal file
BIN
project/auxillary/vis_ast/dependencies/raylib/lib/raylib.exp
Normal file
Binary file not shown.
8
project/auxillary/vis_ast/dependencies/raylib/raylib.c
Normal file
8
project/auxillary/vis_ast/dependencies/raylib/raylib.c
Normal file
@ -0,0 +1,8 @@
|
||||
#include "raudio.c"
|
||||
#include "rcore.c"
|
||||
#include "rglfw.c"
|
||||
#include "rmodels.c"
|
||||
#include "rshapes.c"
|
||||
#include "rtext.c"
|
||||
#include "rtextures.c"
|
||||
#include "rutils.c"
|
1019
project/auxillary/vis_ast/dependencies/raylib/raylib_cpp.refactor
Normal file
1019
project/auxillary/vis_ast/dependencies/raylib/raylib_cpp.refactor
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,242 @@
|
||||
// rlgl.h
|
||||
|
||||
word RL_NOT_REFACTORED, RL_REFACTORED_CPP
|
||||
|
||||
namespace rl_,
|
||||
namespace rl,
|
||||
namespace rlgl,
|
||||
not word rl
|
||||
not word rlgl
|
||||
|
||||
namespace RL_LOG_, LOG_
|
||||
namespace RL_PIXELFORMAT_, PIXELFORMAT_
|
||||
namespace RL_TEXTURE_, TEXTURE_
|
||||
namespace RL_SHADER_, SHADER_
|
||||
namespace RL_BLEND_, BLEND_
|
||||
namespace RL_ATTACHMENT_, ATTACHMENT_
|
||||
namespace RL_CULL_, CULL_
|
||||
|
||||
not include rlgl.h
|
||||
|
||||
word TRACELOG, RL_TRACELOG
|
||||
|
||||
word RLGL, GLOBAL_DATA
|
||||
|
||||
word Vector2, Vector2
|
||||
word Vector3, Vector3
|
||||
word Vector4, Vector4
|
||||
word Quaternion, Quaternion
|
||||
word Matrix, Matrix
|
||||
word Color, Color
|
||||
word Rectangle, Rectangle
|
||||
word Image, Image
|
||||
word Texture, Texture
|
||||
word Texture2D, Texture2d
|
||||
word TextureCubemap, Texture_Cubemap
|
||||
word RenderTexture, Render_Texture
|
||||
word RenderTexture2D, Render_Texture2D
|
||||
word NPatchInfo, N_Patch_Info
|
||||
word GlyphInfo, Glyph_Info
|
||||
word Font, Font
|
||||
word Camera3D, Camera3D
|
||||
word Camera, Camera
|
||||
word Camera2D, Camera2D
|
||||
word Mesh, Mesh
|
||||
word Shader, Shader
|
||||
word MaterialMap, Material_Map
|
||||
word Material, Material
|
||||
word Transform, Transform
|
||||
word BoneInfo, Bone_Info
|
||||
word Model, Model
|
||||
word ModelAnimation, Model_Animation
|
||||
word Ray, Ray
|
||||
word RayCollision, Ray_Collision
|
||||
word BoundingBox, Bounding_box
|
||||
word Wave, Wave
|
||||
word rAudioBuffer, Audio_Buffer
|
||||
word rAudioProcessor, Audio_Processor
|
||||
word AudioStream, Audio_Stream
|
||||
word Sound, Sound
|
||||
word Music, Music
|
||||
word VrDeviceInfo, VR_Device_Info
|
||||
word VrStereoConfig, VR_Stereo_Config
|
||||
word FilePathList, File_Path_List
|
||||
word AutomationEvent, Automation_Event
|
||||
word AutomationEventList, Automation_Event_List
|
||||
word Matrix, Matrix
|
||||
|
||||
word rlVertexBuffer, vertex_buffer
|
||||
word rlDrawCall, draw_call
|
||||
word rlRenderBatch, render_batch
|
||||
word rlGlVersion, gl_version
|
||||
word rlTraceLogLevel, trace_log_level
|
||||
word rlPixelFormat, pixel_format
|
||||
word rlTextureFilter, texture_filter
|
||||
word rlShaderLocationIndex, shader_location_index
|
||||
word rlShaderUniformDataType, shader_uniform_data_type
|
||||
word rlShaderAttributeDataType, shader_attribute_data_type
|
||||
word rlBlendMode, blend_mode
|
||||
word rlFramebufferAttachType, framebuffer_attach_type
|
||||
word rlFramebufferAttachTextureType, framebuffer_attach_texture_type
|
||||
word rlCullMode, cull_mode
|
||||
|
||||
word get_pixel_data_size, gpu_get_pixel_data_size
|
||||
|
||||
word rlMatrixMode, matrix_mode
|
||||
word rlPushMatrix, push_matrix
|
||||
word rlPopMatrix, pop_matrix
|
||||
word rlLoadIdentity, load_identity
|
||||
word rlTranslatef, translatef
|
||||
word rlRotatef, rotatef
|
||||
word rlScalef, scalef
|
||||
word rlMultMatrixf, mult_matrixf
|
||||
word rlFrustum, frustum
|
||||
word rlOrtho, ortho
|
||||
word rlViewport, viewport
|
||||
word rlBegin, begin
|
||||
word rlEnd, end
|
||||
word rlVertex2i, vertex2i
|
||||
word rlVertex2f, vertex2f
|
||||
word rlVertex3f, vertex3f
|
||||
word rlTexCoord2f, tex_coord2f
|
||||
word rlNormal3f, normal3f
|
||||
word rlColor4ub, color4ub
|
||||
word rlColor3f, color3f
|
||||
word rlColor4f, color4f
|
||||
word rlEnableVertexArray, enable_vertex_array
|
||||
word rlDisableVertexArray, disable_vertex_array
|
||||
word rlEnableVertexBuffer, enable_vertex_buffer
|
||||
word rlDisableVertexBuffer, disable_vertex_buffer
|
||||
word rlEnableVertexBufferElement, enable_vertex_buffer_element
|
||||
word rlDisableVertexBufferElement, disable_vertex_buffer_element
|
||||
word rlEnableVertexAttribute, enable_vertex_attribute
|
||||
word rlDisableVertexAttribute, disable_vertex_attribute
|
||||
word rlEnableStatePointer, enable_state_pointer
|
||||
word rlDisableStatePointer, disable_state_pointer
|
||||
word rlActiveTextureSlot, active_texture_slot
|
||||
word rlEnableTexture, enable_texture
|
||||
word rlDisableTexture, disable_texture
|
||||
word rlEnableTextureCubemap, enable_texture_cubemap
|
||||
word rlDisableTextureCubemap, disable_texture_cubemap
|
||||
word rlTextureParameters, texture_parameters
|
||||
word rlCubemapParameters, cubemap_parameters
|
||||
word rlEnableShader, enable_shader
|
||||
word rlDisableShader, disable_shader
|
||||
word rlEnableFramebuffer, enable_framebuffer
|
||||
word rlDisableFramebuffer, disable_framebuffer
|
||||
word rlActiveDrawBuffers, active_draw_buffers
|
||||
word rlBlitFramebuffer, blit_framebuffer
|
||||
word rlEnableColorBlend, enable_color_blend
|
||||
word rlDisableColorBlend, disable_color_blend
|
||||
word rlEnableDepthTest, enable_depth_test
|
||||
word rlDisableDepthTest, disable_depth_test
|
||||
word rlEnableDepthMask, enable_depth_mask
|
||||
word rlDisableDepthMask, disable_depth_mask
|
||||
word rlEnableBackfaceCulling, enable_backface_culling
|
||||
word rlDisableBackfaceCulling, disable_backface_culling
|
||||
word rlSetCullFace, set_cull_face
|
||||
word rlEnableScissorTest, enable_scissor_test
|
||||
word rlDisableScissorTest, disable_scissor_test
|
||||
word rlScissor, scissor
|
||||
word rlEnableWireMode, enable_wire_mode
|
||||
word rlEnablePointMode, enable_point_mode
|
||||
word rlDisableWireMode, disable_wire_mode
|
||||
word rlSetLineWidth, set_line_width
|
||||
word rlGetLineWidth, get_line_width
|
||||
word rlEnableSmoothLines, enable_smooth_lines
|
||||
word rlDisableSmoothLines, disable_smooth_lines
|
||||
word rlEnableStereoRender, enable_stereo_render
|
||||
word rlDisableStereoRender, disable_stereo_render
|
||||
word rlIsStereoRenderEnabled, is_stereo_render_enabled
|
||||
word rlClearColor, clear_color
|
||||
word rlClearScreenBuffers, clear_screen_buffers
|
||||
word rlCheckErrors, check_errors
|
||||
word rlSetBlendMode, set_blend_mode
|
||||
word rlSetBlendFactors, set_blend_factors
|
||||
word rlSetBlendFactorsSeparate, set_blend_factors_separate
|
||||
word rlglInit, init
|
||||
word rlglClose, close
|
||||
word rlLoadExtensions, load_extensions
|
||||
word rlGetVersion, get_version
|
||||
word rlSetFramebufferWidth, set_framebuffer_width
|
||||
word rlGetFramebufferWidth, get_framebuffer_width
|
||||
word rlSetFramebufferHeight, set_framebuffer_height
|
||||
word rlGetFramebufferHeight, get_framebuffer_height
|
||||
word rlGetTextureIdDefault, get_texture_id_default
|
||||
word rlGetShaderIdDefault, get_shader_id_default
|
||||
word rlLoadRenderBatch, load_render_batch
|
||||
word rlUnloadRenderBatch, unload_render_batch
|
||||
word rlDrawRenderBatch, draw_render_batch
|
||||
word rlSetRenderBatchActive, set_render_batch_active
|
||||
word rlDrawRenderBatchActive, draw_render_batch_active
|
||||
word rlCheckRenderBatchLimit, check_render_batch_limit
|
||||
word rlSetTexture, set_texture
|
||||
word rlLoadVertexArray, load_vertex_array
|
||||
word rlLoadVertexBuffer, load_vertex_buffer
|
||||
word rlLoadVertexBufferElement, load_vertex_buffer_element
|
||||
word rlUpdateVertexBuffer, update_vertex_buffer
|
||||
word rlUpdateVertexBufferElements, update_vertex_buffer_elements
|
||||
word rlUnloadVertexArray, unload_vertex_array
|
||||
word rlUnloadVertexBuffer, unload_vertex_buffer
|
||||
word rlSetVertexAttribute, set_vertex_attribute
|
||||
word rlSetVertexAttributeDivisor, set_vertex_attribute_divisor
|
||||
word rlSetVertexAttributeDefault, set_vertex_attribute_default
|
||||
word rlDrawVertexArray, draw_vertex_array
|
||||
word rlDrawVertexArrayElements, draw_vertex_array_elements
|
||||
word rlDrawVertexArrayInstanced, draw_vertex_array_instanced
|
||||
word rlDrawVertexArrayElementsInstanced, draw_vertex_array_elements_instanced
|
||||
word rlLoadTexture, load_texture
|
||||
word rlLoadTextureDepth, load_texture_depth
|
||||
word rlLoadTextureCubemap, load_texture_cubemap
|
||||
word rlUpdateTexture, update_texture
|
||||
word rlGetGlTextureFormats, get_gl_texture_formats
|
||||
word rlUnloadTexture, unload_texture
|
||||
word rlGenTextureMipmaps, gen_texture_mipmaps
|
||||
word rlLoadFramebuffer, load_framebuffer
|
||||
word rlFramebufferAttach, framebuffer_attach
|
||||
word rlFramebufferComplete, framebuffer_complete
|
||||
word rlUnloadFramebuffer, unload_framebuffer
|
||||
word rlLoadShaderCode, load_shader_code
|
||||
word rlCompileShader, compile_shader
|
||||
word rlLoadShaderProgram, load_shader_program
|
||||
word rlUnloadShaderProgram, unload_shader_program
|
||||
word rlGetLocationUniform, get_location_uniform
|
||||
word rlGetLocationAttrib, get_location_attrib
|
||||
word rlSetUniform, set_uniform
|
||||
word rlSetUniformMatrix, set_uniform_matrix
|
||||
word rlSetUniformSampler, set_uniform_sampler
|
||||
word rlSetShader, set_shader
|
||||
word rlLoadComputeShaderProgram, load_compute_shader_program
|
||||
word rlComputeShaderDispatch, compute_shader_dispatch
|
||||
word rlLoadShaderBuffer, load_shader_buffer
|
||||
word rlUnloadShaderBuffer, unload_shader_buffer
|
||||
word rlUpdateShaderBuffer, update_shader_buffer
|
||||
word rlBindShaderBuffer, bind_shader_buffer
|
||||
word rlReadShaderBuffer, read_shader_buffer
|
||||
word rlCopyShaderBuffer, copy_shader_buffer
|
||||
word rlGetShaderBufferSize, get_shader_buffer_size
|
||||
word rlBindImageTexture, bind_image_texture
|
||||
word rlGetMatrixModelview, get_matrix_modelview
|
||||
word rlGetMatrixProjection, get_matrix_projection
|
||||
word rlGetMatrixTransform, get_matrix_transform
|
||||
word rlGetMatrixProjectionStereo, get_matrix_projection_stereo
|
||||
word rlGetMatrixViewOffsetStereo, get_matrix_view_offset_stereo
|
||||
word rlSetMatrixProjection, set_matrix_projection
|
||||
word rlSetMatrixModelview, set_matrix_modelview
|
||||
word rlSetMatrixProjectionStereo, set_matrix_projection_stereo
|
||||
word rlSetMatrixViewOffsetStereo, set_matrix_view_offset_stereo
|
||||
word rlLoadDrawCube, load_draw_cube
|
||||
word rlLoadDrawQuad, load_draw_quad
|
||||
word rlLoadShaderDefault, load_shader_default
|
||||
word rlUnloadShaderDefault, unload_shader_default
|
||||
word rlGetPixelDataSize, internal_get_pixel_data_size
|
||||
word rlMatrixIdentity, internal_matrix_identity
|
||||
word rlMatrixMultiply, internal_matrix_multiply
|
||||
word rlCheckRenderBatchLimit, check_render_batch_limit
|
||||
word rlLoadShaderDefault, load_shader_default
|
||||
word rlSetMatrixProjection, set_matrix_projection
|
||||
word rlUnloadFramebuffer, unload_framebuffer
|
||||
word rlReadScreenPixels, read_screen_pixels
|
||||
word rlReadTexturePixels, read_texture_pixels
|
||||
word rlGetShaderLocsDefault, get_shader_locs_default
|
||||
word rlGetPixelFormatName, get_pixel_format_name
|
@ -0,0 +1,322 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_BENCHMARK
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
// #define GEN_IMPLEMENTATION
|
||||
#include "gen.cpp"
|
||||
#include "gen.builder.cpp"
|
||||
|
||||
|
||||
constexpr char const* path_config_h = "config.h";
|
||||
constexpr char const* path_raylib_h = "raylib.h";
|
||||
constexpr char const* path_raymath_h = "raymath.h";
|
||||
constexpr char const* path_rcamera_h = "rcamera.h";
|
||||
constexpr char const* path_rcore_h = "rcore.h";
|
||||
constexpr char const* path_rgestures_h = "rgestures.h";
|
||||
constexpr char const* path_rgl_h = "rgl.h";
|
||||
constexpr char const* path_rtext_h = "rtext.h";
|
||||
|
||||
constexpr char const* path_rcore_desktop_c = "rcore_desktop.c";
|
||||
|
||||
constexpr char const* path_raudio_c = "raudio.c";
|
||||
constexpr char const* path_rcore_c = "rcore.c";
|
||||
constexpr char const* path_rglfw_c = "rglfw.c";
|
||||
constexpr char const* path_rmodels_c = "rmodels.c";
|
||||
constexpr char const* path_rtext_c = "rtext.c";
|
||||
constexpr char const* path_rtextures_c = "rtextures.c";
|
||||
constexpr char const* path_rutils_c = "rutils.c";
|
||||
|
||||
using namespace gen;
|
||||
|
||||
StringCached upper_snake_to_mixed_snake(StringCached str)
|
||||
{
|
||||
local_persist String scratch = String::make_reserve(GlobalAllocator, kilobytes(1));
|
||||
scratch.clear();
|
||||
|
||||
bool capitalizeNext = true;
|
||||
|
||||
for (s32 index = 0; index < str.length(); ++index)
|
||||
{
|
||||
char c = str[index];
|
||||
|
||||
if (c == '_')
|
||||
{
|
||||
scratch.append(c);
|
||||
capitalizeNext = true;
|
||||
}
|
||||
else if (capitalizeNext)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
{
|
||||
scratch.append(c - 32); // Convert to uppercase
|
||||
}
|
||||
else
|
||||
{
|
||||
scratch.append(c);
|
||||
}
|
||||
capitalizeNext = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
scratch.append(c + 32); // Convert to lowercase
|
||||
}
|
||||
else
|
||||
{
|
||||
scratch.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringCached result = get_cached_string(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
StringCached pascal_to_lower_snake(StringCached str)
|
||||
{
|
||||
local_persist String scratch = String::make_reserve(GlobalAllocator, kilobytes(1));
|
||||
scratch.clear();
|
||||
|
||||
for (s32 index = 0; index < str.length(); ++index)
|
||||
{
|
||||
char c = str[index];
|
||||
char next = (index + 1 < str.length()) ? str[index + 1] : '\0'; // Ensure we don't go out of bounds
|
||||
|
||||
// Whitelist check for "2D" and "3D"
|
||||
if ((c == '2' || c == '3' | c == '4') && (next == 'D' || next == 'd'))
|
||||
{
|
||||
if (index > 0) // If it's not the start of the string, append an underscore
|
||||
{
|
||||
char* prev = str.Data + index - 1;
|
||||
if (*prev != '_') // Avoid double underscores
|
||||
{
|
||||
scratch.append('_');
|
||||
}
|
||||
}
|
||||
scratch.append(c);
|
||||
scratch.append('d'); // Convert to lowercase
|
||||
index++; // Skip the next character since we've already processed it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
char* prev = (index > 0) ? str.Data + index - 1 : nullptr;
|
||||
|
||||
if ((index > 0 && prev && *prev >= 'a' && *prev <= 'z') ||
|
||||
(prev && char_is_digit(*prev) && (next >= 'A' && next <= 'Z')))
|
||||
{
|
||||
scratch.append('_');
|
||||
}
|
||||
|
||||
scratch.append(c + 32);
|
||||
}
|
||||
else if (char_is_digit(c) && (next >= 'A' && next <= 'Z')) // Check for a number followed by an uppercase letter
|
||||
{
|
||||
scratch.append(c);
|
||||
scratch.append('_');
|
||||
}
|
||||
else
|
||||
{
|
||||
scratch.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
StringCached result = get_cached_string(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
void refactor_define( CodeDefine& code )
|
||||
{
|
||||
local_persist String name_scratch = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
if ( str_compare( elem->Name, txt("RL"), 2 ) == 0 || str_compare( elem->Name, txt("RAYLIB"), 6 ) == 0 )
|
||||
continue;
|
||||
|
||||
name_scratch.append_fmt( "%RL_%S", elem->Name );
|
||||
elem->Name = get_cached_string( name_scratch );
|
||||
name_scratch.clear();
|
||||
}
|
||||
|
||||
void refactor_enum( CodeEnum& code )
|
||||
{
|
||||
for ( Code elem : code->Body )
|
||||
{
|
||||
if ( elem->Type == ECode::Untyped )
|
||||
{
|
||||
elem->Content = upper_snake_to_mixed_snake( elem->Content );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void refactor_typename( CodeType& type )
|
||||
{
|
||||
local_persist CodeType t_unsigned_char = parse_type( code(unsigned char) );
|
||||
local_persist CodeType t_unsigned_char_ptr = parse_type( code(unsigned char*) );
|
||||
local_persist CodeType t_unsigned_short_ptr = parse_type( code(unsigned short*) );
|
||||
local_persist CodeType t_int = parse_type( code(int) );
|
||||
local_persist CodeType t_int_ptr = parse_type( code(int*) );
|
||||
local_persist CodeType t_unsigned_int = parse_type( code(unsigned int) );
|
||||
local_persist CodeType t_float = parse_type( code(float) );
|
||||
local_persist CodeType t_float_ptr = parse_type( code(float*) );
|
||||
|
||||
local_persist CodeType t_f32_ptr = parse_type( code(f32*) );
|
||||
local_persist CodeType t_u8_ptr = parse_type( code(u8*) );
|
||||
local_persist CodeType t_s32_ptr = parse_type( code(s32*) );
|
||||
|
||||
String type_str = type.to_string();
|
||||
|
||||
if ( str_compare( type_str, t_unsigned_char.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_u8.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_unsigned_char_ptr.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_u8_ptr.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_unsigned_short_ptr.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_u8_ptr.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_int.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_s32.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_int_ptr.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_s32_ptr.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_unsigned_int.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_u32.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_float.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_f32.ast;
|
||||
}
|
||||
if ( str_compare( type_str, t_float_ptr.to_string() ) == 0 )
|
||||
{
|
||||
type.ast = t_f32_ptr.ast;
|
||||
}
|
||||
}
|
||||
|
||||
void refactor_fn( CodeFn& fn )
|
||||
{
|
||||
StringCached original_name = fn->Name;
|
||||
fn->Name = pascal_to_lower_snake( fn->Name );
|
||||
|
||||
log_fmt( "%S", "Proc ID: %S -> %S", original_name, fn->Name );
|
||||
|
||||
for ( CodeParam param : fn->Params )
|
||||
{
|
||||
refactor_typename( param->ValueType );
|
||||
}
|
||||
}
|
||||
|
||||
void refactor_struct( CodeStruct& code )
|
||||
{
|
||||
for ( Code field : code->Body )
|
||||
{
|
||||
if ( field->Type == ECode::Variable )
|
||||
{
|
||||
CodeVar var = field.cast<CodeVar>();
|
||||
refactor_typename( var->ValueType );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void refactor_file( char const* path )
|
||||
{
|
||||
FileContents contents = file_read_contents( GlobalAllocator, true, path );
|
||||
CodeBody code = parse_global_body( { contents.size, rcast(char const*, contents.data) } );
|
||||
|
||||
local_perist String name_scratch = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
// CodeBody includes
|
||||
// CodeBody nspace_body = def_body( ECode::Namespace );
|
||||
CodeBody new_code = def_body( ECode::Global_Body );
|
||||
|
||||
for ( Code elem : code )
|
||||
{
|
||||
if ( elem->Type == ECode::Preprocess_Define )
|
||||
{
|
||||
refactor_define( elem.cast<CodeDefine>() );
|
||||
}
|
||||
|
||||
if ( elem->Type == ECode::Enum )
|
||||
{
|
||||
refactor_enum( elem.cast<CodeEnum>() );
|
||||
}
|
||||
|
||||
if ( elem->Type == ECode::Typedef )
|
||||
{
|
||||
CodeTypedef td = elem.cast<CodeTypedef>();
|
||||
if ( td->UnderlyingType->Type == ECode::Enum )
|
||||
{
|
||||
CodeEnum code = td->UnderlyingType.cast<CodeEnum>();
|
||||
refactor_enum( code );
|
||||
}
|
||||
if ( td->UnderlyingType->Type == ECode::Struct )
|
||||
{
|
||||
CodeStruct code = td->UnderlyingType.cast<CodeStruct>();
|
||||
refactor_struct( code );
|
||||
}
|
||||
}
|
||||
|
||||
if ( elem->Type == ECode::Struct )
|
||||
{
|
||||
refactor_struct( elem.cast<CodeStruct>() );
|
||||
}
|
||||
|
||||
if ( elem->Type == ECode::Function || elem->Type == ECode::Function_Fwd )
|
||||
{
|
||||
refactor_fn( elem.cast<CodeFn>() );
|
||||
}
|
||||
|
||||
if ( elem->Type == ECode::Extern_Linkage )
|
||||
{
|
||||
CodeBody body = elem.cast<CodeExtern>()->Body;
|
||||
for ( Code elem : body )
|
||||
{
|
||||
if ( elem->Type == ECode::Function || elem->Type == ECode::Function_Fwd )
|
||||
{
|
||||
refactor_fn( elem.cast<CodeFn>() );
|
||||
}
|
||||
}
|
||||
|
||||
Code nspace = def_namespace( txt("raylib"), def_namespace_body( args(elem) ) );
|
||||
elem = nspace;
|
||||
}
|
||||
|
||||
new_code.append( elem );
|
||||
}
|
||||
|
||||
Builder builder = Builder::open( path );
|
||||
builder.print( new_code );
|
||||
builder.write();
|
||||
|
||||
name_scratch.clear();
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
refactor_file( path_config_h );
|
||||
refactor_file( path_raylib_h );
|
||||
refactor_file( path_rcamera_h );
|
||||
refactor_file( path_raymath_h );
|
||||
refactor_file( path_rcore_h );
|
||||
refactor_file( path_rgl_h );
|
||||
refactor_file( path_rtext_h );
|
||||
|
||||
refactor_file( path_rcore_desktop_c );
|
||||
refactor_file( path_raudio_c );
|
||||
refactor_file( path_rcore_c );
|
||||
refactor_file( path_rglfw_c );
|
||||
refactor_file( path_rmodels_c );
|
||||
refactor_file( path_rtext_c );
|
||||
refactor_file( path_rutils_c );
|
||||
|
||||
return 0;
|
||||
}
|
10
project/auxillary/vis_ast/readme.md
Normal file
10
project/auxillary/vis_ast/readme.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Vis AST
|
||||
|
||||
AST visualizer for gencpp
|
||||
|
||||
This is a early start to creating frontend tooling for c/c++ using gencpp as a core component.
|
||||
I'll be exploring creating an AST explorer for this library with raylib as the graphical & general platform vendor for dependencies that go beyond the scope of gencpp.
|
||||
|
||||
For now I'll have its build script in this file, however it will heavily rely on gencpp's helper scripts.
|
||||
|
||||
Whatever sort of UX tooling I setup for this will be reused for the other tools I'll be creating for gencpp.
|
256
project/auxillary/vis_ast/update_deps.ps1
Normal file
256
project/auxillary/vis_ast/update_deps.ps1
Normal file
@ -0,0 +1,256 @@
|
||||
Clear-Host
|
||||
|
||||
$path_root = git rev-parse --show-toplevel
|
||||
$path_scripts = Join-Path $path_root 'scripts'
|
||||
|
||||
$target_arch = Join-Path $path_scripts 'helpers/target_arch.psm1'
|
||||
$devshell = Join-Path $path_scripts 'helpers/devshell.ps1'
|
||||
$format_cpp = Join-Path $path_scripts 'helpers/format_cpp.psm1'
|
||||
$incremental_checks = Join-Path $path_scripts 'helpers/incremental_checks.ps1'
|
||||
$vendor_toolchain = Join-Path $path_scripts 'helpers/vendor_toolchain.ps1'
|
||||
|
||||
$path_project = Join-Path $path_root 'project'
|
||||
$path_aux = Join-Path $path_project 'auxillary'
|
||||
$path_vis_root = Join-Path $path_aux 'vis_ast'
|
||||
$path_binaries = Join-Path $path_vis_root 'binaries'
|
||||
|
||||
$path_deps = Join-Path $path_vis_root 'dependencies'
|
||||
$path_temp = Join-Path $path_deps 'temp'
|
||||
|
||||
Import-Module $target_arch
|
||||
Import-Module $format_cpp
|
||||
|
||||
#region Arguments
|
||||
$vendor = $null
|
||||
$optimize = $null
|
||||
$debug = $null
|
||||
$analysis = $false
|
||||
$dev = $false
|
||||
$verbose = $null
|
||||
|
||||
[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 }
|
||||
"optimize" { $optimize = $true }
|
||||
"debug" { $debug = $true }
|
||||
"analysis" { $analysis = $true }
|
||||
"dev" { $dev = $true }
|
||||
"verbose" { $verbose = $true }
|
||||
}
|
||||
}}
|
||||
#endregion Argument
|
||||
|
||||
# Load up toolchain configuraion
|
||||
. $vendor_toolchain
|
||||
. $incremental_checks
|
||||
|
||||
# Clear out the current content first
|
||||
if ( test-path $path_temp) {
|
||||
remove-item $path_temp -Recurse
|
||||
}
|
||||
New-Item -ItemType Directory -Path $path_temp
|
||||
|
||||
if ( -not (Test-Path $path_binaries) ) {
|
||||
New-Item -ItemType Directory -Path $path_binaries
|
||||
}
|
||||
|
||||
function setup-raylib {
|
||||
$path_raylib = join-path $path_deps 'raylib'
|
||||
$path_raylib_inc = join-path $path_raylib 'include'
|
||||
$path_raylib_lib = join-path $path_raylib 'lib'
|
||||
if ( test-path $path_raylib_inc ) {
|
||||
remove-item $path_raylib_inc -recurse
|
||||
remove-item $path_raylib_lib -recurse
|
||||
}
|
||||
new-item -path $path_raylib_inc -ItemType Directory
|
||||
new-item -path $path_raylib_lib -ItemType Directory
|
||||
|
||||
$url_raylib_zip = 'https://github.com/Ed94/raylib_refactored/archive/refs/heads/refactor-support.zip'
|
||||
$path_raylib_zip = join-path $path_temp 'raylib.zip'
|
||||
|
||||
$path_raylib_master = join-path $path_temp 'raylib_refactored-refactor-support'
|
||||
$path_raylib_src = join-path $path_raylib_master 'src'
|
||||
$path_raylib_platforms = join-path $path_raylib_src 'platforms'
|
||||
$path_raylib_glfw_inc = join-path $path_raylib_src 'external/glfw/include'
|
||||
$path_raylib_gputex = join-path $path_raylib_src 'external/rl_gputex.h'
|
||||
|
||||
if ( test-path $path_raylib_master ) {
|
||||
remove-item $path_raylib_master -Recurse
|
||||
}
|
||||
invoke-webrequest -uri $url_raylib_zip -outfile $path_raylib_zip
|
||||
expand-archive -path $path_raylib_zip -destinationpath $path_temp
|
||||
|
||||
write-host "Building raylib with $vendor"
|
||||
|
||||
$path_build = Join-Path $path_raylib 'build'
|
||||
if ( (Test-Path $path_build) -eq $false ) {
|
||||
New-Item $path_build -ItemType Directory
|
||||
}
|
||||
|
||||
$raylib_headers = Get-ChildItem -Path $path_raylib_src -Filter '*.h' -File
|
||||
$raylib_modules = get-childitem -path $path_raylib_src -filter '*.c' -file
|
||||
|
||||
# Refactor with refactor.exe
|
||||
if ( $true ) {
|
||||
$path_refactor = join-path $path_raylib 'raylib_cpp.refactor'
|
||||
$path_refactor_rlgl = join-path $path_raylib 'raylib_cpp_gl.refactor'
|
||||
|
||||
$files = @()
|
||||
foreach ( $header in $raylib_headers ) {
|
||||
$file_name = split-path $header -leaf
|
||||
|
||||
if ( -not $file_name.Equals('rlgl.h' ) ) {
|
||||
$files += "$header"
|
||||
}
|
||||
}
|
||||
foreach ( $module in $raylib_modules ) {
|
||||
$files += "$module"
|
||||
}
|
||||
|
||||
$files += "$path_raylib_gputex"
|
||||
|
||||
$platform_modules = @()
|
||||
foreach ( $module in (get-childitem -path $path_raylib_platforms -filter '*.c' -file) ) {
|
||||
$platform_modules += "$module"
|
||||
}
|
||||
|
||||
$path_rlgl = join-path $path_raylib_src 'rlgl.h'
|
||||
|
||||
Push-Location $path_raylib_src
|
||||
write-host "Beginning refactor...`n"
|
||||
$refactors = @(@())
|
||||
$refactorParams = @(
|
||||
# "-debug",
|
||||
"-num=$($files.Count)"
|
||||
"-src=$($files)",
|
||||
"-spec=$($path_refactor)"
|
||||
)
|
||||
& refactor $refactorParams
|
||||
Write-Host "`nRefactoring complete`n`n"
|
||||
Pop-Location
|
||||
|
||||
Push-Location $path_raylib_platforms
|
||||
write-host "Beginning refactor...`n"
|
||||
$refactors = @(@())
|
||||
$refactorParams = @(
|
||||
# "-debug",
|
||||
"-num=$($platform_modules.Count)"
|
||||
"-src=$($platform_modules)",
|
||||
"-spec=$($path_refactor)"
|
||||
)
|
||||
& refactor $refactorParams
|
||||
Write-Host "`nRefactoring complete`n`n"
|
||||
Pop-Location
|
||||
|
||||
Push-Location $path_raylib_src
|
||||
$gl_modules = @( "$path_rlgl", "$path_raylib_gputex" )
|
||||
|
||||
write-host "Beginning refactor just for rlgl.h...`n"
|
||||
$refactors = @(@())
|
||||
$refactorParams = @(
|
||||
# "-debug",
|
||||
"-num=$($gl_modules.Count)"
|
||||
"-src=$($gl_modules)",
|
||||
"-spec=$($path_refactor_rlgl)"
|
||||
)
|
||||
& refactor $refactorParams
|
||||
Write-Host "`nRefactoring complete`n`n"
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Refactor raylib with gencpp
|
||||
if ( $false ) {
|
||||
# if ( $false ) {
|
||||
$path_gencpp = join-path $path_root 'project/gen'
|
||||
|
||||
$includes = @(
|
||||
$path_gencpp
|
||||
)
|
||||
|
||||
$compiler_args = @(
|
||||
($flag_define + 'GEN_TIME')
|
||||
)
|
||||
|
||||
$linker_args = @(
|
||||
|
||||
)
|
||||
|
||||
$unit = join-path $path_raylib 'raylib_refactor.cpp'
|
||||
$executable = join-path $path_build 'raylib_refactor.exe'
|
||||
|
||||
$build_result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
Push-Location $path_raylib_src
|
||||
if ( Test-Path( $executable ) ) {
|
||||
Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
}
|
||||
Pop-Location
|
||||
|
||||
push-location $path_scripts
|
||||
# Time to format
|
||||
$fmt_includes = @()
|
||||
foreach ( $header in $raylib_headers ) {
|
||||
$fmt_includes += split-path $header -leaf
|
||||
}
|
||||
foreach ( $module in $raylib_modules ) {
|
||||
$fmt_includes += split-path $module -leaf
|
||||
}
|
||||
format-cpp $path_raylib_src $fmt_includes $null
|
||||
pop-location
|
||||
}
|
||||
|
||||
# Build raylib
|
||||
if ( $true ) {
|
||||
# Microsoft
|
||||
$lib_gdi32 = 'Gdi32.lib'
|
||||
$lib_shell32 = 'Shell32.lib'
|
||||
$lib_xinput = 'Xinput.lib'
|
||||
$lib_user32 = 'User32.lib'
|
||||
$lib_winmm = 'Winmm.lib'
|
||||
|
||||
$includes = @(
|
||||
$path_raylib_src,
|
||||
$path_raylib_glfw_inc
|
||||
)
|
||||
foreach ($include in $includes) {
|
||||
write-host $include
|
||||
}
|
||||
|
||||
$compiler_args = @(
|
||||
($flag_define + 'PLATFORM_DESKTOP'),
|
||||
($flag_define + 'RL_BUILD_LIBTYPE_SHARED'),
|
||||
$flag_all_cpp
|
||||
)
|
||||
$linker_args = @(
|
||||
$flag_link_dll,
|
||||
|
||||
# $lib_xinput,
|
||||
$lib_gdi32,
|
||||
$lib_shell32,
|
||||
$lib_user32,
|
||||
$lib_winmm
|
||||
)
|
||||
|
||||
# $unit = join-path $path_raylib 'raylib.c'
|
||||
$dll = join-path $path_raylib_lib 'raylib.dll'
|
||||
# $build_result = build-simple $path_build $includes $compiler_args $linker_args $unit $dll
|
||||
|
||||
$build_result = build $path_build $includes $compiler_args $linker_args $raylib_modules $dll
|
||||
}
|
||||
|
||||
# Move headers to used include
|
||||
foreach ($header in $raylib_headers) {
|
||||
Copy-Item -Path $header -Destination (join-path $path_raylib_inc (split-path $header -Leaf))
|
||||
}
|
||||
|
||||
# Don't want to remove as it hampers debugging.
|
||||
# remove-item -path $path_temp -Recurse
|
||||
}
|
||||
setup-raylib
|
303
project/bootstrap.cpp
Normal file
303
project/bootstrap.cpp
Normal file
@ -0,0 +1,303 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "helpers/helper.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
#include "dependencies/parsing.cpp"
|
||||
GEN_NS_END
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( "helpers/pop_ignores.inline.hpp" );
|
||||
|
||||
// gen_dep.hpp
|
||||
{
|
||||
Code header_start = scan_file( "dependencies/header_start.hpp" );
|
||||
Code macros = scan_file( "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( "dependencies/memory.hpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.hpp" );
|
||||
Code printing = scan_file( "dependencies/printing.hpp" );
|
||||
Code containers = scan_file( "dependencies/containers.hpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.hpp" );
|
||||
Code strings = scan_file( "dependencies/strings.hpp" );
|
||||
Code filesystem = scan_file( "dependencies/filesystem.hpp" );
|
||||
Code timing = scan_file( "dependencies/timing.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open("gen/gen.dep.hpp");
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "// This file is intended to be included within gen.hpp (There is no pragma diagnostic ignores)\n\n" );
|
||||
header.print( header_start );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( macros );
|
||||
header.print( basic_types );
|
||||
header.print( debug );
|
||||
header.print( memory );
|
||||
header.print( string_ops );
|
||||
header.print( printing );
|
||||
header.print( containers );
|
||||
header.print( hashing );
|
||||
header.print( strings );
|
||||
header.print( filesystem );
|
||||
header.print( timing );
|
||||
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_dep.cpp
|
||||
{
|
||||
Code src_start = scan_file( "dependencies/src_start.cpp" );
|
||||
Code debug = scan_file( "dependencies/debug.cpp" );
|
||||
Code string_ops = scan_file( "dependencies/string_ops.cpp" );
|
||||
Code printing = scan_file( "dependencies/printing.cpp" );
|
||||
Code memory = scan_file( "dependencies/memory.cpp" );
|
||||
Code hashing = scan_file( "dependencies/hashing.cpp" );
|
||||
Code strings = scan_file( "dependencies/strings.cpp" );
|
||||
Code filesystem = scan_file( "dependencies/filesystem.cpp" );
|
||||
Code timing = scan_file( "dependencies/timing.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.dep.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print_fmt( "// This file is intended to be included within gen.cpp (There is no pragma diagnostic ignores)\n\n" );
|
||||
src.print( src_start );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
src.print( debug );
|
||||
src.print( string_ops );
|
||||
src.print( printing );
|
||||
src.print( hashing );
|
||||
src.print( memory );
|
||||
src.print( strings );
|
||||
src.print( filesystem );
|
||||
src.print( timing );
|
||||
|
||||
src.print_fmt( "\nGEN_NS_END\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
fmt_newline,
|
||||
untyped_str( to_str(generation_notice) )
|
||||
));
|
||||
|
||||
// gen.hpp
|
||||
{
|
||||
Code header_start = scan_file( "components/header_start.hpp" );
|
||||
Code types = scan_file( "components/types.hpp" );
|
||||
Code ast = scan_file( "components/ast.hpp" );
|
||||
Code ast_types = scan_file( "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( "components/code_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( code_types );
|
||||
header.print( ast_types );
|
||||
header.print_fmt( "\n#pragma endregion AST\n" );
|
||||
|
||||
header.print( interface );
|
||||
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( fmt_newline );
|
||||
header.print( ast_inlines );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
header.print_fmt( "GEN_NS_END\n\n" );
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
|
||||
Builder
|
||||
header_ecode = Builder::open( "components/gen/ecode.hpp" );
|
||||
header_ecode.print( gen_component_header );
|
||||
header_ecode.print( ecode );
|
||||
header_ecode.write();
|
||||
|
||||
Builder
|
||||
header_eoperator = Builder::open( "components/gen/eoperator.hpp" );
|
||||
header_eoperator.print( gen_component_header );
|
||||
header_eoperator.print( eoperator );
|
||||
header_eoperator.write();
|
||||
|
||||
Builder
|
||||
header_especifier = Builder::open( "components/gen/especifier.hpp" );
|
||||
header_especifier.print( gen_component_header );
|
||||
header_especifier.print( especifier );
|
||||
header_especifier.write();
|
||||
|
||||
Builder
|
||||
header_ast_inlines = Builder::open( "components/gen/ast_inlines.hpp" );
|
||||
header_ast_inlines.print( gen_component_header );
|
||||
header_ast_inlines.print( ast_inlines );
|
||||
header_ast_inlines.write();
|
||||
}
|
||||
|
||||
// gen.cpp
|
||||
{
|
||||
Code src_start = scan_file( "components/src_start.cpp" );
|
||||
Code static_data = scan_file( "components/static_data.cpp" );
|
||||
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
|
||||
Code ast = scan_file( "components/ast.cpp" );
|
||||
Code code_serialization = scan_file( "components/code_serialization.cpp" );
|
||||
Code interface = scan_file( "components/interface.cpp" );
|
||||
Code upfront = scan_file( "components/interface.upfront.cpp" );
|
||||
Code lexer = scan_file( "components/lexer.cpp" );
|
||||
Code parser = scan_file( "components/parser.cpp" );
|
||||
Code parsing_interface = 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( code_serialization );
|
||||
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( lexer );
|
||||
src.print( parser );
|
||||
src.print( parsing_interface );
|
||||
src.print( untyped );
|
||||
src.print_fmt( "\n#pragma endregion Parsing\n\n" );
|
||||
src.print_fmt( "#pragma endregion Interface\n\n" );
|
||||
|
||||
src.print_fmt( "GEN_NS_END\n\n");
|
||||
src.print( pop_ignores );
|
||||
src.write();
|
||||
|
||||
Builder
|
||||
src_etoktype = Builder::open( "components/gen/etoktype.cpp" );
|
||||
src_etoktype.print( gen_component_header );
|
||||
src_etoktype.print( nspaced_etoktype );
|
||||
src_etoktype.write();
|
||||
}
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( "auxillary/builder.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.builder.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "#pragma once\n\n" );
|
||||
header.print( def_include( txt("gen.hpp") ));
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
header.print( builder );
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( "auxillary/builder.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.builder.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( def_include( txt("gen.builder.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
src.print( builder );
|
||||
src.print_fmt( "\nGEN_NS_END\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.hpp" );
|
||||
Code scanner = scan_file( "auxillary/scanner.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.scanner.hpp" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt( "#pragma once\n\n" );
|
||||
header.print( def_include( txt("gen.hpp") ) );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
header.print( parsing );
|
||||
header.print( scanner );
|
||||
header.print_fmt( "GEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
|
||||
// gen_scanner.cpp
|
||||
{
|
||||
Code parsing = scan_file( "dependencies/parsing.cpp" );
|
||||
Code scanner = scan_file( "auxillary/scanner.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.scanner.cpp" );
|
||||
src.print_fmt( generation_notice );
|
||||
src.print( def_include( txt("gen.scanner.hpp") ) );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
src.print( parsing );
|
||||
src.print( scanner );
|
||||
src.print_fmt( "GEN_NS_END\n" );
|
||||
src.write();
|
||||
}
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
456
project/components/ast.hpp
Normal file
456
project/components/ast.hpp
Normal file
@ -0,0 +1,456 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "gen/ecode.hpp"
|
||||
#include "gen/eoperator.hpp"
|
||||
#include "gen/especifier.hpp"
|
||||
#endif
|
||||
|
||||
struct AST;
|
||||
struct AST_Body;
|
||||
struct AST_Attributes;
|
||||
struct AST_Comment;
|
||||
struct AST_Constructor;
|
||||
// struct AST_BaseClass;
|
||||
struct AST_Class;
|
||||
struct AST_Define;
|
||||
struct AST_Destructor;
|
||||
struct AST_Enum;
|
||||
struct AST_Exec;
|
||||
struct AST_Extern;
|
||||
struct AST_Include;
|
||||
struct AST_Friend;
|
||||
struct AST_Fn;
|
||||
struct AST_Module;
|
||||
struct AST_NS;
|
||||
struct AST_Operator;
|
||||
struct AST_OpCast;
|
||||
struct AST_Param;
|
||||
struct AST_Pragma;
|
||||
struct AST_PreprocessCond;
|
||||
struct AST_Specifiers;
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct AST_Expr;
|
||||
struct AST_Expr_Assign;
|
||||
struct AST_Expr_Alignof;
|
||||
struct AST_Expr_Binary;
|
||||
struct AST_Expr_CStyleCast;
|
||||
struct AST_Expr_FunctionalCast;
|
||||
struct AST_Expr_CppCast;
|
||||
struct AST_Expr_ProcCall;
|
||||
struct AST_Expr_Decltype;
|
||||
struct AST_Expr_Comma; // TODO(Ed) : This is a binary op not sure if it needs its own AST...
|
||||
struct AST_Expr_AMS; // Access Member Symbol
|
||||
struct AST_Expr_Sizeof;
|
||||
struct AST_Expr_Subscript;
|
||||
struct AST_Expr_Ternary;
|
||||
struct AST_Expr_UnaryPrefix;
|
||||
struct AST_Expr_UnaryPostfix;
|
||||
struct AST_Expr_Element;
|
||||
|
||||
struct AST_Stmt;
|
||||
struct AST_Stmt_Break;
|
||||
struct AST_Stmt_Case;
|
||||
struct AST_Stmt_Continue;
|
||||
struct AST_Stmt_Decl;
|
||||
struct AST_Stmt_Do;
|
||||
struct AST_Stmt_Expr; // TODO(Ed) : Is this distinction needed? (Should it be a flag instead?)
|
||||
struct AST_Stmt_Else;
|
||||
struct AST_Stmt_If;
|
||||
struct AST_Stmt_For;
|
||||
struct AST_Stmt_Goto;
|
||||
struct AST_Stmt_Label;
|
||||
struct AST_Stmt_Switch;
|
||||
struct AST_Stmt_While;
|
||||
#endif
|
||||
|
||||
struct AST_Struct;
|
||||
struct AST_Template;
|
||||
struct AST_Type;
|
||||
struct AST_Typedef;
|
||||
struct AST_Union;
|
||||
struct AST_Using;
|
||||
struct AST_Var;
|
||||
|
||||
struct Code;
|
||||
struct CodeBody;
|
||||
// These are to offer ease of use and optionally strong type safety for the AST.
|
||||
struct CodeAttributes;
|
||||
// struct CodeBaseClass;
|
||||
struct CodeComment;
|
||||
struct CodeClass;
|
||||
struct CodeConstructor;
|
||||
struct CodeDefine;
|
||||
struct CodeDestructor;
|
||||
struct CodeEnum;
|
||||
struct CodeExec;
|
||||
struct CodeExtern;
|
||||
struct CodeInclude;
|
||||
struct CodeFriend;
|
||||
struct CodeFn;
|
||||
struct CodeModule;
|
||||
struct CodeNS;
|
||||
struct CodeOperator;
|
||||
struct CodeOpCast;
|
||||
struct CodeParam;
|
||||
struct CodePreprocessCond;
|
||||
struct CodePragma;
|
||||
struct CodeSpecifiers;
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct CodeExpr;
|
||||
struct CodeExpr_Assign;
|
||||
struct CodeExpr_Alignof;
|
||||
struct CodeExpr_Binary;
|
||||
struct CodeExpr_CStyleCast;
|
||||
struct CodeExpr_FunctionalCast;
|
||||
struct CodeExpr_CppCast;
|
||||
struct CodeExpr_Element;
|
||||
struct CodeExpr_ProcCall;
|
||||
struct CodeExpr_Decltype;
|
||||
struct CodeExpr_Comma;
|
||||
struct CodeExpr_AMS; // Access Member Symbol
|
||||
struct CodeExpr_Sizeof;
|
||||
struct CodeExpr_Subscript;
|
||||
struct CodeExpr_Ternary;
|
||||
struct CodeExpr_UnaryPrefix;
|
||||
struct CodeExpr_UnaryPostfix;
|
||||
|
||||
struct CodeStmt;
|
||||
struct CodeStmt_Break;
|
||||
struct CodeStmt_Case;
|
||||
struct CodeStmt_Continue;
|
||||
struct CodeStmt_Decl;
|
||||
struct CodeStmt_Do;
|
||||
struct CodeStmt_Expr;
|
||||
struct CodeStmt_Else;
|
||||
struct CodeStmt_If;
|
||||
struct CodeStmt_For;
|
||||
struct CodeStmt_Goto;
|
||||
struct CodeStmt_Label;
|
||||
struct CodeStmt_Switch;
|
||||
struct CodeStmt_While;
|
||||
#endif
|
||||
|
||||
struct CodeStruct;
|
||||
struct CodeTemplate;
|
||||
struct CodeType;
|
||||
struct CodeTypedef;
|
||||
struct CodeUnion;
|
||||
struct CodeUsing;
|
||||
struct CodeVar;
|
||||
|
||||
namespace parser
|
||||
{
|
||||
struct Token;
|
||||
}
|
||||
|
||||
/*
|
||||
AST* wrapper
|
||||
- Not constantly have to append the '*' as this is written often..
|
||||
- Allows for implicit conversion to any of the ASTs (raw or filtered).
|
||||
*/
|
||||
struct Code
|
||||
{
|
||||
# pragma region Statics
|
||||
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
|
||||
static Code Global;
|
||||
|
||||
// Used to identify invalid generated code.
|
||||
static Code Invalid;
|
||||
# pragma endregion Statics
|
||||
|
||||
# define Using_Code( Typename ) \
|
||||
char const* debug_str(); \
|
||||
Code duplicate(); \
|
||||
bool is_equal( Code other ); \
|
||||
bool is_valid(); \
|
||||
void set_global(); \
|
||||
String to_string(); \
|
||||
Typename& operator = ( AST* other ); \
|
||||
Typename& operator = ( Code other ); \
|
||||
bool operator ==( Code other ); \
|
||||
bool operator !=( Code other ); \
|
||||
operator bool();
|
||||
|
||||
Using_Code( Code );
|
||||
|
||||
template< class Type >
|
||||
forceinline Type cast()
|
||||
{
|
||||
return * rcast( Type*, this );
|
||||
}
|
||||
|
||||
AST* operator ->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
Code& operator ++();
|
||||
|
||||
// TODO(Ed) : Remove this overload.
|
||||
auto& operator*()
|
||||
{
|
||||
local_persist thread_local
|
||||
Code NullRef = { nullptr };
|
||||
|
||||
if ( ast == nullptr )
|
||||
return NullRef;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
AST* ast;
|
||||
|
||||
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define operator explicit operator
|
||||
#endif
|
||||
operator CodeBody() const;
|
||||
operator CodeAttributes() const;
|
||||
// operator CodeBaseClass() const;
|
||||
operator CodeComment() const;
|
||||
operator CodeClass() const;
|
||||
operator CodeConstructor() const;
|
||||
operator CodeDefine() const;
|
||||
operator CodeDestructor() const;
|
||||
operator CodeExec() const;
|
||||
operator CodeEnum() const;
|
||||
operator CodeExtern() const;
|
||||
operator CodeInclude() const;
|
||||
operator CodeFriend() const;
|
||||
operator CodeFn() const;
|
||||
operator CodeModule() const;
|
||||
operator CodeNS() const;
|
||||
operator CodeOperator() const;
|
||||
operator CodeOpCast() const;
|
||||
operator CodeParam() const;
|
||||
operator CodePragma() const;
|
||||
operator CodePreprocessCond() const;
|
||||
operator CodeSpecifiers() const;
|
||||
operator CodeStruct() const;
|
||||
operator CodeTemplate() const;
|
||||
operator CodeType() const;
|
||||
operator CodeTypedef() const;
|
||||
operator CodeUnion() const;
|
||||
operator CodeUsing() const;
|
||||
operator CodeVar() const;
|
||||
#undef operator
|
||||
};
|
||||
|
||||
struct Code_POD
|
||||
{
|
||||
AST* ast;
|
||||
};
|
||||
|
||||
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
||||
|
||||
// Desired width of the AST data structure.
|
||||
constexpr int const AST_POD_Size = 128;
|
||||
|
||||
/*
|
||||
Simple AST POD with functionality to seralize into C++ syntax.
|
||||
*/
|
||||
struct AST
|
||||
{
|
||||
# pragma region Member Functions
|
||||
void append ( AST* other );
|
||||
char const* debug_str ();
|
||||
AST* duplicate ();
|
||||
Code& entry ( u32 idx );
|
||||
bool has_entries();
|
||||
bool is_equal ( AST* other );
|
||||
char const* type_str();
|
||||
bool validate_body();
|
||||
|
||||
String to_string();
|
||||
|
||||
neverinline
|
||||
void to_string( String& result );
|
||||
|
||||
template< class Type >
|
||||
forceinline Type cast()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
|
||||
operator Code();
|
||||
operator CodeBody();
|
||||
operator CodeAttributes();
|
||||
// operator CodeBaseClass();
|
||||
operator CodeComment();
|
||||
operator CodeConstructor();
|
||||
operator CodeDestructor();
|
||||
operator CodeClass();
|
||||
operator CodeDefine();
|
||||
operator CodeEnum();
|
||||
operator CodeExec();
|
||||
operator CodeExtern();
|
||||
operator CodeInclude();
|
||||
operator CodeFriend();
|
||||
operator CodeFn();
|
||||
operator CodeModule();
|
||||
operator CodeNS();
|
||||
operator CodeOperator();
|
||||
operator CodeOpCast();
|
||||
operator CodeParam();
|
||||
operator CodePragma();
|
||||
operator CodePreprocessCond();
|
||||
operator CodeSpecifiers();
|
||||
operator CodeStruct();
|
||||
operator CodeTemplate();
|
||||
operator CodeType();
|
||||
operator CodeTypedef();
|
||||
operator CodeUnion();
|
||||
operator CodeUsing();
|
||||
operator CodeVar();
|
||||
# pragma endregion Member Functions
|
||||
|
||||
constexpr static
|
||||
int ArrSpecs_Cap =
|
||||
(
|
||||
AST_POD_Size
|
||||
- sizeof(AST*) * 3
|
||||
- sizeof(parser::Token*)
|
||||
- sizeof(AST*)
|
||||
- sizeof(StringCached)
|
||||
- sizeof(CodeT)
|
||||
- sizeof(ModuleFlag)
|
||||
- sizeof(int)
|
||||
)
|
||||
/ sizeof(int) - 1; // -1 for 4 extra bytes
|
||||
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Macro; // Parameter
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Friend, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
// CodeFlag CodeFlags;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
struct AST_POD
|
||||
{
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* Macro; // Parameter
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Friend, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
struct {
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
};
|
||||
union {
|
||||
AST* Prev;
|
||||
AST* Front;
|
||||
AST* Last;
|
||||
};
|
||||
union {
|
||||
AST* Next;
|
||||
AST* Back;
|
||||
};
|
||||
parser::Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
|
||||
AST* Parent;
|
||||
StringCached Name;
|
||||
CodeT Type;
|
||||
CodeFlag CodeFlags;
|
||||
ModuleFlag ModuleFlags;
|
||||
union {
|
||||
b32 IsFunction; // Used by typedef to not serialize the name field.
|
||||
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
|
||||
OperatorT Op;
|
||||
AccessSpec ParentAccess;
|
||||
s32 NumEntries;
|
||||
};
|
||||
};
|
||||
|
||||
struct test {
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
};
|
||||
|
||||
constexpr int pls = sizeof(test);
|
||||
|
||||
// Its intended for the AST to have equivalent size to its POD.
|
||||
// All extra functionality within the AST namespace should just be syntatic sugar.
|
||||
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );
|
||||
static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
|
||||
|
||||
// Used when the its desired when omission is allowed in a definition.
|
||||
#define NoCode { nullptr }
|
||||
#define CodeInvalid (* Code::Invalid.ast) // Uses an implicitly overloaded cast from the AST to the desired code type.
|
@ -49,7 +49,6 @@
|
||||
case Execution: \
|
||||
case Friend: \
|
||||
case Function_Body: \
|
||||
case Global_Body: \
|
||||
case Namespace_Body: \
|
||||
case Operator_Member: \
|
||||
case Operator_Member_Fwd: \
|
||||
|
1122
project/components/ast_types.hpp
Normal file
1122
project/components/ast_types.hpp
Normal file
File diff suppressed because it is too large
Load Diff
1350
project/components/code_serialization.cpp
Normal file
1350
project/components/code_serialization.cpp
Normal file
File diff suppressed because it is too large
Load Diff
881
project/components/code_types.hpp
Normal file
881
project/components/code_types.hpp
Normal file
@ -0,0 +1,881 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Code Types
|
||||
|
||||
struct CodeBody
|
||||
{
|
||||
Using_Code( CodeBody );
|
||||
|
||||
void append( Code other )
|
||||
{
|
||||
raw()->append( other.ast );
|
||||
}
|
||||
void append( CodeBody body )
|
||||
{
|
||||
for ( Code entry : body )
|
||||
{
|
||||
append( entry );
|
||||
}
|
||||
}
|
||||
bool has_entries()
|
||||
{
|
||||
return rcast( AST*, ast )->has_entries();
|
||||
}
|
||||
void to_string( String& result );
|
||||
void to_string_export( String& result );
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Body* operator->()
|
||||
{
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
#pragma region Iterator
|
||||
Code begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { rcast( AST*, ast)->Front };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
Code end()
|
||||
{
|
||||
return { rcast(AST*, ast)->Back->Next };
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Body* ast;
|
||||
};
|
||||
|
||||
struct CodeClass
|
||||
{
|
||||
Using_Code( CodeClass );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Class* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Class* ast;
|
||||
};
|
||||
|
||||
struct CodeParam
|
||||
{
|
||||
Using_Code( CodeParam );
|
||||
|
||||
void append( CodeParam other );
|
||||
|
||||
CodeParam get( s32 idx );
|
||||
bool has_entries();
|
||||
void to_string( String& result );
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Param* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*)ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
CodeParam begin()
|
||||
{
|
||||
if ( ast )
|
||||
return { ast };
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
CodeParam end()
|
||||
{
|
||||
// return { (AST_Param*) rcast( AST*, ast)->Last };
|
||||
return { nullptr };
|
||||
}
|
||||
CodeParam& operator++();
|
||||
CodeParam operator*()
|
||||
{
|
||||
return * this;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Param* ast;
|
||||
};
|
||||
|
||||
struct CodeSpecifiers
|
||||
{
|
||||
Using_Code( CodeSpecifiers );
|
||||
|
||||
bool append( SpecifierT spec )
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( raw()->NumEntries == AST::ArrSpecs_Cap )
|
||||
{
|
||||
log_failure("CodeSpecifiers: Attempted to append over %d specifiers to a specifiers AST!", AST::ArrSpecs_Cap );
|
||||
return false;
|
||||
}
|
||||
|
||||
raw()->ArrSpecs[ raw()->NumEntries ] = spec;
|
||||
raw()->NumEntries++;
|
||||
return true;
|
||||
}
|
||||
s32 has( SpecifierT spec )
|
||||
{
|
||||
for ( s32 idx = 0; idx < raw()->NumEntries; idx++ )
|
||||
{
|
||||
if ( raw()->ArrSpecs[ idx ] == spec )
|
||||
return idx;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
void to_string( String& result );
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
AST_Specifiers* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr!");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return { (AST*) ast };
|
||||
}
|
||||
#pragma region Iterator
|
||||
SpecifierT* begin()
|
||||
{
|
||||
if ( ast )
|
||||
return & raw()->ArrSpecs[0];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
SpecifierT* end()
|
||||
{
|
||||
return raw()->ArrSpecs + raw()->NumEntries;
|
||||
}
|
||||
#pragma endregion Iterator
|
||||
|
||||
AST_Specifiers* ast;
|
||||
};
|
||||
|
||||
struct CodeStruct
|
||||
{
|
||||
Using_Code( CodeStruct );
|
||||
|
||||
void add_interface( CodeType interface );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw()
|
||||
{
|
||||
return rcast( AST*, ast );
|
||||
}
|
||||
operator Code()
|
||||
{
|
||||
return * rcast( Code*, this );
|
||||
}
|
||||
AST_Struct* operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
{
|
||||
log_failure("Attempt to dereference a nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
AST_Struct* ast;
|
||||
};
|
||||
|
||||
#define Define_CodeType( Typename ) \
|
||||
struct Code##Typename \
|
||||
{ \
|
||||
Using_Code( Code ## Typename ); \
|
||||
AST* raw(); \
|
||||
operator Code(); \
|
||||
AST_##Typename* operator->(); \
|
||||
AST_##Typename* ast; \
|
||||
}
|
||||
|
||||
Define_CodeType( Attributes );
|
||||
// Define_CodeType( BaseClass );
|
||||
Define_CodeType( Comment );
|
||||
|
||||
struct CodeConstructor
|
||||
{
|
||||
Using_Code( CodeConstructor );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Constructor* operator->();
|
||||
AST_Constructor* ast;
|
||||
};
|
||||
|
||||
struct CodeDefine
|
||||
{
|
||||
Using_Code( CodeDefine );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Define* operator->();
|
||||
AST_Define* ast;
|
||||
};
|
||||
|
||||
struct CodeDestructor
|
||||
{
|
||||
Using_Code( CodeDestructor );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Destructor* operator->();
|
||||
AST_Destructor* ast;
|
||||
};
|
||||
|
||||
struct CodeEnum
|
||||
{
|
||||
Using_Code( CodeEnum );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
void to_string_class_def( String& result );
|
||||
void to_string_class_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Enum* operator->();
|
||||
AST_Enum* ast;
|
||||
};
|
||||
|
||||
Define_CodeType( Exec );
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct CodeExpr
|
||||
{
|
||||
Using_Code( CodeExpr );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr* operator->();
|
||||
AST_Expr* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Assign
|
||||
{
|
||||
Using_Code( CodeExpr_Assign );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Assign* operator->();
|
||||
AST_Expr_Assign* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Alignof
|
||||
{
|
||||
Using_Code( CodeExpr_Alignof );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Alignof* operator->();
|
||||
AST_Expr_Alignof* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Binary
|
||||
{
|
||||
Using_Code( CodeExpr_Binary );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Binary* operator->();
|
||||
AST_Expr_Binary* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_CStyleCast
|
||||
{
|
||||
Using_Code( CodeExpr_CStyleCast );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_CStyleCast* operator->();
|
||||
AST_Expr_CStyleCast* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_FunctionalCast
|
||||
{
|
||||
Using_Code( CodeExpr_FunctionalCast );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_FunctionalCast* operator->();
|
||||
AST_Expr_FunctionalCast* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_CppCast
|
||||
{
|
||||
Using_Code( CodeExpr_CppCast );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_CppCast* operator->();
|
||||
AST_Expr_CppCast* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Element
|
||||
{
|
||||
Using_Code( CodeExpr_Element );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Element* operator->();
|
||||
AST_Expr_Element* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_ProcCall
|
||||
{
|
||||
Using_Code( CodeExpr_ProcCall );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_ProcCall* operator->();
|
||||
AST_Expr_ProcCall* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Decltype
|
||||
{
|
||||
Using_Code( CodeExpr_Decltype );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Decltype* operator->();
|
||||
AST_Expr_Decltype* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Comma
|
||||
{
|
||||
Using_Code( CodeExpr_Comma );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Comma* operator->();
|
||||
AST_Expr_Comma* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_AMS
|
||||
{
|
||||
Using_Code( CodeExpr_AMS );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_AMS* operator->();
|
||||
AST_Expr_AMS* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Sizeof
|
||||
{
|
||||
Using_Code( CodeExpr_Sizeof );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Sizeof* operator->();
|
||||
AST_Expr_Sizeof* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Subscript
|
||||
{
|
||||
Using_Code( CodeExpr_Subscript );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Subscript* operator->();
|
||||
AST_Expr_Subscript* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_Ternary
|
||||
{
|
||||
Using_Code( CodeExpr_Ternary );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_Ternary* operator->();
|
||||
AST_Expr_Ternary* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_UnaryPrefix
|
||||
{
|
||||
Using_Code( CodeExpr_UnaryPrefix );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_UnaryPrefix* operator->();
|
||||
AST_Expr_UnaryPrefix* ast;
|
||||
};
|
||||
|
||||
struct CodeExpr_UnaryPostfix
|
||||
{
|
||||
Using_Code( CodeExpr_UnaryPostfix );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Expr_UnaryPostfix* operator->();
|
||||
AST_Expr_UnaryPostfix* ast;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct CodeExtern
|
||||
{
|
||||
Using_Code( CodeExtern );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Extern* operator->();
|
||||
AST_Extern* ast;
|
||||
};
|
||||
|
||||
struct CodeInclude
|
||||
{
|
||||
Using_Code( CodeInclude );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Include* operator->();
|
||||
AST_Include* ast;
|
||||
};
|
||||
|
||||
struct CodeFriend
|
||||
{
|
||||
Using_Code( CodeFriend );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Friend* operator->();
|
||||
AST_Friend* ast;
|
||||
};
|
||||
|
||||
struct CodeFn
|
||||
{
|
||||
Using_Code( CodeFn );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Fn* operator->();
|
||||
AST_Fn* ast;
|
||||
};
|
||||
|
||||
struct CodeModule
|
||||
{
|
||||
Using_Code( CodeModule );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Module* operator->();
|
||||
AST_Module* ast;
|
||||
};
|
||||
|
||||
struct CodeNS
|
||||
{
|
||||
Using_Code( CodeNS );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_NS* operator->();
|
||||
AST_NS* ast;
|
||||
};
|
||||
|
||||
struct CodeOperator
|
||||
{
|
||||
Using_Code( CodeOperator );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Operator* operator->();
|
||||
AST_Operator* ast;
|
||||
};
|
||||
|
||||
struct CodeOpCast
|
||||
{
|
||||
Using_Code( CodeOpCast );
|
||||
|
||||
void to_string_def( String& result );
|
||||
void to_string_fwd( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_OpCast* operator->();
|
||||
AST_OpCast* ast;
|
||||
};
|
||||
|
||||
struct CodePragma
|
||||
{
|
||||
Using_Code( CodePragma );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Pragma* operator->();
|
||||
AST_Pragma* ast;
|
||||
};
|
||||
|
||||
struct CodePreprocessCond
|
||||
{
|
||||
Using_Code( CodePreprocessCond );
|
||||
|
||||
void to_string_if( String& result );
|
||||
void to_string_ifdef( String& result );
|
||||
void to_string_ifndef( String& result );
|
||||
void to_string_elif( String& result );
|
||||
void to_string_else( String& result );
|
||||
void to_string_endif( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_PreprocessCond* operator->();
|
||||
AST_PreprocessCond* ast;
|
||||
};
|
||||
|
||||
#if GEN_EXECUTION_EXPRESSION_SUPPORT
|
||||
struct CodeStmt
|
||||
{
|
||||
Using_Code( CodeStmt );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt* operator->();
|
||||
AST_Stmt* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Break
|
||||
{
|
||||
Using_Code( CodeStmt_Break );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Break* operator->();
|
||||
AST_Stmt_Break* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Case
|
||||
{
|
||||
Using_Code( CodeStmt_Case );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Case* operator->();
|
||||
AST_Stmt_Case* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Continue
|
||||
{
|
||||
Using_Code( CodeStmt_Continue );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Continue* operator->();
|
||||
AST_Stmt_Continue* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Decl
|
||||
{
|
||||
Using_Code( CodeStmt_Decl );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Decl* operator->();
|
||||
AST_Stmt_Decl* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Do
|
||||
{
|
||||
Using_Code( CodeStmt_Do );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Do* operator->();
|
||||
AST_Stmt_Do* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Expr
|
||||
{
|
||||
Using_Code( CodeStmt_Expr );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Expr* operator->();
|
||||
AST_Stmt_Expr* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Else
|
||||
{
|
||||
Using_Code( CodeStmt_Else );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Else* operator->();
|
||||
AST_Stmt_Else* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_If
|
||||
{
|
||||
Using_Code( CodeStmt_If );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_If* operator->();
|
||||
AST_Stmt_If* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_For
|
||||
{
|
||||
Using_Code( CodeStmt_For );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_For* operator->();
|
||||
AST_Stmt_For* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Goto
|
||||
{
|
||||
Using_Code( CodeStmt_Goto );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Goto* operator->();
|
||||
AST_Stmt_Goto* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Label
|
||||
{
|
||||
Using_Code( CodeStmt_Label );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Label* operator->();
|
||||
AST_Stmt_Label* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_Switch
|
||||
{
|
||||
Using_Code( CodeStmt_Switch );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_Switch* operator->();
|
||||
AST_Stmt_Switch* ast;
|
||||
};
|
||||
|
||||
struct CodeStmt_While
|
||||
{
|
||||
Using_Code( CodeStmt_While );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Stmt_While* operator->();
|
||||
AST_Stmt_While* ast;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct CodeTemplate
|
||||
{
|
||||
Using_Code( CodeTemplate );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Template* operator->();
|
||||
AST_Template* ast;
|
||||
};
|
||||
|
||||
struct CodeType
|
||||
{
|
||||
Using_Code( CodeType );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Type* operator->();
|
||||
AST_Type* ast;
|
||||
};
|
||||
|
||||
struct CodeTypedef
|
||||
{
|
||||
Using_Code( CodeTypedef );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Typedef* operator->();
|
||||
AST_Typedef* ast;
|
||||
};
|
||||
|
||||
struct CodeUnion
|
||||
{
|
||||
Using_Code( CodeUnion );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Union* operator->();
|
||||
AST_Union* ast;
|
||||
};
|
||||
|
||||
struct CodeUsing
|
||||
{
|
||||
Using_Code( CodeUsing );
|
||||
|
||||
void to_string( String& result );
|
||||
void to_string_ns( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Using* operator->();
|
||||
AST_Using* ast;
|
||||
};
|
||||
|
||||
struct CodeVar
|
||||
{
|
||||
Using_Code( CodeVar );
|
||||
|
||||
void to_string( String& result );
|
||||
|
||||
AST* raw();
|
||||
operator Code();
|
||||
AST_Var* operator->();
|
||||
AST_Var* ast;
|
||||
};
|
||||
|
||||
#undef Define_CodeType
|
||||
#undef Using_Code
|
||||
|
||||
#pragma endregion Code Types
|
File diff suppressed because it is too large
Load Diff
@ -1,86 +0,0 @@
|
||||
// This is the non-bootstraped version of the ECode. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
namespace ECode
|
||||
{
|
||||
# define Define_Types \
|
||||
Entry( Invalid ) \
|
||||
Entry( Untyped ) \
|
||||
Entry( Comment ) \
|
||||
Entry( Access_Private ) \
|
||||
Entry( Access_Protected ) \
|
||||
Entry( Access_Public ) \
|
||||
Entry( PlatformAttributes ) \
|
||||
Entry( Class ) \
|
||||
Entry( Class_Fwd ) \
|
||||
Entry( Class_Body ) \
|
||||
Entry( Enum ) \
|
||||
Entry( Enum_Fwd ) \
|
||||
Entry( Enum_Body ) \
|
||||
Entry( Enum_Class ) \
|
||||
Entry( Enum_Class_Fwd ) \
|
||||
Entry( Execution ) \
|
||||
Entry( Export_Body ) \
|
||||
Entry( Extern_Linkage ) \
|
||||
Entry( Extern_Linkage_Body ) \
|
||||
Entry( Friend ) \
|
||||
Entry( Function ) \
|
||||
Entry( Function_Fwd ) \
|
||||
Entry( Function_Body ) \
|
||||
Entry( Global_Body ) \
|
||||
Entry( Module ) \
|
||||
Entry( Namespace ) \
|
||||
Entry( Namespace_Body ) \
|
||||
Entry( Operator ) \
|
||||
Entry( Operator_Fwd ) \
|
||||
Entry( Operator_Member ) \
|
||||
Entry( Operator_Member_Fwd ) \
|
||||
Entry( Operator_Cast ) \
|
||||
Entry( Operator_Cast_Fwd ) \
|
||||
Entry( Parameters ) \
|
||||
Entry( 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,75 +0,0 @@
|
||||
// This is the non-bootstraped version of the EOperator. This will be obsolete once bootstrap is stress tested.
|
||||
|
||||
namespace EOperator
|
||||
{
|
||||
# define Define_Operators \
|
||||
Entry( Invalid, INVALID ) \
|
||||
Entry( Assign, = ) \
|
||||
Entry( Assign_Add, += ) \
|
||||
Entry( Assign_Subtract, -= ) \
|
||||
Entry( Assign_Multiply, *= ) \
|
||||
Entry( Assign_Divide, /= ) \
|
||||
Entry( Assign_Modulo, %= ) \
|
||||
Entry( Assign_BAnd, &= ) \
|
||||
Entry( Assign_BOr, |= ) \
|
||||
Entry( Assign_BXOr, ^= ) \
|
||||
Entry( Assign_LShift, <<= ) \
|
||||
Entry( Assign_RShift, >>= ) \
|
||||
Entry( Increment, ++ ) \
|
||||
Entry( Decrement, -- ) \
|
||||
Entry( Unary_Plus, + ) \
|
||||
Entry( Unary_Minus, - ) \
|
||||
Entry( UnaryNot, ! ) \
|
||||
Entry( Add, + ) \
|
||||
Entry( Subtract, - ) \
|
||||
Entry( Multiply, * ) \
|
||||
Entry( Divide, / ) \
|
||||
Entry( Modulo, % ) \
|
||||
Entry( BNot, ~ ) \
|
||||
Entry( BAnd, & ) \
|
||||
Entry( BOr, | ) \
|
||||
Entry( BXOr, ^ ) \
|
||||
Entry( LShift, << ) \
|
||||
Entry( RShift, >> ) \
|
||||
Entry( LAnd, && ) \
|
||||
Entry( LOr, || ) \
|
||||
Entry( LEqual, == ) \
|
||||
Entry( LNot, != ) \
|
||||
Entry( Lesser, < ) \
|
||||
Entry( Greater, > ) \
|
||||
Entry( LesserEqual, <= ) \
|
||||
Entry( GreaterEqual, >= ) \
|
||||
Entry( Subscript, [] ) \
|
||||
Entry( Indirection, * ) \
|
||||
Entry( AddressOf, & ) \
|
||||
Entry( MemberOfPointer, -> ) \
|
||||
Entry( PtrToMemOfPtr, ->* ) \
|
||||
Entry( FunctionCall, () )
|
||||
|
||||
enum Type : u32
|
||||
{
|
||||
# define Entry( Type_, Token_ ) Type_,
|
||||
Define_Operators
|
||||
# undef Entry
|
||||
Comma,
|
||||
|
||||
Num_Ops,
|
||||
};
|
||||
|
||||
inline
|
||||
char const* to_str( Type op )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[ Num_Ops ] = {
|
||||
# define Entry( Type_, Token_ ) stringize(Token_),
|
||||
Define_Operators
|
||||
# undef Entry
|
||||
","
|
||||
};
|
||||
|
||||
return lookup[ op ];
|
||||
}
|
||||
|
||||
# undef Define_Operators
|
||||
}
|
||||
using OperatorT = EOperator::Type;
|
@ -1,108 +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 )
|
||||
|
||||
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,164 +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( 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( Number, "__number__" ) \
|
||||
Entry( Operator, "__operator__" ) \
|
||||
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_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
|
||||
char const* to_str( Type type )
|
||||
{
|
||||
local_persist
|
||||
char const* lookup[(u32)NumTokens] =
|
||||
{
|
||||
# define Entry( Name_, Str_ ) Str_,
|
||||
Define_TokType
|
||||
GEN_DEFINE_ATTRIBUTE_TOKENS
|
||||
# undef Entry
|
||||
};
|
||||
|
||||
return lookup[(u32)type];
|
||||
}
|
||||
# undef Define_TokType
|
||||
};
|
||||
|
||||
using TokType = ETokType::Type;
|
||||
|
||||
} // Parser
|
2697
project/components/gen/ast_inlines.hpp
Normal file
2697
project/components/gen/ast_inlines.hpp
Normal file
File diff suppressed because it is too large
Load Diff
144
project/components/gen/ecode.hpp
Normal file
144
project/components/gen/ecode.hpp
Normal file
@ -0,0 +1,144 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace ECode
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Untyped,
|
||||
NewLine,
|
||||
Comment,
|
||||
Access_Private,
|
||||
Access_Protected,
|
||||
Access_Public,
|
||||
PlatformAttributes,
|
||||
Class,
|
||||
Class_Fwd,
|
||||
Class_Body,
|
||||
Constructor,
|
||||
Constructor_Fwd,
|
||||
Destructor,
|
||||
Destructor_Fwd,
|
||||
Enum,
|
||||
Enum_Fwd,
|
||||
Enum_Body,
|
||||
Enum_Class,
|
||||
Enum_Class_Fwd,
|
||||
Execution,
|
||||
Export_Body,
|
||||
Extern_Linkage,
|
||||
Extern_Linkage_Body,
|
||||
Friend,
|
||||
Function,
|
||||
Function_Fwd,
|
||||
Function_Body,
|
||||
Global_Body,
|
||||
Module,
|
||||
Namespace,
|
||||
Namespace_Body,
|
||||
Operator,
|
||||
Operator_Fwd,
|
||||
Operator_Member,
|
||||
Operator_Member_Fwd,
|
||||
Operator_Cast,
|
||||
Operator_Cast_Fwd,
|
||||
Parameters,
|
||||
Preprocess_Define,
|
||||
Preprocess_Include,
|
||||
Preprocess_If,
|
||||
Preprocess_IfDef,
|
||||
Preprocess_IfNotDef,
|
||||
Preprocess_ElIf,
|
||||
Preprocess_Else,
|
||||
Preprocess_EndIf,
|
||||
Preprocess_Pragma,
|
||||
Specifiers,
|
||||
Struct,
|
||||
Struct_Fwd,
|
||||
Struct_Body,
|
||||
Template,
|
||||
Typedef,
|
||||
Typename,
|
||||
Union,
|
||||
Union_Body,
|
||||
Using,
|
||||
Using_Namespace,
|
||||
Variable,
|
||||
NumTypes
|
||||
};
|
||||
|
||||
StrC to_str( Type type )
|
||||
{
|
||||
local_persist StrC lookup[] {
|
||||
{ sizeof( "Invalid" ), "Invalid" },
|
||||
{ sizeof( "Untyped" ), "Untyped" },
|
||||
{ sizeof( "NewLine" ), "NewLine" },
|
||||
{ sizeof( "Comment" ), "Comment" },
|
||||
{ sizeof( "Access_Private" ), "Access_Private" },
|
||||
{ sizeof( "Access_Protected" ), "Access_Protected" },
|
||||
{ sizeof( "Access_Public" ), "Access_Public" },
|
||||
{ sizeof( "PlatformAttributes" ), "PlatformAttributes" },
|
||||
{ sizeof( "Class" ), "Class" },
|
||||
{ sizeof( "Class_Fwd" ), "Class_Fwd" },
|
||||
{ sizeof( "Class_Body" ), "Class_Body" },
|
||||
{ sizeof( "Constructor" ), "Constructor" },
|
||||
{ sizeof( "Constructor_Fwd" ), "Constructor_Fwd" },
|
||||
{ sizeof( "Destructor" ), "Destructor" },
|
||||
{ sizeof( "Destructor_Fwd" ), "Destructor_Fwd" },
|
||||
{ sizeof( "Enum" ), "Enum" },
|
||||
{ sizeof( "Enum_Fwd" ), "Enum_Fwd" },
|
||||
{ sizeof( "Enum_Body" ), "Enum_Body" },
|
||||
{ sizeof( "Enum_Class" ), "Enum_Class" },
|
||||
{ sizeof( "Enum_Class_Fwd" ), "Enum_Class_Fwd" },
|
||||
{ sizeof( "Execution" ), "Execution" },
|
||||
{ sizeof( "Export_Body" ), "Export_Body" },
|
||||
{ sizeof( "Extern_Linkage" ), "Extern_Linkage" },
|
||||
{ sizeof( "Extern_Linkage_Body" ), "Extern_Linkage_Body" },
|
||||
{ sizeof( "Friend" ), "Friend" },
|
||||
{ sizeof( "Function" ), "Function" },
|
||||
{ sizeof( "Function_Fwd" ), "Function_Fwd" },
|
||||
{ sizeof( "Function_Body" ), "Function_Body" },
|
||||
{ sizeof( "Global_Body" ), "Global_Body" },
|
||||
{ sizeof( "Module" ), "Module" },
|
||||
{ sizeof( "Namespace" ), "Namespace" },
|
||||
{ sizeof( "Namespace_Body" ), "Namespace_Body" },
|
||||
{ sizeof( "Operator" ), "Operator" },
|
||||
{ sizeof( "Operator_Fwd" ), "Operator_Fwd" },
|
||||
{ sizeof( "Operator_Member" ), "Operator_Member" },
|
||||
{ sizeof( "Operator_Member_Fwd" ), "Operator_Member_Fwd" },
|
||||
{ sizeof( "Operator_Cast" ), "Operator_Cast" },
|
||||
{ sizeof( "Operator_Cast_Fwd" ), "Operator_Cast_Fwd" },
|
||||
{ sizeof( "Parameters" ), "Parameters" },
|
||||
{ sizeof( "Preprocess_Define" ), "Preprocess_Define" },
|
||||
{ sizeof( "Preprocess_Include" ), "Preprocess_Include" },
|
||||
{ sizeof( "Preprocess_If" ), "Preprocess_If" },
|
||||
{ sizeof( "Preprocess_IfDef" ), "Preprocess_IfDef" },
|
||||
{ sizeof( "Preprocess_IfNotDef" ), "Preprocess_IfNotDef" },
|
||||
{ sizeof( "Preprocess_ElIf" ), "Preprocess_ElIf" },
|
||||
{ sizeof( "Preprocess_Else" ), "Preprocess_Else" },
|
||||
{ sizeof( "Preprocess_EndIf" ), "Preprocess_EndIf" },
|
||||
{ sizeof( "Preprocess_Pragma" ), "Preprocess_Pragma" },
|
||||
{ sizeof( "Specifiers" ), "Specifiers" },
|
||||
{ sizeof( "Struct" ), "Struct" },
|
||||
{ sizeof( "Struct_Fwd" ), "Struct_Fwd" },
|
||||
{ sizeof( "Struct_Body" ), "Struct_Body" },
|
||||
{ sizeof( "Template" ), "Template" },
|
||||
{ sizeof( "Typedef" ), "Typedef" },
|
||||
{ sizeof( "Typename" ), "Typename" },
|
||||
{ sizeof( "Union" ), "Union" },
|
||||
{ sizeof( "Union_Body" ), "Union_Body" },
|
||||
{ sizeof( "Using" ), "Using" },
|
||||
{ sizeof( "Using_Namespace" ), "Using_Namespace" },
|
||||
{ sizeof( "Variable" ), "Variable" },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
} // namespace ECode
|
||||
|
||||
using CodeT = ECode::Type;
|
118
project/components/gen/eoperator.hpp
Normal file
118
project/components/gen/eoperator.hpp
Normal file
@ -0,0 +1,118 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace EOperator
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Assign,
|
||||
Assign_Add,
|
||||
Assign_Subtract,
|
||||
Assign_Multiply,
|
||||
Assign_Divide,
|
||||
Assign_Modulo,
|
||||
Assign_BAnd,
|
||||
Assign_BOr,
|
||||
Assign_BXOr,
|
||||
Assign_LShift,
|
||||
Assign_RShift,
|
||||
Increment,
|
||||
Decrement,
|
||||
Unary_Plus,
|
||||
Unary_Minus,
|
||||
UnaryNot,
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide,
|
||||
Modulo,
|
||||
BNot,
|
||||
BAnd,
|
||||
BOr,
|
||||
BXOr,
|
||||
LShift,
|
||||
RShift,
|
||||
LAnd,
|
||||
LOr,
|
||||
LEqual,
|
||||
LNot,
|
||||
Lesser,
|
||||
Greater,
|
||||
LesserEqual,
|
||||
GreaterEqual,
|
||||
Subscript,
|
||||
Indirection,
|
||||
AddressOf,
|
||||
MemberOfPointer,
|
||||
PtrToMemOfPtr,
|
||||
FunctionCall,
|
||||
Comma,
|
||||
New,
|
||||
NewArray,
|
||||
Delete,
|
||||
DeleteArray,
|
||||
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( "," ), "," },
|
||||
{ sizeof( "new" ), "new" },
|
||||
{ sizeof( "new[]" ), "new[]" },
|
||||
{ sizeof( "delete" ), "delete" },
|
||||
{ sizeof( "delete[]" ), "delete[]" },
|
||||
};
|
||||
return lookup[op];
|
||||
}
|
||||
|
||||
} // namespace EOperator
|
||||
|
||||
using OperatorT = EOperator::Type;
|
98
project/components/gen/especifier.hpp
Normal file
98
project/components/gen/especifier.hpp
Normal file
@ -0,0 +1,98 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace ESpecifier
|
||||
{
|
||||
enum Type : u32
|
||||
{
|
||||
Invalid,
|
||||
Consteval,
|
||||
Constexpr,
|
||||
Constinit,
|
||||
Explicit,
|
||||
External_Linkage,
|
||||
ForceInline,
|
||||
Global,
|
||||
Inline,
|
||||
Internal_Linkage,
|
||||
Local_Persist,
|
||||
Mutable,
|
||||
NeverInline,
|
||||
Ptr,
|
||||
Ref,
|
||||
Register,
|
||||
RValue,
|
||||
Static,
|
||||
Thread_Local,
|
||||
Virtual,
|
||||
Const,
|
||||
Final,
|
||||
NoExceptions,
|
||||
Override,
|
||||
Pure,
|
||||
Volatile,
|
||||
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( "virtual" ), "virtual" },
|
||||
{ sizeof( "const" ), "const" },
|
||||
{ sizeof( "final" ), "final" },
|
||||
{ sizeof( "noexcept" ), "noexcept" },
|
||||
{ sizeof( "override" ), "override" },
|
||||
{ sizeof( "= 0" ), "= 0" },
|
||||
{ sizeof( "volatile" ), "volatile" },
|
||||
};
|
||||
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;
|
241
project/components/gen/etoktype.cpp
Normal file
241
project/components/gen/etoktype.cpp
Normal file
@ -0,0 +1,241 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace parser
|
||||
{
|
||||
namespace ETokType
|
||||
{
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Attribute_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_Typename,
|
||||
Type_Unsigned,
|
||||
Type_Signed,
|
||||
Type_Short,
|
||||
Type_Long,
|
||||
Type_bool,
|
||||
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,
|
||||
Attribute_API_Export,
|
||||
Attribute_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( "typename" ), "typename" },
|
||||
{ sizeof( "unsigned" ), "unsigned" },
|
||||
{ sizeof( "signed" ), "signed" },
|
||||
{ sizeof( "short" ), "short" },
|
||||
{ sizeof( "long" ), "long" },
|
||||
{ sizeof( "bool" ), "bool" },
|
||||
{ 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,403 +1,16 @@
|
||||
#pragma region Inlines
|
||||
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
other = other->duplicate();
|
||||
|
||||
other->Parent = this;
|
||||
|
||||
if ( Front == nullptr )
|
||||
{
|
||||
Front = other;
|
||||
Back = other;
|
||||
|
||||
NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
AST*
|
||||
Current = Back;
|
||||
Current->Next = other;
|
||||
other->Prev = Current;
|
||||
Back = other;
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
char const* AST::debug_str()
|
||||
{
|
||||
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;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
if ( idx == 0 )
|
||||
return * rcast( Code*, current);
|
||||
|
||||
current = & ( * current )->Next;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return * rcast( Code*, current);
|
||||
}
|
||||
|
||||
bool AST::has_entries()
|
||||
{
|
||||
return NumEntries;
|
||||
}
|
||||
|
||||
char const* AST::type_str()
|
||||
{
|
||||
return ECode::to_str( Type );
|
||||
}
|
||||
|
||||
AST::operator Code()
|
||||
{
|
||||
return { this };
|
||||
}
|
||||
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
ast = ast->Next;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma region AST & Code Gen Common
|
||||
|
||||
#define Define_CodeImpl( Typename ) \
|
||||
char const* Typename::debug_str() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
return "Code::debug_str: AST is null!"; \
|
||||
\
|
||||
return rcast(AST*, ast)->debug_str(); \
|
||||
} \
|
||||
Code Typename::duplicate() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); \
|
||||
return Code::Invalid; \
|
||||
} \
|
||||
\
|
||||
return { rcast(AST*, ast)->duplicate() }; \
|
||||
} \
|
||||
bool Typename::is_equal( Code other ) \
|
||||
{ \
|
||||
if ( ast == nullptr || other.ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::is_equal: Cannot compare code, AST is null!"); \
|
||||
return false; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->is_equal( other.ast ); \
|
||||
} \
|
||||
bool Typename::is_valid() \
|
||||
{ \
|
||||
return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid; \
|
||||
} \
|
||||
void Typename::set_global() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::set_global: Cannot set code as global, AST is null!"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
rcast(AST*, ast)->Parent = Code::Global.ast; \
|
||||
} \
|
||||
String Typename::to_string() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Code::to_string: Cannot convert code to string, AST is null!"); \
|
||||
return { nullptr }; \
|
||||
} \
|
||||
\
|
||||
return rcast(AST*, ast)->to_string(); \
|
||||
} \
|
||||
Typename& Typename::operator =( Code other ) \
|
||||
{ \
|
||||
if ( other.ast && other->Parent ) \
|
||||
{ \
|
||||
ast = rcast( decltype(ast), other.ast->duplicate() ); \
|
||||
rcast( AST*, ast)->Parent = nullptr; \
|
||||
} \
|
||||
\
|
||||
ast = rcast( decltype(ast), other.ast ); \
|
||||
return *this; \
|
||||
} \
|
||||
bool Typename::operator ==( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast == other.ast; \
|
||||
} \
|
||||
bool Typename::operator !=( Code other ) \
|
||||
{ \
|
||||
return (AST*) ast != other.ast; \
|
||||
}
|
||||
|
||||
Define_CodeImpl( Code );
|
||||
Define_CodeImpl( CodeBody );
|
||||
Define_CodeImpl( CodeAttributes );
|
||||
Define_CodeImpl( CodeComment );
|
||||
Define_CodeImpl( CodeClass );
|
||||
Define_CodeImpl( CodeDefine );
|
||||
Define_CodeImpl( CodeEnum );
|
||||
Define_CodeImpl( CodeExec );
|
||||
Define_CodeImpl( CodeExtern );
|
||||
Define_CodeImpl( CodeInclude );
|
||||
Define_CodeImpl( CodeFriend );
|
||||
Define_CodeImpl( CodeFn );
|
||||
Define_CodeImpl( CodeModule );
|
||||
Define_CodeImpl( CodeNamespace );
|
||||
Define_CodeImpl( CodeOperator );
|
||||
Define_CodeImpl( CodeOpCast );
|
||||
Define_CodeImpl( CodeParam );
|
||||
Define_CodeImpl( 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 );
|
||||
#undef Define_CodeImpl
|
||||
|
||||
#define Define_AST_Cast( typename ) \
|
||||
AST::operator Code ## typename() \
|
||||
{ \
|
||||
return { rcast( AST_ ## typename*, this ) }; \
|
||||
}
|
||||
|
||||
Define_AST_Cast( Body );
|
||||
Define_AST_Cast( Attributes );
|
||||
Define_AST_Cast( Comment );
|
||||
Define_AST_Cast( Class );
|
||||
Define_AST_Cast( Define );
|
||||
Define_AST_Cast( Enum );
|
||||
Define_AST_Cast( Exec );
|
||||
Define_AST_Cast( Extern );
|
||||
Define_AST_Cast( Include );
|
||||
Define_AST_Cast( Friend );
|
||||
Define_AST_Cast( Fn );
|
||||
Define_AST_Cast( Module );
|
||||
Define_AST_Cast( Namespace );
|
||||
Define_AST_Cast( Operator );
|
||||
Define_AST_Cast( OpCast );
|
||||
Define_AST_Cast( Param );
|
||||
Define_AST_Cast( 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( Class );
|
||||
Define_CodeCast( Define );
|
||||
Define_CodeCast( Exec );
|
||||
Define_CodeCast( Enum );
|
||||
Define_CodeCast( Extern );
|
||||
Define_CodeCast( Include );
|
||||
Define_CodeCast( Friend );
|
||||
Define_CodeCast( Fn );
|
||||
Define_CodeCast( Module );
|
||||
Define_CodeCast( Namespace );
|
||||
Define_CodeCast( Operator );
|
||||
Define_CodeCast( OpCast );
|
||||
Define_CodeCast( Param );
|
||||
Define_CodeCast( 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 & Code Gen Common
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
return;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = entry->duplicate();
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
if ( self->Last == nullptr )
|
||||
{
|
||||
self->Last = entry;
|
||||
self->Next = entry;
|
||||
self->NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
self->Last->Next = entry;
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
return { (AST_Param*) param.raw()->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
bool CodeParam::has_entries()
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
}
|
||||
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Export_Body:
|
||||
case Extern_Linkage:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
||||
return (CodeBody)Code::Invalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = type;
|
||||
return (CodeBody)result;
|
||||
}
|
||||
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
// Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string.
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
||||
|
||||
va_list va;
|
||||
va_start(va, num );
|
||||
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
}
|
||||
|
||||
#pragma endregion Inlines
|
||||
#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(8)
|
||||
#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)
|
||||
@ -415,10 +28,10 @@ StrC token_fmt_impl( sw num, ... )
|
||||
# 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)
|
||||
# define GEN_BUILDER_STR_BUFFER_RESERVE megabytes(2)
|
||||
#endif
|
||||
|
||||
// These constexprs are used for allocation behavior of data structures
|
||||
@ -450,6 +63,9 @@ extern CodeAttributes attrib_api_import;
|
||||
extern Code module_global_fragment;
|
||||
extern Code module_private_fragment;
|
||||
|
||||
// Exposed, but this is really used for parsing.
|
||||
extern Code fmt_newline;
|
||||
|
||||
extern CodePragma pragma_once;
|
||||
|
||||
extern CodeParam param_varadic;
|
||||
@ -463,14 +79,17 @@ extern CodeSpecifiers spec_constexpr;
|
||||
extern CodeSpecifiers spec_constinit;
|
||||
extern CodeSpecifiers spec_extern_linkage;
|
||||
extern CodeSpecifiers spec_final;
|
||||
extern CodeSpecifiers spec_forceinline;
|
||||
extern CodeSpecifiers spec_global;
|
||||
extern CodeSpecifiers spec_inline;
|
||||
extern CodeSpecifiers spec_internal_linkage;
|
||||
extern CodeSpecifiers spec_local_persist;
|
||||
extern CodeSpecifiers spec_mutable;
|
||||
extern CodeSpecifiers spec_neverinline;
|
||||
extern CodeSpecifiers spec_noexcept;
|
||||
extern CodeSpecifiers spec_override;
|
||||
extern CodeSpecifiers spec_ptr;
|
||||
extern CodeSpecifiers spec_pure;
|
||||
extern CodeSpecifiers spec_ref;
|
||||
extern CodeSpecifiers spec_register;
|
||||
extern CodeSpecifiers spec_rvalue;
|
||||
@ -528,19 +147,25 @@ 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
|
||||
|
||||
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
|
||||
// Populate with strings via gen::get_cached_string.
|
||||
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
|
||||
extern Array< StringCached > PreprocessorDefines;
|
||||
|
||||
#ifdef GEN_EXPOSE_BACKEND
|
||||
|
||||
// Global allocator used for data with process lifetime.
|
||||
extern AllocatorInfo GlobalAllocator;
|
||||
extern Array< Arena > Global_AllocatorBuckets;
|
||||
|
||||
extern Array< Pool > CodePools;
|
||||
extern Array< Arena > StringArenas;
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
gencpp: An attempt at "simple" staged metaprogramming for c/c++.
|
||||
|
||||
@ -15,3 +17,15 @@
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.hpp"
|
||||
#endif
|
||||
|
||||
#ifndef GEN_NS_BEGIN
|
||||
# ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
# else
|
||||
# define GEN_NS gen::
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
# endif
|
||||
#endif
|
||||
|
194
project/components/inlines.hpp
Normal file
194
project/components/inlines.hpp
Normal file
@ -0,0 +1,194 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.hpp"
|
||||
#endif
|
||||
|
||||
void AST::append( AST* other )
|
||||
{
|
||||
if ( other->Parent )
|
||||
other = other->duplicate();
|
||||
|
||||
other->Parent = this;
|
||||
|
||||
if ( Front == nullptr )
|
||||
{
|
||||
Front = other;
|
||||
Back = other;
|
||||
|
||||
NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
AST*
|
||||
Current = Back;
|
||||
Current->Next = other;
|
||||
other->Prev = Current;
|
||||
Back = other;
|
||||
NumEntries++;
|
||||
}
|
||||
|
||||
Code& AST::entry( u32 idx )
|
||||
{
|
||||
AST** current = & Front;
|
||||
while ( idx >= 0 && current != nullptr )
|
||||
{
|
||||
if ( idx == 0 )
|
||||
return * rcast( Code*, current);
|
||||
|
||||
current = & ( * current )->Next;
|
||||
idx--;
|
||||
}
|
||||
|
||||
return * rcast( Code*, current);
|
||||
}
|
||||
|
||||
bool AST::has_entries()
|
||||
{
|
||||
return NumEntries;
|
||||
}
|
||||
|
||||
char const* AST::type_str()
|
||||
{
|
||||
return ECode::to_str( Type );
|
||||
}
|
||||
|
||||
AST::operator Code()
|
||||
{
|
||||
return { this };
|
||||
}
|
||||
|
||||
Code& Code::operator ++()
|
||||
{
|
||||
if ( ast )
|
||||
ast = ast->Next;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
ast->ParentAccess = AccessSpec::Public;
|
||||
// If your planning on adding a proper parent,
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
{
|
||||
AST* self = (AST*) ast;
|
||||
AST* entry = (AST*) other.ast;
|
||||
|
||||
if ( entry->Parent )
|
||||
entry = entry->duplicate();
|
||||
|
||||
entry->Parent = self;
|
||||
|
||||
if ( self->Last == nullptr )
|
||||
{
|
||||
self->Last = entry;
|
||||
self->Next = entry;
|
||||
self->NumEntries++;
|
||||
return;
|
||||
}
|
||||
|
||||
self->Last->Next = entry;
|
||||
self->Last = entry;
|
||||
self->NumEntries++;
|
||||
}
|
||||
|
||||
CodeParam CodeParam::get( s32 idx )
|
||||
{
|
||||
CodeParam param = *this;
|
||||
do
|
||||
{
|
||||
if ( ! ++ param )
|
||||
return { nullptr };
|
||||
|
||||
return { (AST_Param*) param.raw()->Next };
|
||||
}
|
||||
while ( --idx );
|
||||
|
||||
return { nullptr };
|
||||
}
|
||||
|
||||
bool CodeParam::has_entries()
|
||||
{
|
||||
return ast->NumEntries > 0;
|
||||
}
|
||||
|
||||
CodeParam& CodeParam::operator ++()
|
||||
{
|
||||
ast = ast->Next.ast;
|
||||
return * this;
|
||||
}
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
ast->ParentAccess = AccessSpec::Public;
|
||||
// If your planning on adding a proper parent,
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
using namespace ECode;
|
||||
case Class_Body:
|
||||
case Enum_Body:
|
||||
case Export_Body:
|
||||
case Extern_Linkage:
|
||||
case Function_Body:
|
||||
case Global_Body:
|
||||
case Namespace_Body:
|
||||
case Struct_Body:
|
||||
case Union_Body:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure( "def_body: Invalid type %s", (char const*)ECode::to_str(type) );
|
||||
return (CodeBody)Code::Invalid;
|
||||
}
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = type;
|
||||
return (CodeBody)result;
|
||||
}
|
||||
|
||||
StrC token_fmt_impl( sw num, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
mem_set( buf, 0, GEN_PRINTF_MAXLEN );
|
||||
|
||||
va_list va;
|
||||
va_start(va, num );
|
||||
sw result = token_fmt_va(buf, GEN_PRINTF_MAXLEN, num, va);
|
||||
va_end(va);
|
||||
|
||||
return { result, buf };
|
||||
}
|
@ -1,5 +1,12 @@
|
||||
internal void init_parser();
|
||||
internal void deinit_parser();
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "code_serialization.cpp"
|
||||
#endif
|
||||
|
||||
namespace parser {
|
||||
internal void init();
|
||||
internal void deinit();
|
||||
}
|
||||
|
||||
internal
|
||||
void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
|
||||
@ -15,10 +22,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 +49,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 +75,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 +83,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:\n") );
|
||||
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:\n") );
|
||||
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:\n") );
|
||||
access_public.set_global();
|
||||
|
||||
attrib_api_export = def_attributes( code(GEN_API_Export_Code));
|
||||
@ -102,25 +109,29 @@ 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();
|
||||
|
||||
fmt_newline = make_code();
|
||||
fmt_newline->Type = ECode::NewLine;
|
||||
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();
|
||||
|
||||
@ -166,33 +177,38 @@ void define_constants()
|
||||
#endif
|
||||
# undef def_constant_code_type
|
||||
|
||||
# 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 def_constant_spec( Type_, ... ) \
|
||||
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
|
||||
spec_##Type_.set_global();
|
||||
|
||||
# pragma push_macro("forceinline")
|
||||
# pragma push_macro("global")
|
||||
# pragma push_macro("internal")
|
||||
# pragma push_macro("local_persist")
|
||||
# pragma push_macro("neverinline")
|
||||
# undef forceinline
|
||||
# undef global
|
||||
# undef internal
|
||||
# undef local_persist
|
||||
# undef neverinline
|
||||
def_constant_spec( const, ESpecifier::Const );
|
||||
def_constant_spec( consteval, ESpecifier::Consteval );
|
||||
def_constant_spec( constexpr, ESpecifier::Constexpr );
|
||||
def_constant_spec( constinit, ESpecifier::Constinit );
|
||||
def_constant_spec( extern_linkage, ESpecifier::External_Linkage );
|
||||
def_constant_spec( final, ESpecifier::Final );
|
||||
def_constant_spec( forceinline, ESpecifier::ForceInline );
|
||||
def_constant_spec( global, ESpecifier::Global );
|
||||
def_constant_spec( inline, ESpecifier::Inline );
|
||||
def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage );
|
||||
def_constant_spec( local_persist, ESpecifier::Local_Persist );
|
||||
def_constant_spec( mutable, ESpecifier::Mutable );
|
||||
def_constant_spec( neverinline, ESpecifier::NeverInline );
|
||||
def_constant_spec( noexcept, ESpecifier::NoExceptions );
|
||||
def_constant_spec( override, ESpecifier::Override );
|
||||
def_constant_spec( ptr, ESpecifier::Ptr );
|
||||
def_constant_spec( pure, ESpecifier::Pure )
|
||||
def_constant_spec( ref, ESpecifier::Ref );
|
||||
def_constant_spec( register, ESpecifier::Register );
|
||||
def_constant_spec( rvalue, ESpecifier::RValue );
|
||||
@ -204,10 +220,11 @@ void define_constants()
|
||||
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
|
||||
spec_local_persist.set_global();
|
||||
|
||||
# pragma pop_macro( "global" )
|
||||
# pragma pop_macro( "internal" )
|
||||
# pragma pop_macro( "local_persist" )
|
||||
# pragma pop_macro( "neverinline" )
|
||||
# pragma pop_macro("forceinline")
|
||||
# pragma pop_macro("global")
|
||||
# pragma pop_macro("internal")
|
||||
# pragma pop_macro("local_persist")
|
||||
# pragma pop_macro("neverinline")
|
||||
|
||||
# undef def_constant_spec
|
||||
}
|
||||
@ -221,12 +238,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 );
|
||||
|
||||
@ -237,12 +254,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.
|
||||
@ -250,7 +267,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 );
|
||||
|
||||
@ -259,7 +276,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 );
|
||||
}
|
||||
@ -269,11 +286,14 @@ 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");
|
||||
}
|
||||
|
||||
// Preprocessor Defines
|
||||
PreprocessorDefines = Array<StringCached>::init_reserve( GlobalAllocator, kilobytes(1) );
|
||||
|
||||
define_constants();
|
||||
init_parser();
|
||||
parser::init();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
@ -305,6 +325,8 @@ void deinit()
|
||||
|
||||
LexArena.free();
|
||||
|
||||
PreprocessorDefines.free();
|
||||
|
||||
index = 0;
|
||||
left = Global_AllocatorBuckets.num();
|
||||
do
|
||||
@ -316,7 +338,7 @@ void deinit()
|
||||
while ( left--, left );
|
||||
|
||||
Global_AllocatorBuckets.free();
|
||||
deinit_parser();
|
||||
parser::deinit();
|
||||
}
|
||||
|
||||
void reset()
|
||||
@ -357,7 +379,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();
|
||||
}
|
||||
@ -383,9 +405,7 @@ StringCached get_cached_string( StrC str )
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Used internally to retireve a Code object form the CodePool.
|
||||
*/
|
||||
// Used internally to retireve a Code object form the CodePool.
|
||||
Code make_code()
|
||||
{
|
||||
Pool* allocator = & CodePools.back();
|
||||
@ -394,24 +414,27 @@ Code make_code()
|
||||
Pool code_pool = Pool::init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
|
||||
|
||||
if ( code_pool.PhysicalStart == nullptr )
|
||||
fatal( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
|
||||
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
|
||||
|
||||
if ( ! CodePools.append( code_pool ) )
|
||||
fatal( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
|
||||
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
|
||||
|
||||
allocator = & CodePools.back();
|
||||
}
|
||||
|
||||
Code result { rcast( AST*, alloc( * allocator, sizeof(AST) )) };
|
||||
mem_set( result.ast, 0, sizeof(AST) );
|
||||
// result->Type = ECode::Invalid;
|
||||
|
||||
result->Content = { nullptr };
|
||||
result->Prev = { nullptr };
|
||||
result->Next = { nullptr };
|
||||
result->Parent = { nullptr };
|
||||
result->Name = { nullptr };
|
||||
result->Type = ECode::Invalid;
|
||||
result->ModuleFlags = ModuleFlag::Invalid;
|
||||
result->NumEntries = 0;
|
||||
// result->Content = { nullptr };
|
||||
// result->Prev = { nullptr };
|
||||
// result->Next = { nullptr };
|
||||
// result->Token = nullptr;
|
||||
// result->Parent = { nullptr };
|
||||
// result->Name = { nullptr };
|
||||
// result->Type = ECode::Invalid;
|
||||
// result->ModuleFlags = ModuleFlag::Invalid;
|
||||
// result->NumEntries = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast_types.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Gen Interface
|
||||
|
||||
// Initialize the library.
|
||||
@ -24,7 +29,6 @@ StringCached get_cached_string( StrC str );
|
||||
Code make_code();
|
||||
|
||||
// Set these before calling gen's init() procedure.
|
||||
// Data
|
||||
|
||||
void set_allocator_data_arrays ( AllocatorInfo data_array_allocator );
|
||||
void set_allocator_code_pool ( AllocatorInfo pool_allocator );
|
||||
@ -45,8 +49,12 @@ CodeClass def_class( StrC name
|
||||
, ModuleFlag mflags = ModuleFlag::None
|
||||
, CodeType* interfaces = nullptr, s32 num_interfaces = 0 );
|
||||
|
||||
CodeConstructor def_constructor( CodeParam params = NoCode, Code initializer_list = NoCode, Code body = NoCode );
|
||||
|
||||
CodeDefine def_define( StrC name, StrC content );
|
||||
|
||||
CodeDestructor def_destructor( Code body = NoCode, CodeSpecifiers specifiers = NoCode );
|
||||
|
||||
CodeEnum def_enum( StrC name
|
||||
, Code body = NoCode, CodeType type = NoCode
|
||||
, EnumT specifier = EnumRegular, CodeAttributes attributes = NoCode
|
||||
@ -61,9 +69,9 @@ CodeFn def_function( StrC name
|
||||
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
|
||||
, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
CodeInclude def_include ( StrC content );
|
||||
CodeInclude def_include ( StrC content, bool foreign = false );
|
||||
CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None );
|
||||
CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
||||
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
|
||||
|
||||
CodeOperator def_operator( OperatorT op, StrC nspace
|
||||
, CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode
|
||||
@ -136,14 +144,52 @@ CodeBody def_union_body ( s32 num, Code* codes );
|
||||
|
||||
#pragma region Parsing
|
||||
|
||||
// TODO(Ed) : Implmeent the new parser API design.
|
||||
|
||||
#if 0
|
||||
namespace parser {
|
||||
struct StackNode
|
||||
{
|
||||
StackNode* Prev;
|
||||
|
||||
Token Start;
|
||||
Token Name; // The name of the AST node (if parsed)
|
||||
StrC FailedProc; // The name of the procedure that failed
|
||||
};
|
||||
// Stack nodes are allocated the error's allocator
|
||||
|
||||
struct Error
|
||||
{
|
||||
String message;
|
||||
StackNode* context_stack;
|
||||
};
|
||||
}
|
||||
|
||||
struct ParseInfo
|
||||
|
||||
Arena FileMem;
|
||||
Arena TokMem;
|
||||
Arena CodeMem;
|
||||
|
||||
FileContents FileContent;
|
||||
Array<parser::Token> Tokens;
|
||||
Array<parser::Error> Errors;
|
||||
// Errors are allocated to a dedicated general arena.
|
||||
;
|
||||
|
||||
CodeBody parse_file( StrC path );
|
||||
#endif
|
||||
|
||||
CodeClass parse_class ( StrC class_def );
|
||||
CodeConstructor parse_constructor ( StrC constructor_def );
|
||||
CodeDestructor parse_destructor ( StrC destructor_def );
|
||||
CodeEnum parse_enum ( StrC enum_def );
|
||||
CodeBody parse_export_body ( StrC export_def );
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def);
|
||||
CodeExtern parse_extern_link ( StrC exten_link_def );
|
||||
CodeFriend parse_friend ( StrC friend_def );
|
||||
CodeFn parse_function ( StrC fn_def );
|
||||
CodeBody parse_global_body ( StrC body_def );
|
||||
CodeNamespace parse_namespace ( StrC namespace_def );
|
||||
CodeNS parse_namespace ( StrC namespace_def );
|
||||
CodeOperator parse_operator ( StrC operator_def );
|
||||
CodeOpCast parse_operator_cast( StrC operator_def );
|
||||
CodeStruct parse_struct ( StrC struct_def );
|
||||
@ -159,6 +205,7 @@ CodeVar parse_variable ( StrC var_def );
|
||||
#pragma region Untyped text
|
||||
|
||||
sw token_fmt_va( char* buf, uw buf_size, s32 num_tokens, va_list va );
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
StrC token_fmt_impl( sw, ... );
|
||||
|
||||
Code untyped_str ( StrC content);
|
||||
|
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;
|
@ -1,3 +1,10 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Upfront
|
||||
|
||||
enum class OpValidateResult : u32
|
||||
{
|
||||
Fail,
|
||||
@ -5,7 +12,6 @@ enum class OpValidateResult : u32
|
||||
Member
|
||||
};
|
||||
|
||||
inline
|
||||
OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeType ret_type, CodeSpecifiers specifier )
|
||||
{
|
||||
using namespace EOperator;
|
||||
@ -30,12 +36,12 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
}
|
||||
|
||||
# define check_param_eq_ret() \
|
||||
if ( ! is_member_symbol && params_code->ValueType != ret_type ) \
|
||||
if ( ! is_member_symbol && ! params_code->ValueType.is_equal( ret_type) ) \
|
||||
{ \
|
||||
log_failure("gen_def_operator: operator%s requires first parameter to equal return type\n" \
|
||||
log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \
|
||||
"param types: %s\n" \
|
||||
"return type: %s", \
|
||||
to_str(op), \
|
||||
to_str(op).Ptr, \
|
||||
params_code.debug_str(), \
|
||||
ret_type.debug_str() \
|
||||
); \
|
||||
@ -153,7 +159,6 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
|
||||
case Unary_Plus:
|
||||
case Unary_Minus:
|
||||
case BNot:
|
||||
if ( ! params_code )
|
||||
is_member_symbol = true;
|
||||
|
||||
@ -188,6 +193,41 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
}
|
||||
break;
|
||||
|
||||
case BNot:
|
||||
{
|
||||
// Some compilers let you do this...
|
||||
#if 0
|
||||
if ( ! ret_type.is_equal( t_bool) )
|
||||
{
|
||||
log_failure( "gen::def_operator: return type is not a boolean - %s", params_code.debug_str() );
|
||||
return OpValidateResult::Fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( ! params_code )
|
||||
is_member_symbol = true;
|
||||
|
||||
else
|
||||
{
|
||||
if ( params_code->Type != ECode::Parameters )
|
||||
{
|
||||
log_failure( "gen::def_operator: params is not of Parameters type - %s", params_code.debug_str() );
|
||||
return OpValidateResult::Fail;
|
||||
}
|
||||
|
||||
if ( params_code->NumEntries > 1 )
|
||||
{
|
||||
log_failure(
|
||||
"gen::def_operator: operator%s may not have more than one parameter - param count: %d",
|
||||
to_str( op ),
|
||||
params_code->NumEntries
|
||||
);
|
||||
return OpValidateResult::Fail;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Add:
|
||||
case Subtract:
|
||||
case Multiply:
|
||||
@ -319,6 +359,11 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
case Comma:
|
||||
check_params();
|
||||
break;
|
||||
|
||||
case New:
|
||||
case Delete:
|
||||
// This library doesn't support validating new and delete yet.
|
||||
break;
|
||||
# undef specs
|
||||
}
|
||||
|
||||
@ -375,7 +420,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
|
||||
|
||||
/*
|
||||
The implementaiton of the upfront constructors involves bascially doing three things:
|
||||
The implementaiton of the upfront constructors involves doing three things:
|
||||
* Validate the arguments given to construct the intended type of AST is valid.
|
||||
* Construct said AST type.
|
||||
* Lock the AST (set to readonly) and return the valid object.
|
||||
@ -411,15 +456,92 @@ CodeComment def_comment( StrC content )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
static char line[ MaxCommentLineLength ];
|
||||
|
||||
String cmt_formatted = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
char const* end = content.Ptr + content.Len;
|
||||
char const* scanner = content.Ptr;
|
||||
s32 curr = 0;
|
||||
do
|
||||
{
|
||||
char const* next = scanner;
|
||||
s32 length = 0;
|
||||
while ( next != end && scanner[ length ] != '\n' )
|
||||
{
|
||||
next = scanner + length;
|
||||
length++;
|
||||
}
|
||||
length++;
|
||||
|
||||
str_copy( line, scanner, length );
|
||||
cmt_formatted.append_fmt( "//%.*s", length, line );
|
||||
mem_set( line, 0, MaxCommentLineLength );
|
||||
|
||||
scanner += length;
|
||||
}
|
||||
while ( scanner <= end );
|
||||
|
||||
if ( cmt_formatted.back() != '\n' )
|
||||
cmt_formatted.append( "\n" );
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = ECode::Comment;
|
||||
result->Name = get_cached_string( content );
|
||||
result->Name = get_cached_string( cmt_formatted );
|
||||
result->Content = result->Name;
|
||||
|
||||
cmt_formatted.free();
|
||||
|
||||
return (CodeComment) result;
|
||||
}
|
||||
|
||||
CodeConstructor def_constructor( CodeParam params, Code initializer_list, Code body )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
if ( params && params->Type != Parameters )
|
||||
{
|
||||
log_failure("gen::def_constructor: params must be of Parameters type - %s", params.debug_str());
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeConstructor
|
||||
result = (CodeConstructor) make_code();
|
||||
|
||||
if ( params )
|
||||
{
|
||||
result->Params = params;
|
||||
}
|
||||
|
||||
if ( initializer_list )
|
||||
{
|
||||
result->InitializerList = initializer_list;
|
||||
}
|
||||
|
||||
if ( body )
|
||||
{
|
||||
switch ( body->Type )
|
||||
{
|
||||
case Function_Body:
|
||||
case Untyped:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", body.debug_str());
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
result->Type = Constructor;
|
||||
result->Body = body;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->Type = Constructor_Fwd;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeClass def_class( StrC name
|
||||
, Code body
|
||||
, CodeType parent, AccessSpec parent_access
|
||||
@ -437,7 +559,7 @@ CodeClass def_class( StrC name
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
if ( parent && (parent->Type != Class || parent->Type != Struct || parent->Type != Typename || parent->Type != Untyped) )
|
||||
if ( parent && ( parent->Type != Class && parent->Type != Struct && parent->Type != Typename && parent->Type != Untyped ) )
|
||||
{
|
||||
log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", parent.debug_str() );
|
||||
return CodeInvalid;
|
||||
@ -463,6 +585,7 @@ CodeClass def_class( StrC name
|
||||
|
||||
result->Type = Class;
|
||||
result->Body = body;
|
||||
result->Body->Parent = result; // TODO(Ed): Review this?
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -495,20 +618,68 @@ CodeDefine def_define( StrC name, StrC content )
|
||||
|
||||
name_check( def_define, name );
|
||||
|
||||
// Defines can be empty definitions
|
||||
#if 0
|
||||
if ( content.Len <= 0 || content.Ptr == nullptr )
|
||||
{
|
||||
log_failure( "gen::def_define: Invalid value provided" );
|
||||
return CodeInvalid;
|
||||
}
|
||||
#endif
|
||||
|
||||
CodeDefine
|
||||
result = (CodeDefine) make_code();
|
||||
result->Type = Preprocess_Define;
|
||||
result->Name = get_cached_string( name );
|
||||
if ( content.Len <= 0 || content.Ptr == nullptr )
|
||||
{
|
||||
result->Content = get_cached_string( txt("") );
|
||||
}
|
||||
else
|
||||
result->Content = get_cached_string( content );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDestructor def_destructor( Code body, CodeSpecifiers specifiers )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
if ( specifiers && specifiers->Type != Specifiers )
|
||||
{
|
||||
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", specifiers.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeDestructor result = (CodeDestructor) make_code();
|
||||
|
||||
if ( specifiers )
|
||||
result->Specs = specifiers;
|
||||
|
||||
if ( body )
|
||||
{
|
||||
switch ( body->Type )
|
||||
{
|
||||
case Function_Body:
|
||||
case Untyped:
|
||||
break;
|
||||
|
||||
default:
|
||||
log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", body.debug_str());
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
result->Type = Destructor;
|
||||
result->Body = body;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->Type = Destructor_Fwd;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeEnum def_enum( StrC name
|
||||
, Code body, CodeType type
|
||||
, EnumT specifier, CodeAttributes attributes
|
||||
@ -729,7 +900,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 )
|
||||
{
|
||||
@ -737,10 +908,14 @@ CodeInclude def_include ( StrC path )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
StrC content = foreign ?
|
||||
to_str( str_fmt_buf( "<%.*s>", path.Len, path.Ptr ))
|
||||
: to_str( str_fmt_buf( "\"%.*s\"", path.Len, path.Ptr ));
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = ECode::Preprocess_Include;
|
||||
result->Name = get_cached_string( path );
|
||||
result->Name = get_cached_string( content );
|
||||
result->Content = result->Name;
|
||||
|
||||
return (CodeInclude) result;
|
||||
@ -760,7 +935,7 @@ CodeModule def_module( StrC name, ModuleFlag mflags )
|
||||
return (CodeModule) result;
|
||||
}
|
||||
|
||||
CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
@ -773,8 +948,8 @@ CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
CodeNamespace
|
||||
result = (CodeNamespace) make_code();
|
||||
CodeNS
|
||||
result = (CodeNS) make_code();
|
||||
result->Type = Namespace;
|
||||
result->Name = get_cached_string( name );
|
||||
result->ModuleFlags = mflags;
|
||||
@ -809,12 +984,18 @@ CodeOperator def_operator( OperatorT op, StrC nspace
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
char const* name = str_fmt_buf( "%.*soperator %s", nspace.Len, nspace.Ptr, to_str(op) );
|
||||
char const* name = nullptr;
|
||||
|
||||
StrC op_str = to_str( op );
|
||||
if ( nspace.Len > 0 )
|
||||
name = str_fmt_buf( "%.*soperator %.*s", nspace.Len, nspace.Ptr, op_str.Len, op_str.Ptr );
|
||||
else
|
||||
name = str_fmt_buf( "operator %.*s", op_str.Len, op_str.Ptr );
|
||||
CodeOperator
|
||||
result = (CodeOperator) make_code();
|
||||
result->Name = get_cached_string( { str_len(name), name } );
|
||||
result->ModuleFlags = mflags;
|
||||
result->Op = op;
|
||||
|
||||
if ( body )
|
||||
{
|
||||
@ -965,13 +1146,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;
|
||||
@ -1127,7 +1312,6 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
|
||||
{
|
||||
using namespace ECode;
|
||||
|
||||
name_check( def_typedef, name );
|
||||
null_check( def_typedef, type );
|
||||
|
||||
switch ( type->Type )
|
||||
@ -1166,12 +1350,28 @@ CodeTypedef def_typedef( StrC name, Code type, CodeAttributes attributes, Module
|
||||
|
||||
CodeTypedef
|
||||
result = (CodeTypedef) make_code();
|
||||
result->Name = get_cached_string( name );
|
||||
result->Type = ECode::Typedef;
|
||||
result->ModuleFlags = mflags;
|
||||
|
||||
result->UnderlyingType = type;
|
||||
|
||||
if ( name.Len <= 0 )
|
||||
{
|
||||
if (type->Type != Untyped)
|
||||
{
|
||||
log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", type.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
result->Name = get_cached_string( type->Name );
|
||||
result->IsFunction = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result->Name = get_cached_string( name );
|
||||
result->IsFunction = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1306,27 +1506,6 @@ CodeVar def_variable( CodeType type, StrC name, Code value
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Body related functions typically follow the same implementation pattern.
|
||||
Opted to use inline helper macros to get the implementaiton done.
|
||||
|
||||
The implementation pattern is as follows:
|
||||
* Validate a valid parameter num was provided, or code array
|
||||
def_body_start or def_body_code_array_start( <name of function >)
|
||||
|
||||
* Begin the code entry do-while loop, make sure each entry is valid processing its type in the switc
|
||||
def_body_code_validation_start( <name of function> )
|
||||
|
||||
* Define the switch case statements between the macros.
|
||||
|
||||
* Add the code entry, finish the closing implemenation for the do-while loop.
|
||||
def_body_code_validation_end( <name of function> )
|
||||
|
||||
* Lock the body AST and return it.
|
||||
|
||||
If a function's implementation deviates from the macros then its just writen it out.
|
||||
*/
|
||||
|
||||
#pragma region Helper Macros for def_**_body functions
|
||||
#define def_body_start( Name_ ) \
|
||||
using namespace ECode; \
|
||||
@ -1352,61 +1531,43 @@ if ( codes == nullptr ) \
|
||||
return CodeInvalid; \
|
||||
}
|
||||
|
||||
#define def_body_code_validation_start( Name_ ) \
|
||||
do \
|
||||
{ \
|
||||
Code_POD pod = va_arg(va, Code_POD); \
|
||||
Code entry = pcast(Code, pod); \
|
||||
\
|
||||
if ( ! entry ) \
|
||||
{ \
|
||||
log_failure("gen::" stringize(Name_) ": Provided an null entry"); \
|
||||
return CodeInvalid; \
|
||||
} \
|
||||
\
|
||||
switch ( entry->Type ) \
|
||||
{
|
||||
|
||||
#define def_body_code_array_validation_start( Name_ ) \
|
||||
do \
|
||||
{ \
|
||||
Code entry = *codes; codes++; \
|
||||
\
|
||||
if ( ! entry ) \
|
||||
{ \
|
||||
log_failure("gen::" stringize(Name_) ": Provided an null entry"); \
|
||||
return CodeInvalid; \
|
||||
} \
|
||||
\
|
||||
switch ( entry->Type ) \
|
||||
{
|
||||
|
||||
#define def_body_code_validation_end( Name_ ) \
|
||||
log_failure("gen::" stringize(Name_) ": Entry type is not allowed: %s", entry.debug_str() ); \
|
||||
return CodeInvalid; \
|
||||
\
|
||||
default: \
|
||||
break; \
|
||||
} \
|
||||
\
|
||||
result.append( entry ); \
|
||||
} \
|
||||
while ( num--, num > 0 )
|
||||
#pragma endregion Helper Macros for def_**_body functions
|
||||
|
||||
CodeBody def_class_body( s32 num, ... )
|
||||
{
|
||||
def_body_start( def_class_body );
|
||||
|
||||
CodeBody
|
||||
result = (CodeBody) make_code();
|
||||
CodeBody result = ( CodeBody )make_code();
|
||||
result->Type = Class_Body;
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_class_body );
|
||||
va_start( va, num );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::"
|
||||
"def_class_body"
|
||||
": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_class_body );
|
||||
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1420,9 +1581,30 @@ CodeBody def_class_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Function_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_class_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_class_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_CLASS_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_class_body );
|
||||
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1450,7 +1632,7 @@ CodeBody def_enum_body( s32 num, ... )
|
||||
|
||||
if ( entry->Type != Untyped && entry->Type != Comment )
|
||||
{
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() ); \
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
@ -1482,7 +1664,7 @@ CodeBody def_enum_body( s32 num, Code* codes )
|
||||
|
||||
if ( entry->Type != Untyped && entry->Type != Comment )
|
||||
{
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed: %s", entry.debug_str() ); \
|
||||
log_failure("gen::def_enum_body: Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
@ -1503,9 +1685,30 @@ CodeBody def_export_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_export_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_export_body );
|
||||
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1519,9 +1722,30 @@ CodeBody def_export_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Export_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_export_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_export_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_export_body );
|
||||
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1536,9 +1760,30 @@ CodeBody def_extern_link_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_extern_linkage_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_extern_linkage_body );
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1552,9 +1797,31 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Extern_Linkage_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_extern_linkage_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_extern_linkage_body );
|
||||
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1569,9 +1836,31 @@ CodeBody def_function_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_function_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" stringize(def_function_body) ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_function_body );
|
||||
log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1585,9 +1874,29 @@ CodeBody def_function_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Function_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_function_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_function_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_function_body );
|
||||
log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1602,9 +1911,34 @@ CodeBody def_global_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_global_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
case Global_Body:
|
||||
result.append( entry.cast<CodeBody>() ) ;
|
||||
continue;
|
||||
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_global_body );
|
||||
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return (*Code::Invalid.ast);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1618,9 +1952,34 @@ CodeBody def_global_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Global_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_global_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_global_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
case Global_Body:
|
||||
result.append( entry.cast<CodeBody>() ) ;
|
||||
continue;
|
||||
|
||||
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_global_body );
|
||||
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1635,9 +1994,30 @@ CodeBody def_namespace_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_namespace_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_namespace_body );
|
||||
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1651,9 +2031,29 @@ CodeBody def_namespace_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Global_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_namespace_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_namespace_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_namespace_body );
|
||||
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1803,9 +2203,30 @@ CodeBody def_struct_body( s32 num, ... )
|
||||
|
||||
va_list va;
|
||||
va_start(va, num);
|
||||
def_body_code_validation_start( def_struct_body );
|
||||
do
|
||||
{
|
||||
Code_POD pod = va_arg(va, Code_POD);
|
||||
Code entry = pcast(Code, pod);
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_struct_body );
|
||||
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str());
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
va_end(va);
|
||||
|
||||
return result;
|
||||
@ -1819,9 +2240,30 @@ CodeBody def_struct_body( s32 num, Code* codes )
|
||||
result = (CodeBody) make_code();
|
||||
result->Type = Struct_Body;
|
||||
|
||||
def_body_code_array_validation_start( def_struct_body );
|
||||
do
|
||||
{
|
||||
Code entry = *codes;
|
||||
codes++;
|
||||
|
||||
if (!entry)
|
||||
{
|
||||
log_failure("gen::" "def_struct_body" ": Provided an null entry");
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
switch (entry->Type)
|
||||
{
|
||||
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||
def_body_code_validation_end( def_struct_body );
|
||||
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(entry);
|
||||
}
|
||||
while (num--, num > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -1849,7 +2291,7 @@ CodeBody def_union_body( s32 num, ... )
|
||||
|
||||
if ( entry->Type != Untyped && entry->Type != Comment )
|
||||
{
|
||||
log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() ); \
|
||||
log_failure("gen::def_union_body: Entry type is not allowed - %s. Must be of untyped or comment type.", entry.debug_str() );
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
@ -1895,3 +2337,7 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
|
||||
# undef name_check
|
||||
# undef null_check
|
||||
# undef null_or_invalid_check
|
||||
# undef def_body_start
|
||||
# undef def_body_code_array_start
|
||||
|
||||
#pragma endregion Upfront
|
||||
|
1251
project/components/lexer.cpp
Normal file
1251
project/components/lexer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
5301
project/components/parser.cpp
Normal file
5301
project/components/parser.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,8 +2,11 @@
|
||||
# error Gen.hpp : GEN_TIME not defined
|
||||
#endif
|
||||
|
||||
#include "gen.hpp"
|
||||
|
||||
//! If its desired to roll your own dependencies, define GEN_ROLL_OWN_DEPENDENCIES before including this file.
|
||||
//! Dependencies are derived from the c-zpl library: https://github.com/zpl-c/zpl
|
||||
#ifndef GEN_ROLL_OWN_DEPENDENCIES
|
||||
# include "gen.dep.cpp"
|
||||
#endif
|
||||
|
@ -1,9 +1,15 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "gen.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region StaticData
|
||||
|
||||
// TODO : Convert global allocation strategy to use a slab allocation strategy.
|
||||
global AllocatorInfo GlobalAllocator;
|
||||
global Array<Arena> Global_AllocatorBuckets;
|
||||
|
||||
// TODO(Ed) : Make the code pool a dynamic arena
|
||||
global Array< Pool > CodePools = { nullptr };
|
||||
global Array< Arena > StringArenas = { nullptr };
|
||||
|
||||
@ -32,6 +38,8 @@ global CodeAttributes attrib_api_import;
|
||||
global Code module_global_fragment;
|
||||
global Code module_private_fragment;
|
||||
|
||||
global Code fmt_newline;
|
||||
|
||||
global CodeParam param_varadic;
|
||||
|
||||
global CodePragma pragma_once;
|
||||
@ -45,14 +53,17 @@ global CodeSpecifiers spec_constexpr;
|
||||
global CodeSpecifiers spec_constinit;
|
||||
global CodeSpecifiers spec_extern_linkage;
|
||||
global CodeSpecifiers spec_final;
|
||||
global CodeSpecifiers spec_forceinline;
|
||||
global CodeSpecifiers spec_global;
|
||||
global CodeSpecifiers spec_inline;
|
||||
global CodeSpecifiers spec_internal_linkage;
|
||||
global CodeSpecifiers spec_local_persist;
|
||||
global CodeSpecifiers spec_mutable;
|
||||
global CodeSpecifiers spec_noexcept;
|
||||
global CodeSpecifiers spec_neverinline;
|
||||
global CodeSpecifiers spec_override;
|
||||
global CodeSpecifiers spec_ptr;
|
||||
global CodeSpecifiers spec_pure;
|
||||
global CodeSpecifiers spec_ref;
|
||||
global CodeSpecifiers spec_register;
|
||||
global CodeSpecifiers spec_rvalue;
|
||||
@ -71,6 +82,8 @@ global CodeType t_wchar_t;
|
||||
global CodeType t_class;
|
||||
global CodeType t_typename;
|
||||
|
||||
global Array< StringCached > PreprocessorDefines;
|
||||
|
||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
global CodeType t_b32;
|
||||
|
||||
|
@ -1,19 +1,24 @@
|
||||
#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
|
||||
constexpr LogFailType log_failure = log_fmt;
|
||||
#define log_failure log_fmt
|
||||
#else
|
||||
constexpr LogFailType log_failure = fatal;
|
||||
#define log_failure GEN_FATAL
|
||||
#endif
|
||||
|
||||
enum class AccessSpec : u32
|
||||
{
|
||||
Default,
|
||||
Public,
|
||||
Protected,
|
||||
Private,
|
||||
Protected,
|
||||
Public,
|
||||
|
||||
Num_AccessSpec,
|
||||
Invalid,
|
||||
@ -25,9 +30,9 @@ char const* to_str( AccessSpec type )
|
||||
local_persist
|
||||
char const* lookup[ (u32)AccessSpec::Num_AccessSpec ] = {
|
||||
"",
|
||||
"public",
|
||||
"protected",
|
||||
"private",
|
||||
"protected",
|
||||
"public",
|
||||
};
|
||||
|
||||
if ( type > AccessSpec::Public )
|
||||
@ -36,6 +41,16 @@ char const* to_str( AccessSpec type )
|
||||
return lookup[ (u32)type ];
|
||||
}
|
||||
|
||||
|
||||
enum CodeFlag : u32
|
||||
{
|
||||
None = 0,
|
||||
FunctionType = bit(0),
|
||||
ParamPack = bit(1),
|
||||
Module_Export = bit(2),
|
||||
Module_Import = bit(3),
|
||||
};
|
||||
|
||||
// Used to indicate if enum definitoin is an enum class or regular enum.
|
||||
enum class EnumT : u8
|
||||
{
|
||||
@ -46,18 +61,31 @@ enum class EnumT : u8
|
||||
constexpr EnumT EnumClass = EnumT::Class;
|
||||
constexpr EnumT EnumRegular = EnumT::Regular;
|
||||
|
||||
|
||||
enum class ModuleFlag : u32
|
||||
{
|
||||
None = 0,
|
||||
Export = bit(0),
|
||||
Import = bit(1),
|
||||
// Private = bit(2),
|
||||
|
||||
Num_ModuleFlags,
|
||||
Invalid,
|
||||
};
|
||||
|
||||
StrC to_str( ModuleFlag flag )
|
||||
{
|
||||
local_persist
|
||||
StrC lookup[ (u32)ModuleFlag::Num_ModuleFlags ] = {
|
||||
{ sizeof("__none__"), "__none__" },
|
||||
{ sizeof("export"), "export" },
|
||||
{ sizeof("import"), "import" },
|
||||
};
|
||||
|
||||
if ( flag > ModuleFlag::Import )
|
||||
return { sizeof("invalid"), "invalid" };
|
||||
|
||||
return lookup[ (u32)flag ];
|
||||
}
|
||||
|
||||
ModuleFlag operator|( ModuleFlag A, ModuleFlag B)
|
||||
{
|
||||
return (ModuleFlag)( (u32)A | (u32)B );
|
||||
@ -75,42 +103,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
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Basic Types
|
||||
|
||||
#define GEN_U8_MIN 0u
|
||||
@ -117,4 +122,4 @@ typedef s8 b8;
|
||||
typedef s16 b16;
|
||||
typedef s32 b32;
|
||||
|
||||
#pragma region Basic Types
|
||||
#pragma endregion Basic Types
|
||||
|
@ -1,5 +1,18 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Containers
|
||||
|
||||
template<class TType> struct RemoveConst { typedef TType Type; };
|
||||
template<class TType> struct RemoveConst<const TType> { typedef TType Type; };
|
||||
template<class TType> struct RemoveConst<const TType[]> { typedef TType Type[]; };
|
||||
template<class TType, uw Size> struct RemoveConst<const TType[Size]> { typedef TType Type[Size]; };
|
||||
|
||||
template<class TType>
|
||||
using TRemoveConst = typename RemoveConst<TType>::Type;
|
||||
|
||||
template<class Type>
|
||||
struct Array
|
||||
{
|
||||
@ -142,7 +155,7 @@ struct Array
|
||||
{
|
||||
Header& header = * get_header();
|
||||
|
||||
if ( begin < 0 || end >= header.Num )
|
||||
if ( begin < 0 || end > header.Num )
|
||||
return false;
|
||||
|
||||
for ( sw idx = begin; idx < end; idx++ )
|
||||
@ -162,7 +175,8 @@ struct Array
|
||||
|
||||
Header* get_header( void )
|
||||
{
|
||||
return rcast( Header*, Data ) - 1 ;
|
||||
using NonConstType = TRemoveConst< Type >;
|
||||
return rcast( Header*, const_cast<NonConstType*>(Data) ) - 1 ;
|
||||
}
|
||||
|
||||
bool grow( uw min_capacity )
|
||||
@ -181,7 +195,7 @@ struct Array
|
||||
return get_header()->Num;
|
||||
}
|
||||
|
||||
bool pop( void )
|
||||
void pop( void )
|
||||
{
|
||||
Header& header = * get_header();
|
||||
|
||||
@ -232,7 +246,11 @@ struct Array
|
||||
return true;
|
||||
|
||||
if ( new_capacity < header.Num )
|
||||
{
|
||||
// Already have the memory, mine as well keep it.
|
||||
header.Num = new_capacity;
|
||||
return true;
|
||||
}
|
||||
|
||||
sw size = sizeof( Header ) + sizeof( Type ) * new_capacity;
|
||||
Header* new_header = rcast( Header*, alloc( header.Allocator, size ) );
|
||||
@ -275,6 +293,8 @@ struct Array
|
||||
}
|
||||
};
|
||||
|
||||
// TODO(Ed) : This thing needs ALOT of work.
|
||||
|
||||
template<typename Type>
|
||||
struct HashTable
|
||||
{
|
||||
@ -292,14 +312,12 @@ struct HashTable
|
||||
Type Value;
|
||||
};
|
||||
|
||||
static constexpr f32 CriticalLoadScale = 0.7f;
|
||||
|
||||
static
|
||||
HashTable init( AllocatorInfo allocator )
|
||||
{
|
||||
HashTable<Type> result = { { nullptr }, { nullptr } };
|
||||
|
||||
result.Hashes = Array<sw>::init( allocator );
|
||||
result.Entries = Array<Entry>::init( allocator );
|
||||
|
||||
HashTable<Type> result = init_reserve(allocator, 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -310,19 +328,17 @@ struct HashTable
|
||||
|
||||
result.Hashes = Array<sw>::init_reserve( allocator, num );
|
||||
result.Hashes.get_header()->Num = num;
|
||||
result.Hashes.resize( num );
|
||||
result.Hashes.fill( 0, num, -1);
|
||||
|
||||
result.Entries = Array<Entry>::init_reserve( allocator, num );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void clear( void )
|
||||
{
|
||||
for ( sw idx = 0; idx < Hashes.num(); idx++ )
|
||||
Hashes[ idx ] = -1;
|
||||
|
||||
Hashes.clear();
|
||||
Entries.clear();
|
||||
Hashes.fill( 0, Hashes.num(), -1);
|
||||
}
|
||||
|
||||
void destroy( void )
|
||||
@ -375,32 +391,19 @@ struct HashTable
|
||||
|
||||
void rehash( sw new_num )
|
||||
{
|
||||
sw idx;
|
||||
sw last_added_index;
|
||||
|
||||
HashTable<Type> new_ht = init_reserve( Hashes.get_header()->Allocator, new_num );
|
||||
|
||||
Array<sw>::Header* hash_header = new_ht.Hashes.get_header();
|
||||
|
||||
for ( idx = 0; idx < new_ht.Hashes.num(); ++idx )
|
||||
new_ht.Hashes[ idx ] = -1;
|
||||
|
||||
for ( idx = 0; idx < Entries.num(); ++idx )
|
||||
for ( sw idx = 0; idx < Entries.num(); ++idx )
|
||||
{
|
||||
Entry& entry = Entries[ idx ];
|
||||
|
||||
FindResult find_result;
|
||||
|
||||
if ( new_ht.Hashes.num() == 0 )
|
||||
new_ht.grow();
|
||||
|
||||
entry = Entries[ idx ];
|
||||
Entry& entry = Entries[ idx ];
|
||||
find_result = new_ht.find( entry.Key );
|
||||
last_added_index = new_ht.add_entry( entry.Key );
|
||||
|
||||
if ( find_result.PrevIndex < 0 )
|
||||
new_ht.Hashes[ find_result.HashIndex ] = last_added_index;
|
||||
|
||||
else
|
||||
new_ht.Entries[ find_result.PrevIndex ].Next = last_added_index;
|
||||
|
||||
@ -425,8 +428,15 @@ struct HashTable
|
||||
for ( idx = 0; idx < Entries.num(); idx++ )
|
||||
{
|
||||
Entry* entry;
|
||||
|
||||
FindResult find_result;
|
||||
|
||||
entry = & Entries[ idx ];
|
||||
find_result = find( entry->Key );
|
||||
|
||||
if ( find_result.PrevIndex < 0 )
|
||||
Hashes[ find_result.HashIndex ] = idx;
|
||||
else
|
||||
Entries[ find_result.PrevIndex ].Next = idx;
|
||||
}
|
||||
}
|
||||
|
||||
@ -451,11 +461,10 @@ struct HashTable
|
||||
sw idx;
|
||||
FindResult find_result;
|
||||
|
||||
if ( Hashes.num() == 0 )
|
||||
if ( full() )
|
||||
grow();
|
||||
|
||||
find_result = find( key );
|
||||
|
||||
if ( find_result.EntryIndex >= 0 )
|
||||
{
|
||||
idx = find_result.EntryIndex;
|
||||
@ -528,7 +537,9 @@ protected:
|
||||
|
||||
b32 full()
|
||||
{
|
||||
return 0.75f * Hashes.num() < Entries.num();
|
||||
uw critical_load = uw( CriticalLoadScale * f32(Hashes.num()) );
|
||||
b32 result = Entries.num() > critical_load;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,11 @@
|
||||
#pragma endregion Debug
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.hpp"
|
||||
# include "basic_types.hpp"
|
||||
# include "src_start.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
|
||||
{
|
||||
|
@ -1,4 +1,9 @@
|
||||
#pragma endregion Debug
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "basic_types.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
|
||||
#if defined( _MSC_VER )
|
||||
# if _MSC_VER < 1300
|
||||
@ -33,4 +38,26 @@ void assert_handler( char const* condition, char const* file, s32 line, char con
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
|
||||
#if Build_Debug
|
||||
#define GEN_FATAL( ... ) \
|
||||
do \
|
||||
{ \
|
||||
local_persist thread_local \
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 }; \
|
||||
\
|
||||
str_fmt(buf, GEN_PRINTF_MAXLEN, __VA_ARGS__); \
|
||||
GEN_PANIC(buf); \
|
||||
} \
|
||||
while (0)
|
||||
#else
|
||||
|
||||
# define GEN_FATAL( ... ) \
|
||||
do \
|
||||
{ \
|
||||
str_fmt_out_err( __VA_ARGS__ ); \
|
||||
process_exit(1); \
|
||||
} \
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
#pragma endregion Debug
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region File Handling
|
||||
|
||||
typedef u32 FileMode;
|
||||
@ -331,8 +336,6 @@ GEN_IMPL_INLINE b32 file_write_at_check( FileInfo* f, void const* buffer, sw siz
|
||||
return f->ops.write_at( f->fd, buffer, size, offset, bytes_written );
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum FileStreamFlags : u32
|
||||
{
|
||||
/* Allows us to write to the buffer directly. Beware: you can not append a new data! */
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
global u32 const _crc32_table[ 256 ] = {
|
||||
@ -82,4 +87,4 @@ u64 crc64( void const* data, sw len )
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma region Hashing
|
||||
#pragma endregion Hashing
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "containers.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
u32 crc32( void const* data, sw len );
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#pragma region Platform Detection
|
||||
|
||||
/* Platform architecture */
|
||||
@ -100,32 +102,25 @@
|
||||
#define GEN_DEF_INLINE static
|
||||
#define GEN_IMPL_INLINE static inline
|
||||
|
||||
#ifdef GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
# define neverinline __declspec( noinline )
|
||||
#elif defined(GEN_COMPILER_GCC)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#elif defined(GEN_COMPILER_CLANG)
|
||||
#if __has_attribute(__always_inline__)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
|
||||
#pragma endregion Platform Detection
|
||||
|
||||
#pragma region Mandatory Includes
|
||||
|
||||
# include <stdarg.h>
|
||||
# include <stddef.h>
|
||||
|
||||
# if defined( GEN_SYSTEM_WINDOWS )
|
||||
# include <intrin.h>
|
||||
# endif
|
||||
|
||||
#pragma endregion Mandatory Includes
|
||||
|
||||
#ifdef GEN_DONT_USE_NAMESPACE
|
||||
# define GEN_NS
|
||||
# define GEN_NS_BEGIN
|
||||
# define GEN_NS_END
|
||||
#else
|
||||
# define GEN_NS gen::
|
||||
# define GEN_NS_BEGIN namespace gen {
|
||||
# define GEN_NS_END }
|
||||
#endif
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#define zpl_cast( Type ) ( Type )
|
||||
@ -8,53 +13,103 @@
|
||||
#define internal static // Internal linkage
|
||||
#define local_persist static // Local Persisting variables
|
||||
|
||||
#ifdef GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
# define neverinline __declspec( noinline )
|
||||
#elif defined(GEN_COMPILER_GCC)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#elif defined(GEN_COMPILER_CLANG)
|
||||
#if __has_attribute(__always_inline__)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
#else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
#endif
|
||||
|
||||
// Bits
|
||||
|
||||
#define bit( Value ) ( 1 << Value )
|
||||
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
|
||||
|
||||
// Casting
|
||||
|
||||
#define ccast( Type, Value ) ( * const_cast< Type* >( & (Value) ) )
|
||||
#define pcast( Type, Value ) ( * reinterpret_cast< Type* >( & ( Value ) ) )
|
||||
#define rcast( Type, Value ) reinterpret_cast< Type >( Value )
|
||||
#define scast( Type, Value ) static_cast< Type >( Value )
|
||||
|
||||
// Num Arguments (Varadics)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
// Supports 0-10 arguments
|
||||
// #if defined(__GNUC__) || defined(__clang__)
|
||||
// Supports 0-50 arguments
|
||||
#define num_args_impl( _0, \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
_21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
_31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
_41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
_51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
||||
_61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
|
||||
_71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
|
||||
_81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
|
||||
_91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
|
||||
N, ... \
|
||||
) N
|
||||
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50,
|
||||
|
||||
// ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang)
|
||||
#define num_args(...) \
|
||||
num_args_impl(_, ## __VA_ARGS__, \
|
||||
100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
|
||||
90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
|
||||
80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
|
||||
70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
|
||||
60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
|
||||
50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \
|
||||
0 \
|
||||
)
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
|
||||
#else
|
||||
// Supports 1-10 arguments
|
||||
#define num_args_impl( \
|
||||
_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
_11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
N, ... \
|
||||
) N
|
||||
|
||||
#define num_args(...) \
|
||||
num_args_impl( __VA_ARGS__, \
|
||||
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
|
||||
)
|
||||
#endif
|
||||
// #else
|
||||
// This doesn't work on latest msvc so I had to use /Zc:preprocessor flag.
|
||||
|
||||
// Supports 1-50 arguments
|
||||
// #define num_args_impl( \
|
||||
// _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
|
||||
// _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \
|
||||
// _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \
|
||||
// _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \
|
||||
// _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \
|
||||
// _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \
|
||||
// _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \
|
||||
// _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \
|
||||
// _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \
|
||||
// _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \
|
||||
// N, ... \
|
||||
// ) N
|
||||
|
||||
// #define num_args(...) \
|
||||
// num_args_impl( __VA_ARGS__, \
|
||||
// 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \
|
||||
// 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \
|
||||
// 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \
|
||||
// 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \
|
||||
// 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \
|
||||
// 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \
|
||||
// 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \
|
||||
// 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
|
||||
// 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \
|
||||
// )
|
||||
// #endif
|
||||
|
||||
// Stringizing
|
||||
#define stringize_va( ... ) #__VA_ARGS__
|
||||
@ -96,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 )
|
||||
{
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
|
||||
void* mem_copy( void* dest, void const* source, sw n )
|
||||
@ -203,6 +208,132 @@ void* heap_allocator_proc( void* allocator_data, AllocType type, sw size, sw ali
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#pragma region VirtualMemory
|
||||
VirtualMemory vm_from_memory( void* data, sw size )
|
||||
{
|
||||
VirtualMemory vm;
|
||||
vm.data = data;
|
||||
vm.size = size;
|
||||
return vm;
|
||||
}
|
||||
|
||||
#if defined( GEN_SYSTEM_WINDOWS )
|
||||
VirtualMemory vm_alloc( void* addr, sw size )
|
||||
{
|
||||
VirtualMemory vm;
|
||||
GEN_ASSERT( size > 0 );
|
||||
vm.data = VirtualAlloc( addr, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE );
|
||||
vm.size = size;
|
||||
return vm;
|
||||
}
|
||||
|
||||
b32 vm_free( VirtualMemory vm )
|
||||
{
|
||||
MEMORY_BASIC_INFORMATION info;
|
||||
while ( vm.size > 0 )
|
||||
{
|
||||
if ( VirtualQuery( vm.data, &info, size_of( info ) ) == 0 )
|
||||
return false;
|
||||
if ( info.BaseAddress != vm.data || info.AllocationBase != vm.data || info.State != MEM_COMMIT || info.RegionSize > zpl_cast( uw ) vm.size )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( VirtualFree( vm.data, 0, MEM_RELEASE ) == 0 )
|
||||
return false;
|
||||
vm.data = pointer_add( vm.data, info.RegionSize );
|
||||
vm.size -= info.RegionSize;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualMemory vm_trim( VirtualMemory vm, sw lead_size, sw size )
|
||||
{
|
||||
VirtualMemory new_vm = { 0 };
|
||||
void* ptr;
|
||||
GEN_ASSERT( vm.size >= lead_size + size );
|
||||
|
||||
ptr = pointer_add( vm.data, lead_size );
|
||||
|
||||
vm_free( vm );
|
||||
new_vm = vm_alloc( ptr, size );
|
||||
if ( new_vm.data == ptr )
|
||||
return new_vm;
|
||||
if ( new_vm.data )
|
||||
vm_free( new_vm );
|
||||
return new_vm;
|
||||
}
|
||||
|
||||
b32 vm_purge( VirtualMemory vm )
|
||||
{
|
||||
VirtualAlloc( vm.data, vm.size, MEM_RESET, PAGE_READWRITE );
|
||||
// NOTE: Can this really fail?
|
||||
return true;
|
||||
}
|
||||
|
||||
sw virtual_memory_page_size( sw* alignment_out )
|
||||
{
|
||||
SYSTEM_INFO info;
|
||||
GetSystemInfo( &info );
|
||||
if ( alignment_out )
|
||||
*alignment_out = info.dwAllocationGranularity;
|
||||
return info.dwPageSize;
|
||||
}
|
||||
|
||||
#else
|
||||
# include <sys/mman.h>
|
||||
|
||||
# ifndef MAP_ANONYMOUS
|
||||
# define MAP_ANONYMOUS MAP_ANON
|
||||
# endif
|
||||
VirtualMemory vm_alloc( void* addr, sw size )
|
||||
{
|
||||
VirtualMemory vm;
|
||||
GEN_ASSERT( size > 0 );
|
||||
vm.data = mmap( addr, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0 );
|
||||
vm.size = size;
|
||||
return vm;
|
||||
}
|
||||
|
||||
b32 vm_free( VirtualMemory vm )
|
||||
{
|
||||
munmap( vm.data, vm.size );
|
||||
return true;
|
||||
}
|
||||
|
||||
VirtualMemory vm_trim( VirtualMemory vm, sw lead_size, sw size )
|
||||
{
|
||||
void* ptr;
|
||||
sw trail_size;
|
||||
GEN_ASSERT( vm.size >= lead_size + size );
|
||||
|
||||
ptr = pointer_add( vm.data, lead_size );
|
||||
trail_size = vm.size - lead_size - size;
|
||||
|
||||
if ( lead_size != 0 )
|
||||
vm_free( vm_from_memory(( vm.data, lead_size ) );
|
||||
if ( trail_size != 0 )
|
||||
vm_free( vm_from_memory( ptr, trail_size ) );
|
||||
return vm_from_memory( ptr, size );
|
||||
}
|
||||
|
||||
b32 vm_purge( VirtualMemory vm )
|
||||
{
|
||||
int err = madvise( vm.data, vm.size, MADV_DONTNEED );
|
||||
return err != 0;
|
||||
}
|
||||
|
||||
sw virtual_memory_page_size( sw* alignment_out )
|
||||
{
|
||||
// TODO: Is this always true?
|
||||
sw result = zpl_cast( sw ) sysconf( _SC_PAGE_SIZE );
|
||||
if ( alignment_out )
|
||||
*alignment_out = result;
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#pragma endregion VirtualMemory
|
||||
|
||||
void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
|
||||
{
|
||||
Arena* arena = rcast(Arena*, allocator_data);
|
||||
@ -221,7 +352,7 @@ void* Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw a
|
||||
if ( arena->TotalUsed + total_size > (sw) arena->TotalSize )
|
||||
{
|
||||
// zpl__printf_err("%s", "Arena out of memory\n");
|
||||
fatal("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
|
||||
GEN_FATAL("Arena out of memory! (Possibly could not fit for the largest size Arena!!)");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Memory
|
||||
|
||||
#define kilobytes( x ) ( ( x ) * ( s64 )( 1024 ) )
|
||||
@ -360,6 +365,33 @@ GEN_IMPL_INLINE void zero_size( void* ptr, sw size )
|
||||
mem_set( ptr, 0, size );
|
||||
}
|
||||
|
||||
struct VirtualMemory
|
||||
{
|
||||
void* data;
|
||||
sw size;
|
||||
};
|
||||
|
||||
//! Initialize virtual memory from existing data.
|
||||
VirtualMemory vm_from_memory( void* data, sw size );
|
||||
|
||||
//! Allocate virtual memory at address with size.
|
||||
|
||||
//! @param addr The starting address of the region to reserve. If NULL, it lets operating system to decide where to allocate it.
|
||||
//! @param size The size to serve.
|
||||
VirtualMemory vm_alloc( void* addr, sw size );
|
||||
|
||||
//! Release the virtual memory.
|
||||
b32 vm_free( VirtualMemory vm );
|
||||
|
||||
//! Trim virtual memory.
|
||||
VirtualMemory vm_trim( VirtualMemory vm, sw lead_size, sw size );
|
||||
|
||||
//! Purge virtual memory.
|
||||
b32 gen_vm_purge( VirtualMemory vm );
|
||||
|
||||
//! Retrieve VM's page size and alignment.
|
||||
sw gen_virtual_memory_page_size( sw* alignment_out );
|
||||
|
||||
struct Arena
|
||||
{
|
||||
static
|
||||
@ -445,6 +477,45 @@ struct Arena
|
||||
}
|
||||
};
|
||||
|
||||
// Just a wrapper around using an arena with memory associated with its scope instead of from an allocator.
|
||||
// Used for static segment or stack allocations.
|
||||
template< s32 Size >
|
||||
struct FixedArena
|
||||
{
|
||||
static
|
||||
FixedArena init()
|
||||
{
|
||||
FixedArena result = { Arena::init_from_memory( result.memory, Size ), {0} };
|
||||
return result;
|
||||
}
|
||||
|
||||
sw size_remaining( sw alignment )
|
||||
{
|
||||
return arena.size_remaining( alignment );
|
||||
}
|
||||
|
||||
operator AllocatorInfo()
|
||||
{
|
||||
return { Arena::allocator_proc, &arena };
|
||||
}
|
||||
|
||||
Arena arena;
|
||||
char memory[ Size ];
|
||||
};
|
||||
|
||||
using Arena_1KB = FixedArena< kilobytes( 1 ) >;
|
||||
using Arena_4KB = FixedArena< kilobytes( 4 ) >;
|
||||
using Arena_8KB = FixedArena< kilobytes( 8 ) >;
|
||||
using Arena_16KB = FixedArena< kilobytes( 16 ) >;
|
||||
using Arena_32KB = FixedArena< kilobytes( 32 ) >;
|
||||
using Arena_64KB = FixedArena< kilobytes( 64 ) >;
|
||||
using Arena_128KB = FixedArena< kilobytes( 128 ) >;
|
||||
using Arena_256KB = FixedArena< kilobytes( 256 ) >;
|
||||
using Arena_512KB = FixedArena< kilobytes( 512 ) >;
|
||||
using Arena_1MB = FixedArena< megabytes( 1 ) >;
|
||||
using Arena_2MB = FixedArena< megabytes( 2 ) >;
|
||||
using Arena_4MB = FixedArena< megabytes( 4 ) >;
|
||||
|
||||
struct Pool
|
||||
{
|
||||
static
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
#define _adt_fprintf( s_, fmt_, ... ) \
|
||||
@ -799,7 +803,6 @@ ADT_Error adt_str_to_number_strict( ADT_Node* node )
|
||||
# define GEN_CSV_ASSERT( msg )
|
||||
#endif
|
||||
|
||||
|
||||
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim )
|
||||
{
|
||||
CSV_Error error = ECSV_Error__NONE;
|
||||
@ -1104,3 +1107,4 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#pragma region ADT
|
||||
|
||||
enum ADT_Type : u32
|
||||
@ -423,3 +427,4 @@ GEN_IMPL_INLINE String csv_write_string( AllocatorInfo a, CSV_Object* obj )
|
||||
}
|
||||
|
||||
#pragma endregion CSV
|
||||
|
||||
|
@ -1,3 +1,10 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
# include "strings.hpp"
|
||||
# include "string_ops.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
enum
|
||||
@ -47,7 +54,8 @@ internal sw _print_string( char* text, sw max_len, _format_info* info, char cons
|
||||
}
|
||||
|
||||
if ( info && info->precision >= 0 )
|
||||
len = str_len( str, info->precision );
|
||||
// Made the design decision for this library that precision is the length of the string.
|
||||
len = info->precision;
|
||||
else
|
||||
len = str_len( str );
|
||||
|
||||
@ -410,6 +418,15 @@ neverinline sw str_fmt_va( char* text, sw max_len, char const* fmt, va_list va )
|
||||
len = _print_string( text, remaining, &info, va_arg( va, char* ) );
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
{
|
||||
String gen_str = String { va_arg( va, char*) };
|
||||
|
||||
info.precision = gen_str.length();
|
||||
len = _print_string( text, remaining, &info, gen_str );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r' :
|
||||
len = _print_repeated_char( text, remaining, &info, va_arg( va, int ) );
|
||||
break;
|
||||
@ -541,6 +558,16 @@ sw str_fmt_file( struct FileInfo* f, char const* fmt, ... )
|
||||
return res;
|
||||
}
|
||||
|
||||
sw str_fmt( char* str, sw n, char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( str, n, fmt, va );
|
||||
va_end( va );
|
||||
return res;
|
||||
}
|
||||
|
||||
sw str_fmt_out_va( char const* fmt, va_list va )
|
||||
{
|
||||
return str_fmt_file_va( file_get_standard( EFileStandard_OUTPUT ), fmt, va );
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
struct FileInfo;
|
||||
@ -9,13 +14,11 @@ struct FileInfo;
|
||||
// NOTE: A locally persisting buffer is used internally
|
||||
char* str_fmt_buf ( char const* fmt, ... );
|
||||
char* str_fmt_buf_va ( char const* fmt, va_list va );
|
||||
sw str_fmt ( char* str, sw n, char const* fmt, ... );
|
||||
sw str_fmt_va ( char* str, sw n, char const* fmt, va_list va );
|
||||
sw str_fmt_out_va ( char const* fmt, va_list va );
|
||||
sw str_fmt_out_err ( char const* fmt, ... );
|
||||
sw str_fmt_out_err_va( char const* fmt, va_list va );
|
||||
|
||||
// TODO : Move these to file handling.
|
||||
|
||||
sw str_fmt_file ( FileInfo* f, char const* fmt, ... );
|
||||
sw str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
|
||||
|
||||
@ -35,29 +38,4 @@ sw log_fmt(char const* fmt, ...)
|
||||
return res;
|
||||
}
|
||||
|
||||
inline
|
||||
sw fatal(char const* fmt, ...)
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[GEN_PRINTF_MAXLEN] = { 0 };
|
||||
|
||||
va_list va;
|
||||
|
||||
#if Build_Debug
|
||||
va_start(va, fmt);
|
||||
str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
|
||||
va_end(va);
|
||||
|
||||
assert_crash(buf);
|
||||
return -1;
|
||||
#else
|
||||
va_start(va, fmt);
|
||||
str_fmt_out_err_va( fmt, va);
|
||||
va_end(va);
|
||||
|
||||
exit(1);
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
||||
|
@ -1,3 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros and Includes
|
||||
|
||||
# include <stdio.h>
|
@ -1,39 +0,0 @@
|
||||
#pragma region String
|
||||
|
||||
String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, buf_size, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
bool String::append_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
return append( buf, res );
|
||||
}
|
||||
|
||||
#pragma endregion String
|
@ -1,3 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "string_ops.hpp"
|
||||
# include "debug.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
internal
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region String Ops
|
||||
|
||||
GEN_DEF_INLINE const char* char_first_occurence( const char* str, char c );
|
||||
|
130
project/dependencies/strings.cpp
Normal file
130
project/dependencies/strings.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "hashing.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region String
|
||||
|
||||
String String::fmt( AllocatorInfo allocator, char* buf, sw buf_size, char const* fmt, ... )
|
||||
{
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, buf_size, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
String String::make_length( AllocatorInfo allocator, char const* str, sw length )
|
||||
{
|
||||
constexpr sw header_size = sizeof( Header );
|
||||
|
||||
s32 alloc_size = header_size + length + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
Header&
|
||||
header = * rcast(Header*, allocation);
|
||||
header = { allocator, length, length };
|
||||
|
||||
String result = { rcast( char*, allocation) + header_size };
|
||||
|
||||
if ( length && str )
|
||||
mem_copy( result, str, length );
|
||||
else
|
||||
mem_set( result, 0, alloc_size - header_size );
|
||||
|
||||
result[ length ] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
String String::make_reserve( AllocatorInfo allocator, sw capacity )
|
||||
{
|
||||
constexpr sw header_size = sizeof( Header );
|
||||
|
||||
s32 alloc_size = header_size + capacity + 1;
|
||||
void* allocation = alloc( allocator, alloc_size );
|
||||
|
||||
if ( allocation == nullptr )
|
||||
return { nullptr };
|
||||
|
||||
mem_set( allocation, 0, alloc_size );
|
||||
|
||||
Header*
|
||||
header = rcast(Header*, allocation);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = capacity;
|
||||
header->Length = 0;
|
||||
|
||||
String result = { rcast(char*, allocation) + header_size };
|
||||
return result;
|
||||
}
|
||||
|
||||
String String::fmt_buf( AllocatorInfo allocator, char const* fmt, ... )
|
||||
{
|
||||
local_persist thread_local
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
str_fmt_va( buf, GEN_PRINTF_MAXLEN, fmt, va );
|
||||
va_end( va );
|
||||
|
||||
return make( allocator, buf );
|
||||
}
|
||||
|
||||
bool String::append_fmt( char const* fmt, ... )
|
||||
{
|
||||
sw res;
|
||||
char buf[ GEN_PRINTF_MAXLEN ] = { 0 };
|
||||
|
||||
va_list va;
|
||||
va_start( va, fmt );
|
||||
res = str_fmt_va( buf, count_of( buf ) - 1, fmt, va ) - 1;
|
||||
va_end( va );
|
||||
|
||||
return append( buf, res );
|
||||
}
|
||||
|
||||
bool String::make_space_for( char const* str, sw add_len )
|
||||
{
|
||||
sw available = avail_space();
|
||||
|
||||
// NOTE: Return if there is enough space left
|
||||
if ( available >= add_len )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
sw new_len, old_size, new_size;
|
||||
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = get_header().Allocator;
|
||||
Header* header = nullptr;
|
||||
|
||||
new_len = grow_formula( length() + add_len );
|
||||
ptr = & get_header();
|
||||
old_size = size_of( Header ) + length() + 1;
|
||||
new_size = size_of( Header ) + new_len + 1;
|
||||
|
||||
new_ptr = resize( allocator, ptr, old_size, new_size );
|
||||
|
||||
if ( new_ptr == nullptr )
|
||||
return false;
|
||||
|
||||
header = zpl_cast( Header* ) new_ptr;
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
Data = rcast( char*, header + 1 );
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
#pragma endregion String
|
@ -1,4 +1,9 @@
|
||||
#pragma region String
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "hashing.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Strings
|
||||
|
||||
// Constant string with length.
|
||||
struct StrC
|
||||
@ -6,24 +11,18 @@ struct StrC
|
||||
sw Len;
|
||||
char const* Ptr;
|
||||
|
||||
operator char const* () const
|
||||
{
|
||||
return Ptr;
|
||||
}
|
||||
operator char const* () const { return Ptr; }
|
||||
char const& operator[]( sw index ) const { return Ptr[index]; }
|
||||
};
|
||||
|
||||
#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 +32,8 @@ struct String
|
||||
struct Header
|
||||
{
|
||||
AllocatorInfo Allocator;
|
||||
sw Length;
|
||||
sw Capacity;
|
||||
sw Length;
|
||||
};
|
||||
|
||||
static
|
||||
@ -58,54 +57,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 +97,24 @@ struct String
|
||||
return true;
|
||||
}
|
||||
|
||||
bool make_space_for( char const* str, sw add_len )
|
||||
static
|
||||
bool are_equal( String lhs, StrC rhs )
|
||||
{
|
||||
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 )
|
||||
if ( lhs.length() != (rhs.Len) )
|
||||
return false;
|
||||
|
||||
header = zpl_cast( Header* ) new_ptr;
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
for ( sw idx = 0; idx < lhs.length(); ++idx )
|
||||
if ( lhs[idx] != rhs[idx] )
|
||||
return false;
|
||||
|
||||
Data = rcast( char*, header + 1 );
|
||||
|
||||
return str;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool make_space_for( char const* str, sw add_len );
|
||||
|
||||
bool append( char c )
|
||||
{
|
||||
return append( & c, 1 );
|
||||
}
|
||||
|
||||
bool append( char const* str )
|
||||
@ -213,7 +149,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 +162,11 @@ struct String
|
||||
return header.Capacity - header.Length;
|
||||
}
|
||||
|
||||
char& back()
|
||||
{
|
||||
return Data[ length() - 1 ];
|
||||
}
|
||||
|
||||
sw capacity() const
|
||||
{
|
||||
Header const&
|
||||
@ -239,7 +180,7 @@ struct String
|
||||
get_header().Length = 0;
|
||||
}
|
||||
|
||||
String duplicate( AllocatorInfo allocator )
|
||||
String duplicate( AllocatorInfo allocator ) const
|
||||
{
|
||||
return make_length( allocator, Data, length() );
|
||||
}
|
||||
@ -267,6 +208,68 @@ struct String
|
||||
return header.Length;
|
||||
}
|
||||
|
||||
b32 starts_with( StrC substring ) const
|
||||
{
|
||||
if (substring.Len > length())
|
||||
return false;
|
||||
|
||||
b32 result = str_compare(Data, substring.Ptr, substring.Len ) == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
b32 starts_with( String substring ) const
|
||||
{
|
||||
if (substring.length() > length())
|
||||
return false;
|
||||
|
||||
b32 result = str_compare(Data, substring, substring.length() - 1 ) == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
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 +298,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 +368,7 @@ struct String
|
||||
|
||||
operator StrC() const
|
||||
{
|
||||
return
|
||||
{
|
||||
length(),
|
||||
Data
|
||||
};
|
||||
return { length(), Data };
|
||||
}
|
||||
|
||||
// Used with cached strings
|
||||
@ -358,18 +395,20 @@ struct String
|
||||
return Data[ index ];
|
||||
}
|
||||
|
||||
char* Data = nullptr;
|
||||
char* Data;
|
||||
};
|
||||
|
||||
struct String_POD
|
||||
{
|
||||
char* Data;
|
||||
|
||||
operator String()
|
||||
{
|
||||
return * rcast(String*, this);
|
||||
}
|
||||
};
|
||||
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
|
||||
|
||||
#pragma endregion String
|
||||
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
|
||||
using StringTable = HashTable<String const>;
|
||||
|
||||
// Represents strings cached with the string table.
|
||||
// Should never be modified, if changed string is desired, cache_string( str ) another.
|
||||
using StringCached = String const;
|
||||
|
||||
#pragma endregion Strings
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
|
@ -1,3 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Timing
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user