diff --git a/project/components/ast.cpp b/project/components/ast.cpp index 3f262fc..b92b260 100644 --- a/project/components/ast.cpp +++ b/project/components/ast.cpp @@ -475,29 +475,29 @@ void to_string( AST* self, String* result ) break; case Module: - cast(CodeModule, {self}).to_string( * result ); + to_string(cast(CodeModule, {self}), result ); break; case Namespace: - cast(CodeNS, {self}).to_string( * result ); + to_string(cast(CodeNS, {self}), result ); break; case Operator: case Operator_Member: - cast(CodeOperator, {self}).to_string_def( * result ); + to_string_def(cast(CodeOperator, {self}), result ); break; case Operator_Fwd: case Operator_Member_Fwd: - cast(CodeOperator, {self}).to_string_fwd( * result ); + to_string_fwd(cast(CodeOperator, {self}), result ); break; case Operator_Cast: - cast(CodeOpCast, {self}).to_string_def( * result ); + to_string_def(cast(CodeOpCast, {self}), result ); break; case Operator_Cast_Fwd: - cast(CodeOpCast, {self}).to_string_fwd( * result ); + to_string_fwd(cast(CodeOpCast, {self}), result ); break; case Parameters: @@ -509,15 +509,15 @@ void to_string( AST* self, String* result ) break; case Preprocess_If: - cast(CodePreprocessCond, {self}).to_string_if( * result ); + to_string_if(cast(CodePreprocessCond, {self}), result ); break; case Preprocess_IfDef: - cast(CodePreprocessCond, {self}).to_string_ifdef( * result ); + to_string_ifdef(cast(CodePreprocessCond, {self}), result ); break; case Preprocess_IfNotDef: - cast(CodePreprocessCond, {self}).to_string_ifndef( * result ); + to_string_ifndef(cast(CodePreprocessCond, {self}), result ); break; case Preprocess_Include: @@ -525,19 +525,19 @@ void to_string( AST* self, String* result ) break; case Preprocess_ElIf: - cast(CodePreprocessCond, {self}).to_string_elif( * result ); + to_string_elif(cast(CodePreprocessCond, {self}), result ); break; case Preprocess_Else: - cast(CodePreprocessCond, {self}).to_string_else( * result ); + to_string_else(cast(CodePreprocessCond, {self}), result ); break; case Preprocess_EndIf: - cast(CodePreprocessCond, {self}).to_string_endif( * result ); + to_string_endif(cast(CodePreprocessCond, {self}), result ); break; case Preprocess_Pragma: - cast(CodePragma, {self}).to_string( * result ); + to_string(cast(CodePragma, {self}), result ); break; case Specifiers: @@ -553,7 +553,7 @@ void to_string( AST* self, String* result ) break; case Template: - cast(CodeTemplate, {self}).to_string( * result ); + to_string(cast(CodeTemplate, {self}), result ); break; case Typedef: @@ -561,7 +561,7 @@ void to_string( AST* self, String* result ) break; case Typename: - cast(CodeType, {self}).to_string( * result ); + to_string(cast(CodeType, {self}), result ); break; case Union: diff --git a/project/components/code_serialization.cpp b/project/components/code_serialization.cpp index 3304678..71c1ccf 100644 --- a/project/components/code_serialization.cpp +++ b/project/components/code_serialization.cpp @@ -181,7 +181,7 @@ void to_string_def( CodeClass self, String* result ) { char const* access_level = to_str( ast->ParentAccess ); - append_fmt( result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() ); + append_fmt( result, "%S : %s %S", ast->Name, access_level, to_string(ast->ParentType) ); CodeType interface = cast(CodeType, ast->ParentType->Next); if ( interface ) @@ -189,7 +189,7 @@ void to_string_def( CodeClass self, String* result ) while ( interface ) { - append_fmt( result, ", %S", interface.to_string() ); + append_fmt( result, ", %S", to_string(interface) ); interface = interface->Next ? cast(CodeType, interface->Next) : CodeType { nullptr }; } } @@ -337,7 +337,7 @@ void to_string_def(CodeEnum self, String* result ) if ( self->UnderlyingType ) append_fmt( result, "%S : %S\n{\n%S\n}" , self->Name - , self->UnderlyingType.to_string() + , to_string(self->UnderlyingType) , GEN_NS to_string(self->Body) ); else if ( self->UnderlyingTypeMacro ) @@ -364,7 +364,7 @@ void to_string_fwd(CodeEnum self, String* result ) append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); if ( self->UnderlyingType ) - append_fmt( result, "enum %S : %S", self->Name, self->UnderlyingType.to_string() ); + append_fmt( result, "enum %S : %S", self->Name, to_string(self->UnderlyingType) ); else append_fmt( result, "enum %S", self->Name ); @@ -393,7 +393,7 @@ void to_string_class_def(CodeEnum self, String* result ) if ( self->UnderlyingType ) { - append_fmt( result, "%S : %S\n{\n%S\n}", self->Name, self->UnderlyingType.to_string(), GEN_NS to_string(self->Body) ); + append_fmt( result, "%S : %S\n{\n%S\n}", self->Name, to_string(self->UnderlyingType), GEN_NS to_string(self->Body) ); } else { @@ -419,7 +419,7 @@ void to_string_class_fwd(CodeEnum self, String* result ) if ( self->Attributes ) append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); - append_fmt( result, "%S : %S", self->Name, self->UnderlyingType.to_string() ); + append_fmt( result, "%S : %S", self->Name, to_string(self->UnderlyingType) ); if ( self->Parent.ast == nullptr || ( self->Parent->Type != ECode::Typedef && self->Parent->Type != ECode::Variable ) ) { @@ -518,7 +518,7 @@ void to_string_def(CodeFn self, String* result ) append( result, "\n" ); if ( self->ReturnType ) - append_fmt( result, "%S %S(", self->ReturnType.to_string(), self->Name ); + append_fmt( result, "%S %S(", to_string(self->ReturnType), self->Name ); else append_fmt( result, "%S(", self->Name ); @@ -573,7 +573,7 @@ void to_string_fwd(CodeFn self, String* result ) } if ( self->ReturnType ) - append_fmt( result, "%S %S(", self->ReturnType.to_string(), self->Name ); + append_fmt( result, "%S %S(", to_string(self->ReturnType), self->Name ); else append_fmt( result, "%S(", self->Name ); @@ -607,250 +607,250 @@ void to_string_fwd(CodeFn self, String* result ) append( result, ";\n" ); } -String CodeModule::to_string() +String to_string(CodeModule self) { String result = string_make( GlobalAllocator, "" ); - to_string( result ); + to_string( self, & result ); return result; } -void CodeModule::to_string( String& result ) +void to_string(CodeModule self, String* result ) { - if (((u32(ModuleFlag_Export) & u32(ast->ModuleFlags)) == u32(ModuleFlag_Export))) - append( & result, "export "); + if (((u32(ModuleFlag_Export) & u32(self->ModuleFlags)) == u32(ModuleFlag_Export))) + append( result, "export "); - if (((u32(ModuleFlag_Import) & u32(ast->ModuleFlags)) == u32(ModuleFlag_Import))) - append( & result, "import "); + if (((u32(ModuleFlag_Import) & u32(self->ModuleFlags)) == u32(ModuleFlag_Import))) + append( result, "import "); - append_fmt( & result, "%S;\n", ast->Name ); + append_fmt( result, "%S;\n", self->Name ); } -String CodeNS::to_string() +String to_string(CodeNS self) { String result = string_make( GlobalAllocator, "" ); - to_string( result ); + to_string( self, & result ); return result; } -void CodeNS::to_string( String& result ) +void to_string(CodeNS self, String* result ) { - if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) - append( & result, "export " ); + if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export )) + append( result, "export " ); - append_fmt( & result, "namespace %S\n{\n%S\n}\n", ast->Name , GEN_NS to_string(ast->Body) ); + append_fmt( result, "namespace %S\n{\n%S\n}\n", self->Name, to_string(self->Body) ); } -String CodeOperator::to_string() +String to_string(CodeOperator self) { String result = string_make( GlobalAllocator, "" ); - switch ( ast->Type ) + switch ( self->Type ) { using namespace ECode; case Operator: case Operator_Member: - to_string_def( result ); + to_string_def( self, & result ); break; case Operator_Fwd: case Operator_Member_Fwd: - to_string_fwd( result ); + to_string_fwd( self, & result ); break; } return result; } -void CodeOperator::to_string_def( String& result ) +void to_string_def(CodeOperator self, String* result ) { - if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) - append( & result, "export " ); + if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export )) + append( result, "export " ); - if ( ast->Attributes ) - append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); + if ( self->Attributes ) + append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); - if ( ast->Attributes ) - append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); + if ( self->Attributes ) + append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); - if ( ast->Specs ) + if ( self->Specs ) { - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ! ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); + append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); } } } - if ( ast->Attributes || ast->Specs ) + if ( self->Attributes || self->Specs ) { - append( & result, "\n" ); + append( result, "\n" ); } - if ( ast->ReturnType ) - append_fmt( & result, "%S %S (", ast->ReturnType.to_string(), ast->Name ); + if ( self->ReturnType ) + append_fmt( result, "%S %S (", GEN_NS to_string(self->ReturnType), self->Name ); - if ( ast->Params ) - append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) ); + if ( self->Params ) + append_fmt( result, "%S)", GEN_NS to_string(self->Params) ); else - append( & result, ")" ); + append( result, ")" ); - if ( ast->Specs ) + if ( self->Specs ) { - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); + append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); } } } - append_fmt( & result, "\n{\n%S\n}\n" - , GEN_NS to_string(ast->Body) + append_fmt( result, "\n{\n%S\n}\n" + , GEN_NS to_string(self->Body) ); } -void CodeOperator::to_string_fwd( String& result ) +void to_string_fwd(CodeOperator self, String* result ) { - if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) - append( & result, "export " ); + if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export )) + append( result, "export " ); - if ( ast->Attributes ) - append_fmt( & result, "%S\n",GEN_NS to_string(ast->Attributes) ); + if ( self->Attributes ) + append_fmt( result, "%S\n",GEN_NS to_string(self->Attributes) ); - if ( ast->Specs ) + if ( self->Specs ) { - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ! ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); + append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); } } } - if ( ast->Attributes || ast->Specs ) + if ( self->Attributes || self->Specs ) { - append( & result, "\n" ); + append( result, "\n" ); } - append_fmt( & result, "%S %S (", ast->ReturnType.to_string(), ast->Name ); + append_fmt( result, "%S %S (", to_string(self->ReturnType), self->Name ); - if ( ast->Params ) - append_fmt( & result, "%S)", GEN_NS to_string(ast->Params) ); + if ( self->Params ) + append_fmt( result, "%S)", GEN_NS to_string(self->Params) ); else - append_fmt( & result, ")" ); + append_fmt( result, ")" ); - if ( ast->Specs ) + if ( self->Specs ) { - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); + append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); } } } - if ( ast->InlineCmt ) - append_fmt( & result, "; %S", ast->InlineCmt->Content ); + if ( self->InlineCmt ) + append_fmt( result, "; %S", self->InlineCmt->Content ); else - append( & result, ";\n" ); + append( result, ";\n" ); } -String CodeOpCast::to_string() +String to_string(CodeOpCast self) { String result = string_make( GlobalAllocator, "" ); - switch ( ast->Type ) + switch ( self->Type ) { using namespace ECode; case Operator_Cast: - to_string_def( result ); + to_string_def(self, & result ); break; case Operator_Cast_Fwd: - to_string_fwd( result ); + to_string_fwd(self, & result ); break; } return result; } -void CodeOpCast::to_string_def( String& result ) +void to_string_def(CodeOpCast self, String* result ) { - if ( ast->Specs ) + if ( self->Specs ) { - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ! ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, "%*s ", spec_str.Len, spec_str.Ptr ); + append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr ); } } - if ( ast->Name && length(ast->Name) ) - append_fmt( & result, "%Soperator %S()", ast->Name, ast->ValueType.to_string() ); + if ( self->Name && length(self->Name) ) + append_fmt( result, "%Soperator %S()", self->Name, to_string(self->ValueType) ); else - append_fmt( & result, "operator %S()", ast->ValueType.to_string() ); + append_fmt( result, "operator %S()", to_string(self->ValueType) ); - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, " %.*s", spec_str.Len, spec_str.Ptr ); + append_fmt( result, " %.*s", spec_str.Len, spec_str.Ptr ); } } - append_fmt( & result, "\n{\n%S\n}\n", GEN_NS to_string(ast->Body) ); + append_fmt( result, "\n{\n%S\n}\n", GEN_NS to_string(self->Body) ); return; } - if ( ast->Name && length(ast->Name) ) - append_fmt( & result, "%Soperator %S()\n{\n%S\n}\n", ast->Name, ast->ValueType.to_string(), GEN_NS to_string(ast->Body) ); + if ( self->Name && length(self->Name) ) + append_fmt( result, "%Soperator %S()\n{\n%S\n}\n", self->Name, to_string(self->ValueType), GEN_NS to_string(self->Body) ); else - append_fmt( & result, "operator %S()\n{\n%S\n}\n", ast->ValueType.to_string(), GEN_NS to_string(ast->Body) ); + append_fmt( result, "operator %S()\n{\n%S\n}\n", to_string(self->ValueType), GEN_NS to_string(self->Body) ); } -void CodeOpCast::to_string_fwd( String& result ) +void to_string_fwd(CodeOpCast self, String* result ) { - if ( ast->Specs ) + if ( self->Specs ) { - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ! ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, "%*s ", spec_str.Len, spec_str.Ptr ); + append_fmt( result, "%*s ", spec_str.Len, spec_str.Ptr ); } } - append_fmt( & result, "operator %S()", ast->ValueType.to_string() ); + append_fmt( result, "operator %S()", to_string(self->ValueType) ); - for ( SpecifierT spec : ast->Specs ) + for ( SpecifierT spec : self->Specs ) { if ( ESpecifier::is_trailing( spec ) ) { StrC spec_str = ESpecifier::to_str( spec ); - append_fmt( & result, " %*s", spec_str.Len, spec_str.Ptr ); + append_fmt( result, " %*s", spec_str.Len, spec_str.Ptr ); } } - if ( ast->InlineCmt ) - append_fmt( & result, "; %S", ast->InlineCmt->Content ); + if ( self->InlineCmt ) + append_fmt( result, "; %S", self->InlineCmt->Content ); else - append( & result, ";\n" ); + append( result, ";\n" ); return; } - if ( ast->InlineCmt ) - append_fmt( & result, "operator %S(); %S", ast->ValueType.to_string() ); + if ( self->InlineCmt ) + append_fmt( result, "operator %S(); %S", to_string(self->ValueType) ); else - append_fmt( & result, "operator %S();\n", ast->ValueType.to_string() ); + append_fmt( result, "operator %S();\n", to_string(self->ValueType) ); } String to_string(CodeParam self) @@ -875,11 +875,11 @@ void to_string( CodeParam self, String* result ) if ( ast->ValueType.ast == nullptr ) append_fmt( result, " %S", ast->Name ); else - append_fmt( result, " %S %S", ast->ValueType.to_string(), ast->Name ); + append_fmt( result, " %S %S", to_string(ast->ValueType), ast->Name ); } else if ( ast->ValueType ) - append_fmt( result, " %S", ast->ValueType.to_string() ); + append_fmt( result, " %S", to_string(ast->ValueType) ); if ( ast->PostNameMacro ) { @@ -898,74 +898,74 @@ void to_string( CodeParam self, String* result ) } } -String CodePreprocessCond::to_string() +String to_string(CodePreprocessCond self) { String result = string_make( GlobalAllocator, "" ); - switch ( ast->Type ) + switch ( self->Type ) { using namespace ECode; case Preprocess_If: - to_string_if( result ); + to_string_if( self, & result ); break; case Preprocess_IfDef: - to_string_ifdef( result ); + to_string_ifdef( self, & result ); break; case Preprocess_IfNotDef: - to_string_ifndef( result ); + to_string_ifndef( self, & result ); break; case Preprocess_ElIf: - to_string_elif( result ); + to_string_elif( self, & result ); break; case Preprocess_Else: - to_string_else( result ); + to_string_else( self, & result ); break; case Preprocess_EndIf: - to_string_endif( result ); + to_string_endif( self, & result ); break; } return result; } -void CodePreprocessCond::to_string_if( String& result ) +void to_string_if(CodePreprocessCond cond, String* result ) { - append_fmt( & result, "#if %S\n", ast->Content ); + append_fmt( result, "#if %S\n", cond->Content ); } -void CodePreprocessCond::to_string_ifdef( String& result ) +void to_string_ifdef(CodePreprocessCond cond, String* result ) { - append_fmt( & result, "#ifdef %S\n", ast->Content ); + append_fmt( result, "#ifdef %S\n", cond->Content ); } -void CodePreprocessCond::to_string_ifndef( String& result ) +void to_string_ifndef(CodePreprocessCond cond, String* result ) { - append_fmt( & result, "#ifndef %S\n", ast->Content ); + append_fmt( result, "#ifndef %S\n", cond->Content ); } -void CodePreprocessCond::to_string_elif( String& result ) +void to_string_elif(CodePreprocessCond cond, String* result ) { - append_fmt( & result, "#elif %S\n", ast->Content ); + append_fmt( result, "#elif %S\n", cond->Content ); } -void CodePreprocessCond::to_string_else( String& result ) +void to_string_else(CodePreprocessCond cond, String* result ) { - append_fmt( & result, "#else\n" ); + append_fmt( result, "#else\n" ); } -void CodePreprocessCond::to_string_endif( String& result ) +void to_string_endif(CodePreprocessCond cond, String* result ) { - append_fmt( & result, "#endif\n" ); + append_fmt( result, "#endif\n" ); } -String CodePragma::to_string() +String to_string(CodePragma self) { String result = string_make( GlobalAllocator, "" ); - to_string( result ); + to_string( self, & result ); return result; } -void CodePragma::to_string( String& result ) +void to_string(CodePragma self, String* result ) { - append_fmt( & result, "#pragma %S\n", ast->Content ); + append_fmt( result, "#pragma %S\n", self->Content ); } String to_string(CodeSpecifiers self) @@ -1025,7 +1025,7 @@ void to_string_def( CodeStruct self, String* result ) { char const* access_level = to_str( ast->ParentAccess ); - append_fmt( result, "%S : %s %S", ast->Name, access_level, ast->ParentType.to_string() ); + append_fmt( result, "%S : %s %S", ast->Name, access_level, GEN_NS to_string(ast->ParentType) ); CodeType interface = cast(CodeType, ast->ParentType->Next); if ( interface ) @@ -1033,7 +1033,7 @@ void to_string_def( CodeStruct self, String* result ) while ( interface ) { - append_fmt( result, ", %S", interface.to_string() ); + append_fmt( result, ", %S", GEN_NS to_string(interface) ); interface = interface->Next ? cast( CodeType, interface->Next) : CodeType { nullptr }; } } @@ -1062,7 +1062,7 @@ void to_string_fwd( CodeStruct self, String* result ) append( result, "export " ); if ( ast->Attributes ) - append_fmt( result, "struct %S %S",GEN_NS to_string(ast->Attributes), ast->Name ); + append_fmt( result, "struct %S %S", GEN_NS to_string(ast->Attributes), ast->Name ); else append_fmt( result, "struct %S", ast->Name ); @@ -1075,22 +1075,22 @@ void to_string_fwd( CodeStruct self, String* result ) } } -String CodeTemplate::to_string() +String to_string(CodeTemplate self) { String result = string_make( GlobalAllocator, "" ); - to_string( result ); + to_string( self, & result ); return result; } -void CodeTemplate::to_string( String& result ) +void to_string(CodeTemplate self, String* result ) { - if ( bitfield_is_equal( u32, ast->ModuleFlags, ModuleFlag_Export )) - append( & result, "export " ); + if ( bitfield_is_equal( u32, self->ModuleFlags, ModuleFlag_Export )) + append( result, "export " ); - if ( ast->Params ) - append_fmt( & result, "template< %S >\n%S", GEN_NS to_string(ast->Params), GEN_NS to_string(ast->Declaration) ); + if ( self->Params ) + append_fmt( result, "template< %S >\n%S", GEN_NS to_string(self->Params), GEN_NS to_string(self->Declaration) ); else - append_fmt( & result, "template<>\n%S", GEN_NS to_string(ast->Declaration) ); + append_fmt( result, "template<>\n%S", GEN_NS to_string(self->Declaration) ); } String CodeTypedef::to_string() @@ -1135,57 +1135,57 @@ void CodeTypedef::to_string( String& result ) append( & result, "\n"); } -String CodeType::to_string() +String to_string(CodeType self) { String result = string_make( GlobalAllocator, "" ); - to_string( result ); + to_string( self, & result ); return result; } -void CodeType::to_string( String& result ) +void to_string(CodeType self, String* result ) { #if defined(GEN_USE_NEW_TYPENAME_PARSING) - if ( ast->ReturnType && ast->Params ) + if ( self->ReturnType && self->Params ) { - if ( ast->Attributes ) - append_fmt( result, "%S ",GEN_NS to_string(ast->Attributes) ); + if ( self->Attributes ) + append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); else { - if ( ast->Specs ) - append_fmt( & result, "%S ( %S ) ( %S ) %S", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string(), ast->Specs.to_string() ); + if ( self->Specs ) + append_fmt( result, "%S ( %S ) ( %S ) %S", self->ReturnType.to_string(), self->Name, self->Params.to_string(), self->Specs.to_string() ); else - append_fmt( & result, "%S ( %S ) ( %S )", ast->ReturnType.to_string(), ast->Name, ast->Params.to_string() ); + append_fmt( result, "%S ( %S ) ( %S )", self->ReturnType.to_string(), self->Name, self->Params.to_string() ); } break; } #else - if ( ast->ReturnType && ast->Params ) + if ( self->ReturnType && self->Params ) { - if ( ast->Attributes ) - append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); + if ( self->Attributes ) + append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); else { - if ( ast->Specs ) - append_fmt( & result, "%S %S ( %S ) %S", ast->ReturnType.to_string(), ast->Name, GEN_NS to_string(ast->Params), GEN_NS to_string(ast->Specs) ); + if ( self->Specs ) + append_fmt( result, "%S %S ( %S ) %S", GEN_NS to_string(self->ReturnType), self->Name, GEN_NS to_string(self->Params), GEN_NS to_string(self->Specs) ); else - append_fmt( & result, "%S %S ( %S )", ast->ReturnType.to_string(), ast->Name, GEN_NS to_string(ast->Params) ); + append_fmt( result, "%S %S ( %S )", GEN_NS to_string(self->ReturnType), self->Name, GEN_NS to_string(self->Params) ); } return; } #endif - if ( ast->Attributes ) - append_fmt( & result, "%S ",GEN_NS to_string(ast->Attributes) ); + if ( self->Attributes ) + append_fmt( result, "%S ",GEN_NS to_string(self->Attributes) ); - if ( ast->Specs ) - append_fmt( & result, "%S %S", ast->Name, GEN_NS to_string(ast->Specs) ); + if ( self->Specs ) + append_fmt( result, "%S %S", self->Name, GEN_NS to_string(self->Specs) ); else - append_fmt( & result, "%S", ast->Name ); + append_fmt( result, "%S", self->Name ); - if ( ast->IsParamPack ) - append( & result, "..."); + if ( self->IsParamPack ) + append( result, "..."); } String CodeUnion::to_string() @@ -1250,7 +1250,7 @@ void CodeUsing::to_string( String& result ) if ( ast->UnderlyingType ) { - append_fmt( & result, "using %S = %S", ast->Name, ast->UnderlyingType.to_string() ); + append_fmt( & result, "using %S = %S", ast->Name, GEN_NS to_string(ast->UnderlyingType) ); if ( ast->UnderlyingType->ArrExpr ) { @@ -1342,7 +1342,7 @@ void CodeVar::to_string( String& result ) if ( ast->Specs ) append_fmt( & result, "%S\n", GEN_NS to_string(ast->Specs) ); - append_fmt( & result, "%S %S", ast->ValueType.to_string(), ast->Name ); + append_fmt( & result, "%S %S", GEN_NS to_string(ast->ValueType), ast->Name ); if ( ast->ValueType->ArrExpr ) { @@ -1382,11 +1382,11 @@ void CodeVar::to_string( String& result ) } if ( ast->BitfieldSize ) - append_fmt( & result, "%S %S : %S", ast->ValueType.to_string(), ast->Name, GEN_NS to_string(ast->BitfieldSize) ); + append_fmt( & result, "%S %S : %S", GEN_NS to_string(ast->ValueType), ast->Name, GEN_NS to_string(ast->BitfieldSize) ); else if ( ast->ValueType->ArrExpr ) { - append_fmt( & result, "%S %S[ %S ]", ast->ValueType.to_string(), ast->Name, GEN_NS to_string(ast->ValueType->ArrExpr) ); + append_fmt( & result, "%S %S[ %S ]", GEN_NS to_string(ast->ValueType), ast->Name, GEN_NS to_string(ast->ValueType->ArrExpr) ); AST* next_arr_expr = ast->ValueType->ArrExpr->Next; while ( next_arr_expr ) @@ -1397,7 +1397,7 @@ void CodeVar::to_string( String& result ) } else - append_fmt( & result, "%S %S", ast->ValueType.to_string(), ast->Name ); + append_fmt( & result, "%S %S", GEN_NS to_string(ast->ValueType), ast->Name ); if ( ast->Value ) { diff --git a/project/components/code_types.hpp b/project/components/code_types.hpp index 302b667..5659f13 100644 --- a/project/components/code_types.hpp +++ b/project/components/code_types.hpp @@ -74,6 +74,37 @@ String to_string (CodeFn self); void to_string_def(CodeFn self, String* result); void to_string_fwd(CodeFn self, String* result); +String to_string(CodeModule self); +void to_string(CodeModule self, String* result); + +String to_string(CodeNS self); +void to_string(CodeNS self, String* result); + +String to_string (CodeOperator self); +void to_string_fwd(CodeOperator self, String* result ); +void to_string_def(CodeOperator self, String* result ); + +String to_string (CodeOpCast op_cast ); +void to_string_def(CodeOpCast op_cast, String* result ); +void to_string_fwd(CodeOpCast op_cast, String* result ); + +String to_string(CodePragma self); +void to_string(CodePragma self, String* result); + +String to_string (CodePreprocessCond cond); +void to_string_if (CodePreprocessCond cond, String* result ); +void to_string_ifdef (CodePreprocessCond cond, String* result ); +void to_string_ifndef(CodePreprocessCond cond, String* result ); +void to_string_elif (CodePreprocessCond cond, String* result ); +void to_string_else (CodePreprocessCond cond, String* result ); +void to_string_endif (CodePreprocessCond cond, String* result ); + +String to_string(CodeTemplate self); +void to_string(CodeTemplate self, String* result); + +String to_string(CodeType self); +void to_string(CodeType self, String* result); + #pragma region Code Types // These structs are not used at all by the C vairant. #if ! GEN_COMPILER_C @@ -292,10 +323,10 @@ struct CodeEnum Using_Code( CodeEnum ); String to_string() { return GEN_NS to_string(* this); } - void to_string_def( String& result ) { return GEN_NS to_string_def(* this); } - void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); } - void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this); } - void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this); } + void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } + void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } + void to_string_class_def( String& result ) { return GEN_NS to_string_class_def(* this, & result); } + void to_string_class_fwd( String& result ) { return GEN_NS to_string_class_fwd(* this, & result); } #endif Using_CodeOps(CodeEnum); @@ -573,8 +604,8 @@ struct CodeFn Using_Code( CodeFn ); String to_string() { return GEN_NS to_string(* this); } - void to_string_def( String& result ) { return GEN_NS to_string_def(* this); } - void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this); } + void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } + void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } #endif Using_CodeOps(CodeFn); @@ -585,11 +616,11 @@ struct CodeFn struct CodeModule { -#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES Using_Code( CodeModule ); - String to_string(); - void to_string( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string( String& result ) { return GEN_NS to_string(* this, & result); } #endif Using_CodeOps(CodeModule); @@ -600,11 +631,11 @@ struct CodeModule struct CodeNS { -#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES Using_Code( CodeNS ); - String to_string(); - void to_string( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string( String& result ) { return GEN_NS to_string(* this, & result); } #endif Using_CodeOps(CodeNS); @@ -615,12 +646,12 @@ struct CodeNS struct CodeOperator { -#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES Using_Code( CodeOperator ); - String to_string(); - void to_string_def( String& result ); - void to_string_fwd( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } + void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } #endif Using_CodeOps(CodeOperator); @@ -631,12 +662,12 @@ struct CodeOperator struct CodeOpCast { -#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES Using_Code( CodeOpCast ); - String to_string(); - void to_string_def( String& result ); - void to_string_fwd( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string_def( String& result ) { return GEN_NS to_string_def(* this, & result); } + void to_string_fwd( String& result ) { return GEN_NS to_string_fwd(* this, & result); } #endif Using_CodeOps(CodeOpCast); @@ -650,8 +681,8 @@ struct CodePragma #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 Using_Code( CodePragma ); - String to_string(); - void to_string( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string( String& result ) { return GEN_NS to_string(* this, & result); } #endif Using_CodeOps( CodePragma ); @@ -662,16 +693,16 @@ struct CodePragma struct CodePreprocessCond { -#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES Using_Code( CodePreprocessCond ); - String to_string(); - void to_string_if( String& result ); - void to_string_ifdef( String& result ); - void to_string_ifndef( String& result ); - void to_string_elif( String& result ); - void to_string_else( String& result ); - void to_string_endif( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string_if( String& result ) { return GEN_NS to_string_if(* this, & result); } + void to_string_ifdef( String& result ) { return GEN_NS to_string_ifdef(* this, & result); } + void to_string_ifndef( String& result ) { return GEN_NS to_string_ifndef(* this, & result); } + void to_string_elif( String& result ) { return GEN_NS to_string_elif(* this, & result); } + void to_string_else( String& result ) { return GEN_NS to_string_else(* this, & result); } + void to_string_endif( String& result ) { return GEN_NS to_string_endif(* this, & result); } #endif Using_CodeOps( CodePreprocessCond ); @@ -869,8 +900,8 @@ struct CodeTemplate #if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 Using_Code( CodeTemplate ); - String to_string(); - void to_string( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string( String& result ) { return GEN_NS to_string(* this, & result); } #endif Using_CodeOps( CodeTemplate ); @@ -881,11 +912,11 @@ struct CodeTemplate struct CodeType { -#if GEN_SUPPORT_CPP_MEMBER_FEATURES || 1 +#if GEN_SUPPORT_CPP_MEMBER_FEATURES Using_Code( CodeType ); - String to_string(); - void to_string( String& result ); + String to_string() { return GEN_NS to_string(* this); } + void to_string( String& result ) { return GEN_NS to_string(* this, & result); } #endif Using_CodeOps( CodeType ); diff --git a/project/components/interface.cpp b/project/components/interface.cpp index 63b9917..97049b6 100644 --- a/project/components/interface.cpp +++ b/project/components/interface.cpp @@ -145,7 +145,7 @@ void define_constants() # define def_constant_code_type( Type_ ) \ t_##Type_ = def_type( name(Type_) ); \ - t_##Type_.set_global(); + set_global(t_##Type_); def_constant_code_type( auto ); def_constant_code_type( void ); diff --git a/project/components/interface.upfront.cpp b/project/components/interface.upfront.cpp index 3d0c197..55a08c4 100644 --- a/project/components/interface.upfront.cpp +++ b/project/components/interface.upfront.cpp @@ -36,14 +36,14 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy } # define check_param_eq_ret() \ - if ( ! is_member_symbol && ! params_code->ValueType.is_equal( ret_type) ) \ + if ( ! is_member_symbol && ! is_equal(params_code->ValueType, ret_type) ) \ { \ log_failure("gen::def_operator: operator%s requires first parameter to equal return type\n" \ "param types: %s\n" \ "return type: %s", \ to_str(op).Ptr, \ debug_str(params_code), \ - ret_type.debug_str() \ + debug_str(ret_type) \ ); \ return OpValidateResult::Fail; \ } @@ -56,7 +56,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy if ( ret_type->Type != ECode::Typename ) { - log_failure("gen::def_operator: ret_type is not of typename type - %s", ret_type.debug_str()); + log_failure("gen::def_operator: ret_type is not of typename type - %s", debug_str(ret_type)); return OpValidateResult::Fail; } @@ -127,7 +127,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy switch ( params_code->NumEntries ) { case 1: - if ( params_code->ValueType.is_equal( t_int ) ) + if ( is_equal(params_code->ValueType, t_int ) ) is_member_symbol = true; else @@ -170,14 +170,14 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy return OpValidateResult::Fail; } - if ( params_code->ValueType.is_equal( ret_type ) ) + if ( is_equal(params_code->ValueType, ret_type ) ) { log_failure("gen::def_operator: " "operator%s is non-member symbol yet first paramter does not equal return type\n" "param type: %s\n" "return type: %s\n" , debug_str(params_code) - , ret_type.debug_str() + , debug_str(ret_type) ); return OpValidateResult::Fail; } @@ -247,14 +247,14 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy break; case 2: - if ( ! params_code->ValueType.is_equal( ret_type ) ) + if ( ! is_equal(params_code->ValueType, ret_type ) ) { log_failure("gen::def_operator: " "operator%s is non-member symbol yet first paramter does not equal return type\n" "param type: %s\n" "return type: %s\n" , debug_str(params_code) - , ret_type.debug_str() + , debug_str(ret_type) ); return OpValidateResult::Fail; } @@ -291,11 +291,11 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy } } - if ( ! ret_type.is_equal( t_bool )) + if ( ! is_equal(ret_type, t_bool )) { log_failure("gen::def_operator: operator%s return type must be of type bool - %s" , to_str(op) - , ret_type.debug_str() + , debug_str(ret_type) ); return OpValidateResult::Fail; } @@ -561,7 +561,7 @@ CodeClass def_class( StrC name if ( parent && ( parent->Type != Class && parent->Type != Struct && parent->Type != Typename && parent->Type != Untyped ) ) { - log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", parent.debug_str() ); + log_failure( "gen::def_class: parent provided is not type 'Class', 'Struct', 'Typeanme', or 'Untyped': %s", debug_str(parent) ); return InvalidCode; } @@ -691,7 +691,7 @@ CodeEnum def_enum( StrC name if ( type && type->Type != Typename ) { - log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", type.debug_str() ); + log_failure( "gen::def_enum: enum underlying type provided was not of type Typename: %s", debug_str(type) ); return InvalidCode; } @@ -1045,7 +1045,7 @@ CodeOpCast def_operator_cast( CodeType type, Code body, CodeSpecifiers const_spe if ( type->Type != Typename ) { - log_failure( "gen::def_operator_cast: type is not a typename - %s", type.debug_str() ); + log_failure( "gen::def_operator_cast: type is not a typename - %s", debug_str(type) ); return InvalidCode; } @@ -1476,7 +1476,7 @@ CodeVar def_variable( CodeType type, StrC name, Code value if ( type->Type != ECode::Typename ) { - log_failure( "gen::def_variable: type was not a Typename - %s", type.debug_str() ); + log_failure( "gen::def_variable: type was not a Typename - %s", debug_str(type) ); return InvalidCode; }