mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 15:54:45 -08:00
Added a new AST member NextVar
to be used for comma separated variable support.
Interface adding has been adjusted to use ParentType->Next. Using the AST_Class->Next was bad since that breaks the linked list a body AST would have used for traversal.
This commit is contained in:
parent
2bfbef1d0c
commit
d606c790ca
@ -103,7 +103,7 @@ String AST::to_string()
|
||||
|
||||
result.append_fmt( "%S : %s %S", Name, access_level, ParentType );
|
||||
|
||||
CodeType interface = Next->cast< CodeType >();
|
||||
CodeType interface = ParentType->Next->cast< CodeType >();
|
||||
if ( interface )
|
||||
result.append( "\n" );
|
||||
|
||||
@ -703,7 +703,7 @@ String AST::to_string()
|
||||
|
||||
result.append_fmt( "%S : %s %S", Name, access_level, ParentType );
|
||||
|
||||
CodeType interface = Next->cast< CodeType >();
|
||||
CodeType interface = ParentType->Next->cast< CodeType >();
|
||||
if ( interface )
|
||||
result.append( "\n" );
|
||||
|
||||
@ -924,6 +924,35 @@ String AST::to_string()
|
||||
|
||||
case Variable:
|
||||
{
|
||||
if ( Parent && Parent->Type == Variable )
|
||||
{
|
||||
// Its a comma-separated variable ( a NextVar )
|
||||
|
||||
if ( Specs )
|
||||
result.append_fmt( "%S ", Specs->to_string() );
|
||||
|
||||
result.append( Name );
|
||||
|
||||
if ( ArrExpr )
|
||||
{
|
||||
result.append_fmt( "[ %S ]", ArrExpr->to_string() );
|
||||
|
||||
AST* next_arr_expr = ArrExpr->Next;
|
||||
while ( next_arr_expr )
|
||||
{
|
||||
result.append_fmt( "[ %S ]", next_arr_expr->to_string() );
|
||||
next_arr_expr = next_arr_expr->Next;
|
||||
}
|
||||
}
|
||||
|
||||
if ( Value )
|
||||
result.append_fmt( " = %S", Value->to_string() );
|
||||
|
||||
// Keep the chain going...
|
||||
if ( NextVar )
|
||||
result.append_fmt( ", %S", NextVar->to_string() );
|
||||
}
|
||||
|
||||
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
|
||||
result.append( "export " );
|
||||
|
||||
@ -955,6 +984,9 @@ String AST::to_string()
|
||||
if ( Value )
|
||||
result.append_fmt( " = %S", Value->to_string() );
|
||||
|
||||
if ( NextVar )
|
||||
result.append_fmt( ", %S", NextVar->to_string() );
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("; %S", InlineCmt->Content);
|
||||
else
|
||||
@ -964,7 +996,7 @@ String AST::to_string()
|
||||
}
|
||||
|
||||
if ( BitfieldSize )
|
||||
result.append_fmt( "%S %S : %S;", ValueType->to_string(), Name, BitfieldSize->to_string() );
|
||||
result.append_fmt( "%S %S : %S", ValueType->to_string(), Name, BitfieldSize->to_string() );
|
||||
|
||||
else if ( ValueType->ArrExpr )
|
||||
{
|
||||
@ -976,12 +1008,18 @@ String AST::to_string()
|
||||
result.append_fmt( "[ %S ]", next_arr_expr->to_string() );
|
||||
next_arr_expr = next_arr_expr->Next;
|
||||
}
|
||||
|
||||
result.append( ";" );
|
||||
}
|
||||
|
||||
else
|
||||
result.append_fmt( "%S %S;", ValueType->to_string(), Name );
|
||||
result.append_fmt( "%S %S", ValueType->to_string(), Name );
|
||||
|
||||
if ( Value )
|
||||
result.append_fmt( " = %S", Value->to_string() );
|
||||
|
||||
if ( NextVar )
|
||||
result.append_fmt( ", %S", NextVar->to_string() );
|
||||
|
||||
result.append( ";" );
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt(" %S", InlineCmt->Content);
|
||||
@ -1508,6 +1546,7 @@ bool AST::is_equal( AST* other )
|
||||
check_member_ast( Value );
|
||||
check_member_ast( Attributes );
|
||||
check_member_ast( Specs );
|
||||
check_member_ast( NextVar );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -229,22 +229,19 @@ struct AST
|
||||
union {
|
||||
struct
|
||||
{
|
||||
union {
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Typename
|
||||
@ -252,6 +249,10 @@ struct AST
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
|
||||
@ -284,28 +285,29 @@ struct AST_POD
|
||||
union {
|
||||
struct
|
||||
{
|
||||
union {
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typename, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Typename, Variable
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typedef, Union, Using, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Typename, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct, ParentType->Next has a possible list of interfaces.
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* ReturnType; // Function, Operator, Typename
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
AST* ValueType; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* BitfieldSize; // Variable (Class/Struct Data Member)
|
||||
AST* Params; // Constructor, Function, Operator, Template, Typename
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
AST* ArrExpr; // Typename
|
||||
AST* Body; // Class, Constructr, Destructor, Enum, Function, Namespace, Struct, Union
|
||||
AST* Declaration; // Friend, Template
|
||||
AST* Value; // Parameter, Variable
|
||||
};
|
||||
union {
|
||||
AST* NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
|
||||
AST* SpecsFuncSuffix; // Only used with typenames, to store the function suffix if typename is function signature.
|
||||
};
|
||||
};
|
||||
StringCached Content; // Attributes, Comment, Execution, Include
|
||||
|
@ -68,6 +68,7 @@ struct AST_Class
|
||||
CodeType ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeType Last;
|
||||
@ -93,6 +94,7 @@ struct AST_Constructor
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -132,6 +134,7 @@ struct AST_Destructor
|
||||
CodeSpecifiers Specs;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
Code Body;
|
||||
char _PAD_PROPERTIES_3_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -156,6 +159,7 @@ struct AST_Enum
|
||||
CodeType UnderlyingType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -193,6 +197,7 @@ struct AST_Extern
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -230,6 +235,7 @@ struct AST_Friend
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -254,6 +260,7 @@ struct AST_Fn
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -288,6 +295,7 @@ struct AST_NS
|
||||
struct {
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -313,6 +321,7 @@ struct AST_Operator
|
||||
CodeType ReturnType;
|
||||
CodeParam Params;
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -338,6 +347,7 @@ struct AST_OpCast
|
||||
CodeType ValueType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -360,6 +370,7 @@ struct AST_Param
|
||||
CodeType ValueType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
Code Value;
|
||||
char _PAD_PROPERTIES_3_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeParam Last;
|
||||
@ -431,6 +442,7 @@ struct AST_Struct
|
||||
CodeType ParentType;
|
||||
char _PAD_PARAMS_[ sizeof(AST*) ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
CodeType Last;
|
||||
@ -453,6 +465,7 @@ struct AST_Template
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParam Params;
|
||||
Code Declaration;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -472,12 +485,13 @@ struct AST_Type
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
char _PAD_INLINE_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType; // Only used for function signatures
|
||||
CodeParam Params; // Only used for function signatures
|
||||
Code ArrExpr;
|
||||
CodeSpecifiers SpecsFuncSuffix; // Only used for function signatures
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -500,7 +514,7 @@ struct AST_Typedef
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
Code UnderlyingType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -524,6 +538,7 @@ struct AST_Union
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
CodeBody Body;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -547,7 +562,7 @@ struct AST_Using
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType UnderlyingType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
@ -573,6 +588,7 @@ struct AST_Var
|
||||
CodeType ValueType;
|
||||
Code BitfieldSize;
|
||||
Code Value;
|
||||
CodeVar NextVar;
|
||||
};
|
||||
};
|
||||
Code Prev;
|
||||
|
@ -67,15 +67,21 @@ Code& Code::operator ++()
|
||||
|
||||
void CodeClass::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
return;
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
ast->ParentAccess = AccessSpec::Public;
|
||||
// If your planning on adding a proper parent,
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
void CodeParam::append( CodeParam other )
|
||||
@ -129,14 +135,21 @@ CodeParam& CodeParam::operator ++()
|
||||
|
||||
void CodeStruct::add_interface( CodeType type )
|
||||
{
|
||||
if ( ! ast->Next )
|
||||
CodeType possible_slot = ast->ParentType;
|
||||
if ( possible_slot.ast )
|
||||
{
|
||||
ast->Next = type;
|
||||
ast->Last = ast->Next;
|
||||
// Were adding an interface to parent type, so we need to make sure the parent type is public.
|
||||
ast->ParentAccess = AccessSpec::Public;
|
||||
// If your planning on adding a proper parent,
|
||||
// then you'll need to move this over to ParentType->next and update ParentAccess accordingly.
|
||||
}
|
||||
|
||||
ast->Next->Next = type;
|
||||
ast->Last = ast->Next->Next;
|
||||
while ( possible_slot.ast != nullptr )
|
||||
{
|
||||
possible_slot.ast = (AST_Type*) possible_slot->Next.ast;
|
||||
}
|
||||
|
||||
possible_slot.ast = type.ast;
|
||||
}
|
||||
|
||||
CodeBody def_body( CodeT type )
|
||||
|
@ -4963,6 +4963,7 @@ CodeType parse_type( bool* typedef_is_function )
|
||||
SpecifierT spec = ESpecifier::to_type( currtok );
|
||||
|
||||
if ( spec != ESpecifier::Const
|
||||
// TODO : Add support for NoExcept
|
||||
// && spec != ESpecifier::NoExcept
|
||||
&& spec != ESpecifier::RValue )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user