mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Fixes to serialization, reduced Define_CodeType macro
Now the execution code is generated in bootstrap/singleheader gen.
This commit is contained in:
@ -308,9 +308,7 @@ String AST::to_string()
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
@ -348,9 +346,7 @@ String AST::to_string()
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
@ -404,9 +400,7 @@ String AST::to_string()
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
@ -441,9 +435,7 @@ String AST::to_string()
|
||||
|
||||
if ( Specs )
|
||||
{
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
@ -463,9 +455,7 @@ String AST::to_string()
|
||||
else
|
||||
result.append_fmt( "operator %s()", ValueType->to_string() );
|
||||
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
@ -487,9 +477,7 @@ String AST::to_string()
|
||||
{
|
||||
result.append_fmt( "operator %s()", ValueType->to_string() );
|
||||
|
||||
CodeSpecifiers specs = cast<CodeSpecifiers>();
|
||||
|
||||
for ( SpecifierT spec : specs )
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( spec ) )
|
||||
result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) );
|
||||
@ -570,7 +558,7 @@ String AST::to_string()
|
||||
s32 left = NumEntries;
|
||||
while ( left-- )
|
||||
{
|
||||
if ( ESpecifier::is_trailing( ArrSpecs[idx]) )
|
||||
if ( ESpecifier::is_trailing( ArrSpecs[idx]) && ArrSpecs[idx] != ESpecifier::Const )
|
||||
{
|
||||
idx++;
|
||||
continue;
|
||||
|
@ -524,29 +524,15 @@ struct CodeStruct
|
||||
AST_Struct* ast;
|
||||
};
|
||||
|
||||
#define Define_CodeType( Typename ) \
|
||||
struct Code##Typename \
|
||||
{ \
|
||||
Using_Code( Code##Typename ); \
|
||||
AST* raw() \
|
||||
{ \
|
||||
return rcast( AST*, ast ); \
|
||||
} \
|
||||
operator Code() \
|
||||
{ \
|
||||
return * rcast( Code*, this ); \
|
||||
} \
|
||||
AST_##Typename* operator->() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure("Attempt to dereference a nullptr!"); \
|
||||
return nullptr; \
|
||||
} \
|
||||
return ast; \
|
||||
} \
|
||||
AST_##Typename* ast; \
|
||||
}
|
||||
#define Define_CodeType( Typename ) \
|
||||
struct Code##Typename \
|
||||
{ \
|
||||
Using_Code( Code ## Typename ); \
|
||||
AST* raw(); \
|
||||
operator Code(); \
|
||||
AST_##Typename* operator->(); \
|
||||
AST_##Typename* ast; \
|
||||
}
|
||||
|
||||
Define_CodeType( Attributes );
|
||||
Define_CodeType( Comment );
|
||||
|
@ -78,6 +78,25 @@ Typename::operator bool()
|
||||
return ast != nullptr; \
|
||||
}
|
||||
|
||||
#define Define_CodeType_Impl( Typename ) \
|
||||
AST* Code##Typename::raw() \
|
||||
{ \
|
||||
return rcast( AST*, ast ); \
|
||||
} \
|
||||
Code##Typename::operator Code() \
|
||||
{ \
|
||||
return *rcast( Code*, this ); \
|
||||
} \
|
||||
AST_##Typename* Code##Typename::operator->() \
|
||||
{ \
|
||||
if ( ast == nullptr ) \
|
||||
{ \
|
||||
log_failure( "Attempt to dereference a nullptr!" ); \
|
||||
return nullptr; \
|
||||
} \
|
||||
return ast; \
|
||||
} \
|
||||
|
||||
Define_CodeImpl( Code );
|
||||
Define_CodeImpl( CodeBody );
|
||||
Define_CodeImpl( CodeAttributes );
|
||||
@ -105,7 +124,31 @@ Define_CodeImpl( CodeTypedef );
|
||||
Define_CodeImpl( CodeUnion );
|
||||
Define_CodeImpl( CodeUsing );
|
||||
Define_CodeImpl( CodeVar );
|
||||
|
||||
Define_CodeType_Impl( Attributes );
|
||||
Define_CodeType_Impl( Comment );
|
||||
Define_CodeType_Impl( Define );
|
||||
Define_CodeType_Impl( Enum );
|
||||
Define_CodeType_Impl( Exec );
|
||||
Define_CodeType_Impl( Extern );
|
||||
Define_CodeType_Impl( Include );
|
||||
Define_CodeType_Impl( Friend );
|
||||
Define_CodeType_Impl( Fn );
|
||||
Define_CodeType_Impl( Module );
|
||||
Define_CodeType_Impl( NS );
|
||||
Define_CodeType_Impl( Operator );
|
||||
Define_CodeType_Impl( OpCast );
|
||||
Define_CodeType_Impl( Pragma );
|
||||
Define_CodeType_Impl( PreprocessCond );
|
||||
Define_CodeType_Impl( Template );
|
||||
Define_CodeType_Impl( Type );
|
||||
Define_CodeType_Impl( Typedef );
|
||||
Define_CodeType_Impl( Union );
|
||||
Define_CodeType_Impl( Using );
|
||||
Define_CodeType_Impl( Var );
|
||||
|
||||
#undef Define_CodeImpl
|
||||
#undef Define_CodeType_Impl
|
||||
|
||||
#define Define_AST_Cast( typename ) \
|
||||
AST::operator Code ## typename() \
|
||||
|
Reference in New Issue
Block a user