test completes singleheader ast construction and serailizes with corruption

This commit is contained in:
Edward R. Gonzalez 2023-08-02 14:01:56 -04:00
parent b96b0821c1
commit a8a9b681f0
4 changed files with 39 additions and 47 deletions

View File

@ -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<CodeSpecifiers>();
@ -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;
}

View File

@ -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 );
@ -2019,7 +2019,6 @@ CodeVar parse_variable_after_name(
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 )
{

View File

@ -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, ... )

View File

@ -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++;
}