diff --git a/.vscode/gencpp.natvis b/.vscode/gencpp.natvis index 91ff517..e505bf4 100644 --- a/.vscode/gencpp.natvis +++ b/.vscode/gencpp.natvis @@ -1,6 +1,10 @@ + + Len:{Len} Ptr:{Ptr, [Len]s} + + null {Data,na} @@ -30,7 +34,30 @@ Type Name + Parent + Op + ModuleFlags + ParentAccess ArrStatic + StaticIndex + ArrDyn + ((ArrayHeader*)((char*)ArrDyn - sizeof(ArrayHeader)))->count + + + + + {ast->Name} {ast->Type} + + ast->Type + ast->Name + ast->Parent + ast->Op + ast->ModuleFlags + ast->ParentAccess + ast->ArrStatic + ast->StaticIndex + ast->ArrDyn + ((ArrayHeader*)((char*)ast->ArrDyn - sizeof(ArrayHeader)))->count @@ -39,7 +66,7 @@ - Type:{Type} Text:{Text, [Length]s} Length:{Length} + Length:{Length} Text:{Text, [Length]s} Type:{Type} diff --git a/Readme.md b/Readme.md index 665e193..a29dc3b 100644 --- a/Readme.md +++ b/Readme.md @@ -262,7 +262,8 @@ Data Notes: Two generic templated containers throughout the library: -`template< class Type> struct Array` and `template< class Type> struct HashTable >` +* `template< class Type> struct Array` +* `template< class Type> struct HashTable` Otherwise the library is free of any templates. diff --git a/gencpp.sln.DotSettings.user b/gencpp.sln.DotSettings.user new file mode 100644 index 0000000..b8b7acd --- /dev/null +++ b/gencpp.sln.DotSettings.user @@ -0,0 +1,3 @@ + + ForceIncluded + ShowAndRun \ No newline at end of file diff --git a/gencpp.vcxproj b/gencpp.vcxproj index 6336ba0..9f4fa15 100644 --- a/gencpp.vcxproj +++ b/gencpp.vcxproj @@ -103,27 +103,34 @@ - - + + - - - + + + + + + + + + - + - + + diff --git a/project/Bloat.cpp b/project/Bloat.cpp index 3b9493d..9800949 100644 --- a/project/Bloat.cpp +++ b/project/Bloat.cpp @@ -2,6 +2,165 @@ #include "Bloat.hpp" +void* gen_Arena::allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags ) +{ + gen_Arena* arena = rcast(gen_Arena*, allocator_data); + void* ptr = NULL; + + // unused( old_size ); + + switch ( type ) + { + case EAllocation_ALLOC : + { + void* end = pointer_add( arena->PhysicalStart, arena->TotalUsed ); + sw total_size = align_forward_i64( size, alignment ); + + // NOTE: Out of memory + if ( arena->TotalUsed + total_size > (sw) arena->TotalSize ) + { + // zpl__printf_err("%s", "Arena out of memory\n"); + return nullptr; + } + + ptr = align_forward( end, alignment ); + arena->TotalUsed += total_size; + + if ( flags & ZPL_ALLOCATOR_FLAG_CLEAR_TO_ZERO ) + zero_size( ptr, size ); + } + break; + + case EAllocation_FREE : + // NOTE: Free all at once + // Use Temp_Arena_Memory if you want to free a block + break; + + case EAllocation_FREE_ALL : + arena->TotalUsed = 0; + break; + + case EAllocation_RESIZE : + { + // TODO : Check if ptr is on top of stack and just extend + AllocatorInfo a = arena->Backing; + ptr = default_resize_align( a, old_memory, old_size, size, alignment ); + } + break; + } + return ptr; +} + +void* gen_Pool::allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags ) +{ + gen_Pool* pool = zpl_cast( gen_Pool* ) allocator_data; + void* ptr = NULL; + + // unused( old_size ); + + switch ( type ) + { + case EAllocation_ALLOC : + { + uptr next_free; + + ZPL_ASSERT( size == pool->BlockSize ); + ZPL_ASSERT( alignment == pool->BlockAlign ); + ZPL_ASSERT( pool->FreeList != NULL ); + + next_free = *zpl_cast( uptr* ) pool->FreeList; + ptr = pool->FreeList; + pool->FreeList = zpl_cast( void* ) next_free; + pool->TotalSize += pool->BlockSize; + + if ( flags & ZPL_ALLOCATOR_FLAG_CLEAR_TO_ZERO ) + zero_size( ptr, size ); + } + break; + + case EAllocation_FREE : + { + uptr* next; + if ( old_memory == NULL ) + return NULL; + + next = zpl_cast( uptr* ) old_memory; + *next = zpl_cast( uptr ) pool->FreeList; + pool->FreeList = old_memory; + pool->TotalSize -= pool->BlockSize; + } + break; + + case EAllocation_FREE_ALL : + { + sw actual_block_size, block_index; + void* curr; + uptr* end; + + actual_block_size = pool->BlockSize + pool->BlockAlign; + pool->TotalSize = 0; + + // NOTE: Init intrusive freelist + curr = pool->PhysicalStart; + for ( block_index = 0; block_index < pool->NumBlocks - 1; block_index++ ) + { + uptr* next = zpl_cast( uptr* ) curr; + *next = zpl_cast( uptr ) curr + actual_block_size; + curr = pointer_add( curr, actual_block_size ); + } + + end = zpl_cast( uptr* ) curr; + *end = zpl_cast( uptr ) NULL; + pool->FreeList = pool->PhysicalStart; + } + break; + + case EAllocation_RESIZE : + // NOTE: Cannot resize + ZPL_PANIC( "You cannot resize something allocated by with a pool." ); + break; + } + + return ptr; +} + +gen_Pool gen_Pool::init_align( AllocatorInfo backing, sw num_blocks, sw block_size, sw block_align ) +{ + gen_Pool pool = {}; + + sw actual_block_size, pool_size, block_index; + void *data, *curr; + uptr* end; + + pool.Backing = backing; + pool.BlockSize = block_size; + pool.BlockAlign = block_align; + pool.NumBlocks = num_blocks; + + actual_block_size = block_size + block_align; + pool_size = num_blocks * actual_block_size; + + data = alloc_align( backing, pool_size, block_align ); + + // NOTE: Init intrusive freelist + curr = data; + for ( block_index = 0; block_index < num_blocks - 1; block_index++ ) + { + uptr* next = ( uptr* ) curr; + *next = ( uptr ) curr + actual_block_size; + curr = pointer_add( curr, actual_block_size ); + } + + end = ( uptr* ) curr; + *end = ( uptr ) 0; + + pool.PhysicalStart = data; + pool.FreeList = data; + + return pool; +} + + namespace Memory { using namespace zpl; @@ -16,7 +175,7 @@ namespace Memory switch ( type ) { - case EAllocationALLOC: + case EAllocation_ALLOC: { if ( last->total_allocated + size > last->total_size ) { @@ -34,15 +193,15 @@ namespace Memory return alloc_align( arena_allocator( last), size, alignment ); } - case EAllocationFREE: + case EAllocation_FREE: { // Doesn't recycle. } - case EAllocationFREE_ALL: + case EAllocation_FREE_ALL: { // Memory::cleanup instead. } - case EAllocationRESIZE: + case EAllocation_RESIZE: { if ( last->total_allocated + size > last->total_size ) { diff --git a/project/Bloat.hpp b/project/Bloat.hpp index ceb4a05..e2dd1cd 100644 --- a/project/Bloat.hpp +++ b/project/Bloat.hpp @@ -40,6 +40,7 @@ using zpl::sw; using zpl::sptr; using zpl::uptr; +using zpl::AllocType; using zpl::Arena; using zpl::AllocatorInfo; using zpl::ArrayHeader; @@ -48,9 +49,17 @@ using zpl::FileError; using zpl::Pool; // using zpl::String; +using zpl::EAllocation_ALLOC; +using zpl::EAllocation_FREE; +using zpl::EAllocation_FREE_ALL; +using zpl::EAllocation_RESIZE; using zpl::EFileMode_WRITE; using zpl::EFileError_NONE; +using zpl::ZPL_ALLOCATOR_FLAG_CLEAR_TO_ZERO; + +using zpl::align_forward; +using zpl::align_forward_i64; using zpl::alloc; using zpl::alloc_align; using zpl::arena_allocator; @@ -58,7 +67,6 @@ using zpl::arena_init_from_memory; using zpl::arena_init_from_allocator; using zpl::arena_free; using zpl::assert_crash; -using zpl::str_fmt_buf; using zpl::char_first_occurence; using zpl::char_is_alpha; using zpl::char_is_alphanumeric; @@ -67,19 +75,23 @@ using zpl::char_is_hex_digit; using zpl::char_is_space; using zpl::crc32; using zpl::free_all; +using zpl::is_power_of_two; using zpl::mem_copy; using zpl::mem_move; using zpl::mem_set; +using zpl::pointer_add; using zpl::pool_allocator; using zpl::pool_init; using zpl::pool_free; using zpl::process_exit; +using zpl::str_compare; using zpl::str_copy; +using zpl::str_fmt_buf; using zpl::str_fmt_va; using zpl::str_fmt_out_va; using zpl::str_fmt_out_err_va; -using zpl::str_compare; using zpl::str_len; +using zpl::zero_size; #if __clang__ # pragma clang diagnostic pop @@ -141,14 +153,13 @@ using zpl::str_len; #define bit( Value_ ) ( 1 << Value_ ) #define bitfield_is_equal( Type_, Field_, Mask_ ) ( (Type_(Mask_) & Type_(Field_)) == Type_(Mask_) ) #define forceinline ZPL_ALWAYS_INLINE -#define print_nl( _) zpl_printf("\n") #define ccast( Type_, Value_ ) * const_cast< Type_* >( & (Value_) ) #define scast( Type_, Value_ ) static_cast< Type_ >( Value_ ) #define rcast( Type_, Value_ ) reinterpret_cast< Type_ >( Value_ ) #define pcast( Type_, Value_ ) ( * (Type_*)( & (Value_) ) ) -#define txt_impl( ... ) #__VA_ARGS__ -#define txt( ... ) txt_impl( __VA_ARGS__ ) -#define txt_n_len( ... ) sizeof( txt_impl( __VA_ARGS__ ) ), txt_impl( __VA_ARGS__ ) +#define GEN_STRINGIZE_VA( ... ) #__VA_ARGS__ +#define txt( ... ) GEN_STRINGIZE_VA( __VA_ARGS__ ) +#define txt_to_StrC( ... ) sizeof( GEN_STRINGIZE_VA( __VA_ARGS__ ) ), GEN_STRINGIZE_VA( __VA_ARGS__ ) #define do_once() \ do \ { \ @@ -176,10 +187,127 @@ while(0); constexpr char const* Msg_Invalid_Value = "INVALID VALUE PROVIDED"; +#pragma region Memory + +// TODO : Use it. +struct gen_Arena +{ + static + void* allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags ); + + static + gen_Arena init_from_memory( void* start, sw size ) + { + return + { + { nullptr, nullptr }, + start, + size, + 0, + 0 + }; + } + + static + gen_Arena init_from_allocator( AllocatorInfo backing, sw size ) + { + gen_Arena result = + { + backing, + alloc( backing, size), + size, + 0, + 0 + }; + return result; + } + + static + gen_Arena init_sub( gen_Arena& parent, sw size ) + { + return init_from_allocator( parent.Backing, size ); + } + + sw alignment_of( sw alignment ) + { + sw alignment_offset, result_pointer, mask; + ZPL_ASSERT( is_power_of_two( alignment ) ); + + alignment_offset = 0; + result_pointer = (sw) PhysicalStart + TotalUsed; + mask = alignment - 1; + + if ( result_pointer & mask ) + alignment_offset = alignment - ( result_pointer & mask ); + + return alignment_offset; + } + + void check() + { + ZPL_ASSERT( TempCount == 0 ); + } + + void free() + { + if ( Backing.proc ) + { + zpl::free( Backing, PhysicalStart ); + PhysicalStart = nullptr; + } + } + + sw size_remaining( sw alignment ) + { + sw result = TotalSize - ( TotalUsed + alignment_of( alignment ) ); + return result; + } + + AllocatorInfo Backing; + void* PhysicalStart; + sw TotalSize; + sw TotalUsed; + sw TempCount; +}; + +struct gen_Pool +{ + static + void* allocator_proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags ); + + static + gen_Pool init( AllocatorInfo backing, sw num_blocks, sw block_size ) + { + return init_align( backing, num_blocks, block_size, ZPL_DEFAULT_MEMORY_ALIGNMENT ); + } + + static + gen_Pool init_align( AllocatorInfo backing, sw num_blocks, sw block_size, sw block_align ); + + void free() + { + if ( Backing.proc ) + { + zpl::free( Backing, PhysicalStart ); + } + } + + AllocatorInfo Backing; + void* PhysicalStart; + void* FreeList; + sw BlockSize; + sw BlockAlign; + sw TotalSize; + sw NumBlocks; +}; + +#pragma endregion Memory + #pragma region Containers #pragma push_macro("template") #undef template +// TODO : Use it. template struct TArray { @@ -191,13 +319,13 @@ struct TArray }; static - TArray init( AllocatorInfo allocator ) + TArray init( AllocatorInfo allocator ) { return init_reserve( allocator, grow_formula(0) ); } static - TArray init_reserve( AllocatorInfo allocator, sw capacity ) + TArray init_reserve( AllocatorInfo allocator, sw capacity ) { Header* header = rcast( Header*, alloc( allocator, sizeof(Header) + sizeof(Type) )); @@ -369,6 +497,7 @@ struct TArray } }; +// TODO : Use it. template struct THashTable { @@ -387,7 +516,7 @@ struct THashTable }; static - THashTable init( AllocatorInfo allocator ) + THashTable init( AllocatorInfo allocator ) { THashTable result = {0}; @@ -621,9 +750,6 @@ protected: #pragma pop_macro("template") #pragma endregion Containers -#pragma region Memory -#pragma endregion Memory - #pragma region String // Constant string with length. struct StrC diff --git a/project/gen.cpp b/project/gen.cpp index d032417..028a847 100644 --- a/project/gen.cpp +++ b/project/gen.cpp @@ -212,6 +212,8 @@ namespace gen case Namespace_Body: case Operator: case Operator_Fwd: + case Operator_Cast: + case Operator_Cast_Fwd: case Operator_Member: case Operator_Member_Fwd: case Parameters: @@ -397,7 +399,7 @@ namespace gen ); } - result.append_fmt( "%s};\n" + result.append_fmt( "%s};" , body()->to_string() ); } @@ -697,6 +699,14 @@ namespace gen } break; + case Operator_Cast: + result.append_fmt("operator %s(){\n%s\n}", entry(1)->to_string(), body()->to_string() ); + break; + + case Operator_Cast_Fwd: + result.append_fmt("operator %s();", entry(0)->to_string() ); + break; + case Parameters: { result.append_fmt( "%s %s", entry( 0 )->to_string(), Name ); @@ -875,10 +885,12 @@ namespace gen if ( entry(idx)->Type == Specifiers ) { result.append_fmt( "%s %s", Name, entry( idx )->to_string() ); - idx++; + } + else + { + result.append_fmt( "%s", Name ); } - result.append_fmt( "%s", Name ); } else { @@ -1414,11 +1426,11 @@ namespace gen case Assign_Add: case Assign_Subtract: - case Assgin_Multiply: - case Assgin_Divide: - case Assgin_Modulo: - case Assgin_BAnd: - case Assgin_BOr: + case Assign_Multiply: + case Assign_Divide: + case Assign_Modulo: + case Assign_BAnd: + case Assign_BOr: case Assign_BXOr: case Assign_LShift: case Assign_RShift: @@ -1566,7 +1578,7 @@ namespace gen } break; - case LNot: + case UnaryNot: if ( ! params_code ) is_member_symbol = true; @@ -1600,8 +1612,8 @@ namespace gen case LAnd: case LOr: - case Equals: - case NotEquals: + case LEqual: + case LNot: case Lesser: case Greater: case LesserEqual: @@ -2192,6 +2204,40 @@ namespace gen return result; } + Code def_operator_cast( Code type, Code body ) + { + using namespace ECode; + null_check( def_operator_cast, type ); + + if ( type->Type != Typename ) + { + log_failure( "gen::def_operator_cast: type is not a typename - %s", type->debug_str() ); + return Code::Invalid; + } + + Code result = make_code(); + + if (body) + { + result->Type = Operator_Cast; + + if ( body->Type != Function_Body && body->Type != Execution ) + { + log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", body->debug_str() ); + return Code::Invalid; + } + + result->add_entry( body ); + } + else + { + result->Type = Operator_Cast_Fwd; + } + + result->add_entry( type ); + return result; + } + Code def_param( Code type, StrC name, Code value ) { using namespace ECode; @@ -3301,7 +3347,6 @@ namespace gen Array(Token) Arr; s32 Idx; - inline bool __eat( TokType type, char const* context ) { if ( array_count(Arr) - Idx <= 0 ) @@ -3323,17 +3368,20 @@ namespace gen return true; } - inline Token& current() { return Arr[Idx]; } - inline Token& previous() { return Arr[Idx - 1]; } + + Token* next() + { + return Idx + 1 < array_count(Arr) ? &Arr[Idx + 1] : nullptr; + } }; TokArray lex( StrC content ) @@ -3833,6 +3881,7 @@ namespace gen return Code::Invalid; \ } +# define nexttok toks.next() # define currtok toks.current() # define prevtok toks.previous() # define eat( Type_ ) toks.__eat( Type_, context ) @@ -3841,7 +3890,6 @@ namespace gen # define check( Type_ ) ( left && currtok.Type == Type_ ) #pragma endregion Helper Macros - internal Code parse_class_struct_body( Parser::TokArray& toks, char const* context ); internal Code parse_function_body ( Parser::TokArray& toks, char const* context ); internal Code parse_global_nspace ( Parser::TokArray& toks, char const* context ); @@ -3907,7 +3955,7 @@ namespace gen return array_expr; } - return Code::Invalid; + return { nullptr }; } internal inline @@ -3942,14 +3990,21 @@ namespace gen } internal - Code parse_params( Parser::TokArray& toks, char const* context ) + Code parse_params( Parser::TokArray& toks, char const* context, bool use_template_capture = false ) { using namespace Parser; using namespace ECode; - eat( TokType::Capture_Start ); + if ( ! use_template_capture ) + eat( TokType::Capture_Start ); - if ( check(TokType::Capture_End) ) + else + { + if ( check ( TokType::Operator ) && currtok.Text[0] == '<' ) + eat( TokType::Operator ); + } + + if ( ! use_template_capture && check(TokType::Capture_End) ) { eat( TokType::Capture_End ); return { nullptr }; @@ -3996,7 +4051,10 @@ namespace gen if ( value ) result->add_entry( value ); - while ( left && currtok.Type != TokType::Capture_End) + while ( left + && use_template_capture ? + currtok.Type != TokType::Operator && currtok.Text[0] != '>' + : currtok.Type != TokType::Capture_End ) { eat( TokType::Comma ); @@ -4044,7 +4102,18 @@ namespace gen result->add_entry( param ); } - eat( TokType::Capture_End ); + if ( ! use_template_capture ) + eat( TokType::Capture_End ); + + else + { + if ( ! check( TokType::Operator) || currtok.Text[0] != '>' ) + { + log_failure("gen::parse_template: expected '<' after 'template' keyword. %s", str_tok_type( currtok.Type )); + return Code::Invalid; + } + eat( TokType::Operator ); + } return result; # undef context @@ -4123,6 +4192,7 @@ namespace gen Code parse_operator_after_ret_type( ModuleFlag mflags, Code attributes, Code specifiers, Code ret_type, Parser::TokArray& toks, char const* context ) { using namespace Parser; + using namespace EOperator; // Parse Operator eat( TokType::Decl_Operator ); @@ -4133,55 +4203,209 @@ namespace gen return Code::Invalid; } - OperatorT op = OperatorT::Invalid; + OperatorT op = Invalid; switch ( currtok.Text[0] ) { case '+': - case '-': - case '*': - case '/': - case '%': - case '&': - case '|': - case '^': - case '~': - case '!': - case '=': - case '<': - case '>': - case '.': - case ',': - case ':': - case ';': - case '?': - case '@': - case '#': - case '$': - case '`': - case '\'': - case '"': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': { - log_failure( "gen::%s: Invalid operator '%c'", context, currtok.Text[0] ); - return Code::Invalid; - } + if ( currtok.Text[1] == '=' ) + op = Assign_Add; + else + op = Add; + } + break; + case '-': + { + if ( currtok.Text[1] == '=' ) + op = Assign_Subtract; + + else + op = Subtract; + } + break; + case '*': + { + if ( currtok.Text[1] == '=' ) + op = Assign_Multiply; + + else + { + Token& finder = prevtok; + while ( finder.Type != TokType::Decl_Operator ) + { + if ( finder.Type == TokType::Identifier) + { + op = Indirection; + break; + } + } + + if ( op == Invalid) + op = Multiply; + } + } + break; + case '/': + { + if ( currtok.Text[1] == '=' ) + op = Assign_Divide; + + else + op = Divide; + } + break; + case '%': + { + if ( currtok.Text[1] == '=' ) + op = Assign_Modulo; + + else + op = Modulo; + } + break; + case '&': + { + if ( currtok.Text[1] == '=' ) + op = Assign_BAnd; + + else if ( currtok.Text[1] == '&' ) + op = LAnd; + + else + { + + + if ( op == Invalid ) + op = BAnd; + } + } + break; + case '|': + { + if ( currtok.Text[1] == '=' ) + op = Assign_BOr; + + else if ( currtok.Text[1] == '|' ) + op = LOr; + + else + op = BOr; + } + break; + case '^': + { + if ( currtok.Text[1] == '=' ) + op = Assign_BXOr; + + else + op = BXOr; + } + break; + case '~': + { + op = BNot; + } + break; + case '!': + { + if ( currtok.Text[1] == '=' ) + op = LNot; + + else + op = UnaryNot; + } + break; + case '=': + { + if ( currtok.Text[1] == '=' ) + op = LEqual; + + else + op = Assign; + } + break; + case '<': + { + if ( currtok.Text[1] == '=' ) + op = LEqual; + + else if ( currtok.Text[1] == '<' ) + { + if ( currtok.Text[2] == '=' ) + op = Assign_LShift; + + else + op = LShift; + } + else + op = Lesser; + } + break; + case '>': + { + if ( currtok.Text[1] == '=' ) + op = GreaterEqual; + + else if ( currtok.Text[1] == '>' ) + { + if ( currtok.Text[2] == '=' ) + op = Assign_RShift; + + else + op = RShift; + } + else + op = Greater; + } + break; + case '(': + { + if ( currtok.Text[1] == ')' ) + op = FunctionCall; + + else + op = Invalid; + } + break; + case '[': + { + if ( currtok.Text[1] == ']' ) + op = Subscript; + + else + op = Invalid; + } + break; default: { break; } } + if ( op == Invalid ) + { + log_failure( "gen::%s: Invalid operator '%s'", context, currtok.Text ); + return Code::Invalid; + } + + eat( TokType::Operator ); + // Parse Params Code params = parse_params( toks, txt(parse_operator) ); // Parse Body Code body = { nullptr }; + if ( check( TokType::BraceCurly_Open ) ) + { + body = parse_function_body( toks, txt(parse_function) ); + if ( body == Code::Invalid ) + return Code::Invalid; + } + else + { + eat( TokType::Statement_End ); + } // OpValidateResult check_result = operator__validate( op, params, ret_type, specifiers ); Code result = def_operator( op, params, ret_type, body, specifiers, attributes, mflags ); @@ -4238,16 +4462,16 @@ namespace gen result->add_entry( type ); - if (array_expr) + if (array_expr.is_valid() ) type->add_entry( array_expr ); - if ( attributes ) + if ( attributes.is_valid() ) result->add_entry( attributes ); - if (specifiers) + if (specifiers.is_valid() ) result->add_entry( specifiers ); - if ( expr ) + if ( expr.is_valid() ) result->add_entry( expr ); return result; @@ -4306,7 +4530,7 @@ namespace gen StrC name = currtok; eat( TokType::Identifier ); - if ( check( TokType::Operator ) && currtok.Text[0] == '(' ) + if ( check( TokType::Capture_Start) ) { // Dealing with a function @@ -4329,77 +4553,7 @@ namespace gen } internal - Code parse_class_struct( Parser::TokType which, Parser::TokArray& toks, char const* context ) - { - using namespace Parser; - - if ( which != TokType::Decl_Class && which != TokType::Decl_Struct ) - { - log_failure( "%s: Error, expected class or struct, not %s", context, str_tok_type( which ) ); - return Code::Invalid; - } - - Token name { nullptr, 0, TokType::Invalid }; - - Code parent = { nullptr }; - Code body = { nullptr }; - Code attributes = { nullptr }; - ModuleFlag mflags = ModuleFlag::None; - - Code result = Code::Invalid; - - // TODO : Parse module specifiers - - eat( which ); - - // TODO : Parse attributes - - name = parse_identifier( toks, context ); - - AccessSpec access = AccessSpec::Invalid; - Token parent_tok = { nullptr, 0, TokType::Invalid }; - - if ( check( TokType::Assign_Classifer ) ) - { - eat( TokType::Assign_Classifer ); - - if ( tok_is_access_specifier( currtok ) ) - { - access = tok_to_access_specifier( currtok ); - } - - parent_tok = parse_identifier( toks, context ); - } - - if ( check( TokType::BraceCurly_Open ) ) - { - body = parse_class_struct_body( toks, context ); - } - - eat( TokType::Statement_End ); - - if ( parent_tok ) - parent = def_type( parent_tok ); - - if ( which == TokType::Decl_Class ) - result = def_class( name, body, parent, access - // TODO : Set these up later - , NoCode // Attributes - , ModuleFlag::None - ); - - else - result = def_struct( name, body, parent, access - // TODO : Set these up later - , NoCode // Attributes - , ModuleFlag::None - ); - - return result; - } - - internal - Code parse_class_struct_body( Parser::TokArray& toks, char const* context ) + Code parse_class_struct_body( Parser::TokType which, Parser::TokArray& toks, char const* context ) { using namespace Parser; using namespace ECode; @@ -4408,7 +4562,12 @@ namespace gen Code result = make_code(); - result->Type = Class_Body; + + if ( which == TokType::Decl_Class ) + result->Type = Class_Body; + + else + result->Type = Struct_Body; while ( left && currtok.Type != TokType::BraceCurly_Close ) { @@ -4538,9 +4697,6 @@ namespace gen return Code::Invalid; } - if ( spec == ESpecifier::Const ) - continue; - specs_found[num_specifiers] = spec; num_specifiers++; eat( currtok.Type ); @@ -4588,6 +4744,76 @@ namespace gen return result; } + internal + Code parse_class_struct( Parser::TokType which, Parser::TokArray& toks, char const* context ) + { + using namespace Parser; + + if ( which != TokType::Decl_Class && which != TokType::Decl_Struct ) + { + log_failure( "%s: Error, expected class or struct, not %s", context, str_tok_type( which ) ); + return Code::Invalid; + } + + Token name { nullptr, 0, TokType::Invalid }; + + Code parent = { nullptr }; + Code body = { nullptr }; + Code attributes = { nullptr }; + ModuleFlag mflags = ModuleFlag::None; + + Code result = Code::Invalid; + + // TODO : Parse module specifiers + + eat( which ); + + // TODO : Parse attributes + + name = parse_identifier( toks, context ); + + AccessSpec access = AccessSpec::Invalid; + Token parent_tok = { nullptr, 0, TokType::Invalid }; + + if ( check( TokType::Assign_Classifer ) ) + { + eat( TokType::Assign_Classifer ); + + if ( tok_is_access_specifier( currtok ) ) + { + access = tok_to_access_specifier( currtok ); + } + + parent_tok = parse_identifier( toks, context ); + } + + if ( check( TokType::BraceCurly_Open ) ) + { + body = parse_class_struct_body( which, toks, context ); + } + + eat( TokType::Statement_End ); + + if ( parent_tok ) + parent = def_type( parent_tok ); + + if ( which == TokType::Decl_Class ) + result = def_class( name, body, parent, access + // TODO : Set these up later + , NoCode // Attributes + , ModuleFlag::None + ); + + else + result = def_struct( name, body, parent, access + // TODO : Set these up later + , NoCode // Attributes + , ModuleFlag::None + ); + + return result; + } + internal Code parse_function_body( Parser::TokArray& toks, char const* context ) { @@ -4600,122 +4826,29 @@ namespace gen result = make_code(); result->Type = Function_Body; - while ( left && currtok.Type != TokType::BraceCurly_Close ) + Token start = currtok; + + s32 level = 0; + while ( left && currtok.Type != TokType::BraceCurly_Close && level == 0 ) { - Code member = Code::Invalid; - Code attributes = { nullptr }; - Code specifiers = { nullptr }; + if ( currtok.Type == TokType::BraceCurly_Open ) + level++; - bool expects_function = false; - - switch ( currtok.Type ) - { - case TokType::Comment: - member = def_comment( currtok ); - eat( TokType::Comment ); - break; - - case TokType::Decl_Class: - member = parse_class( toks, context ); - break; - - case TokType::Decl_Enum: - member = parse_enum( toks, context ); - break; - - case TokType::Decl_Struct: - member = parse_struct( toks, context ); - break; - - case TokType::Decl_Typedef: - member = parse_typedef( toks, context ); - break; - - case TokType::Decl_Union: - member = parse_union( toks, context ); - break; - - case TokType::Decl_Using: - member = parse_using( toks, context ); - break; - - case TokType::Spec_Constexpr: - case TokType::Spec_Constinit: - case TokType::Spec_Mutable: - case TokType::Spec_Static: - case TokType::Spec_ThreadLocal: - case TokType::Spec_Volatile: - { - SpecifierT specs_found[16] { ESpecifier::Num_Specifiers }; - s32 num_specifiers = 0; - - while ( left && tok_is_specifier( currtok ) ) - { - SpecifierT spec = ESpecifier::to_type( currtok ); - - switch ( spec ) - { - case ESpecifier::Constexpr: - case ESpecifier::Constinit: - case ESpecifier::Mutable: - case ESpecifier::Static_Member: - case ESpecifier::Thread_Local: - case ESpecifier::Volatile: - break; - - case ESpecifier::Consteval: - expects_function = true; - break; - - default: - log_failure( "gen::parse_class_struct_body: invalid specifier " txt(spec) " for variable" ); - return Code::Invalid; - } - - if ( spec == ESpecifier::Const ) - continue; - - specs_found[num_specifiers] = spec; - num_specifiers++; - eat( currtok.Type ); - } - - if ( num_specifiers ) - { - specifiers = def_specifiers( num_specifiers, specs_found ); - } - } - //! Fallthrough intentional - case TokType::Identifier: - case TokType::Spec_Const: - case TokType::Type_Unsigned: - case TokType::Type_Signed: - case TokType::Type_Short: - case TokType::Type_Long: - member = parse_variable( toks, context ); - break; - - default: - Token untyped_tok = currtok; - - while ( left && currtok.Type != TokType::Statement_End ) - { - untyped_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)untyped_tok.Text; - eat( currtok.Type ); - } - - Code member = untyped_str( untyped_tok ); - break; - } - - if ( member == Code::Invalid ) - return Code::Invalid; - - result->add_entry( member ); + else if ( currtok.Type == TokType::BraceCurly_Close && level > 0 ) + level--; eat( currtok.Type ); } + Token previous = prevtok; + + s32 len = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)start.Text; + + if ( len > 0 ) + { + result->add_entry( def_execution( { len, start.Text } )); + } + eat( TokType::BraceCurly_Close ); return result; } @@ -4870,9 +5003,6 @@ namespace gen return Code::Invalid; } - if ( spec == ESpecifier::Const ) - continue; - specs_found[num_specifiers] = spec; num_specifiers++; eat( currtok.Type ); @@ -5179,10 +5309,8 @@ namespace gen SpecifierT specs_found[16] { ESpecifier::Num_Specifiers }; s32 num_specifiers = 0; - Code lang_linkage = { nullptr }; - Code attributes = { nullptr }; - Code array_expr = { nullptr }; - Code specifiers = { nullptr }; + Code attributes = { nullptr }; + Code specifiers = { nullptr }; // TODO : Parse module specifiers @@ -5194,13 +5322,12 @@ namespace gen switch ( spec ) { + case ESpecifier::Const: + case ESpecifier::Consteval: case ESpecifier::Constexpr: case ESpecifier::External_Linkage: - case ESpecifier::Local_Persist: - case ESpecifier::Mutable: + case ESpecifier::Inline: case ESpecifier::Static_Member: - case ESpecifier::Thread_Local: - case ESpecifier::Volatile: break; default: @@ -5208,21 +5335,6 @@ namespace gen return Code::Invalid; } - if ( spec == ESpecifier::External_Linkage ) - { - specs_found[num_specifiers] = spec; - num_specifiers++; - eat( TokType::Spec_Extern ); - - if ( currtok.Type == TokType::String ) - { - lang_linkage = untyped_str( currtok ); - eat( TokType::String ); - } - - continue; - } - specs_found[num_specifiers] = spec; num_specifiers++; eat( currtok.Type ); @@ -5308,14 +5420,43 @@ namespace gen internal Code parse_operator( Parser::TokArray& toks, char const* context ) { - // Parse Module specifier + // TODO : Parse Module specifier - // Parse Attributes + // TODO : Parse Attributes Code attributes = { nullptr }; - // Parse Speciifers Code specifiers = { nullptr }; + SpecifierT specs_found[16] { ESpecifier::Num_Specifiers }; + s32 num_specifiers = 0; + + while ( left && tok_is_specifier( currtok ) ) + { + SpecifierT spec = ESpecifier::to_type( currtok ); + + switch ( spec ) + { + case ESpecifier::Const: + case ESpecifier::Constexpr: + case ESpecifier::Inline: + case ESpecifier::Static_Member: + break; + + default: + log_failure( "gen::parse_variable: invalid specifier " txt(spec) " for variable" ); + return Code::Invalid; + } + + specs_found[num_specifiers] = spec; + num_specifiers++; + eat( currtok.Type ); + } + + if ( num_specifiers ) + { + specifiers = def_specifiers( num_specifiers, specs_found ); + } + // Parse Return Type Code ret_type = parse_type( toks, txt(parse_operator) ); @@ -5335,6 +5476,63 @@ namespace gen return parse_operator( toks, txt(parse_operator) ); } + Code parse_operator_cast( Parser::TokArray& toks, char const* context ) + { + using namespace Parser; + + eat( TokType::Decl_Operator ); + + Code type = parse_type( toks, txt(parse_operator_cast) ); + + eat( TokType::Capture_Start ); + eat( TokType::Capture_End ); + + Code body = { nullptr }; + + if ( check( TokType::BraceCurly_Open) ) + { + eat( TokType::BraceCurly_Open ); + + Token body_str = currtok; + + while ( ! check( TokType::BraceCurly_Close ) ) + { + eat( currtok.Type ); + } + + body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text; + + body = untyped_str( body_str ); + } + + Code result = make_code(); + + if (body) + { + result->Type = ECode::Operator_Cast; + result->add_entry( body ); + } + else + { + result->Type = ECode::Operator_Cast_Fwd; + result->add_entry( type ); + } + + return result; + } + + Code parse_operator_cast( StrC def ) + { + check_parse_args( parse_operator_cast, def ); + using namespace Parser; + + TokArray toks = lex( def ); + if ( toks.Arr == nullptr ) + return Code::Invalid; + + return parse_operator_cast( toks, txt(parse_operator_cast) ); + } + internal inline Code parse_struct( Parser::TokArray& toks, char const* context ) { @@ -5356,31 +5554,19 @@ namespace gen internal Code parse_template( Parser::TokArray& toks, char const* context ) { + # define UseTemplateCapture true + using namespace Parser; // TODO : Parse Module specifier eat( TokType::Template ); - if ( ! check( TokType::Operator) || currtok.Text[0] != '<' ) - { - log_failure("gen::parse_template: expected '<' after 'template' keyword. %s", str_tok_type( currtok.Type )); - return Code::Invalid; - } - eat( TokType::Operator ); - - Code params = parse_params( toks, txt(parse_template) ); + Code params = parse_params( toks, txt(parse_template), UseTemplateCapture ); if ( params == Code::Invalid ) return Code::Invalid; - if ( ! check( TokType::Operator) || currtok.Text[0] != '>' ) - { - log_failure("gen::parse_template: expected '<' after 'template' keyword. %s", str_tok_type( currtok.Type )); - return Code::Invalid; - } - eat( TokType::Operator ); - - Code definition = Code::Invalid; + Code definition = { nullptr }; while ( left ) { @@ -5406,8 +5592,8 @@ namespace gen Token name = { nullptr, 0, TokType::Invalid }; - Code attributes = Code::Invalid; - Code specifiers = Code::Invalid; + Code attributes = { nullptr }; + Code specifiers = { nullptr }; // TODO : Parse attributes @@ -5459,6 +5645,7 @@ namespace gen } definition = parse_operator_function_or_variable( expects_function, attributes, specifiers, toks, txt(parse_template) ); + break; } Code @@ -5467,7 +5654,8 @@ namespace gen result->add_entry( definition ); result->add_entry( params ); - return Code::Invalid; + return result; + # undef UseTemplateCapture } Code parse_template( StrC def ) @@ -5561,7 +5749,7 @@ namespace gen Token func_sig = { nullptr, 0, TokType::Invalid }; - if ( check( TokType::Capture_Start ) ) + if ( check( TokType::Capture_Start ) && prevtok.Type == TokType::Capture_End ) { // Its a function type @@ -5616,6 +5804,7 @@ namespace gen if (num_specifiers) { Code specifiers = def_specifiers( num_specifiers, (SpecifierT*)specs_found ); + result->add_entry( specifiers ); } } @@ -5700,7 +5889,7 @@ namespace gen eat( TokType::Decl_Union ); - // Parse attributes + // TODO : Parse attributes Code attributes = { nullptr }; StrC name = { 0, nullptr }; @@ -5713,24 +5902,20 @@ namespace gen Code body = { nullptr }; - if ( check( TokType::BraceCurly_Open ) ) + eat( TokType::BraceCurly_Open ); + + body = make_code(); + body->Type = ECode::Union_Body; + + while ( ! check( TokType::BraceCurly_Close ) ) { - eat( TokType::BraceCurly_Open ); + Code entry = parse_variable( toks, txt(parse_union) ); - body = make_code(); - body->Type = ECode::Union_Body; - - while ( ! check( TokType::BraceCurly_Close ) ) - { - Code entry = parse_variable( toks, txt(parse_union) ); - - if ( entry ) - body->add_entry( entry ); - } - - eat( TokType::BraceCurly_Close ); + if ( entry ) + body->add_entry( entry ); } + eat( TokType::BraceCurly_Close ); eat( TokType::Statement_End ); Code @@ -5758,7 +5943,7 @@ namespace gen if ( toks.Arr == nullptr ) return Code::Invalid; - return parse_typedef( toks, txt(parse_union) ); + return parse_union( toks, txt(parse_union) ); } internal @@ -5805,12 +5990,13 @@ namespace gen Code result = make_code(); - result->Type = is_namespace ? Using : Using_Namespace; + result->Type = is_namespace ? Using_Namespace : Using; result->Name = get_cached_string( name ); - result->add_entry( type ); + if ( type.is_valid() ) + result->add_entry( type ); - if ( array_expr ) + if ( array_expr.is_valid() ) type->add_entry( array_expr ); return result; diff --git a/project/gen.hpp b/project/gen.hpp index bc34a7c..6743b52 100644 --- a/project/gen.hpp +++ b/project/gen.hpp @@ -65,6 +65,8 @@ namespace gen Entry( Operator_Fwd ) \ Entry( Operator_Member ) \ Entry( Operator_Member_Fwd ) \ + Entry( Operator_Cast ) \ + Entry( Operator_Cast_Fwd ) \ Entry( Parameters ) \ Entry( Preprocessor_Include ) \ Entry( Specifiers ) \ @@ -95,7 +97,7 @@ namespace gen { static StrC lookup[Num_Types] = { - # define Entry( Type ) { txt_n_len( Type ) }, + # define Entry( Type ) { txt_to_StrC( Type ) }, Define_Types # undef Entry }; @@ -132,11 +134,11 @@ namespace gen Entry( Assign, = ) \ Entry( Assign_Add, += ) \ Entry( Assign_Subtract, -= ) \ - Entry( Assgin_Multiply, *= ) \ - Entry( Assgin_Divide, /= ) \ - Entry( Assgin_Modulo, %= ) \ - Entry( Assgin_BAnd, &= ) \ - Entry( Assgin_BOr, |= ) \ + Entry( Assign_Multiply, *= ) \ + Entry( Assign_Divide, /= ) \ + Entry( Assign_Modulo, %= ) \ + Entry( Assign_BAnd, &= ) \ + Entry( Assign_BOr, |= ) \ Entry( Assign_BXOr, ^= ) \ Entry( Assign_LShift, <<= ) \ Entry( Assign_RShift, >>= ) \ @@ -144,6 +146,7 @@ namespace gen Entry( Decrement, -- ) \ Entry( Unary_Plus, + ) \ Entry( Unary_Minus, - ) \ + Entry( UnaryNot, ! ) \ Entry( Add, + ) \ Entry( Subtract, - ) \ Entry( Multiply, * ) \ @@ -155,11 +158,10 @@ namespace gen Entry( BXOr, ^ ) \ Entry( LShift, << ) \ Entry( RShift, >> ) \ - Entry( LNot, ! ) \ Entry( LAnd, && ) \ Entry( LOr, || ) \ - Entry( Equals, == ) \ - Entry( NotEquals, != ) \ + Entry( LEqual, == ) \ + Entry( LNot, != ) \ Entry( Lesser, < ) \ Entry( Greater, > ) \ Entry( LesserEqual, <= ) \ @@ -250,7 +252,7 @@ namespace gen # define internal internal # define local_persist local_persist - # define Entry( Spec_, Code_ ) { txt_n_len(Code_) }, + # define Entry( Spec_, Code_ ) { txt_to_StrC(Code_) }, Define_Specifiers # undef Entry @@ -272,7 +274,9 @@ namespace gen { StrC enum_str = to_str( (Type)index ); - keymap[index] = crc32( enum_str.Ptr, enum_str.Len); + // We subtract 1 to remove the null terminator + // This is because the tokens lexed are not null terminated. + keymap[index] = crc32( enum_str.Ptr, enum_str.Len - 1); } do_once_end @@ -398,7 +402,6 @@ namespace gen # pragma region Member Functions void add_entry( AST* other ); - inline AST* body() { return entry( 0 ); @@ -411,22 +414,18 @@ namespace gen return DynamicEntries ? ArrDyn[ idx ] : ArrStatic[ idx ]; } - inline bool has_entries() { return num_entries(); } - inline bool is_invalid() { return Type != ECode::Invalid; } - inline bool is_equal( AST* other ); - inline s32 num_entries() { return DynamicEntries ? array_count( ArrDyn ) : StaticIndex; @@ -434,7 +433,6 @@ namespace gen // Parameter - inline AST* get_param( s32 index ) { if ( index <= 0 ) @@ -443,14 +441,12 @@ namespace gen return entry( index + 1 ); } - inline s32 param_count() { // The first entry (which holds the type) represents the first parameter. return num_entries(); } - inline AST* param_type() { return entry( 0 ); @@ -458,7 +454,6 @@ namespace gen // Specifiers - inline bool add_specifier( SpecifierT spec ) { if ( StaticIndex == AST::ArrSpecs_Cap ) @@ -472,7 +467,6 @@ namespace gen return true; } - inline s32 has_specifier( SpecifierT spec ) { for ( s32 idx = 0; idx < StaticIndex; idx++ ) @@ -486,21 +480,18 @@ namespace gen // Typename - inline bool typename_is_ptr() { assert_crash("not implemented"); return false; } - inline bool typename_is_ref() { assert_crash("not implemented"); return false; } - inline AST* typename_specifiers() { return entry( 0 ); @@ -508,7 +499,6 @@ namespace gen // Serialization - inline char const* debug_str() { char const* fmt = txt( @@ -530,7 +520,6 @@ namespace gen ); } - inline char const* type_str() { return ECode::to_str( Type ); @@ -582,9 +571,6 @@ namespace gen # undef Using_CodePOD }; - constexpr sw size_AST = sizeof(AST); - constexpr sw size_POD = sizeof(AST_POD); - // Its intended for the AST to have equivalent size to its POD. // All extra functionality within the AST namespace should just be syntatic sugar. static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" ); @@ -604,7 +590,6 @@ namespace gen # pragma endregion Statics # pragma region Member Functions - inline Code body() { if ( ast == nullptr ) @@ -622,13 +607,11 @@ namespace gen return { ast->body() }; } - inline String to_string() const { return ast->to_string(); } - inline void set_global() { if ( ast == nullptr ) @@ -640,45 +623,34 @@ namespace gen ast->Parent = Global.ast; } - inline - operator bool() const + bool is_valid() { - return ast; + // Originally intended to use operator bool(), however for some reason + // The C++ standard has operator Type*() with higher precedence than operator bool(). + // Even when directly casting to bool. Amazing. + return ast != nullptr && ast->Type != ECode::Invalid; + } + + operator bool() const + { + return ast != nullptr && ast->Type != ECode::Invalid; } - inline bool operator ==( Code other ) { return ast == other.ast; } - inline bool operator !=( Code other ) { return ast != other.ast; } - inline operator AST*() { return ast; } - inline - Code& operator=( Code other ) - { - if ( other.ast == nullptr ) - { - log_failure("Attempted to assign a nullptr!"); - return *this; - } - - ast = other.ast; - - return *this; - } - - inline AST* operator->() { if ( ast == nullptr ) @@ -732,12 +704,12 @@ namespace gen // Set these before calling gen's init() procedure. // Data - void set_allocator_data_arrays ( AllocatorInfo data_array_allocator ); - void set_allocator_code_pool ( AllocatorInfo pool_allocator ); - void set_allocator_code_enries_arena( AllocatorInfo pool_allocator ); - void set_allocator_string_arena ( AllocatorInfo string_allocator ); - void set_allocator_string_table ( AllocatorInfo string_allocator ); - void set_allocator_type_table ( AllocatorInfo type_reg_allocator ); + void set_allocator_data_arrays ( AllocatorInfo data_array_allocator ); + void set_allocator_code_pool ( AllocatorInfo pool_allocator ); + void set_allocator_code_enrties_arena( AllocatorInfo pool_allocator ); + void set_allocator_string_arena ( AllocatorInfo string_allocator ); + void set_allocator_string_table ( AllocatorInfo string_allocator ); + void set_allocator_type_table ( AllocatorInfo type_reg_allocator ); # pragma region Upfront Code def_attributes( StrC content ); @@ -772,6 +744,8 @@ namespace gen , Code specifiers = NoCode, Code attributes = NoCode , ModuleFlag mflags = ModuleFlag::None ); + Code def_operator_cast( Code type, Code body = NoCode ); + Code def_param ( Code type, StrC name, Code value = NoCode ); Code def_specifier( SpecifierT specifier ); @@ -824,22 +798,23 @@ namespace gen # pragma region Parsing # ifdef GEN_FEATURE_PARSING - Code parse_class ( StrC class_def ); - Code parse_enum ( StrC enum_def ); - Code parse_export_body ( StrC export_def ); - Code parse_extern_link ( StrC exten_link_def); - Code parse_friend ( StrC friend_def ); - Code parse_function ( StrC fn_def ); - Code parse_global_body ( StrC body_def ); - Code parse_namespace ( StrC namespace_def ); - Code parse_operator ( StrC operator_def ); - Code parse_struct ( StrC struct_def ); - Code parse_template ( StrC template_def ); - Code parse_type ( StrC type_def ); - Code parse_typedef ( StrC typedef_def ); - Code parse_union ( StrC union_def ); - Code parse_using ( StrC using_def ); - Code parse_variable ( StrC var_def ); + Code parse_class ( StrC class_def ); + Code parse_enum ( StrC enum_def ); + Code parse_export_body ( StrC export_def ); + Code parse_extern_link ( StrC exten_link_def); + Code parse_friend ( StrC friend_def ); + Code parse_function ( StrC fn_def ); + Code parse_global_body ( StrC body_def ); + Code parse_namespace ( StrC namespace_def ); + Code parse_operator ( StrC operator_def ); + Code parse_operator_cast( StrC operator_def ); + Code parse_struct ( StrC struct_def ); + Code parse_template ( StrC template_def ); + Code parse_type ( StrC type_def ); + Code parse_typedef ( StrC typedef_def ); + Code parse_union ( StrC union_def ); + Code parse_using ( StrC using_def ); + Code parse_variable ( StrC var_def ); # endif # pragma endregion Parsing @@ -994,10 +969,10 @@ namespace gen // Convienence for defining any name used with the gen api. // Lets you provide the length and string literal to the functions without the need for the DSL. -# define name( Id_ ) { txt_n_len( Id_ ) } +# define name( Id_ ) { txt_to_StrC( Id_ ) } // Same as name just used to indicate intention of literal for code instead of names. -# define code( ... ) { txt_n_len( __VA_ARGS__ ) } +# define code( ... ) { txt_to_StrC( __VA_ARGS__ ) } #pragma endregion Macros #pragma region Constants diff --git a/project/gen.undef.macros.hpp b/project/gen.undef.macros.hpp new file mode 100644 index 0000000..c6b8400 --- /dev/null +++ b/project/gen.undef.macros.hpp @@ -0,0 +1,28 @@ +#if gen_time +// This undefines the macros used by the gen library but are not necessary for the user. +// TODO : This is incomplete until all dependencies are brough in from ZPL into bloat. + +#undef bit +#undef bitfield_is_equal +#undef ccast +#undef scast +#undef rcast +#undef pcast +#undef do_once +#undef do_once_start +#undef do_once_end + +#undef kilobytes +#undef megabytes +#undef gigabytes +#undef terabytes + +#undef global +#undef internal +#undef local_persist +#undef forceinline + +#undef txt + +// gen_time +#endif diff --git a/scripts/gencpp.refactor b/scripts/gencpp.refactor new file mode 100644 index 0000000..2a0aba4 --- /dev/null +++ b/scripts/gencpp.refactor @@ -0,0 +1,230 @@ + __VERSION 1 + +// This is a example template to be used with the refactor program +// Use it to refactor the naming convention of this library to your own. +// Can be used as an aid to help use use your project's implementation if it fullfills the dependencies of this project. +// Example: Most likely have a memory and string library already, just rename the functions and make sure the args are the same. +// Program: https://github.com/Ed94/refactor + +// NOTE: Due to the current limitations of the program, not every symbol in the library can be renamed. +// This is due to the program not actually parsing C/C++. + +// not : Ignore +// include : #includes +// word : Alphanumeric or underscore +// namespace : Prefix search and replace (c-namspaces). +// regex : Unavailable in __VERSION 1. + +// Precedence (highest to lowest): +// word, namespace, regex + +// Basic Types + +// word b32 new_name +// word s8 new_name +// word s64 new_name +// word u8 new_name +// word u32 new_name +// word u64 new_name +// word uw new_name +// word sw new_name +// word sptr new_name +// word uptr new_name + +// ZPL Derived + +// namespace EAllocator_ new_namespace_ +// namespace EFileMode_ new_namespace_ +// namespace EFileError_ new_namespace_ + +// word Arena new_name +// word AllocatorInfo new_name +// word ArrayHeader new_name +// word FileInfo new_name +// word FileError new_name +// word Pool new_name + +// word Array new_name +// word HashTable new_name + +// word alloc new_name +// word alloc_align new_name +// word assert_crash new_name +// word char_first_occurence new_name +// word char_is_alpha new_name +// word char_is_alphanumeric new_name +// word char_is_digit new_name +// word char_is_hex_digit new_name +// word char_is_space new_name +// word crc32 new_name +// word free_all new_name +// word mem_copy new_name +// word mem_move new_name +// word mem_set new_name +// word process_exit new_name +// word str_compare new_name +// word str_copy new_name +// word str_fmt_buf new_name +// word str_fmt_va new_name +// word str_fmt_out_va new_name +// word str_fmt_out_err_va new_name +// word str_len new_name + +// generic API + +// word to_str new_name +// word to_type new_name + +// gencpp Types & Constants + +// word LogFailType new_name +// word log_failure new_name + +// word ECode new_name +// word EnumT new_name +// word EnumClass new_name +// word EnumRegular new_name +// word UsingT new_name +// word UsingRegular new_name +// word UsingNamespace new_name +// word EOperator new_name +// word OperatorT new_name +// word ESpecifier new_name +// word SpecifierT new_name +// word AccessSpec new_name +// word ModuleFlag new_name + +// word API_Export new_name +// word API_Import new_name +// word Keyword new_name + +// gencpp Data + +// word StringTable new_name +// word StringCached new_name +// word AST_POD_Size new_name +// word AST new_name +// word AST_POD new_name +// word Code new_name +// word Code_POD new_name +// word NoCode new_name + +// gencpp API + +// word init new_name +// word deinit new_name + +// word get_cached_string new_name +// word make_code new_name +// word make_code_entries new_name + +// word set_allocator_data_arrays new_name +// word set_allocator_code_pool new_name +// word set_allocator_code_entries_arena new_name +// word set_allocator_string_arena new_name +// word set_allocator_string_table new_name +// word set_allocator_type_table new_name + +// upfront constructor namespace +// namespace def_ new_namespace_ + +// upfront constructor individual + +// word def_attributes new_name +// word def_comment new_name +// word def_class new_name +// word def_enum new_name +// word def_execution new_name +// word def_extern_link new_name +// word def_friend new_name +// word def_function new_name +// word def_include new_name +// word def_module new_name +// word def_namespace new_name +// word def_operator new_name +// word def_param new_name +// word def_specifier new_name +// word def_struct new_name +// word def_template new_name +// word def_type new_name +// word def_typedef new_name +// word def_union new_name +// word def_using new_name +// word def_using_namespace new_name +// word def_variable new_name + +// word def_class_body new_name +// word def_class_body new_name +// word def_enum_body new_name +// word def_enum_body new_name +// word def_export_body new_name +// word def_export_body new_name +// word def_extern_link_body new_name +// word def_extern_link_body new_name +// word def_function_body new_name +// word def_function_body new_name +// word def_global_body new_name +// word def_global_body new_name +// word def_namespace_body new_name +// word def_namespace_body new_name +// word def_params new_name +// word def_params new_name +// word def_specifiers new_name +// word def_specifiers new_name +// word def_struct_body new_name +// word def_struct_body new_name +// word def_union_body new_name +// word def_union_body new_name + +// parse constructor namespace +// namespace parse_ new_namespace_ + +// parse constructor individual + +// word parse_class new_name +// word parse_enum new_name +// word parse_export_body new_name +// word parse_extern_link new_name +// word parse_friend new_name +// word parse_function new_name +// word parse_global_body new_name +// word parse_namespace new_name +// word parse_operator new_name +// word parse_struct new_name +// word parse_template new_name +// word parse_type new_name +// word parse_typedef new_name +// word parse_union new_name +// word parse_using new_name +// word parse_variable new_name + +// untyped constructor namespace +// namespace untyped_ new_namespace_ + +// untyped constructor individual + +// word token_fmt_va new_name +// word token_fmt new_name +// word untyped_str new_name +// word untyped_fmt new_name +// word untyped_token_fmt new_name + +// File Handling + +// word Builder new_name +// word Editor new_name +// word Scanner new_name + +// gencpp macros + +// word __ new_name +// word code new_name +// word name new_name +// word txt new_name +// word txt_to_StrC new_name + +// Type AST namespace +// namespace t_ new_namespace_ + +// Specifier AST namespace +// namespace spec_ new_namespace_ diff --git a/test/NonParsed/Array.NonParsed.hpp b/test/NonParsed/Array.NonParsed.hpp index b5d448b..263de16 100644 --- a/test/NonParsed/Array.NonParsed.hpp +++ b/test/NonParsed/Array.NonParsed.hpp @@ -258,12 +258,9 @@ Code gen__array( StrC type, sw type_size ) set_capacity = def_function( name(set_capacity), def_param( t_uw, name(new_capacity)), t_bool, body ); } - Code op_ptr = untyped_str( code( - operator Type*() - { - return Data; - } - )); + Code op_ptr = def_operator_cast( t_type_ptr, def_execution( code( + return Data; + ))); Code body = def_struct_body( 20 , using_header @@ -327,7 +324,7 @@ void gen__array_request( StrC type, sw size, StrC dep = {} ) GenArrayRequest request = { dep, type, size }; array_append( GenArrayRequests, request ); } -#define gen_array( type ) gen__array_request( { txt_n_len(type) }, sizeof(type) ) +#define gen_array( type ) gen__array_request( { txt_to_StrC(type) }, sizeof(type) ) u32 gen_array_file() { diff --git a/test/NonParsed/Buffer.NonParsed.hpp b/test/NonParsed/Buffer.NonParsed.hpp index 5af1944..172c821 100644 --- a/test/NonParsed/Buffer.NonParsed.hpp +++ b/test/NonParsed/Buffer.NonParsed.hpp @@ -172,12 +172,9 @@ Code gen__buffer( StrC type, sw type_size ) )) ); - Code op_type_ptr = untyped_str( code( - operator Type*() - { - return Data; - } - )); + Code op_type_ptr = def_operator_cast( t_type_ptr, def_execution( code( + return Data; + ))); buffer = def_struct( name, def_struct_body( 14 , using_header @@ -232,7 +229,7 @@ void gen__buffer_request( StrC type, sw size, StrC dep = {} ) GenBufferRequest request = { dep, type, size}; array_append( GenBufferRequests, request ); } -#define gen_buffer( type ) gen__buffer_request( { txt_n_len(type) }, sizeof( type )) +#define gen_buffer( type ) gen__buffer_request( { txt_to_StrC(type) }, sizeof( type )) u32 gen_buffer_file() { diff --git a/test/NonParsed/HashTable.NonParsed.hpp b/test/NonParsed/HashTable.NonParsed.hpp index 4dfc79b..63f849c 100644 --- a/test/NonParsed/HashTable.NonParsed.hpp +++ b/test/NonParsed/HashTable.NonParsed.hpp @@ -425,7 +425,7 @@ void gen__hashtable_request( StrC type, sw size, StrC dep = {} ) GenHashTableRequest request = { dep, type, size}; array_append( GenHashTableRequests, request ); } -#define gen_hashtable( type ) gen__hashtable_request( { txt_n_len(type) }, sizeof( type )) +#define gen_hashtable( type ) gen__hashtable_request( { txt_to_StrC(type) }, sizeof( type )) u32 gen_hashtable_file() { diff --git a/test/NonParsed/Ring.NonParsed.hpp b/test/NonParsed/Ring.NonParsed.hpp index e209927..737c036 100644 --- a/test/NonParsed/Ring.NonParsed.hpp +++ b/test/NonParsed/Ring.NonParsed.hpp @@ -188,7 +188,7 @@ void gen__ring_request( StrC type, sw size, StrC dep = {} ) GenRingRequest request = { dep, type, size}; array_append( GenRingRequests, request ); } -#define gen_ring( type ) gen__ring_request( { txt_n_len(type) }, sizeof( type )) +#define gen_ring( type ) gen__ring_request( { txt_to_StrC(type) }, sizeof( type )) u32 gen_ring_file() { diff --git a/test/NonParsed/Sanity.NonParsed.hpp b/test/NonParsed/Sanity.NonParsed.hpp index 9c909f9..2a85db3 100644 --- a/test/NonParsed/Sanity.NonParsed.hpp +++ b/test/NonParsed/Sanity.NonParsed.hpp @@ -190,6 +190,19 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); + // Operator cast + { + Code t_u8_ptr = def_type( name(u8), __, spec_ptr ); + + Code op_ptr = def_operator_cast( t_u8_ptr, __ ); + + Code op_class = def_class( name(TestOperatorCast), def_class_body( 1, op_ptr ) ); + + gen_sanity_file.print(op_class); + } + + gen_sanity_file.print_fmt("\n"); + // Parameters { Code fwd; @@ -295,6 +308,21 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); + // Template + { + Code t_Type = def_type( name(Type) ); + + Code tmpl = def_template( def_param( t_class, name(Type) ) + , def_function( name(test_template), def_param( t_Type, name(a) ), __ + , def_function_body(1, def_comment( StrC::from("Empty template function body"))) + ) + ); + + gen_sanity_file.print(tmpl); + } + + gen_sanity_file.print_fmt("\n"); + gen_sanity_file.print( def_comment( StrC::from( "End of base case tests.\n" ))); diff --git a/test/Parsed/Array.Parsed.hpp b/test/Parsed/Array.Parsed.hpp index 3ac0584..c828928 100644 --- a/test/Parsed/Array.Parsed.hpp +++ b/test/Parsed/Array.Parsed.hpp @@ -251,7 +251,7 @@ void gen__array_request( StrC type, sw size, StrC dep = {} ) GenArrayRequest request = { dep, type, size }; array_append( GenArrayRequests, request ); } -#define gen_array( type ) gen__array_request( { txt_n_len(type) }, sizeof(type) ) +#define gen_array( type ) gen__array_request( { txt_to_StrC(type) }, sizeof(type) ) u32 gen_array_file() { diff --git a/test/Parsed/Sanity.Parsed.hpp b/test/Parsed/Sanity.Parsed.hpp index 49f0596..9ecd11b 100644 --- a/test/Parsed/Sanity.Parsed.hpp +++ b/test/Parsed/Sanity.Parsed.hpp @@ -142,7 +142,6 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); // Operator - if (0) { Code bitflagtest = parse_enum( code( enum class EBitFlagTest : u8 @@ -171,6 +170,25 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); + // Operator cast + { + Code op_ptr = parse_operator_cast( code( + operator u8* (); + )); + + Code class_def = parse_class( code( + class TestClass + { + }; + )); + + class_def.body()->add_entry( op_ptr ); + + gen_sanity_file.print(class_def); + } + + gen_sanity_file.print_fmt("\n"); + // Parameters { Code fwd = parse_function( code( @@ -209,7 +227,6 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); // Struct - if (0) { Code fwd = parse_struct( code( struct TestEmptyStruct; @@ -229,7 +246,6 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); // Union - if (0) { Code empty = parse_union( code( union TestEmptyUnion @@ -239,10 +255,13 @@ u32 gen_sanity() empty.body()->add_entry( def_comment( StrC::from("Empty union body") ) ); + gen_sanity_file.print( parse_typedef( code( typedef unsigned short u16; )) ); + gen_sanity_file.print( parse_typedef( code( typedef unsigned long u32; )) ); + Code def = parse_union( code( union TestUnion { - u8 a; + u8 a; u16 b; u32 c; }; @@ -255,28 +274,30 @@ u32 gen_sanity() gen_sanity_file.print_fmt("\n"); // Using - if (0) { Code reg = parse_using( code( using TestUsing = u8; )); - Code nspace = parse_using( code( + Code nspace = parse_namespace( code( namespace TestNamespace { }; - using namespace TestUsing; + )); + + Code npspace_using = parse_using( code( + using namespace TestNamespace; )); gen_sanity_file.print(reg); gen_sanity_file.print(nspace); + gen_sanity_file.print(npspace_using); } gen_sanity_file.print_fmt("\n"); // Variable - if (0) { Code bss = parse_variable( code( u8 test_variable; @@ -285,6 +306,26 @@ u32 gen_sanity() Code data = parse_variable( code( u8 test_variable = 0x12; )); + + gen_sanity_file.print(bss); + gen_sanity_file.print(data); + } + + gen_sanity_file.print_fmt("\n"); + + // template + { + #pragma push_macro("template") + #undef template + Code tmpl = parse_template( code( + template< typename Type > + void test_template( Type a ) + { + } + )); + #pragma pop_macro("template") + + gen_sanity_file.print(tmpl); } gen_sanity_file.print_fmt("\n"); diff --git a/test/test.NonParsed.cpp b/test/test.NonParsed.cpp index 32a2da0..99740ce 100644 --- a/test/test.NonParsed.cpp +++ b/test/test.NonParsed.cpp @@ -17,7 +17,7 @@ int gen_main() Memory::setup(); gen::init(); - // gen_sanity(); + gen_sanity(); gen_array( u8 ); // gen_array( sw ); diff --git a/thirdparty/zpl.h b/thirdparty/zpl.h index 71e5853..59bbb1f 100644 --- a/thirdparty/zpl.h +++ b/thirdparty/zpl.h @@ -3141,10 +3141,10 @@ ZPL_BEGIN_C_DECLS typedef enum AllocType { - EAllocationALLOC, - EAllocationFREE, - EAllocationFREE_ALL, - EAllocationRESIZE, + EAllocation_ALLOC, + EAllocation_FREE, + EAllocation_FREE_ALL, + EAllocation_RESIZE, } AllocType; // NOTE: This is useful so you can define an allocator of the same type and parameters @@ -3392,7 +3392,7 @@ ZPL_DEF ZPL_ALLOCATOR_PROC( stack_allocator_proc ); ZPL_IMPL_INLINE void* alloc_align( AllocatorInfo a, sw size, sw alignment ) { - return a.proc( a.data, EAllocationALLOC, size, alignment, NULL, 0, ZPL_DEFAULT_ALLOCATOR_FLAGS ); + return a.proc( a.data, EAllocation_ALLOC, size, alignment, NULL, 0, ZPL_DEFAULT_ALLOCATOR_FLAGS ); } ZPL_IMPL_INLINE void* alloc( AllocatorInfo a, sw size ) @@ -3403,12 +3403,12 @@ ZPL_IMPL_INLINE void* alloc( AllocatorInfo a, sw size ) ZPL_IMPL_INLINE void free( AllocatorInfo a, void* ptr ) { if ( ptr != NULL ) - a.proc( a.data, EAllocationFREE, 0, 0, ptr, 0, ZPL_DEFAULT_ALLOCATOR_FLAGS ); + a.proc( a.data, EAllocation_FREE, 0, 0, ptr, 0, ZPL_DEFAULT_ALLOCATOR_FLAGS ); } ZPL_IMPL_INLINE void free_all( AllocatorInfo a ) { - a.proc( a.data, EAllocationFREE_ALL, 0, 0, NULL, 0, ZPL_DEFAULT_ALLOCATOR_FLAGS ); + a.proc( a.data, EAllocation_FREE_ALL, 0, 0, NULL, 0, ZPL_DEFAULT_ALLOCATOR_FLAGS ); } ZPL_IMPL_INLINE void* resize( AllocatorInfo a, void* ptr, sw old_size, sw new_size ) @@ -3418,7 +3418,7 @@ ZPL_IMPL_INLINE void* resize( AllocatorInfo a, void* ptr, sw old_size, sw new_si ZPL_IMPL_INLINE void* resize_align( AllocatorInfo a, void* ptr, sw old_size, sw new_size, sw alignment ) { - return a.proc( a.data, EAllocationRESIZE, new_size, alignment, ptr, old_size, ZPL_DEFAULT_ALLOCATOR_FLAGS ); + return a.proc( a.data, EAllocation_RESIZE, new_size, alignment, ptr, old_size, ZPL_DEFAULT_ALLOCATOR_FLAGS ); } ZPL_IMPL_INLINE void* alloc_copy( AllocatorInfo a, void const* src, sw size ) @@ -4025,12 +4025,12 @@ typedef struct BufferHeader buffer_count( x ) += ( item_count ); \ } while ( 0 ) -#define buffer_copy_init( y, x ) \ - do \ - { \ - buffer_init( y, buffer_allocator( x ), buffer_capacity( x ) ); \ - ZPL_NS( mem_copy )( y, x, buffer_capacity( x ) * size_of( *x ) ); \ - buffer_count( y ) = buffer_count( x ); \ +#define buffer_copy_init( y, x ) \ + do \ + { \ + ZPL_NS( buffer_init )( y, ZPL_NS( buffer_allocator )( x ), buffer_capacity( x ) ); \ + ZPL_NS( mem_copy )( y, x, buffer_capacity( x ) * size_of( *x ) ); \ + buffer_count( y ) = buffer_count( x ); \ } while ( 0 ) #define buffer_pop( x ) \ @@ -8324,10 +8324,10 @@ ZPL_BEGIN_C_DECLS typedef enum CSV_Error { - ECSV_Error_NONE, - ECSV_Error_INTERNAL, - ECSV_Error_UNEXPECTED_END_OF_INPUT, - ECSV_Error_MISMATCHED_ROWS, + ECSV_Error__NONE, + ECSV_Error__INTERNAL, + ECSV_Error__UNEXPECTED_END_OF_INPUT, + ECSV_Error__MISMATCHED_ROWS, } CSV_Error; typedef ADT_Node CSV_Object; @@ -9302,7 +9302,7 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) sw track_size = max( alloc_info_size, alignment ) + alloc_info_remainder; switch ( type ) { - case EAllocationFREE : + case EAllocation_FREE : { if ( ! old_memory ) break; @@ -9312,7 +9312,7 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) old_memory = alloc_info->physical_start; } break; - case EAllocationALLOC : + case EAllocation_ALLOC : { size += track_size; } @@ -9325,15 +9325,15 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) switch ( type ) { #if defined( ZPL_COMPILER_MSVC ) || ( defined( ZPL_COMPILER_GCC ) && defined( ZPL_SYSTEM_WINDOWS ) ) || ( defined( ZPL_COMPILER_TINYC ) && defined( ZPL_SYSTEM_WINDOWS ) ) - case EAllocationALLOC : + case EAllocation_ALLOC : ptr = _aligned_malloc( size, alignment ); if ( flags & ZPL_ALLOCATOR_FLAG_CLEAR_TO_ZERO ) zero_size( ptr, size ); break; - case EAllocationFREE : + case EAllocation_FREE : _aligned_free( old_memory ); break; - case EAllocationRESIZE : + case EAllocation_RESIZE : { AllocatorInfo a = heap_allocator(); ptr = default_resize_align( a, old_memory, old_size, size, alignment ); @@ -9341,7 +9341,7 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) break; #elif defined( ZPL_SYSTEM_LINUX ) && ! defined( ZPL_CPU_ARM ) && ! defined( ZPL_COMPILER_TINYC ) - case EAllocationALLOC : + case EAllocation_ALLOC : { ptr = aligned_alloc( alignment, ( size + alignment - 1 ) & ~( alignment - 1 ) ); @@ -9352,20 +9352,20 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) } break; - case EAllocationFREE : + case EAllocation_FREE : { free( old_memory ); } break; - case EAllocationRESIZE : + case EAllocation_RESIZE : { AllocatorInfo a = heap_allocator(); ptr = default_resize_align( a, old_memory, old_size, size, alignment ); } break; #else - case EAllocationALLOC : + case EAllocation_ALLOC : { posix_memalign( &ptr, alignment, size ); @@ -9376,13 +9376,13 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) } break; - case EAllocationFREE : + case EAllocation_FREE : { free( old_memory ); } break; - case EAllocationRESIZE : + case EAllocation_RESIZE : { AllocatorInfo a = heap_allocator(); ptr = default_resize_align( a, old_memory, old_size, size, alignment ); @@ -9390,12 +9390,12 @@ ZPL_ALLOCATOR_PROC( heap_allocator_proc ) break; #endif - case EAllocationFREE_ALL : + case EAllocation_FREE_ALL : break; } #ifdef ZPL_HEAP_ANALYSIS - if ( type == EAllocationALLOC ) + if ( type == EAllocation_ALLOC ) { _heap_alloc_info* alloc_info = zpl_cast( _heap_alloc_info* )( zpl_cast( char* ) ptr + alloc_info_remainder ); zero_item( alloc_info ); @@ -9423,7 +9423,7 @@ ZPL_ALLOCATOR_PROC( arena_allocator_proc ) switch ( type ) { - case EAllocationALLOC : + case EAllocation_ALLOC : { void* end = pointer_add( arena->physical_start, arena->total_allocated ); sw total_size = align_forward_i64( size, alignment ); @@ -9442,16 +9442,16 @@ ZPL_ALLOCATOR_PROC( arena_allocator_proc ) } break; - case EAllocationFREE : + case EAllocation_FREE : // NOTE: Free all at once // Use Temp_Arena_Memory if you want to free a block break; - case EAllocationFREE_ALL : + case EAllocation_FREE_ALL : arena->total_allocated = 0; break; - case EAllocationRESIZE : + case EAllocation_RESIZE : { // TODO: Check if ptr is on top of stack and just extend AllocatorInfo a = arena_allocator( arena ); @@ -9509,7 +9509,7 @@ ZPL_ALLOCATOR_PROC( pool_allocator_proc ) switch ( type ) { - case EAllocationALLOC : + case EAllocation_ALLOC : { uptr next_free; ZPL_ASSERT( size == pool->block_size ); @@ -9525,7 +9525,7 @@ ZPL_ALLOCATOR_PROC( pool_allocator_proc ) } break; - case EAllocationFREE : + case EAllocation_FREE : { uptr* next; if ( old_memory == NULL ) @@ -9538,7 +9538,7 @@ ZPL_ALLOCATOR_PROC( pool_allocator_proc ) } break; - case EAllocationFREE_ALL : + case EAllocation_FREE_ALL : { sw actual_block_size, block_index; void* curr; @@ -9562,7 +9562,7 @@ ZPL_ALLOCATOR_PROC( pool_allocator_proc ) } break; - case EAllocationRESIZE : + case EAllocation_RESIZE : // NOTE: Cannot resize ZPL_PANIC( "You cannot resize something allocated by with a pool." ); break; @@ -9608,7 +9608,7 @@ ZPL_ALLOCATOR_PROC( scratch_allocator_proc ) switch ( type ) { - case EAllocationALLOC : + case EAllocation_ALLOC : { void* pt = s->alloc_point; allocation_header_ev* header = zpl_cast( allocation_header_ev* ) pt; @@ -9641,7 +9641,7 @@ ZPL_ALLOCATOR_PROC( scratch_allocator_proc ) } break; - case EAllocationFREE : + case EAllocation_FREE : { if ( old_memory ) { @@ -9672,12 +9672,12 @@ ZPL_ALLOCATOR_PROC( scratch_allocator_proc ) } break; - case EAllocationFREE_ALL : + case EAllocation_FREE_ALL : s->alloc_point = s->physical_start; s->free_point = s->physical_start; break; - case EAllocationRESIZE : + case EAllocation_RESIZE : ptr = default_resize_align( scratch_allocator( s ), old_memory, old_size, size, alignment ); break; } @@ -9698,7 +9698,7 @@ ZPL_ALLOCATOR_PROC( stack_allocator_proc ) switch ( type ) { - case EAllocationALLOC : + case EAllocation_ALLOC : { size += ZPL_STACK_ALLOC_OFFSET; u64 alloc_offset = s->allocated; @@ -9729,7 +9729,7 @@ ZPL_ALLOCATOR_PROC( stack_allocator_proc ) } break; - case EAllocationFREE : + case EAllocation_FREE : { if ( old_memory ) { @@ -9742,13 +9742,13 @@ ZPL_ALLOCATOR_PROC( stack_allocator_proc ) } break; - case EAllocationFREE_ALL : + case EAllocation_FREE_ALL : { s->allocated = 0; } break; - case EAllocationRESIZE : + case EAllocation_RESIZE : { ZPL_PANIC( "You cannot resize something allocated by a stack." ); } @@ -21338,7 +21338,7 @@ ZPL_BEGIN_C_DECLS u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b32 has_header, char delim ) { - CSV_Error err = ECSV_Error_NONE; + CSV_Error err = ECSV_Error__NONE; ZPL_ASSERT_NOT_NULL( root ); ZPL_ASSERT_NOT_NULL( text ); zero_item( root ); @@ -21379,7 +21379,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b if ( *e == 0 ) { ZPL_CSV_ASSERT( "unmatched quoted string" ); - err = ECSV_Error_UNEXPECTED_END_OF_INPUT; + err = ECSV_Error__UNEXPECTED_END_OF_INPUT; return err; } *e = 0; @@ -21467,7 +21467,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b else if ( total_colc != colc ) { ZPL_CSV_ASSERT( "mismatched rows" ); - err = ECSV_Error_MISMATCHED_ROWS; + err = ECSV_Error__MISMATCHED_ROWS; return err; } colc = 0; @@ -21479,7 +21479,7 @@ u8 csv_parse_delimiter( CSV_Object* root, char* text, AllocatorInfo allocator, b if ( array_count( root->nodes ) == 0 ) { ZPL_CSV_ASSERT( "unexpected end of input. stream is empty." ); - err = ECSV_Error_UNEXPECTED_END_OF_INPUT; + err = ECSV_Error__UNEXPECTED_END_OF_INPUT; return err; }