Code::duplicate reduction

This commit is contained in:
Edward R. Gonzalez 2024-12-02 00:16:11 -05:00
parent 37c33ffb3e
commit 007bfa0cb0
4 changed files with 15 additions and 305 deletions

View File

@ -166,10 +166,11 @@ String to_string (Code code);
*/ */
struct Code struct Code
{ {
AST* ast;
# define Using_Code( Typename ) \ # define Using_Code( Typename ) \
char const* debug_str() { return GEN_NS debug_str(* this); } \ char const* debug_str() { return GEN_NS debug_str(* this); } \
Code duplicate(); \ Code duplicate() { return GEN_NS duplicate(* this); } \
bool is_equal( Code other ); \ bool is_equal( Code other ); \
bool is_body(); \ bool is_body(); \
bool is_valid(); \ bool is_valid(); \
@ -207,8 +208,6 @@ struct Code
return *this; return *this;
} }
AST* ast;
#ifdef GEN_ENFORCE_STRONG_CODE_TYPES #ifdef GEN_ENFORCE_STRONG_CODE_TYPES
# define operator explicit operator # define operator explicit operator
#endif #endif

View File

@ -7,16 +7,6 @@
#pragma region generated code inline implementation #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() inline bool Code::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -66,16 +56,6 @@ inline Code::operator bool()
return ast != nullptr; 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() inline bool CodeBody::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -125,16 +105,6 @@ inline CodeBody::operator bool()
return ast != nullptr; 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() inline bool CodeAttributes::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -204,16 +174,6 @@ inline AST_Attributes* CodeAttributes::operator->()
return ast; 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() inline bool CodeComment::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -283,16 +243,6 @@ inline AST_Comment* CodeComment::operator->()
return ast; 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() inline bool CodeConstructor::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -362,16 +312,6 @@ inline AST_Constructor* CodeConstructor::operator->()
return ast; 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() inline bool CodeClass::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -421,16 +361,6 @@ inline CodeClass::operator bool()
return ast != nullptr; 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() inline bool CodeDefine::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -500,16 +430,6 @@ inline AST_Define* CodeDefine::operator->()
return ast; 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() inline bool CodeDestructor::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -579,16 +499,6 @@ inline AST_Destructor* CodeDestructor::operator->()
return ast; 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() inline bool CodeEnum::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -658,16 +568,6 @@ inline AST_Enum* CodeEnum::operator->()
return ast; 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() inline bool CodeExec::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -737,16 +637,6 @@ inline AST_Exec* CodeExec::operator->()
return ast; 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() inline bool CodeExtern::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -816,16 +706,6 @@ inline AST_Extern* CodeExtern::operator->()
return ast; 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() inline bool CodeFriend::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -895,16 +775,6 @@ inline AST_Friend* CodeFriend::operator->()
return ast; 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() inline bool CodeFn::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -974,16 +844,6 @@ inline AST_Fn* CodeFn::operator->()
return ast; 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() inline bool CodeInclude::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1053,16 +913,6 @@ inline AST_Include* CodeInclude::operator->()
return ast; 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() inline bool CodeModule::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1132,16 +982,6 @@ inline AST_Module* CodeModule::operator->()
return ast; 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() inline bool CodeNS::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1211,16 +1051,6 @@ inline AST_NS* CodeNS::operator->()
return ast; 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() inline bool CodeOperator::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1290,16 +1120,6 @@ inline AST_Operator* CodeOperator::operator->()
return ast; 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() inline bool CodeOpCast::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1369,16 +1189,6 @@ inline AST_OpCast* CodeOpCast::operator->()
return ast; 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() inline bool CodeParam::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1428,16 +1238,6 @@ inline CodeParam::operator bool()
return ast != nullptr; 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() inline bool CodePragma::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1507,16 +1307,6 @@ inline AST_Pragma* CodePragma::operator->()
return ast; 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() inline bool CodePreprocessCond::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1586,16 +1376,6 @@ inline AST_PreprocessCond* CodePreprocessCond::operator->()
return ast; 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() inline bool CodeSpecifiers::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1645,16 +1425,6 @@ inline CodeSpecifiers::operator bool()
return ast != nullptr; 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() inline bool CodeStruct::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1704,16 +1474,6 @@ inline CodeStruct::operator bool()
return ast != nullptr; 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() inline bool CodeTemplate::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1783,16 +1543,6 @@ inline AST_Template* CodeTemplate::operator->()
return ast; 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() inline bool CodeType::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1862,16 +1612,6 @@ inline AST_Type* CodeType::operator->()
return ast; 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() inline bool CodeTypedef::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -1941,16 +1681,6 @@ inline AST_Typedef* CodeTypedef::operator->()
return ast; 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() inline bool CodeUnion::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -2020,16 +1750,6 @@ inline AST_Union* CodeUnion::operator->()
return ast; 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() inline bool CodeUsing::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )
@ -2099,16 +1819,6 @@ inline AST_Using* CodeUsing::operator->()
return ast; 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() inline bool CodeVar::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )

View File

@ -99,6 +99,18 @@ char const* debug_str( Code code )
return debug_str( code.ast ); 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 inline
Code& Code::operator ++() Code& Code::operator ++()
{ {

View File

@ -354,17 +354,6 @@ CodeBody gen_ast_inlines()
char const* code_impl_tmpl = stringize( char const* code_impl_tmpl = stringize(
\n \n
inline inline
Code <typename>::duplicate()
{
if ( ast == nullptr )
{
log_failure("Code::duplicate: Cannot duplicate code, AST is null!");
return Code_Invalid;
}
return { rcast(AST*, ast)->duplicate() };
}
inline
bool <typename>::is_body() bool <typename>::is_body()
{ {
if ( ast == nullptr ) if ( ast == nullptr )