borken : lots of stuff changed, explaining in later commit...v

This commit is contained in:
Edward R. Gonzalez 2024-12-07 00:21:09 -05:00
parent ceea184d5a
commit 4d638a7255
46 changed files with 3352 additions and 2570 deletions

View File

@ -1,9 +1,9 @@
{ {
"configurations": [ "configurations": [
{ {
"name": "Win32 msvc", "name": "Bootstrap",
"includePath": [ "includePath": [
"${workspaceFolder}/**" "${workspaceFolder}/project/**"
], ],
"defines": [ "defines": [
"_DEBUG", "_DEBUG",
@ -15,10 +15,39 @@
"GEN_INTELLISENSE_DIRECTIVES", "GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES" "INTELLISENSE_DIRECTIVES"
], ],
"cStandard": "c11",
"cppStandard": "c++17",
"windowsSdkVersion": "10.0.19041.0", "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", "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
"intelliSenseMode": "msvc-x64", "intelliSenseMode": "msvc-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json" "compileCommands": "C:\\projects\\gencpp\\.vscode\\tasks.json",
"compilerArgs": [
"/EHsc-",
"/GR-",
"/Zc:preprocessor",
"/FC"
]
},
{
"name": "Win32 msvc c_library",
"includePath": [
"${workspaceFolder}/gen_c_library/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"GEN_TIME",
"GEN_IMPLEMENTATION",
// "GEN_DONT_USE_NAMESPACE"
"GEN_INTELLISENSE_DIRECTIVES",
"INTELLISENSE_DIRECTIVES"
],
"cppStandard": "c++17",
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe",
"intelliSenseMode": "msvc-x64",
"compileCommands": "C:\\projects\\gencpp\\.vscode\\tasks.json"
}, },
{ {
"name": "Win32 clang", "name": "Win32 clang",
@ -38,7 +67,7 @@
"windowsSdkVersion": "10.0.19041.0", "windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe", "compilerPath": "C:/Users/Ed/scoop/apps/llvm/current/bin/clang++.exe",
"intelliSenseMode": "windows-clang-x64", "intelliSenseMode": "windows-clang-x64",
"compileCommands": "${workspaceFolder}/project/build/compile_commands.json" "compileCommands": ".vscode/tasks.json"
} }
], ],
"version": 4 "version": 4

View File

@ -67,8 +67,10 @@
"C_Cpp.files.exclude": { "C_Cpp.files.exclude": {
"**/.vscode": true, "**/.vscode": true,
"**/.vs": true, "**/.vs": true,
"**/sanity.gen.hpp": true "**/sanity.gen.hpp": true,
"test/**":true,
}, },
"autoHide.autoHidePanel": false, "autoHide.autoHidePanel": false,
"autoHide.autoHideSideBar": false "autoHide.autoHideSideBar": false,
"dimmer.enabled": true
} }

144
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,144 @@
{
"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
}
}
]
}

View File

