From 97750388addd185ac32069d2e7cecf563b3ff8e3 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 6 Aug 2023 14:58:43 -0400 Subject: [PATCH] No longer using components/temp/ast_inlines (switched to helper function to avoid macro usage) Increased the arg count support of num_args to 100. --- docs/Parsing.md | 2 +- docs/Readme.md | 2 +- project/components/ast.cpp | 26 ++- project/components/ast.hpp | 10 +- project/components/ast_case_macros.cpp | 1 - project/components/ast_types.hpp | 4 +- project/components/interface.hpp | 4 +- project/components/interface.parsing.cpp | 13 +- project/components/interface.upfront.cpp | 14 +- project/components/temp/ast_inlines.hpp | 6 +- project/dependencies/macros.hpp | 79 ++++--- project/gen.bootstrap.cpp | 12 +- project/helpers/helper.hpp | 271 ++++++++++++++++++++++- scripts/gencpp.natvis | 4 +- singleheader/gen.singleheader.cpp | 22 +- test/parsed/Sanity.Parsed.hpp | 4 +- test/upfront/Sanity.Upfront.hpp | 2 +- 17 files changed, 395 insertions(+), 81 deletions(-) diff --git a/docs/Parsing.md b/docs/Parsing.md index 518f22a..704b7f6 100644 --- a/docs/Parsing.md +++ b/docs/Parsing.md @@ -13,7 +13,7 @@ CodeExtern parse_extern_link ( StrC exten_link_def); CodeFriend parse_friend ( StrC friend_def ); CodeFn parse_function ( StrC fn_def ); CodeBody parse_global_body ( StrC body_def ); -CodeNamespace parse_namespace ( StrC namespace_def ); +CodeNS parse_namespace ( StrC namespace_def ); CodeOperator parse_operator ( StrC operator_def ); CodeOpCast parse_operator_cast( StrC operator_def ); CodeStruct parse_struct ( StrC struct_def ); diff --git a/docs/Readme.md b/docs/Readme.md index 145a2e8..5341e4c 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -195,7 +195,7 @@ The following CodeTypes are used which the user may optionally use strong typing * CodeFriend * CodeFn * CodeModule -* CodeNamespace +* CodeNS * CodeOperator * CodeOpCast * CodeParam : Has support for `for-range` iterating across parameters. diff --git a/project/components/ast.cpp b/project/components/ast.cpp index 05057d5..9896285 100644 --- a/project/components/ast.cpp +++ b/project/components/ast.cpp @@ -906,7 +906,31 @@ bool AST::validate_body() CheckEntries( GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES ); break; case Global_Body: - CheckEntries( GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES ); + for (Code entry : cast()) + { + switch (entry->Type) + { + case Access_Public: + case Access_Protected: + case Access_Private: + case PlatformAttributes: + case Class_Body: + case Enum_Body: + case Execution: + case Friend: + case Function_Body: + case Global_Body: + case Namespace_Body: + case Operator_Member: + case Operator_Member_Fwd: + case Parameters: + case Specifiers: + case Struct_Body: + case Typename: + log_failure("AST::validate_body: Invalid entry in body %s", entry.debug_str()); + return false; + } + } break; case Namespace_Body: CheckEntries( GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES ); diff --git a/project/components/ast.hpp b/project/components/ast.hpp index f4e9fdf..a0306e5 100644 --- a/project/components/ast.hpp +++ b/project/components/ast.hpp @@ -11,7 +11,7 @@ struct AST_Include; struct AST_Friend; struct AST_Fn; struct AST_Module; -struct AST_Namespace; +struct AST_NS; struct AST_Operator; struct AST_OpCast; struct AST_Param; @@ -40,7 +40,7 @@ struct CodeInclude; struct CodeFriend; struct CodeFn; struct CodeModule; -struct CodeNamespace; +struct CodeNS; struct CodeOperator; struct CodeOpCast; struct CodeParam; @@ -117,7 +117,7 @@ struct Code operator CodeFriend() const; operator CodeFn() const; operator CodeModule() const; - operator CodeNamespace() const; + operator CodeNS() const; operator CodeOperator() const; operator CodeOpCast() const; operator CodeParam() const; @@ -180,7 +180,7 @@ struct AST operator CodeFriend(); operator CodeFn(); operator CodeModule(); - operator CodeNamespace(); + operator CodeNS(); operator CodeOperator(); operator CodeOpCast(); operator CodeParam(); @@ -558,7 +558,7 @@ Define_CodeType( Include ); Define_CodeType( Friend ); Define_CodeType( Fn ); Define_CodeType( Module ); -Define_CodeType( Namespace ); +Define_CodeType( NS ); Define_CodeType( Operator ); Define_CodeType( OpCast ); Define_CodeType( Pragma ); diff --git a/project/components/ast_case_macros.cpp b/project/components/ast_case_macros.cpp index d9c05af..4ed2ad2 100644 --- a/project/components/ast_case_macros.cpp +++ b/project/components/ast_case_macros.cpp @@ -49,7 +49,6 @@ case Execution: \ case Friend: \ case Function_Body: \ - case Global_Body: \ case Namespace_Body: \ case Operator_Member: \ case Operator_Member_Fwd: \ diff --git a/project/components/ast_types.hpp b/project/components/ast_types.hpp index 0f56611..4ed13a6 100644 --- a/project/components/ast_types.hpp +++ b/project/components/ast_types.hpp @@ -216,7 +216,7 @@ struct AST_Module }; static_assert( sizeof(AST_Module) == sizeof(AST), "ERROR: AST_Module is not the same size as AST"); -struct AST_Namespace +struct AST_NS { union { char _PAD_[ sizeof(SpecifierT) * AST::ArrSpecs_Cap ]; @@ -233,7 +233,7 @@ struct AST_Namespace ModuleFlag ModuleFlags; char _PAD_UNUSED_[ sizeof(u32) ]; }; -static_assert( sizeof(AST_Namespace) == sizeof(AST), "ERROR: AST_Namespace is not the same size as AST"); +static_assert( sizeof(AST_NS) == sizeof(AST), "ERROR: AST_NS is not the same size as AST"); struct AST_Operator { diff --git a/project/components/interface.hpp b/project/components/interface.hpp index 020feee..3e75498 100644 --- a/project/components/interface.hpp +++ b/project/components/interface.hpp @@ -63,7 +63,7 @@ CodeFn def_function( StrC name CodeInclude def_include ( StrC content ); CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None ); -CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None ); +CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None ); CodeOperator def_operator( OperatorT op, StrC nspace , CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode @@ -143,7 +143,7 @@ CodeExtern parse_extern_link ( StrC exten_link_def); CodeFriend parse_friend ( StrC friend_def ); CodeFn parse_function ( StrC fn_def ); CodeBody parse_global_body ( StrC body_def ); -CodeNamespace parse_namespace ( StrC namespace_def ); +CodeNS parse_namespace ( StrC namespace_def ); CodeOperator parse_operator ( StrC operator_def ); CodeOpCast parse_operator_cast( StrC operator_def ); CodeStruct parse_struct ( StrC struct_def ); diff --git a/project/components/interface.parsing.cpp b/project/components/interface.parsing.cpp index 51649fe..ba14d59 100644 --- a/project/components/interface.parsing.cpp +++ b/project/components/interface.parsing.cpp @@ -1120,7 +1120,7 @@ internal CodeBody parse_extern_link_body(); internal CodeExtern parse_exten_link (); internal CodeFriend parse_friend (); internal CodeFn parse_function (); -internal CodeNamespace parse_namespace (); +internal CodeNS parse_namespace (); internal CodeOpCast parse_operator_cast (); internal CodeStruct parse_struct ( bool inplace_def = false ); internal CodeVar parse_variable (); @@ -3071,7 +3071,10 @@ CodeBody parse_global_nspace( CodeT which ) } if ( found_operator_cast ) + { member = parse_operator_cast(); + break; + } member = parse_operator_function_or_variable( expects_function, attributes, specifiers ); } @@ -3566,7 +3569,7 @@ CodeBody parse_global_body( StrC def ) } internal -CodeNamespace parse_namespace() +CodeNS parse_namespace() { using namespace Parser; push_scope(); @@ -3583,8 +3586,8 @@ CodeNamespace parse_namespace() return CodeInvalid; } - CodeNamespace - result = (CodeNamespace) make_code(); + CodeNS + result = (CodeNS) make_code(); result->Type = ECode::Namespace; result->Name = get_cached_string( name ); @@ -3594,7 +3597,7 @@ CodeNamespace parse_namespace() return result; } -CodeNamespace parse_namespace( StrC def ) +CodeNS parse_namespace( StrC def ) { check_parse_args( def ); using namespace Parser; diff --git a/project/components/interface.upfront.cpp b/project/components/interface.upfront.cpp index 60dfb79..ab7be0b 100644 --- a/project/components/interface.upfront.cpp +++ b/project/components/interface.upfront.cpp @@ -763,7 +763,7 @@ CodeModule def_module( StrC name, ModuleFlag mflags ) return (CodeModule) result; } -CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags ) +CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags ) { using namespace ECode; @@ -776,8 +776,8 @@ CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags ) return CodeInvalid; } - CodeNamespace - result = (CodeNamespace) make_code(); + CodeNS + result = (CodeNS) make_code(); result->Type = Namespace; result->Name = get_cached_string( name ); result->ModuleFlags = mflags; @@ -1732,6 +1732,10 @@ CodeBody def_global_body( s32 num, ... ) switch (entry->Type) { + case Global_Body: + result.append( entry.cast() ) ; + continue; + GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str()); return (*Code::Invalid.ast); @@ -1769,6 +1773,10 @@ CodeBody def_global_body( s32 num, Code* codes ) switch (entry->Type) { + case Global_Body: + result.append( entry.cast() ) ; + continue; + GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", entry.debug_str()); return CodeInvalid; diff --git a/project/components/temp/ast_inlines.hpp b/project/components/temp/ast_inlines.hpp index cf5cef2..25245ba 100644 --- a/project/components/temp/ast_inlines.hpp +++ b/project/components/temp/ast_inlines.hpp @@ -91,7 +91,7 @@ Define_CodeImpl( CodeInclude ); Define_CodeImpl( CodeFriend ); Define_CodeImpl( CodeFn ); Define_CodeImpl( CodeModule ); -Define_CodeImpl( CodeNamespace ); +Define_CodeImpl( CodeNS ); Define_CodeImpl( CodeOperator ); Define_CodeImpl( CodeOpCast ); Define_CodeImpl( CodeParam ); @@ -125,7 +125,7 @@ Define_AST_Cast( Include ); Define_AST_Cast( Friend ); Define_AST_Cast( Fn ); Define_AST_Cast( Module ); -Define_AST_Cast( Namespace ); +Define_AST_Cast( NS ); Define_AST_Cast( Operator ); Define_AST_Cast( OpCast ); Define_AST_Cast( Param ); @@ -158,7 +158,7 @@ Define_CodeCast( Include ); Define_CodeCast( Friend ); Define_CodeCast( Fn ); Define_CodeCast( Module ); -Define_CodeCast( Namespace ); +Define_CodeCast( NS ); Define_CodeCast( Operator ); Define_CodeCast( OpCast ); Define_CodeCast( Param ); diff --git a/project/dependencies/macros.hpp b/project/dependencies/macros.hpp index b50fa77..34824f9 100644 --- a/project/dependencies/macros.hpp +++ b/project/dependencies/macros.hpp @@ -23,44 +23,65 @@ // Num Arguments (Varadics) #if defined(__GNUC__) || defined(__clang__) // Supports 0-50 arguments -#define num_args_impl( _0, \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ - _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ - _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ - _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ - _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \ - N, ... \ +#define num_args_impl( _0, \ + _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ + _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ + _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ + _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ + _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \ + _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \ + _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \ + _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \ + _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \ + _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \ + N, ... \ ) N // ## deletes preceding comma if _VA_ARGS__ is empty (GCC, Clang) -#define num_args(...) \ - num_args_impl(_, ## __VA_ARGS__, \ - 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ - 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ - 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ - 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \ - 0 \ +#define num_args(...) \ + num_args_impl(_, ## __VA_ARGS__, \ + 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \ + 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \ + 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \ + 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \ + 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \ + 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ + 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ + 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ + 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, \ + 0 \ ) #else // Supports 1-50 arguments -#define num_args_impl( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ - _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ - _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ - _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ - _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \ - N, ... \ +#define num_args_impl( \ + _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \ + _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ + _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ + _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ + _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, \ + _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, \ + _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, \ + _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, \ + _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, \ + _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, \ + N, ... \ ) N -#define num_args(...) \ - num_args_impl( __VA_ARGS__, \ - 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ - 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ - 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ - 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ - 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \ +#define num_args(...) \ + num_args_impl( __VA_ARGS__, \ + 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, \ + 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, \ + 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, \ + 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, \ + 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, \ + 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ + 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ + 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ + 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ + 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ + 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 \ ) #endif diff --git a/project/gen.bootstrap.cpp b/project/gen.bootstrap.cpp index 75e216b..a0bcc90 100644 --- a/project/gen.bootstrap.cpp +++ b/project/gen.bootstrap.cpp @@ -104,12 +104,12 @@ int gen_main() Code ast_types = scan_file( "components/ast_types.hpp" ); Code interface = scan_file( "components/interface.hpp" ); Code inlines = scan_file( "components/inlines.hpp" ); - Code ast_inlines = scan_file( "components/temp/ast_inlines.hpp" ); Code header_end = scan_file( "components/header_end.hpp" ); - CodeBody ecode = gen_ecode ( "enums/ECode.csv" ); - CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" ); - CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" ); + CodeBody ecode = gen_ecode ( "enums/ECode.csv" ); + CodeBody eoperator = gen_eoperator ( "enums/EOperator.csv" ); + CodeBody especifier = gen_especifier( "enums/ESpecifier.csv" ); + CodeBody ast_inlines = gen_ast_inlines(); Builder header = Builder::open( "gen/gen.hpp" ); @@ -155,8 +155,8 @@ int gen_main() Code parsing = scan_file( "components/interface.parsing.cpp" ); Code untyped = scan_file( "components/untyped.cpp" ); - CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" ); - CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) ); + CodeBody etoktype = gen_etoktype( "enums/ETokType.csv", "enums/AttributeTokens.csv" ); + CodeNS parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) ); Builder src = Builder::open( "gen/gen.cpp" ); diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index 9a1f366..9b9612e 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -53,7 +53,7 @@ CodeBody gen_ecode( char const* path ) ))); #pragma pop_macro( "local_persist" ) - CodeNamespace nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) ); + CodeNS nspace = def_namespace( name(ECode), def_namespace_body( args( enum_code, to_str ) ) ); CodeUsing code_t = def_using( name(CodeT), def_type( name(ECode::Type) ) ); return def_global_body( args( nspace, code_t ) ); @@ -107,7 +107,7 @@ CodeBody gen_eoperator( char const* path ) ))); #pragma pop_macro( "local_persist" ) - CodeNamespace nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) ); + CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) ); CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) ); @@ -203,7 +203,7 @@ CodeBody gen_especifier( char const* path ) #pragma pop_macro( "do_once_start" ) #pragma pop_macro( "do_once_end" ) - CodeNamespace nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) ); + CodeNS nspace = def_namespace( name(ESpecifier), def_namespace_body( args( enum_code, is_trailing, to_str, to_type ) ) ); CodeUsing specifier_t = def_using( name(SpecifierT), def_type( name(ESpecifier::Type) ) ); @@ -324,13 +324,272 @@ CodeBody gen_etoktype( char const* etok_path, char const* attr_path ) #pragma pop_macro( "do_once_start" ) #pragma pop_macro( "do_once_end" ) - CodeNamespace nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) ); + CodeNS nspace = def_namespace( name(ETokType), def_namespace_body( args( attribute_entires_def, enum_code, to_str, to_type ) ) ); CodeUsing td_toktype = def_using( name(TokType), def_type( name(ETokType::Type) ) ); return def_global_body( args( nspace, td_toktype ) ); } -CodeBody gen_data_structures( char const* data_path, char const* ast_path ) +CodeBody gen_ast_inlines() { - return CodeInvalid; +#pragma push_macro("rcast") +#undef rcast + char const* code_impl_tmpl = stringize( + \n + char const* ::debug_str() + { + if ( ast == nullptr ) + return "Code::debug_str: AST is null!"; + + return rcast(AST*, ast)->debug_str(); + } + Code ::duplicate() + { + if ( ast == nullptr ) + { + log_failure("Code::duplicate: Cannot duplicate code, AST is null!"); + return Code::Invalid; + } + + return { rcast(AST*, ast)->duplicate() }; + } + bool ::is_equal( Code other ) + { + if ( ast == nullptr || other.ast == nullptr ) + { + log_failure("Code::is_equal: Cannot compare code, AST is null!"); + return false; + } + + return rcast(AST*, ast)->is_equal( other.ast ); + } + bool ::is_valid() + { + return (AST*) ast != nullptr && rcast( AST*, ast)->Type != CodeT::Invalid; + } + void ::set_global() + { + if ( ast == nullptr ) + { + log_failure("Code::set_global: Cannot set code as global, AST is null!"); + return; + } + + rcast(AST*, ast)->Parent = Code::Global.ast; + } + String ::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(); + } + & ::operator =( Code other ) + { + if ( other.ast && other->Parent ) + { + ast = rcast( decltype(ast), other.ast->duplicate() ); + rcast( AST*, ast)->Parent = nullptr; + } + + ast = rcast( decltype(ast), other.ast ); + return *this; + } + bool ::operator ==( Code other ) + { + return (AST*) ast == other.ast; + } + bool ::operator !=( Code other ) + { + return (AST*) ast != other.ast; + } + ::operator bool() + { + return ast != nullptr; + } + \n + ); + + CodeBody impl_code = parse_global_body( token_fmt( "typename", StrC name(Code), code_impl_tmpl )); + CodeBody impl_code_body = parse_global_body( token_fmt( "typename", StrC name(CodeBody), code_impl_tmpl )); + CodeBody impl_code_attr = parse_global_body( token_fmt( "typename", StrC name(CodeAttributes), code_impl_tmpl )); + CodeBody impl_code_cmt = parse_global_body( token_fmt( "typename", StrC name(CodeComment), code_impl_tmpl )); + CodeBody impl_code_class = parse_global_body( token_fmt( "typename", StrC name(CodeClass), code_impl_tmpl )); + CodeBody impl_code_define = parse_global_body( token_fmt( "typename", StrC name(CodeDefine), code_impl_tmpl )); + CodeBody impl_code_enum = parse_global_body( token_fmt( "typename", StrC name(CodeEnum), code_impl_tmpl )); + CodeBody impl_code_exec = parse_global_body( token_fmt( "typename", StrC name(CodeExec), code_impl_tmpl )); + CodeBody impl_code_extern = parse_global_body( token_fmt( "typename", StrC name(CodeExtern), code_impl_tmpl )); + CodeBody impl_code_include = parse_global_body( token_fmt( "typename", StrC name(CodeInclude), code_impl_tmpl )); + CodeBody impl_code_friend = parse_global_body( token_fmt( "typename", StrC name(CodeFriend), code_impl_tmpl )); + CodeBody impl_code_fn = parse_global_body( token_fmt( "typename", StrC name(CodeFn), code_impl_tmpl )); + CodeBody impl_code_module = parse_global_body( token_fmt( "typename", StrC name(CodeModule), code_impl_tmpl )); + CodeBody impl_code_ns = parse_global_body( token_fmt( "typename", StrC name(CodeNS), code_impl_tmpl )); + CodeBody impl_code_op = parse_global_body( token_fmt( "typename", StrC name(CodeOperator), code_impl_tmpl )); + CodeBody impl_code_opcast = parse_global_body( token_fmt( "typename", StrC name(CodeOpCast), code_impl_tmpl )); + CodeBody impl_code_param = parse_global_body( token_fmt( "typename", StrC name(CodeParam), code_impl_tmpl )); + CodeBody impl_code_precond = parse_global_body( token_fmt( "typename", StrC name(CodePreprocessCond), code_impl_tmpl )); + CodeBody impl_code_specs = parse_global_body( token_fmt( "typename", StrC name(CodeSpecifiers), code_impl_tmpl )); + CodeBody impl_code_struct = parse_global_body( token_fmt( "typename", StrC name(CodeStruct), code_impl_tmpl )); + CodeBody impl_code_tmpl = parse_global_body( token_fmt( "typename", StrC name(CodeTemplate), code_impl_tmpl )); + CodeBody impl_code_type = parse_global_body( token_fmt( "typename", StrC name(CodeType), code_impl_tmpl )); + CodeBody impl_code_typedef = parse_global_body( token_fmt( "typename", StrC name(CodeTypedef), code_impl_tmpl )); + CodeBody impl_code_union = parse_global_body( token_fmt( "typename", StrC name(CodeUnion), code_impl_tmpl )); + CodeBody impl_code_using = parse_global_body( token_fmt( "typename", StrC name(CodeUsing), code_impl_tmpl )); + CodeBody impl_code_var = parse_global_body( token_fmt( "typename", StrC name(CodeVar), code_impl_tmpl )); + + char const* ast_cast_tmpl = stringize( + AST::operator Code() + { + return { rcast( AST_*, this ) }; + } + ); + + CodeOpCast impl_astcast_body = parse_operator_cast( token_fmt( "typename", StrC name(Body), ast_cast_tmpl )); + CodeOpCast impl_astcast_attribute = parse_operator_cast( token_fmt( "typename", StrC name(Attributes), ast_cast_tmpl )); + CodeOpCast impl_astcast_cmt = parse_operator_cast( token_fmt( "typename", StrC name(Comment), ast_cast_tmpl )); + CodeOpCast impl_astcast_class = parse_operator_cast( token_fmt( "typename", StrC name(Class), ast_cast_tmpl )); + CodeOpCast impl_astcast_define = parse_operator_cast( token_fmt( "typename", StrC name(Define), ast_cast_tmpl )); + CodeOpCast impl_astcast_enum = parse_operator_cast( token_fmt( "typename", StrC name(Enum), ast_cast_tmpl )); + CodeOpCast impl_astcast_exec = parse_operator_cast( token_fmt( "typename", StrC name(Exec), ast_cast_tmpl )); + CodeOpCast impl_astcast_extern = parse_operator_cast( token_fmt( "typename", StrC name(Extern), ast_cast_tmpl )); + CodeOpCast impl_astcast_friend = parse_operator_cast( token_fmt( "typename", StrC name(Friend), ast_cast_tmpl )); + CodeOpCast impl_astcast_fn = parse_operator_cast( token_fmt( "typename", StrC name(Fn), ast_cast_tmpl )); + CodeOpCast impl_astcast_module = parse_operator_cast( token_fmt( "typename", StrC name(Module), ast_cast_tmpl )); + CodeOpCast impl_astcast_ns = parse_operator_cast( token_fmt( "typename", StrC name(NS), ast_cast_tmpl )); + CodeOpCast impl_astcast_op = parse_operator_cast( token_fmt( "typename", StrC name(Operator), ast_cast_tmpl )); + CodeOpCast impl_astcast_opcast = parse_operator_cast( token_fmt( "typename", StrC name(OpCast), ast_cast_tmpl )); + CodeOpCast impl_astcast_param = parse_operator_cast( token_fmt( "typename", StrC name(Param), ast_cast_tmpl )); + CodeOpCast impl_astcast_precond = parse_operator_cast( token_fmt( "typename", StrC name(PreprocessCond), ast_cast_tmpl )); + CodeOpCast impl_astcast_specs = parse_operator_cast( token_fmt( "typename", StrC name(Specifiers), ast_cast_tmpl )); + CodeOpCast impl_astcast_struct = parse_operator_cast( token_fmt( "typename", StrC name(Struct), ast_cast_tmpl )); + CodeOpCast impl_astcast_tmpl = parse_operator_cast( token_fmt( "typename", StrC name(Template), ast_cast_tmpl )); + CodeOpCast impl_astcast_type = parse_operator_cast( token_fmt( "typename", StrC name(Type), ast_cast_tmpl )); + CodeOpCast impl_astcast_typedef = parse_operator_cast( token_fmt( "typename", StrC name(Typedef), ast_cast_tmpl )); + CodeOpCast impl_astcast_union = parse_operator_cast( token_fmt( "typename", StrC name(Union), ast_cast_tmpl )); + CodeOpCast impl_astcast_using = parse_operator_cast( token_fmt( "typename", StrC name(Using), ast_cast_tmpl )); + CodeOpCast impl_astcast_var = parse_operator_cast( token_fmt( "typename", StrC name(Var), ast_cast_tmpl )); + + char const* code_cast_tmpl = stringize( + Code::operator Code() const + { + return { (AST_*) ast }; + } + ); + + CodeOpCast impl_codecast_attr = parse_operator_cast( token_fmt( "type", StrC name(CodeAttributes), code_cast_tmpl ) ); + CodeOpCast impl_codecast_cmt = parse_operator_cast( token_fmt( "type", StrC name(CodeComment), code_cast_tmpl ) ); + CodeOpCast impl_codecast_class = parse_operator_cast( token_fmt( "type", StrC name(CodeClass), code_cast_tmpl ) ); + CodeOpCast impl_codecast_define = parse_operator_cast( token_fmt( "type", StrC name(CodeDefine), code_cast_tmpl ) ); + CodeOpCast impl_codecast_enum = parse_operator_cast( token_fmt( "type", StrC name(CodeEnum), code_cast_tmpl ) ); + CodeOpCast impl_codecast_exec = parse_operator_cast( token_fmt( "type", StrC name(CodeExec), code_cast_tmpl ) ); + CodeOpCast impl_codecast_extern = parse_operator_cast( token_fmt( "type", StrC name(CodeExtern), code_cast_tmpl ) ); + CodeOpCast impl_codecast_friend = parse_operator_cast( token_fmt( "type", StrC name(CodeFriend), code_cast_tmpl ) ); + CodeOpCast impl_codecast_fn = parse_operator_cast( token_fmt( "type", StrC name(CodeFn), code_cast_tmpl ) ); + CodeOpCast impl_codecast_module = parse_operator_cast( token_fmt( "type", StrC name(CodeModule), code_cast_tmpl ) ); + CodeOpCast impl_codecast_ns = parse_operator_cast( token_fmt( "type", StrC name(CodeNS), code_cast_tmpl ) ); + CodeOpCast impl_codecast_op = parse_operator_cast( token_fmt( "type", StrC name(CodeOperator), code_cast_tmpl ) ); + CodeOpCast impl_codecast_opCast = parse_operator_cast( token_fmt( "type", StrC name(CodeOpCast), code_cast_tmpl ) ); + CodeOpCast impl_codecast_param = parse_operator_cast( token_fmt( "type", StrC name(CodeParam), code_cast_tmpl ) ); + CodeOpCast impl_codecast_precond = parse_operator_cast( token_fmt( "type", StrC name(CodePreprocessCond), code_cast_tmpl ) ); + CodeOpCast impl_codecast_specs = parse_operator_cast( token_fmt( "type", StrC name(CodeSpecifiers), code_cast_tmpl ) ); + CodeOpCast impl_codecast_struct = parse_operator_cast( token_fmt( "type", StrC name(CodeStruct), code_cast_tmpl ) ); + CodeOpCast impl_codecast_template= parse_operator_cast( token_fmt( "type", StrC name(CodeTemplate), code_cast_tmpl ) ); + CodeOpCast impl_codecast_type = parse_operator_cast( token_fmt( "type", StrC name(CodeType), code_cast_tmpl ) ); + CodeOpCast impl_codecast_typedef = parse_operator_cast( token_fmt( "type", StrC name(CodeTypedef), code_cast_tmpl ) ); + CodeOpCast impl_codecast_union = parse_operator_cast( token_fmt( "type", StrC name(CodeUnion), code_cast_tmpl ) ); + CodeOpCast impl_codecast_using = parse_operator_cast( token_fmt( "type", StrC name(CodeUsing), code_cast_tmpl ) ); + CodeOpCast impl_codecast_var = parse_operator_cast( token_fmt( "type", StrC name(CodeVar), code_cast_tmpl ) ); + + CodeBody result = def_global_body( args( + def_pragma( txt_StrC("region generated code inline implementation")), + fmt_newline, + impl_code, + impl_code_body, + impl_code_cmt, + impl_code_class, + impl_code_define, + impl_code_enum, + impl_code_exec, + impl_code_extern, + impl_code_friend, + impl_code_fn, + impl_code_module, + impl_code_ns, + impl_code_op, + impl_code_opcast, + impl_code_param, + impl_code_precond, + impl_code_specs, + impl_code_struct, + impl_code_tmpl, + impl_code_type, + impl_code_typedef, + impl_code_union, + impl_code_using, + impl_code_var, + fmt_newline, + def_pragma( txt_StrC("endregion generated code inline implementation")), + fmt_newline, + def_pragma( txt_StrC("region generated AST cast implementation")), + fmt_newline, + impl_astcast_body, + impl_astcast_cmt, + impl_astcast_class, + impl_astcast_define, + impl_astcast_enum, + impl_astcast_exec, + impl_astcast_extern, + impl_astcast_friend, + impl_astcast_fn, + impl_astcast_module, + impl_astcast_ns, + impl_astcast_op, + impl_astcast_opcast, + impl_astcast_param, + impl_astcast_precond, + impl_astcast_specs, + impl_astcast_struct, + impl_astcast_tmpl, + impl_astcast_type, + impl_astcast_typedef, + impl_astcast_union, + impl_astcast_using, + impl_astcast_var, + fmt_newline, + def_pragma( txt_StrC("endregion generated AST cast implementation")), + fmt_newline, + def_pragma( txt_StrC("region Code cast implementation")), + impl_codecast_attr, + impl_codecast_cmt, + impl_codecast_class, + impl_codecast_define, + impl_codecast_enum, + impl_codecast_exec, + impl_codecast_extern, + impl_codecast_friend, + impl_codecast_fn, + impl_codecast_module, + impl_codecast_ns, + impl_codecast_op, + impl_codecast_opCast, + impl_codecast_param, + impl_codecast_precond, + impl_codecast_specs, + impl_codecast_struct, + impl_codecast_template, + impl_codecast_type, + impl_codecast_typedef, + impl_codecast_union, + impl_codecast_using, + impl_codecast_var, + fmt_newline, + def_pragma( txt_StrC("endregion Code cast implementation")), + fmt_newline + )); + + return result; +#pragma pop_macro("rcast") } diff --git a/scripts/gencpp.natvis b/scripts/gencpp.natvis index 66c0081..5673a1c 100644 --- a/scripts/gencpp.natvis +++ b/scripts/gencpp.natvis @@ -213,7 +213,7 @@ - + {Name} Type: {Type} ModuleFlags @@ -498,7 +498,7 @@ - + Null {ast->Name} {ast->Type} diff --git a/singleheader/gen.singleheader.cpp b/singleheader/gen.singleheader.cpp index b28e41e..7a2d601 100644 --- a/singleheader/gen.singleheader.cpp +++ b/singleheader/gen.singleheader.cpp @@ -108,17 +108,17 @@ int gen_main() header.print_fmt( roll_own_dependencies_guard_end ); } - Code types = scan_file( project_dir "components/types.hpp" ); - Code ast = scan_file( project_dir "components/ast.hpp" ); - Code ast_types = scan_file( project_dir "components/ast_types.hpp" ); - Code interface = scan_file( project_dir "components/interface.hpp" ); - Code inlines = scan_file( project_dir "components/inlines.hpp" ); - Code ast_inlines = scan_file( project_dir "components/temp/ast_inlines.hpp" ); - Code header_end = scan_file( project_dir "components/header_end.hpp" ); + Code types = scan_file( project_dir "components/types.hpp" ); + Code ast = scan_file( project_dir "components/ast.hpp" ); + Code ast_types = scan_file( project_dir "components/ast_types.hpp" ); + Code interface = scan_file( project_dir "components/interface.hpp" ); + Code inlines = scan_file( project_dir "components/inlines.hpp" ); + Code header_end = scan_file( project_dir "components/header_end.hpp" ); - CodeBody ecode = gen_ecode ( project_dir "enums/ECode.csv" ); - CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" ); - CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" ); + CodeBody ecode = gen_ecode ( project_dir "enums/ECode.csv" ); + CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" ); + CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" ); + CodeBody ast_inlines = gen_ast_inlines(); header.print_fmt( "GEN_NS_BEGIN\n\n" ); @@ -211,7 +211,7 @@ int gen_main() Code untyped = scan_file( project_dir "components/untyped.cpp" ); CodeBody etoktype = gen_etoktype( project_dir "enums/ETokType.csv", project_dir "enums/AttributeTokens.csv" ); - CodeNamespace parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) ); + CodeNS parser_nspace = def_namespace( name(Parser), def_namespace_body( args(etoktype)) ); header.print_fmt( "GEN_NS_BEGIN\n\n"); header.print( static_data ); diff --git a/test/parsed/Sanity.Parsed.hpp b/test/parsed/Sanity.Parsed.hpp index bfa0f0f..e4a3352 100644 --- a/test/parsed/Sanity.Parsed.hpp +++ b/test/parsed/Sanity.Parsed.hpp @@ -132,7 +132,7 @@ u32 gen_sanity() // Namespace { - CodeNamespace def = parse_namespace( code( + CodeNS def = parse_namespace( code( namespace TestNamespace { } @@ -283,7 +283,7 @@ u32 gen_sanity() using TestUsing = u8; )); - CodeNamespace nspace = parse_namespace( code( + CodeNS nspace = parse_namespace( code( namespace TestNamespace { }; diff --git a/test/upfront/Sanity.Upfront.hpp b/test/upfront/Sanity.Upfront.hpp index 6fb1c07..5c9a7a0 100644 --- a/test/upfront/Sanity.Upfront.hpp +++ b/test/upfront/Sanity.Upfront.hpp @@ -139,7 +139,7 @@ u32 gen_sanity_upfront() // Namespace { - CodeNamespace namespace_def; + CodeNS namespace_def; { CodeBody body = def_namespace_body( 1 , def_comment( txt_StrC("Empty namespace body") )