Compare commits
65
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
050019c8c0 | ||
|
|
cc7fdac795 | ||
|
|
4140e7e237 | ||
|
|
1a60fd54fc | ||
|
|
b754adcd96 | ||
|
|
61d53362e8 | ||
|
|
f044c6d5eb | ||
|
|
a2b5163341 | ||
|
|
286552c3c3 | ||
|
|
9ff5908e40 | ||
|
|
822a3b07dc | ||
|
|
685bba36d5 | ||
|
|
2ad164dc39 | ||
|
|
346e8e3305 | ||
|
|
bfc754e66c | ||
|
|
84f4fc5ae9 | ||
|
|
ad5cb6597b | ||
|
|
1c7dd4ab32 | ||
|
|
1e7fdcec16 | ||
|
|
2ed36506b1 | ||
|
|
790087aa3c | ||
|
|
441a46daaa | ||
|
|
26623075ad | ||
|
|
7ea90ef349 | ||
|
|
6d531fdf97 | ||
|
|
3b81eea688 | ||
|
|
844d431e1c | ||
|
|
727b54c341 | ||
|
|
ef72d27f3e | ||
|
|
75b1d42cca | ||
|
|
878bc4c8ae | ||
|
|
ec8dd1e9cd | ||
|
|
c0ea2ce3ff | ||
|
|
b5652a4dad | ||
|
|
dda70fce36 | ||
|
|
3bce2e9b8a | ||
|
|
f3f8f2fff2 | ||
|
|
c600a3e0dc | ||
|
|
372cda734e | ||
|
|
6481313969 | ||
|
|
5c17983a73 | ||
|
|
b6d95e8d70 | ||
|
|
6f2d81434e | ||
|
|
b8695a33db | ||
|
|
1f958e121c | ||
|
|
e457191f5d | ||
|
|
0d8f30b25c | ||
|
|
d08efcb5ef | ||
|
|
13ebd105c4 | ||
|
|
bdd9c9bcdf | ||
|
|
16bc66c80e | ||
|
|
f8c42a53c6 | ||
|
|
eca538c6af | ||
|
|
ce2be411d7 | ||
|
|
16fc3fa379 | ||
|
|
62b36ec8bb | ||
|
|
b6b246fb38 | ||
|
|
d91d3c6b6f | ||
|
|
3ab2673fd3 | ||
|
|
ca7ff99a79 | ||
|
|
177820cd6e | ||
|
|
d254d3aec4 | ||
|
|
299f1b1ef7 | ||
|
|
9c968967e2 | ||
|
|
04ae75c698 |
No files matched your search
+4
-1
@@ -1,3 +1,4 @@
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
**/build/*
|
||||
@@ -27,7 +28,7 @@ release/**
|
||||
**/Unreal/*.h
|
||||
**/Unreal/*.cpp
|
||||
! **/Unreal/validate.unreal.cpp
|
||||
project/auxillary/vis_ast/dependencies/temp
|
||||
project/auxiliary/vis_ast/dependencies/temp
|
||||
test/gen/original
|
||||
singleheader/gen/scratch.hpp
|
||||
test/gen/scratch.cpp
|
||||
@@ -41,3 +42,5 @@ gen_c_library/gen
|
||||
**/*.vcxproj.user
|
||||
test/c_library/gen
|
||||
test/cpp_library/gen
|
||||
|
||||
!scripts/helpers/refactor.exe
|
||||
Vendored
-99
@@ -1,99 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Bootstrap",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/base/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json",
|
||||
"compilerArgs": [
|
||||
"/EHsc-",
|
||||
"/GR-",
|
||||
"/Zc:preprocessor",
|
||||
"/FC"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Win32 clang",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/base/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "clang++.exe",
|
||||
"intelliSenseMode": "windows-clang-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 msvc c_library",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/gen_c_library/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"cppStandard": "c++17",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
},
|
||||
{
|
||||
"name": "Win32 msvc c_library test",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/test/c_library/**",
|
||||
"${workspaceFolder}/gen_c_library/gen/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"GEN_TIME",
|
||||
"GEN_IMPLEMENTATION",
|
||||
// "GEN_DONT_USE_NAMESPACE"
|
||||
"GEN_INTELLISENSE_DIRECTIVES",
|
||||
"INTELLISENSE_DIRECTIVES"
|
||||
],
|
||||
"cStandard": "c11",
|
||||
"windowsSdkVersion": "10.0.19041.0",
|
||||
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
|
||||
"intelliSenseMode": "msvc-x64",
|
||||
"compileCommands": "${workspaceFolder}/.vscode/tasks.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
Vendored
-35
@@ -1,35 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug base vsdbg",
|
||||
"program": "${workspaceFolder}/base/build/base.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/base/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug singleheader vsdbg",
|
||||
"program": "${workspaceFolder}/singleheader/build/singleheader.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/singleheader/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
},
|
||||
{
|
||||
"type": "cppvsdbg",
|
||||
"request": "launch",
|
||||
"name": "Debug unreal vsdbg",
|
||||
"program": "${workspaceFolder}/unreal_engine/build/unreal.exe",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/unreal_engine/",
|
||||
"visualizerFile": "${workspaceFolder}/scripts/gencpp.natvis"
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
-97
@@ -1,97 +0,0 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"*.rmd": "markdown",
|
||||
"array": "cpp",
|
||||
"compare": "cpp",
|
||||
"type_traits": "cpp",
|
||||
"utility": "cpp",
|
||||
"xtr1common": "cpp",
|
||||
"xutility": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"table.h": "c",
|
||||
"iterator": "cpp",
|
||||
"memory": "cpp",
|
||||
"exception": "cpp",
|
||||
"optional": "cpp",
|
||||
"tuple": "cpp",
|
||||
"xmemory": "cpp",
|
||||
"algorithm": "cpp",
|
||||
"limits": "cpp",
|
||||
"concepts": "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",
|
||||
"atomic": "cpp",
|
||||
"gen.h": "c",
|
||||
"string_ops.hpp": "c",
|
||||
"assert.h": "c",
|
||||
"intrin.h": "c",
|
||||
"bit": "cpp",
|
||||
"cmath": "cpp",
|
||||
"cstddef": "cpp",
|
||||
"cstdint": "cpp",
|
||||
"cstdio": "cpp",
|
||||
"cstdlib": "cpp",
|
||||
"cstring": "cpp",
|
||||
"ctime": "cpp",
|
||||
"cwchar": "cpp",
|
||||
"iosfwd": "cpp",
|
||||
"new": "cpp",
|
||||
"typeinfo": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"xstddef": "cpp",
|
||||
"gen_singleheader.h": "c"
|
||||
},
|
||||
"C_Cpp.intelliSenseEngineFallback": "disabled",
|
||||
"mesonbuild.configureOnOpen": true,
|
||||
"C_Cpp.errorSquiggles": "disabled", // This doesn't work well with how the headers are included.
|
||||
"godot_tools.scene_file_config": "",
|
||||
"C_Cpp.default.compilerPath": "cl.exe",
|
||||
"C_Cpp.exclusionPolicy": "checkFilesAndFolders",
|
||||
"C_Cpp.files.exclude": {
|
||||
"**/.vscode": true,
|
||||
"**/.vs": true,
|
||||
"**/sanity.gen.hpp": true,
|
||||
"test/**":true,
|
||||
},
|
||||
"autoHide.autoHidePanel": false,
|
||||
"autoHide.autoHideSideBar": false,
|
||||
"dimmer.enabled": false,
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.activeBackground": "#fa1b49",
|
||||
"activityBar.background": "#fa1b49",
|
||||
"activityBar.foreground": "#e7e7e7",
|
||||
"activityBar.inactiveForeground": "#e7e7e799",
|
||||
"activityBarBadge.background": "#155e02",
|
||||
"activityBarBadge.foreground": "#e7e7e7",
|
||||
"commandCenter.border": "#e7e7e799",
|
||||
"sash.hoverBorder": "#fa1b49",
|
||||
"statusBar.background": "#dd0531",
|
||||
"statusBar.foreground": "#e7e7e7",
|
||||
"statusBarItem.hoverBackground": "#fa1b49",
|
||||
"statusBarItem.remoteBackground": "#dd0531",
|
||||
"statusBarItem.remoteForeground": "#e7e7e7",
|
||||
"titleBar.activeBackground": "#dd0531",
|
||||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveBackground": "#dd053199",
|
||||
"titleBar.inactiveForeground": "#e7e7e799"
|
||||
},
|
||||
"peacock.color": "#dd0531"
|
||||
}
|
||||
Vendored
-144
@@ -1,144 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Build Bootstrap",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"bootstrap",
|
||||
"msvc"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"relative",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(warning|error)\\s*(\\w+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build C Library",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"c_library",
|
||||
"msvc"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": [
|
||||
"relative",
|
||||
"${workspaceFolder}"
|
||||
],
|
||||
"pattern": {
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(warning|error)\\s*(\\w+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build Singleheader (MSVC)",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"singleheader",
|
||||
"msvc",
|
||||
"debug"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(error|warning|info|note)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Build Unreal (MSVC)",
|
||||
"type": "shell",
|
||||
"command": "C:\\Program Files\\PowerShell\\7\\pwsh.exe",
|
||||
"args": [
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-File",
|
||||
"${workspaceFolder}/scripts/build.ci.ps1",
|
||||
"unreal",
|
||||
"msvc",
|
||||
"debug"
|
||||
],
|
||||
"group": "build",
|
||||
"problemMatcher": {
|
||||
"owner": "cpp",
|
||||
"fileLocation": ["relative", "${workspaceFolder}"],
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(.*)\\((\\d+)\\)\\s*:\\s*(error|warning|info|note)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"severity": 3,
|
||||
"code": 4,
|
||||
"message": 5
|
||||
}
|
||||
]
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "shared",
|
||||
"clear": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,44 +1,26 @@
|
||||
BSD 3-Clause License
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023, Edward R. Gonzalez
|
||||
Copyright (c) 2025 Edward R. Gonzalez
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
Source URL: https://github.com/Ed94/gencpp
|
||||
|
||||
Acknowledgements
|
||||
|
||||
* The dependencies for gencpp source are derived from the zpl library: https://github.com/zpl-c/zpl
|
||||
|
||||
Special thanks to:
|
||||
|
||||
* The Handmade Community.
|
||||
|
||||
* Casey Muratori, Ginger Bill (Bill Hall), Mr. 4th (Allen Webster), Ryan Fluery: Influnced conceptually how to handle staged metaprograming.
|
||||
|
||||
* Jonathan Blow: Jai's metaprogramming influenced the design of this library.
|
||||
|
||||
* My friends for putting up with discord spam on this library.
|
||||
@@ -11,6 +11,14 @@ These build up a code AST to then serialize with a file builder, or can be trave
|
||||
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
|
||||
Its not meant to be a black box metaprogramming utility, it should be easy to integrate into a user's project domain.
|
||||
|
||||
## Langauge Bindings
|
||||
|
||||
* [gencpp-odin](https://github.com/Ed94/gencpp-odin): Bindings for the odin programming language.
|
||||
|
||||
## Utility Libraries
|
||||
|
||||
* [UnrealGencpp](https://github.com/Ed94/UnrealGencpp): Setup as a plugin to integrate into Unreal Engine or Unreal Projects.
|
||||
|
||||
## Documentation
|
||||
|
||||
* [docs - General](./docs/Readme.md): Overview and additional docs
|
||||
@@ -79,18 +87,18 @@ Example using each construction interface:
|
||||
Validation and construction through a functional interface.
|
||||
|
||||
```cpp
|
||||
Code t_uw = def_type( name(usize) );
|
||||
Code t_allocator = def_type( name(allocator) );
|
||||
Code t_string_const = def_type( name(char), def_specifiers( args( ESpecifier::Const, ESpecifier::Ptr ) ));
|
||||
CodeTypename t_uw = def_type( name(usize) );
|
||||
CodeTypename t_allocator = def_type( name(allocator) );
|
||||
CodeTypename t_string_const = def_type( name(char), def_specifiers( args( ESpecifier::Const, ESpecifier::Ptr ) ));
|
||||
|
||||
Code header;
|
||||
CodeStruct header;
|
||||
{
|
||||
Code num = def_variable( t_uw, name(Num) );
|
||||
Code cap = def_variable( t_uw, name(Capacity) );
|
||||
Code mem_alloc = def_variable( t_allocator, name(Allocator) );
|
||||
Code body = def_struct_body( args( num, cap, mem_alloc ) );
|
||||
CodeVar num = def_variable( t_uw, name(Num) );
|
||||
CodeVar cap = def_variable( t_uw, name(Capacity) );
|
||||
CodeVar mem_alloc = def_variable( t_allocator, name(Allocator) );
|
||||
CodeBody body = def_struct_body( args( num, cap, mem_alloc ) );
|
||||
|
||||
header = def_struct( name(ArrayHeader), __, __, body );
|
||||
header = def_struct( name(ArrayHeader), { body });
|
||||
}
|
||||
```
|
||||
|
||||
@@ -99,7 +107,7 @@ Code header;
|
||||
Validation through ast construction.
|
||||
|
||||
```cpp
|
||||
Code header = parse_struct( code(
|
||||
CodeStruct header = parse_struct( code(
|
||||
struct ArrayHeader
|
||||
{
|
||||
usize Num;
|
||||
|
||||
+7
-7
@@ -24,16 +24,16 @@ If using the library's provided build scripts:
|
||||
* `<push/pop>.<name>.inline.<hpp>`: macros that are meant to be injected at specific locations of the library file/s.
|
||||
* `misc.hpp`: Misc functionality used by the library generation metaprograms.
|
||||
* `undef.macros.h`: Undefines all macros from library.
|
||||
* **auxillary**: Non-essential tooling:
|
||||
* **auxiliary**: Non-essential tooling:
|
||||
* `Builder`: Similar conceptually to Jai programming language's *builder*, just opens a file and prepares a string buffer to serialize code into (`builder_print`, `builder_print_fmt`). Then write & close the file when completed (`builder_write`).
|
||||
* **`Scanner`**: Interface to load up `Code` from files two basic funcctions are currently provided.
|
||||
* **`Scanner`**: Interface to load up `Code` from files two basic functions are currently provided.
|
||||
* `scan_file`: Used mainly by the library format generators to directly scan files into untyped `Code` (raw string content, pre-formatted no AST parsed).
|
||||
* `parse_file`: Used to read file and then parsed to populate a `CodeBody` AST.
|
||||
* CSV parsing via one or two columns simplified.
|
||||
* **gen_segemetned**: Dependencies go into gen.dep.{hpp/cpp} and components into gen.{hpp/cpp}
|
||||
* **gen_singleheader**: Everything into a single file: gen.hpp
|
||||
* **gen_unreal_engine**: Like gen_segemented but the library is modified slightly to compile as a thirdparty library within an Unreal Engine plugin or module.
|
||||
* **gen_c_library**: The library is heavily modifed into C11 compliant code. A segemented and single-header set of variants are generated.
|
||||
* **gen_unreal_engine**: Like gen_segmented but the library is modified slightly to compile as a thirdparty library within an Unreal Engine plugin or module.
|
||||
* **gen_c_library**: The library is heavily modifed into C11 compliant code. A segmented and single-header set of variants are generated.
|
||||
|
||||
Code not making up the core library is located in `auxiliary/<auxiliary_name>.<hpp/cpp>`. These are optional extensions or tools for the library.
|
||||
|
||||
@@ -108,7 +108,7 @@ Any large macros used implementing the gen interface or parser are going to be p
|
||||
The vast majority of macros should be single-line subsitutions that either add:
|
||||
|
||||
* Improvements to searching
|
||||
* Inteniality of keyword usage
|
||||
* Intentionality of keyword usage
|
||||
* A feature that only the preprocessor has (ex: function name reflection or stringifying)
|
||||
* Compatibility of statements or expressions bewteen C & C++ that cannot be parsed by gencpp itself.
|
||||
* Masking highly verbose syntax (the latter is getting phased out).
|
||||
@@ -123,7 +123,7 @@ The vast majority of macros should be single-line subsitutions that either add:
|
||||
|
||||
There are ***five*** header files which are automatically generated using [base_codegen.hpp](./helpers/base_codegen.hpp) by [base.cpp](./base.cpp). They are all located in [components/gen](./components/gen/).
|
||||
|
||||
* [ecodetypes.hpp](./components/gen/ecode.hpp): `CodeType` enum definition and related implementaiton. Generation is based off of [ECodeType.csv](./enums/ECodeTypes.csv).
|
||||
* [ecodetypes.hpp](./components/gen/ecode.hpp): `CodeType` enum definition and related implementation. Generation is based off of [ECodeType.csv](./enums/ECodeTypes.csv).
|
||||
* [especifier.hpp](./components/gen/especifier.hpp): `Specifier` enum definition, etc. Generated using [ESpecifier.csv](./enums/ESpecifier.csv).
|
||||
* [eoperator.hpp](./components/gen/eoperator.hpp): `Operator` enum definition, etc. Generated using [EOperator.hpp](./enums/EOperator.csv).
|
||||
* [etoktype.cpp](./components/gen/etoktype.cpp): `TokType` enum defininition, etc. Used by the lexer and parser backend. Uses two csvs:
|
||||
@@ -191,7 +191,7 @@ These require the following to be handled to the equivalent extent as the other
|
||||
4. [ast.cpp](./components/ast.cpp): Need to review
|
||||
* `code_debug_str`
|
||||
* `code_is_equal`
|
||||
* `code_to_strbuilder_ptr`
|
||||
* `code_to_strbuilder_ref`
|
||||
* `code_validate_body`
|
||||
5. [code_serialization.cpp](./components/code_serialization.cpp): Define serialization here.
|
||||
6. [inlines.hpp](./components/inlines.hpp): Any inline definitions for the `struct Code<Name>` are defined here.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# include "builder.hpp"
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "components/header_start.hpp"
|
||||
# include "components/types.hpp"
|
||||
# include "components/gen/ecode.hpp"
|
||||
# include "components/gen/ecodetypes.hpp"
|
||||
# include "components/gen/eoperator.hpp"
|
||||
# include "components/gen/especifier.hpp"
|
||||
# include "components/ast.hpp"
|
||||
@@ -21,11 +21,11 @@ using namespace gen;
|
||||
struct Builder;
|
||||
typedef struct Builder Builder;
|
||||
|
||||
Builder builder_open ( char const* path );
|
||||
void builder_pad_lines ( Builder* builder, s32 num );
|
||||
void builder_print ( Builder* builder, Code code );
|
||||
void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
|
||||
void builder_write ( Builder* builder );
|
||||
GEN_API Builder builder_open ( char const* path );
|
||||
GEN_API void builder_pad_lines ( Builder* builder, s32 num );
|
||||
GEN_API void builder_print ( Builder* builder, Code code );
|
||||
GEN_API void builder_print_fmt_va( Builder* builder, char const* fmt, va_list va );
|
||||
GEN_API void builder_write ( Builder* builder );
|
||||
|
||||
forceinline void builder_print_fmt ( Builder* builder, char const* fmt, ... ) {
|
||||
va_list va;
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "components/header_start.hpp"
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# include "scanner.hpp"
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,7 @@ Code scan_file( char const* path )
|
||||
file_read( & file, str, fsize );
|
||||
strbuilder_get_header(str)->Length = fsize;
|
||||
|
||||
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
|
||||
// Skip 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.
|
||||
{
|
||||
@@ -33,7 +33,7 @@ Code scan_file( char const* path )
|
||||
#define move_fwd() do { ++ scanner; -- left; } while (0)
|
||||
const Str directive_start = txt( "ifdef" );
|
||||
const Str directive_end = txt( "endif" );
|
||||
const Str def_intellisense = txt("GEN_INTELLISENSE_DIRECTIVES" );
|
||||
const Str def_intellisense = txt("INTELLISENSE_DIRECTIVES" );
|
||||
|
||||
bool found_directive = false;
|
||||
char const* scanner = (char const*)str;
|
||||
@@ -1,9 +1,9 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "components/header_start.hpp"
|
||||
# include "components/types.hpp"
|
||||
# include "components/gen/ecode.hpp"
|
||||
# include "components/gen/ecodetypes.hpp"
|
||||
# include "components/gen/eoperator.hpp"
|
||||
# include "components/gen/especifier.hpp"
|
||||
# include "components/ast.hpp"
|
||||
@@ -20,9 +20,9 @@
|
||||
// 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 );
|
||||
GEN_API Code scan_file( char const* path );
|
||||
|
||||
CodeBody parse_file( const char* path );
|
||||
GEN_API CodeBody parse_file( const char* path );
|
||||
|
||||
// The follow is basic support for light csv parsing (use it as an example)
|
||||
// Make something robust if its more serious.
|
||||
@@ -40,7 +40,7 @@ struct CSV_Columns2 {
|
||||
Array(ADT_Node) Col_2;
|
||||
};
|
||||
|
||||
CSV_Column parse_csv_one_column(AllocatorInfo allocator, char const* path);
|
||||
CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path);
|
||||
GEN_API CSV_Column parse_csv_one_column (AllocatorInfo allocator, char const* path);
|
||||
GEN_API CSV_Columns2 parse_csv_two_columns(AllocatorInfo allocator, char const* path);
|
||||
|
||||
#pragma endregion Scanner
|
||||
+1
-1
@@ -30,7 +30,7 @@ int gen_main()
|
||||
gen::init( & ctx);
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "static_data.cpp"
|
||||
#endif
|
||||
@@ -379,11 +379,11 @@ Code code_duplicate(Code self)
|
||||
StrBuilder code_to_strbuilder(Code self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") );
|
||||
code_to_strbuilder_ptr( self, & result );
|
||||
code_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void code_to_strbuilder_ptr( Code self, StrBuilder* result )
|
||||
void code_to_strbuilder_ref( Code self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
local_persist thread_local
|
||||
|
||||
+21
-21
@@ -1,9 +1,6 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "gen/ecode.hpp"
|
||||
#include "gen/eoperator.hpp"
|
||||
#include "gen/especifier.hpp"
|
||||
#include "parser_types.hpp"
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -193,6 +190,7 @@ typedef AST_Stmt_If* CodeStmt_If;
|
||||
typedef AST_Stmt_For* CodeStmt_For;
|
||||
typedef AST_Stmt_Goto* CodeStmt_Goto;
|
||||
typedef AST_Stmt_Label* CodeStmt_Label;
|
||||
typedef AST_Stmt_Lambda* CodeStmt_Lambda;
|
||||
typedef AST_Stmt_Switch* CodeStmt_Switch;
|
||||
typedef AST_Stmt_While* CodeStmt_While;
|
||||
#else
|
||||
@@ -208,6 +206,7 @@ struct CodeStmt_If;
|
||||
struct CodeStmt_For;
|
||||
struct CodeStmt_Goto;
|
||||
struct CodeStmt_Label;
|
||||
struct CodeStmt_Lambda;
|
||||
struct CodeStmt_Switch;
|
||||
struct CodeStmt_While;
|
||||
#endif
|
||||
@@ -239,18 +238,18 @@ template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast(
|
||||
|
||||
#pragma region Code C-Interface
|
||||
|
||||
GEN_API void code_append (Code code, Code other );
|
||||
void code_append (Code code, Code other );
|
||||
GEN_API Str code_debug_str (Code code);
|
||||
GEN_API Code code_duplicate (Code code);
|
||||
GEN_API Code* code_entry (Code code, u32 idx );
|
||||
GEN_API bool code_has_entries (Code code);
|
||||
GEN_API bool code_is_body (Code code);
|
||||
Code* code_entry (Code code, u32 idx );
|
||||
bool code_has_entries (Code code);
|
||||
bool code_is_body (Code code);
|
||||
GEN_API bool code_is_equal (Code code, Code other);
|
||||
GEN_API bool code_is_valid (Code code);
|
||||
GEN_API void code_set_global (Code code);
|
||||
bool code_is_valid (Code code);
|
||||
void code_set_global (Code code);
|
||||
GEN_API StrBuilder code_to_strbuilder (Code self );
|
||||
GEN_API void code_to_strbuilder_ptr(Code self, StrBuilder* result );
|
||||
GEN_API Str code_type_str (Code self );
|
||||
GEN_API void code_to_strbuilder_ref(Code self, StrBuilder* result );
|
||||
Str code_type_str (Code self );
|
||||
GEN_API bool code_validate_body (Code self );
|
||||
|
||||
#pragma endregion Code C-Interface
|
||||
@@ -287,7 +286,7 @@ struct Code
|
||||
forceinline Code* entry(u32 idx) { return code_entry(* this, idx); }
|
||||
forceinline bool has_entries() { return code_has_entries(* this); }
|
||||
forceinline StrBuilder to_strbuilder() { return code_to_strbuilder(* this); }
|
||||
forceinline void to_strbuilder(StrBuilder& result) { return code_to_strbuilder_ptr(* this, & result); }
|
||||
forceinline void to_strbuilder(StrBuilder& result) { return code_to_strbuilder_ref(* this, & result); }
|
||||
forceinline Str type_str() { return code_type_str(* this); }
|
||||
forceinline bool validate_body() { return code_validate_body(*this); }
|
||||
#endif
|
||||
@@ -337,10 +336,10 @@ struct Code
|
||||
|
||||
#pragma region Statics
|
||||
// Used to identify ASTs that should always be duplicated. (Global constant ASTs)
|
||||
extern Code Code_Global;
|
||||
GEN_API extern Code Code_Global;
|
||||
|
||||
// Used to identify invalid generated code.
|
||||
extern Code Code_Invalid;
|
||||
GEN_API extern Code Code_Invalid;
|
||||
#pragma endregion Statics
|
||||
|
||||
struct Code_POD
|
||||
@@ -378,7 +377,7 @@ struct AST
|
||||
{
|
||||
Code InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
Code Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable // TODO(Ed): Parameters can have attributes
|
||||
Code Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
Code Specs; // Class, Destructor, Function, Operator, Struct, Typename, Variable
|
||||
union {
|
||||
Code InitializerList; // Constructor
|
||||
Code ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
@@ -399,12 +398,13 @@ struct AST
|
||||
Code Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
Code SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
|
||||
Code NextVar; // Variable
|
||||
Code SuffixSpecs; // Typename, Function (Thanks Unreal)
|
||||
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
|
||||
};
|
||||
};
|
||||
StrCached Content; // Attributes, Comment, Execution, Include
|
||||
StrCached Content; // Attributes, Comment, Execution, Include
|
||||
TokenSlice ContentToks; // TODO(Ed): Use a token slice for content
|
||||
struct {
|
||||
Specifier ArrSpecs[AST_ArrSpecs_Cap]; // Specifiers
|
||||
Code NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
|
||||
@@ -420,7 +420,7 @@ struct AST
|
||||
Code Next;
|
||||
Code Back;
|
||||
};
|
||||
Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
|
||||
Token* Token; // Reference to starting token, only available if it was derived from parsing. // TODO(Ed): Change this to a token slice.
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
// CodeFlag CodeFlags;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "code_types.hpp"
|
||||
#endif
|
||||
@@ -100,7 +100,7 @@ struct AST_Class
|
||||
{
|
||||
CodeComment InlineCmt; // Only supported by forward declarations
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs; // Support for final
|
||||
CodeTypename ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
@@ -227,7 +227,7 @@ struct AST_Enum
|
||||
Code Parent;
|
||||
CodeType Type;
|
||||
ModuleFlag ModuleFlags;
|
||||
char _PAD_UNUSED_[ sizeof(ModuleFlag) + sizeof(u32) ];
|
||||
char _PAD_UNUSED_[ sizeof(u32) ];
|
||||
};
|
||||
static_assert( sizeof(AST_Enum) == sizeof(AST), "ERROR: AST_Enum is not the same size as AST");
|
||||
|
||||
@@ -575,7 +575,7 @@ struct AST_Fn
|
||||
CodeTypename ReturnType;
|
||||
CodeParams Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
Code SuffixSpecs; // Thanks Unreal
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
@@ -738,8 +738,8 @@ static_assert( sizeof(AST_PreprocessCond) == sizeof(AST), "ERROR: AST_Preprocess
|
||||
struct AST_Specifiers
|
||||
{
|
||||
Specifier ArrSpecs[ AST_ArrSpecs_Cap ];
|
||||
StrCached Name;
|
||||
CodeSpecifiers NextSpecs;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@@ -970,7 +970,7 @@ struct AST_Struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs; // Support for final
|
||||
CodeTypename ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
@@ -1056,7 +1056,7 @@ struct AST_Typename
|
||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
@@ -1077,12 +1077,13 @@ struct AST_Typedef
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
Code UnderlyingType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
StrCached Name;
|
||||
StrCached Name;
|
||||
Code Prev;
|
||||
Code Next;
|
||||
Token* Tok;
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast.cpp"
|
||||
#endif
|
||||
|
||||
inline
|
||||
StrBuilder attributes_to_strbuilder(CodeAttributes attributes) {
|
||||
GEN_ASSERT(attributes);
|
||||
char* raw = ccast(char*, str_duplicate( attributes->Content, _ctx->Allocator_Temp ).Ptr);
|
||||
StrBuilder result = { raw };
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result) {
|
||||
GEN_ASSERT(attributes);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str(result, attributes->Content);
|
||||
}
|
||||
|
||||
StrBuilder body_to_strbuilder(CodeBody body)
|
||||
{
|
||||
GEN_ASSERT(body);
|
||||
@@ -47,55 +32,27 @@ StrBuilder body_to_strbuilder(CodeBody body)
|
||||
return result;
|
||||
}
|
||||
|
||||
void body_to_strbuilder_ref( CodeBody body, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(body != nullptr);
|
||||
GEN_ASSERT(result != nullptr);
|
||||
Code curr = body->Front;
|
||||
s32 left = body->NumEntries;
|
||||
while ( left -- )
|
||||
{
|
||||
code_to_strbuilder_ptr(curr, result);
|
||||
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
|
||||
++curr;
|
||||
}
|
||||
}
|
||||
|
||||
void body_to_strbuilder_export( CodeBody body, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(body != nullptr);
|
||||
GEN_ASSERT(result != nullptr);
|
||||
strbuilder_append_fmt( result, "export\n{\n" );
|
||||
|
||||
Code curr = cast(Code, body);
|
||||
Code curr = body->Front;
|
||||
s32 left = body->NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
code_to_strbuilder_ptr(curr, result);
|
||||
code_to_strbuilder_ref(curr, result);
|
||||
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
|
||||
++curr;
|
||||
curr = curr->Next;
|
||||
}
|
||||
|
||||
strbuilder_append_fmt( result, "};\n" );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder comment_to_strbuilder(CodeComment comment) {
|
||||
GEN_ASSERT(comment);
|
||||
char* raw = ccast(char*, str_duplicate( comment->Content, _ctx->Allocator_Temp ).Ptr);
|
||||
StrBuilder result = { raw };
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result) {
|
||||
GEN_ASSERT(comment);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str(result, comment->Content);
|
||||
}
|
||||
|
||||
StrBuilder constructor_to_strbuilder(CodeConstructor self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
switch (self->Type)
|
||||
{
|
||||
@@ -111,6 +68,8 @@ StrBuilder constructor_to_strbuilder(CodeConstructor self)
|
||||
|
||||
void constructor_to_strbuilder_def(CodeConstructor self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
Code ClassStructParent = self->Parent->Parent;
|
||||
if (ClassStructParent) {
|
||||
strbuilder_append_str( result, ClassStructParent->Name );
|
||||
@@ -135,6 +94,8 @@ void constructor_to_strbuilder_def(CodeConstructor self, StrBuilder* result )
|
||||
|
||||
void constructor_to_strbuilder_fwd(CodeConstructor self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
Code ClassStructParent = self->Parent->Parent;
|
||||
if (ClassStructParent) {
|
||||
strbuilder_append_str( result, ClassStructParent->Name );
|
||||
@@ -159,6 +120,7 @@ void constructor_to_strbuilder_fwd(CodeConstructor self, StrBuilder* result )
|
||||
|
||||
StrBuilder class_to_strbuilder( CodeClass self )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -175,6 +137,7 @@ StrBuilder class_to_strbuilder( CodeClass self )
|
||||
void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
@@ -186,10 +149,16 @@ void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
}
|
||||
|
||||
if ( self->Name.Len )
|
||||
strbuilder_append_str( result, self->Name );
|
||||
|
||||
if (self->Specs && specifiers_has(self->Specs, Spec_Final))
|
||||
strbuilder_append_str(result, txt(" final"));
|
||||
|
||||
if ( self->ParentType )
|
||||
{
|
||||
Str access_level = access_spec_to_str( self->ParentAccess );
|
||||
strbuilder_append_fmt( result, "%S : %S %SB", self->Name, access_level, typename_to_strbuilder(self->ParentType) );
|
||||
strbuilder_append_fmt( result, " : %S %SB", access_level, typename_to_strbuilder(self->ParentType) );
|
||||
|
||||
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
||||
if ( interface )
|
||||
@@ -201,10 +170,6 @@ void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
|
||||
interface = interface->Next ? cast(CodeTypename, interface->Next) : NullCode;
|
||||
}
|
||||
}
|
||||
else if ( self->Name.Len )
|
||||
{
|
||||
strbuilder_append_str( result, self->Name );
|
||||
}
|
||||
|
||||
if ( self->InlineCmt )
|
||||
{
|
||||
@@ -220,6 +185,7 @@ void class_to_strbuilder_def( CodeClass self, StrBuilder* result )
|
||||
void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
@@ -239,13 +205,6 @@ void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result )
|
||||
}
|
||||
}
|
||||
|
||||
StrBuilder define_to_strbuilder(CodeDefine define)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
define_to_strbuilder_ref(define, & result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void define_to_strbuilder_ref(CodeDefine define, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(define);
|
||||
@@ -260,14 +219,6 @@ void define_to_strbuilder_ref(CodeDefine define, StrBuilder* result )
|
||||
}
|
||||
}
|
||||
|
||||
StrBuilder define_params_to_strbuilder(CodeDefineParams params)
|
||||
{
|
||||
GEN_ASSERT(params);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
define_params_to_strbuilder_ref( params, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void define_params_to_strbuilder_ref(CodeDefineParams self, StrBuilder* result)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
@@ -287,6 +238,7 @@ void define_params_to_strbuilder_ref(CodeDefineParams self, StrBuilder* result)
|
||||
|
||||
StrBuilder destructor_to_strbuilder(CodeDestructor self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -302,6 +254,8 @@ StrBuilder destructor_to_strbuilder(CodeDestructor self)
|
||||
|
||||
void destructor_to_strbuilder_def(CodeDestructor self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->Name.Len )
|
||||
{
|
||||
strbuilder_append_fmt( result, "%S()", self->Name );
|
||||
@@ -309,18 +263,20 @@ void destructor_to_strbuilder_def(CodeDestructor self, StrBuilder* result )
|
||||
else if ( self->Specs )
|
||||
{
|
||||
if ( specifiers_has(self->Specs, Spec_Virtual ) )
|
||||
strbuilder_append_fmt( result, "virtual ~%S()", self->Parent->Name );
|
||||
strbuilder_append_fmt( result, "virtual ~%S()", self->Parent->Parent->Name );
|
||||
else
|
||||
strbuilder_append_fmt( result, "~%S()", self->Parent->Name );
|
||||
strbuilder_append_fmt( result, "~%S()", self->Parent->Parent->Name );
|
||||
}
|
||||
else
|
||||
strbuilder_append_fmt( result, "~%S()", self->Parent->Name );
|
||||
strbuilder_append_fmt( result, "~%S()", self->Parent->Parent->Name );
|
||||
|
||||
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", code_to_strbuilder(self->Body) );
|
||||
}
|
||||
|
||||
void destructor_to_strbuilder_fwd(CodeDestructor self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->Specs )
|
||||
{
|
||||
if ( specifiers_has(self->Specs, Spec_Virtual ) )
|
||||
@@ -344,6 +300,7 @@ void destructor_to_strbuilder_fwd(CodeDestructor self, StrBuilder* result )
|
||||
|
||||
StrBuilder enum_to_strbuilder(CodeEnum self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -365,6 +322,8 @@ StrBuilder enum_to_strbuilder(CodeEnum self)
|
||||
|
||||
void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -398,6 +357,8 @@ void enum_to_strbuilder_def(CodeEnum self, StrBuilder* result )
|
||||
|
||||
void enum_to_strbuilder_fwd(CodeEnum self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -425,6 +386,8 @@ void enum_to_strbuilder_fwd(CodeEnum self, StrBuilder* result )
|
||||
|
||||
void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -457,6 +420,8 @@ void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result )
|
||||
|
||||
void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -476,56 +441,9 @@ void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result )
|
||||
}
|
||||
}
|
||||
|
||||
StrBuilder exec_to_strbuilder(CodeExec exec)
|
||||
{
|
||||
GEN_ASSERT(exec);
|
||||
char* raw = ccast(char*, str_duplicate( exec->Content, _ctx->Allocator_Temp ).Ptr);
|
||||
StrBuilder result = { raw };
|
||||
return result;
|
||||
}
|
||||
|
||||
void extern_to_strbuilder(CodeExtern self, StrBuilder* result )
|
||||
{
|
||||
if ( self->Body )
|
||||
strbuilder_append_fmt( result, "extern \"%S\"\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
|
||||
else
|
||||
strbuilder_append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
|
||||
}
|
||||
|
||||
StrBuilder include_to_strbuilder(CodeInclude include)
|
||||
{
|
||||
return strbuilder_fmt_buf( _ctx->Allocator_Temp, "#include %S\n", include->Content );
|
||||
}
|
||||
|
||||
void include_to_strbuilder_ref( CodeInclude include, StrBuilder* result )
|
||||
{
|
||||
strbuilder_append_fmt( result, "#include %S\n", include->Content );
|
||||
}
|
||||
|
||||
StrBuilder friend_to_strbuilder(CodeFriend self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
|
||||
friend_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result )
|
||||
{
|
||||
strbuilder_append_fmt( result, "friend %SB", code_to_strbuilder(self->Declaration) );
|
||||
|
||||
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* result)[ strbuilder_length(* result) - 1 ] != ';' )
|
||||
{
|
||||
strbuilder_append_str( result, txt(";") );
|
||||
}
|
||||
|
||||
if ( self->InlineCmt )
|
||||
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content );
|
||||
else
|
||||
strbuilder_append_str( result, txt("\n"));
|
||||
}
|
||||
|
||||
StrBuilder fn_to_strbuilder(CodeFn self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -541,6 +459,8 @@ StrBuilder fn_to_strbuilder(CodeFn self)
|
||||
|
||||
void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export") );
|
||||
|
||||
@@ -589,11 +509,17 @@ void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
|
||||
}
|
||||
}
|
||||
|
||||
// This is bodged in for now SOLEY for Unreal's PURE_VIRTUAL functional macro
|
||||
if ( self->SuffixSpecs )
|
||||
strbuilder_append_fmt( result, " %SB", code_to_strbuilder(self->SuffixSpecs) );
|
||||
|
||||
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", body_to_strbuilder(self->Body) );
|
||||
}
|
||||
|
||||
void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -642,11 +568,18 @@ void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr );
|
||||
}
|
||||
}
|
||||
|
||||
if ( specifiers_has(self->Specs, Spec_Pure ) )
|
||||
strbuilder_append_str( result, txt(" = 0") );
|
||||
else if ( specifiers_has(self->Specs, Spec_Delete ) )
|
||||
strbuilder_append_str( result, txt(" = delete") );
|
||||
}
|
||||
|
||||
if ( self->Specs && specifiers_has(self->Specs, Spec_Pure ) >= 0 )
|
||||
strbuilder_append_str( result, txt(" = 0;") );
|
||||
else if (self->Body)
|
||||
// This is bodged in for now SOLEY for Unreal's PURE_VIRTUAL functional macro (I kept it open ended for other jank)
|
||||
if ( self->SuffixSpecs )
|
||||
strbuilder_append_fmt( result, " %SB", code_to_strbuilder(self->SuffixSpecs) );
|
||||
|
||||
if (self->Body)
|
||||
strbuilder_append_fmt( result, " = %SB;", body_to_strbuilder(self->Body) );
|
||||
|
||||
if ( self->InlineCmt )
|
||||
@@ -655,15 +588,10 @@ void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
|
||||
strbuilder_append_str( result, txt(";\n") );
|
||||
}
|
||||
|
||||
StrBuilder module_to_strbuilder(CodeModule self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
|
||||
module_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void module_to_strbuilder_ref(CodeModule self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if (((scast(u32, ModuleFlag_Export) & scast(u32, self->ModuleFlags)) == scast(u32, ModuleFlag_Export)))
|
||||
strbuilder_append_str( result, txt("export "));
|
||||
|
||||
@@ -673,23 +601,9 @@ void module_to_strbuilder_ref(CodeModule self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, "%S;\n", self->Name );
|
||||
}
|
||||
|
||||
StrBuilder namespace_to_strbuilder(CodeNS self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
namespace_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result )
|
||||
{
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
strbuilder_append_fmt( result, "namespace %S\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
|
||||
}
|
||||
|
||||
StrBuilder code_op_to_strbuilder(CodeOperator self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -707,15 +621,14 @@ StrBuilder code_op_to_strbuilder(CodeOperator self)
|
||||
|
||||
void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
if ( self->Attributes )
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
|
||||
if ( self->Attributes )
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
|
||||
if ( self->Specs )
|
||||
{
|
||||
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
||||
@@ -728,8 +641,7 @@ void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result )
|
||||
}
|
||||
}
|
||||
|
||||
if ( self->Attributes || self->Specs )
|
||||
{
|
||||
if ( self->Attributes || self->Specs ) {
|
||||
strbuilder_append_str( result, txt("\n") );
|
||||
}
|
||||
|
||||
@@ -761,6 +673,8 @@ void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result )
|
||||
|
||||
void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -812,6 +726,7 @@ void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result )
|
||||
|
||||
StrBuilder opcast_to_strbuilder(CodeOpCast self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -827,6 +742,8 @@ StrBuilder opcast_to_strbuilder(CodeOpCast self)
|
||||
|
||||
void opcast_to_strbuilder_def(CodeOpCast self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->Specs )
|
||||
{
|
||||
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
||||
@@ -864,6 +781,8 @@ void opcast_to_strbuilder_def(CodeOpCast self, StrBuilder* result )
|
||||
|
||||
void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->Specs )
|
||||
{
|
||||
for ( Specifier* spec = begin_CodeSpecifiers(self->Specs); spec != end_CodeSpecifiers(self->Specs); spec = next_CodeSpecifiers(self->Specs, spec) )
|
||||
@@ -899,14 +818,6 @@ void opcast_to_strbuilder_fwd(CodeOpCast self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, "operator %SB();\n", typename_to_strbuilder(self->ValueType) );
|
||||
}
|
||||
|
||||
StrBuilder params_to_strbuilder(CodeParams self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
params_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void params_to_strbuilder_ref( CodeParams self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
@@ -974,62 +885,6 @@ StrBuilder preprocess_to_strbuilder(CodePreprocessCond self)
|
||||
return result;
|
||||
}
|
||||
|
||||
void preprocess_to_strbuilder_if(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
strbuilder_append_fmt( result, "#if %S", cond->Content );
|
||||
}
|
||||
|
||||
void preprocess_to_strbuilder_ifdef(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
strbuilder_append_fmt( result, "#ifdef %S\n", cond->Content );
|
||||
}
|
||||
|
||||
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
strbuilder_append_fmt( result, "#ifndef %S", cond->Content );
|
||||
}
|
||||
|
||||
void preprocess_to_strbuilder_elif(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
strbuilder_append_fmt( result, "#elif %S\n", cond->Content );
|
||||
}
|
||||
|
||||
void preprocess_to_strbuilder_else(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
strbuilder_append_str( result, txt("#else\n") );
|
||||
}
|
||||
|
||||
void preprocess_to_strbuilder_endif(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
strbuilder_append_str( result, txt("#endif\n") );
|
||||
}
|
||||
|
||||
StrBuilder pragma_to_strbuilder(CodePragma self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
|
||||
pragma_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result )
|
||||
{
|
||||
strbuilder_append_fmt( result, "#pragma %S\n", self->Content );
|
||||
}
|
||||
|
||||
StrBuilder specifiers_to_strbuilder(CodeSpecifiers self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
|
||||
specifiers_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void specifiers_to_strbuilder_ref( CodeSpecifiers self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
@@ -1087,11 +942,17 @@ void struct_to_strbuilder_def( CodeStruct self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
}
|
||||
|
||||
if ( self->Name.Len )
|
||||
strbuilder_append_str( result, self->Name );
|
||||
|
||||
if (self->Specs && specifiers_has(self->Specs, Spec_Final))
|
||||
strbuilder_append_str( result, txt(" final"));
|
||||
|
||||
if ( self->ParentType )
|
||||
{
|
||||
Str access_level = access_spec_to_str( self->ParentAccess );
|
||||
|
||||
strbuilder_append_fmt( result, "%S : %S %SB", self->Name, access_level, typename_to_strbuilder(self->ParentType) );
|
||||
strbuilder_append_fmt( result, " : %S %SB", access_level, typename_to_strbuilder(self->ParentType) );
|
||||
|
||||
CodeTypename interface = cast(CodeTypename, self->ParentType->Next);
|
||||
if ( interface )
|
||||
@@ -1103,10 +964,6 @@ void struct_to_strbuilder_def( CodeStruct self, StrBuilder* result )
|
||||
interface = interface->Next ? cast( CodeTypename, interface->Next) : NullCode;
|
||||
}
|
||||
}
|
||||
else if ( self->Name.Len )
|
||||
{
|
||||
strbuilder_append_str( result, self->Name );
|
||||
}
|
||||
|
||||
if ( self->InlineCmt )
|
||||
{
|
||||
@@ -1140,14 +997,6 @@ void struct_to_strbuilder_fwd( CodeStruct self, StrBuilder* result )
|
||||
}
|
||||
}
|
||||
|
||||
StrBuilder template_to_strbuilder(CodeTemplate self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 1024 );
|
||||
template_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
@@ -1161,18 +1010,16 @@ void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result )
|
||||
strbuilder_append_fmt( result, "template<>\n%SB", code_to_strbuilder(self->Declaration) );
|
||||
}
|
||||
|
||||
StrBuilder typedef_to_strbuilder(CodeTypedef self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
typedef_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
if ( self->Attributes )
|
||||
strbuilder_append_fmt( result, "%SB ", attributes_to_strbuilder(self->Attributes) );
|
||||
|
||||
strbuilder_append_str( result, txt("typedef "));
|
||||
|
||||
// Determines if the typedef is a function typename
|
||||
@@ -1203,15 +1050,10 @@ void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result )
|
||||
strbuilder_append_str( result, txt("\n"));
|
||||
}
|
||||
|
||||
StrBuilder typename_to_strbuilder(CodeTypename self)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") );
|
||||
typename_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
#if defined(GEN_USE_NEW_TYPENAME_PARSING)
|
||||
if ( self->ReturnType && self->Params )
|
||||
{
|
||||
@@ -1268,6 +1110,7 @@ void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result )
|
||||
|
||||
StrBuilder union_to_strbuilder(CodeUnion self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
@@ -1283,6 +1126,8 @@ StrBuilder union_to_strbuilder(CodeUnion self)
|
||||
|
||||
void union_to_strbuilder_def(CodeUnion self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
@@ -1331,22 +1176,6 @@ void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result )
|
||||
strbuilder_append_str( result, txt(";\n"));
|
||||
}
|
||||
|
||||
StrBuilder using_to_strbuilder(CodeUsing self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
case CT_Using:
|
||||
using_to_strbuilder_ref( self, & result );
|
||||
break;
|
||||
case CT_Using_Namespace:
|
||||
using_to_strbuilder_ns( self, & result );
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
@@ -1384,26 +1213,6 @@ void using_to_strbuilder_ref(CodeUsing self, StrBuilder* result )
|
||||
strbuilder_append_str( result, txt("\n"));
|
||||
}
|
||||
|
||||
inline
|
||||
void using_to_strbuilder_ns(CodeUsing self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->InlineCmt )
|
||||
strbuilder_append_fmt( result, "using namespace $SC; %S", self->Name, self->InlineCmt->Content );
|
||||
else
|
||||
strbuilder_append_fmt( result, "using namespace %S;\n", self->Name );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder var_to_strbuilder(CodeVar self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
|
||||
var_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
neverinline
|
||||
void var_to_strbuilder_ref(CodeVar self, StrBuilder* result )
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast.hpp"
|
||||
#endif
|
||||
@@ -20,58 +20,59 @@
|
||||
GEN_API void body_append ( CodeBody body, Code other );
|
||||
GEN_API void body_append_body ( CodeBody body, CodeBody other );
|
||||
GEN_API StrBuilder body_to_strbuilder ( CodeBody body );
|
||||
GEN_API void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result );
|
||||
void body_to_strbuilder_ref ( CodeBody body, StrBuilder* result );
|
||||
GEN_API void body_to_strbuilder_export( CodeBody body, StrBuilder* result );
|
||||
|
||||
GEN_API Code begin_CodeBody( CodeBody body);
|
||||
GEN_API Code end_CodeBody ( CodeBody body );
|
||||
GEN_API Code next_CodeBody ( CodeBody body, Code entry_iter );
|
||||
Code begin_CodeBody( CodeBody body);
|
||||
Code end_CodeBody ( CodeBody body );
|
||||
Code next_CodeBody ( CodeBody body, Code entry_iter );
|
||||
|
||||
GEN_API void class_add_interface ( CodeClass self, CodeTypename interface );
|
||||
void class_add_interface ( CodeClass self, CodeTypename interface );
|
||||
GEN_API StrBuilder class_to_strbuilder ( CodeClass self );
|
||||
GEN_API void class_to_strbuilder_def( CodeClass self, StrBuilder* result );
|
||||
GEN_API void class_to_strbuilder_fwd( CodeClass self, StrBuilder* result );
|
||||
|
||||
GEN_API void define_params_append (CodeDefineParams appendee, CodeDefineParams other );
|
||||
GEN_API CodeDefineParams define_params_get (CodeDefineParams params, s32 idx);
|
||||
GEN_API bool define_params_has_entries (CodeDefineParams params );
|
||||
GEN_API StrBuilder define_params_to_strbuilder (CodeDefineParams params );
|
||||
void define_params_append (CodeDefineParams appendee, CodeDefineParams other );
|
||||
CodeDefineParams define_params_get (CodeDefineParams params, s32 idx);
|
||||
bool define_params_has_entries (CodeDefineParams params );
|
||||
StrBuilder define_params_to_strbuilder (CodeDefineParams params );
|
||||
GEN_API void define_params_to_strbuilder_ref(CodeDefineParams params, StrBuilder* result );
|
||||
|
||||
GEN_API CodeDefineParams begin_CodeDefineParams(CodeDefineParams params);
|
||||
GEN_API CodeDefineParams end_CodeDefineParams (CodeDefineParams params);
|
||||
GEN_API CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter);
|
||||
CodeDefineParams begin_CodeDefineParams(CodeDefineParams params);
|
||||
CodeDefineParams end_CodeDefineParams (CodeDefineParams params);
|
||||
CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter);
|
||||
|
||||
GEN_API void params_append (CodeParams appendee, CodeParams other );
|
||||
GEN_API CodeParams params_get (CodeParams params, s32 idx);
|
||||
GEN_API bool params_has_entries (CodeParams params );
|
||||
GEN_API StrBuilder params_to_strbuilder (CodeParams params );
|
||||
void params_append (CodeParams appendee, CodeParams other );
|
||||
CodeParams params_get (CodeParams params, s32 idx);
|
||||
bool params_has_entries (CodeParams params );
|
||||
StrBuilder params_to_strbuilder (CodeParams params );
|
||||
GEN_API void params_to_strbuilder_ref(CodeParams params, StrBuilder* result );
|
||||
|
||||
GEN_API CodeParams begin_CodeParams(CodeParams params);
|
||||
GEN_API CodeParams end_CodeParams (CodeParams params);
|
||||
GEN_API CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
|
||||
CodeParams begin_CodeParams(CodeParams params);
|
||||
CodeParams end_CodeParams (CodeParams params);
|
||||
CodeParams next_CodeParams (CodeParams params, CodeParams entry_iter);
|
||||
|
||||
GEN_API bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
||||
GEN_API s32 specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
||||
GEN_API s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove );
|
||||
GEN_API StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers);
|
||||
bool specifiers_append (CodeSpecifiers specifiers, Specifier spec);
|
||||
bool specifiers_has (CodeSpecifiers specifiers, Specifier spec);
|
||||
s32 specifiers_index_of (CodeSpecifiers specifiers, Specifier spec);
|
||||
s32 specifiers_remove (CodeSpecifiers specifiers, Specifier to_remove );
|
||||
StrBuilder specifiers_to_strbuilder (CodeSpecifiers specifiers);
|
||||
GEN_API void specifiers_to_strbuilder_ref(CodeSpecifiers specifiers, StrBuilder* result);
|
||||
|
||||
GEN_API Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers);
|
||||
GEN_API Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
|
||||
GEN_API Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
|
||||
Specifier* begin_CodeSpecifiers(CodeSpecifiers specifiers);
|
||||
Specifier* end_CodeSpecifiers (CodeSpecifiers specifiers);
|
||||
Specifier* next_CodeSpecifiers (CodeSpecifiers specifiers, Specifier* spec_iter);
|
||||
|
||||
GEN_API void struct_add_interface (CodeStruct self, CodeTypename interface);
|
||||
void struct_add_interface (CodeStruct self, CodeTypename interface);
|
||||
GEN_API StrBuilder struct_to_strbuilder (CodeStruct self);
|
||||
GEN_API void struct_to_strbuilder_fwd(CodeStruct self, StrBuilder* result);
|
||||
GEN_API void struct_to_strbuilder_def(CodeStruct self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder attributes_to_strbuilder (CodeAttributes attributes);
|
||||
GEN_API void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result);
|
||||
StrBuilder attributes_to_strbuilder (CodeAttributes attributes);
|
||||
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder comment_to_strbuilder (CodeComment comment );
|
||||
GEN_API void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result );
|
||||
StrBuilder comment_to_strbuilder (CodeComment comment );
|
||||
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result );
|
||||
|
||||
GEN_API StrBuilder constructor_to_strbuilder (CodeConstructor constructor);
|
||||
GEN_API void constructor_to_strbuilder_def(CodeConstructor constructor, StrBuilder* result );
|
||||
@@ -90,66 +91,68 @@ GEN_API void enum_to_strbuilder_fwd (CodeEnum self, StrBuilder* resul
|
||||
GEN_API void enum_to_strbuilder_class_def(CodeEnum self, StrBuilder* result );
|
||||
GEN_API void enum_to_strbuilder_class_fwd(CodeEnum self, StrBuilder* result );
|
||||
|
||||
GEN_API StrBuilder exec_to_strbuilder (CodeExec exec);
|
||||
GEN_API void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result);
|
||||
StrBuilder exec_to_strbuilder (CodeExec exec);
|
||||
void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result);
|
||||
|
||||
GEN_API void extern_to_strbuilder(CodeExtern self, StrBuilder* result);
|
||||
void extern_to_strbuilder(CodeExtern self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder include_to_strbuilder (CodeInclude self);
|
||||
GEN_API void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result);
|
||||
StrBuilder include_to_strbuilder (CodeInclude self);
|
||||
void include_to_strbuilder_ref(CodeInclude self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder friend_to_strbuilder (CodeFriend self);
|
||||
GEN_API void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result);
|
||||
StrBuilder friend_to_strbuilder (CodeFriend self);
|
||||
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder fn_to_strbuilder (CodeFn self);
|
||||
GEN_API void fn_to_strbuilder_def(CodeFn self, StrBuilder* result);
|
||||
GEN_API void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder module_to_strbuilder (CodeModule self);
|
||||
StrBuilder module_to_strbuilder (CodeModule self);
|
||||
GEN_API void module_to_strbuilder_ref(CodeModule self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder namespace_to_strbuilder (CodeNS self);
|
||||
GEN_API void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result);
|
||||
StrBuilder namespace_to_strbuilder (CodeNS self);
|
||||
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder code_op_to_strbuilder (CodeOperator self);
|
||||
GEN_API void code_op_to_strbuilder_fwd(CodeOperator self, StrBuilder* result );
|
||||
GEN_API void code_op_to_strbuilder_def(CodeOperator self, StrBuilder* result );
|
||||
|
||||
GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast );
|
||||
GEN_API StrBuilder opcast_to_strbuilder (CodeOpCast op_cast );
|
||||
GEN_API void opcast_to_strbuilder_def(CodeOpCast op_cast, StrBuilder* result );
|
||||
GEN_API void opcast_to_strbuilder_fwd(CodeOpCast op_cast, StrBuilder* result );
|
||||
|
||||
GEN_API StrBuilder pragma_to_strbuilder (CodePragma self);
|
||||
GEN_API void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result);
|
||||
StrBuilder pragma_to_strbuilder (CodePragma self);
|
||||
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder preprocess_to_strbuilder (CodePreprocessCond cond);
|
||||
GEN_API void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result );
|
||||
GEN_API void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_if (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_ifdef (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_elif (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_else (CodePreprocessCond cond, StrBuilder* result );
|
||||
void preprocess_to_strbuilder_endif (CodePreprocessCond cond, StrBuilder* result );
|
||||
|
||||
GEN_API StrBuilder template_to_strbuilder (CodeTemplate self);
|
||||
StrBuilder template_to_strbuilder (CodeTemplate self);
|
||||
GEN_API void template_to_strbuilder_ref(CodeTemplate self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder typename_to_strbuilder (CodeTypename self);
|
||||
GEN_API void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder typedef_to_strbuilder (CodeTypedef self);
|
||||
StrBuilder typedef_to_strbuilder (CodeTypedef self);
|
||||
GEN_API void typedef_to_strbuilder_ref(CodeTypedef self, StrBuilder* result );
|
||||
|
||||
StrBuilder typename_to_strbuilder (CodeTypename self);
|
||||
GEN_API void typename_to_strbuilder_ref(CodeTypename self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder union_to_strbuilder (CodeUnion self);
|
||||
GEN_API void union_to_strbuilder_def(CodeUnion self, StrBuilder* result);
|
||||
GEN_API void union_to_strbuilder_fwd(CodeUnion self, StrBuilder* result);
|
||||
|
||||
GEN_API StrBuilder using_to_strbuilder (CodeUsing op_cast );
|
||||
StrBuilder using_to_strbuilder (CodeUsing op_cast );
|
||||
GEN_API void using_to_strbuilder_ref(CodeUsing op_cast, StrBuilder* result );
|
||||
GEN_API void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result );
|
||||
void using_to_strbuilder_ns (CodeUsing op_cast, StrBuilder* result );
|
||||
|
||||
GEN_API StrBuilder var_to_strbuilder (CodeVar self);
|
||||
StrBuilder var_to_strbuilder (CodeVar self);
|
||||
GEN_API void var_to_strbuilder_ref(CodeVar self, StrBuilder* result);
|
||||
|
||||
// TODO(Ed): Move C-Interface inlines here...
|
||||
|
||||
#pragma endregion Code Type C-Interface
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
@@ -249,7 +252,8 @@ struct CodeSpecifiers
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
Using_Code( CodeSpecifiers );
|
||||
bool append( Specifier spec ) { return specifiers_append(* this, spec); }
|
||||
s32 has( Specifier spec ) { return specifiers_has(* this, spec); }
|
||||
bool has( Specifier spec ) { return specifiers_has(* this, spec); }
|
||||
s32 index_of( Specifier spec ) { return specifiers_index_of(* this, spec); }
|
||||
s32 remove( Specifier to_remove ) { return specifiers_remove(* this, to_remove); }
|
||||
StrBuilder to_strbuilder() { return specifiers_to_strbuilder(* this ); }
|
||||
void to_strbuilder( StrBuilder& result ) { return specifiers_to_strbuilder_ref(* this, & result); }
|
||||
@@ -1070,11 +1074,12 @@ forceinline bool has_entries (CodeParams params ) {
|
||||
forceinline StrBuilder to_strbuilder(CodeParams params ) { return params_to_strbuilder(params); }
|
||||
forceinline void to_strbuilder(CodeParams params, StrBuilder& result ) { return params_to_strbuilder_ref(params, & result); }
|
||||
|
||||
forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); }
|
||||
forceinline s32 has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); }
|
||||
forceinline s32 remove (CodeSpecifiers specifiers, Specifier to_remove ) { return specifiers_remove(specifiers, to_remove); }
|
||||
forceinline StrBuilder to_strbuilder(CodeSpecifiers specifiers) { return specifiers_to_strbuilder(specifiers); }
|
||||
forceinline void to_strbuilder(CodeSpecifiers specifiers, StrBuilder& result) { return specifiers_to_strbuilder_ref(specifiers, & result); }
|
||||
forceinline bool append (CodeSpecifiers specifiers, Specifier spec) { return specifiers_append(specifiers, spec); }
|
||||
forceinline bool has (CodeSpecifiers specifiers, Specifier spec) { return specifiers_has(specifiers, spec); }
|
||||
forceinline s32 index_of (CodeSpecifiers specifiers, Specifier spec) { return specifiers_index_of(specifiers, spec); }
|
||||
forceinline s32 remove (CodeSpecifiers specifiers, Specifier to_remove ) { return specifiers_remove(specifiers, to_remove); }
|
||||
forceinline StrBuilder to_strbuilder (CodeSpecifiers specifiers) { return specifiers_to_strbuilder(specifiers); }
|
||||
forceinline void to_strbuilder (CodeSpecifiers specifiers, StrBuilder& result) { return specifiers_to_strbuilder_ref(specifiers, & result); }
|
||||
|
||||
forceinline void add_interface (CodeStruct self, CodeTypename interface) { return struct_add_interface(self, interface); }
|
||||
forceinline StrBuilder to_strbuilder (CodeStruct self) { return struct_to_strbuilder(self); }
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "interface.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Constants
|
||||
// Predefined typename codes. Are set to readonly and are setup during gen::init()
|
||||
|
||||
GEN_API extern Token NullToken;
|
||||
|
||||
GEN_API extern Macro enum_underlying_macro;
|
||||
|
||||
GEN_API extern Code access_public;
|
||||
GEN_API extern Code access_protected;
|
||||
GEN_API extern Code access_private;
|
||||
|
||||
GEN_API extern CodeAttributes attrib_api_export;
|
||||
GEN_API extern CodeAttributes attrib_api_import;
|
||||
|
||||
GEN_API extern Code module_global_fragment;
|
||||
GEN_API extern Code module_private_fragment;
|
||||
|
||||
GEN_API extern Code fmt_newline;
|
||||
|
||||
GEN_API extern CodePragma pragma_once;
|
||||
|
||||
GEN_API extern CodeParams param_varadic;
|
||||
|
||||
GEN_API extern CodePreprocessCond preprocess_else;
|
||||
GEN_API extern CodePreprocessCond preprocess_endif;
|
||||
|
||||
GEN_API extern CodeSpecifiers spec_const;
|
||||
GEN_API extern CodeSpecifiers spec_consteval;
|
||||
GEN_API extern CodeSpecifiers spec_constexpr;
|
||||
GEN_API extern CodeSpecifiers spec_constinit;
|
||||
GEN_API extern CodeSpecifiers spec_extern_linkage;
|
||||
GEN_API extern CodeSpecifiers spec_final;
|
||||
GEN_API extern CodeSpecifiers spec_forceinline;
|
||||
GEN_API extern CodeSpecifiers spec_global;
|
||||
GEN_API extern CodeSpecifiers spec_inline;
|
||||
GEN_API extern CodeSpecifiers spec_internal_linkage;
|
||||
GEN_API extern CodeSpecifiers spec_local_persist;
|
||||
GEN_API extern CodeSpecifiers spec_mutable;
|
||||
GEN_API extern CodeSpecifiers spec_neverinline;
|
||||
GEN_API extern CodeSpecifiers spec_noexcept;
|
||||
GEN_API extern CodeSpecifiers spec_override;
|
||||
GEN_API extern CodeSpecifiers spec_ptr;
|
||||
GEN_API extern CodeSpecifiers spec_pure;
|
||||
GEN_API extern CodeSpecifiers spec_ref;
|
||||
GEN_API extern CodeSpecifiers spec_register;
|
||||
GEN_API extern CodeSpecifiers spec_rvalue;
|
||||
GEN_API extern CodeSpecifiers spec_static_member;
|
||||
GEN_API extern CodeSpecifiers spec_thread_local;
|
||||
GEN_API extern CodeSpecifiers spec_virtual;
|
||||
GEN_API extern CodeSpecifiers spec_volatile;
|
||||
|
||||
GEN_API extern CodeTypename t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
|
||||
GEN_API extern CodeTypename t_auto;
|
||||
GEN_API extern CodeTypename t_void;
|
||||
GEN_API extern CodeTypename t_int;
|
||||
GEN_API extern CodeTypename t_bool;
|
||||
GEN_API extern CodeTypename t_char;
|
||||
GEN_API extern CodeTypename t_wchar_t;
|
||||
GEN_API extern CodeTypename t_class;
|
||||
GEN_API extern CodeTypename t_typename;
|
||||
|
||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
GEN_API extern CodeTypename t_b32;
|
||||
|
||||
GEN_API extern CodeTypename t_s8;
|
||||
GEN_API extern CodeTypename t_s16;
|
||||
GEN_API extern CodeTypename t_s32;
|
||||
GEN_API extern CodeTypename t_s64;
|
||||
|
||||
GEN_API extern CodeTypename t_u8;
|
||||
GEN_API extern CodeTypename t_u16;
|
||||
GEN_API extern CodeTypename t_u32;
|
||||
GEN_API extern CodeTypename t_u64;
|
||||
|
||||
GEN_API extern CodeTypename t_ssize;
|
||||
GEN_API extern CodeTypename t_usize;
|
||||
|
||||
GEN_API extern CodeTypename t_f32;
|
||||
GEN_API extern CodeTypename t_f64;
|
||||
#endif
|
||||
|
||||
#pragma endregion Constants
|
||||
+190
-190
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
#pragma region generated code inline implementation
|
||||
|
||||
inline Code& Code::operator=( Code other )
|
||||
inline Code& Code::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ inline Code::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodeBody& CodeBody::operator=( Code other )
|
||||
inline CodeBody& CodeBody::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -39,14 +39,14 @@ inline CodeBody::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodeAttributes& CodeAttributes::operator=( Code other )
|
||||
inline CodeAttributes& CodeAttributes::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -57,27 +57,27 @@ inline CodeAttributes::operator bool()
|
||||
|
||||
inline CodeAttributes::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Attributes* CodeAttributes::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeComment& CodeComment::operator=( Code other )
|
||||
inline CodeComment& CodeComment::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -88,27 +88,27 @@ inline CodeComment::operator bool()
|
||||
|
||||
inline CodeComment::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Comment* CodeComment::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeConstructor& CodeConstructor::operator=( Code other )
|
||||
inline CodeConstructor& CodeConstructor::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -119,27 +119,27 @@ inline CodeConstructor::operator bool()
|
||||
|
||||
inline CodeConstructor::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Constructor* CodeConstructor::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeClass& CodeClass::operator=( Code other )
|
||||
inline CodeClass& CodeClass::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -148,14 +148,14 @@ inline CodeClass::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodeDefine& CodeDefine::operator=( Code other )
|
||||
inline CodeDefine& CodeDefine::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -166,27 +166,27 @@ inline CodeDefine::operator bool()
|
||||
|
||||
inline CodeDefine::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Define* CodeDefine::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeDefineParams& CodeDefineParams::operator=( Code other )
|
||||
inline CodeDefineParams& CodeDefineParams::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -195,14 +195,14 @@ inline CodeDefineParams::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodeDestructor& CodeDestructor::operator=( Code other )
|
||||
inline CodeDestructor& CodeDestructor::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -213,27 +213,27 @@ inline CodeDestructor::operator bool()
|
||||
|
||||
inline CodeDestructor::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Destructor* CodeDestructor::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeEnum& CodeEnum::operator=( Code other )
|
||||
inline CodeEnum& CodeEnum::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -244,27 +244,27 @@ inline CodeEnum::operator bool()
|
||||
|
||||
inline CodeEnum::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Enum* CodeEnum::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeExec& CodeExec::operator=( Code other )
|
||||
inline CodeExec& CodeExec::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -275,27 +275,27 @@ inline CodeExec::operator bool()
|
||||
|
||||
inline CodeExec::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Exec* CodeExec::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeExtern& CodeExtern::operator=( Code other )
|
||||
inline CodeExtern& CodeExtern::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -306,27 +306,27 @@ inline CodeExtern::operator bool()
|
||||
|
||||
inline CodeExtern::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Extern* CodeExtern::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeFriend& CodeFriend::operator=( Code other )
|
||||
inline CodeFriend& CodeFriend::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -337,27 +337,27 @@ inline CodeFriend::operator bool()
|
||||
|
||||
inline CodeFriend::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Friend* CodeFriend::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeFn& CodeFn::operator=( Code other )
|
||||
inline CodeFn& CodeFn::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -368,27 +368,27 @@ inline CodeFn::operator bool()
|
||||
|
||||
inline CodeFn::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Fn* CodeFn::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeInclude& CodeInclude::operator=( Code other )
|
||||
inline CodeInclude& CodeInclude::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -399,27 +399,27 @@ inline CodeInclude::operator bool()
|
||||
|
||||
inline CodeInclude::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Include* CodeInclude::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeModule& CodeModule::operator=( Code other )
|
||||
inline CodeModule& CodeModule::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -430,27 +430,27 @@ inline CodeModule::operator bool()
|
||||
|
||||
inline CodeModule::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Module* CodeModule::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeNS& CodeNS::operator=( Code other )
|
||||
inline CodeNS& CodeNS::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -461,27 +461,27 @@ inline CodeNS::operator bool()
|
||||
|
||||
inline CodeNS::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_NS* CodeNS::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeOperator& CodeOperator::operator=( Code other )
|
||||
inline CodeOperator& CodeOperator::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -492,27 +492,27 @@ inline CodeOperator::operator bool()
|
||||
|
||||
inline CodeOperator::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Operator* CodeOperator::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeOpCast& CodeOpCast::operator=( Code other )
|
||||
inline CodeOpCast& CodeOpCast::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -523,27 +523,27 @@ inline CodeOpCast::operator bool()
|
||||
|
||||
inline CodeOpCast::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_OpCast* CodeOpCast::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeParams& CodeParams::operator=( Code other )
|
||||
inline CodeParams& CodeParams::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -552,14 +552,14 @@ inline CodeParams::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodePragma& CodePragma::operator=( Code other )
|
||||
inline CodePragma& CodePragma::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -570,27 +570,27 @@ inline CodePragma::operator bool()
|
||||
|
||||
inline CodePragma::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Pragma* CodePragma::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodePreprocessCond& CodePreprocessCond::operator=( Code other )
|
||||
inline CodePreprocessCond& CodePreprocessCond::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -601,27 +601,27 @@ inline CodePreprocessCond::operator bool()
|
||||
|
||||
inline CodePreprocessCond::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_PreprocessCond* CodePreprocessCond::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeSpecifiers& CodeSpecifiers::operator=( Code other )
|
||||
inline CodeSpecifiers& CodeSpecifiers::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -630,14 +630,14 @@ inline CodeSpecifiers::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodeStruct& CodeStruct::operator=( Code other )
|
||||
inline CodeStruct& CodeStruct::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -646,14 +646,14 @@ inline CodeStruct::operator bool()
|
||||
return ast != nullptr;
|
||||
}
|
||||
|
||||
inline CodeTemplate& CodeTemplate::operator=( Code other )
|
||||
inline CodeTemplate& CodeTemplate::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -664,27 +664,27 @@ inline CodeTemplate::operator bool()
|
||||
|
||||
inline CodeTemplate::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Template* CodeTemplate::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeTypename& CodeTypename::operator=( Code other )
|
||||
inline CodeTypename& CodeTypename::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -695,27 +695,27 @@ inline CodeTypename::operator bool()
|
||||
|
||||
inline CodeTypename::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Typename* CodeTypename::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeTypedef& CodeTypedef::operator=( Code other )
|
||||
inline CodeTypedef& CodeTypedef::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -726,27 +726,27 @@ inline CodeTypedef::operator bool()
|
||||
|
||||
inline CodeTypedef::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Typedef* CodeTypedef::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeUnion& CodeUnion::operator=( Code other )
|
||||
inline CodeUnion& CodeUnion::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -757,27 +757,27 @@ inline CodeUnion::operator bool()
|
||||
|
||||
inline CodeUnion::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Union* CodeUnion::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeUsing& CodeUsing::operator=( Code other )
|
||||
inline CodeUsing& CodeUsing::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -788,27 +788,27 @@ inline CodeUsing::operator bool()
|
||||
|
||||
inline CodeUsing::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Using* CodeUsing::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
}
|
||||
|
||||
inline CodeVar& CodeVar::operator=( Code other )
|
||||
inline CodeVar& CodeVar::operator=(Code other)
|
||||
{
|
||||
if ( other.ast != nullptr && other->Parent != nullptr )
|
||||
if (other.ast != nullptr && other->Parent != nullptr)
|
||||
{
|
||||
ast = rcast( decltype( ast ), code_duplicate( other ).ast );
|
||||
ast = rcast(decltype(ast), code_duplicate(other).ast);
|
||||
ast->Parent = { nullptr };
|
||||
}
|
||||
ast = rcast( decltype( ast ), other.ast );
|
||||
ast = rcast(decltype(ast), other.ast);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -819,14 +819,14 @@ inline CodeVar::operator bool()
|
||||
|
||||
inline CodeVar::operator Code()
|
||||
{
|
||||
return *rcast( Code*, this );
|
||||
return *rcast(Code*, this);
|
||||
}
|
||||
|
||||
inline AST_Var* CodeVar::operator->()
|
||||
{
|
||||
if ( ast == nullptr )
|
||||
if (ast == nullptr)
|
||||
{
|
||||
log_failure( "Attempt to dereference a nullptr!\n" );
|
||||
log_failure("Attempt to dereference a nullptr!\n");
|
||||
return nullptr;
|
||||
}
|
||||
return ast;
|
||||
|
||||
+131
-131
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
@@ -73,150 +73,150 @@ enum CodeType : u32
|
||||
CT_UnderlyingType = GEN_U32_MAX
|
||||
};
|
||||
|
||||
inline Str codetype_to_str( CodeType type )
|
||||
inline Str codetype_to_str(CodeType type)
|
||||
{
|
||||
local_persist Str lookup[] = {
|
||||
{ "Invalid", sizeof( "Invalid" ) - 1 },
|
||||
{ "Untyped", sizeof( "Untyped" ) - 1 },
|
||||
{ "NewLine", sizeof( "NewLine" ) - 1 },
|
||||
{ "Comment", sizeof( "Comment" ) - 1 },
|
||||
{ "Access_Private", sizeof( "Access_Private" ) - 1 },
|
||||
{ "Access_Protected", sizeof( "Access_Protected" ) - 1 },
|
||||
{ "Access_Public", sizeof( "Access_Public" ) - 1 },
|
||||
{ "PlatformAttributes", sizeof( "PlatformAttributes" ) - 1 },
|
||||
{ "Class", sizeof( "Class" ) - 1 },
|
||||
{ "Class_Fwd", sizeof( "Class_Fwd" ) - 1 },
|
||||
{ "Class_Body", sizeof( "Class_Body" ) - 1 },
|
||||
{ "Constructor", sizeof( "Constructor" ) - 1 },
|
||||
{ "Constructor_Fwd", sizeof( "Constructor_Fwd" ) - 1 },
|
||||
{ "Destructor", sizeof( "Destructor" ) - 1 },
|
||||
{ "Destructor_Fwd", sizeof( "Destructor_Fwd" ) - 1 },
|
||||
{ "Enum", sizeof( "Enum" ) - 1 },
|
||||
{ "Enum_Fwd", sizeof( "Enum_Fwd" ) - 1 },
|
||||
{ "Enum_Body", sizeof( "Enum_Body" ) - 1 },
|
||||
{ "Enum_Class", sizeof( "Enum_Class" ) - 1 },
|
||||
{ "Enum_Class_Fwd", sizeof( "Enum_Class_Fwd" ) - 1 },
|
||||
{ "Execution", sizeof( "Execution" ) - 1 },
|
||||
{ "Export_Body", sizeof( "Export_Body" ) - 1 },
|
||||
{ "Extern_Linkage", sizeof( "Extern_Linkage" ) - 1 },
|
||||
{ "Extern_Linkage_Body", sizeof( "Extern_Linkage_Body" ) - 1 },
|
||||
{ "Friend", sizeof( "Friend" ) - 1 },
|
||||
{ "Function", sizeof( "Function" ) - 1 },
|
||||
{ "Function_Fwd", sizeof( "Function_Fwd" ) - 1 },
|
||||
{ "Function_Body", sizeof( "Function_Body" ) - 1 },
|
||||
{ "Global_Body", sizeof( "Global_Body" ) - 1 },
|
||||
{ "Module", sizeof( "Module" ) - 1 },
|
||||
{ "Namespace", sizeof( "Namespace" ) - 1 },
|
||||
{ "Namespace_Body", sizeof( "Namespace_Body" ) - 1 },
|
||||
{ "Operator", sizeof( "Operator" ) - 1 },
|
||||
{ "Operator_Fwd", sizeof( "Operator_Fwd" ) - 1 },
|
||||
{ "Operator_Member", sizeof( "Operator_Member" ) - 1 },
|
||||
{ "Operator_Member_Fwd", sizeof( "Operator_Member_Fwd" ) - 1 },
|
||||
{ "Operator_Cast", sizeof( "Operator_Cast" ) - 1 },
|
||||
{ "Operator_Cast_Fwd", sizeof( "Operator_Cast_Fwd" ) - 1 },
|
||||
{ "Parameters", sizeof( "Parameters" ) - 1 },
|
||||
{ "Parameters_Define", sizeof( "Parameters_Define" ) - 1 },
|
||||
{ "Preprocess_Define", sizeof( "Preprocess_Define" ) - 1 },
|
||||
{ "Preprocess_Include", sizeof( "Preprocess_Include" ) - 1 },
|
||||
{ "Preprocess_If", sizeof( "Preprocess_If" ) - 1 },
|
||||
{ "Preprocess_IfDef", sizeof( "Preprocess_IfDef" ) - 1 },
|
||||
{ "Preprocess_IfNotDef", sizeof( "Preprocess_IfNotDef" ) - 1 },
|
||||
{ "Preprocess_ElIf", sizeof( "Preprocess_ElIf" ) - 1 },
|
||||
{ "Preprocess_Else", sizeof( "Preprocess_Else" ) - 1 },
|
||||
{ "Preprocess_EndIf", sizeof( "Preprocess_EndIf" ) - 1 },
|
||||
{ "Preprocess_Pragma", sizeof( "Preprocess_Pragma" ) - 1 },
|
||||
{ "Specifiers", sizeof( "Specifiers" ) - 1 },
|
||||
{ "Struct", sizeof( "Struct" ) - 1 },
|
||||
{ "Struct_Fwd", sizeof( "Struct_Fwd" ) - 1 },
|
||||
{ "Struct_Body", sizeof( "Struct_Body" ) - 1 },
|
||||
{ "Template", sizeof( "Template" ) - 1 },
|
||||
{ "Typedef", sizeof( "Typedef" ) - 1 },
|
||||
{ "Typename", sizeof( "Typename" ) - 1 },
|
||||
{ "Union", sizeof( "Union" ) - 1 },
|
||||
{ "Union_Fwd", sizeof( "Union_Fwd" ) - 1 },
|
||||
{ "Union_Body", sizeof( "Union_Body" ) - 1 },
|
||||
{ "Using", sizeof( "Using" ) - 1 },
|
||||
{ "Using_Namespace", sizeof( "Using_Namespace" ) - 1 },
|
||||
{ "Variable", sizeof( "Variable" ) - 1 },
|
||||
{ "Invalid", sizeof("Invalid") - 1 },
|
||||
{ "Untyped", sizeof("Untyped") - 1 },
|
||||
{ "NewLine", sizeof("NewLine") - 1 },
|
||||
{ "Comment", sizeof("Comment") - 1 },
|
||||
{ "Access_Private", sizeof("Access_Private") - 1 },
|
||||
{ "Access_Protected", sizeof("Access_Protected") - 1 },
|
||||
{ "Access_Public", sizeof("Access_Public") - 1 },
|
||||
{ "PlatformAttributes", sizeof("PlatformAttributes") - 1 },
|
||||
{ "Class", sizeof("Class") - 1 },
|
||||
{ "Class_Fwd", sizeof("Class_Fwd") - 1 },
|
||||
{ "Class_Body", sizeof("Class_Body") - 1 },
|
||||
{ "Constructor", sizeof("Constructor") - 1 },
|
||||
{ "Constructor_Fwd", sizeof("Constructor_Fwd") - 1 },
|
||||
{ "Destructor", sizeof("Destructor") - 1 },
|
||||
{ "Destructor_Fwd", sizeof("Destructor_Fwd") - 1 },
|
||||
{ "Enum", sizeof("Enum") - 1 },
|
||||
{ "Enum_Fwd", sizeof("Enum_Fwd") - 1 },
|
||||
{ "Enum_Body", sizeof("Enum_Body") - 1 },
|
||||
{ "Enum_Class", sizeof("Enum_Class") - 1 },
|
||||
{ "Enum_Class_Fwd", sizeof("Enum_Class_Fwd") - 1 },
|
||||
{ "Execution", sizeof("Execution") - 1 },
|
||||
{ "Export_Body", sizeof("Export_Body") - 1 },
|
||||
{ "Extern_Linkage", sizeof("Extern_Linkage") - 1 },
|
||||
{ "Extern_Linkage_Body", sizeof("Extern_Linkage_Body") - 1 },
|
||||
{ "Friend", sizeof("Friend") - 1 },
|
||||
{ "Function", sizeof("Function") - 1 },
|
||||
{ "Function_Fwd", sizeof("Function_Fwd") - 1 },
|
||||
{ "Function_Body", sizeof("Function_Body") - 1 },
|
||||
{ "Global_Body", sizeof("Global_Body") - 1 },
|
||||
{ "Module", sizeof("Module") - 1 },
|
||||
{ "Namespace", sizeof("Namespace") - 1 },
|
||||
{ "Namespace_Body", sizeof("Namespace_Body") - 1 },
|
||||
{ "Operator", sizeof("Operator") - 1 },
|
||||
{ "Operator_Fwd", sizeof("Operator_Fwd") - 1 },
|
||||
{ "Operator_Member", sizeof("Operator_Member") - 1 },
|
||||
{ "Operator_Member_Fwd", sizeof("Operator_Member_Fwd") - 1 },
|
||||
{ "Operator_Cast", sizeof("Operator_Cast") - 1 },
|
||||
{ "Operator_Cast_Fwd", sizeof("Operator_Cast_Fwd") - 1 },
|
||||
{ "Parameters", sizeof("Parameters") - 1 },
|
||||
{ "Parameters_Define", sizeof("Parameters_Define") - 1 },
|
||||
{ "Preprocess_Define", sizeof("Preprocess_Define") - 1 },
|
||||
{ "Preprocess_Include", sizeof("Preprocess_Include") - 1 },
|
||||
{ "Preprocess_If", sizeof("Preprocess_If") - 1 },
|
||||
{ "Preprocess_IfDef", sizeof("Preprocess_IfDef") - 1 },
|
||||
{ "Preprocess_IfNotDef", sizeof("Preprocess_IfNotDef") - 1 },
|
||||
{ "Preprocess_ElIf", sizeof("Preprocess_ElIf") - 1 },
|
||||
{ "Preprocess_Else", sizeof("Preprocess_Else") - 1 },
|
||||
{ "Preprocess_EndIf", sizeof("Preprocess_EndIf") - 1 },
|
||||
{ "Preprocess_Pragma", sizeof("Preprocess_Pragma") - 1 },
|
||||
{ "Specifiers", sizeof("Specifiers") - 1 },
|
||||
{ "Struct", sizeof("Struct") - 1 },
|
||||
{ "Struct_Fwd", sizeof("Struct_Fwd") - 1 },
|
||||
{ "Struct_Body", sizeof("Struct_Body") - 1 },
|
||||
{ "Template", sizeof("Template") - 1 },
|
||||
{ "Typedef", sizeof("Typedef") - 1 },
|
||||
{ "Typename", sizeof("Typename") - 1 },
|
||||
{ "Union", sizeof("Union") - 1 },
|
||||
{ "Union_Fwd", sizeof("Union_Fwd") - 1 },
|
||||
{ "Union_Body", sizeof("Union_Body") - 1 },
|
||||
{ "Using", sizeof("Using") - 1 },
|
||||
{ "Using_Namespace", sizeof("Using_Namespace") - 1 },
|
||||
{ "Variable", sizeof("Variable") - 1 },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline Str codetype_to_keyword_str( CodeType type )
|
||||
inline Str codetype_to_keyword_str(CodeType type)
|
||||
{
|
||||
local_persist Str lookup[] = {
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "//", sizeof( "//" ) - 1 },
|
||||
{ "private", sizeof( "private" ) - 1 },
|
||||
{ "protected", sizeof( "protected" ) - 1 },
|
||||
{ "public", sizeof( "public" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "class", sizeof( "class" ) - 1 },
|
||||
{ "clsss", sizeof( "clsss" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "enum", sizeof( "enum" ) - 1 },
|
||||
{ "enum", sizeof( "enum" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "enum class", sizeof( "enum class" ) - 1 },
|
||||
{ "enum class", sizeof( "enum class" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "extern", sizeof( "extern" ) - 1 },
|
||||
{ "extern", sizeof( "extern" ) - 1 },
|
||||
{ "friend", sizeof( "friend" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "module", sizeof( "module" ) - 1 },
|
||||
{ "namespace", sizeof( "namespace" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "define", sizeof( "define" ) - 1 },
|
||||
{ "include", sizeof( "include" ) - 1 },
|
||||
{ "if", sizeof( "if" ) - 1 },
|
||||
{ "ifdef", sizeof( "ifdef" ) - 1 },
|
||||
{ "ifndef", sizeof( "ifndef" ) - 1 },
|
||||
{ "elif", sizeof( "elif" ) - 1 },
|
||||
{ "else", sizeof( "else" ) - 1 },
|
||||
{ "endif", sizeof( "endif" ) - 1 },
|
||||
{ "pragma", sizeof( "pragma" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "struct", sizeof( "struct" ) - 1 },
|
||||
{ "struct", sizeof( "struct" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "template", sizeof( "template" ) - 1 },
|
||||
{ "typedef", sizeof( "typedef" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "union", sizeof( "union" ) - 1 },
|
||||
{ "union", sizeof( "union" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "using", sizeof( "using" ) - 1 },
|
||||
{ "using namespace", sizeof( "using namespace" ) - 1 },
|
||||
{ "__NA__", sizeof( "__NA__" ) - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "//", sizeof("//") - 1 },
|
||||
{ "private", sizeof("private") - 1 },
|
||||
{ "protected", sizeof("protected") - 1 },
|
||||
{ "public", sizeof("public") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "class", sizeof("class") - 1 },
|
||||
{ "clsss", sizeof("clsss") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "enum", sizeof("enum") - 1 },
|
||||
{ "enum", sizeof("enum") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "enum class", sizeof("enum class") - 1 },
|
||||
{ "enum class", sizeof("enum class") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "extern", sizeof("extern") - 1 },
|
||||
{ "extern", sizeof("extern") - 1 },
|
||||
{ "friend", sizeof("friend") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "module", sizeof("module") - 1 },
|
||||
{ "namespace", sizeof("namespace") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "define", sizeof("define") - 1 },
|
||||
{ "include", sizeof("include") - 1 },
|
||||
{ "if", sizeof("if") - 1 },
|
||||
{ "ifdef", sizeof("ifdef") - 1 },
|
||||
{ "ifndef", sizeof("ifndef") - 1 },
|
||||
{ "elif", sizeof("elif") - 1 },
|
||||
{ "else", sizeof("else") - 1 },
|
||||
{ "endif", sizeof("endif") - 1 },
|
||||
{ "pragma", sizeof("pragma") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "struct", sizeof("struct") - 1 },
|
||||
{ "struct", sizeof("struct") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "template", sizeof("template") - 1 },
|
||||
{ "typedef", sizeof("typedef") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "union", sizeof("union") - 1 },
|
||||
{ "union", sizeof("union") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
{ "using", sizeof("using") - 1 },
|
||||
{ "using namespace", sizeof("using namespace") - 1 },
|
||||
{ "__NA__", sizeof("__NA__") - 1 },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
forceinline Str to_str( CodeType type )
|
||||
forceinline Str to_str(CodeType type)
|
||||
{
|
||||
return codetype_to_str( type );
|
||||
return codetype_to_str(type);
|
||||
}
|
||||
|
||||
forceinline Str to_keyword_str( CodeType type )
|
||||
forceinline Str to_keyword_str(CodeType type)
|
||||
{
|
||||
return codetype_to_keyword_str( type );
|
||||
return codetype_to_keyword_str(type);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
@@ -58,61 +58,61 @@ enum Operator : u32
|
||||
Op_UnderlyingType = 0xffffffffu
|
||||
};
|
||||
|
||||
inline Str operator_to_str( Operator op )
|
||||
inline Str operator_to_str(Operator op)
|
||||
{
|
||||
local_persist Str lookup[] = {
|
||||
{ "INVALID", sizeof( "INVALID" ) - 1 },
|
||||
{ "=", sizeof( "=" ) - 1 },
|
||||
{ "+=", sizeof( "+=" ) - 1 },
|
||||
{ "-=", sizeof( "-=" ) - 1 },
|
||||
{ "*=", sizeof( "*=" ) - 1 },
|
||||
{ "/=", sizeof( "/=" ) - 1 },
|
||||
{ "%=", sizeof( "%=" ) - 1 },
|
||||
{ "&=", sizeof( "&=" ) - 1 },
|
||||
{ "|=", sizeof( "|=" ) - 1 },
|
||||
{ "^=", sizeof( "^=" ) - 1 },
|
||||
{ "<<=", sizeof( "<<=" ) - 1 },
|
||||
{ ">>=", sizeof( ">>=" ) - 1 },
|
||||
{ "++", sizeof( "++" ) - 1 },
|
||||
{ "--", sizeof( "--" ) - 1 },
|
||||
{ "+", sizeof( "+" ) - 1 },
|
||||
{ "-", sizeof( "-" ) - 1 },
|
||||
{ "!", sizeof( "!" ) - 1 },
|
||||
{ "+", sizeof( "+" ) - 1 },
|
||||
{ "-", sizeof( "-" ) - 1 },
|
||||
{ "*", sizeof( "*" ) - 1 },
|
||||
{ "/", sizeof( "/" ) - 1 },
|
||||
{ "%", sizeof( "%" ) - 1 },
|
||||
{ "~", sizeof( "~" ) - 1 },
|
||||
{ "&", sizeof( "&" ) - 1 },
|
||||
{ "|", sizeof( "|" ) - 1 },
|
||||
{ "^", sizeof( "^" ) - 1 },
|
||||
{ "<<", sizeof( "<<" ) - 1 },
|
||||
{ ">>", sizeof( ">>" ) - 1 },
|
||||
{ "&&", sizeof( "&&" ) - 1 },
|
||||
{ "||", sizeof( "||" ) - 1 },
|
||||
{ "==", sizeof( "==" ) - 1 },
|
||||
{ "!=", sizeof( "!=" ) - 1 },
|
||||
{ "<", sizeof( "<" ) - 1 },
|
||||
{ ">", sizeof( ">" ) - 1 },
|
||||
{ "<=", sizeof( "<=" ) - 1 },
|
||||
{ ">=", sizeof( ">=" ) - 1 },
|
||||
{ "[]", sizeof( "[]" ) - 1 },
|
||||
{ "*", sizeof( "*" ) - 1 },
|
||||
{ "&", sizeof( "&" ) - 1 },
|
||||
{ "->", sizeof( "->" ) - 1 },
|
||||
{ "->*", sizeof( "->*" ) - 1 },
|
||||
{ "()", sizeof( "()" ) - 1 },
|
||||
{ ",", sizeof( "," ) - 1 },
|
||||
{ "new", sizeof( "new" ) - 1 },
|
||||
{ "new[]", sizeof( "new[]" ) - 1 },
|
||||
{ "delete", sizeof( "delete" ) - 1 },
|
||||
{ "delete[]", sizeof( "delete[]" ) - 1 },
|
||||
{ "INVALID", sizeof("INVALID") - 1 },
|
||||
{ "=", sizeof("=") - 1 },
|
||||
{ "+=", sizeof("+=") - 1 },
|
||||
{ "-=", sizeof("-=") - 1 },
|
||||
{ "*=", sizeof("*=") - 1 },
|
||||
{ "/=", sizeof("/=") - 1 },
|
||||
{ "%=", sizeof("%=") - 1 },
|
||||
{ "&=", sizeof("&=") - 1 },
|
||||
{ "|=", sizeof("|=") - 1 },
|
||||
{ "^=", sizeof("^=") - 1 },
|
||||
{ "<<=", sizeof("<<=") - 1 },
|
||||
{ ">>=", sizeof(">>=") - 1 },
|
||||
{ "++", sizeof("++") - 1 },
|
||||
{ "--", sizeof("--") - 1 },
|
||||
{ "+", sizeof("+") - 1 },
|
||||
{ "-", sizeof("-") - 1 },
|
||||
{ "!", sizeof("!") - 1 },
|
||||
{ "+", sizeof("+") - 1 },
|
||||
{ "-", sizeof("-") - 1 },
|
||||
{ "*", sizeof("*") - 1 },
|
||||
{ "/", sizeof("/") - 1 },
|
||||
{ "%", sizeof("%") - 1 },
|
||||
{ "~", sizeof("~") - 1 },
|
||||
{ "&", sizeof("&") - 1 },
|
||||
{ "|", sizeof("|") - 1 },
|
||||
{ "^", sizeof("^") - 1 },
|
||||
{ "<<", sizeof("<<") - 1 },
|
||||
{ ">>", sizeof(">>") - 1 },
|
||||
{ "&&", sizeof("&&") - 1 },
|
||||
{ "||", sizeof("||") - 1 },
|
||||
{ "==", sizeof("==") - 1 },
|
||||
{ "!=", sizeof("!=") - 1 },
|
||||
{ "<", sizeof("<") - 1 },
|
||||
{ ">", sizeof(">") - 1 },
|
||||
{ "<=", sizeof("<=") - 1 },
|
||||
{ ">=", sizeof(">=") - 1 },
|
||||
{ "[]", sizeof("[]") - 1 },
|
||||
{ "*", sizeof("*") - 1 },
|
||||
{ "&", sizeof("&") - 1 },
|
||||
{ "->", sizeof("->") - 1 },
|
||||
{ "->*", sizeof("->*") - 1 },
|
||||
{ "()", sizeof("()") - 1 },
|
||||
{ ",", sizeof(",") - 1 },
|
||||
{ "new", sizeof("new") - 1 },
|
||||
{ "new[]", sizeof("new[]") - 1 },
|
||||
{ "delete", sizeof("delete") - 1 },
|
||||
{ "delete[]", sizeof("delete[]") - 1 },
|
||||
};
|
||||
return lookup[op];
|
||||
}
|
||||
|
||||
forceinline Str to_str( Operator op )
|
||||
forceinline Str to_str(Operator op)
|
||||
{
|
||||
return operator_to_str( op );
|
||||
return operator_to_str(op);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "components/types.hpp"
|
||||
#endif
|
||||
@@ -33,89 +33,92 @@ enum Specifier : u32
|
||||
Spec_NoExceptions,
|
||||
Spec_Override,
|
||||
Spec_Pure,
|
||||
Spec_Delete,
|
||||
Spec_Volatile,
|
||||
Spec_NumSpecifiers,
|
||||
Spec_UnderlyingType = 0xffffffffu
|
||||
};
|
||||
|
||||
inline Str spec_to_str( Specifier type )
|
||||
inline Str spec_to_str(Specifier type)
|
||||
{
|
||||
local_persist Str lookup[] = {
|
||||
{ "INVALID", sizeof( "INVALID" ) - 1 },
|
||||
{ "consteval", sizeof( "consteval" ) - 1 },
|
||||
{ "constexpr", sizeof( "constexpr" ) - 1 },
|
||||
{ "constinit", sizeof( "constinit" ) - 1 },
|
||||
{ "explicit", sizeof( "explicit" ) - 1 },
|
||||
{ "extern", sizeof( "extern" ) - 1 },
|
||||
{ "forceinline", sizeof( "forceinline" ) - 1 },
|
||||
{ "global", sizeof( "global" ) - 1 },
|
||||
{ "inline", sizeof( "inline" ) - 1 },
|
||||
{ "internal", sizeof( "internal" ) - 1 },
|
||||
{ "local_persist", sizeof( "local_persist" ) - 1 },
|
||||
{ "mutable", sizeof( "mutable" ) - 1 },
|
||||
{ "neverinline", sizeof( "neverinline" ) - 1 },
|
||||
{ "*", sizeof( "*" ) - 1 },
|
||||
{ "&", sizeof( "&" ) - 1 },
|
||||
{ "register", sizeof( "register" ) - 1 },
|
||||
{ "restrict", sizeof( "restrict" ) - 1 },
|
||||
{ "&&", sizeof( "&&" ) - 1 },
|
||||
{ "static", sizeof( "static" ) - 1 },
|
||||
{ "thread_local", sizeof( "thread_local" ) - 1 },
|
||||
{ "virtual", sizeof( "virtual" ) - 1 },
|
||||
{ "const", sizeof( "const" ) - 1 },
|
||||
{ "final", sizeof( "final" ) - 1 },
|
||||
{ "noexcept", sizeof( "noexcept" ) - 1 },
|
||||
{ "override", sizeof( "override" ) - 1 },
|
||||
{ "= 0", sizeof( "= 0" ) - 1 },
|
||||
{ "volatile", sizeof( "volatile" ) - 1 },
|
||||
{ "INVALID", sizeof("INVALID") - 1 },
|
||||
{ "consteval", sizeof("consteval") - 1 },
|
||||
{ "constexpr", sizeof("constexpr") - 1 },
|
||||
{ "constinit", sizeof("constinit") - 1 },
|
||||
{ "explicit", sizeof("explicit") - 1 },
|
||||
{ "extern", sizeof("extern") - 1 },
|
||||
{ "forceinline", sizeof("forceinline") - 1 },
|
||||
{ "global", sizeof("global") - 1 },
|
||||
{ "inline", sizeof("inline") - 1 },
|
||||
{ "internal", sizeof("internal") - 1 },
|
||||
{ "local_persist", sizeof("local_persist") - 1 },
|
||||
{ "mutable", sizeof("mutable") - 1 },
|
||||
{ "neverinline", sizeof("neverinline") - 1 },
|
||||
{ "*", sizeof("*") - 1 },
|
||||
{ "&", sizeof("&") - 1 },
|
||||
{ "register", sizeof("register") - 1 },
|
||||
{ "restrict", sizeof("restrict") - 1 },
|
||||
{ "&&", sizeof("&&") - 1 },
|
||||
{ "static", sizeof("static") - 1 },
|
||||
{ "thread_local", sizeof("thread_local") - 1 },
|
||||
{ "virtual", sizeof("virtual") - 1 },
|
||||
{ "const", sizeof("const") - 1 },
|
||||
{ "final", sizeof("final") - 1 },
|
||||
{ "noexcept", sizeof("noexcept") - 1 },
|
||||
{ "override", sizeof("override") - 1 },
|
||||
{ "= 0", sizeof("= 0") - 1 },
|
||||
{ "= delete", sizeof("= delete") - 1 },
|
||||
{ "volatile", sizeof("volatile") - 1 },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline bool spec_is_trailing( Specifier specifier )
|
||||
inline bool spec_is_trailing(Specifier specifier)
|
||||
{
|
||||
switch ( specifier )
|
||||
switch (specifier)
|
||||
{
|
||||
case Spec_Const :
|
||||
case Spec_Final :
|
||||
case Spec_NoExceptions :
|
||||
case Spec_Override :
|
||||
case Spec_Pure :
|
||||
case Spec_Volatile :
|
||||
case Spec_Const:
|
||||
case Spec_Final:
|
||||
case Spec_NoExceptions:
|
||||
case Spec_Override:
|
||||
case Spec_Pure:
|
||||
case Spec_Delete:
|
||||
case Spec_Volatile:
|
||||
return true;
|
||||
default :
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline Specifier str_to_specifier( Str str )
|
||||
inline Specifier str_to_specifier(Str str)
|
||||
{
|
||||
local_persist u32 keymap[Spec_NumSpecifiers];
|
||||
do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
||||
do_once_start for (u32 index = 0; index < Spec_NumSpecifiers; index++)
|
||||
{
|
||||
Str enum_str = spec_to_str( (Specifier)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len );
|
||||
Str enum_str = spec_to_str((Specifier)index);
|
||||
keymap[index] = crc32(enum_str.Ptr, enum_str.Len);
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
|
||||
do_once_end u32 hash = crc32(str.Ptr, str.Len);
|
||||
for (u32 index = 0; index < Spec_NumSpecifiers; index++)
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
if (keymap[index] == hash)
|
||||
return (Specifier)index;
|
||||
}
|
||||
return Spec_Invalid;
|
||||
}
|
||||
|
||||
forceinline Str to_str( Specifier spec )
|
||||
forceinline Str to_str(Specifier spec)
|
||||
{
|
||||
return spec_to_str( spec );
|
||||
return spec_to_str(spec);
|
||||
}
|
||||
|
||||
forceinline Specifier to_type( Str str )
|
||||
forceinline Specifier to_type(Str str)
|
||||
{
|
||||
return str_to_specifier( str );
|
||||
return str_to_specifier(str);
|
||||
}
|
||||
|
||||
forceinline bool is_trailing( Specifier specifier )
|
||||
forceinline bool is_trailing(Specifier specifier)
|
||||
{
|
||||
return spec_is_trailing( specifier );
|
||||
return spec_is_trailing(specifier);
|
||||
}
|
||||
+110
-110
@@ -1,11 +1,11 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef 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)
|
||||
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_GEN_API, "GEN_API" )
|
||||
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry(Tok_Attribute_GEN_API, "GEN_API")
|
||||
|
||||
enum TokType : u32
|
||||
{
|
||||
@@ -112,125 +112,125 @@ enum TokType : u32
|
||||
Tok_NumTokens
|
||||
};
|
||||
|
||||
inline Str toktype_to_str( TokType type )
|
||||
inline Str toktype_to_str(TokType type)
|
||||
{
|
||||
local_persist Str lookup[] = {
|
||||
{ "__invalid__", sizeof( "__invalid__" ) - 1 },
|
||||
{ "private", sizeof( "private" ) - 1 },
|
||||
{ "protected", sizeof( "protected" ) - 1 },
|
||||
{ "public", sizeof( "public" ) - 1 },
|
||||
{ ".", sizeof( "." ) - 1 },
|
||||
{ "::", sizeof( "::" ) - 1 },
|
||||
{ "&", sizeof( "&" ) - 1 },
|
||||
{ "&&", sizeof( "&&" ) - 1 },
|
||||
{ ":", sizeof( ":" ) - 1 },
|
||||
{ "[[", sizeof( "[[" ) - 1 },
|
||||
{ "]]", sizeof( "]]" ) - 1 },
|
||||
{ "{", sizeof( "{" ) - 1 },
|
||||
{ "}", sizeof( "}" ) - 1 },
|
||||
{ "[", sizeof( "[" ) - 1 },
|
||||
{ "]", sizeof( "]" ) - 1 },
|
||||
{ "(", sizeof( "(" ) - 1 },
|
||||
{ ")", sizeof( ")" ) - 1 },
|
||||
{ "__comment__", sizeof( "__comment__" ) - 1 },
|
||||
{ "__comment_end__", sizeof( "__comment_end__" ) - 1 },
|
||||
{ "__comment_start__", sizeof( "__comment_start__" ) - 1 },
|
||||
{ "__character__", sizeof( "__character__" ) - 1 },
|
||||
{ ",", sizeof( "," ) - 1 },
|
||||
{ "class", sizeof( "class" ) - 1 },
|
||||
{ "__attribute__", sizeof( "__attribute__" ) - 1 },
|
||||
{ "__declspec", sizeof( "__declspec" ) - 1 },
|
||||
{ "enum", sizeof( "enum" ) - 1 },
|
||||
{ "extern", sizeof( "extern" ) - 1 },
|
||||
{ "friend", sizeof( "friend" ) - 1 },
|
||||
{ "module", sizeof( "module" ) - 1 },
|
||||
{ "namespace", sizeof( "namespace" ) - 1 },
|
||||
{ "operator", sizeof( "operator" ) - 1 },
|
||||
{ "struct", sizeof( "struct" ) - 1 },
|
||||
{ "template", sizeof( "template" ) - 1 },
|
||||
{ "typedef", sizeof( "typedef" ) - 1 },
|
||||
{ "using", sizeof( "using" ) - 1 },
|
||||
{ "union", sizeof( "union" ) - 1 },
|
||||
{ "__identifier__", sizeof( "__identifier__" ) - 1 },
|
||||
{ "import", sizeof( "import" ) - 1 },
|
||||
{ "export", sizeof( "export" ) - 1 },
|
||||
{ "__new_line__", sizeof( "__new_line__" ) - 1 },
|
||||
{ "__number__", sizeof( "__number__" ) - 1 },
|
||||
{ "__operator__", sizeof( "__operator__" ) - 1 },
|
||||
{ "#", sizeof( "#" ) - 1 },
|
||||
{ "define", sizeof( "define" ) - 1 },
|
||||
{ "__define_param__", sizeof( "__define_param__" ) - 1 },
|
||||
{ "if", sizeof( "if" ) - 1 },
|
||||
{ "ifdef", sizeof( "ifdef" ) - 1 },
|
||||
{ "ifndef", sizeof( "ifndef" ) - 1 },
|
||||
{ "elif", sizeof( "elif" ) - 1 },
|
||||
{ "else", sizeof( "else" ) - 1 },
|
||||
{ "endif", sizeof( "endif" ) - 1 },
|
||||
{ "include", sizeof( "include" ) - 1 },
|
||||
{ "pragma", sizeof( "pragma" ) - 1 },
|
||||
{ "__macro_content__", sizeof( "__macro_content__" ) - 1 },
|
||||
{ "__macro_expression__", sizeof( "__macro_expression__" ) - 1 },
|
||||
{ "__macro_statment__", sizeof( "__macro_statment__" ) - 1 },
|
||||
{ "__macro_typename__", sizeof( "__macro_typename__" ) - 1 },
|
||||
{ "__unsupported__", sizeof( "__unsupported__" ) - 1 },
|
||||
{ "alignas", sizeof( "alignas" ) - 1 },
|
||||
{ "const", sizeof( "const" ) - 1 },
|
||||
{ "consteval", sizeof( "consteval" ) - 1 },
|
||||
{ "constexpr", sizeof( "constexpr" ) - 1 },
|
||||
{ "constinit", sizeof( "constinit" ) - 1 },
|
||||
{ "explicit", sizeof( "explicit" ) - 1 },
|
||||
{ "extern", sizeof( "extern" ) - 1 },
|
||||
{ "final", sizeof( "final" ) - 1 },
|
||||
{ "forceinline", sizeof( "forceinline" ) - 1 },
|
||||
{ "global", sizeof( "global" ) - 1 },
|
||||
{ "inline", sizeof( "inline" ) - 1 },
|
||||
{ "internal", sizeof( "internal" ) - 1 },
|
||||
{ "local_persist", sizeof( "local_persist" ) - 1 },
|
||||
{ "mutable", sizeof( "mutable" ) - 1 },
|
||||
{ "neverinline", sizeof( "neverinline" ) - 1 },
|
||||
{ "override", sizeof( "override" ) - 1 },
|
||||
{ "restrict", sizeof( "restrict" ) - 1 },
|
||||
{ "static", sizeof( "static" ) - 1 },
|
||||
{ "thread_local", sizeof( "thread_local" ) - 1 },
|
||||
{ "volatile", sizeof( "volatile" ) - 1 },
|
||||
{ "virtual", sizeof( "virtual" ) - 1 },
|
||||
{ "*", sizeof( "*" ) - 1 },
|
||||
{ ";", sizeof( ";" ) - 1 },
|
||||
{ "static_assert", sizeof( "static_assert" ) - 1 },
|
||||
{ "__string__", sizeof( "__string__" ) - 1 },
|
||||
{ "typename", sizeof( "typename" ) - 1 },
|
||||
{ "unsigned", sizeof( "unsigned" ) - 1 },
|
||||
{ "signed", sizeof( "signed" ) - 1 },
|
||||
{ "short", sizeof( "short" ) - 1 },
|
||||
{ "long", sizeof( "long" ) - 1 },
|
||||
{ "bool", sizeof( "bool" ) - 1 },
|
||||
{ "char", sizeof( "char" ) - 1 },
|
||||
{ "int", sizeof( "int" ) - 1 },
|
||||
{ "double", sizeof( "double" ) - 1 },
|
||||
{ "__int8", sizeof( "__int8" ) - 1 },
|
||||
{ "__int16", sizeof( "__int16" ) - 1 },
|
||||
{ "__int32", sizeof( "__int32" ) - 1 },
|
||||
{ "__int64", sizeof( "__int64" ) - 1 },
|
||||
{ "_W64", sizeof( "_W64" ) - 1 },
|
||||
{ "...", sizeof( "..." ) - 1 },
|
||||
{ "__attrib_start__", sizeof( "__attrib_start__" ) - 1 },
|
||||
{ "GEN_API", sizeof( "GEN_API" ) - 1 },
|
||||
{ "__invalid__", sizeof("__invalid__") - 1 },
|
||||
{ "private", sizeof("private") - 1 },
|
||||
{ "protected", sizeof("protected") - 1 },
|
||||
{ "public", sizeof("public") - 1 },
|
||||
{ ".", sizeof(".") - 1 },
|
||||
{ "::", sizeof("::") - 1 },
|
||||
{ "&", sizeof("&") - 1 },
|
||||
{ "&&", sizeof("&&") - 1 },
|
||||
{ ":", sizeof(":") - 1 },
|
||||
{ "[[", sizeof("[[") - 1 },
|
||||
{ "]]", sizeof("]]") - 1 },
|
||||
{ "{", sizeof("{") - 1 },
|
||||
{ "}", sizeof("}") - 1 },
|
||||
{ "[", sizeof("[") - 1 },
|
||||
{ "]", sizeof("]") - 1 },
|
||||
{ "(", sizeof("(") - 1 },
|
||||
{ ")", sizeof(")") - 1 },
|
||||
{ "__comment__", sizeof("__comment__") - 1 },
|
||||
{ "__comment_end__", sizeof("__comment_end__") - 1 },
|
||||
{ "__comment_start__", sizeof("__comment_start__") - 1 },
|
||||
{ "__character__", sizeof("__character__") - 1 },
|
||||
{ ",", sizeof(",") - 1 },
|
||||
{ "class", sizeof("class") - 1 },
|
||||
{ "__attribute__", sizeof("__attribute__") - 1 },
|
||||
{ "__declspec", sizeof("__declspec") - 1 },
|
||||
{ "enum", sizeof("enum") - 1 },
|
||||
{ "extern", sizeof("extern") - 1 },
|
||||
{ "friend", sizeof("friend") - 1 },
|
||||
{ "module", sizeof("module") - 1 },
|
||||
{ "namespace", sizeof("namespace") - 1 },
|
||||
{ "operator", sizeof("operator") - 1 },
|
||||
{ "struct", sizeof("struct") - 1 },
|
||||
{ "template", sizeof("template") - 1 },
|
||||
{ "typedef", sizeof("typedef") - 1 },
|
||||
{ "using", sizeof("using") - 1 },
|
||||
{ "union", sizeof("union") - 1 },
|
||||
{ "__identifier__", sizeof("__identifier__") - 1 },
|
||||
{ "import", sizeof("import") - 1 },
|
||||
{ "export", sizeof("export") - 1 },
|
||||
{ "__new_line__", sizeof("__new_line__") - 1 },
|
||||
{ "__number__", sizeof("__number__") - 1 },
|
||||
{ "__operator__", sizeof("__operator__") - 1 },
|
||||
{ "#", sizeof("#") - 1 },
|
||||
{ "define", sizeof("define") - 1 },
|
||||
{ "__define_param__", sizeof("__define_param__") - 1 },
|
||||
{ "if", sizeof("if") - 1 },
|
||||
{ "ifdef", sizeof("ifdef") - 1 },
|
||||
{ "ifndef", sizeof("ifndef") - 1 },
|
||||
{ "elif", sizeof("elif") - 1 },
|
||||
{ "else", sizeof("else") - 1 },
|
||||
{ "endif", sizeof("endif") - 1 },
|
||||
{ "include", sizeof("include") - 1 },
|
||||
{ "pragma", sizeof("pragma") - 1 },
|
||||
{ "__macro_content__", sizeof("__macro_content__") - 1 },
|
||||
{ "__macro_expression__", sizeof("__macro_expression__") - 1 },
|
||||
{ "__macro_statment__", sizeof("__macro_statment__") - 1 },
|
||||
{ "__macro_typename__", sizeof("__macro_typename__") - 1 },
|
||||
{ "__unsupported__", sizeof("__unsupported__") - 1 },
|
||||
{ "alignas", sizeof("alignas") - 1 },
|
||||
{ "const", sizeof("const") - 1 },
|
||||
{ "consteval", sizeof("consteval") - 1 },
|
||||
{ "constexpr", sizeof("constexpr") - 1 },
|
||||
{ "constinit", sizeof("constinit") - 1 },
|
||||
{ "explicit", sizeof("explicit") - 1 },
|
||||
{ "extern", sizeof("extern") - 1 },
|
||||
{ "final", sizeof("final") - 1 },
|
||||
{ "forceinline", sizeof("forceinline") - 1 },
|
||||
{ "global", sizeof("global") - 1 },
|
||||
{ "inline", sizeof("inline") - 1 },
|
||||
{ "internal", sizeof("internal") - 1 },
|
||||
{ "local_persist", sizeof("local_persist") - 1 },
|
||||
{ "mutable", sizeof("mutable") - 1 },
|
||||
{ "neverinline", sizeof("neverinline") - 1 },
|
||||
{ "override", sizeof("override") - 1 },
|
||||
{ "restrict", sizeof("restrict") - 1 },
|
||||
{ "static", sizeof("static") - 1 },
|
||||
{ "thread_local", sizeof("thread_local") - 1 },
|
||||
{ "volatile", sizeof("volatile") - 1 },
|
||||
{ "virtual", sizeof("virtual") - 1 },
|
||||
{ "*", sizeof("*") - 1 },
|
||||
{ ";", sizeof(";") - 1 },
|
||||
{ "static_assert", sizeof("static_assert") - 1 },
|
||||
{ "__string__", sizeof("__string__") - 1 },
|
||||
{ "typename", sizeof("typename") - 1 },
|
||||
{ "unsigned", sizeof("unsigned") - 1 },
|
||||
{ "signed", sizeof("signed") - 1 },
|
||||
{ "short", sizeof("short") - 1 },
|
||||
{ "long", sizeof("long") - 1 },
|
||||
{ "bool", sizeof("bool") - 1 },
|
||||
{ "char", sizeof("char") - 1 },
|
||||
{ "int", sizeof("int") - 1 },
|
||||
{ "double", sizeof("double") - 1 },
|
||||
{ "__int8", sizeof("__int8") - 1 },
|
||||
{ "__int16", sizeof("__int16") - 1 },
|
||||
{ "__int32", sizeof("__int32") - 1 },
|
||||
{ "__int64", sizeof("__int64") - 1 },
|
||||
{ "_W64", sizeof("_W64") - 1 },
|
||||
{ "...", sizeof("...") - 1 },
|
||||
{ "__attrib_start__", sizeof("__attrib_start__") - 1 },
|
||||
{ "GEN_API", sizeof("GEN_API") - 1 },
|
||||
};
|
||||
return lookup[type];
|
||||
}
|
||||
|
||||
inline TokType str_to_toktype( Str str )
|
||||
inline TokType str_to_toktype(Str str)
|
||||
{
|
||||
local_persist u32 keymap[Tok_NumTokens];
|
||||
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
do_once_start for (u32 index = 0; index < Tok_NumTokens; index++)
|
||||
{
|
||||
Str enum_str = toktype_to_str( (TokType)index );
|
||||
keymap[index] = crc32( enum_str.Ptr, enum_str.Len );
|
||||
Str enum_str = toktype_to_str((TokType)index);
|
||||
keymap[index] = crc32(enum_str.Ptr, enum_str.Len);
|
||||
}
|
||||
do_once_end u32 hash = crc32( str.Ptr, str.Len );
|
||||
for ( u32 index = 0; index < Tok_NumTokens; index++ )
|
||||
do_once_end u32 hash = crc32(str.Ptr, str.Len);
|
||||
for (u32 index = 0; index < Tok_NumTokens; index++)
|
||||
{
|
||||
if ( keymap[index] == hash )
|
||||
if (keymap[index] == hash)
|
||||
return (TokType)index;
|
||||
}
|
||||
return Tok_Invalid;
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "inlines.hpp"
|
||||
#include "gen/ast_inlines.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Constants
|
||||
|
||||
extern Macro enum_underlying_macro;
|
||||
|
||||
extern Code access_public;
|
||||
extern Code access_protected;
|
||||
extern Code access_private;
|
||||
|
||||
extern CodeAttributes attrib_api_export;
|
||||
extern CodeAttributes attrib_api_import;
|
||||
|
||||
extern Code module_global_fragment;
|
||||
extern Code module_private_fragment;
|
||||
|
||||
extern Code fmt_newline;
|
||||
|
||||
extern CodePragma pragma_once;
|
||||
|
||||
extern CodeParams param_varadic;
|
||||
|
||||
extern CodePreprocessCond preprocess_else;
|
||||
extern CodePreprocessCond preprocess_endif;
|
||||
|
||||
extern CodeSpecifiers spec_const;
|
||||
extern CodeSpecifiers spec_consteval;
|
||||
extern CodeSpecifiers spec_constexpr;
|
||||
extern CodeSpecifiers spec_constinit;
|
||||
extern CodeSpecifiers spec_extern_linkage;
|
||||
extern CodeSpecifiers spec_final;
|
||||
extern CodeSpecifiers spec_forceinline;
|
||||
extern CodeSpecifiers spec_global;
|
||||
extern CodeSpecifiers spec_inline;
|
||||
extern CodeSpecifiers spec_internal_linkage;
|
||||
extern CodeSpecifiers spec_local_persist;
|
||||
extern CodeSpecifiers spec_mutable;
|
||||
extern CodeSpecifiers spec_neverinline;
|
||||
extern CodeSpecifiers spec_noexcept;
|
||||
extern CodeSpecifiers spec_override;
|
||||
extern CodeSpecifiers spec_ptr;
|
||||
extern CodeSpecifiers spec_pure;
|
||||
extern CodeSpecifiers spec_ref;
|
||||
extern CodeSpecifiers spec_register;
|
||||
extern CodeSpecifiers spec_rvalue;
|
||||
extern CodeSpecifiers spec_static_member;
|
||||
extern CodeSpecifiers spec_thread_local;
|
||||
extern CodeSpecifiers spec_virtual;
|
||||
extern CodeSpecifiers spec_volatile;
|
||||
|
||||
extern CodeTypename t_empty; // Used with varaidc parameters. (Exposing just in case its useful for another circumstance)
|
||||
extern CodeTypename t_auto;
|
||||
extern CodeTypename t_void;
|
||||
extern CodeTypename t_int;
|
||||
extern CodeTypename t_bool;
|
||||
extern CodeTypename t_char;
|
||||
extern CodeTypename t_wchar_t;
|
||||
extern CodeTypename t_class;
|
||||
extern CodeTypename t_typename;
|
||||
|
||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
// Predefined typename codes. Are set to readonly and are setup during gen::init()
|
||||
extern Context* _ctx;
|
||||
|
||||
extern CodeTypename t_b32;
|
||||
|
||||
extern CodeTypename t_s8;
|
||||
extern CodeTypename t_s16;
|
||||
extern CodeTypename t_s32;
|
||||
extern CodeTypename t_s64;
|
||||
|
||||
extern CodeTypename t_u8;
|
||||
extern CodeTypename t_u16;
|
||||
extern CodeTypename t_u32;
|
||||
extern CodeTypename t_u64;
|
||||
|
||||
extern CodeTypename t_ssize;
|
||||
extern CodeTypename t_usize;
|
||||
|
||||
extern CodeTypename t_f32;
|
||||
extern CodeTypename t_f64;
|
||||
#endif
|
||||
|
||||
#pragma endregion Constants
|
||||
@@ -15,7 +15,7 @@
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
|
||||
! ============================================================================================ |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
|
||||
+328
-8
@@ -1,8 +1,318 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.hpp"
|
||||
#include "constants.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Serialization
|
||||
inline
|
||||
StrBuilder attributes_to_strbuilder(CodeAttributes attributes) {
|
||||
GEN_ASSERT(attributes);
|
||||
char* raw = ccast(char*, str_duplicate( attributes->Content, get_context()->Allocator_Temp ).Ptr);
|
||||
StrBuilder result = { raw };
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void attributes_to_strbuilder_ref(CodeAttributes attributes, StrBuilder* result) {
|
||||
GEN_ASSERT(attributes);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str(result, attributes->Content);
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder comment_to_strbuilder(CodeComment comment) {
|
||||
GEN_ASSERT(comment);
|
||||
char* raw = ccast(char*, str_duplicate( comment->Content, get_context()->Allocator_Temp ).Ptr);
|
||||
StrBuilder result = { raw };
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void body_to_strbuilder_ref( CodeBody body, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(body != nullptr);
|
||||
GEN_ASSERT(result != nullptr);
|
||||
Code curr = body->Front;
|
||||
s32 left = body->NumEntries;
|
||||
while ( left -- )
|
||||
{
|
||||
code_to_strbuilder_ref(curr, result);
|
||||
// strbuilder_append_fmt( result, "%SB", code_to_strbuilder(curr) );
|
||||
curr = curr->Next;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
void comment_to_strbuilder_ref(CodeComment comment, StrBuilder* result) {
|
||||
GEN_ASSERT(comment);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str(result, comment->Content);
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder define_to_strbuilder(CodeDefine define)
|
||||
{
|
||||
GEN_ASSERT(define);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
define_to_strbuilder_ref(define, & result);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder define_params_to_strbuilder(CodeDefineParams params)
|
||||
{
|
||||
GEN_ASSERT(params);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
define_params_to_strbuilder_ref( params, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder exec_to_strbuilder(CodeExec exec)
|
||||
{
|
||||
GEN_ASSERT(exec);
|
||||
char* raw = ccast(char*, str_duplicate( exec->Content, _ctx->Allocator_Temp ).Ptr);
|
||||
StrBuilder result = { raw };
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void exec_to_strbuilder_ref(CodeExec exec, StrBuilder* result) {
|
||||
GEN_ASSERT(exec);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str(result, exec->Content);
|
||||
}
|
||||
|
||||
inline
|
||||
void extern_to_strbuilder(CodeExtern self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->Body )
|
||||
strbuilder_append_fmt( result, "extern \"%S\"\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
|
||||
else
|
||||
strbuilder_append_fmt( result, "extern \"%S\"\n{}\n", self->Name );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder friend_to_strbuilder(CodeFriend self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
|
||||
friend_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void friend_to_strbuilder_ref(CodeFriend self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "friend %SB", code_to_strbuilder(self->Declaration) );
|
||||
|
||||
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* result)[ strbuilder_length(* result) - 1 ] != ';' )
|
||||
{
|
||||
strbuilder_append_str( result, txt(";") );
|
||||
}
|
||||
|
||||
if ( self->InlineCmt )
|
||||
strbuilder_append_fmt( result, " %S", self->InlineCmt->Content );
|
||||
else
|
||||
strbuilder_append_str( result, txt("\n"));
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder include_to_strbuilder(CodeInclude include)
|
||||
{
|
||||
GEN_ASSERT(include);
|
||||
return strbuilder_fmt_buf( _ctx->Allocator_Temp, "#include %S\n", include->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
void include_to_strbuilder_ref( CodeInclude include, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(include);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "#include %S\n", include->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder module_to_strbuilder(CodeModule self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
|
||||
module_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder namespace_to_strbuilder(CodeNS self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 512 );
|
||||
namespace_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void namespace_to_strbuilder_ref(CodeNS self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( bitfield_is_set( u32, self->ModuleFlags, ModuleFlag_Export ))
|
||||
strbuilder_append_str( result, txt("export ") );
|
||||
|
||||
strbuilder_append_fmt( result, "namespace %S\n{\n%SB\n}\n", self->Name, body_to_strbuilder(self->Body) );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder params_to_strbuilder(CodeParams self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
params_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder pragma_to_strbuilder(CodePragma self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 256 );
|
||||
pragma_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void pragma_to_strbuilder_ref(CodePragma self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "#pragma %S\n", self->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
void preprocess_to_strbuilder_if(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "#if %S", cond->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
void preprocess_to_strbuilder_ifdef(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "#ifdef %S\n", cond->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
void preprocess_to_strbuilder_ifndef(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "#ifndef %S", cond->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
void preprocess_to_strbuilder_elif(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_fmt( result, "#elif %S\n", cond->Content );
|
||||
}
|
||||
|
||||
inline
|
||||
void preprocess_to_strbuilder_else(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str( result, txt("#else\n") );
|
||||
}
|
||||
|
||||
inline
|
||||
void preprocess_to_strbuilder_endif(CodePreprocessCond cond, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(cond);
|
||||
GEN_ASSERT(result);
|
||||
strbuilder_append_str( result, txt("#endif\n") );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder specifiers_to_strbuilder(CodeSpecifiers self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 64 );
|
||||
specifiers_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder template_to_strbuilder(CodeTemplate self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 1024 );
|
||||
template_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder typedef_to_strbuilder(CodeTypedef self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
typedef_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder typename_to_strbuilder(CodeTypename self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_str( _ctx->Allocator_Temp, txt("") );
|
||||
typename_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder using_to_strbuilder(CodeUsing self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, 128 );
|
||||
switch ( self->Type )
|
||||
{
|
||||
case CT_Using:
|
||||
using_to_strbuilder_ref( self, & result );
|
||||
break;
|
||||
case CT_Using_Namespace:
|
||||
using_to_strbuilder_ns( self, & result );
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void using_to_strbuilder_ns(CodeUsing self, StrBuilder* result )
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
GEN_ASSERT(result);
|
||||
if ( self->InlineCmt )
|
||||
strbuilder_append_fmt( result, "using namespace $S; %S", self->Name, self->InlineCmt->Content );
|
||||
else
|
||||
strbuilder_append_fmt( result, "using namespace %S;\n", self->Name );
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder var_to_strbuilder(CodeVar self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
StrBuilder result = strbuilder_make_reserve( get_context()->Allocator_Temp, 256 );
|
||||
var_to_strbuilder_ref( self, & result );
|
||||
return result;
|
||||
}
|
||||
#pragma endregion Serialization
|
||||
|
||||
#pragma region Code
|
||||
inline
|
||||
void code_append( Code self, Code other )
|
||||
@@ -74,7 +384,7 @@ bool code_is_valid(Code self)
|
||||
return self != nullptr && self->Type != CT_Invalid;
|
||||
}
|
||||
forceinline
|
||||
bool code_has_entries(AST* self)
|
||||
bool code_has_entries(Code self)
|
||||
{
|
||||
GEN_ASSERT(self);
|
||||
return self->NumEntries > 0;
|
||||
@@ -169,12 +479,12 @@ void class_add_interface( CodeClass self, CodeTypename type )
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot != nullptr )
|
||||
while ( possible_slot->Next != nullptr )
|
||||
{
|
||||
possible_slot = cast(CodeTypename, possible_slot->Next);
|
||||
}
|
||||
|
||||
possible_slot = type;
|
||||
possible_slot->Next = cast(Code, type);
|
||||
}
|
||||
#pragma endregion CodeClass
|
||||
|
||||
@@ -296,7 +606,17 @@ bool specifiers_append(CodeSpecifiers self, Specifier spec )
|
||||
return true;
|
||||
}
|
||||
inline
|
||||
s32 specifiers_has(CodeSpecifiers self, Specifier spec)
|
||||
bool specifiers_has(CodeSpecifiers self, Specifier spec)
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
|
||||
if ( self->ArrSpecs[ idx ] == spec )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
inline
|
||||
s32 specifiers_index_of(CodeSpecifiers self, Specifier spec)
|
||||
{
|
||||
GEN_ASSERT(self != nullptr);
|
||||
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
|
||||
@@ -378,12 +698,12 @@ void struct_add_interface(CodeStruct self, CodeTypename type )
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
while ( possible_slot != nullptr )
|
||||
while ( possible_slot->Next != nullptr )
|
||||
{
|
||||
possible_slot = cast(CodeTypename, possible_slot->Next);
|
||||
}
|
||||
|
||||
possible_slot = type;
|
||||
possible_slot->Next = cast(Code, type);
|
||||
}
|
||||
#pragma endregion Code
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "code_serialization.cpp"
|
||||
#endif
|
||||
|
||||
internal void parser_init();
|
||||
internal void parser_deinit();
|
||||
internal void parser_init(Context* ctx);
|
||||
internal void parser_deinit(Context* ctx);
|
||||
|
||||
internal
|
||||
void* fallback_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
|
||||
@@ -71,6 +71,14 @@ void* fallback_allocator_proc( void* allocator_data, AllocType type, ssize size,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
internal
|
||||
void fallback_logger(LogEntry entry)
|
||||
{
|
||||
GEN_ASSERT(entry.msg.Len > 0);
|
||||
GEN_ASSERT(entry.msg.Ptr);
|
||||
log_fmt("%S: %S", loglevel_to_str(entry.level), entry.msg);
|
||||
}
|
||||
|
||||
internal
|
||||
void define_constants()
|
||||
{
|
||||
@@ -283,6 +291,19 @@ void init(Context* ctx)
|
||||
ctx->InitSize_Fallback_Allocator_Bucket_Size = megabytes(8);
|
||||
}
|
||||
|
||||
if (ctx->InitSize_StrCacheTable == 0)
|
||||
{
|
||||
ctx->InitSize_StrCacheTable = kilobytes(8);
|
||||
}
|
||||
if (ctx->InitSize_MacrosTable == 0)
|
||||
{
|
||||
ctx->InitSize_MacrosTable = kilobytes(8);
|
||||
}
|
||||
|
||||
if (ctx->Logger == nullptr) {
|
||||
ctx->Logger = & fallback_logger;
|
||||
}
|
||||
|
||||
// Override the current context (user has to put it back if unwanted).
|
||||
_ctx = ctx;
|
||||
|
||||
@@ -298,7 +319,7 @@ void init(Context* ctx)
|
||||
}
|
||||
// Setup the code pool and code entries arena.
|
||||
{
|
||||
Pool code_pool = pool_init( ctx->Allocator_Pool, ctx->CodePool_NumBlocks, sizeof(AST) );
|
||||
Pool code_pool = pool_init( ctx->Allocator_Pool, ctx->CodePool_NumBlocks, size_of(AST) );
|
||||
if ( code_pool.PhysicalStart == nullptr )
|
||||
GEN_FATAL( "gen::init: Failed to initialize the code pool" );
|
||||
array_append( ctx->CodePools, code_pool );
|
||||
@@ -311,18 +332,18 @@ void init(Context* ctx)
|
||||
}
|
||||
// Setup the hash tables
|
||||
{
|
||||
ctx->StrCache = hashtable_init(StrCached, ctx->Allocator_DyanmicContainers);
|
||||
ctx->StrCache = hashtable_init_reserve(StrCached, ctx->Allocator_DyanmicContainers, ctx->InitSize_StrCacheTable);
|
||||
if ( ctx->StrCache.Entries == nullptr )
|
||||
GEN_FATAL( "gen::init: Failed to initialize the StringCache");
|
||||
|
||||
ctx->Macros = hashtable_init(Macro, ctx->Allocator_DyanmicContainers);
|
||||
ctx->Macros = hashtable_init_reserve(Macro, ctx->Allocator_DyanmicContainers, ctx->InitSize_MacrosTable);
|
||||
if (ctx->Macros.Hashes == nullptr || ctx->Macros.Entries == nullptr) {
|
||||
GEN_FATAL( "gen::init: Failed to initialize the PreprocessMacros table" );
|
||||
}
|
||||
}
|
||||
|
||||
define_constants();
|
||||
parser_init();
|
||||
parser_init(ctx);
|
||||
|
||||
++ context_counter;
|
||||
}
|
||||
@@ -371,7 +392,7 @@ void deinit(Context* ctx)
|
||||
while ( left--, left );
|
||||
array_free( ctx->Fallback_AllocatorBuckets);
|
||||
}
|
||||
parser_deinit();
|
||||
parser_deinit(ctx);
|
||||
|
||||
if (_ctx == ctx)
|
||||
_ctx = nullptr;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "ast_types.hpp"
|
||||
#endif
|
||||
@@ -15,24 +15,13 @@
|
||||
\▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓
|
||||
*/
|
||||
|
||||
#if 0
|
||||
enum LogLevel : u32
|
||||
struct ParseInfo
|
||||
{
|
||||
Info,
|
||||
Warning,
|
||||
Panic,
|
||||
ParseMessage* messages;
|
||||
LexedInfo lexed;
|
||||
Code result;
|
||||
};
|
||||
|
||||
struct LogEntry
|
||||
{
|
||||
Str msg;
|
||||
u32 line_num;
|
||||
void* data;
|
||||
};
|
||||
|
||||
typedef void LoggerCallback(LogEntry entry);
|
||||
#endif
|
||||
|
||||
// Note(Ed): This is subject to heavily change
|
||||
// with upcoming changes to the library's fallback (default) allocations strategy;
|
||||
// and major changes to lexer/parser context usage.
|
||||
@@ -50,6 +39,7 @@ struct Context
|
||||
|
||||
// LoggerCallaback* log_callback; // TODO(Ed): Impl user logger callback as an option.
|
||||
|
||||
// Initalization config
|
||||
u32 Max_CommentLineLength; // Used by def_comment
|
||||
u32 Max_StrCacheLength; // Any cached string longer than this is always allocated again.
|
||||
|
||||
@@ -63,9 +53,16 @@ struct Context
|
||||
u32 InitSize_LexerTokens;
|
||||
u32 SizePer_StringArena;
|
||||
|
||||
u32 InitSize_StrCacheTable;
|
||||
u32 InitSize_MacrosTable;
|
||||
|
||||
// TODO(Ed): Symbol Table
|
||||
// Keep track of all resolved symbols (naemspaced identifiers)
|
||||
|
||||
// Logging
|
||||
|
||||
LoggerProc* Logger;
|
||||
|
||||
// Parser
|
||||
|
||||
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
|
||||
@@ -88,16 +85,50 @@ struct Context
|
||||
|
||||
StringTable StrCache;
|
||||
|
||||
// TODO(Ed): This needs to be just handled by a parser context
|
||||
Array(Token) Lexer_Tokens;
|
||||
|
||||
// TODO(Ed): Active parse context vs a parse result need to be separated conceptually
|
||||
ParseContext parser;
|
||||
ParseInfo parse_info;
|
||||
|
||||
// TODO(Ed): Formatting - This will eventually be in a separate struct when in the process of serialization of the builder.
|
||||
s32 temp_serialize_indent;
|
||||
};
|
||||
|
||||
// TODO(Ed): Eventually this library should opt out of an implicit context for baseline implementation
|
||||
// This would automatically make it viable for multi-threaded purposes among other things
|
||||
// An implicit context interface will be provided instead as wrapper procedures as convience.
|
||||
GEN_API extern Context* _ctx;
|
||||
|
||||
// TODO(Ed): Swap all usage of this with logger_fmt (then rename logger_fmt to log_fmt)
|
||||
inline
|
||||
ssize log_fmt(char const* fmt, ...)
|
||||
{
|
||||
ssize res;
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
res = c_str_fmt_out_va(fmt, va);
|
||||
va_end(va);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline
|
||||
void logger_fmt(Context* ctx, LogLevel level, char const* fmt, ...)
|
||||
{
|
||||
local_persist thread_local
|
||||
PrintF_Buffer buf = struct_zero_init();
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
ssize res = c_str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va) -1;
|
||||
va_end(va);
|
||||
|
||||
StrBuilder msg = strbuilder_make_length(ctx->Allocator_Temp, buf, res);
|
||||
|
||||
LogEntry entry = { strbuilder_to_str(msg), level };
|
||||
ctx->Logger(entry);
|
||||
}
|
||||
|
||||
// Initialize the library. There first ctx initialized must exist for lifetime of other contextes that come after as its the one that
|
||||
GEN_API void init(Context* ctx);
|
||||
|
||||
@@ -108,7 +139,7 @@ GEN_API void deinit(Context* ctx);
|
||||
// Retrieves the active context (not usually needed, but here in case...)
|
||||
GEN_API Context* get_context();
|
||||
|
||||
// Clears the allocations, but doesn't free the memoery, then calls init() again.
|
||||
// Clears the allocations, but doesn't free the memory, then calls init() again.
|
||||
// Ease of use.
|
||||
GEN_API void reset(Context* ctx);
|
||||
|
||||
@@ -155,6 +186,7 @@ struct Opts_def_struct {
|
||||
CodeAttributes attributes;
|
||||
CodeTypename* interfaces;
|
||||
s32 num_interfaces;
|
||||
CodeSpecifiers specifiers; // Only used for final specifier for now.
|
||||
ModuleFlag mflags;
|
||||
};
|
||||
GEN_API CodeClass def_class( Str name, Opts_def_struct opts GEN_PARAM_DEFAULT );
|
||||
@@ -192,7 +224,7 @@ GEN_API CodeEnum def_enum( Str name, Opts_def_enum opts GEN_PARAM_DEFAULT );
|
||||
|
||||
GEN_API CodeExec def_execution ( Str content );
|
||||
GEN_API CodeExtern def_extern_link( Str name, CodeBody body );
|
||||
GEN_API CodeFriend def_friend ( Code symbol );
|
||||
GEN_API CodeFriend def_friend ( Code code );
|
||||
|
||||
struct Opts_def_function {
|
||||
CodeParams params;
|
||||
@@ -228,7 +260,7 @@ struct Opts_def_operator_cast {
|
||||
GEN_API CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opts GEN_PARAM_DEFAULT );
|
||||
|
||||
struct Opts_def_param { Code value; };
|
||||
GEN_API CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodeParams def_param ( CodeTypename type, Str name, Opts_def_param opts GEN_PARAM_DEFAULT );
|
||||
GEN_API CodePragma def_pragma( Str directive );
|
||||
|
||||
GEN_API CodePreprocessCond def_preprocess_cond( EPreprocessCond type, Str content );
|
||||
@@ -242,7 +274,7 @@ GEN_API CodeTemplate def_template( CodeParams params, Code definition, Opts_def_
|
||||
|
||||
struct Opts_def_type {
|
||||
ETypenameTag type_tag;
|
||||
Code arrayexpr;
|
||||
Code array_expr;
|
||||
CodeSpecifiers specifiers;
|
||||
CodeAttributes attributes;
|
||||
};
|
||||
@@ -278,7 +310,7 @@ struct Opts_def_variable
|
||||
GEN_API CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opts GEN_PARAM_DEFAULT );
|
||||
|
||||
// Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries.
|
||||
GEN_API CodeBody def_body( CodeType type );
|
||||
CodeBody def_body( CodeType type );
|
||||
|
||||
// There are two options for defining a struct body, either varadically provided with the args macro to auto-deduce the arg num,
|
||||
/// or provide as an array of Code objects.
|
||||
@@ -327,37 +359,26 @@ forceinline CodeBody def_union_body ( s32 num, Code* codes )
|
||||
|
||||
#pragma region Parsing
|
||||
|
||||
#if 0
|
||||
struct StackNode
|
||||
struct ParseStackNode
|
||||
{
|
||||
StackNode* Prev;
|
||||
ParseStackNode* prev;
|
||||
|
||||
Token Start;
|
||||
Token Name; // The name of the AST node (if parsed)
|
||||
Str FailedProc; // The name of the procedure that failed
|
||||
};
|
||||
// Stack nodes are allocated the error's allocator
|
||||
|
||||
struct Error
|
||||
{
|
||||
StrBuilder message;
|
||||
StackNode* context_stack;
|
||||
TokenSlice tokens;
|
||||
Token* start;
|
||||
Str name; // The name of the AST node (if parsed)
|
||||
Str proc_name; // The name of the procedure
|
||||
Code code_rel; // Relevant AST node
|
||||
// TODO(Ed): When an error occurs, the parse stack is not released and instead the scope is left dangling.
|
||||
};
|
||||
|
||||
struct ParseInfo
|
||||
struct ParseOpts
|
||||
{
|
||||
Arena FileMem;
|
||||
Arena TokMem;
|
||||
Arena CodeMem;
|
||||
|
||||
FileContents FileContent;
|
||||
Array<Token> Tokens;
|
||||
Array<Error> Errors;
|
||||
// Errors are allocated to a dedicated general arena.
|
||||
AllocatorInfo backing_msgs;
|
||||
AllocatorInfo backing_tokens;
|
||||
AllocatorInfo backing_ast;
|
||||
};
|
||||
|
||||
CodeBody parse_file( Str path );
|
||||
#endif
|
||||
ParseInfo wip_parse_str( LexedInfo lexed, ParseOpts* opts GEN_PARAM_DEFAULT );
|
||||
|
||||
GEN_API CodeClass parse_class ( Str class_def );
|
||||
GEN_API CodeConstructor parse_constructor ( Str constructor_def );
|
||||
@@ -368,7 +389,15 @@ GEN_API CodeBody parse_export_body ( Str export_def );
|
||||
GEN_API CodeExtern parse_extern_link ( Str exten_link_def );
|
||||
GEN_API CodeFriend parse_friend ( Str friend_def );
|
||||
GEN_API CodeFn parse_function ( Str fn_def );
|
||||
GEN_API CodeBody parse_global_body ( Str body_def );
|
||||
|
||||
struct Opts_parse_global_body
|
||||
{
|
||||
Context* ctx;
|
||||
ParseInfo* info;
|
||||
};
|
||||
GEN_API void parse_global_body_base( Context* ctx, Str body_def, ParseInfo* info );
|
||||
GEN_API CodeBody parse_global_body( Str body_def, Opts_parse_global_body opts GEN_PARAM_DEFAULT );
|
||||
|
||||
GEN_API CodeNS parse_namespace ( Str namespace_def );
|
||||
GEN_API CodeOperator parse_operator ( Str operator_def );
|
||||
GEN_API CodeOpCast parse_operator_cast( Str operator_def );
|
||||
@@ -386,11 +415,12 @@ GEN_API CodeVar parse_variable ( Str var_def );
|
||||
|
||||
GEN_API ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va );
|
||||
//! Do not use directly. Use the token_fmt macro instead.
|
||||
GEN_API Str token_fmt_impl( ssize, ... );
|
||||
Str token_fmt_impl( ssize, ... );
|
||||
|
||||
GEN_API Code untyped_str( Str content);
|
||||
GEN_API Code untyped_str ( Str content);
|
||||
GEN_API Code untyped_fmt ( char const* fmt, ... );
|
||||
GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
|
||||
GEN_API Code untyped_toks ( TokenSlice tokens );
|
||||
|
||||
#pragma endregion Untyped text
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "gen/etoktype.cpp"
|
||||
#include "gen/etoktype.hpp"
|
||||
#include "interface.upfront.cpp"
|
||||
#include "lexer.cpp"
|
||||
#include "parser.cpp"
|
||||
@@ -8,28 +8,95 @@
|
||||
|
||||
// Publically Exposed Interface
|
||||
|
||||
ParseInfo wip_parse_str(LexedInfo lexed, ParseOpts* opts)
|
||||
{
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
ParseInfo info = struct_zero(ParseInfo);
|
||||
|
||||
if (lexed.tokens.num == 0 && lexed.tokens.ptr == nullptr) {
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(lexed.text) == false) {
|
||||
info.messages = ctx->parser.messages;
|
||||
goto done;
|
||||
}
|
||||
lexed = lex(ctx, lexed.text);
|
||||
}
|
||||
info.lexed = lexed;
|
||||
|
||||
// TODO(Ed): ParseInfo should be set to the parser context.
|
||||
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
|
||||
{
|
||||
ParseStackNode scope = NullScope;
|
||||
parser_push(& ctx->parser, & scope);
|
||||
|
||||
CodeBody result = parse_global_nspace(ctx,CT_Global_Body);
|
||||
(void)result;
|
||||
|
||||
parser_pop(& ctx->parser);
|
||||
}
|
||||
done:
|
||||
return info;
|
||||
}
|
||||
|
||||
CodeClass parse_class( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeClass result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
push_scope();
|
||||
CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class, parser_not_inplace_def );
|
||||
parser_pop(& _ctx->parser);
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
{
|
||||
ParseStackNode scope = NullScope;
|
||||
parser_push(& ctx->parser, & scope);
|
||||
result = (CodeClass) parse_class_struct( ctx, Tok_Decl_Class, parser_not_inplace_def );
|
||||
parser_pop(& ctx->parser);
|
||||
}
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeConstructor parse_constructor( Str def )
|
||||
CodeConstructor parse_constructor(Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeConstructor result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
{
|
||||
ParseStackNode scope = NullScope;
|
||||
parser_push(& ctx->parser, & scope);
|
||||
|
||||
// TODO(Ed): Constructors can have prefix attributes
|
||||
|
||||
@@ -57,9 +124,9 @@ CodeConstructor parse_constructor( Str def )
|
||||
break;
|
||||
|
||||
default :
|
||||
log_failure( "Invalid specifier %s for variable\n%S", spec_to_str( spec ), parser_to_strbuilder(_ctx->parser) );
|
||||
parser_pop(& _ctx->parser);
|
||||
return InvalidCode;
|
||||
log_failure( "Invalid specifier %s for variable\n%S", spec_to_str( spec ), parser_to_strbuilder(& ctx->parser, ctx->Allocator_Temp) );
|
||||
parser_pop(& ctx->parser);
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Every specifier after would be considered part of the type type signature
|
||||
@@ -71,247 +138,526 @@ CodeConstructor parse_constructor( Str def )
|
||||
eat( currtok.Type );
|
||||
}
|
||||
|
||||
if ( NumSpecifiers )
|
||||
{
|
||||
if ( NumSpecifiers ) {
|
||||
specifiers = def_specifiers_arr( NumSpecifiers, specs_found );
|
||||
// <specifiers> ...
|
||||
}
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
CodeConstructor result = parser_parse_constructor( specifiers );
|
||||
result = parser_parse_constructor(ctx, specifiers);
|
||||
parser_pop(& ctx->parser);
|
||||
}
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDefine parse_define( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeDefine result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
push_scope();
|
||||
CodeDefine result = parser_parse_define();
|
||||
parser_pop(& _ctx->parser);
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
{
|
||||
ParseStackNode scope = NullScope;
|
||||
parser_push(& ctx->parser, & scope);
|
||||
result = parser_parse_define(ctx);
|
||||
parser_pop(& ctx->parser);
|
||||
}
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDestructor parse_destructor( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeDestructor result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
// TODO(Ed): Destructors can have prefix attributes
|
||||
// TODO(Ed): Destructors can have virtual
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
CodeDestructor result = parser_parse_destructor(NullCode);
|
||||
result = parser_parse_destructor(ctx, NullCode);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeEnum parse_enum( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeEnum result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
{
|
||||
parser_pop(& _ctx->parser);
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_enum( parser_not_inplace_def);
|
||||
result = parser_parse_enum(ctx, parser_not_inplace_def);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody parse_export_body( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeBody result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_export_body();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_export_body(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeExtern parse_extern_link( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeExtern result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_extern_link();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_extern_link(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeFriend parse_friend( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeFriend result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_friend();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_friend(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeFn parse_function( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeFn result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return (CodeFn) parser_parse_function();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = (CodeFn) parser_parse_function(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody parse_global_body( Str def )
|
||||
void parse_global_body_base( Context* ctx, Str def, ParseInfo* info )
|
||||
{
|
||||
check_parse_args( def );
|
||||
LexedInfo lexed;
|
||||
CodeBody body;
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
if ( ctx == nullptr || info == nullptr )
|
||||
GEN_FATAL( "parse_global_body_base: null context or info" );
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
push_scope();
|
||||
CodeBody result = parse_global_nspace( CT_Global_Body );
|
||||
parser_pop(& _ctx->parser);
|
||||
return result;
|
||||
info[0] = struct_zero( ParseInfo );
|
||||
lexed = struct_zero( LexedInfo );
|
||||
body = (CodeBody) make_code();
|
||||
body->Type = CT_Global_Body;
|
||||
|
||||
ctx->parser = struct_zero( ParseContext );
|
||||
if ( check_parse_args( def ) == false ) {
|
||||
info->result = cast( Code, body );
|
||||
info->messages = ctx->parser.messages;
|
||||
return;
|
||||
}
|
||||
|
||||
lexed = lex( ctx, def );
|
||||
info->lexed = lexed;
|
||||
if ( lexed.tokens.num == 0 ) {
|
||||
info->result = cast( Code, body );
|
||||
info->messages = ctx->parser.messages;
|
||||
return;
|
||||
}
|
||||
|
||||
ctx->parser.tokens = lexed.tokens; {
|
||||
ParseStackNode scope = NullScope;
|
||||
parser_push( & ctx->parser, & scope );
|
||||
body = parse_global_nspace( ctx, CT_Global_Body );
|
||||
parser_pop( & ctx->parser );
|
||||
}
|
||||
info->result = cast( Code, body );
|
||||
info->messages = ctx->parser.messages;
|
||||
}
|
||||
|
||||
CodeBody parse_global_body( Str def, Opts_parse_global_body opts ) {
|
||||
Opts_parse_global_body resolved = get_optional( opts );
|
||||
Context* ctx = resolved.ctx;
|
||||
ParseInfo* info;
|
||||
|
||||
if ( ctx == nullptr ) ctx = _ctx;
|
||||
if ( ctx == nullptr ) GEN_FATAL( "parse_global_body: no context" );
|
||||
info = resolved.info; if ( info == nullptr ) info = & ctx->parse_info;
|
||||
|
||||
parse_global_body_base( ctx, def, info );
|
||||
return cast( CodeBody, info->result );
|
||||
}
|
||||
|
||||
CodeNS parse_namespace( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeNS result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_namespace();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_namespace(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeOperator parse_operator( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeOperator result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return (CodeOperator) parser_parse_operator();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = (CodeOperator) parser_parse_operator(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeOpCast parse_operator_cast( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeOpCast result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_operator_cast(NullCode);
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_operator_cast(ctx, NullCode);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeStruct parse_struct( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeStruct result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
push_scope();
|
||||
CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct, parser_not_inplace_def );
|
||||
parser_pop(& _ctx->parser);
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
{
|
||||
ParseStackNode scope = NullScope;
|
||||
parser_push(& ctx->parser, & scope);
|
||||
result = (CodeStruct) parse_class_struct( ctx, Tok_Decl_Struct, parser_not_inplace_def );
|
||||
parser_pop(& ctx->parser);
|
||||
}
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTemplate parse_template( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeTemplate result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_template();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_template(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTypename parse_type( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeTypename result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_type( parser_not_from_template, nullptr);
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_type( ctx, parser_not_from_template, nullptr);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTypedef parse_typedef( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeTypedef result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_typedef();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_typedef(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeUnion parse_union( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeUnion result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_union( parser_not_inplace_def);
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_union(ctx, parser_not_inplace_def);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeUsing parse_using( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeUsing result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_using();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_using(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeVar parse_variable( Str def )
|
||||
{
|
||||
check_parse_args( def );
|
||||
// TODO(Ed): Lift this.
|
||||
Context* ctx = _ctx;
|
||||
CodeVar result = InvalidCode;
|
||||
LexedInfo lexed = struct_zero(LexedInfo);
|
||||
|
||||
TokArray toks = lex( def );
|
||||
if ( toks.Arr == nullptr )
|
||||
return InvalidCode;
|
||||
ctx->parser = struct_zero(ParseContext);
|
||||
if (check_parse_args(def) == false)
|
||||
goto done;
|
||||
|
||||
_ctx->parser.Tokens = toks;
|
||||
return parser_parse_variable();
|
||||
lexed = lex(ctx, def);
|
||||
ctx->parser.tokens = lexed.tokens;
|
||||
if (lexed.messages != nullptr || ctx->parser.tokens.num == 0) {
|
||||
if (lexed.messages != nullptr && lexed.messages->content.Ptr != nullptr)
|
||||
parser_record_failure(ctx, lexed.messages->content);
|
||||
else
|
||||
parser_record_failure(ctx, txt("parse: lex produced no tokens"));
|
||||
goto done;
|
||||
}
|
||||
if (parser_slice_is_formatting_only(&ctx->parser)) {
|
||||
parser_record_failure(ctx, txt("parse_variable: only formatting tokens"));
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = parser_parse_variable(ctx);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
// Undef helper macros
|
||||
@@ -326,6 +672,7 @@ CodeVar parse_variable( Str def )
|
||||
#undef left
|
||||
#undef check
|
||||
#undef push_scope
|
||||
#undef NullScope
|
||||
#undef def_assign
|
||||
|
||||
// Here for C Variant
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.parsing.cpp"
|
||||
#endif
|
||||
@@ -176,3 +176,16 @@ Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... )
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Code untyped_toks( TokenSlice tokens )
|
||||
{
|
||||
if ( tokens.num == 0 ) {
|
||||
log_failure( "untyped_toks: empty token slice" );
|
||||
return InvalidCode;
|
||||
}
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = CT_Untyped;
|
||||
result->ContentToks = tokens;
|
||||
return result;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.cpp"
|
||||
#endif
|
||||
@@ -402,7 +402,7 @@ bool null__check( char const* context, char const* code_id, Code code ) {
|
||||
#define null_check( context, code ) null__check( #context, #code, cast(Code, code) )
|
||||
|
||||
/*
|
||||
The implementaiton of the upfront constructors involves doing three things:
|
||||
The implementation 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.
|
||||
@@ -473,8 +473,10 @@ CodeComment def_comment( Str content )
|
||||
return (CodeComment) result;
|
||||
}
|
||||
|
||||
CodeConstructor def_constructor( Opts_def_constructor p )
|
||||
CodeConstructor def_constructor( Opts_def_constructor opt )
|
||||
{
|
||||
Opts_def_constructor p = get_optional(opt);
|
||||
|
||||
if ( p.params && p.params->Type != CT_Parameters ) {
|
||||
log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)p.params));
|
||||
GEN_DEBUG_TRAP();
|
||||
@@ -510,8 +512,10 @@ CodeConstructor def_constructor( Opts_def_constructor p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeClass def_class( Str name, Opts_def_struct p )
|
||||
CodeClass def_class( Str name, Opts_def_struct opt )
|
||||
{
|
||||
Opts_def_struct p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_class, name ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -532,6 +536,7 @@ CodeClass def_class( Str name, Opts_def_struct p )
|
||||
result->Name = cache_str( name );
|
||||
result->ModuleFlags = p.mflags;
|
||||
result->Attributes = p.attributes;
|
||||
result->Specs = p.specifiers;
|
||||
result->ParentAccess = p.parent_access;
|
||||
result->ParentType = p.parent;
|
||||
if ( p.body )
|
||||
@@ -560,8 +565,10 @@ CodeClass def_class( Str name, Opts_def_struct p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDefine def_define( Str name, MacroType type, Opts_def_define p )
|
||||
CodeDefine def_define( Str name, MacroType type, Opts_def_define opt )
|
||||
{
|
||||
Opts_def_define p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_define, name ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -584,8 +591,10 @@ CodeDefine def_define( Str name, MacroType type, Opts_def_define p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeDestructor def_destructor( Opts_def_destructor p )
|
||||
CodeDestructor def_destructor( Opts_def_destructor opt )
|
||||
{
|
||||
Opts_def_destructor p = get_optional(opt);
|
||||
|
||||
if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) {
|
||||
log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", code_debug_str(p.specifiers) );
|
||||
GEN_DEBUG_TRAP();
|
||||
@@ -618,8 +627,10 @@ CodeDestructor def_destructor( Opts_def_destructor p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeEnum def_enum( Str name, Opts_def_enum p )
|
||||
CodeEnum def_enum( Str name, Opts_def_enum opt )
|
||||
{
|
||||
Opts_def_enum p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_enum, name ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -741,8 +752,10 @@ CodeFriend def_friend( Code declaration )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeFn def_function( Str name, Opts_def_function p )
|
||||
CodeFn def_function( Str name, Opts_def_function opt )
|
||||
{
|
||||
Opts_def_function p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_function, name )) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -801,8 +814,10 @@ CodeFn def_function( Str name, Opts_def_function p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeInclude def_include( Str path, Opts_def_include p )
|
||||
CodeInclude def_include( Str path, Opts_def_include opt )
|
||||
{
|
||||
Opts_def_include p = get_optional(opt);
|
||||
|
||||
if ( path.Len <= 0 || path.Ptr == nullptr ) {
|
||||
log_failure( "gen::def_include: Invalid path provided - %d" );
|
||||
GEN_DEBUG_TRAP();
|
||||
@@ -820,8 +835,10 @@ CodeInclude def_include( Str path, Opts_def_include p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeModule def_module( Str name, Opts_def_module p )
|
||||
CodeModule def_module( Str name, Opts_def_module opt )
|
||||
{
|
||||
Opts_def_module p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_module, name )) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -834,8 +851,10 @@ CodeModule def_module( Str name, Opts_def_module p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace p )
|
||||
CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace opt )
|
||||
{
|
||||
Opts_def_namespace p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_namespace, name )) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -858,8 +877,10 @@ CodeNS def_namespace( Str name, CodeBody body, Opts_def_namespace p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator p )
|
||||
CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator opt )
|
||||
{
|
||||
Opts_def_operator p = get_optional(opt);
|
||||
|
||||
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
||||
log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", code_debug_str(p.attributes) );
|
||||
GEN_DEBUG_TRAP();
|
||||
@@ -925,8 +946,10 @@ CodeOperator def_operator( Operator op, Str nspace, Opts_def_operator p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
||||
CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast opt )
|
||||
{
|
||||
Opts_def_operator_cast p = get_optional(opt);
|
||||
|
||||
if ( ! null_check( def_operator_cast, type )) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -958,8 +981,10 @@ CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeParams def_param( CodeTypename type, Str name, Opts_def_param p )
|
||||
CodeParams def_param( CodeTypename type, Str name, Opts_def_param opt )
|
||||
{
|
||||
Opts_def_param p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_param, name ) || ! null_check( def_param, type ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -1033,8 +1058,10 @@ CodeSpecifiers def_specifier( Specifier spec )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeStruct def_struct( Str name, Opts_def_struct p )
|
||||
CodeStruct def_struct( Str name, Opts_def_struct opt )
|
||||
{
|
||||
Opts_def_struct p = get_optional(opt);
|
||||
|
||||
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
||||
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, p.attributes)) );
|
||||
GEN_DEBUG_TRAP();
|
||||
@@ -1065,6 +1092,7 @@ CodeStruct def_struct( Str name, Opts_def_struct p )
|
||||
result->Type = CT_Struct_Fwd;
|
||||
}
|
||||
result->Attributes = p.attributes;
|
||||
result->Specs = p.specifiers;
|
||||
result->ParentAccess = p.parent_access;
|
||||
result->ParentType = p.parent;
|
||||
|
||||
@@ -1074,8 +1102,10 @@ CodeStruct def_struct( Str name, Opts_def_struct p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template p )
|
||||
CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template opt )
|
||||
{
|
||||
Opts_def_template p = get_optional(opt);
|
||||
|
||||
if ( ! null_check( def_template, declaration ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -1106,13 +1136,15 @@ CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_templat
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTypename def_type( Str name, Opts_def_type p )
|
||||
CodeTypename def_type( Str name, Opts_def_type opt )
|
||||
{
|
||||
Opts_def_type p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_type, name )) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
}
|
||||
Code arrayexpr = p.arrayexpr;
|
||||
Code array_expr = p.array_expr;
|
||||
CodeSpecifiers specifiers = p.specifiers;
|
||||
CodeAttributes attributes = p.attributes;
|
||||
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) {
|
||||
@@ -1125,8 +1157,8 @@ CodeTypename def_type( Str name, Opts_def_type p )
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
}
|
||||
if ( p.arrayexpr && p.arrayexpr->Type != CT_Untyped ) {
|
||||
log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)p.arrayexpr) );
|
||||
if ( p.array_expr && p.array_expr->Type != CT_Untyped ) {
|
||||
log_failure( "gen::def_type: arrayexpr is not of untyped type - %S", code_debug_str((Code)p.array_expr) );
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
}
|
||||
@@ -1136,13 +1168,15 @@ CodeTypename def_type( Str name, Opts_def_type p )
|
||||
result->Type = CT_Typename;
|
||||
result->Attributes = p.attributes;
|
||||
result->Specs = p.specifiers;
|
||||
result->ArrExpr = p.arrayexpr;
|
||||
result->ArrExpr = p.array_expr;
|
||||
result->TypeTag = p.type_tag;
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef p )
|
||||
CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef opt )
|
||||
{
|
||||
Opts_def_typedef p = get_optional(opt);
|
||||
|
||||
if ( ! null_check( def_typedef, type ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -1184,6 +1218,7 @@ CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef p )
|
||||
result = (CodeTypedef) make_code();
|
||||
result->Type = CT_Typedef;
|
||||
result->ModuleFlags = p.mflags;
|
||||
result->Attributes = p.attributes;
|
||||
result->UnderlyingType = type;
|
||||
|
||||
if ( name.Len <= 0 )
|
||||
@@ -1204,8 +1239,10 @@ CodeTypedef def_typedef( Str name, Code type, Opts_def_typedef p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeUnion def_union( Str name, CodeBody body, Opts_def_union p )
|
||||
CodeUnion def_union( Str name, CodeBody body, Opts_def_union opt )
|
||||
{
|
||||
Opts_def_union p = get_optional(opt);
|
||||
|
||||
if ( ! null_check( def_union, body ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
@@ -1231,9 +1268,11 @@ CodeUnion def_union( Str name, CodeBody body, Opts_def_union p )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using p )
|
||||
CodeUsing def_using( Str name, CodeTypename type, Opts_def_using opt )
|
||||
{
|
||||
if ( ! name_check( def_using, name ) || null_check( def_using, type ) ) {
|
||||
Opts_def_using p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_using, name ) || ! null_check( def_using, type ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
}
|
||||
@@ -1272,8 +1311,10 @@ CodeUsing def_using_namespace( Str name )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable p )
|
||||
CodeVar def_variable( CodeTypename type, Str name, Opts_def_variable opt )
|
||||
{
|
||||
Opts_def_variable p = get_optional(opt);
|
||||
|
||||
if ( ! name_check( def_variable, name ) || ! null_check( def_variable, type ) ) {
|
||||
GEN_DEBUG_TRAP();
|
||||
return InvalidCode;
|
||||
|
||||
+184
-149
@@ -1,14 +1,12 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "interface.upfront.cpp"
|
||||
#include "gen/etoktype.cpp"
|
||||
#include "gen/etoktype.hpp"
|
||||
#endif
|
||||
|
||||
StrBuilder tok_to_strbuilder(Token tok)
|
||||
{
|
||||
StrBuilder result = strbuilder_make_reserve( _ctx->Allocator_Temp, kilobytes(4) );
|
||||
StrBuilder tok_to_strbuilder(AllocatorInfo ainfo, Token tok) {
|
||||
StrBuilder result = strbuilder_make_reserve( ainfo, kilobytes(4) );
|
||||
Str type_str = toktype_to_str( tok.Type );
|
||||
|
||||
strbuilder_append_fmt( & result, "Line: %d Column: %d, Type: %.*s Content: %.*s"
|
||||
, tok.Line, tok.Column
|
||||
, type_str.Len, type_str.Ptr
|
||||
@@ -17,59 +15,70 @@ StrBuilder tok_to_strbuilder(Token tok)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool lex__eat( TokArray* self, TokType type );
|
||||
bool lex__eat(Context* ctx, ParseContext* self, TokType type );
|
||||
|
||||
Token* lex_current(TokArray* self, bool skip_formatting )
|
||||
{
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( self->Arr[self->Idx].Type == Tok_NewLine || self->Arr[self->Idx].Type == Tok_Comment )
|
||||
self->Idx++;
|
||||
}
|
||||
return & self->Arr[self->Idx];
|
||||
forceinline
|
||||
b32 lex_index_in_range(ParseContext const* self, s32 idx) {
|
||||
return self->tokens.ptr != nullptr
|
||||
&& idx >= 0
|
||||
&& idx < self->tokens.num;
|
||||
}
|
||||
|
||||
Token* lex_peek(TokArray self, bool skip_formatting)
|
||||
{
|
||||
s32 idx = self.Idx;
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( self.Arr[idx].Type == Tok_NewLine )
|
||||
idx++;
|
||||
|
||||
return & self.Arr[idx];
|
||||
}
|
||||
return & self.Arr[idx];
|
||||
forceinline
|
||||
Token* lex_token_at(ParseContext const* self, s32 idx) {
|
||||
Token* result = & NullToken;
|
||||
if (lex_index_in_range(self, idx)) result = & self->tokens.ptr[idx];
|
||||
return result;
|
||||
}
|
||||
|
||||
Token* lex_previous(TokArray self, bool skip_formatting)
|
||||
{
|
||||
s32 idx = self.Idx;
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( self.Arr[idx].Type == Tok_NewLine )
|
||||
idx --;
|
||||
|
||||
return & self.Arr[idx];
|
||||
Token* lex_current(ParseContext* self, bool skip_formatting) {
|
||||
if (skip_formatting) while (lex_index_in_range(self, self->token_id)) {
|
||||
TokType type = self->tokens.ptr[self->token_id].Type;
|
||||
if (type != Tok_NewLine && type != Tok_Comment) break;
|
||||
++ self->token_id;
|
||||
}
|
||||
return & self.Arr[idx - 1];
|
||||
return lex_token_at(self, self->token_id);
|
||||
}
|
||||
|
||||
Token* lex_next(TokArray self, bool skip_formatting)
|
||||
{
|
||||
s32 idx = self.Idx;
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( self.Arr[idx].Type == Tok_NewLine )
|
||||
idx++;
|
||||
|
||||
return & self.Arr[idx + 1];
|
||||
Token* lex_peek(ParseContext const* self, bool skip_formatting) {
|
||||
s32 idx = self->token_id;
|
||||
if (skip_formatting) {
|
||||
while (lex_index_in_range(self, idx) && self->tokens.ptr[idx].Type == Tok_NewLine)
|
||||
++ idx;
|
||||
}
|
||||
return & self.Arr[idx + 1];
|
||||
return lex_token_at(self, idx);
|
||||
}
|
||||
|
||||
enum
|
||||
Token* lex_previous(ParseContext const* self, bool skip_formatting)
|
||||
{
|
||||
Token* result = & NullToken;
|
||||
s32 idx = self->token_id;
|
||||
if (skip_formatting)
|
||||
{
|
||||
if (self->tokens.num > 0 && idx >= self->tokens.num)
|
||||
idx = self->tokens.num - 1;
|
||||
while (lex_index_in_range(self, idx) && self->tokens.ptr[idx].Type == Tok_NewLine && idx > 0)
|
||||
-- idx;
|
||||
if (lex_index_in_range(self, idx) && self->tokens.ptr[idx].Type != Tok_NewLine)
|
||||
result = &self->tokens.ptr[idx];
|
||||
goto done;
|
||||
}
|
||||
if (self->tokens.num > 0 && idx >= self->tokens.num) result = lex_token_at(self, self->tokens.num - 1);
|
||||
else result = lex_token_at(self, idx - 1);
|
||||
done:
|
||||
return result;
|
||||
}
|
||||
|
||||
Token* lex_next(ParseContext const* self, bool skip_formatting) {
|
||||
s32 idx = self->token_id;
|
||||
if (skip_formatting) {
|
||||
while (lex_index_in_range(self, idx) && self->tokens.ptr[idx].Type == Tok_NewLine)
|
||||
-- idx;
|
||||
}
|
||||
return lex_token_at(self, idx + 1);
|
||||
}
|
||||
|
||||
enum {
|
||||
Lex_Continue,
|
||||
Lex_ReturnNull,
|
||||
};
|
||||
@@ -90,19 +99,16 @@ void lexer_move_forward( LexContext* ctx )
|
||||
#define move_forward() lexer_move_forward(ctx)
|
||||
|
||||
forceinline
|
||||
void lexer_skip_whitespace( LexContext* ctx )
|
||||
{
|
||||
void lexer_skip_whitespace( LexContext* ctx ) {
|
||||
while ( ctx->left && char_is_space( * ctx->scanner ) )
|
||||
move_forward();
|
||||
}
|
||||
#define skip_whitespace() lexer_skip_whitespace(ctx)
|
||||
|
||||
forceinline
|
||||
void lexer_end_line( LexContext* ctx )
|
||||
{
|
||||
void lexer_end_line( LexContext* ctx ) {
|
||||
while ( ctx->left && (* ctx->scanner) == ' ' )
|
||||
move_forward();
|
||||
|
||||
if ( ctx->left && (* ctx->scanner) == '\r' ) {
|
||||
move_forward();
|
||||
move_forward();
|
||||
@@ -113,7 +119,9 @@ void lexer_end_line( LexContext* ctx )
|
||||
#define end_line() lexer_end_line(ctx)
|
||||
|
||||
// TODO(Ed): We need to to attempt to recover from a lex failure?
|
||||
s32 lex_preprocessor_define( LexContext* ctx )
|
||||
internal void lexer_record_failure_fmt(Context* lib_ctx, LexContext* ctx, char const* fmt, ...);
|
||||
|
||||
s32 lex_preprocessor_define(Context* lib_ctx, LexContext* ctx)
|
||||
{
|
||||
Token name = { { ctx->scanner, 1 }, Tok_Identifier, ctx->line, ctx->column, TF_Preprocess };
|
||||
move_forward();
|
||||
@@ -137,7 +145,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
);
|
||||
// GEN_DEBUG_TRAP();
|
||||
}
|
||||
array_append( _ctx->Lexer_Tokens, name );
|
||||
array_append(ctx->tokens, name);
|
||||
|
||||
if ( ctx->left && (* ctx->scanner) == '(' )
|
||||
{
|
||||
@@ -152,7 +160,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
}
|
||||
|
||||
Token opening_paren = { { ctx->scanner, 1 }, Tok_Paren_Open, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append( _ctx->Lexer_Tokens, opening_paren );
|
||||
array_append(ctx->tokens, opening_paren);
|
||||
move_forward();
|
||||
|
||||
Token last_parameter = {};
|
||||
@@ -168,7 +176,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
move_forward();
|
||||
move_forward();
|
||||
|
||||
array_append(_ctx->Lexer_Tokens, parameter);
|
||||
array_append(ctx->tokens, parameter);
|
||||
skip_whitespace();
|
||||
last_parameter = parameter;
|
||||
|
||||
@@ -178,7 +186,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
}
|
||||
if (* ctx->scanner != ')' )
|
||||
{
|
||||
log_failure("lex_preprocessor_define(%d, %d): Expected a ')' after '...' (varaidc macro param) %S\n"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "lex_preprocessor_define(%d, %d): Expected a ')' after '...' (varaidc macro param) %S\n"
|
||||
, ctx->line
|
||||
, ctx->column
|
||||
, name.Text
|
||||
@@ -202,12 +210,12 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
move_forward();
|
||||
parameter.Text.Len++;
|
||||
}
|
||||
array_append(_ctx->Lexer_Tokens, parameter);
|
||||
array_append(ctx->tokens, parameter);
|
||||
skip_whitespace();
|
||||
last_parameter = parameter;
|
||||
}
|
||||
else {
|
||||
log_failure("lex_preprocessor_define(%d, %d): Expected a '_' or alpha character for a parameter name for %S\n"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "lex_preprocessor_define(%d, %d): Expected a '_' or alpha character for a parameter name for %S\n"
|
||||
, ctx->line
|
||||
, ctx->column
|
||||
, name.Text
|
||||
@@ -220,7 +228,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
|
||||
// There should be a comma
|
||||
if ( * ctx->scanner != ',' ) {
|
||||
log_failure("lex_preprocessor_define(%d, %d): Expected a comma after parameter %S for %S\n"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "lex_preprocessor_define(%d, %d): Expected a comma after parameter %S for %S\n"
|
||||
, ctx->line
|
||||
, ctx->column
|
||||
, last_parameter.Text
|
||||
@@ -229,12 +237,12 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
return Lex_ReturnNull;
|
||||
}
|
||||
Token comma = { { ctx->scanner, 1 }, Tok_Comma, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append(_ctx->Lexer_Tokens, comma);
|
||||
array_append(ctx->tokens, comma);
|
||||
move_forward();
|
||||
}
|
||||
|
||||
if ( * ctx->scanner != ')' ) {
|
||||
log_failure("lex_preprocessor_define(%d, %d): Expected a ')' after last_parameter %S for %S (ran out of characters...)\n"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "lex_preprocessor_define(%d, %d): Expected a ')' after last_parameter %S for %S (ran out of characters...)\n"
|
||||
, ctx->line
|
||||
, ctx->column
|
||||
, last_parameter.Text
|
||||
@@ -243,7 +251,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
return Lex_ReturnNull;
|
||||
}
|
||||
Token closing_paren = { { ctx->scanner, 1 }, Tok_Paren_Close, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append(_ctx->Lexer_Tokens, closing_paren);
|
||||
array_append(ctx->tokens, closing_paren);
|
||||
move_forward();
|
||||
}
|
||||
else if ( registered_macro && macro_is_functional( * registered_macro) ) {
|
||||
@@ -264,12 +272,11 @@ s32 lex_preprocessor_define( LexContext* ctx )
|
||||
}
|
||||
|
||||
// TODO(Ed): We need to to attempt to recover from a lex failure?
|
||||
forceinline
|
||||
s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
s32 lex_preprocessor_directive(Context* lib_ctx, LexContext* ctx)
|
||||
{
|
||||
char const* hash = ctx->scanner;
|
||||
Token hash_tok = { { hash, 1 }, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess };
|
||||
array_append( _ctx->Lexer_Tokens, hash_tok );
|
||||
array_append(ctx->tokens, hash_tok);
|
||||
|
||||
move_forward();
|
||||
skip_whitespace();
|
||||
@@ -318,11 +325,11 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
}
|
||||
else
|
||||
{
|
||||
log_failure( "gen::Parser::lex: Invalid escape sequence '\\%c' (%d, %d)"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "gen::Parser::lex: Invalid escape sequence '\\%c' (%d, %d)"
|
||||
" in preprocessor directive (%d, %d)\n%.100s"
|
||||
, (* ctx->scanner), ctx->line, ctx->column
|
||||
, ctx->token.Line, ctx->token.Column, ctx->token.Text );
|
||||
break;
|
||||
return Lex_ReturnNull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,14 +352,14 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
|
||||
ctx->token.Text.Len = ctx->token.Text.Len + ctx->token.Text.Ptr - hash;
|
||||
ctx->token.Text.Ptr = hash;
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
return Lex_Continue; // Skip found token, its all handled here.
|
||||
}
|
||||
|
||||
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf )
|
||||
{
|
||||
ctx->token.Flags |= TF_Preprocess_Cond;
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
end_line();
|
||||
return Lex_Continue;
|
||||
}
|
||||
@@ -361,13 +368,13 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
ctx->token.Flags |= TF_Preprocess_Cond;
|
||||
}
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
|
||||
skip_whitespace();
|
||||
|
||||
if ( ctx->token.Type == Tok_Preprocess_Define )
|
||||
{
|
||||
u32 result = lex_preprocessor_define(ctx); // handles: #define <name>( <params> ) - define's content handled later on within this scope.
|
||||
u32 result = lex_preprocessor_define(lib_ctx, ctx); // handles: #define <name>( <params> ) - define's content handled later on within this scope.
|
||||
if (result != Lex_Continue)
|
||||
return Lex_ReturnNull;
|
||||
}
|
||||
@@ -380,9 +387,9 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
|
||||
if ( (* ctx->scanner) != '"' && (* ctx->scanner) != '<' )
|
||||
{
|
||||
StrBuilder directive_str = strbuilder_fmt_buf( _ctx->Allocator_Temp, "%.*s", min( 80, ctx->left + preprocess_content.Text.Len ), ctx->token.Text.Ptr );
|
||||
StrBuilder directive_str = strbuilder_fmt_buf( ctx->allocator_temp, "%.*s", min( 80, ctx->left + preprocess_content.Text.Len ), ctx->token.Text.Ptr );
|
||||
|
||||
log_failure( "gen::Parser::lex: Expected '\"' or '<' after #include, not '%c' (%d, %d)\n%s"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "gen::Parser::lex: Expected '\"' or '<' after #include, not '%c' (%d, %d)\n%s"
|
||||
, (* ctx->scanner)
|
||||
, preprocess_content.Line
|
||||
, preprocess_content.Column
|
||||
@@ -412,7 +419,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
move_forward();
|
||||
}
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, preprocess_content );
|
||||
array_append(ctx->tokens, preprocess_content);
|
||||
return Lex_Continue; // Skip found token, its all handled here.
|
||||
}
|
||||
|
||||
@@ -447,16 +454,15 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
}
|
||||
else
|
||||
{
|
||||
StrBuilder directive_str = strbuilder_make_length( _ctx->Allocator_Temp, ctx->token.Text.Ptr, ctx->token.Text.Len );
|
||||
StrBuilder content_str = strbuilder_fmt_buf( _ctx->Allocator_Temp, "%.*s", min( 400, ctx->left + preprocess_content.Text.Len ), preprocess_content.Text.Ptr );
|
||||
StrBuilder directive_str = strbuilder_make_length( ctx->allocator_temp, ctx->token.Text.Ptr, ctx->token.Text.Len );
|
||||
StrBuilder content_str = strbuilder_fmt_buf( ctx->allocator_temp, "%.*s", min( 400, ctx->left + preprocess_content.Text.Len ), preprocess_content.Text.Ptr );
|
||||
|
||||
log_failure( "gen::Parser::lex: Invalid escape sequence '\\%c' (%d, %d)"
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "gen::Parser::lex: Invalid escape sequence '\\%c' (%d, %d)"
|
||||
" in preprocessor directive '%s' (%d, %d)\n%s"
|
||||
, (* ctx->scanner), ctx->line, ctx->column
|
||||
, directive_str, preprocess_content.Line, preprocess_content.Column
|
||||
, content_str );
|
||||
return Lex_ReturnNull;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,20 +482,23 @@ s32 lex_preprocessor_directive( LexContext* ctx )
|
||||
preprocess_content.Text.Len++;
|
||||
}
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, preprocess_content );
|
||||
array_append(ctx->tokens, preprocess_content);
|
||||
return Lex_Continue; // Skip found token, its all handled here.
|
||||
}
|
||||
|
||||
forceinline
|
||||
void lex_found_token( LexContext* ctx )
|
||||
{
|
||||
if ( ctx->token.Type != Tok_Invalid ) {
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
return;
|
||||
}
|
||||
|
||||
TokType type = str_to_toktype( ctx->token.Text );
|
||||
|
||||
if (type == Tok_Preprocess_Define || type == Tok_Preprocess_Include) {
|
||||
ctx->token.Flags |= TF_Identifier;
|
||||
}
|
||||
|
||||
if (type <= Tok_Access_Public && type >= Tok_Access_Private ) {
|
||||
ctx->token.Flags |= TF_AccessSpecifier;
|
||||
}
|
||||
@@ -506,7 +515,7 @@ void lex_found_token( LexContext* ctx )
|
||||
}
|
||||
|
||||
ctx->token.Type = type;
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
return;
|
||||
}
|
||||
if ( ( type <= Tok_Star && type >= Tok_Spec_Alignas)
|
||||
@@ -515,13 +524,13 @@ void lex_found_token( LexContext* ctx )
|
||||
{
|
||||
ctx->token.Type = type;
|
||||
ctx->token.Flags |= TF_Specifier;
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
return;
|
||||
}
|
||||
if ( type != Tok_Invalid )
|
||||
{
|
||||
ctx->token.Type = type;
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -532,11 +541,16 @@ void lex_found_token( LexContext* ctx )
|
||||
ctx->token.Type = macrotype_to_toktype(macro->Type);
|
||||
b32 is_functional = macro_is_functional(* macro);
|
||||
resolved_to_macro = has_args ? is_functional : ! is_functional;
|
||||
if ( ! resolved_to_macro && GEN_BUILD_DEBUG ) {
|
||||
log_fmt("Info(%d, %d): %S identified as a macro but usage here does not resolve to one (interpreting as identifier)\n"
|
||||
, ctx->token.Line
|
||||
if ( ! resolved_to_macro && GEN_BUILD_DEBUG && ! bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Identifier) ) {
|
||||
log_fmt("Info(%d, %d): %S identified as a macro but usage here does not resolve to one (functional=%d, has_args=%d, flags=%u, next='%.*s')\n"
|
||||
, ctx->token.Line
|
||||
, ctx->token.Column
|
||||
, macro->Name
|
||||
, is_functional
|
||||
, has_args
|
||||
, macro->Flags
|
||||
, min(16, ctx->left)
|
||||
, ctx->scanner
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -550,56 +564,75 @@ void lex_found_token( LexContext* ctx )
|
||||
if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Attribute) ) {
|
||||
ctx->token.Flags |= TF_Attribute;
|
||||
}
|
||||
if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Specifier ) ) {
|
||||
ctx->token.Flags |= TF_Specifier;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx->token.Type = Tok_Identifier;
|
||||
}
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, ctx->token );
|
||||
array_append(ctx->tokens, ctx->token);
|
||||
}
|
||||
|
||||
// TODO(Ed): We should dynamically allocate the lexer's array in Allocator_DyanmicContainers.
|
||||
|
||||
// TODO(Ed): We need to to attempt to recover from a lex failure?
|
||||
|
||||
internal
|
||||
void lexer_record_failure(Context* lib_ctx, LexContext* ctx, Str text) {
|
||||
LexerMessage* msg = rcast(LexerMessage*, alloc(lib_ctx->Allocator_DyanmicContainers, size_of(LexerMessage)));
|
||||
if (msg == nullptr) GEN_FATAL("lexer_record_failure: allocation failed");
|
||||
msg->next = ctx->messages;
|
||||
msg->content = cache_str(text);
|
||||
msg->level = LL_Error;
|
||||
ctx->messages = msg;
|
||||
}
|
||||
|
||||
internal
|
||||
void lexer_record_failure_fmt(Context* lib_ctx, LexContext* ctx, char const* fmt, ...) {
|
||||
va_list va;
|
||||
char* buf;
|
||||
Str text;
|
||||
va_start(va, fmt);
|
||||
buf = c_str_fmt_buf_va(fmt, va);
|
||||
va_end(va);
|
||||
text.Ptr = buf;
|
||||
text.Len = c_str_len(buf);
|
||||
lexer_record_failure(lib_ctx, ctx, text);
|
||||
}
|
||||
|
||||
neverinline
|
||||
// TokArray lex( Array<Token> tokens, Str content )
|
||||
TokArray lex( Str content )
|
||||
LexedInfo lex(Context* lib_ctx, Str content)
|
||||
{
|
||||
LexContext c; LexContext* ctx = & c;
|
||||
c.content = content;
|
||||
c.left = content.Len;
|
||||
c.scanner = content.Ptr;
|
||||
LexedInfo info = struct_zero(LexedInfo);
|
||||
|
||||
char const* word = c.scanner;
|
||||
s32 word_length = 0;
|
||||
LexContext c = struct_zero(LexContext); LexContext* ctx = & c;
|
||||
c.allocator_temp = lib_ctx->Allocator_Temp;
|
||||
c.content = content;
|
||||
c.left = content.Len;
|
||||
c.scanner = content.Ptr;
|
||||
c.line = 1;
|
||||
c.column = 1;
|
||||
c.tokens = array_init_reserve(Token, lib_ctx->Allocator_DyanmicContainers, lib_ctx->InitSize_LexerTokens );
|
||||
|
||||
c.line = 1;
|
||||
c.column = 1;
|
||||
|
||||
skip_whitespace();
|
||||
if ( c.left <= 0 )
|
||||
{
|
||||
log_failure( "gen::lex: no tokens found (only whitespace provided)" );
|
||||
TokArray null_array = {};
|
||||
return null_array;
|
||||
}
|
||||
|
||||
array_clear(_ctx->Lexer_Tokens);
|
||||
// TODO(Ed): Re-implement to new constraints:
|
||||
// 1. Ability to continue on error
|
||||
// 2. Return a lexed info.
|
||||
|
||||
b32 preprocess_args = true;
|
||||
|
||||
skip_whitespace();
|
||||
if ( c.left <= 0 ) {
|
||||
lexer_record_failure(lib_ctx, ctx, txt("gen::lex: no tokens found (only whitespace provided)"));
|
||||
info.messages = c.messages;
|
||||
goto Lex_Done;
|
||||
}
|
||||
|
||||
while (c.left )
|
||||
{
|
||||
#if 0
|
||||
if (Tokens.num())
|
||||
{
|
||||
log_fmt("\nLastTok: %SB", Tokens.back().to_strbuilder());
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
Token thanks_c = { { c.scanner, 0 }, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
c.token = thanks_c;
|
||||
}
|
||||
c.token = struct_init(Token) { { c.scanner, 0 }, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
|
||||
bool is_define = false;
|
||||
|
||||
@@ -618,7 +651,7 @@ TokArray lex( Str content )
|
||||
c.token.Type = Tok_NewLine;
|
||||
c.token.Text.Len++;
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, c.token );
|
||||
array_append(c.tokens, c.token);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -633,7 +666,7 @@ TokArray lex( Str content )
|
||||
{
|
||||
case '#':
|
||||
{
|
||||
s32 result = lex_preprocessor_directive( ctx );
|
||||
s32 result = lex_preprocessor_directive(lib_ctx, ctx);
|
||||
switch ( result )
|
||||
{
|
||||
case Lex_Continue:
|
||||
@@ -657,7 +690,7 @@ TokArray lex( Str content )
|
||||
c.token.Text.Len++;
|
||||
move_forward();
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, c.token );
|
||||
array_append(c.tokens, c.token);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -665,8 +698,8 @@ TokArray lex( Str content )
|
||||
|
||||
case Lex_ReturnNull:
|
||||
{
|
||||
TokArray tok_array = {};
|
||||
return tok_array;
|
||||
info.messages = c.messages;
|
||||
goto Lex_Done;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -693,9 +726,11 @@ TokArray lex( Str content )
|
||||
}
|
||||
else
|
||||
{
|
||||
StrBuilder context_str = strbuilder_fmt_buf( _ctx->Allocator_Temp, "%s", c.scanner, min( 100, c.left ) );
|
||||
StrBuilder context_str = strbuilder_fmt_buf( lib_ctx->Allocator_Temp, "%s", c.scanner, min( 100, c.left ) );
|
||||
|
||||
log_failure( "gen::lex: invalid varadic argument, expected '...' got '..%c' (%d, %d)\n%s", (* ctx->scanner), c.line, c.column, context_str );
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "gen::lex: invalid varadic argument, expected '...' got '..%c' (%d, %d)\n%s", (* ctx->scanner), c.line, c.column, context_str );
|
||||
info.messages = c.messages;
|
||||
goto Lex_Done;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1114,7 +1149,7 @@ TokArray lex( Str content )
|
||||
move_forward();
|
||||
c.token.Text.Len++;
|
||||
}
|
||||
array_append( _ctx->Lexer_Tokens, c.token );
|
||||
array_append(c.tokens, c.token);
|
||||
continue;
|
||||
}
|
||||
else if ( (* ctx->scanner) == '*' )
|
||||
@@ -1150,7 +1185,7 @@ TokArray lex( Str content )
|
||||
move_forward();
|
||||
c.token.Text.Len++;
|
||||
}
|
||||
array_append( _ctx->Lexer_Tokens, c.token );
|
||||
array_append(c.tokens, c.token);
|
||||
// end_line();
|
||||
continue;
|
||||
}
|
||||
@@ -1238,30 +1273,27 @@ TokArray lex( Str content )
|
||||
}
|
||||
else
|
||||
{
|
||||
s32 start = max( 0, array_num(_ctx->Lexer_Tokens) - 100 );
|
||||
s32 start = max( 0, array_num(c.tokens) - 100 );
|
||||
log_fmt("\n%d\n", start);
|
||||
for ( s32 idx = start; idx < array_num(_ctx->Lexer_Tokens); idx++ )
|
||||
for ( s32 idx = start; idx < array_num(c.tokens); idx++ )
|
||||
{
|
||||
log_fmt( "Token %d Type: %s : %.*s\n"
|
||||
, idx
|
||||
, toktype_to_str( _ctx->Lexer_Tokens[ idx ].Type ).Ptr
|
||||
, _ctx->Lexer_Tokens[ idx ].Text.Len, _ctx->Lexer_Tokens[ idx ].Text.Ptr
|
||||
, toktype_to_str( c.tokens[ idx ].Type ).Ptr
|
||||
, c.tokens[ idx ].Text.Len, c.tokens[ idx ].Text.Ptr
|
||||
);
|
||||
}
|
||||
|
||||
StrBuilder context_str = strbuilder_fmt_buf( _ctx->Allocator_Temp, "%.*s", min( 100, c.left ), c.scanner );
|
||||
log_failure( "Failed to lex token '%c' (%d, %d)\n%s", (* ctx->scanner), c.line, c.column, context_str );
|
||||
|
||||
// Skip to next whitespace since we can't know if anything else is valid until then.
|
||||
while ( c.left && ! char_is_space( (* ctx->scanner) ) ) {
|
||||
move_forward();
|
||||
}
|
||||
StrBuilder context_str = strbuilder_fmt_buf( lib_ctx->Allocator_Temp, "%.*s", min( 100, c.left ), c.scanner );
|
||||
lexer_record_failure_fmt(lib_ctx, ctx, "Failed to lex token '%c' (%d, %d)\n%s", (* ctx->scanner), c.line, c.column, context_str );
|
||||
info.messages = c.messages;
|
||||
goto Lex_Done;
|
||||
}
|
||||
|
||||
FoundToken:
|
||||
{
|
||||
lex_found_token( ctx );
|
||||
TokType last_type = array_back(_ctx->Lexer_Tokens)->Type;
|
||||
TokType last_type = array_back(c.tokens)->Type;
|
||||
if ( last_type == Tok_Preprocess_Macro_Stmt || last_type == Tok_Preprocess_Macro_Expr )
|
||||
{
|
||||
Token thanks_c = { { c.scanner, 0 }, Tok_Invalid, c.line, c.column, TF_Null };
|
||||
@@ -1276,21 +1308,24 @@ TokArray lex( Str content )
|
||||
c.token.Text.Len++;
|
||||
move_forward();
|
||||
|
||||
array_append( _ctx->Lexer_Tokens, c.token );
|
||||
array_append(c.tokens, c.token);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( array_num(_ctx->Lexer_Tokens) == 0 ) {
|
||||
log_failure( "Failed to lex any tokens" );
|
||||
TokArray tok_array = {};
|
||||
return tok_array;
|
||||
if ( array_num(c.tokens) == 0 ) {
|
||||
lexer_record_failure(lib_ctx, ctx, txt("gen::lex: failed to lex any tokens"));
|
||||
info.messages = c.messages;
|
||||
goto Lex_Done;
|
||||
}
|
||||
|
||||
TokArray result = { _ctx->Lexer_Tokens, 0 };
|
||||
return result;
|
||||
|
||||
info.messages = c.messages;
|
||||
info.text = content;
|
||||
Lex_Done:
|
||||
info.tokens = struct_init(TokenSlice) { pcast(Token*, c.tokens), scast(s32, array_num(c.tokens)) };
|
||||
return info;
|
||||
}
|
||||
|
||||
#undef move_forward
|
||||
|
||||
+1076
-797
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,7 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
#include "gen/ecode.hpp"
|
||||
#include "gen/ecodetypes.hpp"
|
||||
#include "gen/eoperator.hpp"
|
||||
#include "gen/especifier.hpp"
|
||||
#include "gen/etoktype.hpp"
|
||||
@@ -11,17 +11,18 @@ enum TokFlags : u32
|
||||
{
|
||||
TF_Operator = bit(0),
|
||||
TF_Assign = bit(1),
|
||||
TF_Preprocess = bit(2),
|
||||
TF_Preprocess_Cond = bit(3),
|
||||
TF_Attribute = bit(6),
|
||||
TF_AccessOperator = bit(7),
|
||||
TF_AccessSpecifier = bit(8),
|
||||
TF_Specifier = bit(9),
|
||||
TF_EndDefinition = bit(10), // Either ; or }
|
||||
TF_Formatting = bit(11),
|
||||
TF_Literal = bit(12),
|
||||
TF_Macro_Functional = bit(13),
|
||||
TF_Macro_Expects_Body = bit(14),
|
||||
TF_Identifier = bit(2),
|
||||
TF_Preprocess = bit(3),
|
||||
TF_Preprocess_Cond = bit(4),
|
||||
TF_Attribute = bit(5),
|
||||
TF_AccessOperator = bit(6),
|
||||
TF_AccessSpecifier = bit(7),
|
||||
TF_Specifier = bit(8),
|
||||
TF_EndDefinition = bit(9), // Either ; or }
|
||||
TF_Formatting = bit(10),
|
||||
TF_Literal = bit(11),
|
||||
TF_Macro_Functional = bit(12),
|
||||
TF_Macro_Expects_Body = bit(13),
|
||||
|
||||
TF_Null = 0,
|
||||
TF_UnderlyingType = GEN_U32_MAX,
|
||||
@@ -36,8 +37,6 @@ struct Token
|
||||
u32 Flags;
|
||||
};
|
||||
|
||||
constexpr Token NullToken { {}, Tok_Invalid, 0, 0, TF_Null };
|
||||
|
||||
forceinline
|
||||
AccessSpec tok_to_access_specifier(Token tok) {
|
||||
return scast(AccessSpec, tok.Type);
|
||||
@@ -88,7 +87,28 @@ bool tok_is_end_definition(Token tok) {
|
||||
return bitfield_is_set( u32, tok.Flags, TF_EndDefinition );
|
||||
}
|
||||
|
||||
StrBuilder tok_to_strbuilder(Token tok);
|
||||
StrBuilder tok_to_strbuilder(AllocatorInfo ainfo, Token tok);
|
||||
|
||||
struct TokenSlice
|
||||
{
|
||||
Token* ptr;
|
||||
s32 num;
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline operator Token* () const { return ptr; }
|
||||
forceinline Token& operator[]( ssize index ) const { return ptr[index]; }
|
||||
#endif
|
||||
};
|
||||
|
||||
forceinline
|
||||
Str token_range_to_str(Token start, Token end)
|
||||
{
|
||||
Str result = {
|
||||
start.Text.Ptr,
|
||||
(scast(sptr, rcast(uptr, end.Text.Ptr)) + end.Text.Len) - scast(sptr, rcast(uptr, start.Text.Ptr))
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
struct TokArray
|
||||
{
|
||||
@@ -96,30 +116,52 @@ struct TokArray
|
||||
s32 Idx;
|
||||
};
|
||||
|
||||
typedef struct LexerMessage LexerMessage;
|
||||
struct LexerMessage
|
||||
{
|
||||
LexerMessage* next;
|
||||
Str content;
|
||||
LogLevel level;
|
||||
};
|
||||
|
||||
struct LexContext
|
||||
{
|
||||
AllocatorInfo allocator_temp;
|
||||
LexerMessage* messages;
|
||||
Str content;
|
||||
s32 left;
|
||||
char const* scanner;
|
||||
s32 line;
|
||||
s32 column;
|
||||
// StringTable defines;
|
||||
Token token;
|
||||
Array(Token) tokens;
|
||||
};
|
||||
|
||||
struct StackNode
|
||||
struct LexedInfo
|
||||
{
|
||||
StackNode* Prev;
|
||||
LexerMessage* messages;
|
||||
Str text;
|
||||
TokenSlice tokens;
|
||||
};
|
||||
|
||||
Token* Start;
|
||||
Str Name; // The name of the AST node (if parsed)
|
||||
Str ProcName; // The name of the procedure
|
||||
typedef struct ParseStackNode ParseStackNode;
|
||||
|
||||
typedef struct ParseMessage ParseMessage;
|
||||
struct ParseMessage
|
||||
{
|
||||
ParseMessage* Next;
|
||||
ParseStackNode* Scope;
|
||||
Str Content;
|
||||
LogLevel Level;
|
||||
};
|
||||
|
||||
struct ParseContext
|
||||
{
|
||||
TokArray Tokens;
|
||||
StackNode* Scope;
|
||||
ParseMessage* messages;
|
||||
ParseStackNode* scope;
|
||||
// TokArray Tokens;
|
||||
TokenSlice tokens;
|
||||
s32 token_id;
|
||||
};
|
||||
|
||||
enum MacroType : u16
|
||||
@@ -167,24 +209,36 @@ Str macrotype_to_str( MacroType type )
|
||||
|
||||
enum EMacroFlags : u16
|
||||
{
|
||||
MF_Functional = bit(0), // Macro has parameters (args expected to be passed)
|
||||
MF_Expects_Body = bit(1), // Expects to assign a braced scope to its body.
|
||||
// Macro has parameters (args expected to be passed)
|
||||
MF_Functional = bit(0),
|
||||
|
||||
// Expects to assign a braced scope to its body.
|
||||
MF_Expects_Body = bit(1),
|
||||
|
||||
// lex__eat wil treat this macro as an identifier if the parser attempts to consume it as one.
|
||||
// ^^^ This is a kludge because we don't support push/pop macro pragmas rn.
|
||||
// This is a kludge because we don't support push/pop macro pragmas rn.
|
||||
MF_Allow_As_Identifier = bit(2),
|
||||
|
||||
// When parsing identifiers, it will allow the consumption of the macro parameters (as its expected to be a part of constructing the identifier)
|
||||
// Example of a decarator macro from stb_sprintf.h:
|
||||
// STBSP__PUBLICDEC int STB_SPRINTF_DECORATE(sprintf)(char* buf, char const *fmt, ...) STBSP__ATTRIBUTE_FORMAT(2,3);
|
||||
// ^^ STB_SPRINTF_DECORATE is decorating sprintf
|
||||
MF_Identifier_Decorator = bit(3),
|
||||
|
||||
// lex__eat wil treat this macro as an attribute if the parser attempts to consume it as one.
|
||||
// ^^^ This a kludge because unreal has a macro that behaves as both a 'statement' and an attribute (UE_DEPRECATED, PRAGMA_ENABLE_DEPRECATION_WARNINGS, etc)
|
||||
// This a kludge because unreal has a macro that behaves as both a 'statement' and an attribute (UE_DEPRECATED, PRAGMA_ENABLE_DEPRECATION_WARNINGS, etc)
|
||||
// TODO(Ed): We can keep the MF_Allow_As_Attribute flag for macros, however, we need to add the ability of AST_Attributes to chain themselves.
|
||||
// Its thats already a thing in the standard language anyway
|
||||
// & it would allow UE_DEPRECATED, (UE_PROPERTY / UE_FUNCTION) to chain themselves as attributes of a resolved member function/varaible definition
|
||||
MF_Allow_As_Attribute = bit(3),
|
||||
// & it would allow UE_DEPRECATED, (UE_PROPERTY / UE_FUNCTION) to chain themselves as attributes of a resolved member function/variable definition
|
||||
MF_Allow_As_Attribute = bit(4),
|
||||
|
||||
// When a macro is encountered after attributs and specifiers while parsing a function, or variable:
|
||||
// It will consume the macro and treat it as resolving the definition. (Yes this is for Unreal Engine)
|
||||
// When a macro is encountered after attributes and specifiers while parsing a function, or variable:
|
||||
// It will consume the macro and treat it as resolving the definition.
|
||||
// (MUST BE OF MT_Statement TYPE)
|
||||
MF_Allow_As_Definition = bit(4),
|
||||
MF_Allow_As_Definition = bit(5),
|
||||
|
||||
// Created for Unreal's PURE_VIRTUAL
|
||||
MF_Allow_As_Specifier = bit(6),
|
||||
|
||||
MF_Null = 0,
|
||||
MF_UnderlyingType = GEN_U16_MAX,
|
||||
|
||||
@@ -1,90 +1,92 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "../gen.hpp"
|
||||
#include "interface.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region StaticData
|
||||
global Context* _ctx;
|
||||
global u32 context_counter;
|
||||
GEN_API global Context* _ctx;
|
||||
GEN_API global u32 context_counter;
|
||||
|
||||
#pragma region Constants
|
||||
global Macro enum_underlying_macro;
|
||||
GEN_API read_only global Token NullToken = { { 0, 0 }, Tok_Invalid, 0, 0, TF_Null };
|
||||
|
||||
global Code Code_Global;
|
||||
global Code Code_Invalid;
|
||||
GEN_API global Macro enum_underlying_macro;
|
||||
|
||||
global Code access_public;
|
||||
global Code access_protected;
|
||||
global Code access_private;
|
||||
GEN_API global Code Code_Global;
|
||||
GEN_API global Code Code_Invalid;
|
||||
|
||||
global CodeAttributes attrib_api_export;
|
||||
global CodeAttributes attrib_api_import;
|
||||
GEN_API global Code access_public;
|
||||
GEN_API global Code access_protected;
|
||||
GEN_API global Code access_private;
|
||||
|
||||
global Code module_global_fragment;
|
||||
global Code module_private_fragment;
|
||||
GEN_API global CodeAttributes attrib_api_export;
|
||||
GEN_API global CodeAttributes attrib_api_import;
|
||||
|
||||
global Code fmt_newline;
|
||||
GEN_API global Code module_global_fragment;
|
||||
GEN_API global Code module_private_fragment;
|
||||
|
||||
global CodeParams param_varadic;
|
||||
GEN_API global Code fmt_newline;
|
||||
|
||||
global CodePragma pragma_once;
|
||||
GEN_API global CodeParams param_varadic;
|
||||
|
||||
global CodePreprocessCond preprocess_else;
|
||||
global CodePreprocessCond preprocess_endif;
|
||||
GEN_API global CodePragma pragma_once;
|
||||
|
||||
global CodeSpecifiers spec_const;
|
||||
global CodeSpecifiers spec_consteval;
|
||||
global CodeSpecifiers spec_constexpr;
|
||||
global CodeSpecifiers spec_constinit;
|
||||
global CodeSpecifiers spec_extern_linkage;
|
||||
global CodeSpecifiers spec_final;
|
||||
global CodeSpecifiers spec_forceinline;
|
||||
global CodeSpecifiers spec_global;
|
||||
global CodeSpecifiers spec_inline;
|
||||
global CodeSpecifiers spec_internal_linkage;
|
||||
global CodeSpecifiers spec_local_persist;
|
||||
global CodeSpecifiers spec_mutable;
|
||||
global CodeSpecifiers spec_noexcept;
|
||||
global CodeSpecifiers spec_neverinline;
|
||||
global CodeSpecifiers spec_override;
|
||||
global CodeSpecifiers spec_ptr;
|
||||
global CodeSpecifiers spec_pure;
|
||||
global CodeSpecifiers spec_ref;
|
||||
global CodeSpecifiers spec_register;
|
||||
global CodeSpecifiers spec_rvalue;
|
||||
global CodeSpecifiers spec_static_member;
|
||||
global CodeSpecifiers spec_thread_local;
|
||||
global CodeSpecifiers spec_virtual;
|
||||
global CodeSpecifiers spec_volatile;
|
||||
GEN_API global CodePreprocessCond preprocess_else;
|
||||
GEN_API global CodePreprocessCond preprocess_endif;
|
||||
|
||||
global CodeTypename t_empty;
|
||||
global CodeTypename t_auto;
|
||||
global CodeTypename t_void;
|
||||
global CodeTypename t_int;
|
||||
global CodeTypename t_bool;
|
||||
global CodeTypename t_char;
|
||||
global CodeTypename t_wchar_t;
|
||||
global CodeTypename t_class;
|
||||
global CodeTypename t_typename;
|
||||
GEN_API global CodeSpecifiers spec_const;
|
||||
GEN_API global CodeSpecifiers spec_consteval;
|
||||
GEN_API global CodeSpecifiers spec_constexpr;
|
||||
GEN_API global CodeSpecifiers spec_constinit;
|
||||
GEN_API global CodeSpecifiers spec_extern_linkage;
|
||||
GEN_API global CodeSpecifiers spec_final;
|
||||
GEN_API global CodeSpecifiers spec_forceinline;
|
||||
GEN_API global CodeSpecifiers spec_global;
|
||||
GEN_API global CodeSpecifiers spec_inline;
|
||||
GEN_API global CodeSpecifiers spec_internal_linkage;
|
||||
GEN_API global CodeSpecifiers spec_local_persist;
|
||||
GEN_API global CodeSpecifiers spec_mutable;
|
||||
GEN_API global CodeSpecifiers spec_noexcept;
|
||||
GEN_API global CodeSpecifiers spec_neverinline;
|
||||
GEN_API global CodeSpecifiers spec_override;
|
||||
GEN_API global CodeSpecifiers spec_ptr;
|
||||
GEN_API global CodeSpecifiers spec_pure;
|
||||
GEN_API global CodeSpecifiers spec_ref;
|
||||
GEN_API global CodeSpecifiers spec_register;
|
||||
GEN_API global CodeSpecifiers spec_rvalue;
|
||||
GEN_API global CodeSpecifiers spec_static_member;
|
||||
GEN_API global CodeSpecifiers spec_thread_local;
|
||||
GEN_API global CodeSpecifiers spec_virtual;
|
||||
GEN_API global CodeSpecifiers spec_volatile;
|
||||
|
||||
GEN_API global CodeTypename t_empty;
|
||||
GEN_API global CodeTypename t_auto;
|
||||
GEN_API global CodeTypename t_void;
|
||||
GEN_API global CodeTypename t_int;
|
||||
GEN_API global CodeTypename t_bool;
|
||||
GEN_API global CodeTypename t_char;
|
||||
GEN_API global CodeTypename t_wchar_t;
|
||||
GEN_API global CodeTypename t_class;
|
||||
GEN_API global CodeTypename t_typename;
|
||||
|
||||
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
global CodeTypename t_b32;
|
||||
GEN_API global CodeTypename t_b32;
|
||||
|
||||
global CodeTypename t_s8;
|
||||
global CodeTypename t_s16;
|
||||
global CodeTypename t_s32;
|
||||
global CodeTypename t_s64;
|
||||
GEN_API global CodeTypename t_s8;
|
||||
GEN_API global CodeTypename t_s16;
|
||||
GEN_API global CodeTypename t_s32;
|
||||
GEN_API global CodeTypename t_s64;
|
||||
|
||||
global CodeTypename t_u8;
|
||||
global CodeTypename t_u16;
|
||||
global CodeTypename t_u32;
|
||||
global CodeTypename t_u64;
|
||||
GEN_API global CodeTypename t_u8;
|
||||
GEN_API global CodeTypename t_u16;
|
||||
GEN_API global CodeTypename t_u32;
|
||||
GEN_API global CodeTypename t_u64;
|
||||
|
||||
global CodeTypename t_ssize;
|
||||
global CodeTypename t_usize;
|
||||
GEN_API global CodeTypename t_ssize;
|
||||
GEN_API global CodeTypename t_usize;
|
||||
|
||||
global CodeTypename t_f32;
|
||||
global CodeTypename t_f64;
|
||||
GEN_API global CodeTypename t_f32;
|
||||
GEN_API global CodeTypename t_f64;
|
||||
#endif
|
||||
|
||||
#pragma endregion Constants
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "header_start.hpp"
|
||||
#include "dependencies/platform.hpp"
|
||||
#include "dependencies/macros.hpp"
|
||||
#include "dependencies/basic_types.hpp"
|
||||
#include "dependencies/debug.hpp"
|
||||
#include "dependencies/memory.hpp"
|
||||
#include "dependencies/string_ops.hpp"
|
||||
#include "dependencies/printing.hpp"
|
||||
#include "dependencies/containers.hpp"
|
||||
#include "dependencies/hashing.hpp"
|
||||
#include "dependencies/strings.hpp"
|
||||
#include "dependencies/filesystem.hpp"
|
||||
#include "dependencies/timing.hpp"
|
||||
#include "dependencies/parsing.hpp"
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -19,14 +31,45 @@
|
||||
|
||||
*/
|
||||
|
||||
using LogFailType = ssize(*)(char const*, ...);
|
||||
enum LogLevel //: u32
|
||||
{
|
||||
LL_Null,
|
||||
LL_Note,
|
||||
LL_Warning,
|
||||
LL_Error,
|
||||
LL_Fatal,
|
||||
LL_UnderlyingType = GEN_U32_MAX,
|
||||
};
|
||||
typedef enum LogLevel LogLevel;
|
||||
|
||||
Str loglevel_to_str(LogLevel level)
|
||||
{
|
||||
local_persist
|
||||
Str lookup[] = {
|
||||
{ "Null", sizeof("Null") - 1 },
|
||||
{ "Note", sizeof("Note") - 1 },
|
||||
{ "Warning", sizeof("Info") - 1 },
|
||||
{ "Error", sizeof("Error") - 1 },
|
||||
{ "Fatal", sizeof("Fatal") - 1 },
|
||||
};
|
||||
return lookup[level];
|
||||
}
|
||||
|
||||
typedef struct LogEntry LogEntry;
|
||||
struct LogEntry
|
||||
{
|
||||
Str msg;
|
||||
LogLevel level;
|
||||
};
|
||||
|
||||
typedef void LoggerProc(LogEntry entry);
|
||||
|
||||
// By default this library will either crash or exit if an error is detected while generating codes.
|
||||
// Even if set to not use GEN_FATAL, GEN_FATAL will still be used for memory failures as the library is unusable when they occur.
|
||||
#ifdef GEN_DONT_USE_FATAL
|
||||
#define log_failure log_fmt
|
||||
#define log_failure( ... ) log_fmt( __VA_ARGS__ )
|
||||
#else
|
||||
#define log_failure GEN_FATAL
|
||||
#define log_failure( ... ) GEN_FATAL( __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
enum AccessSpec : u32
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.hpp"
|
||||
#endif
|
||||
@@ -17,6 +17,39 @@ template <class TType> struct RemovePtr<TType*> { typedef TType Type; };
|
||||
|
||||
template <class TType> using TRemovePtr = typename RemovePtr<TType>::Type;
|
||||
|
||||
#pragma region Slice
|
||||
#if 0
|
||||
#define Slice(Type) Slice<Type>
|
||||
|
||||
template<class Type> struct Slice;
|
||||
|
||||
template<class Type>
|
||||
Type* slice_get(Slice<Type> self, ssize id) {
|
||||
GEN_ASSERT(id > -1);
|
||||
GEN_ASSERT(id < self.len);
|
||||
return self.ptr[id];
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
struct Slice
|
||||
{
|
||||
Type* ptr;
|
||||
ssize len;
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
forceinline operator Token* () const { return ptr; }
|
||||
forceinline Token& operator[]( ssize index ) const { return ptr[index]; }
|
||||
|
||||
forceinline Type* begin() { return ptr; }
|
||||
forceinline Type* end() { return ptr + len; }
|
||||
#endif
|
||||
|
||||
#if ! GEN_C_LIKE_CPP && GEN_COMPILER_CPP
|
||||
forceinline Type& back() { return ptr[len - 1]; }
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
#pragma endregion Slice
|
||||
|
||||
#pragma region Array
|
||||
#define Array(Type) Array<Type>
|
||||
@@ -26,10 +59,8 @@ template <class TType> using TRemovePtr = typename RemovePtr<TType>::Type;
|
||||
|
||||
struct ArrayHeader;
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
template<class Type> struct Array;
|
||||
# define get_array_underlying_type(array) typename TRemovePtr<typeof(array)>:: DataType
|
||||
#endif
|
||||
template<class Type> struct Array;
|
||||
#define get_array_underlying_type(array) typename TRemovePtr<typeof(array)>:: DataType
|
||||
|
||||
usize array_grow_formula(ssize value);
|
||||
|
||||
@@ -59,12 +90,12 @@ struct ArrayHeader {
|
||||
usize Num;
|
||||
};
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
template<class Type>
|
||||
struct Array
|
||||
{
|
||||
Type* Data;
|
||||
|
||||
#if ! GEN_C_LIKE_CPP
|
||||
#pragma region Member Mapping
|
||||
forceinline static Array init(AllocatorInfo allocator) { return array_init<Type>(allocator); }
|
||||
forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return array_init_reserve<Type>(allocator, capacity); }
|
||||
@@ -88,6 +119,7 @@ struct Array
|
||||
forceinline bool resize(usize num) { return array_resize<Type>(this, num); }
|
||||
forceinline bool set_capacity(usize new_capacity) { return array_set_capacity<Type>(this, new_capacity); }
|
||||
#pragma endregion Member Mapping
|
||||
#endif
|
||||
|
||||
forceinline operator Type*() { return Data; }
|
||||
forceinline operator Type const*() const { return Data; }
|
||||
@@ -99,9 +131,8 @@ struct Array
|
||||
|
||||
using DataType = Type;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP && 0
|
||||
#if 0
|
||||
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return append( & array, other ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type value) { return append( & array, value ); }
|
||||
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return append( & array, items, item_num ); }
|
||||
@@ -309,6 +340,7 @@ ArrayHeader* array_get_header(Array<Type> array) {
|
||||
using NonConstType = TRemoveConst<Type>;
|
||||
return rcast(ArrayHeader*, const_cast<NonConstType*>(Data)) - 1;
|
||||
}
|
||||
|
||||
template<class Type> forceinline
|
||||
bool array_grow(Array<Type>* array, usize min_capacity)
|
||||
{
|
||||
@@ -415,7 +447,7 @@ bool array_set_capacity(Array<Type>* array, usize new_capacity)
|
||||
// These are intended for use in the base library of gencpp and the C-variant of the library
|
||||
// It provides a interoperability between the C++ and C implementation of arrays. (not letting these do any crazy substiution though)
|
||||
// They are undefined in gen.hpp and gen.cpp at the end of the files.
|
||||
// We cpp library expects the user to use the regular calls as they can resolve the type fine.
|
||||
// The cpp library expects the user to use the regular calls as they can resolve the type fine.
|
||||
|
||||
#define array_init(type, allocator) array_init <type> (allocator )
|
||||
#define array_init_reserve(type, allocator, cap) array_init_reserve <type> (allocator, cap)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "src_start.cpp"
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "dependencies/platform.hpp"
|
||||
# include "dependencies/macros.hpp"
|
||||
# include "basic_types.hpp"
|
||||
# include "macros.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Debug
|
||||
@@ -67,8 +64,8 @@
|
||||
while (0)
|
||||
#endif
|
||||
|
||||
void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... );
|
||||
s32 assert_crash( char const* condition );
|
||||
void process_exit( u32 code );
|
||||
GEN_API void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... );
|
||||
GEN_API s32 assert_crash( char const* condition );
|
||||
GEN_API void process_exit( u32 code );
|
||||
|
||||
#pragma endregion Debug
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.cpp"
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strings.hpp"
|
||||
#endif
|
||||
@@ -121,20 +121,20 @@ enum FileStandardType
|
||||
* @param std Check zpl_file_standard_type
|
||||
* @return File handle to standard I/O
|
||||
*/
|
||||
FileInfo* file_get_standard( FileStandardType std );
|
||||
GEN_API FileInfo* file_get_standard( FileStandardType std );
|
||||
|
||||
/**
|
||||
* Closes the file
|
||||
* @param file
|
||||
*/
|
||||
FileError file_close( FileInfo* file );
|
||||
GEN_API FileError file_close( FileInfo* file );
|
||||
|
||||
/**
|
||||
* Returns the currently opened file's name
|
||||
* @param file
|
||||
*/
|
||||
inline
|
||||
char const* file_name( FileInfo* file )
|
||||
char const* file_name( FileInfo* file )
|
||||
{
|
||||
return file->filename ? file->filename : "";
|
||||
}
|
||||
@@ -144,7 +144,7 @@ inline
|
||||
* @param file
|
||||
* @param filename
|
||||
*/
|
||||
FileError file_open( FileInfo* file, char const* filename );
|
||||
GEN_API FileError file_open( FileInfo* file, char const* filename );
|
||||
|
||||
/**
|
||||
* Opens a file using a specified mode
|
||||
@@ -152,7 +152,7 @@ FileError file_open( FileInfo* file, char const* filename );
|
||||
* @param mode Access mode to use
|
||||
* @param filename
|
||||
*/
|
||||
FileError file_open_mode( FileInfo* file, FileMode mode, char const* filename );
|
||||
GEN_API FileError file_open_mode( FileInfo* file, FileMode mode, char const* filename );
|
||||
|
||||
/**
|
||||
* Reads from a file
|
||||
@@ -187,7 +187,7 @@ struct FileContents
|
||||
{
|
||||
AllocatorInfo allocator;
|
||||
void* data;
|
||||
ssize size;
|
||||
ssize size;
|
||||
};
|
||||
|
||||
constexpr b32 file_zero_terminate = true;
|
||||
@@ -200,14 +200,14 @@ constexpr b32 file_no_zero_terminate = false;
|
||||
* @param filepath Path to the file
|
||||
* @return File contents data
|
||||
*/
|
||||
FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const* filepath );
|
||||
GEN_API FileContents file_read_contents( AllocatorInfo a, b32 zero_terminate, char const* filepath );
|
||||
|
||||
/**
|
||||
* Returns a size of the file
|
||||
* @param file
|
||||
* @return File size
|
||||
*/
|
||||
s64 file_size( FileInfo* file );
|
||||
GEN_API s64 file_size( FileInfo* file );
|
||||
|
||||
/**
|
||||
* Seeks the file cursor from the beginning of file to a specific position
|
||||
@@ -274,7 +274,7 @@ enum FileStreamFlags : u32
|
||||
* @param file
|
||||
* @param allocator
|
||||
*/
|
||||
b8 file_stream_new( FileInfo* file, AllocatorInfo allocator );
|
||||
GEN_API b8 file_stream_new( FileInfo* file, AllocatorInfo allocator );
|
||||
|
||||
/**
|
||||
* Opens a memory stream over an existing buffer
|
||||
@@ -284,14 +284,14 @@ b8 file_stream_new( FileInfo* file, AllocatorInfo allocator );
|
||||
* @param size Buffer's size
|
||||
* @param flags
|
||||
*/
|
||||
b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize size, FileStreamFlags flags );
|
||||
GEN_API b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize size, FileStreamFlags flags );
|
||||
|
||||
/**
|
||||
* Retrieves the stream's underlying buffer and buffer size.
|
||||
* @param file memory stream
|
||||
* @param size (Optional) buffer size
|
||||
*/
|
||||
u8* file_stream_buf( FileInfo* file, ssize* size );
|
||||
GEN_API u8* file_stream_buf( FileInfo* file, ssize* size );
|
||||
|
||||
extern FileOperations const memory_file_operations;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.cpp"
|
||||
#endif
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
#pragma once
|
||||
#include "containers.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Hashing
|
||||
|
||||
u32 crc32( void const* data, ssize len );
|
||||
u64 crc64( void const* data, ssize len );
|
||||
GEN_API u32 crc32( void const* data, ssize len );
|
||||
GEN_API u64 crc64( void const* data, ssize len );
|
||||
|
||||
#pragma endregion Hashing
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "platform.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Macros
|
||||
|
||||
#ifndef GEN_API
|
||||
#if GEN_COMPILER_MSVC
|
||||
#ifdef GEN_DYN_LINK
|
||||
#ifdef GEN_DYN_EXPORT
|
||||
@@ -22,9 +23,14 @@
|
||||
#define GEN_API // Empty for static builds
|
||||
#endif
|
||||
#endif
|
||||
#endif // GEN_API
|
||||
|
||||
#ifndef global
|
||||
#define global static // Global variables
|
||||
#ifndef global // Global variables
|
||||
# if defined(GEN_STATIC_LINK) || defined(GEN_DYN_LINK)
|
||||
# define global
|
||||
# else
|
||||
# define global static
|
||||
# endif
|
||||
#endif
|
||||
#ifndef internal
|
||||
#define internal static // Internal linkage
|
||||
@@ -32,9 +38,22 @@
|
||||
#ifndef local_persist
|
||||
#define local_persist static // Local Persisting variables
|
||||
#endif
|
||||
#ifndef read_only
|
||||
# if GEN_COMPILER_MSVC || ( defined(GEN_COMPILER_CLANG) && GEN_COMPILER_CLANG && GEN_SYSTEM_WINDOWS )
|
||||
# pragma section(".rdata$", read)
|
||||
# define read_only __declspec(allocate(".rdata$"))
|
||||
# elif defined(GEN_COMPILER_CLANG) && GEN_COMPILER_CLANG
|
||||
# define read_only __attribute__((section(".rodata")))
|
||||
# else
|
||||
# define read_only
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef bit
|
||||
#define bit( Value ) ( 1 << Value )
|
||||
#endif
|
||||
|
||||
#ifndef bitfield_is_set
|
||||
#define bitfield_is_set( Type, Field, Mask ) ( (scast(Type, Mask) & scast(Type, Field)) == scast(Type, Mask) )
|
||||
#endif
|
||||
|
||||
@@ -89,9 +108,9 @@
|
||||
#define src_line_str stringize(__LINE__)
|
||||
|
||||
#ifndef do_once
|
||||
#define do_once() \
|
||||
local_persist int __do_once_counter_##src_line_str = 0; \
|
||||
for(; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1 ) \
|
||||
#define do_once() \
|
||||
local_persist int __do_once_counter_##src_line_str = 0; \
|
||||
for(; __do_once_counter_##src_line_str != 1; __do_once_counter_##src_line_str = 1 ) \
|
||||
|
||||
#define do_once_defer( expression ) \
|
||||
local_persist int __do_once_counter_##src_line_str = 0; \
|
||||
@@ -189,21 +208,16 @@
|
||||
#ifndef forceinline
|
||||
# if GEN_COMPILER_MSVC
|
||||
# define forceinline __forceinline
|
||||
# define neverinline __declspec( noinline )
|
||||
# elif GEN_COMPILER_GCC
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
# elif GEN_COMPILER_CLANG
|
||||
# if __has_attribute(__always_inline__)
|
||||
# define forceinline inline __attribute__((__always_inline__))
|
||||
# define neverinline __attribute__( ( __noinline__ ) )
|
||||
# else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
# endif
|
||||
# else
|
||||
# define forceinline
|
||||
# define neverinline
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -294,10 +308,28 @@
|
||||
# define GEN_PARAM_DEFAULT
|
||||
#endif
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
#define struct_init(type, value) {value}
|
||||
#else
|
||||
#define struct_init(type, value) {value}
|
||||
#ifndef struct_init
|
||||
# if GEN_COMPILER_CPP
|
||||
# define struct_init(type)
|
||||
# else
|
||||
# define struct_init(type) (type)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef struct_zero
|
||||
# if GEN_COMPILER_CPP
|
||||
# define struct_zero(type) {}
|
||||
# else
|
||||
# define struct_zero(type) (type) {0}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef struct_zero_init
|
||||
# if GEN_COMPILER_CPP
|
||||
# define struct_zero_init() {}
|
||||
# else
|
||||
# define struct_zero_init() {0}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
@@ -310,4 +342,12 @@
|
||||
# define GEN_OPITMIZE_MAPPINGS_END
|
||||
#endif
|
||||
|
||||
#ifndef get_optional
|
||||
# if GEN_COMPILER_C
|
||||
# define get_optional(opt) opt ? *opt : (typeof(*opt)){0}
|
||||
# else
|
||||
# define get_optional(opt) opt
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#pragma endregion Macros
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "printing.cpp"
|
||||
#endif
|
||||
@@ -84,13 +84,13 @@ void heap_stats_check( void )
|
||||
typedef struct _heap_alloc_info _heap_alloc_info;
|
||||
struct _heap_alloc_info
|
||||
{
|
||||
ssize size;
|
||||
ssize size;
|
||||
void* physical_start;
|
||||
};
|
||||
|
||||
void* heap_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
|
||||
{
|
||||
void* ptr = NULL;
|
||||
void* ptr = nullptr;
|
||||
// unused( allocator_data );
|
||||
// unused( old_size );
|
||||
if ( ! alignment )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.hpp"
|
||||
#endif
|
||||
@@ -41,10 +41,10 @@ void const* pointer_add_const( void const* ptr, ssize bytes );
|
||||
ssize pointer_diff( void const* begin, void const* end );
|
||||
|
||||
//! Copy non-overlapping memory from source to destination.
|
||||
void* mem_copy( void* dest, void const* source, ssize size );
|
||||
GEN_API void* mem_copy( void* dest, void const* source, ssize size );
|
||||
|
||||
//! Search for a constant value within the size limit at memory location.
|
||||
void const* mem_find( void const* data, u8 byte_value, ssize size );
|
||||
GEN_API void const* mem_find( void const* data, u8 byte_value, ssize size );
|
||||
|
||||
//! Copy memory from source to destination.
|
||||
void* mem_move( void* dest, void const* source, ssize size );
|
||||
@@ -119,27 +119,21 @@ void* resize_align( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size,
|
||||
/* define GEN_HEAP_ANALYSIS to enable this feature */
|
||||
/* call zpl_heap_stats_init at the beginning of the entry point */
|
||||
/* you can call zpl_heap_stats_check near the end of the execution to validate any possible leaks */
|
||||
void heap_stats_init( void );
|
||||
ssize heap_stats_used_memory( void );
|
||||
ssize heap_stats_alloc_count( void );
|
||||
void heap_stats_check( void );
|
||||
GEN_API void heap_stats_init( void );
|
||||
GEN_API ssize heap_stats_used_memory( void );
|
||||
GEN_API ssize heap_stats_alloc_count( void );
|
||||
GEN_API void heap_stats_check( void );
|
||||
|
||||
//! Allocate/Resize memory using default options.
|
||||
|
||||
//! Use this if you don't need a "fancy" resize allocation
|
||||
void* default_resize_align( AllocatorInfo a, void* ptr, ssize old_size, ssize new_size, ssize alignment );
|
||||
|
||||
void* heap_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
|
||||
GEN_API void* heap_allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
|
||||
|
||||
//! The heap allocator backed by operating system's memory manager.
|
||||
constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocator_proc, nullptr }; return allocator; }
|
||||
|
||||
//! Helper to allocate memory using heap allocator.
|
||||
#define malloc( sz ) alloc( heap(), sz )
|
||||
|
||||
//! Helper to free memory allocated by heap allocator.
|
||||
#define mfree( ptr ) free( heap(), ptr )
|
||||
|
||||
struct VirtualMemory
|
||||
{
|
||||
void* data;
|
||||
@@ -147,25 +141,25 @@ struct VirtualMemory
|
||||
};
|
||||
|
||||
//! Initialize virtual memory from existing data.
|
||||
VirtualMemory vm_from_memory( void* data, ssize size );
|
||||
GEN_API VirtualMemory vm_from_memory( void* data, ssize 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, ssize size );
|
||||
GEN_API VirtualMemory vm_alloc( void* addr, ssize size );
|
||||
|
||||
//! Release the virtual memory.
|
||||
b32 vm_free( VirtualMemory vm );
|
||||
GEN_API b32 vm_free( VirtualMemory vm );
|
||||
|
||||
//! Trim virtual memory.
|
||||
VirtualMemory vm_trim( VirtualMemory vm, ssize lead_size, ssize size );
|
||||
GEN_API VirtualMemory vm_trim( VirtualMemory vm, ssize lead_size, ssize size );
|
||||
|
||||
//! Purge virtual memory.
|
||||
b32 vm_purge( VirtualMemory vm );
|
||||
GEN_API b32 vm_purge( VirtualMemory vm );
|
||||
|
||||
//! Retrieve VM's page size and alignment.
|
||||
ssize virtual_memory_page_size( ssize* alignment_out );
|
||||
GEN_API ssize virtual_memory_page_size( ssize* alignment_out );
|
||||
|
||||
#pragma region Arena
|
||||
struct Arena;
|
||||
@@ -173,7 +167,7 @@ struct Arena;
|
||||
AllocatorInfo arena_allocator_info( Arena* arena );
|
||||
|
||||
// Remove static keyword and rename allocator_proc
|
||||
void* arena_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
|
||||
GEN_API void* arena_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
|
||||
|
||||
// Add these declarations after the Arena struct
|
||||
Arena arena_init_from_allocator(AllocatorInfo backing, ssize size);
|
||||
@@ -185,6 +179,8 @@ void arena_check (Arena* arena);
|
||||
void arena_free (Arena* arena);
|
||||
ssize arena_size_remaining(Arena* arena, ssize alignment);
|
||||
|
||||
// TODO(Ed): Add arena_pos, arena_pop, and arena_pop_to
|
||||
|
||||
struct Arena
|
||||
{
|
||||
AllocatorInfo Backing;
|
||||
@@ -382,13 +378,13 @@ using FixedArena_4MB = FixedArena< megabytes( 4 ) >;
|
||||
#pragma region Pool
|
||||
struct Pool;
|
||||
|
||||
void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
|
||||
GEN_API void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
|
||||
|
||||
Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size);
|
||||
Pool pool_init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align);
|
||||
AllocatorInfo pool_allocator_info(Pool* pool);
|
||||
void pool_clear(Pool* pool);
|
||||
void pool_free(Pool* pool);
|
||||
Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size);
|
||||
Pool pool_init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align);
|
||||
AllocatorInfo pool_allocator_info(Pool* pool);
|
||||
GEN_API void pool_clear(Pool* pool);
|
||||
void pool_free(Pool* pool);
|
||||
|
||||
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
|
||||
forceinline AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "parsing.hpp"
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "timing.hpp"
|
||||
#endif
|
||||
@@ -122,7 +122,7 @@ struct ADT_Node
|
||||
* @param is_array
|
||||
* @return error code
|
||||
*/
|
||||
u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32 is_array );
|
||||
GEN_API u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32 is_array );
|
||||
|
||||
/**
|
||||
* @brief Destroy an ADT branch and its descendants
|
||||
@@ -130,7 +130,7 @@ u8 adt_make_branch( ADT_Node* node, AllocatorInfo backing, char const* name, b32
|
||||
* @param node
|
||||
* @return error code
|
||||
*/
|
||||
u8 adt_destroy_branch( ADT_Node* node );
|
||||
GEN_API u8 adt_destroy_branch( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Initialise an ADT leaf
|
||||
@@ -140,7 +140,7 @@ u8 adt_destroy_branch( ADT_Node* node );
|
||||
* @param type Node's type (use zpl_adt_make_branch for container nodes)
|
||||
* @return error code
|
||||
*/
|
||||
u8 adt_make_leaf( ADT_Node* node, char const* name, ADT_Type type );
|
||||
GEN_API u8 adt_make_leaf( ADT_Node* node, char const* name, ADT_Type type );
|
||||
|
||||
|
||||
/**
|
||||
@@ -160,7 +160,7 @@ u8 adt_make_leaf( ADT_Node* node, char const* name, ADT_Type type );
|
||||
*
|
||||
* @see code/apps/examples/json_get.c
|
||||
*/
|
||||
ADT_Node* adt_query( ADT_Node* node, char const* uri );
|
||||
GEN_API ADT_Node* adt_query( ADT_Node* node, char const* uri );
|
||||
|
||||
/**
|
||||
* @brief Find a field node within an object by the given name.
|
||||
@@ -170,7 +170,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri );
|
||||
* @param deep_search Perform search recursively
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
|
||||
GEN_API ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
|
||||
|
||||
/**
|
||||
* @brief Allocate an unitialised node within a container at a specified index.
|
||||
@@ -179,7 +179,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search );
|
||||
* @param index
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index );
|
||||
GEN_API ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index );
|
||||
|
||||
/**
|
||||
* @brief Allocate an unitialised node within a container.
|
||||
@@ -187,7 +187,7 @@ ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index );
|
||||
* @param parent
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_alloc( ADT_Node* parent );
|
||||
GEN_API ADT_Node* adt_alloc( ADT_Node* parent );
|
||||
|
||||
/**
|
||||
* @brief Move an existing node to a new container at a specified index.
|
||||
@@ -197,7 +197,7 @@ ADT_Node* adt_alloc( ADT_Node* parent );
|
||||
* @param index
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index );
|
||||
GEN_API ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index );
|
||||
|
||||
/**
|
||||
* @brief Move an existing node to a new container.
|
||||
@@ -206,7 +206,7 @@ ADT_Node* adt_move_node_at( ADT_Node* node, ADT_Node* new_parent, ssize index );
|
||||
* @param new_parent
|
||||
* @return zpl_adt_node * node
|
||||
*/
|
||||
ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent );
|
||||
GEN_API ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent );
|
||||
|
||||
/**
|
||||
* @brief Swap two nodes.
|
||||
@@ -215,7 +215,7 @@ ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent );
|
||||
* @param other_node
|
||||
* @return
|
||||
*/
|
||||
void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node );
|
||||
GEN_API void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node );
|
||||
|
||||
/**
|
||||
* @brief Remove node from container.
|
||||
@@ -223,7 +223,7 @@ void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node );
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
void adt_remove_node( ADT_Node* node );
|
||||
GEN_API void adt_remove_node( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as an object
|
||||
@@ -233,7 +233,7 @@ void adt_remove_node( ADT_Node* node );
|
||||
* @param backing
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
GEN_API b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as an array
|
||||
@@ -243,7 +243,7 @@ b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
* @param backing
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_arr( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
GEN_API b8 adt_set_arr( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as a string
|
||||
@@ -253,7 +253,7 @@ b8 adt_set_arr( ADT_Node* obj, char const* name, AllocatorInfo backing );
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_str( ADT_Node* obj, char const* name, char const* value );
|
||||
GEN_API b8 adt_set_str( ADT_Node* obj, char const* name, char const* value );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as a float
|
||||
@@ -263,7 +263,7 @@ b8 adt_set_str( ADT_Node* obj, char const* name, char const* value );
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_flt( ADT_Node* obj, char const* name, f64 value );
|
||||
GEN_API b8 adt_set_flt( ADT_Node* obj, char const* name, f64 value );
|
||||
|
||||
/**
|
||||
* @brief Initialise a node as a signed integer
|
||||
@@ -273,7 +273,7 @@ b8 adt_set_flt( ADT_Node* obj, char const* name, f64 value );
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
b8 adt_set_int( ADT_Node* obj, char const* name, s64 value );
|
||||
GEN_API b8 adt_set_int( ADT_Node* obj, char const* name, s64 value );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as an object
|
||||
@@ -282,7 +282,7 @@ b8 adt_set_int( ADT_Node* obj, char const* name, s64 value );
|
||||
* @param name
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_obj( ADT_Node* parent, char const* name );
|
||||
GEN_API ADT_Node* adt_append_obj( ADT_Node* parent, char const* name );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as an array
|
||||
@@ -291,7 +291,7 @@ ADT_Node* adt_append_obj( ADT_Node* parent, char const* name );
|
||||
* @param name
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_arr( ADT_Node* parent, char const* name );
|
||||
GEN_API ADT_Node* adt_append_arr( ADT_Node* parent, char const* name );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as a string
|
||||
@@ -301,7 +301,7 @@ ADT_Node* adt_append_arr( ADT_Node* parent, char const* name );
|
||||
* @param value
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_str( ADT_Node* parent, char const* name, char const* value );
|
||||
GEN_API ADT_Node* adt_append_str( ADT_Node* parent, char const* name, char const* value );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as a float
|
||||
@@ -311,7 +311,7 @@ ADT_Node* adt_append_str( ADT_Node* parent, char const* name, char const* value
|
||||
* @param value
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_flt( ADT_Node* parent, char const* name, f64 value );
|
||||
GEN_API ADT_Node* adt_append_flt( ADT_Node* parent, char const* name, f64 value );
|
||||
|
||||
/**
|
||||
* @brief Append a new node to a container as a signed integer
|
||||
@@ -321,7 +321,7 @@ ADT_Node* adt_append_flt( ADT_Node* parent, char const* name, f64 value );
|
||||
* @param value
|
||||
* @return*
|
||||
*/
|
||||
ADT_Node* adt_append_int( ADT_Node* parent, char const* name, s64 value );
|
||||
GEN_API ADT_Node* adt_append_int( ADT_Node* parent, char const* name, s64 value );
|
||||
|
||||
/* parser helpers */
|
||||
|
||||
@@ -332,7 +332,7 @@ ADT_Node* adt_append_int( ADT_Node* parent, char const* name, s64 value );
|
||||
* @param base
|
||||
* @return*
|
||||
*/
|
||||
char* adt_parse_number( ADT_Node* node, char* base );
|
||||
GEN_API char* adt_parse_number( ADT_Node* node, char* base );
|
||||
|
||||
/**
|
||||
* @brief Parses a text and stores the result into an unitialised node.
|
||||
@@ -342,7 +342,7 @@ char* adt_parse_number( ADT_Node* node, char* base );
|
||||
* @param base
|
||||
* @return*
|
||||
*/
|
||||
char* adt_parse_number_strict( ADT_Node* node, char* base_str );
|
||||
GEN_API char* adt_parse_number_strict( ADT_Node* node, char* base_str );
|
||||
|
||||
/**
|
||||
* @brief Parses and converts an existing string node into a number.
|
||||
@@ -350,7 +350,7 @@ char* adt_parse_number_strict( ADT_Node* node, char* base_str );
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_c_str_to_number( ADT_Node* node );
|
||||
GEN_API ADT_Error adt_c_str_to_number( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Parses and converts an existing string node into a number.
|
||||
@@ -359,7 +359,7 @@ ADT_Error adt_c_str_to_number( ADT_Node* node );
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_c_str_to_number_strict( ADT_Node* node );
|
||||
GEN_API ADT_Error adt_c_str_to_number_strict( ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Prints a number into a file stream.
|
||||
@@ -371,7 +371,7 @@ ADT_Error adt_c_str_to_number_strict( ADT_Node* node );
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_print_number( FileInfo* file, ADT_Node* node );
|
||||
GEN_API ADT_Error adt_print_number( FileInfo* file, ADT_Node* node );
|
||||
|
||||
/**
|
||||
* @brief Prints a string into a file stream.
|
||||
@@ -385,7 +385,7 @@ ADT_Error adt_print_number( FileInfo* file, ADT_Node* node );
|
||||
* @param escape_symbol
|
||||
* @return
|
||||
*/
|
||||
ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_chars, char const* escape_symbol );
|
||||
GEN_API ADT_Error adt_print_string( FileInfo* file, ADT_Node* node, char const* escaped_chars, char const* escape_symbol );
|
||||
|
||||
#pragma endregion ADT
|
||||
|
||||
@@ -401,14 +401,14 @@ enum CSV_Error : u32
|
||||
|
||||
typedef ADT_Node CSV_Object;
|
||||
|
||||
u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
|
||||
u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
|
||||
void csv_free( CSV_Object* obj );
|
||||
u8 csv_parse( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header );
|
||||
GEN_API u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim );
|
||||
void csv_free( CSV_Object* obj );
|
||||
|
||||
void csv_write( FileInfo* file, CSV_Object* obj );
|
||||
StrBuilder csv_write_string( AllocatorInfo a, CSV_Object* obj );
|
||||
void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
|
||||
StrBuilder csv_write_strbuilder_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
|
||||
void csv_write( FileInfo* file, CSV_Object* obj );
|
||||
StrBuilder csv_write_string( AllocatorInfo a, CSV_Object* obj );
|
||||
GEN_API void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delim );
|
||||
GEN_API StrBuilder csv_write_strbuilder_delimiter( AllocatorInfo a, CSV_Object* obj, char delim );
|
||||
|
||||
/* inline */
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strbuilder_ops.cpp"
|
||||
# include "string_ops.cpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "strbuilder_ops.hpp"
|
||||
# include "string_ops.hpp"
|
||||
#endif
|
||||
|
||||
#pragma region Printing
|
||||
@@ -13,30 +13,17 @@ typedef struct FileInfo FileInfo;
|
||||
typedef char PrintF_Buffer[GEN_PRINTF_MAXLEN];
|
||||
|
||||
// NOTE: A locally persisting buffer is used internally
|
||||
char* c_str_fmt_buf ( char const* fmt, ... );
|
||||
char* c_str_fmt_buf_va ( char const* fmt, va_list va );
|
||||
ssize c_str_fmt ( char* str, ssize n, char const* fmt, ... );
|
||||
ssize c_str_fmt_va ( char* str, ssize n, char const* fmt, va_list va );
|
||||
ssize c_str_fmt_out_va ( char const* fmt, va_list va );
|
||||
ssize c_str_fmt_out_err ( char const* fmt, ... );
|
||||
ssize c_str_fmt_out_err_va( char const* fmt, va_list va );
|
||||
ssize c_str_fmt_file ( FileInfo* f, char const* fmt, ... );
|
||||
ssize c_str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
|
||||
GEN_API char* c_str_fmt_buf ( char const* fmt, ... );
|
||||
GEN_API char* c_str_fmt_buf_va ( char const* fmt, va_list va );
|
||||
GEN_API ssize c_str_fmt ( char* str, ssize n, char const* fmt, ... );
|
||||
GEN_API ssize c_str_fmt_va ( char* str, ssize n, char const* fmt, va_list va );
|
||||
GEN_API ssize c_str_fmt_out_va ( char const* fmt, va_list va );
|
||||
GEN_API ssize c_str_fmt_out_err ( char const* fmt, ... );
|
||||
GEN_API ssize c_str_fmt_out_err_va( char const* fmt, va_list va );
|
||||
GEN_API ssize c_str_fmt_file ( FileInfo* f, char const* fmt, ... );
|
||||
GEN_API ssize c_str_fmt_file_va ( FileInfo* f, char const* fmt, va_list va );
|
||||
|
||||
constexpr
|
||||
char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED";
|
||||
|
||||
inline
|
||||
ssize log_fmt(char const* fmt, ...)
|
||||
{
|
||||
ssize res;
|
||||
va_list va;
|
||||
|
||||
va_start(va, fmt);
|
||||
res = c_str_fmt_out_va(fmt, va);
|
||||
va_end(va);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#pragma endregion Printing
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "header_start.hpp"
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "debug.cpp"
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "memory.hpp"
|
||||
#endif
|
||||
@@ -33,10 +33,10 @@ char const* c_str_trim( char const* str, b32 catch_newline );
|
||||
void c_str_to_lower( char* str );
|
||||
void c_str_to_upper( char* str );
|
||||
|
||||
s64 c_str_to_i64( const char* str, char** end_ptr, s32 base );
|
||||
void i64_to_str( s64 value, char* string, s32 base );
|
||||
void u64_to_str( u64 value, char* string, s32 base );
|
||||
f64 c_str_to_f64( const char* str, char** end_ptr );
|
||||
GEN_API s64 c_str_to_i64( const char* str, char** end_ptr, s32 base );
|
||||
GEN_API void i64_to_str( s64 value, char* string, s32 base );
|
||||
GEN_API void u64_to_str( u64 value, char* string, s32 base );
|
||||
GEN_API f64 c_str_to_f64( const char* str, char** end_ptr );
|
||||
|
||||
inline
|
||||
const char* char_first_occurence( const char* s, char c )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "hashing.cpp"
|
||||
#endif
|
||||
@@ -58,4 +58,120 @@ StrBuilder strbuilder_make_reserve( AllocatorInfo allocator, ssize capacity )
|
||||
return result;
|
||||
}
|
||||
|
||||
bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len)
|
||||
{
|
||||
ssize available = strbuilder_avail_space(* str);
|
||||
|
||||
if (available >= add_len) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ssize new_len, old_size, new_size;
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = strbuilder_get_header(* str)->Allocator;
|
||||
StrBuilderHeader* header = nullptr;
|
||||
|
||||
new_len = strbuilder_grow_formula(strbuilder_length(* str) + add_len);
|
||||
ptr = strbuilder_get_header(* str);
|
||||
old_size = size_of(StrBuilderHeader) + strbuilder_length(* str) + 1;
|
||||
new_size = size_of(StrBuilderHeader) + new_len + 1;
|
||||
|
||||
new_ptr = resize(allocator, ptr, old_size, new_size);
|
||||
|
||||
if (new_ptr == nullptr)
|
||||
return false;
|
||||
|
||||
header = rcast(StrBuilderHeader*, new_ptr);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
char** Data = rcast(char**, str);
|
||||
* Data = rcast(char*, header + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool strbuilder_append_c_str_len(StrBuilder* str, char const* c_str_to_append, ssize append_length)
|
||||
{
|
||||
GEN_ASSERT(str != nullptr);
|
||||
if ( rcast(sptr, c_str_to_append) > 0)
|
||||
{
|
||||
ssize curr_len = strbuilder_length(* str);
|
||||
|
||||
if ( ! strbuilder_make_space_for(str, c_str_to_append, append_length))
|
||||
return false;
|
||||
|
||||
StrBuilderHeader* header = strbuilder_get_header(* str);
|
||||
|
||||
char* Data = * str;
|
||||
mem_copy( Data + curr_len, c_str_to_append, append_length);
|
||||
|
||||
Data[curr_len + append_length] = '\0';
|
||||
|
||||
header->Length = curr_len + append_length;
|
||||
}
|
||||
return c_str_to_append != nullptr;
|
||||
}
|
||||
|
||||
void strbuilder_trim(StrBuilder str, char const* cut_set)
|
||||
{
|
||||
ssize len = 0;
|
||||
|
||||
char* start_pos = str;
|
||||
char* end_pos = scast(char*, str) + strbuilder_length(str) - 1;
|
||||
|
||||
while (start_pos <= end_pos && char_first_occurence(cut_set, *start_pos))
|
||||
start_pos++;
|
||||
|
||||
while (end_pos > start_pos && char_first_occurence(cut_set, *end_pos))
|
||||
end_pos--;
|
||||
|
||||
len = scast(ssize, (start_pos > end_pos) ? 0 : ((end_pos - start_pos) + 1));
|
||||
|
||||
if (str != start_pos)
|
||||
mem_move(str, start_pos, len);
|
||||
|
||||
str[len] = '\0';
|
||||
|
||||
strbuilder_get_header(str)->Length = len;
|
||||
}
|
||||
|
||||
StrBuilder strbuilder_visualize_whitespace(StrBuilder const str)
|
||||
{
|
||||
StrBuilderHeader* header = (StrBuilderHeader*)(scast(char const*, str) - sizeof(StrBuilderHeader));
|
||||
StrBuilder result = strbuilder_make_reserve(header->Allocator, strbuilder_length(str) * 2); // Assume worst case for space requirements.
|
||||
|
||||
for (char const* c = strbuilder_begin(str); c != strbuilder_end(str); c = strbuilder_next(str, c))
|
||||
switch ( * c )
|
||||
{
|
||||
case ' ':
|
||||
strbuilder_append_str(& result, txt("·"));
|
||||
break;
|
||||
case '\t':
|
||||
strbuilder_append_str(& result, txt("→"));
|
||||
break;
|
||||
case '\n':
|
||||
strbuilder_append_str(& result, txt("↵"));
|
||||
break;
|
||||
case '\r':
|
||||
strbuilder_append_str(& result, txt("⏎"));
|
||||
break;
|
||||
case '\v':
|
||||
strbuilder_append_str(& result, txt("⇕"));
|
||||
break;
|
||||
case '\f':
|
||||
strbuilder_append_str(& result, txt("⌂"));
|
||||
break;
|
||||
default:
|
||||
strbuilder_append_char(& result, * c);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#pragma endregion StrBuilder
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "hashing.hpp"
|
||||
#endif
|
||||
@@ -122,19 +122,22 @@ struct StrBuilder;
|
||||
|
||||
forceinline usize strbuilder_grow_formula(usize value);
|
||||
|
||||
GEN_API StrBuilder strbuilder_make_reserve (AllocatorInfo allocator, ssize capacity);
|
||||
GEN_API StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
|
||||
GEN_API bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
|
||||
GEN_API bool strbuilder_append_c_str_len (StrBuilder* str, char const* c_str_to_append, ssize length);
|
||||
GEN_API void strbuilder_trim (StrBuilder str, char const* cut_set);
|
||||
GEN_API StrBuilder strbuilder_visualize_whitespace(StrBuilder const str);
|
||||
|
||||
StrBuilder strbuilder_make_c_str (AllocatorInfo allocator, char const* str);
|
||||
StrBuilder strbuilder_make_str (AllocatorInfo allocator, Str str);
|
||||
StrBuilder strbuilder_make_reserve (AllocatorInfo allocator, ssize capacity);
|
||||
StrBuilder strbuilder_make_length (AllocatorInfo allocator, char const* str, ssize length);
|
||||
StrBuilder strbuilder_fmt (AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ...);
|
||||
StrBuilder strbuilder_fmt_buf (AllocatorInfo allocator, char const* fmt, ...);
|
||||
StrBuilder strbuilder_join (AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue);
|
||||
bool strbuilder_are_equal (StrBuilder const lhs, StrBuilder const rhs);
|
||||
bool strbuilder_are_equal_str (StrBuilder const lhs, Str rhs);
|
||||
bool strbuilder_make_space_for (StrBuilder* str, char const* to_append, ssize add_len);
|
||||
bool strbuilder_append_char (StrBuilder* str, char c);
|
||||
bool strbuilder_append_c_str (StrBuilder* str, char const* c_str_to_append);
|
||||
bool strbuilder_append_c_str_len (StrBuilder* str, char const* c_str_to_append, ssize length);
|
||||
bool strbuilder_append_str (StrBuilder* str, Str c_str_to_append);
|
||||
bool strbuilder_append_string (StrBuilder* str, StrBuilder const other);
|
||||
bool strbuilder_append_fmt (StrBuilder* str, char const* fmt, ...);
|
||||
@@ -153,9 +156,7 @@ b32 strbuilder_starts_with_string (StrBuilder const str, StrBuild
|
||||
void strbuilder_skip_line (StrBuilder str);
|
||||
void strbuilder_strip_space (StrBuilder str);
|
||||
Str strbuilder_to_str (StrBuilder str);
|
||||
void strbuilder_trim (StrBuilder str, char const* cut_set);
|
||||
void strbuilder_trim_space (StrBuilder str);
|
||||
StrBuilder strbuilder_visualize_whitespace(StrBuilder const str);
|
||||
|
||||
struct StrBuilderHeader {
|
||||
AllocatorInfo Allocator;
|
||||
@@ -319,7 +320,7 @@ inline
|
||||
StrBuilder strbuilder_fmt_buf(AllocatorInfo allocator, char const* fmt, ...)
|
||||
{
|
||||
local_persist thread_local
|
||||
PrintF_Buffer buf = struct_init(PrintF_Buffer, {0});
|
||||
PrintF_Buffer buf = struct_zero_init();
|
||||
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
@@ -357,29 +358,6 @@ bool strbuilder_append_c_str(StrBuilder* str, char const* c_str_to_append) {
|
||||
return strbuilder_append_c_str_len(str, c_str_to_append, c_str_len(c_str_to_append));
|
||||
}
|
||||
|
||||
inline
|
||||
bool strbuilder_append_c_str_len(StrBuilder* str, char const* c_str_to_append, ssize append_length)
|
||||
{
|
||||
GEN_ASSERT(str != nullptr);
|
||||
if ( rcast(sptr, c_str_to_append) > 0)
|
||||
{
|
||||
ssize curr_len = strbuilder_length(* str);
|
||||
|
||||
if ( ! strbuilder_make_space_for(str, c_str_to_append, append_length))
|
||||
return false;
|
||||
|
||||
StrBuilderHeader* header = strbuilder_get_header(* str);
|
||||
|
||||
char* Data = * str;
|
||||
mem_copy( Data + curr_len, c_str_to_append, append_length);
|
||||
|
||||
Data[curr_len + append_length] = '\0';
|
||||
|
||||
header->Length = curr_len + append_length;
|
||||
}
|
||||
return c_str_to_append != nullptr;
|
||||
}
|
||||
|
||||
forceinline
|
||||
bool strbuilder_append_str(StrBuilder* str, Str c_str_to_append) {
|
||||
GEN_ASSERT(str != nullptr);
|
||||
@@ -521,44 +499,6 @@ ssize strbuilder_length(StrBuilder const str)
|
||||
return header->Length;
|
||||
}
|
||||
|
||||
inline
|
||||
bool strbuilder_make_space_for(StrBuilder* str, char const* to_append, ssize add_len)
|
||||
{
|
||||
ssize available = strbuilder_avail_space(* str);
|
||||
|
||||
if (available >= add_len) {
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ssize new_len, old_size, new_size;
|
||||
void* ptr;
|
||||
void* new_ptr;
|
||||
|
||||
AllocatorInfo allocator = strbuilder_get_header(* str)->Allocator;
|
||||
StrBuilderHeader* header = nullptr;
|
||||
|
||||
new_len = strbuilder_grow_formula(strbuilder_length(* str) + add_len);
|
||||
ptr = strbuilder_get_header(* str);
|
||||
old_size = size_of(StrBuilderHeader) + strbuilder_length(* str) + 1;
|
||||
new_size = size_of(StrBuilderHeader) + new_len + 1;
|
||||
|
||||
new_ptr = resize(allocator, ptr, old_size, new_size);
|
||||
|
||||
if (new_ptr == nullptr)
|
||||
return false;
|
||||
|
||||
header = rcast(StrBuilderHeader*, new_ptr);
|
||||
header->Allocator = allocator;
|
||||
header->Capacity = new_len;
|
||||
|
||||
char** Data = rcast(char**, str);
|
||||
* Data = rcast(char*, header + 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
forceinline
|
||||
b32 strbuilder_starts_with_str(StrBuilder const str, Str substring) {
|
||||
if (substring.Len > strbuilder_length(str))
|
||||
@@ -626,69 +566,11 @@ Str strbuilder_to_str(StrBuilder str) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline
|
||||
void strbuilder_trim(StrBuilder str, char const* cut_set)
|
||||
{
|
||||
ssize len = 0;
|
||||
|
||||
char* start_pos = str;
|
||||
char* end_pos = scast(char*, str) + strbuilder_length(str) - 1;
|
||||
|
||||
while (start_pos <= end_pos && char_first_occurence(cut_set, *start_pos))
|
||||
start_pos++;
|
||||
|
||||
while (end_pos > start_pos && char_first_occurence(cut_set, *end_pos))
|
||||
end_pos--;
|
||||
|
||||
len = scast(ssize, (start_pos > end_pos) ? 0 : ((end_pos - start_pos) + 1));
|
||||
|
||||
if (str != start_pos)
|
||||
mem_move(str, start_pos, len);
|
||||
|
||||
str[len] = '\0';
|
||||
|
||||
strbuilder_get_header(str)->Length = len;
|
||||
}
|
||||
|
||||
forceinline
|
||||
void strbuilder_trim_space(StrBuilder str) {
|
||||
strbuilder_trim(str, " \t\r\n\v\f");
|
||||
}
|
||||
|
||||
inline
|
||||
StrBuilder strbuilder_visualize_whitespace(StrBuilder const str)
|
||||
{
|
||||
StrBuilderHeader* header = (StrBuilderHeader*)(scast(char const*, str) - sizeof(StrBuilderHeader));
|
||||
StrBuilder result = strbuilder_make_reserve(header->Allocator, strbuilder_length(str) * 2); // Assume worst case for space requirements.
|
||||
|
||||
for (char const* c = strbuilder_begin(str); c != strbuilder_end(str); c = strbuilder_next(str, c))
|
||||
switch ( * c )
|
||||
{
|
||||
case ' ':
|
||||
strbuilder_append_str(& result, txt("·"));
|
||||
break;
|
||||
case '\t':
|
||||
strbuilder_append_str(& result, txt("→"));
|
||||
break;
|
||||
case '\n':
|
||||
strbuilder_append_str(& result, txt("↵"));
|
||||
break;
|
||||
case '\r':
|
||||
strbuilder_append_str(& result, txt("⏎"));
|
||||
break;
|
||||
case '\v':
|
||||
strbuilder_append_str(& result, txt("⇕"));
|
||||
break;
|
||||
case '\f':
|
||||
strbuilder_append_str(& result, txt("⌂"));
|
||||
break;
|
||||
default:
|
||||
strbuilder_append_char(& result, * c);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#pragma endregion StrBuilder
|
||||
|
||||
#if GEN_COMPILER_CPP
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.cpp"
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# pragma once
|
||||
# include "filesystem.hpp"
|
||||
#endif
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#ifdef GEN_BENCHMARK
|
||||
//! Return CPU timestamp.
|
||||
u64 read_cpu_time_stamp_counter( void );
|
||||
GEN_API u64 read_cpu_time_stamp_counter( void );
|
||||
|
||||
//! Return relative time (in seconds) since the application start.
|
||||
f64 time_rel( void );
|
||||
GEN_API f64 time_rel( void );
|
||||
|
||||
//! Return relative time since the application start.
|
||||
u64 time_rel_ms( void );
|
||||
GEN_API u64 time_rel_ms( void );
|
||||
#endif
|
||||
|
||||
#pragma endregion Timing
|
||||
@@ -24,4 +24,5 @@ Final, final
|
||||
NoExceptions, noexcept
|
||||
Override, override
|
||||
Pure, = 0
|
||||
Delete, = delete
|
||||
Volatile, volatile
|
||||
|
+2
-2
@@ -37,8 +37,8 @@ GEN_NS_BEGIN
|
||||
#include "components/interface.parsing.cpp"
|
||||
#include "components/interface.untyped.cpp"
|
||||
|
||||
#include "auxillary/builder.cpp"
|
||||
#include "auxillary/scanner.cpp"
|
||||
#include "auxiliary/builder.cpp"
|
||||
#include "auxiliary/scanner.cpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
|
||||
+3
-6
@@ -11,9 +11,6 @@
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "components/header_start.hpp"
|
||||
|
||||
// Has container defines pushed
|
||||
#include "gen.dep.hpp"
|
||||
|
||||
GEN_NS_BEGIN
|
||||
|
||||
#include "components/types.hpp"
|
||||
@@ -29,12 +26,12 @@ GEN_NS_BEGIN
|
||||
|
||||
#include "components/interface.hpp"
|
||||
|
||||
#include "components/constants.hpp"
|
||||
#include "components/inlines.hpp"
|
||||
#include "components/gen/ast_inlines.hpp"
|
||||
#include "components/header_end.hpp"
|
||||
|
||||
#include "auxillary/builder.hpp"
|
||||
#include "auxillary/scanner.hpp"
|
||||
#include "auxiliary/builder.hpp"
|
||||
#include "auxiliary/scanner.hpp"
|
||||
|
||||
GEN_NS_END
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#if GEN_INTELLISENSE_DIRECTIVES
|
||||
#if INTELLISENSE_DIRECTIVES
|
||||
# include "../gen.hpp"
|
||||
# include "misc.hpp"
|
||||
|
||||
@@ -220,6 +220,7 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
|
||||
case Spec_NoExceptions:
|
||||
case Spec_Override:
|
||||
case Spec_Pure:
|
||||
case Spec_Delete:
|
||||
case Spec_Volatile:
|
||||
return true;
|
||||
|
||||
|
||||
+19
-7
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef GEN_INTELLISENSE_DIRECTIVES
|
||||
#ifdef INTELLISENSE_DIRECTIVES
|
||||
# define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
# define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
# define GEN_EXPOSE_BACKEND
|
||||
# include "gen.hpp"
|
||||
# include "helpers/push_ignores.inline.hpp"
|
||||
# include "helpers/helper.hpp"
|
||||
# include "auxillary/builder.hpp"
|
||||
# include "auxillary/builder.cpp"
|
||||
# include "auxillary/scanner.hpp"
|
||||
# include "auxiliary/builder.hpp"
|
||||
# include "auxiliary/builder.cpp"
|
||||
# include "auxiliary/scanner.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -37,7 +37,11 @@ void clang_format_file( char const* path, char const* style_path )
|
||||
strbuilder_append_str( & command, cf_verbose );
|
||||
strbuilder_append_string( & command, style_arg );
|
||||
strbuilder_append_string( & command, resolved_path );
|
||||
system( command );
|
||||
int command_result = system( command );
|
||||
if ( command_result != 0 ) {
|
||||
log_fmt( "clang-format failed with status %d\n", command_result );
|
||||
process_exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
// Will refactor a file with the given script at the provided path.
|
||||
@@ -48,12 +52,20 @@ void refactor_file( char const* path, char const* refactor_script )
|
||||
GEN_ASSERT_NOT_NULL(path);
|
||||
GEN_ASSERT_NOT_NULL(refactor_script);
|
||||
|
||||
StrBuilder command = strbuilder_make_str(_ctx->Allocator_Temp, txt("refactor "));
|
||||
Str refactor_exe = GEN_SYSTEM_WINDOWS ?
|
||||
txt("\"..\\scripts\\helpers\\refactor.exe\" ")
|
||||
: txt("../scripts/helpers/refactor ");
|
||||
|
||||
StrBuilder command = strbuilder_make_str(_ctx->Allocator_Temp, refactor_exe);
|
||||
// strbuilder_append_str( & command, txt("-debug ") );
|
||||
strbuilder_append_str( & command, txt("-num=1 ") );
|
||||
strbuilder_append_fmt( & command, "-src=%s ", path );
|
||||
strbuilder_append_fmt( & command,"-spec=%s ", refactor_script );
|
||||
system(command);
|
||||
int command_result = system( command );
|
||||
if ( command_result != 0 ) {
|
||||
log_fmt( "refactor failed with status %d\n", command_result );
|
||||
process_exit( 1 );
|
||||
}
|
||||
log_fmt("\n");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ In order to abstract away constant use of `AST*` its wrapped in a Code type whic
|
||||
When its the [C generated variant of the library](../gen_c_library/)
|
||||
```c
|
||||
typedef AST* Code;
|
||||
tyepdef AST_<name>* Code<name>;
|
||||
typedef AST_<name>* Code<name>;
|
||||
...
|
||||
```
|
||||
|
||||
@@ -53,7 +53,7 @@ StrBuilder <prefix>_to_strbuilder(Code code);
|
||||
|
||||
Where the first generates strings allocated using Allocator_StringArena and the other appends an existing strings with their backed allocator.
|
||||
|
||||
Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ptr` & `code_to_strbuilder`.
|
||||
Serialization of for the AST is defined for `Code` in [`ast.cpp`](../base/components/ast.cpp) with `code_to_strbuilder_ref` & `code_to_strbuilder`.
|
||||
Serializtion for the rest of the code types is within [`code_serialization.cpp`](../base/components/code_serialization.cpp).
|
||||
|
||||
Gencpp's serialization does not provide coherent formatting of the code. The user should use a formatter after serializing.
|
||||
+4
-4
@@ -6,7 +6,7 @@
|
||||
|
||||
# AST Types Documentation
|
||||
|
||||
While the Readme for docs covers the data layout per AST, this will focus on the AST types avaialble, and their nuances.
|
||||
While the Readme for docs covers the data layout per AST, this will focus on the AST types available, and their nuances.
|
||||
|
||||
## Body
|
||||
|
||||
@@ -37,7 +37,7 @@ 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 CodeType type for the type of defintion used.
|
||||
Parent should have a compatible CodeType type for the type of definition used.
|
||||
|
||||
Serialization:
|
||||
|
||||
@@ -95,7 +95,7 @@ Serialization:
|
||||
<Content>
|
||||
```
|
||||
|
||||
The parser will perserve comments found if residing with a body or in accepted inline-to-definition locations.
|
||||
The parser will preserve 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.
|
||||
@@ -289,7 +289,7 @@ Serialization:
|
||||
## Execution
|
||||
|
||||
Just represents an execution body. Equivalent to an untyped body.
|
||||
Will be obsolute when function body parsing is implemented.
|
||||
Will be obsolete when function body parsing is implemented.
|
||||
|
||||
Fields:
|
||||
|
||||
|
||||
+9
-9
@@ -4,7 +4,7 @@
|
||||
|
||||
<- [docs - General](Readme.md)
|
||||
|
||||
# Parser's Algorithim
|
||||
# Parser's Algorithm
|
||||
|
||||
gencpp uses a hand-written recursive descent parser. Both the lexer and parser currently handle a full C/C++ file in a single pass.
|
||||
|
||||
@@ -399,7 +399,7 @@ Below is an outline of the general alogirithim used for these internal procedure
|
||||
|
||||
## `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
|
||||
This is needed as a function definition 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
|
||||
@@ -548,7 +548,7 @@ In the future statements and expressions will be parsed.
|
||||
|
||||
### Implementation Constraints
|
||||
|
||||
* Cannot definitively distinguish nested namespaces with identical names
|
||||
* Cannot distinguish nested namespaces with identical names
|
||||
* Return type detection requires parser enhancement
|
||||
* Template parameter validation is syntax-based only
|
||||
* Future enhancement: Implement type parsing with rollback capability
|
||||
@@ -595,7 +595,7 @@ Notes:
|
||||
|
||||
## `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.
|
||||
This is needed as a operator definition 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, and return type
|
||||
|
||||
@@ -639,7 +639,7 @@ By the point this function is called the following are known : export module fla
|
||||
|
||||
## `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.
|
||||
When this function is called, attribute and specifiers may have been resolved, however what comes next can still be either an operator, function, or variable.
|
||||
|
||||
1. Initial Type Resolution
|
||||
1. Push parsing scope
|
||||
@@ -792,7 +792,7 @@ This will get changed heavily once we have better support for typename expressio
|
||||
|
||||
## `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.
|
||||
This is needed as a variable definition 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. Initialization Processing
|
||||
@@ -1090,7 +1090,7 @@ Limitations:
|
||||
|
||||
This implementatin will be updated in the future to properly handle functional typename signatures.
|
||||
|
||||
### Current Algorithim
|
||||
### Current Algorithm
|
||||
|
||||
Anything that is in the qualifier capture of the function typename is treated as an expression abstracted as an untyped string
|
||||
|
||||
@@ -1119,7 +1119,7 @@ Anything that is in the qualifier capture of the function typename is treated as
|
||||
8. Check for varaidic argument (param pack) token:
|
||||
1. Consume varadic argument token
|
||||
|
||||
### WIP - Alternative Algorithim
|
||||
### WIP - Alternative Algorithm
|
||||
|
||||
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
|
||||
@@ -1152,7 +1152,7 @@ Anything that is in the qualifier capture of the function typename is treated as
|
||||
7. Check for varaidic argument (param pack) token:
|
||||
1. Consume varadic argument token
|
||||
|
||||
### **Later: Algorithim based on typename expressions**
|
||||
### **Later: Algorithm based on typename expressions**
|
||||
|
||||
## `parse_typedef`
|
||||
|
||||
|
||||
+5
-5
@@ -10,11 +10,14 @@ The library features a naive single-pass parser, tailored for only what the libr
|
||||
|
||||
This parser does not, and should not do the compiler's job. By only supporting this minimal set of features, the parser is kept (so far) around ~7000 loc. I hope to keep it under 10-15k loc worst case.
|
||||
|
||||
You can think of this parser as *frontend parser* vs a *semantic parser*. Its intuitively similar to WYSIWYG. What you ***precerive*** as the syntax from the user-side before the compiler gets a hold of it, is what you get.
|
||||
You can think of this parser as *frontend parser* vs a *semantic parser*. Its intuitively similar to WYSIWYG. What you ***perceive*** as the syntax from the user-side before the compiler gets a hold of it, is what you get.
|
||||
|
||||
User exposed interface:
|
||||
|
||||
```cpp
|
||||
CodeBody parse_global_body ( Str body_def, Opts_parse_global_body opts );
|
||||
void parse_global_body_base( Context* ctx, Str body_def, ParseInfo* info );
|
||||
|
||||
CodeClass parse_class ( Str class_def );
|
||||
CodeConstructor parse_constructor ( Str constructor_def );
|
||||
CodeDefine parse_define ( Str define_def );
|
||||
@@ -24,7 +27,6 @@ CodeBody parse_export_body ( Str export_def );
|
||||
CodeExtern parse_extern_link ( Str exten_link_def );
|
||||
CodeFriend parse_friend ( Str friend_def );
|
||||
CodeFn parse_function ( Str fn_def );
|
||||
CodeBody parse_global_body ( Str body_def );
|
||||
CodeNS parse_namespace ( Str namespace_def );
|
||||
CodeOperator parse_operator ( Str operator_def );
|
||||
CodeOpCast parse_operator_cast( Str operator_def );
|
||||
@@ -63,7 +65,7 @@ The preprocessor lines are stored as members of their associated scope they are
|
||||
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:
|
||||
|
||||
* varaible definitions are allowed for a preprocessed macro `extern MACRO();`
|
||||
* variable definitions are allowed for a preprocessed macro `extern MACRO();`
|
||||
* function definitions are allowed for a preprocessed macro: `neverinline MACRO() { ... }`
|
||||
* Disable with: `#define GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES`
|
||||
* typedefs allow for a preprocessed macro: `typedef MACRO();`
|
||||
@@ -155,5 +157,3 @@ typedef HashTable(Macro) MacroTable;
|
||||
* 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)
|
||||
* This is useful for example: parsing Unreal `Module_API` macros.
|
||||
|
||||
**The lexer & parser do not gracefully attempt to continue when it comes across incorrect code, and doesn't properly track errors into a listing (yet).**
|
||||
+3
-3
@@ -260,7 +260,7 @@ def_global_body( args( ht_entry, array_ht_entry, hashtable ));
|
||||
def_global_body( 3, ht_entry, array_ht_entry, hashtable );
|
||||
```
|
||||
|
||||
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty body.
|
||||
If a more incremental approach is desired for the body ASTs, `Code def_body( CodeT type )` can be used to create an empty bodyss
|
||||
When the members have been populated use: `code_validate_body` to verify that the members are valid entires for that type.
|
||||
|
||||
### Parse construction
|
||||
@@ -432,7 +432,7 @@ and have the desired specifiers assigned to them beforehand.
|
||||
|
||||
## Code generation and modification
|
||||
|
||||
There are two provided auxillary interfaces:
|
||||
There are two provided auxiliary interfaces:
|
||||
|
||||
* Builder
|
||||
* Scanner
|
||||
@@ -444,7 +444,7 @@ There are two provided auxillary interfaces:
|
||||
* The code is provided via print( code ) function will be serialized to its buffer.
|
||||
* When all serialization is finished, use the write() command to write the buffer to the file.
|
||||
|
||||
### Scanner Auxillary Interface
|
||||
### Scanner
|
||||
|
||||
* The purpose is to scan or parse files
|
||||
* Some with two basic functions to convert a fil to code: `scan_file` and `parse_file`
|
||||
|
||||
@@ -21,7 +21,7 @@ To generate a static or dynamic library:
|
||||
```ps1
|
||||
.\build.ps1 <compiler> <debug or omit> c_lib_static c_lib_dyn
|
||||
```
|
||||
|
||||
.
|
||||
All free from tag identifiers will be prefixed with `gen_` or `GEN_` as the namespace. This can either be changed after generation with a `.refactor` script (or your preferred subst method), OR by modifying [c_library.refactor](./c_library.refactor).
|
||||
|
||||
**If c_library.refactor is modified you may need to modify c_library.cpp and its [components](./components/). As some of the container generation relies on that prefix.**
|
||||
@@ -29,10 +29,10 @@ All free from tag identifiers will be prefixed with `gen_` or `GEN_` as the name
|
||||
## Generation structure
|
||||
|
||||
1. Files are scanned in or parsed.
|
||||
* If they are parsed, its dude to requiring some changes to either naming, or adding additonal definitions (container generation, typedefs, etc).
|
||||
* If they are parsed, its due to requiring some changes to either naming, or adding additonal definitions (container generation, typedefs, etc).
|
||||
2. All scanned or parsed code is refactored (identifiers substs) and/or formatted.
|
||||
3. Singleheader generated.
|
||||
4. Segemented headers and source generated.
|
||||
4. Segmented headers and source generated.
|
||||
|
||||
## Templated container generation
|
||||
|
||||
@@ -43,7 +43,7 @@ The array and hashtable containers used across this library are generated using
|
||||
|
||||
These are functionally (and interface wise) equivalent to the library's `Array<Type>` `HashTable<Type>` within [containers.hpp](../base/dependencies/containers.hpp)
|
||||
|
||||
Both files follow the same patter of providing three procedures:
|
||||
Both files follow the same pattern of providing three procedures:
|
||||
|
||||
* `gen_<container>_base` : Intended to be called once, defines universal "base" definitions.
|
||||
* `gen_<container>` : Called per instatiation of the container for a given set of dependent args.
|
||||
@@ -54,11 +54,13 @@ A simple `<container>_DefinitionCounter` is used to know how many instantiations
|
||||
## Macro Usage
|
||||
|
||||
For the most part macros are kept minimal with exception to `_Generic`...
|
||||
*(I will be explaining this thing for the rest of this seciton along with gencpp c library's usage of it)*
|
||||
|
||||
The `_Generic` macro plays a key role in reducing direct need of the user to wrangle with mangled definition identifiers of 'templated' containers or for type coercion to map distinct data types to a common code path.
|
||||
|
||||
Because of its lack of use in many C11 libraries.. and, of those that do; they usually end up obfuscating it with excessive preprocessor abuse; Effort was put into minimizing how much of these macros are handled by the preprocessor vs gencpp itself.
|
||||
Many C11 libraries don't use it.. and, of those that do. they usually end up obfuscate it with excessive preprocessor abuse; Effort was put into minimizing how much of these macros are handled by the preprocessor vs gencpp itself.
|
||||
|
||||
*(I will be explaining this thing for the rest of this seciton along with gencpp c library's usage of it)*
|
||||
|
||||
|
||||
The usual presentation (done bare) is the following:
|
||||
|
||||
@@ -95,7 +97,7 @@ For this library's purposes we'll be using the functional macro equivalent *(if
|
||||
|
||||
```c
|
||||
#define macro_that_uses_selector_arg_for_resolving_a_fucntion( selecting_exp) \
|
||||
_Generic( (arg), \
|
||||
_Generic( (selecting_exp), \
|
||||
int : func_use_int, \
|
||||
double : func_use_double, \
|
||||
struct Whatnot : func_use_Whatnot, \
|
||||
|
||||
+215
-104
@@ -129,7 +129,8 @@ int gen_main()
|
||||
(Macro { txt("GEN_FILE_WRITE_AT_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||
(Macro { txt("GEN_FILE_SEEK_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||
(Macro { txt("GEN_FILE_CLOSE_PROC"), MT_Statement, MF_Functional | MF_Expects_Body }),
|
||||
(Macro { txt("log_failure"), MT_Expression, MF_Null }),
|
||||
(Macro { txt("log_failure"), MT_Statement, MF_Functional }),
|
||||
(Macro { txt("NullScope"), MT_Expression, MF_Null }),
|
||||
(Macro { txt("operator"), MT_Expression, MF_Null }),
|
||||
(Macro { txt("InvalidCode"), MT_Expression, MF_Null }),
|
||||
(Macro { txt("NullCode"), MT_Expression, MF_Null }),
|
||||
@@ -137,8 +138,8 @@ int gen_main()
|
||||
(Macro { txt("gen_main"), MT_Statement, MF_Null })
|
||||
));
|
||||
register_macros( args(
|
||||
(Macro { txt("name"), MT_Expression, MF_Functional }),
|
||||
(Macro { txt("code"), MT_Expression, MF_Functional }),
|
||||
(Macro { txt("name"), MT_Expression, MF_Functional | MF_Allow_As_Identifier }),
|
||||
(Macro { txt("code"), MT_Expression, MF_Functional | MF_Allow_As_Identifier }),
|
||||
(Macro { txt("args"), MT_Expression, MF_Functional }),
|
||||
(Macro { txt("code_str"), MT_Expression, MF_Functional }),
|
||||
(Macro { txt("code_fmt"), MT_Expression, MF_Functional }),
|
||||
@@ -306,7 +307,7 @@ do \
|
||||
break;
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_memory, header_memory );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_memory, header_memory );
|
||||
if (found) break;
|
||||
|
||||
header_memory.append(entry);
|
||||
@@ -334,7 +335,7 @@ do \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_printing, header_printing );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_printing, header_printing );
|
||||
if (found) break;
|
||||
|
||||
header_printing.append(entry);
|
||||
@@ -391,7 +392,7 @@ do \
|
||||
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_strings, header_strings );
|
||||
ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_strings, header_strings );
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -472,7 +473,7 @@ do \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_filesystem, header_filesystem );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_filesystem, header_filesystem );
|
||||
if (found) break;
|
||||
|
||||
header_filesystem.append(entry);
|
||||
@@ -494,10 +495,10 @@ do \
|
||||
case CT_Union_Fwd:
|
||||
{
|
||||
Str type_str = codetype_to_keyword_str(entry->Type);
|
||||
Str formated_tmpl = token_fmt_impl( 3,
|
||||
"type", type_str
|
||||
, "name", entry->Name,
|
||||
stringize(
|
||||
Str formated_tmpl = token_fmt_impl( 3
|
||||
, "type", type_str
|
||||
, "name", entry->Name
|
||||
, stringize(
|
||||
typedef <type> <name> <name>;
|
||||
));
|
||||
CodeTypedef tdef = parse_typedef(formated_tmpl);
|
||||
@@ -509,7 +510,7 @@ do \
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs.has(Spec_Constexpr) > -1)
|
||||
if (var->Specs.has(Spec_Constexpr))
|
||||
{
|
||||
Opts_def_define opts = { {}, entry->Value->Content };
|
||||
CodeDefine define = def_define(entry->Name, MT_Expression, opts);
|
||||
@@ -532,7 +533,7 @@ do \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_parsing, header_parsing );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_parsing, header_parsing );
|
||||
if (found) break;
|
||||
|
||||
header_parsing.append(entry);
|
||||
@@ -597,10 +598,10 @@ do \
|
||||
}
|
||||
|
||||
Str type_str = codetype_to_keyword_str(entry->Type);
|
||||
Str formated_tmpl = token_fmt_impl( 3,
|
||||
"type", type_str
|
||||
, "name", entry->Name,
|
||||
stringize(
|
||||
Str formated_tmpl = token_fmt_impl( 3
|
||||
, "type", type_str
|
||||
, "name", entry->Name
|
||||
, stringize(
|
||||
typedef <type> <name> <name>;
|
||||
));
|
||||
CodeTypedef tdef = parse_typedef(formated_tmpl);
|
||||
@@ -640,7 +641,7 @@ do \
|
||||
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_types, types );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_types, types );
|
||||
if (found) break;
|
||||
|
||||
types.append(entry);
|
||||
@@ -702,7 +703,7 @@ do \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_parser_types, parser_types );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_parser_types, parser_types );
|
||||
if (found) break;
|
||||
|
||||
parser_types.append(entry);
|
||||
@@ -739,10 +740,10 @@ do \
|
||||
{
|
||||
// pop the array entry
|
||||
array_token->NumEntries -= 1;
|
||||
Code next = array_entry->Next;
|
||||
Code prev = array_entry->Prev;
|
||||
next->Prev = array_entry->Prev;
|
||||
prev->Next = next;
|
||||
Code next = array_entry->Next;
|
||||
Code prev = array_entry->Prev;
|
||||
next->Prev = array_entry->Prev;
|
||||
prev->Next = next;
|
||||
if ( array_token->Front == array_entry )
|
||||
array_token->Front = next;
|
||||
|
||||
@@ -767,20 +768,7 @@ do \
|
||||
break;
|
||||
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) {
|
||||
Code define_ver = untyped_str(token_fmt(
|
||||
"name", var->Name
|
||||
, "value", var->Value->Content
|
||||
, "type", var->ValueType.to_strbuilder().to_str()
|
||||
, "#define <name> (<type>) <value>\n"
|
||||
));
|
||||
parser_types.append(define_ver);
|
||||
continue;
|
||||
}
|
||||
parser_types.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -797,7 +785,7 @@ do \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_ast, ast );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast, ast );
|
||||
@@ -978,7 +966,7 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
++ entry; // Skip a newline...
|
||||
break;
|
||||
}
|
||||
found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
|
||||
found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_code_types, code_types);
|
||||
@@ -995,7 +983,7 @@ R"(#define AST_ArrSpecs_Cap \
|
||||
/*
|
||||
This thing makes a:
|
||||
#define code_<interface_name>( code, ... ) _Generic( (code), \
|
||||
<slots> of defintions that look like: <typeof(code)>: code__<interface_name>, \
|
||||
<slots> of definitions that look like: <typeof(code)>: code__<interface_name>, \
|
||||
default: gen_generic_selection (Fail case) \
|
||||
) GEN_RESOLVED_FUNCTION_CALL( code, ... ) \
|
||||
*/
|
||||
@@ -1078,7 +1066,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_ast_types, ast_types );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_ast_types, ast_types );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_EXECUTION_EXPRESSION_SUPPORT"), entry, parsed_ast_types, ast_types);
|
||||
@@ -1132,7 +1120,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_interface, interface );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_interface, interface );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
|
||||
@@ -1155,10 +1143,33 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
for ( CodeParams opt_param : fn->Params ) if (opt_param->ValueType->Name.starts_with(txt("Opts_")))
|
||||
{
|
||||
// Convert the definition to use a default struct: https://vxtwitter.com/vkrajacic/status/1749816169736073295
|
||||
if ( fn->Name.is_equal( txt("parse_global_body") ) )
|
||||
{
|
||||
Str new_name = txt("parse_global_body_opts");
|
||||
char const* tmpl_fn_macro = "#define <def_name>( <params> ... ) <def__name>( <params> & (<opts_type>) { __VA_ARGS__ } )\n";
|
||||
Code fn_macro;
|
||||
|
||||
opt_param->ValueType->Specs = def_specifier( Spec_Ptr );
|
||||
fn_macro = untyped_str( token_fmt(
|
||||
"def_name", fn->Name
|
||||
, "def__name", new_name
|
||||
, "params", txt("def, ")
|
||||
, "opts_type", opt_param->ValueType->Name
|
||||
, tmpl_fn_macro
|
||||
));
|
||||
fn->Name = cache_str( new_name );
|
||||
interface.append( fn );
|
||||
interface.append( fn_macro );
|
||||
handled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Str prefix = txt("def_");
|
||||
Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len };
|
||||
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str();
|
||||
|
||||
opt_param->ValueType->Specs = def_specifier(Spec_Ptr);
|
||||
|
||||
// Resolve define's arguments
|
||||
b32 has_args = fn->Params->NumEntries > 1;
|
||||
StrBuilder params_str = StrBuilder::make_reserve(_ctx->Allocator_Temp, 32);
|
||||
@@ -1172,10 +1183,10 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
char const* tmpl_fn_macro = nullptr;
|
||||
if (params_str.length() > 0 ) {
|
||||
tmpl_fn_macro= "#define <def_name>( <params> ... ) <def__name>( <params> (<opts_type>) { __VA_ARGS__ } )\n";
|
||||
tmpl_fn_macro= "#define <def_name>( <params> ... ) <def__name>( <params> & (<opts_type>) { __VA_ARGS__ } )\n";
|
||||
}
|
||||
else {
|
||||
tmpl_fn_macro= "#define <def_name>( ... ) <def__name>( (<opts_type>) { __VA_ARGS__ } )\n";
|
||||
tmpl_fn_macro= "#define <def_name>( ... ) <def__name>( & (<opts_type>) { __VA_ARGS__ } )\n";
|
||||
}
|
||||
Code fn_macro = untyped_str(token_fmt(
|
||||
"def_name", fn->Name
|
||||
@@ -1221,7 +1232,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Preprocess_If:
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_inlines, inlines );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_inlines, inlines );
|
||||
if (found) break;
|
||||
|
||||
found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_interface, interface);
|
||||
@@ -1256,13 +1267,53 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
break;
|
||||
}
|
||||
|
||||
CodeBody parsed_header_builder = parse_file( path_base "auxillary/builder.hpp" );
|
||||
CodeBody header_builder = def_body(CT_Global_Body);
|
||||
s32 idx = 0;
|
||||
CodeBody parsed_constants = parse_file( path_base "components/constants.hpp" );
|
||||
CodeBody constants = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_constants.begin(); entry != parsed_constants.end(); ++ entry, ++ idx ) switch( entry->Type )
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_constants, constants );
|
||||
if (found) break;
|
||||
|
||||
constants.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs)
|
||||
{
|
||||
s32 constexpr_found = var->Specs.remove( Spec_Constexpr );
|
||||
if (constexpr_found > -1)
|
||||
{
|
||||
Opts_def_define opts = { {}, entry->Value->Content };
|
||||
CodeDefine define = def_define(entry->Name, MT_Expression, opts );
|
||||
constants.append(define);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
constants.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
constants.append(entry);
|
||||
break;
|
||||
}
|
||||
#pragma endregion Resolve Components
|
||||
|
||||
#pragma region Resolve Aux
|
||||
CodeDefine gsel_builder_print = NullCode;
|
||||
CodeBody parsed_header_builder = parse_file( path_base "auxiliary/builder.hpp" );
|
||||
CodeBody header_builder = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_builder.begin(); entry != parsed_header_builder.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_builder, header_builder );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_header_builder, header_builder );
|
||||
if (found) break;
|
||||
|
||||
header_builder.append(entry);
|
||||
@@ -1281,6 +1332,51 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Function_Fwd:
|
||||
{
|
||||
CodeFn fn = cast(CodeFn, entry);
|
||||
|
||||
if (! fn->Name.is_equal(txt("builder_print")) ) {
|
||||
header_builder.append(fn);
|
||||
continue;
|
||||
}
|
||||
|
||||
fn->Name = cache_str(txt("builder__print"));
|
||||
|
||||
StrBuilder generic_selector = StrBuilder::make(_ctx->Allocator_Temp,
|
||||
"#define builder_print(builder, code) _Generic( (code), \\\n"
|
||||
);
|
||||
// Append slots
|
||||
for(Str type : code_typenames ) {
|
||||
generic_selector.append_fmt("%S : %S,\\\n", type, fn->Name );
|
||||
}
|
||||
generic_selector.append(txt("default: gen_generic_selection_fail \\\n"));
|
||||
generic_selector.append(txt("\t)\tGEN_RESOLVED_FUNCTION_CALL( builder, (Code)code )"));
|
||||
|
||||
// We need to register this as an identifier macro now sot that parsing the source wont break.
|
||||
register_macro({ txt("builder_print"), MT_Statement, MF_Functional | MF_Allow_As_Identifier });
|
||||
|
||||
// We'll be adding this selector after builder_print_fmt
|
||||
gsel_builder_print = parse_define(generic_selector);
|
||||
|
||||
header_builder.append(fn);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Function:
|
||||
{
|
||||
CodeFn fn = cast(CodeFn, entry);
|
||||
|
||||
if ( fn->Name.is_equal(txt("builder_print_fmt")) ) {
|
||||
header_builder.append(fn);
|
||||
|
||||
// Add the selector right after
|
||||
header_builder.append(fmt_newline);
|
||||
header_builder.append(gsel_builder_print);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Struct:
|
||||
{
|
||||
CodeBody body = cast(CodeBody, entry->Body);
|
||||
@@ -1312,44 +1408,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header_builder.append(entry);
|
||||
break;
|
||||
}
|
||||
|
||||
s32 idx = 0;
|
||||
CodeBody parsed_header_end = parse_file( path_base "components/header_end.hpp" );
|
||||
CodeBody header_end = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_header_end.begin(); entry != parsed_header_end.end(); ++ entry, ++ idx ) switch( entry->Type )
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_header_end, header_end );
|
||||
if (found) break;
|
||||
|
||||
header_end.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs)
|
||||
{
|
||||
s32 constexpr_found = var->Specs.remove( Spec_Constexpr );
|
||||
if (constexpr_found > -1)
|
||||
{
|
||||
Opts_def_define opts = { {}, entry->Value->Content };
|
||||
CodeDefine define = def_define(entry->Name, MT_Expression, opts );
|
||||
header_end.append(define);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
header_end.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
header_end.append(entry);
|
||||
break;
|
||||
}
|
||||
#pragma endregion Resolve Components
|
||||
#pragma endregion Aux
|
||||
|
||||
// Source Content : Reflection and Generation
|
||||
|
||||
@@ -1372,6 +1431,29 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
Code src_code_serialization = scan_file( path_base "components/code_serialization.cpp" );
|
||||
|
||||
Code src_parsing_interface = scan_file( path_base "components/interface.parsing.cpp" );
|
||||
{
|
||||
Str needle = txt("CodeBody parse_global_body( Str def, Opts_parse_global_body opts )");
|
||||
Str scanned = src_parsing_interface->Content;
|
||||
ssize signature_at = -1;
|
||||
ssize scan_offset;
|
||||
ssize last_offset = scanned.Len - needle.Len;
|
||||
for ( scan_offset = 0; scan_offset <= last_offset; ++ scan_offset )
|
||||
{
|
||||
if ( c_str_compare_len( scanned.Ptr + scan_offset, needle.Ptr, needle.Len ) == 0 ) {
|
||||
signature_at = scan_offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( signature_at < 0 ) GEN_FATAL( "c_library: parse_global_body signature missing from scanned interface.parsing.cpp" );
|
||||
/*Resolved replacement*/ {
|
||||
Str replacement = txt("CodeBody parse_global_body_opts( Str def, Opts_parse_global_body* opts )");
|
||||
StrBuilder rebuilt = strbuilder_make_reserve( _ctx->Allocator_Temp, scanned.Len + replacement.Len );
|
||||
strbuilder_append_str( & rebuilt, Str { scanned.Ptr, signature_at } );
|
||||
strbuilder_append_str( & rebuilt, replacement );
|
||||
strbuilder_append_str( & rebuilt, Str { scanned.Ptr + signature_at + needle.Len, scanned.Len - signature_at - needle.Len } );
|
||||
src_parsing_interface = untyped_str( strbuilder_to_str( rebuilt ) );
|
||||
}
|
||||
}
|
||||
Code src_untyped = scan_file( path_base "components/interface.untyped.cpp" );
|
||||
Code src_parser_case_macros = scan_file( path_base "components/parser_case_macros.cpp" );
|
||||
|
||||
@@ -1398,7 +1480,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_ast, src_ast );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_ast, src_ast );
|
||||
if (found) break;
|
||||
|
||||
src_ast.append(entry);
|
||||
@@ -1433,7 +1515,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_upfront, src_upfront );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_upfront, src_upfront );
|
||||
if (found) break;
|
||||
|
||||
src_upfront.append(entry);
|
||||
@@ -1456,6 +1538,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
Str actual_name = { fn->Name.Ptr + prefix.Len, fn->Name.Len - prefix.Len };
|
||||
Str new_name = StrBuilder::fmt_buf(_ctx->Allocator_Temp, "def__%S", actual_name ).to_str();
|
||||
fn->Name = cache_str(new_name);
|
||||
opt_param->ValueType->Specs = def_specifier(Spec_Ptr);
|
||||
}
|
||||
src_upfront.append(fn);
|
||||
}
|
||||
@@ -1472,7 +1555,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_lexer, src_lexer );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_lexer, src_lexer );
|
||||
if (found) break;
|
||||
|
||||
src_lexer.append(entry);
|
||||
@@ -1494,7 +1577,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) {
|
||||
if (var->Specs && var->Specs.has(Spec_Constexpr)) {
|
||||
Code define_ver = untyped_str(token_fmt(
|
||||
"name", var->Name
|
||||
, "value", var->Value->Content
|
||||
@@ -1521,7 +1604,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
{
|
||||
case CT_Preprocess_IfDef:
|
||||
{
|
||||
b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_src_parser, src_parser );
|
||||
b32 found = ignore_preprocess_cond_block(txt("INTELLISENSE_DIRECTIVES"), entry, parsed_src_parser, src_parser );
|
||||
if (found) break;
|
||||
|
||||
src_parser.append(entry);
|
||||
@@ -1539,7 +1622,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
case CT_Variable:
|
||||
{
|
||||
CodeVar var = cast(CodeVar, entry);
|
||||
if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) {
|
||||
if (var->Specs && var->Specs.has(Spec_Constexpr)) {
|
||||
Code define_ver = untyped_str(token_fmt(
|
||||
"name", var->Name
|
||||
, "value", var->Value->Content
|
||||
@@ -1559,7 +1642,27 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
}
|
||||
#pragma endregion Resolve Components
|
||||
|
||||
// THERE SHOULD BE NO NEW GENERIC CONTAINER DEFINTIONS PAST THIS POINT (It will not have slots for the generic selection generated macros)
|
||||
#pragma region Resolve Aux
|
||||
CodeBody parsed_src_builder = parse_file( path_base "auxiliary/builder.cpp" );
|
||||
CodeBody src_builder = def_body(CT_Global_Body);
|
||||
for ( Code entry = parsed_src_builder.begin(); entry != parsed_src_builder.end(); ++ entry ) switch( entry->Type )
|
||||
{
|
||||
case CT_Function:
|
||||
{
|
||||
if (entry->Name.is_equal(txt("builder_print"))) {
|
||||
entry->Name = cache_str(txt("builder__print"));
|
||||
}
|
||||
src_builder.append(entry);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
src_builder.append(entry);
|
||||
break;
|
||||
}
|
||||
#pragma endregion ResolveAux
|
||||
|
||||
// THERE SHOULD BE NO NEW GENERIC CONTAINER DEFINITIONS PAST THIS POINT (It will not have slots for the generic selection generated macros)
|
||||
CodeBody containers = def_body(CT_Global_Body);
|
||||
{
|
||||
containers.append( def_pragma(code(region Containers)));
|
||||
@@ -1605,13 +1708,13 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
Code rf_ast_types = refactor_and_format(ast_types);
|
||||
|
||||
Code rf_interface = refactor_and_format(interface);
|
||||
Code rf_constants = refactor_and_format(constants);
|
||||
Code rf_inlines = refactor_and_format(inlines);
|
||||
|
||||
Code rf_ht_preprocessor_macro = refactor_and_format(ht_preprocessor_macro);
|
||||
Code rf_array_string_cached = refactor_and_format(array_string_cached);
|
||||
Code rf_header_end = refactor_and_format(header_end);
|
||||
Code rf_header_builder = refactor_and_format(header_builder);
|
||||
Code rf_header_scanner = refactor_and_format( scan_file( path_base "auxillary/scanner.hpp" ));
|
||||
Code rf_header_scanner = refactor_and_format( scan_file( path_base "auxiliary/scanner.hpp" ));
|
||||
|
||||
Code r_src_dep_start = refactor(src_dep_start);
|
||||
Code r_src_debug = refactor(src_debug);
|
||||
@@ -1644,8 +1747,8 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
CodeBody etoktype = gen_etoktype( path_base "enums/ETokType.csv", path_base "enums/AttributeTokens.csv", helper_use_c_definition );
|
||||
Code rf_etoktype = refactor_and_format(etoktype);
|
||||
|
||||
Code rf_src_builder = refactor_and_format( scan_file( path_base "auxillary/builder.cpp" ));
|
||||
Code rf_src_scanner = refactor_and_format( scan_file( path_base "auxillary/scanner.cpp" ));
|
||||
Code rf_src_builder = refactor_and_format( src_builder );
|
||||
Code rf_src_scanner = refactor_and_format( scan_file( path_base "auxiliary/scanner.cpp" ));
|
||||
#pragma endregion Refactored / Formatted
|
||||
|
||||
#pragma region Singleheader
|
||||
@@ -1720,6 +1823,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( rf_ht_preprocessor_macro );
|
||||
|
||||
header.print( rf_interface );
|
||||
header.print( rf_constants );
|
||||
header.print(fmt_newline);
|
||||
|
||||
header.print_fmt("#pragma region Inlines\n");
|
||||
@@ -1728,7 +1832,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
|
||||
header.print(fmt_newline);
|
||||
|
||||
header.print( rf_header_end );
|
||||
header.print( rf_header_builder );
|
||||
header.print( rf_header_scanner );
|
||||
|
||||
@@ -1814,6 +1917,9 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
|
||||
header.print( r_header_macros );
|
||||
header.print( header_generic_macros );
|
||||
|
||||
header.print_fmt( "\nGEN_API_C_BEGIN\n" );
|
||||
|
||||
header.print( r_header_basic_types );
|
||||
header.print( r_header_debug );
|
||||
header.print( rf_header_memory );
|
||||
@@ -1827,6 +1933,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( r_header_timing );
|
||||
header.print(rf_header_parsing );
|
||||
|
||||
header.print_fmt( "\nGEN_API_C_END\n" );
|
||||
header.print_fmt( "\nGEN_NS_END\n" );
|
||||
header.write();
|
||||
}
|
||||
@@ -1881,7 +1988,17 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print( rf_ast_types );
|
||||
header.print_fmt("\n#pragma endregion AST\n");
|
||||
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_arena );
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_pool);
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_array_string_cached );
|
||||
header.print( fmt_newline);
|
||||
header.print( rf_ht_preprocessor_macro );
|
||||
|
||||
header.print( rf_interface );
|
||||
header.print( rf_constants );
|
||||
header.print(fmt_newline);
|
||||
|
||||
header.print_fmt("#pragma region Inlines\n");
|
||||
@@ -1889,9 +2006,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
header.print_fmt("#pragma endregion Inlines\n");
|
||||
|
||||
header.print(fmt_newline);
|
||||
header.print( rf_array_string_cached );
|
||||
|
||||
header.print( rf_header_end );
|
||||
header.print( rf_header_builder );
|
||||
header.print( rf_header_scanner );
|
||||
|
||||
@@ -1908,11 +2023,6 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
builder_print( src, src_start );
|
||||
src.print_fmt( "\nGEN_NS_BEGIN\n");
|
||||
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_arena );
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_pool);
|
||||
|
||||
src.print( r_src_static_data );
|
||||
src.print( fmt_newline);
|
||||
|
||||
@@ -1930,6 +2040,7 @@ R"(#define <interface_name>( code ) _Generic( (code), \
|
||||
src.print( fmt_newline);
|
||||
src.print( rf_array_code_typename );
|
||||
src.print( fmt_newline);
|
||||
src.print( r_src_parser_case_macros );
|
||||
src.print( rf_src_parser );
|
||||
src.print( r_src_parsing );
|
||||
src.print_fmt( "\n#pragma endregion Parsing\n" );
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
word global, gen_global
|
||||
word internal, gen_internal
|
||||
word local_persist, gen_local_persist
|
||||
word read_only, gen_read_only
|
||||
word bit, gen_bit
|
||||
word bitfield_is_set, gen_bitfield_is_set
|
||||
word cast, gen_cast
|
||||
@@ -53,6 +54,7 @@ word enum_underlying, gen_enum_underlying
|
||||
word nullptr, gen_nullptr
|
||||
word struct_init, gen_struct_init
|
||||
word hash, gen_hash
|
||||
word txt, gen_txt
|
||||
|
||||
// Basic Types
|
||||
|
||||
@@ -410,6 +412,8 @@ namespace var_, gen_var_
|
||||
|
||||
word _ctx, gen__ctx
|
||||
|
||||
word get_context, gen_get_context
|
||||
|
||||
word init, gen_init
|
||||
word deinit, gen_deinit
|
||||
word reset, gen_reset
|
||||
@@ -532,7 +536,7 @@ namespace Lexer_, gen_Lexer_
|
||||
word LexContext, gen_LexContext
|
||||
word lex, gen_lex
|
||||
|
||||
word StackNode, gen_StackNode
|
||||
word ParseStackNode, gen_ParseStackNode
|
||||
word ParseContext, gen_ParseContext
|
||||
|
||||
// namespace parse_, gen_parse_
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
| \_____|\___}_l |_|\___} .__/| .__/ {_____/ \__\__/_l\__. |\___/\__,_l \____}{_____}{_____} |
|
||||
| | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
|
||||
! ============================================================================================= |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
|
||||
@@ -7,8 +7,19 @@ void convert_cpp_enum_to_c( CodeEnum to_convert, CodeBody to_append )
|
||||
{
|
||||
#pragma push_macro("enum_underlying")
|
||||
#undef enum_underlying
|
||||
StrCached type = to_convert->UnderlyingType ? to_convert->UnderlyingType.to_strbuilder().to_str() : to_convert->Name;
|
||||
CodeTypedef tdef = parse_typedef(token_fmt("type", type, "name", to_convert->Name, stringize( typedef enum <type> <name>; )));
|
||||
StrCached type;
|
||||
CodeTypedef tdef;
|
||||
if (to_convert->UnderlyingType)
|
||||
{
|
||||
type = to_convert->UnderlyingType.to_strbuilder().to_str();
|
||||
tdef = parse_typedef(token_fmt("type", type, "name", to_convert->Name, stringize( typedef <type> <name>; )));
|
||||
}
|
||||
else
|
||||
{
|
||||
type = to_convert->Name;
|
||||
tdef = parse_typedef(token_fmt("type", type, "name", to_convert->Name, stringize( typedef enum <type> <name>; )));
|
||||
|
||||
}
|
||||
if (to_convert->UnderlyingType)
|
||||
{
|
||||
to_convert->UnderlyingTypeMacro = untyped_str(token_fmt("type", to_convert->UnderlyingType->Name, stringize(enum_underlying(<type>))));
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#define GEN_IMPLEMENTATION
|
||||
#define GEN_DONT_ENFORCE_GEN_TIME_GUARD
|
||||
#define GEN_DEFINE_LIBRARY_CORE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen/gen_singleheader.h"
|
||||
@@ -6,15 +6,15 @@
|
||||
|
||||
* [docs](../docs/Readme.md)
|
||||
|
||||
# Segemented Library Generation
|
||||
# segmented Library Generation
|
||||
|
||||
Create a segemented library using `segemented.cpp`
|
||||
Create a segmented library using `segmented.cpp`
|
||||
|
||||
The principal (user) files are `gen.hpp` and `gen.cpp`.
|
||||
They contain includes for its various components: `components/<component_name>.<hpp/cpp>`
|
||||
|
||||
Dependencies are bundled into `gen.dep.<hpp/cpp>`. They are included in `gen.<hpp/cpp>` before component includes.
|
||||
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`. The auxillary content (builder & scanner) is given their own files.
|
||||
Just like the `gen.<hpp/cpp>` they include their components: `dependencies/<dependency_name>.<hpp/cpp>`. The auxiliary content (builder & scanner) is given their own files.
|
||||
|
||||
If using the library's provided build scripts:
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ int gen_main()
|
||||
}
|
||||
|
||||
CodeBody gen_component_header = def_global_body( args(
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("GEN_INTELLISENSE_DIRECTIVES") ),
|
||||
def_preprocess_cond( PreprocessCond_IfDef, txt("INTELLISENSE_DIRECTIVES") ),
|
||||
pragma_once,
|
||||
def_include(txt("components/types.hpp")),
|
||||
preprocess_endif,
|
||||
@@ -131,8 +131,8 @@ int gen_main()
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code constants = scan_file( path_base "components/constants.hpp");
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
@@ -168,6 +168,7 @@ int gen_main()
|
||||
builder_print_fmt( header, "\n#pragma endregion AST\n" );
|
||||
|
||||
builder_print( header, interface );
|
||||
builder_print( header, constants );
|
||||
|
||||
builder_print_fmt( header, "\n#pragma region Inlines\n" );
|
||||
builder_print( header, inlines );
|
||||
@@ -176,7 +177,6 @@ int gen_main()
|
||||
builder_print( header, fmt_newline );
|
||||
builder_print_fmt( header, "#pragma endregion Inlines\n" );
|
||||
|
||||
builder_print( header, header_end );
|
||||
builder_print_fmt( header, "\nGEN_NS_END\n\n" );
|
||||
builder_print( header, pop_ignores );
|
||||
builder_write(header);
|
||||
@@ -231,7 +231,7 @@ int gen_main()
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.hpp" );
|
||||
Code builder = scan_file( path_base "auxiliary/builder.hpp" );
|
||||
|
||||
Builder header = builder_open( "gen/gen.builder.hpp" );
|
||||
builder_print_fmt( & header, generation_notice );
|
||||
@@ -245,7 +245,7 @@ int gen_main()
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.cpp" );
|
||||
Code builder = scan_file( path_base "auxiliary/builder.cpp" );
|
||||
|
||||
Builder src = builder_open( "gen/gen.builder.cpp" );
|
||||
builder_print_fmt( & src, generation_notice );
|
||||
@@ -258,7 +258,7 @@ int gen_main()
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
|
||||
Code scanner = scan_file( path_base "auxiliary/scanner.hpp" );
|
||||
|
||||
Builder header = builder_open( "gen/gen.scanner.hpp" );
|
||||
builder_print_fmt( & header, generation_notice );
|
||||
@@ -272,7 +272,7 @@ int gen_main()
|
||||
|
||||
// gen_scanner.cpp
|
||||
{
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
|
||||
Code scanner = scan_file( path_base "auxiliary/scanner.cpp" );
|
||||
|
||||
Builder src = builder_open( "gen/gen.scanner.cpp" );
|
||||
builder_print_fmt( & src, generation_notice );
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| Singleheader | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
|
||||
! ============================================================================================ |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
|
||||
@@ -117,8 +117,8 @@ int gen_main()
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code constants = scan_file( path_base "components/constants.hpp" );
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
@@ -149,6 +149,7 @@ int gen_main()
|
||||
header.print_fmt("\n#pragma endregion AST\n");
|
||||
|
||||
header.print( interface );
|
||||
header.print( constants );
|
||||
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
@@ -156,13 +157,11 @@ int gen_main()
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
|
||||
if ( generate_builder ) {
|
||||
header.print( scan_file( path_base "auxillary/builder.hpp" ) );
|
||||
header.print( scan_file( path_base "auxiliary/builder.hpp" ) );
|
||||
}
|
||||
if ( generate_scanner ) {
|
||||
header.print( scan_file( path_base "auxillary/scanner.hpp" ) );
|
||||
header.print( scan_file( path_base "auxiliary/scanner.hpp" ) );
|
||||
}
|
||||
|
||||
header.print(fmt_newline);
|
||||
@@ -246,11 +245,11 @@ int gen_main()
|
||||
header.print_fmt( "\n#pragma endregion Interface\n");
|
||||
|
||||
if ( generate_builder ) {
|
||||
header.print( scan_file( path_base "auxillary/builder.cpp" ) );
|
||||
header.print( scan_file( path_base "auxiliary/builder.cpp" ) );
|
||||
}
|
||||
|
||||
if ( generate_scanner ) {
|
||||
header.print( scan_file( path_base "auxillary/scanner.cpp" ) );
|
||||
header.print( scan_file( path_base "auxiliary/scanner.cpp" ) );
|
||||
}
|
||||
|
||||
header.print( fmt_newline);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
| \_____|\___}_l |_|\___} ,__/| ,__/ (_____/ \__\__/_|\__, |\___}\__,_l |
|
||||
| Unreal Engine | | | | __} | |
|
||||
| l_l l_l {___/ |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.23-Alpha |
|
||||
! ----------------------------------------------------------------------- VERSION: v0.25-Alpha |
|
||||
! ============================================================================================ |
|
||||
! WARNING: THIS IS AN ALPHA VERSION OF THE LIBRARY, USE AT YOUR OWN DISCRETION |
|
||||
! NEVER DO CODE GENERATION WITHOUT AT LEAST HAVING CONTENT IN A CODEBASE UNDER VERSION CONTROL |
|
||||
|
||||
@@ -4,4 +4,3 @@ COREUOBJECT_API, COREUOBJECT_API
|
||||
ENGINE_API, ENGINE_API
|
||||
GAMEPLAYABILITIES_API, GAMEPLAYABILITIES_API
|
||||
UMG_API, UMG_API
|
||||
GASA_API, GASA_API
|
||||
|
@@ -24,4 +24,5 @@ Final, final
|
||||
NoExceptions, noexcept
|
||||
Override, override
|
||||
Pure, = 0
|
||||
Delete, = delete
|
||||
Volatile, volatile
|
||||
|
@@ -224,8 +224,8 @@ int gen_main()
|
||||
Code ast_types = scan_file( path_base "components/ast_types.hpp" );
|
||||
Code code_types = scan_file( path_base "components/code_types.hpp" );
|
||||
Code interface = scan_file( path_base "components/interface.hpp" );
|
||||
Code constants = scan_file( path_base "components/constants.hpp" );
|
||||
Code inlines = scan_file( path_base "components/inlines.hpp" );
|
||||
Code header_end = scan_file( path_base "components/header_end.hpp" );
|
||||
|
||||
CodeBody ecode = gen_ecode ( path_base "enums/ECodeTypes.csv" );
|
||||
CodeBody eoperator = gen_eoperator ( path_base "enums/EOperator.csv" );
|
||||
@@ -266,6 +266,7 @@ int gen_main()
|
||||
header.print_fmt( "\n#pragma endregion AST\n" );
|
||||
|
||||
header.print( interface );
|
||||
header.print( constants );
|
||||
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
@@ -274,7 +275,6 @@ int gen_main()
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
header.print_fmt( "\nGEN_NS_END\n\n" );
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
@@ -337,7 +337,7 @@ int gen_main()
|
||||
|
||||
// gen_builder.hpp
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.hpp" );
|
||||
Code builder = scan_file( path_base "auxiliary/builder.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.builder.hpp" );
|
||||
@@ -356,7 +356,7 @@ int gen_main()
|
||||
|
||||
// gen_builder.cpp
|
||||
{
|
||||
Code builder = scan_file( path_base "auxillary/builder.cpp" );
|
||||
Code builder = scan_file( path_base "auxiliary/builder.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.builder.cpp" );
|
||||
@@ -374,7 +374,7 @@ int gen_main()
|
||||
|
||||
// gen_scanner.hpp
|
||||
{
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.hpp" );
|
||||
Code scanner = scan_file( path_base "auxiliary/scanner.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.scanner.hpp" );
|
||||
@@ -393,7 +393,7 @@ int gen_main()
|
||||
|
||||
// gen.scanner.cpp
|
||||
{
|
||||
Code scanner = scan_file( path_base "auxillary/scanner.cpp" );
|
||||
Code scanner = scan_file( path_base "auxiliary/scanner.cpp" );
|
||||
|
||||
Builder
|
||||
src = Builder::open( "gen/gen.scanner.cpp" );
|
||||
|
||||
@@ -146,7 +146,7 @@ QualifierAlignment: Leave
|
||||
|
||||
ReferenceAlignment: Left
|
||||
|
||||
ReflowComments: true
|
||||
ReflowComments: false
|
||||
|
||||
# RequiresExpressionIndentation: OuterScope
|
||||
|
||||
@@ -164,7 +164,7 @@ SpaceAfterTemplateKeyword: false
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
@@ -182,7 +182,7 @@ SpacesInContainerLiterals: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: 20
|
||||
SpacesInParentheses: true
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
|
||||
Standard: c++17
|
||||
|
||||
+6
-1
@@ -22,9 +22,14 @@ args:
|
||||
c_lib : Build c11 library (singleheader & segmented)
|
||||
c_lib_static : Build static c11 library
|
||||
c_lib_dyn : Buidl dyanmic c11
|
||||
segemented
|
||||
segmented
|
||||
singleheader
|
||||
unreal
|
||||
test
|
||||
parser_bounds
|
||||
lexer_failures
|
||||
parse_body_messages
|
||||
dogfood_parse
|
||||
clang
|
||||
msvc : By default this project builds with clang, specifying msvc will build with MSVC.
|
||||
debug
|
||||
|
||||
+238
-135
@@ -10,22 +10,76 @@ $vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1'
|
||||
|
||||
Import-Module $misc
|
||||
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
function stop-stage {
|
||||
param([string]$stage, [int]$code_exit = 1)
|
||||
Write-Host "FAILED: $stage" -ForegroundColor Red
|
||||
exit $code_exit
|
||||
}
|
||||
|
||||
function invoke-stageTool {
|
||||
param(
|
||||
[string]$stage,
|
||||
[bool]$compiled,
|
||||
[string]$executable,
|
||||
[string]$path_work
|
||||
)
|
||||
if (-not $compiled) {
|
||||
stop-stage "$stage compile/link"
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath $executable)) {
|
||||
stop-stage "$stage missing output $executable"
|
||||
}
|
||||
$code_exit = 1
|
||||
push-location $path_work
|
||||
try {
|
||||
& $executable
|
||||
$code_exit = $LASTEXITCODE
|
||||
}
|
||||
finally {
|
||||
pop-location
|
||||
}
|
||||
if ($code_exit -ne 0) {
|
||||
stop-stage "$stage run" $code_exit
|
||||
}
|
||||
Write-Host "PASSED: $stage"
|
||||
}
|
||||
|
||||
if ($env:GENCPP_SOURCE_ROOT) {
|
||||
$path_root = (Resolve-Path -LiteralPath $env:GENCPP_SOURCE_ROOT).Path
|
||||
$probe = Join-Path $path_root "base\base.cpp"
|
||||
if (-not (Test-Path -LiteralPath $probe)) {
|
||||
stop-stage "GENCPP_SOURCE_ROOT is not a gencpp tree: $path_root"
|
||||
}
|
||||
}
|
||||
else {
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
}
|
||||
Write-Host "SOURCE_ROOT: $path_root"
|
||||
if ($null -eq $is_windows) {
|
||||
$is_windows = [System.Environment]::OSVersion.Platform -eq 'Win32NT'
|
||||
}
|
||||
if ($null -eq $is_linux) {
|
||||
$is_linux = [System.Environment]::OSVersion.Platform -eq 'Unix'
|
||||
}
|
||||
|
||||
Push-Location $path_root
|
||||
|
||||
#region Arguments
|
||||
$vendor = $null
|
||||
$release = $null
|
||||
[bool] $verbose = $false
|
||||
[bool] $base = $false
|
||||
[bool] $segmented = $false
|
||||
[bool] $singleheader = $false
|
||||
[bool] $c_lib = $false
|
||||
[bool] $c_lib_static = $false
|
||||
[bool] $c_lib_dyn = $false
|
||||
[bool] $unreal = $false
|
||||
[bool] $test = $false
|
||||
$vendor = $null
|
||||
$release = $null
|
||||
[bool] $verbose = $false
|
||||
[bool] $base = $false
|
||||
[bool] $segmented = $false
|
||||
[bool] $singleheader = $false
|
||||
[bool] $c_lib = $false
|
||||
[bool] $c_lib_static = $false
|
||||
[bool] $c_lib_dyn = $false
|
||||
[bool] $unreal = $false
|
||||
[bool] $test = $false
|
||||
[bool] $parser_bounds = $false
|
||||
[bool] $lexer_failures = $false
|
||||
[bool] $parse_body_messages = $false
|
||||
[bool] $dogfood_parse = $false
|
||||
|
||||
[array] $vendors = @( "clang", "msvc" )
|
||||
|
||||
@@ -33,24 +87,28 @@ Push-Location $path_root
|
||||
|
||||
if ( $args ) { $args | ForEach-Object {
|
||||
switch ($_){
|
||||
{ $_ -in $vendors } { $vendor = $_; break }
|
||||
"verbose" { $verbose = $true }
|
||||
"release" { $release = $true }
|
||||
"debug" { $release = $false }
|
||||
"base" { $base = $true }
|
||||
"segmented" { $segmented = $true }
|
||||
"singleheader" { $singleheader = $true }
|
||||
"c_lib" { $c_lib = $true }
|
||||
"c_lib_static" { $c_lib_static = $true }
|
||||
"c_lib_dyn" { $c_lib_dyn = $true }
|
||||
"unreal" { $unreal = $true }
|
||||
"test" { $test = $true }
|
||||
{ $_ -in $vendors } { $vendor = $_; break }
|
||||
"verbose" { $verbose = $true }
|
||||
"release" { $release = $true }
|
||||
"debug" { $release = $false }
|
||||
"base" { $base = $true }
|
||||
"segmented" { $segmented = $true }
|
||||
"singleheader" { $singleheader = $true }
|
||||
"c_lib" { $c_lib = $true }
|
||||
"c_lib_static" { $c_lib_static = $true }
|
||||
"c_lib_dyn" { $c_lib_dyn = $true }
|
||||
"unreal" { $unreal = $true }
|
||||
"test" { $test = $true }
|
||||
"parser_bounds" { $parser_bounds = $true }
|
||||
"lexer_failures" { $lexer_failures = $true }
|
||||
"parse_body_messages" { $parse_body_messages = $true }
|
||||
"dogfood_parse" { $dogfood_parse = $true }
|
||||
}
|
||||
}}
|
||||
#endregion Arguments
|
||||
|
||||
#region Configuration
|
||||
if ($IsWindows) {
|
||||
if ($is_windows) {
|
||||
# This library was really designed to only run on 64-bit systems.
|
||||
# (Its a development tool after all)
|
||||
& $devshell -arch amd64
|
||||
@@ -64,6 +122,7 @@ if ( $vendor -eq $null ) {
|
||||
if ( $release -eq $null ) {
|
||||
write-host "No build type specified, assuming debug"
|
||||
$release = $false
|
||||
$debug = $true
|
||||
}
|
||||
elseif ( $release -eq $false ) {
|
||||
$debug = $true
|
||||
@@ -72,16 +131,20 @@ else {
|
||||
$optimize = $true
|
||||
}
|
||||
|
||||
$cannot_build = $base -eq $false
|
||||
$cannot_build = $cannot_build -and $segmented -eq $false
|
||||
$cannot_build = $cannot_build -and $singleheader -eq $false
|
||||
$cannot_build = $cannot_build -and $c_lib -eq $false
|
||||
$cannot_build = $cannot_build -and $c_lib_static -eq $false
|
||||
$cannot_build = $cannot_build -and $c_lib_dyn -eq $false
|
||||
$cannot_build = $cannot_build -and $unreal -eq $false
|
||||
$cannot_build = $cannot_build -and $test -eq $false
|
||||
$cannot_build = $base -eq $false
|
||||
$cannot_build = $cannot_build -and $segmented -eq $false
|
||||
$cannot_build = $cannot_build -and $singleheader -eq $false
|
||||
$cannot_build = $cannot_build -and $c_lib -eq $false
|
||||
$cannot_build = $cannot_build -and $c_lib_static -eq $false
|
||||
$cannot_build = $cannot_build -and $c_lib_dyn -eq $false
|
||||
$cannot_build = $cannot_build -and $unreal -eq $false
|
||||
$cannot_build = $cannot_build -and $test -eq $false
|
||||
$cannot_build = $cannot_build -and $parser_bounds -eq $false
|
||||
$cannot_build = $cannot_build -and $lexer_failures -eq $false
|
||||
$cannot_build = $cannot_build -and $parse_body_messages -eq $false
|
||||
$cannot_build = $cannot_build -and $dogfood_parse -eq $false
|
||||
if ( $cannot_build ) {
|
||||
throw "No build target specified. One must be specified, this script will not assume one"
|
||||
Stop-stage "No build target specified"
|
||||
}
|
||||
|
||||
. $vendor_toolchain
|
||||
@@ -125,18 +188,7 @@ if ( $base )
|
||||
$executable = join-path $path_build "base.exe"
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_base
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning base"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nbase completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
invoke-stageTool -stage "base" -compiled $result -executable $executable -path_work $path_base
|
||||
}
|
||||
|
||||
if ( $segmented )
|
||||
@@ -163,18 +215,7 @@ if ( $segmented )
|
||||
$executable = join-path $path_build "segmented.exe"
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_segmented
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning segmented"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nBootstrap completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
invoke-stageTool -stage "segmented" -compiled $result -executable $executable -path_work $path_segmented
|
||||
}
|
||||
|
||||
if ( $singleheader )
|
||||
@@ -201,18 +242,7 @@ if ( $singleheader )
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_singleheader
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning singleheader generator"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nSingleheader generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
invoke-stageTool -stage "singleheader" -compiled $result -executable $executable -path_work $path_singleheader
|
||||
}
|
||||
|
||||
if ( $c_lib -or $c_lib_static -or $c_lib_dyn )
|
||||
@@ -239,18 +269,7 @@ if ( $c_lib -or $c_lib_static -or $c_lib_dyn )
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_c_library
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning c_library generator"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
invoke-stageTool -stage "c_lib" -compiled $result -executable $executable -path_work $path_c_library
|
||||
}
|
||||
|
||||
if ( $c_lib_static )
|
||||
@@ -263,9 +282,11 @@ if ( $c_lib_static )
|
||||
$compiler_args += $flag_all_c
|
||||
$compiler_args += $flag_updated_cpp_macro
|
||||
$compiler_args += $flag_c11
|
||||
$compiler_args += ($flag_define + 'GEN_STATIC_LINK')
|
||||
|
||||
$linker_args = @()
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_lib
|
||||
if (-not $result) { Stop-stage "c_lib_static compile/link" }
|
||||
}
|
||||
|
||||
if ( $c_lib_dyn )
|
||||
@@ -280,9 +301,11 @@ if ( $c_lib_dyn )
|
||||
$compiler_args += $flag_c11
|
||||
$compiler_args += ( $flag_define + 'GEN_DYN_LINK' )
|
||||
$compiler_args += ( $flag_define + 'GEN_DYN_EXPORT' )
|
||||
$compiler_args += ( $flag_define + 'GEN_DEFINE_LIBRARY_CODE_CONSTANTS' )
|
||||
|
||||
$linker_args = @()
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $path_dll
|
||||
if (-not $result) { Stop-stage "c_lib_dyn compile/link" }
|
||||
}
|
||||
|
||||
if ( $unreal )
|
||||
@@ -309,24 +332,28 @@ if ( $unreal )
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_unreal
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning unreal variant generator"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`n Unreal variant generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
invoke-stageTool -stage "unreal" -compiled $result -executable $executable -path_work $path_unreal
|
||||
|
||||
. $refactor_unreal
|
||||
}
|
||||
|
||||
# C Library testing
|
||||
if ( $test -and $false )
|
||||
if ($test) {
|
||||
$consumer_headers = @(
|
||||
(Join-Path $path_c_library 'gen\gen_singleheader.h'),
|
||||
(Join-Path $path_singleheader 'gen\gen.hpp')
|
||||
)
|
||||
$header_hashes_before = @{}
|
||||
foreach ($header in $consumer_headers) {
|
||||
if (-not (Test-Path -LiteralPath $header -PathType Leaf)) {
|
||||
Stop-stage "test missing generated header $header"
|
||||
}
|
||||
$header_hashes_before[$header] = (Get-FileHash -LiteralPath $header -Algorithm SHA256).Hash
|
||||
Write-Host "HEADER_SHA256_GENERATED: $($header_hashes_before[$header]) $header"
|
||||
}
|
||||
}
|
||||
|
||||
if ( $test -and $true )
|
||||
{
|
||||
$path_test_c = join-path $path_test c_library
|
||||
$path_build = join-path $path_test_c build
|
||||
@@ -354,21 +381,10 @@ if ( $test -and $false )
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_test_c
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning c_library test"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
invoke-stageTool -stage "test-c11" -compiled $result -executable $executable -path_work $path_test_c
|
||||
}
|
||||
|
||||
if ( $test -and $true )
|
||||
if ( $test -and $false )
|
||||
{
|
||||
$path_test_c = join-path $path_test c_library
|
||||
$path_build = join-path $path_test_c build
|
||||
@@ -396,30 +412,18 @@ if ( $test -and $true )
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
|
||||
Push-Location $path_test_c
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning c_library test"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
if ($test -and $false)
|
||||
if ($test)
|
||||
{
|
||||
$path_test_cpp = join-path $path_test cpp_library
|
||||
$path_build = join-path $path_test_cpp build
|
||||
$path_gen = join-path $path_test_cpp gen
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
New-Item -ItemType Directory -Path $path_build
|
||||
new-item -ItemType Directory -Path $path_build
|
||||
}
|
||||
if ( -not(Test-Path($path_gen) )) {
|
||||
New-Item -ItemType Directory -Path $path_gen
|
||||
new-item -ItemType Directory -Path $path_gen
|
||||
}
|
||||
|
||||
$path_singleheader_include = join-path $path_singleheader gen
|
||||
@@ -429,25 +433,124 @@ if ($test -and $false)
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
$compiler_args += $flag_all_cpp
|
||||
$compiler_args += $flag_cpp17
|
||||
$compiler_args += ($flag_define + "GEN_BUILD_DEBUG=1")
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
invoke-stageTool -stage "test-cpp" -compiled $result -executable $executable -path_work $path_test_cpp
|
||||
}
|
||||
if ($test) {
|
||||
foreach ($header in $consumer_headers) {
|
||||
$hash = (Get-FileHash -LiteralPath $header -Algorithm SHA256).Hash
|
||||
write-host "HEADER_SHA256_CONSUMED: $hash $header"
|
||||
if ($hash -ne $header_hashes_before[$header]) {
|
||||
Stop-stage "test header changed after generation $header"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Push-Location $path_test_cpp
|
||||
if ( Test-Path( $executable ) ) {
|
||||
write-host "`nRunning cpp_library test"
|
||||
$time_taken = Measure-Command { & $executable
|
||||
| ForEach-Object {
|
||||
write-host `t $_ -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
write-host "`nc_library generator completed in $($time_taken.TotalMilliseconds) ms"
|
||||
}
|
||||
Pop-Location
|
||||
if ($parser_bounds)
|
||||
{
|
||||
$path_probe = join-path $path_test parser_bounds
|
||||
$path_build = join-path $path_probe build
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
new-item -ItemType Directory -Path $path_build | Out-Null
|
||||
}
|
||||
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_probe "test.cpp"
|
||||
$executable = join-path $path_build "parser_bounds.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
$compiler_args += $flag_cpp17
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
invoke-stageTool -stage "parser_bounds" -compiled $result -executable $executable -path_work $path_probe
|
||||
}
|
||||
|
||||
if ($lexer_failures)
|
||||
{
|
||||
$path_probe = join-path $path_test lexer_failures
|
||||
$path_build = join-path $path_probe build
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
new-item -ItemType Directory -Path $path_build | Out-Null
|
||||
}
|
||||
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_probe "test.cpp"
|
||||
$executable = join-path $path_build "lexer_failures.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
$compiler_args += $flag_cpp17
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
invoke-stageTool -stage "lexer_failures" -compiled $result -executable $executable -path_work $path_probe
|
||||
}
|
||||
|
||||
if ($parse_body_messages)
|
||||
{
|
||||
$path_probe = join-path $path_test parse_body_messages
|
||||
$path_build = join-path $path_probe build
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
new-item -ItemType Directory -Path $path_build | Out-Null
|
||||
}
|
||||
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_probe "test.cpp"
|
||||
$executable = join-path $path_build "parse_body_messages.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
$compiler_args += $flag_cpp17
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
invoke-stageTool -stage "parse_body_messages" -compiled $result -executable $executable -path_work $path_probe
|
||||
}
|
||||
|
||||
if ($dogfood_parse)
|
||||
{
|
||||
$path_probe = join-path $path_test dogfood_parse
|
||||
$path_build = join-path $path_probe build
|
||||
if ( -not(Test-Path($path_build) )) {
|
||||
new-item -ItemType Directory -Path $path_build | Out-Null
|
||||
}
|
||||
|
||||
$includes = @( $path_base )
|
||||
$unit = join-path $path_probe "test.cpp"
|
||||
$executable = join-path $path_build "dogfood_parse.exe"
|
||||
|
||||
$compiler_args = @()
|
||||
$compiler_args += ( $flag_define + 'GEN_TIME' )
|
||||
$compiler_args += $flag_cpp17
|
||||
|
||||
$linker_args = @(
|
||||
$flag_link_win_subsystem_console
|
||||
)
|
||||
|
||||
$result = build-simple $path_build $includes $compiler_args $linker_args $unit $executable
|
||||
invoke-stageTool -stage "dogfood_parse" -compiled $result -executable $executable -path_work $path_probe
|
||||
}
|
||||
#endregion Building
|
||||
|
||||
Pop-Location # $path_root
|
||||
pop-location # $path_root
|
||||
write-host "PASSED: build.ci.ps1"
|
||||
exit 0
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
cls
|
||||
$build = Join-Path $PSScriptRoot 'build.ci.ps1'
|
||||
& $build @args
|
||||
exit $LASTEXITCODE
|
||||
+36
-20
@@ -1,26 +1,30 @@
|
||||
$misc = Join-Path $PSScriptRoot 'helpers/misc.psm1'
|
||||
Import-Module $misc
|
||||
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
$path_base = Join-Path $path_root base
|
||||
$path_base_build = Join-Path $path_base build
|
||||
$path_c_library = Join-Path $path_root gen_c_library
|
||||
$path_c_library_build = Join-Path $path_c_library build
|
||||
$path_c_library_gen = Join-Path $path_c_library gen
|
||||
$path_segmented = Join-Path $path_root gen_segmented
|
||||
$path_segmented_build = Join-Path $path_segmented build
|
||||
$path_segmented_gen = Join-Path $path_segmented gen
|
||||
$path_singleheader = Join-Path $path_root gen_singleheader
|
||||
$path_singleheader_build = Join-Path $path_singleheader build
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_unreal = Join-Path $path_root gen_unreal_engine
|
||||
$path_unreal_build = Join-Path $path_unreal build
|
||||
$path_unreal_gen = Join-Path $path_unreal gen
|
||||
$path_test = Join-Path $path_root test
|
||||
$path_test_build = Join-Path $path_test build
|
||||
$path_test_gen = Join-Path $path_test gen
|
||||
$path_x64 = Join-Path $path_root x64
|
||||
$path_release = Join-Path $path_root release
|
||||
$path_root = Get-ScriptRepoRoot
|
||||
$path_base = Join-Path $path_root base
|
||||
$path_base_build = Join-Path $path_base build
|
||||
$path_c_library = Join-Path $path_root gen_c_library
|
||||
$path_c_library_build = Join-Path $path_c_library build
|
||||
$path_c_library_gen = Join-Path $path_c_library gen
|
||||
$path_segmented = Join-Path $path_root gen_segmented
|
||||
$path_segmented_build = Join-Path $path_segmented build
|
||||
$path_segmented_gen = Join-Path $path_segmented gen
|
||||
$path_singleheader = Join-Path $path_root gen_singleheader
|
||||
$path_singleheader_build = Join-Path $path_singleheader build
|
||||
$path_singleheader_gen = Join-Path $path_singleheader gen
|
||||
$path_unreal = Join-Path $path_root gen_unreal_engine
|
||||
$path_unreal_build = Join-Path $path_unreal build
|
||||
$path_unreal_gen = Join-Path $path_unreal gen
|
||||
$path_test = Join-Path $path_root test
|
||||
$path_test_build = Join-Path $path_test build
|
||||
$path_test_gen = Join-Path $path_test gen
|
||||
$path_parser_bounds_build = Join-Path $path_test "parser_bounds\build"
|
||||
$path_lexer_failures_build = Join-Path $path_test "lexer_failures\build"
|
||||
$path_parse_body_messages_build = Join-Path $path_test "parse_body_messages\build"
|
||||
$path_dogfood_parse_build = Join-Path $path_test "dogfood_parse\build"
|
||||
$path_x64 = Join-Path $path_root x64
|
||||
$path_release = Join-Path $path_root release
|
||||
|
||||
if ( Test-Path $path_base_build) {
|
||||
Remove-Item $path_base_build -Recurse -Verbose
|
||||
@@ -58,6 +62,18 @@ if ( Test-Path $path_test_build ) {
|
||||
if ( Test-Path $path_test_gen ) {
|
||||
Remove-Item $path_test_gen -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_parser_bounds_build ) {
|
||||
Remove-Item $path_parser_bounds_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_lexer_failures_build ) {
|
||||
Remove-Item $path_lexer_failures_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_parse_body_messages_build ) {
|
||||
Remove-Item $path_parse_body_messages_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_dogfood_parse_build ) {
|
||||
Remove-Item $path_dogfood_parse_build -Recurse -Verbose
|
||||
}
|
||||
if ( Test-Path $path_x64) {
|
||||
Remove-Item $path_x64 -Recurse -Verbose
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -3,7 +3,7 @@
|
||||
|
||||
import-module $target_arch
|
||||
|
||||
if ($IsWindows) {
|
||||
if ($is_windows) {
|
||||
# This HandmadeHero implementation is only designed for 64-bit systems
|
||||
& $devshell -arch amd64
|
||||
}
|
||||
@@ -27,6 +27,12 @@ function run-archiver
|
||||
{
|
||||
param( $archiver, $library, $lib_args )
|
||||
|
||||
if (-not (Get-Command $archiver -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "FAILED: archiver launch $archiver" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
Write-Host ("ARCHIVER_ARGV: " + ($lib_args -join " "))
|
||||
|
||||
write-host "`Creating library $library"
|
||||
if ( $verbose ) {
|
||||
write-host "Lib manager config:"
|
||||
@@ -60,9 +66,15 @@ function run-compiler
|
||||
{
|
||||
param( $compiler, $unit, $compiler_args )
|
||||
|
||||
if (-not (Get-Command $compiler -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "FAILED: compiler launch $compiler" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
|
||||
if ( $analysis ) {
|
||||
$compiler_args += $flag_syntax_only
|
||||
}
|
||||
Write-Host ("COMPILER_ARGV: " + ($compiler_args -join " "))
|
||||
|
||||
write-host "`Compiling $unit"
|
||||
if ( $verbose ) {
|
||||
@@ -97,6 +109,12 @@ function run-linker
|
||||
{
|
||||
param( $linker, $binary, $linker_args )
|
||||
|
||||
if (-not (Get-Command $linker -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "FAILED: linker launch $linker" -ForegroundColor Red
|
||||
return $false
|
||||
}
|
||||
Write-Host ("LINKER_ARGV: " + ($linker_args -join " "))
|
||||
|
||||
write-host "`Linking $binary"
|
||||
if ( $verbose ) {
|
||||
write-host "Linker config:"
|
||||
@@ -131,7 +149,9 @@ if ( $vendor -match "clang" )
|
||||
# https://clang.llvm.org/docs/ClangCommandLineReference.html
|
||||
$flag_all_c = @('-x', 'c')
|
||||
$flag_c11 = '-std=c11'
|
||||
$flag_all_cpp = '-x c++'
|
||||
$flag_cpp17 = '-std=c++17'
|
||||
$flag_all_cpp = @('-x', 'c++')
|
||||
$flag_charset_utf8 = '-utf-8'
|
||||
$flag_compile = '-c'
|
||||
$flag_color_diagnostics = '-fcolor-diagnostics'
|
||||
$flag_no_color_diagnostics = '-fno-color-diagnostics'
|
||||
@@ -146,12 +166,12 @@ if ( $vendor -match "clang" )
|
||||
$flag_library = '-l'
|
||||
$flag_library_path = '-L'
|
||||
$flag_linker = '-Wl,'
|
||||
if ( $IsWindows ) {
|
||||
if ( $is_windows ) {
|
||||
$flag_link_dll = '/DLL'
|
||||
$flag_link_mapfile = '/MAP:'
|
||||
$flag_link_optimize_references = '/OPT:REF'
|
||||
}
|
||||
if ( $IsLinux ) {
|
||||
if ( $is_linux ) {
|
||||
$flag_link_mapfile = '--Map='
|
||||
$flag_link_optimize_references = '--gc-sections'
|
||||
}
|
||||
@@ -190,7 +210,7 @@ if ( $vendor -match "clang" )
|
||||
)
|
||||
|
||||
# https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170
|
||||
if ( $IsWindows ) {
|
||||
if ( $is_windows ) {
|
||||
$libraries = @(
|
||||
'Kernel32' # For Windows API
|
||||
# 'msvcrt', # For the C Runtime (Dynamically Linked)
|
||||
@@ -344,15 +364,17 @@ if ( $vendor -match "clang" )
|
||||
}
|
||||
|
||||
# Check if output is a static library
|
||||
# if ( $binary -match '\.lib$' )
|
||||
# {
|
||||
# $lib_args = @()
|
||||
if ( $binary -match '\.lib$' )
|
||||
{
|
||||
$lib_args = @()
|
||||
# $lib_args += $flag_nologo
|
||||
# $lib_args += $flag_link_win_machine_64
|
||||
# $lib_args += ( $flag_link_win_path_output + $binary )
|
||||
# $lib_args += $object
|
||||
# return run-archiver $archiver $binary $lib_args
|
||||
# }
|
||||
# $lib_args += '--format=windows'
|
||||
# $lib_args += '-X64'
|
||||
$lib_args += $object
|
||||
return run-archiver $archiver $binary $lib_args
|
||||
}
|
||||
|
||||
$linker_args += $object
|
||||
return run-linker $linker $binary $linker_args
|
||||
@@ -368,7 +390,9 @@ if ( $vendor -match "msvc" )
|
||||
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
|
||||
$flag_all_c = '/TC'
|
||||
$flag_c11 = '/std:c11'
|
||||
$flag_cpp17 = '/std:c++17'
|
||||
$flag_all_cpp = '/TP'
|
||||
$flag_charset_utf8 = '/utf-8'
|
||||
$flag_compile = '/c'
|
||||
$flag_debug = '/Zi'
|
||||
$flag_define = '/D'
|
||||
@@ -402,7 +426,7 @@ if ( $vendor -match "msvc" )
|
||||
$flag_optimize_intrinsics = '/Oi'
|
||||
$flag_optimized_debug_forceinline = '/d2Obforceinline'
|
||||
$flag_optimized_debug = '/Zo'
|
||||
$flag_
|
||||
# $flag_
|
||||
# $flag_out_name = '/OUT:'
|
||||
$flag_path_interm = '/Fo'
|
||||
$flag_path_debug = '/Fd'
|
||||
@@ -562,6 +586,7 @@ if ( $vendor -match "msvc" )
|
||||
# Check if output is a static library
|
||||
if ( $binary -match '\.lib$' )
|
||||
{
|
||||
write-host "Running archiver for $binary"
|
||||
$lib_args = @()
|
||||
$lib_args += $flag_nologo
|
||||
$lib_args += $flag_link_win_machine_64
|
||||
|
||||
@@ -106,10 +106,10 @@ Copy-Item -Verbose -Path $path_base\gen.hpp -Destination $path_rel
|
||||
Copy-Item -Verbose -Path $path_base\gen.cpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\gen.dep.hpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\gen.dep.cpp -Destination $path_release_content
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\builder.hpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\builder.cpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\scanner.hpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxillary\scanner.cpp -Destination $path_release_content\auxillary
|
||||
Copy-Item -Verbose -Path $path_base\auxiliary\builder.hpp -Destination $path_release_content\auxiliary
|
||||
Copy-Item -Verbose -Path $path_base\auxiliary\builder.cpp -Destination $path_release_content\auxiliary
|
||||
Copy-Item -Verbose -Path $path_base\auxiliary\scanner.hpp -Destination $path_release_content\auxiliary
|
||||
Copy-Item -Verbose -Path $path_base\auxiliary\scanner.cpp -Destination $path_release_content\auxiliary
|
||||
|
||||
New-Item -ItemType Directory -Force -Path "$path_release_content\components"
|
||||
New-Item -ItemType Directory -Force -Path "$path_release_content\components\gen"
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
# Basic indentation settings
|
||||
indent_columns = 4
|
||||
indent_with_tabs = 1
|
||||
indent_case_brace = 0
|
||||
indent_switch_case = 4
|
||||
indent_col1_comment = true
|
||||
indent_namespace = true
|
||||
indent_class = true
|
||||
indent_extern = true
|
||||
|
||||
# Alignment settings
|
||||
align_assign_span = 1
|
||||
align_assign_thresh = 0
|
||||
align_enum_equ_span = 1
|
||||
align_var_def_span = 1
|
||||
align_var_def_thresh = 0
|
||||
align_var_def_inline = true
|
||||
align_right_cmt_span = 1
|
||||
align_pp_define_span = 1
|
||||
align_typedef_span = 1
|
||||
align_typedef_gap = 0
|
||||
|
||||
# Spacing settings
|
||||
sp_before_square = remove
|
||||
sp_inside_square = remove
|
||||
sp_after_comma = force
|
||||
sp_before_comma = remove
|
||||
sp_after_cast = remove
|
||||
sp_inside_paren = remove
|
||||
sp_inside_fparen = remove
|
||||
sp_inside_sparen = remove
|
||||
sp_before_sparen = force
|
||||
sp_after_operator = remove
|
||||
sp_after_operator_sym = remove
|
||||
sp_after_ptr_star = remove
|
||||
sp_before_ptr_star = force
|
||||
sp_between_ptr_star = remove
|
||||
|
||||
# Code style settings
|
||||
mod_full_brace_do = force
|
||||
mod_full_brace_for = force
|
||||
mod_full_brace_if = force
|
||||
mod_full_brace_while = force
|
||||
mod_paren_on_return = remove
|
||||
mod_full_brace_nl = 1
|
||||
mod_remove_extra_semicolon = true
|
||||
|
||||
# Line breaking
|
||||
nl_after_brace_open = true
|
||||
nl_after_brace_close = true
|
||||
nl_after_return = true
|
||||
nl_before_case = true
|
||||
nl_fcall_brace = force
|
||||
nl_enum_brace = force
|
||||
nl_struct_brace = force
|
||||
nl_union_brace = force
|
||||
nl_if_brace = force
|
||||
nl_brace_else = force
|
||||
nl_elseif_brace = force
|
||||
nl_else_brace = force
|
||||
nl_else_if = remove
|
||||
nl_while_brace = force
|
||||
nl_do_brace = force
|
||||
nl_for_brace = force
|
||||
nl_max = 4
|
||||
nl_after_func_proto = 2
|
||||
nl_after_func_body = 2
|
||||
|
||||
# Template settings
|
||||
sp_inside_angle = remove
|
||||
sp_after_angle = force
|
||||
sp_angle_paren = remove
|
||||
sp_angle_word = force
|
||||
|
||||
# Other settings
|
||||
cmt_indent_multi = true
|
||||
cmt_c_group = false
|
||||
cmt_cpp_group = false
|
||||
indent_func_call_param = true
|
||||
indent_func_def_param = true
|
||||
indent_func_proto_param = true
|
||||
indent_template_param = true
|
||||
indent_relative_single_line_comments = true
|
||||
|
||||
# Preprocessor settings
|
||||
pp_indent = remove
|
||||
pp_space = remove
|
||||
|
||||
# Column limit
|
||||
code_width = 160
|
||||
@@ -0,0 +1,267 @@
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][Alias('MirrorRoot')][string]$path_mirror,
|
||||
[ValidateSet(
|
||||
"measure",
|
||||
"positive",
|
||||
"negative-compile",
|
||||
"negative-link",
|
||||
"negative-launch",
|
||||
"negative-stale",
|
||||
"negative-stale-header",
|
||||
"negative-format",
|
||||
"negative-refactor",
|
||||
"negative-assert"
|
||||
)]
|
||||
[string]$mode = "positive",
|
||||
[Alias('SourceRoot')][string]$path_source_root = "C:\projects\gencpp",
|
||||
[Alias('ReuseMirror')][switch]$reuse_mirror
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$path_source = (Resolve-Path -LiteralPath $path_source_root).Path
|
||||
$path_mirror = [System.IO.Path]::GetFullPath($path_mirror)
|
||||
$path_verification_root = Join-Path $path_mirror 'test\verification'
|
||||
if ($path_mirror -eq $path_source) { throw "MirrorRoot must not be the project checkout" }
|
||||
$prefix_source = $path_source.TrimEnd('\') + '\'
|
||||
$prefix_mirror = $path_mirror.TrimEnd('\') + '\'
|
||||
if ($path_source.StartsWith($prefix_mirror, [System.StringComparison]::OrdinalIgnoreCase) -or
|
||||
$path_mirror.StartsWith($prefix_source, [System.StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "path_mirror and path_source_root must not overlap"
|
||||
}
|
||||
if ($reuse_mirror -and $mode -ne "positive") { throw "reuse_mirror is for the positive mode only" }
|
||||
if ($reuse_mirror -and -not (Test-Path -LiteralPath (Join-Path $path_mirror 'base\base.cpp'))) {
|
||||
throw "reuse_mirror needs an existing baseline mirror"
|
||||
}
|
||||
|
||||
function Copy-Snapshot([string]$path_destination)
|
||||
{
|
||||
if (Test-Path -LiteralPath $path_destination) { Remove-Item -LiteralPath $path_destination -Recurse -Force }
|
||||
New-Item -ItemType Directory -Path $path_destination | Out-Null
|
||||
& robocopy $path_source $path_destination /E /NFL /NDL /NJH /NJS /XD .git
|
||||
if ($LASTEXITCODE -ge 8) { throw "robocopy failed: $LASTEXITCODE" }
|
||||
$global:LASTEXITCODE = 0
|
||||
@(
|
||||
"gen_segmented\gen",
|
||||
"gen_segmented\build",
|
||||
"gen_singleheader\gen",
|
||||
"gen_singleheader\build",
|
||||
"gen_c_library\gen",
|
||||
"gen_c_library\build",
|
||||
"gen_unreal_engine\gen",
|
||||
"gen_unreal_engine\build",
|
||||
"test\c_library\build",
|
||||
"test\c_library\gen",
|
||||
"test\cpp_library\build",
|
||||
"test\cpp_library\gen",
|
||||
"base\build"
|
||||
) | ForEach-Object {
|
||||
$path_item = Join-Path $path_destination $_
|
||||
if (Test-Path -LiteralPath $path_item) { Remove-Item -LiteralPath $path_item -Recurse -Force }
|
||||
}
|
||||
}
|
||||
|
||||
function Copy-VerificationFixture([string]$name_fixture, [string]$path_destination) {
|
||||
$path_fixture = Join-Path $path_verification_root $name_fixture
|
||||
if (-not (Test-Path -LiteralPath $path_fixture -PathType Leaf)) {
|
||||
throw "Missing verification fixture: $path_fixture"
|
||||
}
|
||||
Copy-Item -LiteralPath $path_fixture -Destination $path_destination -Force
|
||||
}
|
||||
|
||||
function Invoke-Driver([string]$path_tree, [string[]]$list_targets) {
|
||||
$path_driver = Join-Path $path_tree "scripts\build.ci.ps1"
|
||||
$name_log = if ($reuse_mirror) { 'verify_driver.repeat.log' } else { 'verify_driver.log' }
|
||||
$path_log = Join-Path $path_tree $name_log
|
||||
$path_previous_root = $env:GENCPP_SOURCE_ROOT
|
||||
$env:GENCPP_SOURCE_ROOT = $path_tree
|
||||
$line_args = $list_targets -join ' '
|
||||
try {
|
||||
$text_output = & powershell.exe -NoProfile -Command "& '$path_driver' clang debug $line_args; exit `$LASTEXITCODE" *>&1
|
||||
$code_exit = $LASTEXITCODE
|
||||
}
|
||||
finally {
|
||||
$env:GENCPP_SOURCE_ROOT = $path_previous_root
|
||||
}
|
||||
$text_output | Tee-Object -FilePath $path_log | Out-Host
|
||||
$script:path_last_driver_log = $path_log
|
||||
$script:code_last_driver = $code_exit
|
||||
return $code_exit
|
||||
}
|
||||
|
||||
function Get-DriverLogText {
|
||||
if (-not $script:path_last_driver_log) { return "" }
|
||||
if (-not (Test-Path -LiteralPath $script:path_last_driver_log)) { return "" }
|
||||
return Get-Content -LiteralPath $script:path_last_driver_log -Raw
|
||||
}
|
||||
|
||||
function Assert-PositiveOutputs([string]$path_tree) {
|
||||
$list_outputs = @(
|
||||
'base\components\gen\ecodetypes.hpp',
|
||||
'base\components\gen\eoperator.hpp',
|
||||
'base\components\gen\especifier.hpp',
|
||||
'base\components\gen\etoktype.hpp',
|
||||
'base\components\gen\ast_inlines.hpp',
|
||||
'gen_segmented\gen\gen.hpp',
|
||||
'gen_segmented\gen\gen.cpp',
|
||||
'gen_segmented\gen\gen.dep.hpp',
|
||||
'gen_segmented\gen\gen.dep.cpp',
|
||||
'gen_segmented\gen\gen.builder.hpp',
|
||||
'gen_segmented\gen\gen.builder.cpp',
|
||||
'gen_segmented\gen\gen.scanner.hpp',
|
||||
'gen_segmented\gen\gen.scanner.cpp',
|
||||
'gen_singleheader\gen\gen.hpp',
|
||||
'gen_c_library\gen\gen.h',
|
||||
'gen_c_library\gen\gen.c',
|
||||
'gen_c_library\gen\gen.dep.h',
|
||||
'gen_c_library\gen\gen.dep.c',
|
||||
'gen_c_library\gen\gen_singleheader.h'
|
||||
)
|
||||
$list_hashes = foreach ($path_relative in $list_outputs) {
|
||||
$path_output = Join-Path $path_tree $path_relative
|
||||
if (-not (Test-Path -LiteralPath $path_output -PathType Leaf)) { throw "Missing output: $path_output" }
|
||||
if ((Get-Item -LiteralPath $path_output).Length -eq 0) { throw "Empty output: $path_output" }
|
||||
"{0} {1}" -f (Get-FileHash -LiteralPath $path_output -Algorithm SHA256).Hash, $path_relative
|
||||
}
|
||||
$text_log = (Get-DriverLogText).Replace('\\', '\')
|
||||
foreach ($path_relative in @('gen_singleheader\gen\gen.hpp', 'gen_c_library\gen\gen_singleheader.h')) {
|
||||
$path_header = Join-Path $path_tree $path_relative
|
||||
if ($text_log -notmatch [regex]::Escape($path_header)) { throw "Compiler trace missing $path_header" }
|
||||
}
|
||||
$name_hash_file = if ($reuse_mirror) { 'verify_outputs.repeat.sha256' } else { 'verify_outputs.sha256' }
|
||||
$list_hashes | Set-Content -LiteralPath (Join-Path $path_tree $name_hash_file)
|
||||
Write-Host "PASSED: outputs and consumer header traces ($name_hash_file)"
|
||||
}
|
||||
|
||||
$list_targets = @("base", "segmented", "singleheader", "c_lib", "test")
|
||||
if (-not $reuse_mirror) { Copy-Snapshot $path_mirror }
|
||||
|
||||
if ($mode -eq "measure" -or $mode -eq "positive") {
|
||||
$code_exit = Invoke-Driver $path_mirror $list_targets
|
||||
if ($mode -eq "positive" -and $code_exit -ne 0) { exit $code_exit }
|
||||
if ($mode -eq "positive") { Assert-PositiveOutputs $path_mirror }
|
||||
exit $code_exit
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-compile") {
|
||||
Copy-VerificationFixture 'failure_compile.cpp' (Join-Path $path_mirror 'base\base.cpp')
|
||||
$code_exit = Invoke-Driver $path_mirror @("base")
|
||||
if ($code_exit -eq 0) { throw "negative-compile returned 0" }
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-link") {
|
||||
Copy-VerificationFixture 'failure_link.cpp' (Join-Path $path_mirror 'base\base.cpp')
|
||||
$code_exit = Invoke-Driver $path_mirror @("base")
|
||||
$text_log = Get-DriverLogText
|
||||
if ($code_exit -eq 0 -or $text_log -notmatch "Linking failed") {
|
||||
throw "negative-link did not fail at the linker"
|
||||
}
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-launch") {
|
||||
$path_toolchain = Join-Path $path_mirror "scripts\helpers\vendor_toolchain.ps1"
|
||||
$text_toolchain = Get-Content -LiteralPath $path_toolchain -Raw
|
||||
$text_patched = $text_toolchain.Replace(
|
||||
"`$linker = 'lld-link'",
|
||||
"`$linker = 'gencpp-missing-linker'"
|
||||
)
|
||||
if ($text_patched -eq $text_toolchain) { throw "negative-launch could not replace the linker path" }
|
||||
|
||||
Set-Content -LiteralPath $path_toolchain -Value $text_patched -NoNewline
|
||||
$code_exit = Invoke-Driver $path_mirror @("base")
|
||||
$text_log = Get-DriverLogText
|
||||
if ($code_exit -eq 0 -or $text_log -notmatch "FAILED: linker launch gencpp-missing-linker") {
|
||||
throw "negative-launch did not report a missing linker"
|
||||
}
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-stale") {
|
||||
$path_stale_source = Join-Path $path_mirror "stale_marker.c"
|
||||
$path_stale_executable = Join-Path $path_mirror "stale_marker.exe"
|
||||
Copy-VerificationFixture 'stale_executable.c' $path_stale_source
|
||||
|
||||
& clang -o $path_stale_executable $path_stale_source
|
||||
if ($LASTEXITCODE -ne 0) { throw "failed to compile stale marker" }
|
||||
|
||||
$path_base_build = Join-Path $path_mirror "base\build"
|
||||
New-Item -ItemType Directory -Path $path_base_build -Force | Out-Null
|
||||
Copy-Item -LiteralPath $path_stale_executable -Destination (Join-Path $path_base_build "base.exe") -Force
|
||||
Copy-VerificationFixture 'failure_compile.cpp' (Join-Path $path_mirror 'base\base.cpp')
|
||||
|
||||
$code_exit = Invoke-Driver $path_mirror @("base")
|
||||
if ($code_exit -eq 0) { throw "negative-stale returned 0" }
|
||||
if ($code_exit -eq 73) { throw "negative-stale ran the stale executable" }
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-stale-header") {
|
||||
$code_exit = Invoke-Driver $path_mirror @("base", "segmented", "singleheader", "c_lib")
|
||||
if ($code_exit -ne 0) { throw "negative-stale-header setup generation failed: $code_exit" }
|
||||
|
||||
Copy-Item -LiteralPath $script:path_last_driver_log -Destination (Join-Path $path_mirror 'verify_driver.setup.log')
|
||||
$path_header = Join-Path $path_mirror 'gen_c_library\gen\gen_singleheader.h'
|
||||
if (-not (Test-Path -LiteralPath $path_header)) { throw 'negative-stale-header missing setup header' }
|
||||
|
||||
Copy-VerificationFixture 'failure_compile.cpp' (Join-Path $path_mirror 'gen_c_library\c_library.cpp')
|
||||
$code_exit = Invoke-Driver $path_mirror @('c_lib', 'test')
|
||||
$text_log = Get-DriverLogText
|
||||
if ($code_exit -eq 0 -or $text_log -notmatch 'FAILED: c_lib compile/link') {
|
||||
throw 'negative-stale-header did not fail at c_lib'
|
||||
}
|
||||
if ($text_log -match 'Compiling .*test[.]c|PASSED: test-c11|PASSED: test-cpp') {
|
||||
throw 'negative-stale-header consumed a prior header'
|
||||
}
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-format") {
|
||||
$path_fake_tools = Join-Path $path_mirror "fake-tools"
|
||||
New-Item -ItemType Directory -Path $path_fake_tools -Force | Out-Null
|
||||
Copy-VerificationFixture 'failure_format.cmd' (Join-Path $path_fake_tools 'clang-format.cmd')
|
||||
$path_saved = $env:PATH
|
||||
$env:PATH = "$path_fake_tools;$env:PATH"
|
||||
try {
|
||||
$code_exit = Invoke-Driver $path_mirror @("base")
|
||||
}
|
||||
finally {
|
||||
$env:PATH = $path_saved
|
||||
}
|
||||
$text_log = Get-DriverLogText
|
||||
if ($code_exit -eq 0) { throw "negative-format returned 0" }
|
||||
if ($text_log -notmatch "clang-format failed") { throw "negative-format log missing clang-format failed" }
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-refactor") {
|
||||
$path_fake_source = Join-Path $path_mirror 'failing_refactor.c'
|
||||
$path_fake_executable = Join-Path $path_mirror 'scripts\helpers\refactor.exe'
|
||||
Copy-VerificationFixture 'failure_refactor.c' $path_fake_source
|
||||
& clang -o $path_fake_executable $path_fake_source
|
||||
if ($LASTEXITCODE -ne 0) { throw 'negative-refactor failed to compile the stub' }
|
||||
|
||||
$code_exit = Invoke-Driver $path_mirror @('c_lib')
|
||||
$text_log = Get-DriverLogText
|
||||
if ($code_exit -eq 0 -or $text_log -notmatch 'refactor failed') {
|
||||
throw 'negative-refactor did not propagate subprocess failure'
|
||||
}
|
||||
exit 0
|
||||
}
|
||||
|
||||
if ($mode -eq "negative-assert") {
|
||||
$path_header = Join-Path $path_mirror "gen_singleheader\gen\gen.hpp"
|
||||
if (-not (Test-Path -LiteralPath $path_header)) {
|
||||
$code_exit = Invoke-Driver $path_mirror $list_targets
|
||||
if ($code_exit -ne 0) { throw "negative-assert setup generation failed: $code_exit" }
|
||||
}
|
||||
|
||||
Copy-VerificationFixture 'failure_assert.cpp' (Join-Path $path_mirror 'test\cpp_library\test.cpp')
|
||||
$code_exit = Invoke-Driver $path_mirror @("test")
|
||||
$text_log = Get-DriverLogText
|
||||
if ($code_exit -eq 0) { throw "negative-assert returned 0" }
|
||||
if ($text_log -notmatch "FAIL forced assertion") { throw "negative-assert log missing forced assertion marker" }
|
||||
exit 0
|
||||
}
|
||||
|
||||
throw "unhandled mode $mode"
|
||||
+38
-2
@@ -1,3 +1,39 @@
|
||||
# Test
|
||||
# Baseline verification
|
||||
|
||||
The implementaiton here has been gutted and will be rewritten...
|
||||
The implementation smoke is `verify_baseline.ps1`. It is not a parser corpus.
|
||||
|
||||
From the project root, in a fresh PowerShell process:
|
||||
|
||||
```powershell
|
||||
.\scripts\verify_baseline.ps1 -Mode positive -MirrorRoot ..\gencpp-verify-positive
|
||||
.\scripts\verify_baseline.ps1 -Mode positive -MirrorRoot ..\gencpp-verify-positive -ReuseMirror
|
||||
```
|
||||
|
||||
The first command generates base component tables, segmented C++, single-header C++, and both C11 layouts.
|
||||
It compiles and runs the C++17 and C11 single-header host smokes. The second command reuses the same mirror.
|
||||
|
||||
The verification wrapper copies them into the disposable mirror; it does not embed C or C++ source text.
|
||||
|
||||
## Parser bounds probe
|
||||
|
||||
`test/parser_bounds/test.cpp` is a GEN_TIME program. It includes `base/gen.cpp`. It is not part of `verify_baseline.ps1`.
|
||||
|
||||
From the project root:
|
||||
|
||||
```powershell
|
||||
.\scripts\build.ps1 clang parser_bounds
|
||||
```
|
||||
|
||||
The script builds and runs the probe. A pass prints `parser bounds passed` and `PASSED: parser_bounds`.
|
||||
The probe covers helper positions, formatting skip at the slice end, empty and whitespace `parse_variable`, and two direct end-of-slice reads.
|
||||
It does not prove in-slice syntax errors return.
|
||||
|
||||
## Lexer failure probe
|
||||
|
||||
```powershell
|
||||
.\scripts\build.ps1 clang lexer_failures
|
||||
```
|
||||
|
||||
A pass prints `lexer failures passed` and `PASSED: lexer_failures`.
|
||||
The probe covers nine lexer failures, six successful sibling inputs, and a baseline variable after each failure.
|
||||
It does not prove in-slice parser errors return.
|
||||
+486
-19
@@ -1,32 +1,499 @@
|
||||
#define GEN_DONT_USE_FATAL
|
||||
#define GEN_IMPLEMENTATION
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#include "gen_singleheader.h"
|
||||
|
||||
#define gen_iterator( Type, container, iter ) \
|
||||
gen_begin_ ## Type(container); \
|
||||
iter != gen_end_ ## Type(container); \
|
||||
code = gen_next_ ## Type(container, iter)
|
||||
gen_global gen_s32 g_failures = 0;
|
||||
|
||||
gen_internal void expect(int condition, gen_Str name) {
|
||||
if (condition == false) { gen_log_fmt("FAIL %S\n", name); ++ g_failures; }
|
||||
}
|
||||
|
||||
gen_internal void expect_fragments(gen_Str text, gen_Str label) {
|
||||
expect(text.Ptr != 0 && text.Len > 0, label);
|
||||
expect(gen_str_contains(text, gen_txt("baseline_message")), label);
|
||||
expect(gen_str_contains(text, gen_txt("char")), label);
|
||||
expect(gen_str_contains(text, gen_txt("const")), label);
|
||||
expect(gen_str_contains(text, gen_txt("*")), label);
|
||||
expect(gen_str_contains(text, gen_txt("GENCPP_BASELINE")), label);
|
||||
}
|
||||
|
||||
gen_internal void expect_variable(gen_CodeVar var, gen_Str label) {
|
||||
expect(var != 0, label); if (var == 0) return;
|
||||
expect(var->Type == CT_Variable, label);
|
||||
expect(gen_str_contains(var->Name, gen_txt("baseline_message")), label);
|
||||
expect(var->ValueType != 0, label);
|
||||
expect(var->Value != 0, label);
|
||||
if (var->Value != 0) {
|
||||
expect(gen_str_contains(var->Value->Content, gen_txt("GENCPP_BASELINE")), label);
|
||||
}
|
||||
}
|
||||
|
||||
gen_internal gen_Code_POD code_pod(gen_Code code) {
|
||||
gen_Code_POD result = { (gen_AST*)code };
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
gen_Context ctx = {0};
|
||||
gen_init(& ctx);
|
||||
gen_Context ctx = {0}; gen_init(&ctx);
|
||||
|
||||
gen_Builder src_hello = gen_builder_open("gen/hello.c");
|
||||
gen_CodeVar hello_var = gen_parse_variable(code(
|
||||
char const* hello_gencpp_str = "HELLO GENCPP C11 !";
|
||||
));
|
||||
gen_builder_print( & src_hello, (gen_Code)hello_var );
|
||||
gen_builder_write(& src_hello);
|
||||
gen_CodeTypename type = gen_def_type(name(char), .specifiers = gen_def_specifiers(2, Spec_Const, Spec_Ptr) );
|
||||
gen_CodeVar upfront = gen_def_variable(type, name(baseline_message),
|
||||
.value = gen_untyped_str(code("\"GENCPP_BASELINE\""))
|
||||
);
|
||||
expect_variable(upfront, gen_txt("c11 upfront"));
|
||||
expect_fragments(gen_strbuilder_to_str(gen_code_to_strbuilder(upfront)), gen_txt("c11 upfront serialized"));
|
||||
|
||||
gen_CodeBody body = gen_parse_file("gen/hello.c");
|
||||
for (gen_Code code = gen_iterator(CodeBody, body, code)) switch (code->Type) {
|
||||
case CT_Variable:
|
||||
gen_CodeVar var = (gen_CodeVar) code;
|
||||
gen_log_fmt("%S", var->Value);
|
||||
break;
|
||||
gen_Code array_expr = gen_untyped_str(gen_txt("3"));
|
||||
gen_CodeSpecifiers type_specs = gen_def_specifier(Spec_Const);
|
||||
gen_CodeAttributes type_attrs = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeTypename option_type = gen_def_type(name(Payload),
|
||||
.type_tag = Tag_Struct,
|
||||
.gen_array_expr = array_expr,
|
||||
.specifiers = type_specs,
|
||||
.attributes = type_attrs
|
||||
);
|
||||
expect(option_type != 0, gen_txt("c11 type options"));
|
||||
if (option_type != 0) {
|
||||
expect(option_type->TypeTag == Tag_Struct, gen_txt("c11 type tag"));
|
||||
expect((gen_Code)option_type->ArrExpr == array_expr, gen_txt("c11 type array expression"));
|
||||
expect((gen_Code)option_type->Specs == (gen_Code)type_specs, gen_txt("c11 type specifiers"));
|
||||
expect((gen_Code)option_type->Attributes == (gen_Code)type_attrs, gen_txt("c11 type attributes"));
|
||||
gen_Str type_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_type));
|
||||
expect(gen_str_contains(type_text, gen_txt("struct Payload")), gen_txt("c11 type tag serialization"));
|
||||
expect(gen_str_contains(type_text, gen_txt("const")), gen_txt("c11 type specifier serialization"));
|
||||
expect(gen_str_contains(type_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 type attribute serialization"));
|
||||
}
|
||||
|
||||
gen_deinit(& ctx);
|
||||
gen_Code value = gen_untyped_str(code("\"UPFRONT_OPTION\""));
|
||||
gen_CodeSpecifiers variable_specs = gen_def_specifier(Spec_Static);
|
||||
gen_CodeAttributes variable_attrs = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeVar option_variable = gen_def_variable(option_type, name(option_payload),
|
||||
.value = value,
|
||||
.specifiers = variable_specs,
|
||||
.attributes = variable_attrs,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_variable != 0, gen_txt("c11 variable options"));
|
||||
if (option_variable != 0) {
|
||||
expect((gen_Code)option_variable->ValueType == (gen_Code)option_type, gen_txt("c11 variable type"));
|
||||
expect( option_variable->Value == value, gen_txt("c11 variable value"));
|
||||
expect((gen_Code)option_variable->Specs == (gen_Code)variable_specs, gen_txt("c11 variable specifiers"));
|
||||
expect((gen_Code)option_variable->Attributes == (gen_Code)variable_attrs, gen_txt("c11 variable attributes"));
|
||||
expect( option_variable->ModuleFlags == ModuleFlag_Export, gen_txt("c11 variable module flags"));
|
||||
gen_Str variable_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_variable));
|
||||
expect(gen_str_contains(variable_text, gen_txt("option_payload")), gen_txt("c11 variable name serialization"));
|
||||
expect(gen_str_contains(variable_text, gen_txt("UPFRONT_OPTION")), gen_txt("c11 variable value serialization"));
|
||||
expect(gen_str_contains(variable_text, gen_txt("static")), gen_txt("c11 variable specifier serialization"));
|
||||
expect(gen_str_contains(variable_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 variable attribute serialization"));
|
||||
expect(gen_str_contains(variable_text, gen_txt("[ 3 ]")), gen_txt("c11 variable array serialization"));
|
||||
expect(gen_str_contains(variable_text, gen_txt("export")), gen_txt("c11 variable module flag serialization"));
|
||||
}
|
||||
|
||||
gen_CodeVar class_member = gen_def_variable(gen_def_type(name(u32)), name(class_option_member));
|
||||
gen_CodeBody class_body = gen_def_class_body(1, code_pod((gen_Code)class_member));
|
||||
gen_CodeTypename class_parent = gen_def_type(name(ClassOptionBase));
|
||||
gen_CodeTypename class_interfaces[] = { gen_def_type(name(IClassOption)) };
|
||||
gen_CodeAttributes class_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeSpecifiers class_specifiers = gen_def_specifier(Spec_Final);
|
||||
gen_CodeClass option_class = gen_def_class(name(ClassOption),
|
||||
.body = class_body,
|
||||
.parent = class_parent,
|
||||
.parent_access = AccessSpec_Public,
|
||||
.attributes = class_attributes,
|
||||
.interfaces = class_interfaces,
|
||||
.num_interfaces = 1,
|
||||
.specifiers = class_specifiers,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_class != 0, gen_txt("c11 class options"));
|
||||
if (option_class != 0) {
|
||||
expect((gen_Code)option_class->Body == (gen_Code)class_body, gen_txt("c11 class body"));
|
||||
expect((gen_Code)option_class->ParentType == (gen_Code)class_parent, gen_txt("c11 class parent"));
|
||||
expect( option_class->ParentAccess == AccessSpec_Public, gen_txt("c11 class parent access"));
|
||||
expect((gen_Code)option_class->Attributes == (gen_Code)class_attributes, gen_txt("c11 class attributes"));
|
||||
expect((gen_Code)option_class->ParentType->Next == (gen_Code)class_interfaces[0], gen_txt("c11 class interface"));
|
||||
expect((gen_Code)option_class->Specs == (gen_Code)class_specifiers, gen_txt("c11 class specifiers"));
|
||||
expect( option_class->ModuleFlags == ModuleFlag_Export, gen_txt("c11 class module flags"));
|
||||
gen_Str class_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_class));
|
||||
expect(gen_str_contains(class_text, gen_txt("ClassOption")), gen_txt("c11 class name serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("ClassOptionBase")), gen_txt("c11 class parent serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("IClassOption")), gen_txt("c11 class interface serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("public")), gen_txt("c11 class access serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("class_option_member")), gen_txt("c11 class body serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 class attribute serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("final")), gen_txt("c11 class final specifier serialization"));
|
||||
expect(gen_str_contains(class_text, gen_txt("export")), gen_txt("c11 class module flag serialization"));
|
||||
}
|
||||
|
||||
gen_CodeVar struct_member = gen_def_variable(gen_def_type(name(u32)), name(struct_option_member));
|
||||
gen_CodeBody struct_body = gen_def_struct_body(1, code_pod((gen_Code)struct_member));
|
||||
gen_CodeTypename struct_parent = gen_def_type(name(StructOptionBase));
|
||||
gen_CodeTypename struct_interfaces[] = { gen_def_type(name(IStructOption)) };
|
||||
gen_CodeAttributes struct_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeSpecifiers struct_specifiers = gen_def_specifier(Spec_Final);
|
||||
gen_CodeStruct option_struct = gen_def_struct(name(StructOption),
|
||||
.body = struct_body,
|
||||
.parent = struct_parent,
|
||||
.parent_access = AccessSpec_Public,
|
||||
.attributes = struct_attributes,
|
||||
.interfaces = struct_interfaces,
|
||||
.num_interfaces = 1,
|
||||
.specifiers = struct_specifiers,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_struct != 0, gen_txt("c11 struct options"));
|
||||
if (option_struct != 0) {
|
||||
expect((gen_Code)option_struct->Body == (gen_Code)struct_body, gen_txt("c11 struct body"));
|
||||
expect((gen_Code)option_struct->ParentType == (gen_Code)struct_parent, gen_txt("c11 struct parent"));
|
||||
expect( option_struct->ParentAccess == AccessSpec_Public, gen_txt("c11 struct parent access"));
|
||||
expect((gen_Code)option_struct->Attributes == (gen_Code)struct_attributes, gen_txt("c11 struct attributes"));
|
||||
expect((gen_Code)option_struct->ParentType->Next == (gen_Code)struct_interfaces[0], gen_txt("c11 struct interface"));
|
||||
expect((gen_Code)option_struct->Specs == (gen_Code)struct_specifiers, gen_txt("c11 struct specifiers"));
|
||||
expect( option_struct->ModuleFlags == ModuleFlag_Export, gen_txt("c11 struct module flags"));
|
||||
gen_Str struct_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_struct));
|
||||
expect(gen_str_contains(struct_text, gen_txt("StructOption")), gen_txt("c11 struct name serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("StructOptionBase")), gen_txt("c11 struct parent serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("IStructOption")), gen_txt("c11 struct interface serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("public")), gen_txt("c11 struct access serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("struct_option_member")), gen_txt("c11 struct body serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 struct attribute serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("final")), gen_txt("c11 struct final specifier serialization"));
|
||||
expect(gen_str_contains(struct_text, gen_txt("export")), gen_txt("c11 struct module flag serialization"));
|
||||
}
|
||||
|
||||
gen_CodeBody enum_body = gen_def_enum_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("Option_None"))));
|
||||
gen_CodeTypename enum_underlying = gen_def_type(name(u32));
|
||||
gen_CodeAttributes enum_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeEnum option_enum = gen_def_enum(name(OptionEnum),
|
||||
.body = enum_body,
|
||||
.type = enum_underlying,
|
||||
.specifier = EnumDecl_Class,
|
||||
.attributes = enum_attributes,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_enum != 0, gen_txt("c11 enum options"));
|
||||
if (option_enum != 0) {
|
||||
expect((gen_Code)option_enum->Body == (gen_Code)enum_body, gen_txt("c11 enum body"));
|
||||
expect((gen_Code)option_enum->UnderlyingType == (gen_Code)enum_underlying, gen_txt("c11 enum underlying type"));
|
||||
expect( option_enum->Type == CT_Enum_Class, gen_txt("c11 enum specifier"));
|
||||
expect((gen_Code)option_enum->Attributes == (gen_Code)enum_attributes, gen_txt("c11 enum attributes"));
|
||||
expect( option_enum->ModuleFlags == ModuleFlag_Export, gen_txt("c11 enum module flags"));
|
||||
gen_Str enum_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_enum));
|
||||
expect(gen_str_contains(enum_text, gen_txt("export")), gen_txt("c11 enum module flag serialization"));
|
||||
expect(gen_str_contains(enum_text, gen_txt("enum class")), gen_txt("c11 enum specifier serialization"));
|
||||
expect(gen_str_contains(enum_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 enum attribute serialization"));
|
||||
expect(gen_str_contains(enum_text, gen_txt("u32")), gen_txt("c11 enum type serialization"));
|
||||
expect(gen_str_contains(enum_text, gen_txt("Option_None")), gen_txt("c11 enum body serialization"));
|
||||
}
|
||||
|
||||
gen_Code enum_macro = gen_untyped_str(gen_txt("ENUM_BASE_TYPE"));
|
||||
gen_CodeEnum macro_enum = gen_def_enum(name(MacroOptionEnum),
|
||||
.body = gen_def_enum_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("Macro_None")))),
|
||||
.type_macro = enum_macro
|
||||
);
|
||||
expect(macro_enum != 0, gen_txt("c11 enum type macro option"));
|
||||
if (macro_enum != 0) {
|
||||
expect(macro_enum->UnderlyingTypeMacro == enum_macro, gen_txt("c11 enum type macro"));
|
||||
expect(gen_str_contains(gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)macro_enum)), gen_txt("ENUM_BASE_TYPE")), gen_txt("c11 enum type macro serialization"));
|
||||
}
|
||||
|
||||
gen_CodeBody union_body = gen_def_union_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("u32 union_option_value;"))));
|
||||
gen_CodeAttributes union_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeUnion option_union = gen_def_union(name(OptionUnion), union_body,
|
||||
.attributes = union_attributes,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_union != 0, gen_txt("c11 union options"));
|
||||
if (option_union != 0) {
|
||||
expect((gen_Code)option_union->Body == (gen_Code)union_body, gen_txt("c11 union body"));
|
||||
expect((gen_Code)option_union->Attributes == (gen_Code)union_attributes, gen_txt("c11 union attributes"));
|
||||
expect( option_union->ModuleFlags == ModuleFlag_Export, gen_txt("c11 union module flags"));
|
||||
gen_Str union_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_union));
|
||||
expect(gen_str_contains(union_text, gen_txt("OptionUnion")), gen_txt("c11 union name serialization"));
|
||||
expect(gen_str_contains(union_text, gen_txt("union_option_value")), gen_txt("c11 union body serialization"));
|
||||
expect(gen_str_contains(union_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 union attribute serialization"));
|
||||
expect(gen_str_contains(union_text, gen_txt("export")), gen_txt("c11 union module flag serialization"));
|
||||
}
|
||||
|
||||
gen_Code typedef_type = (gen_Code)gen_def_type(name(u32));
|
||||
gen_CodeAttributes typedef_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeTypedef option_typedef = gen_def_typedef(name(OptionTypedef), typedef_type,
|
||||
.attributes = typedef_attributes,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_typedef != 0, gen_txt("c11 typedef options"));
|
||||
if (option_typedef != 0) {
|
||||
expect( option_typedef->UnderlyingType == typedef_type, gen_txt("c11 typedef underlying type"));
|
||||
expect((gen_Code)option_typedef->Attributes == (gen_Code)typedef_attributes, gen_txt("c11 typedef attributes"));
|
||||
expect( option_typedef->ModuleFlags == ModuleFlag_Export, gen_txt("c11 typedef module flags"));
|
||||
gen_Str typedef_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_typedef));
|
||||
expect(gen_str_contains(typedef_text, gen_txt("OptionTypedef")), gen_txt("c11 typedef name serialization"));
|
||||
expect(gen_str_contains(typedef_text, gen_txt("u32")), gen_txt("c11 typedef type serialization"));
|
||||
expect(gen_str_contains(typedef_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 typedef attribute serialization"));
|
||||
expect(gen_str_contains(typedef_text, gen_txt("export")), gen_txt("c11 typedef module flag serialization"));
|
||||
}
|
||||
|
||||
gen_CodeTypename using_type = gen_def_type(name(u32));
|
||||
gen_CodeAttributes using_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeUsing option_using = gen_def_using(name(OptionUsing), using_type,
|
||||
.attributes = using_attributes,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_using != 0, gen_txt("c11 using options"));
|
||||
if (option_using != 0) {
|
||||
expect((gen_Code)option_using->UnderlyingType == (gen_Code)using_type, gen_txt("c11 using underlying type"));
|
||||
expect((gen_Code)option_using->Attributes == (gen_Code)using_attributes, gen_txt("c11 using attributes"));
|
||||
expect( option_using->ModuleFlags == ModuleFlag_Export, gen_txt("c11 using module flags"));
|
||||
gen_Str using_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_using));
|
||||
expect(gen_str_contains(using_text, gen_txt("OptionUsing")), gen_txt("c11 using name serialization"));
|
||||
expect(gen_str_contains(using_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 using attribute serialization"));
|
||||
expect(gen_str_contains(using_text, gen_txt("export")), gen_txt("c11 using module flag serialization"));
|
||||
}
|
||||
|
||||
gen_CodeParams template_params = gen_def_param(gen_def_type(name(class)), name(T));
|
||||
gen_CodeTemplate option_template = gen_def_template(template_params, (gen_Code)option_struct, .mflags = ModuleFlag_Export);
|
||||
expect(option_template != 0, gen_txt("c11 template options"));
|
||||
if (option_template != 0) {
|
||||
expect((gen_Code)option_template->Params == (gen_Code)template_params, gen_txt("c11 template parameters"));
|
||||
expect( option_template->Declaration == (gen_Code)option_struct, gen_txt("c11 template declaration"));
|
||||
expect( option_template->ModuleFlags == ModuleFlag_Export, gen_txt("c11 template module flags"));
|
||||
gen_Str template_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_template));
|
||||
expect(gen_str_contains(template_text, gen_txt("export")), gen_txt("c11 template module flag serialization"));
|
||||
expect(gen_str_contains(template_text, gen_txt("template")), gen_txt("c11 template serialization"));
|
||||
expect(gen_str_contains(template_text, gen_txt("StructOption")), gen_txt("c11 template declaration serialization"));
|
||||
}
|
||||
|
||||
gen_Macro source_macro = { gen_txt("OptionParamSource"), MT_Expression, MF_Functional }; gen_register_macro(source_macro);
|
||||
gen_CodeDefine parsed_macro_source = gen_parse_define(gen_txt("#define OptionParamSource(param) param\n"));
|
||||
expect(parsed_macro_source != 0, gen_txt("c11 define parameter source"));
|
||||
gen_MacroFlags define_flags = MF_Functional | MF_Allow_As_Identifier;
|
||||
gen_CodeDefine option_define = gen_def_define(name(OptionMacro), MT_Expression,
|
||||
.params = parsed_macro_source->Params,
|
||||
.content = gen_txt("param + 1"),
|
||||
.flags = define_flags
|
||||
);
|
||||
expect(option_define != 0, gen_txt("c11 define options"));
|
||||
if (option_define != 0) {
|
||||
expect(option_define->Params == parsed_macro_source->Params, gen_txt("c11 define parameters"));
|
||||
expect(gen_str_contains(option_define->Body->Content, gen_txt("param + 1")), gen_txt("c11 define content"));
|
||||
gen_Macro* option_macro = lookup_macro(name(OptionMacro));
|
||||
expect(option_macro != 0, gen_txt("c11 define registration"));
|
||||
if (option_macro != 0) expect(option_macro->Flags == define_flags, gen_txt("c11 define flags"));
|
||||
gen_Str define_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_define));
|
||||
expect(gen_str_contains(define_text, gen_txt("OptionMacro")), gen_txt("c11 define name serialization"));
|
||||
expect(gen_str_contains(define_text, gen_txt("OptionMacro( param)")), gen_txt("c11 define parameters serialization"));
|
||||
expect(gen_str_contains(define_text, gen_txt("param + 1")), gen_txt("c11 define content serialization"));
|
||||
}
|
||||
|
||||
gen_CodeDefine no_register_define = gen_def_define(name(OptionMacroNoRegister), MT_Expression,
|
||||
.dont_register_to_preprocess_macros = true
|
||||
);
|
||||
expect(no_register_define != 0, gen_txt("c11 define registration suppression"));
|
||||
expect(lookup_macro(name(OptionMacroNoRegister)) == 0, gen_txt("c11 define suppression flag"));
|
||||
|
||||
gen_CodeInclude local_include = gen_def_include(gen_txt("option_local.h"));
|
||||
expect(local_include != 0, gen_txt("c11 local include option"));
|
||||
if (local_include != 0) {
|
||||
expect(gen_str_contains(local_include->Content, gen_txt("\"option_local.h\"")), gen_txt("c11 quoted include"));
|
||||
}
|
||||
|
||||
gen_CodeInclude foreign_include = gen_def_include(gen_txt("option_system.h"), .foreign = true);
|
||||
expect(foreign_include != 0, gen_txt("c11 foreign include option"));
|
||||
if (foreign_include != 0) {
|
||||
expect(gen_str_contains(foreign_include->Content, gen_txt("<option_system.h>")), gen_txt("c11 foreign include path"));
|
||||
gen_Str include_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)foreign_include));
|
||||
expect(gen_str_contains(include_text, gen_txt("#include <option_system.h>")), gen_txt("c11 foreign include directive serialization"));
|
||||
}
|
||||
|
||||
gen_CodeModule option_module = gen_def_module(name(OptionModule), .mflags = ModuleFlag_Export);
|
||||
expect(option_module != 0, gen_txt("c11 module options"));
|
||||
if (option_module != 0) {
|
||||
expect(option_module->ModuleFlags == ModuleFlag_Export, gen_txt("c11 module flags"));
|
||||
expect(gen_str_contains(gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_module)), gen_txt("export")), gen_txt("c11 module serialization"));
|
||||
}
|
||||
|
||||
gen_CodeVar namespace_member = gen_def_variable(gen_def_type(name(u32)), name(namespace_option_value));
|
||||
gen_CodeBody namespace_body = gen_def_namespace_body(1, code_pod((gen_Code)namespace_member));
|
||||
gen_CodeNS option_namespace = gen_def_namespace(name(OptionNamespace), namespace_body, .mflags = ModuleFlag_Export);
|
||||
expect(option_namespace != 0, gen_txt("c11 namespace options"));
|
||||
if (option_namespace != 0) {
|
||||
expect((gen_Code)option_namespace->Body == (gen_Code)namespace_body, gen_txt("c11 namespace body"));
|
||||
expect( option_namespace->ModuleFlags == ModuleFlag_Export, gen_txt("c11 namespace flags"));
|
||||
gen_Str namespace_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_namespace));
|
||||
expect(gen_str_contains(namespace_text, gen_txt("OptionNamespace")), gen_txt("c11 namespace name serialization"));
|
||||
expect(gen_str_contains(namespace_text, gen_txt("namespace_option_value")), gen_txt("c11 namespace body serialization"));
|
||||
expect(gen_str_contains(namespace_text, gen_txt("export")), gen_txt("c11 namespace serialization"));
|
||||
}
|
||||
|
||||
gen_Code parameter_value = gen_untyped_str(code(7));
|
||||
gen_CodeParams option_parameter = gen_def_param(gen_def_type(name(u32)), name(option_parameter_value), .value = parameter_value);
|
||||
expect(option_parameter != 0, gen_txt("c11 parameter options"));
|
||||
if (option_parameter != 0) {
|
||||
expect(option_parameter->Value == parameter_value, gen_txt("c11 parameter value"));
|
||||
gen_Str parameter_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_parameter));
|
||||
expect(gen_str_contains(parameter_text, gen_txt("= 7")), gen_txt("c11 parameter value serialization"));
|
||||
}
|
||||
|
||||
gen_CodeParams function_params = gen_def_param(gen_def_type(name(u32)), name(function_option_arg));
|
||||
gen_CodeTypename function_return = gen_def_type(name(FunctionOptionReturn));
|
||||
gen_CodeBody function_body = gen_def_function_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("return function_option_arg;"))));
|
||||
gen_CodeAttributes function_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeSpecifiers function_specs = gen_def_specifier(Spec_Inline);
|
||||
gen_CodeFn option_function = gen_def_function(name(OptionFunction),
|
||||
.params = function_params,
|
||||
.ret_type = function_return,
|
||||
.body = function_body,
|
||||
.specs = function_specs,
|
||||
.attrs = function_attributes,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_function != 0, gen_txt("c11 function options"));
|
||||
if (option_function != 0) {
|
||||
expect((gen_Code)option_function->Params == (gen_Code)function_params, gen_txt("c11 function parameters"));
|
||||
expect((gen_Code)option_function->ReturnType == (gen_Code)function_return, gen_txt("c11 function return type"));
|
||||
expect((gen_Code)option_function->Body == (gen_Code)function_body, gen_txt("c11 function body"));
|
||||
expect((gen_Code)option_function->Specs == (gen_Code)function_specs, gen_txt("c11 function specifiers"));
|
||||
expect((gen_Code)option_function->Attributes == (gen_Code)function_attributes, gen_txt("c11 function attributes"));
|
||||
expect( option_function->ModuleFlags == ModuleFlag_Export, gen_txt("c11 function module flags"));
|
||||
gen_Str function_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_function));
|
||||
expect(gen_str_contains(function_text, gen_txt("OptionFunction")), gen_txt("c11 function name serialization"));
|
||||
expect(gen_str_contains(function_text, gen_txt("FunctionOptionReturn OptionFunction(")), gen_txt("c11 function return type serialization"));
|
||||
expect(gen_str_contains(function_text, gen_txt("function_option_arg")), gen_txt("c11 function parameters serialization"));
|
||||
expect(gen_str_contains(function_text, gen_txt("return function_option_arg")), gen_txt("c11 function body serialization"));
|
||||
expect(gen_str_contains(function_text, gen_txt("inline")), gen_txt("c11 function specifier serialization"));
|
||||
expect(gen_str_contains(function_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 function attribute serialization"));
|
||||
expect(gen_str_contains(function_text, gen_txt("export")), gen_txt("c11 function module flag serialization"));
|
||||
}
|
||||
|
||||
gen_CodeParams constructor_params = gen_def_param(gen_def_type(name(u32)), name(constructor_option_arg));
|
||||
gen_Code initializer_list = gen_untyped_str(gen_txt("option_member( 0 )"));
|
||||
gen_CodeBody constructor_body = gen_def_function_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("option_member = constructor_option_arg;"))));
|
||||
gen_CodeConstructor option_constructor = gen_def_constructor(
|
||||
.params = constructor_params,
|
||||
.initializer_list = initializer_list,
|
||||
.body = (gen_Code)constructor_body
|
||||
);
|
||||
expect(option_constructor != 0, gen_txt("c11 constructor options"));
|
||||
if (option_constructor != 0) {
|
||||
expect((gen_Code)option_constructor->Params == (gen_Code)constructor_params, gen_txt("c11 constructor parameters"));
|
||||
expect( option_constructor->InitializerList == initializer_list, gen_txt("c11 constructor initializer list"));
|
||||
expect( option_constructor->Body == (gen_Code)constructor_body, gen_txt("c11 constructor body"));
|
||||
}
|
||||
|
||||
gen_Code_POD constructor_pod = code_pod((gen_Code)option_constructor);
|
||||
gen_CodeBody constructor_class_body = gen_def_class_body(1, constructor_pod);
|
||||
gen_CodeClass constructor_class = gen_def_class(name(ConstructorOptions), .body = constructor_class_body);
|
||||
expect(constructor_class != 0, gen_txt("c11 constructor serialization parent"));
|
||||
if (constructor_class != 0) {
|
||||
gen_Str constructor_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)constructor_class));
|
||||
expect(gen_str_contains(constructor_text, gen_txt("ConstructorOptions(")), gen_txt("c11 constructor name serialization"));
|
||||
expect(gen_str_contains(constructor_text, gen_txt("u32 constructor_option_arg")), gen_txt("c11 constructor parameter serialization"));
|
||||
expect(gen_str_contains(constructor_text, gen_txt("option_member( 0 )")), gen_txt("c11 constructor initializer serialization"));
|
||||
expect(gen_str_contains(constructor_text, gen_txt("constructor_option_arg")), gen_txt("c11 constructor body serialization"));
|
||||
}
|
||||
|
||||
gen_Code destructor_body = gen_untyped_str(gen_txt("release_option_resource();"));
|
||||
gen_CodeSpecifiers destructor_specs = gen_def_specifier(Spec_Virtual);
|
||||
gen_CodeDestructor option_destructor = gen_def_destructor(
|
||||
.body = destructor_body,
|
||||
.specifiers = destructor_specs
|
||||
);
|
||||
expect(option_destructor != 0, gen_txt("c11 destructor options"));
|
||||
if (option_destructor != 0) {
|
||||
expect(option_destructor->Body == destructor_body, gen_txt("c11 destructor body"));
|
||||
expect((gen_Code)option_destructor->Specs == (gen_Code)destructor_specs, gen_txt("c11 destructor specifiers"));
|
||||
gen_Code_POD destructor_pod = code_pod((gen_Code)option_destructor);
|
||||
gen_CodeBody destructor_class_body = gen_def_class_body(1, destructor_pod);
|
||||
gen_CodeClass destructor_class = gen_def_class(name(DestructorOptions), .body = destructor_class_body);
|
||||
expect(destructor_class != 0, gen_txt("c11 destructor serialization parent"));
|
||||
if (destructor_class != 0) {
|
||||
gen_Str destructor_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)destructor_class));
|
||||
if (gen_str_contains(destructor_text, gen_txt("virtual ~DestructorOptions()")) == false) gen_log_fmt("%S\n", destructor_text);
|
||||
expect(gen_str_contains(destructor_text, gen_txt("virtual ~DestructorOptions()")), gen_txt("c11 destructor signature serialization"));
|
||||
expect(gen_str_contains(destructor_text, gen_txt("release_option_resource();")), gen_txt("c11 destructor body serialization"));
|
||||
}
|
||||
}
|
||||
|
||||
gen_CodeTypename operator_type = gen_def_type(name(OperatorOptionType));
|
||||
gen_CodeTypename operator_return = gen_def_type(name(OperatorOptionReturn));
|
||||
gen_CodeParams operator_lhs = gen_def_param(operator_type, name(operator_option_lhs));
|
||||
gen_CodeParams operator_rhs = gen_def_param(operator_type, name(operator_option_rhs));
|
||||
gen_CodeParams operator_params = gen_def_params(2, code_pod((gen_Code)operator_lhs), code_pod((gen_Code)operator_rhs));
|
||||
gen_CodeBody operator_body = gen_def_function_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("return operator_option_lhs;"))));
|
||||
gen_CodeSpecifiers operator_specs = gen_def_specifier(Spec_Inline);
|
||||
gen_CodeAttributes operator_attributes = gen_def_attributes(gen_txt("[[maybe_unused]]"));
|
||||
gen_CodeOperator option_operator = gen_def_operator(Op_Add, gen_txt(""),
|
||||
.params = operator_params,
|
||||
.ret_type = operator_return,
|
||||
.body = operator_body,
|
||||
.specifiers = operator_specs,
|
||||
.attributes = operator_attributes,
|
||||
.mflags = ModuleFlag_Export
|
||||
);
|
||||
expect(option_operator != 0, gen_txt("c11 operator options"));
|
||||
if (option_operator != 0) {
|
||||
expect((gen_Code)option_operator->Params == (gen_Code)operator_params, gen_txt("c11 operator parameters"));
|
||||
expect((gen_Code)option_operator->ReturnType == (gen_Code)operator_return, gen_txt("c11 operator return type"));
|
||||
expect((gen_Code)option_operator->Body == (gen_Code)operator_body, gen_txt("c11 operator body"));
|
||||
expect((gen_Code)option_operator->Specs == (gen_Code)operator_specs, gen_txt("c11 operator specifiers"));
|
||||
expect((gen_Code)option_operator->Attributes == (gen_Code)operator_attributes, gen_txt("c11 operator attributes"));
|
||||
expect( option_operator->ModuleFlags == ModuleFlag_Export, gen_txt("c11 operator module flags"));
|
||||
gen_Str operator_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_operator));
|
||||
expect(gen_str_contains(operator_text, gen_txt("OperatorOptionReturn")), gen_txt("c11 operator return type serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("operator +")), gen_txt("c11 operator name serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("operator_option_lhs")), gen_txt("c11 operator parameters serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("operator_option_rhs")), gen_txt("c11 operator second parameter serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("return operator_option_lhs")), gen_txt("c11 operator body serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("inline")), gen_txt("c11 operator specifier serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("[[maybe_unused]]")), gen_txt("c11 operator attribute serialization"));
|
||||
expect(gen_str_contains(operator_text, gen_txt("export")), gen_txt("c11 operator module flag serialization"));
|
||||
if (gen_str_starts_with(operator_text, gen_txt("export [[maybe_unused]] inline\nOperatorOptionReturn")) == false) gen_log_fmt("%S\n", operator_text);
|
||||
expect(gen_str_starts_with(operator_text, gen_txt("export [[maybe_unused]] inline\nOperatorOptionReturn")), gen_txt("c11 operator one-attribute prefix serialization"));
|
||||
}
|
||||
|
||||
gen_CodeTypename cast_type = gen_def_type(name(s32));
|
||||
gen_CodeBody cast_body = gen_def_function_body(1, code_pod((gen_Code)gen_untyped_str(gen_txt("return 0;"))));
|
||||
gen_CodeSpecifiers cast_specs = gen_def_specifier(Spec_Const);
|
||||
gen_CodeOpCast option_cast = gen_def_operator_cast(cast_type,
|
||||
.body = cast_body,
|
||||
.specs = cast_specs
|
||||
);
|
||||
expect(option_cast != 0, gen_txt("c11 operator cast options"));
|
||||
if (option_cast != 0) {
|
||||
expect((gen_Code)option_cast->ValueType == (gen_Code)cast_type, gen_txt("c11 operator cast type"));
|
||||
expect((gen_Code)option_cast->Body == (gen_Code)cast_body, gen_txt("c11 operator cast body"));
|
||||
expect((gen_Code)option_cast->Specs == (gen_Code)cast_specs, gen_txt("c11 operator cast specifiers"));
|
||||
gen_Str cast_text = gen_strbuilder_to_str(gen_code_to_strbuilder((gen_Code)option_cast));
|
||||
expect(gen_str_contains(cast_text, gen_txt("operator s32")), gen_txt("c11 operator cast serialization"));
|
||||
expect(gen_str_contains(cast_text, gen_txt("const")), gen_txt("c11 operator cast specifier serialization"));
|
||||
expect(gen_str_contains(cast_text, gen_txt("return 0")), gen_txt("c11 operator cast body serialization"));
|
||||
}
|
||||
|
||||
gen_Code untyped = gen_code_str(char const* baseline_message = "GENCPP_BASELINE"; );
|
||||
expect(untyped != 0, gen_txt("c11 untyped"));
|
||||
|
||||
gen_Str untyped_text = gen_strbuilder_to_str(gen_code_to_strbuilder(untyped));
|
||||
expect_fragments(untyped_text, gen_txt("c11 untyped content"));
|
||||
expect_variable(gen_parse_variable(untyped_text), gen_txt("c11 untyped reparsed"));
|
||||
|
||||
gen_CodeVar parsed = gen_parse_variable(code(char const* baseline_message = "GENCPP_BASELINE"; ));
|
||||
expect_variable(parsed, gen_txt("c11 parsed"));
|
||||
expect_fragments(gen_strbuilder_to_str(gen_code_to_strbuilder(parsed)), gen_txt("c11 parsed serialized"));
|
||||
|
||||
#if ! GEN_BUILD_DEBUG
|
||||
gen_CodeVar wrong_array_value = gen_def_variable(gen_def_type(name(u32)), name(invalid_array_expr));
|
||||
gen_CodeTypename invalid_array_type = gen_def_type(name(InvalidArrayOption), .gen_array_expr = (gen_Code)wrong_array_value);
|
||||
expect((gen_Code)invalid_array_type == gen_Code_Invalid, gen_txt("c11 wrong type invalid code"));
|
||||
|
||||
gen_CodeBody missing_union_body = 0;
|
||||
gen_CodeUnion missing_union = gen_def_union(name(MissingUnionBody), missing_union_body);
|
||||
expect((gen_Code)missing_union == gen_Code_Invalid, gen_txt("c11 missing body invalid code"));
|
||||
#endif
|
||||
|
||||
gen_deinit(&ctx);
|
||||
if (g_failures != 0) { gen_log_fmt("c11 baseline smoke failed: %d\n", g_failures); return 1; }
|
||||
gen_log_fmt("c11 baseline smoke passed\n");
|
||||
return 0;
|
||||
}
|
||||
+465
-15
@@ -1,29 +1,479 @@
|
||||
#define GEN_DONT_USE_FATAL
|
||||
#define GEN_IMPLEMENTATION
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#include "gen.hpp"
|
||||
|
||||
global int g_failures = 0;
|
||||
|
||||
internal void expect(int condition, gen::Str name) {
|
||||
if (condition == false) { gen::log_fmt("FAIL %S\n", name); ++ g_failures; }
|
||||
}
|
||||
|
||||
internal void expect_fragments(gen::Str text, gen::Str label) {
|
||||
expect(text.Ptr != nullptr && text.Len > 0, label);
|
||||
expect(gen::str_contains(text, txt("baseline_message")), label);
|
||||
expect(gen::str_contains(text, txt("char")), label);
|
||||
expect(gen::str_contains(text, txt("const")), label);
|
||||
expect(gen::str_contains(text, txt("*")), label);
|
||||
expect(gen::str_contains(text, txt("GENCPP_BASELINE")), label);
|
||||
}
|
||||
|
||||
internal void expect_variable(gen::CodeVar var, gen::Str label) {
|
||||
expect(var.ast != nullptr, label); if (var.ast == nullptr) return;
|
||||
expect(var->Type == gen::CT_Variable, label);
|
||||
expect(gen::str_contains(var->Name, txt("baseline_message")), label);
|
||||
expect(var->ValueType.ast != nullptr, label);
|
||||
expect(var->Value.ast != nullptr, label);
|
||||
if (var->Value.ast != nullptr) {
|
||||
expect(gen::str_contains(var->Value->Content, txt("GENCPP_BASELINE")), label);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace gen;
|
||||
Context ctx = {};
|
||||
gen::init( & ctx);
|
||||
Context ctx = {}; init(&ctx);
|
||||
|
||||
Builder src_hello = builder_open("gen/hello.cpp");
|
||||
CodeVar hello_var = parse_variable( code(
|
||||
constexpr char const* hello_gencpp_str = "HELLO GENCPP !";
|
||||
));
|
||||
src_hello.print(hello_var);
|
||||
src_hello.write();
|
||||
Opts_def_type type_opts = {};
|
||||
type_opts.specifiers = def_specifiers(args(Spec_Const, Spec_Ptr));
|
||||
CodeTypename type = def_type(name(char), type_opts);
|
||||
Opts_def_variable opts = {}; opts.value = untyped_str(code("\"GENCPP_BASELINE\""));
|
||||
CodeVar upfront = def_variable(type, name(baseline_message), opts);
|
||||
expect_variable(upfront, txt("cpp upfront"));
|
||||
expect_fragments(strbuilder_to_str(code_to_strbuilder((Code)upfront)), txt("cpp upfront serialized"));
|
||||
|
||||
CodeBody body = parse_file("gen/hello.cpp");
|
||||
for ( Code code : body ) switch (code->Type) {
|
||||
case CT_Variable:
|
||||
CodeVar var = cast(CodeVar, code);
|
||||
log_fmt("%S", var->Value);
|
||||
break;
|
||||
Opts_def_type type_options = {};
|
||||
Code array_expr = untyped_str(txt("3"));
|
||||
CodeSpecifiers type_specs = def_specifier(Spec_Const);
|
||||
CodeAttributes type_attrs = def_attributes(txt("[[maybe_unused]]"));
|
||||
type_options.type_tag = Tag_Struct;
|
||||
type_options.array_expr = array_expr;
|
||||
type_options.specifiers = type_specs;
|
||||
type_options.attributes = type_attrs;
|
||||
CodeTypename option_type = def_type(name(Payload), type_options);
|
||||
expect(option_type.ast != nullptr, txt("cpp type options"));
|
||||
if (option_type.ast != nullptr) {
|
||||
expect(option_type->TypeTag == Tag_Struct, txt("cpp type tag"));
|
||||
expect(option_type->ArrExpr.ast == array_expr.ast, txt("cpp type array expression"));
|
||||
expect(option_type->Specs.ast == type_specs.ast, txt("cpp type specifiers"));
|
||||
expect(option_type->Attributes.ast == type_attrs.ast, txt("cpp type attributes"));
|
||||
Str type_text = strbuilder_to_str(code_to_strbuilder((Code)option_type));
|
||||
expect(str_contains(type_text, txt("struct Payload")), txt("cpp type tag serialization"));
|
||||
expect(str_contains(type_text, txt("const")), txt("cpp type specifier serialization"));
|
||||
expect(str_contains(type_text, txt("[[maybe_unused]]")), txt("cpp type attribute serialization"));
|
||||
}
|
||||
|
||||
gen::deinit(& ctx);
|
||||
Opts_def_variable variable_options = {};
|
||||
Code value = untyped_str(code("\"UPFRONT_OPTION\""));
|
||||
CodeSpecifiers variable_specs = def_specifier(Spec_Static);
|
||||
CodeAttributes variable_attrs = def_attributes(txt("[[maybe_unused]]"));
|
||||
variable_options.value = value;
|
||||
variable_options.specifiers = variable_specs;
|
||||
variable_options.attributes = variable_attrs;
|
||||
variable_options.mflags = ModuleFlag_Export;
|
||||
CodeVar option_variable = def_variable(option_type, name(option_payload), variable_options);
|
||||
expect(option_variable.ast != nullptr, txt("cpp variable options"));
|
||||
if (option_variable.ast != nullptr) {
|
||||
expect(option_variable->ValueType.ast == option_type.ast, txt("cpp variable type"));
|
||||
expect(option_variable->Value.ast == value.ast, txt("cpp variable value"));
|
||||
expect(option_variable->Specs.ast == variable_specs.ast, txt("cpp variable specifiers"));
|
||||
expect(option_variable->Attributes.ast == variable_attrs.ast, txt("cpp variable attributes"));
|
||||
expect(option_variable->ModuleFlags == ModuleFlag_Export, txt("cpp variable module flags"));
|
||||
Str variable_text = strbuilder_to_str(code_to_strbuilder((Code)option_variable));
|
||||
expect(str_contains(variable_text, txt("option_payload")), txt("cpp variable name serialization"));
|
||||
expect(str_contains(variable_text, txt("UPFRONT_OPTION")), txt("cpp variable value serialization"));
|
||||
expect(str_contains(variable_text, txt("static")), txt("cpp variable specifier serialization"));
|
||||
expect(str_contains(variable_text, txt("[[maybe_unused]]")), txt("cpp variable attribute serialization"));
|
||||
expect(str_contains(variable_text, txt("[ 3 ]")), txt("cpp variable array serialization"));
|
||||
expect(str_contains(variable_text, txt("export")), txt("cpp variable module flag serialization"));
|
||||
}
|
||||
|
||||
CodeVar class_member = def_variable(def_type(name(u32)), name(class_option_member));
|
||||
CodeBody class_body = def_class_body(args(class_member));
|
||||
CodeTypename class_parent = def_type(name(ClassOptionBase));
|
||||
CodeTypename class_interfaces[] = { def_type(name(IClassOption)) };
|
||||
Opts_def_struct class_options = {};
|
||||
class_options.body = class_body;
|
||||
class_options.parent = class_parent;
|
||||
class_options.parent_access = AccessSpec_Public;
|
||||
class_options.attributes = def_attributes(txt("[[maybe_unused]]"));
|
||||
class_options.interfaces = class_interfaces;
|
||||
class_options.num_interfaces = 1;
|
||||
class_options.specifiers = def_specifier(Spec_Final);
|
||||
class_options.mflags = ModuleFlag_Export;
|
||||
CodeClass option_class = def_class(name(ClassOption), class_options);
|
||||
expect(option_class.ast != nullptr, txt("cpp class options"));
|
||||
if (option_class.ast != nullptr) {
|
||||
expect(option_class->Body.ast == class_body.ast, txt("cpp class body"));
|
||||
expect(option_class->ParentType.ast == class_parent.ast, txt("cpp class parent"));
|
||||
expect(option_class->ParentAccess == AccessSpec_Public, txt("cpp class parent access"));
|
||||
expect(option_class->Attributes.ast == class_options.attributes.ast, txt("cpp class attributes"));
|
||||
expect(option_class->ParentType->Next.ast == ((Code)class_interfaces[0]).ast, txt("cpp class interface"));
|
||||
expect(option_class->Specs.ast == class_options.specifiers.ast, txt("cpp class specifiers"));
|
||||
expect(option_class->ModuleFlags == ModuleFlag_Export, txt("cpp class module flags"));
|
||||
Str class_text = strbuilder_to_str(code_to_strbuilder((Code)option_class));
|
||||
expect(str_contains(class_text, txt("ClassOption")), txt("cpp class name serialization"));
|
||||
expect(str_contains(class_text, txt("ClassOptionBase")), txt("cpp class parent serialization"));
|
||||
expect(str_contains(class_text, txt("IClassOption")), txt("cpp class interface serialization"));
|
||||
expect(str_contains(class_text, txt("public")), txt("cpp class access serialization"));
|
||||
expect(str_contains(class_text, txt("class_option_member")), txt("cpp class body serialization"));
|
||||
expect(str_contains(class_text, txt("[[maybe_unused]]")), txt("cpp class attribute serialization"));
|
||||
expect(str_contains(class_text, txt("final")), txt("cpp class final specifier serialization"));
|
||||
expect(str_contains(class_text, txt("export")), txt("cpp class module flag serialization"));
|
||||
}
|
||||
|
||||
CodeVar struct_member = def_variable(def_type(name(u32)), name(struct_option_member));
|
||||
CodeBody struct_body = def_struct_body(args(struct_member));
|
||||
CodeTypename struct_parent = def_type(name(StructOptionBase));
|
||||
CodeTypename struct_interfaces[] = { def_type(name(IStructOption)) };
|
||||
Opts_def_struct struct_options = {};
|
||||
struct_options.body = struct_body;
|
||||
struct_options.parent = struct_parent;
|
||||
struct_options.parent_access = AccessSpec_Public;
|
||||
struct_options.attributes = def_attributes(txt("[[maybe_unused]]"));
|
||||
struct_options.interfaces = struct_interfaces;
|
||||
struct_options.num_interfaces = 1;
|
||||
struct_options.specifiers = def_specifier(Spec_Final);
|
||||
struct_options.mflags = ModuleFlag_Export;
|
||||
CodeStruct option_struct = def_struct(name(StructOption), struct_options);
|
||||
expect(option_struct.ast != nullptr, txt("cpp struct options"));
|
||||
if (option_struct.ast != nullptr) {
|
||||
expect(option_struct->Body.ast == struct_body.ast, txt("cpp struct body"));
|
||||
expect(option_struct->ParentType.ast == struct_parent.ast, txt("cpp struct parent"));
|
||||
expect(option_struct->ParentAccess == AccessSpec_Public, txt("cpp struct parent access"));
|
||||
expect(option_struct->Attributes.ast == struct_options.attributes.ast, txt("cpp struct attributes"));
|
||||
expect(option_struct->ParentType->Next.ast == ((Code)struct_interfaces[0]).ast, txt("cpp struct interface"));
|
||||
expect(option_struct->Specs.ast == struct_options.specifiers.ast, txt("cpp struct specifiers"));
|
||||
expect(option_struct->ModuleFlags == ModuleFlag_Export, txt("cpp struct module flags"));
|
||||
Str struct_text = strbuilder_to_str(code_to_strbuilder((Code)option_struct));
|
||||
expect(str_contains(struct_text, txt("StructOption")), txt("cpp struct name serialization"));
|
||||
expect(str_contains(struct_text, txt("StructOptionBase")), txt("cpp struct parent serialization"));
|
||||
expect(str_contains(struct_text, txt("IStructOption")), txt("cpp struct interface serialization"));
|
||||
expect(str_contains(struct_text, txt("public")), txt("cpp struct access serialization"));
|
||||
expect(str_contains(struct_text, txt("struct_option_member")), txt("cpp struct body serialization"));
|
||||
expect(str_contains(struct_text, txt("[[maybe_unused]]")), txt("cpp struct attribute serialization"));
|
||||
expect(str_contains(struct_text, txt("final")), txt("cpp struct final specifier serialization"));
|
||||
expect(str_contains(struct_text, txt("export")), txt("cpp struct module flag serialization"));
|
||||
}
|
||||
|
||||
CodeBody enum_body = def_enum_body(args(untyped_str(txt("Option_None"))));
|
||||
Opts_def_enum enum_options = {};
|
||||
enum_options.body = enum_body;
|
||||
enum_options.type = def_type(name(u32));
|
||||
enum_options.specifier = EnumDecl_Class;
|
||||
enum_options.attributes = def_attributes(txt("[[maybe_unused]]"));
|
||||
enum_options.mflags = ModuleFlag_Export;
|
||||
CodeEnum option_enum = def_enum(name(OptionEnum), enum_options);
|
||||
expect(option_enum.ast != nullptr, txt("cpp enum options"));
|
||||
if (option_enum.ast != nullptr) {
|
||||
expect(option_enum->Body.ast == enum_body.ast, txt("cpp enum body"));
|
||||
expect(option_enum->UnderlyingType.ast == enum_options.type.ast, txt("cpp enum underlying type"));
|
||||
expect(option_enum->Type == CT_Enum_Class, txt("cpp enum specifier"));
|
||||
expect(option_enum->Attributes.ast == enum_options.attributes.ast, txt("cpp enum attributes"));
|
||||
expect(option_enum->ModuleFlags == ModuleFlag_Export, txt("cpp enum module flags"));
|
||||
Str enum_text = strbuilder_to_str(code_to_strbuilder((Code)option_enum));
|
||||
expect(str_contains(enum_text, txt("export")), txt("cpp enum module flag serialization"));
|
||||
expect(str_contains(enum_text, txt("enum class")), txt("cpp enum specifier serialization"));
|
||||
expect(str_contains(enum_text, txt("[[maybe_unused]]")), txt("cpp enum attribute serialization"));
|
||||
expect(str_contains(enum_text, txt("u32")), txt("cpp enum type serialization"));
|
||||
expect(str_contains(enum_text, txt("Option_None")), txt("cpp enum body serialization"));
|
||||
}
|
||||
Code enum_macro = untyped_str(txt("ENUM_BASE_TYPE"));
|
||||
CodeEnum macro_enum = def_enum(name(MacroOptionEnum), {
|
||||
.body = def_enum_body(args(untyped_str(txt("Macro_None")))),
|
||||
.type_macro = enum_macro,
|
||||
});
|
||||
expect(macro_enum.ast != nullptr, txt("cpp enum type macro option"));
|
||||
if (macro_enum.ast != nullptr) {
|
||||
expect(macro_enum->UnderlyingTypeMacro.ast == enum_macro.ast, txt("cpp enum type macro"));
|
||||
expect(str_contains(strbuilder_to_str(code_to_strbuilder((Code)macro_enum)), txt("ENUM_BASE_TYPE")), txt("cpp enum type macro serialization"));
|
||||
}
|
||||
|
||||
CodeBody union_body = def_union_body(args(untyped_str(txt("u32 union_option_value;"))));
|
||||
Opts_def_union union_options = {};
|
||||
union_options.attributes = def_attributes(txt("[[maybe_unused]]"));
|
||||
union_options.mflags = ModuleFlag_Export;
|
||||
CodeUnion option_union = def_union(name(OptionUnion), union_body, union_options);
|
||||
expect(option_union.ast != nullptr, txt("cpp union options"));
|
||||
if (option_union.ast != nullptr) {
|
||||
expect(option_union->Body.ast == union_body.ast, txt("cpp union body"));
|
||||
expect(option_union->Attributes.ast == union_options.attributes.ast, txt("cpp union attributes"));
|
||||
expect(option_union->ModuleFlags == ModuleFlag_Export, txt("cpp union module flags"));
|
||||
Str union_text = strbuilder_to_str(code_to_strbuilder((Code)option_union));
|
||||
expect(str_contains(union_text, txt("OptionUnion")), txt("cpp union name serialization"));
|
||||
expect(str_contains(union_text, txt("union_option_value")), txt("cpp union body serialization"));
|
||||
expect(str_contains(union_text, txt("[[maybe_unused]]")), txt("cpp union attribute serialization"));
|
||||
expect(str_contains(union_text, txt("export")), txt("cpp union module flag serialization"));
|
||||
}
|
||||
|
||||
CodeAttributes typedef_attrs = def_attributes(txt("[[maybe_unused]]"));
|
||||
Code typedef_type = (Code)def_type(name(u32));
|
||||
Opts_def_typedef typedef_options = {};
|
||||
typedef_options.attributes = typedef_attrs;
|
||||
typedef_options.mflags = ModuleFlag_Export;
|
||||
CodeTypedef option_typedef = def_typedef(name(OptionTypedef), typedef_type, typedef_options);
|
||||
expect(option_typedef.ast != nullptr, txt("cpp typedef options"));
|
||||
if (option_typedef.ast != nullptr) {
|
||||
expect(option_typedef->UnderlyingType.ast == typedef_type.ast, txt("cpp typedef underlying type"));
|
||||
expect(option_typedef->Attributes.ast == typedef_attrs.ast, txt("cpp typedef attributes"));
|
||||
expect(option_typedef->ModuleFlags == ModuleFlag_Export, txt("cpp typedef module flags"));
|
||||
Str typedef_text = strbuilder_to_str(code_to_strbuilder((Code)option_typedef));
|
||||
expect(str_contains(typedef_text, txt("OptionTypedef")), txt("cpp typedef name serialization"));
|
||||
expect(str_contains(typedef_text, txt("u32")), txt("cpp typedef type serialization"));
|
||||
expect(str_contains(typedef_text, txt("[[maybe_unused]]")), txt("cpp typedef attribute serialization"));
|
||||
expect(str_contains(typedef_text, txt("export")), txt("cpp typedef module flag serialization"));
|
||||
}
|
||||
|
||||
Opts_def_using using_options = {};
|
||||
using_options.attributes = def_attributes(txt("[[maybe_unused]]"));
|
||||
using_options.mflags = ModuleFlag_Export;
|
||||
CodeTypename using_type = def_type(name(u32));
|
||||
CodeUsing option_using = def_using(name(OptionUsing), using_type, using_options);
|
||||
expect(option_using.ast != nullptr, txt("cpp using options"));
|
||||
if (option_using.ast != nullptr) {
|
||||
expect(option_using->UnderlyingType.ast == using_type.ast, txt("cpp using underlying type"));
|
||||
expect(option_using->Attributes.ast == using_options.attributes.ast, txt("cpp using attributes"));
|
||||
expect(option_using->ModuleFlags == ModuleFlag_Export, txt("cpp using module flags"));
|
||||
Str using_text = strbuilder_to_str(code_to_strbuilder((Code)option_using));
|
||||
expect(str_contains(using_text, txt("OptionUsing")), txt("cpp using name serialization"));
|
||||
expect(str_contains(using_text, txt("[[maybe_unused]]")), txt("cpp using attribute serialization"));
|
||||
expect(str_contains(using_text, txt("export")), txt("cpp using module flag serialization"));
|
||||
}
|
||||
|
||||
CodeParams template_params = def_param(def_type(name(class)), name(T));
|
||||
CodeTemplate option_template = def_template(template_params, (Code)option_struct, { .mflags = ModuleFlag_Export });
|
||||
expect(option_template.ast != nullptr, txt("cpp template options"));
|
||||
if (option_template.ast != nullptr) {
|
||||
expect(option_template->Params.ast == template_params.ast, txt("cpp template parameters"));
|
||||
expect(option_template->Declaration.ast == ((Code)option_struct).ast, txt("cpp template declaration"));
|
||||
expect(option_template->ModuleFlags == ModuleFlag_Export, txt("cpp template module flags"));
|
||||
Str template_text = strbuilder_to_str(code_to_strbuilder((Code)option_template));
|
||||
expect(str_contains(template_text, txt("export")), txt("cpp template module flag serialization"));
|
||||
expect(str_contains(template_text, txt("template")), txt("cpp template serialization"));
|
||||
expect(str_contains(template_text, txt("StructOption")), txt("cpp template declaration serialization"));
|
||||
}
|
||||
|
||||
Macro source_macro = { txt("OptionParamSource"), MT_Expression, MF_Functional };
|
||||
register_macro(source_macro);
|
||||
CodeDefine parsed_macro_source = parse_define(txt("#define OptionParamSource(param) param\n"));
|
||||
expect(parsed_macro_source.ast != nullptr, txt("cpp define parameter source"));
|
||||
Opts_def_define define_options = {};
|
||||
define_options.params = parsed_macro_source->Params;
|
||||
define_options.content = txt("param + 1");
|
||||
define_options.flags = MF_Functional | MF_Allow_As_Identifier;
|
||||
CodeDefine option_define = def_define(name(OptionMacro), MT_Expression, define_options);
|
||||
expect(option_define.ast != nullptr, txt("cpp define options"));
|
||||
if (option_define.ast != nullptr) {
|
||||
expect(option_define->Params.ast == define_options.params.ast, txt("cpp define parameters"));
|
||||
expect(str_contains(option_define->Body->Content, txt("param + 1")), txt("cpp define content"));
|
||||
Macro* option_macro = lookup_macro(name(OptionMacro));
|
||||
expect(option_macro != nullptr, txt("cpp define registration"));
|
||||
if (option_macro != nullptr) expect(option_macro->Flags == define_options.flags, txt("cpp define flags"));
|
||||
Str define_text = strbuilder_to_str(code_to_strbuilder((Code)option_define));
|
||||
expect(str_contains(define_text, txt("OptionMacro")), txt("cpp define name serialization"));
|
||||
expect(str_contains(define_text, txt("OptionMacro( param)")), txt("cpp define parameters serialization"));
|
||||
expect(str_contains(define_text, txt("param + 1")), txt("cpp define content serialization"));
|
||||
}
|
||||
Opts_def_define no_register_options = {};
|
||||
no_register_options.dont_register_to_preprocess_macros = true;
|
||||
CodeDefine no_register_define = def_define(name(OptionMacroNoRegister), MT_Expression, no_register_options);
|
||||
expect(no_register_define.ast != nullptr, txt("cpp define registration suppression"));
|
||||
expect(lookup_macro(name(OptionMacroNoRegister)) == nullptr, txt("cpp define suppression flag"));
|
||||
|
||||
CodeInclude local_include = def_include(txt("option_local.h"));
|
||||
expect(local_include.ast != nullptr, txt("cpp local include option"));
|
||||
if (local_include.ast != nullptr) {
|
||||
expect(str_contains(local_include->Content, txt("\"option_local.h\"")), txt("cpp quoted include"));
|
||||
}
|
||||
Opts_def_include foreign_include_options = {};
|
||||
foreign_include_options.foreign = true;
|
||||
CodeInclude foreign_include = def_include(txt("option_system.h"), foreign_include_options);
|
||||
expect(foreign_include.ast != nullptr, txt("cpp foreign include option"));
|
||||
if (foreign_include.ast != nullptr) {
|
||||
expect(str_contains(foreign_include->Content, txt("<option_system.h>")), txt("cpp foreign include path"));
|
||||
Str include_text = strbuilder_to_str(code_to_strbuilder((Code)foreign_include));
|
||||
expect(str_contains(include_text, txt("#include <option_system.h>")), txt("cpp foreign include directive serialization"));
|
||||
}
|
||||
|
||||
CodeModule option_module = def_module(name(OptionModule), { .mflags = ModuleFlag_Export });
|
||||
expect(option_module.ast != nullptr, txt("cpp module options"));
|
||||
if (option_module.ast != nullptr) {
|
||||
expect(option_module->ModuleFlags == ModuleFlag_Export, txt("cpp module flags"));
|
||||
expect(str_contains(strbuilder_to_str(code_to_strbuilder((Code)option_module)), txt("export")), txt("cpp module serialization"));
|
||||
}
|
||||
CodeVar namespace_member = def_variable(def_type(name(u32)), name(namespace_option_value));
|
||||
CodeBody namespace_body = def_namespace_body(args(namespace_member));
|
||||
CodeNS option_namespace = def_namespace(name(OptionNamespace), namespace_body, { .mflags = ModuleFlag_Export });
|
||||
expect(option_namespace.ast != nullptr, txt("cpp namespace options"));
|
||||
if (option_namespace.ast != nullptr) {
|
||||
expect(option_namespace->Body.ast == namespace_body.ast, txt("cpp namespace body"));
|
||||
expect(option_namespace->ModuleFlags == ModuleFlag_Export, txt("cpp namespace flags"));
|
||||
Str namespace_text = strbuilder_to_str(code_to_strbuilder((Code)option_namespace));
|
||||
expect(str_contains(namespace_text, txt("OptionNamespace")), txt("cpp namespace name serialization"));
|
||||
expect(str_contains(namespace_text, txt("namespace_option_value")), txt("cpp namespace body serialization"));
|
||||
expect(str_contains(namespace_text, txt("export")), txt("cpp namespace serialization"));
|
||||
}
|
||||
|
||||
Code parameter_value = untyped_str(code(7));
|
||||
Opts_def_param parameter_options = {};
|
||||
parameter_options.value = parameter_value;
|
||||
CodeParams option_parameter = def_param(def_type(name(u32)), name(option_parameter_value), parameter_options);
|
||||
expect(option_parameter.ast != nullptr, txt("cpp parameter options"));
|
||||
if (option_parameter.ast != nullptr) {
|
||||
expect(option_parameter->Value.ast == parameter_value.ast, txt("cpp parameter value"));
|
||||
Str parameter_text = strbuilder_to_str(code_to_strbuilder((Code)option_parameter));
|
||||
expect(str_contains(parameter_text, txt("= 7")), txt("cpp parameter value serialization"));
|
||||
}
|
||||
|
||||
CodeParams function_params = def_param(def_type(name(u32)), name(function_option_arg));
|
||||
CodeTypename function_return = def_type(name(FunctionOptionReturn));
|
||||
CodeBody function_body = def_function_body(args(untyped_str(txt("return function_option_arg;"))));
|
||||
Opts_def_function function_options = {};
|
||||
function_options.params = function_params;
|
||||
function_options.ret_type = function_return;
|
||||
function_options.body = function_body;
|
||||
function_options.specs = def_specifier(Spec_Inline);
|
||||
function_options.attrs = def_attributes(txt("[[maybe_unused]]"));
|
||||
function_options.mflags = ModuleFlag_Export;
|
||||
CodeFn option_function = def_function(name(OptionFunction), function_options);
|
||||
expect(option_function.ast != nullptr, txt("cpp function options"));
|
||||
if (option_function.ast != nullptr) {
|
||||
expect(option_function->Params.ast == function_params.ast, txt("cpp function parameters"));
|
||||
expect(option_function->ReturnType.ast == function_return.ast, txt("cpp function return type"));
|
||||
expect(option_function->Body.ast == function_body.ast, txt("cpp function body"));
|
||||
expect(option_function->Specs.ast == function_options.specs.ast, txt("cpp function specifiers"));
|
||||
expect(option_function->Attributes.ast == function_options.attrs.ast, txt("cpp function attributes"));
|
||||
expect(option_function->ModuleFlags == ModuleFlag_Export, txt("cpp function module flags"));
|
||||
Str function_text = strbuilder_to_str(code_to_strbuilder((Code)option_function));
|
||||
expect(str_contains(function_text, txt("OptionFunction")), txt("cpp function name serialization"));
|
||||
expect(str_contains(function_text, txt("FunctionOptionReturn OptionFunction(")), txt("cpp function return type serialization"));
|
||||
expect(str_contains(function_text, txt("function_option_arg")), txt("cpp function parameters serialization"));
|
||||
expect(str_contains(function_text, txt("return function_option_arg")), txt("cpp function body serialization"));
|
||||
expect(str_contains(function_text, txt("inline")), txt("cpp function specifier serialization"));
|
||||
expect(str_contains(function_text, txt("[[maybe_unused]]")), txt("cpp function attribute serialization"));
|
||||
expect(str_contains(function_text, txt("export")), txt("cpp function module flag serialization"));
|
||||
}
|
||||
|
||||
CodeParams constructor_params = def_param(def_type(name(u32)), name(constructor_option_arg));
|
||||
Code initializer_list = untyped_str(txt("option_member( 0 )"));
|
||||
CodeBody constructor_body = def_function_body(args(untyped_str(txt("option_member = constructor_option_arg;"))));
|
||||
Opts_def_constructor constructor_options = {};
|
||||
constructor_options.params = constructor_params;
|
||||
constructor_options.initializer_list = initializer_list;
|
||||
constructor_options.body = constructor_body;
|
||||
CodeConstructor option_constructor = def_constructor(constructor_options);
|
||||
expect(option_constructor.ast != nullptr, txt("cpp constructor options"));
|
||||
if (option_constructor.ast != nullptr) {
|
||||
expect(option_constructor->Params.ast == constructor_params.ast, txt("cpp constructor parameters"));
|
||||
expect(option_constructor->InitializerList.ast == initializer_list.ast, txt("cpp constructor initializer list"));
|
||||
expect(option_constructor->Body.ast == ((Code)constructor_body).ast, txt("cpp constructor body"));
|
||||
}
|
||||
CodeBody constructor_class_body = def_class_body(args(option_constructor));
|
||||
CodeClass constructor_class = def_class(name(ConstructorOptions), { .body = constructor_class_body });
|
||||
expect(constructor_class.ast != nullptr, txt("cpp constructor serialization parent"));
|
||||
if (constructor_class.ast != nullptr) {
|
||||
Str constructor_text = strbuilder_to_str(code_to_strbuilder((Code)constructor_class));
|
||||
expect(str_contains(constructor_text, txt("ConstructorOptions(")), txt("cpp constructor name serialization"));
|
||||
expect(str_contains(constructor_text, txt("u32 constructor_option_arg")), txt("cpp constructor parameter serialization"));
|
||||
expect(str_contains(constructor_text, txt("option_member( 0 )")), txt("cpp constructor initializer serialization"));
|
||||
expect(str_contains(constructor_text, txt("constructor_option_arg")), txt("cpp constructor body serialization"));
|
||||
}
|
||||
Code destructor_body = untyped_str(txt("release_option_resource();"));
|
||||
CodeSpecifiers destructor_specs = def_specifier(Spec_Virtual);
|
||||
Opts_def_destructor destructor_options = {};
|
||||
destructor_options.body = destructor_body;
|
||||
destructor_options.specifiers = destructor_specs;
|
||||
CodeDestructor option_destructor = def_destructor(destructor_options);
|
||||
expect(option_destructor.ast != nullptr, txt("cpp destructor options"));
|
||||
if (option_destructor.ast != nullptr) {
|
||||
expect(option_destructor->Body.ast == destructor_body.ast, txt("cpp destructor body"));
|
||||
expect(option_destructor->Specs.ast == destructor_specs.ast, txt("cpp destructor specifiers"));
|
||||
CodeBody destructor_class_body = def_class_body(args(option_destructor));
|
||||
CodeClass destructor_class = def_class(name(DestructorOptions), { .body = destructor_class_body });
|
||||
expect(destructor_class.ast != nullptr, txt("cpp destructor serialization parent"));
|
||||
if (destructor_class.ast != nullptr) {
|
||||
Str destructor_text = strbuilder_to_str(code_to_strbuilder((Code)destructor_class));
|
||||
expect(str_contains(destructor_text, txt("virtual ~DestructorOptions()")), txt("cpp destructor signature serialization"));
|
||||
expect(str_contains(destructor_text, txt("release_option_resource();")), txt("cpp destructor body serialization"));
|
||||
}
|
||||
}
|
||||
|
||||
CodeTypename operator_type = def_type(name(OperatorOptionType));
|
||||
CodeTypename operator_return = def_type(name(OperatorOptionReturn));
|
||||
CodeParams operator_lhs = def_param(operator_type, name(operator_option_lhs));
|
||||
CodeParams operator_rhs = def_param(operator_type, name(operator_option_rhs));
|
||||
CodeParams operator_params = def_params(args(operator_lhs, operator_rhs));
|
||||
CodeBody operator_body = def_function_body(args(untyped_str(txt("return operator_option_lhs;"))));
|
||||
Opts_def_operator operator_options = {};
|
||||
operator_options.params = operator_params;
|
||||
operator_options.ret_type = operator_return;
|
||||
operator_options.body = operator_body;
|
||||
operator_options.specifiers = def_specifier(Spec_Inline);
|
||||
operator_options.attributes = def_attributes(txt("[[maybe_unused]]"));
|
||||
operator_options.mflags = ModuleFlag_Export;
|
||||
CodeOperator option_operator = def_operator(Op_Add, txt(""), operator_options);
|
||||
expect(option_operator.ast != nullptr, txt("cpp operator options"));
|
||||
if (option_operator.ast != nullptr) {
|
||||
expect(option_operator->Params.ast == operator_params.ast, txt("cpp operator parameters"));
|
||||
expect(option_operator->ReturnType.ast == operator_return.ast, txt("cpp operator return type"));
|
||||
expect(option_operator->Body.ast == operator_body.ast, txt("cpp operator body"));
|
||||
expect(option_operator->Specs.ast == operator_options.specifiers.ast, txt("cpp operator specifiers"));
|
||||
expect(option_operator->Attributes.ast == operator_options.attributes.ast, txt("cpp operator attributes"));
|
||||
expect(option_operator->ModuleFlags == ModuleFlag_Export, txt("cpp operator module flags"));
|
||||
Str operator_text = strbuilder_to_str(code_to_strbuilder((Code)option_operator));
|
||||
expect(str_contains(operator_text, txt("OperatorOptionReturn")), txt("cpp operator return type serialization"));
|
||||
expect(str_contains(operator_text, txt("operator +")), txt("cpp operator name serialization"));
|
||||
expect(str_contains(operator_text, txt("operator_option_lhs")), txt("cpp operator parameters serialization"));
|
||||
expect(str_contains(operator_text, txt("operator_option_rhs")), txt("cpp operator second parameter serialization"));
|
||||
expect(str_contains(operator_text, txt("return operator_option_lhs")), txt("cpp operator body serialization"));
|
||||
expect(str_contains(operator_text, txt("inline")), txt("cpp operator specifier serialization"));
|
||||
expect(str_contains(operator_text, txt("[[maybe_unused]]")), txt("cpp operator attribute serialization"));
|
||||
expect(str_contains(operator_text, txt("export")), txt("cpp operator module flag serialization"));
|
||||
if (!str_starts_with(operator_text, txt("export [[maybe_unused]] inline\nOperatorOptionReturn"))) log_fmt("%S\n", operator_text);
|
||||
expect(str_starts_with(operator_text, txt("export [[maybe_unused]] inline\nOperatorOptionReturn")), txt("cpp operator one-attribute prefix serialization"));
|
||||
}
|
||||
|
||||
CodeTypename cast_type = def_type(name(s32));
|
||||
CodeBody cast_body = def_function_body(args(untyped_str(txt("return 0;"))));
|
||||
CodeSpecifiers cast_specs = def_specifier(Spec_Const);
|
||||
Opts_def_operator_cast cast_options = {};
|
||||
cast_options.body = cast_body;
|
||||
cast_options.specs = cast_specs;
|
||||
CodeOpCast option_cast = def_operator_cast(cast_type, cast_options);
|
||||
expect(option_cast.ast != nullptr, txt("cpp operator cast options"));
|
||||
if (option_cast.ast != nullptr) {
|
||||
expect(option_cast->ValueType.ast == cast_type.ast, txt("cpp operator cast type"));
|
||||
expect(option_cast->Body.ast == cast_body.ast, txt("cpp operator cast body"));
|
||||
expect(option_cast->Specs.ast == cast_specs.ast, txt("cpp operator cast specifiers"));
|
||||
Str cast_text = strbuilder_to_str(code_to_strbuilder((Code)option_cast));
|
||||
expect(str_contains(cast_text, txt("operator s32")), txt("cpp operator cast serialization"));
|
||||
expect(str_contains(cast_text, txt("const")), txt("cpp operator cast specifier serialization"));
|
||||
expect(str_contains(cast_text, txt("return 0")), txt("cpp operator cast body serialization"));
|
||||
}
|
||||
|
||||
Code untyped = code_str(char const* baseline_message = "GENCPP_BASELINE";); expect(untyped.ast != nullptr, txt("cpp untyped"));
|
||||
Str untyped_text = strbuilder_to_str(code_to_strbuilder(untyped)); expect_fragments(untyped_text, txt("cpp untyped content"));
|
||||
CodeVar parsed_untyped = parse_variable(untyped_text); expect_variable(parsed_untyped, txt("cpp untyped reparsed"));
|
||||
|
||||
CodeVar parsed = parse_variable(code(char const* baseline_message = "GENCPP_BASELINE"; ));
|
||||
expect_variable(parsed, txt("cpp parsed"));
|
||||
expect_fragments(strbuilder_to_str(code_to_strbuilder((Code)parsed)), txt("cpp parsed serialized"));
|
||||
|
||||
#if ! GEN_BUILD_DEBUG
|
||||
CodeVar wrong_array_value = def_variable(def_type(name(u32)), name(invalid_array_expr));
|
||||
Opts_def_type wrong_array_options = {};
|
||||
wrong_array_options.array_expr = (Code)wrong_array_value;
|
||||
CodeTypename invalid_array_type = def_type(name(InvalidArrayOption), wrong_array_options);
|
||||
expect(((Code)invalid_array_type).ast == Code_Invalid.ast, txt("cpp wrong type invalid code"));
|
||||
|
||||
CodeBody missing_union_body = {};
|
||||
CodeUnion missing_union = def_union(name(MissingUnionBody), missing_union_body);
|
||||
expect(((Code)missing_union).ast == Code_Invalid.ast, txt("cpp missing body invalid code"));
|
||||
#endif
|
||||
|
||||
deinit(&ctx);
|
||||
if (g_failures != 0) { log_fmt("cpp baseline smoke failed: %d\n", g_failures); return 1; }
|
||||
log_fmt("cpp baseline smoke passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
#define GEN_TIME
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#include "gen.cpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
global int g_failures = 0;
|
||||
|
||||
internal void expect(int condition, Str label) {
|
||||
if (condition == false) { log_fmt("FAIL %S\n", label); ++g_failures; }
|
||||
}
|
||||
|
||||
internal Str body_text(CodeBody body) {
|
||||
return strbuilder_to_str(code_to_strbuilder(cast(Code, body)));
|
||||
}
|
||||
|
||||
internal b32 body_has_variable(CodeBody body, Str name) { for (Code member : body) {
|
||||
if (member->Type == CT_Variable && member->Name.is_equal(name)) return true;
|
||||
if ((member->Type == CT_Struct || member->Type == CT_Union) && member->Body.ast != nullptr) {
|
||||
if (body_has_variable(cast(CodeBody, member->Body), name))
|
||||
return true;
|
||||
}
|
||||
} return false; }
|
||||
|
||||
internal Str bad_at(Str good) {
|
||||
StrBuilder built = strbuilder_make_reserve(_ctx->Allocator_Temp, good.Len + 2);
|
||||
strbuilder_append_str(& built, good);
|
||||
strbuilder_append_str(& built, txt("\n@"));
|
||||
return strbuilder_to_str(built);
|
||||
}
|
||||
|
||||
internal void expect_context_good(Context* ctx, Str label) {
|
||||
Str def = txt("struct Context\n{\n\tContext* parent;\n};\n\nContext* make_context();\n");
|
||||
CodeBody body = parse_global_body(def);
|
||||
Code found = InvalidCode;
|
||||
for (Code code : body) if (code->Type == CT_Struct && code->Name.is_equal(txt("Context")))
|
||||
found = code;
|
||||
expect(found.ast != nullptr, label); if (found.ast != nullptr) {
|
||||
Code member = InvalidCode;
|
||||
for (Code code : cast(CodeBody, found->Body)) {
|
||||
if (code->Type == CT_Variable && code->Name.is_equal(txt("parent")))
|
||||
member = code;
|
||||
}
|
||||
expect(member.ast != nullptr, label);
|
||||
}
|
||||
expect(ctx->parse_info.messages == nullptr, label);
|
||||
expect(ctx->parse_info.lexed.messages == nullptr, label);
|
||||
}
|
||||
|
||||
internal void expect_context_bad(Str label) {
|
||||
Context ctx = {}; init(& ctx);
|
||||
Str good = txt("struct Context\n{\n\tContext* parent;\n};\n\nContext* make_context();\n");
|
||||
CodeBody body = parse_global_body(bad_at(good));
|
||||
Str text = body_text(body);
|
||||
expect(str_contains(text, txt("Context")), label);
|
||||
expect(str_contains(text, txt("parent")), label);
|
||||
expect(ctx.parse_info.lexed.messages != nullptr, label);
|
||||
if (ctx.parse_info.lexed.messages != nullptr) expect(str_contains(ctx.parse_info.lexed.messages->content, txt("Failed to lex token")), label);
|
||||
expect_context_good(&ctx, txt("context-reuse"));
|
||||
deinit(& ctx);
|
||||
}
|
||||
|
||||
internal Str vec_def() {
|
||||
Str type = txt("Vec2f");
|
||||
Str unit_type = txt("f32");
|
||||
return token_fmt("type", type, "unit_type", unit_type, stringize(
|
||||
struct <type>
|
||||
{
|
||||
union {
|
||||
struct {
|
||||
<unit_type> x;
|
||||
<unit_type> y;
|
||||
};
|
||||
<unit_type> Basis[2];
|
||||
};
|
||||
};
|
||||
));
|
||||
}
|
||||
|
||||
internal void expect_vec_good(Context* ctx, Str label) {
|
||||
Str def = vec_def();
|
||||
expect(str_contains(def, txt("struct Vec2f")), txt("vec-def-struct"));
|
||||
expect(str_contains(def, txt("union")), txt("vec-def-union"));
|
||||
expect(str_contains(def, txt("f32 x;")), txt("vec-def-x"));
|
||||
expect(str_contains(def, txt("f32 y;")), txt("vec-def-y"));
|
||||
expect(str_contains(def, txt("f32 Basis[2]")), txt("vec-def-Basis"));
|
||||
CodeBody body = parse_global_body(def);
|
||||
expect(body_has_variable(body, txt("x")), txt("vec-ast-x"));
|
||||
expect(body_has_variable(body, txt("y")), txt("vec-ast-y"));
|
||||
Str text = body_text(body);
|
||||
expect(str_contains(text, txt("Vec2f")), txt("vec-name"));
|
||||
expect(str_contains(text, txt("x")), txt("vec-x"));
|
||||
expect(str_contains(text, txt("y")), txt("vec-y"));
|
||||
expect(ctx->parse_info.messages == nullptr, txt("vec-parser-messages"));
|
||||
expect(ctx->parse_info.lexed.messages == nullptr, txt("vec-lexer-messages"));
|
||||
}
|
||||
|
||||
internal void expect_vec_bad(Str label) {
|
||||
Context ctx = {}; init(& ctx);
|
||||
CodeBody body = parse_global_body(bad_at(vec_def()));
|
||||
Str text = body_text(body);
|
||||
expect(str_contains(text, txt("Vec2f")), label);
|
||||
expect(ctx.parse_info.lexed.messages != nullptr, label);
|
||||
if (ctx.parse_info.lexed.messages != nullptr) expect(str_contains(ctx.parse_info.lexed.messages->content, txt("Failed to lex token")), label);
|
||||
expect_vec_good(& ctx, txt("vec-reuse"));
|
||||
deinit(& ctx);
|
||||
}
|
||||
|
||||
internal Str unreal_def() { return txt("UCLASS()\nclass UGasaFixture\n{\n\tUPROPERTY()\n\tint Health;\n};\n"); }
|
||||
|
||||
internal void expect_unreal_good(Context* ctx, Str label) {
|
||||
CodeBody body = parse_global_body(unreal_def());
|
||||
Code found = InvalidCode;
|
||||
for (Code code : body) if (code->Type == CT_Class && code->Name.is_equal(txt("UGasaFixture")))
|
||||
found = code;
|
||||
expect(found.ast != nullptr, label); if (found.ast != nullptr) {
|
||||
b32 saw_prop = false;
|
||||
b32 saw_health = false;
|
||||
for (Code member : cast(CodeBody, found->Body)) {
|
||||
if ( member->Type == CT_Untyped && member->Name.starts_with(txt("UPROPERTY"))) saw_prop = true;
|
||||
if (saw_prop && member->Type == CT_Variable && member->Name.is_equal(txt("Health"))) saw_health = true;
|
||||
}
|
||||
expect(saw_prop, label);
|
||||
expect(saw_health, label);
|
||||
}
|
||||
expect(ctx->parse_info.messages == nullptr, label);
|
||||
expect(ctx->parse_info.lexed.messages == nullptr, label);
|
||||
}
|
||||
|
||||
internal void expect_unreal_bad(Str label) {
|
||||
Context ctx = {}; init(& ctx);
|
||||
register_macros(args(
|
||||
(Macro { txt("UCLASS"), MT_Statement, MF_Functional }),
|
||||
(Macro { txt("UPROPERTY"), MT_Statement, MF_Functional })
|
||||
));
|
||||
CodeBody body = parse_global_body(bad_at(unreal_def()));
|
||||
Str text = body_text(body);
|
||||
expect(str_contains(text, txt("UGasaFixture")), label);
|
||||
expect(ctx.parse_info.lexed.messages != nullptr, label);
|
||||
if (ctx.parse_info.lexed.messages != nullptr) expect(str_contains(ctx.parse_info.lexed.messages->content, txt("Failed to lex token")), label);
|
||||
expect_unreal_good(&ctx, txt("unreal-reuse"));
|
||||
deinit(& ctx);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Context ctx = {}; init(& ctx);
|
||||
expect_context_good(&ctx, txt("context"));
|
||||
deinit(& ctx);
|
||||
expect_context_bad(txt("context-at"));
|
||||
|
||||
init(& ctx);
|
||||
expect_vec_good(& ctx, txt("vec"));
|
||||
deinit(& ctx);
|
||||
expect_vec_bad(txt("vec-at"));
|
||||
|
||||
init(& ctx);
|
||||
register_macros(args(
|
||||
(Macro { txt("UCLASS"), MT_Statement, MF_Functional }),
|
||||
(Macro { txt("UPROPERTY"), MT_Statement, MF_Functional })
|
||||
));
|
||||
expect_unreal_good(& ctx, txt("unreal"));
|
||||
deinit(& ctx);
|
||||
expect_unreal_bad(txt("unreal-at"));
|
||||
|
||||
if (g_failures != 0) { log_fmt("dogfood parse fixtures failed: %d\n", g_failures); return 1; }
|
||||
log_fmt("dogfood parse fixtures passed\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
#define GEN_TIME
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#include "gen.cpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
global int g_failures = 0;
|
||||
|
||||
internal void expect(int condition, Str label) {
|
||||
if (condition == false) { log_fmt("FAIL %S\n", label); ++g_failures; }
|
||||
}
|
||||
|
||||
internal void expect_public(Str def, Str needle, Str label) {
|
||||
Context ctx = {}; init(&ctx);
|
||||
CodeVar parsed = parse_variable(def); expect(cast(Code, parsed) == Code_Invalid, label);
|
||||
expect(_ctx->parser.messages != nullptr, label);
|
||||
expect(_ctx->parser.messages->Scope == nullptr, label);
|
||||
expect(_ctx->parser.messages->Content.Ptr != nullptr, label);
|
||||
expect(str_contains(_ctx->parser.messages->Content, needle), label);
|
||||
|
||||
CodeVar again = parse_variable(txt("char const* baseline_message = \"GENCPP_BASELINE\";")); expect(again.ast != nullptr, label);
|
||||
if (again.ast != nullptr) {
|
||||
expect(again->Type == CT_Variable, label);
|
||||
expect(str_contains(again->Name, txt("baseline_message")), label);
|
||||
}
|
||||
deinit(&ctx);
|
||||
}
|
||||
|
||||
internal void expect_lex_fail(Str def, Str needle, Str label) {
|
||||
Context ctx = {}; init(&ctx);
|
||||
LexedInfo lexed = lex(&ctx, def);
|
||||
expect(lexed.tokens.ptr != nullptr, label);
|
||||
expect(lexed.messages != nullptr, label);
|
||||
if (lexed.messages != nullptr) expect(str_contains(lexed.messages->content, needle), label);
|
||||
deinit(&ctx);
|
||||
}
|
||||
|
||||
internal void expect_lex_ok(Str def, Str label) {
|
||||
Context ctx = {}; init(&ctx);
|
||||
LexedInfo lexed = lex(&ctx, def);
|
||||
expect(lexed.tokens.ptr != nullptr, label);
|
||||
expect(lexed.tokens.num > 0, label);
|
||||
expect(lexed.messages == nullptr, label);
|
||||
deinit(&ctx);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
expect_public(txt("#define FOO(... x)"), txt("Expected a ')' after '...'"), txt("L01-public"));
|
||||
expect_public(txt("#define FOO(1)"), txt("Expected a '_' or alpha character"), txt("L02-public"));
|
||||
expect_public(txt("#define FOO(a b)"), txt("Expected a comma after parameter"), txt("L03-public"));
|
||||
expect_public(txt("#define FOO(a,"), txt("Expected a ')' after last_parameter"), txt("L04-public"));
|
||||
expect_public(txt("#foo \\q"), txt("in preprocessor directive ("), txt("L05-public"));
|
||||
expect_public(txt("#include foo"), txt("after #include"), txt("L06-public"));
|
||||
expect_public(txt("#pragma \\q"), txt("in preprocessor directive '"), txt("L07-public"));
|
||||
expect_public(txt("..x"), txt("invalid varadic argument"), txt("L08-public"));
|
||||
expect_public(txt("@"), txt("Failed to lex token"), txt("L09-public"));
|
||||
|
||||
expect_lex_fail(txt("#define FOO(... x)"), txt("Expected a ')' after '...'"), txt("L01-lex"));
|
||||
expect_lex_fail(txt("#define FOO(1)"), txt("Expected a '_' or alpha character"), txt("L02-lex"));
|
||||
expect_lex_fail(txt("#define FOO(a b)"), txt("Expected a comma after parameter"), txt("L03-lex"));
|
||||
expect_lex_fail(txt("#define FOO(a,"), txt("Expected a ')' after last_parameter"), txt("L04-lex"));
|
||||
expect_lex_fail(txt("#foo \\q"), txt("in preprocessor directive ("), txt("L05-lex"));
|
||||
expect_lex_fail(txt("#include foo"), txt("after #include"), txt("L06-lex"));
|
||||
expect_lex_fail(txt("#pragma \\q"), txt("in preprocessor directive '"), txt("L07-lex"));
|
||||
expect_lex_fail(txt("..x"), txt("invalid varadic argument"), txt("L08-lex"));
|
||||
expect_lex_fail(txt("@"), txt("Failed to lex token"), txt("L09-lex"));
|
||||
|
||||
expect_lex_ok(txt("#define FOO(a, b) a"), txt("S01"));
|
||||
expect_lex_ok(txt("#define FOO(...)"), txt("S02"));
|
||||
expect_lex_ok(txt("#include \"a.h\""), txt("S03"));
|
||||
expect_lex_ok(txt("#pragma once"), txt("S04"));
|
||||
expect_lex_ok(txt("#foo bar"), txt("S05"));
|
||||
expect_lex_ok(txt("..."), txt("S06"));
|
||||
|
||||
if (g_failures != 0) { log_fmt("lexer failures failed: %d\n", g_failures); return 1; }
|
||||
log_fmt("lexer failures passed\n");
|
||||
return 0;
|
||||
}
|
||||
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user