Updates to test and workspace

Added a more granular test using the original library files. Already helped me identify a bug.
This commit is contained in:
Edward R. Gonzalez 2023-11-21 20:03:51 -05:00
parent 9d27c7d37e
commit 3319bfcaa9
9 changed files with 206 additions and 16 deletions

1
.gitignore vendored
View File

@ -28,3 +28,4 @@ release/**
**/Unreal/*.cpp **/Unreal/*.cpp
! **/Unreal/validate.unreal.cpp ! **/Unreal/validate.unreal.cpp
project/auxillary/vis_ast/dependencies/temp project/auxillary/vis_ast/dependencies/temp
test/gen/original

View File

@ -36,7 +36,8 @@
"mmsystem.h": "c", "mmsystem.h": "c",
"propidl.h": "c", "propidl.h": "c",
"android_native_app_glue.h": "c", "android_native_app_glue.h": "c",
"raylib.h": "c" "raylib.h": "c",
"*.m": "cpp"
}, },
"C_Cpp.intelliSenseEngineFallback": "disabled", "C_Cpp.intelliSenseEngineFallback": "disabled",
"mesonbuild.configureOnOpen": true, "mesonbuild.configureOnOpen": true,

View File

@ -43,6 +43,7 @@
<Define>GEN_TIME</Define> <Define>GEN_TIME</Define>
<Define>GEN_SYSTEM_WINDOWS</Define> <Define>GEN_SYSTEM_WINDOWS</Define>
<Define>GEN_INTELLISENSE_DIRECTIVES</Define> <Define>GEN_INTELLISENSE_DIRECTIVES</Define>
<Define>GEN_EXECUTION_EXPRESSION_SUPPORT</Define>
</Defines> </Defines>
<ConfigProperties> <ConfigProperties>
<ConfigAndPlatform> <ConfigAndPlatform>

View File

