Changes to include usage, starting to attempt singleheader automated verification

This commit is contained in:
Edward R. Gonzalez 2023-08-23 13:17:22 -04:00
parent f9117a2353
commit 30eec99628
5 changed files with 64 additions and 16 deletions

View File

@ -609,7 +609,7 @@ String AST::to_string()
break;
case Preprocess_Include:
result.append_fmt( "#include \"%S\"\n", Content );
result.append_fmt( "#include %S\n", Content );
break;
case Preprocess_ElIf:

View File

@ -68,7 +68,7 @@ CodeFn def_function( StrC name
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None );
CodeInclude def_include ( StrC content );
CodeInclude def_include ( StrC content, bool foreign = false );
CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None );
CodeNS def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );

View File

@ -56,6 +56,21 @@ namespace Parser
{
return scast(AccessSpec, Type);
}
String to_string()
{
String result = String::make_reserve( GlobalAllocator, kilobytes(4) );
StrC type_str = ETokType::to_str( Type );
result.append_fmt( "Line: %d Column: %d, Type: %.*s Content: %.*s"
, Line, Column
, type_str.Len, type_str.Ptr
, Length, Text
);
return result;
}
};
constexpr Token NullToken { nullptr, 0, TokType::Invalid, false, 0, 0 };
@ -303,6 +318,13 @@ namespace Parser
while (left )
{
#if 0
if (Tokens.num())
{
log_fmt("\nLastTok: %S", Tokens.back().to_string());
}
#endif
Token token = { scanner, 0, TokType::Invalid, line, column, false };
bool is_define = false;
@ -873,18 +895,15 @@ namespace Parser
token.Text = scanner;
token.Length = 1;
token.Type = TokType::Operator;
move_forward();
if ( left )
{
move_forward();
if ( current == '/' )
{
token.Type = TokType::Comment;
token.Length = 2;
move_forward();
token.Length++;
while ( left && current != '\n' && current != '\r' )
{
@ -909,9 +928,7 @@ namespace Parser
{
token.Type = TokType::Comment;
token.Length = 2;
move_forward();
token.Length++;
bool star = current == '*';
bool slash = scanner[1] == '/';
@ -925,11 +942,21 @@ namespace Parser
slash = scanner[1] == '/';
at_end = star && slash;
}
token.Length += 3;
Tokens.append( token );
token.Length += 2;
move_forward();
move_forward();
if ( current == '\r' )
{
move_forward();
token.Length++;
}
if ( current == '\n' )
{
move_forward();
token.Length++;
}
Tokens.append( token );
end_line();
continue;
}

View File

@ -850,7 +850,7 @@ CodeFn def_function( StrC name
return result;
}
CodeInclude def_include ( StrC path )
CodeInclude def_include( StrC path, bool foreign )
{
if ( path.Len <= 0 || path.Ptr == nullptr )
{
@ -858,10 +858,14 @@ CodeInclude def_include ( StrC path )
return CodeInvalid;
}
StrC content = foreign ?
to_str( str_fmt_buf( "<%.*s>\n", path.Len, path.Ptr ))
: to_str( str_fmt_buf( "\"%.*s\"\n", path.Len, path.Ptr ));
Code
result = make_code();
result->Type = ECode::Preprocess_Include;
result->Name = get_cached_string( path );
result->Name = get_cached_string( content );
result->Content = result->Name;
return (CodeInclude) result;

View File

@ -27,7 +27,24 @@ void check_singleheader_ast()
builder.print( ast );
builder.write();
log_fmt("passed!! Time taken: %llu ms\n", time_rel_ms() - time_start);
log_fmt("Serialized. Time taken: %llu ms\n", time_rel_ms() - time_start);
FileContents file_gen = file_read_contents( GlobalAllocator, true, "gen/singleheader_copy.gen.hpp" );
log_fmt("Reconstructing from generated file:\n");
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", time_rel_ms() - time_start);
time_start = time_rel_ms();
if ( ast.is_equal( ast_gen ) )
log_fmt( "Passed!: AST passed validation!\n" );
else
log_fmt( "Failed: AST did not pass validation\n" );
log_fmt( "Time taken: %llu ms\n", time_rel_ms() - time_start );
gen::deinit();
}