@ -1,9 +1,9 @@
# gencpp # gencpp
An attempt at simple staged metaprogramming for c/c++. An attempt at simple staged metaprogramming for C/C++.
The library API is a composition of code element constructors. The library API is a composition of code element constructors, and a non-standards-compliant single-pass C/C++ parser.
These build up a code AST to then serialize with a file builder. These build up a code AST to then serialize with a file builder, or can be traversed for staged-reflection of C/C++ code.
This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto). This code base attempts follow the [handmade philosophy](https://handmade.network/manifesto).
Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain. Its not meant to be a black box metaprogramming utility, it should be easy to intergrate into a user's project domain.
@ -31,7 +31,7 @@ A metaprogram is built to generate files before the main program is built. We'll
`gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated. `gen.cpp` \`s `main()` is defined as `gen_main()` which the user will have to define once for their program. There they will dictate everything that should be generated.
In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't required at all): In order to keep the locality of this code within the same files the following pattern may be used (although this pattern isn't the best to use):
Within `program.cpp` : Within `program.cpp` :
@ -54,7 +54,6 @@ u32 gen_main()
// Regular runtime dependent on the generated code here. // Regular runtime dependent on the generated code here.
#endif #endif
``` ```
The design uses a constructive builder API for the code to generate. The design uses a constructive builder API for the code to generate.

1146
gen_c_library/Test.jsonc Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,6 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
#define GEN_SUPPORT_CPP_REFERENCES 1
#include "../project/gen.cpp" #include "../project/gen.cpp"
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"
@ -97,6 +95,8 @@ CodeBody parse_file( const char* path )
return code; return code;
} }
constexpr bool helper_use_c_definition = true;
int gen_main() int gen_main()
{ {
#define project_dir "../project/" #define project_dir "../project/"
@ -138,7 +138,7 @@ int gen_main()
if (using_ver->UnderlyingType->ReturnType) if (using_ver->UnderlyingType->ReturnType)
{ {
CodeTypename type = using_ver->UnderlyingType; CodeTypename type = using_ver->UnderlyingType;
CodeTypedef typedef_ver = parse_typedef(token_fmt( CodeTypedef typedef_ver = parse_typedef(token_fmt(
"ReturnType", to_string(type->ReturnType).to_strc() "ReturnType", to_string(type->ReturnType).to_strc()
, "Name" , using_ver->Name , "Name" , using_ver->Name
, "Parameters", to_string(type->Params).to_strc() , "Parameters", to_string(type->Params).to_strc()
@ -170,10 +170,12 @@ int gen_main()
Code inlines = scan_file( project_dir "components/inlines.hpp" ); Code inlines = scan_file( project_dir "components/inlines.hpp" );
Code header_end = scan_file( project_dir "components/header_end.hpp" ); Code header_end = scan_file( project_dir "components/header_end.hpp" );
CodeBody ecode = gen_ecode ( project_dir "enums/ECode.csv" ); CodeBody ecode = gen_ecode ( project_dir "enums/ECode.csv", helper_use_c_definition );
CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" ); CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition );
CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" ); CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition );
CodeBody ast_inlines = gen_ast_inlines();
// Only has operator overload definitions that C doesn't need.
// CodeBody ast_inlines = gen_ast_inlines();
CodeBody parsed_ast = parse_file( project_dir "components/ast.hpp" ); CodeBody parsed_ast = parse_file( project_dir "components/ast.hpp" );
CodeBody ast = def_body(CT_Global_Body); CodeBody ast = def_body(CT_Global_Body);
@ -185,7 +187,7 @@ int gen_main()
CodePreprocessCond cond = cast(CodePreprocessCond, entry); CodePreprocessCond cond = cast(CodePreprocessCond, entry);
if (cond->Content.contains(txt("GEN_COMPILER_C"))) if (cond->Content.contains(txt("GEN_COMPILER_C")))
{ {
//++ entry; // //++ entry; //
//ast.append(entry) // typedef //ast.append(entry) // typedef
//for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_EndIf; ++ entry) {} //for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_EndIf; ++ entry) {}
//++ entry; // Consume endif //++ entry; // Consume endif
@ -292,15 +294,13 @@ R"(#define AST_ArrSpecs_Cap \
case CT_Function: case CT_Function:
{ {
CodeFn fn = cast(CodeFn, entry); CodeFn fn = cast(CodeFn, entry);
s32 constexpr_found = fn->Specs.remove( Spec_Constexpr ); if (fn->Specs) {
if (constexpr_found > -1) { s32 constexpr_found = fn->Specs.remove( Spec_Constexpr );
log_fmt("Found constexpr: %S\n", entry.to_string()); if (constexpr_found > -1) {
fn->Specs.append(Spec_Inline); log_fmt("Found constexpr: %S\n", entry.to_string());
fn->Specs.append(Spec_Inline);
}
} }
// for ( StrC id : to_rename ) if (fn->Name.is_equal(id)) {
// Array(CodeFn) list = * needs_selectors.get(id);
// list.append(rename_function_to_unique_symbol(fn));
// }
memory.append(fn); memory.append(fn);
} }
break; break;

View File

@ -1,8 +1,6 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
#define GEN_SUPPORT_CPP_REFERENCES 0
#include "gen.cpp" #include "gen.cpp"
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"

View File

@ -1,8 +1,7 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS #define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES #define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND #define GEN_EXPOSE_BACKEND
#define GEN_SUPPORT_CPP_MEMBER_FEATURES 0 #define GEN_C_LIKE_CPP 1
#define GEN_SUPPORT_CPP_REFERENCES 0
#include "gen.cpp" #include "gen.cpp"
#include "helpers/push_ignores.inline.hpp" #include "helpers/push_ignores.inline.hpp"

View File

@ -362,7 +362,9 @@ Code code_duplicate(Code self)
{ {
Code result = make_code(); Code result = make_code();
mem_copy( result.ast, self.ast, sizeof( AST ) ); void* mem_result = rcast(void*, cast(AST*, result));
void* mem_self = rcast(void*, cast(AST*, self));
mem_copy( mem_result, mem_self, sizeof( AST ) );
result->Parent = { nullptr }; result->Parent = { nullptr };
return result; return result;
@ -409,173 +411,173 @@ void code_to_string_ptr( Code self, String* result )
break; break;
case CT_Class: case CT_Class:
to_string_def(cast(CodeClass, self), result ); class_to_string_def(cast(CodeClass, self), result );
break; break;
case CT_Class_Fwd: case CT_Class_Fwd:
to_string_fwd(cast(CodeClass, self), result ); class_to_string_fwd(cast(CodeClass, self), result );
break; break;
case CT_Constructor: case CT_Constructor:
to_string_def(cast(CodeConstructor, self), result ); constructor_to_string_def(cast(CodeConstructor, self), result );
break; break;
case CT_Constructor_Fwd: case CT_Constructor_Fwd:
to_string_fwd(cast(CodeConstructor, self), result ); constructor_to_string_fwd(cast(CodeConstructor, self), result );
break; break;
case CT_Destructor: case CT_Destructor:
to_string_def(cast(CodeDestructor, self), result ); destructor_to_string_def(cast(CodeDestructor, self), result );
break; break;
case CT_Destructor_Fwd: case CT_Destructor_Fwd:
to_string_fwd(cast(CodeDestructor, self), result ); destructor_to_string_fwd(cast(CodeDestructor, self), result );
break; break;
case CT_Enum: case CT_Enum:
to_string_def(cast(CodeEnum, self), result ); enum_to_string_def(cast(CodeEnum, self), result );
break; break;
case CT_Enum_Fwd: case CT_Enum_Fwd:
to_string_fwd(cast(CodeEnum, self), result ); enum_to_string_fwd(cast(CodeEnum, self), result );
break; break;
case CT_Enum_Class: case CT_Enum_Class:
to_string_class_def(cast(CodeEnum, self), result ); enum_to_string_class_def(cast(CodeEnum, self), result );
break; break;
case CT_Enum_Class_Fwd: case CT_Enum_Class_Fwd:
to_string_class_fwd(cast(CodeEnum, self), result ); enum_to_string_class_fwd(cast(CodeEnum, self), result );
break; break;
case CT_Export_Body: case CT_Export_Body:
to_string_export(cast(CodeBody, self), result ); body_to_string_export(cast(CodeBody, self), result );
break; break;
case CT_Extern_Linkage: case CT_Extern_Linkage:
to_string(cast(CodeExtern, self), result ); extern_to_string(cast(CodeExtern, self), result );
break; break;
case CT_Friend: case CT_Friend:
to_string(cast(CodeFriend, self), result ); friend_to_string_ref(cast(CodeFriend, self), result );
break; break;
case CT_Function: case CT_Function:
to_string_def(cast(CodeFn, self), result ); fn_to_string_def(cast(CodeFn, self), result );
break; break;
case CT_Function_Fwd: case CT_Function_Fwd:
to_string_fwd(cast(CodeFn, self), result ); fn_to_string_fwd(cast(CodeFn, self), result );
break; break;
case CT_Module: case CT_Module:
to_string(cast(CodeModule, self), result ); module_to_string_ref(cast(CodeModule, self), result );
break; break;
case CT_Namespace: case CT_Namespace:
to_string(cast(CodeNS, self), result ); namespace_to_string_ref(cast(CodeNS, self), result );
break; break;
case CT_Operator: case CT_Operator:
case CT_Operator_Member: case CT_Operator_Member:
to_string_def(cast(CodeOperator, self), result ); code_op_to_string_def(cast(CodeOperator, self), result );
break; break;
case CT_Operator_Fwd: case CT_Operator_Fwd:
case CT_Operator_Member_Fwd: case CT_Operator_Member_Fwd:
to_string_fwd(cast(CodeOperator, self), result ); code_op_to_string_fwd(cast(CodeOperator, self), result );
break; break;
case CT_Operator_Cast: case CT_Operator_Cast:
to_string_def(cast(CodeOpCast, self), result ); opcast_to_string_def(cast(CodeOpCast, self), result );
break; break;
case CT_Operator_Cast_Fwd: case CT_Operator_Cast_Fwd:
to_string_fwd(cast(CodeOpCast, self), result ); opcast_to_string_fwd(cast(CodeOpCast, self), result );
break; break;
case CT_Parameters: case CT_Parameters:
to_string(cast(CodeParam, self), result ); params_to_string_ref(cast(CodeParam, self), result );
break; break;
case CT_Preprocess_Define: case CT_Preprocess_Define:
to_string(cast(CodeDefine, self), result ); define_to_string_ref(cast(CodeDefine, self), result );
break; break;
case CT_Preprocess_If: case CT_Preprocess_If:
to_string_if(cast(CodePreprocessCond, self), result ); preprocess_to_string_if(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_IfDef: case CT_Preprocess_IfDef:
to_string_ifdef(cast(CodePreprocessCond, self), result ); preprocess_to_string_ifdef(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_IfNotDef: case CT_Preprocess_IfNotDef:
to_string_ifndef(cast(CodePreprocessCond, self), result ); preprocess_to_string_ifndef(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_Include: case CT_Preprocess_Include:
to_string(cast(CodeInclude, self), result ); include_to_string_ref(cast(CodeInclude, self), result );
break; break;
case CT_Preprocess_ElIf: case CT_Preprocess_ElIf:
to_string_elif(cast(CodePreprocessCond, self), result ); preprocess_to_string_elif(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_Else: case CT_Preprocess_Else:
to_string_else(cast(CodePreprocessCond, self), result ); preprocess_to_string_else(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_EndIf: case CT_Preprocess_EndIf:
to_string_endif(cast(CodePreprocessCond, self), result ); preprocess_to_string_endif(cast(CodePreprocessCond, self), result );
break; break;
case CT_Preprocess_Pragma: case CT_Preprocess_Pragma:
to_string(cast(CodePragma, self), result ); pragma_to_string_ref(cast(CodePragma, self), result );
break; break;
case CT_Specifiers: case CT_Specifiers:
to_string(cast(CodeSpecifiers, self), result ); specifiers_to_string_ref(cast(CodeSpecifiers, self), result );
break; break;
case CT_Struct: case CT_Struct:
to_string_def(cast(CodeStruct, self), result ); struct_to_string_def(cast(CodeStruct, self), result );
break; break;
case CT_Struct_Fwd: case CT_Struct_Fwd:
to_string_fwd(cast(CodeStruct, self), result ); struct_to_string_fwd(cast(CodeStruct, self), result );
break; break;
case CT_Template: case CT_Template:
to_string(cast(CodeTemplate, self), result ); template_to_string_ref(cast(CodeTemplate, self), result );
break; break;
case CT_Typedef: case CT_Typedef:
to_string(cast(CodeTypedef, self), result ); typedef_to_string_ref(cast(CodeTypedef, self), result );
break; break;
case CT_Typename: case CT_Typename:
to_string(cast(CodeTypename, self), result ); typename_to_string_ref(cast(CodeTypename, self), result );
break; break;
case CT_Union: case CT_Union:
to_string_def( cast(CodeUnion, self), result ); union_to_string_def( cast(CodeUnion, self), result );
break; break;
case CT_Union_Fwd: case CT_Union_Fwd:
to_string_fwd( cast(CodeUnion, self), result ); union_to_string_fwd( cast(CodeUnion, self), result );
break; break;
case CT_Using: case CT_Using:
to_string(cast(CodeUsing, self), result ); using_to_string_ref(cast(CodeUsing, self), result );
break; break;
case CT_Using_Namespace: case CT_Using_Namespace:
to_string_ns(cast(CodeUsing, self), result ); using_to_string_ns(cast(CodeUsing, self), result );
break; break;
case CT_Variable: case CT_Variable:
to_string(cast(CodeVar, self), result ); var_to_string_ref(cast(CodeVar, self), result );
break; break;
case CT_Enum_Body: case CT_Enum_Body:
@ -586,7 +588,7 @@ void code_to_string_ptr( Code self, String* result )
case CT_Namespace_Body: case CT_Namespace_Body:
case CT_Struct_Body: case CT_Struct_Body:
case CT_Union_Body: case CT_Union_Body:
to_string( cast(CodeBody, self), result ); body_to_string_ref( cast(CodeBody, self), result );
break; break;
} }
} }
@ -1159,20 +1161,20 @@ bool code_is_equal( Code self, Code other )
bool code_validate_body(Code self) bool code_validate_body(Code self)
{ {
#define CheckEntries( Unallowed_Types ) \ #define CheckEntries( Unallowed_Types ) \
do \ do \
{ \ { \
CodeBody body = cast(CodeBody, self); \ CodeBody body = cast(CodeBody, self); \
for ( Code code_entry = begin(body); code_entry != end(body); next(body, code_entry) ) \ for ( Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry) ) \
{ \ { \
switch ( code_entry->Type ) \ switch ( code_entry->Type ) \
{ \ { \
Unallowed_Types \ Unallowed_Types \
log_failure( "AST::validate_body: Invalid entry in body %s", code_debug_str(code_entry) ); \ log_failure( "AST::validate_body: Invalid entry in body %s", code_debug_str(code_entry) ); \
return false; \ return false; \
} \ } \
} \ } \
} \ } \
while (0); while (0);
switch ( self->Type ) switch ( self->Type )
@ -1185,7 +1187,7 @@ bool code_validate_body(Code self)
case CT_Enum_Body: case CT_Enum_Body:
{ {
CodeBody body = cast(CodeBody, self); CodeBody body = cast(CodeBody, self);
for ( Code entry = begin(body); entry != end(body); next(body, entry) ) for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
{ {
if ( entry->Type != CT_Untyped ) if ( entry->Type != CT_Untyped )
{ {
@ -1213,7 +1215,7 @@ bool code_validate_body(Code self)
case CT_Global_Body: case CT_Global_Body:
{ {
CodeBody body = cast(CodeBody, self); CodeBody body = cast(CodeBody, self);
for ( Code entry = begin(body); entry != end(body); next(body, entry) ) for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
{ {
switch (entry->Type) switch (entry->Type)
{ {
@ -1253,7 +1255,7 @@ bool code_validate_body(Code self)
case CT_Union_Body: case CT_Union_Body:
{ {
CodeBody body = cast(CodeBody, self); CodeBody body = cast(CodeBody, self);
for ( Code entry = begin(body); entry != end(body); next(body, entry) ) for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )
{ {
if ( entry->Type != CT_Untyped ) if ( entry->Type != CT_Untyped )
{ {

View File

@ -6,8 +6,6 @@
#include "gen/especifier.hpp" #include "gen/especifier.hpp"
#endif #endif
GEN_API_C_BEGIN
struct AST; struct AST;
struct AST_Body; struct AST_Body;
struct AST_Attributes; struct AST_Attributes;
@ -158,17 +156,20 @@ GEN_NS_PARSER_BEGIN
struct Token; struct Token;
GEN_NS_PARSER_END GEN_NS_PARSER_END
#define Token_Typedef struct Token Token
typedef Token_Typedef;
#undef Token_Typedef
#if GEN_COMPILER_CPP #if GEN_COMPILER_CPP
GEN_API_C_END // Note(Ed): This is to alleviate an edge case with parsing usings or typedefs where I don't really have it setup
template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); } // to parse a 'namespace' macro or a type with a macro.
GEN_API_C_BEGIN // I have ideas for ways to pack that into the typedef/using ast, but for now just keeping it like this
#define ParserTokenType GEN_NS_PARSER Token
typedef ParserTokenType Token;
#undef ParserTokenType
#endif #endif
#pragma region Code Interface #if GEN_COMPILER_CPP
template< class Type> forceinline Type tmpl_cast( Code self ) { return * rcast( Type*, & self ); }
#endif
#pragma region Code C-Interface
void code_append (Code code, Code other ); void code_append (Code code, Code other );
char const* code_debug_str (Code code); char const* code_debug_str (Code code);
Code code_duplicate (Code code); Code code_duplicate (Code code);
@ -182,10 +183,9 @@ String code_to_string (Code self );
void code_to_string_ptr(Code self, String* result ); void code_to_string_ptr(Code self, String* result );
char const* code_type_str (Code self ); char const* code_type_str (Code self );
bool code_validate_body(Code self ); bool code_validate_body(Code self );
#pragma endregion Code Interface #pragma endregion Code C-Interface
#if GEN_COMPILER_CPP #if GEN_COMPILER_CPP
GEN_API_C_END
/* /*
AST* wrapper AST* wrapper
- Not constantly have to append the '*' as this is written often.. - Not constantly have to append the '*' as this is written often..
@ -195,34 +195,36 @@ struct Code
{ {
AST* ast; AST* ast;
# define Using_Code( Typename ) \ # define Using_Code( Typename ) \
char const* debug_str() { return code_debug_str(* this); } \ forceinline char const* debug_str() { return code_debug_str(* this); } \
Code duplicate() { return code_duplicate(* this); } \ forceinline Code duplicate() { return code_duplicate(* this); } \
bool is_equal( Code other ) { return code_is_equal(* this, other); } \ forceinline bool is_equal( Code other ) { return code_is_equal(* this, other); } \
bool is_body() { return code_is_body(* this); } \ forceinline bool is_body() { return code_is_body(* this); } \
bool is_valid() { return code_is_valid(* this); } \ forceinline bool is_valid() { return code_is_valid(* this); } \
void set_global() { return code_set_global(* this); } forceinline void set_global() { return code_set_global(* this); }
# define Using_CodeOps( Typename ) \ # define Using_CodeOps( Typename ) \
Typename& operator = ( Code other ); \ forceinline Typename& operator = ( Code other ); \
bool operator ==( Code other ) { return (AST*)ast == other.ast; } \ forceinline bool operator ==( Code other ) { return (AST*)ast == other.ast; } \
bool operator !=( Code other ) { return (AST*)ast != other.ast; } \ forceinline bool operator !=( Code other ) { return (AST*)ast != other.ast; } \
forceinline bool operator ==(std::nullptr_t) const { return ast == nullptr; } \
forceinline bool operator !=(std::nullptr_t) const { return ast != nullptr; } \
operator bool(); operator bool();
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if ! GEN_C_LIKE_CPP
Using_Code( Code ); Using_Code( Code );
void append(Code other) { return code_append(* this, other); } forceinline void append(Code other) { return code_append(* this, other); }
Code* entry(u32 idx) { return code_entry(* this, idx); } forceinline Code* entry(u32 idx) { return code_entry(* this, idx); }
bool has_entries() { return code_has_entries(* this); } forceinline bool has_entries() { return code_has_entries(* this); }
String to_string() { return code_to_string(* this); } forceinline String to_string() { return code_to_string(* this); }
void to_string(String& result) { return code_to_string_ptr(* this, & result); } forceinline void to_string(String& result) { return code_to_string_ptr(* this, & result); }
char const* type_str() { return code_type_str(* this); } forceinline char const* type_str() { return code_type_str(* this); }
bool validate_body() { return code_validate_body(*this); } forceinline bool validate_body() { return code_validate_body(*this); }
#endif #endif
Using_CodeOps( Code ); Using_CodeOps( Code );
forceinline AST* operator ->() { return ast; }
AST* operator ->() { return ast; }
Code& operator ++(); Code& operator ++();
// TODO(Ed) : Remove this overload. // TODO(Ed) : Remove this overload.
@ -237,11 +239,6 @@ struct Code
return *this; return *this;
} }
bool operator==(std::nullptr_t) const { return ast == nullptr; }
bool operator!=(std::nullptr_t) const { return ast != nullptr; }
friend bool operator==(std::nullptr_t, const Code code) { return code.ast == nullptr; }
friend bool operator!=(std::nullptr_t, const Code code) { return code.ast != nullptr; }
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES #ifdef GEN_ENFORCE_STRONG_CODE_TYPES
# define operator explicit operator # define operator explicit operator
#endif #endif
@ -276,7 +273,6 @@ struct Code
operator CodeVar() const; operator CodeVar() const;
#undef operator #undef operator
}; };
GEN_API_C_BEGIN
#endif #endif
#pragma region Statics #pragma region Statics
@ -287,7 +283,6 @@ extern Code Code_Global;
extern Code Code_Invalid; extern Code Code_Invalid;
#pragma endregion Statics #pragma endregion Statics
typedef struct Code_POD Code_POD;
struct Code_POD struct Code_POD
{ {
AST* ast; AST* ast;
@ -362,7 +357,7 @@ struct AST
Code Next; Code Next;
Code Back; Code Back;
}; };
Token* Token; // Reference to starting token, only avaialble if it was derived from parsing. Token* Token; // Reference to starting token, only avaialble if it was derived from parsing.
Code Parent; Code Parent;
StringCached Name; StringCached Name;
CodeType Type; CodeType Type;
@ -385,10 +380,12 @@ static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST POD is not size of AST_P
struct InvalidCode_ImplictCaster; struct InvalidCode_ImplictCaster;
#define InvalidCode (InvalidCode_ImplictCaster{}) #define InvalidCode (InvalidCode_ImplictCaster{})
#else #else
#define InvalidCode Code_Invalid #define InvalidCode { (AST*)Code_Invalid }
#endif #endif
#if GEN_COMPILER_CPP
// Used when the its desired when omission is allowed in a definition. // Used when the its desired when omission is allowed in a definition.
#define NullCode { nullptr } #define NullCode { nullptr }
#else
GEN_API_C_END #define NullCode nullptr
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,139 +1,79 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #include "components/types.hpp" #pragma once
#include "components/types.hpp"
#endif #endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
enum CodeType_Def enum_underlying( u32 ) enum CodeType : u32
{ CT_Invalid,
CT_Untyped,
CT_NewLine,
CT_Comment,
CT_Access_Private,
CT_Access_Protected,
CT_Access_Public,
CT_PlatformAttributes,
CT_Class,
CT_Class_Fwd,
CT_Class_Body,
CT_Constructor,
CT_Constructor_Fwd,
CT_Destructor,
CT_Destructor_Fwd,
CT_Enum,
CT_Enum_Fwd,
CT_Enum_Body,
CT_Enum_Class,
CT_Enum_Class_Fwd,
CT_Execution,
CT_Export_Body,
CT_Extern_Linkage,
CT_Extern_Linkage_Body,
CT_Friend,
CT_Function,
CT_Function_Fwd,
CT_Function_Body,
CT_Global_Body,
CT_Module,
CT_Namespace,
CT_Namespace_Body,
CT_Operator,
CT_Operator_Fwd,
CT_Operator_Member,
CT_Operator_Member_Fwd,
CT_Operator_Cast,
CT_Operator_Cast_Fwd,
CT_Parameters,
CT_Preprocess_Define,
CT_Preprocess_Include,
CT_Preprocess_If,
CT_Preprocess_IfDef,
CT_Preprocess_IfNotDef,
CT_Preprocess_ElIf,
CT_Preprocess_Else,
CT_Preprocess_EndIf,
CT_Preprocess_Pragma,
CT_Specifiers,
CT_Struct,
CT_Struct_Fwd,
CT_Struct_Body,
CT_Template,
CT_Typedef,
CT_Typename,
CT_Union,
CT_Union_Fwd,
CT_Union_Body,
CT_Using,
CT_Using_Namespace,
CT_Variable,
CT_NumTypes };
typedef enum CodeType_Def CodeType;
inline StrC codetype_to_str( CodeType type )
{ {
local_persist StrC lookup[61] = { CT_Invalid,CT_Untyped,CT_NewLine,CT_Comment,CT_Access_Private,CT_Access_Protected,CT_Access_Public,CT_PlatformAttributes,CT_Class,CT_Class_Fwd,CT_Class_Body,CT_Constructor,CT_Constructor_Fwd,CT_Destructor,CT_Destructor_Fwd,CT_Enum,CT_Enum_Fwd,CT_Enum_Body,CT_Enum_Class,CT_Enum_Class_Fwd,CT_Execution,CT_Export_Body,CT_Extern_Linkage,CT_Extern_Linkage_Body,CT_Friend,CT_Function,CT_Function_Fwd,CT_Function_Body,CT_Global_Body,CT_Module,CT_Namespace,CT_Namespace_Body,CT_Operator,CT_Operator_Fwd,CT_Operator_Member,CT_Operator_Member_Fwd,CT_Operator_Cast,CT_Operator_Cast_Fwd,CT_Parameters,CT_Preprocess_Define,CT_Preprocess_Include,CT_Preprocess_If,CT_Preprocess_IfDef,CT_Preprocess_IfNotDef,CT_Preprocess_ElIf,CT_Preprocess_Else,CT_Preprocess_EndIf,CT_Preprocess_Pragma,CT_Specifiers,CT_Struct,CT_Struct_Fwd,CT_Struct_Body,CT_Template,CT_Typedef,CT_Typename,CT_Union,CT_Union_Fwd,CT_Union_Body,CT_Using,CT_Using_Namespace,CT_Variable,CT_NumTypes
{ sizeof( "Invalid" ), "Invalid" }, };
{ sizeof( "Untyped" ), "Untyped" }, typedef enum CodeType CodeType;
{ sizeof( "NewLine" ), "NewLine" }, inline
{ sizeof( "Comment" ), "Comment" }, StrC codetype_to_str( CodeType type)
{ sizeof( "Access_Private" ), "Access_Private" }, {
{ sizeof( "Access_Protected" ), "Access_Protected" }, local_persist StrC lookup[61] = { { sizeof("Invalid"), "Invalid" },
{ sizeof( "Access_Public" ), "Access_Public" }, { sizeof("Untyped"), "Untyped" },
{ sizeof( "PlatformAttributes" ), "PlatformAttributes" }, { sizeof("NewLine"), "NewLine" },
{ sizeof( "Class" ), "Class" }, { sizeof("Comment"), "Comment" },
{ sizeof( "Class_Fwd" ), "Class_Fwd" }, { sizeof("Access_Private"), "Access_Private" },
{ sizeof( "Class_Body" ), "Class_Body" }, { sizeof("Access_Protected"), "Access_Protected" },
{ sizeof( "Constructor" ), "Constructor" }, { sizeof("Access_Public"), "Access_Public" },
{ sizeof( "Constructor_Fwd" ), "Constructor_Fwd" }, { sizeof("PlatformAttributes"), "PlatformAttributes" },
{ sizeof( "Destructor" ), "Destructor" }, { sizeof("Class"), "Class" },
{ sizeof( "Destructor_Fwd" ), "Destructor_Fwd" }, { sizeof("Class_Fwd"), "Class_Fwd" },
{ sizeof( "Enum" ), "Enum" }, { sizeof("Class_Body"), "Class_Body" },
{ sizeof( "Enum_Fwd" ), "Enum_Fwd" }, { sizeof("Constructor"), "Constructor" },
{ sizeof( "Enum_Body" ), "Enum_Body" }, { sizeof("Constructor_Fwd"), "Constructor_Fwd" },
{ sizeof( "Enum_Class" ), "Enum_Class" }, { sizeof("Destructor"), "Destructor" },
{ sizeof( "Enum_Class_Fwd" ), "Enum_Class_Fwd" }, { sizeof("Destructor_Fwd"), "Destructor_Fwd" },
{ sizeof( "Execution" ), "Execution" }, { sizeof("Enum"), "Enum" },
{ sizeof( "Export_Body" ), "Export_Body" }, { sizeof("Enum_Fwd"), "Enum_Fwd" },
{ sizeof( "Extern_Linkage" ), "Extern_Linkage" }, { sizeof("Enum_Body"), "Enum_Body" },
{ sizeof( "Extern_Linkage_Body" ), "Extern_Linkage_Body" }, { sizeof("Enum_Class"), "Enum_Class" },
{ sizeof( "Friend" ), "Friend" }, { sizeof("Enum_Class_Fwd"), "Enum_Class_Fwd" },
{ sizeof( "Function" ), "Function" }, { sizeof("Execution"), "Execution" },
{ sizeof( "Function_Fwd" ), "Function_Fwd" }, { sizeof("Export_Body"), "Export_Body" },
{ sizeof( "Function_Body" ), "Function_Body" }, { sizeof("Extern_Linkage"), "Extern_Linkage" },
{ sizeof( "Global_Body" ), "Global_Body" }, { sizeof("Extern_Linkage_Body"), "Extern_Linkage_Body" },
{ sizeof( "Module" ), "Module" }, { sizeof("Friend"), "Friend" },
{ sizeof( "Namespace" ), "Namespace" }, { sizeof("Function"), "Function" },
{ sizeof( "Namespace_Body" ), "Namespace_Body" }, { sizeof("Function_Fwd"), "Function_Fwd" },
{ sizeof( "Operator" ), "Operator" }, { sizeof("Function_Body"), "Function_Body" },
{ sizeof( "Operator_Fwd" ), "Operator_Fwd" }, { sizeof("Global_Body"), "Global_Body" },
{ sizeof( "Operator_Member" ), "Operator_Member" }, { sizeof("Module"), "Module" },
{ sizeof( "Operator_Member_Fwd" ), "Operator_Member_Fwd" }, { sizeof("Namespace"), "Namespace" },
{ sizeof( "Operator_Cast" ), "Operator_Cast" }, { sizeof("Namespace_Body"), "Namespace_Body" },
{ sizeof( "Operator_Cast_Fwd" ), "Operator_Cast_Fwd" }, { sizeof("Operator"), "Operator" },
{ sizeof( "Parameters" ), "Parameters" }, { sizeof("Operator_Fwd"), "Operator_Fwd" },
{ sizeof( "Preprocess_Define" ), "Preprocess_Define" }, { sizeof("Operator_Member"), "Operator_Member" },
{ sizeof( "Preprocess_Include" ), "Preprocess_Include" }, { sizeof("Operator_Member_Fwd"), "Operator_Member_Fwd" },
{ sizeof( "Preprocess_If" ), "Preprocess_If" }, { sizeof("Operator_Cast"), "Operator_Cast" },
{ sizeof( "Preprocess_IfDef" ), "Preprocess_IfDef" }, { sizeof("Operator_Cast_Fwd"), "Operator_Cast_Fwd" },
{ sizeof( "Preprocess_IfNotDef" ), "Preprocess_IfNotDef" }, { sizeof("Parameters"), "Parameters" },
{ sizeof( "Preprocess_ElIf" ), "Preprocess_ElIf" }, { sizeof("Preprocess_Define"), "Preprocess_Define" },
{ sizeof( "Preprocess_Else" ), "Preprocess_Else" }, { sizeof("Preprocess_Include"), "Preprocess_Include" },
{ sizeof( "Preprocess_EndIf" ), "Preprocess_EndIf" }, { sizeof("Preprocess_If"), "Preprocess_If" },
{ sizeof( "Preprocess_Pragma" ), "Preprocess_Pragma" }, { sizeof("Preprocess_IfDef"), "Preprocess_IfDef" },
{ sizeof( "Specifiers" ), "Specifiers" }, { sizeof("Preprocess_IfNotDef"), "Preprocess_IfNotDef" },
{ sizeof( "Struct" ), "Struct" }, { sizeof("Preprocess_ElIf"), "Preprocess_ElIf" },
{ sizeof( "Struct_Fwd" ), "Struct_Fwd" }, { sizeof("Preprocess_Else"), "Preprocess_Else" },
{ sizeof( "Struct_Body" ), "Struct_Body" }, { sizeof("Preprocess_EndIf"), "Preprocess_EndIf" },
{ sizeof( "Template" ), "Template" }, { sizeof("Preprocess_Pragma"), "Preprocess_Pragma" },
{ sizeof( "Typedef" ), "Typedef" }, { sizeof("Specifiers"), "Specifiers" },
{ sizeof( "Typename" ), "Typename" }, { sizeof("Struct"), "Struct" },
{ sizeof( "Union" ), "Union" }, { sizeof("Struct_Fwd"), "Struct_Fwd" },
{ sizeof( "Union_Fwd" ), "Union_Fwd" }, { sizeof("Struct_Body"), "Struct_Body" },
{ sizeof( "Union_Body" ), "Union_Body" }, { sizeof("Template"), "Template" },
{ sizeof( "Using" ), "Using" }, { sizeof("Typedef"), "Typedef" },
{ sizeof( "Using_Namespace" ), "Using_Namespace" }, { sizeof("Typename"), "Typename" },
{ sizeof( "Variable" ), "Variable" }, { sizeof("Union"), "Union" },
}; { sizeof("Union_Fwd"), "Union_Fwd" },
return lookup[type]; { sizeof("Union_Body"), "Union_Body" },
{ sizeof("Using"), "Using" },
{ sizeof("Using_Namespace"), "Using_Namespace" },
{ sizeof("Variable"), "Variable" },
}; return lookup[ type ];
} }

View File

@ -1,111 +1,65 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #include "components/types.hpp" #pragma once
#include "components/types.hpp"
#endif #endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
enum Operator_Def enum_underlying( u32 ) enum Operator : u32
{ Op_Invalid,
Op_Assign,
Op_Assign_Add,
Op_Assign_Subtract,
Op_Assign_Multiply,
Op_Assign_Divide,
Op_Assign_Modulo,
Op_Assign_BAnd,
Op_Assign_BOr,
Op_Assign_BXOr,
Op_Assign_LShift,
Op_Assign_RShift,
Op_Increment,
Op_Decrement,
Op_Unary_Plus,
Op_Unary_Minus,
Op_UnaryNot,
Op_Add,
Op_Subtract,
Op_Multiply,
Op_Divide,
Op_Modulo,
Op_BNot,
Op_BAnd,
Op_BOr,
Op_BXOr,
Op_LShift,
Op_RShift,
Op_LAnd,
Op_LOr,
Op_LEqual,
Op_LNot,
Op_Lesser,
Op_Greater,
Op_LesserEqual,
Op_GreaterEqual,
Op_Subscript,
Op_Indirection,
Op_AddressOf,
Op_MemberOfPointer,
Op_PtrToMemOfPtr,
Op_FunctionCall,
Op_Comma,
Op_New,
Op_NewArray,
Op_Delete,
Op_DeleteArray,
NumOps };
typedef enum Operator_Def Operator;
inline StrC operator_to_str( Operator op )
{ {
local_persist StrC lookup[47] = { Op_Invalid,Op_Assign,Op_Assign_Add,Op_Assign_Subtract,Op_Assign_Multiply,Op_Assign_Divide,Op_Assign_Modulo,Op_Assign_BAnd,Op_Assign_BOr,Op_Assign_BXOr,Op_Assign_LShift,Op_Assign_RShift,Op_Increment,Op_Decrement,Op_Unary_Plus,Op_Unary_Minus,Op_UnaryNot,Op_Add,Op_Subtract,Op_Multiply,Op_Divide,Op_Modulo,Op_BNot,Op_BAnd,Op_BOr,Op_BXOr,Op_LShift,Op_RShift,Op_LAnd,Op_LOr,Op_LEqual,Op_LNot,Op_Lesser,Op_Greater,Op_LesserEqual,Op_GreaterEqual,Op_Subscript,Op_Indirection,Op_AddressOf,Op_MemberOfPointer,Op_PtrToMemOfPtr,Op_FunctionCall,Op_Comma,Op_New,Op_NewArray,Op_Delete,Op_DeleteArray,NumOps
{ sizeof( "INVALID" ), "INVALID" }, };
{ sizeof( "=" ), "=" }, typedef enum Operator Operator;
{ sizeof( "+=" ), "+=" }, inline
{ sizeof( "-=" ), "-=" }, StrC operator_to_str( Operator op)
{ sizeof( "*=" ), "*=" }, {
{ sizeof( "/=" ), "/=" }, local_persist StrC lookup[47] = { { sizeof("INVALID"), "INVALID" },
{ sizeof( "%=" ), "%=" }, { sizeof("="), "=" },
{ sizeof( "&=" ), "&=" }, { sizeof("+="), "+=" },
{ sizeof( "|=" ), "|=" }, { sizeof("-="), "-=" },
{ sizeof( "^=" ), "^=" }, { sizeof("*="), "*=" },
{ sizeof( "<<=" ), "<<=" }, { sizeof("/="), "/=" },
{ sizeof( ">>=" ), ">>=" }, { sizeof("%="), "%=" },
{ sizeof( "++" ), "++" }, { sizeof("&="), "&=" },
{ sizeof( "--" ), "--" }, { sizeof("|="), "|=" },
{ sizeof( "+" ), "+" }, { sizeof("^="), "^=" },
{ sizeof( "-" ), "-" }, { sizeof("<<="), "<<=" },
{ sizeof( "!" ), "!" }, { sizeof(">>="), ">>=" },
{ sizeof( "+" ), "+" }, { sizeof("++"), "++" },
{ sizeof( "-" ), "-" }, { sizeof("--"), "--" },
{ sizeof( "*" ), "*" }, { sizeof("+"), "+" },
{ sizeof( "/" ), "/" }, { sizeof("-"), "-" },
{ sizeof( "%" ), "%" }, { sizeof("!"), "!" },
{ sizeof( "~" ), "~" }, { sizeof("+"), "+" },
{ sizeof( "&" ), "&" }, { sizeof("-"), "-" },
{ sizeof( "|" ), "|" }, { sizeof("*"), "*" },
{ sizeof( "^" ), "^" }, { sizeof("/"), "/" },
{ sizeof( "<<" ), "<<" }, { sizeof("%"), "%" },
{ sizeof( ">>" ), ">>" }, { sizeof("~"), "~" },
{ sizeof( "&&" ), "&&" }, { sizeof("&"), "&" },
{ sizeof( "||" ), "||" }, { sizeof("|"), "|" },
{ sizeof( "==" ), "==" }, { sizeof("^"), "^" },
{ sizeof( "!=" ), "!=" }, { sizeof("<<"), "<<" },
{ sizeof( "<" ), "<" }, { sizeof(">>"), ">>" },
{ sizeof( ">" ), ">" }, { sizeof("&&"), "&&" },
{ sizeof( "<=" ), "<=" }, { sizeof("||"), "||" },
{ sizeof( ">=" ), ">=" }, { sizeof("=="), "==" },
{ sizeof( "[]" ), "[]" }, { sizeof("!="), "!=" },
{ sizeof( "*" ), "*" }, { sizeof("<"), "<" },
{ sizeof( "&" ), "&" }, { sizeof(">"), ">" },
{ sizeof( "->" ), "->" }, { sizeof("<="), "<=" },
{ sizeof( "->*" ), "->*" }, { sizeof(">="), ">=" },
{ sizeof( "()" ), "()" }, { sizeof("[]"), "[]" },
{ sizeof( "," ), "," }, { sizeof("*"), "*" },
{ sizeof( "new" ), "new" }, { sizeof("&"), "&" },
{ sizeof( "new[]" ), "new[]" }, { sizeof("->"), "->" },
{ sizeof( "delete" ), "delete" }, { sizeof("->*"), "->*" },
{ sizeof( "delete[]" ), "delete[]" }, { sizeof("()"), "()" },
}; { sizeof(","), "," },
return lookup[op]; { sizeof("new"), "new" },
{ sizeof("new[]"), "new[]" },
{ sizeof("delete"), "delete" },
{ sizeof("delete[]"), "delete[]" },
}; return lookup[ op ];
} }

View File

@ -1,68 +1,54 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #include "components/types.hpp" #pragma once
#include "components/types.hpp"
#endif #endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
enum Specifier_Def enum_underlying( u32 ) enum Specifier : u32
{ Spec_Invalid, Spec_Consteval, Spec_Constexpr, Spec_Constinit, Spec_Explicit, Spec_External_Linkage, Spec_ForceInline,
Spec_Global, Spec_Inline, Spec_Internal_Linkage, Spec_Local_Persist, Spec_Mutable, Spec_NeverInline, Spec_Ptr,
Spec_Ref, Spec_Register, Spec_RValue, Spec_Static, Spec_Thread_Local, Spec_Virtual, Spec_Const,
Spec_Final, Spec_NoExceptions, Spec_Override, Spec_Pure, Spec_Volatile, Spec_NumSpecifiers };
typedef enum Specifier_Def Specifier;
inline bool spec_is_trailing( Specifier specifier )
{ {
return specifier > Spec_Virtual; Spec_Invalid,Spec_Consteval,Spec_Constexpr,Spec_Constinit,Spec_Explicit,Spec_External_Linkage,Spec_ForceInline,Spec_Global,Spec_Inline,Spec_Internal_Linkage,Spec_Local_Persist,Spec_Mutable,Spec_NeverInline,Spec_Ptr,Spec_Ref,Spec_Register,Spec_RValue,Spec_Static,Spec_Thread_Local,Spec_Virtual,Spec_Const,Spec_Final,Spec_NoExceptions,Spec_Override,Spec_Pure,Spec_Volatile,Spec_NumSpecifiers
};
typedef enum Specifier Specifier;
inline
bool spec_is_trailing( Specifier specifier)
{
return specifier > Spec_Virtual;
}
inline
StrC spec_to_str( Specifier type)
{
local_persist StrC lookup[26] = { { sizeof("INVALID"), "INVALID" },
{ sizeof("consteval"), "consteval" },
{ sizeof("constexpr"), "constexpr" },
{ sizeof("constinit"), "constinit" },
{ sizeof("explicit"), "explicit" },
{ sizeof("extern"), "extern" },
{ sizeof("forceinline"), "forceinline" },
{ sizeof("global"), "global" },
{ sizeof("inline"), "inline" },
{ sizeof("internal"), "internal" },
{ sizeof("local_persist"), "local_persist" },
{ sizeof("mutable"), "mutable" },
{ sizeof("neverinline"), "neverinline" },
{ sizeof("*"), "*" },
{ sizeof("&"), "&" },
{ sizeof("register"), "register" },
{ sizeof("&&"), "&&" },
{ sizeof("static"), "static" },
{ sizeof("thread_local"), "thread_local" },
{ sizeof("virtual"), "virtual" },
{ sizeof("const"), "const" },
{ sizeof("final"), "final" },
{ sizeof("noexcept"), "noexcept" },
{ sizeof("override"), "override" },
{ sizeof("= 0"), "= 0" },
{ sizeof("volatile"), "volatile" },
}; return lookup[ type ];
}
inline
Specifier strc_to_specifier( StrC str)
{
local_persist u32 keymap[ Spec_NumSpecifiers ]; do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) { StrC enum_str = spec_to_str( (Specifier)index ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1); } do_once_end u32 hash = crc32( str.Ptr, str.Len ); for ( u32 index = 0; index < Spec_NumSpecifiers; index++ ) { if ( keymap[index] == hash ) return (Specifier)index; } return Spec_Invalid;
} }
inline StrC spec_to_str( Specifier type )
{
local_persist StrC lookup[26] = {
{ sizeof( "INVALID" ), "INVALID" },
{ sizeof( "consteval" ), "consteval" },
{ sizeof( "constexpr" ), "constexpr" },
{ sizeof( "constinit" ), "constinit" },
{ sizeof( "explicit" ), "explicit" },
{ sizeof( "extern" ), "extern" },
{ sizeof( "forceinline" ), "forceinline" },
{ sizeof( "global" ), "global" },
{ sizeof( "inline" ), "inline" },
{ sizeof( "internal" ), "internal" },
{ sizeof( "local_persist" ), "local_persist" },
{ sizeof( "mutable" ), "mutable" },
{ sizeof( "neverinline" ), "neverinline" },
{ sizeof( "*" ), "*" },
{ sizeof( "&" ), "&" },
{ sizeof( "register" ), "register" },
{ sizeof( "&&" ), "&&" },
{ sizeof( "static" ), "static" },
{ sizeof( "thread_local" ), "thread_local" },
{ sizeof( "virtual" ), "virtual" },
{ sizeof( "const" ), "const" },
{ sizeof( "final" ), "final" },
{ sizeof( "noexcept" ), "noexcept" },
{ sizeof( "override" ), "override" },
{ sizeof( "= 0" ), "= 0" },
{ sizeof( "volatile" ), "volatile" },
};
return lookup[type];
}
inline Specifier strc_to_specifier( StrC str )
{
local_persist u32 keymap[Spec_NumSpecifiers];
do_once_start for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
{
StrC enum_str = spec_to_str( (Specifier)index );
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
}
do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < Spec_NumSpecifiers; index++ )
{
if ( keymap[index] == hash )
return (Specifier)index;
}
return Spec_Invalid;
}

View File

@ -1,234 +1,124 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES #ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once #include "components/types.hpp" #pragma once
#include "components/types.hpp"
#endif #endif
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
GEN_NS_PARSER_BEGIN GEN_NS_PARSER_BEGIN
#define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" ) #define GEN_DEFINE_ATTRIBUTE_TOKENS Entry( Tok_Attribute_API_Export, "GEN_API_Export_Code" ) \
Entry( Tok_Attribute_API_Import, "GEN_API_Import_Code" )
enum TokType_Def : u32 enum TokType_Def : u32
{ {
Tok_Invalid, Tok_Invalid,Tok_Access_Private,Tok_Access_Protected,Tok_Access_Public,Tok_Access_MemberSymbol,Tok_Access_StaticSymbol,Tok_Ampersand,Tok_Ampersand_DBL,Tok_Assign_Classifer,Tok_Attribute_Open,Tok_Attribute_Close,Tok_BraceCurly_Open,Tok_BraceCurly_Close,Tok_BraceSquare_Open,Tok_BraceSquare_Close,Tok_Capture_Start,Tok_Capture_End,Tok_Comment,Tok_Comment_End,Tok_Comment_Start,Tok_Char,Tok_Comma,Tok_Decl_Class,Tok_Decl_GNU_Attribute,Tok_Decl_MSVC_Attribute,Tok_Decl_Enum,Tok_Decl_Extern_Linkage,Tok_Decl_Friend,Tok_Decl_Module,Tok_Decl_Namespace,Tok_Decl_Operator,Tok_Decl_Struct,Tok_Decl_Template,Tok_Decl_Typedef,Tok_Decl_Using,Tok_Decl_Union,Tok_Identifier,Tok_Module_Import,Tok_Module_Export,Tok_NewLine,Tok_Number,Tok_Operator,Tok_Preprocess_Hash,Tok_Preprocess_Define,Tok_Preprocess_If,Tok_Preprocess_IfDef,Tok_Preprocess_IfNotDef,Tok_Preprocess_ElIf,Tok_Preprocess_Else,Tok_Preprocess_EndIf,Tok_Preprocess_Include,Tok_Preprocess_Pragma,Tok_Preprocess_Content,Tok_Preprocess_Macro,Tok_Preprocess_Unsupported,Tok_Spec_Alignas,Tok_Spec_Const,Tok_Spec_Consteval,Tok_Spec_Constexpr,Tok_Spec_Constinit,Tok_Spec_Explicit,Tok_Spec_Extern,Tok_Spec_Final,Tok_Spec_ForceInline,Tok_Spec_Global,Tok_Spec_Inline,Tok_Spec_Internal_Linkage,Tok_Spec_LocalPersist,Tok_Spec_Mutable,Tok_Spec_NeverInline,Tok_Spec_Override,Tok_Spec_Static,Tok_Spec_ThreadLocal,Tok_Spec_Volatile,Tok_Spec_Virtual,Tok_Star,Tok_Statement_End,Tok_StaticAssert,Tok_String,Tok_Type_Typename,Tok_Type_Unsigned,Tok_Type_Signed,Tok_Type_Short,Tok_Type_Long,Tok_Type_bool,Tok_Type_char,Tok_Type_int,Tok_Type_double,Tok_Type_MS_int8,Tok_Type_MS_int16,Tok_Type_MS_int32,Tok_Type_MS_int64,Tok_Type_MS_W64,Tok_Varadic_Argument,Tok___Attributes_Start,Tok_Attribute_API_Export,Tok_Attribute_API_Import,Tok_NumTokens
Tok_Access_Private,
Tok_Access_Protected,
Tok_Access_Public,
Tok_Access_MemberSymbol,
Tok_Access_StaticSymbol,
Tok_Ampersand,
Tok_Ampersand_DBL,
Tok_Assign_Classifer,
Tok_Attribute_Open,
Tok_Attribute_Close,
Tok_BraceCurly_Open,
Tok_BraceCurly_Close,
Tok_BraceSquare_Open,
Tok_BraceSquare_Close,
Tok_Capture_Start,
Tok_Capture_End,
Tok_Comment,
Tok_Comment_End,
Tok_Comment_Start,
Tok_Char,
Tok_Comma,
Tok_Decl_Class,
Tok_Decl_GNU_Attribute,
Tok_Decl_MSVC_Attribute,
Tok_Decl_Enum,
Tok_Decl_Extern_Linkage,
Tok_Decl_Friend,
Tok_Decl_Module,
Tok_Decl_Namespace,
Tok_Decl_Operator,
Tok_Decl_Struct,
Tok_Decl_Template,
Tok_Decl_Typedef,
Tok_Decl_Using,
Tok_Decl_Union,
Tok_Identifier,
Tok_Module_Import,
Tok_Module_Export,
Tok_NewLine,
Tok_Number,
Tok_Operator,
Tok_Preprocess_Hash,
Tok_Preprocess_Define,
Tok_Preprocess_If,
Tok_Preprocess_IfDef,
Tok_Preprocess_IfNotDef,
Tok_Preprocess_ElIf,
Tok_Preprocess_Else,
Tok_Preprocess_EndIf,
Tok_Preprocess_Include,
Tok_Preprocess_Pragma,
Tok_Preprocess_Content,
Tok_Preprocess_Macro,
Tok_Preprocess_Unsupported,
Tok_Spec_Alignas,
Tok_Spec_Const,
Tok_Spec_Consteval,
Tok_Spec_Constexpr,
Tok_Spec_Constinit,
Tok_Spec_Explicit,
Tok_Spec_Extern,
Tok_Spec_Final,
Tok_Spec_ForceInline,
Tok_Spec_Global,
Tok_Spec_Inline,
Tok_Spec_Internal_Linkage,
Tok_Spec_LocalPersist,
Tok_Spec_Mutable,
Tok_Spec_NeverInline,
Tok_Spec_Override,
Tok_Spec_Static,
Tok_Spec_ThreadLocal,
Tok_Spec_Volatile,
Tok_Spec_Virtual,
Tok_Star,
Tok_Statement_End,
Tok_StaticAssert,
Tok_String,
Tok_Type_Typename,
Tok_Type_Unsigned,
Tok_Type_Signed,
Tok_Type_Short,
Tok_Type_Long,
Tok_Type_bool,
Tok_Type_char,
Tok_Type_int,
Tok_Type_double,
Tok_Type_MS_int8,
Tok_Type_MS_int16,
Tok_Type_MS_int32,
Tok_Type_MS_int64,
Tok_Type_MS_W64,
Tok_Varadic_Argument,
Tok___Attributes_Start,
Tok_Attribute_API_Export,
Tok_Attribute_API_Import,
Tok_NumTokens
}; };
typedef enum TokType_Def TokType; typedef enum TokType_Def TokType;
inline
inline StrC to_str( TokType type ) StrC to_str( TokType type)
{ {
local_persist StrC lookup[] { local_persist StrC lookup[] { { sizeof("__invalid__"), "__invalid__" },
{ sizeof( "__invalid__" ), "__invalid__" }, { sizeof("private"), "private" },
{ sizeof( "private" ), "private" }, { sizeof("protected"), "protected" },
{ sizeof( "protected" ), "protected" }, { sizeof("public"), "public" },
{ sizeof( "public" ), "public" }, { sizeof("."), "." },
{ sizeof( "." ), "." }, { sizeof("::"), "::" },
{ sizeof( "::" ), "::" }, { sizeof("&"), "&" },
{ sizeof( "&" ), "&" }, { sizeof("&&"), "&&" },
{ sizeof( "&&" ), "&&" }, { sizeof(":"), ":" },
{ sizeof( ":" ), ":" }, { sizeof("[["), "[[" },
{ sizeof( "[[" ), "[[" }, { sizeof("]]"), "]]" },
{ sizeof( "]]" ), "]]" }, { sizeof("{"), "{" },
{ sizeof( "{" ), "{" }, { sizeof("}"), "}" },
{ sizeof( "}" ), "}" }, { sizeof("["), "[" },
{ sizeof( "[" ), "[" }, { sizeof("]"), "]" },
{ sizeof( "]" ), "]" }, { sizeof("("), "(" },
{ sizeof( "(" ), "(" }, { sizeof(")"), ")" },
{ sizeof( ")" ), ")" }, { sizeof("__comment__"), "__comment__" },
{ sizeof( "__comment__" ), "__comment__" }, { sizeof("__comment_end__"), "__comment_end__" },
{ sizeof( "__comment_end__" ), "__comment_end__" }, { sizeof("__comment_start__"), "__comment_start__" },
{ sizeof( "__comment_start__" ), "__comment_start__" }, { sizeof("__character__"), "__character__" },
{ sizeof( "__character__" ), "__character__" }, { sizeof(","), "," },
{ sizeof( "," ), "," }, { sizeof("class"), "class" },
{ sizeof( "class" ), "class" }, { sizeof("__attribute__"), "__attribute__" },
{ sizeof( "__attribute__" ), "__attribute__" }, { sizeof("__declspec"), "__declspec" },
{ sizeof( "__declspec" ), "__declspec" }, { sizeof("enum"), "enum" },
{ sizeof( "enum" ), "enum" }, { sizeof("extern"), "extern" },
{ sizeof( "extern" ), "extern" }, { sizeof("friend"), "friend" },
{ sizeof( "friend" ), "friend" }, { sizeof("module"), "module" },
{ sizeof( "module" ), "module" }, { sizeof("namespace"), "namespace" },
{ sizeof( "namespace" ), "namespace" }, { sizeof("operator"), "operator" },
{ sizeof( "operator" ), "operator" }, { sizeof("struct"), "struct" },
{ sizeof( "struct" ), "struct" }, { sizeof("template"), "template" },
{ sizeof( "template" ), "template" }, { sizeof("typedef"), "typedef" },
{ sizeof( "typedef" ), "typedef" }, { sizeof("using"), "using" },
{ sizeof( "using" ), "using" }, { sizeof("union"), "union" },
{ sizeof( "union" ), "union" }, { sizeof("__identifier__"), "__identifier__" },
{ sizeof( "__identifier__" ), "__identifier__" }, { sizeof("import"), "import" },
{ sizeof( "import" ), "import" }, { sizeof("export"), "export" },
{ sizeof( "export" ), "export" }, { sizeof("__new_line__"), "__new_line__" },
{ sizeof( "__new_line__" ), "__new_line__" }, { sizeof("__number__"), "__number__" },
{ sizeof( "__number__" ), "__number__" }, { sizeof("__operator__"), "__operator__" },
{ sizeof( "__operator__" ), "__operator__" }, { sizeof("#"), "#" },
{ sizeof( "#" ), "#" }, { sizeof("define"), "define" },
{ sizeof( "define" ), "define" }, { sizeof("if"), "if" },
{ sizeof( "if" ), "if" }, { sizeof("ifdef"), "ifdef" },
{ sizeof( "ifdef" ), "ifdef" }, { sizeof("ifndef"), "ifndef" },
{ sizeof( "ifndef" ), "ifndef" }, { sizeof("elif"), "elif" },
{ sizeof( "elif" ), "elif" }, { sizeof("else"), "else" },
{ sizeof( "else" ), "else" }, { sizeof("endif"), "endif" },
{ sizeof( "endif" ), "endif" }, { sizeof("include"), "include" },
{ sizeof( "include" ), "include" }, { sizeof("pragma"), "pragma" },
{ sizeof( "pragma" ), "pragma" }, { sizeof("__macro_content__"), "__macro_content__" },
{ sizeof( "__macro_content__" ), "__macro_content__" }, { sizeof("__macro__"), "__macro__" },
{ sizeof( "__macro__" ), "__macro__" }, { sizeof("__unsupported__"), "__unsupported__" },
{ sizeof( "__unsupported__" ), "__unsupported__" }, { sizeof("alignas"), "alignas" },
{ sizeof( "alignas" ), "alignas" }, { sizeof("const"), "const" },
{ sizeof( "const" ), "const" }, { sizeof("consteval"), "consteval" },
{ sizeof( "consteval" ), "consteval" }, { sizeof("constexpr"), "constexpr" },
{ sizeof( "constexpr" ), "constexpr" }, { sizeof("constinit"), "constinit" },
{ sizeof( "constinit" ), "constinit" }, { sizeof("explicit"), "explicit" },
{ sizeof( "explicit" ), "explicit" }, { sizeof("extern"), "extern" },
{ sizeof( "extern" ), "extern" }, { sizeof("final"), "final" },
{ sizeof( "final" ), "final" }, { sizeof("forceinline"), "forceinline" },
{ sizeof( "forceinline" ), "forceinline" }, { sizeof("global"), "global" },
{ sizeof( "global" ), "global" }, { sizeof("inline"), "inline" },
{ sizeof( "inline" ), "inline" }, { sizeof("internal"), "internal" },
{ sizeof( "internal" ), "internal" }, { sizeof("local_persist"), "local_persist" },
{ sizeof( "local_persist" ), "local_persist" }, { sizeof("mutable"), "mutable" },
{ sizeof( "mutable" ), "mutable" }, { sizeof("neverinline"), "neverinline" },
{ sizeof( "neverinline" ), "neverinline" }, { sizeof("override"), "override" },
{ sizeof( "override" ), "override" }, { sizeof("static"), "static" },
{ sizeof( "static" ), "static" }, { sizeof("thread_local"), "thread_local" },
{ sizeof( "thread_local" ), "thread_local" }, { sizeof("volatile"), "volatile" },
{ sizeof( "volatile" ), "volatile" }, { sizeof("virtual"), "virtual" },
{ sizeof( "virtual" ), "virtual" }, { sizeof("*"), "*" },
{ sizeof( "*" ), "*" }, { sizeof(";"), ";" },
{ sizeof( ";" ), ";" }, { sizeof("static_assert"), "static_assert" },
{ sizeof( "static_assert" ), "static_assert" }, { sizeof("__string__"), "__string__" },
{ sizeof( "__string__" ), "__string__" }, { sizeof("typename"), "typename" },
{ sizeof( "typename" ), "typename" }, { sizeof("unsigned"), "unsigned" },
{ sizeof( "unsigned" ), "unsigned" }, { sizeof("signed"), "signed" },
{ sizeof( "signed" ), "signed" }, { sizeof("short"), "short" },
{ sizeof( "short" ), "short" }, { sizeof("long"), "long" },
{ sizeof( "long" ), "long" }, { sizeof("bool"), "bool" },
{ sizeof( "bool" ), "bool" }, { sizeof("char"), "char" },
{ sizeof( "char" ), "char" }, { sizeof("int"), "int" },
{ sizeof( "int" ), "int" }, { sizeof("double"), "double" },
{ sizeof( "double" ), "double" }, { sizeof("__int8"), "__int8" },
{ sizeof( "__int8" ), "__int8" }, { sizeof("__int16"), "__int16" },
{ sizeof( "__int16" ), "__int16" }, { sizeof("__int32"), "__int32" },
{ sizeof( "__int32" ), "__int32" }, { sizeof("__int64"), "__int64" },
{ sizeof( "__int64" ), "__int64" }, { sizeof("_W64"), "_W64" },
{ sizeof( "_W64" ), "_W64" }, { sizeof("..."), "..." },
{ sizeof( "..." ), "..." }, { sizeof("__attrib_start__"), "__attrib_start__" },
{ sizeof( "__attrib_start__" ), "__attrib_start__" }, { sizeof("GEN_API_Export_Code"), "GEN_API_Export_Code" },
{ sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code" }, { sizeof("GEN_API_Import_Code"), "GEN_API_Import_Code" },
{ sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code" }, }; return lookup[ type ];
};
return lookup[type];
} }
inline
inline TokType to_toktype( StrC str ) TokType to_toktype( StrC str)
{ {
local_persist u32 keymap[Tok_NumTokens]; local_persist u32 keymap[ Tok_NumTokens ]; do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ ) { StrC enum_str = to_str( (TokType)index ); keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1); } do_once_end u32 hash = crc32( str.Ptr, str.Len ); for ( u32 index = 0; index < Tok_NumTokens; index++ ) { if ( keymap[index] == hash ) return (TokType)index; } return Tok_Invalid;
do_once_start for ( u32 index = 0; index < Tok_NumTokens; index++ )
{
StrC enum_str = to_str( (TokType)index );
keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1 );
}
do_once_end u32 hash = crc32( str.Ptr, str.Len );
for ( u32 index = 0; index < Tok_NumTokens; index++ )
{
if ( keymap[index] == hash )
return (TokType)index;
}
return Tok_Invalid;
} }
GEN_NS_PARSER_END GEN_NS_PARSER_END

View File

@ -7,10 +7,11 @@
inline inline
void code_append( Code self, Code other ) void code_append( Code self, Code other )
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self);
GEN_ASSERT(other.ast != nullptr); GEN_ASSERT(other);
GEN_ASSERT_MSG(self != other, "Attempted to recursively append Code AST to itself.");
if ( other->Parent ) if ( other->Parent != nullptr )
other = code_duplicate(other); other = code_duplicate(other);
other->Parent = self; other->Parent = self;
@ -34,7 +35,7 @@ void code_append( Code self, Code other )
inline inline
bool code_is_body(Code self) bool code_is_body(Code self)
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self);
switch (self->Type) switch (self->Type)
{ {
case CT_Enum_Body: case CT_Enum_Body:
@ -53,7 +54,7 @@ bool code_is_body(Code self)
inline inline
Code* code_entry( Code self, u32 idx ) Code* code_entry( Code self, u32 idx )
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self != nullptr);
Code* current = & self->Front; Code* current = & self->Front;
while ( idx >= 0 && current != nullptr ) while ( idx >= 0 && current != nullptr )
{ {
@ -66,29 +67,31 @@ Code* code_entry( Code self, u32 idx )
return rcast( Code*, current); return rcast( Code*, current);
} }
inline forceinline
bool code_is_valid(Code self) bool code_is_valid(Code self)
{ {
return self.ast != nullptr && self.ast->Type != CT_Invalid; GEN_ASSERT(self);
return self != nullptr && self->Type != CT_Invalid;
} }
inline forceinline
bool code_has_entries(AST* self) bool code_has_entries(AST* self)
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self);
return self->NumEntries > 0; return self->NumEntries > 0;
} }
inline forceinline
void code_set_global(Code self) void code_set_global(Code self)
{ {
if ( self.ast == nullptr ) if ( self == nullptr )
{ {
log_failure("Code::set_global: Cannot set code as global, AST is null!"); log_failure("Code::set_global: Cannot set code as global, AST is null!");
return; return;
} }
self->Parent.ast = Code_Global.ast; self->Parent = Code_Global;
} }
inline #if GEN_COMPILER_CPP
forceinline
Code& Code::operator ++() Code& Code::operator ++()
{ {
if ( ast ) if ( ast )
@ -96,7 +99,8 @@ Code& Code::operator ++()
return * this; return * this;
} }
inline #endif
forceinline
char const* code_type_str(Code self) char const* code_type_str(Code self)
{ {
GEN_ASSERT(self != nullptr); GEN_ASSERT(self != nullptr);
@ -106,49 +110,57 @@ char const* code_type_str(Code self)
#pragma region CodeBody #pragma region CodeBody
inline inline
void append( CodeBody self, Code other ) void body_append( CodeBody self, Code other )
{ {
GEN_ASSERT(other.ast != nullptr); GEN_ASSERT(self);
GEN_ASSERT(other);
if (code_is_body(other)) { if (code_is_body(other)) {
append( self, cast(CodeBody, other) ); body_append_body( self, cast(CodeBody, other) );
return; return;
} }
code_append( cast(Code, self), other ); code_append( cast(Code, self), other );
} }
inline inline
void append( CodeBody self, CodeBody body ) void body_append_body( CodeBody self, CodeBody body )
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self);
GEN_ASSERT(body);
GEN_ASSERT_MSG(self != body, "Attempted to append body to itself.");
for ( Code entry : body ) { for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); entry = next_CodeBody(body, entry) ) {
append( self, entry ); body_append( self, entry );
} }
} }
inline inline
Code begin( CodeBody body) { Code begin_CodeBody( CodeBody body) {
if ( body.ast ) GEN_ASSERT(body);
return { rcast( AST*, body.ast)->Front }; if ( body != nullptr )
return body->Front;
return { nullptr }; return { nullptr };
} }
inline forceinline
Code end(CodeBody body ){ Code end_CodeBody(CodeBody body ){
return { rcast(AST*, body.ast)->Back->Next }; GEN_ASSERT(body);
return body->Back->Next;
} }
inline inline
Code next(CodeBody body, Code entry) { Code next_CodeBody(CodeBody body, Code entry) {
GEN_ASSERT(body);
GEN_ASSERT(entry);
return entry->Next; return entry->Next;
} }
#pragma endregion CodeBody #pragma endregion CodeBody
#pragma region CodeClass #pragma region CodeClass
inline inline
void add_interface( CodeClass self, CodeTypename type ) void class_add_interface( CodeClass self, CodeTypename type )
{ {
GEN_ASSERT(self.ast !=nullptr); GEN_ASSERT(self);
GEN_ASSERT(type);
CodeTypename possible_slot = self->ParentType; CodeTypename possible_slot = self->ParentType;
if ( possible_slot.ast ) if ( possible_slot != nullptr )
{ {
// Were adding an interface to parent type, so we need to make sure the parent type is public. // Were adding an interface to parent type, so we need to make sure the parent type is public.
self->ParentAccess = AccessSpec_Public; self->ParentAccess = AccessSpec_Public;
@ -156,24 +168,25 @@ void add_interface( CodeClass self, CodeTypename type )
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly. // then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
} }
while ( possible_slot.ast != nullptr ) while ( possible_slot != nullptr )
{ {
possible_slot.ast = (AST_Typename*) possible_slot->Next.ast; possible_slot = possible_slot->Next;
} }
possible_slot.ast = type.ast; possible_slot = type;
} }
#pragma endregion CodeClass #pragma endregion CodeClass
#pragma region CodeParam #pragma region CodeParam
inline inline
void append( CodeParam appendee, CodeParam other ) void params_append( CodeParam appendee, CodeParam other )
{ {
GEN_ASSERT(appendee.ast != nullptr); GEN_ASSERT(appendee);
GEN_ASSERT(other);
Code self = cast(Code, appendee); Code self = cast(Code, appendee);
Code entry = cast(Code, other); Code entry = cast(Code, other);
if ( entry->Parent ) if ( entry->Parent != nullptr )
entry = code_duplicate( entry ); entry = code_duplicate( entry );
entry->Parent = self; entry->Parent = self;
@ -191,54 +204,61 @@ void append( CodeParam appendee, CodeParam other )
self->NumEntries++; self->NumEntries++;
} }
inline inline
CodeParam get(CodeParam self, s32 idx ) CodeParam params_get(CodeParam self, s32 idx )
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self);
CodeParam param = * self; CodeParam param = self;
do do
{ {
if ( ! ++ param ) if ( ++ param != nullptr )
return { nullptr }; return { nullptr };
param = cast(Code, param)->Next; param = cast(CodeParam, cast(Code, param)->Next);
} }
while ( --idx ); while ( --idx );
return param; return param;
} }
inline forceinline
bool has_entries(CodeParam self) bool params_has_entries(CodeParam self)
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self);
return self->NumEntries > 0; return self->NumEntries > 0;
} }
inline #if GEN_COMPILER_CPP
forceinline
CodeParam& CodeParam::operator ++() CodeParam& CodeParam::operator ++()
{ {
ast = ast->Next.ast; * this = ast->Next;
return * this; return * this;
} }
inline #endif
CodeParam begin(CodeParam params) forceinline
CodeParam begin_CodeParam(CodeParam params)
{ {
if ( params.ast ) if ( params != nullptr )
return { params.ast }; return params;
return { nullptr }; return NullCode;
} }
inline forceinline
CodeParam end(CodeParam params) CodeParam end_CodeParam(CodeParam params)
{ {
// return { (AST_Param*) rcast( AST*, ast)->Last }; // return { (AST_Param*) rcast( AST*, ast)->Last };
return { nullptr }; return { nullptr };
} }
forceinline
CodeParam next_CodeParam(CodeParam params, CodeParam param_iter)
{
return params->Next;
}
#pragma endregion CodeParam #pragma endregion CodeParam
#pragma region CodeSpecifiers #pragma region CodeSpecifiers
inline inline
bool append(CodeSpecifiers self, Specifier spec ) bool specifiers_append(CodeSpecifiers self, Specifier spec )
{ {
if ( self.ast == nullptr ) if ( self == nullptr )
{ {
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!"); log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return false; return false;
@ -254,9 +274,9 @@ bool append(CodeSpecifiers self, Specifier spec )
return true; return true;
} }
inline inline
s32 has(CodeSpecifiers self, Specifier spec) s32 specifiers_has(CodeSpecifiers self, Specifier spec)
{ {
GEN_ASSERT(self.ast != nullptr); GEN_ASSERT(self != nullptr);
for ( s32 idx = 0; idx < self->NumEntries; idx++ ) { for ( s32 idx = 0; idx < self->NumEntries; idx++ ) {
if ( self->ArrSpecs[ idx ] == spec ) if ( self->ArrSpecs[ idx ] == spec )
return idx; return idx;
@ -264,10 +284,9 @@ s32 has(CodeSpecifiers self, Specifier spec)
return -1; return -1;
} }
inline inline
s32 remove( CodeSpecifiers self, Specifier to_remove ) s32 specifiers_remove( CodeSpecifiers self, Specifier to_remove )
{ {
AST_Specifiers* ast = self.ast; if ( self == nullptr )
if ( ast == nullptr )
{ {
log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!"); log_failure("CodeSpecifiers: Attempted to append to a null specifiers AST!");
return -1; return -1;
@ -304,19 +323,24 @@ s32 remove( CodeSpecifiers self, Specifier to_remove )
} }
return result; return result;
} }
inline forceinline
Specifier* begin(CodeSpecifiers self) Specifier* begin_CodeSpecifiers(CodeSpecifiers self)
{ {
if ( self.ast ) if ( self != nullptr )
return & self->ArrSpecs[0]; return & self->ArrSpecs[0];
return nullptr; return nullptr;
} }
inline forceinline
Specifier* end(CodeSpecifiers self) Specifier* end_CodeSpecifiers(CodeSpecifiers self)
{ {
return self->ArrSpecs + self->NumEntries; return self->ArrSpecs + self->NumEntries;
} }
forceinline
Specifier* next_CodeSpecifiers(CodeSpecifiers self, Specifier* spec_iter)
{
return spec_iter + 1;
}
#pragma endregion CodeSpecifiers #pragma endregion CodeSpecifiers
#pragma region CodeStruct #pragma region CodeStruct
@ -324,7 +348,7 @@ inline
void add_interface(CodeStruct self, CodeTypename type ) void add_interface(CodeStruct self, CodeTypename type )
{ {
CodeTypename possible_slot = self->ParentType; CodeTypename possible_slot = self->ParentType;
if ( possible_slot.ast ) if ( possible_slot != nullptr )
{ {
// Were adding an interface to parent type, so we need to make sure the parent type is public. // Were adding an interface to parent type, so we need to make sure the parent type is public.
self->ParentAccess = AccessSpec_Public; self->ParentAccess = AccessSpec_Public;
@ -332,12 +356,12 @@ void add_interface(CodeStruct self, CodeTypename type )
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly. // then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
} }
while ( possible_slot.ast != nullptr ) while ( possible_slot != nullptr )
{ {
possible_slot.ast = (AST_Typename*) possible_slot->Next.ast; possible_slot = possible_slot->Next;
} }
possible_slot.ast = type.ast; possible_slot = type;
} }
#pragma endregion Code #pragma endregion Code

View File

@ -84,12 +84,12 @@ void define_constants()
t_empty = (CodeTypename) make_code(); t_empty = (CodeTypename) make_code();
t_empty->Type = CT_Typename; t_empty->Type = CT_Typename;
t_empty->Name = get_cached_string( txt("") ); t_empty->Name = get_cached_string( txt("") );
code_set_global(t_empty); code_set_global(cast(Code, t_empty));
access_private = make_code(); access_private = make_code();
access_private->Type = CT_Access_Private; access_private->Type = CT_Access_Private;
access_private->Name = get_cached_string( txt("private:\n") ); access_private->Name = get_cached_string( txt("private:\n") );
code_set_global(access_private); code_set_global(cast(Code, access_private));
access_protected = make_code(); access_protected = make_code();
access_protected->Type = CT_Access_Protected; access_protected->Type = CT_Access_Protected;
@ -102,50 +102,50 @@ void define_constants()
code_set_global(access_public); code_set_global(access_public);
attrib_api_export = def_attributes( code(GEN_API_Export_Code)); attrib_api_export = def_attributes( code(GEN_API_Export_Code));
code_set_global(attrib_api_export); code_set_global(cast(Code, attrib_api_export));
attrib_api_import = def_attributes( code(GEN_API_Import_Code)); attrib_api_import = def_attributes( code(GEN_API_Import_Code));
code_set_global(attrib_api_import); code_set_global(cast(Code, attrib_api_import));
module_global_fragment = make_code(); module_global_fragment = make_code();
module_global_fragment->Type = CT_Untyped; module_global_fragment->Type = CT_Untyped;
module_global_fragment->Name = get_cached_string( txt("module;") ); module_global_fragment->Name = get_cached_string( txt("module;") );
module_global_fragment->Content = module_global_fragment->Name; module_global_fragment->Content = module_global_fragment->Name;
code_set_global(module_global_fragment); code_set_global(cast(Code, module_global_fragment));
module_private_fragment = make_code(); module_private_fragment = make_code();
module_private_fragment->Type = CT_Untyped; module_private_fragment->Type = CT_Untyped;
module_private_fragment->Name = get_cached_string( txt("module : private;") ); module_private_fragment->Name = get_cached_string( txt("module : private;") );
module_private_fragment->Content = module_private_fragment->Name; module_private_fragment->Content = module_private_fragment->Name;
code_set_global(module_private_fragment); code_set_global(cast(Code, module_private_fragment));
fmt_newline = make_code(); fmt_newline = make_code();
fmt_newline->Type = CT_NewLine; fmt_newline->Type = CT_NewLine;
code_set_global(fmt_newline); code_set_global((Code)fmt_newline);
pragma_once = (CodePragma) make_code(); pragma_once = (CodePragma) make_code();
pragma_once->Type = CT_Preprocess_Pragma; pragma_once->Type = CT_Preprocess_Pragma;
pragma_once->Name = get_cached_string( txt("once") ); pragma_once->Name = get_cached_string( txt("once") );
pragma_once->Content = pragma_once->Name; pragma_once->Content = pragma_once->Name;
code_set_global(pragma_once); code_set_global((Code)pragma_once);
param_varadic = (CodeTypename) make_code(); param_varadic = (CodeParam) make_code();
param_varadic->Type = CT_Parameters; param_varadic->Type = CT_Parameters;
param_varadic->Name = get_cached_string( txt("...") ); param_varadic->Name = get_cached_string( txt("...") );
param_varadic->ValueType = t_empty; param_varadic->ValueType = t_empty;
code_set_global(param_varadic); code_set_global((Code)param_varadic);
preprocess_else = (CodePreprocessCond) make_code(); preprocess_else = (CodePreprocessCond) make_code();
preprocess_else->Type = CT_Preprocess_Else; preprocess_else->Type = CT_Preprocess_Else;
code_set_global(preprocess_else); code_set_global((Code)preprocess_else);
preprocess_endif = (CodePreprocessCond) make_code(); preprocess_endif = (CodePreprocessCond) make_code();
preprocess_endif->Type = CT_Preprocess_EndIf; preprocess_endif->Type = CT_Preprocess_EndIf;
code_set_global(preprocess_endif); code_set_global((Code)preprocess_endif);
# define def_constant_code_type( Type_ ) \ # define def_constant_code_type( Type_ ) \
t_##Type_ = def_type( name(Type_) ); \ t_##Type_ = def_type( name(Type_) ); \
code_set_global(t_##Type_); code_set_global( cast(Code, t_##Type_));
def_constant_code_type( auto ); def_constant_code_type( auto );
def_constant_code_type( void ); def_constant_code_type( void );
@ -180,7 +180,7 @@ void define_constants()
# define def_constant_spec( Type_, ... ) \ # define def_constant_spec( Type_, ... ) \
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \ spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
code_set_global(spec_##Type_); code_set_global( cast(Code, spec_##Type_));
# pragma push_macro("forceinline") # pragma push_macro("forceinline")
# pragma push_macro("global") # pragma push_macro("global")
@ -218,7 +218,7 @@ void define_constants()
def_constant_spec( volatile, Spec_Volatile) def_constant_spec( volatile, Spec_Volatile)
spec_local_persist = def_specifiers( 1, Spec_Local_Persist ); spec_local_persist = def_specifiers( 1, Spec_Local_Persist );
code_set_global(spec_local_persist); code_set_global(cast(Code, spec_local_persist));
# pragma pop_macro("forceinline") # pragma pop_macro("forceinline")
# pragma pop_macro("global") # pragma pop_macro("global")
@ -426,7 +426,7 @@ Code make_code()
} }
Code result { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) }; Code result { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) };
mem_set( result.ast, 0, sizeof(AST) ); mem_set( rcast(void*, cast(AST*, result)), 0, sizeof(AST) );
// result->Type = ECode::Invalid; // result->Type = ECode::Invalid;
// result->Content = { nullptr }; // result->Content = { nullptr };

View File

@ -29,19 +29,19 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
} \ } \
if ( params_code->Type != CT_Parameters ) \ if ( params_code->Type != CT_Parameters ) \
{ \ { \
log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str(params_code)); \ log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str( cast(Code, params_code))); \
return OpValResult_Fail; \ return OpValResult_Fail; \
} }
# define check_param_eq_ret() \ # define check_param_eq_ret() \
if ( ! is_member_symbol && ! code_is_equal(params_code->ValueType, ret_type) ) \ if ( ! is_member_symbol && ! code_is_equal(cast(Code, params_code->ValueType), cast(Code, ret_type)) ) \
{ \ { \
log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \ log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \
"param types: %s\n" \ "param types: %s\n" \
"return type: %s", \ "return type: %s", \
operator_to_str(op).Ptr, \ operator_to_str(op).Ptr, \
code_debug_str(params_code), \ code_debug_str(cast(Code, params_code)), \
code_debug_str(ret_type) \ code_debug_str(cast(Code, ret_type)) \
); \ ); \
return OpValResult_Fail; \ return OpValResult_Fail; \
} }
@ -54,7 +54,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
if ( ret_type->Type != CT_Typename ) if ( ret_type->Type != CT_Typename )
{ {
log_failure("gen::def_operator: ret_type is not of typename type - %s", code_debug_str(ret_type)); log_failure("gen::def_operator: ret_type is not of typename type - %s", code_debug_str(cast(Code, ret_type)));
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -71,7 +71,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s does not support non-member definition (more than one parameter provided) - %s", "operator%s does not support non-member definition (more than one parameter provided) - %s",
operator_to_str(op), operator_to_str(op),
code_debug_str(params_code) code_debug_str(cast(Code, params_code))
); );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -102,7 +102,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
log_failure("gen::def_operator: operator%s may not be defined with more than two parametes - param count; %d\n%s" log_failure("gen::def_operator: operator%s may not be defined with more than two parametes - param count; %d\n%s"
, operator_to_str(op) , operator_to_str(op)
, params_code->NumEntries , params_code->NumEntries
, code_debug_str(params_code) , code_debug_str(cast(Code, params_code))
); );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -117,7 +117,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
{ {
log_failure("gen::def_operator: operator%s params code provided is not of Parameters type - %s" log_failure("gen::def_operator: operator%s params code provided is not of Parameters type - %s"
, operator_to_str(op) , operator_to_str(op)
, code_debug_str(params_code) , code_debug_str(cast(Code, params_code))
); );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -125,7 +125,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
switch ( params_code->NumEntries ) switch ( params_code->NumEntries )
{ {
case 1: case 1:
if ( code_is_equal(params_code->ValueType, t_int ) ) if ( code_is_equal((Code)params_code->ValueType, (Code)t_int ) )
is_member_symbol = true; is_member_symbol = true;
else else
@ -135,7 +135,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
case 2: case 2:
check_param_eq_ret(); check_param_eq_ret();
if ( ! code_is_equal(get(params_code, 1), t_int ) ) if ( ! code_is_equal((Code)params_get(params_code, 1), (Code)t_int ) )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s requires second parameter of non-member definition to be int for post-decrement", "operator%s requires second parameter of non-member definition to be int for post-decrement",
@ -164,18 +164,18 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
{ {
if ( params_code->Type != CT_Parameters ) if ( params_code->Type != CT_Parameters )
{ {
log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str(params_code)); log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str((Code)params_code));
return OpValResult_Fail; return OpValResult_Fail;
} }
if ( code_is_equal(params_code->ValueType, ret_type ) ) if ( code_is_equal((Code)params_code->ValueType, (Code)ret_type ) )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s is non-member symbol yet first paramter does not equal return type\n" "operator%s is non-member symbol yet first paramter does not equal return type\n"
"param type: %s\n" "param type: %s\n"
"return type: %s\n" "return type: %s\n"
, code_debug_str(params_code) , code_debug_str((Code)params_code)
, code_debug_str(ret_type) , code_debug_str((Code)ret_type)
); );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -209,7 +209,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
{ {
if ( params_code->Type != CT_Parameters ) if ( params_code->Type != CT_Parameters )
{ {
log_failure( "gen::def_operator: params is not of Parameters type - %s", code_debug_str(params_code) ); log_failure( "gen::def_operator: params is not of Parameters type - %s", code_debug_str((Code)params_code) );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -245,14 +245,14 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
break; break;
case 2: case 2:
if ( ! code_is_equal(params_code->ValueType, ret_type ) ) if ( ! code_is_equal((Code)params_code->ValueType, (Code)ret_type ) )
{ {
log_failure("gen::def_operator: " log_failure("gen::def_operator: "
"operator%s is non-member symbol yet first paramter does not equal return type\n" "operator%s is non-member symbol yet first paramter does not equal return type\n"
"param type: %s\n" "param type: %s\n"
"return type: %s\n" "return type: %s\n"
, code_debug_str(params_code) , code_debug_str((Code)params_code)
, code_debug_str(ret_type) , code_debug_str((Code)ret_type)
); );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -275,7 +275,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
{ {
if ( params_code->Type != CT_Parameters ) if ( params_code->Type != CT_Parameters )
{ {
log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str(params_code)); log_failure("gen::def_operator: params is not of Parameters type - %s", code_debug_str((Code)params_code));
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -289,11 +289,11 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
} }
} }
if ( ! code_is_equal(ret_type, t_bool )) if ( ! code_is_equal((Code)ret_type, (Code)t_bool ))
{ {
log_failure("gen::def_operator: operator%s return type must be of type bool - %s" log_failure("gen::def_operator: operator%s return type must be of type bool - %s"
, operator_to_str(op) , operator_to_str(op)
, code_debug_str(ret_type) , code_debug_str((Code)ret_type)
); );
return OpValResult_Fail; return OpValResult_Fail;
} }
@ -347,7 +347,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
case Op_PtrToMemOfPtr: case Op_PtrToMemOfPtr:
if ( params_code ) if ( params_code )
{ {
log_failure("gen::def_operator: operator%s expects no paramters - %s", operator_to_str(op), code_debug_str(params_code)); log_failure("gen::def_operator: operator%s expects no paramters - %s", operator_to_str(op), code_debug_str((Code)params_code));
return OpValResult_Fail; return OpValResult_Fail;
} }
break; break;
@ -390,7 +390,7 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp
} }
#define null_check( Context_, Code_ ) \ #define null_check( Context_, Code_ ) \
if ( ! Code_ ) \ if ( Code_ != nullptr ) \
{ \ { \
log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \ log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \
return InvalidCode; \ return InvalidCode; \
@ -501,7 +501,7 @@ CodeConstructor def_constructor( Opts_def_constructor p )
if ( params && params->Type != CT_Parameters ) if ( params && params->Type != CT_Parameters )
{ {
log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str(params)); log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)params));
return InvalidCode; return InvalidCode;
} }
@ -606,7 +606,7 @@ CodeClass def_class( StrC name, Opts_def_struct p )
{ {
for (s32 idx = 0; idx < num_interfaces; idx++ ) for (s32 idx = 0; idx < num_interfaces; idx++ )
{ {
add_interface(result, interfaces[idx] ); class_add_interface(result, interfaces[idx] );
} }
} }
@ -692,13 +692,13 @@ CodeEnum def_enum( StrC name, Opts_def_enum p )
if ( type && type->Type != CT_Typename ) if ( type && type->Type != CT_Typename )
{ {
log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", code_debug_str(type) ); log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", code_debug_str((Code)type) );
return InvalidCode; return InvalidCode;
} }
if ( attributes && attributes->Type != CT_PlatformAttributes ) if ( attributes && attributes->Type != CT_PlatformAttributes )
{ {
log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(attributes) ); log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", code_debug_str((Code)attributes) );
return InvalidCode; return InvalidCode;
} }
@ -1161,7 +1161,7 @@ CodeSpecifiers def_specifier( Specifier spec )
CodeSpecifiers CodeSpecifiers
result = (CodeSpecifiers) make_code(); result = (CodeSpecifiers) make_code();
result->Type = CT_Specifiers; result->Type = CT_Specifiers;
append(result, spec ); specifiers_append(result, spec );
return result; return result;
} }
@ -1178,7 +1178,7 @@ CodeStruct def_struct( StrC name, Opts_def_struct p )
if ( attributes && attributes->Type != CT_PlatformAttributes ) if ( attributes && attributes->Type != CT_PlatformAttributes )
{ {
log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(attributes) ); log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, attributes)) );
return InvalidCode; return InvalidCode;
} }
@ -1273,19 +1273,19 @@ CodeTypename def_type( StrC name, Opts_def_type p )
if ( attributes && attributes->Type != CT_PlatformAttributes ) if ( attributes && attributes->Type != CT_PlatformAttributes )
{ {
log_failure( "gen::def_type: attributes is not of attributes type - %s", code_debug_str(attributes) ); log_failure( "gen::def_type: attributes is not of attributes type - %s", code_debug_str((Code)attributes) );
return InvalidCode; return InvalidCode;
} }
if ( specifiers && specifiers->Type != CT_Specifiers ) if ( specifiers && specifiers->Type != CT_Specifiers )
{ {
log_failure( "gen::def_type: specifiers is not of specifiers type - %s", code_debug_str(specifiers) ); log_failure( "gen::def_type: specifiers is not of specifiers type - %s", code_debug_str((Code)specifiers) );
return InvalidCode; return InvalidCode;
} }
if ( arrayexpr && arrayexpr->Type != CT_Untyped ) if ( arrayexpr && arrayexpr->Type != CT_Untyped )
{ {
log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str(arrayexpr) ); log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)arrayexpr) );
return InvalidCode; return InvalidCode;
} }
@ -1325,13 +1325,13 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p )
case CT_Typename: case CT_Typename:
break; break;
default: default:
log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", code_debug_str(type) ); log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", code_debug_str((Code)type) );
return InvalidCode; return InvalidCode;
} }
if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) if ( p.attributes && p.attributes->Type != CT_PlatformAttributes )
{ {
log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", code_debug_str(p.attributes) ); log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", code_debug_str((Code)p.attributes) );
return InvalidCode; return InvalidCode;
} }
@ -1553,7 +1553,7 @@ CodeBody def_class_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1590,7 +1590,7 @@ CodeBody def_class_body( s32 num, Code* codes )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1624,7 +1624,7 @@ CodeBody def_enum_body( s32 num, ... )
return InvalidCode; return InvalidCode;
} }
append(result, entry ); body_append(result, entry );
} }
while ( num--, num > 0 ); while ( num--, num > 0 );
va_end(va); va_end(va);
@ -1656,7 +1656,7 @@ CodeBody def_enum_body( s32 num, Code* codes )
return InvalidCode; return InvalidCode;
} }
append(result, entry ); body_append(result, entry );
} }
while ( codes++, num--, num > 0 ); while ( codes++, num--, num > 0 );
@ -1694,7 +1694,7 @@ CodeBody def_export_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1731,7 +1731,7 @@ CodeBody def_export_body( s32 num, Code* codes )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1769,7 +1769,7 @@ CodeBody def_extern_link_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1806,8 +1806,7 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1846,7 +1845,7 @@ CodeBody def_function_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1882,7 +1881,7 @@ CodeBody def_function_body( s32 num, Code* codes )
default: default:
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -1913,8 +1912,8 @@ CodeBody def_global_body( s32 num, ... )
switch (entry->Type) switch (entry->Type)
{ {
case CT_Global_Body: case CT_Global_Body:
// result.append( entry.code_cast<CodeBody>() ) ; // result.body_append( entry.code_cast<CodeBody>() ) ;
append( result, cast(CodeBody, entry) ); body_append( result, cast(CodeBody, entry) );
continue; continue;
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
@ -1925,7 +1924,7 @@ CodeBody def_global_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -1955,7 +1954,7 @@ CodeBody def_global_body( s32 num, Code* codes )
switch (entry->Type) switch (entry->Type)
{ {
case CT_Global_Body: case CT_Global_Body:
append(result, cast(CodeBody, entry) ); body_append(result, cast(CodeBody, entry) );
continue; continue;
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
@ -1966,7 +1965,7 @@ CodeBody def_global_body( s32 num, Code* codes )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -2004,7 +2003,7 @@ CodeBody def_namespace_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -2040,7 +2039,7 @@ CodeBody def_namespace_body( s32 num, Code* codes )
default: break; default: break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -2078,7 +2077,7 @@ CodeParam def_params( s32 num, ... )
return InvalidCode; return InvalidCode;
} }
append(result, param ); params_append(result, param );
} }
va_end(va); va_end(va);
@ -2114,7 +2113,7 @@ CodeParam def_params( s32 num, CodeParam* codes )
while( codes++, current = * codes, num--, num > 0 ) while( codes++, current = * codes, num--, num > 0 )
{ {
check_current(); check_current();
append(result, current ); params_append(result, current );
} }
# undef check_current # undef check_current
@ -2145,7 +2144,7 @@ CodeSpecifiers def_specifiers( s32 num, ... )
{ {
Specifier type = (Specifier)va_arg(va, int); Specifier type = (Specifier)va_arg(va, int);
append(result, type ); specifiers_append(result, type );
} }
while ( --num, num ); while ( --num, num );
va_end(va); va_end(va);
@ -2174,7 +2173,7 @@ CodeSpecifiers def_specifiers( s32 num, Specifier* specs )
s32 idx = 0; s32 idx = 0;
do do
{ {
append(result, specs[idx] ); specifiers_append(result, specs[idx] );
idx++; idx++;
} }
while ( --num, num ); while ( --num, num );
@ -2213,7 +2212,7 @@ CodeBody def_struct_body( s32 num, ... )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
va_end(va); va_end(va);
@ -2250,7 +2249,7 @@ CodeBody def_struct_body( s32 num, Code* codes )
break; break;
} }
append(result, entry); body_append(result, entry);
} }
while (num--, num > 0); while (num--, num > 0);
@ -2284,7 +2283,7 @@ CodeBody def_union_body( s32 num, ... )
return InvalidCode; return InvalidCode;
} }
append(result, entry ); body_append(result, entry );
} }
while ( num--, num > 0 ); while ( num--, num > 0 );
va_end(va); va_end(va);
@ -2316,7 +2315,7 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
return InvalidCode; return InvalidCode;
} }
append(result, entry ); body_append(result, entry );
} }
while ( codes++, num--, num > 0 ); while ( codes++, num--, num > 0 );

View File

@ -1124,7 +1124,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
return InvalidCode; return InvalidCode;
} }
append(result, member ); body_append(result, member );
} }
eat( Tok_BraceCurly_Close ); eat( Tok_BraceCurly_Close );
@ -1438,7 +1438,7 @@ CodeFn parse_function_after_name(
CodeParam params = parse_params(); CodeParam params = parse_params();
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Parameters> ) // <Attributes> <Specifiers> <ReturnType> <Name> ( <Parameters> )
// TODO(Ed), Review old comment : These have to be kept separate from the return type's specifiers. // TODO(Ed), Review old comment : These have to be kept separate from the return type's specifiers.
while ( left && is_specifier(currtok) ) while ( left && is_specifier(currtok) )
{ {
if ( specifiers.ast == nullptr ) if ( specifiers.ast == nullptr )
@ -1448,7 +1448,7 @@ CodeFn parse_function_after_name(
continue; continue;
} }
append(specifiers, strc_to_specifier( to_str(currtok)) ); specifiers_append(specifiers, strc_to_specifier( to_str(currtok)) );
eat( currtok.Type ); eat( currtok.Type );
} }
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> // <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>
@ -1468,7 +1468,7 @@ CodeFn parse_function_after_name(
else if ( check(Tok_Operator) && currtok.Text[0] == '=' ) else if ( check(Tok_Operator) && currtok.Text[0] == '=' )
{ {
eat(Tok_Operator); eat(Tok_Operator);
append(specifiers, Spec_Pure ); specifiers_append(specifiers, Spec_Pure );
eat( Tok_Number); eat( Tok_Number);
Token stmt_end = currtok; Token stmt_end = currtok;
@ -1544,7 +1544,7 @@ CodeFn parse_function_after_name(
internal internal
Code parse_function_body() Code parse_function_body()
{ {
push_scope(); push_scope();
eat( Tok_BraceCurly_Open ); eat( Tok_BraceCurly_Open );
@ -1574,7 +1574,7 @@ Code parse_function_body()
if ( len > 0 ) if ( len > 0 )
{ {
append( result, def_execution( { len, start.Text } ) ); body_append( result, def_execution( { len, start.Text } ) );
} }
eat( Tok_BraceCurly_Close ); eat( Tok_BraceCurly_Close );
@ -1891,7 +1891,7 @@ CodeBody parse_global_nspace( CodeType which )
} }
// log_fmt("Global Body Member: %s", member->debug_str()); // log_fmt("Global Body Member: %s", member->debug_str());
append(result, member ); body_append(result, member );
} }
if ( which != CT_Global_Body ) if ( which != CT_Global_Body )
@ -2032,7 +2032,7 @@ Code parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers )
// TODO(Ed): I want to eventually change the identifier to its own AST type. // TODO(Ed): I want to eventually change the identifier to its own AST type.
// This would allow distinction of the qualifier for a symbol <qualifier>::<nested symboL> // This would allow distinction of the qualifier for a symbol <qualifier>::<nested symboL>
// This would also allow // This would also allow
internal internal
Token parse_identifier( bool* possible_member_function ) Token parse_identifier( bool* possible_member_function )
{ {
@ -2455,7 +2455,7 @@ CodeOperator parse_operator_after_ret_type(
continue; continue;
} }
append(specifiers, strc_to_specifier( to_str(currtok)) ); specifiers_append(specifiers, strc_to_specifier( to_str(currtok)) );
eat( currtok.Type ); eat( currtok.Type );
} }
// <ExportFlag> <Attributes> <Specifiers> <ReturnType> <Qualifier::...> operator <Op> ( <Parameters> ) <Specifiers> // <ExportFlag> <Attributes> <Specifiers> <ReturnType> <Qualifier::...> operator <Op> ( <Parameters> ) <Specifiers>
@ -2771,7 +2771,7 @@ CodeParam parse_params( bool use_template_capture )
if ( check( Tok_Varadic_Argument ) ) if ( check( Tok_Varadic_Argument ) )
{ {
eat( Tok_Varadic_Argument ); eat( Tok_Varadic_Argument );
append(result, param_varadic ); params_append(result, param_varadic );
continue; continue;
// ( <Macro> <ValueType> <Name> = <Expression>, ... // ( <Macro> <ValueType> <Name> = <Expression>, ...
} }
@ -2875,7 +2875,7 @@ CodeParam parse_params( bool use_template_capture )
if ( value ) if ( value )
param->Value = value; param->Value = value;
append(result, param ); params_append(result, param );
} }
if ( ! use_template_capture ) if ( ! use_template_capture )
@ -2933,7 +2933,7 @@ CodePreprocessCond parse_preprocess_cond()
return cond; return cond;
} }
internal internal
Code parse_simple_preprocess( TokType which, bool dont_consume_braces ) Code parse_simple_preprocess( TokType which, bool dont_consume_braces )
{ {
// TODO(Ed): We can handle a macro a bit better than this. It's AST can be made more robust.. // TODO(Ed): We can handle a macro a bit better than this. It's AST can be made more robust..
@ -3305,7 +3305,7 @@ CodeVar parse_variable_declaration_list()
"(Parser will add and continue to specifiers, but will most likely fail to compile)\n%s" "(Parser will add and continue to specifiers, but will most likely fail to compile)\n%s"
, to_string(Context) ); , to_string(Context) );
append(specifiers, spec ); specifiers_append(specifiers, spec );
} }
break; break;
@ -3327,7 +3327,7 @@ CodeVar parse_variable_declaration_list()
// eat(currtok.Type); // eat(currtok.Type);
if ( specifiers ) if ( specifiers )
append(specifiers, spec ); specifiers_append(specifiers, spec );
else else
specifiers = def_specifier( spec ); specifiers = def_specifier( spec );
} }
@ -3467,7 +3467,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
if ( check( Tok_Spec_Virtual ) ) if ( check( Tok_Spec_Virtual ) )
{ {
if ( specifiers ) if ( specifiers )
append(specifiers, Spec_Virtual ); specifiers_append(specifiers, Spec_Virtual );
else else
specifiers = def_specifier( Spec_Virtual ); specifiers = def_specifier( Spec_Virtual );
eat( Tok_Spec_Virtual ); eat( Tok_Spec_Virtual );
@ -3510,7 +3510,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
eat( Tok_Number ); eat( Tok_Number );
// <Virtual Specifier> ~<Name>() = 0 // <Virtual Specifier> ~<Name>() = 0
append(specifiers, Spec_Pure ); specifiers_append(specifiers, Spec_Pure );
} }
else if ( left && str_compare_len( upcoming.Text, "default", sizeof("default") - 1 ) == 0) else if ( left && str_compare_len( upcoming.Text, "default", sizeof("default") - 1 ) == 0)
{ {
@ -3762,7 +3762,7 @@ CodeEnum parse_enum( bool inplace_def )
return InvalidCode; return InvalidCode;
} }
append(body, member ); body_append(body, member );
} }
eat( Tok_BraceCurly_Close ); eat( Tok_BraceCurly_Close );
@ -4206,7 +4206,7 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
specifiers = def_specifier( Spec_Const ); specifiers = def_specifier( Spec_Const );
else else
append(specifiers, Spec_Const ); specifiers_append(specifiers, Spec_Const );
eat( Tok_Spec_Const ); eat( Tok_Spec_Const );
} }
@ -4965,6 +4965,7 @@ CodeTypedef parse_typedef()
name = currtok; name = currtok;
eat(Tok_Identifier); eat(Tok_Identifier);
} }
// <ModuleFalgs> typedef <Preprocessed_Macro> <Identifier>
} }
else else
{ {
@ -5250,7 +5251,7 @@ CodeUnion parse_union( bool inplace_def )
} }
if ( member ) if ( member )
append(body, member ); body_append(body, member );
} }
// <ModuleFlags> union <Attributes> <Name> { <Body> // <ModuleFlags> union <Attributes> <Name> { <Body>

View File

@ -5,7 +5,6 @@
#endif #endif
#pragma region Basic Types #pragma region Basic Types
GEN_API_C_BEGIN
#define GEN_U8_MIN 0u #define GEN_U8_MIN 0u
#define GEN_U8_MAX 0xffu #define GEN_U8_MAX 0xffu
@ -127,14 +126,12 @@ typedef s32 b32;
typedef void* mem_ptr; typedef void* mem_ptr;
typedef void const* mem_ptr_const ; typedef void const* mem_ptr_const ;
#if ! GEN_COMPILER_C #if GEN_COMPILER_CPP
GEN_API_C_END
template<typename Type> uptr to_uptr( Type* ptr ) { return (uptr)ptr; } template<typename Type> uptr to_uptr( Type* ptr ) { return (uptr)ptr; }
template<typename Type> sptr to_sptr( Type* ptr ) { return (sptr)ptr; } template<typename Type> sptr to_sptr( Type* ptr ) { return (sptr)ptr; }
template<typename Type> mem_ptr to_mem_ptr ( Type ptr ) { return (mem_ptr) ptr; } template<typename Type> mem_ptr to_mem_ptr ( Type ptr ) { return (mem_ptr) ptr; }
template<typename Type> mem_ptr_const to_mem_ptr_const( Type ptr ) { return (mem_ptr_const)ptr; } template<typename Type> mem_ptr_const to_mem_ptr_const( Type ptr ) { return (mem_ptr_const)ptr; }
GEN_API_C_BEGIN
#else #else
#define to_uptr( ptr ) ((uptr)(ptr)) #define to_uptr( ptr ) ((uptr)(ptr))
#define to_sptr( ptr ) ((sptr)(ptr)) #define to_sptr( ptr ) ((sptr)(ptr))
@ -143,5 +140,4 @@ GEN_API_C_BEGIN
#define to_mem_ptr_const( ptr) ((mem_ptr)ptr) #define to_mem_ptr_const( ptr) ((mem_ptr)ptr)
#endif #endif
GEN_API_C_END
#pragma endregion Basic Types #pragma endregion Basic Types

View File

@ -26,12 +26,9 @@ template <class TType> using TRemovePtr = typename RemovePtr<TType>::Type;
struct ArrayHeader; struct ArrayHeader;
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_COMPILER_CPP
template<class Type> struct Array; template<class Type> struct Array;
# define get_array_underlying_type(array) typename TRemovePtr<typeof(array)>:: DataType # define get_array_underlying_type(array) typename TRemovePtr<typeof(array)>:: DataType
#else
template<class Type> using Array = Type*;
# define get_array_underlying_type(array) TRemovePtr<typeof(array)>
#endif #endif
usize array_grow_formula(ssize value); usize array_grow_formula(ssize value);
@ -62,7 +59,7 @@ struct ArrayHeader {
usize Num; usize Num;
}; };
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_COMPILER_CPP
template<class Type> template<class Type>
struct Array struct Array
{ {
@ -104,7 +101,7 @@ struct Array
}; };
#endif #endif
#if GEN_SUPPORT_CPP_REFERENCES #if GEN_COMPILER_CPP && 0
template<class Type> bool append(Array<Type>& array, Array<Type> other) { return GEN_NS append( & array, other ); } template<class Type> bool append(Array<Type>& array, Array<Type> other) { return GEN_NS append( & array, other ); }
template<class Type> bool append(Array<Type>& array, Type value) { return GEN_NS append( & array, value ); } template<class Type> bool append(Array<Type>& array, Type value) { return GEN_NS append( & array, value ); }
template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return GEN_NS append( & array, items, item_num ); } template<class Type> bool append(Array<Type>& array, Type* items, usize item_num) { return GEN_NS append( & array, items, item_num ); }

View File

@ -6,7 +6,6 @@
#endif #endif
#pragma region Debug #pragma region Debug
GEN_API_C_BEGIN
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... ) void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... )
{ {
@ -46,5 +45,4 @@ s32 assert_crash( char const* condition )
} }
#endif #endif
GEN_API_C_END
#pragma endregion Debug #pragma endregion Debug

View File

@ -56,10 +56,8 @@
while (0) while (0)
#endif #endif
GEN_API_C_BEGIN
void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... ); void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... );
s32 assert_crash( char const* condition ); s32 assert_crash( char const* condition );
void process_exit( u32 code ); void process_exit( u32 code );
GEN_API_C_END
#pragma endregion Debug #pragma endregion Debug

View File

@ -4,7 +4,6 @@
#endif #endif
#pragma region File Handling #pragma region File Handling
GEN_API_C_BEGIN
#if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN ) #if defined( GEN_SYSTEM_WINDOWS ) || defined( GEN_SYSTEM_CYGWIN )
@ -656,5 +655,4 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close }; FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };
GEN_API_C_END
#pragma endregion File Handling #pragma endregion File Handling

View File

@ -4,11 +4,10 @@
#endif #endif
#pragma region File Handling #pragma region File Handling
GEN_API_C_BEGIN
typedef u32 FileMode; typedef u32 FileMode;
enum FileModeFlag_Def enum FileModeFlag
{ {
EFileMode_READ = bit( 0 ), EFileMode_READ = bit( 0 ),
EFileMode_WRITE = bit( 1 ), EFileMode_WRITE = bit( 1 ),
@ -16,18 +15,16 @@ enum FileModeFlag_Def
EFileMode_RW = bit( 3 ), EFileMode_RW = bit( 3 ),
GEN_FILE_MODES = EFileMode_READ | EFileMode_WRITE | EFileMode_APPEND | EFileMode_RW, GEN_FILE_MODES = EFileMode_READ | EFileMode_WRITE | EFileMode_APPEND | EFileMode_RW,
}; };
typedef enum FileModeFlag_Def FileModeFlag;
// NOTE: Only used internally and for the file operations // NOTE: Only used internally and for the file operations
enum SeekWhenceType_Def enum SeekWhenceType
{ {
ESeekWhence_BEGIN = 0, ESeekWhence_BEGIN = 0,
ESeekWhence_CURRENT = 1, ESeekWhence_CURRENT = 1,
ESeekWhence_END = 2, ESeekWhence_END = 2,
}; };
typedef enum SeekWhenceType_Def SeekWhenceType;
enum FileError_Def enum FileError
{ {
EFileError_NONE, EFileError_NONE,
EFileError_INVALID, EFileError_INVALID,
@ -40,17 +37,15 @@ enum FileError_Def
EFileError_NAME_TOO_LONG, EFileError_NAME_TOO_LONG,
EFileError_UNKNOWN, EFileError_UNKNOWN,
}; };
typedef enum FileError_Def FileError;
union FileDescriptor_Def union FileDescriptor
{ {
void* p; void* p;
sptr i; sptr i;
uptr u; uptr u;
}; };
typedef union FileDescriptor_Def FileDescriptor;
typedef struct FileOperations_Def FileOperations; typedef struct FileOperations FileOperations;
#define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename ) #define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename )
#define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, ssize size, s64 offset, ssize* bytes_read, b32 stop_at_newline ) #define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, ssize size, s64 offset, ssize* bytes_read, b32 stop_at_newline )
@ -64,39 +59,35 @@ typedef GEN_FILE_WRITE_AT_PROC( FileWriteProc );
typedef GEN_FILE_SEEK_PROC( FileSeekProc ); typedef GEN_FILE_SEEK_PROC( FileSeekProc );
typedef GEN_FILE_CLOSE_PROC( FileCloseProc ); typedef GEN_FILE_CLOSE_PROC( FileCloseProc );
struct FileOperations_Def struct FileOperations
{ {
FileReadProc* read_at; FileReadProc* read_at;
FileWriteProc* write_at; FileWriteProc* write_at;
FileSeekProc* seek; FileSeekProc* seek;
FileCloseProc* close; FileCloseProc* close;
}; };
typedef struct FileOperations_Def FileOperations;
extern FileOperations const default_file_operations; extern FileOperations const default_file_operations;
typedef u64 FileTime; typedef u64 FileTime;
enum DirType_Def enum DirType
{ {
GEN_DIR_TYPE_FILE, GEN_DIR_TYPE_FILE,
GEN_DIR_TYPE_FOLDER, GEN_DIR_TYPE_FOLDER,
GEN_DIR_TYPE_UNKNOWN, GEN_DIR_TYPE_UNKNOWN,
}; };
typedef enum DirType_Def DirType;
struct DirInfo_Def; struct DirInfo;
typedef struct DirInfo_Def DirInfo;
struct DirEntry_Def struct DirEntry
{ {
char const* filename; char const* filename;
DirInfo* dir_info; DirInfo* dir_info;
u8 type; u8 type;
}; };
typedef struct DirEntry_Def DirEntry;
struct DirInfo_Def struct DirInfo
{ {
char const* fullpath; char const* fullpath;
DirEntry* entries; // zpl_array DirEntry* entries; // zpl_array
@ -106,7 +97,7 @@ struct DirInfo_Def
String buf; String buf;
}; };
struct FileInfo_Def struct FileInfo
{ {
FileOperations ops; FileOperations ops;
FileDescriptor fd; FileDescriptor fd;
@ -116,9 +107,9 @@ struct FileInfo_Def
FileTime last_write_time; FileTime last_write_time;
DirEntry* dir; DirEntry* dir;
}; };
typedef struct FileInfo_Def FileInfo; typedef struct FileInfo FileInfo;
enum FileStandardType_Def enum FileStandardType
{ {
EFileStandard_INPUT, EFileStandard_INPUT,
EFileStandard_OUTPUT, EFileStandard_OUTPUT,
@ -126,7 +117,7 @@ enum FileStandardType_Def
EFileStandard_COUNT, EFileStandard_COUNT,
}; };
typedef enum FileStandardType_Def FileStandardType; typedef enum FileStandardType FileStandardType;
/** /**
* Get standard file I/O. * Get standard file I/O.
@ -269,7 +260,7 @@ b32 file_write_at( FileInfo* file, void const* buffer, ssize size, s64 offset );
*/ */
b32 file_write_at_check( FileInfo* file, void const* buffer, ssize size, s64 offset, ssize* bytes_written ); b32 file_write_at_check( FileInfo* file, void const* buffer, ssize size, s64 offset, ssize* bytes_written );
enum FileStreamFlags_Def enum_underlying(u32) enum FileStreamFlags : u32
{ {
/* Allows us to write to the buffer directly. Beware: you can not append a new data! */ /* Allows us to write to the buffer directly. Beware: you can not append a new data! */
EFileStream_WRITABLE = bit( 0 ), EFileStream_WRITABLE = bit( 0 ),
@ -280,7 +271,6 @@ enum FileStreamFlags_Def enum_underlying(u32)
EFileStream_UNDERLYING = GEN_U32_MAX, EFileStream_UNDERLYING = GEN_U32_MAX,
}; };
typedef enum FileStreamFlags_Def FileStreamFlags;
/** /**
* Opens a new memory stream * Opens a new memory stream
@ -396,5 +386,4 @@ b32 file_write_at_check( FileInfo* f, void const* buffer, ssize size, s64 offset
return f->ops.write_at( f->fd, buffer, size, offset, bytes_written ); return f->ops.write_at( f->fd, buffer, size, offset, bytes_written );
} }
GEN_API_C_END
#pragma endregion File Handling #pragma endregion File Handling

View File

@ -4,7 +4,6 @@
#endif #endif
#pragma region Hashing #pragma region Hashing
GEN_API_C_BEGIN
global u32 const _crc32_table[ 256 ] = { global u32 const _crc32_table[ 256 ] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd,
@ -88,5 +87,4 @@ u64 crc64( void const* data, ssize len )
return result; return result;
} }
GEN_API_C_END
#pragma endregion Hashing #pragma endregion Hashing

View File

@ -4,10 +4,8 @@
#endif #endif
#pragma region Hashing #pragma region Hashing
GEN_API_C_BEGIN
u32 crc32( void const* data, ssize len ); u32 crc32( void const* data, ssize len );
u64 crc64( void const* data, ssize len ); u64 crc64( void const* data, ssize len );
GEN_API_C_END
#pragma endregion Hashing #pragma endregion Hashing

View File

@ -19,10 +19,22 @@
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) ) #define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
#endif #endif
// Mainly intended for forcing the base library to utilize only C-valid constructs or type coercion
#ifndef GEN_C_LIKE_CPP
#define GEN_C_LIKE_CPP 0
#endif
#if GEN_COMPILER_CPP #if GEN_COMPILER_CPP
# ifndef cast # ifndef cast
# define cast( type, value ) (tmpl_cast<type>( value )) # define cast( type, value ) (tmpl_cast<type>( value ))
# endif # endif
#else
# ifndef cast
# define cast( type, value ) ( (type)(value) )
# endif
#endif
#if GEN_COMPILER_CPP
# ifndef ccast # ifndef ccast
# define ccast( type, value ) ( const_cast< type >( (value) ) ) # define ccast( type, value ) ( const_cast< type >( (value) ) )
# endif # endif
@ -36,9 +48,6 @@
# define scast( type, value ) static_cast< type >( value ) # define scast( type, value ) static_cast< type >( value )
# endif # endif
#else #else
# ifndef cast
# define cast( type, value ) ( (type)(value) )
# endif
# ifndef ccast # ifndef ccast
# define ccast( type, value ) ( (type)(value) ) # define ccast( type, value ) ( (type)(value) )
# endif # endif
@ -210,22 +219,6 @@
# error "No thread local support" # error "No thread local support"
#endif #endif
#if !defined(GEN_SUPPORT_CPP_REFERENCES)
# define GEN_SUPPORT_CPP_REFERENCES 1
#endif
#if GEN_COMPILER_C && defined(GEN_SUPPORT_CPP_REFERENCES)
# undef GEN_SUPPORT_CPP_REFERENCES
# define GEN_SUPPORT_CPP_REFERENCES 0
#endif
#if !defined(GEN_SUPPORT_CPP_MEMBER_FEATURES)
# define GEN_SUPPORT_CPP_MEMBER_FEATURES 1
#endif
#if GEN_COMPILER_C && defined(GEN_SUPPORT_CPP_MEMBER_FEATURES)
# undef GEN_SUPPORT_CPP_MEMBER_FEATURES
# define GEN_SUPPORT_CPP_MEMBER_FEATURES 0
#endif
#if ! defined(typeof) && (!GEN_COMPILER_C || __STDC_VERSION__ < 202311L) #if ! defined(typeof) && (!GEN_COMPILER_C || __STDC_VERSION__ < 202311L)
# if ! GEN_COMPILER_C # if ! GEN_COMPILER_C
# define typeof decltype # define typeof decltype
@ -239,12 +232,12 @@
#endif #endif
#ifndef GEN_API_C_BEGIN #ifndef GEN_API_C_BEGIN
# if GEN_COMPILER_C || (GEN_COMPILER_CPP && GEN_SUPPORT_CPP_REFERENCES) # if GEN_COMPILER_C
# define GEN_API_C_BEGIN # define GEN_API_C_BEGIN
# define GEN_API_C_END # define GEN_API_C_END
# else # else
# define GEN_API_C_BEGIN extern "C" { # define GEN_API_C_BEGIN extern "C" {
# define GEN_API_C_END } # define GEN_API_C_END }
# endif # endif
#endif #endif
@ -280,6 +273,16 @@
#define struct_init(type, value) {value} #define struct_init(type, value) {value}
#endif #endif
#if 0
#ifndef GEN_OPTIMIZE_MAPPINGS_BEGIN
# define GEN_OPTIMIZE_MAPPINGS_BEGIN _pragma(optimize("gt", on))
# define GEN_OPITMIZE_MAPPINGS_END _pragma(optimize("", on))
#endif
#else
# define GEN_OPTIMIZE_MAPPINGS_BEGIN
# define GEN_OPITMIZE_MAPPINGS_END
#endif
#if GEN_COMPILER_C #if GEN_COMPILER_C
// ------------------------ _Generic function overloading ----------------------------------------- // ------------------------ _Generic function overloading -----------------------------------------
// This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in: // This implemnents macros for utilizing "The Naive Extendible _Generic Macro" explained in:
@ -295,12 +298,7 @@
// Helper macros for argument selection // Helper macros for argument selection
#define GEN_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1. #define GEN_SELECT_ARG_1( _1, ... ) _1 // <-- Of all th args passed pick _1.
#define GEN_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2. #define GEN_SELECT_ARG_2( _1, _2, ... ) _2 // <-- Of all the args passed pick _2.
#define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc.. (by induction until _8, which we don't support any more beyond) #define GEN_SELECT_ARG_3( _1, _2, _3, ... ) _3 // etc..
// #define GEN_SELECT_ARG_4( _1, _2, _3, _4, ... ) _4
// #define GEN_SELECT_ARG_5( _1, _2, _3, _4, _5, ... ) _5
// #define GEN_SELECT_ARG_6( _1, _2, _3, _4, _5, _6, ... ) _6
// #define GEN_SELECT_ARG_7( _1, _2, _3, _4, _5, _6, _7, ... ) _7
// #define GEN_SELECT_ARG_8( _1, _2, _3, _4, _5, _6, _7, _8, ... ) _8
#define GEN_GENERIC_SEL_ENTRY_TYPE GEN_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type. #define GEN_GENERIC_SEL_ENTRY_TYPE GEN_SELECT_ARG_1 // Use the arg expansion macro to select arg 1 which should have the type.
#define GEN_GENERIC_SEL_ENTRY_FUNCTION GEN_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function. #define GEN_GENERIC_SEL_ENTRY_FUNCTION GEN_SELECT_ARG_2 // Use the arg expansion macro to select arg 2 which should have the function.
@ -314,10 +312,10 @@
// Expands to ',' if it can find (type): (function) <comma_operator: ',' > // Expands to ',' if it can find (type): (function) <comma_operator: ',' >
// Where GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> , // Where GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER is specifically looking for that <comma> ,
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) GEN_COMMA_OPERATOR, , ) #define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ) GEN_COMMA_OPERATOR, , )
// ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma // ^ Selects the comma ^ is the type ^ is the function ^ Insert a comma
// The slot won't exist if that comma is not found. | // The slot won't exist if that comma is not found. |
// | // |
// This is the same as above but it does not insert a comma V no comma here. // This is the same as above but it does not insert a comma V no comma here.
#define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ), , ) #define GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( slot_exp ) GEN_GENERIC_SEL_ENTRY_COMMA_DELIMITER( slot_exp, GEN_GENERIC_SEL_ENTRY_TYPE( slot_exp, ): GEN_GENERIC_SEL_ENTRY_FUNCTION( slot_exp, ), , )
// Needed for the last slot as they don't allow trailing commas. // Needed for the last slot as they don't allow trailing commas.
// ---------------------------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------------------
@ -392,6 +390,7 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u
// typedef void* GEN_GenericExampleType; // typedef void* GEN_GenericExampleType;
// GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType ); // GEN_FUNCTION_GENERIC_EXAMPLE_DIRECT_TYPE( GEN_GenericExampleType );
// END OF ------------------------ _Generic function overloading ----------------------------------------- END OF // END OF ------------------------ _Generic function overloading ----------------------------------------- END OF
#endif #endif

View File

@ -4,13 +4,12 @@
#endif #endif
#pragma region Memory #pragma region Memory
GEN_API_C_BEGIN
void* mem_copy( void* dest, void const* source, ssize n ) void* mem_copy( void* dest, void const* source, ssize n )
{ {
if ( dest == NULL ) if ( dest == nullptr )
{ {
return NULL; return nullptr;
} }
return memcpy( dest, source, n ); return memcpy( dest, source, n );
@ -518,5 +517,4 @@ void pool_clear(Pool* pool)
pool->FreeList = pool->PhysicalStart; pool->FreeList = pool->PhysicalStart;
} }
GEN_API_C_END
#pragma endregion Memory #pragma endregion Memory

View File

@ -22,8 +22,6 @@ void swap( Type& a, Type& b )
b = tmp; b = tmp;
} }
GEN_API_C_BEGIN
//! Checks if value is power of 2. //! Checks if value is power of 2.
b32 is_power_of_two( ssize x ); b32 is_power_of_two( ssize x );
@ -64,23 +62,21 @@ void zero_size( void* ptr, ssize size );
//! Clears up an array. //! Clears up an array.
#define zero_array( a, count ) zero_size( ( a ), size_of( *( a ) ) * count ) #define zero_array( a, count ) zero_size( ( a ), size_of( *( a ) ) * count )
enum AllocType_Def //enum_underlying(u8) enum AllocType : u8
{ {
EAllocation_ALLOC, EAllocation_ALLOC,
EAllocation_FREE, EAllocation_FREE,
EAllocation_FREE_ALL, EAllocation_FREE_ALL,
EAllocation_RESIZE, EAllocation_RESIZE,
}; };
typedef enum AllocType_Def AllocType;
typedef void*(AllocatorProc)( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ); typedef void*(AllocatorProc)( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags );
struct AllocatorInfo_Def struct AllocatorInfo
{ {
AllocatorProc* Proc; AllocatorProc* Proc;
void* Data; void* Data;
}; };
typedef struct AllocatorInfo_Def AllocatorInfo;
enum AllocFlag enum AllocFlag
{ {
@ -144,12 +140,11 @@ constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocato
//! Helper to free memory allocated by heap allocator. //! Helper to free memory allocated by heap allocator.
#define mfree( ptr ) free( heap(), ptr ) #define mfree( ptr ) free( heap(), ptr )
struct VirtualMemory_Def struct VirtualMemory
{ {
void* data; void* data;
ssize size; ssize size;
}; };
typedef struct VirtualMemory_Def VirtualMemory;
//! Initialize virtual memory from existing data. //! Initialize virtual memory from existing data.
VirtualMemory vm_from_memory( void* data, ssize size ); VirtualMemory vm_from_memory( void* data, ssize size );
@ -173,8 +168,7 @@ b32 vm_purge( VirtualMemory vm );
ssize virtual_memory_page_size( ssize* alignment_out ); ssize virtual_memory_page_size( ssize* alignment_out );
#pragma region Arena #pragma region Arena
struct Arena_Def; struct Arena;
typedef struct Arena_Def Arena;
AllocatorInfo arena_allocator_info( Arena* arena ); AllocatorInfo arena_allocator_info( Arena* arena );
@ -191,7 +185,7 @@ void arena_check (Arena* arena);
void arena_free (Arena* arena); void arena_free (Arena* arena);
ssize arena_size_remaining(Arena* arena, ssize alignment); ssize arena_size_remaining(Arena* arena, ssize alignment);
struct Arena_Def struct Arena
{ {
AllocatorInfo Backing; AllocatorInfo Backing;
void* PhysicalStart; void* PhysicalStart;
@ -199,7 +193,7 @@ struct Arena_Def
ssize TotalUsed; ssize TotalUsed;
ssize TempCount; ssize TempCount;
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_COMPILER_CPP
#pragma region Member Mapping #pragma region Member Mapping
forceinline operator AllocatorInfo() { return GEN_NS arena_allocator_info(this); } forceinline operator AllocatorInfo() { return GEN_NS arena_allocator_info(this); }
@ -221,8 +215,7 @@ struct Arena_Def
#endif #endif
}; };
#if GEN_SUPPORT_CPP_REFERENCES #if GEN_COMPILER_CPP
GEN_API_C_END
forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); } forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); }
forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); } forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); }
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); } forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); }
@ -234,7 +227,6 @@ forceinline ssize size_remaining(Arena& arena, ssize alignment) { return
#undef check #undef check
forceinline void check(Arena& arena) { return arena_check(& arena); }; forceinline void check(Arena& arena) { return arena_check(& arena); };
#pragma pop_macro("check") #pragma pop_macro("check")
GEN_API_C_BEGIN
#endif #endif
@ -320,8 +312,6 @@ ssize arena_size_remaining(Arena* arena, ssize alignment)
} }
#pragma endregion Arena #pragma endregion Arena
GEN_API_C_END
#pragma region FixedArena #pragma region FixedArena
template<s32 Size> template<s32 Size>
struct FixedArena; struct FixedArena;
@ -330,7 +320,7 @@ template<s32 Size> FixedArena<Size> fixed_arena_init();
template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena ); template<s32 Size> AllocatorInfo fixed_arena_allocator_info(FixedArena<Size>* fixed_arena );
template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment); template<s32 Size> ssize fixed_arena_size_remaining(FixedArena<Size>* fixed_arena, ssize alignment);
#if GEN_SUPPORT_CPP_REFERENCES #if 0
template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); } template<s32 Size> AllocatorInfo allocator_info( FixedArena<Size>& fixed_arena ) { return allocator_info(& fixed_arena); }
template<s32 Size> ssize size_remaining(FixedArena<Size>& fixed_arena, ssize alignment) { return size_remaining( & fixed_arena, alignment); } template<s32 Size> ssize size_remaining(FixedArena<Size>& fixed_arena, ssize alignment) { return size_remaining( & fixed_arena, alignment); }
#endif #endif
@ -343,7 +333,7 @@ struct FixedArena
char memory[Size]; char memory[Size];
Arena arena; Arena arena;
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if 0
#pragma region Member Mapping #pragma region Member Mapping
forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); } forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); }
@ -389,11 +379,8 @@ using Arena_2MB = FixedArena< megabytes( 2 ) >;
using Arena_4MB = FixedArena< megabytes( 4 ) >; using Arena_4MB = FixedArena< megabytes( 4 ) >;
#pragma endregion FixedArena #pragma endregion FixedArena
GEN_API_C_BEGIN
#pragma region Pool #pragma region Pool
struct Pool_Def; struct Pool;
typedef struct Pool_Def Pool;
void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags); void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
@ -403,15 +390,13 @@ AllocatorInfo pool_allocator_info(Pool* pool);
void pool_clear(Pool* pool); void pool_clear(Pool* pool);
void pool_free(Pool* pool); void pool_free(Pool* pool);
#if GEN_SUPPORT_CPP_REFERENCES #if 0
GEN_API_C_END
AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); } AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); }
void clear(Pool& pool) { return pool_clear(& pool); } void clear(Pool& pool) { return pool_clear(& pool); }
void free(Pool& pool) { return pool_free(& pool); } void free(Pool& pool) { return pool_free(& pool); }
GEN_API_C_BEGIN
#endif #endif
struct Pool_Def struct Pool
{ {
AllocatorInfo Backing; AllocatorInfo Backing;
void* PhysicalStart; void* PhysicalStart;
@ -421,7 +406,7 @@ struct Pool_Def
ssize TotalSize; ssize TotalSize;
ssize NumBlocks; ssize NumBlocks;
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if ! GEN_C_LIKE_CPP
#pragma region Member Mapping #pragma region Member Mapping
forceinline operator AllocatorInfo() { return GEN_NS pool_allocator_info(this); } forceinline operator AllocatorInfo() { return GEN_NS pool_allocator_info(this); }
@ -684,6 +669,4 @@ void zero_size( void* ptr, ssize size ) {
mem_set( ptr, 0, size ); mem_set( ptr, 0, size );
} }
GEN_API_C_END
#pragma endregion Memory #pragma endregion Memory

View File

@ -4,7 +4,6 @@
#endif #endif
#pragma region ADT #pragma region ADT
GEN_API_C_BEGIN
#define _adt_fprintf( s_, fmt_, ... ) \ #define _adt_fprintf( s_, fmt_, ... ) \
do \ do \
@ -1112,5 +1111,4 @@ String csv_write_string_delimiter( AllocatorInfo a, CSV_Object* obj, char delimi
return output; return output;
} }
GEN_API_C_END
#pragma endregion CSV #pragma endregion CSV

View File

@ -3,7 +3,6 @@
#endif #endif
#pragma region ADT #pragma region ADT
GEN_API_C_BEGIN
enum ADT_Type : u32 enum ADT_Type : u32
{ {
@ -430,5 +429,4 @@ String csv_write_string( AllocatorInfo a, CSV_Object* obj )
return csv_write_string_delimiter( a, obj, ',' ); return csv_write_string_delimiter( a, obj, ',' );
} }
GEN_API_C_END
#pragma endregion CSV #pragma endregion CSV

View File

@ -76,17 +76,20 @@
/* Platform compiler */ /* Platform compiler */
#if defined( _MSC_VER ) #if defined( _MSC_VER )
# define GEN_COMPILER_CLANG 0 # pragma message("Detected MSVC")
// # define GEN_COMPILER_CLANG 0
# define GEN_COMPILER_MSVC 1 # define GEN_COMPILER_MSVC 1
# define GEN_COMPILER_GCC 0 // # define GEN_COMPILER_GCC 0
#elif defined( __GNUC__ ) #elif defined( __GNUC__ )
# define GEN_COMPILER_CLANG 0 # pragma message("Detected GCC")
# define GEN_COMPILER_MSVC 0 // # define GEN_COMPILER_CLANG 0
// # define GEN_COMPILER_MSVC 0
# define GEN_COMPILER_GCC 1 # define GEN_COMPILER_GCC 1
#elif defined( __clang__ ) #elif defined( __clang__ )
# pragma message("Detected CLANG")
# define GEN_COMPILER_CLANG 1 # define GEN_COMPILER_CLANG 1
# define GEN_COMPILER_MSVC 0 // # define GEN_COMPILER_MSVC 0
# define GEN_COMPILER_GCC 1 // # define GEN_COMPILER_GCC 0
#else #else
# error Unknown compiler # error Unknown compiler
#endif #endif

View File

@ -6,7 +6,6 @@
#endif #endif
#pragma region Printing #pragma region Printing
GEN_API_C_BEGIN
enum enum
{ {
@ -598,5 +597,4 @@ ssize str_fmt_out_err( char const* fmt, ... )
return res; return res;
} }
GEN_API_C_END
#pragma endregion Printing #pragma endregion Printing

View File

@ -5,9 +5,7 @@
#pragma region Printing #pragma region Printing
GEN_API_C_BEGIN typedef struct FileInfo FileInfo;
typedef struct FileInfo_Def FileInfo;
#ifndef GEN_PRINTF_MAXLEN #ifndef GEN_PRINTF_MAXLEN
# define GEN_PRINTF_MAXLEN kilobytes(128) # define GEN_PRINTF_MAXLEN kilobytes(128)
@ -41,6 +39,4 @@ ssize log_fmt(char const* fmt, ...)
return res; return res;
} }
GEN_API_C_END
#pragma endregion Printing #pragma endregion Printing

View File

@ -5,7 +5,6 @@
#endif #endif
#pragma region String Ops #pragma region String Ops
GEN_API_C_BEGIN
internal internal
ssize _scan_zpl_i64( const char* text, s32 base, s64* value ) ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
@ -213,5 +212,4 @@ f64 str_to_f64( const char* str, char** end_ptr )
return result; return result;
} }
GEN_API_C_END
#pragma endregion String Ops #pragma endregion String Ops

View File

@ -5,8 +5,6 @@
#pragma region String Ops #pragma region String Ops
GEN_API_C_BEGIN
const char* char_first_occurence( const char* str, char c ); const char* char_first_occurence( const char* str, char c );
b32 char_is_alpha( char c ); b32 char_is_alpha( char c );
@ -286,6 +284,4 @@ void str_to_upper( char* str )
} }
} }
GEN_API_C_END
#pragma endregion String Ops #pragma endregion String Ops

View File

@ -4,7 +4,6 @@
#endif #endif
#pragma region String #pragma region String
GEN_API_C_BEGIN
String string_make_length( AllocatorInfo allocator, char const* str, ssize length ) String string_make_length( AllocatorInfo allocator, char const* str, ssize length )
{ {
@ -54,5 +53,4 @@ String string_make_reserve( AllocatorInfo allocator, ssize capacity )
return result; return result;
} }
GEN_API_C_END
#pragma endregion String #pragma endregion String

View File

@ -5,8 +5,6 @@
#pragma region Strings #pragma region Strings
GEN_API_C_BEGIN
struct StrC_Def; struct StrC_Def;
typedef struct StrC_Def StrC; typedef struct StrC_Def StrC;
@ -18,8 +16,6 @@ b32 strc_starts_with (StrC str, StrC substring);
StrC strc_to_str (char const* bad_string); StrC strc_to_str (char const* bad_string);
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator); StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
GEN_API_C_END
// Constant string with length. // Constant string with length.
struct StrC_Def struct StrC_Def
{ {
@ -30,7 +26,7 @@ struct StrC_Def
forceinline operator char const* () const { return Ptr; } forceinline operator char const* () const { return Ptr; }
forceinline char const& operator[]( ssize index ) const { return Ptr[index]; } forceinline char const& operator[]( ssize index ) const { return Ptr[index]; }
#if GEN_SUPPORT_CPP_MEMBER_FEATURES #if ! GEN_C_LIKE_CPP
forceinline bool is_equal (StrC rhs) const { return GEN_NS strc_are_equal(* this, rhs); } forceinline bool is_equal (StrC rhs) const { return GEN_NS strc_are_equal(* this, rhs); }
forceinline char const* back () const { return GEN_NS strc_back(* this); } forceinline char const* back () const { return GEN_NS strc_back(* this); }
forceinline bool contains (StrC substring) const { return GEN_NS strc_contains(* this, substring); } forceinline bool contains (StrC substring) const { return GEN_NS strc_contains(* this, substring); }
@ -63,8 +59,6 @@ forceinline char const* end (StrC str) { return str.Ptr + str
forceinline char const* next (StrC str, char const* iter) { return iter + 1; } forceinline char const* next (StrC str, char const* iter) { return iter + 1; }
#endif #endif
GEN_API_C_BEGIN
inline inline
bool strc_are_equal(StrC lhs, StrC rhs) bool strc_are_equal(StrC lhs, StrC rhs)
{ {
@ -113,24 +107,21 @@ StrC to_strc_from_c_str( char const* bad_str ) {
StrC result = { str_len( bad_str ), bad_str }; StrC result = { str_len( bad_str ), bad_str };
return result; return result;
} }
GEN_API_C_END
// Dynamic String // Dynamic String
// This is directly based off the ZPL string api. // This is directly based off the ZPL string api.
// They used a header pattern // They used a header pattern
// I kept it for simplicty of porting but its not necessary to keep it that way. // I kept it for simplicty of porting but its not necessary to keep it that way.
#pragma region String #pragma region String
struct StringHeader_Def; struct StringHeader;
typedef struct StringHeader_Def StringHeader; typedef struct StringHeader StringHeader;
#if GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_COMPILER_C
typedef char* String; typedef char* String;
#else #else
struct String; struct String;
#endif #endif
GEN_API_C_BEGIN
forceinline usize string_grow_formula(usize value); forceinline usize string_grow_formula(usize value);
String string_make_c_str (AllocatorInfo allocator, char const* str); String string_make_c_str (AllocatorInfo allocator, char const* str);
@ -168,15 +159,13 @@ void string_trim (String str, char const* cut_set)
void string_trim_space (String str); void string_trim_space (String str);
String string_visualize_whitespace(String const str); String string_visualize_whitespace(String const str);
GEN_API_C_END struct StringHeader {
struct StringHeader_Def {
AllocatorInfo Allocator; AllocatorInfo Allocator;
ssize Capacity; ssize Capacity;
ssize Length; ssize Length;
}; };
#if GEN_COMPILER_CPP && GEN_SUPPORT_CPP_MEMBER_FEATURES #if GEN_COMPILER_CPP
struct String struct String
{ {
char* Data; char* Data;
@ -203,6 +192,7 @@ struct String
friend forceinline bool operator==(std::nullptr_t, const String str) { return str.Data == nullptr; } friend forceinline bool operator==(std::nullptr_t, const String str) { return str.Data == nullptr; }
friend forceinline bool operator!=(std::nullptr_t, const String str) { return str.Data != nullptr; } friend forceinline bool operator!=(std::nullptr_t, const String str) { return str.Data != nullptr; }
#if ! GEN_C_LIKE_CPP
forceinline char* begin() const { return Data; } forceinline char* begin() const { return Data; }
forceinline char* end() const { return Data + string_length(* this); } forceinline char* end() const { return Data + string_length(* this); }
@ -273,6 +263,7 @@ struct String
return string_append_c_str_len(this, buf, res); return string_append_c_str_len(this, buf, res);
} }
#pragma endregion Member Mapping #pragma endregion Member Mapping
#endif
}; };
#endif #endif
@ -282,13 +273,13 @@ forceinline char* string_end (String str) { return ((char*) s
forceinline char* string_next (String str, char const* iter) { return ((char*) iter + 1); } forceinline char* string_next (String str, char const* iter) { return ((char*) iter + 1); }
GEN_API_C_END GEN_API_C_END
#if GEN_COMPILER_CPP && 0 #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline char* begin(String str) { return ((char*) str); } forceinline char* begin(String str) { return ((char*) str); }
forceinline char* end (String str) { return ((char*) str + string_length(str)); } forceinline char* end (String str) { return ((char*) str + string_length(str)); }
forceinline char* next (String str, char* iter) { return ((char*) iter + 1); } forceinline char* next (String str, char* iter) { return ((char*) iter + 1); }
#endif #endif
#if GEN_SUPPORT_CPP_REFERENCES #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline bool make_space_for(String& str, char const* to_append, ssize add_len); forceinline bool make_space_for(String& str, char const* to_append, ssize add_len);
forceinline bool append(String& str, char c); forceinline bool append(String& str, char c);
forceinline bool append(String& str, char const* str_to_append); forceinline bool append(String& str, char const* str_to_append);
@ -301,8 +292,6 @@ forceinline void clear(String& str);
forceinline void free(String& str); forceinline void free(String& str);
#endif #endif
GEN_API_C_BEGIN
forceinline forceinline
usize string_grow_formula(usize value) { usize string_grow_formula(usize value) {
// Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library. // Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library.
@ -755,8 +744,6 @@ StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator)
// Should never be modified, if changed string is desired, cache_string( str ) another. // Should never be modified, if changed string is desired, cache_string( str ) another.
typedef StrC StringCached; typedef StrC StringCached;
GEN_API_C_END
// Implements basic string interning. Data structure is based off the ZPL Hashtable. // Implements basic string interning. Data structure is based off the ZPL Hashtable.
typedef HashTable(StringCached) StringTable; typedef HashTable(StringCached) StringTable;
#pragma endregion Strings #pragma endregion Strings

View File

@ -4,7 +4,6 @@
#endif #endif
#pragma region Timing #pragma region Timing
GEN_API_C_BEGIN
#ifdef GEN_BENCHMARK #ifdef GEN_BENCHMARK
#if defined( GEN_COMPILER_MSVC ) && ! defined( __clang__ ) #if defined( GEN_COMPILER_MSVC ) && ! defined( __clang__ )
@ -165,5 +164,4 @@ GEN_API_C_BEGIN
} }
#endif #endif
GEN_API_C_END
#pragma endregion Timing #pragma endregion Timing

View File

@ -5,8 +5,6 @@
#pragma region Timing #pragma region Timing
GEN_API_C_BEGIN
#ifdef GEN_BENCHMARK #ifdef GEN_BENCHMARK
//! Return CPU timestamp. //! Return CPU timestamp.
u64 read_cpu_time_stamp_counter( void ); u64 read_cpu_time_stamp_counter( void );
@ -18,6 +16,4 @@ f64 time_rel( void );
u64 time_rel_ms( void ); u64 time_rel_ms( void );
#endif #endif
GEN_API_C_END
#pragma endregion Timing #pragma endregion Timing

View File

@ -8,7 +8,7 @@ GEN_NS_END
using namespace gen; using namespace gen;
CodeBody gen_ecode( char const* path ) CodeBody gen_ecode( char const* path, bool use_c_definition = false )
{ {
char scratch_mem[kilobytes(1)]; char scratch_mem[kilobytes(1)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) ); Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
@ -31,14 +31,24 @@ CodeBody gen_ecode( char const* path )
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code ); string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
} }
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries), CodeEnum enum_code;
"enum CodeType_Def enum_underlying(u32) { <entries> CT_NumTypes };" if (use_c_definition)
)); {
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
"enum CodeType enum_underlying(u32) { <entries> CT_NumTypes };"
));
}
else
{
enum_code = parse_enum(token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
"enum CodeType : u32 { <entries> CT_NumTypes };"
));
}
#pragma push_macro("local_persist") #pragma push_macro("local_persist")
#undef local_persist #undef local_persist
StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) )); StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) ));
CodeFn to_str = parse_function( token_fmt( CodeFn to_str = parse_function( token_fmt(
"entries", string_to_strc(to_str_entries) "entries", string_to_strc(to_str_entries)
, "num", lookup_size , "num", lookup_size
, stringize( , stringize(
@ -57,12 +67,12 @@ CodeBody gen_ecode( char const* path )
//CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) ); //CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) );
//CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) ); //CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) );
CodeTypedef code_t = parse_typedef(code(typedef enum CodeType_Def CodeType; )); CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; ));
return def_global_body( args( enum_code, code_t, to_str, fmt_newline ) ); return def_global_body( args( enum_code, code_t, to_str, fmt_newline ) );
} }
CodeBody gen_eoperator( char const* path ) CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
{ {
char scratch_mem[kilobytes(4)]; char scratch_mem[kilobytes(4)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) ); Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
@ -87,16 +97,30 @@ CodeBody gen_eoperator( char const* path )
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
} }
#pragma push_macro("enum_underlying") CodeEnum enum_code;
#undef enum_underlying if (use_c_definition)
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize( {
enum Operator_Def enum_underlying(u32) #pragma push_macro("enum_underlying")
{ #undef enum_underlying
<entries> enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
NumOps enum Operator enum_underlying(u32)
}; {
))); <entries>
#pragma pop_macro("enum_underlying") NumOps
};
)));
#pragma pop_macro("enum_underlying")
}
else
{
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
enum Operator : u32
{
<entries>
NumOps
};
)));
}
#pragma push_macro("local_persist") #pragma push_macro("local_persist")
#undef local_persist #undef local_persist
@ -120,12 +144,12 @@ CodeBody gen_eoperator( char const* path )
//CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) ); //CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
//CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) ); //CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator_Def Operator; )); CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; ));
return def_global_body( args( enum_code, operator_t, to_str, fmt_newline ) ); return def_global_body( args( enum_code, operator_t, to_str, fmt_newline ) );
} }
CodeBody gen_especifier( char const* path ) CodeBody gen_especifier( char const* path, bool use_c_definition = false )
{ {
char scratch_mem[kilobytes(4)]; char scratch_mem[kilobytes(4)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) ); Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
@ -150,16 +174,30 @@ CodeBody gen_especifier( char const* path )
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str); string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
} }
#pragma push_macro("enum_underlying") CodeEnum enum_code;
#undef enum_underlying if (use_c_definition)
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize( {
enum Specifier_Def enum_underlying(u32) #pragma push_macro("enum_underlying")
{ #undef enum_underlying
<entries> enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
Spec_NumSpecifiers enum Specifier enum_underlying(u32)
}; {
))); <entries>
#pragma pop_macro("enum_underlying") Spec_NumSpecifiers
};
)));
#pragma pop_macro("enum_underlying")
}
else
{
enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
enum Specifier : u32
{
<entries>
Spec_NumSpecifiers
};
)));
}
CodeFn is_trailing = parse_function(token_fmt("specifier", string_to_strc(to_str_entries), stringize( CodeFn is_trailing = parse_function(token_fmt("specifier", string_to_strc(to_str_entries), stringize(
inline inline
@ -233,7 +271,7 @@ CodeBody gen_especifier( char const* path )
//CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) ); //CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) );
//CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) ); //CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) );
CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier_Def Specifier; )); CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier Specifier; ));
return def_global_body( args( enum_code, specifier_t, is_trailing, to_str, to_type, fmt_newline ) ); return def_global_body( args( enum_code, specifier_t, is_trailing, to_str, to_type, fmt_newline ) );
} }
@ -384,7 +422,7 @@ CodeBody gen_ast_inlines()
inline inline
<typename>& <typename>::operator =( Code other ) <typename>& <typename>::operator =( Code other )
{ {
if ( other.ast && other->Parent ) 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->Parent = { nullptr };
@ -451,36 +489,39 @@ CodeBody gen_ast_inlines()
CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl )); CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl ));
CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl )); CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl ));
append(impl_code_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl ))); body_append(impl_code_attr, parse_global_body( token_fmt( "typename", StrC name(Attributes), codetype_impl_tmpl )));
append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl ))); body_append(impl_code_cmt, parse_global_body( token_fmt( "typename", StrC name(Comment), codetype_impl_tmpl )));
append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl ))); body_append(impl_code_constr, parse_global_body( token_fmt( "typename", StrC name(Constructor), codetype_impl_tmpl )));
append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl ))); body_append(impl_code_define, parse_global_body( token_fmt( "typename", StrC name(Define), codetype_impl_tmpl )));
append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl ))); body_append(impl_code_destruct, parse_global_body( token_fmt( "typename", StrC name(Destructor), codetype_impl_tmpl )));
append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl ))); body_append(impl_code_enum, parse_global_body( token_fmt( "typename", StrC name(Enum), codetype_impl_tmpl )));
append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl ))); body_append(impl_code_exec, parse_global_body( token_fmt( "typename", StrC name(Exec), codetype_impl_tmpl )));
append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl ))); body_append(impl_code_extern, parse_global_body( token_fmt( "typename", StrC name(Extern), codetype_impl_tmpl )));
append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl ))); body_append(impl_code_include, parse_global_body( token_fmt( "typename", StrC name(Include), codetype_impl_tmpl )));
append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl ))); body_append(impl_code_friend, parse_global_body( token_fmt( "typename", StrC name(Friend), codetype_impl_tmpl )));
append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl ))); body_append(impl_code_fn, parse_global_body( token_fmt( "typename", StrC name(Fn), codetype_impl_tmpl )));
append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl ))); body_append(impl_code_module, parse_global_body( token_fmt( "typename", StrC name(Module), codetype_impl_tmpl )));
append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl ))); body_append(impl_code_ns, parse_global_body( token_fmt( "typename", StrC name(NS), codetype_impl_tmpl )));
append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl ))); body_append(impl_code_op, parse_global_body( token_fmt( "typename", StrC name(Operator), codetype_impl_tmpl )));
append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl ))); body_append(impl_code_opcast, parse_global_body( token_fmt( "typename", StrC name(OpCast), codetype_impl_tmpl )));
append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl ))); body_append(impl_code_pragma, parse_global_body( token_fmt( "typename", StrC name(Pragma), codetype_impl_tmpl )));
append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl ))); body_append(impl_code_precond, parse_global_body( token_fmt( "typename", StrC name(PreprocessCond), codetype_impl_tmpl )));
append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl ))); body_append(impl_code_tmpl, parse_global_body( token_fmt( "typename", StrC name(Template), codetype_impl_tmpl )));
append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Typename), codetype_impl_tmpl ))); body_append(impl_code_type, parse_global_body( token_fmt( "typename", StrC name(Typename), codetype_impl_tmpl )));
append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl ))); body_append(impl_code_typedef, parse_global_body( token_fmt( "typename", StrC name(Typedef), codetype_impl_tmpl )));
append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl ))); body_append(impl_code_union, parse_global_body( token_fmt( "typename", StrC name(Union), codetype_impl_tmpl )));
append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl ))); body_append(impl_code_using, parse_global_body( token_fmt( "typename", StrC name(Using), codetype_impl_tmpl )));
append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl ))); body_append(impl_code_var, parse_global_body( token_fmt( "typename", StrC name(Var), codetype_impl_tmpl )));
#pragma push_macro("forceinline")
#undef forceinline
char const* cast_tmpl = stringize( char const* cast_tmpl = stringize(
inline Code::operator Code<typename>() const forceinline Code::operator Code<typename>() const
{ {
return { (AST_<typename>*) ast }; return { (AST_<typename>*) ast };
} }
); );
#pragma pop_macro("forceinline")
CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", StrC name(Body), cast_tmpl )); CodeBody impl_cast_body = parse_global_body( token_fmt( "typename", StrC name(Body), cast_tmpl ));
CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", StrC name(Attributes), cast_tmpl )); CodeBody impl_cast_attribute = parse_global_body( token_fmt( "typename", StrC name(Attributes), cast_tmpl ));
@ -547,6 +588,7 @@ CodeBody gen_ast_inlines()
def_pragma( txt("endregion generated code inline implementation")), def_pragma( txt("endregion generated code inline implementation")),
fmt_newline, fmt_newline,
def_pragma( txt("region generated AST/Code cast implementation")), def_pragma( txt("region generated AST/Code cast implementation")),
untyped_str(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN\n")),
fmt_newline, fmt_newline,
impl_cast_body, impl_cast_body,
impl_cast_attribute, impl_cast_attribute,
@ -577,6 +619,7 @@ CodeBody gen_ast_inlines()
impl_cast_using, impl_cast_using,
impl_cast_var, impl_cast_var,
fmt_newline, fmt_newline,
untyped_str(txt("GEN_OPITMIZE_MAPPINGS_END\n")),
def_pragma( txt("endregion generated AST/Code cast implementation")), def_pragma( txt("endregion generated AST/Code cast implementation")),
fmt_newline fmt_newline
)); ));

View File

@ -9,8 +9,6 @@ $refactor_unreal = Join-Path $PSScriptRoot 'refactor_unreal.ps1'
$incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1' $incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1'
$vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1' $vendor_toolchain = Join-Path $PSScriptRoot 'helpers/vendor_toolchain.ps1'
Import-Module $target_arch
function Get-ScriptRepoRoot { function Get-ScriptRepoRoot {
$currentPath = $PSScriptRoot $currentPath = $PSScriptRoot
while ($currentPath -ne $null -and $currentPath -ne "") while ($currentPath -ne $null -and $currentPath -ne "")
@ -33,7 +31,7 @@ function Get-ScriptRepoRoot {
} }
$path_root = Get-ScriptRepoRoot $path_root = Get-ScriptRepoRoot
Import-Module $target_arch # Import-Module $target_arch
Import-Module $format_cpp Import-Module $format_cpp
Push-Location $path_root Push-Location $path_root

View File

@ -188,7 +188,7 @@ if ( $vendor -match "clang" )
# $compiler_args += $flag_time_trace # $compiler_args += $flag_time_trace
} }
if ( $optimize ) { if ( $optimize ) {
$compiler_args += $flag_optimize_fast $compiler_args += $flag_optimize_size
} }
else { else {
$compiler_args += $flag_no_optimization $compiler_args += $flag_no_optimization
@ -268,7 +268,7 @@ if ( $vendor -match "clang" )
# $compiler_args += $flag_time_trace # $compiler_args += $flag_time_trace
} }
if ( $optimize ) { if ( $optimize ) {
$compiler_args += $flag_optimize_fast $compiler_args += $flag_optimize_size
} }
else { else {
$compiler_args += $flag_no_optimization $compiler_args += $flag_no_optimization
@ -316,48 +316,50 @@ if ( $vendor -match "clang" )
if ( $vendor -match "msvc" ) if ( $vendor -match "msvc" )
{ {
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170 # https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
$flag_all_c = '/TC' $flag_all_c = '/TC'
$flag_all_cpp = '/TP' $flag_all_cpp = '/TP'
$flag_compile = '/c' $flag_compile = '/c'
$flag_debug = '/Zi' $flag_debug = '/Zi'
$flag_define = '/D' $flag_define = '/D'
$flag_exceptions_disabled = '/EHsc-' $flag_exceptions_disabled = '/EHsc-'
$flag_RTTI_disabled = '/GR-' $flag_RTTI_disabled = '/GR-'
$flag_include = '/I' $flag_include = '/I'
$flag_full_src_path = '/FC' $flag_full_src_path = '/FC'
$flag_nologo = '/nologo' $flag_nologo = '/nologo'
$flag_dll = '/LD' $flag_dll = '/LD'
$flag_dll_debug = '/LDd' $flag_dll_debug = '/LDd'
$flag_linker = '/link' $flag_linker = '/link'
$flag_link_dll = '/DLL' $flag_link_dll = '/DLL'
$flag_link_no_incremental = '/INCREMENTAL:NO' $flag_link_no_incremental = '/INCREMENTAL:NO'
$flag_link_mapfile = '/MAP:' $flag_link_mapfile = '/MAP:'
$flag_link_optimize_references = '/OPT:REF' $flag_link_optimize_references = '/OPT:REF'
$flag_link_win_debug = '/DEBUG' $flag_link_win_debug = '/DEBUG'
$flag_link_win_pdb = '/PDB:' $flag_link_win_pdb = '/PDB:'
$flag_link_win_machine_32 = '/MACHINE:X86' $flag_link_win_machine_32 = '/MACHINE:X86'
$flag_link_win_machine_64 = '/MACHINE:X64' $flag_link_win_machine_64 = '/MACHINE:X64'
$flag_link_win_path_output = '/OUT:' $flag_link_win_path_output = '/OUT:'
$flag_link_win_rt_dll = '/MD' $flag_link_win_rt_dll = '/MD'
$flag_link_win_rt_dll_debug = '/MDd' $flag_link_win_rt_dll_debug = '/MDd'
$flag_link_win_rt_static = '/MT' $flag_link_win_rt_static = '/MT'
$flag_link_win_rt_static_debug = '/MTd' $flag_link_win_rt_static_debug = '/MTd'
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE' $flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS' $flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
$flag_no_optimization = '/Od' $flag_no_optimization = '/Od'
$flag_optimize_fast = '/O2' $flag_optimize_fast = '/O2'
$flag_optimize_size = '/O1' $flag_optimize_size = '/O1'
$flag_optimize_intrinsics = '/Oi' $flag_optimize_intrinsics = '/Oi'
$flag_optimized_debug = '/Zo' $flag_optimized_debug_forceinline = '/d2Obforceinline'
$flag_out_name = '/OUT:' $flag_optimized_debug = '/Zo'
$flag_path_interm = '/Fo' $flag_
$flag_path_debug = '/Fd' $flag_out_name = '/OUT:'
$flag_path_output = '/Fe' $flag_path_interm = '/Fo'
$flag_preprocess_conform = '/Zc:preprocessor' $flag_path_debug = '/Fd'
$flag_set_stack_size = '/F' $flag_path_output = '/Fe'
$flag_syntax_only = '/Zs' $flag_preprocess_conform = '/Zc:preprocessor'
$flag_wall = '/Wall' $flag_set_stack_size = '/F'
$flag_warnings_as_errors = '/WX' $flag_syntax_only = '/Zs'
$flag_wall = '/Wall'
$flag_warnings_as_errors = '/WX'
function build function build
{ {
@ -388,7 +390,7 @@ if ( $vendor -match "msvc" )
} }
if ( $optimize ) { if ( $optimize ) {
$compiler_args += $flag_optimize_fast $compiler_args += $flag_optimize_size
} }
else { else {
$compiler_args += $flag_no_optimization $compiler_args += $flag_no_optimization
@ -403,6 +405,7 @@ if ( $vendor -match "msvc" )
if ( $optimize ) { if ( $optimize ) {
$compiler_args += $flag_optimized_debug $compiler_args += $flag_optimized_debug
$compiler_args += $flag_optimized_debug_forceinline
} }
} }
else { else {
@ -474,7 +477,7 @@ if ( $vendor -match "msvc" )
} }
if ( $optimize ) { if ( $optimize ) {
$compiler_args += $flag_optimize_fast $compiler_args += $flag_optimize_size
} }
else { else {
$compiler_args += $flag_no_optimization $compiler_args += $flag_no_optimization