Skip to content

Commit

Permalink
Last fixes before handmade hero hiatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed94 committed Sep 25, 2023
1 parent 754bcfb commit 729c891
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 15 deletions.
75 changes: 63 additions & 12 deletions project/components/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,13 +690,25 @@ String AST::to_string()
case Function:
{
if ( bitfield_is_equal( u32, ModuleFlags, ModuleFlag::Export ))
result.append( "export " );
result.append( "export" );

if ( Attributes )
result.append_fmt( "%S ", Attributes->to_string() );
result.append_fmt( " %S ", Attributes->to_string() );

if ( Specs )
result.append_fmt( "%S", Specs->to_string() );
{
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
{
if ( ! ESpecifier::is_trailing( spec ) )
{
StrC spec_str = ESpecifier::to_str( spec );
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
}
}
}

if ( Attributes || Specs )
result.append( "\n" );

if ( ReturnType )
result.append_fmt( "%S %S(", ReturnType->to_string(), Name );
Expand Down Expand Up @@ -735,7 +747,21 @@ String AST::to_string()
result.append_fmt( "%S ", Attributes->to_string() );

if ( Specs )
result.append_fmt( "%S", Specs->to_string() );
{
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
{
if ( ! ESpecifier::is_trailing( spec ) )
{
StrC spec_str = ESpecifier::to_str( spec );
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
}
}
}

if ( Attributes || Specs )
{
result.append("\n" );
}

if ( ReturnType )
result.append_fmt( "%S %S(", ReturnType->to_string(), Name );
Expand Down Expand Up @@ -795,7 +821,24 @@ String AST::to_string()
result.append_fmt( "%S ", Attributes->to_string() );

if ( Attributes )
result.append_fmt( "%S\n", Attributes->to_string() );
result.append_fmt( "%S ", Attributes->to_string() );

if ( Specs )
{
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
{
if ( ! ESpecifier::is_trailing( spec ) )
{
StrC spec_str = ESpecifier::to_str( spec );
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
}
}
}

if ( Attributes || Specs )
{
result.append("\n" );
}

if ( ReturnType )
result.append_fmt( "%S %S (", ReturnType->to_string(), Name );
Expand Down Expand Up @@ -834,7 +877,21 @@ String AST::to_string()
result.append_fmt( "%S\n", Attributes->to_string() );

if ( Specs )
result.append_fmt( "%S\n", Specs->to_string() );
{
for ( SpecifierT spec : Specs->cast<CodeSpecifiers>() )
{
if ( ! ESpecifier::is_trailing( spec ) )
{
StrC spec_str = ESpecifier::to_str( spec );
result.append_fmt( " %.*s", spec_str.Len, spec_str.Ptr );
}
}
}

if ( Attributes || Specs )
{
result.append("\n" );
}

result.append_fmt( "%S %S (", ReturnType->to_string(), Name );

Expand Down Expand Up @@ -991,12 +1048,6 @@ String AST::to_string()
s32 left = NumEntries;
while ( left-- )
{
if ( ESpecifier::is_trailing( ArrSpecs[idx]) && ArrSpecs[idx] != ESpecifier::Const )
{
idx++;
continue;
}

StrC spec = ESpecifier::to_str( ArrSpecs[idx] );
result.append_fmt( "%.*s ", spec.Len, spec.Ptr );
idx++;
Expand Down
4 changes: 2 additions & 2 deletions project/components/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct AST
};
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. ( May not be needed )
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
};
};
StringCached Content; // Attributes, Comment, Execution, Include
Expand Down Expand Up @@ -316,7 +316,7 @@ struct AST_POD
};
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. ( May not be needed )
AST* SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed )
};
};
StringCached Content; // Attributes, Comment, Execution, Include
Expand Down
3 changes: 2 additions & 1 deletion project/components/interface.parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,7 @@ CodeFn parse_function_after_name(

CodeParam params = parse_params();

// These have to be kept separate from the return type's specifiers.
while ( left && currtok.is_specifier() )
{
if ( specifiers.ast == nullptr )
Expand Down Expand Up @@ -4784,7 +4785,7 @@ CodeType parse_type( bool* typedef_is_function )
#if 0
else if ( currtok.Type == TokType::DeclType )
{
// Will have a capture and its own parsing rules, were going to just shove everything in a string.
// Will have a capture and its own parsing rules, were going to just shove everything in a string (for now).
name = currtok;
eat( TokType::DeclType );

Expand Down

0 comments on commit 729c891

Please sign in to comment.