mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08:00
Setup workaround with type casting for POD with assignment overload restriction on varadic args.
This commit is contained in:
parent
0de0e1632b
commit
59042a162c
@ -2587,10 +2587,25 @@ namespace gen
|
|||||||
return Code::Invalid; \
|
return Code::Invalid; \
|
||||||
}
|
}
|
||||||
|
|
||||||
# define def_body_code_validation_start( Name_, Get_Code_Expr_ ) \
|
# define def_body_code_validation_start( Name_ ) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
Code entry = Get_Code_Expr_; \
|
Code_POD pod = va_arg(va, Code_POD); \
|
||||||
|
Code entry = pcast(Code, pod); \
|
||||||
|
\
|
||||||
|
if ( ! entry ) \
|
||||||
|
{ \
|
||||||
|
log_failure("gen::" txt(Name_) ": Provided an null entry"); \
|
||||||
|
return Code::Invalid; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
switch ( entry->Type ) \
|
||||||
|
{
|
||||||
|
|
||||||
|
# define def_body_code_array_validation_start( Name_ ) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
Code entry = *codes; codes++; \
|
||||||
\
|
\
|
||||||
if ( ! entry ) \
|
if ( ! entry ) \
|
||||||
{ \
|
{ \
|
||||||
@ -2624,7 +2639,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_class_body, va_arg( va, Code ) );
|
def_body_code_validation_start( def_class_body );
|
||||||
AST_BODY_CLASS_UNALLOWED_TYPES
|
AST_BODY_CLASS_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_class_body );
|
def_body_code_validation_end( def_class_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -2641,7 +2656,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Function_Body;
|
result->Type = Function_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_class_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_class_body );
|
||||||
AST_BODY_CLASS_UNALLOWED_TYPES
|
AST_BODY_CLASS_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_class_body );
|
def_body_code_validation_end( def_class_body );
|
||||||
|
|
||||||
@ -2661,7 +2676,8 @@ namespace gen
|
|||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Code entry = va_arg(va, Code);
|
Code_POD pod = va_arg(va, Code_POD);
|
||||||
|
Code entry = pcast(Code, pod);
|
||||||
|
|
||||||
if ( ! entry )
|
if ( ! entry )
|
||||||
{
|
{
|
||||||
@ -2726,7 +2742,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_export_body, va_arg(va, Code) );
|
def_body_code_validation_start( def_export_body );
|
||||||
AST_BODY_EXPORT_UNALLOWED_TYPES
|
AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_export_body );
|
def_body_code_validation_end( def_export_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -2743,7 +2759,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Export_Body;
|
result->Type = Export_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_export_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_export_body );
|
||||||
AST_BODY_EXPORT_UNALLOWED_TYPES
|
AST_BODY_EXPORT_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_export_body );
|
def_body_code_validation_end( def_export_body );
|
||||||
|
|
||||||
@ -2761,7 +2777,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_extern_linkage_body, va_arg(va, Code) );
|
def_body_code_validation_start( def_extern_linkage_body );
|
||||||
AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_extern_linkage_body );
|
def_body_code_validation_end( def_extern_linkage_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -2778,7 +2794,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Extern_Linkage_Body;
|
result->Type = Extern_Linkage_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_extern_linkage_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_extern_linkage_body );
|
||||||
AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_extern_linkage_body );
|
def_body_code_validation_end( def_extern_linkage_body );
|
||||||
|
|
||||||
@ -2796,7 +2812,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_function_body, va_arg(va, Code) );
|
def_body_code_validation_start( def_function_body );
|
||||||
AST_BODY_FUNCTION_UNALLOWED_TYPES
|
AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_function_body );
|
def_body_code_validation_end( def_function_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -2813,7 +2829,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Function_Body;
|
result->Type = Function_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_function_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_function_body );
|
||||||
AST_BODY_FUNCTION_UNALLOWED_TYPES
|
AST_BODY_FUNCTION_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_function_body );
|
def_body_code_validation_end( def_function_body );
|
||||||
|
|
||||||
@ -2831,7 +2847,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_global_body, va_arg(va, Code) );
|
def_body_code_validation_start( def_global_body );
|
||||||
AST_BODY_GLOBAL_UNALLOWED_TYPES
|
AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_global_body );
|
def_body_code_validation_end( def_global_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -2848,7 +2864,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Global_Body;
|
result->Type = Global_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_global_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_global_body );
|
||||||
AST_BODY_GLOBAL_UNALLOWED_TYPES
|
AST_BODY_GLOBAL_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_global_body );
|
def_body_code_validation_end( def_global_body );
|
||||||
|
|
||||||
@ -2866,7 +2882,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_namespace_body, va_arg(va, Code) );
|
def_body_code_validation_start( def_namespace_body );
|
||||||
AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_namespace_body );
|
def_body_code_validation_end( def_namespace_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -2883,7 +2899,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Global_Body;
|
result->Type = Global_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_namespace_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_namespace_body );
|
||||||
AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
AST_BODY_NAMESPACE_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_namespace_body );
|
def_body_code_validation_end( def_namespace_body );
|
||||||
|
|
||||||
@ -2908,7 +2924,8 @@ namespace gen
|
|||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
|
|
||||||
Code type = va_arg(va, Code);
|
Code_POD pod = va_arg(va, Code_POD);
|
||||||
|
Code type = pcast( Code, pod );
|
||||||
s32 name_length = va_arg(va, s32 );
|
s32 name_length = va_arg(va, s32 );
|
||||||
char const* name = va_arg(va, char const*);
|
char const* name = va_arg(va, char const*);
|
||||||
|
|
||||||
@ -2924,7 +2941,8 @@ namespace gen
|
|||||||
|
|
||||||
while( num -= 3, num && num % 3 == 0 )
|
while( num -= 3, num && num % 3 == 0 )
|
||||||
{
|
{
|
||||||
type = va_arg(va, Code);
|
pod = va_arg(va, Code_POD);
|
||||||
|
type = pcast( Code, pod );
|
||||||
name_length = va_arg(va, u32);
|
name_length = va_arg(va, u32);
|
||||||
name = va_arg(va, char const*);
|
name = va_arg(va, char const*);
|
||||||
|
|
||||||
@ -3029,7 +3047,7 @@ namespace gen
|
|||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
def_body_code_validation_start( def_struct_body, va_arg(va, Code) );
|
def_body_code_validation_start( def_struct_body );
|
||||||
AST_BODY_STRUCT_UNALLOWED_TYPES
|
AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_struct_body );
|
def_body_code_validation_end( def_struct_body );
|
||||||
va_end(va);
|
va_end(va);
|
||||||
@ -3046,7 +3064,7 @@ namespace gen
|
|||||||
result = make_code();
|
result = make_code();
|
||||||
result->Type = Struct_Body;
|
result->Type = Struct_Body;
|
||||||
|
|
||||||
def_body_code_validation_start( def_struct_body, *codes; codes++ );
|
def_body_code_array_validation_start( def_struct_body );
|
||||||
AST_BODY_STRUCT_UNALLOWED_TYPES
|
AST_BODY_STRUCT_UNALLOWED_TYPES
|
||||||
def_body_code_validation_end( def_struct_body );
|
def_body_code_validation_end( def_struct_body );
|
||||||
|
|
||||||
@ -3066,7 +3084,8 @@ namespace gen
|
|||||||
va_start(va, num);
|
va_start(va, num);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
Code entry = va_arg(va, Code);
|
Code_POD pod = va_arg(va, Code_POD);
|
||||||
|
Code entry = pcast( Code, pod );
|
||||||
|
|
||||||
if ( ! entry )
|
if ( ! entry )
|
||||||
{
|
{
|
||||||
@ -3187,7 +3206,7 @@ namespace gen
|
|||||||
return Code::Invalid;
|
return Code::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( type && type != Typename )
|
if ( type && type->Type != Typename )
|
||||||
{
|
{
|
||||||
log_failure("gen::make_enum: type provided is not of code type typename - %s", type->debug_str() );
|
log_failure("gen::make_enum: type provided is not of code type typename - %s", type->debug_str() );
|
||||||
return Code::Invalid;
|
return Code::Invalid;
|
||||||
|
@ -547,7 +547,7 @@ namespace gen
|
|||||||
constexpr static
|
constexpr static
|
||||||
uw ArrSpecs_Cap = ArrS_Cap * (sizeof(AST*) / sizeof(SpecifierT));
|
uw ArrSpecs_Cap = ArrS_Cap * (sizeof(AST*) / sizeof(SpecifierT));
|
||||||
|
|
||||||
# define Using_Code_POD \
|
# define Using_AST_POD \
|
||||||
union { \
|
union { \
|
||||||
AST* ArrStatic[AST::ArrS_Cap]; \
|
AST* ArrStatic[AST::ArrS_Cap]; \
|
||||||
Array(AST*) Entries; \
|
Array(AST*) Entries; \
|
||||||
@ -565,22 +565,22 @@ namespace gen
|
|||||||
bool DynamicEntries; \
|
bool DynamicEntries; \
|
||||||
u8 _Align_Pad[2];
|
u8 _Align_Pad[2];
|
||||||
|
|
||||||
Using_Code_POD
|
Using_AST_POD
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CodePOD
|
struct AST_POD
|
||||||
{
|
{
|
||||||
Using_Code_POD
|
Using_AST_POD
|
||||||
# undef Using_CodePOD
|
# undef Using_CodePOD
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr sw size_AST = sizeof(AST);
|
constexpr sw size_AST = sizeof(AST);
|
||||||
constexpr sw size_POD = sizeof(CodePOD);
|
constexpr sw size_POD = sizeof(AST_POD);
|
||||||
|
|
||||||
// Its intended for the AST to have equivalent size to its POD.
|
// Its intended for the AST to have equivalent size to its POD.
|
||||||
// All extra functionality within the AST namespace should just be syntatic sugar.
|
// All extra functionality within the AST namespace should just be syntatic sugar.
|
||||||
static_assert( sizeof(AST) == sizeof(CodePOD), "ERROR: AST IS NOT POD" );
|
static_assert( sizeof(AST) == sizeof(AST_POD), "ERROR: AST IS NOT POD" );
|
||||||
static_assert( sizeof(CodePOD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
|
static_assert( sizeof(AST_POD) == AST_POD_Size, "ERROR: AST POD is not size of AST_POD_Size" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
AST* typedef as to not constantly have to add the '*' as this is written often..
|
AST* typedef as to not constantly have to add the '*' as this is written often..
|
||||||
@ -666,8 +666,6 @@ namespace gen
|
|||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cannot be done unfortunately c++ sucks. (Will lose POD by doing so)
|
|
||||||
#if 0
|
|
||||||
inline
|
inline
|
||||||
Code& operator=( Code other )
|
Code& operator=( Code other )
|
||||||
{
|
{
|
||||||
@ -689,7 +687,6 @@ namespace gen
|
|||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
inline
|
inline
|
||||||
AST* operator->()
|
AST* operator->()
|
||||||
@ -714,7 +711,13 @@ namespace gen
|
|||||||
|
|
||||||
AST* ast;
|
AST* ast;
|
||||||
};
|
};
|
||||||
static_assert( sizeof(Code) == sizeof(AST*), "ERROR: Code is not POD" );
|
|
||||||
|
struct Code_POD
|
||||||
|
{
|
||||||
|
AST_POD* ast;
|
||||||
|
};
|
||||||
|
|
||||||
|
static_assert( sizeof(Code) == sizeof(Code_POD), "ERROR: Code is not POD" );
|
||||||
|
|
||||||
// Used when the its desired when omission is allowed in a definition.
|
// Used when the its desired when omission is allowed in a definition.
|
||||||
constexpr Code NoCode = { nullptr };
|
constexpr Code NoCode = { nullptr };
|
||||||
|
Loading…
Reference in New Issue
Block a user