@ -167,6 +167,10 @@ if ( $test )
$path_gen = join-path $path_test gen $path_gen = join-path $path_test gen
$path_gen_build = join-path $path_gen build $path_gen_build = join-path $path_gen build
$path_build = join-path $path_test build $path_build = join-path $path_test build
$path_original = join-path $path_gen original
$path_components = join-path $path_original components
$path_dependencies = join-path $path_original dependencies
$path_helpers = join-path $path_original helpers
if ( -not(Test-Path($path_build) )) { if ( -not(Test-Path($path_build) )) {
New-Item -ItemType Directory -Path $path_build New-Item -ItemType Directory -Path $path_build
@ -177,6 +181,18 @@ if ( $test )
if ( -not(Test-Path($path_gen_build) )) { if ( -not(Test-Path($path_gen_build) )) {
New-Item -ItemType Directory -Path $path_gen_build New-Item -ItemType Directory -Path $path_gen_build
} }
if ( -not(test-path $path_original)) {
new-item -ItemType Directory -Path $path_original
}
if ( -not(test-path $path_components)) {
new-item -ItemType Directory -Path $path_components
}
if ( -not(test-path $path_dependencies)) {
new-item -ItemType Directory -Path $path_dependencies
}
if ( -not(test-path $path_helpers)) {
new-item -ItemType Directory -Path $path_helpers
}
$path_bootstrap = join-path $path_project gen $path_bootstrap = join-path $path_project gen

View File

@ -671,11 +671,11 @@
</Expand> </Expand>
</Type> </Type>
<Type Name="gen::Parser::Token"> <Type Name="gen::parser::Token">
<DisplayString>Length:{Length} Text:{Text, [Length]s} Type:{Type}</DisplayString> <DisplayString>Length:{Length} Text:{Text, [Length]s} Type:{Type}</DisplayString>
</Type> </Type>
<Type Name="gen::Parser::TokArray"> <Type Name="gen::parser::TokArray">
<DisplayString>Current[ { Arr[Idx] } ] Idx:{ Idx }</DisplayString> <DisplayString>Current[ { Arr[Idx] } ] Idx:{ Idx }</DisplayString>
</Type> </Type>

View File

@ -1,4 +1,5 @@
#include <functional> #include <functional>
#include <tuple>
class MyClass; class MyClass;
@ -24,12 +25,20 @@ struct TemplateStruct<int, 10> {
int specialMember[10]; int specialMember[10];
}; };
typedef decltype(nullptr) (MyClass::*InsaneComplexTypeDef)( template<typename T>
decltype((MyEnum::VAL1 == MyEnum::VAL2) ? 1 : 2.0) struct AnotherTemplate {
(TemplateStruct<decltype(OuterStruct().unionInstance.inner), 5>::*ptr)[5][alignof(double)], T value;
std::function<void *(TemplateStruct<int, 10>&&, };
void (MyClass::*memFnPtr)(TemplateStruct<decltype(OuterStruct().unionInstance.inner)>))>,
typedef decltype(nullptr) (MyClass::*InsaneComplexTypeDef)
(
decltype((MyEnum::VAL1 == MyEnum::VAL2) ? 1 : 2.0)(TemplateStruct<decltype(OuterStruct().unionInstance.inner), 5>::*ptr)[5][alignof(double)],
std::function<void *(TemplateStruct<int, 10>&&, void (MyClass::*memFnPtr)(TemplateStruct<decltype(OuterStruct().unionInstance.inner)>))>,
int (MyClass::*&refToMemFnPtr)(TemplateStruct<int, 10>), int (MyClass::*&refToMemFnPtr)(TemplateStruct<int, 10>),
int (TemplateStruct<int, 10>::*memberPointer)[10], int (TemplateStruct<int, 10>::*memberPointer)[10],
char&&... typename std::tuple_element<0, std::tuple<AnotherTemplate<TemplateStruct<decltype(OuterStruct().unionInstance), 3>>>>::type::*complexMember,
) volatile const && noexcept; template<typename U> typename AnotherTemplate<U>::*templateMember
char&&...,
)
volatile const && noexcept;

View File

@ -7,6 +7,7 @@
#include "gen.builder.cpp" #include "gen.builder.cpp"
#include "sanity.cpp" #include "sanity.cpp"
#include "SOA.cpp" #include "SOA.cpp"
#include "validate.original.cpp"
#include "validate.singleheader.cpp" #include "validate.singleheader.cpp"
int gen_main() int gen_main()
@ -18,7 +19,9 @@ int gen_main()
// check_SOA(); // check_SOA();
check_singleheader_ast(); validate_original_files_ast();
validate_singleheader_ast();
return 0; return 0;
} }
#endif #endif

159
test/validate.original.cpp Normal file
View File

