Massive total progress on c_library generation: (Summary of last 3 WIP commits)

- No longer using GEN_API_C_* macros as C-library wont need them and if you need C linkage there is no need to use the c++ library.
- GEN_C_LIKE_CPP replaces GEN_SUPPORT_CPP_MEMBER_FEATURES && GEN_SUPPORT_CPP_REFERENCES
  a. If users don't want to use member functions, function overloading, or referencese they can just this one macro to before including the library.
- Enums aren't accomodated in C++ sources, they entirely converted in c_libray.cpp
- ast.hpp now properly generates with C variant
- Fully prepared code_types.hpp for C library gen (not tested yet)
- Generated enums managed by helper.hpp now properly generate for C library.
This commit is contained in:
Edward R. Gonzalez 2024-12-07 17:58:56 -05:00
parent 451b71884c
commit 1c133bfc8d
4 changed files with 89 additions and 82 deletions

View File

@ -351,7 +351,8 @@ R"(#define AST_ArrSpecs_Cap \
(body_entry->Type) { (body_entry->Type) {
case CT_Preprocess_If: 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; break;
@ -552,25 +553,29 @@ R"(#define AST_ArrSpecs_Cap \
break; break;
case CT_Enum: 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_Enum_Fwd:
case CT_Struct_Fwd: case CT_Struct_Fwd:
case CT_Struct: case CT_Struct:
case CT_Union: case CT_Union:
case CT_Union_Fwd: case CT_Union_Fwd:
{ {
if (entry->Name.is_equal(txt("FileOperations"))) StrC type_str = codetype_to_keyword_str(entry->Type);
continue; StrC formated_tmpl = token_fmt_impl( 3,
"type", type_str
// StrC type_str = codetype_to_keyword_str(entry->Type); , "name", entry->Name,
// StrC formated_tmpl = token_fmt_impl( 3, stringize(
// "type", type_str typedef <type> <name> <name>;
// , "name", entry->Name, ));
// stringize( CodeTypedef tdef = parse_typedef(formated_tmpl);
// typedef <type> <name> <name>; filesystem.append(entry);
// )); filesystem.append(tdef);
// CodeTypedef tdef = parse_typedef(formated_tmpl);
// filesystem.append(entry);
// filesystem.append(tdef);
} }
break; break;

View File

@ -142,67 +142,67 @@ inline StrC codetype_to_str( CodeType type )
inline StrC codetype_to_keyword_str( CodeType type ) inline StrC codetype_to_keyword_str( CodeType type )
{ {
local_persist StrC lookup[61] = { local_persist StrC lookup[61] = {
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "//" ), "//" }, { sizeof( "//" ) - 1, "//" },
{ sizeof( "private" ), "private" }, { sizeof( "private" ) - 1, "private" },
{ sizeof( "protected" ), "protected" }, { sizeof( "protected" ) - 1, "protected" },
{ sizeof( "public" ), "public" }, { sizeof( "public" ) - 1, "public" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "class" ), "class" }, { sizeof( "class" ) - 1, "class" },
{ sizeof( "clsss" ), "clsss" }, { sizeof( "clsss" ) - 1, "clsss" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "enum" ), "enum" }, { sizeof( "enum" ) - 1, "enum" },
{ sizeof( "enum" ), "enum" }, { sizeof( "enum" ) - 1, "enum" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "enum class" ), "enum class" }, { sizeof( "enum class" ) - 1, "enum class" },
{ sizeof( "enum class" ), "enum class" }, { sizeof( "enum class" ) - 1, "enum class" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "extern" ), "extern" }, { sizeof( "extern" ) - 1, "extern" },
{ sizeof( "extern" ), "extern" }, { sizeof( "extern" ) - 1, "extern" },
{ sizeof( "friend" ), "friend" }, { sizeof( "friend" ) - 1, "friend" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "module" ), "module" }, { sizeof( "module" ) - 1, "module" },
{ sizeof( "namespace" ), "namespace" }, { sizeof( "namespace" ) - 1, "namespace" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "operator" ), "operator" }, { sizeof( "operator" ) - 1, "operator" },
{ sizeof( "operator" ), "operator" }, { sizeof( "operator" ) - 1, "operator" },
{ sizeof( "operator" ), "operator" }, { sizeof( "operator" ) - 1, "operator" },
{ sizeof( "operator" ), "operator" }, { sizeof( "operator" ) - 1, "operator" },
{ sizeof( "operator" ), "operator" }, { sizeof( "operator" ) - 1, "operator" },
{ sizeof( "operator" ), "operator" }, { sizeof( "operator" ) - 1, "operator" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "define" ), "define" }, { sizeof( "define" ) - 1, "define" },
{ sizeof( "include" ), "include" }, { sizeof( "include" ) - 1, "include" },
{ sizeof( "if" ), "if" }, { sizeof( "if" ) - 1, "if" },
{ sizeof( "ifdef" ), "ifdef" }, { sizeof( "ifdef" ) - 1, "ifdef" },
{ sizeof( "ifndef" ), "ifndef" }, { sizeof( "ifndef" ) - 1, "ifndef" },
{ sizeof( "elif" ), "elif" }, { sizeof( "elif" ) - 1, "elif" },
{ sizeof( "else" ), "else" }, { sizeof( "else" ) - 1, "else" },
{ sizeof( "endif" ), "endif" }, { sizeof( "endif" ) - 1, "endif" },
{ sizeof( "pragma" ), "pragma" }, { sizeof( "pragma" ) - 1, "pragma" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "struct" ), "struct" }, { sizeof( "struct" ) - 1, "struct" },
{ sizeof( "struct" ), "struct" }, { sizeof( "struct" ) - 1, "struct" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "template" ), "template" }, { sizeof( "template" ) - 1, "template" },
{ sizeof( "typedef" ), "typedef" }, { sizeof( "typedef" ) - 1, "typedef" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "union" ), "union" }, { sizeof( "union" ) - 1, "union" },
{ sizeof( "union" ), "union" }, { sizeof( "union" ) - 1, "union" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
{ sizeof( "using" ), "using" }, { sizeof( "using" ) - 1, "using" },
{ sizeof( "using namespace" ), "using namespace" }, { sizeof( "using namespace" ) - 1, "using namespace" },
{ sizeof( "__NA__" ), "__NA__" }, { sizeof( "__NA__" ) - 1, "__NA__" },
}; };
return lookup[type]; return lookup[type];
} }

