reduce 'large macro' usage in ast.cpp and interface.cpp

Properly disabled GEN_DEBUG_TRAP in non-debug builds
This commit is contained in:
Edward R. Gonzalez 2024-12-12 11:35:50 -05:00
parent 633879d35f
commit 30dea2e9fd
7 changed files with 434 additions and 627 deletions

View File

@ -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:
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
}

View File

@ -1,3 +1,5 @@
// 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: \
@ -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

View File

@ -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 ));;

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -8,7 +8,8 @@
#pragma region Debug
#if defined( _MSC_VER )
#if GEN_BUILD_DEBUG
# if defined( GEN_COMPILER_MSVC )
# if _MSC_VER < 1300
# define GEN_DEBUG_TRAP() __asm int 3 /* Trap to debugger! */
# else
@ -19,6 +20,9 @@
# else
# define GEN_DEBUG_TRAP() __builtin_trap()
# endif
#else
# 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 \
{ \

View File

@ -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 + $_ }