mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-21 23:34:44 -08:00
WIP: code_types.hpp c_library.cpp conversion (issue with C struct padding on asts)
This commit is contained in:
parent
1c133bfc8d
commit
99dbc499fa
@ -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 <name> <name>; )));
|
||||
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" );
|
||||
|
@ -257,6 +257,7 @@
|
||||
<None Include="test\Readme.md" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="gen_c_library\gen\gen.h" />
|
||||
<ClInclude Include="project\auxillary\builder.hpp" />
|
||||
<ClInclude Include="project\auxillary\editor.hpp" />
|
||||
<ClInclude Include="project\auxillary\scanner.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
|
||||
|
@ -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 );
|
||||
// <Macro>;
|
||||
|
||||
// TODO(Ed): Reveiw the context for this? (ESPECIALLY THIS)
|
||||
if ( currtok_noskip.Type == Tok_Comment && currtok_noskip.Line == stmt_end.Line )
|
||||
eat( Tok_Comment );
|
||||
// <Macro>; <InlineCmt>
|
||||
}
|
||||
|
||||
}
|
||||
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 );
|
||||
// <Macro>;
|
||||
}
|
||||
}
|
||||
|
||||
tok.Length = ( (sptr)currtok_noskip.Text + currtok_noskip.Length ) - (sptr)tok.Text;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user