View File

@ -193,7 +193,7 @@ struct Arena
ssize TotalUsed; ssize TotalUsed;
ssize TempCount; ssize TempCount;
#if ! GEN_C_LIKE_CPP #if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
#pragma region Member Mapping #pragma region Member Mapping
forceinline operator AllocatorInfo() { return arena_allocator_info(this); } forceinline operator AllocatorInfo() { return arena_allocator_info(this); }

View File

@ -30,9 +30,11 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false )
char const* code = enum_strs [idx].string; char const* code = enum_strs [idx].string;
char const* keyword = keyword_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( & enum_entries, "CT_%s,\n", code );
string_append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, 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; 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); CodeBody result = def_body(CT_Global_Body);
body_append(result, enum_code); body_append(result, enum_code);
body_append(result, to_str_fns);
if (! use_c_definition) if (! use_c_definition)
{ {
#pragma push_macro("forceinline") #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; )); CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; ));
body_append(result, code_t); body_append(result, code_t);
} }
body_append(result, to_str_fns);
return result; return result;
} }
@ -173,7 +175,6 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false )
CodeBody result = def_body(CT_Global_Body); CodeBody result = def_body(CT_Global_Body);
body_append(result, enum_code); body_append(result, enum_code);
body_append(result, to_str);
if (! use_c_definition) if (! use_c_definition)
{ {
#pragma push_macro("forceinline") #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; )); CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; ));
body_append(result, operator_t); body_append(result, operator_t);
} }
body_append(result, to_str);
return result; return result;
} }
@ -313,9 +315,6 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false )
CodeBody result = def_body(CT_Global_Body); CodeBody result = def_body(CT_Global_Body);
body_append(result, enum_code); body_append(result, enum_code);
body_append(result, to_str);
body_append(result, is_trailing);
body_append(result, to_type);
if (! use_c_definition) if (! use_c_definition)
{ {
#pragma push_macro("forceinline") #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; )); CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier Specifier; ));
body_append(result, specifier_t); body_append(result, specifier_t);
} }
body_append(result, to_str);
body_append(result, is_trailing);
body_append(result, to_type);
return result; return result;
} }