From ceea184d5a5bc71098e5d1875fff9159b94b2eac Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 6 Dec 2024 05:29:36 -0500 Subject: [PATCH] Update to c_library.cpp (now up to ast.hpp) --- gen_c_library/c_library.cpp | 144 ++++++++++++++++++++++++++++-- gen_c_library/components/misc.hpp | 4 +- 2 files changed, 140 insertions(+), 8 deletions(-) diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 1941792..0c633c6 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -105,6 +105,10 @@ int gen_main() PreprocessorDefines.append(txt("GEN_API_C_BEGIN")); PreprocessorDefines.append(txt("GEN_API_C_END")); PreprocessorDefines.append(txt("HashTable(")); + PreprocessorDefines.append(txt("GEN_NS_PARSER")); + PreprocessorDefines.append(txt("GEN_NS_PARSER_BEGIN")); + PreprocessorDefines.append(txt("GEN_NS_PARSER_END")); + //PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT")); Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" ); Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" ); @@ -121,8 +125,45 @@ int gen_main() header.print( c_library_header_start ); #pragma region Scan, Parse, and Generate Components - Code types = scan_file( project_dir "components/types.hpp" ); - Code ast = scan_file( project_dir "components/ast.hpp" ); + CodeBody parsed_types = parse_file( project_dir "components/types.hpp" ); + CodeBody types = def_body(CT_Global_Body); + for ( Code entry = parsed_types.begin(); entry != parsed_types.end(); ++ entry ) + { + switch(entry->Type) + { + case CT_Using: + { + CodeUsing using_ver = cast(CodeUsing, entry); + + if (using_ver->UnderlyingType->ReturnType) + { + CodeTypename type = using_ver->UnderlyingType; + CodeTypedef typedef_ver = parse_typedef(token_fmt( + "ReturnType", to_string(type->ReturnType).to_strc() + , "Name" , using_ver->Name + , "Parameters", to_string(type->Params).to_strc() + , stringize( + typedef ( * )(); + ))); + types.append(typedef_ver); + break; + } + CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType); + types.append(typedef_ver); + } + break; + + case CT_Enum: + { + CodeEnum enum_def = cast(CodeEnum, entry); + CodeTypedef typedef_enum = parse_typedef(token_fmt("name", enum_def->Name, stringize( typedef enum ; ))); + types.append(enum_def); + types.append(typedef_enum); + } + break; + } + } + Code ast_types = scan_file( project_dir "components/ast_types.hpp" ); Code code_types = scan_file( project_dir "components/code_types.hpp" ); Code interface = scan_file( project_dir "components/interface.hpp" ); @@ -133,6 +174,86 @@ int gen_main() CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv" ); CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv" ); CodeBody ast_inlines = gen_ast_inlines(); + + CodeBody parsed_ast = parse_file( project_dir "components/ast.hpp" ); + CodeBody ast = def_body(CT_Global_Body); + for ( Code entry = parsed_ast.begin(); entry != parsed_ast.end(); ++ entry ) + switch (entry->Type) + { + case CT_Preprocess_If: + { + CodePreprocessCond cond = cast(CodePreprocessCond, entry); + if (cond->Content.contains(txt("GEN_COMPILER_C"))) + { + //++ entry; // + //ast.append(entry) // typedef + //for ( ; entry != parsed_ast.end() && entry->Type != CT_Preprocess_EndIf; ++ entry) {} + //++ entry; // Consume endif + } + + b32 found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, parsed_ast, ast ); + if (found) break; + + found = ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_REFERENCES"), entry, parsed_ast, ast); + if (found) break; + + found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_ast, ast); + if (found) break; + + ast.append(entry); + } + break; + + case CT_Struct_Fwd: + { + CodeStruct fwd = cast(CodeStruct, entry); + if (fwd->Name.starts_with(txt("AST"))) { + ast.append(fwd); + CodeTypedef td = parse_typedef(token_fmt("name", fwd->Name, stringize( typedef struct ; ))); + ast.append(td); + } + } + break; + + case CT_Variable: + { + CodeVar var = cast(CodeVar, entry); + + s32 constexpr_found = var->Specs.remove( Spec_Constexpr ); + if (constexpr_found > -1) { + log_fmt("Found constexpr: %S\n", entry.to_string()); + if (var->Name.contains(txt("AST_ArrSpecs_Cap"))) + { + Code def = untyped_str(txt( +R"(#define AST_ArrSpecs_Cap \ +( \ + AST_POD_Size \ + - sizeof(AST*) * 3 \ + - sizeof(Token*) \ + - sizeof(AST*) \ + - sizeof(StringCached) \ + - sizeof(CodeType) \ + - sizeof(ModuleFlag) \ + - sizeof(int) \ +) \ +/ sizeof(int) - 1 +)" + )); + ast.append(def); + break; + } + CodeDefine def = def_define(var->Name, var->Value.to_string()); + ast.append(def); + break; + } + ast.append(var); + } + break; + + default: + ast.append(entry); + break; + } #pragma endregion Scan, Parse, and Generate Components #pragma region Scan, Parse, and Generate Dependencies @@ -464,19 +585,30 @@ int gen_main() header.print_fmt( roll_own_dependencies_guard_end ); #pragma endregion Print Dependencies + header.print(fmt_newline); + +#if 1 +#pragma region region Print Components + header.print_fmt( "GEN_NS_BEGIN\n" ); + header.print_fmt( "GEN_API_C_BEGIN\n\n" ); -#if 0 -#region region Print Components header.print_fmt("#pragma region Types\n"); - header.print( types ); + header.print( dump_to_scratch_and_retireve(types) ); header.print( fmt_newline ); header.print( dump_to_scratch_and_retireve( ecode )); header.print( fmt_newline ); header.print( dump_to_scratch_and_retireve( eoperator )); header.print( fmt_newline ); header.print( dump_to_scratch_and_retireve( especifier )); - header.print( fmt_newline ); header.print_fmt("#pragma endregion Types\n\n"); + + header.print_fmt("#pragma region AST\n"); + header.print( dump_to_scratch_and_retireve(ast) ); + header.print_fmt("\n#pragma endregion AST\n"); + + header.print_fmt( "\nGEN_API_C_END\n" ); + + header.print_fmt( "GEN_NS_END\n\n" ); #pragma endregion Print Compoennts #endif } diff --git a/gen_c_library/components/misc.hpp b/gen_c_library/components/misc.hpp index 1190e0c..0f910fb 100644 --- a/gen_c_library/components/misc.hpp +++ b/gen_c_library/components/misc.hpp @@ -181,7 +181,7 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt("" continue; } - new_name.append_fmt("%SC_", to_str(spec)); + new_name.append_fmt("%SC_", spec_to_str(spec)); } } @@ -197,7 +197,7 @@ CodeFn rename_function_to_unique_symbol(CodeFn fn, StrC optional_prefix = txt("" spec != end(fn->Specs); ++spec) { - new_name.append_fmt("%SC_", to_str(*spec)); + new_name.append_fmt("%SC_", spec_to_str(*spec)); } }