WIP(broken): Converting base library to use c-linkage symbols only

This commit is contained in:
Edward R. Gonzalez 2024-12-04 11:01:53 -05:00
parent 6081834687
commit 3a55af9ce4
31 changed files with 1283 additions and 1062 deletions

View File

@ -40,7 +40,9 @@
"*.m": "cpp",
"atomic": "cpp",
"gen.h": "c",
"string_ops.hpp": "c"
"string_ops.hpp": "c",
"assert.h": "c",
"intrin.h": "c"
},
"C_Cpp.intelliSenseEngineFallback": "disabled",
"mesonbuild.configureOnOpen": true,

View File

@ -127,8 +127,25 @@ int gen_main()
header.print( basic_types );
header.print( debug );
Array(StrC) to_rename = array_init_reserve(StrC, GlobalAllocator, 128);
to_rename.append(txt("align_forward"));
to_rename.append(txt("pointer_add"));
to_rename.append(txt("allocator_info"));
to_rename.append(txt("size_remaining"));
to_rename.append(txt("free"));
// to_rename.append(txt("clear"));
// to_rename.append(txt("init_sub"));
// to_rename.append(txt("check"));
NeedsSelectors needs_selectors;
needs_selectors.table = hashtable_init_reserve(Array(CodeFn), GlobalAllocator, 1024);
for ( StrC id : to_rename ) {
needs_selectors.set(id, array_init_reserve(CodeFn, GlobalAllocator, 128));
}
CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" );
CodeBody memory = def_body(CT_Global_Body);
for ( Code entry = parsed_memory.begin(); entry != parsed_memory.end(); ++ entry )
{
switch (entry->Type)
@ -145,11 +162,10 @@ int gen_main()
case CT_Function_Fwd:
{
CodeFn fn = cast(CodeFn, entry);
if ( fn->Name.is_equal(txt("free")) )
{
fn->Name = get_cached_string(txt("gen_free_ptr"));
}
memory.append(entry);
// for ( StrC id : to_rename ) if (fn->Name.is_equal(id)) {
// rename_function_to_unique_symbol(fn);
// }
memory.append(fn);
}
break;
case CT_Function:
@ -160,11 +176,11 @@ int gen_main()
log_fmt("Found constexpr: %S\n", entry.to_string());
fn->Specs.append(Spec_Inline);
}
if ( fn->Name.is_equal(txt("free")) )
{
fn->Name = get_cached_string(txt("gen_free_ptr"));
}
memory.append(entry);
// for ( StrC id : to_rename ) if (fn->Name.is_equal(id)) {
// Array(CodeFn) list = * needs_selectors.get(id);
// list.append(rename_function_to_unique_symbol(fn));
// }
memory.append(fn);
}
break;
case CT_Template:
@ -213,6 +229,9 @@ int gen_main()
b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_memory );
if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_memory );
if (found) break;
memory.append(entry);
}
break;
@ -226,6 +245,12 @@ int gen_main()
break;
case CT_Preprocess_Pragma:
{
CodePragma pragma = cast(CodePragma, entry);
// if (pragma->Content.starts_with(txt("region Memory"))) {
// memory.append(generic_test);
// break;
// }
b32 found = swap_pragma_region_implementation( txt("FixedArena"), gen_fixed_arenas, entry, memory);
if (found) break;
@ -238,10 +263,15 @@ int gen_main()
break;
}
}
// CodeBody selectors = generate_generic_selectors(needs_selectors);
// memory.append_at(selectors, 0)
// memory.append(fmt_newline);
header.print( dump_to_scratch_and_retireve(memory) );
Code string_ops = scan_file( project_dir "dependencies/string_ops.hpp" );
header.print( string_ops );
// header.print( string_ops );
CodeBody printing_parsed = parse_file( project_dir "dependencies/printing.hpp" );
CodeBody printing = def_body(CT_Global_Body);
@ -273,7 +303,7 @@ int gen_main()
break;
}
}
header.print(dump_to_scratch_and_retireve(printing));
// header.print(dump_to_scratch_and_retireve(printing));
CodeBody containers = def_body(CT_Global_Body);
{
@ -285,10 +315,10 @@ int gen_main()
containers.append( def_pragma(code(endregion Containers)));
}
header.print(fmt_newline);
header.print(dump_to_scratch_and_retireve(containers));
// header.print(dump_to_scratch_and_retireve(containers));
Code hashing = scan_file( project_dir "dependencies/hashing.hpp" );
header.print( hashing );
// header.print( hashing );
CodeBody parsed_strings = parse_file( project_dir "dependencies/strings.hpp" );
CodeBody strings = def_body(CT_Global_Body);
@ -298,7 +328,22 @@ int gen_main()
{
case CT_Preprocess_If:
{
ignore_preprocess_cond_block(txt("! GEN_COMPILER_C"), entry, parsed_strings);
CodePreprocessCond cond = cast(CodePreprocessCond, entry);
if (cond->Content.starts_with(txt("GEN_COMPILER_C || ! GEN_SUPPORT_CPP_MEMBER_FEATURES")))
{
++ entry;
strings.append(entry); // typedef
strings.append(fmt_newline);
for (; entry != end(parsed_strings) && entry->Type != CT_Preprocess_EndIf; ++ entry) {}
++ entry;
break;
}
bool found = ignore_preprocess_cond_block(txt("! GEN_COMPILER_C"), entry, parsed_strings);
if (found) break;
found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_strings);
}
break;
@ -350,7 +395,7 @@ int gen_main()
break;
}
}
header.print(dump_to_scratch_and_retireve(strings));
// header.print(dump_to_scratch_and_retireve(strings));
Code filesystem = scan_file( project_dir "dependencies/filesystem.hpp" );
Code timing = scan_file( project_dir "dependencies/timing.hpp" );

View File

@ -5,22 +5,67 @@
using SwapContentProc = CodeBody(void);
struct NeedsSelectors {
HashTable(Array(CodeFn)) table;
void set(StrC sig, Array(CodeFn) list) {
u32 key = crc32(sig.Ptr, sig.Len);
table.set(key, list);
}
Array(CodeFn)* get(StrC sig) {
u32 key = crc32(sig.Ptr, sig.Len);
return table.get(key);
}
};
CodeBody generate_generic_selectors(Array(Array(CodeFn)) listing)
{
constexpr char const* tmpl_selector =
R"( #define <base_name>(<params>) \
_Generic((
))
);
)";
CodeBody result = def_body(CT_Global_Body);
for (Array(CodeFn) functions : listing)
{
}
return result;
}
b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& body )
{
b32 found = false;
CodePreprocessCond cond = cast(CodePreprocessCond, entry_iter);
if ( cond->Content.contains(cond_sig) )
{
log_fmt("Preprocess cond found: %S\n", cond->Content);
log_fmt("Preprocess cond found: %SC\n", cond->Content);
found = true;
s32 depth = 1;
++ entry_iter; for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
++ entry_iter;
for(b32 continue_for = true; continue_for && entry_iter != body.end(); ) switch
(entry_iter->Type) {
case CT_Preprocess_If:
case CT_Preprocess_IfDef:
case CT_Preprocess_IfNotDef:
depth ++;
++ depth;
++ entry_iter;
break;
case CT_Preprocess_Else:
++ entry_iter;
for(; continue_for && entry_iter != body.end(); ++ entry_iter)
{
if (entry_iter->Type == CT_Preprocess_EndIf)
{
continue_for = false;
break;
}
body.append(entry_iter);
}
break;
case CT_Preprocess_EndIf:
@ -30,6 +75,7 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
continue_for = false;
break;
}
++ entry_iter;
}
break;
default:
@ -41,6 +87,72 @@ b32 ignore_preprocess_cond_block( StrC cond_sig, Code& entry_iter, CodeBody& bod
return found;
}
CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt(""))
{
// Get basic components for the name
StrC old_name = fn->Name;
String new_name;
// Add prefix if provided
if (optional_prefix.Len)
new_name = string_fmt_buf(GlobalAllocator, "%SC_%SC_", optional_prefix, old_name);
else
new_name = string_fmt_buf(GlobalAllocator, "%SC_", old_name);
// Add return type to the signature
if (fn->ReturnType)
new_name.append_fmt("_%SC", fn->ReturnType->Name);
// Add parameter types to create a unique signature
bool first_param = true;
for (CodeParam param = fn->Params; param.ast; param = param->Next)
{
if (param->ValueType)
{
// Add separator for readability
if (first_param)
{
new_name.append("_P_");
first_param = false;
}
else
new_name.append("_");
// Add parameter type, handle any specifiers
if (param->ValueType->Specs && param->ValueType->Specs->NumEntries > 0)
{
// Add specifiers (const, volatile, etc)
for (Specifier spec : param->ValueType->Specs)
{
if (spec == Spec_Ptr) {
new_name.append("ptr_");
continue;
}
new_name.append_fmt("%SC_", to_str(spec));
}
}
new_name.append_fmt("%SC", param->ValueType->Name);
}
}
// Handle function specifiers if present
if (fn->Specs && fn->Specs->NumEntries > 0)
{
new_name.append("_S_");
for (Specifier* spec = begin(fn->Specs);
spec != end(fn->Specs);
++spec)
{
new_name.append_fmt("%SC_", to_str(*spec));
}
}
fn->Name = new_name;
return fn;
}
bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_content, Code& entry_iter, CodeBody& body )
{
bool found = false;
@ -54,7 +166,8 @@ bool swap_pragma_region_implementation( StrC region_name, SwapContentProc* swap_
// body.append(possible_region);
body.append(swap_content());
++ entry_iter; for(b32 continue_for = true; continue_for; ++entry_iter) switch
++ entry_iter;
for(b32 continue_for = true; continue_for; ++entry_iter) switch
(entry_iter->Type) {
case CT_Preprocess_Pragma:
{

View File

@ -21,7 +21,7 @@ Builder Builder::open( char const* path )
void Builder::pad_lines( s32 num )
{
append( & Buffer, "\n" );
string_append_strc( & Buffer, txt("\n") );
}
void Builder::print( Code code )
@ -29,7 +29,7 @@ void Builder::print( Code code )
String str = to_string(code);
// const ssize len = str.length();
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
append( & Buffer, str );
string_append_string( & Buffer, str );
}
void Builder::print_fmt( char const* fmt, ... )
@ -43,17 +43,17 @@ void Builder::print_fmt( char const* fmt, ... )
va_end( va );
// log_fmt( "$%s - print_fmt: %.*s\n", File.filename, res > 80 ? 80 : res, buf );
append( (String*) & Buffer, (char const*)buf, res );
string_append_c_str_len( (String*) & Buffer, (char const*)buf, res );
}
void Builder::write()
{
b32 result = file_write( & File, Buffer, length(Buffer) );
b32 result = file_write( & File, Buffer, string_length(Buffer) );
if ( result == false )
log_failure("gen::File::write - Failed to write to file: %s\n", file_name( & File ) );
log_fmt( "Generated: %s\n", File.filename );
file_close( & File );
free(& Buffer);
string_free(& Buffer);
}

View File

@ -25,7 +25,7 @@ Code scan_file( char const* path )
String str = string_make_reserve( GlobalAllocator, fsize );
file_read( & file, str, fsize );
get_header(str)->Length = fsize;
string_get_header(str)->Length = fsize;
// Skip GEN_INTELLISENSE_DIRECTIVES preprocessor blocks
// Its designed so that the directive should be the first thing in the file.
@ -52,7 +52,7 @@ Code scan_file( char const* path )
if ( ! found_directive )
{
if ( left && str_compare( scanner, directive_start.Ptr, directive_start.Len ) == matched )
if ( left && str_compare_len( scanner, directive_start.Ptr, directive_start.Len ) == matched )
{
scanner += directive_start.Len;
left -= directive_start.Len;
@ -60,7 +60,7 @@ Code scan_file( char const* path )
while ( left && char_is_space( current ) )
move_fwd();
if ( left && str_compare( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
if ( left && str_compare_len( scanner, def_intellisense.Ptr, def_intellisense.Len ) == matched )
{
scanner += def_intellisense.Len;
left -= def_intellisense.Len;
@ -80,7 +80,7 @@ Code scan_file( char const* path )
continue;
}
if ( left && str_compare( scanner, directive_end.Ptr, directive_end.Len ) == matched )
if ( left && str_compare_len( scanner, directive_end.Ptr, directive_end.Len ) == matched )
{
scanner += directive_end.Len;
left -= directive_end.Len;
@ -97,12 +97,12 @@ Code scan_file( char const* path )
if ( (scanner + 2) >= ( (char const*) str + fsize ) )
{
mem_move( str, scanner, left );
get_header(str)->Length = left;
string_get_header(str)->Length = left;
break;
}
mem_move( str, scanner, left );
get_header(str)->Length = left;
string_get_header(str)->Length = left;
break;
}
@ -116,7 +116,7 @@ Code scan_file( char const* path )
}
file_close( & file );
return untyped_str( to_strc(str) );
return untyped_str( string_to_strc(str) );
}
#if 0

View File

@ -26,20 +26,20 @@ constexpr char const* generation_notice =
void format_file( char const* path )
{
String resolved_path = string_make(GlobalAllocator, to_str(path));
String resolved_path = string_make_strc(GlobalAllocator, to_strc_from_c_str(path));
String style_arg = string_make(GlobalAllocator, txt("-style=file:"));
append( & style_arg, "../scripts/.clang-format ");
String style_arg = string_make_strc(GlobalAllocator, txt("-style=file:"));
string_append_strc( & style_arg, txt("../scripts/.clang-format "));
// Need to execute clang format on the generated file to get it to match the original.
#define clang_format "clang-format "
#define cf_format_inplace "-i "
#define cf_verbose "-verbose "
String command = string_make( GlobalAllocator, clang_format );
append( & command, cf_format_inplace );
append( & command, cf_verbose );
append( & command, style_arg );
append( & command, resolved_path );
#define clang_format txt("clang-format ")
#define cf_format_inplace txt("-i ")
#define cf_verbose txt("-verbose ")
String command = string_make_strc( GlobalAllocator, clang_format );
string_append_strc( & command, cf_format_inplace );
string_append_strc( & command, cf_verbose );
string_append_string( & command, style_arg );
string_append_string( & command, resolved_path );
log_fmt("\tRunning clang-format on file:\n");
system( command );
log_fmt("\tclang-format finished reformatting.\n");
@ -145,7 +145,7 @@ int gen_main()
def_include(txt("components/types.hpp")),
preprocess_endif,
fmt_newline,
untyped_str( to_str(generation_notice) )
untyped_str( strc_to_str(generation_notice) )
));
// gen.hpp

View File

@ -14,13 +14,13 @@ char const* debug_str(Code self)
String* result = & result_stack;
if ( self->Parent )
append_fmt( result, "\n\tParent : %S %S", type_str(self->Parent), self->Name ? self->Name : "" );
string_append_fmt( result, "\n\tParent : %S %S", type_str(self->Parent), self->Name ? self->Name : "" );
else
append_fmt( result, "\n\tParent : %S", "Null" );
string_append_fmt( result, "\n\tParent : %S", "Null" );
append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
append_fmt( result, "\n\tType : %S", type_str(self) );
append_fmt( result, "\n\tModule Flags : %S", to_str( self->ModuleFlags ) );
string_append_fmt( result, "\n\tName : %S", self->Name ? self->Name : "Null" );
string_append_fmt( result, "\n\tType : %S", type_str(self) );
string_append_fmt( result, "\n\tModule Flags : %S", to_str( self->ModuleFlags ) );
switch ( self->Type )
{
@ -30,9 +30,9 @@ char const* debug_str(Code self)
case CT_Access_Protected:
case CT_Access_Public:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
break;
case CT_Untyped:
@ -48,74 +48,74 @@ char const* debug_str(Code self)
case CT_Preprocess_IfDef:
case CT_Preprocess_IfNotDef:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tContent: %S", self->Content );
string_append_fmt( result, "\n\tContent: %S", self->Content );
break;
case CT_Class:
case CT_Struct:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" );
append_fmt( result, "\n\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? 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\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Class_Fwd:
case CT_Struct_Fwd:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tParentAccess: %s", self->ParentType ? to_str( self->ParentAccess ) : "No Parent" );
append_fmt( result, "\n\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? 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\tParentType : %s", self->ParentType ? type_str(self->ParentType) : "Null" );
break;
case CT_Constructor:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? to_string(self->InitializerList) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? to_string(self->InitializerList) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Constructor_Fwd:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? to_string(self->InitializerList) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tInitializerList: %S", self->InitializerList ? to_string(self->InitializerList) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
break;
case CT_Destructor:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Destructor_Fwd:
@ -124,208 +124,208 @@ char const* debug_str(Code self)
case CT_Enum:
case CT_Enum_Class:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Enum_Fwd:
case CT_Enum_Class_Fwd:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tUnderlying Type : %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
break;
case CT_Extern_Linkage:
case CT_Namespace:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tBody: %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tBody: %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Friend:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
break;
case CT_Function:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Function_Fwd:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
break;
case CT_Module:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
break;
case CT_Operator:
case CT_Operator_Member:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
break;
case CT_Operator_Fwd:
case CT_Operator_Member_Fwd:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tReturnType: %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tOp : %S", to_str( self->Op ) );
break;
case CT_Operator_Cast:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Operator_Cast_Fwd:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
break;
case CT_Parameters:
append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
append_fmt( result, "\n\tLast : %S", self->Last->Name );
append_fmt( result, "\n\tNext : %S", self->Next->Name );
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
string_append_fmt( result, "\n\tLast : %S", self->Last->Name );
string_append_fmt( result, "\n\tNext : %S", self->Next->Name );
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
string_append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
break;
case CT_Specifiers:
{
append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
GEN_NS append( result, "\n\tArrSpecs: " );
string_append_fmt( result, "\n\tNumEntries: %d", self->NumEntries );
string_append_c_str( result, "\n\tArrSpecs: " );
s32 idx = 0;
s32 left = self->NumEntries;
while ( left-- )
{
StrC spec = to_str( self->ArrSpecs[idx] );
append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
string_append_fmt( result, "%.*s, ", spec.Len, spec.Ptr );
idx++;
}
append_fmt( result, "\n\tNextSpecs: %S", self->NextSpecs ? debug_str(self->NextSpecs) : "Null" );
string_append_fmt( result, "\n\tNextSpecs: %S", self->NextSpecs ? debug_str(self->NextSpecs) : "Null" );
}
break;
case CT_Template:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tDeclaration: %S", self->Declaration ? to_string(self->Declaration) : "Null" );
break;
case CT_Typedef:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
break;
case CT_Typename:
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? to_string(self->ArrExpr) : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tReturnType : %S", self->ReturnType ? to_string(self->ReturnType) : "Null" );
string_append_fmt( result, "\n\tParams : %S", self->Params ? to_string(self->Params) : "Null" );
string_append_fmt( result, "\n\tArrExpr : %S", self->ArrExpr ? to_string(self->ArrExpr) : "Null" );
break;
case CT_Union:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
string_append_fmt( result, "\n\tAttributes: %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tBody : %S", self->Body ? debug_str(self->Body) : "Null" );
break;
case CT_Using:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tUnderlyingType: %S", self->UnderlyingType ? to_string(self->UnderlyingType) : "Null" );
break;
case CT_Variable:
@ -333,25 +333,25 @@ char const* debug_str(Code self)
if ( self->Parent && self->Parent->Type == CT_Variable )
{
// Its a NextVar
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? to_string(self->BitfieldSize) : "Null" );
append_fmt( result, "\n\tNextVar : %S", self->NextVar ? debug_str(self->NextVar) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
string_append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? to_string(self->BitfieldSize) : "Null" );
string_append_fmt( result, "\n\tNextVar : %S", self->NextVar ? debug_str(self->NextVar) : "Null" );
break;
}
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
if ( self->Next )
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
string_append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? to_string(self->BitfieldSize) : "Null" );
append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
append_fmt( result, "\n\tNextVar : %S", self->NextVar ? debug_str(self->NextVar) : "Null" );
string_append_fmt( result, "\n\tInlineCmt : %S", self->InlineCmt ? self->InlineCmt->Content : "Null" );
string_append_fmt( result, "\n\tAttributes : %S", self->Attributes ? to_string(self->Attributes) : "Null" );
string_append_fmt( result, "\n\tSpecs : %S", self->Specs ? to_string(self->Specs) : "Null" );
string_append_fmt( result, "\n\tValueType : %S", self->ValueType ? to_string(self->ValueType) : "Null" );
string_append_fmt( result, "\n\tBitfieldSize: %S", self->BitfieldSize ? to_string(self->BitfieldSize) : "Null" );
string_append_fmt( result, "\n\tValue : %S", self->Value ? to_string(self->Value) : "Null" );
string_append_fmt( result, "\n\tNextVar : %S", self->NextVar ? debug_str(self->NextVar) : "Null" );
break;
}
@ -370,7 +370,7 @@ Code duplicate(Code self)
String to_string(Code self)
{
String result = string_make( GlobalAllocator, "" );
String result = string_make_strc( GlobalAllocator, txt("") );
GEN_NS to_string( self, & result );
return result;
}
@ -392,20 +392,20 @@ void to_string( Code self, String* result )
break;
case CT_NewLine:
append( result,"\n");
string_append_strc( result, txt("\n"));
break;
case CT_Untyped:
case CT_Execution:
case CT_Comment:
case CT_PlatformAttributes:
append( result, self->Content );
string_append_strc( result, self->Content );
break;
case CT_Access_Private:
case CT_Access_Protected:
case CT_Access_Public:
append( result, self->Name );
string_append_strc( result, self->Name );
break;
case CT_Class:
@ -654,8 +654,8 @@ bool is_equal( Code self, Code other )
"so it must be verified by eye for now\n" \
"AST Content:\n%S\n" \
"Other Content:\n%S\n" \
, visualize_whitespace(self->content, GlobalAllocator) \
, visualize_whitespace(other->content, GlobalAllocator) \
, strc_visualize_whitespace(self->content, GlobalAllocator) \
, strc_visualize_whitespace(other->content, GlobalAllocator) \
); \
}

