diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 1e5c8c5..768466b 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -351,7 +351,8 @@ R"(#define AST_ArrSpecs_Cap \ (body_entry->Type) { case CT_Preprocess_If: { - ignore_preprocess_cond_block(txt("! GEN_C_LIKE_CPP"), body_entry, body, new_body ); + b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP"), body_entry, body, new_body ); + if (found) break; } break; @@ -552,25 +553,29 @@ R"(#define AST_ArrSpecs_Cap \ break; case CT_Enum: + { + if (entry->Name.is_equal(txt("FileOperations"))) + continue; + convert_cpp_enum_to_c(cast(CodeEnum, entry), filesystem); + } + break; + 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); + 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; diff --git a/project/components/gen/ecode.hpp b/project/components/gen/ecode.hpp index cfe3e44..316222f 100644 --- a/project/components/gen/ecode.hpp +++ b/project/components/gen/ecode.hpp @@ -142,67 +142,67 @@ inline StrC codetype_to_str( CodeType 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__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "//" ) - 1, "//" }, + { sizeof( "private" ) - 1, "private" }, + { sizeof( "protected" ) - 1, "protected" }, + { sizeof( "public" ) - 1, "public" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "class" ) - 1, "class" }, + { sizeof( "clsss" ) - 1, "clsss" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "enum" ) - 1, "enum" }, + { sizeof( "enum" ) - 1, "enum" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "enum class" ) - 1, "enum class" }, + { sizeof( "enum class" ) - 1, "enum class" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "extern" ) - 1, "extern" }, + { sizeof( "extern" ) - 1, "extern" }, + { sizeof( "friend" ) - 1, "friend" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "module" ) - 1, "module" }, + { sizeof( "namespace" ) - 1, "namespace" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "operator" ) - 1, "operator" }, + { sizeof( "operator" ) - 1, "operator" }, + { sizeof( "operator" ) - 1, "operator" }, + { sizeof( "operator" ) - 1, "operator" }, + { sizeof( "operator" ) - 1, "operator" }, + { sizeof( "operator" ) - 1, "operator" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "define" ) - 1, "define" }, + { sizeof( "include" ) - 1, "include" }, + { sizeof( "if" ) - 1, "if" }, + { sizeof( "ifdef" ) - 1, "ifdef" }, + { sizeof( "ifndef" ) - 1, "ifndef" }, + { sizeof( "elif" ) - 1, "elif" }, + { sizeof( "else" ) - 1, "else" }, + { sizeof( "endif" ) - 1, "endif" }, + { sizeof( "pragma" ) - 1, "pragma" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "struct" ) - 1, "struct" }, + { sizeof( "struct" ) - 1, "struct" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "template" ) - 1, "template" }, + { sizeof( "typedef" ) - 1, "typedef" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "union" ) - 1, "union" }, + { sizeof( "union" ) - 1, "union" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, + { sizeof( "using" ) - 1, "using" }, + { sizeof( "using namespace" ) - 1, "using namespace" }, + { sizeof( "__NA__" ) - 1, "__NA__" }, }; return lookup[type]; } diff --git a/project/dependencies/memory.hpp b/project/dependencies/memory.hpp index f6eb4b7..1fb24c9 100644 --- a/project/dependencies/memory.hpp +++ b/project/dependencies/memory.hpp @@ -193,7 +193,7 @@ struct Arena ssize TotalUsed; ssize TempCount; -#if ! GEN_C_LIKE_CPP +#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP #pragma region Member Mapping forceinline operator AllocatorInfo() { return arena_allocator_info(this); } diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index dd65af8..72d886c 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -30,9 +30,11 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) char const* code = enum_strs [idx].string; char const* keyword = keyword_strs[idx].string; + // TODO(Ed): to_str_entries and the others in here didn't have proper sizing of the StrC slice. + 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 ); + string_append_fmt( & to_keyword_str_entries, "{ sizeof(\"%s\") - 1, \"%s\" },\n", keyword, keyword ); } CodeEnum enum_code; @@ -81,7 +83,6 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) 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") @@ -98,6 +99,7 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; )); body_append(result, code_t); } + body_append(result, to_str_fns); return result; } @@ -173,7 +175,6 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false ) 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") @@ -189,6 +190,7 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false ) CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; )); body_append(result, operator_t); } + body_append(result, to_str); return result; } @@ -313,9 +315,6 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false ) 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") @@ -333,6 +332,9 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false ) CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier Specifier; )); body_append(result, specifier_t); } + body_append(result, to_str); + body_append(result, is_trailing); + body_append(result, to_type); return result; }