mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-14 18:51:47 -07:00
Improved singleheader test
Need to make the debug_str provided by the AST type aware to provide as much contextual information as possible (finally got to this point with validation). Singleheader test now directly calls clang-format to cleanup the reconstructed copy of the singleheader. Its needed to remove any sort of formatting discrepancies found by the parser since its sensistive to that for new-lines, etc.
This commit is contained in:
@ -7,34 +7,49 @@
|
||||
#include "gen.scanner.hpp"
|
||||
using namespace gen;
|
||||
|
||||
#ifdef GEN_SYSTEM_WINDOWS
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
void check_singleheader_ast()
|
||||
{
|
||||
#define project_dir "../"
|
||||
#define root_dir "../"
|
||||
gen::init();
|
||||
log_fmt("\ncheck_singleheader_ast:\n");
|
||||
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, project_dir "singleheader/gen/gen.hpp" );
|
||||
FileContents file = file_read_contents( GlobalAllocator, true, root_dir "singleheader/gen/gen.hpp" );
|
||||
u64 time_start = time_rel_ms();
|
||||
CodeBody ast = parse_global_body( { file.size, (char const*)file.data } );
|
||||
|
||||
log_fmt("\nAst generated. Time taken: %llu ms\n", time_rel_ms() - time_start);
|
||||
|
||||
log_fmt("\nSerializng ast:\n");
|
||||
time_start = time_rel_ms();
|
||||
|
||||
Builder
|
||||
builder = Builder::open( "gen/singleheader_copy.gen.hpp" );
|
||||
builder.print( ast );
|
||||
builder.write();
|
||||
|
||||
log_fmt("Serialized. Time taken: %llu ms\n", time_rel_ms() - time_start);
|
||||
|
||||
// Need to execute clang format on the generated file to get it to match the original.
|
||||
#define script_path root_dir "scripts/"
|
||||
#define clang_format "clang-format "
|
||||
#define cf_format_inplace "-i "
|
||||
#define cf_style "-style=file:" "C:/projects/gencpp/scripts/.clang-format "
|
||||
#define cf_verbose "-verbose "
|
||||
|
||||
log_fmt("\nRunning clang-format on generated file:\n");
|
||||
system( clang_format cf_format_inplace cf_style cf_verbose "gen/singleheader_copy.gen.hpp" );
|
||||
log_fmt("clang-format finished reformatting.\n");
|
||||
#undef script_path
|
||||
#undef cf_cmd
|
||||
#undef cf_format_inplace
|
||||
#undef cf_style
|
||||
#undef cf_verbse
|
||||
|
||||
FileContents file_gen = file_read_contents( GlobalAllocator, true, "gen/singleheader_copy.gen.hpp" );
|
||||
|
||||
log_fmt("\nReconstructing from generated file:\n");
|
||||
time_start = time_rel_ms();
|
||||
CodeBody ast_gen = parse_global_body( { file_gen.size, (char const*)file_gen.data } );
|
||||
|
||||
time_start = time_rel_ms();
|
||||
CodeBody ast_gen = parse_global_body( { file_gen.size, (char const*)file_gen.data } );
|
||||
log_fmt("\nAst generated. Time taken: %llu ms\n\n", time_rel_ms() - time_start);
|
||||
|
||||
time_start = time_rel_ms();
|
||||
|
Reference in New Issue
Block a user