File diff suppressed because it is too large Load Diff

View File

@ -134,7 +134,7 @@ Code begin( CodeBody body) {
}
inline
Code end(CodeBody body ){
return { nullptr };
return { rcast(AST*, body.ast)->Back->Next };
}
#pragma endregion CodeBody

View File

@ -11,7 +11,7 @@ internal void deinit();
internal
void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags )
{
Arena* last = back(& Global_AllocatorBuckets);
Arena* last = array_back(& Global_AllocatorBuckets);
switch ( type )
{
@ -24,13 +24,13 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
if ( ! append( & Global_AllocatorBuckets, bucket ) )
if ( ! array_append( & Global_AllocatorBuckets, bucket ) )
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
last = back(& Global_AllocatorBuckets);
last = array_back(& Global_AllocatorBuckets);
}
return alloc_align( allocator_info(last), size, alignment );
return alloc_align( arena_allocator_info(last), size, alignment );
}
case EAllocation_FREE:
{
@ -51,10 +51,10 @@ void* Global_Allocator_Proc( void* allocator_data, AllocType type, ssize size, s
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create bucket for Global_AllocatorBuckets");
if ( ! append( & Global_AllocatorBuckets, bucket ) )
if ( ! array_append( & Global_AllocatorBuckets, bucket ) )
GEN_FATAL( "Failed to append bucket to Global_AllocatorBuckets");
last = back(& Global_AllocatorBuckets);
last = array_back(& Global_AllocatorBuckets);
}
void* result = alloc_align( last->Backing, size, alignment );
@ -249,7 +249,7 @@ void init()
if ( bucket.PhysicalStart == nullptr )
GEN_FATAL( "Failed to create first bucket for Global_AllocatorBuckets");
append( & Global_AllocatorBuckets, bucket );
array_append( & Global_AllocatorBuckets, bucket );
}
// Setup the arrays
@ -272,7 +272,7 @@ void init()
if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the code pool" );
append( & CodePools, code_pool );
array_append( & CodePools, code_pool );
LexArena = arena_init_from_allocator( Allocator_Lexer, LexAllocator_Size );
@ -281,7 +281,7 @@ void init()
if ( string_arena.PhysicalStart == nullptr )
GEN_FATAL( "gen::init: Failed to initialize the string arena" );
append( & StringArenas, string_arena );
array_append( & StringArenas, string_arena );
}
// Setup the hash tables
@ -302,52 +302,52 @@ void init()
void deinit()
{
usize index = 0;
usize left = num(CodePools);
usize left = array_num(CodePools);
do
{
Pool* code_pool = & CodePools[index];
free(code_pool);
pool_free(code_pool);
index++;
}
while ( left--, left );
index = 0;
left = num(StringArenas);
left = array_num(StringArenas);
do
{
Arena* string_arena = & StringArenas[index];
free(string_arena);
arena_free(string_arena);
index++;
}
while ( left--, left );
destroy(& StringCache);
free( & CodePools);
free( & StringArenas);
array_free( & CodePools);
array_free( & StringArenas);
free(& LexArena);
arena_free(& LexArena);
free(& PreprocessorDefines);
array_free(& PreprocessorDefines);
index = 0;
left = num(Global_AllocatorBuckets);
left = array_num(Global_AllocatorBuckets);
do
{
Arena* bucket = & Global_AllocatorBuckets[ index ];
free(bucket);
arena_free(bucket);
index++;
}
while ( left--, left );
free(Global_AllocatorBuckets);
array_free(& Global_AllocatorBuckets);
parser::deinit();
}
void reset()
{
s32 index = 0;
s32 left = num(CodePools);
s32 left = array_num(CodePools);
do
{
Pool* code_pool = & CodePools[index];
@ -357,7 +357,7 @@ void reset()
while ( left--, left );
index = 0;
left = num(StringArenas);
left = array_num(StringArenas);
do
{
Arena* string_arena = & StringArenas[index];
@ -373,7 +373,7 @@ void reset()
AllocatorInfo get_string_allocator( s32 str_length )
{
Arena* last = back(& StringArenas);
Arena* last = array_back(& StringArenas);
usize size_req = str_length + sizeof(StringHeader) + sizeof(char*);
@ -381,13 +381,13 @@ AllocatorInfo get_string_allocator( s32 str_length )
{
Arena new_arena = arena_init_from_allocator( Allocator_StringArena, SizePer_StringArena );
if ( ! append( & StringArenas, new_arena ) )
if ( ! array_append( & StringArenas, new_arena ) )
GEN_FATAL( "gen::get_string_allocator: Failed to allocate a new string arena" );
last = back(& StringArenas);
last = array_back(& StringArenas);
}
return allocator_info(last);
return arena_allocator_info(last);
}
// Will either make or retrive a code string.
@ -402,16 +402,16 @@ StringCached get_cached_string( StrC str )
return * result;
}
String result = string_make( get_string_allocator( str.Len ), str );
set(& StringCache, key, { length(result), result } );
String result = string_make_strc( get_string_allocator( str.Len ), str );
set(& StringCache, key, { str.Len, result } );
return { length(result), result };
return { str.Len, result };
}
// Used internally to retireve a Code object form the CodePool.
Code make_code()
{
Pool* allocator = back( & CodePools);
Pool* allocator = array_back( & CodePools);
if ( allocator->FreeList == nullptr )
{
Pool code_pool = pool_init( Allocator_CodePool, CodePool_NumBlocks, sizeof(AST) );
@ -419,13 +419,13 @@ Code make_code()
if ( code_pool.PhysicalStart == nullptr )
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePool allcoator returned nullptr." );
if ( ! append( & CodePools, code_pool ) )
if ( ! array_append( & CodePools, code_pool ) )
GEN_FATAL( "gen::make_code: Failed to allocate a new code pool - CodePools failed to append new pool." );
allocator = back( & CodePools);
allocator = array_back( & CodePools);
}
Code result { rcast( AST*, alloc( allocator_info(allocator), sizeof(AST) )) };
Code result { rcast( AST*, alloc( pool_allocator_info(allocator), sizeof(AST) )) };
mem_set( result.ast, 0, sizeof(AST) );
// result->Type = ECode::Invalid;

View File

@ -17,7 +17,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char tok_map_mem[ TokenFmt_TokenMap_MemSize ];
tok_map_arena = arena_init_from_memory( tok_map_mem, sizeof(tok_map_mem) );
tok_map = hashtable_init(StrC, allocator_info(& tok_map_arena) );
tok_map = hashtable_init(StrC, arena_allocator_info(& tok_map_arena) );
s32 left = num_tokens - 1;
@ -94,7 +94,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
}
clear(tok_map);
free(& tok_map_arena);
arena_free(& tok_map_arena);
ssize result = buf_size - remaining;
@ -142,7 +142,7 @@ Code untyped_fmt( char const* fmt, ...)
Code
result = make_code();
result->Name = get_cached_string( { str_len(fmt, MaxNameLength), fmt } );
result->Name = get_cached_string( { str_len_capped(fmt, MaxNameLength), fmt } );
result->Type = CT_Untyped;
result->Content = get_cached_string( { length, buf } );

View File

@ -472,23 +472,23 @@ CodeComment def_comment( StrC content )
length++;
str_copy( line, scanner, length );
append_fmt(& cmt_formatted, "//%.*s", length, line );
string_append_fmt(& cmt_formatted, "//%.*s", length, line );
mem_set( line, 0, MaxCommentLineLength );
scanner += length;
}
while ( scanner <= end );
if ( * back(& cmt_formatted) != '\n' )
append( & cmt_formatted, "\n" );
if ( * string_back(cmt_formatted) != '\n' )
string_append_strc( & cmt_formatted, txt("\n") );
Code
result = make_code();
result->Type = CT_Comment;
result->Name = get_cached_string( { length(cmt_formatted), cmt_formatted } );
result->Name = get_cached_string( { string_length(cmt_formatted), cmt_formatted } );
result->Content = result->Name;
free(& cmt_formatted);
string_free(& cmt_formatted);
return (CodeComment) result;
}
@ -908,8 +908,8 @@ CodeInclude def_include( StrC path, Opts_def_include p )
}
StrC content = p.foreign ?
to_str( str_fmt_buf( "<%.*s>", path.Len, path.Ptr ))
: to_str( str_fmt_buf( "\"%.*s\"", path.Len, path.Ptr ));
string_to_strc( str_fmt_buf( "<%.*s>", path.Len, path.Ptr ))
: string_to_strc( str_fmt_buf( "\"%.*s\"", path.Len, path.Ptr ));
Code
result = make_code();

View File

