WIP : AST serialization improvements

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

View File

@ -249,6 +249,8 @@ function setup-raylib {
foreach ($header in $raylib_headers) {
Copy-Item -Path $header -Destination (join-path $path_raylib_inc (split-path $header -Leaf))
}
remove-item -path $path_temp -Recurse
# Don't want to remove as it hampers debugging.
# remove-item -path $path_temp -Recurse
}
setup-raylib

View File

@ -185,13 +185,14 @@ int gen_main()
Code static_data = scan_file( "components/static_data.cpp" );
Code ast_case_macros = scan_file( "components/ast_case_macros.cpp" );
Code ast = scan_file( "components/ast.cpp" );
Code code_serialization = scan_file( "components/code_serialization.cpp" );
Code interface = scan_file( "components/interface.cpp" );
Code upfront = scan_file( "components/interface.upfront.cpp" );
Code parsing = scan_file( "components/interface.parsing.cpp" );
Code untyped = scan_file( "components/interface.untyped.cpp" );
CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" );
CodeNS nspaced_etoktype = def_namespace( name(Parser), def_namespace_body( args(etoktype)) );
CodeNS nspaced_etoktype = def_namespace( name(parser), def_namespace_body( args(etoktype)) );
Builder
src = Builder::open( "gen/gen.cpp" );
@ -205,6 +206,7 @@ int gen_main()
src.print_fmt( "\n#pragma region AST\n\n" );
src.print( ast_case_macros );
src.print( ast );
src.print( code );
src.print_fmt( "\n#pragma endregion AST\n" );
src.print_fmt( "\n#pragma region Interface\n" );

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;
}
@ -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 );
@ -420,6 +425,9 @@ struct CodeClass
void add_interface( CodeType interface );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw()
{
return rcast( AST*, ast );
@ -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 );
@ -560,6 +570,9 @@ struct CodeStruct
void add_interface( CodeType interface );
void to_string_def( String& result );
void to_string_fwd( String& result );
AST* raw()
{
return rcast( AST*, ast );
@ -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();

View File

@ -20,6 +20,7 @@ GEN_NS_BEGIN
#include "components/ast_case_macros.cpp"
#include "components/ast.cpp"
#include "components/code_serialization.cpp"
#include "components/interface.cpp"
#include "components/interface.upfront.cpp"

View File

@ -379,16 +379,16 @@ CodeBody gen_ast_inlines()
rcast(AST*, ast)->Parent = Code::Global.ast;
}
String <typename>::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();
}
// String <typename>::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();
// }
<typename>& <typename>::operator =( Code other )
{
if ( other.ast && other->Parent )

View File

@ -198,6 +198,7 @@ int gen_main()
Code static_data = scan_file( project_dir "components/static_data.cpp" );
Code ast_case_macros = scan_file( project_dir "components/ast_case_macros.cpp" );
Code ast = scan_file( project_dir "components/ast.cpp" );
Code code = scan_file( project_dir "components/code_serialization.cpp" );
Code interface = scan_file( project_dir "components/interface.cpp" );
Code upfront = scan_file( project_dir "components/interface.upfront.cpp" );
Code parsing = scan_file( project_dir "components/interface.parsing.cpp" );
@ -212,6 +213,7 @@ int gen_main()
header.print_fmt( "#pragma region AST\n\n" );
header.print( ast_case_macros );
header.print( ast );
header.print( code );
header.print_fmt( "#pragma endregion AST\n\n" );
header.print_fmt( "#pragma region Interface\n" );