Fixes to parsing marco content, progress on validation test (single-header)

This commit is contained in:
Edward R. Gonzalez 2023-08-23 21:19:31 -04:00
parent a6766cf0b1
commit 9edcbad907
4 changed files with 49 additions and 58 deletions

View File

@ -4,6 +4,36 @@
Code Code::Global; Code Code::Global;
Code Code::Invalid; Code Code::Invalid;
char const* AST::debug_str()
{
if ( Parent )
{
String
result = String::make_reserve( GlobalAllocator, kilobytes(1) );
result.append_fmt(
"\nType : %s"
"\nParent : %s %s"
"\nName : %s"
, type_str()
, Parent->type_str()
, Parent->Name, Name ? Name : ""
);
return result;
}
String
result = String::make_reserve( GlobalAllocator, kilobytes(1) );
result.append_fmt(
"\nType : %s"
"\nName : %s"
, type_str()
, Name ? Name : ""
);
return result;
}
AST* AST::duplicate() AST* AST::duplicate()
{ {
using namespace ECode; using namespace ECode;
@ -952,10 +982,9 @@ bool AST::is_equal( AST* other )
#define check_member_val( val ) \ #define check_member_val( val ) \
if ( val != other->val ) \ if ( val != other->val ) \
{ \ { \
log_fmt("AST::is_equal: Member - " #val "\n failed" \ log_fmt("AST::is_equal: Member - " #val " failed\n" \
"AST : %S\n" \ "AST : %S\n" \
"Other: %S\n" \ "Other: %S\n" \
"For val member: " #val \
, debug_str() \ , debug_str() \
, other->debug_str() \ , other->debug_str() \
); \ ); \
@ -963,18 +992,17 @@ bool AST::is_equal( AST* other )
return false; \ return false; \
} }
#define check_member_str( str ) \ #define check_member_str( str ) \
if ( str != other->str ) \ if ( str != other->str ) \
{ \ { \
log_fmt("AST::is_equal: Member string check failure with other\n" \ log_fmt("AST::is_equal: Member string - "#str " failed\n" \
"AST : %S\n" \ "AST : %S\n" \
"Other: %S\n" \ "Other: %S\n" \
"For str member: " #str \ , debug_str() \
, debug_str() \ , other->debug_str() \
, other->debug_str() \ ); \
); \ \
\ return false; \
return false; \
} }
#define check_member_ast( ast ) \ #define check_member_ast( ast ) \
@ -983,9 +1011,9 @@ bool AST::is_equal( AST* other )
if ( other->ast == nullptr ) \ if ( other->ast == nullptr ) \
{ \ { \
log_fmt("AST::is_equal: Failed for member " #ast " other equivalent param is null\n" \ log_fmt("AST::is_equal: Failed for member " #ast " other equivalent param is null\n" \
"AST : %S\n" \ "AST : %s\n" \
"Other: %S\n" \ "Other: %s\n" \
"For ast member: %S\n" \ "For ast member: %s\n" \
, debug_str() \ , debug_str() \
, other->debug_str() \ , other->debug_str() \
, ast->debug_str() \ , ast->debug_str() \
@ -1000,7 +1028,7 @@ bool AST::is_equal( AST* other )
"AST : %S\n" \ "AST : %S\n" \
"Other: %S\n" \ "Other: %S\n" \
"For ast member: %S\n" \ "For ast member: %S\n" \
"other's ast member: %S\n" \ "other ast member: %S\n" \
, debug_str() \ , debug_str() \
, other->debug_str() \ , other->debug_str() \
, ast->debug_str() \ , ast->debug_str() \

View File

@ -25,43 +25,6 @@ void AST::append( AST* other )
NumEntries++; NumEntries++;
} }
char const* AST::debug_str()
{
if ( Parent )
{
char const* fmt = stringize(
\nType : %s
\nParent : %s %s
\nName : %s
);
// These should be used immediately in a log.
// Thus if its desired to keep the debug str
// for multiple calls to bprintf,
// allocate this to proper string.
return str_fmt_buf( fmt
, type_str()
, Parent->Name
, Parent->type_str()
, Name ? Name : ""
);
}
char const* fmt = stringize(
\nType : %s
\nName : %s
);
// These should be used immediately in a log.
// Thus if its desired to keep the debug str
// for multiple calls to bprintf,
// allocate this to proper string.
return str_fmt_buf( fmt
, type_str()
, Name ? Name : ""
);
}
Code& AST::entry( u32 idx ) Code& AST::entry( u32 idx )
{ {
AST** current = & Front; AST** current = & Front;

View File

@ -523,10 +523,10 @@ namespace Parser
s32 within_char = false; s32 within_char = false;
while ( left ) while ( left )
{ {
if ( current == '"' ) if ( current == '"' && ! within_char )
within_string ^= true; within_string ^= true;
if ( current == '\'' ) if ( current == '\'' && ! within_string )
within_char ^= true; within_char ^= true;
if ( current == '\\' && ! within_string && ! within_char ) if ( current == '\\' && ! within_string && ! within_char )

View File

@ -35,7 +35,7 @@ void check_singleheader_ast()
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", 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();