mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Introduced the general context struct for gencpp
This commit is contained in:
@ -42,8 +42,8 @@ CodeBody gen_array_base()
|
||||
|
||||
CodeBody gen_array( Str type, Str array_name )
|
||||
{
|
||||
StrBuilder array_type = StrBuilder::fmt_buf( GlobalAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
||||
StrBuilder fn = StrBuilder::fmt_buf( GlobalAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
||||
StrBuilder array_type = StrBuilder::fmt_buf( FallbackAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
||||
StrBuilder fn = StrBuilder::fmt_buf( FallbackAllocator, "%.*s", array_name.Len, array_name.Ptr );
|
||||
// c_str_to_lower(fn.Data);
|
||||
|
||||
#pragma push_macro( "GEN_ASSERT" )
|
||||
@ -375,7 +375,7 @@ CodeBody gen_array( Str type, Str array_name )
|
||||
#pragma pop_macro( "forceinline" )
|
||||
|
||||
++ Array_DefinitionCounter;
|
||||
Str slot_str = StrBuilder::fmt_buf(GlobalAllocator, "%d", Array_DefinitionCounter).to_str();
|
||||
Str slot_str = StrBuilder::fmt_buf(FallbackAllocator, "%d", Array_DefinitionCounter).to_str();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "array_type", (Str)array_type, "slot", (Str)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_init
|
||||
@ -399,13 +399,13 @@ R"(#define GENERIC_SLOT_<slot>__array_init <type>, <array_type>_i
|
||||
));
|
||||
|
||||
return def_global_body( args(
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( GlobalAllocator, "region %SB", array_type ))),
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( FallbackAllocator, "region %SB", array_type ))),
|
||||
fmt_newline,
|
||||
generic_interface_slot,
|
||||
fmt_newline,
|
||||
result,
|
||||
fmt_newline,
|
||||
def_pragma( strbuilder_to_str(strbuilder_fmt_buf( GlobalAllocator, "endregion %SB", array_type ))),
|
||||
def_pragma( strbuilder_to_str(strbuilder_fmt_buf( FallbackAllocator, "endregion %SB", array_type ))),
|
||||
fmt_newline
|
||||
));
|
||||
};
|
||||
|
@ -30,16 +30,16 @@ R"(#define HashTable(_type) struct _type
|
||||
CodeBody gen_hashtable( Str type, Str hashtable_name )
|
||||
{
|
||||
|
||||
StrBuilder tbl_type = {(char*) hashtable_name.duplicate(GlobalAllocator).Ptr};
|
||||
StrBuilder fn = tbl_type.duplicate(GlobalAllocator);
|
||||
StrBuilder tbl_type = {(char*) hashtable_name.duplicate(FallbackAllocator).Ptr};
|
||||
StrBuilder fn = tbl_type.duplicate(FallbackAllocator);
|
||||
// c_str_to_lower(fn.Data);
|
||||
|
||||
StrBuilder name_lower = StrBuilder::make( GlobalAllocator, hashtable_name );
|
||||
StrBuilder name_lower = StrBuilder::make( FallbackAllocator, hashtable_name );
|
||||
// c_str_to_lower( name_lower.Data );
|
||||
|
||||
StrBuilder hashtable_entry = StrBuilder::fmt_buf( GlobalAllocator, "HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_name = StrBuilder::fmt_buf( GlobalAllocator, "Arr_HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_fn_ns = StrBuilder::fmt_buf( GlobalAllocator, "arr_hte_%.*s", name_lower.length(), name_lower.Data );
|
||||
StrBuilder hashtable_entry = StrBuilder::fmt_buf( FallbackAllocator, "HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_name = StrBuilder::fmt_buf( FallbackAllocator, "Arr_HTE_%.*s", hashtable_name.Len, hashtable_name.Ptr );
|
||||
StrBuilder entry_array_fn_ns = StrBuilder::fmt_buf( FallbackAllocator, "arr_hte_%.*s", name_lower.length(), name_lower.Data );
|
||||
|
||||
CodeBody hashtable_types = parse_global_body( token_fmt(
|
||||
"type", (Str) type,
|
||||
@ -372,7 +372,7 @@ CodeBody gen_hashtable( Str type, Str hashtable_name )
|
||||
#pragma pop_macro( "forceinline" )
|
||||
|
||||
++ HashTable_DefinitionCounter;
|
||||
Str slot_str = StrBuilder::fmt_buf(GlobalAllocator, "%d", HashTable_DefinitionCounter).to_str();
|
||||
Str slot_str = StrBuilder::fmt_buf(FallbackAllocator, "%d", HashTable_DefinitionCounter).to_str();
|
||||
|
||||
Code generic_interface_slot = untyped_str(token_fmt( "type", type, "tbl_type", (Str)tbl_type, "slot", (Str)slot_str,
|
||||
R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_init
|
||||
@ -400,7 +400,7 @@ R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_
|
||||
, type.Len, type.Ptr );
|
||||
|
||||
return def_global_body(args(
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( GlobalAllocator, "region %SB", tbl_type ))),
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( FallbackAllocator, "region %SB", tbl_type ))),
|
||||
fmt_newline,
|
||||
generic_interface_slot,
|
||||
fmt_newline,
|
||||
@ -409,7 +409,7 @@ R"(#define GENERIC_SLOT_<slot>__hashtable_init <type>, <tbl_type>_
|
||||
entry_array,
|
||||
hashtable_def,
|
||||
fmt_newline,
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( GlobalAllocator, "endregion %SB", tbl_type ))),
|
||||
def_pragma( strbuilder_to_str( strbuilder_fmt_buf( FallbackAllocator, "endregion %SB", tbl_type ))),
|
||||
fmt_newline
|
||||
));
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ Code gen_generic_selection_function_macro( s32 num_slots, Str macro_name, Generi
|
||||
) GEN_RESOLVED_FUNCTION_CALL( selector_arg )
|
||||
*/
|
||||
local_persist
|
||||
StrBuilder define_builder = StrBuilder::make_reserve(GlobalAllocator, kilobytes(64));
|
||||
StrBuilder define_builder = StrBuilder::make_reserve(FallbackAllocator, kilobytes(64));
|
||||
define_builder.clear();
|
||||
|
||||
Str macro_begin;
|
||||
@ -104,7 +104,7 @@ R"(#define <macro_name>(selector_arg, ...) _Generic( (selector_arg), \
|
||||
|
||||
for ( s32 slot = 1; slot <= num_slots; ++ slot )
|
||||
{
|
||||
Str slot_str = StrBuilder::fmt_buf(GlobalAllocator, "%d", slot).to_str();
|
||||
Str slot_str = StrBuilder::fmt_buf(FallbackAllocator, "%d", slot).to_str();
|
||||
define_builder.append( token_fmt( "macro_name", macro_name, "slot", slot_str,
|
||||
R"(GEN_IF_MACRO_DEFINED_INCLUDE_THIS_SLOT( GENERIC_SLOT_<slot>__<macro_name> ) \
|
||||
)"
|
||||
@ -147,9 +147,9 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, Str optional_prefix = txt("")
|
||||
|
||||
// Add prefix if provided
|
||||
if (optional_prefix.Len)
|
||||
new_name = strbuilder_fmt_buf(GlobalAllocator, "%S_%S_", optional_prefix, old_name);
|
||||
new_name = strbuilder_fmt_buf(FallbackAllocator, "%S_%S_", optional_prefix, old_name);
|
||||
else
|
||||
new_name = strbuilder_fmt_buf(GlobalAllocator, "%S_", old_name);
|
||||
new_name = strbuilder_fmt_buf(FallbackAllocator, "%S_", old_name);
|
||||
|
||||
// Add return type to the signature
|
||||
if (fn->ReturnType)
|
||||
@ -211,8 +211,8 @@ bool swap_pragma_region_implementation( Str region_name, SwapContentProc* swap_c
|
||||
bool found = false;
|
||||
CodePragma possible_region = cast(CodePragma, entry_iter);
|
||||
|
||||
StrBuilder region_sig = strbuilder_fmt_buf(GlobalAllocator, "region %s", region_name.Ptr);
|
||||
StrBuilder endregion_sig = strbuilder_fmt_buf(GlobalAllocator, "endregion %s", region_name.Ptr);
|
||||
StrBuilder region_sig = strbuilder_fmt_buf(FallbackAllocator, "region %s", region_name.Ptr);
|
||||
StrBuilder endregion_sig = strbuilder_fmt_buf(FallbackAllocator, "endregion %s", region_name.Ptr);
|
||||
if ( possible_region->Content.contains(region_sig))
|
||||
{
|
||||
found = true;
|
||||
|
Reference in New Issue
Block a user