diff --git a/project/components/ast.cpp b/project/components/ast.cpp index e5b82b4..b457bb6 100644 --- a/project/components/ast.cpp +++ b/project/components/ast.cpp @@ -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() ) + { + 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 ); @@ -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() ) + { + 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 ); @@ -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() ) + { + 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 ); @@ -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() ) + { + 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 ); @@ -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++; diff --git a/project/components/ast.hpp b/project/components/ast.hpp index 46a8311..4ddcb90 100644 --- a/project/components/ast.hpp +++ b/project/components/ast.hpp @@ -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 @@ -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 diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp index 2f86926..e90c8f0 100644 --- a/project/components/interface.parsing.cpp +++ b/project/components/interface.parsing.cpp @@ -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 ) @@ -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 );