mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-16 19:51:47 -07:00
Finished first pass reviewing memory.hpp for C lib generation
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#define GEN_EXPOSE_BACKEND
|
||||
#include "gen.cpp"
|
||||
#include "../project/gen.cpp"
|
||||
|
||||
#include "helpers/push_ignores.inline.hpp"
|
||||
#include "helpers/helper.hpp"
|
||||
@ -16,6 +16,9 @@ GEN_NS_END
|
||||
|
||||
#include <cstdlib> // for system()
|
||||
|
||||
#include "components/fixed_arena.hpp"
|
||||
#include "components/misc.hpp"
|
||||
|
||||
using namespace gen;
|
||||
|
||||
constexpr char const* generation_notice =
|
||||
@ -80,26 +83,117 @@ Code dump_to_scratch_and_retireve( Code code )
|
||||
return result;
|
||||
}
|
||||
|
||||
CodeBody parse_file( const char* path )
|
||||
{
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, path );
|
||||
CodeBody code = parse_global_body( { file.size, (char const*)file.data } );
|
||||
return code;
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
#define project_dir "../project/"
|
||||
gen::init();
|
||||
|
||||
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
Code single_header_start = scan_file( "components/header_start.hpp" );
|
||||
Code push_ignores = scan_file( project_dir "helpers/push_ignores.inline.hpp" );
|
||||
Code pop_ignores = scan_file( project_dir "helpers/pop_ignores.inline.hpp" );
|
||||
Code c_library_header_start = scan_file( "components/header_start.hpp" );
|
||||
|
||||
Builder
|
||||
header = Builder::open( "gen/gen.hpp" );
|
||||
header = Builder::open( "gen/gen.h" );
|
||||
header.print_fmt( generation_notice );
|
||||
header.print_fmt("#pragma once\n\n");
|
||||
header.print( push_ignores );
|
||||
|
||||
// Headers
|
||||
{
|
||||
header.print( c_library_header_start );
|
||||
|
||||
Code platform = scan_file( project_dir "dependencies/platform.hpp" );
|
||||
Code macros = scan_file( project_dir "dependencies/macros.hpp" );
|
||||
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
|
||||
CodeBody parsed_memory = parse_file( project_dir "dependencies/memory.hpp" );
|
||||
CodeBody memory = def_body(ECode::Struct_Body);
|
||||
for ( Code entry = parsed_memory.begin(); entry != parsed_memory.end(); ++ entry )
|
||||
{
|
||||
switch (entry->Type)
|
||||
{
|
||||
case ECode::Using:
|
||||
{
|
||||
log_fmt("REPLACE THIS MANUALLY: %S\n", entry->Name);
|
||||
CodeUsing using_ver = entry.cast<CodeUsing>();
|
||||
CodeTypedef typedef_ver = def_typedef(using_ver->Name, using_ver->UnderlyingType);
|
||||
|
||||
memory.append(typedef_ver);
|
||||
}
|
||||
break;
|
||||
case ECode::Function:
|
||||
{
|
||||
CodeFn fn = entry.cast<CodeFn>();
|
||||
s32 constexpr_found = fn->Specs.remove( ESpecifier::Constexpr );
|
||||
if (constexpr_found > -1) {
|
||||
log_fmt("Found constexpr proc\n");
|
||||
fn->Specs.append(ESpecifier::Inline);
|
||||
}
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
case ECode::Class:
|
||||
case ECode::Struct:
|
||||
{
|
||||
CodeBody body = entry->Body->operator CodeBody();
|
||||
CodeBody new_body = def_body( entry->Body->Type );
|
||||
for ( Code body_entry = body.begin(); body_entry != body.end(); ++ body_entry ) switch
|
||||
(body_entry->Type) {
|
||||
case ECode::Preprocess_If:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), body_entry, body );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
new_body.append(body_entry);
|
||||
break;
|
||||
}
|
||||
|
||||
entry->Body = rcast(AST*, new_body.ast);
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
case ECode::Preprocess_If:
|
||||
{
|
||||
ignore_preprocess_cond_block(txt("GEN_SUPPORT_CPP_MEMBER_FEATURES"), entry, memory );
|
||||
}
|
||||
break;
|
||||
case ECode::Preprocess_Pragma:
|
||||
{
|
||||
swap_pragma_region_implementation( txt("FixedArena"), gen_fixed_arenas, entry, memory);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
memory.append(entry);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print( platform );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( macros );
|
||||
header.print( basic_types );
|
||||
header.print( debug );
|
||||
header.print( memory );
|
||||
}
|
||||
|
||||
header.print( pop_ignores );
|
||||
header.write();
|
||||
|
||||
format_file( "gen/gen.h" );
|
||||
|
||||
gen::deinit();
|
||||
return 0;
|
||||
#undef project_dir
|
||||
|
Reference in New Issue
Block a user