diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index d91baba..7b01b2d 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -1311,6 +1311,8 @@ R"(#define ( code ) _Generic( (code), \ break; } + CodeBody array_code_typename = gen_array(txt("CodeTypename"), txt("Array_CodeTypename")); + CodeBody parsed_src_parser = parse_file( project_dir "components/parser.cpp" ); CodeBody src_parser = def_body(CT_Global_Body); for ( Code entry = parsed_src_parser.begin(); entry != parsed_src_parser.end(); ++ entry ) switch( entry ->Type ) @@ -1327,9 +1329,27 @@ R"(#define ( code ) _Generic( (code), \ case CT_Struct: { CodeTypedef tdef = parse_typedef(token_fmt("name", entry->Name, stringize( typedef struct ; ))); - src_parser.append(entry); src_parser.append(tdef); + src_parser.append(entry); } + break; + + case CT_Variable: + { + CodeVar var = cast(CodeVar, entry); + if (var->Specs && var->Specs.has(Spec_Constexpr) > -1) { + Code define_ver = untyped_str(token_fmt( + "name", var->Name + , "value", var->Value->Content + , "type", var->ValueType.to_string().to_strc() + , "#define () \n" + )); + src_parser.append(define_ver); + continue; + } + src_parser.append(entry); + } + break; default: src_parser.append(entry); @@ -1484,6 +1504,9 @@ R"(#define ( code ) _Generic( (code), \ header.print_fmt( "\n#pragma region Parsing\n\n" ); header.print( format_code_to_untyped(etoktype) ); header.print( format_code_to_untyped(src_lexer) ); + header.print( fmt_newline); + header.print( format_code_to_untyped(array_code_typename)); + header.print( fmt_newline); header.print( format_code_to_untyped(src_parser) ); // header.print( parsing_interface ); header.print_fmt( "\n#pragma endregion Parsing\n" ); diff --git a/gen_c_library/components/memory.fixed_arena.hpp b/gen_c_library/components/memory.fixed_arena.hpp index b8a5fe4..0b5061a 100644 --- a/gen_c_library/components/memory.fixed_arena.hpp +++ b/gen_c_library/components/memory.fixed_arena.hpp @@ -84,7 +84,7 @@ CodeBody gen_fixed_arenas() result.append(arena_interface_2mb); result.append(arena_interface_4mb); - CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), code({ arena_allocator_proc, & fixed_arena.arena }) ); + CodeDefine def = def_define(txt("fixed_arena_allocator_info(fixed_arena)"), txt("( (AllocatorInfo) { arena_allocator_proc, & (fixed_arena)->arena } )")); result.append(def); result.append(fmt_newline); @@ -103,7 +103,7 @@ CodeBody gen_fixed_arenas() FixedArena_2MB* : fixed_arena_init_2MB, \ FixedArena_4MB* : fixed_arena_init_4MB, \ default : gen_generic_selection_fail \ -) GEN_RESOLVED_FUNCTION_CALL(& expr) +) GEN_RESOLVED_FUNCTION_CALL(expr) #define fixed_arena_size_remaining(expr, alignment) _Generic((expr), \ FixedArena_1KB* : fixed_arena_size_remaining_1KB, \ @@ -119,7 +119,7 @@ CodeBody gen_fixed_arenas() FixedArena_2MB* : fixed_arena_size_remaining_2MB, \ FixedArena_4MB* : fixed_arena_size_remaining_4MB, \ default : gen_generic_selection_fail \ -) GEN_RESOLVED_FUNCTION_CALL(& expr, alignment) +) GEN_RESOLVED_FUNCTION_CALL(expr, alignment) )" ))); diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp index e6b53ac..a90870f 100644 --- a/project/components/interface.parsing.cpp +++ b/project/components/interface.parsing.cpp @@ -19,7 +19,7 @@ CodeClass parse_class( StrC def ) Context.Tokens = toks; push_scope(); - CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class ); + CodeClass result = (CodeClass) parse_class_struct( Tok_Decl_Class, parser_not_inplace_def ); parser_pop(& Context); return result; } @@ -80,7 +80,7 @@ CodeConstructor parse_constructor( StrC def ) } Context.Tokens = toks; - CodeConstructor result = parse_constructor( specifiers ); + CodeConstructor result = parser_parse_constructor( specifiers ); return result; } @@ -97,7 +97,7 @@ CodeDestructor parse_destructor( StrC def ) // TODO(Ed): Destructors can have virtual Context.Tokens = toks; - CodeDestructor result = parse_destructor(); + CodeDestructor result = parser_parse_destructor(NullCode); return result; } @@ -114,7 +114,7 @@ CodeEnum parse_enum( StrC def ) } Context.Tokens = toks; - return parse_enum( parser_not_inplace_def); + return parser_parse_enum( parser_not_inplace_def); } CodeBody parse_export_body( StrC def ) @@ -127,7 +127,7 @@ CodeBody parse_export_body( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_export_body(); + return parser_parse_export_body(); } CodeExtern parse_extern_link( StrC def ) @@ -140,7 +140,7 @@ CodeExtern parse_extern_link( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_extern_link(); + return parser_parse_extern_link(); } CodeFriend parse_friend( StrC def ) @@ -153,7 +153,7 @@ CodeFriend parse_friend( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_friend(); + return parser_parse_friend(); } CodeFn parse_function( StrC def ) @@ -166,7 +166,7 @@ CodeFn parse_function( StrC def ) return InvalidCode; Context.Tokens = toks; - return (CodeFn) parse_function(); + return (CodeFn) parser_parse_function(); } CodeBody parse_global_body( StrC def ) @@ -195,7 +195,7 @@ CodeNS parse_namespace( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_namespace(); + return parser_parse_namespace(); } CodeOperator parse_operator( StrC def ) @@ -208,7 +208,7 @@ CodeOperator parse_operator( StrC def ) return InvalidCode; Context.Tokens = toks; - return (CodeOperator) parse_operator(); + return (CodeOperator) parser_parse_operator(); } CodeOpCast parse_operator_cast( StrC def ) @@ -221,7 +221,7 @@ CodeOpCast parse_operator_cast( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_operator_cast(); + return parser_parse_operator_cast(NullCode); } CodeStruct parse_struct( StrC def ) @@ -235,7 +235,7 @@ CodeStruct parse_struct( StrC def ) Context.Tokens = toks; push_scope(); - CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct ); + CodeStruct result = (CodeStruct) parse_class_struct( Tok_Decl_Struct, parser_not_inplace_def ); parser_pop(& Context); return result; } @@ -250,7 +250,7 @@ CodeTemplate parse_template( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_template(); + return parser_parse_template(); } CodeTypename parse_type( StrC def ) @@ -263,7 +263,7 @@ CodeTypename parse_type( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_type( parser_not_from_template, nullptr); + return parser_parse_type( parser_not_from_template, nullptr); } CodeTypedef parse_typedef( StrC def ) @@ -276,7 +276,7 @@ CodeTypedef parse_typedef( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_typedef(); + return parser_parse_typedef(); } CodeUnion parse_union( StrC def ) @@ -289,7 +289,7 @@ CodeUnion parse_union( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_union( parser_not_inplace_def); + return parser_parse_union( parser_not_inplace_def); } CodeUsing parse_using( StrC def ) @@ -302,7 +302,7 @@ CodeUsing parse_using( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_using(); + return parser_parse_using(); } CodeVar parse_variable( StrC def ) @@ -315,15 +315,19 @@ CodeVar parse_variable( StrC def ) return InvalidCode; Context.Tokens = toks; - return parse_variable(); + return parser_parse_variable(); } // Undef helper macros # undef check_parse_args +# undef currtok_noskip # undef currtok +# undef peektok # undef prevtok # undef nexttok +# undef nexttok_noskip # undef eat # undef left # undef check # undef push_scope +# undef def_assign diff --git a/project/components/lexer.cpp b/project/components/lexer.cpp index d179a15..211c967 100644 --- a/project/components/lexer.cpp +++ b/project/components/lexer.cpp @@ -113,7 +113,7 @@ struct TokArray s32 Idx; }; -bool lex__eat( TokType type ); +bool lex__eat( TokArray* self, TokType type ); Token* lex_current(TokArray* self, bool skip_formatting ) { diff --git a/project/components/parser.cpp b/project/components/parser.cpp index 3c8b1ee..2f7062f 100644 --- a/project/components/parser.cpp +++ b/project/components/parser.cpp @@ -60,13 +60,16 @@ String parser_to_string(ParseContext ctx) length++; } - String line = string_make_strc( GlobalAllocator, { length, scope_start.Text } ); + StrC scope_strc = { length, scope_start.Text }; + String line = string_make_strc( GlobalAllocator, scope_strc ); 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_strc( GlobalAllocator, { length_from_err, last_valid.Text } ); + + StrC err_strc = { length_from_err, last_valid.Text }; + String line_from_err = string_make_strc( GlobalAllocator, err_strc ); if ( length_from_err < 100 ) string_append_fmt(& result, "\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' ); @@ -147,7 +150,8 @@ void parser_init() internal void parser_deinit() { - Lexer_Tokens = { nullptr }; + Array(Token) null_array = {}; + Lexer_Tokens = null_array; } #pragma region Helper Macros @@ -179,6 +183,13 @@ bool _check_parse_args( StrC def, char const* func_name ) # define eat( Type_ ) lex__eat( & Context.Tokens, Type_ ) # define left ( array_num(Context.Tokens.Arr) - Context.Tokens.Idx ) +#if GEN_COMPILER_CPP +# define def_assign( ... ) { __VA_ARGS__ } +#else +# define def_assign( ... ) __VA_ARGS__ +#endif + + #ifdef check #define CHECK_WAS_DEFINED #pragma push_macro("check") @@ -189,8 +200,8 @@ bool _check_parse_args( StrC def, char const* func_name ) # define check( Type_ ) ( left && currtok.Type == Type_ ) # define push_scope() \ - GEN_NS_PARSER StackNode scope { nullptr, currtok_noskip, GEN_NS_PARSER NullToken, txt( __func__ ) }; \ - parser_push( & parser::Context, & scope ) + GEN_NS_PARSER StackNode scope = { nullptr, currtok_noskip, GEN_NS_PARSER NullToken, txt( __func__ ) }; \ + parser_push( & GEN_NS_PARSER Context, & scope ) #pragma endregion Helper Macros @@ -200,14 +211,14 @@ internal Code parse_array_decl (); internal CodeAttributes parse_attributes (); internal CodeComment parse_comment (); internal Code parse_complicated_definition ( TokType which ); -internal CodeBody parse_class_struct_body ( TokType which, Token name = NullToken ); +internal CodeBody parse_class_struct_body ( TokType which, Token name ); internal Code parse_class_struct ( TokType which, bool inplace_def ); internal CodeDefine parse_define (); internal Code parse_expression (); internal Code parse_forward_or_definition ( TokType which, bool is_inplace ); internal CodeFn parse_function_after_name ( ModuleFlag mflags, CodeAttributes attributes, CodeSpecifiers specifiers, CodeTypename ret_type, Token name ); internal Code parse_function_body (); -internal Code parse_global_nspace (); +internal CodeBody parse_global_nspace ( CodeType which ); internal Code parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers ); internal Token parse_identifier ( bool* possible_member_function ); internal CodeInclude parse_include (); @@ -218,28 +229,28 @@ internal CodeParam parse_params ( bool use_templa internal CodePreprocessCond parse_preprocess_cond (); internal Code parse_simple_preprocess ( TokType which, bool dont_consume_braces ); internal Code parse_static_assert (); -internal void parse_template_args ( Token& token ); +internal void parse_template_args ( Token* token ); internal CodeVar parse_variable_after_name ( ModuleFlag mflags, CodeAttributes attributes, CodeSpecifiers specifiers, CodeTypename type, StrC name ); internal CodeVar parse_variable_declaration_list (); -internal CodeClass parse_class ( bool inplace_def ); -internal CodeConstructor parse_constructor ( CodeSpecifiers specifiers ); -internal CodeDestructor parse_destructor ( CodeSpecifiers specifiers = NullCode ); -internal CodeEnum parse_enum ( bool inplace_def ); -internal CodeBody parse_export_body (); -internal CodeBody parse_extern_link_body(); -internal CodeExtern parse_extern_link (); -internal CodeFriend parse_friend (); -internal CodeFn parse_function (); -internal CodeNS parse_namespace (); -internal CodeOpCast parse_operator_cast ( CodeSpecifiers specifiers = NullCode ); -internal CodeStruct parse_struct ( bool inplace_def ); -internal CodeVar parse_variable (); -internal CodeTemplate parse_template (); -internal CodeTypename parse_type ( bool from_template, bool* is_function ); -internal CodeTypedef parse_typedef (); -internal CodeUnion parse_union ( bool inplace_def ); -internal CodeUsing parse_using (); +internal CodeClass parser_parse_class ( bool inplace_def ); +internal CodeConstructor parser_parse_constructor ( CodeSpecifiers specifiers ); +internal CodeDestructor parser_parse_destructor ( CodeSpecifiers specifiers ); +internal CodeEnum parser_parse_enum ( bool inplace_def ); +internal CodeBody parser_parse_export_body (); +internal CodeBody parser_parse_extern_link_body(); +internal CodeExtern parser_parse_extern_link (); +internal CodeFriend parser_parse_friend (); +internal CodeFn parser_parse_function (); +internal CodeNS parser_parse_namespace (); +internal CodeOpCast parser_parse_operator_cast ( CodeSpecifiers specifiers ); +internal CodeStruct parser_parse_struct ( bool inplace_def ); +internal CodeVar parser_parse_variable (); +internal CodeTemplate parser_parse_template (); +internal CodeTypename parser_parse_type ( bool from_template, bool* is_function ); +internal CodeTypedef parser_parse_typedef (); +internal CodeUnion parser_parse_union ( bool inplace_def ); +internal CodeUsing parser_parse_using (); constexpr bool parser_inplace_def = true; constexpr bool parser_not_inplace_def = false; @@ -257,7 +268,7 @@ constexpr bool parser_strip_formatting_dont_preserve_newlines = false; It has edge case failures that prevent it from being used in function bodies. */ internal -String strip_formatting( StrC raw_text, bool preserve_newlines = true ) +String parser_strip_formatting( StrC raw_text, bool preserve_newlines ) { String content = string_make_reserve( GlobalAllocator, raw_text.Len ); @@ -266,7 +277,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) #define cut_length ( scanner - raw_text.Ptr - last_cut ) #define cut_ptr ( raw_text.Ptr + last_cut ) -#define pos ( sptr( scanner ) - sptr( raw_text.Ptr ) ) +#define pos ( rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ) ) #define move_fwd() do { scanner++; tokleft--; } while(0) s32 tokleft = raw_text.Len; @@ -307,7 +318,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) move_fwd(); string_append_c_str_len( & content, cut_ptr, cut_length ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast(sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -329,7 +340,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) move_fwd(); string_append_c_str_len( & content, cut_ptr, cut_length ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -343,7 +354,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) tokleft -= 2; string_append_c_str_len( & content, cut_ptr, cut_length ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -362,7 +373,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) move_fwd(); string_append_c_str_len( & content, cut_ptr, cut_length ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -376,7 +387,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) string_append_char( & content, ' ' ); move_fwd(); - last_cut = sptr(scanner) - sptr(raw_text.Ptr); + last_cut = rcast( sptr, scanner) - rcast( sptr, raw_text.Ptr); continue; } @@ -390,7 +401,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) tokleft -= 2; string_append_c_str_len( & content, cut_ptr, cut_length ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -404,7 +415,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) scanner += 2; tokleft -= 2; - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -417,7 +428,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) move_fwd(); string_append_c_str_len( & content, cut_ptr, cut_length ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -430,7 +441,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) move_fwd(); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -457,7 +468,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) else move_fwd(); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); continue; } @@ -471,7 +482,7 @@ String strip_formatting( StrC raw_text, bool preserve_newlines = true ) } while ( tokleft && char_is_space( scanner[0] ) ); - last_cut = sptr( scanner ) - sptr( raw_text.Ptr ); + last_cut = rcast( sptr, scanner ) - rcast( sptr, raw_text.Ptr ); // Preserve only 1 space of formattting char* last = string_back(content); @@ -566,7 +577,7 @@ Code parse_array_decl() Code adjacent_arr_expr = parse_array_decl(); // [ ][ ]... - array_expr->Next.ast = adjacent_arr_expr.ast; + array_expr->Next = adjacent_arr_expr; } parser_pop(& Context); @@ -574,7 +585,7 @@ Code parse_array_decl() } parser_pop(& Context); - return { nullptr }; + return NullCode; } internal inline @@ -673,11 +684,11 @@ CodeAttributes parse_attributes() StrC attribute_txt = { len, start.Text }; parser_pop(& Context); - String name_stripped = strip_formatting( attribute_txt, parser_strip_formatting_dont_preserve_newlines ); + String name_stripped = parser_strip_formatting( attribute_txt, parser_strip_formatting_dont_preserve_newlines ); Code result = make_code(); result->Type = CT_PlatformAttributes; - result->Name = get_cached_string( { string_length(name_stripped), name_stripped } ); + result->Name = get_cached_string( string_to_strc(name_stripped) ); result->Content = result->Name; // result->Token = @@ -685,11 +696,11 @@ CodeAttributes parse_attributes() } parser_pop(& Context); - return { nullptr }; + return NullCode; } internal -Code parse_class_struct( TokType which, bool inplace_def = false ) +Code parse_class_struct( TokType which, bool inplace_def ) { if ( which != Tok_Decl_Class && which != Tok_Decl_Struct ) { @@ -697,7 +708,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false ) return InvalidCode; } - Token name { nullptr, 0, Tok_Invalid }; + Token name = { nullptr, 0, Tok_Invalid }; AccessSpec access = AccessSpec_Default; CodeTypename parent = { nullptr }; @@ -705,7 +716,7 @@ Code parse_class_struct( TokType which, bool inplace_def = false ) CodeAttributes attributes = { nullptr }; ModuleFlag mflags = ModuleFlag_None; - CodeClass result = InvalidCode; + Code result = InvalidCode; if ( check(Tok_Module_Export) ) { @@ -728,8 +739,8 @@ Code parse_class_struct( TokType which, bool inplace_def = false ) // local_persist - char interface_arr_mem[ kilobytes(4) ] {0}; - Array interfaces; { + 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, arena_allocator_info(& arena), 4 ); } @@ -786,13 +797,14 @@ Code parse_class_struct( TokType which, bool inplace_def = false ) } if ( which == Tok_Decl_Class ) - result = def_class( tok_to_str(name), { body, parent, access, attributes, nullptr, 0, mflags } ); + result = cast(Code, def_class( tok_to_str(name), def_assign( body, parent, access, attributes, nullptr, 0, mflags ) )); else - result = def_struct( tok_to_str(name), { body, (CodeTypename)parent, access, attributes, nullptr, 0, mflags } ); + result = cast(Code, def_struct( tok_to_str(name), def_assign( body, (CodeTypename)parent, access, attributes, nullptr, 0, mflags ) )); + if ( inline_cmt ) - result->InlineCmt = inline_cmt; + result->InlineCmt = cast(Code, inline_cmt); array_free(interfaces); return result; @@ -845,7 +857,7 @@ CodeBody parse_class_struct_body( TokType which, Token name ) break; case Tok_Comment: - member = parse_comment(); + member = cast(Code, parse_comment()); break; case Tok_Access_Public: @@ -880,12 +892,12 @@ CodeBody parse_class_struct_body( TokType which, Token name ) break; case Tok_Decl_Friend: - member = parse_friend(); + member = cast(Code, parser_parse_friend()); // friend break; case Tok_Decl_Operator: - member = parse_operator_cast(); + member = cast(Code, parser_parse_operator_cast(NullCode)); // operator () break; @@ -895,12 +907,12 @@ CodeBody parse_class_struct_body( TokType which, Token name ) break; case Tok_Decl_Template: - member = parse_template(); + member = cast(Code, parser_parse_template()); // template< ... > break; case Tok_Decl_Typedef: - member = parse_typedef(); + member = cast(Code, parser_parse_typedef()); // typedef break; @@ -910,7 +922,7 @@ CodeBody parse_class_struct_body( TokType which, Token name ) break; case Tok_Decl_Using: - member = parse_using(); + member = cast(Code, parser_parse_using()); // using break; @@ -921,17 +933,17 @@ CodeBody parse_class_struct_body( TokType which, Token name ) // return InvalidCode; //} - member = parse_destructor(); + member = cast(Code, parser_parse_destructor(NullCode)); // ~() break; case Tok_Preprocess_Define: - member = parse_define(); + member = cast(Code, parse_define()); // #define break; case Tok_Preprocess_Include: - member = parse_include(); + member = cast(Code, parse_include()); // #include break; @@ -939,18 +951,18 @@ CodeBody parse_class_struct_body( TokType which, Token name ) case Tok_Preprocess_IfDef: case Tok_Preprocess_IfNotDef: case Tok_Preprocess_ElIf: - member = parse_preprocess_cond(); + member = cast(Code, parse_preprocess_cond()); // # break; case Tok_Preprocess_Else: - member = preprocess_else; + member = cast(Code, preprocess_else); eat( Tok_Preprocess_Else ); // #else break; case Tok_Preprocess_EndIf: - member = preprocess_endif; + member = cast(Code, preprocess_endif); eat( Tok_Preprocess_EndIf ); // #endif break; @@ -962,12 +974,12 @@ CodeBody parse_class_struct_body( TokType which, Token name ) break; case Tok_Preprocess_Pragma: - member = parse_pragma(); + member = cast(Code, parse_pragma()); // #pragma break; case Tok_Preprocess_Unsupported: - member = parse_simple_preprocess( Tok_Preprocess_Unsupported, parser_consume_braces ); + member = cast(Code, parse_simple_preprocess( Tok_Preprocess_Unsupported, parser_consume_braces )); // # break; @@ -999,7 +1011,7 @@ CodeBody parse_class_struct_body( TokType which, Token name ) case Tok_Spec_Volatile: case Tok_Spec_Virtual: { - Specifier specs_found[16] { Spec_NumSpecifiers }; + Specifier specs_found[16] = { Spec_NumSpecifiers }; s32 NumSpecifiers = 0; while ( left && tok_is_specifier(currtok) ) @@ -1072,14 +1084,14 @@ CodeBody parse_class_struct_body( TokType which, Token name ) if ( currtok.Type == Tok_Operator && currtok.Text[0] == '~' ) { - member = parse_destructor( specifiers ); + member = cast(Code, parser_parse_destructor( specifiers )); // ~() break; } if ( currtok.Type == Tok_Decl_Operator ) { - member = parse_operator_cast( specifiers ); + member = cast(Code, parser_parse_operator_cast( specifiers )); // operator () break; } @@ -1100,7 +1112,7 @@ CodeBody parse_class_struct_body( TokType which, Token name ) { if ( str_compare_len( name.Text, currtok.Text, name.Length ) == 0 ) { - member = parse_constructor( specifiers ); + member = cast(Code, parser_parse_constructor( specifiers )); // () break; } @@ -1112,7 +1124,7 @@ CodeBody parse_class_struct_body( TokType which, Token name ) b32 lone_macro = nexttok.Type == Tok_Statement_End || nexttok_noskip.Type == Tok_NewLine; if (lone_macro) { - member = parse_simple_preprocess( Tok_Preprocess_Macro, parser_consume_braces ); + member = cast(Code, parse_simple_preprocess( Tok_Preprocess_Macro, parser_consume_braces )); // ; if ( member == Code_Invalid ) @@ -1232,7 +1244,7 @@ Code parse_complicated_definition( TokType which ) // Forward declaration with trailing specifiers for a procedure tok = tokens.Arr[spec_idx]; - Code result = parse_operator_function_or_variable( false, { nullptr }, { nullptr } ); + Code result = parse_operator_function_or_variable( false, NullCode, NullCode ); // , or Name> ... parser_pop(& Context); return result; @@ -1270,7 +1282,7 @@ Code parse_complicated_definition( TokType which ) // : ; // : ; ok_to_parse = true; - Code result = parse_enum( ! parser_inplace_def); + Code result = cast(Code, parser_parse_enum( ! parser_inplace_def)); parser_pop(& Context); return result; } @@ -1288,7 +1300,7 @@ Code parse_complicated_definition( TokType which ) return InvalidCode; } - Code result = parse_operator_function_or_variable( false, { nullptr }, { nullptr } ); + Code result = parse_operator_function_or_variable( false, NullCode, NullCode ); // , or Name> ... parser_pop(& Context); return result; @@ -1310,7 +1322,7 @@ Code parse_complicated_definition( TokType which ) // Its a forward declaration of an enum class // : ; // : ; - Code result = parse_enum( ! parser_inplace_def); + Code result = cast(Code, parser_parse_enum( ! parser_inplace_def)); parser_pop(& Context); return result; } @@ -1325,7 +1337,7 @@ Code parse_complicated_definition( TokType which ) else if ( tok.Type == Tok_BraceSquare_Close ) { // Its an array definition - Code result = parse_operator_function_or_variable( false, { nullptr }, { nullptr } ); + Code result = parse_operator_function_or_variable( false, NullCode, NullCode ); // [ ... ]; parser_pop(& Context); return result; @@ -1378,7 +1390,7 @@ CodeDefine parse_define() return define; } - define->Content = get_cached_string( string_to_strc( strip_formatting( tok_to_str(currtok), parser_strip_formatting_dont_preserve_newlines )) ); + define->Content = get_cached_string( string_to_strc( parser_strip_formatting( tok_to_str(currtok), parser_strip_formatting_dont_preserve_newlines )) ); eat( Tok_Preprocess_Content ); // #define @@ -1432,19 +1444,19 @@ Code parse_forward_or_definition( TokType which, bool is_inplace ) switch ( which ) { case Tok_Decl_Class: - result = parse_class( is_inplace ); + result = cast(Code, parser_parse_class( is_inplace )); return result; case Tok_Decl_Enum: - result = parse_enum( is_inplace ); + result = cast(Code, parser_parse_enum( is_inplace )); return result; case Tok_Decl_Struct: - result = parse_struct( is_inplace ); + result = cast(Code, parser_parse_struct( is_inplace )); return result; case Tok_Decl_Union: - result = parse_union( is_inplace ); + result = cast(Code, parser_parse_union( is_inplace )); return result; default: @@ -1473,7 +1485,7 @@ CodeFn parse_function_after_name( // TODO(Ed), Review old comment : These have to be kept separate from the return type's specifiers. while ( left && tok_is_specifier(currtok) ) { - if ( specifiers.ast == nullptr ) + if ( specifiers == nullptr ) { specifiers = def_specifier( strc_to_specifier( tok_to_str(currtok)) ); eat( currtok.Type ); @@ -1489,8 +1501,8 @@ CodeFn parse_function_after_name( CodeComment inline_cmt = NullCode; if ( check( Tok_BraceCurly_Open ) ) { - body = parse_function_body(); - if ( body == Code_Invalid ) + body = cast(CodeBody, parse_function_body()); + if ( cast(Code, body) == Code_Invalid ) { parser_pop(& Context); return InvalidCode; @@ -1605,13 +1617,14 @@ Code parse_function_body() if ( len > 0 ) { - body_append( result, def_execution( { len, start.Text } ) ); + StrC str = { len, start.Text }; + body_append( result, cast(Code, def_execution( str )) ); } eat( Tok_BraceCurly_Close ); parser_pop(& Context); - return result; + return cast(Code, result); } internal neverinline @@ -1668,7 +1681,7 @@ CodeBody parse_global_nspace( CodeType which ) break; case Tok_Comment: - member = parse_comment(); + member = cast(Code, parse_comment()); break; case Tok_Decl_Class: @@ -1685,12 +1698,12 @@ CodeBody parse_global_nspace( CodeType which ) if ( which == CT_Extern_Linkage_Body ) log_failure( "Nested extern linkage\n%s", parser_to_string(Context) ); - member = parse_extern_link(); + member = cast(Code, parser_parse_extern_link()); // extern "..." { ... } break; case Tok_Decl_Namespace: - member = parse_namespace(); + member = cast(Code, parser_parse_namespace()); // namespace { ... } break; @@ -1700,12 +1713,12 @@ CodeBody parse_global_nspace( CodeType which ) break; case Tok_Decl_Template: - member = parse_template(); + member = cast(Code, parser_parse_template()); // template<...> ... break; case Tok_Decl_Typedef: - member = parse_typedef(); + member = cast(Code, parser_parse_typedef()); // typedef ... break; @@ -1715,17 +1728,17 @@ CodeBody parse_global_nspace( CodeType which ) break; case Tok_Decl_Using: - member = parse_using(); + member = cast(Code, parser_parse_using()); // using ... break; case Tok_Preprocess_Define: - member = parse_define(); + member = cast(Code, parse_define()); // #define ... break; case Tok_Preprocess_Include: - member = parse_include(); + member = cast(Code, parse_include()); // #include ... break; @@ -1733,18 +1746,18 @@ CodeBody parse_global_nspace( CodeType which ) case Tok_Preprocess_IfDef: case Tok_Preprocess_IfNotDef: case Tok_Preprocess_ElIf: - member = parse_preprocess_cond(); + member = cast(Code, parse_preprocess_cond()); // # ... break; case Tok_Preprocess_Else: - member = preprocess_else; + member = cast(Code, preprocess_else); eat( Tok_Preprocess_Else ); // #else break; case Tok_Preprocess_EndIf: - member = preprocess_endif; + member = cast(Code, preprocess_endif); eat( Tok_Preprocess_EndIf ); // #endif break; @@ -1757,19 +1770,19 @@ CodeBody parse_global_nspace( CodeType which ) break; case Tok_Preprocess_Pragma: { - member = parse_pragma(); + member = cast(Code, parse_pragma()); // #pragma ... } break; case Tok_Preprocess_Unsupported: { - member = parse_simple_preprocess( Tok_Preprocess_Unsupported, parser_consume_braces ); + member = cast(Code, parse_simple_preprocess( Tok_Preprocess_Unsupported, parser_consume_braces )); // # ... } break; case Tok_StaticAssert: { - member = parse_static_assert(); + member = cast(Code, parse_static_assert()); // static_assert( , ... ); } break; @@ -1778,7 +1791,7 @@ CodeBody parse_global_nspace( CodeType which ) if ( which == CT_Export_Body ) log_failure( "Nested export declaration\n%s", parser_to_string(Context) ); - member = parse_export_body(); + member = cast(Code, parser_parse_export_body()); // export { ... } } break; @@ -1810,7 +1823,7 @@ CodeBody parse_global_nspace( CodeType which ) case Tok_Spec_NeverInline: case Tok_Spec_Static: { - Specifier specs_found[16] { Spec_NumSpecifiers }; + Specifier specs_found[16] = { Spec_NumSpecifiers }; s32 NumSpecifiers = 0; while ( left && tok_is_specifier(currtok) ) @@ -1911,7 +1924,7 @@ CodeBody parse_global_nspace( CodeType which ) if ( found_operator_cast_outside_class_implmentation ) { - member = parse_operator_cast( specifiers ); + member = cast(Code, parser_parse_operator_cast( specifiers )); // ::operator () { ... } break; } @@ -2081,11 +2094,11 @@ Code parse_global_nspace_constructor_destructor( CodeSpecifiers specifiers ) if (possible_destructor) { // :: ~ ( - result = parse_destructor( specifiers ); + result = cast(Code, parser_parse_destructor( specifiers )); } else { // :: ( - result = parse_constructor( specifiers ); + result = cast(Code, parser_parse_constructor( specifiers )); } } @@ -2105,7 +2118,7 @@ Token parse_identifier( bool* possible_member_function ) eat( Tok_Identifier ); // - parse_template_args( name ); + parse_template_args( & name ); //