From 37c33ffb3e62be8c078e0e24f5b19379f45e17fe Mon Sep 17 00:00:00 2001 From: Ed_ Date: Mon, 2 Dec 2024 00:10:24 -0500 Subject: [PATCH] reduction on debug_str --- project/components/ast.hpp | 2 +- project/components/gen/ast_inlines.hpp | 203 ------------------------- project/components/inlines.hpp | 13 ++ project/helpers/helper.hpp | 8 - 4 files changed, 14 insertions(+), 212 deletions(-) diff --git a/project/components/ast.hpp b/project/components/ast.hpp index 0f327db..dfd6d16 100644 --- a/project/components/ast.hpp +++ b/project/components/ast.hpp @@ -168,7 +168,7 @@ struct Code { # define Using_Code( Typename ) \ - char const* debug_str(); \ + char const* debug_str() { return GEN_NS debug_str(*this); } \ Code duplicate(); \ bool is_equal( Code other ); \ bool is_body(); \ diff --git a/project/components/gen/ast_inlines.hpp b/project/components/gen/ast_inlines.hpp index 0df47a5..5e14fde 100644 --- a/project/components/gen/ast_inlines.hpp +++ b/project/components/gen/ast_inlines.hpp @@ -7,13 +7,6 @@ #pragma region generated code inline implementation -inline char const* Code::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code Code::duplicate() { if ( ast == nullptr ) @@ -73,13 +66,6 @@ inline Code::operator bool() return ast != nullptr; } -inline char const* CodeBody::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeBody::duplicate() { if ( ast == nullptr ) @@ -139,13 +125,6 @@ inline CodeBody::operator bool() return ast != nullptr; } -inline char const* CodeAttributes::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeAttributes::duplicate() { if ( ast == nullptr ) @@ -225,13 +204,6 @@ inline AST_Attributes* CodeAttributes::operator->() return ast; } -inline char const* CodeComment::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeComment::duplicate() { if ( ast == nullptr ) @@ -311,13 +283,6 @@ inline AST_Comment* CodeComment::operator->() return ast; } -inline char const* CodeConstructor::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeConstructor::duplicate() { if ( ast == nullptr ) @@ -397,13 +362,6 @@ inline AST_Constructor* CodeConstructor::operator->() return ast; } -inline char const* CodeClass::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeClass::duplicate() { if ( ast == nullptr ) @@ -463,13 +421,6 @@ inline CodeClass::operator bool() return ast != nullptr; } -inline char const* CodeDefine::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeDefine::duplicate() { if ( ast == nullptr ) @@ -549,13 +500,6 @@ inline AST_Define* CodeDefine::operator->() return ast; } -inline char const* CodeDestructor::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeDestructor::duplicate() { if ( ast == nullptr ) @@ -635,13 +579,6 @@ inline AST_Destructor* CodeDestructor::operator->() return ast; } -inline char const* CodeEnum::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeEnum::duplicate() { if ( ast == nullptr ) @@ -721,13 +658,6 @@ inline AST_Enum* CodeEnum::operator->() return ast; } -inline char const* CodeExec::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeExec::duplicate() { if ( ast == nullptr ) @@ -807,13 +737,6 @@ inline AST_Exec* CodeExec::operator->() return ast; } -inline char const* CodeExtern::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeExtern::duplicate() { if ( ast == nullptr ) @@ -893,13 +816,6 @@ inline AST_Extern* CodeExtern::operator->() return ast; } -inline char const* CodeFriend::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeFriend::duplicate() { if ( ast == nullptr ) @@ -979,13 +895,6 @@ inline AST_Friend* CodeFriend::operator->() return ast; } -inline char const* CodeFn::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeFn::duplicate() { if ( ast == nullptr ) @@ -1065,13 +974,6 @@ inline AST_Fn* CodeFn::operator->() return ast; } -inline char const* CodeInclude::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeInclude::duplicate() { if ( ast == nullptr ) @@ -1151,13 +1053,6 @@ inline AST_Include* CodeInclude::operator->() return ast; } -inline char const* CodeModule::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeModule::duplicate() { if ( ast == nullptr ) @@ -1237,13 +1132,6 @@ inline AST_Module* CodeModule::operator->() return ast; } -inline char const* CodeNS::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeNS::duplicate() { if ( ast == nullptr ) @@ -1323,13 +1211,6 @@ inline AST_NS* CodeNS::operator->() return ast; } -inline char const* CodeOperator::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeOperator::duplicate() { if ( ast == nullptr ) @@ -1409,13 +1290,6 @@ inline AST_Operator* CodeOperator::operator->() return ast; } -inline char const* CodeOpCast::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeOpCast::duplicate() { if ( ast == nullptr ) @@ -1495,13 +1369,6 @@ inline AST_OpCast* CodeOpCast::operator->() return ast; } -inline char const* CodeParam::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeParam::duplicate() { if ( ast == nullptr ) @@ -1561,13 +1428,6 @@ inline CodeParam::operator bool() return ast != nullptr; } -inline char const* CodePragma::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodePragma::duplicate() { if ( ast == nullptr ) @@ -1647,13 +1507,6 @@ inline AST_Pragma* CodePragma::operator->() return ast; } -inline char const* CodePreprocessCond::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodePreprocessCond::duplicate() { if ( ast == nullptr ) @@ -1733,13 +1586,6 @@ inline AST_PreprocessCond* CodePreprocessCond::operator->() return ast; } -inline char const* CodeSpecifiers::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeSpecifiers::duplicate() { if ( ast == nullptr ) @@ -1799,13 +1645,6 @@ inline CodeSpecifiers::operator bool() return ast != nullptr; } -inline char const* CodeStruct::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeStruct::duplicate() { if ( ast == nullptr ) @@ -1865,13 +1704,6 @@ inline CodeStruct::operator bool() return ast != nullptr; } -inline char const* CodeTemplate::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeTemplate::duplicate() { if ( ast == nullptr ) @@ -1951,13 +1783,6 @@ inline AST_Template* CodeTemplate::operator->() return ast; } -inline char const* CodeType::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeType::duplicate() { if ( ast == nullptr ) @@ -2037,13 +1862,6 @@ inline AST_Type* CodeType::operator->() return ast; } -inline char const* CodeTypedef::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeTypedef::duplicate() { if ( ast == nullptr ) @@ -2123,13 +1941,6 @@ inline AST_Typedef* CodeTypedef::operator->() return ast; } -inline char const* CodeUnion::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeUnion::duplicate() { if ( ast == nullptr ) @@ -2209,13 +2020,6 @@ inline AST_Union* CodeUnion::operator->() return ast; } -inline char const* CodeUsing::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeUsing::duplicate() { if ( ast == nullptr ) @@ -2295,13 +2099,6 @@ inline AST_Using* CodeUsing::operator->() return ast; } -inline char const* CodeVar::debug_str() -{ - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - return GEN_NS debug_str( rcast( AST*, ast ) ); -} - inline Code CodeVar::duplicate() { if ( ast == nullptr ) diff --git a/project/components/inlines.hpp b/project/components/inlines.hpp index 613a8f8..6cbe321 100644 --- a/project/components/inlines.hpp +++ b/project/components/inlines.hpp @@ -88,6 +88,17 @@ AST::operator Code() return { this }; } +#pragma region Code + +inline +char const* debug_str( Code code ) +{ + if ( code.ast == nullptr ) + return "Code::debug_str: AST is null!"; + + return debug_str( code.ast ); +} + inline Code& Code::operator ++() { @@ -97,6 +108,8 @@ Code& Code::operator ++() return *this; } +#pragma endregion Code + inline void CodeClass::add_interface( CodeType type ) { diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index 0cc6673..fa227bc 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -354,14 +354,6 @@ CodeBody gen_ast_inlines() char const* code_impl_tmpl = stringize( \n inline - char const* ::debug_str() - { - if ( ast == nullptr ) - return "Code::debug_str: AST is null!"; - - return GEN_NS debug_str( rcast(AST*, ast) ); - } - inline Code ::duplicate() { if ( ast == nullptr )