diff --git a/base/components/ast.cpp b/base/components/ast.cpp index b0b9347..1d83489 100644 --- a/base/components/ast.cpp +++ b/base/components/ast.cpp @@ -1161,27 +1161,20 @@ bool code_is_equal( Code self, Code other ) bool code_validate_body(Code self) { -#define CheckEntries( Unallowed_Types ) \ - do \ - { \ - CodeBody body = cast(CodeBody, self); \ - for ( Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry) ) \ - { \ - switch ( code_entry->Type ) \ - { \ - Unallowed_Types \ - log_failure( "AST::validate_body: Invalid entry in body %SC", code_debug_str(code_entry) ); \ - return false; \ - } \ - } \ - } \ - while (0); - switch ( self->Type ) { case CT_Class_Body: { - CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES ); + CodeBody body = cast(CodeBody, self); + for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type) + { + GEN_AST_BODY_CLASS_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(code_entry)); + return false; + + default: + continue; + } } break; case CT_Enum_Body: @@ -1199,57 +1192,77 @@ bool code_validate_body(Code self) break; case CT_Export_Body: { - CheckEntries( GEN_AST_BODY_CLASS_UNALLOWED_TYPES ); + CodeBody body = cast(CodeBody, self); + for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type) + { + GEN_AST_BODY_EXPORT_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(code_entry)); + return false; + + default: + continue; + } } break; case CT_Extern_Linkage: { - CheckEntries( GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES ); + CodeBody body = cast(CodeBody, self); + for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type) + { + GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(code_entry)); + return false; + + default: + continue; + } } break; case CT_Function_Body: { - CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES ); + CodeBody body = cast(CodeBody, self); + for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type) + { + GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(code_entry)); + return false; + + default: + continue; + } } break; case CT_Global_Body: { CodeBody body = cast(CodeBody, self); - for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) ) + for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )switch (entry->Type) { - switch (entry->Type) - { - case CT_Access_Public: - case CT_Access_Protected: - case CT_Access_Private: - case CT_PlatformAttributes: - case CT_Class_Body: - case CT_Enum_Body: - case CT_Execution: - case CT_Friend: - case CT_Function_Body: - case CT_Global_Body: - case CT_Namespace_Body: - case CT_Operator_Member: - case CT_Operator_Member_Fwd: - case CT_Parameters: - case CT_Specifiers: - case CT_Struct_Body: - case CT_Typename: - log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(entry)); - return false; - } + GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(entry)); + return false; } } break; case CT_Namespace_Body: { - CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES ); + CodeBody body = cast(CodeBody, self); + for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) ) switch (entry->Type) + { + GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(entry)); + return false; + } } break; case CT_Struct_Body: { - CheckEntries( GEN_AST_BODY_STRUCT_UNALLOWED_TYPES ); + CodeBody body = cast(CodeBody, self); + for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) ) switch (entry->Type) + { + GEN_AST_BODY_STRUCT_UNALLOWED_TYPES: + log_failure("AST::validate_body: Invalid entry in body %SC", code_debug_str(entry)); + return false; + } } break; case CT_Union_Body: @@ -1272,6 +1285,4 @@ bool code_validate_body(Code self) } return false; - -#undef CheckEntries } diff --git a/base/components/ast_case_macros.cpp b/base/components/ast_case_macros.cpp index 8f1c9fa..4959914 100644 --- a/base/components/ast_case_macros.cpp +++ b/base/components/ast_case_macros.cpp @@ -1,4 +1,6 @@ -# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \ +// These macros are used in the swtich cases are used within ast.cpp, inteface.upfront.cpp, parser.cpp + +# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \ case CT_PlatformAttributes: \ case CT_Class_Body: \ case CT_Enum_Body: \ @@ -13,7 +15,7 @@ case CT_Parameters: \ case CT_Specifiers: \ case CT_Struct_Body: \ - case CT_Typename: + case CT_Typename # define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES # define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \ @@ -37,7 +39,7 @@ case CT_Parameters: \ case CT_Specifiers: \ case CT_Struct_Body: \ - case CT_Typename: + case CT_Typename # define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \ case CT_Access_Public: \ @@ -55,7 +57,7 @@ case CT_Parameters: \ case CT_Specifiers: \ case CT_Struct_Body: \ - case CT_Typename: + case CT_Typename # define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES # define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES @@ -75,4 +77,4 @@ case CT_Parameters: \ case CT_Specifiers: \ case CT_Struct_Body: \ - case CT_Typename: + case CT_Typename diff --git a/base/components/interface.cpp b/base/components/interface.cpp index b713dde..cc09014 100644 --- a/base/components/interface.cpp +++ b/base/components/interface.cpp @@ -145,43 +145,34 @@ void define_constants() preprocess_endif->Type = CT_Preprocess_EndIf; code_set_global((Code)preprocess_endif); -# define def_constant_code_type( Type_ ) \ - do \ - { \ - StrC name_str = name(Type_); \ - t_##Type_ = def_type( name_str ); \ - code_set_global( cast(Code, t_##Type_)); \ - } while(0) - - def_constant_code_type( auto ); - def_constant_code_type( void ); - def_constant_code_type( int ); - def_constant_code_type( bool ); - def_constant_code_type( char ); - def_constant_code_type( wchar_t ); - def_constant_code_type( class ); - def_constant_code_type( typename ); + StrC auto_str = txt("auto"); t_auto = def_type( auto_str ); code_set_global( t_auto ); + StrC void_str = txt("void"); t_void = def_type( void_str ); code_set_global( t_void ); + StrC int_str = txt("int"); t_int = def_type( int_str ); code_set_global( t_int ); + StrC bool_str = txt("bool"); t_bool = def_type( bool_str ); code_set_global( t_bool ); + StrC char_str = txt("char"); t_char = def_type( char_str ); code_set_global( t_char ); + StrC wchar_str = txt("wchar_t"); t_wchar_t = def_type( wchar_str ); code_set_global( t_wchar_t ); + StrC class_str = txt("class"); t_class = def_type( class_str ); code_set_global( t_class ); + StrC typename_str = txt("typename"); t_typename = def_type( typename_str ); code_set_global( t_typename ); #ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS - t_b32 = def_type( name(b32) ); + t_b32 = def_type( name(b32) ); code_set_global( t_b32 ); - def_constant_code_type( s8 ); - def_constant_code_type( s16 ); - def_constant_code_type( s32 ); - def_constant_code_type( s64 ); + StrC s8_str = txt("s8"); t_s8 = def_type( s8_str ); code_set_global( t_s8 ); + StrC s16_str = txt("s16"); t_s16 = def_type( s16_str ); code_set_global( t_s16 ); + StrC s32_str = txt("s32"); t_s32 = def_type( s32_str ); code_set_global( t_s32 ); + StrC s64_str = txt("s64"); t_s64 = def_type( s64_str ); code_set_global( t_s64 ); - def_constant_code_type( u8 ); - def_constant_code_type( u16 ); - def_constant_code_type( u32 ); - def_constant_code_type( u64 ); + StrC u8_str = txt("u8"); t_u8 = def_type( u8_str ); code_set_global( t_u8 ); + StrC u16_str = txt("u16"); t_u16 = def_type( u16_str ); code_set_global( t_u16 ); + StrC u32_str = txt("u32"); t_u32 = def_type( u32_str ); code_set_global( t_u32 ); + StrC u64_str = txt("u64"); t_u64 = def_type( u64_str ); code_set_global( t_u64 ); - def_constant_code_type( ssize ); - def_constant_code_type( usize ); + StrC ssize_str = txt("ssize"); t_ssize = def_type( ssize_str ); code_set_global( t_ssize ); + StrC usize_str = txt("usize"); t_usize = def_type( usize_str ); code_set_global( t_usize ); - def_constant_code_type( f32 ); - def_constant_code_type( f64 ); + StrC f32_str = txt("f32"); t_f32 = def_type( f32_str ); code_set_global( t_f32 ); + StrC f64_str = txt("f64"); t_f64 = def_type( f64_str ); code_set_global( t_f64 ); #endif -# undef def_constant_code_type spec_const = def_specifier( Spec_Const); code_set_global( cast(Code, spec_const )); spec_consteval = def_specifier( Spec_Consteval); code_set_global( cast(Code, spec_consteval ));; diff --git a/base/components/interface.upfront.cpp b/base/components/interface.upfront.cpp index bab9686..04782db 100644 --- a/base/components/interface.upfront.cpp +++ b/base/components/interface.upfront.cpp @@ -372,50 +372,30 @@ OpValidateResult operator__validate( Operator op, CodeParams params_code, CodeTy # undef check_param_eq_ret } - -#pragma region Helper Marcos -// This snippet is used in nearly all the functions. -#define name_check( Context_, Name_ ) \ -{ \ - if ( Name_.Len <= 0 ) \ - { \ - log_failure( "gen::" stringize(Context_) ": Invalid name length provided - %d", Name_.Len ); \ - return InvalidCode; \ - } \ - \ - if ( Name_.Ptr == nullptr ) \ - { \ - log_failure( "gen::" stringize(Context_) ": name is null" ); \ - return InvalidCode; \ - } \ -} - -#define null_check( Context_, Code_ ) \ - if ( Code_ == nullptr ) \ - { \ - log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \ - return InvalidCode; \ +forceinline +bool name__check( char const* context, StrC name ) +{ + if ( name.Len <= 0 ) { + log_failure( "gen::%s: Invalid name length provided - %d", name.Len ); + return false; } - -#define null_or_invalid_check( Context_, Code_ ) \ -{ \ - if ( ! Code_ ) \ - { \ - log_failure( "gen::" stringize(Context_) ": " stringize(Code_) " provided is null" ); \ - return InvalidCode; \ - } \ - \ - if ( Code_->is_invalid() ) \ - { \ - log_failure("gen::" stringize(Context_) ": " stringize(Code_) " provided is invalid" ); \ - return InvalidCode; \ - } \ + if ( name.Ptr == nullptr ) { + log_failure( "gen::%s: name is null" ); + return false; + } + return true; } +#define name_check( context, name ) name__check( #context, name ) -#define not_implemented( Context_ ) \ - log_failure( "gen::%s: This function is not implemented" ); \ - return InvalidCode; -#pragma endregion Helper Marcos +forceinline +bool null__check( char const* context, char const* code_id, Code code ) { + if ( code == nullptr ) { + log_failure( "gen::%s: %s provided is null", context, code_id ); + return false; + } + return true; +} +#define null_check( context, code ) null__check( #context, #code, cast(Code, code) ) /* The implementaiton of the upfront constructors involves doing three things: @@ -431,18 +411,16 @@ The library validates a good protion of their form and thus the argument process */ CodeAttributes def_attributes( StrC content ) { - if ( content.Len <= 0 || content.Ptr == nullptr ) - { + if ( content.Len <= 0 || content.Ptr == nullptr ) { log_failure( "gen::def_attributes: Invalid attributes provided" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - Code result = make_code(); result->Type = CT_PlatformAttributes; result->Name = get_cached_string( content ); result->Content = result->Name; - return (CodeAttributes) result; } @@ -451,6 +429,7 @@ CodeComment def_comment( StrC content ) if ( content.Len <= 0 || content.Ptr == nullptr ) { log_failure( "gen::def_comment: Invalid comment provided:" ); + GEN_DEBUG_TRAP(); return InvalidCode; } @@ -497,150 +476,113 @@ CodeComment def_comment( StrC content ) CodeConstructor def_constructor( Opts_def_constructor p ) { - CodeParams params = p.params; - Code initializer_list = p.initializer_list; - Code body = p.body; - - if ( params && params->Type != CT_Parameters ) - { - log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)params)); + if ( p.params && p.params->Type != CT_Parameters ) { + log_failure("gen::def_constructor: params must be of Parameters type - %s", code_debug_str((Code)p.params)); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeConstructor - result = (CodeConstructor) make_code(); - - if ( params ) - { - result->Params = params; + CodeConstructor result = (CodeConstructor) make_code(); + if ( p.params ) { + result->Params = p.params; } - - if ( initializer_list ) - { - result->InitializerList = initializer_list; + if ( p.initializer_list ) { + result->InitializerList = p.initializer_list; } - - if ( body ) + if ( p.body ) { - switch ( body->Type ) - { + switch ( p.body->Type ) { case CT_Function_Body: case CT_Untyped: break; default: - log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", code_debug_str(body)); + log_failure("gen::def_constructor: body must be either of Function_Body or Untyped type - %s", code_debug_str(p.body)); return InvalidCode; } result->Type = CT_Constructor; - result->Body = body; + result->Body = p.body; } else { result->Type = CT_Constructor_Fwd; } - return result; } CodeClass def_class( StrC name, Opts_def_struct p ) { - name_check( def_class, name ); - - CodeBody body = p.body; - CodeTypename parent = p.parent; - AccessSpec parent_access = p.parent_access; - CodeAttributes attributes = p.attributes; - ModuleFlag mflags = p.mflags; - CodeTypename* interfaces = p.interfaces; - s32 num_interfaces = p.num_interfaces; - - if ( attributes && attributes->Type != CT_PlatformAttributes ) - { - log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(attributes) ); + if ( ! name_check( def_class, name ) ) { + GEN_DEBUG_TRAP(); return InvalidCode; } - if ( parent && ( parent->Type != CT_Class && parent->Type != CT_Struct && parent->Type != CT_Typename && parent->Type != CT_Untyped ) ) - { - log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", code_debug_str(parent) ); + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { + log_failure( "gen::def_class: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(p.attributes) ); + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( p.parent && ( p.parent->Type != CT_Class && p.parent->Type != CT_Struct && p.parent->Type != CT_Typename && p.parent->Type != CT_Untyped ) ) { + log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", code_debug_str(p.parent) ); + GEN_DEBUG_TRAP(); return InvalidCode; } CodeClass result = (CodeClass) make_code(); result->Name = get_cached_string( name ); - result->ModuleFlags = mflags; - - if ( body ) + result->ModuleFlags = p.mflags; + if ( p.body ) { - switch ( body->Type ) + switch ( p.body->Type ) { case CT_Class_Body: case CT_Untyped: break; default: - log_failure("gen::def_class: body must be either of Class_Body or Untyped type - %s", code_debug_str(body)); + log_failure("gen::def_class: body must be either of Class_Body or Untyped type - %s", code_debug_str(p.body)); return InvalidCode; } - result->Type = CT_Class; - result->Body = body; - result->Body->Parent = cast(Code, result); // TODO(Ed): Review this? + result->Type = CT_Class; + result->Body = p.body; + result->Body->Parent = cast(Code, result); } - else - { + else { result->Type = CT_Class_Fwd; } - if ( attributes ) - result->Attributes = attributes; + result->Attributes = p.attributes; + result->ParentAccess = p.parent_access; + result->ParentType = p.parent; - if ( parent ) - { - result->ParentAccess = parent_access; - result->ParentType = parent; + for (s32 idx = 0; idx < p.num_interfaces; idx++ ) { + class_add_interface(result, p.interfaces[idx] ); } - - if ( interfaces ) - { - for (s32 idx = 0; idx < num_interfaces; idx++ ) - { - class_add_interface(result, interfaces[idx] ); - } - } - return result; } CodeDefine def_define( StrC name, StrC content, Opts_def_define p ) { - name_check( def_define, name ); - - // Defines can be empty definitions -#if 0 - if ( content.Len <= 0 || content.Ptr == nullptr ) - { - log_failure( "gen::def_define: Invalid value provided" ); + if ( ! name_check( def_define, name ) ) { + GEN_DEBUG_TRAP(); return InvalidCode; } -#endif CodeDefine result = (CodeDefine) make_code(); result->Type = CT_Preprocess_Define; result->Name = get_cached_string( name ); + if ( content.Len <= 0 || content.Ptr == nullptr ) - { result->Content = get_cached_string( txt("") ); - } else result->Content = get_cached_string( string_to_strc(string_fmt_buf(GlobalAllocator, "%SC\n", content)) ); - b32 append_preprocess_defines = ! p.dont_append_preprocess_defines; - if ( append_preprocess_defines ) { + b32 append_preprocess_defines = ! p.dont_append_preprocess_defines; + if ( append_preprocess_defines ) { // Add the define to PreprocessorDefines for usage in parsing s32 lex_id_len = 0; for (; lex_id_len < result->Name.Len; ++ lex_id_len ) { @@ -655,157 +597,138 @@ CodeDefine def_define( StrC name, StrC content, Opts_def_define p ) CodeDestructor def_destructor( Opts_def_destructor p ) { - Code body = p.body; - CodeSpecifiers specifiers = p.specifiers; - - if ( specifiers && specifiers->Type != CT_Specifiers ) - { - log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", code_debug_str(specifiers) ); + if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) { + log_failure( "gen::def_destructor: specifiers was not a 'Specifiers' type: %s", code_debug_str(p.specifiers) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeDestructor result = (CodeDestructor) make_code(); - - if ( specifiers ) - result->Specs = specifiers; - - if ( body ) + CodeDestructor + result = (CodeDestructor) make_code(); + result->Specs = p.specifiers; + if ( p.body ) { - switch ( body->Type ) + switch ( p.body->Type ) { case CT_Function_Body: case CT_Untyped: break; default: - log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", code_debug_str(body)); + log_failure("gen::def_destructor: body must be either of Function_Body or Untyped type - %s", code_debug_str(p.body)); return InvalidCode; } result->Type = CT_Destructor; - result->Body = body; + result->Body = p.body; } else { result->Type = CT_Destructor_Fwd; } - return result; } CodeEnum def_enum( StrC name, Opts_def_enum p ) { - CodeBody body = p.body; - CodeTypename type = p.type; - EnumT specifier = p.specifier; - CodeAttributes attributes = p.attributes; - ModuleFlag mflags = p.mflags; - Code type_macro = p.type_macro; - - name_check( def_enum, name ); - - if ( type && type->Type != CT_Typename ) - { - log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", code_debug_str((Code)type) ); + if ( ! name_check( def_enum, name ) ) { + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( attributes && attributes->Type != CT_PlatformAttributes ) - { - log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", code_debug_str((Code)attributes) ); + if ( p.type && p.type->Type != CT_Typename ) { + log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", code_debug_str(p.type) ); + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { + log_failure( "gen::def_enum: attributes was not a 'PlatformAttributes' type: %s", code_debug_str(p.attributes) ); + GEN_DEBUG_TRAP(); return InvalidCode; } CodeEnum result = (CodeEnum) make_code(); result->Name = get_cached_string( name ); - result->ModuleFlags = mflags; - - if ( body ) + result->ModuleFlags = p.mflags; + if ( p.body ) { - switch ( body->Type ) + switch ( p.body->Type ) { case CT_Enum_Body: case CT_Untyped: break; default: - log_failure( "gen::def_enum: body must be of Enum_Body or Untyped type %s", code_debug_str(body)); + log_failure( "gen::def_enum: body must be of Enum_Body or Untyped type %s", code_debug_str(p.body)); return InvalidCode; } - result->Type = specifier == EnumDecl_Class ? + result->Type = p.specifier == EnumDecl_Class ? CT_Enum_Class : CT_Enum; - result->Body = body; + result->Body = p.body; } else { - result->Type = specifier == EnumDecl_Class ? + result->Type = p.specifier == EnumDecl_Class ? CT_Enum_Class_Fwd : CT_Enum_Fwd; } + result->Attributes = p.attributes; - if ( attributes ) - result->Attributes = attributes; - - if ( type ) - { - result->UnderlyingType = type; + if ( p.type ) { + result->UnderlyingType = p.type; } - else if ( type_macro ) - { - result->UnderlyingTypeMacro = type_macro; + else if ( p.type_macro ) { + result->UnderlyingTypeMacro = p.type_macro; } else if ( result->Type != CT_Enum_Class_Fwd && result->Type != CT_Enum_Fwd ) { log_failure( "gen::def_enum: enum forward declaration must have an underlying type" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - return result; } CodeExec def_execution( StrC content ) { - if ( content.Len <= 0 || content.Ptr == nullptr ) - { + if ( content.Len <= 0 || content.Ptr == nullptr ) { log_failure( "gen::def_execution: Invalid execution provided" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - Code - result = make_code(); + CodeExec + result = (CodeExec) make_code(); result->Type = CT_Execution; - result->Name = get_cached_string( content ); - result->Content = result->Name; - - return (CodeExec) result; + result->Content = get_cached_string( content ); + return result; } CodeExtern def_extern_link( StrC name, CodeBody body ) { - name_check( def_extern_linkage, name ); - null_check( def_extern_linkage, body ); - - if ( body->Type != CT_Extern_Linkage_Body && body->Type != CT_Untyped ) - { - log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", code_debug_str(body)); + if ( ! name_check(def_extern_link, name) || ! null_check(def_extern_link, body) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( body->Type != CT_Extern_Linkage_Body && body->Type != CT_Untyped ) { + log_failure("gen::def_extern_linkage: body is not of extern_linkage or untyped type %s", code_debug_str(body)); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeExtern result = (CodeExtern)make_code(); result->Type = CT_Extern_Linkage; result->Name = get_cached_string( name ); result->Body = body; - - return (CodeExtern) result; + return result; } CodeFriend def_friend( Code declaration ) { - null_check( def_friend, declaration ); - + if ( ! null_check( def_friend, declaration ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } switch ( declaration->Type ) { case CT_Class_Fwd: @@ -822,59 +745,47 @@ CodeFriend def_friend( Code declaration ) log_failure("gen::def_friend: requires declartion to have class, function, operator, or struct - %s", code_debug_str(declaration)); return InvalidCode; } - CodeFriend - result = (CodeFriend) make_code(); - result->Type = CT_Friend; - + result = (CodeFriend) make_code(); + result->Type = CT_Friend; result->Declaration = declaration; - return result; } CodeFn def_function( StrC name, Opts_def_function p ) { - CodeParams params = p.params; - CodeTypename ret_type = p.ret_type; - CodeBody body = p.body; - CodeSpecifiers specifiers = p.specs; - CodeAttributes attributes = p.attrs; - ModuleFlag mflags = p.mflags; - - name_check( def_function, name ); - - if ( params && params->Type != CT_Parameters ) - { - log_failure( "gen::def_function: params was not a `Parameters` type: %s", code_debug_str(params) ); + if ( ! name_check( def_function, name )) { + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( ret_type && ret_type->Type != CT_Typename ) - { - log_failure( "gen::def_function: ret_type was not a Typename: %s", code_debug_str(ret_type) ); + if ( p.params && p.params->Type != CT_Parameters ) { + log_failure( "gen::def_function: params was not a `Parameters` type: %s", code_debug_str(p.params) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( specifiers && specifiers->Type != CT_Specifiers ) - { - log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", code_debug_str(specifiers) ); + if ( p.ret_type && p.ret_type->Type != CT_Typename ) { + log_failure( "gen::def_function: ret_type was not a Typename: %s", code_debug_str(p.ret_type) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( attributes && attributes->Type != CT_PlatformAttributes ) - { - log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", code_debug_str(attributes) ); + if ( p.specs && p.specs-> Type != CT_Specifiers ) { + log_failure( "gen::def_function: specifiers was not a `Specifiers` type: %s", code_debug_str(p.specs) ); + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( p.attrs && p.attrs->Type != CT_PlatformAttributes ) { + log_failure( "gen::def_function: attributes was not a `PlatformAttributes` type: %s", code_debug_str(p.attrs) ); + GEN_DEBUG_TRAP(); return InvalidCode; } CodeFn result = (CodeFn) make_code(); result->Name = get_cached_string( name ); - result->ModuleFlags = mflags; - - if ( body ) + result->ModuleFlags = p.mflags; + if ( p.body ) { - switch ( body->Type ) + switch ( p.body->Type ) { case CT_Function_Body: case CT_Execution: @@ -883,86 +794,72 @@ CodeFn def_function( StrC name, Opts_def_function p ) default: { - log_failure("gen::def_function: body must be either of Function_Body, Execution, or Untyped type. %s", code_debug_str(body)); + log_failure("gen::def_function: body must be either of Function_Body, Execution, or Untyped type. %s", code_debug_str(p.body)); return InvalidCode; } } - result->Type = CT_Function; - result->Body = body; + result->Body = p.body; } else { result->Type = CT_Function_Fwd; } - - if ( attributes ) - result->Attributes = attributes; - - if ( specifiers ) - result->Specs = specifiers; - - if ( ret_type ) - { - result->ReturnType = ret_type; - } - else - { - result->ReturnType = t_void; - } - - if ( params ) - result->Params = params; - + result->Attributes = p.attrs; + result->Specs = p.specs; + result->Params = p.params; + result->ReturnType = p.ret_type ? p.ret_type : t_void; return result; } CodeInclude def_include( StrC path, Opts_def_include p ) { - if ( path.Len <= 0 || path.Ptr == nullptr ) - { + if ( path.Len <= 0 || path.Ptr == nullptr ) { log_failure( "gen::def_include: Invalid path provided - %d" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - String content = p.foreign ? string_fmt_buf( GlobalAllocator, "<%.*s>", path.Len, path.Ptr ) : string_fmt_buf( GlobalAllocator, "\"%.*s\"", path.Len, path.Ptr ); - Code - result = make_code(); + CodeInclude + result = (CodeInclude) make_code(); result->Type = CT_Preprocess_Include; result->Name = get_cached_string( string_to_strc(content) ); result->Content = result->Name; - - return (CodeInclude) result; + return result; } CodeModule def_module( StrC name, Opts_def_module p ) { - name_check( def_module, name ); - - Code - result = make_code(); + if ( ! name_check( def_module, name )) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + CodeModule + result = (CodeModule) make_code(); result->Type = CT_Module; result->Name = get_cached_string( name ); - result->Content = result->Name; result->ModuleFlags = p.mflags; - - return (CodeModule) result; + return result; } CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace p ) { - name_check( def_namespace, name ); - null_check( def_namespace, body); - - if ( body && body->Type != CT_Namespace_Body && body->Type != CT_Untyped ) - { - log_failure("gen::def_namespace: body is not of namespace or untyped type %s", code_debug_str(body)); + if ( ! name_check( def_namespace, name )) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( ! null_check( def_namespace, body)) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( body && body->Type != CT_Namespace_Body && body->Type != CT_Untyped ) { + log_failure("gen::def_namespace: body is not of namespace or untyped type %s", code_debug_str(body)); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeNS result = (CodeNS) make_code(); result->Type = CT_Namespace; @@ -974,29 +871,19 @@ CodeNS def_namespace( StrC name, CodeBody body, Opts_def_namespace p ) CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p ) { - CodeParams params_code = p.params; - CodeTypename ret_type = p.ret_type; - CodeBody body = p.body; - CodeSpecifiers specifiers = p.specifiers; - CodeAttributes attributes = p.attributes; - ModuleFlag mflags = p.mflags; - - if ( attributes && attributes->Type != CT_PlatformAttributes ) - { - log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", code_debug_str(attributes) ); + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { + log_failure( "gen::def_operator: PlatformAttributes was provided but its not of attributes type: %s", code_debug_str(p.attributes) ); + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) { + log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", code_debug_str(p.specifiers) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - if ( specifiers && specifiers->Type != CT_Specifiers ) - { - log_failure( "gen::def_operator: Specifiers was provided but its not of specifiers type: %s", code_debug_str(specifiers) ); - return InvalidCode; - } - - OpValidateResult check_result = operator__validate( op, params_code, ret_type, specifiers ); - - if ( check_result == OpValResult_Fail ) - { + OpValidateResult check_result = operator__validate( op, p.params, p.ret_type, p.specifiers ); + if ( check_result == OpValResult_Fail ) { return InvalidCode; } @@ -1013,12 +900,11 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p ) CodeOperator result = (CodeOperator) make_code(); result->Name = get_cached_string( name_resolved ); - result->ModuleFlags = mflags; + result->ModuleFlags = p.mflags; result->Op = op; - - if ( body ) + if ( p.body ) { - switch ( body->Type ) + switch ( p.body->Type ) { case CT_Function_Body: case CT_Execution: @@ -1027,7 +913,8 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p ) default: { - log_failure("gen::def_operator: body must be either of Function_Body, Execution, or Untyped type. %s", code_debug_str(body)); + log_failure("gen::def_operator: body must be either of Function_Body, Execution, or Untyped type. %s", code_debug_str(p.body)); + GEN_DEBUG_TRAP(); return InvalidCode; } } @@ -1035,129 +922,101 @@ CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p ) result->Type = check_result == OpValResult_Global ? CT_Operator : CT_Operator_Member; - result->Body = body; + result->Body = p.body; } else { result->Type = check_result == OpValResult_Global ? CT_Operator_Fwd : CT_Operator_Member_Fwd; } - - if ( attributes ) - result->Attributes = attributes; - - if ( specifiers ) - result->Specs = specifiers; - - result->ReturnType = ret_type; - - if (params_code) - result->Params = params_code; - + result->Attributes = p.attributes; + result->Specs = p.specifiers; + result->ReturnType = p.ret_type; + result->Params = p.params; return result; } CodeOpCast def_operator_cast( CodeTypename type, Opts_def_operator_cast p ) { - CodeBody body = p.body; - CodeSpecifiers const_spec = p.specs; - - null_check( def_operator_cast, type ); - - if ( type->Type != CT_Typename ) - { + if ( ! null_check( def_operator_cast, type )) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( type->Type != CT_Typename ) { log_failure( "gen::def_operator_cast: type is not a typename - %s", code_debug_str(type) ); + GEN_DEBUG_TRAP(); return InvalidCode; } CodeOpCast result = (CodeOpCast) make_code(); - - if (body) + if (p.body) { result->Type = CT_Operator_Cast; - if ( body->Type != CT_Function_Body && body->Type != CT_Execution ) - { - log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", code_debug_str(body) ); + if ( p.body->Type != CT_Function_Body && p.body->Type != CT_Execution ) { + log_failure( "gen::def_operator_cast: body is not of function body or execution type - %s", code_debug_str(p.body) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - result->Body = body; + result->Body = p.body; } else { result->Type = CT_Operator_Cast_Fwd; } - - if ( const_spec ) - { - result->Specs = const_spec; - } - + result->Specs = p.specs; result->ValueType = type; return result; } CodeParams def_param( CodeTypename type, StrC name, Opts_def_param p ) { - name_check( def_param, name ); - null_check( def_param, type ); - - if ( type->Type != CT_Typename ) - { + if ( ! name_check( def_param, name ) || ! null_check( def_param, type ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( type->Type != CT_Typename ) { log_failure( "gen::def_param: type is not a typename - %s", code_debug_str(type) ); return InvalidCode; } - - if ( p.value && p.value->Type != CT_Untyped ) - { + if ( p.value && p.value->Type != CT_Untyped ) { log_failure( "gen::def_param: value is not untyped - %s", code_debug_str(p.value) ); return InvalidCode; } - CodeParams - result = (CodeParams) make_code(); - result->Type = CT_Parameters; - result->Name = get_cached_string( name ); - + result = (CodeParams) make_code(); + result->Type = CT_Parameters; + result->Name = get_cached_string( name ); result->ValueType = type; - - if ( p.value ) - result->Value = p.value; - + result->Value = p.value; result->NumEntries++; - return result; } CodePragma def_pragma( StrC directive ) { - if ( directive.Len <= 0 || directive.Ptr == nullptr ) - { + if ( directive.Len <= 0 || directive.Ptr == nullptr ) { log_failure( "gen::def_comment: Invalid comment provided:" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodePragma result = (CodePragma) make_code(); result->Type = CT_Preprocess_Pragma; result->Content = get_cached_string( directive ); - return result; } CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr ) { - if ( expr.Len <= 0 || expr.Ptr == nullptr ) - { + if ( expr.Len <= 0 || expr.Ptr == nullptr ) { log_failure( "gen::def_comment: Invalid comment provided:" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodePreprocessCond result = (CodePreprocessCond) make_code(); result->Content = get_cached_string( expr ); - switch (type) { case PreprocessCond_If: @@ -1173,7 +1032,6 @@ CodePreprocessCond def_preprocess_cond( EPreprocessCond type, StrC expr ) result->Type = CT_Preprocess_ElIf; break; } - return result; } @@ -1183,85 +1041,61 @@ CodeSpecifiers def_specifier( Specifier spec ) result = (CodeSpecifiers) make_code(); result->Type = CT_Specifiers; specifiers_append(result, spec ); - return result; } CodeStruct def_struct( StrC name, Opts_def_struct p ) { - CodeBody body = p.body; - CodeTypename parent = p.parent; - AccessSpec parent_access = p.parent_access; - CodeAttributes attributes = p.attributes; - ModuleFlag mflags = p.mflags; - CodeTypename* interfaces = p.interfaces; - s32 num_interfaces = p.num_interfaces; - - if ( attributes && attributes->Type != CT_PlatformAttributes ) - { - log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, attributes)) ); + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { + log_failure( "gen::def_struct: attributes was not a `PlatformAttributes` type - %s", code_debug_str(cast(Code, p.attributes)) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( parent && parent->Type != CT_Typename ) - { - log_failure( "gen::def_struct: parent was not a `Struct` type - %s", code_debug_str(parent) ); + if ( p.parent && p.parent->Type != CT_Typename ) { + log_failure( "gen::def_struct: parent was not a `Struct` type - %s", code_debug_str(p.parent) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( body && body->Type != CT_Struct_Body ) - { - log_failure( "gen::def_struct: body was not a Struct_Body type - %s", code_debug_str(body) ); + if ( p.body && p.body->Type != CT_Struct_Body ) { + log_failure( "gen::def_struct: body was not a Struct_Body type - %s", code_debug_str(p.body) ); + GEN_DEBUG_TRAP(); return InvalidCode; } CodeStruct result = (CodeStruct) make_code(); - result->ModuleFlags = mflags; - + result->ModuleFlags = p.mflags; if ( name.Len ) result->Name = get_cached_string( name ); - if ( body ) - { + if ( p.body ) { result->Type = CT_Struct; - result->Body = body; + result->Body = p.body; } - else - { + else { result->Type = CT_Struct_Fwd; } + result->Attributes = p.attributes; + result->ParentAccess = p.parent_access; + result->ParentType = p.parent; - if ( attributes ) - result->Attributes = attributes; - - if ( parent ) - { - result->ParentAccess = parent_access; - result->ParentType = parent; + for (s32 idx = 0; idx < p.num_interfaces; idx++ ) { + struct_add_interface(result, p.interfaces[idx] ); } - - if ( interfaces ) - { - for (s32 idx = 0; idx < num_interfaces; idx++ ) - { - struct_add_interface(result, interfaces[idx] ); - } - } - return result; } CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_template p ) { - null_check( def_template, declaration ); - - if ( params && params->Type != CT_Parameters ) - { - log_failure( "gen::def_template: params is not of parameters type - %s", code_debug_str(params) ); + if ( ! null_check( def_template, declaration ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( params && params->Type != CT_Parameters ){ + log_failure( "gen::def_template: params is not of parameters type - %s", code_debug_str(params) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - switch (declaration->Type ) { case CT_Class: @@ -1274,7 +1108,6 @@ CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_templat default: log_failure( "gen::def_template: declaration is not of class, function, struct, variable, or using type - %s", code_debug_str(declaration) ); } - CodeTemplate result = (CodeTemplate) make_code(); result->Type = CT_Template; @@ -1286,53 +1119,45 @@ CodeTemplate def_template( CodeParams params, Code declaration, Opts_def_templat CodeTypename def_type( StrC name, Opts_def_type p ) { - name_check( def_type, name ); - + if ( ! name_check( def_type, name )) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } Code arrayexpr = p.arrayexpr; CodeSpecifiers specifiers = p.specifiers; CodeAttributes attributes = p.attributes; - - if ( attributes && attributes->Type != CT_PlatformAttributes ) - { - log_failure( "gen::def_type: attributes is not of attributes type - %s", code_debug_str((Code)attributes) ); + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { + log_failure( "gen::def_type: attributes is not of attributes type - %s", code_debug_str((Code)p.attributes) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( specifiers && specifiers->Type != CT_Specifiers ) - { - log_failure( "gen::def_type: specifiers is not of specifiers type - %s", code_debug_str((Code)specifiers) ); + if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) { + log_failure( "gen::def_type: specifiers is not of specifiers type - %s", code_debug_str((Code)p.specifiers) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( arrayexpr && arrayexpr->Type != CT_Untyped ) - { - log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)arrayexpr) ); + if ( p.arrayexpr && p.arrayexpr->Type != CT_Untyped ) { + log_failure( "gen::def_type: arrayexpr is not of untyped type - %s", code_debug_str((Code)p.arrayexpr) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeTypename - result = (CodeTypename) make_code(); - result->Name = get_cached_string( name ); - result->Type = CT_Typename; - - if ( attributes ) - result->Attributes = attributes; - - if ( specifiers ) - result->Specs = specifiers; - - if ( arrayexpr ) - result->ArrExpr = arrayexpr; - - result->TypeTag = p.type_tag; - + result = (CodeTypename) make_code(); + result->Name = get_cached_string( name ); + result->Type = CT_Typename; + result->Attributes = p.attributes; + result->Specs = p.specifiers; + result->ArrExpr = p.arrayexpr; + result->TypeTag = p.type_tag; return result; } CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p ) { - null_check( def_typedef, type ); - + if ( ! null_check( def_typedef, type ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } switch ( type->Type ) { case CT_Class: @@ -1349,39 +1174,36 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p ) break; default: log_failure( "gen::def_typedef: type was not a Class, Enum, Function Forward, Struct, Typename, or Union - %s", code_debug_str((Code)type) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) - { + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { log_failure( "gen::def_typedef: attributes was not a PlatformAttributes - %s", code_debug_str((Code)p.attributes) ); + GEN_DEBUG_TRAP(); return InvalidCode; } // Registering the type. CodeTypename registered_type = def_type( name ); - - if ( ! registered_type ) - { + if ( ! registered_type ) { log_failure( "gen::def_typedef: failed to register type" ); + GEN_DEBUG_TRAP(); return InvalidCode; } CodeTypedef - result = (CodeTypedef) make_code(); - result->Type = CT_Typedef; - result->ModuleFlags = p.mflags; - + result = (CodeTypedef) make_code(); + result->Type = CT_Typedef; + result->ModuleFlags = p.mflags; result->UnderlyingType = type; if ( name.Len <= 0 ) { - if (type->Type != CT_Untyped) - { + if (type->Type != CT_Untyped) { log_failure( "gen::def_typedef: name was empty and type was not untyped (indicating its a function typedef) - %s", code_debug_str(type) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - result->Name = get_cached_string( type->Name ); result->IsFunction = true; } @@ -1390,134 +1212,112 @@ CodeTypedef def_typedef( StrC name, Code type, Opts_def_typedef p ) result->Name = get_cached_string( name ); result->IsFunction = false; } - return result; } CodeUnion def_union( StrC name, CodeBody body, Opts_def_union p ) { - null_check( def_union, body ); - - if ( body->Type != CT_Union_Body ) - { + if ( ! null_check( def_union, body ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + if ( body->Type != CT_Union_Body ) { log_failure( "gen::def_union: body was not a Union_Body type - %s", code_debug_str(body) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) - { + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { log_failure( "gen::def_union: attributes was not a PlatformAttributes type - %s", code_debug_str(p.attributes) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeUnion result = (CodeUnion) make_code(); result->ModuleFlags = p.mflags; result->Type = CT_Union; - + result->Body = body; + result->Attributes = p.attributes; if ( name.Ptr ) result->Name = get_cached_string( name ); - - result->Body = body; - - if ( p.attributes ) - result->Attributes = p.attributes; - return result; } CodeUsing def_using( StrC name, CodeTypename type, Opts_def_using p ) { - name_check( def_using, name ); - null_check( def_using, type ); + if ( ! name_check( def_using, name ) || null_check( def_using, type ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } CodeTypename register_type = def_type( name ); - - if ( ! register_type ) - { + if ( ! register_type ) { log_failure( "gen::def_using: failed to register type" ); + GEN_DEBUG_TRAP(); return InvalidCode; } - - if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) - { + if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { log_failure( "gen::def_using: attributes was not a PlatformAttributes type - %s", code_debug_str(p.attributes) ); + GEN_DEBUG_TRAP(); return InvalidCode; } - CodeUsing - result = (CodeUsing) make_code(); - result->Name = get_cached_string( name ); - result->ModuleFlags = p.mflags; - result->Type = CT_Using; - + result = (CodeUsing) make_code(); + result->Name = get_cached_string( name ); + result->ModuleFlags = p.mflags; + result->Type = CT_Using; result->UnderlyingType = type; - - if ( p.attributes ) - result->Attributes = p.attributes; - + result->Attributes = p.attributes; return result; } CodeUsing def_using_namespace( StrC name ) { - name_check( def_using_namespace, name ); - - Code - result = make_code(); + if ( ! name_check( def_using_namespace, name ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } + CodeUsing + result = (CodeUsing) make_code(); result->Name = get_cached_string( name ); - result->Content = result->Name; result->Type = CT_Using_Namespace; - - return (CodeUsing) result; + return result; } CodeVar def_variable( CodeTypename type, StrC name, Opts_def_variable p ) { - name_check( def_variable, name ); - null_check( def_variable, type ); - + if ( ! name_check( def_variable, name ) || null_check( def_variable, type ) ) { + GEN_DEBUG_TRAP(); + return InvalidCode; + } if ( p.attributes && p.attributes->Type != CT_PlatformAttributes ) { log_failure( "gen::def_variable: attributes was not a `PlatformAttributes` type - %s", code_debug_str(p.attributes) ); return InvalidCode; } - if ( p.specifiers && p.specifiers->Type != CT_Specifiers ) { log_failure( "gen::def_variable: specifiers was not a `Specifiers` type - %s", code_debug_str(p.specifiers) ); return InvalidCode; } - if ( type->Type != CT_Typename ) { log_failure( "gen::def_variable: type was not a Typename - %s", code_debug_str(type) ); return InvalidCode; } - if ( p.value && p.value->Type != CT_Untyped ) { log_failure( "gen::def_variable: value was not a `Untyped` type - %s", code_debug_str(p.value) ); return InvalidCode; } - CodeVar result = (CodeVar) make_code(); result->Name = get_cached_string( name ); result->Type = CT_Variable; result->ModuleFlags = p.mflags; - - result->ValueType = type; - - if ( p.attributes ) - result->Attributes = p.attributes; - - if ( p.specifiers ) - result->Specs = p.specifiers; - - if ( p.value ) - result->Value = p.value; - + result->ValueType = type; + result->Attributes = p.attributes; + result->Specs = p.specifiers; + result->Value = p.value; return result; } @@ -1568,7 +1368,7 @@ CodeBody def_class_body( s32 num, ... ) switch (entry->Type) { - GEN_AST_BODY_CLASS_UNALLOWED_TYPES + GEN_AST_BODY_CLASS_UNALLOWED_TYPES: log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1605,7 +1405,7 @@ CodeBody def_class_body( s32 num, Code* codes ) switch (entry->Type) { - GEN_AST_BODY_CLASS_UNALLOWED_TYPES + GEN_AST_BODY_CLASS_UNALLOWED_TYPES: log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1709,7 +1509,7 @@ CodeBody def_export_body( s32 num, ... ) switch (entry->Type) { - GEN_AST_BODY_EXPORT_UNALLOWED_TYPES + GEN_AST_BODY_EXPORT_UNALLOWED_TYPES: log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1746,7 +1546,7 @@ CodeBody def_export_body( s32 num, Code* codes ) switch (entry->Type) { - GEN_AST_BODY_EXPORT_UNALLOWED_TYPES + GEN_AST_BODY_EXPORT_UNALLOWED_TYPES: log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1784,7 +1584,7 @@ CodeBody def_extern_link_body( s32 num, ... ) switch (entry->Type) { - GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES + GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES: log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1821,7 +1621,7 @@ CodeBody def_extern_link_body( s32 num, Code* codes ) switch (entry->Type) { - GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES + GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES: log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1860,7 +1660,7 @@ CodeBody def_function_body( s32 num, ... ) switch (entry->Type) { - GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES + GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES: log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1897,7 +1697,7 @@ CodeBody def_function_body( s32 num, Code* codes ) switch (entry->Type) { - GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES + GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES: log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1939,7 +1739,7 @@ CodeBody def_global_body( s32 num, ... ) body_append_body( result, cast(CodeBody, entry) ); continue; - GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES + GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES: log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -1980,7 +1780,7 @@ CodeBody def_global_body( s32 num, Code* codes ) body_append_body(result, cast(CodeBody, entry) ); continue; - GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES + GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES: log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -2018,7 +1818,7 @@ CodeBody def_namespace_body( s32 num, ... ) switch (entry->Type) { - GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES + GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES: log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -2055,7 +1855,7 @@ CodeBody def_namespace_body( s32 num, Code* codes ) switch (entry->Type) { - GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES + GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES: log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", code_debug_str(entry) ); return InvalidCode; @@ -2227,7 +2027,7 @@ CodeBody def_struct_body( s32 num, ... ) switch (entry->Type) { - GEN_AST_BODY_STRUCT_UNALLOWED_TYPES + GEN_AST_BODY_STRUCT_UNALLOWED_TYPES: log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", code_debug_str(entry)); return InvalidCode; @@ -2264,7 +2064,7 @@ CodeBody def_struct_body( s32 num, Code* codes ) switch (entry->Type) { - GEN_AST_BODY_STRUCT_UNALLOWED_TYPES + GEN_AST_BODY_STRUCT_UNALLOWED_TYPES: log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", code_debug_str(entry) ); return InvalidCode; @@ -2347,7 +2147,6 @@ CodeBody def_union_body( s32 num, Code* codes ) # undef name_check # undef null_check -# undef null_or_invalid_check # undef def_body_start # undef def_body_code_array_start diff --git a/base/components/parser.cpp b/base/components/parser.cpp index c93aafc..c746c6c 100644 --- a/base/components/parser.cpp +++ b/base/components/parser.cpp @@ -32,14 +32,14 @@ void parser_push( ParseContext* ctx, StackNode* node ) node->Prev = ctx->Scope; ctx->Scope = node; -#if 0 && Build_Debug +#if 0 && GEN_BUILD_DEBUG log_fmt("\tEntering Context: %.*s\n", Scope->ProcName.Len, Scope->ProcName.Ptr ); #endif } void parser_pop(ParseContext* ctx) { -#if 0 && Build_Debug +#if 0 && GEN_BUILD_DEBUG log_fmt("\tPopping Context: %.*s\n", Scope->ProcName.Len, Scope->ProcName.Ptr ); #endif ctx->Scope = ctx->Scope->Prev; @@ -128,7 +128,7 @@ bool lex__eat(TokArray* self, TokType type ) return false; } -#if 0 && Build_Debug +#if 0 && GEN_BUILD_DEBUG log_fmt("Ate: %S\n", self->Arr[Idx].to_string() ); #endif @@ -1796,8 +1796,9 @@ CodeBody parse_global_nspace( CodeType which ) break; case Tok_Module_Import: { - not_implemented( context ); // import ... + log_failure( "gen::%s: This function is not implemented" ); + return InvalidCode; } //! Fallthrough intentional case Tok_Attribute_Open: @@ -5580,11 +5581,10 @@ CodeVar parser_parse_variable() return result; } - internal CodeTypename parser_parse_type_alt( bool from_template, bool* typedef_is_functon ) { - + return InvalidCode; } GEN_NS_PARSER_END diff --git a/base/dependencies/debug.hpp b/base/dependencies/debug.hpp index 06b5ea6..a7e0da3 100644 --- a/base/dependencies/debug.hpp +++ b/base/dependencies/debug.hpp @@ -8,16 +8,20 @@ #pragma region Debug -#if defined( _MSC_VER ) -# if _MSC_VER < 1300 -# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */ +#if GEN_BUILD_DEBUG +# if defined( GEN_COMPILER_MSVC ) +# if _MSC_VER < 1300 +# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */ +# else +# define GEN_DEBUG_TRAP() __debugbreak() +# endif +# elif defined( GEN_COMPILER_TINYC ) +# define GEN_DEBUG_TRAP() process_exit( 1 ) # else -# define GEN_DEBUG_TRAP() __debugbreak() +# define GEN_DEBUG_TRAP() __builtin_trap() # endif -#elif defined( GEN_COMPILER_TINYC ) -# define GEN_DEBUG_TRAP() process_exit( 1 ) #else -# define GEN_DEBUG_TRAP() __builtin_trap() +# define GEN_DEBUG_TRAP() #endif #define GEN_ASSERT( cond ) GEN_ASSERT_MSG( cond, NULL ) @@ -37,7 +41,7 @@ // NOTE: Things that shouldn't happen with a message! #define GEN_PANIC( msg, ... ) GEN_ASSERT_MSG( 0, msg, ##__VA_ARGS__ ) -#if Build_Debug +#if GEN_BULD_DEBUG #define GEN_FATAL( ... ) \ do \ { \ diff --git a/scripts/helpers/vendor_toolchain.ps1 b/scripts/helpers/vendor_toolchain.ps1 index df3a59c..e3202f0 100644 --- a/scripts/helpers/vendor_toolchain.ps1 +++ b/scripts/helpers/vendor_toolchain.ps1 @@ -197,11 +197,11 @@ if ( $vendor -match "clang" ) $compiler_args += $flag_no_optimization } if ( $debug ) { - $compiler_args += ( $flag_define + 'Build_Debug=1' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=1' ) $compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug } else { - $compiler_args += ( $flag_define + 'Build_Debug=0' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=0' ) } $warning_ignores | ForEach-Object { @@ -277,11 +277,11 @@ if ( $vendor -match "clang" ) $compiler_args += $flag_no_optimization } if ( $debug ) { - $compiler_args += ( $flag_define + 'Build_Debug=1' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=1' ) $compiler_args += $flag_debug, $flag_debug_codeview, $flag_profiling_debug } else { - $compiler_args += ( $flag_define + 'Build_Debug=0' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=0' ) } $warning_ignores | ForEach-Object { @@ -402,7 +402,7 @@ if ( $vendor -match "msvc" ) if ( $debug ) { $compiler_args += $flag_debug - $compiler_args += ( $flag_define + 'Build_Debug=1' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=1' ) $compiler_args += ( $flag_path_debug + $path_output + '\' ) $compiler_args += $flag_link_win_rt_static_debug @@ -412,7 +412,7 @@ if ( $vendor -match "msvc" ) } } else { - $compiler_args += ( $flag_define + 'Build_Debug=0' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=0' ) $compiler_args += $flag_link_win_rt_static } $compiler_args += $includes | ForEach-Object { $flag_include + $_ } @@ -489,7 +489,7 @@ if ( $vendor -match "msvc" ) if ( $debug ) { $compiler_args += $flag_debug - $compiler_args += ( $flag_define + 'Build_Debug=1' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=1' ) $compiler_args += ( $flag_path_debug + $path_output + '\' ) $compiler_args += $flag_link_win_rt_static_debug @@ -498,7 +498,7 @@ if ( $vendor -match "msvc" ) } } else { - $compiler_args += ( $flag_define + 'Build_Debug=0' ) + $compiler_args += ( $flag_define + 'GEN_BUILD_DEBUG=0' ) $compiler_args += $flag_link_win_rt_static } $compiler_args += $includes | ForEach-Object { $flag_include + $_ }