@ -0,0 +1,159 @@
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
#define GEN_ENFORCE_STRONG_CODE_TYPES
#define GEN_EXPOSE_BACKEND
#define GEN_BENCHMARK
#include "gen.hpp"
#include "gen.builder.hpp"
#include "gen.scanner.hpp"
using namespace gen;
#ifdef GEN_SYSTEM_WINDOWS
#include <process.h>
#endif
#define path_root "../"
#define path_project path_root "project/"
#define path_scripts path_root "scripts/"
#define path_components path_project "components/"
#define path_generated path_components "gen/"
#define path_dependencies path_project "dependencies/"
#define path_helpers path_project "helpers/"
void validate_file_ast( char const* path, char const* path_gen )
{
log_fmt( "\nValidating: %s", path );
FileContents file = file_read_contents( GlobalAllocator, true, path );
u64 time_start = time_rel_ms();
CodeBody ast = parse_global_body( { file.size, (char const*)file.data } );
log_fmt("\n\tAst generated. Time taken: %llu ms", time_rel_ms() - time_start);
log_fmt("\n\tSerializng ast:\n");
time_start = time_rel_ms();
Builder
builder = Builder::open( path_gen );
builder.print( ast );
builder.write();
log_fmt("\tSerialized. Time taken: %llu ms", time_rel_ms() - time_start);
// 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_style "-style=file:" "C:/projects/gencpp/scripts/.clang-format "
#define cf_verbose "-verbose "
String command = String::make( GlobalAllocator, clang_format );
command.append( cf_format_inplace );
command.append( cf_style );
command.append( cf_verbose );
command.append( path_gen );
log_fmt("\n\tRunning clang-format on generated file:\n");
system( command );
log_fmt("\tclang-format finished reformatting.");
#undef cf_cmd
#undef cf_format_inplace
#undef cf_style
#undef cf_verbse
FileContents file_gen = file_read_contents( GlobalAllocator, true, path_gen );
log_fmt("\n\tReconstructing from generated file:");
time_start = time_rel_ms();
CodeBody ast_gen = parse_global_body( { file_gen.size, (char const*)file_gen.data } );
log_fmt("\n\tAst generated. Time taken: %llu ms", time_rel_ms() - time_start);
time_start = time_rel_ms();
if ( ast.is_equal( ast_gen ) )
log_fmt( "\n\tPassed!: AST passed validation! " );
else
log_fmt( "\nFailed: AST did not pass validation " );
log_fmt( "Time taken: %llu ms\n", time_rel_ms() - time_start );
}
void validate_original_files_ast()
{
gen::init();
log_fmt("\nvalidate_original_files_ast:\n");
PreprocessorDefines.append( get_cached_string( txt("GEN_DEF_INLINE") ));
PreprocessorDefines.append( get_cached_string( txt("GEN_IMPL_INLINE") ));
// Helpers
{
#define validate( path ) validate_file_ast( path_helpers path, "gen/original/helpers/" path );
validate( "push_ignores.inline.hpp" );
validate( "pop_ignores.inline.hpp" );
#undef validate
}
// Dependencies
{
#define validate( path ) validate_file_ast( path_dependencies path, "gen/original/dependencies/" path )
validate( "header_start.hpp" );
validate( "macros.hpp" );
validate( "basic_types.hpp" );
validate( "debug.hpp" );
validate( "memory.hpp" );
validate( "string_ops.hpp" );
validate( "printing.hpp" );
validate( "containers.hpp" );
validate( "hashing.hpp" );
validate( "strings.hpp" );
validate( "filesystem.hpp" );
validate( "timing.hpp" );
validate( "src_start.cpp" );
validate( "debug.cpp" );
validate( "string_ops.cpp" );
validate( "printing.cpp" );
validate( "memory.cpp" );
validate( "hashing.cpp" );
validate( "strings.cpp" );
validate( "filesystem.cpp" );
validate( "timing.cpp" );
validate( "parsing.cpp" );
validate( "parisng.hpp" );
#undef validate
}
// Components
{
#define validate( path ) validate_file_ast( path_components path, "gen/original/components/" path )
validate( "header_start.hpp" );
validate( "types.hpp" );
validate( "gen/ecode.hpp" );
validate( "gen/eoperator.hpp" );
validate( "gen/especifier.hpp" );
validate( "ast.hpp" );
validate( "code_types.hpp" );
validate( "ast_types.hpp" );
validate( "interface.hpp" );
validate( "inlines.hpp" );
validate( "gen/ast_inlines.hpp" );
validate( "header_end.hpp" );
validate( "static_data.cpp" );
validate( "ast_case_macros.cpp" );
validate( "ast.cpp" );
validate( "code_serialization.cpp" );
validate( "interface.cpp" );
validate( "interface.upfront.cpp" );
validate( "gen/etoktype.cpp" );
validate( "lexer.cpp" );
validate( "parser.cpp" );
validate( "interface.parsing.cpp" );
validate( "interface.untyped.cpp" );
#undef validate
}
gen::deinit();
}
#undef path_root
#undef path_project
#undef path_scripts
#undef path_components
#undef path_generated
#undef path_dependencies

View File

@ -11,11 +11,11 @@ using namespace gen;
#include <process.h> #include <process.h>
#endif #endif
void check_singleheader_ast() void validate_singleheader_ast()
{ {
#define root_dir "../" #define root_dir "../"
gen::init(); gen::init();
log_fmt("\ncheck_singleheader_ast:\n"); log_fmt("\validate_singleheader_ast:\n");
FileContents file = file_read_contents( GlobalAllocator, true, root_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();