mirror of
https://github.com/Ed94/gencpp.git
synced 2024-11-10 02:54:53 -08:00
Added support for inline comments
Also now doing comment serialization on def_comment directly as parse_comment doesn't need it. Essentially comment ast types serialize the same way s untyped and execution ASTs
This commit is contained in:
parent
5e79e8ba65
commit
c97762ac16
@ -17,7 +17,7 @@ GEN_NS_END
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gen.bootstrap.cpp "
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
constexpr bool DontSkipInitialDirectives = false;
|
||||
|
@ -43,6 +43,11 @@ String AST::to_string()
|
||||
|
||||
case Comment:
|
||||
{
|
||||
// TODO : Move this formmating process to def_comment,
|
||||
// Were going to preserve as much of the original formatting as possible
|
||||
// so that the parsed comments don't have any artifacts.
|
||||
// Just doing what untyped and execution do
|
||||
#if 0
|
||||
if ( Prev && Prev->Type != Comment && Prev->Type != NewLine )
|
||||
result.append( "\n" );
|
||||
|
||||
@ -72,6 +77,9 @@ String AST::to_string()
|
||||
|
||||
if ( result.back() != '\n' )
|
||||
result.append( "\n" );
|
||||
#else
|
||||
result.append( Content );
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
@ -141,9 +149,15 @@ String AST::to_string()
|
||||
|
||||
else result.append_fmt( "class %S", Name );
|
||||
|
||||
// Check if it can have an end-statement
|
||||
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( "; // %S\n", InlineCmt->Content );
|
||||
else
|
||||
result.append(";\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Constructor:
|
||||
@ -168,9 +182,14 @@ String AST::to_string()
|
||||
|
||||
if ( Params )
|
||||
result.append_fmt( "( %S )", Params->to_string() );
|
||||
else
|
||||
{
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( "(void); // %S\n", InlineCmt->Content );
|
||||
else
|
||||
result.append( "(void);\n" );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Destructor:
|
||||
@ -203,10 +222,15 @@ String AST::to_string()
|
||||
result.append_fmt( "~%S()", Parent->Name );
|
||||
|
||||
if ( specs.has( ESpecifier::Pure ) )
|
||||
result.append( " = 0;\n" );
|
||||
result.append( " = 0;" );
|
||||
}
|
||||
else
|
||||
result.append_fmt( "~%S();\n", Parent->Name );
|
||||
result.append_fmt( "~%S();", Parent->Name );
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( " %S", InlineCmt->Content );
|
||||
else
|
||||
result.append("\n");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -249,8 +273,13 @@ String AST::to_string()
|
||||
result.append_fmt( "enum %S : %S", Name, UnderlyingType->to_string() );
|
||||
|
||||
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append(";\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Enum_Class:
|
||||
@ -299,8 +328,13 @@ String AST::to_string()
|
||||
result.append_fmt( "%S : %S", Name, UnderlyingType->to_string() );
|
||||
|
||||
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append(";\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Export_Body:
|
||||
@ -327,7 +361,14 @@ String AST::to_string()
|
||||
result.append_fmt( "friend %S", Declaration->to_string() );
|
||||
|
||||
if ( result[ result.length() -1 ] != ';' )
|
||||
result.append( ";\n" );
|
||||
{
|
||||
result.append( ";" );
|
||||
}
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt(" %S", InlineCmt->Content );
|
||||
else
|
||||
result.append("\n");
|
||||
break;
|
||||
|
||||
case Function:
|
||||
@ -404,6 +445,9 @@ String AST::to_string()
|
||||
}
|
||||
}
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( "; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append( ";\n" );
|
||||
}
|
||||
break;
|
||||
@ -496,6 +540,9 @@ String AST::to_string()
|
||||
}
|
||||
}
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( "; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append( ";\n" );
|
||||
}
|
||||
break;
|
||||
@ -504,6 +551,8 @@ String AST::to_string()
|
||||
{
|
||||
if ( Specs )
|
||||
{
|
||||
// TODO : Add support for specifies before the operator keyword
|
||||
|
||||
if ( Name && Name.length() )
|
||||
result.append_fmt( "%Soperator %S()", Name, ValueType->to_string() );
|
||||
else
|
||||
@ -532,6 +581,8 @@ String AST::to_string()
|
||||
case Operator_Cast_Fwd:
|
||||
if ( Specs )
|
||||
{
|
||||
// TODO : Add support for specifies before the operator keyword
|
||||
|
||||
result.append_fmt( "operator %S()", ValueType->to_string() );
|
||||
|
||||
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
|
||||
@ -543,10 +594,16 @@ String AST::to_string()
|
||||
}
|
||||
}
|
||||
|
||||
result.append( ";" );
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( "; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append( ";\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("operator %S(); %S", ValueType->to_string() );
|
||||
else
|
||||
result.append_fmt("operator %S();\n", ValueType->to_string() );
|
||||
break;
|
||||
|
||||
@ -680,8 +737,13 @@ String AST::to_string()
|
||||
}
|
||||
|
||||
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append(";\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Struct_Fwd:
|
||||
@ -695,8 +757,13 @@ String AST::to_string()
|
||||
else result.append_fmt( "struct %S", Name );
|
||||
|
||||
if ( Parent == nullptr || ( Parent->Type != ECode::Typedef && Parent->Type != ECode::Variable ) )
|
||||
{
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("; %S", InlineCmt->Content );
|
||||
else
|
||||
result.append(";\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case Template:
|
||||
@ -726,8 +793,13 @@ String AST::to_string()
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append( ";\n" );
|
||||
result.append( ";" );
|
||||
}
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt(" %S", InlineCmt->Content);
|
||||
else
|
||||
result.append("\n");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -796,14 +868,22 @@ String AST::to_string()
|
||||
if ( UnderlyingType->ArrExpr )
|
||||
result.append_fmt( "[%S]", UnderlyingType->ArrExpr->to_string() );
|
||||
|
||||
result.append( ";\n" );
|
||||
result.append( ";" );
|
||||
}
|
||||
else
|
||||
result.append_fmt( "using %S;\n", Name );
|
||||
result.append_fmt( "using %S;", Name );
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt(" %S\n", InlineCmt->Content );
|
||||
else
|
||||
result.append("\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case Using_Namespace:
|
||||
if ( InlineCmt )
|
||||
result.append_fmt( "using namespace $S; %S", Name, InlineCmt->Content );
|
||||
else
|
||||
result.append_fmt( "using namespace %s;\n", Name );
|
||||
break;
|
||||
|
||||
@ -831,19 +911,27 @@ String AST::to_string()
|
||||
if ( Value )
|
||||
result.append_fmt( " = %S", Value->to_string() );
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt("; %S", InlineCmt->Content);
|
||||
else
|
||||
result.append( ";\n" );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ( BitfieldSize )
|
||||
result.append_fmt( "%S %S : %S;\n", ValueType->to_string(), Name, BitfieldSize->to_string() );
|
||||
result.append_fmt( "%S %S : %S;", ValueType->to_string(), Name, BitfieldSize->to_string() );
|
||||
|
||||
else if ( UnderlyingType->ArrExpr )
|
||||
result.append_fmt( "%S %S[%S];\n", UnderlyingType->to_string(), Name, UnderlyingType->ArrExpr->to_string() );
|
||||
result.append_fmt( "%S %S[%S];", UnderlyingType->to_string(), Name, UnderlyingType->ArrExpr->to_string() );
|
||||
|
||||
else
|
||||
result.append_fmt( "%S %S;\n", UnderlyingType->to_string(), Name );
|
||||
result.append_fmt( "%S %S;", UnderlyingType->to_string(), Name );
|
||||
|
||||
if ( InlineCmt )
|
||||
result.append_fmt(" %S", InlineCmt->Content);
|
||||
else
|
||||
result.append("\n");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -226,10 +226,11 @@ struct AST
|
||||
union {
|
||||
struct
|
||||
{
|
||||
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; // Function, Operator, Type symbol, Variable
|
||||
AST* Specs; // Destructor, Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor, Destructor
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
@ -237,7 +238,7 @@ struct AST
|
||||
};
|
||||
union {
|
||||
AST* BitfieldSize; // Varaiable (Class/Struct Data Member)
|
||||
AST* Params; // Function, Operator, Template
|
||||
AST* Params; // Constructor, Function, Operator, Template
|
||||
};
|
||||
union {
|
||||
AST* ArrExpr; // Type Symbol
|
||||
@ -275,10 +276,11 @@ struct AST_POD
|
||||
union {
|
||||
struct
|
||||
{
|
||||
AST* InlineCmt; // Class, Constructor, Destructor, Enum, Friend, Functon, Operator, OpCast, Struct, Typedef, Using, Variable
|
||||
AST* Attributes; // Class, Enum, Function, Struct, Typename, Union, Using, Variable
|
||||
AST* Specs; // Function, Operator, Type symbol, Variable
|
||||
union {
|
||||
AST* InitializerList; // Constructor, Destructor
|
||||
AST* InitializerList; // Constructor
|
||||
AST* ParentType; // Class, Struct
|
||||
AST* ReturnType; // Function, Operator
|
||||
AST* UnderlyingType; // Enum, Typedef
|
||||
|
@ -57,6 +57,7 @@ struct AST_Class
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType ParentType;
|
||||
@ -80,6 +81,7 @@ struct AST_Constructor
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 3 ];
|
||||
Code InitializerList;
|
||||
CodeParam Params;
|
||||
@ -116,6 +118,7 @@ struct AST_Destructor
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_ [ sizeof(AST*) * 1 ];
|
||||
CodeSpecifiers Specs;
|
||||
char _PAD_PROPERTIES_2_ [ sizeof(AST*) * 2 ];
|
||||
@ -137,6 +140,7 @@ struct AST_Enum
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPEC_ [ sizeof(AST*) ];
|
||||
CodeType UnderlyingType;
|
||||
@ -175,7 +179,7 @@ struct AST_Extern
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
};
|
||||
};
|
||||
@ -209,6 +213,7 @@ struct AST_Friend
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
Code Declaration;
|
||||
};
|
||||
@ -228,6 +233,7 @@ struct AST_Fn
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
@ -263,7 +269,7 @@ struct AST_NS
|
||||
union {
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct {
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 5 ];
|
||||
CodeBody Body;
|
||||
};
|
||||
};
|
||||
@ -283,6 +289,7 @@ struct AST_Operator
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ReturnType;
|
||||
@ -306,6 +313,7 @@ struct AST_OpCast
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
@ -328,7 +336,7 @@ struct AST_Param
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 2 ];
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 3 ];
|
||||
CodeType ValueType;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) ];
|
||||
Code Value;
|
||||
@ -393,6 +401,7 @@ struct AST_Struct
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType ParentType;
|
||||
@ -416,7 +425,7 @@ struct AST_Template
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 4 ];
|
||||
CodeParam Params;
|
||||
Code Declaration;
|
||||
};
|
||||
@ -437,6 +446,7 @@ struct AST_Type
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
@ -458,6 +468,7 @@ struct AST_Typedef
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 2 ];
|
||||
Code UnderlyingType;
|
||||
char _PAD_PROPERTIES_2_[ sizeof(AST*) * 2 ];
|
||||
@ -479,6 +490,7 @@ struct AST_Union
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
char _PAD_INLINE_CMT_[ sizeof(AST*) ];
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_PROPERTIES_[ sizeof(AST*) * 3 ];
|
||||
CodeBody Body;
|
||||
@ -500,6 +512,7 @@ struct AST_Using
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
char _PAD_SPECS_ [ sizeof(AST*) ];
|
||||
CodeType UnderlyingType;
|
||||
@ -522,6 +535,7 @@ struct AST_Var
|
||||
char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ];
|
||||
struct
|
||||
{
|
||||
CodeComment InlineCmt;
|
||||
CodeAttributes Attributes;
|
||||
CodeSpecifiers Specs;
|
||||
CodeType ValueType;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
// This file was generated automatially by gen.bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
#pragma region generated code inline implementation
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// This file was generated automatially by gen.bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace ECode
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// This file was generated automatially by gen.bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace EOperator
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// This file was generated automatially by gen.bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
namespace ESpecifier
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
// This file was generated automatially by gen.bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -128,7 +128,7 @@ namespace Parser
|
||||
{ sizeof( "]" ), "]" },
|
||||
{ sizeof( "(" ), "(" },
|
||||
{ sizeof( ")" ), ")" },
|
||||
{ sizeof( "__comemnt__" ), "__comemnt__" },
|
||||
{ sizeof( "__comment__" ), "__comment__" },
|
||||
{ sizeof( "__comment_end__" ), "__comment_end__" },
|
||||
{ sizeof( "__comment_start__" ), "__comment_start__" },
|
||||
{ sizeof( "__character__" ), "__character__" },
|
||||
|
@ -67,22 +67,22 @@ namespace Parser
|
||||
|
||||
bool __eat( TokType type );
|
||||
|
||||
Token& current( bool skip_new_lines = true )
|
||||
Token& current( bool skip_formatting = true )
|
||||
{
|
||||
if ( skip_new_lines )
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( Arr[Idx].Type == TokType::NewLine )
|
||||
while ( Arr[Idx].Type == TokType::NewLine || Arr[Idx].Type == TokType::Comment )
|
||||
Idx++;
|
||||
}
|
||||
|
||||
return Arr[Idx];
|
||||
}
|
||||
|
||||
Token& previous( bool skip_new_lines = false )
|
||||
Token& previous( bool skip_formatting = false )
|
||||
{
|
||||
s32 idx = this->Idx;
|
||||
|
||||
if ( skip_new_lines )
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( Arr[idx].Type == TokType::NewLine )
|
||||
idx--;
|
||||
@ -93,11 +93,11 @@ namespace Parser
|
||||
return Arr[idx - 1];
|
||||
}
|
||||
|
||||
Token& next( bool skip_new_lines = false )
|
||||
Token& next( bool skip_formatting = false )
|
||||
{
|
||||
s32 idx = this->Idx;
|
||||
|
||||
if ( skip_new_lines )
|
||||
if ( skip_formatting )
|
||||
{
|
||||
while ( Arr[idx].Type == TokType::NewLine )
|
||||
idx++;
|
||||
@ -114,7 +114,7 @@ namespace Parser
|
||||
}
|
||||
};
|
||||
|
||||
constexpr bool dont_skip_new_lines = false;
|
||||
constexpr bool dont_skip_formatting = false;
|
||||
|
||||
struct StackNode
|
||||
{
|
||||
@ -200,7 +200,8 @@ namespace Parser
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Arr[Idx].Type == TokType::NewLine && type != TokType::NewLine )
|
||||
if ( Arr[ Idx ].Type == TokType::NewLine && type != TokType::NewLine
|
||||
|| Arr[ Idx ].Type == TokType::Comment && type != TokType::Comment )
|
||||
{
|
||||
Idx++;
|
||||
}
|
||||
@ -879,39 +880,38 @@ namespace Parser
|
||||
|
||||
if ( current == '/' )
|
||||
{
|
||||
token.Type = TokType::Comment_Start;
|
||||
token.Type = TokType::Comment;
|
||||
token.Length = 2;
|
||||
Tokens.append( token );
|
||||
|
||||
move_forward();
|
||||
Token content = { scanner, 1, TokType::Comment, line, column, false };
|
||||
token.Length++;
|
||||
|
||||
while ( left && current != '\n' && current != '\r' )
|
||||
{
|
||||
move_forward();
|
||||
content.Length++;
|
||||
token.Length++;
|
||||
}
|
||||
Tokens.append( content );
|
||||
|
||||
if ( current == '\r' )
|
||||
{
|
||||
move_forward();
|
||||
token.Length++;
|
||||
}
|
||||
if ( current == '\n' )
|
||||
{
|
||||
move_forward();
|
||||
token.Length++;
|
||||
}
|
||||
Tokens.append( token );
|
||||
continue;
|
||||
}
|
||||
else if ( current == '*' )
|
||||
{
|
||||
token.Type = TokType::Comment_Start;
|
||||
token.Type = TokType::Comment;
|
||||
token.Length = 2;
|
||||
Tokens.append( token );
|
||||
|
||||
Token content = { token.Text, 0, TokType::Comment, line, column, false };
|
||||
move_forward();
|
||||
content.Length++;
|
||||
token.Length++;
|
||||
|
||||
bool star = current == '*';
|
||||
bool slash = scanner[1] == '/';
|
||||
@ -919,17 +919,14 @@ namespace Parser
|
||||
while ( left && ! at_end )
|
||||
{
|
||||
move_forward();
|
||||
content.Length++;
|
||||
token.Length++;
|
||||
|
||||
star = current == '*';
|
||||
slash = scanner[1] == '/';
|
||||
at_end = star && slash;
|
||||
}
|
||||
content.Length += 3;
|
||||
Tokens.append( content );
|
||||
|
||||
Token end = { scanner, 2, TokType::Comment_End, line, column, false };
|
||||
Tokens.append( end );
|
||||
token.Length += 3;
|
||||
Tokens.append( token );
|
||||
move_forward();
|
||||
move_forward();
|
||||
|
||||
@ -1141,7 +1138,7 @@ if ( def.Ptr == nullptr ) \
|
||||
return CodeInvalid; \
|
||||
}
|
||||
|
||||
# define currtok_noskip Context.Tokens.current( dont_skip_new_lines )
|
||||
# define currtok_noskip Context.Tokens.current( dont_skip_formatting )
|
||||
# define currtok Context.Tokens.current()
|
||||
# define prevtok Context.Tokens.previous()
|
||||
# define nexttok Context.Tokens.next()
|
||||
@ -1185,20 +1182,16 @@ internal
|
||||
CodeComment parse_comment()
|
||||
{
|
||||
using namespace Parser;
|
||||
push_scope();
|
||||
|
||||
eat( TokType::Comment_Start );
|
||||
StackNode scope { nullptr, currtok_noskip, NullToken, txt( __func__ ) };
|
||||
Context.push( & scope );
|
||||
|
||||
CodeComment
|
||||
result = (CodeComment) make_code();
|
||||
result->Type = ECode::Comment;
|
||||
result->Content = get_cached_string( currtok );
|
||||
result->Content = get_cached_string( currtok_noskip );
|
||||
result->Name = result->Content;
|
||||
eat( TokType::Comment );
|
||||
|
||||
if ( check( TokType::Comment_End ) )
|
||||
eat( TokType::Comment_End );
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -1804,7 +1797,8 @@ CodeFn parse_function_after_name(
|
||||
eat( currtok.Type );
|
||||
}
|
||||
|
||||
CodeBody body = { nullptr };
|
||||
CodeBody body = NoCode;
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( check( TokType::BraceCurly_Open ) )
|
||||
{
|
||||
body = parse_function_body();
|
||||
@ -1816,7 +1810,11 @@ CodeFn parse_function_after_name(
|
||||
}
|
||||
else
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type && TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
using namespace ECode;
|
||||
@ -1858,6 +1856,9 @@ CodeFn parse_function_after_name(
|
||||
if ( params )
|
||||
result->Params = params;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -2127,6 +2128,7 @@ CodeOperator parse_operator_after_ret_type(
|
||||
|
||||
// Parse Body
|
||||
CodeBody body = { nullptr };
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( check( TokType::BraceCurly_Open ) )
|
||||
{
|
||||
body = parse_function_body();
|
||||
@ -2138,11 +2140,19 @@ CodeOperator parse_operator_after_ret_type(
|
||||
}
|
||||
else
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
// OpValidateResult check_result = operator__validate( op, params, ret_type, specifiers );
|
||||
CodeOperator result = def_operator( op, nspace, params, ret_type, body, specifiers, attributes, mflags );
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -2231,8 +2241,18 @@ CodeVar parse_variable_after_name(
|
||||
bitfield_expr = untyped_str( expr_tok );
|
||||
}
|
||||
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
// Check for inline comment : <type> <identifier> = <expression>; // <inline comment>
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( left
|
||||
&& ( currtok_noskip.Type == TokType::Comment )
|
||||
&& currtok_noskip.Line == stmt_end.Line )
|
||||
{
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
using namespace ECode;
|
||||
|
||||
CodeVar
|
||||
@ -2258,6 +2278,9 @@ CodeVar parse_variable_after_name(
|
||||
if ( expr )
|
||||
result->Value = expr;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -2294,7 +2317,11 @@ Code parse_simple_preprocess( Parser::TokType which )
|
||||
{
|
||||
if ( check( TokType::Statement_End ))
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
eat( TokType::Comment );
|
||||
}
|
||||
}
|
||||
|
||||
@ -2306,7 +2333,11 @@ Code parse_simple_preprocess( Parser::TokType which )
|
||||
{
|
||||
if ( check( TokType::Statement_End ))
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
eat( TokType::Comment );
|
||||
}
|
||||
}
|
||||
|
||||
@ -2382,7 +2413,6 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
|
||||
if ( check( TokType::Capture_Start) )
|
||||
{
|
||||
// Dealing with a function
|
||||
|
||||
result = parse_function_after_name( ModuleFlag::None, attributes, specifiers, type, name );
|
||||
}
|
||||
else
|
||||
@ -2575,7 +2605,7 @@ CodeBody parse_class_struct_body( Parser::TokType which, Parser::Token name = Pa
|
||||
eat( TokType::NewLine );
|
||||
break;
|
||||
|
||||
case TokType::Comment_Start:
|
||||
case TokType::Comment:
|
||||
member = parse_comment();
|
||||
break;
|
||||
|
||||
@ -2880,15 +2910,25 @@ Code parse_class_struct( Parser::TokType which, bool inplace_def = false )
|
||||
body = parse_class_struct_body( which, name );
|
||||
}
|
||||
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( ! inplace_def )
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
if ( which == TokType::Decl_Class )
|
||||
result = def_class( name, body, parent, access, attributes, mflags );
|
||||
|
||||
else
|
||||
result = def_struct( name, body, (CodeType)parent, access, attributes, mflags );
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
interfaces.free();
|
||||
return result;
|
||||
}
|
||||
@ -2972,7 +3012,7 @@ CodeBody parse_global_nspace( CodeT which )
|
||||
eat( TokType::NewLine );
|
||||
break;
|
||||
|
||||
case TokType::Comment_Start:
|
||||
case TokType::Comment:
|
||||
member = parse_comment();
|
||||
break;
|
||||
|
||||
@ -3234,8 +3274,9 @@ CodeConstructor parse_constructor()
|
||||
|
||||
Token identifier = parse_identifier();
|
||||
CodeParam params = parse_params();
|
||||
Code initializer_list = { nullptr };
|
||||
CodeBody body = { nullptr };
|
||||
Code initializer_list = NoCode;
|
||||
CodeBody body = NoCode;
|
||||
CodeComment inline_cmt = NoCode;
|
||||
|
||||
if ( check( TokType::Assign_Classifer ) )
|
||||
{
|
||||
@ -3263,6 +3304,14 @@ CodeConstructor parse_constructor()
|
||||
{
|
||||
body = parse_function_body();
|
||||
}
|
||||
else
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
CodeConstructor result = (CodeConstructor) make_code();
|
||||
|
||||
@ -3280,6 +3329,9 @@ CodeConstructor parse_constructor()
|
||||
else
|
||||
result->Type = ECode::Constructor_Fwd;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -3344,8 +3396,18 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
|
||||
}
|
||||
}
|
||||
|
||||
CodeComment inline_cmt = NoCode;
|
||||
|
||||
if ( check( TokType::BraceCurly_Open ) )
|
||||
body = parse_function_body();
|
||||
else
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
CodeDestructor result = (CodeDestructor) make_code();
|
||||
|
||||
@ -3360,6 +3422,9 @@ CodeDestructor parse_destructor( CodeSpecifiers specifiers )
|
||||
else
|
||||
result->Type = ECode::Destructor_Fwd;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -3452,7 +3517,7 @@ CodeEnum parse_enum( bool inplace_def )
|
||||
eat( TokType::NewLine );
|
||||
break;
|
||||
|
||||
case TokType::Comment_Start:
|
||||
case TokType::Comment:
|
||||
member = parse_comment();
|
||||
break;
|
||||
|
||||
@ -3528,9 +3593,17 @@ CodeEnum parse_enum( bool inplace_def )
|
||||
eat( TokType::BraceCurly_Close );
|
||||
}
|
||||
|
||||
CodeComment inline_cmt = NoCode;
|
||||
|
||||
if ( ! inplace_def )
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
using namespace ECode;
|
||||
|
||||
CodeEnum
|
||||
@ -3554,6 +3627,9 @@ CodeEnum parse_enum( bool inplace_def )
|
||||
if ( type )
|
||||
result->UnderlyingType = type;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -3691,8 +3767,13 @@ CodeFriend parse_friend()
|
||||
function->Params = params;
|
||||
}
|
||||
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
|
||||
CodeFriend
|
||||
result = (CodeFriend) make_code();
|
||||
result->Type = Friend;
|
||||
@ -3703,6 +3784,9 @@ CodeFriend parse_friend()
|
||||
else
|
||||
result->Declaration = type;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -3949,7 +4033,7 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
|
||||
using namespace Parser;
|
||||
push_scope();
|
||||
|
||||
// Specifiers attributed to the cast
|
||||
// TODO : Specifiers attributed to the cast
|
||||
|
||||
// Operator's namespace if not within same class.
|
||||
Token name = NullToken;
|
||||
@ -3987,7 +4071,8 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
|
||||
eat( TokType::Spec_Const );
|
||||
}
|
||||
|
||||
Code body = { nullptr };
|
||||
Code body = NoCode;
|
||||
CodeComment inline_cmt = NoCode;
|
||||
|
||||
if ( check( TokType::BraceCurly_Open) )
|
||||
{
|
||||
@ -4014,7 +4099,11 @@ CodeOpCast parse_operator_cast( CodeSpecifiers specifiers )
|
||||
}
|
||||
else
|
||||
{
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
CodeOpCast result = (CodeOpCast) make_code();
|
||||
@ -4543,8 +4632,13 @@ CodeTypedef parse_typedef()
|
||||
|
||||
array_expr = parse_array_decl();
|
||||
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
inline_cmt = parse_comment();
|
||||
|
||||
using namespace ECode;
|
||||
|
||||
CodeTypedef
|
||||
@ -4568,6 +4662,9 @@ CodeTypedef parse_typedef()
|
||||
if ( type->Type == Typename && array_expr && array_expr->Type != Invalid )
|
||||
type.cast<CodeType>()->ArrExpr = array_expr;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
|
||||
Context.pop();
|
||||
return result;
|
||||
}
|
||||
@ -4633,7 +4730,7 @@ CodeUnion parse_union( bool inplace_def )
|
||||
eat( TokType::NewLine );
|
||||
break;
|
||||
|
||||
case TokType::Comment_Start:
|
||||
case TokType::Comment:
|
||||
member = parse_comment();
|
||||
break;
|
||||
|
||||
@ -4778,8 +4875,15 @@ CodeUsing parse_using()
|
||||
|
||||
array_expr = parse_array_decl();
|
||||
|
||||
Token stmt_end = currtok;
|
||||
eat( TokType::Statement_End );
|
||||
|
||||
CodeComment inline_cmt = NoCode;
|
||||
if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
{
|
||||
inline_cmt = parse_comment();
|
||||
}
|
||||
|
||||
using namespace ECode;
|
||||
|
||||
CodeUsing
|
||||
@ -4803,6 +4907,9 @@ CodeUsing parse_using()
|
||||
|
||||
if ( attributes )
|
||||
result->Attributes = attributes;
|
||||
|
||||
if ( inline_cmt )
|
||||
result->InlineCmt = inline_cmt;
|
||||
}
|
||||
|
||||
Context.pop();
|
||||
|
@ -415,12 +415,42 @@ CodeComment def_comment( StrC content )
|
||||
return CodeInvalid;
|
||||
}
|
||||
|
||||
static char line[ MaxCommentLineLength ];
|
||||
|
||||
String cmt_formatted = String::make_reserve( GlobalAllocator, kilobytes(1) );
|
||||
char const* end = content.Ptr + content.Len;
|
||||
char const* scanner = content.Ptr;
|
||||
s32 curr = 0;
|
||||
do
|
||||
{
|
||||
char const* next = scanner;
|
||||
s32 length = 0;
|
||||
while ( next != end && scanner[ length ] != '\n' )
|
||||
{
|
||||
next = scanner + length;
|
||||
length++;
|
||||
}
|
||||
length++;
|
||||
|
||||
str_copy( line, scanner, length );
|
||||
cmt_formatted.append_fmt( "//%.*s", length, line );
|
||||
mem_set( line, 0, MaxCommentLineLength );
|
||||
|
||||
scanner += length;
|
||||
}
|
||||
while ( scanner <= end );
|
||||
|
||||
if ( cmt_formatted.back() != '\n' )
|
||||
cmt_formatted.append( "\n" );
|
||||
|
||||
Code
|
||||
result = make_code();
|
||||
result->Type = ECode::Comment;
|
||||
result->Name = get_cached_string( content );
|
||||
result->Name = get_cached_string( cmt_formatted );
|
||||
result->Content = result->Name;
|
||||
|
||||
cmt_formatted.free();
|
||||
|
||||
return (CodeComment) result;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ BraceSquare_Open, "["
|
||||
BraceSquare_Close, "]"
|
||||
Capture_Start, "("
|
||||
Capture_End, ")"
|
||||
Comment, "__comemnt__"
|
||||
Comment, "__comment__"
|
||||
Comment_End, "__comment_end__"
|
||||
Comment_Start, "__comment_start__"
|
||||
Char, "__character__"
|
||||
|
|
@ -17,7 +17,7 @@ GEN_NS_END
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gen.bootstrap.cpp "
|
||||
"// This file was generated automatially by gencpp's singleheader.cpp"
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
constexpr StrC implementation_guard_start = txt(R"(
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "gen.builder.cpp"
|
||||
#include "sanity.cpp"
|
||||
#include "SOA.cpp"
|
||||
#include "test.singleheader.cpp"
|
||||
#include "validate.singleheader.cpp"
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
@ -18,7 +18,7 @@ int gen_main()
|
||||
|
||||
// check_SOA();
|
||||
|
||||
// check_singleheader_ast();
|
||||
check_singleheader_ast();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user