From a8a9b681f0a1ec75272782252b1901fcd25ebe8e Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 2 Aug 2023 14:01:56 -0400 Subject: [PATCH] test completes singleheader ast construction and serailizes with corruption --- project/components/ast.cpp | 4 +- project/components/interface.parsing.cpp | 76 ++++++++++-------------- project/file_processors/builder.cpp | 2 +- test/test.singleheader_ast.cpp | 4 ++ 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/project/components/ast.cpp b/project/components/ast.cpp index 33babe4..8804942 100644 --- a/project/components/ast.cpp +++ b/project/components/ast.cpp @@ -483,7 +483,7 @@ String AST::to_string() case Operator_Cast_Fwd: if ( Specs ) { - result.append_fmt( "operator %s()" ); + result.append_fmt( "operator %s()", ValueType->to_string() ); CodeSpecifiers specs = cast(); @@ -493,7 +493,7 @@ String AST::to_string() result.append_fmt( " %s", (char const*)ESpecifier::to_str( spec ) ); } - result.append_fmt( ";", Body->to_string() ); + result.append( ";" ); break; } diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp index 7dde9a3..8de7a61 100644 --- a/project/components/interface.parsing.cpp +++ b/project/components/interface.parsing.cpp @@ -1498,11 +1498,6 @@ CodeParam parse_params( bool use_template_capture = false ) Token name = NullToken; - if ( Context.Tokens.Idx == 18546 ) - { - log_fmt("here"); - } - if ( check( TokType::Identifier ) ) { name = currtok; @@ -1521,7 +1516,10 @@ CodeParam parse_params( bool use_template_capture = false ) return CodeInvalid; } - while ( left && currtok.Type != TokType::Comma ) + while ( left + && currtok.Type != TokType::Comma + && currtok.Type != TokType::Capture_End + ) { value_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)value_tok.Text; eat( currtok.Type ); @@ -1589,7 +1587,9 @@ CodeParam parse_params( bool use_template_capture = false ) return CodeInvalid; } - while ( left && currtok.Type != TokType::Comma ) + while ( left + && currtok.Type != TokType::Comma && currtok.Type != TokType::Capture_End + ) { value_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)value_tok.Text; eat( currtok.Type ); @@ -2017,9 +2017,8 @@ CodeVar parse_variable_after_name( using namespace Parser; push_scope(); - Code array_expr = parse_array_decl(); - Code expr = { nullptr }; - + Code array_expr = parse_array_decl(); + Code expr = { nullptr }; Code bitfield_expr = { nullptr }; if ( currtok.IsAssign ) @@ -2044,6 +2043,29 @@ CodeVar parse_variable_after_name( expr = untyped_str( expr_tok ); } + if ( currtok.Type == TokType::BraceCurly_Open ) + { + Token expr_tok = currtok; + + eat( TokType::BraceCurly_Open ); + + s32 level = 0; + while ( left && ( currtok.Type != TokType::BraceCurly_Close || level > 0 ) ) + { + if ( currtok.Type == TokType::BraceCurly_Open ) + level++; + + else if ( currtok.Type == TokType::BraceCurly_Close && level > 0 ) + level--; + + eat( currtok.Type ); + } + eat( TokType::BraceCurly_Close ); + + expr_tok.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)expr_tok.Text; + expr = untyped_str( expr_tok ); + } + if ( currtok.Type == TokType::Assign_Classifer ) { eat( TokType::Assign_Classifer ); @@ -2142,40 +2164,6 @@ Code parse_simple_preprocess( Parser::TokType which ) return result; } -internal inline -Code parse_variable_assignment() -{ - using namespace Parser; - push_scope(); - - Code expr = CodeInvalid; - - if ( currtok.IsAssign ) - { - eat( TokType::Operator ); - - Token expr_tok = currtok; - - if ( currtok.Type == TokType::Statement_End ) - { - log_failure( "Expected expression after assignment operator\n%s", Context.to_string() ); - Context.pop(); - return CodeInvalid; - } - - while ( left && currtok.Type != TokType::Statement_End ) - { - expr_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)expr_tok.Text; - eat( currtok.Type ); - } - - expr = untyped_str( expr_tok ); - } - - Context.pop(); - return expr; -} - internal inline Code parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers ) { diff --git a/project/file_processors/builder.cpp b/project/file_processors/builder.cpp index 64662ea..e747d43 100644 --- a/project/file_processors/builder.cpp +++ b/project/file_processors/builder.cpp @@ -1,6 +1,6 @@ void Builder::print( Code code ) { - Buffer.append_fmt( "%s", code->to_string() ); + Buffer.append( code->to_string() ); } void Builder::print_fmt( char const* fmt, ... ) diff --git a/test/test.singleheader_ast.cpp b/test/test.singleheader_ast.cpp index 4322b74..7fa0efe 100644 --- a/test/test.singleheader_ast.cpp +++ b/test/test.singleheader_ast.cpp @@ -23,6 +23,10 @@ void check_singleheader_ast() s32 idx = 0; for ( Code entry : ast ) { + if (idx == 900) + { + log_fmt("break here\n"); + } log_fmt("Entry %d: %s\n", idx, entry.to_string() ); idx++; }