mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
Single header generates again, some more cleanup.
Looking into properly dealing with empty lines... I want to preserve the text's empty lines in the AST for serialization purposes (perserve formatting for gapes between definitions). Don't want to introduce the possibility of it breaking though, so will have to ignore empty_lines in a general way (if they are in a bad spot). Attempted to cover that by having TokArray::current() auto-skip empty lines and eat as well if the type doesn't match.
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
#pragma region AST
|
||||
|
||||
Code Code::Global;
|
||||
Code Code::Invalid;
|
||||
|
||||
@ -916,6 +914,3 @@ bool AST::validate_body()
|
||||
|
||||
#undef CheckEntries
|
||||
}
|
||||
|
||||
#pragma endregion AST
|
||||
|
||||
|
@ -383,9 +383,7 @@ StringCached get_cached_string( StrC str )
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Used internally to retireve a Code object form the CodePool.
|
||||
*/
|
||||
// Used internally to retireve a Code object form the CodePool.
|
||||
Code make_code()
|
||||
{
|
||||
Pool* allocator = & CodePools.back();
|
||||
|
@ -65,17 +65,19 @@ namespace Parser
|
||||
|
||||
Token& current()
|
||||
{
|
||||
while ( Arr[Idx].Type == TokType::Empty_Line )
|
||||
Idx++;
|
||||
|
||||
return Arr[Idx];
|
||||
}
|
||||
|
||||
Token& previous()
|
||||
{
|
||||
return Arr[Idx - 1];
|
||||
}
|
||||
s32 idx = this->Idx;
|
||||
while ( Arr[Idx].Type == TokType::Empty_Line )
|
||||
idx--;
|
||||
|
||||
Token* next()
|
||||
{
|
||||
return Idx + 1 < Arr.num() ? &Arr[Idx + 1] : nullptr;
|
||||
return Arr[idx - 1];
|
||||
}
|
||||
|
||||
Token& operator []( s32 idx )
|
||||
@ -168,6 +170,12 @@ namespace Parser
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( Arr[Idx].Type == TokType::Empty_Line && type != TokType::Empty_Line )
|
||||
{
|
||||
Idx++;
|
||||
return log_fmt( "Auto-skipping empty line (%d, %d)\n", current().Line, current().Column );
|
||||
}
|
||||
|
||||
if ( Arr[Idx].Type != type )
|
||||
{
|
||||
String token_str = String::make( GlobalAllocator, { Arr[Idx].Length, Arr[Idx].Text } );
|
||||
@ -203,7 +211,7 @@ namespace Parser
|
||||
if ( current == '\n' ) \
|
||||
{ \
|
||||
line++; \
|
||||
column = 0; \
|
||||
column = 1; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
@ -249,13 +257,25 @@ namespace Parser
|
||||
{
|
||||
Token token = { nullptr, 0, TokType::Invalid, line, column, false };
|
||||
|
||||
if ( line == 4921 )
|
||||
{
|
||||
log_fmt("here");
|
||||
}
|
||||
|
||||
bool is_define = false;
|
||||
|
||||
if ( column == 1 )
|
||||
{
|
||||
token.Text = scanner;
|
||||
|
||||
if ( current == '\r')
|
||||
token.Length = 1;
|
||||
|
||||
if ( current == '\n' )
|
||||
{
|
||||
token.Type = TokType::Empty_Line;
|
||||
token.Length ++;
|
||||
|
||||
Tokens.append( token );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
SkipWhitespace();
|
||||
if ( left <= 0 )
|
||||
break;
|
||||
@ -1022,13 +1042,16 @@ if ( def.Ptr == nullptr ) \
|
||||
return CodeInvalid; \
|
||||
}
|
||||
|
||||
# define nexttok Context.Tokens.next()
|
||||
# define currtok Context.Tokens.current()
|
||||
# define prevtok Context.Tokens.previous()
|
||||
# define eat( Type_ ) Context.Tokens.__eat( Type_ )
|
||||
# define left ( Context.Tokens.Arr.num() - Context.Tokens.Idx )
|
||||
|
||||
# define check( Type_ ) ( left && currtok.Type == Type_ )
|
||||
# define check( Type_ ) \
|
||||
( left \
|
||||
&& (currtok.Type == TokType::Empty_Line ? \
|
||||
eat( TokType::Empty_Line) : true) \
|
||||
&& currtok.Type == Type_ )
|
||||
|
||||
# define push_scope() \
|
||||
StackNode scope { nullptr, currtok, NullToken, txt_StrC( __func__ ) }; \
|
||||
@ -2402,6 +2425,12 @@ CodeBody parse_class_struct_body( Parser::TokType which )
|
||||
|
||||
switch ( currtok.Type )
|
||||
{
|
||||
case TokType::Empty_Line:
|
||||
// Empty lines are auto skipped by Tokens.current()
|
||||
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] );
|
||||
eat( TokType::Empty_Line );
|
||||
break;
|
||||
|
||||
case TokType::Comment:
|
||||
member = def_comment( currtok );
|
||||
eat( TokType::Comment );
|
||||
@ -2756,6 +2785,12 @@ CodeBody parse_global_nspace( CodeT which )
|
||||
|
||||
switch ( currtok.Type )
|
||||
{
|
||||
case TokType::Empty_Line:
|
||||
// Empty lines are auto skipped by Tokens.current()
|
||||
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] );
|
||||
eat( TokType::Empty_Line );
|
||||
break;
|
||||
|
||||
case TokType::Comment:
|
||||
member = def_comment( currtok );
|
||||
eat( TokType::Comment );
|
||||
@ -3072,6 +3107,12 @@ CodeEnum parse_enum( bool inplace_def )
|
||||
{
|
||||
switch ( currtok.Type )
|
||||
{
|
||||
case TokType::Empty_Line:
|
||||
// Empty lines are auto skipped by Tokens.current()
|
||||
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] );
|
||||
eat( TokType::Empty_Line );
|
||||
break;
|
||||
|
||||
case TokType::Comment:
|
||||
member = def_comment( currtok );
|
||||
eat( TokType::Comment );
|
||||
@ -4027,11 +4068,6 @@ CodeTypedef parse_typedef()
|
||||
|
||||
eat( TokType::Decl_Typedef );
|
||||
|
||||
if ( currtok.Line == 2196 )
|
||||
{
|
||||
log_fmt("here");
|
||||
}
|
||||
|
||||
constexpr bool from_typedef = true;
|
||||
|
||||
if ( check( TokType::Preprocess_Macro ))
|
||||
@ -4144,6 +4180,12 @@ CodeUnion parse_union( bool inplace_def )
|
||||
Code member = { nullptr };
|
||||
switch ( currtok.Type )
|
||||
{
|
||||
case TokType::Empty_Line:
|
||||
// Empty lines are auto skipped by Tokens.current()
|
||||
member = untyped_str( Context.Tokens.Arr[ Context.Tokens.Idx] );
|
||||
eat( TokType::Empty_Line );
|
||||
break;
|
||||
|
||||
case TokType::Comment:
|
||||
member = def_comment( currtok );
|
||||
eat( TokType::Comment );
|
||||
@ -4422,7 +4464,6 @@ CodeVar parse_variable( StrC def )
|
||||
|
||||
// Undef helper macros
|
||||
# undef check_parse_args
|
||||
# undef nexttok
|
||||
# undef currtok
|
||||
# undef prevtok
|
||||
# undef eat
|
||||
|
@ -1,3 +1,5 @@
|
||||
#pragma region Upfront
|
||||
|
||||
enum class OpValidateResult : u32
|
||||
{
|
||||
Fail,
|
||||
@ -375,7 +377,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
|
||||
|
||||
|
||||
/*
|
||||
The implementaiton of the upfront constructors involves bascially doing three things:
|
||||
The implementaiton of the upfront constructors involves doing three things:
|
||||
* Validate the arguments given to construct the intended type of AST is valid.
|
||||
* Construct said AST type.
|
||||
* Lock the AST (set to readonly) and return the valid object.
|
||||
@ -2130,4 +2132,9 @@ CodeBody def_union_body( s32 num, CodeUnion* codes )
|
||||
# undef name_check
|
||||
# undef null_check
|
||||
# undef null_or_invalid_check
|
||||
# undef def_body_start
|
||||
# undef def_body_code_array_start
|
||||
|
||||
|
||||
#pragma endregion Upfront
|
||||
|
||||
|
@ -53,8 +53,8 @@ namespace ECode
|
||||
Entry( Template ) \
|
||||
Entry( Typedef ) \
|
||||
Entry( Typename ) \
|
||||
Entry( Union ) \
|
||||
Entry( Union_Body) \
|
||||
Entry( Union ) \
|
||||
Entry( Union_Body) \
|
||||
Entry( Using ) \
|
||||
Entry( Using_Namespace ) \
|
||||
Entry( Variable )
|
||||
|
@ -26,7 +26,7 @@ namespace Parser
|
||||
Entry( Ampersand_DBL, "&&" ) \
|
||||
Entry( Assign_Classifer, ":" ) \
|
||||
Entry( Attribute_Open, "[[" ) \
|
||||
Entry( Attribute_Close, "]]" ) \
|
||||
Entry( Attribute_Close, "]]" ) \
|
||||
Entry( BraceCurly_Open, "{" ) \
|
||||
Entry( BraceCurly_Close, "}" ) \
|
||||
Entry( BraceSquare_Open, "[" ) \
|
||||
@ -50,6 +50,7 @@ namespace Parser
|
||||
Entry( Decl_Typedef, "typedef" ) \
|
||||
Entry( Decl_Using, "using" ) \
|
||||
Entry( Decl_Union, "union" ) \
|
||||
Entry( Empty_Line, "__empty_line__" ) \
|
||||
Entry( Identifier, "__identifier__" ) \
|
||||
Entry( Module_Import, "import" ) \
|
||||
Entry( Module_Export, "export" ) \
|
||||
@ -63,8 +64,8 @@ namespace Parser
|
||||
Entry( Preprocess_Else, "else") \
|
||||
Entry( Preprocess_EndIf, "endif") \
|
||||
Entry( Preprocess_Include, "include" ) \
|
||||
Entry( Preprocess_Pragma, "pragma") \
|
||||
Entry( Preprocess_Content, "__macro_content__") \
|
||||
Entry( Preprocess_Pragma, "pragma") \
|
||||
Entry( Preprocess_Content, "__macro_content__") \
|
||||
Entry( Preprocess_Macro, "__macro__") \
|
||||
Entry( Preprocess_Unsupported, "__unsupported__" ) \
|
||||
Entry( Spec_Alignas, "alignas" ) \
|
||||
@ -72,10 +73,10 @@ namespace Parser
|
||||
Entry( Spec_Consteval, "consteval" ) \
|
||||
Entry( Spec_Constexpr, "constexpr" ) \
|
||||
Entry( Spec_Constinit, "constinit" ) \
|
||||
Entry( Spec_Explicit, "explicit" ) \
|
||||
Entry( Spec_Explicit, "explicit" ) \
|
||||
Entry( Spec_Extern, "extern" ) \
|
||||
Entry( Spec_Final, "final" ) \
|
||||
Entry( Spec_Global, "global" ) \
|
||||
Entry( Spec_Final, "final" ) \
|
||||
Entry( Spec_Global, "global" ) \
|
||||
Entry( Spec_Inline, "inline" ) \
|
||||
Entry( Spec_Internal_Linkage, "internal" ) \
|
||||
Entry( Spec_LocalPersist, "local_persist" ) \
|
||||
@ -87,20 +88,20 @@ namespace Parser
|
||||
Entry( Spec_Volatile, "volatile") \
|
||||
Entry( Star, "*" ) \
|
||||
Entry( Statement_End, ";" ) \
|
||||
Entry( StaticAssert, "static_assert" ) \
|
||||
Entry( StaticAssert, "static_assert" ) \
|
||||
Entry( String, "__string__" ) \
|
||||
Entry( Type_Unsigned, "unsigned" ) \
|
||||
Entry( Type_Unsigned, "unsigned" ) \
|
||||
Entry( Type_Signed, "signed" ) \
|
||||
Entry( Type_Short, "short" ) \
|
||||
Entry( Type_Long, "long" ) \
|
||||
Entry( Type_char, "char" ) \
|
||||
Entry( Type_int, "int" ) \
|
||||
Entry( Type_double, "double" ) \
|
||||
Entry( Type_MS_int8, "__int8" ) \
|
||||
Entry( Type_MS_int16, "__int16" ) \
|
||||
Entry( Type_MS_int32, "__int32" ) \
|
||||
Entry( Type_MS_int64, "__int64" ) \
|
||||
Entry( Type_MS_W64, "_W64" ) \
|
||||
Entry( Type_char, "char" ) \
|
||||
Entry( Type_int, "int" ) \
|
||||
Entry( Type_double, "double" ) \
|
||||
Entry( Type_MS_int8, "__int8" ) \
|
||||
Entry( Type_MS_int16, "__int16" ) \
|
||||
Entry( Type_MS_int32, "__int32" ) \
|
||||
Entry( Type_MS_int64, "__int64" ) \
|
||||
Entry( Type_MS_W64, "_W64" ) \
|
||||
Entry( Varadic_Argument, "..." ) \
|
||||
Entry( __Attributes_Start, "__attrib_start__" )
|
||||
|
||||
|
Reference in New Issue
Block a user