diff --git a/gen_c_library/c_library.cpp b/gen_c_library/c_library.cpp index 768466b..1cec0c8 100644 --- a/gen_c_library/c_library.cpp +++ b/gen_c_library/c_library.cpp @@ -108,6 +108,10 @@ int gen_main() PreprocessorDefines.append(txt("GEN_NS_PARSER")); PreprocessorDefines.append(txt("GEN_NS_PARSER_BEGIN")); PreprocessorDefines.append(txt("GEN_NS_PARSER_END")); + PreprocessorDefines.append(txt("Using_Code(")); + PreprocessorDefines.append(txt("Using_CodeOps(")); + PreprocessorDefines.append(txt("GEN_OPTIMIZE_MAPPINGS_BEGIN")); + PreprocessorDefines.append(txt("GEN_OPITMIZE_MAPPINGS_END")); //PreprocessorDefines.append(txt("GEN_EXECUTION_EXPRESSION_SUPPORT")); Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" ); @@ -125,6 +129,17 @@ int gen_main() header.print( c_library_header_start ); #pragma region Scan, Parse, and Generate Components + // Only has operator overload definitions that C doesn't need. + // CodeBody ast_inlines = gen_ast_inlines(); + + 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/ECodeTypes.csv", helper_use_c_definition ); + CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition ); + CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition ); + 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 ) @@ -165,20 +180,6 @@ int gen_main() 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" ); - 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/ECodeTypes.csv", helper_use_c_definition ); - CodeBody eoperator = gen_eoperator ( project_dir "enums/EOperator.csv", helper_use_c_definition ); - CodeBody especifier = gen_especifier( project_dir "enums/ESpecifier.csv", helper_use_c_definition ); - - // Only has operator overload definitions that C doesn't need. - // 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 ) @@ -213,7 +214,6 @@ int gen_main() case CT_Struct: { - CodeStruct struct_def = cast(CodeStruct, entry); ast.append(struct_def); if ( ! entry->Name.is_equal(txt("AST"))) @@ -263,6 +263,56 @@ R"(#define AST_ArrSpecs_Cap \ ast.append(entry); break; } + CodeBody parsed_code_types = parse_file( project_dir "components/code_types.hpp" ); + CodeBody code_types = def_body(CT_Global_Body); + for ( Code entry = parsed_code_types.begin(); entry != parsed_code_types.end(); ++ entry ) switch( entry->Type ) + { + case CT_Preprocess_If: + case CT_Preprocess_IfDef: + { + b32 found = ignore_preprocess_cond_block(txt("GEN_COMPILER_CPP"), entry, parsed_code_types, code_types ); + if (found) { + ++ entry; + break; + } + found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types ); + if (found) break; + + code_types.append(entry); + } + break; + + default: + code_types.append(entry); + break; + } + CodeBody parsed_ast_types = parse_file( project_dir "components/ast_types.hpp" ); + CodeBody ast_types = def_body(CT_Global_Body); + for ( Code entry = parsed_ast_types.begin(); entry != parsed_ast_types.end(); ++ entry ) switch( entry->Type ) + { + case CT_Preprocess_If: + case CT_Preprocess_IfDef: + { + b32 found = ignore_preprocess_cond_block(txt("GEN_INTELLISENSE_DIRECTIVES"), entry, parsed_code_types, code_types ); + if (found) break; + + ast_types.append(entry); + } + break; + + case CT_Struct: + { + CodeStruct struct_def = cast(CodeStruct, entry); + CodeTypedef tdef = parse_typedef(token_fmt("name", struct_def->Name, stringize( typedef struct ; ))); + ast_types.append(struct_def); + ast_types.append(tdef); + } + break; + + default: + ast_types.append(entry); + break; + } #pragma endregion Scan, Parse, and Generate Components #pragma region Scan, Parse, and Generate Dependencies @@ -662,6 +712,8 @@ R"(#define AST_ArrSpecs_Cap \ header.print_fmt("#pragma region AST\n"); header.print( dump_to_scratch_and_retireve(ast) ); + header.print( dump_to_scratch_and_retireve(code_types) ); + header.print( dump_to_scratch_and_retireve(ast_types) ); header.print_fmt("\n#pragma endregion AST\n"); header.print_fmt( "\nGEN_API_C_END\n" ); diff --git a/gencpp.vcxproj b/gencpp.vcxproj index d31feaa..3ace0d3 100644 --- a/gencpp.vcxproj +++ b/gencpp.vcxproj @@ -257,6 +257,7 @@ + diff --git a/project/components/code_types.hpp b/project/components/code_types.hpp index 95526b0..9556cd0 100644 --- a/project/components/code_types.hpp +++ b/project/components/code_types.hpp @@ -54,8 +54,8 @@ String constructor_to_string (CodeConstructor constructor); void constructor_to_string_def(CodeConstructor constructor, String* result ); void constructor_to_string_fwd(CodeConstructor constructor, String* result ); -String define_to_string (CodeDefine define); -void define_to_string_ref(CodeDefine define, String* result); +String define_to_string (CodeDefine self); +void define_to_string_ref(CodeDefine self, String* result); String destructor_to_string (CodeDestructor destructor); void destructor_to_string_def(CodeDestructor destructor, String* result ); @@ -72,8 +72,8 @@ void exec_to_string_ref(CodeExec exec, String* result); void extern_to_string(CodeExtern self, String* result); -String include_to_string (CodeInclude include); -void include_to_string_ref(CodeInclude include, String* result); +String include_to_string (CodeInclude self); +void include_to_string_ref(CodeInclude self, String* result); String friend_to_string (CodeFriend self); void friend_to_string_ref(CodeFriend self, String* result); @@ -128,10 +128,10 @@ String var_to_string (CodeVar self); void var_to_string_ref(CodeVar self, String* result); #pragma endregion Code Type C-Interface +#if GEN_COMPILER_CPP #pragma region Code Types C++ // These structs are not used at all by the C vairant. -#if GEN_COMPILER_CPP static_assert( GEN_COMPILER_CPP, "This should not be compiled with the C-library" ); #define Verify_POD(Type) static_assert(size_of(Code##Type) == size_of(AST_##Type), "ERROR: Code##Type is not a POD") @@ -983,7 +983,7 @@ struct NullCode_ImplicitCaster #if ! GEN_C_LIKE_CPP GEN_OPTIMIZE_MAPPINGS_BEGIN forceinline void append ( CodeBody body, Code other ) { return body_append(body, other); } -forceinline void append ( CodeBody body, CodeBody other ) { return body_append_body(body, other); }; +forceinline void append ( CodeBody body, CodeBody other ) { return body_append_body(body, other); } forceinline String to_string ( CodeBody body ) { return body_to_string(body); } forceinline void to_string ( CodeBody body, String& result ) { return body_to_string_ref(body, & result); } forceinline void to_string_export( CodeBody body, String& result ) { return body_to_string_export(body, & result); } @@ -1032,8 +1032,8 @@ forceinline String to_string (CodeConstructor constructor) { forceinline void to_string_def(CodeConstructor constructor, String& result ) { return constructor_to_string_def(constructor, & result); } forceinline void to_string_fwd(CodeConstructor constructor, String& result ) { return constructor_to_string_fwd(constructor, & result); } -forceinline String to_string(CodeDefine define) { return define_to_string(define); } -forceinline void to_string(CodeDefine define, String& result) { return define_to_string_ref(define, & result); } +forceinline String to_string(CodeDefine self) { return define_to_string(self); } +forceinline void to_string(CodeDefine self, String& result) { return define_to_string_ref(self, & result); } forceinline String to_string (CodeDestructor destructor) { return destructor_to_string(destructor); } forceinline void to_string_def(CodeDestructor destructor, String& result ) { return destructor_to_string_def(destructor, & result); } @@ -1050,8 +1050,8 @@ forceinline void to_string(CodeExec exec, String& result) { return exec_to_str forceinline void to_string(CodeExtern self, String& result) { return extern_to_string(self, & result); } -forceinline String to_string(CodeInclude include) { return include_to_string(include); } -forceinline void to_string(CodeInclude include, String& result) { return include_to_string_ref(include, & result); } +forceinline String to_string(CodeInclude self) { return include_to_string(self); } +forceinline void to_string(CodeInclude self, String& result) { return include_to_string_ref(self, & result); } forceinline String to_string(CodeFriend self) { return friend_to_string(self); } forceinline void to_string(CodeFriend self, String& result) { return friend_to_string_ref(self, & result); } @@ -1105,8 +1105,7 @@ forceinline void to_string_ns(CodeUsing op_cast, String& result ) { return usi forceinline String to_string(CodeVar self) { return var_to_string(self); } forceinline void to_string(CodeVar self, String& result) { return var_to_string_ref(self, & result); } GEN_OPITMIZE_MAPPINGS_END -#endif - -#endif //if GEN_COMPILER_CPP && GEN_SUPPORT_CPP_MEMBER_FEATURES +#endif //if GEN_C_LIKE_CPP #pragma endregion Code Types C++ +#endif //if GEN_COMPILER_CPP diff --git a/project/components/parser.cpp b/project/components/parser.cpp index 8408e6b..e8dd96b 100644 --- a/project/components/parser.cpp +++ b/project/components/parser.cpp @@ -2992,6 +2992,10 @@ Code parse_simple_preprocess( TokType which, bool dont_consume_braces ) } else { + // If the macro is just a macro in the body of an AST it may have a semi-colon for the user to close on purpsoe + // (especially for functional macros) + StrC& calling_proc = Context.Scope->Prev->ProcName; + if (strc_contains(Context.Scope->Prev->ProcName, txt("parse_enum"))) { // Do nothing @@ -2999,17 +3003,30 @@ Code parse_simple_preprocess( TokType which, bool dont_consume_braces ) } else if (strc_contains(Context.Scope->Prev->ProcName, txt("parse_typedef"))) { + // TODO(Ed): Reveiw the context for this? if ( peektok.Type == Tok_Statement_End ) { Token stmt_end = currtok; eat( Tok_Statement_End ); // ; + // TODO(Ed): Reveiw the context for this? (ESPECIALLY THIS) if ( currtok_noskip.Type == Tok_Comment && currtok_noskip.Line == stmt_end.Line ) eat( Tok_Comment ); // ; } - + } + else if ( + strc_contains(calling_proc, txt("parse_global_nspace")) + && strc_contains(calling_proc, txt("parse_class_struct_body")) + ) + { + if (peektok.Type == Tok_Statement_End) + { + Token stmt_end = currtok; + eat( Tok_Statement_End ); + // ; + } } tok.Length = ( (sptr)currtok_noskip.Text + currtok_noskip.Length ) - (sptr)tok.Text; diff --git a/project/helpers/helper.hpp b/project/helpers/helper.hpp index 72d886c..2f0fb6b 100644 --- a/project/helpers/helper.hpp +++ b/project/helpers/helper.hpp @@ -83,6 +83,15 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) CodeBody result = def_body(CT_Global_Body); body_append(result, enum_code); + + if (use_c_definition) + { + CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; )); + body_append(result, code_t); + } + + body_append(result, to_str_fns); + if (! use_c_definition) { #pragma push_macro("forceinline") @@ -94,12 +103,6 @@ CodeBody gen_ecode( char const* path, bool use_c_definition = false ) #pragma pop_macro("forceinline") body_append(result, alias_mappings); } - else - { - CodeTypedef code_t = parse_typedef(code(typedef enum CodeType CodeType; )); - body_append(result, code_t); - } - body_append(result, to_str_fns); return result; } @@ -175,6 +178,14 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false ) CodeBody result = def_body(CT_Global_Body); body_append(result, enum_code); + if ( use_c_definition ) + { + CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; )); + body_append(result, operator_t); + } + + body_append(result, to_str); + if (! use_c_definition) { #pragma push_macro("forceinline") @@ -185,12 +196,6 @@ CodeBody gen_eoperator( char const* path, bool use_c_definition = false ) #pragma pop_macro("forceinline") body_append(result, alias_mappings); } - else - { - CodeTypedef operator_t = parse_typedef(code( typedef enum Operator Operator; )); - body_append(result, operator_t); - } - body_append(result, to_str); return result; } @@ -315,6 +320,16 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false ) CodeBody result = def_body(CT_Global_Body); body_append(result, enum_code); + if (use_c_definition) + { + CodeTypedef specifier_t = parse_typedef( code(typedef u32 Specifier; )); + body_append(result, specifier_t); + } + + body_append(result, to_str); + body_append(result, is_trailing); + body_append(result, to_type); + if (! use_c_definition) { #pragma push_macro("forceinline") @@ -327,14 +342,6 @@ CodeBody gen_especifier( char const* path, bool use_c_definition = false ) #pragma pop_macro("forceinline") body_append(result, alias_mappings); } - else - { - CodeTypedef specifier_t = parse_typedef( code(typedef enum Specifier Specifier; )); - body_append(result, specifier_t); - } - body_append(result, to_str); - body_append(result, is_trailing); - body_append(result, to_type); return result; }