WIP : AST serialization improvements

Code untestd its an initial draft
This commit is contained in:
2023-11-19 20:34:46 -05:00
parent 36ebbfe29b
commit 5c73fbee83
10 changed files with 1669 additions and 1211 deletions

File diff suppressed because it is too large Load Diff

View File

@ -103,7 +103,7 @@ struct Code
Using_Code( Code );
template< class Type >
Type cast()
forceinline Type cast()
{
return * rcast( Type*, this );
}
@ -113,10 +113,13 @@ struct Code
return ast;
}
Code& operator ++();
auto& operator*()
{
return *this;
}
// TODO(Ed) : Remove this overload.
// auto& operator*()
// {
// return *this;
// }
AST* ast;
@ -182,7 +185,7 @@ struct AST
neverinline String to_string();
template< class Type >
Type cast()
forceinline Type cast()
{
return * this;
}
@ -263,7 +266,7 @@ struct AST
StringCached Content; // Attributes, Comment, Execution, Include
struct {
SpecifierT ArrSpecs[ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
};
union {
@ -350,7 +353,7 @@ struct AST_POD
struct test {
SpecifierT ArrSpecs[AST::ArrSpecs_Cap]; // Specifiers
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
AST* NextSpecs; // Specifiers; If ArrSpecs is full, then NextSpecs is used.
};
constexpr int pls = sizeof(test);
@ -385,6 +388,8 @@ struct CodeBody
{
return rcast( AST*, ast )->has_entries();
}
void to_string( String& result );
void to_string_export( String& result );
AST* raw()
{
return rcast( AST*, ast );
@ -419,6 +424,9 @@ struct CodeClass
Using_Code( CodeClass );
void add_interface( CodeType interface );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw()
{
@ -448,6 +456,7 @@ struct CodeParam
CodeParam get( s32 idx );
bool has_entries();
void to_string( String& result );
AST* raw()
{
return rcast( AST*, ast );
@ -520,6 +529,7 @@ struct CodeSpecifiers
return -1;
}
void to_string( String& result );
AST* raw()
{
return rcast( AST*, ast );
@ -559,6 +569,9 @@ struct CodeStruct
Using_Code( CodeStruct );
void add_interface( CodeType interface );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw()
{
@ -592,27 +605,260 @@ struct CodeStruct
Define_CodeType( Attributes );
Define_CodeType( Comment );
Define_CodeType( Constructor );
Define_CodeType( Define );
Define_CodeType( Destructor );
Define_CodeType( Enum );
struct CodeConstructor
{
Using_Code( CodeConstructor );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Constructor* operator->();
AST_Constructor* ast;
};
struct CodeDefine
{
Using_Code( CodeDefine );
void to_string( String& result );
AST* raw();
operator Code();
AST_Define* operator->();
AST_Define* ast;
};
struct CodeDestructor
{
Using_Code( CodeDestructor );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Destructor* operator->();
AST_Destructor* ast;
};
struct CodeEnum
{
Using_Code( CodeEnum );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Enum* operator->();
AST_Enum* ast;
};
Define_CodeType( Exec );
Define_CodeType( Extern );
Define_CodeType( Include );
Define_CodeType( Friend );
Define_CodeType( Fn );
Define_CodeType( Module );
Define_CodeType( NS );
Define_CodeType( Operator );
Define_CodeType( OpCast );
Define_CodeType( Pragma );
Define_CodeType( PreprocessCond );
Define_CodeType( Template );
Define_CodeType( Type );
Define_CodeType( Typedef );
Define_CodeType( Union );
Define_CodeType( Using );
Define_CodeType( Var );
struct CodeExtern
{
Using_Code( CodeExtern );
void to_string( String& result );
AST* raw();
operator Code();
AST_Extern* operator->();
AST_Extern* ast;
};
struct CodeInclude
{
Using_Code( CodeInclude );
void to_string( String& result );
AST* raw();
operator Code();
AST_Include* operator->();
AST_Include* ast;
};
struct CodeFriend
{
Using_Code( CodeFriend );
void to_string( String& result );
AST* raw();
operator Code();
AST_Friend* operator->();
AST_Friend* ast;
};
struct CodeFn
{
Using_Code( CodeFriend );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Fn* operator->();
AST_Fn* ast;
};
struct CodeModule
{
Using_Code( CodeModule );
void to_string( String& result );
AST* raw();
operator Code();
AST_Module* operator->();
AST_Module* ast;
};
struct CodeNS
{
Using_Code( CodeNS );
void to_string( String& result );
AST* raw();
operator Code();
AST_NS* operator->();
AST_NS* ast;
};
struct CodeOperator
{
Using_Code( CodeOperator );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_Operator* operator->();
AST_Operator* ast;
};
struct CodeOpCast
{
Using_Code( CodeOpCast );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw();
operator Code();
AST_OpCast* operator->();
AST_OpCast* ast;
};
struct CodePragma
{
Using_Code( CodePragma );
void to_string( String& result );
AST* raw();
operator Code();
AST_Pragma* operator->();
AST_Pragma* ast;
};
struct CodePreprocessCond
{
Using_Code( CodePreprocessCond );
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 );
AST* raw();
operator Code();
AST_PreprocessCond* operator->();
AST_PreprocessCond* ast;
};
struct CodeTemplate
{
Using_Code( CodeTemplate );
void to_string( String& result );
AST* raw();
operator Code();
AST_Template* operator->();
AST_Template* ast;
};
struct CodeType
{
Using_Code( CodeType );
void to_string( String& result );
AST* raw();
operator Code();
AST_Type* operator->();
AST_Type* ast;
};
struct CodeTypedef
{
Using_Code( CodeTypedef );
void to_string( String& result );
AST* raw();
operator Code();
AST_Typedef* operator->();
AST_Typedef* ast;
};
struct CodeUnion
{
Using_Code( CodeUnion );
void to_string( String& result );
AST* raw();
operator Code();
AST_Union* operator->();
AST_Union* ast;
};
struct CodeUsing
{
Using_Code( CodeUsing );
void to_string( String& result );
void to_string_ns( String& result );
AST* raw();
operator Code();
AST_Using* operator->();
AST_Using* ast;
};
struct CodeVar
{
Using_Code( CodeVar );
void to_string( String& result );
AST* raw();
operator Code();
AST_Var* operator->();
AST_Var* ast;
};
#undef Define_CodeType
#undef Using_Code

File diff suppressed because it is too large Load Diff

View File

@ -49,16 +49,6 @@ void Code::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String Code::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
Code& Code::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -127,16 +117,6 @@ void CodeBody::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeBody::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeBody& CodeBody::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -205,16 +185,6 @@ void CodeAttributes::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeAttributes::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeAttributes& CodeAttributes::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -303,16 +273,6 @@ void CodeComment::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeComment::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeComment& CodeComment::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -401,16 +361,6 @@ void CodeConstructor::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeConstructor::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeConstructor& CodeConstructor::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -499,16 +449,6 @@ void CodeClass::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeClass::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeClass& CodeClass::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -577,16 +517,6 @@ void CodeDefine::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeDefine::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeDefine& CodeDefine::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -675,16 +605,6 @@ void CodeDestructor::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeDestructor::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeDestructor& CodeDestructor::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -773,16 +693,6 @@ void CodeEnum::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeEnum::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeEnum& CodeEnum::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -871,16 +781,6 @@ void CodeExec::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeExec::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeExec& CodeExec::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1067,16 +967,6 @@ void CodeFriend::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeFriend::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeFriend& CodeFriend::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1165,16 +1055,6 @@ void CodeFn::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeFn::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeFn& CodeFn::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1263,16 +1143,6 @@ void CodeInclude::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeInclude::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeInclude& CodeInclude::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1361,16 +1231,6 @@ void CodeModule::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeModule::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeModule& CodeModule::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1459,16 +1319,6 @@ void CodeNS::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeNS::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeNS& CodeNS::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1557,16 +1407,6 @@ void CodeOperator::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeOperator::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeOperator& CodeOperator::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1655,16 +1495,6 @@ void CodeOpCast::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeOpCast::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeOpCast& CodeOpCast::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1753,16 +1583,6 @@ void CodeParam::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeParam::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeParam& CodeParam::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1831,16 +1651,6 @@ void CodePragma::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodePragma::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodePragma& CodePragma::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -1929,16 +1739,6 @@ void CodePreprocessCond::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodePreprocessCond::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodePreprocessCond& CodePreprocessCond::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2027,16 +1827,6 @@ void CodeSpecifiers::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeSpecifiers::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeSpecifiers& CodeSpecifiers::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2105,16 +1895,6 @@ void CodeStruct::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeStruct::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeStruct& CodeStruct::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2183,16 +1963,6 @@ void CodeTemplate::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeTemplate::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeTemplate& CodeTemplate::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2281,16 +2051,6 @@ void CodeType::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeType::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeType& CodeType::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2379,16 +2139,6 @@ void CodeTypedef::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeTypedef::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeTypedef& CodeTypedef::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2477,16 +2227,6 @@ void CodeUnion::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeUnion::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeUnion& CodeUnion::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2575,16 +2315,6 @@ void CodeUsing::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeUsing::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeUsing& CodeUsing::operator=( Code other )
{
if ( other.ast && other->Parent )
@ -2673,16 +2403,6 @@ void CodeVar::set_global()
rcast( AST*, ast )->Parent = Code::Global.ast;
}
String CodeVar::to_string()
{
if ( ast == nullptr )
{
log_failure( "Code::to_string: Cannot convert code to string, AST is null!" );
return { nullptr };
}
return rcast( AST*, ast )->to_string();
}
CodeVar& CodeVar::operator=( Code other )
{
if ( other.ast && other->Parent )

View File

@ -1,6 +1,6 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "ast.cpp"
#include "code_serialization.cpp"
#endif
internal void init_parser();