@ -221,7 +221,7 @@ forceinline
s32 lex_preprocessor_directive( LexContext* ctx )
{
char const* hash = ctx->scanner;
append( & Tokens, { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess } );
array_append( & Tokens, { hash, 1, Tok_Preprocess_Hash, ctx->line, ctx->column, TF_Preprocess } );
move_forward();
SkipWhitespace();
@ -297,14 +297,14 @@ s32 lex_preprocessor_directive( LexContext* ctx )
ctx->token.Length = ctx->token.Length + ctx->token.Text - hash;
ctx->token.Text = hash;
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
return Lex_Continue; // Skip found token, its all handled here.
}
if ( ctx->token.Type == Tok_Preprocess_Else || ctx->token.Type == Tok_Preprocess_EndIf )
{
ctx->token.Flags |= TF_Preprocess_Cond;
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
end_line();
return Lex_Continue;
}
@ -313,7 +313,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
ctx->token.Flags |= TF_Preprocess_Cond;
}
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
SkipWhitespace();
@ -337,7 +337,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
name.Length++;
}
append( & Tokens, name );
array_append( & Tokens, name );
u64 key = crc32( name.Text, name.Length );
set(& ctx->defines, key, to_str(name) );
@ -383,7 +383,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
move_forward();
}
append( & Tokens, preprocess_content );
array_append( & Tokens, preprocess_content );
return Lex_Continue; // Skip found token, its all handled here.
}
@ -445,7 +445,7 @@ s32 lex_preprocessor_directive( LexContext* ctx )
preprocess_content.Length++;
}
append( & Tokens, preprocess_content );
array_append( & Tokens, preprocess_content );
return Lex_Continue; // Skip found token, its all handled here.
}
@ -454,7 +454,7 @@ void lex_found_token( LexContext* ctx )
{
if ( ctx->token.Type != Tok_Invalid )
{
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
return;
}
@ -481,7 +481,7 @@ void lex_found_token( LexContext* ctx )
}
ctx->token.Type = type;
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
return;
}
@ -491,7 +491,7 @@ void lex_found_token( LexContext* ctx )
{
ctx->token.Type = type;
ctx->token.Flags |= TF_Specifier;
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
return;
}
@ -499,7 +499,7 @@ void lex_found_token( LexContext* ctx )
if ( type != Tok_Invalid )
{
ctx->token.Type = type;
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
return;
}
@ -551,7 +551,7 @@ void lex_found_token( LexContext* ctx )
ctx->token.Type = Tok_Identifier;
}
append( & Tokens, ctx->token );
array_append( & Tokens, ctx->token );
}
@ -578,7 +578,7 @@ TokArray lex( StrC content )
return { {}, 0 };
}
foreach( StringCached*, entry, PreprocessorDefines )
for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); array_next(PreprocessorDefines, entry))
{
s32 length = 0;
char const* scanner = * entry;
@ -596,7 +596,7 @@ TokArray lex( StrC content )
set(& c.defines, key, (StrC) * entry );
}
clear(Tokens);
array_clear(Tokens);
while (c.left )
{
@ -626,7 +626,7 @@ TokArray lex( StrC content )
c.token.Type = Tok_NewLine;
c.token.Length++;
append( & Tokens, c.token );
array_append( & Tokens, c.token );
continue;
}
}
@ -1095,7 +1095,7 @@ TokArray lex( StrC content )
move_forward();
c.token.Length++;
}
append( & Tokens, c.token );
array_append( & Tokens, c.token );
continue;
}
else if ( current == '*' )
@ -1131,7 +1131,7 @@ TokArray lex( StrC content )
move_forward();
c.token.Length++;
}
append( & Tokens, c.token );
array_append( & Tokens, c.token );
// end_line();
continue;
}
@ -1224,9 +1224,9 @@ TokArray lex( StrC content )
}
else
{
s32 start = max( 0, num(Tokens) - 100 );
s32 start = max( 0, array_num(Tokens) - 100 );
log_fmt("\n%d\n", start);
for ( s32 idx = start; idx < num(Tokens); idx++ )
for ( s32 idx = start; idx < array_num(Tokens); idx++ )
{
log_fmt( "Token %d Type: %s : %.*s\n"
, idx
@ -1249,7 +1249,7 @@ TokArray lex( StrC content )
lex_found_token( ctx );
}
if ( num(Tokens) == 0 )
if ( array_num(Tokens) == 0 )
{
log_failure( "Failed to lex any tokens" );
return { {}, 0 };

View File

@ -50,28 +50,28 @@ String to_string(ParseContext ctx)
String result = string_make_reserve( GlobalAllocator, kilobytes(4) );
Token scope_start = ctx.Scope->Start;
Token last_valid = ctx.Tokens.Idx >= num(ctx.Tokens.Arr) ? ctx.Tokens.Arr[num(ctx.Tokens.Arr) -1] : (* current(& ctx.Tokens, true));
Token last_valid = ctx.Tokens.Idx >= array_num(ctx.Tokens.Arr) ? ctx.Tokens.Arr[array_num(ctx.Tokens.Arr) -1] : (* current(& ctx.Tokens, true));
sptr length = scope_start.Length;
char const* current = scope_start.Text + length;
while ( current <= back( & ctx.Tokens.Arr)->Text && *current != '\n' && length < 74 )
while ( current <= array_back( & ctx.Tokens.Arr)->Text && *current != '\n' && length < 74 )
{
current++;
length++;
}
String line = string_make( GlobalAllocator, { length, scope_start.Text } );
append_fmt( & result, "\tScope : %s\n", line );
free(& line);
String line = string_make_strc( GlobalAllocator, { length, scope_start.Text } );
string_append_fmt( & result, "\tScope : %s\n", line );
string_free(& line);
sptr dist = (sptr)last_valid.Text - (sptr)scope_start.Text + 2;
sptr length_from_err = dist;
String line_from_err = string_make( GlobalAllocator, { length_from_err, last_valid.Text } );
String line_from_err = string_make_strc( GlobalAllocator, { length_from_err, last_valid.Text } );
if ( length_from_err < 100 )
append_fmt(& result, "\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' );
string_append_fmt(& result, "\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' );
else
append_fmt(& result, "\t(%d, %d)\n", last_valid.Line, last_valid.Column );
string_append_fmt(& result, "\t(%d, %d)\n", last_valid.Line, last_valid.Column );
StackNode* curr_scope = ctx.Scope;
s32 level = 0;
@ -79,11 +79,11 @@ String to_string(ParseContext ctx)
{
if ( is_valid(curr_scope->Name) )
{
append_fmt(& result, "\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, curr_scope->Name.Text );
string_append_fmt(& result, "\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, curr_scope->Name.Text );
}
else
{
append_fmt(& result, "\t%d: %s\n", level, curr_scope->ProcName.Ptr );
string_append_fmt(& result, "\t%d: %s\n", level, curr_scope->ProcName.Ptr );
}
curr_scope = curr_scope->Prev;
@ -97,7 +97,7 @@ global ParseContext Context;
bool __eat(TokArray* self, TokType type )
{
if ( num(self->Arr) - self->Idx <= 0 )
if ( array_num(self->Arr) - self->Idx <= 0 )
{
log_failure( "No tokens left.\n%s", to_string(Context) );
return false;
@ -136,12 +136,12 @@ bool __eat(TokArray* self, TokType type )
internal
void init()
{
Tokens = array_init_reserve<Token>( allocator_info( & LexArena)
Tokens = array_init_reserve(Token, arena_allocator_info( & LexArena)
, ( LexAllocator_Size - sizeof( ArrayHeader ) ) / sizeof(Token)
);
fixed_arena_init(& defines_map_arena);
defines = hashtable_init_reserve<StrC>( allocator_info( & defines_map_arena), 256 );
defines = hashtable_init_reserve(StrC, allocator_info( & defines_map_arena), 256 );
}
internal
@ -175,7 +175,7 @@ bool _check_parse_args( StrC def, char const* func_name )
# define prevtok (* previous( Context.Tokens, dont_skip_formatting))
# define nexttok (* next( Context.Tokens, skip_formatting ))
# define eat( Type_ ) __eat( & Context.Tokens, Type_ )
# define left ( num(Context.Tokens.Arr) - Context.Tokens.Idx )
# define left ( array_num(Context.Tokens.Arr) - Context.Tokens.Idx )
#ifdef check
#define CHECK_WAS_DEFINED
@ -298,7 +298,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
if ( tokleft )
move_fwd();
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
continue;
}
@ -320,7 +320,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
if ( tokleft )
move_fwd();
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
continue;
}
@ -334,7 +334,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
scanner += 2;
tokleft -= 2;
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
continue;
}
@ -353,7 +353,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
if (tokleft)
move_fwd();
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
continue;
}
@ -362,10 +362,10 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
if (scanner[0] == '\t')
{
if (pos > last_cut)
append( & content, cut_ptr, cut_length);
string_append_c_str_len( & content, cut_ptr, cut_length);
if ( * back( & content ) != ' ' )
append( & content, ' ');
if ( * string_back( content ) != ' ' )
string_append_strc( & content, txt(' '));
move_fwd();
last_cut = sptr(scanner) - sptr(raw_text.Ptr);
@ -381,17 +381,17 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
scanner += 2;
tokleft -= 2;
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
continue;
}
if ( pos > last_cut )
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
// Replace with a space
if ( * back( & content ) != ' ' )
append( & content, ' ' );
if ( * string_back( content ) != ' ' )
string_append_strc( & content, txt(' ') );
scanner += 2;
tokleft -= 2;
@ -408,17 +408,17 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
move_fwd();
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
last_cut = sptr( scanner ) - sptr( raw_text.Ptr );
continue;
}
if ( pos > last_cut )
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
// Replace with a space
if ( * back( & content ) != ' ' )
append( & content, ' ' );
string_append_strc( & content, txt(' ') );
move_fwd();
@ -429,7 +429,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
// Escaped newlines
if ( scanner[0] == '\\' )
{
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
s32 amount_to_skip = 1;
if ( tokleft > 1 && scanner[1] == '\n' )
@ -456,7 +456,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
// Consectuive spaces
if ( tokleft > 1 && char_is_space( scanner[0] ) && char_is_space( scanner[ 1 ] ) )
{
append( & content, cut_ptr, cut_length );
string_append_c_str_len( & content, cut_ptr, cut_length );
do
{
move_fwd();
@ -468,7 +468,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
// Preserve only 1 space of formattting
char* last = back(& content);
if ( last == nullptr || * last != ' ' )
append( & content, ' ' );
string_append_strc( & content, txt(' ') );
continue;
}
@ -478,7 +478,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true )
if ( last_cut < raw_text.Len )
{
append( & content, cut_ptr, raw_text.Len - last_cut );
string_append_c_str_len( & content, cut_ptr, raw_text.Len - last_cut );
}
#undef cut_ptr
@ -669,7 +669,7 @@ CodeAttributes parse_attributes()
Code result = make_code();
result->Type = CT_PlatformAttributes;
result->Name = get_cached_string( { length(name_stripped), name_stripped } );
result->Name = get_cached_string( { string_length(name_stripped), name_stripped } );
result->Content = result->Name;
// result->Token =
@ -723,7 +723,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
char interface_arr_mem[ kilobytes(4) ] {0};
Array<CodeTypename> interfaces; {
Arena arena = arena_init_from_memory( interface_arr_mem, kilobytes(4) );
interfaces = array_init_reserve<CodeTypename>( allocator_info(& arena), 4 );
interfaces = array_init_reserve(CodeTypename, arena_allocator_info(& arena), 4 );
}
// TODO(Ed) : Make an AST_DerivedType, we'll store any arbitary derived type into there as a linear linked list of them.
@ -754,7 +754,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
}
Token interface_tok = parse_identifier();
append( & interfaces, def_type( to_str(interface_tok) ) );
array_append( & interfaces, def_type( to_str(interface_tok) ) );
// <ModuleFlags> <class/struct> <Attributes> <Name> : <Access Specifier> <Name>, ...
}
}
@ -786,7 +786,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false )
if ( inline_cmt )
result->InlineCmt = inline_cmt;
free(& interfaces);
array_free(& interfaces);
return result;
}
@ -1048,9 +1048,9 @@ CodeBody parse_class_struct_body( TokType which, Token name )
if ( attributes )
{
String fused = string_make_reserve( GlobalAllocator, attributes->Content.Len + more_attributes->Content.Len );
append_fmt( & fused, "%S %S", attributes->Content, more_attributes->Content );
string_append_fmt( & fused, "%S %S", attributes->Content, more_attributes->Content );
attributes->Name = get_cached_string({ length(fused), fused });
attributes->Name = get_cached_string( { string_length(fused), fused });
attributes->Content = attributes->Name;
// <Attributes> <Specifiers> <Attributes>
}
@ -1086,7 +1086,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
{
if ( nexttok.Type == Tok_Capture_Start && name.Length && currtok.Type == Tok_Identifier )
{
if ( str_compare( name.Text, currtok.Text, name.Length ) == 0 )
if ( str_compare_len( name.Text, currtok.Text, name.Length ) == 0 )
{
member = parse_constructor( specifiers );
// <Attributes> <Specifiers> <Name>()
@ -1159,7 +1159,7 @@ Code parse_complicated_definition( TokType which )
s32 idx = tokens.Idx;
s32 level = 0;
for ( ; idx < num(tokens.Arr); idx++ )
for ( ; idx < array_num(tokens.Arr); idx++ )
{
if ( tokens.Arr[ idx ].Type == Tok_BraceCurly_Open )
level++;
@ -1344,7 +1344,7 @@ CodeDefine parse_define()
return define;
}
define->Content = get_cached_string( to_strc( strip_formatting( to_str(currtok), strip_formatting_dont_preserve_newlines )) );
define->Content = get_cached_string( string_to_strc( strip_formatting( to_str(currtok), strip_formatting_dont_preserve_newlines )) );
eat( Tok_Preprocess_Content );
// #define <Name> <Content>
@ -1489,12 +1489,12 @@ CodeFn parse_function_after_name(
}
String
name_stripped = string_make( GlobalAllocator, to_str(name) );
name_stripped = string_make_strc( GlobalAllocator, to_str(name) );
strip_space(name_stripped);
CodeFn
result = (CodeFn) make_code();
result->Name = get_cached_string( to_strc(name_stripped) );
result->Name = get_cached_string( string_to_strc(name_stripped) );
result->ModuleFlags = mflags;
if ( body )
@ -1840,7 +1840,7 @@ CodeBody parse_global_nspace( CodeType which )
bool found_operator_cast_outside_class_implmentation = false;
s32 idx = Context.Tokens.Idx;
for ( ; idx < num(Context.Tokens.Arr); idx++ )
for ( ; idx < array_num(Context.Tokens.Arr); idx++ )
{
Token tok = Context.Tokens.Arr[ idx ];
@ -1912,14 +1912,14 @@ Code parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers )
s32 idx = tokens.Idx;
Token nav = tokens.Arr[ idx ];
for ( ; idx < num(tokens.Arr); idx++, nav = tokens.Arr[ idx ] )
for ( ; idx < array_num(tokens.Arr); idx++, nav = tokens.Arr[ idx ] )
{
if ( nav.Text[0] == '<' )
{
// Skip templated expressions as they mey have expressions with the () operators
s32 capture_level = 0;
s32 template_level = 0;
for ( ; idx < num(tokens.Arr); idx++, nav = tokens.Arr[idx] )
for ( ; idx < array_num(tokens.Arr); idx++, nav = tokens.Arr[idx] )
{
if (nav.Text[ 0 ] == '<')
++ template_level;
@ -2001,7 +2001,7 @@ Code parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers )
tok_left = tokens.Arr[idx];
}
bool is_same = str_compare( tok_right.Text, tok_left.Text, tok_right.Length ) == 0;
bool is_same = str_compare_len( tok_right.Text, tok_left.Text, tok_right.Length ) == 0;
if (tok_left.Type == Tok_Identifier && is_same)
{
// We have found the pattern we desired
@ -2357,7 +2357,7 @@ CodeOperator parse_operator_after_ret_type(
{
StrC str_new = to_str(Op_New);
StrC str_delete = to_str(Op_Delete);
if ( str_compare( currtok.Text, str_new.Ptr, max(str_new.Len - 1, currtok.Length)) == 0)
if ( str_compare_len( currtok.Text, str_new.Ptr, max(str_new.Len - 1, currtok.Length)) == 0)
{
op = Op_New;
eat( Tok_Identifier );
@ -2369,7 +2369,7 @@ CodeOperator parse_operator_after_ret_type(
idx++;
}
Token next = Context.Tokens.Arr[idx];
if ( currtok.Type == Tok_Operator && str_compare(currtok.Text, "[]", 2) == 0)
if ( currtok.Type == Tok_Operator && str_compare_len(currtok.Text, "[]", 2) == 0)
{
eat(Tok_Operator);
op = Op_NewArray;
@ -2381,7 +2381,7 @@ CodeOperator parse_operator_after_ret_type(
op = Op_NewArray;
}
}
else if ( str_compare( currtok.Text, str_delete.Ptr, max(str_delete.Len - 1, currtok.Length )) == 0)
else if ( str_compare_len( currtok.Text, str_delete.Ptr, max(str_delete.Len - 1, currtok.Length )) == 0)
{
op = Op_Delete;
eat(Tok_Identifier);
@ -2393,7 +2393,7 @@ CodeOperator parse_operator_after_ret_type(
idx++;
}
Token next = Context.Tokens.Arr[idx];
if ( currtok.Type == Tok_Operator && str_compare(currtok.Text, "[]", 2) == 0)
if ( currtok.Type == Tok_Operator && str_compare_len(currtok.Text, "[]", 2) == 0)
{
eat(Tok_Operator);
op = Op_DeleteArray;
@ -2513,7 +2513,7 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
bool found_operator = false;
s32 idx = Context.Tokens.Idx;
for ( ; idx < num(Context.Tokens.Arr); idx++ )
for ( ; idx < array_num(Context.Tokens.Arr); idx++ )
{
Token tok = Context.Tokens.Arr[ idx ];
@ -2730,7 +2730,7 @@ CodeParam parse_params( bool use_template_capture )
eat( currtok.Type );
}
value = untyped_str( to_strc(strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines )) );
value = untyped_str( string_to_strc(strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines )) );
// ( <Macro> <ValueType> <Name> = <Expression>
}
}
@ -2845,7 +2845,7 @@ CodeParam parse_params( bool use_template_capture )
eat( currtok.Type );
}
value = untyped_str( to_strc(strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines )) );
value = untyped_str( string_to_strc(strip_formatting( to_str(value_tok), strip_formatting_dont_preserve_newlines )) );
// ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name> = <Expression>
}
// ( <Macro> <ValueType> <Name> = <Expression>, <Macro> <ValueType> <Name> = <Expression>, ..
@ -2957,7 +2957,7 @@ Code parse_simple_preprocess( TokType which )
// <Macro> { <Body> }
StrC prev_proc = Context.Scope->Prev->ProcName;
if ( str_compare( prev_proc.Ptr, "parse_typedef", prev_proc.Len ) != 0 )
if ( str_compare_len( prev_proc.Ptr, "parse_typedef", prev_proc.Len ) != 0 )
{
if ( check( Tok_Statement_End ))
{
@ -2975,7 +2975,7 @@ Code parse_simple_preprocess( TokType which )
}
else
{
if ( str_compare( Context.Scope->Prev->ProcName.Ptr, "parse_typedef", Context.Scope->Prev->ProcName.Len ) != 0 )
if ( str_compare_len( Context.Scope->Prev->ProcName.Ptr, "parse_typedef", Context.Scope->Prev->ProcName.Len ) != 0 )
{
if ( check( Tok_Statement_End ))
{
@ -2994,7 +2994,7 @@ Code parse_simple_preprocess( TokType which )
char const* content = str_fmt_buf( "%.*s ", tok.Length, tok.Text );
Code result = untyped_str( GEN_NS to_str(content) );
Code result = untyped_str( to_strc_from_c_str(content) );
Context.Scope->Name = tok;
pop(& Context);
@ -3494,7 +3494,7 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
append(specifiers, Spec_Pure );
}
else if ( left && str_compare( upcoming.Text, "default", sizeof("default") - 1 ) == 0)
else if ( left && str_compare_len( upcoming.Text, "default", sizeof("default") - 1 ) == 0)
{
body = parse_assignment_expression();
// <Virtual Specifier> ~<
@ -3609,7 +3609,7 @@ CodeEnum parse_enum( bool inplace_def )
// We'll support the enum_underlying macro
StrC sig = txt("enum_underlying");
if (currtok.Length >= sig.Len && str_compare(currtok.Text, sig.Ptr, sig.Len) == 0 )
if (currtok.Length >= sig.Len && str_compare_len(currtok.Text, sig.Ptr, sig.Len) == 0 )
{
use_macro_underlying = true;
underlying_macro = parse_simple_preprocess( Tok_Preprocess_Macro);
@ -4375,7 +4375,7 @@ CodeTemplate parse_template()
bool found_operator_cast_outside_class_implmentation = false;
s32 idx = Context.Tokens.Idx;
for ( ; idx < num(Context.Tokens.Arr); idx++ )
for ( ; idx < array_num(Context.Tokens.Arr); idx++ )
{
Token tok = Context.Tokens.Arr[ idx ];
@ -4829,7 +4829,7 @@ else if ( currtok.Type == Tok_DeclType )
}
#endif
result->Name = get_cached_string( to_strc(name_stripped) );
result->Name = get_cached_string( string_to_strc(name_stripped) );
if ( attributes )
result->Attributes = attributes;
@ -4924,7 +4924,7 @@ CodeTypedef parse_typedef()
s32 idx = tokens.Idx;
s32 level = 0;
for ( ; idx < num(tokens.Arr); idx ++ )
for ( ; idx < array_num(tokens.Arr); idx ++ )
{
if ( tokens.Arr[idx].Type == Tok_BraceCurly_Open )
level++;

View File

@ -31,23 +31,23 @@ usize array_grow_formula(ssize value);
template<class Type> Array(Type) array_init (AllocatorInfo allocator);
template<class Type> Array(Type) array_init_reserve(AllocatorInfo allocator, ssize capacity);
template<class Type> bool append (Array(Type)* array, Array(Type) other);
template<class Type> bool append (Array(Type)* array, Type value);
template<class Type> bool append (Array(Type)* array, Type* items, usize item_num);
template<class Type> bool append_at (Array(Type)* array, Type item, usize idx);
template<class Type> bool append_at (Array(Type)* array, Type* items, usize item_num, usize idx);
template<class Type> Type* back (Array(Type) array);
template<class Type> void clear (Array(Type) array);
template<class Type> bool fill (Array(Type) array, usize begin, usize end, Type value);
template<class Type> void free (Array(Type)* array);
template<class Type> bool grow (Array(Type)* array, usize min_capacity);
template<class Type> usize num (Array(Type) array);
template<class Type> void pop (Array(Type) array);
template<class Type> void remove_at (Array(Type) array, usize idx);
template<class Type> bool reserve (Array(Type)* array, usize new_capacity);
template<class Type> bool resize (Array(Type)* array, usize num);
template<class Type> bool set_capacity (Array(Type)* array, usize new_capacity);
template<class Type> ArrayHeader* get_header (Array(Type) array);
template<class Type> bool array_append (Array(Type)* array, Array(Type) other);
template<class Type> bool array_append (Array(Type)* array, Type value);
template<class Type> bool array_append (Array(Type)* array, Type* items, usize item_num);
template<class Type> bool array_append_at (Array(Type)* array, Type item, usize idx);
template<class Type> bool array_append_at (Array(Type)* array, Type* items, usize item_num, usize idx);
template<class Type> Type* array_back (Array(Type) array);
template<class Type> void array_clear (Array(Type) array);
template<class Type> bool array_fill (Array(Type) array, usize begin, usize end, Type value);
template<class Type> void array_free (Array(Type)* array);
template<class Type> bool arary_grow (Array(Type)* array, usize min_capacity);
template<class Type> usize array_num (Array(Type) array);
template<class Type> void arary_pop (Array(Type) array);
template<class Type> void arary_remove_at (Array(Type) array, usize idx);
template<class Type> bool arary_reserve (Array(Type)* array, usize new_capacity);
template<class Type> bool arary_resize (Array(Type)* array, usize num);
template<class Type> bool arary_set_capacity(Array(Type)* array, usize new_capacity);
template<class Type> ArrayHeader* arary_get_header (Array(Type) array);
struct ArrayHeader {
AllocatorInfo Allocator;
@ -66,23 +66,23 @@ struct Array
forceinline static Array init_reserve(AllocatorInfo allocator, ssize capacity) { return GEN_NS array_init_reserve<Type>(allocator, capacity); }
forceinline static usize grow_formula(ssize value) { return GEN_NS array_grow_formula<Type>(value); }
forceinline bool append(Array other) { return GEN_NS append<Type>(this, other); }
forceinline bool append(Type value) { return GEN_NS append<Type>(this, value); }
forceinline bool append(Type* items, usize item_num) { return GEN_NS append<Type>(this, items, item_num); }
forceinline bool append_at(Type item, usize idx) { return GEN_NS append_at<Type>(this, item, idx); }
forceinline bool append_at(Type* items, usize item_num, usize idx) { return GEN_NS append_at<Type>(this, items, item_num, idx); }
forceinline Type* back() { return GEN_NS back<Type>(* this); }
forceinline void clear() { GEN_NS clear<Type>(* this); }
forceinline bool fill(usize begin, usize end, Type value) { return GEN_NS fill<Type>(* this, begin, end, value); }
forceinline void free() { GEN_NS free<Type>(this); }
forceinline ArrayHeader* get_header() { return GEN_NS get_header<Type>(* this); }
forceinline bool grow(usize min_capacity) { return GEN_NS grow<Type>(this, min_capacity); }
forceinline usize num() { return GEN_NS num<Type>(*this); }
forceinline void pop() { GEN_NS pop<Type>(* this); }
forceinline void remove_at(usize idx) { GEN_NS remove_at<Type>(* this, idx); }
forceinline bool reserve(usize new_capacity) { return GEN_NS reserve<Type>(this, new_capacity); }
forceinline bool resize(usize num) { return GEN_NS resize<Type>(this, num); }
forceinline bool set_capacity(usize new_capacity) { return GEN_NS set_capacity<Type>(this, new_capacity); }
forceinline bool append(Array other) { return GEN_NS array_append<Type>(this, other); }
forceinline bool append(Type value) { return GEN_NS array_append<Type>(this, value); }
forceinline bool append(Type* items, usize item_num) { return GEN_NS array_append<Type>(this, items, item_num); }
forceinline bool append_at(Type item, usize idx) { return GEN_NS array_append_at<Type>(this, item, idx); }
forceinline bool append_at(Type* items, usize item_num, usize idx) { return GEN_NS array_append_at<Type>(this, items, item_num, idx); }
forceinline Type* back() { return GEN_NS array_back<Type>(* this); }
forceinline void clear() { GEN_NS array_clear<Type>(* this); }
forceinline bool fill(usize begin, usize end, Type value) { return GEN_NS array_fill<Type>(* this, begin, end, value); }
forceinline void free() { GEN_NS array_free<Type>(this); }
forceinline ArrayHeader* get_header() { return GEN_NS array_get_header<Type>(* this); }
forceinline bool grow(usize min_capacity) { return GEN_NS array_grow<Type>(this, min_capacity); }
forceinline usize num() { return GEN_NS array_num<Type>(*this); }
forceinline void pop() { GEN_NS array_pop<Type>(* this); }
forceinline void remove_at(usize idx) { GEN_NS array_remove_at<Type>(* this, idx); }
forceinline bool reserve(usize new_capacity) { return GEN_NS array_reserve<Type>(this, new_capacity); }
forceinline bool resize(usize num) { return GEN_NS array_resize<Type>(this, num); }
forceinline bool set_capacity(usize new_capacity) { return GEN_NS array_set_capacity<Type>(this, new_capacity); }
#pragma endregion Member Mapping
forceinline operator Type*() { return Data; }
@ -108,14 +108,14 @@ template<class Type> bool resize(Array<Type>& array, usize num)
template<class Type> bool set_capacity(Array<Type>& array, usize new_capacity) { return GEN_NS set_capacity( & array, new_capacity); }
template<class Type> forceinline Type* begin(Array<Type>& array) { return array; }
template<class Type> forceinline Type* end(Array<Type>& array) { return array + get_header(array)->Num; }
template<class Type> forceinline Type* end(Array<Type>& array) { return array + array_get_header(array)->Num; }
template<class Type> forceinline Type* next(Array<Type>& array, Type* entry) { return entry + 1; }
#else
template<class Type> forceinline Type* begin(Array<Type> array) { return array; }
template<class Type> forceinline Type* end(Array<Type> array) { return array + get_header(array)->Num; }
template<class Type> forceinline Type* next(Array<Type> array, Type* entry) { return entry + 1; }
#endif
template<class Type> forceinline Type* array_begin(Array<Type> array) { return array; }
template<class Type> forceinline Type* array_end(Array<Type> array) { return array + array_get_header(array)->Num; }
template<class Type> forceinline Type* array_next(Array<Type> array, Type* entry) { return entry + 1; }
template<class Type> inline
Array<Type> array_init(AllocatorInfo allocator) {
return array_init_reserve<Type>(allocator, array_grow_formula(0));
@ -141,20 +141,20 @@ usize array_grow_formula(ssize value) {
}
template<class Type> inline
bool append(Array<Type>* array, Array<Type> other) {
bool array_append(Array<Type>* array, Array<Type> other) {
return append(array, other, num(other));
}
template<class Type> inline
bool append(Array<Type>* array, Type value)
bool array_append(Array<Type>* array, Type value)
{
ArrayHeader* header = get_header(* array);
ArrayHeader* header = array_get_header(* array);
if (header->Num == header->Capacity)
{
if ( ! grow(array, header->Capacity))
if ( ! array_grow(array, header->Capacity))
return false;
header = get_header(* array);
header = array_get_header(* array);
}
(*array)[ header->Num] = value;
@ -164,15 +164,15 @@ bool append(Array<Type>* array, Type value)
}
template<class Type> inline
bool append(Array<Type>* array, Type* items, usize item_num)
bool array_append(Array<Type>* array, Type* items, usize item_num)
{
ArrayHeader* header = get_header(array);
ArrayHeader* header = array_get_header(array);
if (header->Num + item_num > header->Capacity)
{
if ( ! grow(array, header->Capacity + item_num))
return false;
header = get_header(array);
header = array_get_header(array);
}
mem_copy((Type*)array + header->Num, items, item_num * sizeof(Type));
@ -182,9 +182,9 @@ bool append(Array<Type>* array, Type* items, usize item_num)
}
template<class Type> inline
bool append_at(Array<Type>* array, Type item, usize idx)
bool array_append_at(Array<Type>* array, Type item, usize idx)
{
ArrayHeader* header = get_header(* array);
ArrayHeader* header = array_get_header(* array);
ssize slot = idx;
if (slot >= header->Num)
@ -195,10 +195,10 @@ bool append_at(Array<Type>* array, Type item, usize idx)
if (header->Capacity < header->Num + 1)
{
if ( ! grow(array, header->Capacity + 1))
if ( ! array_grow(array, header->Capacity + 1))
return false;
header = get_header(* array);
header = array_get_header(* array);
}
Type* target = &(*array)[slot];
@ -206,13 +206,13 @@ bool append_at(Array<Type>* array, Type item, usize idx)
mem_move(target + 1, target, (header->Num - slot) * sizeof(Type));
header->Num++;
header = get_header(* array);
header = array_get_header(* array);
return true;
}
template<class Type> inline
bool append_at(Array<Type>* array, Type* items, usize item_num, usize idx)
bool array_append_at(Array<Type>* array, Type* items, usize item_num, usize idx)
{
ArrayHeader* header = get_header(array);
@ -240,11 +240,11 @@ bool append_at(Array<Type>* array, Type* items, usize item_num, usize idx)
}
template<class Type> inline
Type* back(Array<Type>* array)
Type* array_back(Array<Type>* array)
{
GEN_ASSERT(array != nullptr);
ArrayHeader* header = get_header(* array);
ArrayHeader* header = array_get_header(* array);
if (header->Num <= 0)
return nullptr;
@ -252,15 +252,15 @@ Type* back(Array<Type>* array)
}
template<class Type> inline
void clear(Array<Type> array) {
ArrayHeader* header = get_header(array);
void array_clear(Array<Type> array) {
ArrayHeader* header = array_get_header(array);
header->Num = 0;
}
template<class Type> inline
bool fill(Array<Type> array, usize begin, usize end, Type value)
bool array_fill(Array<Type> array, usize begin, usize end, Type value)
{
ArrayHeader* header = get_header(array);
ArrayHeader* header = array_get_header(array);
if (begin < 0 || end > header->Num)
return false;
@ -274,49 +274,49 @@ bool fill(Array<Type> array, usize begin, usize end, Type value)
}
template<class Type> inline
void free(Array<Type>* array) {
void array_free(Array<Type>* array) {
GEN_ASSERT(array != nullptr);
ArrayHeader* header = get_header(* array);
GEN_NS free(header->Allocator, header);
ArrayHeader* header = array_get_header(* array);
allocator_free(header->Allocator, header);
Type** Data = (Type**)array;
*Data = nullptr;
}
template<class Type> forceinline
ArrayHeader* get_header(Array<Type> array) {
ArrayHeader* array_get_header(Array<Type> array) {
Type* Data = array;
using NonConstType = TRemoveConst<Type>;
return rcast(ArrayHeader*, const_cast<NonConstType*>(Data)) - 1;
}
template<class Type> inline
bool grow(Array<Type>* array, usize min_capacity)
bool array_grow(Array<Type>* array, usize min_capacity)
{
ArrayHeader* header = get_header(* array);
ArrayHeader* header = array_get_header(* array);
usize new_capacity = array_grow_formula(header->Capacity);
if (new_capacity < min_capacity)
new_capacity = min_capacity;
return set_capacity(array, new_capacity);
return array_set_capacity(array, new_capacity);
}
template<class Type> inline
usize num(Array<Type> array) {
return get_header(array)->Num;
usize array_num(Array<Type> array) {
return array_get_header(array)->Num;
}
template<class Type> inline
void pop(Array<Type> array) {
ArrayHeader* header = get_header(array);
void array_pop(Array<Type> array) {
ArrayHeader* header = array_get_header(array);
GEN_ASSERT(header->Num > 0);
header->Num--;
}
template<class Type> inline
void remove_at(Array<Type> array, usize idx)
void array_remove_at(Array<Type> array, usize idx)
{
ArrayHeader* header = get_header(array);
ArrayHeader* header = array_get_header(array);
GEN_ASSERT(idx < header->Num);
mem_move(array + idx, array + idx + 1, sizeof(Type) * (header->Num - idx - 1));
@ -324,9 +324,9 @@ void remove_at(Array<Type> array, usize idx)
}
template<class Type> inline
bool reserve(Array<Type>* array, usize new_capacity)
bool array_reserve(Array<Type>* array, usize new_capacity)
{
ArrayHeader* header = get_header(array);
ArrayHeader* header = array_get_header(array);
if (header->Capacity < new_capacity)
return set_capacity(array, new_capacity);
@ -335,14 +335,14 @@ bool reserve(Array<Type>* array, usize new_capacity)
}
template<class Type> inline
bool resize(Array<Type>* array, usize num)
bool array_resize(Array<Type>* array, usize num)
{
ArrayHeader* header = get_header(* array);
ArrayHeader* header = array_get_header(* array);
if (header->Capacity < num) {
if (! grow( array, num))
if (! array_grow( array, num))
return false;
header = get_header(* array);
header = array_get_header(* array);
}
header->Num = num;
@ -350,9 +350,9 @@ bool resize(Array<Type>* array, usize num)
}
template<class Type> inline
bool set_capacity(Array<Type>* array, usize new_capacity)
bool array_set_capacity(Array<Type>* array, usize new_capacity)
{
ArrayHeader* header = get_header(* array);
ArrayHeader* header = array_get_header(* array);
if (new_capacity == header->Capacity)
return true;
@ -373,13 +373,15 @@ bool set_capacity(Array<Type>* array, usize new_capacity)
new_header->Capacity = new_capacity;
GEN_NS free(header->Allocator, header);
allocator_free(header->Allocator, header);
Type** Data = (Type**)array;
* Data = rcast(Type*, new_header + 1);
return true;
}
#define array_init_reserve(type, allocator, cap) array_init_reserve<type>(allocator, cap)
#pragma endregion Array
// TODO(Ed) : This thing needs ALOT of work.
@ -471,9 +473,9 @@ HashTable<Type> hashtable_init_reserve(AllocatorInfo allocator, usize num)
HashTable<Type> result = { { nullptr }, { nullptr } };
result.Hashes = array_init_reserve<ssize>(allocator, num);
get_header(result.Hashes)->Num = num;
resize(& result.Hashes, num);
fill<ssize>(result.Hashes, 0, num, -1);
array_get_header(result.Hashes)->Num = num;
array_resize(& result.Hashes, num);
array_fill<ssize>(result.Hashes, 0, num, -1);
result.Entries = array_init_reserve<HashTableEntry<Type>>(allocator, num);
return result;
@ -481,15 +483,15 @@ HashTable<Type> hashtable_init_reserve(AllocatorInfo allocator, usize num)
template<typename Type> inline
void clear(HashTable<Type> table) {
clear(table.Entries);
fill<ssize>(table.Hashes, 0, num(table.Hashes), -1);
array_clear(table.Entries);
array_fill(table.Hashes, 0, array_num(table.Hashes), (ssize)-1);
}
template<typename Type> inline
void destroy(HashTable<Type>* table) {
if (table->Hashes && get_header(table->Hashes)->Capacity) {
free(& table->Hashes);
free(& table->Entries);
if (table->Hashes && array_get_header(table->Hashes)->Capacity) {
array_free(& table->Hashes);
array_free(& table->Entries);
}
}
@ -522,7 +524,7 @@ void map_mut(HashTable<Type> table, void (*map_proc)(u64 key, Type* value)) {
template<typename Type> inline
void grow(HashTable<Type>* table) {
ssize new_num = array_grow_formula(num(table->Entries));
ssize new_num = array_grow_formula( array_num(table->Entries));
rehash(table, new_num);
}
@ -530,9 +532,9 @@ template<typename Type> inline
void rehash(HashTable<Type>* table, ssize new_num)
{
ssize last_added_index;
HashTable<Type> new_ht = hashtable_init_reserve<Type>(get_header(table->Hashes)->Allocator, new_num);
HashTable<Type> new_ht = hashtable_init_reserve<Type>( array_get_header(table->Hashes)->Allocator, new_num);
for (ssize idx = 0; idx < ssize(num(table->Entries)); ++idx)
for (ssize idx = 0; idx < ssize( array_num(table->Entries)); ++idx)
{
HashTableFindResult find_result;
HashTableEntry<Type>& entry = table->Entries[idx];
@ -639,8 +641,8 @@ ssize add_entry(HashTable<Type>* table, u64 key) {
ssize idx;
HashTableEntry<Type> entry = { key, -1 };
idx = num(table->Entries);
append( & table->Entries, entry);
idx = array_num(table->Entries);
array_append( & table->Entries, entry);
return idx;
}
@ -649,9 +651,9 @@ HashTableFindResult find(HashTable<Type> table, u64 key)
{
HashTableFindResult result = { -1, -1, -1 };
if (num(table.Hashes) > 0)
if (array_num(table.Hashes) > 0)
{
result.HashIndex = key % num(table.Hashes);
result.HashIndex = key % array_num(table.Hashes);
result.EntryIndex = table.Hashes[result.HashIndex];
while (result.EntryIndex >= 0)
@ -669,8 +671,8 @@ HashTableFindResult find(HashTable<Type> table, u64 key)
template<typename Type> inline
bool full(HashTable<Type> table) {
usize critical_load = usize(HashTable_CriticalLoadScale * f32(num(table.Hashes)));
b32 result = num(table.Entries) > critical_load;
usize critical_load = usize(HashTable_CriticalLoadScale * f32(array_num(table.Hashes)));
b32 result = array_num(table.Entries) > critical_load;
return result;
}

View File

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

View File

@ -36,7 +36,7 @@ wchar_t* _alloc_utf8_to_ucs2( AllocatorInfo a, char const* text, ssize* w_len_ )
w_len1 = MultiByteToWideChar( CP_UTF8, MB_ERR_INVALID_CHARS, text, scast( int, len), w_text, scast( int, w_len) );
if ( w_len1 == 0 )
{
free( a, w_text );
allocator_free( a, w_text );
if ( w_len_ )
*w_len_ = 0;
return NULL;
@ -145,7 +145,7 @@ GEN_FILE_OPEN_PROC( _win32_file_open )
w_text = _alloc_utf8_to_ucs2( heap(), filename, NULL );
handle = CreateFileW( w_text, desired_access, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL );
free( heap(), w_text );
allocator_free( heap(), w_text );
if ( handle == INVALID_HANDLE_VALUE )
{
@ -340,7 +340,7 @@ FileError file_close( FileInfo* f )
return EFileError_INVALID;
if ( f->filename )
free( heap(), ccast( char*, f->filename ));
allocator_free( heap(), ccast( char*, f->filename ));
#if defined( GEN_SYSTEM_WINDOWS )
if ( f->fd.p == INVALID_HANDLE_VALUE )
@ -540,7 +540,7 @@ b8 file_stream_open( FileInfo* file, AllocatorInfo allocator, u8* buffer, ssize
mem_copy( d->buf, buffer, size );
d->cap = size;
get_header(arr)->Num = size;
array_get_header(arr)->Num = size;
}
else
{
@ -610,9 +610,9 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
{
Array<u8> arr = { d->buf };
if ( get_header(arr)->Capacity < usize(new_cap) )
if ( array_get_header(arr)->Capacity < usize(new_cap) )
{
if ( ! grow( & arr, ( s64 )( new_cap ) ) )
if ( ! array_grow( & arr, ( s64 )( new_cap ) ) )
return false;
d->buf = arr;
}
@ -626,7 +626,7 @@ GEN_FILE_WRITE_AT_PROC( _memory_file_write )
mem_copy( d->buf + offset + rwlen, pointer_add_const( buffer, rwlen ), extralen );
d->cap = new_cap;
get_header(arr)->Capacity = new_cap;
array_get_header(arr)->Capacity = new_cap;
}
else
{
@ -647,10 +647,10 @@ GEN_FILE_CLOSE_PROC( _memory_file_close )
if ( d->flags & EFileStream_CLONE_WRITABLE )
{
Array<u8> arr = { d->buf };
free(& arr);
array_free(& arr);
}
free( allocator, d );
allocator_free( allocator, d );
}
FileOperations const memory_file_operations = { _memory_file_read, _memory_file_write, _memory_file_seek, _memory_file_close };

View File

@ -49,7 +49,7 @@ typedef struct FileOperations FileOperations;
#define GEN_FILE_OPEN_PROC( name ) FileError name( FileDescriptor* fd, FileOperations* ops, FileMode mode, char const* filename )
#define GEN_FILE_READ_AT_PROC( name ) b32 name( FileDescriptor fd, void* buffer, ssize size, s64 offset, ssize* bytes_read, b32 stop_at_newline )
#define GEN_FILE_WRITE_AT_PROC( name ) b32 name( FileDescriptor fd, void const* buffer, ssize size, s64 offset, ssize* bytes_written )
#define GEN_FILE_WRITE_AT_PROC( name ) b32 name( FileDescriptor fd, mem_ptr_const buffer, ssize size, s64 offset, ssize* bytes_written )
#define GEN_FILE_SEEK_PROC( name ) b32 name( FileDescriptor fd, s64 offset, SeekWhenceType whence, s64* new_offset )
#define GEN_FILE_CLOSE_PROC( name ) void name( FileDescriptor fd )

View File

@ -5,7 +5,11 @@
#pragma region Hashing
GEN_API_C_BEGIN
u32 crc32( void const* data, ssize len );
u64 crc64( void const* data, ssize len );
GEN_API_C_END
#pragma endregion Hashing

View File

@ -14,17 +14,12 @@
#define local_persist static // Local Persisting variables
#endif
#ifndef api_c
#define api_c extern "C"
#endif
#ifndef bit
#define bit( Value ) ( 1 << Value )
#define bitfield_is_equal( Type, Field, Mask ) ( (Type(Mask) & Type(Field)) == Type(Mask) )
#endif
#if ! GEN_C_COMPILER
#if GEN_COMPILER_CPP
# ifndef cast
# define cast( type, value ) (tmpl_cast<type>( value ))
# endif
@ -210,9 +205,15 @@
# endif
#endif
// This is intended to only really be used internally or with the C-library variant
// C++ users can just use the for-range directly.
#define foreach(Type, entry_id, iterable) for ( Type entry_id = begin(iterable); entry_id != end(iterable); entry_id = next(iterable, entry_id) )
#ifndef GEN_API_C_BEGIN
# if GEN_COMPILER_C
# define GEN_API_C_BEGIN
# define GEN_API_C_END
# else
# define GEN_API_C_BEGIN extern "C" {
# define GEN_API_C_END }
# endif
#endif
#if GEN_COMPILER_C
# if __STDC_VERSION__ >= 202311L
@ -230,7 +231,7 @@
# endif
#endif
#if ! defined(GEN_PARAM_DEFAULT) && ! GEN_COMPILER_C
#if ! defined(GEN_PARAM_DEFAULT) && GEN_COMPILER_CPP
# define GEN_PARAM_DEFAULT = {}
#else
# define GEN_PARAM_DEFAULT

View File

@ -346,7 +346,7 @@ void* arena_allocator_proc( void* allocator_data, AllocType type, ssize size, ss
case EAllocation_ALLOC :
{
void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed );
ssize total_size = align_forward_i64( size, alignment );
ssize total_size = align_forward_s64( size, alignment );
// NOTE: Out of memory
if ( arena->TotalUsed + total_size > (ssize) arena->TotalSize )

View File

@ -22,6 +22,8 @@ void swap( Type& a, Type& b )
b = tmp;
}
GEN_API_C_BEGIN
//! Checks if value is power of 2.
b32 is_power_of_two( ssize x );
@ -29,7 +31,7 @@ b32 is_power_of_two( ssize x );
void* align_forward( void* ptr, ssize alignment );
//! Aligns value to a specified alignment.
s64 align_forward_i64( s64 value, ssize alignment );
s64 align_forward_by_value( s64 value, ssize alignment );
//! Moves pointer forward by bytes.
void* pointer_add( void* ptr, ssize bytes );
@ -100,7 +102,7 @@ void* alloc( AllocatorInfo a, ssize size );
void* alloc_align( AllocatorInfo a, ssize size, ssize alignment );
//! Free allocated memory.
void free( AllocatorInfo a, void* ptr );
void allocator_free( AllocatorInfo a, void* ptr );
//! Free all memory allocated by an allocator.
void free_all( AllocatorInfo a );
@ -142,11 +144,12 @@ constexpr AllocatorInfo heap( void ) { AllocatorInfo allocator = { heap_allocato
//! Helper to free memory allocated by heap allocator.
#define mfree( ptr ) free( heap(), ptr )
struct VirtualMemory
struct VirtualMemory_Def
{
void* data;
ssize size;
};
typedef struct VirtualMemory_Def VirtualMemory;
//! Initialize virtual memory from existing data.
VirtualMemory vm_from_memory( void* data, ssize size );
@ -164,15 +167,16 @@ b32 vm_free( VirtualMemory vm );
VirtualMemory vm_trim( VirtualMemory vm, ssize lead_size, ssize size );
//! Purge virtual memory.
b32 gen_vm_purge( VirtualMemory vm );
b32 vm_purge( VirtualMemory vm );
//! Retrieve VM's page size and alignment.
ssize gen_virtual_memory_page_size( ssize* alignment_out );
ssize virtual_memory_page_size( ssize* alignment_out );
#pragma region Arena
struct Arena;
struct Arena_Def;
typedef struct Arena_Def Arena;
AllocatorInfo allocator_info( Arena* arena );
AllocatorInfo arena_allocator_info( Arena* arena );
// Remove static keyword and rename allocator_proc
void* arena_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
@ -181,18 +185,13 @@ void* arena_allocator_proc(void* allocator_data, AllocType type, ssize size, ssi
Arena arena_init_from_allocator(AllocatorInfo backing, ssize size);
Arena arena_init_from_memory ( void* start, ssize size );
Arena init_sub (Arena* parent, ssize size);
ssize alignment_of (Arena* arena, ssize alignment);
void free (Arena* arena);
ssize size_remaining(Arena* arena, ssize alignment);
Arena arena_init_sub (Arena* parent, ssize size);
ssize arena_alignment_of (Arena* arena, ssize alignment);
void arena_check (Arena* arena);
void arena_free (Arena* arena);
ssize arena_size_remaining(Arena* arena, ssize alignment);
// This id is defined by Unreal for asserts
#pragma push_macro("check")
#undef check
void check(Arena* arena);
#pragma pop_macro("check")
struct Arena
struct Arena_Def
{
AllocatorInfo Backing;
void* PhysicalStart;
@ -202,20 +201,20 @@ struct Arena
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#pragma region Member Mapping
forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); }
forceinline operator AllocatorInfo() { return GEN_NS 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 alignment_of(this, alignment); }
forceinline void free() { return GEN_NS free(this); }
forceinline ssize size_remaining( ssize alignment ) { return GEN_NS size_remaining(this, alignment); }
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); }
// This id is defined by Unreal for asserts
#pragma push_macro("check")
#undef check
forceinline void check() { GEN_NS check(this); }
forceinline void check() { GEN_NS arena_check(this); }
#pragma pop_macro("check")
#pragma endregion Member Mapping
@ -223,11 +222,11 @@ struct Arena
};
#if GEN_SUPPORT_CPP_REFERENCES
forceinline AllocatorInfo allocator_info(Arena& arena ) { return allocator_info(& arena); }
forceinline Arena init_sub (Arena& parent, ssize size) { return init_sub( & parent, size); }
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return alignment_of( & arena, alignment); }
forceinline void free (Arena& arena) { return free(& arena); }
forceinline ssize size_remaining(Arena& arena, ssize alignment) { return size_remaining(& arena, alignment); }
forceinline AllocatorInfo allocator_info(Arena& arena ) { return arena_allocator_info(& arena); }
forceinline Arena init_sub (Arena& parent, ssize size) { return arena_init_sub( & parent, size); }
forceinline ssize alignment_of (Arena& arena, ssize alignment) { return arena_alignment_of( & arena, alignment); }
forceinline void free (Arena& arena) { return arena_free(& arena); }
forceinline ssize size_remaining(Arena& arena, ssize alignment) { return arena_size_remaining(& arena, alignment); }
// This id is defined by Unreal for asserts
#pragma push_macro("check")
@ -238,9 +237,10 @@ forceinline void check(Arena& arena) { return check(& arena); };
inline
AllocatorInfo allocator_info( Arena* arena ) {
AllocatorInfo arena_allocator_info( Arena* arena ) {
GEN_ASSERT(arena != nullptr);
return { arena_allocator_proc, arena };
AllocatorInfo info = { arena_allocator_proc, arena };
return info;
}
inline
@ -269,13 +269,13 @@ Arena arena_init_from_allocator(AllocatorInfo backing, ssize size) {
}
inline
Arena init_sub(Arena* parent, ssize size) {
Arena arena_init_sub(Arena* parent, ssize size) {
GEN_ASSERT(parent != nullptr);
return arena_init_from_allocator(parent->Backing, size);
}
inline
ssize alignment_of(Arena* arena, ssize alignment)
ssize arena_alignment_of(Arena* arena, ssize alignment)
{
GEN_ASSERT(arena != nullptr);
ssize alignment_offset, result_pointer, mask;
@ -291,36 +291,35 @@ ssize alignment_of(Arena* arena, ssize alignment)
return alignment_offset;
}
#pragma push_macro("check")
#undef check
inline
void check(Arena* arena)
void arena_check(Arena* arena)
{
GEN_ASSERT(arena != nullptr );
GEN_ASSERT(arena->TempCount == 0);
}
#pragma pop_macro("check")
inline
void free(Arena* arena)
void arena_free(Arena* arena)
{
GEN_ASSERT(arena != nullptr);
if (arena->Backing.Proc)
{
GEN_NS free(arena->Backing, arena->PhysicalStart);
allocator_free(arena->Backing, arena->PhysicalStart);
arena->PhysicalStart = nullptr;
}
}
inline
ssize size_remaining(Arena* arena, ssize alignment)
ssize arena_size_remaining(Arena* arena, ssize alignment)
{
GEN_ASSERT(arena != nullptr);
ssize result = arena->TotalSize - (arena->TotalUsed + alignment_of(arena, alignment));
ssize result = arena->TotalSize - (arena->TotalUsed + arena_alignment_of(arena, alignment));
return result;
}
#pragma endregion Arena
GEN_API_C_END
#pragma region FixedArena
template<s32 Size>
struct FixedArena;
@ -383,24 +382,27 @@ using Arena_2MB = FixedArena< megabytes( 2 ) >;
using Arena_4MB = FixedArena< megabytes( 4 ) >;
#pragma endregion FixedArena
GEN_API_C_BEGIN
#pragma region Pool
struct Pool;
struct Pool_Def;
typedef struct Pool_Def Pool;
void* pool_allocator_proc(void* allocator_data, AllocType type, ssize size, ssize alignment, void* old_memory, ssize old_size, u64 flags);
Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size);
Pool pool_init_align(AllocatorInfo backing, ssize num_blocks, ssize block_size, ssize block_align);
AllocatorInfo allocator_info(Pool* pool);
void clear(Pool* pool);
void free(Pool* pool);
AllocatorInfo pool_allocator_info(Pool* pool);
void pool_clear(Pool* pool);
void pool_free(Pool* pool);
#if GEN_SUPPORT_CPP_REFERENCES
AllocatorInfo allocator_info(Pool& pool);
void clear(Pool& pool);
void free(Pool& pool);
AllocatorInfo allocator_info(Pool& pool) { return GEN_NS allocator_info(& pool); }
void clear(Pool& pool) { return GEN_NS clear(& pool); }
void free(Pool& pool) { return GEN_NS free(& pool); }
#endif
struct Pool
struct Pool_Def
{
AllocatorInfo Backing;
void* PhysicalStart;
@ -412,19 +414,19 @@ struct Pool
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
#pragma region Member Mapping
forceinline operator AllocatorInfo() { return GEN_NS allocator_info(this); }
forceinline operator AllocatorInfo() { return GEN_NS 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 clear( this); }
forceinline void free() { GEN_NS free( this); }
forceinline void clear() { GEN_NS pool_clear( this); }
forceinline void free() { GEN_NS pool_free( this); }
#pragma endregion
#endif
};
inline
AllocatorInfo allocator_info(Pool* pool) {
AllocatorInfo pool_allocator_info(Pool* pool) {
return { pool_allocator_proc, pool };
}
@ -434,9 +436,9 @@ Pool pool_init(AllocatorInfo backing, ssize num_blocks, ssize block_size) {
}
inline
void free(Pool* pool) {
void pool_free(Pool* pool) {
if(pool->Backing.Proc) {
GEN_NS free(pool->Backing, pool->PhysicalStart);
allocator_free(pool->Backing, pool->PhysicalStart);
}
}
#pragma endregion Pool
@ -458,7 +460,7 @@ mem_ptr align_forward( void* ptr, ssize alignment )
return to_mem_ptr(forward);
}
inline s64 align_forward_i64( s64 value, ssize alignment ) { return value + ( alignment - value % alignment ) % alignment; }
inline s64 align_forward_s64( s64 value, ssize alignment ) { return value + ( alignment - value % alignment ) % alignment; }
inline void* pointer_add ( void* ptr, ssize bytes ) { return rcast(void*, rcast( u8*, ptr) + bytes ); }
inline void const* pointer_add_const( void const* ptr, ssize bytes ) { return rcast(void const*, rcast( u8 const*, ptr) + bytes ); }
@ -616,7 +618,7 @@ void* alloc( AllocatorInfo a, ssize size ) {
}
inline
void free( AllocatorInfo a, void* ptr ) {
void allocator_free( AllocatorInfo a, void* ptr ) {
if ( ptr != nullptr )
a.Proc( a.Data, EAllocation_FREE, 0, 0, ptr, 0, GEN_DEFAULT_ALLOCATOR_FLAGS );
}
@ -644,7 +646,7 @@ void* default_resize_align( AllocatorInfo a, void* old_memory, ssize old_size, s
if ( new_size == 0 )
{
free( a, old_memory );
allocator_free( a, old_memory );
return nullptr;
}
@ -662,7 +664,7 @@ void* default_resize_align( AllocatorInfo a, void* old_memory, ssize old_size, s
return nullptr;
mem_move( new_memory, old_memory, min( new_size, old_size ) );
free( a, old_memory );
allocator_free( a, old_memory );
return new_memory;
}
}
@ -672,4 +674,6 @@ void zero_size( void* ptr, ssize size ) {
mem_set( ptr, 0, size );
}
GEN_API_C_END
#pragma endregion Memory

View File

@ -36,12 +36,12 @@ u8 adt_destroy_branch( ADT_Node* node )
GEN_ASSERT_NOT_NULL( node );
if ( ( node->type == EADT_TYPE_OBJECT || node->type == EADT_TYPE_ARRAY ) && node->nodes )
{
for ( ssize i = 0; i < scast(ssize, num(node->nodes)); ++i )
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); ++i )
{
adt_destroy_branch( node->nodes + i );
}
free(& node->nodes);
array_free(& node->nodes);
}
return 0;
}
@ -66,7 +66,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
return NULL;
}
for ( ssize i = 0; i < scast(ssize, num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
{
if ( ! str_compare( node->nodes[ i ].name, name ) )
{
@ -76,7 +76,7 @@ ADT_Node* adt_find( ADT_Node* node, char const* name, b32 deep_search )
if ( deep_search )
{
for ( ssize i = 0; i < scast(ssize, num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
{
ADT_Node* res = adt_find( node->nodes + i, name, deep_search );
@ -132,7 +132,7 @@ internal ADT_Node* _adt_get_value( ADT_Node* node, char const* value )
internal ADT_Node* _adt_get_field( ADT_Node* node, char* name, char* value )
{
for ( ssize i = 0; i < scast(ssize, num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
{
if ( ! str_compare( node->nodes[ i ].name, name ) )
{
@ -207,7 +207,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* run a value comparison against any child that is an object node */
else if ( node->type == EADT_TYPE_ARRAY )
{
for ( ssize i = 0; i < scast(ssize, num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
{
ADT_Node* child = &node->nodes[ i ];
if ( child->type != EADT_TYPE_OBJECT )
@ -225,7 +225,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
/* [value] */
else
{
for ( ssize i = 0; i < scast(ssize, num(node->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, array_num(node->nodes)); i++ )
{
ADT_Node* child = &node->nodes[ i ];
if ( _adt_get_value( child, l_b2 ) )
@ -257,7 +257,7 @@ ADT_Node* adt_query( ADT_Node* node, char const* uri )
else
{
ssize idx = ( ssize )str_to_i64( buf, NULL, 10 );
if ( idx >= 0 && idx < scast(ssize, num(node->nodes)) )
if ( idx >= 0 && idx < scast(ssize, array_num(node->nodes)) )
{
found_node = &node->nodes[ idx ];
@ -282,12 +282,12 @@ ADT_Node* adt_alloc_at( ADT_Node* parent, ssize index )
if ( ! parent->nodes )
return NULL;
if ( index < 0 || index > scast(ssize, num(parent->nodes)) )
if ( index < 0 || index > scast(ssize, array_num(parent->nodes)) )
return NULL;
ADT_Node o = { 0 };
o.parent = parent;
if ( ! append_at( & parent->nodes, o, index ) )
if ( ! array_append_at( & parent->nodes, o, index ) )
return NULL;
ADT_Node* node = & parent->nodes[index];
@ -304,7 +304,7 @@ ADT_Node* adt_alloc( ADT_Node* parent )
if ( ! parent->nodes )
return NULL;
return adt_alloc_at( parent, num(parent->nodes) );
return adt_alloc_at( parent, array_num(parent->nodes) );
}
b8 adt_set_obj( ADT_Node* obj, char const* name, AllocatorInfo backing )
@ -358,7 +358,7 @@ ADT_Node* adt_move_node( ADT_Node* node, ADT_Node* new_parent )
GEN_ASSERT_NOT_NULL( node );
GEN_ASSERT_NOT_NULL( new_parent );
GEN_ASSERT( new_parent->type == EADT_TYPE_ARRAY || new_parent->type == EADT_TYPE_OBJECT );
return adt_move_node_at( node, new_parent, num(new_parent->nodes) );
return adt_move_node_at( node, new_parent, array_num(new_parent->nodes) );
}
void adt_swap_nodes( ADT_Node* node, ADT_Node* other_node )
@ -382,7 +382,7 @@ void adt_remove_node( ADT_Node* node )
GEN_ASSERT_NOT_NULL( node->parent );
ADT_Node* parent = node->parent;
ssize index = ( pointer_diff( parent->nodes, node ) / size_of( ADT_Node ) );
remove_at( parent->nodes, index );
array_remove_at( parent->nodes, index );
}
ADT_Node* adt_append_obj( ADT_Node* parent, char const* name )
@ -390,7 +390,7 @@ ADT_Node* adt_append_obj( ADT_Node* parent, char const* name )
ADT_Node* o = adt_alloc( parent );
if ( ! o )
return NULL;
if ( adt_set_obj( o, name, get_header(parent->nodes)->Allocator ) )
if ( adt_set_obj( o, name, array_get_header(parent->nodes)->Allocator ) )
{
adt_remove_node( o );
return NULL;
@ -404,7 +404,7 @@ ADT_Node* adt_append_arr( ADT_Node* parent, char const* name )
if ( ! o )
return NULL;
ArrayHeader* node_header = get_header(parent->nodes);
ArrayHeader* node_header = array_get_header(parent->nodes);
if ( adt_set_arr( o, name, node_header->Allocator ) )
{
adt_remove_node( o );
@ -510,7 +510,7 @@ char* adt_parse_number( ADT_Node* node, char* base_str )
}
else
{
if ( ! str_compare( e, "0x", 2 ) || ! str_compare( e, "0X", 2 ) )
if ( ! str_compare_len( e, "0x", 2 ) || ! str_compare_len( e, "0X", 2 ) )
{
node_props = EADT_PROPS_IS_HEX;
}
@ -949,12 +949,12 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
}
}
if ( columnIndex >= scast(ssize, num(root->nodes)) )
if ( columnIndex >= scast(ssize, array_num(root->nodes)) )
{
adt_append_arr( root, NULL );
}
append( & root->nodes[ columnIndex ].nodes, rowItem );
array_append( & root->nodes[ columnIndex ].nodes, rowItem );
if ( delimiter == delim )
{
@ -982,7 +982,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
}
while ( *currentChar );
if (num( root->nodes) == 0 )
if (array_num( root->nodes) == 0 )
{
GEN_CSV_ASSERT( "unexpected end of input. stream is empty." );
error = ECSV_Error__UNEXPECTED_END_OF_INPUT;
@ -992,12 +992,12 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b
/* consider first row as a header. */
if ( has_header )
{
for ( ssize i = 0; i < scast(ssize, num(root->nodes)); i++ )
for ( ssize i = 0; i < scast(ssize, array_num(root->nodes)); i++ )
{
CSV_Object* col = root->nodes + i;
CSV_Object* hdr = col->nodes;
col->name = hdr->string;
remove_at(col->nodes, 0 );
array_remove_at(col->nodes, 0 );
}
}
@ -1060,11 +1060,11 @@ void csv_write_delimiter( FileInfo* file, CSV_Object* obj, char delimiter )
GEN_ASSERT_NOT_NULL( file );
GEN_ASSERT_NOT_NULL( obj );
GEN_ASSERT( obj->nodes );
ssize cols = num(obj->nodes);
ssize cols = array_num(obj->nodes);
if ( cols == 0 )
return;
ssize rows = num(obj->nodes[ 0 ].nodes);
ssize rows = array_num(obj->nodes[ 0 ].nodes);
if ( rows == 0 )
return;

View File

@ -106,13 +106,25 @@
# define GEN_GCC_VERSION_CHECK(major,minor,patch) (0)
#endif
#ifndef GEN_COMPILER_C
# if defined(__STDC_VERSION__)
# define GEN_COMPILER_C 1
# else
#if !defined(GEN_COMPILER_C)
# ifdef __cplusplus
# define GEN_COMPILER_C 0
# define GEN_COMPILER_CPP 1
# else
# if defined(__STDC__)
# define GEN_COMPILER_C 1
# define GEN_COMPILER_CPP 0
# else
// Fallback for very old C compilers
# define GEN_COMPILER_C 1
# define GEN_COMPILER_CPP 0
# endif
# endif
#endif
#if GEN_COMPILER_C
#pragma message("Detected C")
#endif
#pragma endregion Platform Detection
@ -136,8 +148,6 @@
# define GEN_NS_PARSER_BEGIN
# define GEN_NS_PARSER_END
# define GEN_USING_NS_PARSER
# define GEN_NS_ENUM_BEGIN
# define GEN_NS_ENUM_END
# define GEN_NS
# define GEN_NS_BEGIN
# define GEN_NS_END
@ -145,8 +155,6 @@
# define GEN_NS_PARSER_BEGIN namespace parser {
# define GEN_NS_PARSER_END }
# define GEN_USING_NS_PARSER using namespace parser
# define GEN_NS_ENUM_BEGIN namespace gen_internal_enums {
# define GEN_NS_ENUM_END }
# define GEN_NS ::
# define GEN_NS_BEGIN
# define GEN_NS_END
@ -155,8 +163,6 @@
# define GEN_NS_PARSER_BEGIN namespace parser {
# define GEN_NS_PARSER_END }
# define GEN_USING_NS_PARSER using namespace parser
# define GEN_NS_ENUM_BEGIN namespace gen_internal_enums {
# define GEN_NS_ENUM_END }
# define GEN_NS gen::
# define GEN_NS_BEGIN namespace gen {
# define GEN_NS_END }

View File

@ -431,7 +431,7 @@ neverinline ssize str_fmt_va( char* text, ssize max_len, char const* fmt, va_lis
String gen_str = String { va_arg( va, char*) };
info.precision = length(gen_str);
info.precision = string_length(gen_str);
len = _print_string( text, remaining, &info, gen_str );
}
break;

View File

@ -5,6 +5,8 @@
#pragma region Printing
GEN_API_C_BEGIN
struct FileInfo;
#ifndef GEN_PRINTF_MAXLEN
@ -38,4 +40,6 @@ ssize log_fmt(char const* fmt, ...)
return res;
}
GEN_API_C_END
#pragma endregion Printing

View File

@ -19,7 +19,7 @@ ssize _scan_zpl_i64( const char* text, s32 base, s64* value )
text++;
}
if ( base == 16 && str_compare( text, "0x", 2 ) == 0 )
if ( base == 16 && str_compare_len( text, "0x", 2 ) == 0 )
text += 2;
for ( ;; )
@ -61,7 +61,7 @@ s64 str_to_i64( const char* str, char** end_ptr, s32 base )
if ( ! base )
{
if ( ( str_len( str ) > 2 ) && ( str_compare( str, "0x", 2 ) == 0 ) )
if ( ( str_len( str ) > 2 ) && ( str_compare_len( str, "0x", 2 ) == 0 ) )
base = 16;
else
base = 10;

View File

@ -5,6 +5,8 @@
#pragma region String Ops
GEN_API_C_BEGIN
const char* char_first_occurence( const char* str, char c );
b32 char_is_alpha( char c );
@ -19,11 +21,11 @@ s32 digit_to_int( char c );
s32 hex_digit_to_int( char c );
s32 str_compare( const char* s1, const char* s2 );
s32 str_compare( const char* s1, const char* s2, ssize len );
s32 str_compare_len( const char* s1, const char* s2, ssize len );
char* str_copy( char* dest, const char* source, ssize len );
ssize str_copy_nulpad( char* dest, const char* source, ssize len );
ssize str_len( const char* str );
ssize str_len( const char* str, ssize max_len );
ssize str_len_capped( const char* str, ssize max_len );
char* str_reverse( char* str ); // NOTE: ASCII only
char const* str_skip( char const* str, char c );
char const* str_skip_any( char const* str, char const* char_list );
@ -132,7 +134,7 @@ s32 str_compare( const char* s1, const char* s2 )
}
inline
s32 str_compare( const char* s1, const char* s2, ssize len )
s32 str_compare_len( const char* s1, const char* s2, ssize len )
{
for ( ; len > 0; s1++, s2++, len-- )
{
@ -204,7 +206,7 @@ ssize str_len( const char* str )
}
inline
ssize str_len( const char* str, ssize max_len )
ssize str_len_capped( const char* str, ssize max_len )
{
const char* end = rcast(const char*, mem_find( str, 0, max_len ));
if ( end )
@ -240,7 +242,7 @@ char const* str_skip( char const* str, char c )
inline
char const* str_skip_any( char const* str, char const* char_list )
{
char const* closest_ptr = rcast( char const*, pointer_add_const( rcast(void const*, str), str_len( str ) ));
char const* closest_ptr = rcast( char const*, pointer_add_const( rcast(mem_ptr_const, str), str_len( str ) ));
ssize char_list_count = str_len( char_list );
for ( ssize i = 0; i < char_list_count; i++ )
{
@ -284,4 +286,6 @@ void str_to_upper( char* str )
}
}
GEN_API_C_END
#pragma endregion String Ops

View File

@ -5,15 +5,19 @@
#pragma region Strings
GEN_API_C_BEGIN
struct StrC;
bool are_equal (StrC lhs, StrC rhs);
char const* back (StrC str);
bool contains (StrC str, StrC substring);
StrC duplicate (StrC str, AllocatorInfo allocator);
b32 starts_with (StrC str, StrC substring);
StrC to_str (char const* bad_string);
StrC visualize_whitespace(StrC str, AllocatorInfo allocator);
bool strc_are_equal (StrC lhs, StrC rhs);
char const* strc_back (StrC str);
bool strc_contains (StrC str, StrC substring);
StrC strc_duplicate (StrC str, AllocatorInfo allocator);
b32 strc_starts_with (StrC str, StrC substring);
StrC strc_to_str (char const* bad_string);
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator);
GEN_API_C_END
// Constant string with length.
struct StrC
@ -21,17 +25,17 @@ struct StrC
ssize Len;
char const* Ptr;
#if ! GEN_COMPILER_C
operator char const* () const { return Ptr; }
char const& operator[]( ssize index ) const { return Ptr[index]; }
#if GEN_COMPILER_CPP
forceinline operator char const* () const { return Ptr; }
forceinline char const& operator[]( ssize index ) const { return Ptr[index]; }
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
bool is_equal (StrC rhs) const { return GEN_NS are_equal(* this, rhs); }
char const* back () const { return GEN_NS back(* this); }
bool contains (StrC substring) const { return GEN_NS contains(* this, substring); }
StrC duplicate (AllocatorInfo allocator) const { return GEN_NS duplicate(* this, allocator); }
b32 starts_with (StrC substring) const { return GEN_NS starts_with(* this, substring); }
StrC visualize_whitespace(AllocatorInfo allocator) const { return GEN_NS visualize_whitespace(* this, allocator); }
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); }
#endif
#endif
};
@ -39,12 +43,21 @@ struct StrC
#define cast_to_strc( str ) * rcast( StrC*, (str) - sizeof(ssize) )
#define txt( text ) StrC { sizeof( text ) - 1, ( text ) }
inline char const* begin(StrC str) { return str.Ptr; }
inline char const* end (StrC str) { return str.Ptr + str.Len; }
inline char const* next (StrC str, char const* iter) { return iter + 1; }
GEN_API_C_BEGIN
forceinline char const* strc_begin(StrC str) { return str.Ptr; }
forceinline char const* strc_end (StrC str) { return str.Ptr + str.Len; }
forceinline char const* strc_next (StrC str, char const* iter) { return iter + 1; }
GEN_API_C_END
#if GEN_COMPILER_CPP && 0
forceinline char const* begin(StrC str) { return str.Ptr; }
forceinline char const* end (StrC str) { return str.Ptr + str.Len; }
forceinline char const* next (StrC str, char const* iter) { return iter + 1; }
#endif
GEN_API_C_BEGIN
inline
bool are_equal(StrC lhs, StrC rhs)
bool strc_are_equal(StrC lhs, StrC rhs)
{
if (lhs.Len != rhs.Len)
return false;
@ -57,12 +70,12 @@ bool are_equal(StrC lhs, StrC rhs)
}
inline
char const* back(StrC str) {
char const* strc_back(StrC str) {
return & str.Ptr[str.Len - 1];
}
inline
bool contains(StrC str, StrC substring)
bool strc_contains(StrC str, StrC substring)
{
if (substring.Len > str.Len)
return false;
@ -71,25 +84,26 @@ bool contains(StrC str, StrC substring)
ssize sub_len = substring.Len;
for (ssize idx = 0; idx <= main_len - sub_len; ++idx)
{
if (str_compare(str.Ptr + idx, substring.Ptr, sub_len) == 0)
if (str_compare_len(str.Ptr + idx, substring.Ptr, sub_len) == 0)
return true;
}
return false;
}
inline
b32 starts_with(StrC str, StrC substring) {
b32 strc_starts_with(StrC str, StrC substring) {
if (substring.Len > str.Len)
return false;
b32 result = str_compare(str.Ptr, substring.Ptr, substring.Len) == 0;
b32 result = str_compare_len(str.Ptr, substring.Ptr, substring.Len) == 0;
return result;
}
inline
StrC to_str( char const* bad_str ) {
StrC to_strc_from_c_str( char const* bad_str ) {
return { str_len( bad_str ), bad_str };
}
GEN_API_C_END
// Dynamic String
// This is directly based off the ZPL string api.
@ -104,42 +118,44 @@ typedef char* String;
struct String;
#endif
usize string_grow_formula(usize value);
GEN_API_C_BEGIN
forceinline usize string_grow_formula(usize value);
String string_make (AllocatorInfo allocator, char const* str);
String string_make (AllocatorInfo allocator, StrC str);
String string_make_c_str (AllocatorInfo allocator, char const* str);
String string_make_strc (AllocatorInfo allocator, StrC str);
String string_make_reserve (AllocatorInfo allocator, ssize capacity);
String string_make_length (AllocatorInfo allocator, char const* str, ssize length);
String string_fmt (AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ...);
String string_fmt_buf (AllocatorInfo allocator, char const* fmt, ...);
String string_join (AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue);
bool are_equal (String const lhs, String const rhs);
bool are_equal (String const lhs, StrC rhs);
bool make_space_for (String* str, char const* to_append, ssize add_len);
bool append (String* str, char c);
bool append (String* str, char const* str_to_append);
bool append (String* str, char const* str_to_append, ssize length);
bool append (String* str, StrC str_to_append);
bool append (String* str, String const other);
bool append_fmt (String* str, char const* fmt, ...);
ssize avail_space (String const str);
char* back (String str);
bool contains (String const str, StrC substring);
bool contains (String const str, String const substring);
ssize capacity (String const str);
void clear (String str);
String duplicate (String const str, AllocatorInfo allocator);
void free (String* str);
StringHeader* get_header (String str);
ssize length (String const str);
b32 starts_with (String const str, StrC substring);
b32 starts_with (String const str, String substring);
void skip_line (String str);
void strip_space (String str);
StrC to_strc (String str);
void trim (String str, char const* cut_set);
void trim_space (String str);
String visualize_whitespace(String const str);
bool string_are_equal (String const lhs, String const rhs);
bool string_are_equal_strc (String const lhs, StrC rhs);
bool string_make_space_for (String* str, char const* to_append, ssize add_len);
bool string_append_char (String* str, char c);
bool string_append_c_str (String* str, char const* str_to_append);
bool string_append_c_str_len (String* str, char const* str_to_append, ssize length);
bool string_append_strc (String* str, StrC str_to_append);
bool string_append_string (String* str, String const other);
bool string_append_fmt (String* str, char const* fmt, ...);
ssize string_avail_space (String const str);
char* string_back (String str);
bool string_contains_strc (String const str, StrC substring);
bool string_contains_string (String const str, String const substring);
ssize string_capacity (String const str);
void string_clear (String str);
String string_duplicate (String const str, AllocatorInfo allocator);
void string_free (String* str);
StringHeader* string_get_header (String str);
ssize string_length (String const str);
b32 string_starts_with_strc (String const str, StrC substring);
b32 string_starts_with_string (String const str, String substring);
void string_skip_line (String str);
void string_strip_space (String str);
StrC string_to_strc (String str);
void string_trim (String str, char const* cut_set);
void string_trim_space (String str);
String string_visualize_whitespace(String const str);
GEN_API_C_END
struct StringHeader {
AllocatorInfo Allocator;
@ -147,7 +163,7 @@ struct StringHeader {
ssize Length;
};
#if ! GEN_COMPILER_C && GEN_SUPPORT_CPP_MEMBER_FEATURES
#if GEN_COMPILER_CPP && GEN_SUPPORT_CPP_MEMBER_FEATURES
struct String
{
char* Data;
@ -169,10 +185,10 @@ struct String
forceinline char& operator[](ssize index) { return Data[index]; }
forceinline char const& operator[](ssize index) const { return Data[index]; }
bool operator==(std::nullptr_t) const { return Data == nullptr; }
bool operator!=(std::nullptr_t) const { return Data != nullptr; }
friend bool operator==(std::nullptr_t, const String str) { return str.Data == nullptr; }
friend bool operator!=(std::nullptr_t, const String str) { return str.Data != nullptr; }
forceinline bool operator==(std::nullptr_t) const { return Data == nullptr; }
forceinline bool operator!=(std::nullptr_t) const { return Data != nullptr; }
friend forceinline bool operator==(std::nullptr_t, const String str) { return str.Data == nullptr; }
friend forceinline bool operator!=(std::nullptr_t, const String str) { return str.Data != nullptr; }
forceinline char* begin() const { return Data; }
forceinline char* end() const { return Data + GEN_NS length(* this); }
@ -206,15 +222,15 @@ struct String
}
forceinline bool make_space_for(char const* str, ssize add_len) { return GEN_NS make_space_for(this, str, add_len); }
forceinline bool append(char c) { return GEN_NS append(this, c); }
forceinline bool append(char const* str) { return GEN_NS append(this, str); }
forceinline bool append(char const* str, ssize length) { return GEN_NS append(this, str, length); }
forceinline bool append(StrC str) { return GEN_NS append(this, str); }
forceinline bool append(const String other) { return GEN_NS append(this, other); }
forceinline ssize avail_space() const { return GEN_NS avail_space(* this); }
forceinline char* back() { return GEN_NS back(* this); }
forceinline bool contains(StrC substring) const { return GEN_NS contains(* this, substring); }
forceinline bool contains(String const& substring) const { return GEN_NS contains(* this, substring); }
forceinline bool append(char c) { return GEN_NS string_append_char(this, c); }
forceinline bool append(char const* str) { return GEN_NS string_append_c_str(this, str); }
forceinline bool append(char const* str, ssize length) { return GEN_NS string_append_c_str_len(this, str, length); }
forceinline bool append(StrC str) { return GEN_NS string_append_strc(this, str); }
forceinline bool append(const String other) { return GEN_NS string_append_string(this, other); }
forceinline ssize avail_space() const { return GEN_NS string_avail_space(* this); }
forceinline char* back() { return GEN_NS string_back(* this); }
forceinline bool contains(StrC substring) const { return GEN_NS string_contains_strc(* this, substring); }
forceinline bool contains(String const& substring) const { return GEN_NS string_contains_string(* this, substring); }
forceinline ssize capacity() const { return GEN_NS capacity(* this); }
forceinline void clear() { GEN_NS clear(* this); }
forceinline String duplicate(AllocatorInfo allocator) const { return GEN_NS duplicate(* this, allocator); }
@ -247,37 +263,47 @@ struct String
};
#endif
inline char* begin(String str) { return ((char*) str); }
inline char* end (String str) { return ((char*) str + length(str)); }
inline char* next (String str, char* iter) { return ((char*) iter + 1); }
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_SUPPORT_CPP_REFERENCES
inline bool make_space_for(String& str, char const* to_append, ssize add_len);
inline bool append(String& str, char c);
inline bool append(String& str, char const* str_to_append);
inline bool append(String& str, char const* str_to_append, ssize length);
inline bool append(String& str, StrC str_to_append);
inline bool append(String& str, const String other);
inline bool append_fmt(String& str, char const* fmt, ...);
inline char& back(String& str);
inline void clear(String& str);
inline void free(String& str);
#if GEN_COMPILER_CPP && 0
forceinline char* begin(String str) { return ((char*) str); }
forceinline char* end (String str) { return ((char*) str + string_length(str)); }
forceinline char* next (String str, char* iter) { return ((char*) iter + 1); }
#endif
inline
#if GEN_SUPPORT_CPP_REFERENCES
forceinline bool make_space_for(String& str, char const* to_append, ssize add_len);
forceinline bool append(String& str, char c);
forceinline bool append(String& str, char const* str_to_append);
forceinline bool append(String& str, char const* str_to_append, ssize length);
forceinline bool append(String& str, StrC str_to_append);
forceinline bool append(String& str, const String other);
forceinline bool append_fmt(String& str, char const* fmt, ...);
forceinline char& back(String& str);
forceinline void clear(String& str);
forceinline void free(String& str);
#endif
GEN_API_C_BEGIN
forceinline
usize string_grow_formula(usize value) {
// Using a very aggressive growth formula to reduce time mem_copying with recursive calls to append in this library.
return 4 * value + 8;
}
inline
String string_make(AllocatorInfo allocator, char const* str) {
forceinline
String string_make_c_str(AllocatorInfo allocator, char const* str) {
ssize length = str ? str_len(str) : 0;
return string_make_length(allocator, str, length);
}
inline
String string_make(AllocatorInfo allocator, StrC str) {
forceinline
String string_make_strc(AllocatorInfo allocator, StrC str) {
return string_make_length(allocator, str.Ptr, str.Len);
}
@ -285,10 +311,10 @@ inline
String string_fmt(AllocatorInfo allocator, char* buf, ssize buf_size, char const* fmt, ...) {
va_list va;
va_start(va, fmt);
str_fmt_va(buf, buf_size, fmt, va);
ssize res = str_fmt_va(buf, buf_size, fmt, va);
va_end(va);
return string_make(allocator, buf);
return string_make_length(allocator, buf, res);
}
inline
@ -299,52 +325,52 @@ String string_fmt_buf(AllocatorInfo allocator, char const* fmt, ...)
va_list va;
va_start(va, fmt);
str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
ssize res = str_fmt_va(buf, GEN_PRINTF_MAXLEN, fmt, va);
va_end(va);
return string_make(allocator, buf);
return string_make_length(allocator, buf, res);
}
inline
String string_join(AllocatorInfo allocator, char const** parts, ssize num_parts, char const* glue)
{
String result = string_make(allocator, "");
String result = string_make_c_str(allocator, "");
for (ssize idx = 0; idx < num_parts; ++idx)
{
append(& result, parts[idx]);
string_append_c_str(& result, parts[idx]);
if (idx < num_parts - 1)
append(& result, glue);
string_append_c_str(& result, glue);
}
return result;
}
inline
bool append(String* str, char c) {
forceinline
bool string_append_char(String* str, char c) {
GEN_ASSERT(str != nullptr);
return append( str, (char const*)& c, (ssize)1);
return string_append_c_str_len( str, (char const*)& c, (ssize)1);
}
forceinline
bool string_append_c_str(String* str, char const* str_to_append) {
GEN_ASSERT(str != nullptr);
return string_append_c_str_len(str, str_to_append, str_len(str_to_append));
}
inline
bool append(String* str, char const* str_to_append) {
GEN_ASSERT(str != nullptr);
return append(str, str_to_append, str_len(str_to_append));
}
inline
bool append(String* str, char const* str_to_append, ssize append_length)
bool string_append_str_c_len(String* str, char const* str_to_append, ssize append_length)
{
GEN_ASSERT(str != nullptr);
if (sptr(str_to_append) > 0)
{
ssize curr_len = length(* str);
ssize curr_len = string_length(* str);
if ( ! make_space_for(str, str_to_append, append_length))
if ( ! string_make_space_for(str, str_to_append, append_length))
return false;
StringHeader* header = get_header(* str);
StringHeader* header = string_get_header(* str);
char* Data = * str;
mem_copy( Data + curr_len, str_to_append, append_length);
@ -356,16 +382,16 @@ bool append(String* str, char const* str_to_append, ssize append_length)
return str_to_append != nullptr;
}
inline
bool append(String* str, StrC str_to_append) {
forceinline
bool string_append_strc(String* str, StrC str_to_append) {
GEN_ASSERT(str != nullptr);
return append(str, str_to_append.Ptr, str_to_append.Len);
return string_append_c_str_len(str, str_to_append.Ptr, str_to_append.Len);
}
inline
bool append(String* str, String const other) {
forceinline
bool string_append_string(String* str, String const other) {
GEN_ASSERT(str != nullptr);
return append(str, (char const*)other, length(other));
return string_append_c_str_len(str, (char const*)other, string_length(other));
}
bool append_fmt(String* str, char const* fmt, ...) {
@ -378,16 +404,16 @@ bool append_fmt(String* str, char const* fmt, ...) {
res = str_fmt_va(buf, count_of(buf) - 1, fmt, va) - 1;
va_end(va);
return append(str, (char const*)buf, res);
return string_append_c_str_len(str, (char const*)buf, res);
}
inline
bool are_equal(String const lhs, String const rhs)
bool string_are_equal_string(String const lhs, String const rhs)
{
if (length(lhs) != length(rhs))
if (string_length(lhs) != string_length(rhs))
return false;
for (ssize idx = 0; idx < length(lhs); ++idx)
for (ssize idx = 0; idx < string_length(lhs); ++idx)
if (lhs[idx] != rhs[idx])
return false;
@ -395,27 +421,27 @@ bool are_equal(String const lhs, String const rhs)
}
inline
bool are_equal(String const lhs, StrC rhs)
bool string_are_equal_strc(String const lhs, StrC rhs)
{
if (length(lhs) != (rhs.Len))
if (string_length(lhs) != (rhs.Len))
return false;
for (ssize idx = 0; idx < length(lhs); ++idx)
for (ssize idx = 0; idx < string_length(lhs); ++idx)
if (lhs[idx] != rhs.Ptr[idx])
return false;
return true;
}
inline
forceinline
ssize avail_space(String const str) {
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
return header->Capacity - header->Length;
}
inline
forceinline
char* back(String* str) {
return & (*str)[length(* str) - 1];
return & (*str)[string_length(* str) - 1];
}
inline
@ -431,7 +457,7 @@ bool contains(String const str, StrC substring)
for (ssize idx = 0; idx <= main_len - sub_len; ++idx)
{
if (str_compare(str + idx, substring.Ptr, sub_len) == 0)
if (str_compare_len(str + idx, substring.Ptr, sub_len) == 0)
return true;
}
@ -439,67 +465,67 @@ bool contains(String const str, StrC substring)
}
inline
bool contains(String const str, String const substring)
bool string_contains_string(String const str, String const substring)
{
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
if (length(substring) > header->Length)
if (string_length(substring) > header->Length)
return false;
ssize main_len = header->Length;
ssize sub_len = length(substring);
ssize sub_len = string_length(substring);
for (ssize idx = 0; idx <= main_len - sub_len; ++idx)
{
if (str_compare(str + idx, substring, sub_len) == 0)
if (str_compare_len(str + idx, substring, sub_len) == 0)
return true;
}
return false;
}
inline
ssize capacity(String const str) {
forceinline
ssize string_capacity(String const str) {
StringHeader const* header = rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
return header->Capacity;
}
inline
void clear(String str) {
get_header(str)->Length = 0;
forceinline
void string_clear(String str) {
string_get_header(str)->Length = 0;
}
inline
String duplicate(String const str, AllocatorInfo allocator) {
return string_make_length(allocator, str, length(str));
forceinline
String string_duplicate(String const str, AllocatorInfo allocator) {
return string_make_length(allocator, str, string_length(str));
}
inline
void free(String* str) {
forceinline
void string_free(String* str) {
GEN_ASSERT(str != nullptr);
if (! (* str))
return;
StringHeader* header = get_header(* str);
GEN_NS free(header->Allocator, header);
StringHeader* header = string_get_header(* str);
allocator_free(header->Allocator, header);
}
inline
StringHeader* get_header(String str) {
forceinline
StringHeader* string_get_header(String str) {
return (StringHeader*)(scast(char*, str) - sizeof(StringHeader));
}
inline
ssize length(String const str)
forceinline
ssize string_length(String const str)
{
StringHeader const& header = *rcast(StringHeader const*, scast(char const*, str) - sizeof(StringHeader));
return header.Length;
}
inline
bool make_space_for(String* str, char const* to_append, ssize add_len)
bool string_make_space_for(String* str, char const* to_append, ssize add_len)
{
ssize available = avail_space(* str);
ssize available = string_avail_space(* str);
if (available >= add_len) {
return true;
@ -510,12 +536,12 @@ bool make_space_for(String* str, char const* to_append, ssize add_len)
void* ptr;
void* new_ptr;
AllocatorInfo allocator = get_header(* str)->Allocator;
AllocatorInfo allocator = string_get_header(* str)->Allocator;
StringHeader* header = nullptr;
new_len = string_grow_formula(length(* str) + add_len);
ptr = get_header(* str);
old_size = size_of(StringHeader) + length(* str) + 1;
new_len = string_grow_formula(string_length(* str) + add_len);
ptr = string_get_header(* str);
old_size = size_of(StringHeader) + string_length(* str) + 1;
new_size = size_of(StringHeader) + new_len + 1;
new_ptr = resize(allocator, ptr, old_size, new_size);
@ -534,26 +560,26 @@ bool make_space_for(String* str, char const* to_append, ssize add_len)
}
}
inline
b32 starts_with(String const str, StrC substring) {
if (substring.Len > length(str))
forceinline
b32 string_starts_with_strc(String const str, StrC substring) {
if (substring.Len > string_length(str))
return false;
b32 result = str_compare(str, substring.Ptr, substring.Len) == 0;
b32 result = str_compare_len(str, substring.Ptr, substring.Len) == 0;
return result;
}
forceinline
b32 string_starts_with_string(String const str, String substring) {
if (string_length(substring) > string_length(str))
return false;
b32 result = str_compare_len(str, substring, string_length(substring) - 1) == 0;
return result;
}
inline
b32 starts_with(String const str, String substring) {
if (length(substring) > length(str))
return false;
b32 result = str_compare(str, substring, length(substring) - 1) == 0;
return result;
}
inline
void skip_line(String str)
void string_skip_line(String str)
{
#define current (*scanner)
char* scanner = str;
@ -569,7 +595,7 @@ void skip_line(String str)
mem_move((char*)str, scanner, new_length);
StringHeader* header = get_header(str);
StringHeader* header = string_get_header(str);
header->Length = new_length;
#undef current
}
@ -593,12 +619,12 @@ void strip_space(String str)
write_pos[0] = '\0'; // Null-terminate the modified string
// Update the length if needed
get_header(str)->Length = write_pos - str;
string_get_header(str)->Length = write_pos - str;
}
inline
StrC to_strc(String str) {
return { length(str), (char const*)str };
forceinline
StrC string_to_strc(String str) {
return { string_length(str), (char const*)str };
}
inline
@ -607,7 +633,7 @@ void trim(String str, char const* cut_set)
ssize len = 0;
char* start_pos = str;
char* end_pos = scast(char*, str) + length(str) - 1;
char* end_pos = scast(char*, str) + string_length(str) - 1;
while (start_pos <= end_pos && char_first_occurence(cut_set, *start_pos))
start_pos++;
@ -622,10 +648,10 @@ void trim(String str, char const* cut_set)
str[len] = '\0';
get_header(str)->Length = len;
string_get_header(str)->Length = len;
}
inline
forceinline
void trim_space(String str) {
trim(str, " \t\r\n\v\f");
}
@ -634,30 +660,31 @@ inline
String visualize_whitespace(String const str)
{
StringHeader* header = (StringHeader*)(scast(char const*, str) - sizeof(StringHeader));
String result = string_make_reserve(header->Allocator, length(str) * 2); // Assume worst case for space requirements.
String result = string_make_reserve(header->Allocator, string_length(str) * 2); // Assume worst case for space requirements.
foreach (char*, c, str) switch ( * c )
for (char const* c = string_begin(str); c != string_end(str); c = string_next(str, c))
switch ( * c )
{
case ' ':
append(& result, txt("·"));
string_append_strc(& result, txt("·"));
break;
case '\t':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\n':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\r':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\v':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\f':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
default:
append(& result, c);
string_append_char(& result, * c);
break;
}
@ -670,47 +697,50 @@ struct String_POD {
};
static_assert( sizeof( String_POD ) == sizeof( String ), "String is not a POD" );
inline
StrC duplicate(StrC str, AllocatorInfo allocator) {
forceinline
StrC strc_duplicate(StrC str, AllocatorInfo allocator) {
String result = string_make_length(allocator, str.Ptr, str.Len);
return { get_header(result)->Length, result };
return { string_get_header(result)->Length, result };
}
inline
StrC visualize_whitespace(StrC str, AllocatorInfo allocator)
StrC strc_visualize_whitespace(StrC str, AllocatorInfo allocator)
{
String result = string_make_reserve(allocator, str.Len * 2); // Assume worst case for space requirements.
foreach (char const*, c, str) switch ( * c )
for (char const* c = strc_begin(str); c != strc_end(str); c = strc_next(str, c))
switch ( * c )
{
case ' ':
append(& result, txt("·"));
string_append_strc(& result, txt("·"));
break;
case '\t':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\n':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\r':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\v':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
case '\f':
append(& result, txt(""));
string_append_strc(& result, txt(""));
break;
default:
append(& result, c);
string_append_char(& result, * c);
break;
}
return to_strc(result);
return string_to_strc(result);
}
// Represents strings cached with the string table.
// Should never be modified, if changed string is desired, cache_string( str ) another.
typedef StrC StringCached;
GEN_API_C_END
// Implements basic string interning. Data structure is based off the ZPL Hashtable.
typedef HashTable<StringCached> StringTable;
#pragma endregion Strings

View File

@ -13,7 +13,7 @@ CodeBody gen_ecode( char const* path )
char scratch_mem[kilobytes(1)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( allocator_info( & scratch), zero_terminate, path );
file_read_contents( arena_allocator_info( & scratch), zero_terminate, path );
CSV_Object csv_nodes;
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
@ -23,19 +23,21 @@ CodeBody gen_ecode( char const* path )
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
for ( ADT_Node& node : enum_strs )
for ( ADT_Node* node = array_begin(enum_strs); node != array_end(enum_strs); node = array_next(enum_strs, node) )
{
char const* code = node.string;
char const* code = node->string;
append_fmt( & enum_entries, "CT_%s,\n", code );
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", code, code );
}
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", to_strc(enum_entries), "enum CodeType_Def : u32 { <entries> CT_NumTypes };"));
CodeEnum enum_code = parse_enum(gen::token_fmt_impl((3 + 1) / 2, "entries", string_to_strc(enum_entries),
"enum CodeType_Def : u32 { <entries> CT_NumTypes };"
));
#pragma push_macro("local_persist")
#undef local_persist
CodeFn to_str = parse_function( token_fmt( "entries", to_strc(to_str_entries), stringize(
CodeFn to_str = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
inline
StrC to_str( CodeType type )
{
@ -61,7 +63,7 @@ CodeBody gen_eoperator( char const* path )
char scratch_mem[kilobytes(4)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( allocator_info(& scratch), zero_terminate, path );
file_read_contents( arena_allocator_info(& scratch), zero_terminate, path );
CSV_Object csv_nodes;
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
@ -72,7 +74,7 @@ CodeBody gen_eoperator( char const* path )
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
for (usize idx = 0; idx < num(enum_strs); idx++)
for (usize idx = 0; idx < array_num(enum_strs); idx++)
{
char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = str_strs [idx].string;
@ -81,7 +83,7 @@ CodeBody gen_eoperator( char const* path )
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
}
CodeEnum enum_code = parse_enum(token_fmt("entries", to_strc(enum_entries), stringize(
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
enum Operator_Def : u32
{
<entries>
@ -91,7 +93,7 @@ CodeBody gen_eoperator( char const* path )
#pragma push_macro("local_persist")
#undef local_persist
CodeFn to_str = parse_function(token_fmt("entries", to_strc(to_str_entries), stringize(
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), stringize(
inline
StrC to_str( Operator op )
{
@ -117,7 +119,7 @@ CodeBody gen_especifier( char const* path )
char scratch_mem[kilobytes(4)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
file_read_contents( allocator_info(& scratch), zero_terminate, path );
file_read_contents( arena_allocator_info(& scratch), zero_terminate, path );
CSV_Object csv_nodes;
csv_parse( &csv_nodes, scratch_mem, GlobalAllocator, false );
@ -128,7 +130,7 @@ CodeBody gen_especifier( char const* path )
String enum_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
String to_str_entries = string_make_reserve( GlobalAllocator, kilobytes(1) );
for (usize idx = 0; idx < num(enum_strs); idx++)
for (usize idx = 0; idx < array_num(enum_strs); idx++)
{
char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = str_strs [idx].string;
@ -137,7 +139,7 @@ CodeBody gen_especifier( char const* path )
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
}
CodeEnum enum_code = parse_enum(token_fmt("entries", to_strc(enum_entries), stringize(
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), stringize(
enum Specifier_Def : u32
{
<entries>
@ -145,7 +147,7 @@ CodeBody gen_especifier( char const* path )
};
)));
CodeFn is_trailing = parse_function(token_fmt("specifier", to_strc(to_str_entries), stringize(
CodeFn is_trailing = parse_function(token_fmt("specifier", string_to_strc(to_str_entries), stringize(
inline
bool is_trailing( Specifier specifier )
{
@ -163,7 +165,7 @@ CodeBody gen_especifier( char const* path )
#undef do_once_end
#undef forceinline
#undef neverinline
CodeFn to_str = parse_function(token_fmt("entries", to_strc(to_str_entries), stringize(
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), stringize(
inline
StrC to_str( Specifier type )
{
@ -176,7 +178,7 @@ CodeBody gen_especifier( char const* path )
}
)));
CodeFn to_type = parse_function( token_fmt( "entries", to_strc(to_str_entries), stringize(
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
inline
Specifier to_specifier( StrC str )
{
@ -222,7 +224,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
char scratch_mem[kilobytes(16)];
Arena scratch = arena_init_from_memory( scratch_mem, sizeof(scratch_mem) );
AllocatorInfo scratch_info = allocator_info(& scratch);
AllocatorInfo scratch_info = arena_allocator_info(& scratch);
FileContents enum_content = file_read_contents( scratch_info, zero_terminate, etok_path );
@ -245,7 +247,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
String to_str_attributes = string_make_reserve( GlobalAllocator, kilobytes(4) );
String attribute_define_entries = string_make_reserve( GlobalAllocator, kilobytes(4) );
for (usize idx = 0; idx < num(enum_strs); idx++)
for (usize idx = 0; idx < array_num(enum_strs); idx++)
{
char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = enum_str_strs [idx].string;
@ -254,7 +256,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
}
for ( usize idx = 0; idx < num(attribute_strs); idx++ )
for ( usize idx = 0; idx < array_num(attribute_strs); idx++ )
{
char const* attribute_str = attribute_strs[idx].string;
char const* entry_to_str = attribute_str_strs [idx].string;
@ -263,19 +265,19 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
append_fmt( & to_str_attributes, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
append_fmt( & attribute_define_entries, "Entry( Tok_Attribute_%s, \"%s\" )", attribute_str, entry_to_str );
if ( idx < num(attribute_strs) - 1 )
append( & attribute_define_entries, " \\\n");
if ( idx < array_num(attribute_strs) - 1 )
string_append_strc( & attribute_define_entries, txt(" \\\n"));
else
append( & attribute_define_entries, "\n");
string_append_strc( & attribute_define_entries, txt("\n"));
}
#pragma push_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
#undef GEN_DEFINE_ATTRIBUTE_TOKENS
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), to_strc(attribute_define_entries) );
CodeDefine attribute_entires_def = def_define( name(GEN_DEFINE_ATTRIBUTE_TOKENS), string_to_strc(attribute_define_entries) );
#pragma pop_macro("GEN_DEFINE_ATTRIBUTE_TOKENS")
// We cannot parse this enum, it has Attribute names as enums
CodeEnum enum_code = parse_enum(token_fmt("entries", to_str(enum_entries), "attribute_toks", to_str(attribute_entries), stringize(
CodeEnum enum_code = parse_enum(token_fmt("entries", string_to_strc(enum_entries), "attribute_toks", string_to_strc(attribute_entries), stringize(
enum TokType_Def : u32
{
<entries>
@ -290,7 +292,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
#undef local_persist
#undef do_once_start
#undef do_once_end
CodeFn to_str = parse_function(token_fmt("entries", to_strc(to_str_entries), "attribute_toks", to_strc(to_str_attributes), stringize(
CodeFn to_str = parse_function(token_fmt("entries", string_to_strc(to_str_entries), "attribute_toks", string_to_strc(to_str_attributes), stringize(
inline
StrC to_str( TokType type )
{
@ -304,7 +306,7 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path )
}
)));
CodeFn to_type = parse_function( token_fmt( "entries", to_strc(to_str_entries), stringize(
CodeFn to_type = parse_function( token_fmt( "entries", string_to_strc(to_str_entries), stringize(
inline
TokType to_toktype( StrC str )
{

View File

@ -231,10 +231,12 @@ if ( $c_library )
$executable = join-path $path_build "gen_c_library_test.exe"
if ($vendor -eq "clang") {
$compiler_args += "-x"
$compiler_args += "c"
$compiler_args += '-x'
$compiler_args += 'c'
$compiler_args += '-std=c11'
} elseif ($vendor -eq "msvc") {
$compiler_args += "/TC"
$compiler_args += "/TC" # Compile as C
$compiler_args += "/Zc:__cplusplus" # Fix __cplusplus macro
}
build-simple $path_build $includes $compiler_args $linker_args $unit $executable