mirror of
				https://github.com/Ed94/gencpp.git
				synced 2025-10-30 22:40:54 -07:00 
			
		
		
		
	reduce 'large macro' usage in ast.cpp and interface.cpp
Properly disabled GEN_DEBUG_TRAP in non-debug builds
This commit is contained in:
		| @@ -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 | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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
											
										
									
								
							| @@ -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 | ||||
|   | ||||
| @@ -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                                                     \ | ||||
| 	{                                                      \ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user