diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index e89c66a..1e5c8c5 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -155,12 +155,14 @@ int gen_main() case CT_Enum: { - CodeEnum enum_def = cast(CodeEnum, entry); - CodeTypedef typedef_enum = parse_typedef(token_fmt("name", enum_def->Name, stringize( typedef enum ; ))); - types.append(enum_def); - types.append(typedef_enum); + log_fmt("Detected ENUM: %S", entry->Name); + convert_cpp_enum_to_c(cast(CodeEnum, entry), types); } break; + + default: + types.append(entry); + break; } } @@ -170,7 +172,7 @@ int gen_main() Code inlines = scan_file( project_dir "components/inlines.hpp" ); Code header_end = scan_file( project_dir "components/header_end.hpp" ); - CodeBody ecode = gen_ecode ( project_dir "enums/ECode.csv", helper_use_c_definition ); + CodeBody ecode = gen_ecode ( project_dir "enums/ECodeTypes.csv", helper_use_c_definition ); CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition ); CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition ); @@ -193,13 +195,7 @@ int gen_main() //++ entry; // Consume endif } - b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_ast, ast ); - if (found) break; - - found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_ast, ast); - if (found) break; - - found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_ast, ast); + b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_ast, ast); if (found) break; ast.append(entry); @@ -208,11 +204,22 @@ int gen_main() case CT_Struct_Fwd: { - CodeStruct fwd = cast(CodeStruct, entry); - if (fwd->Name.starts_with(txt("AST"))) { - ast.append(fwd); - CodeTypedef td = parse_typedef(token_fmt("name", fwd->Name, stringize( typedef struct ; ))); - ast.append(td); + CodeStruct fwd = cast(CodeStruct, entry); + CodeTypedef tdef = parse_typedef(token_fmt("name", fwd->Name, stringize( typedef struct ; ))); + ast.append(fwd); + ast.append(tdef); + } + break; + + case CT_Struct: + { + + CodeStruct struct_def = cast(CodeStruct, entry); + ast.append(struct_def); + if ( ! entry->Name.is_equal(txt("AST"))) + { + CodeTypedef tdef = parse_typedef(token_fmt("name", struct_def->Name, stringize( typedef struct ; ))); + ast.append(tdef); } } break; @@ -221,7 +228,7 @@ int gen_main() { CodeVar var = cast(CodeVar, entry); - s32 constexpr_found = var->Specs.remove( Spec_Constexpr ); + s32 constexpr_found = var->Specs ? var->Specs.remove( Spec_Constexpr ) : - 1; if (constexpr_found > -1) { log_fmt("Found constexpr: %S\n", entry.to_string()); if (var->Name.contains(txt("AST_ArrSpecs_Cap"))) @@ -323,6 +330,18 @@ R"(#define AST_ArrSpecs_Cap \ } } break; + case CT_Enum: + { + convert_cpp_enum_to_c(cast(CodeEnum, entry), memory); + } + break; + case CT_Struct_Fwd: + { + CodeTypedef tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct ; ))); + memory.append(entry); + memory.append(tdef); + } + break; case CT_Class: case CT_Struct: { @@ -332,7 +351,7 @@ R"(#define AST_ArrSpecs_Cap \ (body_entry->Type) { case CT_Preprocess_If: { - ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), body_entry, body, new_body ); + ignore_preprocess_cond_block(txt("! GEN_C_LIKE_CPP"), body_entry, body, new_body ); } break; @@ -340,17 +359,16 @@ R"(#define AST_ArrSpecs_Cap \ new_body.append(body_entry); break; } - entry->Body = new_body; + + CodeTypedef tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct ; ))); memory.append(entry); + memory.append(tdef); } break; case CT_Preprocess_If: { - b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory, memory ); - if (found) break; - - found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_memory, memory ); + b32 found = ignore_preprocess_cond_block(txt("! GEN_C_LIKE_CPP"), entry, parsed_memory, memory ); if (found) break; memory.append(entry); @@ -418,93 +436,104 @@ R"(#define AST_ArrSpecs_Cap \ CodeBody parsed_strings = parse_file( project_dir "dependencies/strings.hpp" ); CodeBody strings = def_body(CT_Global_Body); - for ( Code entry = parsed_strings.begin(); entry != parsed_strings.end(); ++ entry ) + for ( Code entry = parsed_strings.begin(); entry != parsed_strings.end(); ++ entry ) switch (entry->Type) { - switch (entry->Type) + case CT_Preprocess_If: { - case CT_Preprocess_If: + CodePreprocessCond cond = cast(CodePreprocessCond, entry); + if (cond->Content.is_equal(txt("GEN_COMPILER_C"))) { - CodePreprocessCond cond = cast(CodePreprocessCond, entry); - if (cond->Content.starts_with(txt("GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES"))) - { - for (; entry != end(parsed_strings) && entry->Type != CT_Typedef; ++ entry) {} - strings.append(entry); - strings.append(fmt_newline); - - for (; entry != end(parsed_strings) && entry->Type != CT_Preprocess_EndIf; ++ entry) {} - ++ entry; - break; + ++ entry; // Remove #if GEN_COMPILER_C + for ( ; entry->Type != CT_Preprocess_Else + && entry->Type != CT_Preprocess_EndIf; ++ entry ) { + strings.append(entry); // Preserve content } - - bool found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_strings, strings); - if (found) break; - - found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_strings, strings ); + for ( ; entry->Type != CT_Preprocess_EndIf; ++ entry ) {} // Discard C++ + // #endif discarded by for loop + break; } - break; - case CT_Preprocess_IfDef: - { - ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_strings, strings ); - } - break; + bool found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_strings, strings); + if (found) break; - case CT_Struct_Fwd: - { - if ( entry->Name.is_equal(txt("String")) ) - { - CodeTypedef c_def = parse_typedef(code( typedef char* String; )); - strings.append(c_def); - strings.append(fmt_newline); - ++ entry; - continue; - } - strings.append(entry); - } - break; - - case CT_Struct: - { - CodeBody body = cast(CodeBody, entry->Body); - CodeBody new_body = def_body( entry->Body->Type ); - for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch - (body_entry->Type) { - case CT_Preprocess_If: - { - b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), body_entry, body, new_body ); - if (found) break; - - new_body.append(body_entry); - } - break; - default: - new_body.append(body_entry); - break; - } - entry->Body = new_body; - strings.append(entry); - } - break; - - case CT_Typedef: - { - StrC name_string_table = txt("StringTable"); - - CodeTypedef td = cast(CodeTypedef, entry); - if (td->Name.contains(name_string_table)) - { - CodeBody ht = gen_hashtable(txt("StrC"), name_string_table); - strings.append(ht); - break; - } - strings.append(td); - } - break; - - default: - strings.append(entry); - break; + found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), entry, parsed_strings, strings); + if (found) break; } + break; + + case CT_Preprocess_IfDef: + { + ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_strings, strings ); + } + break; + + case CT_Preprocess_IfNotDef: + { + log_fmt("\nIFNDEF: %SC\n", entry->Content); + strings.append(entry); + } + break; + + case CT_Struct_Fwd: + { + if ( entry->Name.is_equal(txt("String")) ) + { + CodeTypedef c_def = parse_typedef(code( typedef char* String; )); + strings.append(c_def); + strings.append(fmt_newline); + ++ entry; + continue; + } + else + { + CodeTypedef c_def = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct ; ))); + strings.append(c_def); + } + strings.append(entry); + } + break; + + case CT_Struct: + { + CodeBody body = cast(CodeBody, entry->Body); + CodeBody new_body = def_body( entry->Body->Type ); + for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch + (body_entry->Type) { + case CT_Preprocess_If: + { + b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), body_entry, body, new_body ); + if (found) break; + + new_body.append(body_entry); + } + break; + default: + new_body.append(body_entry); + break; + } + entry->Body = new_body; + strings.append(entry); + } + break; + + case CT_Typedef: + { + StrC name_string_table = txt("StringTable"); + + CodeTypedef td = cast(CodeTypedef, entry); + if (td->Name.contains(name_string_table)) + { + CodeBody ht = gen_hashtable(txt("StrC"), name_string_table); + strings.append(ht); + break; + } + strings.append(td); + } + break; + + default: + strings.append(entry); + break; } CodeBody parsed_filesystem = parse_file( project_dir "dependencies/filesystem.hpp" ); @@ -521,6 +550,30 @@ R"(#define AST_ArrSpecs_Cap \ filesystem.append(entry); } break; + + case CT_Enum: + case CT_Enum_Fwd: + case CT_Struct_Fwd: + case CT_Struct: + case CT_Union: + case CT_Union_Fwd: + { + if (entry->Name.is_equal(txt("FileOperations"))) + continue; + + // StrC type_str = codetype_to_keyword_str(entry->Type); + // StrC formated_tmpl = token_fmt_impl( 3, + // "type", type_str + // , "name", entry->Name, + // stringize( + // typedef ; + // )); + // CodeTypedef tdef = parse_typedef(formated_tmpl); + // filesystem.append(entry); + // filesystem.append(tdef); + } + break; + case CT_Variable: { CodeVar var = cast(CodeVar, entry); diff --git a/gen_c_library/components/misc.hpp b/gen_c_library/components/misc.hpp index 0f910fb..4a4f2b1 100644 --- a/gen_c_library/components/misc.hpp +++ b/gen_c_library/components/misc.hpp @@ -3,11 +3,26 @@ using namespace gen; +void convert_cpp_enum_to_c( CodeEnum to_convert, CodeBody to_append ) +{ +#pragma push_macro("enum_underlying") +#undef enum_underlying + if (to_convert->UnderlyingType) + { + to_convert->UnderlyingTypeMacro = untyped_str(token_fmt("type", to_convert->UnderlyingType->Name, stringize(enum_underlying()))); + to_convert->UnderlyingType = CodeTypename{nullptr}; + } + CodeTypedef tdef = parse_typedef(token_fmt("name", to_convert->Name, stringize( typedef enum ; ))); + to_append.append(to_convert); + to_append.append(tdef); +#pragma pop_macro("enum_underlying") +} + b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& parsed_body, CodeBody& body ) { b32 found = false; CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter); - if ( cond->Content.contains(cond_sig) ) + if ( cond->Content.is_equal(cond_sig) ) { log_fmt("Preprocess cond found: %SC\n", cond->Content); found = true; @@ -193,8 +208,8 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt("" if (fn->Specs && fn->Specs->NumEntries > 0) { new_name.append("_S_"); - for (Specifier* spec = begin(fn->Specs); - spec != end(fn->Specs); + for (Specifier* spec = begin(fn->Specs); + spec != end(fn->Specs); ++spec) { new_name.append_fmt("%SC_", spec_to_str(*spec)); diff --git a/gen_singleheader/singleheader.cpp b/gen_singleheader/singleheader.cpp index 5226d62..9454e81 100644 --- a/gen_singleheader/singleheader.cpp +++ b/gen_singleheader/singleheader.cpp @@ -155,7 +155,7 @@ int gen_main() Code inlines = scan_file( project_dir "components/inlines.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/ECodeTypes.csv" ); CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" ); CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" ); CodeBody ast_inlines = gen_ast_inlines(); diff --git a/gen_unreal_engine/unreal.cpp b/gen_unreal_engine/unreal.cpp index 2712bc3..e9fd72b 100644 --- a/gen_unreal_engine/unreal.cpp +++ b/gen_unreal_engine/unreal.cpp @@ -217,7 +217,7 @@ int gen_main() Code inlines = scan_file( project_dir "components/inlines.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/ECodeTypes.csv" ); CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" ); CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" ); CodeBody ast_inlines = gen_ast_inlines(); diff --git a/project/bootstrap.cpp b/project/bootstrap.cpp index 84e436c..8eb2188 100644 --- a/project/bootstrap.cpp +++ b/project/bootstrap.cpp @@ -160,7 +160,7 @@ int gen_main() Code inlines = scan_file( "components/inlines.hpp" ); Code header_end = scan_file( "components/header_end.hpp" ); - CodeBody ecode = gen_ecode ( "enums/ECode.csv" ); + CodeBody ecode = gen_ecode ( "enums/ECodeTypes.csv" ); CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" ); CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" ); CodeBody ast_inlines = gen_ast_inlines(); diff --git a/project/components/ast.cpp b/project/components/ast.cpp index 21e3c33..1e93c7e 100644 --- a/project/components/ast.cpp +++ b/project/components/ast.cpp @@ -20,7 +20,7 @@ char const* code_debug_str(Code self) string_append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" ); string_append_fmt( result, "\n\tType : %S", code_type_str(self) ); - string_append_fmt( result, "\n\tModule Flags : %S", to_str( self->ModuleFlags ) ); + string_append_fmt( result, "\n\tModule Flags : %S", module_flag_to_str( self->ModuleFlags ) ); switch ( self->Type ) { @@ -64,7 +64,7 @@ char const* code_debug_str(Code self) string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" ); string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" ); - string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" ); + string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" ); string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" ); string_append_fmt( result, "\n\tBody : %S", self->Body ? code_debug_str(self->Body) : "Null" ); break; @@ -78,7 +78,7 @@ char const* code_debug_str(Code self) string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" ); string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? code_to_string(self->Attributes) : "Null" ); - string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" ); + string_append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? access_spec_to_str( self->ParentAccess ) : "No Parent" ); string_append_fmt( result, "\n\tParentType : %s", self->ParentType ? code_type_str(self->ParentType) : "Null" ); break; @@ -626,8 +626,8 @@ bool code_is_equal( Code self, Code other ) log_fmt("\nAST::is_equal: Member - " #val " failed\n" \ "AST : %S\n" \ "Other: %S\n" \ - , code_debug_str(self) \ - ,code_debug_str(other) \ + , code_debug_str(self) \ + ,code_debug_str(other) \ ); \ \ return false; \ @@ -639,8 +639,8 @@ bool code_is_equal( Code self, Code other ) log_fmt("\nAST::is_equal: Member string - "#str " failed\n" \ "AST : %S\n" \ "Other: %S\n" \ - , code_debug_str(self) \ - ,code_debug_str(other) \ + , code_debug_str(self) \ + ,code_debug_str(other) \ ); \ \ return false; \ @@ -652,8 +652,8 @@ bool code_is_equal( Code self, Code other ) log_fmt("\nAST::is_equal: Member content - "#content " failed\n" \ "AST : %S\n" \ "Other: %S\n" \ - , code_debug_str(self) \ - , code_debug_str(other) \ + , code_debug_str(self) \ + , code_debug_str(other) \ ); \ \ log_fmt("Content cannot be trusted to be unique with this check " \ @@ -674,25 +674,25 @@ bool code_is_equal( Code self, Code other ) "AST : %s\n" \ "Other: %s\n" \ "For ast member: %s\n" \ - , code_debug_str(self) \ - , code_debug_str(other) \ - , code_debug_str(self->ast) \ + , code_debug_str(self) \ + , code_debug_str(other) \ + , code_debug_str(self->ast) \ ); \ \ return false; \ } \ \ - if ( ! code_is_equal(self->ast, other->ast ) ) \ + if ( ! code_is_equal(self->ast, other->ast ) ) \ { \ log_fmt( "\nAST::is_equal: Failed for " #ast"\n" \ - "AST : %S\n" \ - "Other: %S\n" \ - "For ast member: %S\n" \ - "other's ast member: %S\n" \ - , code_debug_str(self) \ - , code_debug_str(other) \ - , code_debug_str(self->ast) \ - , code_debug_str(other->ast) \ + "AST : %S\n" \ + "Other: %S\n" \ + "For ast member: %S\n" \ + "other's ast member: %S\n" \ + , code_debug_str(self) \ + , code_debug_str(other) \ + , code_debug_str(self->ast) \ + , code_debug_str(other->ast) \ ); \ \ return false; \ @@ -918,10 +918,10 @@ bool code_is_equal( Code self, Code other ) if ( curr_other == nullptr ) { log_fmt("\nAST::is_equal: Failed for parameter, other equivalent param is null\n" - "AST : %S\n" - "Other: %S\n" - "For ast member: %S\n" - , code_debug_str(curr) + "AST : %S\n" + "Other: %S\n" + "For ast member: %S\n" + , code_debug_str(curr) ); return false; @@ -1066,7 +1066,7 @@ bool code_is_equal( Code self, Code other ) return true; } - + case CT_Union_Fwd: { check_member_val( ModuleFlags ); @@ -1117,10 +1117,10 @@ bool code_is_equal( Code self, Code other ) if ( curr_other == nullptr ) { log_fmt("\nAST::is_equal: Failed for body, other equivalent param is null\n" - "AST : %S\n" - "Other: %S\n" - "For ast member: %S\n" - , code_debug_str(curr) + "AST : %S\n" + "Other: %S\n" + "For ast member: %S\n" + , code_debug_str(curr) ); return false; diff --git a/project/components/ast.hpp b/project/components/ast.hpp index fb973aa..e5d656c 100644 --- a/project/components/ast.hpp +++ b/project/components/ast.hpp @@ -153,7 +153,9 @@ Define_Code(Var); #undef Define_Code GEN_NS_PARSER_BEGIN + struct Token; + GEN_NS_PARSER_END #if GEN_COMPILER_CPP @@ -380,12 +382,13 @@ static_assert( sizeof(AST) == AST_POD_Size, "ERROR: AST POD is not size of AST_P struct InvalidCode_ImplictCaster; #define InvalidCode (InvalidCode_ImplictCaster{}) #else -#define InvalidCode { (AST*)Code_Invalid } +#define InvalidCode { (void*)Code_Invalid } #endif #if GEN_COMPILER_CPP +struct NullCode_ImplicitCaster; // Used when the its desired when omission is allowed in a definition. -#define NullCode { nullptr } +#define NullCode (NullCode_ImplicitCaster{}) #else #define NullCode nullptr #endif diff --git a/project/components/code_serialization.cpp b/project/components/code_serialization.cpp index c5d488b..8f0ee50 100644 --- a/project/components/code_serialization.cpp +++ b/project/components/code_serialization.cpp @@ -184,7 +184,7 @@ void class_to_string_def( CodeClass self, String* result ) if ( self->ParentType ) { - char const* access_level = to_str( self->ParentAccess ); + char const* access_level = access_spec_to_str( self->ParentAccess ); string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) ); @@ -368,7 +368,10 @@ void enum_to_string_fwd(CodeEnum self, String* result ) if ( self->UnderlyingType ) string_append_fmt( result, "enum %SC : %S", self->Name, typename_to_string(self->UnderlyingType) ); else if (self->UnderlyingTypeMacro) - string_append_fmt( result, "enum %SC %S", self->Name, typename_to_string(self->UnderlyingType) ); + { + log_fmt("IDENTIFIED A UNDERLYING ENUM MACRO"); + string_append_fmt( result, "enum %SC %S", self->Name, code_to_string(self->UnderlyingTypeMacro) ); + } else string_append_fmt( result, "enum %SC", self->Name ); @@ -1033,7 +1036,7 @@ void struct_to_string_def( CodeStruct self, String* result ) if ( self->ParentType ) { - char const* access_level = to_str( self->ParentAccess ); + char const* access_level = access_spec_to_str( self->ParentAccess ); string_append_fmt( result, "%SC : %s %S", self->Name, access_level, typename_to_string(self->ParentType) ); diff --git a/project/components/code_types.hpp b/project/components/code_types.hpp index b3ce6ea..95526b0 100644 --- a/project/components/code_types.hpp +++ b/project/components/code_types.hpp @@ -911,10 +911,6 @@ struct CodeVar #undef Using_Code #undef Using_CodeOps -#if GEN_SUPPORT_CPP_REFERENCES -void to_string_export( CodeBody body, String& result ) { return body_to_string_export(body, & result); }; -#endif - #undef Verify_POD struct InvalidCode_ImplictCaster @@ -951,6 +947,38 @@ struct InvalidCode_ImplictCaster operator CodeVar () const { return cast(CodeVar, Code_Invalid); } }; +struct NullCode_ImplicitCaster +{ + operator Code () const { return {nullptr}; } + operator CodeBody () const { return {(AST_Body*) nullptr}; } + operator CodeAttributes () const { return {(AST_Attributes*)nullptr}; } + operator CodeComment () const { return {nullptr}; } + operator CodeClass () const { return {nullptr}; } + operator CodeConstructor () const { return {nullptr}; } + operator CodeDefine () const { return {nullptr}; } + operator CodeDestructor () const { return {nullptr}; } + operator CodeExec () const { return {nullptr}; } + operator CodeEnum () const { return {nullptr}; } + operator CodeExtern () const { return {nullptr}; } + operator CodeInclude () const { return {nullptr}; } + operator CodeFriend () const { return {nullptr}; } + operator CodeFn () const { return {nullptr}; } + operator CodeModule () const { return {nullptr}; } + operator CodeNS () const { return {nullptr}; } + operator CodeOperator () const { return {nullptr}; } + operator CodeOpCast () const { return {nullptr}; } + operator CodeParam () const { return {nullptr}; } + operator CodePragma () const { return {nullptr}; } + operator CodePreprocessCond() const { return {nullptr}; } + operator CodeSpecifiers () const { return {nullptr}; } + operator CodeStruct () const { return {nullptr}; } + operator CodeTemplate () const { return {nullptr}; } + operator CodeTypename () const { return CodeTypename{(AST_Typename*)nullptr}; } + operator CodeTypedef () const { return {nullptr}; } + operator CodeUnion () const { return {nullptr}; } + operator CodeUsing () const { return {nullptr}; } + operator CodeVar () const { return {nullptr}; } +}; #if ! GEN_C_LIKE_CPP GEN_OPTIMIZE_MAPPINGS_BEGIN diff --git a/project/components/gen/ast_inlines.hpp b/project/components/gen/ast_inlines.hpp index 439b8d9..e93bcea 100644 --- a/project/components/gen/ast_inlines.hpp +++ b/project/components/gen/ast_inlines.hpp @@ -7,473 +7,813 @@ #pragma region generated code inline implementation - inline -Code & Code::operator = ( Code other) +inline Code& Code::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline Code:: operator bool() + +inline Code::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline -CodeBody & CodeBody::operator = ( Code other) + +inline CodeBody& CodeBody::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeBody:: operator bool() + +inline CodeBody::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline -CodeAttributes & CodeAttributes::operator = ( Code other) + +inline CodeAttributes& CodeAttributes::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeAttributes:: operator bool() + +inline CodeAttributes::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeAttributes:: operator Code() + +inline CodeAttributes::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Attributes * CodeAttributes::operator -> () + +inline AST_Attributes* CodeAttributes::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeComment & CodeComment::operator = ( Code other) + +inline CodeComment& CodeComment::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeComment:: operator bool() + +inline CodeComment::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeComment:: operator Code() + +inline CodeComment::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Comment * CodeComment::operator -> () + +inline AST_Comment* CodeComment::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeConstructor & CodeConstructor::operator = ( Code other) + +inline CodeConstructor& CodeConstructor::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeConstructor:: operator bool() + +inline CodeConstructor::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeConstructor:: operator Code() + +inline CodeConstructor::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Constructor * CodeConstructor::operator -> () + +inline AST_Constructor* CodeConstructor::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeClass & CodeClass::operator = ( Code other) + +inline CodeClass& CodeClass::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeClass:: operator bool() + +inline CodeClass::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline -CodeDefine & CodeDefine::operator = ( Code other) + +inline CodeDefine& CodeDefine::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeDefine:: operator bool() + +inline CodeDefine::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeDefine:: operator Code() + +inline CodeDefine::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Define * CodeDefine::operator -> () + +inline AST_Define* CodeDefine::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeDestructor & CodeDestructor::operator = ( Code other) + +inline CodeDestructor& CodeDestructor::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeDestructor:: operator bool() + +inline CodeDestructor::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeDestructor:: operator Code() + +inline CodeDestructor::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Destructor * CodeDestructor::operator -> () + +inline AST_Destructor* CodeDestructor::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeEnum & CodeEnum::operator = ( Code other) + +inline CodeEnum& CodeEnum::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeEnum:: operator bool() + +inline CodeEnum::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeEnum:: operator Code() + +inline CodeEnum::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Enum * CodeEnum::operator -> () + +inline AST_Enum* CodeEnum::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeExec & CodeExec::operator = ( Code other) + +inline CodeExec& CodeExec::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeExec:: operator bool() + +inline CodeExec::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeExec:: operator Code() + +inline CodeExec::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Exec * CodeExec::operator -> () + +inline AST_Exec* CodeExec::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeExtern & CodeExtern::operator = ( Code other) + +inline CodeExtern& CodeExtern::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeExtern:: operator bool() + +inline CodeExtern::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeExtern:: operator Code() + +inline CodeExtern::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Extern * CodeExtern::operator -> () + +inline AST_Extern* CodeExtern::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeFriend & CodeFriend::operator = ( Code other) + +inline CodeFriend& CodeFriend::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeFriend:: operator bool() + +inline CodeFriend::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeFriend:: operator Code() + +inline CodeFriend::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Friend * CodeFriend::operator -> () + +inline AST_Friend* CodeFriend::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeFn & CodeFn::operator = ( Code other) + +inline CodeFn& CodeFn::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeFn:: operator bool() + +inline CodeFn::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeFn:: operator Code() + +inline CodeFn::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Fn * CodeFn::operator -> () + +inline AST_Fn* CodeFn::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeInclude & CodeInclude::operator = ( Code other) + +inline CodeInclude& CodeInclude::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeInclude:: operator bool() + +inline CodeInclude::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeInclude:: operator Code() + +inline CodeInclude::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Include * CodeInclude::operator -> () + +inline AST_Include* CodeInclude::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeModule & CodeModule::operator = ( Code other) + +inline CodeModule& CodeModule::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeModule:: operator bool() + +inline CodeModule::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeModule:: operator Code() + +inline CodeModule::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Module * CodeModule::operator -> () + +inline AST_Module* CodeModule::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeNS & CodeNS::operator = ( Code other) + +inline CodeNS& CodeNS::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeNS:: operator bool() + +inline CodeNS::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeNS:: operator Code() + +inline CodeNS::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_NS * CodeNS::operator -> () + +inline AST_NS* CodeNS::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeOperator & CodeOperator::operator = ( Code other) + +inline CodeOperator& CodeOperator::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeOperator:: operator bool() + +inline CodeOperator::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeOperator:: operator Code() + +inline CodeOperator::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Operator * CodeOperator::operator -> () + +inline AST_Operator* CodeOperator::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeOpCast & CodeOpCast::operator = ( Code other) + +inline CodeOpCast& CodeOpCast::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeOpCast:: operator bool() + +inline CodeOpCast::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeOpCast:: operator Code() + +inline CodeOpCast::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_OpCast * CodeOpCast::operator -> () + +inline AST_OpCast* CodeOpCast::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeParam & CodeParam::operator = ( Code other) + +inline CodeParam& CodeParam::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeParam:: operator bool() + +inline CodeParam::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline -CodePragma & CodePragma::operator = ( Code other) + +inline CodePragma& CodePragma::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodePragma:: operator bool() + +inline CodePragma::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodePragma:: operator Code() + +inline CodePragma::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Pragma * CodePragma::operator -> () + +inline AST_Pragma* CodePragma::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodePreprocessCond & CodePreprocessCond::operator = ( Code other) + +inline CodePreprocessCond& CodePreprocessCond::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodePreprocessCond:: operator bool() + +inline CodePreprocessCond::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodePreprocessCond:: operator Code() + +inline CodePreprocessCond::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_PreprocessCond * CodePreprocessCond::operator -> () + +inline AST_PreprocessCond* CodePreprocessCond::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeSpecifiers & CodeSpecifiers::operator = ( Code other) + +inline CodeSpecifiers& CodeSpecifiers::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeSpecifiers:: operator bool() + +inline CodeSpecifiers::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline -CodeStruct & CodeStruct::operator = ( Code other) + +inline CodeStruct& CodeStruct::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeStruct:: operator bool() + +inline CodeStruct::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline -CodeTemplate & CodeTemplate::operator = ( Code other) + +inline CodeTemplate& CodeTemplate::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeTemplate:: operator bool() + +inline CodeTemplate::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeTemplate:: operator Code() + +inline CodeTemplate::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Template * CodeTemplate::operator -> () + +inline AST_Template* CodeTemplate::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeTypename & CodeTypename::operator = ( Code other) + +inline CodeTypename& CodeTypename::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeTypename:: operator bool() + +inline CodeTypename::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeTypename:: operator Code() + +inline CodeTypename::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Typename * CodeTypename::operator -> () + +inline AST_Typename* CodeTypename::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeTypedef & CodeTypedef::operator = ( Code other) + +inline CodeTypedef& CodeTypedef::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeTypedef:: operator bool() + +inline CodeTypedef::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeTypedef:: operator Code() + +inline CodeTypedef::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Typedef * CodeTypedef::operator -> () + +inline AST_Typedef* CodeTypedef::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeUnion & CodeUnion::operator = ( Code other) + +inline CodeUnion& CodeUnion::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeUnion:: operator bool() + +inline CodeUnion::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeUnion:: operator Code() + +inline CodeUnion::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Union * CodeUnion::operator -> () + +inline AST_Union* CodeUnion::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeUsing & CodeUsing::operator = ( Code other) + +inline CodeUsing& CodeUsing::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeUsing:: operator bool() + +inline CodeUsing::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeUsing:: operator Code() + +inline CodeUsing::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Using * CodeUsing::operator -> () + +inline AST_Using* CodeUsing::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } - inline -CodeVar & CodeVar::operator = ( Code other) + +inline CodeVar& CodeVar::operator=( Code other ) { -if ( other.ast != nullptr && other->Parent != nullptr ) { ast = rcast( decltype(ast), code_duplicate(other).ast); ast->Parent = { nullptr }; } ast = rcast( decltype( ast ), other.ast ); return * this; + if ( other.ast != nullptr && other->Parent != nullptr ) + { + ast = rcast( decltype( ast ), code_duplicate( other ).ast ); + ast->Parent = { nullptr }; + } + ast = rcast( decltype( ast ), other.ast ); + return *this; } - inline CodeVar:: operator bool() + +inline CodeVar::operator bool() { -return ast != nullptr; + return ast != nullptr; } - inline CodeVar:: operator Code() + +inline CodeVar::operator Code() { -return *rcast( Code*, this ); + return *rcast( Code*, this ); } - inline -AST_Var * CodeVar::operator -> () + +inline AST_Var* CodeVar::operator->() { -if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); return nullptr; } return ast; + if ( ast == nullptr ) + { + log_failure( "Attempt to dereference a nullptr!" ); + return nullptr; + } + return ast; } #pragma endregion generated code inline implementation @@ -481,119 +821,145 @@ if ( ast == nullptr ) { log_failure( "Attempt to dereference a nullptr!" ); retu #pragma region generated AST/Code cast implementation GEN_OPTIMIZE_MAPPINGS_BEGIN - forceinline Code:: operator CodeBody() const +forceinline Code::operator CodeBody() const { -return { (AST_Body*) ast }; + return { (AST_Body*)ast }; } - forceinline Code:: operator CodeAttributes() const + +forceinline Code::operator CodeAttributes() const { -return { (AST_Attributes*) ast }; + return { (AST_Attributes*)ast }; } - forceinline Code:: operator CodeComment() const + +forceinline Code::operator CodeComment() const { -return { (AST_Comment*) ast }; + return { (AST_Comment*)ast }; } - forceinline Code:: operator CodeConstructor() const + +forceinline Code::operator CodeConstructor() const { -return { (AST_Constructor*) ast }; + return { (AST_Constructor*)ast }; } - forceinline Code:: operator CodeClass() const + +forceinline Code::operator CodeClass() const { -return { (AST_Class*) ast }; + return { (AST_Class*)ast }; } - forceinline Code:: operator CodeDefine() const + +forceinline Code::operator CodeDefine() const { -return { (AST_Define*) ast }; + return { (AST_Define*)ast }; } - forceinline Code:: operator CodeDestructor() const + +forceinline Code::operator CodeDestructor() const { -return { (AST_Destructor*) ast }; + return { (AST_Destructor*)ast }; } - forceinline Code:: operator CodeEnum() const + +forceinline Code::operator CodeEnum() const { -return { (AST_Enum*) ast }; + return { (AST_Enum*)ast }; } - forceinline Code:: operator CodeExec() const + +forceinline Code::operator CodeExec() const { -return { (AST_Exec*) ast }; + return { (AST_Exec*)ast }; } - forceinline Code:: operator CodeExtern() const + +forceinline Code::operator CodeExtern() const { -return { (AST_Extern*) ast }; + return { (AST_Extern*)ast }; } - forceinline Code:: operator CodeFriend() const + +forceinline Code::operator CodeFriend() const { -return { (AST_Friend*) ast }; + return { (AST_Friend*)ast }; } - forceinline Code:: operator CodeFn() const + +forceinline Code::operator CodeFn() const { -return { (AST_Fn*) ast }; + return { (AST_Fn*)ast }; } - forceinline Code:: operator CodeInclude() const + +forceinline Code::operator CodeInclude() const { -return { (AST_Include*) ast }; + return { (AST_Include*)ast }; } - forceinline Code:: operator CodeModule() const + +forceinline Code::operator CodeModule() const { -return { (AST_Module*) ast }; + return { (AST_Module*)ast }; } - forceinline Code:: operator CodeNS() const + +forceinline Code::operator CodeNS() const { -return { (AST_NS*) ast }; + return { (AST_NS*)ast }; } - forceinline Code:: operator CodeOperator() const + +forceinline Code::operator CodeOperator() const { -return { (AST_Operator*) ast }; + return { (AST_Operator*)ast }; } - forceinline Code:: operator CodeOpCast() const + +forceinline Code::operator CodeOpCast() const { -return { (AST_OpCast*) ast }; + return { (AST_OpCast*)ast }; } - forceinline Code:: operator CodeParam() const + +forceinline Code::operator CodeParam() const { -return { (AST_Param*) ast }; + return { (AST_Param*)ast }; } - forceinline Code:: operator CodePragma() const + +forceinline Code::operator CodePragma() const { -return { (AST_Pragma*) ast }; + return { (AST_Pragma*)ast }; } - forceinline Code:: operator CodePreprocessCond() const + +forceinline Code::operator CodePreprocessCond() const { -return { (AST_PreprocessCond*) ast }; + return { (AST_PreprocessCond*)ast }; } - forceinline Code:: operator CodeSpecifiers() const + +forceinline Code::operator CodeSpecifiers() const { -return { (AST_Specifiers*) ast }; + return { (AST_Specifiers*)ast }; } - forceinline Code:: operator CodeStruct() const + +forceinline Code::operator CodeStruct() const { -return { (AST_Struct*) ast }; + return { (AST_Struct*)ast }; } - forceinline Code:: operator CodeTemplate() const + +forceinline Code::operator CodeTemplate() const { -return { (AST_Template*) ast }; + return { (AST_Template*)ast }; } - forceinline Code:: operator CodeTypename() const + +forceinline Code::operator CodeTypename() const { -return { (AST_Typename*) ast }; + return { (AST_Typename*)ast }; } - forceinline Code:: operator CodeTypedef() const + +forceinline Code::operator CodeTypedef() const { -return { (AST_Typedef*) ast }; + return { (AST_Typedef*)ast }; } - forceinline Code:: operator CodeUnion() const + +forceinline Code::operator CodeUnion() const { -return { (AST_Union*) ast }; + return { (AST_Union*)ast }; } - forceinline Code:: operator CodeUsing() const + +forceinline Code::operator CodeUsing() const { -return { (AST_Using*) ast }; + return { (AST_Using*)ast }; } - forceinline Code:: operator CodeVar() const + +forceinline Code::operator CodeVar() const { -return { (AST_Var*) ast }; + return { (AST_Var*)ast }; } GEN_OPITMIZE_MAPPINGS_END -#pragma endregion generated AST/Code cast implementation - +#pragma endregion generated AST / Code cast implementation diff --git a/project/components/gen/ecode.hpp b/project/components/gen/ecode.hpp index 2a374e0..cfe3e44 100644 --- a/project/components/gen/ecode.hpp +++ b/project/components/gen/ecode.hpp @@ -7,73 +7,212 @@ 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 + 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 CodeType; - inline -StrC codetype_to_str( CodeType type) + +inline StrC codetype_to_str( CodeType type ) { -local_persist StrC lookup[61] = { { sizeof("Invalid"), "Invalid" }, -{ sizeof("Untyped"), "Untyped" }, -{ sizeof("NewLine"), "NewLine" }, -{ sizeof("Comment"), "Comment" }, -{ sizeof("Access_Private"), "Access_Private" }, -{ sizeof("Access_Protected"), "Access_Protected" }, -{ sizeof("Access_Public"), "Access_Public" }, -{ sizeof("PlatformAttributes"), "PlatformAttributes" }, -{ sizeof("Class"), "Class" }, -{ sizeof("Class_Fwd"), "Class_Fwd" }, -{ sizeof("Class_Body"), "Class_Body" }, -{ sizeof("Constructor"), "Constructor" }, -{ sizeof("Constructor_Fwd"), "Constructor_Fwd" }, -{ sizeof("Destructor"), "Destructor" }, -{ sizeof("Destructor_Fwd"), "Destructor_Fwd" }, -{ sizeof("Enum"), "Enum" }, -{ sizeof("Enum_Fwd"), "Enum_Fwd" }, -{ sizeof("Enum_Body"), "Enum_Body" }, -{ sizeof("Enum_Class"), "Enum_Class" }, -{ sizeof("Enum_Class_Fwd"), "Enum_Class_Fwd" }, -{ sizeof("Execution"), "Execution" }, -{ sizeof("Export_Body"), "Export_Body" }, -{ sizeof("Extern_Linkage"), "Extern_Linkage" }, -{ sizeof("Extern_Linkage_Body"), "Extern_Linkage_Body" }, -{ sizeof("Friend"), "Friend" }, -{ sizeof("Function"), "Function" }, -{ sizeof("Function_Fwd"), "Function_Fwd" }, -{ sizeof("Function_Body"), "Function_Body" }, -{ sizeof("Global_Body"), "Global_Body" }, -{ sizeof("Module"), "Module" }, -{ sizeof("Namespace"), "Namespace" }, -{ sizeof("Namespace_Body"), "Namespace_Body" }, -{ sizeof("Operator"), "Operator" }, -{ sizeof("Operator_Fwd"), "Operator_Fwd" }, -{ sizeof("Operator_Member"), "Operator_Member" }, -{ sizeof("Operator_Member_Fwd"), "Operator_Member_Fwd" }, -{ sizeof("Operator_Cast"), "Operator_Cast" }, -{ sizeof("Operator_Cast_Fwd"), "Operator_Cast_Fwd" }, -{ sizeof("Parameters"), "Parameters" }, -{ sizeof("Preprocess_Define"), "Preprocess_Define" }, -{ sizeof("Preprocess_Include"), "Preprocess_Include" }, -{ sizeof("Preprocess_If"), "Preprocess_If" }, -{ sizeof("Preprocess_IfDef"), "Preprocess_IfDef" }, -{ sizeof("Preprocess_IfNotDef"), "Preprocess_IfNotDef" }, -{ sizeof("Preprocess_ElIf"), "Preprocess_ElIf" }, -{ sizeof("Preprocess_Else"), "Preprocess_Else" }, -{ sizeof("Preprocess_EndIf"), "Preprocess_EndIf" }, -{ sizeof("Preprocess_Pragma"), "Preprocess_Pragma" }, -{ sizeof("Specifiers"), "Specifiers" }, -{ sizeof("Struct"), "Struct" }, -{ sizeof("Struct_Fwd"), "Struct_Fwd" }, -{ sizeof("Struct_Body"), "Struct_Body" }, -{ sizeof("Template"), "Template" }, -{ sizeof("Typedef"), "Typedef" }, -{ sizeof("Typename"), "Typename" }, -{ sizeof("Union"), "Union" }, -{ sizeof("Union_Fwd"), "Union_Fwd" }, -{ sizeof("Union_Body"), "Union_Body" }, -{ sizeof("Using"), "Using" }, -{ sizeof("Using_Namespace"), "Using_Namespace" }, -{ sizeof("Variable"), "Variable" }, - }; return lookup[ type ]; + local_persist StrC lookup[61] = { + { sizeof( "Invalid" ), "Invalid" }, + { sizeof( "Untyped" ), "Untyped" }, + { sizeof( "NewLine" ), "NewLine" }, + { sizeof( "Comment" ), "Comment" }, + { sizeof( "Access_Private" ), "Access_Private" }, + { sizeof( "Access_Protected" ), "Access_Protected" }, + { sizeof( "Access_Public" ), "Access_Public" }, + { sizeof( "PlatformAttributes" ), "PlatformAttributes" }, + { sizeof( "Class" ), "Class" }, + { sizeof( "Class_Fwd" ), "Class_Fwd" }, + { sizeof( "Class_Body" ), "Class_Body" }, + { sizeof( "Constructor" ), "Constructor" }, + { sizeof( "Constructor_Fwd" ), "Constructor_Fwd" }, + { sizeof( "Destructor" ), "Destructor" }, + { sizeof( "Destructor_Fwd" ), "Destructor_Fwd" }, + { sizeof( "Enum" ), "Enum" }, + { sizeof( "Enum_Fwd" ), "Enum_Fwd" }, + { sizeof( "Enum_Body" ), "Enum_Body" }, + { sizeof( "Enum_Class" ), "Enum_Class" }, + { sizeof( "Enum_Class_Fwd" ), "Enum_Class_Fwd" }, + { sizeof( "Execution" ), "Execution" }, + { sizeof( "Export_Body" ), "Export_Body" }, + { sizeof( "Extern_Linkage" ), "Extern_Linkage" }, + { sizeof( "Extern_Linkage_Body" ), "Extern_Linkage_Body" }, + { sizeof( "Friend" ), "Friend" }, + { sizeof( "Function" ), "Function" }, + { sizeof( "Function_Fwd" ), "Function_Fwd" }, + { sizeof( "Function_Body" ), "Function_Body" }, + { sizeof( "Global_Body" ), "Global_Body" }, + { sizeof( "Module" ), "Module" }, + { sizeof( "Namespace" ), "Namespace" }, + { sizeof( "Namespace_Body" ), "Namespace_Body" }, + { sizeof( "Operator" ), "Operator" }, + { sizeof( "Operator_Fwd" ), "Operator_Fwd" }, + { sizeof( "Operator_Member" ), "Operator_Member" }, + { sizeof( "Operator_Member_Fwd" ), "Operator_Member_Fwd" }, + { sizeof( "Operator_Cast" ), "Operator_Cast" }, + { sizeof( "Operator_Cast_Fwd" ), "Operator_Cast_Fwd" }, + { sizeof( "Parameters" ), "Parameters" }, + { sizeof( "Preprocess_Define" ), "Preprocess_Define" }, + { sizeof( "Preprocess_Include" ), "Preprocess_Include" }, + { sizeof( "Preprocess_If" ), "Preprocess_If" }, + { sizeof( "Preprocess_IfDef" ), "Preprocess_IfDef" }, + { sizeof( "Preprocess_IfNotDef" ), "Preprocess_IfNotDef" }, + { sizeof( "Preprocess_ElIf" ), "Preprocess_ElIf" }, + { sizeof( "Preprocess_Else" ), "Preprocess_Else" }, + { sizeof( "Preprocess_EndIf" ), "Preprocess_EndIf" }, + { sizeof( "Preprocess_Pragma" ), "Preprocess_Pragma" }, + { sizeof( "Specifiers" ), "Specifiers" }, + { sizeof( "Struct" ), "Struct" }, + { sizeof( "Struct_Fwd" ), "Struct_Fwd" }, + { sizeof( "Struct_Body" ), "Struct_Body" }, + { sizeof( "Template" ), "Template" }, + { sizeof( "Typedef" ), "Typedef" }, + { sizeof( "Typename" ), "Typename" }, + { sizeof( "Union" ), "Union" }, + { sizeof( "Union_Fwd" ), "Union_Fwd" }, + { sizeof( "Union_Body" ), "Union_Body" }, + { sizeof( "Using" ), "Using" }, + { sizeof( "Using_Namespace" ), "Using_Namespace" }, + { sizeof( "Variable" ), "Variable" }, + }; + return lookup[type]; } +inline StrC codetype_to_keyword_str( CodeType type ) +{ + local_persist StrC lookup[61] = { + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "//" ), "//" }, + { sizeof( "private" ), "private" }, + { sizeof( "protected" ), "protected" }, + { sizeof( "public" ), "public" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "class" ), "class" }, + { sizeof( "clsss" ), "clsss" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "enum" ), "enum" }, + { sizeof( "enum" ), "enum" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "enum class" ), "enum class" }, + { sizeof( "enum class" ), "enum class" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "extern" ), "extern" }, + { sizeof( "extern" ), "extern" }, + { sizeof( "friend" ), "friend" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "module" ), "module" }, + { sizeof( "namespace" ), "namespace" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "define" ), "define" }, + { sizeof( "include" ), "include" }, + { sizeof( "if" ), "if" }, + { sizeof( "ifdef" ), "ifdef" }, + { sizeof( "ifndef" ), "ifndef" }, + { sizeof( "elif" ), "elif" }, + { sizeof( "else" ), "else" }, + { sizeof( "endif" ), "endif" }, + { sizeof( "pragma" ), "pragma" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "struct" ), "struct" }, + { sizeof( "struct" ), "struct" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "template" ), "template" }, + { sizeof( "typedef" ), "typedef" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "union" ), "union" }, + { sizeof( "union" ), "union" }, + { sizeof( "__NA__" ), "__NA__" }, + { sizeof( "using" ), "using" }, + { sizeof( "using namespace" ), "using namespace" }, + { sizeof( "__NA__" ), "__NA__" }, + }; + return lookup[type]; +} + +forceinline StrC to_str( CodeType type ) +{ + return codetype_to_str( type ); +} + +forceinline StrC to_keyword_str( CodeType type ) +{ + return codetype_to_keyword_str( type ); +} diff --git a/project/components/gen/eoperator.hpp b/project/components/gen/eoperator.hpp index 34493e5..d8c2d80 100644 --- a/project/components/gen/eoperator.hpp +++ b/project/components/gen/eoperator.hpp @@ -7,59 +7,111 @@ 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 + 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 Operator; - inline -StrC operator_to_str( Operator op) + +inline StrC operator_to_str( Operator op ) { -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("new"), "new" }, -{ sizeof("new[]"), "new[]" }, -{ sizeof("delete"), "delete" }, -{ sizeof("delete[]"), "delete[]" }, - }; return lookup[ op ]; + 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( "new" ), "new" }, + { sizeof( "new[]" ), "new[]" }, + { sizeof( "delete" ), "delete" }, + { sizeof( "delete[]" ), "delete[]" }, + }; + return lookup[op]; } +forceinline StrC to_str( Operator op ) +{ + return operator_to_str( op ); +} diff --git a/project/components/gen/especifier.hpp b/project/components/gen/especifier.hpp index 8e56395..fb63f37 100644 --- a/project/components/gen/especifier.hpp +++ b/project/components/gen/especifier.hpp @@ -7,48 +7,101 @@ 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 + 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) + +inline StrC spec_to_str( Specifier type ) { -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; + 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 bool spec_is_trailing( Specifier specifier ) +{ + return specifier > Spec_Virtual; +} + +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; +} + +forceinline StrC to_str( Specifier spec ) +{ + return spec_to_str( spec ); +} + +forceinline Specifier to_type( StrC str ) +{ + return strc_to_specifier( str ); +} + +forceinline bool is_trailing( Specifier specifier ) +{ + return spec_is_trailing( specifier ); +} diff --git a/project/components/gen/etoktype.cpp b/project/components/gen/etoktype.cpp index 83e8b66..7116eaf 100644 --- a/project/components/gen/etoktype.cpp +++ b/project/components/gen/etoktype.cpp @@ -6,119 +6,230 @@ // This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp) 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 { -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_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 }; typedef enum TokType_Def TokType; - inline -StrC to_str( TokType type) + +inline StrC to_str( TokType type ) { -local_persist StrC lookup[] { { sizeof("__invalid__"), "__invalid__" }, -{ sizeof("private"), "private" }, -{ sizeof("protected"), "protected" }, -{ sizeof("public"), "public" }, -{ sizeof("."), "." }, -{ sizeof("::"), "::" }, -{ sizeof("&"), "&" }, -{ sizeof("&&"), "&&" }, -{ sizeof(":"), ":" }, -{ sizeof("[["), "[[" }, -{ sizeof("]]"), "]]" }, -{ sizeof("{"), "{" }, -{ sizeof("}"), "}" }, -{ sizeof("["), "[" }, -{ sizeof("]"), "]" }, -{ sizeof("("), "(" }, -{ sizeof(")"), ")" }, -{ sizeof("__comment__"), "__comment__" }, -{ sizeof("__comment_end__"), "__comment_end__" }, -{ sizeof("__comment_start__"), "__comment_start__" }, -{ sizeof("__character__"), "__character__" }, -{ sizeof(","), "," }, -{ sizeof("class"), "class" }, -{ sizeof("__attribute__"), "__attribute__" }, -{ sizeof("__declspec"), "__declspec" }, -{ sizeof("enum"), "enum" }, -{ sizeof("extern"), "extern" }, -{ sizeof("friend"), "friend" }, -{ sizeof("module"), "module" }, -{ sizeof("namespace"), "namespace" }, -{ sizeof("operator"), "operator" }, -{ sizeof("struct"), "struct" }, -{ sizeof("template"), "template" }, -{ sizeof("typedef"), "typedef" }, -{ sizeof("using"), "using" }, -{ sizeof("union"), "union" }, -{ sizeof("__identifier__"), "__identifier__" }, -{ sizeof("import"), "import" }, -{ sizeof("export"), "export" }, -{ sizeof("__new_line__"), "__new_line__" }, -{ sizeof("__number__"), "__number__" }, -{ sizeof("__operator__"), "__operator__" }, -{ sizeof("#"), "#" }, -{ sizeof("define"), "define" }, -{ sizeof("if"), "if" }, -{ sizeof("ifdef"), "ifdef" }, -{ sizeof("ifndef"), "ifndef" }, -{ sizeof("elif"), "elif" }, -{ sizeof("else"), "else" }, -{ sizeof("endif"), "endif" }, -{ sizeof("include"), "include" }, -{ sizeof("pragma"), "pragma" }, -{ sizeof("__macro_content__"), "__macro_content__" }, -{ sizeof("__macro__"), "__macro__" }, -{ sizeof("__unsupported__"), "__unsupported__" }, -{ sizeof("alignas"), "alignas" }, -{ sizeof("const"), "const" }, -{ sizeof("consteval"), "consteval" }, -{ sizeof("constexpr"), "constexpr" }, -{ sizeof("constinit"), "constinit" }, -{ sizeof("explicit"), "explicit" }, -{ sizeof("extern"), "extern" }, -{ sizeof("final"), "final" }, -{ sizeof("forceinline"), "forceinline" }, -{ sizeof("global"), "global" }, -{ sizeof("inline"), "inline" }, -{ sizeof("internal"), "internal" }, -{ sizeof("local_persist"), "local_persist" }, -{ sizeof("mutable"), "mutable" }, -{ sizeof("neverinline"), "neverinline" }, -{ sizeof("override"), "override" }, -{ sizeof("static"), "static" }, -{ sizeof("thread_local"), "thread_local" }, -{ sizeof("volatile"), "volatile" }, -{ sizeof("virtual"), "virtual" }, -{ sizeof("*"), "*" }, -{ sizeof(";"), ";" }, -{ sizeof("static_assert"), "static_assert" }, -{ sizeof("__string__"), "__string__" }, -{ sizeof("typename"), "typename" }, -{ sizeof("unsigned"), "unsigned" }, -{ sizeof("signed"), "signed" }, -{ sizeof("short"), "short" }, -{ sizeof("long"), "long" }, -{ sizeof("bool"), "bool" }, -{ sizeof("char"), "char" }, -{ sizeof("int"), "int" }, -{ sizeof("double"), "double" }, -{ sizeof("__int8"), "__int8" }, -{ sizeof("__int16"), "__int16" }, -{ sizeof("__int32"), "__int32" }, -{ sizeof("__int64"), "__int64" }, -{ sizeof("_W64"), "_W64" }, -{ sizeof("..."), "..." }, -{ sizeof("__attrib_start__"), "__attrib_start__" }, - { sizeof("GEN_API_Export_Code"), "GEN_API_Export_Code" }, -{ sizeof("GEN_API_Import_Code"), "GEN_API_Import_Code" }, - }; return lookup[ type ]; + local_persist StrC lookup[] { + { sizeof( "__invalid__" ), "__invalid__" }, + { sizeof( "private" ), "private" }, + { sizeof( "protected" ), "protected" }, + { sizeof( "public" ), "public" }, + { sizeof( "." ), "." }, + { sizeof( "::" ), "::" }, + { sizeof( "&" ), "&" }, + { sizeof( "&&" ), "&&" }, + { sizeof( ":" ), ":" }, + { sizeof( "[[" ), "[[" }, + { sizeof( "]]" ), "]]" }, + { sizeof( "{" ), "{" }, + { sizeof( "}" ), "}" }, + { sizeof( "[" ), "[" }, + { sizeof( "]" ), "]" }, + { sizeof( "(" ), "(" }, + { sizeof( ")" ), ")" }, + { sizeof( "__comment__" ), "__comment__" }, + { sizeof( "__comment_end__" ), "__comment_end__" }, + { sizeof( "__comment_start__" ), "__comment_start__" }, + { sizeof( "__character__" ), "__character__" }, + { sizeof( "," ), "," }, + { sizeof( "class" ), "class" }, + { sizeof( "__attribute__" ), "__attribute__" }, + { sizeof( "__declspec" ), "__declspec" }, + { sizeof( "enum" ), "enum" }, + { sizeof( "extern" ), "extern" }, + { sizeof( "friend" ), "friend" }, + { sizeof( "module" ), "module" }, + { sizeof( "namespace" ), "namespace" }, + { sizeof( "operator" ), "operator" }, + { sizeof( "struct" ), "struct" }, + { sizeof( "template" ), "template" }, + { sizeof( "typedef" ), "typedef" }, + { sizeof( "using" ), "using" }, + { sizeof( "union" ), "union" }, + { sizeof( "__identifier__" ), "__identifier__" }, + { sizeof( "import" ), "import" }, + { sizeof( "export" ), "export" }, + { sizeof( "__new_line__" ), "__new_line__" }, + { sizeof( "__number__" ), "__number__" }, + { sizeof( "__operator__" ), "__operator__" }, + { sizeof( "#" ), "#" }, + { sizeof( "define" ), "define" }, + { sizeof( "if" ), "if" }, + { sizeof( "ifdef" ), "ifdef" }, + { sizeof( "ifndef" ), "ifndef" }, + { sizeof( "elif" ), "elif" }, + { sizeof( "else" ), "else" }, + { sizeof( "endif" ), "endif" }, + { sizeof( "include" ), "include" }, + { sizeof( "pragma" ), "pragma" }, + { sizeof( "__macro_content__" ), "__macro_content__" }, + { sizeof( "__macro__" ), "__macro__" }, + { sizeof( "__unsupported__" ), "__unsupported__" }, + { sizeof( "alignas" ), "alignas" }, + { sizeof( "const" ), "const" }, + { sizeof( "consteval" ), "consteval" }, + { sizeof( "constexpr" ), "constexpr" }, + { sizeof( "constinit" ), "constinit" }, + { sizeof( "explicit" ), "explicit" }, + { sizeof( "extern" ), "extern" }, + { sizeof( "final" ), "final" }, + { sizeof( "forceinline" ), "forceinline" }, + { sizeof( "global" ), "global" }, + { sizeof( "inline" ), "inline" }, + { sizeof( "internal" ), "internal" }, + { sizeof( "local_persist" ), "local_persist" }, + { sizeof( "mutable" ), "mutable" }, + { sizeof( "neverinline" ), "neverinline" }, + { sizeof( "override" ), "override" }, + { sizeof( "static" ), "static" }, + { sizeof( "thread_local" ), "thread_local" }, + { sizeof( "volatile" ), "volatile" }, + { sizeof( "virtual" ), "virtual" }, + { sizeof( "*" ), "*" }, + { sizeof( ";" ), ";" }, + { sizeof( "static_assert" ), "static_assert" }, + { sizeof( "__string__" ), "__string__" }, + { sizeof( "typename" ), "typename" }, + { sizeof( "unsigned" ), "unsigned" }, + { sizeof( "signed" ), "signed" }, + { sizeof( "short" ), "short" }, + { sizeof( "long" ), "long" }, + { sizeof( "bool" ), "bool" }, + { sizeof( "char" ), "char" }, + { sizeof( "int" ), "int" }, + { sizeof( "double" ), "double" }, + { sizeof( "__int8" ), "__int8" }, + { sizeof( "__int16" ), "__int16" }, + { sizeof( "__int32" ), "__int32" }, + { sizeof( "__int64" ), "__int64" }, + { sizeof( "_W64" ), "_W64" }, + { sizeof( "..." ), "..." }, + { sizeof( "__attrib_start__" ), "__attrib_start__" }, + { sizeof( "GEN_API_Export_Code" ), "GEN_API_Export_Code" }, + { sizeof( "GEN_API_Import_Code" ), "GEN_API_Import_Code" }, + }; + return lookup[type]; } - inline -TokType to_toktype( StrC str) + +inline TokType to_toktype( StrC str ) { -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; + 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; } + GEN_NS_PARSER_END diff --git a/project/components/header_end.hpp b/project/components/header_end.hpp index d12dad2..74d76cc 100644 --- a/project/components/header_end.hpp +++ b/project/components/header_end.hpp @@ -25,7 +25,7 @@ # define GEN_MAX_UNTYPED_STR_LENGTH megabytes(1) #endif #ifndef GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE -# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(4) +# define GEN_TOKEN_FMT_TOKEN_MAP_MEM_SIZE kilobytes(8) #endif #ifndef GEN_LEX_ALLOCATOR_SIZE # define GEN_LEX_ALLOCATOR_SIZE megabytes(4) @@ -42,7 +42,7 @@ constexpr s32 InitSize_DataArrays = 16; // NOTE: This limits the maximum size of an allocation // If you are generating a string larger than this, increase the size of the bucket here. -constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE; +constexpr usize Global_BucketSize = GEN_GLOBAL_BUCKET_SIZE; constexpr s32 CodePool_NumBlocks = GEN_CODEPOOL_NUM_BLOCKS; constexpr s32 SizePer_StringArena = GEN_SIZE_PER_STRING_ARENA; @@ -131,38 +131,12 @@ extern CodeTypename t_typename; #pragma endregion Constants -#pragma region Macros - -#ifndef token_fmt -# define gen_main main - -# define __ NullCode - - // Convienence for defining any name used with the gen api. - // Lets you provide the length and string literal to the functions without the need for the DSL. -# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) } - - // Same as name just used to indicate intention of literal for code instead of names. -# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) } - -# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__ - -# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) ) -# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) ) - - // Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string. -# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ ) -#endif - -#pragma endregion Macros - // Used by the lexer to persistently treat all these identifiers as preprocessor defines. // Populate with strings via gen::get_cached_string. // Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments. extern Array(StringCached) PreprocessorDefines; #ifdef GEN_EXPOSE_BACKEND - // Global allocator used for data with process lifetime. extern AllocatorInfo GlobalAllocator; extern Array(Arena) Global_AllocatorBuckets; @@ -180,5 +154,4 @@ extern Array(StringCached) PreprocessorDefines; extern AllocatorInfo Allocator_StringArena; extern AllocatorInfo Allocator_StringTable; extern AllocatorInfo Allocator_TypeTable; - #endif diff --git a/project/components/inlines.hpp b/project/components/inlines.hpp index d2b70ac..97cfbd1 100644 --- a/project/components/inlines.hpp +++ b/project/components/inlines.hpp @@ -183,6 +183,7 @@ void params_append( CodeParam appendee, CodeParam other ) { GEN_ASSERT(appendee); GEN_ASSERT(other); + GEN_ASSERT_MSG(appendee != other, "Attempted to append parameter to itself."); Code self = cast(Code, appendee); Code entry = cast(Code, other); @@ -250,7 +251,8 @@ CodeParam end_CodeParam(CodeParam params) forceinline CodeParam next_CodeParam(CodeParam params, CodeParam param_iter) { - return params->Next; + GEN_ASSERT(param_iter); + return param_iter->Next; } #pragma endregion CodeParam diff --git a/project/components/interface.cpp b/project/components/interface.cpp index 747cdf8..2d4cb24 100644 --- a/project/components/interface.cpp +++ b/project/components/interface.cpp @@ -3,10 +3,10 @@ #include "code_serialization.cpp" #endif -namespace parser { +GEN_NS_PARSER_BEGIN internal void init(); internal void deinit(); -} +GEN_NS_PARSER_END internal void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) diff --git a/project/components/interface.hpp b/project/components/interface.hpp index 29895c6..b29f28b 100644 --- a/project/components/interface.hpp +++ b/project/components/interface.hpp @@ -161,7 +161,7 @@ struct Opts_def_variable CodeAttributes attributes; ModuleFlag mflags; }; -CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT ); +CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable opts GEN_PARAM_DEFAULT ); // Constructs an empty body. Use AST::validate_body() to check if the body is was has valid entries. CodeBody def_body( CodeTypename type ); @@ -266,4 +266,55 @@ Code untyped_token_fmt( char const* fmt, s32 num_tokens, ... ); #pragma endregion Untyped text +#pragma region Macros + +#ifndef token_fmt +# define gen_main main + +# define __ NullCode + + // Convienence for defining any name used with the gen api. + // Lets you provide the length and string literal to the functions without the need for the DSL. +# define name( Id_ ) { sizeof(stringize( Id_ )) - 1, stringize(Id_) } + + // Same as name just used to indicate intention of literal for code instead of names. +# define code( ... ) { sizeof(stringize(__VA_ARGS__)) - 1, stringize( __VA_ARGS__ ) } + + // Provides the number of arguments while passing args inplace. +# define args( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__ + + // Just wrappers over common untyped code definition constructions. +# define code_str( ... ) GEN_NS untyped_str( code( __VA_ARGS__ ) ) +# define code_fmt( ... ) GEN_NS untyped_str( token_fmt( __VA_ARGS__ ) ) + +# define parse_fmt( type, ... ) GEN_NS parse_##type( token_fmt( __VA_ARGS__ ) ) + + /* + Takes a format string (char const*) and a list of tokens (StrC) and returns a StrC of the formatted string. + Tokens are provided in '<'identifier'>' format where '<' '>' are just angle brakcets (you can change it in token_fmt_va) + --------------------------------------------------------- + Example - A string with: + typedef ; + Will have a token_fmt arguments populated with: + "type", strc_for_type, + "name", strc_for_name, + and: + stringize( typedef ; ) ) + ----------------------------------------------------------- + So the full call for this example would be: + token_fmt( + "type", strc_for_type + , "name", strc_for_name + , stringize( + typedef + )); + !---------------------------------------------------------- + ! Note: token_fmt_va is whitespace sensitive for the tokens. + ! This can be alleviated by skipping whitespace between brackets but it was choosen to not have that implementation by default. + */ +# define token_fmt( ... ) GEN_NS token_fmt_impl( (num_args( __VA_ARGS__ ) + 1) / 2, __VA_ARGS__ ) +#endif + +#pragma endregion Macros + #pragma endregion Gen Interface diff --git a/project/components/interface.upfront.cpp b/project/components/interface.upfront.cpp index 839cd99..4a22a4c 100644 --- a/project/components/interface.upfront.cpp +++ b/project/components/interface.upfront.cpp @@ -21,29 +21,29 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp } #pragma region Helper Macros -# define check_params() \ - if ( ! params_code ) \ - { \ - log_failure("gen::def_operator: params is null and operator%s requires it", operator_to_str(op)); \ - return OpValResult_Fail; \ - } \ - if ( params_code->Type != CT_Parameters ) \ - { \ +# define check_params() \ + if ( ! params_code ) \ + { \ + log_failure("gen::def_operator: params is null and operator%s requires it", operator_to_str(op)); \ + return OpValResult_Fail; \ + } \ + if ( params_code->Type != CT_Parameters ) \ + { \ 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() \ - 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" \ - "param types: %s\n" \ - "return type: %s", \ - operator_to_str(op).Ptr, \ - code_debug_str(cast(Code, params_code)), \ - code_debug_str(cast(Code, ret_type)) \ - ); \ - return OpValResult_Fail; \ +# define check_param_eq_ret() \ + 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" \ + "param types: %s\n" \ + "return type: %s", \ + operator_to_str(op).Ptr, \ + code_debug_str(cast(Code, params_code)), \ + code_debug_str(cast(Code, ret_type)) \ + ); \ + return OpValResult_Fail; \ } #pragma endregion Helper Macros @@ -216,9 +216,9 @@ OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeTyp if ( params_code->NumEntries > 1 ) { log_failure( - "gen::def_operator: operator%s may not have more than one parameter - param count: %d", - operator_to_str( op ), - params_code->NumEntries + "gen::def_operator: operator%s may not have more than one parameter - param count: %d", + operator_to_str( op ), + params_code->NumEntries ); return OpValResult_Fail; } diff --git a/project/components/parser.cpp b/project/components/parser.cpp index 2c44806..8408e6b 100644 --- a/project/components/parser.cpp +++ b/project/components/parser.cpp @@ -1614,6 +1614,13 @@ CodeBody parse_global_nspace( CodeType which ) switch ( currtok_noskip.Type ) { + case Tok_Comma: + { + log_failure("Dangling comma found: %S\nContext:\n%S", to_string(currtok), to_string(Context)); + pop( & Context); + return InvalidCode; + } + break; case Tok_Statement_End: { // TODO(Ed): Convert this to a general warning procedure @@ -1885,7 +1892,7 @@ CodeBody parse_global_nspace( CodeType which ) if ( member == Code_Invalid ) { - log_failure( "Failed to parse member\n%s", to_string(Context) ); + log_failure( "Failed to parse member\nToken: %s\nContext:\n%s", to_string(currtok_noskip), to_string(Context) ); pop(& Context); return InvalidCode; } diff --git a/project/components/types.hpp b/project/components/types.hpp index e7a9e81..8ed26f9 100644 --- a/project/components/types.hpp +++ b/project/components/types.hpp @@ -13,7 +13,7 @@ using LogFailType = ssize(*)(char const*, ...); #define log_failure GEN_FATAL #endif -enum AccessSpec enum_underlying(u32) +enum AccessSpec : u32 { AccessSpec_Default, AccessSpec_Private, @@ -28,7 +28,7 @@ enum AccessSpec enum_underlying(u32) static_assert( size_of(AccessSpec) == size_of(u32), "AccessSpec not u32 size" ); inline -char const* to_str( AccessSpec type ) +char const* access_spec_to_str( AccessSpec type ) { local_persist char const* lookup[ (u32)AccessSpec_Num_AccessSpec ] = { @@ -44,7 +44,7 @@ char const* to_str( AccessSpec type ) return lookup[ (u32)type ]; } -enum CodeFlag enum_underlying(u32) +enum CodeFlag : u32 { CodeFlag_None = 0, CodeFlag_FunctionType = bit(0), @@ -57,7 +57,7 @@ enum CodeFlag enum_underlying(u32) static_assert( size_of(CodeFlag) == size_of(u32), "CodeFlag not u32 size" ); // Used to indicate if enum definitoin is an enum class or regular enum. -enum EnumDecl enum_underlying(u8) +enum EnumDecl : u8 { EnumDecl_Regular, EnumDecl_Class, @@ -66,7 +66,7 @@ enum EnumDecl enum_underlying(u8) }; typedef u8 EnumT; -enum ModuleFlag enum_underlying(u32) +enum ModuleFlag : u32 { ModuleFlag_None = 0, ModuleFlag_Export = bit(0), @@ -80,28 +80,24 @@ enum ModuleFlag enum_underlying(u32) static_assert( size_of(ModuleFlag) == size_of(u32), "ModuleFlag not u32 size" ); inline -StrC to_str( ModuleFlag flag ) +StrC module_flag_to_str( ModuleFlag flag ) { local_persist - StrC lookup[ (u32)ModuleFlag::Num_ModuleFlags ] = { + StrC lookup[ (u32)Num_ModuleFlags ] = { { sizeof("__none__"), "__none__" }, { sizeof("export"), "export" }, { sizeof("import"), "import" }, }; + local_persist + StrC invalid_flag = { sizeof("invalid"), "invalid" }; if ( flag > ModuleFlag_Import ) - return { sizeof("invalid"), "invalid" }; + return invalid_flag; return lookup[ (u32)flag ]; } -inline -ModuleFlag operator|( ModuleFlag A, ModuleFlag B) -{ - return (ModuleFlag)( (u32)A | (u32)B ); -} - -enum EPreprocessCond enum_underlying(u32) +enum EPreprocessCond : u32 { PreprocessCond_If, PreprocessCond_IfDef, diff --git a/project/dependencies/containers.hpp b/project/dependencies/containers.hpp index 5ef4c88..057fa7a 100644 --- a/project/dependencies/containers.hpp +++ b/project/dependencies/containers.hpp @@ -66,27 +66,27 @@ struct Array Type* Data; #pragma region Member Mapping - forceinline static Array init(AllocatorInfo allocator) { return GEN_NS array_init(allocator); } - forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return GEN_NS array_init_reserve(allocator, capacity); } - forceinline static usize grow_formula(ssize value) { return GEN_NS array_grow_formula(value); } + forceinline static Array init(AllocatorInfo allocator) { return array_init(allocator); } + forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return array_init_reserve(allocator, capacity); } + forceinline static usize grow_formula(ssize value) { return array_grow_formula(value); } - forceinline bool append(Array other) { return GEN_NS array_append_array(this, other); } - forceinline bool append(Type value) { return GEN_NS array_append(this, value); } - forceinline bool append(Type* items, usize item_num) { return GEN_NS array_append_items(this, items, item_num); } - forceinline bool append_at(Type item, usize idx) { return GEN_NS array_append_at(this, item, idx); } - forceinline bool append_at(Type* items, usize item_num, usize idx) { return GEN_NS array_append_items_at(this, items, item_num, idx); } - forceinline Type* back() { return GEN_NS array_back(* this); } - forceinline void clear() { GEN_NS array_clear(* this); } - forceinline bool fill(usize begin, usize end, Type value) { return GEN_NS array_fill(* this, begin, end, value); } - forceinline void free() { GEN_NS array_free(this); } - forceinline ArrayHeader* get_header() { return GEN_NS array_get_header(* this); } - forceinline bool grow(usize min_capacity) { return GEN_NS array_grow(this, min_capacity); } - forceinline usize num() { return GEN_NS array_num(*this); } - forceinline void pop() { GEN_NS array_pop(* this); } - forceinline void remove_at(usize idx) { GEN_NS array_remove_at(* this, idx); } - forceinline bool reserve(usize new_capacity) { return GEN_NS array_reserve(this, new_capacity); } - forceinline bool resize(usize num) { return GEN_NS array_resize(this, num); } - forceinline bool set_capacity(usize new_capacity) { return GEN_NS array_set_capacity(this, new_capacity); } + forceinline bool append(Array other) { return array_append_array(this, other); } + forceinline bool append(Type value) { return array_append(this, value); } + forceinline bool append(Type* items, usize item_num) { return array_append_items(this, items, item_num); } + forceinline bool append_at(Type item, usize idx) { return array_append_at(this, item, idx); } + forceinline bool append_at(Type* items, usize item_num, usize idx) { return array_append_items_at(this, items, item_num, idx); } + forceinline Type* back() { return array_back(* this); } + forceinline void clear() { array_clear(* this); } + forceinline bool fill(usize begin, usize end, Type value) { return array_fill(* this, begin, end, value); } + forceinline void free() { array_free(this); } + forceinline ArrayHeader* get_header() { return array_get_header(* this); } + forceinline bool grow(usize min_capacity) { return array_grow(this, min_capacity); } + forceinline usize num() { return array_num(*this); } + forceinline void pop() { array_pop(* this); } + forceinline void remove_at(usize idx) { array_remove_at(* this, idx); } + forceinline bool reserve(usize new_capacity) { return array_reserve(this, new_capacity); } + forceinline bool resize(usize num) { return array_resize(this, num); } + forceinline bool set_capacity(usize new_capacity) { return array_set_capacity(this, new_capacity); } #pragma endregion Member Mapping forceinline operator Type*() { return Data; } @@ -102,16 +102,16 @@ struct Array #endif #if GEN_COMPILER_CPP && 0 -template bool append(Array& array, Array other) { return GEN_NS append( & array, other ); } -template bool append(Array& array, Type value) { return GEN_NS append( & array, value ); } -template bool append(Array& array, Type* items, usize item_num) { return GEN_NS append( & array, items, item_num ); } -template bool append_at(Array& array, Type item, usize idx) { return GEN_NS append_at( & array, item, idx ); } -template bool append_at(Array& array, Type* items, usize item_num, usize idx) { return GEN_NS append_at( & array, items, item_num, idx ); } -template void free(Array& array) { return GEN_NS free( & array ); } -template bool grow(Array& array, usize min_capacity) { return GEN_NS grow( & array, min_capacity); } -template bool reserve(Array& array, usize new_capacity) { return GEN_NS reserve( & array, new_capacity); } -template bool resize(Array& array, usize num) { return GEN_NS resize( & array, num); } -template bool set_capacity(Array& array, usize new_capacity) { return GEN_NS set_capacity( & array, new_capacity); } +template bool append(Array& array, Array other) { return append( & array, other ); } +template bool append(Array& array, Type value) { return append( & array, value ); } +template bool append(Array& array, Type* items, usize item_num) { return append( & array, items, item_num ); } +template bool append_at(Array& array, Type item, usize idx) { return append_at( & array, item, idx ); } +template bool append_at(Array& array, Type* items, usize item_num, usize idx) { return append_at( & array, items, item_num, idx ); } +template void free(Array& array) { return free( & array ); } +template bool grow(Array& array, usize min_capacity) { return grow( & array, min_capacity); } +template bool reserve(Array& array, usize new_capacity) { return reserve( & array, new_capacity); } +template bool resize(Array& array, usize num) { return resize( & array, num); } +template bool set_capacity(Array& array, usize new_capacity) { return set_capacity( & array, new_capacity); } template forceinline Type* begin(Array& array) { return array; } template forceinline Type* end(Array& array) { return array + array_get_header(array)->Num; } @@ -134,7 +134,7 @@ Array array_init_reserve(AllocatorInfo allocator, ssize capacity) ArrayHeader* header = rcast(ArrayHeader*, alloc(allocator, sizeof(ArrayHeader) + sizeof(Type) * capacity)); if (header == nullptr) - return {nullptr}; + return {nullptr}; header->Allocator = allocator; header->Capacity = capacity; @@ -203,10 +203,10 @@ bool array_append_at(Array* array, Type item, usize idx) ssize slot = idx; if (slot >= header->Num) - slot = header->Num - 1; + slot = header->Num - 1; if (slot < 0) - slot = 0; + slot = 0; if (header->Capacity < header->Num + 1) { @@ -234,7 +234,7 @@ bool array_append_items_at(Array* array, Type* items, usize item_num, usiz if (idx >= header->Num) { return array_append_items(array, items, item_num); - } + } if (item_num > header->Capacity) { @@ -358,7 +358,7 @@ bool array_reserve(Array* array, usize new_capacity) ArrayHeader* header = array_get_header(array); if (header->Capacity < new_capacity) - return set_capacity(array, new_capacity); + return set_capacity(array, new_capacity); return true; } @@ -377,7 +377,7 @@ bool array_resize(Array* array, usize num) } header->Num = num; - return true; + return true; } template inline @@ -493,23 +493,23 @@ struct HashTable Array Hashes; Array> Entries; -#if GEN_SUPPORT_CPP_MEMBER_FEATURES +#if ! GEN_C_LIKE_CPP #pragma region Member Mapping - forceinline static HashTable init(AllocatorInfo allocator) { return GEN_NS hashtable_init(allocator); } - forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return GEN_NS hashtable_init_reserve(allocator, num); } + forceinline static HashTable init(AllocatorInfo allocator) { return hashtable_init(allocator); } + forceinline static HashTable init_reserve(AllocatorInfo allocator, usize num) { return hashtable_init_reserve(allocator, num); } - forceinline void clear() { GEN_NS clear(*this); } - forceinline void destroy() { GEN_NS destroy(*this); } - forceinline Type* get(u64 key) { return GEN_NS get(*this, key); } - forceinline void grow() { GEN_NS grow(*this); } - forceinline void rehash(ssize new_num) { GEN_NS rehash(*this, new_num); } - forceinline void rehash_fast() { GEN_NS rehash_fast(*this); } - forceinline void remove(u64 key) { GEN_NS remove(*this, key); } - forceinline void remove_entry(ssize idx) { GEN_NS remove_entry(*this, idx); } - forceinline void set(u64 key, Type value) { GEN_NS set(*this, key, value); } - forceinline ssize slot(u64 key) { return GEN_NS slot(*this, key); } - forceinline void map(void (*proc)(u64, Type)) { GEN_NS map(*this, proc); } - forceinline void map_mut(void (*proc)(u64, Type*)) { GEN_NS map_mut(*this, proc); } + forceinline void clear() { clear(*this); } + forceinline void destroy() { destroy(*this); } + forceinline Type* get(u64 key) { return get(*this, key); } + forceinline void grow() { grow(*this); } + forceinline void rehash(ssize new_num) { rehash(*this, new_num); } + forceinline void rehash_fast() { rehash_fast(*this); } + forceinline void remove(u64 key) { remove(*this, key); } + forceinline void remove_entry(ssize idx) { remove_entry(*this, idx); } + forceinline void set(u64 key, Type value) { set(*this, key, value); } + forceinline ssize slot(u64 key) { return slot(*this, key); } + forceinline void map(void (*proc)(u64, Type)) { map(*this, proc); } + forceinline void map_mut(void (*proc)(u64, Type*)) { map_mut(*this, proc); } #pragma endregion Member Mapping #endif diff --git a/project/dependencies/debug.cpp b/project/dependencies/debug.cpp index c5aaf59..6c188c1 100644 --- a/project/dependencies/debug.cpp +++ b/project/dependencies/debug.cpp @@ -7,9 +7,9 @@ #pragma region Debug -void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... ) +void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... ) { - _printf_err( "%s:(%d): Assert Failure: ", file, line ); + _printf_err( "%s - %s:(%d): Assert Failure: ", file, function, line ); if ( condition ) _printf_err( "`%s` \n", condition ); diff --git a/project/dependencies/debug.hpp b/project/dependencies/debug.hpp index 3b041bd..eae52d1 100644 --- a/project/dependencies/debug.hpp +++ b/project/dependencies/debug.hpp @@ -19,14 +19,14 @@ #define GEN_ASSERT( cond ) GEN_ASSERT_MSG( cond, NULL ) -#define GEN_ASSERT_MSG( cond, msg, ... ) \ - do \ - { \ - if ( ! ( cond ) ) \ - { \ - assert_handler( #cond, __FILE__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \ - GEN_DEBUG_TRAP(); \ - } \ +#define GEN_ASSERT_MSG( cond, msg, ... ) \ + do \ + { \ + if ( ! ( cond ) ) \ + { \ + assert_handler( #cond, __FILE__, __func__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \ + GEN_DEBUG_TRAP(); \ + } \ } while ( 0 ) #define GEN_ASSERT_NOT_NULL( ptr ) GEN_ASSERT_MSG( ( ptr ) != NULL, #ptr " must not be NULL" ) @@ -56,7 +56,7 @@ while (0) #endif -void assert_handler( char const* condition, char const* file, s32 line, char const* msg, ... ); +void assert_handler( char const* condition, char const* file, char const* function, s32 line, char const* msg, ... ); s32 assert_crash( char const* condition ); void process_exit( u32 code ); diff --git a/project/dependencies/filesystem.hpp b/project/dependencies/filesystem.hpp index 5c3f9da..94adc18 100644 --- a/project/dependencies/filesystem.hpp +++ b/project/dependencies/filesystem.hpp @@ -5,8 +5,6 @@ #pragma region File Handling -typedef u32 FileMode; - enum FileModeFlag { EFileMode_READ = bit( 0 ), @@ -45,6 +43,7 @@ union FileDescriptor uptr u; }; +typedef u32 FileMode; typedef struct FileOperations FileOperations; #define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename ) @@ -107,7 +106,6 @@ struct FileInfo FileTime last_write_time; DirEntry* dir; }; -typedef struct FileInfo FileInfo; enum FileStandardType { @@ -117,7 +115,6 @@ enum FileStandardType EFileStandard_COUNT, }; -typedef enum FileStandardType FileStandardType; /** * Get standard file I/O. diff --git a/project/dependencies/macros.hpp b/project/dependencies/macros.hpp index 2cf4ca8..8f13bad 100644 --- a/project/dependencies/macros.hpp +++ b/project/dependencies/macros.hpp @@ -322,17 +322,17 @@ // Below are generated on demand for an overlaod depdendent on a type: // ---------------------------------------------------------------------------------------------------------------------------------- -#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \ -(selector_arg), /* Select Via Expression*/ \ - /* Extendibility slots: */ \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST(FunctionID__ARGS_SIG_1 ) \ +#define GEN_FUNCTION_GENERIC_EXAMPLE( selector_arg ) _Generic( \ +(selector_arg), /* Select Via Expression*/ \ + /* Extendibility slots: */ \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( FunctionID__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST(FunctionID__ARGS_SIG_1 ) \ ) GEN_RESOLVED_FUNCTION_CALL( selector_arg ) // ---------------------------------------------------------------------------------------------------------------------------------- @@ -355,17 +355,17 @@ size_t gen_example_hash__P_long_long( long long val ) { return val * 2654435761u // If using an Editor with support for syntax hightlighting macros: HASH__ARGS_SIG_1 and HASH_ARGS_SIG_2 should show color highlighting indicating the slot is enabled, // or, "defined" for usage during the compilation pass that handles the _Generic instrinsic. -#define hash( function_arguments ) _Generic( \ -(function_arguments), /* Select Via Expression*/ \ - /* Extendibility slots: */ \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \ - GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( HASH__ARGS_SIG_8 ) \ +#define hash( function_arguments ) _Generic( \ +(function_arguments), /* Select Via Expression*/ \ + /* Extendibility slots: */ \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_1 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_2 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_3 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_4 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_5 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_6 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( HASH__ARGS_SIG_7 ) \ + GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT_LAST( HASH__ARGS_SIG_8 ) \ ) GEN_RESOLVED_FUNCTION_CALL( function_arguments ) // Additional Variations: diff --git a/project/dependencies/memory.hpp b/project/dependencies/memory.hpp index 59fca53..f6eb4b7 100644 --- a/project/dependencies/memory.hpp +++ b/project/dependencies/memory.hpp @@ -193,17 +193,17 @@ struct Arena ssize TotalUsed; ssize TempCount; -#if GEN_COMPILER_CPP +#if ! GEN_C_LIKE_CPP #pragma region Member Mapping - forceinline operator AllocatorInfo() { return GEN_NS arena_allocator_info(this); } + forceinline operator AllocatorInfo() { return arena_allocator_info(this); } - forceinline static void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) { return GEN_NS arena_allocator_proc( allocator_data, type, size, alignment, old_memory, old_size, flags ); } - forceinline static Arena init_from_memory( void* start, ssize size ) { return GEN_NS arena_init_from_memory( start, size ); } - forceinline static Arena init_from_allocator( AllocatorInfo backing, ssize size ) { return GEN_NS arena_init_from_allocator( backing, size ); } - forceinline static Arena init_sub( Arena& parent, ssize size ) { return GEN_NS arena_init_from_allocator( parent.Backing, size ); } - forceinline ssize alignment_of( ssize alignment ) { return GEN_NS arena_alignment_of(this, alignment); } - forceinline void free() { return GEN_NS arena_free(this); } - forceinline ssize size_remaining( ssize alignment ) { return GEN_NS arena_size_remaining(this, alignment); } + forceinline static void* allocator_proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags ) { return arena_allocator_proc( allocator_data, type, size, alignment, old_memory, old_size, flags ); } + forceinline static Arena init_from_memory( void* start, ssize size ) { return arena_init_from_memory( start, size ); } + forceinline static Arena init_from_allocator( AllocatorInfo backing, ssize size ) { return arena_init_from_allocator( backing, size ); } + forceinline static Arena init_sub( Arena& parent, ssize size ) { return arena_init_from_allocator( parent.Backing, size ); } + forceinline ssize alignment_of( ssize alignment ) { return arena_alignment_of(this, alignment); } + forceinline void free() { return arena_free(this); } + forceinline ssize size_remaining( ssize alignment ) { return arena_size_remaining(this, alignment); } // This id is defined by Unreal for asserts #pragma push_macro("check") @@ -320,7 +320,7 @@ template FixedArena fixed_arena_init(); template AllocatorInfo fixed_arena_allocator_info(FixedArena* fixed_arena ); template ssize fixed_arena_size_remaining(FixedArena* fixed_arena, ssize alignment); -#if 0 +#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP template AllocatorInfo allocator_info( FixedArena& fixed_arena ) { return allocator_info(& fixed_arena); } template ssize size_remaining(FixedArena& fixed_arena, ssize alignment) { return size_remaining( & fixed_arena, alignment); } #endif @@ -333,12 +333,12 @@ struct FixedArena char memory[Size]; Arena arena; -#if 0 +#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP #pragma region Member Mapping forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); } - forceinline static FixedArena init() { FixedArena result; GEN_NS fixed_arena_init(result); return result; } - forceinline ssize size_remaining(ssize alignment) { GEN_NS size_remaining(this, alignment); } + forceinline static FixedArena init() { FixedArena result; fixed_arena_init(result); return result; } + forceinline ssize size_remaining(ssize alignment) { fixed_arena_size_remaining(this, alignment); } #pragma endregion Member Mapping #endif }; @@ -390,7 +390,7 @@ AllocatorInfo pool_allocator_info(Pool* pool); void pool_clear(Pool* pool); void pool_free(Pool* pool); -#if 0 +#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP AllocatorInfo allocator_info(Pool& pool) { return pool_allocator_info(& pool); } void clear(Pool& pool) { return pool_clear(& pool); } void free(Pool& pool) { return pool_free(& pool); } @@ -406,15 +406,15 @@ struct Pool ssize TotalSize; ssize NumBlocks; -#if ! GEN_C_LIKE_CPP +#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP #pragma region Member Mapping - forceinline operator AllocatorInfo() { return GEN_NS pool_allocator_info(this); } + forceinline operator AllocatorInfo() { return pool_allocator_info(this); } - forceinline static void* allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags) { return GEN_NS pool_allocator_proc(allocator_data, type, size, alignment, old_memory, old_size, flags); } - forceinline static Pool init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { return GEN_NS pool_init(backing, num_blocks, block_size); } - forceinline static Pool init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align) { return GEN_NS pool_init_align(backing, num_blocks, block_size, block_align); } - forceinline void clear() { GEN_NS pool_clear( this); } - forceinline void free() { GEN_NS pool_free( this); } + forceinline static void* allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags) { return pool_allocator_proc(allocator_data, type, size, alignment, old_memory, old_size, flags); } + forceinline static Pool init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { return pool_init(backing, num_blocks, block_size); } + forceinline static Pool init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align) { return pool_init_align(backing, num_blocks, block_size, block_align); } + forceinline void clear() { pool_clear( this); } + forceinline void free() { pool_free( this); } #pragma endregion #endif }; @@ -427,14 +427,14 @@ AllocatorInfo pool_allocator_info(Pool* pool) { inline Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size) { - return pool_init_align(backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT); + return pool_init_align(backing, num_blocks, block_size, GEN_DEFAULT_MEMORY_ALIGNMENT); } inline void pool_free(Pool* pool) { - if(pool->Backing.Proc) { - allocator_free(pool->Backing, pool->PhysicalStart); - } + if(pool->Backing.Proc) { + allocator_free(pool->Backing, pool->PhysicalStart); + } } #pragma endregion Pool diff --git a/project/dependencies/strings.hpp b/project/dependencies/strings.hpp index 3d8c3a2..21f68d0 100644 --- a/project/dependencies/strings.hpp +++ b/project/dependencies/strings.hpp @@ -5,8 +5,7 @@ #pragma region Strings -struct StrC_Def; -typedef struct StrC_Def StrC; +struct StrC; bool strc_are_equal (StrC lhs, StrC rhs); char const* strc_back (StrC str); @@ -17,7 +16,7 @@ StrC strc_to_str (char const* bad_string); StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator); // Constant string with length. -struct StrC_Def +struct StrC { ssize Len; char const* Ptr; @@ -27,12 +26,12 @@ struct StrC_Def forceinline char const& operator[]( ssize index ) const { return Ptr[index]; } #if ! GEN_C_LIKE_CPP - 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 bool contains (StrC substring) const { return GEN_NS strc_contains(* this, substring); } - forceinline StrC duplicate (AllocatorInfo allocator) const { return GEN_NS strc_duplicate(* this, allocator); } - forceinline b32 starts_with (StrC substring) const { return GEN_NS strc_starts_with(* this, substring); } - forceinline StrC visualize_whitespace(AllocatorInfo allocator) const { return GEN_NS strc_visualize_whitespace(* this, allocator); } + forceinline bool is_equal (StrC rhs) const { return strc_are_equal(* this, rhs); } + forceinline char const* back () const { return strc_back(* this); } + forceinline bool contains (StrC substring) const { return strc_contains(* this, substring); } + forceinline StrC duplicate (AllocatorInfo allocator) const { return strc_duplicate(* this, allocator); } + forceinline b32 starts_with (StrC substring) const { return strc_starts_with(* this, substring); } + forceinline StrC visualize_whitespace(AllocatorInfo allocator) const { return strc_visualize_whitespace(* this, allocator); } #endif #endif }; @@ -113,8 +112,7 @@ StrC to_strc_from_c_str( char const* bad_str ) { // They used a header pattern // I kept it for simplicty of porting but its not necessary to keep it that way. #pragma region String - struct StringHeader; -typedef struct StringHeader StringHeader; +struct StringHeader; #if GEN_COMPILER_C typedef char* String; @@ -267,11 +265,9 @@ struct String }; #endif -GEN_API_C_BEGIN forceinline char* string_begin(String str) { return ((char*) str); } forceinline char* string_end (String str) { return ((char*) str + string_length(str)); } forceinline char* string_next (String str, char const* iter) { return ((char*) iter + 1); } -GEN_API_C_END #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP forceinline char* begin(String str) { return ((char*) str); } @@ -488,18 +484,18 @@ bool string_contains_string(String const str, String const substring) forceinline ssize string_capacity(String const str) { - StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader)); - return header->Capacity; + StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader)); + return header->Capacity; } forceinline void string_clear(String str) { - string_get_header(str)->Length = 0; + string_get_header(str)->Length = 0; } forceinline String string_duplicate(String const str, AllocatorInfo allocator) { - return string_make_length(allocator, str, string_length(str)); + return string_make_length(allocator, str, string_length(str)); } forceinline @@ -514,14 +510,14 @@ void string_free(String* str) { forceinline StringHeader* string_get_header(String str) { - return (StringHeader*)(scast(char*, str) - sizeof(StringHeader)); + return (StringHeader*)(scast(char*, str) - sizeof(StringHeader)); } forceinline ssize string_length(String const str) { - StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader)); - return header->Length; + StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader)); + return header->Length; } inline @@ -586,7 +582,7 @@ void string_skip_line(String str) #define current (*scanner) char* scanner = str; while (current != '\r' && current != '\n') { - ++scanner; + ++scanner; } s32 new_length = scanner - str; @@ -605,23 +601,22 @@ void string_skip_line(String str) inline void strip_space(String str) { - char* write_pos = str; - char* read_pos = str; - - while (* read_pos) - { - if (! char_is_space(* read_pos)) - { - * write_pos = * read_pos; - write_pos++; - } - read_pos++; - } + char* write_pos = str; + char* read_pos = str; + while (* read_pos) + { + if (! char_is_space(* read_pos)) + { + * write_pos = * read_pos; + write_pos++; + } + read_pos++; + } write_pos[0] = '\0'; // Null-terminate the modified string - // Update the length if needed - string_get_header(str)->Length = write_pos - str; + // Update the length if needed + string_get_header(str)->Length = write_pos - str; } forceinline @@ -651,12 +646,12 @@ void trim(String str, char const* cut_set) str[len] = '\0'; - string_get_header(str)->Length = len; + string_get_header(str)->Length = len; } forceinline void trim_space(String str) { - trim(str, " \t\r\n\v\f"); + trim(str, " \t\r\n\v\f"); } inline @@ -712,7 +707,7 @@ inline StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator) { String result = string_make_reserve(allocator, str.Len * 2); // Assume worst case for space requirements. - for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c)) + for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c)) switch ( * c ) { case ' ': diff --git a/project/enums/ECode.csv b/project/enums/ECode.csv deleted file mode 100644 index 8ad029e..0000000 --- a/project/enums/ECode.csv +++ /dev/null @@ -1,61 +0,0 @@ -Invalid -Untyped -NewLine -Comment -Access_Private -Access_Protected -Access_Public -PlatformAttributes -Class -Class_Fwd -Class_Body -Constructor -Constructor_Fwd -Destructor -Destructor_Fwd -Enum -Enum_Fwd -Enum_Body -Enum_Class -Enum_Class_Fwd -Execution -Export_Body -Extern_Linkage -Extern_Linkage_Body -Friend -Function -Function_Fwd -Function_Body -Global_Body -Module -Namespace -Namespace_Body -Operator -Operator_Fwd -Operator_Member -Operator_Member_Fwd -Operator_Cast -Operator_Cast_Fwd -Parameters -Preprocess_Define -Preprocess_Include -Preprocess_If -Preprocess_IfDef -Preprocess_IfNotDef -Preprocess_ElIf -Preprocess_Else -Preprocess_EndIf -Preprocess_Pragma -Specifiers -Struct -Struct_Fwd -Struct_Body -Template -Typedef -Typename -Union -Union_Fwd -Union_Body -Using -Using_Namespace -Variable diff --git a/project/enums/ECodeTypes.csv b/project/enums/ECodeTypes.csv new file mode 100644 index 0000000..fe30838 --- /dev/null +++ b/project/enums/ECodeTypes.csv @@ -0,0 +1,61 @@ +Invalid, "__NA__" +Untyped, "__NA__" +NewLine, "__NA__" +Comment, "//" +Access_Private, "private" +Access_Protected, "protected" +Access_Public, "public" +PlatformAttributes, "__NA__" +Class, "class" +Class_Fwd, "clsss" +Class_Body, "__NA__" +Constructor, "__NA__" +Constructor_Fwd, "__NA__" +Destructor, "__NA__" +Destructor_Fwd, "__NA__" +Enum, "enum" +Enum_Fwd, "enum" +Enum_Body, "__NA__" +Enum_Class, "enum class" +Enum_Class_Fwd, "enum class" +Execution, "__NA__" +Export_Body, "__NA__" +Extern_Linkage, "extern" +Extern_Linkage_Body, "extern" +Friend, "friend" +Function, "__NA__" +Function_Fwd, "__NA__" +Function_Body, "__NA__" +Global_Body, "__NA__" +Module, "module" +Namespace, "namespace" +Namespace_Body, "__NA__" +Operator, "operator" +Operator_Fwd, "operator" +Operator_Member, "operator" +Operator_Member_Fwd, "operator" +Operator_Cast, "operator" +Operator_Cast_Fwd, "operator" +Parameters, "__NA__" +Preprocess_Define, "define" +Preprocess_Include, "include" +Preprocess_If, "if" +Preprocess_IfDef, "ifdef" +Preprocess_IfNotDef, "ifndef" +Preprocess_ElIf, "elif" +Preprocess_Else, "else" +Preprocess_EndIf, "endif" +Preprocess_Pragma, "pragma" +Specifiers, "__NA__" +Struct, "struct" +Struct_Fwd, "struct" +Struct_Body, "__NA__" +Template, "template" +Typedef, "typedef" +Typename, "__NA__" +Union, "union" +Union_Fwd, "union" +Union_Body, "__NA__" +Using, "using" +Using_Namespace, "using namespace" +Variable, "__NA__" diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index 09f8782..dd65af8 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -10,7 +10,7 @@ using namespace gen; CodeBody gen_ecode( char const* path, bool use_c_definition = false ) { - char scratch_mem[kilobytes(1)]; + char scratch_mem[kilobytes(4)]; Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) ); file_read_contents( arena_allocator_info( & scratch), file_zero_terminate, path ); @@ -18,17 +18,21 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) CSV_Object csv_nodes; csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false ); - Array enum_strs = csv_nodes.nodes[0].nodes; + Array enum_strs = csv_nodes.nodes[0].nodes; + Array keyword_strs = csv_nodes.nodes[1].nodes; - String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) ); - String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) ); + String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) ); + String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) ); + String to_keyword_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) ); - for ( ADT_Node* node = array_begin(enum_strs); node != array_end(enum_strs); node = array_next(enum_strs, node) ) + for ( ssize idx = 0; idx < array_num(enum_strs); ++ idx ) { - char const* code = node->string; + char const* code = enum_strs [idx].string; + char const* keyword = keyword_strs[idx].string; - string_append_fmt( & enum_entries, "CT_%s,\n", code ); - string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code ); + string_append_fmt( & enum_entries, "CT_%s,\n", code ); + string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code ); + string_append_fmt( & to_keyword_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", keyword, keyword ); } CodeEnum enum_code; @@ -48,9 +52,10 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) #pragma push_macro("local_persist") #undef local_persist StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) )); - CodeFn to_str = parse_function( token_fmt( - "entries", string_to_strc(to_str_entries) - , "num", lookup_size + CodeBody to_str_fns = parse_global_body( token_fmt( + "entries", string_to_strc(to_str_entries) + , "keywords", string_to_strc(to_keyword_str_entries) + , "num", lookup_size , stringize( inline StrC codetype_to_str( CodeType type ) @@ -59,17 +64,41 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) StrC lookup[] = { }; + return lookup[ type ]; + } + inline + StrC codetype_to_keyword_str( CodeType type ) + { + local_persist + StrC lookup[ ] = { + + }; return lookup[ type ]; } ))); #pragma pop_macro("local_persist") - //CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) ); - //CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) ); - CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; )); - - return def_global_body( args( enum_code, code_t, to_str, fmt_newline ) ); + CodeBody result = def_body(CT_Global_Body); + body_append(result, enum_code); + body_append(result, to_str_fns); + if (! use_c_definition) + { + #pragma push_macro("forceinline") + #undef forceinline + CodeBody alias_mappings = parse_global_body(code( + forceinline StrC to_str (CodeType type) { return codetype_to_str(type); } + forceinline StrC to_keyword_str(CodeType type) { return codetype_to_keyword_str(type); } + )); + #pragma pop_macro("forceinline") + body_append(result, alias_mappings); + } + else + { + CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; )); + body_append(result, code_t); + } + return result; } CodeBody gen_eoperator( char const* path, bool use_c_definition = false ) @@ -142,11 +171,25 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false ) ))); #pragma pop_macro("local_persist") - //CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) ); - //CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) ); - CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; )); - - return def_global_body( args( enum_code, operator_t, to_str, fmt_newline ) ); + CodeBody result = def_body(CT_Global_Body); + body_append(result, enum_code); + body_append(result, to_str); + if (! use_c_definition) + { + #pragma push_macro("forceinline") + #undef forceinline + CodeBody alias_mappings = parse_global_body(code( + forceinline StrC to_str(Operator op) { return operator_to_str(op); } + )); + #pragma pop_macro("forceinline") + body_append(result, alias_mappings); + } + else + { + CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; )); + body_append(result, operator_t); + } + return result; } CodeBody gen_especifier( char const* path, bool use_c_definition = false ) @@ -217,7 +260,6 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false ) #undef do_once_end #undef forceinline #undef neverinline - StrC lookup_size = string_to_strc(string_fmt_buf(GlobalAllocator, "%d", array_num(enum_strs) )); CodeFn to_str = parse_function(token_fmt( "entries", string_to_strc(to_str_entries) @@ -269,11 +311,29 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false ) #pragma pop_macro("forceinline") #pragma pop_macro("neverinline") - //CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) ); - //CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) ); - 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 ) ); + CodeBody result = def_body(CT_Global_Body); + body_append(result, enum_code); + body_append(result, to_str); + body_append(result, is_trailing); + body_append(result, to_type); + if (! use_c_definition) + { + #pragma push_macro("forceinline") + #undef forceinline + CodeBody alias_mappings = parse_global_body(code( + forceinline StrC to_str (Specifier spec) { return spec_to_str(spec); } + forceinline Specifier to_type( StrC str ) { return strc_to_specifier(str); } + forceinline bool is_trailing( Specifier specifier ) { return spec_is_trailing(specifier); } + )); + #pragma pop_macro("forceinline") + body_append(result, alias_mappings); + } + else + { + CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier Specifier; )); + body_append(result, specifier_t); + } + return result; } CodeBody gen_etoktype( char const* etok_path, char const* attr_path ) diff --git a/scripts/build.ci.ps1 b/scripts/build.ci.ps1 index a471ceb..cbf1bd5 100644 --- a/scripts/build.ci.ps1 +++ b/scripts/build.ci.ps1 @@ -2,7 +2,6 @@ # It will most likely need a partial rewrite to segment the build process into separate script invocations based on the OS. # That or just rewrite it in an sh script and call it a day. -$target_arch = Join-Path $PSScriptRoot 'helpers/target_arch.psm1' $devshell = Join-Path $PSScriptRoot 'helpers/devshell.ps1' $format_cpp = Join-Path $PSScriptRoot 'helpers/format_cpp.psm1' $refactor_unreal = Join-Path $PSScriptRoot 'refactor_unreal.ps1' @@ -92,7 +91,6 @@ if ( $bootstrap -eq $false -and $singleheader -eq $false -and $c_library -eq $fa throw "No build target specified. One must be specified, this script will not assume one" } - . $vendor_toolchain . $incremental_checks diff --git a/scripts/helpers/vendor_toolchain.ps1 b/scripts/helpers/vendor_toolchain.ps1 index 133597c..df3a59c 100644 --- a/scripts/helpers/vendor_toolchain.ps1 +++ b/scripts/helpers/vendor_toolchain.ps1 @@ -1,4 +1,7 @@ # This is meant to be used with build.ps1, and is not a standalone script. + $target_arch = Join-Path $PSScriptRoot 'target_arch.psm1' + + import-module $target_arch if ($IsWindows) { # This HandmadeHero implementation is only designed for 64-bit systems