mirror of
https://github.com/Ed94/gencpp.git
synced 2024-11-12 20:04:52 -08:00
Minimizing reformatting of generated library files
This commit is contained in:
parent
23742868c4
commit
c1878265c8
2
.gitignore
vendored
2
.gitignore
vendored
@ -29,3 +29,5 @@ release/**
|
||||
! **/Unreal/validate.unreal.cpp
|
||||
project/auxillary/vis_ast/dependencies/temp
|
||||
test/gen/original
|
||||
singleheader/gen/scratch.hpp
|
||||
test/gen/scratch.cpp
|
||||
|
@ -20,6 +20,42 @@ constexpr char const* generation_notice =
|
||||
"// This file was generated automatially by gencpp's bootstrap.cpp "
|
||||
"(See: https://github.com/Ed94/gencpp)\n\n";
|
||||
|
||||
void format_file( char const* path )
|
||||
{
|
||||
String resolved_path = String::make(GlobalAllocator, to_str(path));
|
||||
|
||||
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
||||
style_arg.append("../scripts/.clang-format ");
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_verbose "-verbose "
|
||||
String command = String::make( GlobalAllocator, clang_format );
|
||||
command.append( cf_format_inplace );
|
||||
command.append( cf_verbose );
|
||||
command.append( style_arg );
|
||||
command.append( resolved_path );
|
||||
log_fmt("\tRunning clang-format on file:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished reformatting.\n");
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
}
|
||||
|
||||
Code dump_to_scratch_and_retireve( Code code )
|
||||
{
|
||||
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
||||
ecode_file_temp.print(code);
|
||||
ecode_file_temp.write();
|
||||
format_file("gen/scratch.hpp");
|
||||
Code result = scan_file( "gen/scratch.hpp" );
|
||||
remove("gen/scratch.hpp");
|
||||
return result;
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen::init();
|
||||
@ -132,9 +168,13 @@ int gen_main()
|
||||
|
||||
header.print_fmt( "#pragma region Types\n" );
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
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" );
|
||||
@ -148,7 +188,8 @@ int gen_main()
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( fmt_newline );
|
||||
header.print( ast_inlines );
|
||||
header.print( dump_to_scratch_and_retireve(ast_inlines) );
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
@ -217,7 +258,7 @@ int gen_main()
|
||||
src.print( interface );
|
||||
src.print( upfront );
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( nspaced_etoktype );
|
||||
src.print( dump_to_scratch_and_retireve(nspaced_etoktype) );
|
||||
src.print( lexer );
|
||||
src.print( parser );
|
||||
src.print( parsing_interface );
|
||||
|
@ -23,7 +23,7 @@
|
||||
{
|
||||
u32 hi, lo;
|
||||
__asm__ __volatile__( "rdtsc" : "=a"( lo ), "=d"( hi ) );
|
||||
return ( scast( u64, lo ) | ( ( scast( u64, hi ) << 32 );
|
||||
return scast( u64, lo ) | ( scast( u64, hi ) << 32 );
|
||||
}
|
||||
#elif defined( __powerpc__ )
|
||||
u64 read_cpu_time_stamp_counter( void )
|
||||
|
@ -291,7 +291,7 @@ if ( $test )
|
||||
|
||||
#region Formatting
|
||||
push-location $path_scripts
|
||||
if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
|
||||
if ( $true -and $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
|
||||
{
|
||||
$path_gen = join-path $path_project gen
|
||||
$include = @(
|
||||
@ -301,12 +301,12 @@ if ( $bootstrap -and (Test-Path (Join-Path $path_project "gen/gen.hpp")) )
|
||||
'gen.scanner.hpp', 'gen.scanner.cpp'
|
||||
)
|
||||
$exclude = $null
|
||||
format-cpp $path_gen $include $exclude
|
||||
# format-cpp $path_gen $include $exclude
|
||||
format-cpp $path_comp_gen @( 'ast_inlines.hpp', 'ecode.hpp', 'especifier.hpp', 'eoperator.hpp', 'etoktype.cpp' ) $null
|
||||
|
||||
}
|
||||
|
||||
if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) )
|
||||
if ( $false -and $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp")) )
|
||||
{
|
||||
$path_gen = join-path $path_singleheader gen
|
||||
$include = @(
|
||||
@ -316,7 +316,7 @@ if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp"))
|
||||
format-cpp $path_gen $include $exclude
|
||||
}
|
||||
|
||||
if ( $unreal -and (Test-Path( Join-Path $path_unreal "gen/gen.hpp")) )
|
||||
if ( $false -and $unreal -and (Test-Path( Join-Path $path_unreal "gen/gen.hpp")) )
|
||||
{
|
||||
$path_gen = join-path $path_unreal gen
|
||||
$include = @(
|
||||
|
@ -48,6 +48,42 @@ global bool generate_builder = true;
|
||||
global bool generate_editor = true;
|
||||
global bool generate_scanner = true;
|
||||
|
||||
void format_file( char const* path )
|
||||
{
|
||||
String resolved_path = String::make(GlobalAllocator, to_str(path));
|
||||
|
||||
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
||||
style_arg.append("../scripts/.clang-format ");
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_verbose "-verbose "
|
||||
String command = String::make( GlobalAllocator, clang_format );
|
||||
command.append( cf_format_inplace );
|
||||
command.append( cf_verbose );
|
||||
command.append( style_arg );
|
||||
command.append( resolved_path );
|
||||
log_fmt("\tRunning clang-format on file:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished reformatting.\n");
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
}
|
||||
|
||||
Code dump_to_scratch_and_retireve( Code code )
|
||||
{
|
||||
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
||||
ecode_file_temp.print(code);
|
||||
ecode_file_temp.write();
|
||||
format_file("gen/scratch.hpp");
|
||||
Code result = scan_file( "gen/scratch.hpp" );
|
||||
remove("gen/scratch.hpp");
|
||||
return result;
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
#define project_dir "../project/"
|
||||
@ -85,7 +121,6 @@ int gen_main()
|
||||
header.print_fmt( roll_own_dependencies_guard_start );
|
||||
header.print( fmt_newline );
|
||||
header.print( platform );
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( macros );
|
||||
@ -129,9 +164,13 @@ int gen_main()
|
||||
|
||||
header.print_fmt("#pragma region Types\n");
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
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");
|
||||
@ -144,7 +183,8 @@ int gen_main()
|
||||
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( ast_inlines );
|
||||
header.print( dump_to_scratch_and_retireve( ast_inlines ));
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
@ -226,7 +266,7 @@ int gen_main()
|
||||
header.print( interface );
|
||||
header.print( upfront );
|
||||
header.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
header.print( parser_nspace );
|
||||
header.print( dump_to_scratch_and_retireve(parser_nspace) );
|
||||
header.print( lexer );
|
||||
header.print( parser );
|
||||
header.print( parsing_interface );
|
||||
|
@ -48,6 +48,42 @@ global bool generate_builder = true;
|
||||
global bool generate_editor = true;
|
||||
global bool generate_scanner = true;
|
||||
|
||||
void format_file( char const* path )
|
||||
{
|
||||
String resolved_path = String::make(GlobalAllocator, to_str(path));
|
||||
|
||||
String style_arg = String::make(GlobalAllocator, txt("-style=file:"));
|
||||
style_arg.append("../scripts/.clang-format ");
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_verbose "-verbose "
|
||||
String command = String::make( GlobalAllocator, clang_format );
|
||||
command.append( cf_format_inplace );
|
||||
command.append( cf_verbose );
|
||||
command.append( style_arg );
|
||||
command.append( resolved_path );
|
||||
log_fmt("\tRunning clang-format on file:\n");
|
||||
system( command );
|
||||
log_fmt("\tclang-format finished reformatting.\n");
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
}
|
||||
|
||||
Code dump_to_scratch_and_retireve( Code code )
|
||||
{
|
||||
Builder ecode_file_temp = Builder::open("gen/scratch.hpp");
|
||||
ecode_file_temp.print(code);
|
||||
ecode_file_temp.write();
|
||||
format_file("gen/scratch.hpp");
|
||||
Code result = scan_file( "gen/scratch.hpp" );
|
||||
remove("gen/scratch.hpp");
|
||||
return result;
|
||||
}
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
#define project_dir "../project/"
|
||||
@ -61,24 +97,6 @@ int gen_main()
|
||||
|
||||
// gen_dep.hpp
|
||||
{
|
||||
CodeBody header_start = def_body( CodeT::Global_Body );
|
||||
{
|
||||
FileContents content = file_read_contents( GlobalAllocator, true, project_dir "dependencies/header_start.hpp" );
|
||||
CodeBody ori_header_start = parse_global_body( StrC { content.size, (char const*)content.data });
|
||||
|
||||
for (Code code = ori_header_start.begin();
|
||||
code != ori_header_start.end();
|
||||
++ code )
|
||||
{
|
||||
header_start.append(code);
|
||||
if (code->Type == CodeT::Preprocess_Pragma && code->Content.starts_with(txt("once")))
|
||||
{
|
||||
header_start.append( fmt_newline );
|
||||
header_start.append( push_ignores );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CodeBody macros = def_body( CodeT::Global_Body );
|
||||
{
|
||||
FileContents content = file_read_contents( GlobalAllocator, true, project_dir "dependencies/macros.hpp" );
|
||||
@ -111,6 +129,7 @@ int gen_main()
|
||||
}
|
||||
}
|
||||
|
||||
Code platform = scan_file( project_dir "dependencies/platform.hpp" );
|
||||
Code basic_types = scan_file( project_dir "dependencies/basic_types.hpp" );
|
||||
Code debug = scan_file( project_dir "dependencies/debug.hpp" );
|
||||
Code memory = scan_file( project_dir "dependencies/memory.hpp" );
|
||||
@ -125,10 +144,13 @@ int gen_main()
|
||||
Builder
|
||||
header = Builder::open("gen/gen.dep.hpp");
|
||||
header.print_fmt( generation_notice );
|
||||
header.print( header_start );
|
||||
header.print( pragma_once );
|
||||
header.print( push_ignores );
|
||||
header.print( platform );
|
||||
header.print_fmt( "\nGEN_NS_BEGIN\n" );
|
||||
|
||||
header.print( macros );
|
||||
header.print( fmt_newline);
|
||||
header.print( dump_to_scratch_and_retireve(macros) );
|
||||
header.print( basic_types );
|
||||
header.print( debug );
|
||||
header.print( memory );
|
||||
@ -209,9 +231,13 @@ int gen_main()
|
||||
|
||||
header.print_fmt( "#pragma region Types\n" );
|
||||
header.print( types );
|
||||
header.print( ecode );
|
||||
header.print( eoperator );
|
||||
header.print( especifier );
|
||||
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" );
|
||||
@ -225,7 +251,8 @@ int gen_main()
|
||||
header.print_fmt( "\n#pragma region Inlines\n" );
|
||||
header.print( inlines );
|
||||
header.print( fmt_newline );
|
||||
header.print( ast_inlines );
|
||||
header.print( dump_to_scratch_and_retireve(ast_inlines) );
|
||||
header.print( fmt_newline );
|
||||
header.print_fmt( "#pragma endregion Inlines\n" );
|
||||
|
||||
header.print( header_end );
|
||||
@ -275,7 +302,7 @@ int gen_main()
|
||||
src.print( interface );
|
||||
src.print( upfront );
|
||||
src.print_fmt( "\n#pragma region Parsing\n\n" );
|
||||
src.print( nspaced_etoktype );
|
||||
src.print( dump_to_scratch_and_retireve(nspaced_etoktype) );
|
||||
src.print( lexer );
|
||||
src.print( parser );
|
||||
src.print( parsing_interface );
|
||||
|
Loading…
Reference in New Issue
Block a user