mirror of
https://github.com/Ed94/gencpp.git
synced 2024-12-22 07:44:45 -08: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:
parent
3e249d9bc5
commit
2200bcde9a
@ -4554,8 +4554,7 @@ CodeTemplate parse_template( StrC def )
|
|||||||
AST_1->Name: (* A ( int (*) (short a,unsigned b,long c) ) )
|
AST_1->Name: (* A ( int (*) (short a,unsigned b,long c) ) )
|
||||||
AST_2->Name: (* A ( int(*)(short a, unsigned b, long c) ) )
|
AST_2->Name: (* A ( int(*)(short a, unsigned b, long c) ) )
|
||||||
|
|
||||||
The excess whitespace can be stripped however, because there is no semantic awareness within the first capture group,
|
The excess whitespace cannot be stripped however, because there is no semantic awareness within the first capture group.
|
||||||
it cannot entirely remove the whitespaceto remove insignificant whitespace.
|
|
||||||
*/
|
*/
|
||||||
internal
|
internal
|
||||||
CodeType parse_type( bool* typedef_is_function )
|
CodeType parse_type( bool* typedef_is_function )
|
||||||
@ -4894,9 +4893,10 @@ CodeType parse_type( bool* typedef_is_function )
|
|||||||
result = (CodeType) make_code();
|
result = (CodeType) make_code();
|
||||||
result->Type = Typename;
|
result->Type = Typename;
|
||||||
|
|
||||||
|
// Need to wait until were using the new parsing method to do this.
|
||||||
String
|
String
|
||||||
name_stripped = String::make( GlobalAllocator, name );
|
name_stripped = String::make( GlobalAllocator, name );
|
||||||
name_stripped.strip_space();
|
// name_stripped.strip_space();
|
||||||
|
|
||||||
#ifdef GEN_USE_NEW_TYPENAME_PARSING
|
#ifdef GEN_USE_NEW_TYPENAME_PARSING
|
||||||
if ( params_nested )
|
if ( params_nested )
|
||||||
|
@ -396,6 +396,7 @@ if ( $test )
|
|||||||
build-simple $includes $unit $executable
|
build-simple $includes $unit $executable
|
||||||
|
|
||||||
Push-Location $path_test
|
Push-Location $path_test
|
||||||
|
Write-Host $path_test
|
||||||
if ( Test-Path( $executable ) ) {
|
if ( Test-Path( $executable ) ) {
|
||||||
write-host "`nRunning test generator"
|
write-host "`nRunning test generator"
|
||||||
$time_taken = Measure-Command { & $executable
|
$time_taken = Measure-Command { & $executable
|
||||||
@ -458,7 +459,7 @@ if ( $singleheader -and (Test-Path (Join-Path $path_singleheader "gen/gen.hpp"))
|
|||||||
format-cpp $path_gen $include $exclude
|
format-cpp $path_gen $include $exclude
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $test )
|
if ( $test -and $false )
|
||||||
{
|
{
|
||||||
$path_gen = join-path $path_test gen
|
$path_gen = join-path $path_test gen
|
||||||
$include = @(
|
$include = @(
|
||||||
|
@ -7,34 +7,49 @@
|
|||||||
#include "gen.scanner.hpp"
|
#include "gen.scanner.hpp"
|
||||||
using namespace gen;
|
using namespace gen;
|
||||||
|
|
||||||
|
#ifdef GEN_SYSTEM_WINDOWS
|
||||||
|
#include <process.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void check_singleheader_ast()
|
void check_singleheader_ast()
|
||||||
{
|
{
|
||||||
#define project_dir "../"
|
#define root_dir "../"
|
||||||
gen::init();
|
gen::init();
|
||||||
log_fmt("\ncheck_singleheader_ast:\n");
|
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();
|
u64 time_start = time_rel_ms();
|
||||||
CodeBody ast = parse_global_body( { file.size, (char const*)file.data } );
|
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("\nAst generated. Time taken: %llu ms\n", time_rel_ms() - time_start);
|
||||||
|
|
||||||
log_fmt("\nSerializng ast:\n");
|
log_fmt("\nSerializng ast:\n");
|
||||||
time_start = time_rel_ms();
|
time_start = time_rel_ms();
|
||||||
|
|
||||||
Builder
|
Builder
|
||||||
builder = Builder::open( "gen/singleheader_copy.gen.hpp" );
|
builder = Builder::open( "gen/singleheader_copy.gen.hpp" );
|
||||||
builder.print( ast );
|
builder.print( ast );
|
||||||
builder.write();
|
builder.write();
|
||||||
|
|
||||||
log_fmt("Serialized. Time taken: %llu ms\n", time_rel_ms() - time_start);
|
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" );
|
FileContents file_gen = file_read_contents( GlobalAllocator, true, "gen/singleheader_copy.gen.hpp" );
|
||||||
|
|
||||||
log_fmt("\nReconstructing from generated file:\n");
|
log_fmt("\nReconstructing from generated file:\n");
|
||||||
time_start = time_rel_ms();
|
time_start = time_rel_ms();
|
||||||
CodeBody ast_gen = parse_global_body( { file_gen.size, (char const*)file_gen.data } );
|
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);
|
log_fmt("\nAst generated. Time taken: %llu ms\n\n", time_rel_ms() - time_start);
|
||||||
|
|
||||||
time_start = time_rel_ms();
|
time_start = time_rel_ms();
|
||||||
|
Loading…
Reference in New Issue
Block a user