diff --git a/project/components/ast.hpp b/project/components/ast.hpp index dfd6d16..89bed56 100644 --- a/project/components/ast.hpp +++ b/project/components/ast.hpp @@ -166,10 +166,11 @@ String to_string (Code code); */ struct Code { + AST* ast; # define Using_Code( Typename ) \ - char const* debug_str() { return GEN_NS debug_str(*this); } \ - Code duplicate(); \ + char const* debug_str() { return GEN_NS debug_str(* this); } \ + Code duplicate() { return GEN_NS duplicate(* this); } \ bool is_equal( Code other ); \ bool is_body(); \ bool is_valid(); \ @@ -207,8 +208,6 @@ struct Code return *this; } - AST* ast; - #ifdef GEN_ENFORCE_STRONG_CODE_TYPES # define operator explicit operator #endif diff --git a/project/components/gen/ast_inlines.hpp b/project/components/gen/ast_inlines.hpp index 5e14fde..7206e47 100644 --- a/project/components/gen/ast_inlines.hpp +++ b/project/components/gen/ast_inlines.hpp @@ -7,16 +7,6 @@ #pragma region generated code inline implementation -inline Code Code::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool Code::is_body() { if ( ast == nullptr ) @@ -66,16 +56,6 @@ inline Code::operator bool() return ast != nullptr; } -inline Code CodeBody::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeBody::is_body() { if ( ast == nullptr ) @@ -125,16 +105,6 @@ inline CodeBody::operator bool() return ast != nullptr; } -inline Code CodeAttributes::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeAttributes::is_body() { if ( ast == nullptr ) @@ -204,16 +174,6 @@ inline AST_Attributes* CodeAttributes::operator->() return ast; } -inline Code CodeComment::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeComment::is_body() { if ( ast == nullptr ) @@ -283,16 +243,6 @@ inline AST_Comment* CodeComment::operator->() return ast; } -inline Code CodeConstructor::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeConstructor::is_body() { if ( ast == nullptr ) @@ -362,16 +312,6 @@ inline AST_Constructor* CodeConstructor::operator->() return ast; } -inline Code CodeClass::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeClass::is_body() { if ( ast == nullptr ) @@ -421,16 +361,6 @@ inline CodeClass::operator bool() return ast != nullptr; } -inline Code CodeDefine::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeDefine::is_body() { if ( ast == nullptr ) @@ -500,16 +430,6 @@ inline AST_Define* CodeDefine::operator->() return ast; } -inline Code CodeDestructor::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeDestructor::is_body() { if ( ast == nullptr ) @@ -579,16 +499,6 @@ inline AST_Destructor* CodeDestructor::operator->() return ast; } -inline Code CodeEnum::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeEnum::is_body() { if ( ast == nullptr ) @@ -658,16 +568,6 @@ inline AST_Enum* CodeEnum::operator->() return ast; } -inline Code CodeExec::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeExec::is_body() { if ( ast == nullptr ) @@ -737,16 +637,6 @@ inline AST_Exec* CodeExec::operator->() return ast; } -inline Code CodeExtern::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeExtern::is_body() { if ( ast == nullptr ) @@ -816,16 +706,6 @@ inline AST_Extern* CodeExtern::operator->() return ast; } -inline Code CodeFriend::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeFriend::is_body() { if ( ast == nullptr ) @@ -895,16 +775,6 @@ inline AST_Friend* CodeFriend::operator->() return ast; } -inline Code CodeFn::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeFn::is_body() { if ( ast == nullptr ) @@ -974,16 +844,6 @@ inline AST_Fn* CodeFn::operator->() return ast; } -inline Code CodeInclude::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeInclude::is_body() { if ( ast == nullptr ) @@ -1053,16 +913,6 @@ inline AST_Include* CodeInclude::operator->() return ast; } -inline Code CodeModule::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeModule::is_body() { if ( ast == nullptr ) @@ -1132,16 +982,6 @@ inline AST_Module* CodeModule::operator->() return ast; } -inline Code CodeNS::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeNS::is_body() { if ( ast == nullptr ) @@ -1211,16 +1051,6 @@ inline AST_NS* CodeNS::operator->() return ast; } -inline Code CodeOperator::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeOperator::is_body() { if ( ast == nullptr ) @@ -1290,16 +1120,6 @@ inline AST_Operator* CodeOperator::operator->() return ast; } -inline Code CodeOpCast::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeOpCast::is_body() { if ( ast == nullptr ) @@ -1369,16 +1189,6 @@ inline AST_OpCast* CodeOpCast::operator->() return ast; } -inline Code CodeParam::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeParam::is_body() { if ( ast == nullptr ) @@ -1428,16 +1238,6 @@ inline CodeParam::operator bool() return ast != nullptr; } -inline Code CodePragma::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodePragma::is_body() { if ( ast == nullptr ) @@ -1507,16 +1307,6 @@ inline AST_Pragma* CodePragma::operator->() return ast; } -inline Code CodePreprocessCond::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodePreprocessCond::is_body() { if ( ast == nullptr ) @@ -1586,16 +1376,6 @@ inline AST_PreprocessCond* CodePreprocessCond::operator->() return ast; } -inline Code CodeSpecifiers::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeSpecifiers::is_body() { if ( ast == nullptr ) @@ -1645,16 +1425,6 @@ inline CodeSpecifiers::operator bool() return ast != nullptr; } -inline Code CodeStruct::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeStruct::is_body() { if ( ast == nullptr ) @@ -1704,16 +1474,6 @@ inline CodeStruct::operator bool() return ast != nullptr; } -inline Code CodeTemplate::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeTemplate::is_body() { if ( ast == nullptr ) @@ -1783,16 +1543,6 @@ inline AST_Template* CodeTemplate::operator->() return ast; } -inline Code CodeType::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeType::is_body() { if ( ast == nullptr ) @@ -1862,16 +1612,6 @@ inline AST_Type* CodeType::operator->() return ast; } -inline Code CodeTypedef::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeTypedef::is_body() { if ( ast == nullptr ) @@ -1941,16 +1681,6 @@ inline AST_Typedef* CodeTypedef::operator->() return ast; } -inline Code CodeUnion::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeUnion::is_body() { if ( ast == nullptr ) @@ -2020,16 +1750,6 @@ inline AST_Union* CodeUnion::operator->() return ast; } -inline Code CodeUsing::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeUsing::is_body() { if ( ast == nullptr ) @@ -2099,16 +1819,6 @@ inline AST_Using* CodeUsing::operator->() return ast; } -inline Code CodeVar::duplicate() -{ - if ( ast == nullptr ) - { - log_failure( "Code::duplicate: Cannot duplicate code, AST is null!" ); - return Code_Invalid; - } - return { rcast( AST*, ast )->duplicate() }; -} - inline bool CodeVar::is_body() { if ( ast == nullptr ) diff --git a/project/components/inlines.hpp b/project/components/inlines.hpp index 6cbe321..dad89ad 100644 --- a/project/components/inlines.hpp +++ b/project/components/inlines.hpp @@ -99,6 +99,18 @@ char const* debug_str( Code code ) return debug_str( code.ast ); } +inline +Code duplicate( Code code ) +{ + if ( code.ast == nullptr ) + { + log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); + return Code_Invalid; + } + + return { duplicate(code.ast) }; +} + inline Code& Code::operator ++() { diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index fa227bc..ce5a01f 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -354,17 +354,6 @@ CodeBody gen_ast_inlines() char const* code_impl_tmpl = stringize( \n inline - Code ::duplicate() - { - if ( ast == nullptr ) - { - log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); - return Code_Invalid; - } - - return { rcast(AST*, ast)->duplicate() }; - } - inline bool ::is_body() { if ( ast == nullptr )