More fixes from clang warnings. Parser::lex prep for changes

parse_static_assert now properly adds new-line to end of statement.

I'm going to end up making a static_assert ast... that or when the statement ast is made it will handle adding that newline.
This commit is contained in:
Edward R. Gonzalez 2023-09-07 22:51:15 -04:00
parent 0a8d3bfc6a
commit 6ea40094ee
6 changed files with 93 additions and 42 deletions

View File

@ -87,5 +87,3 @@ Each internal procedure will be
## parse_type ## parse_type
This is the worst part of the parser. Because other than actual expression values in C++, typenames are the second worst thing to parse in the langauge.

View File

@ -28,8 +28,7 @@ void Builder::pad_lines( s32 num )
void Builder::print( Code code ) void Builder::print( Code code )
{ {
String str = code->to_string(); String str = code->to_string();
const sw len = str.length(); // const sw len = str.length();
// log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data ); // log_fmt( "%s - print: %.*s\n", File.filename, len > 80 ? 80 : len, str.Data );
Buffer.append( str ); Buffer.append( str );
} }

View File

@ -92,7 +92,7 @@ Code scan_file( char const* path )
if ( left && current == '\n' ) if ( left && current == '\n' )
move_fwd(); move_fwd();
sptr skip_size = fsize - left; // sptr skip_size = fsize - left;
if ( (scanner + 2) >= ( str.Data + fsize ) ) if ( (scanner + 2) >= ( str.Data + fsize ) )
{ {
mem_move( str, scanner, left ); mem_move( str, scanner, left );

View File

@ -82,7 +82,7 @@ struct Code
static Code Invalid; static Code Invalid;
# pragma endregion Statics # pragma endregion Statics
#define Using_Code( Typename ) \ # define Using_Code( Typename ) \
char const* debug_str(); \ char const* debug_str(); \
Code duplicate(); \ Code duplicate(); \
bool is_equal( Code other ); \ bool is_equal( Code other ); \

View File

@ -224,8 +224,8 @@ namespace Parser
return false; return false;
} }
if ( Arr[ Idx ].Type == TokType::NewLine && type != TokType::NewLine if ( ( Arr[ Idx ].Type == TokType::NewLine && type != TokType::NewLine )
|| Arr[ Idx ].Type == TokType::Comment && type != TokType::Comment ) || ( Arr[ Idx ].Type == TokType::Comment && type != TokType::Comment ) )
{ {
Idx++; Idx++;
} }
@ -284,7 +284,7 @@ namespace Parser
move_forward(); \ move_forward(); \
} }
#define end_line() \ # define end_line() \
do \ do \
{ \ { \
while ( left && current == ' ' ) \ while ( left && current == ' ' ) \
@ -319,13 +319,8 @@ namespace Parser
return { { nullptr }, 0 }; return { { nullptr }, 0 };
} }
local_persist char defines_map_mem[ kilobytes(64) ]; local_persist Arena_64KB defines_map_arena = Arena_64KB::init();
local_persist Arena defines_map_arena; HashTable<StrC> defines = HashTable<StrC>::init( defines_map_arena );
HashTable<StrC> defines;
{
defines_map_arena = Arena::init_from_memory( defines_map_mem, sizeof(defines_map_mem) );
defines = HashTable<StrC>::init( defines_map_arena );
}
Tokens.clear(); Tokens.clear();
@ -583,6 +578,7 @@ namespace Parser
continue; // Skip found token, its all handled here. continue; // Skip found token, its all handled here.
} }
case '.': case '.':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Access_MemberSymbol; token.Type = TokType::Access_MemberSymbol;
@ -609,8 +605,9 @@ namespace Parser
} }
goto FoundToken; goto FoundToken;
}
case '&' : case '&' :
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Ampersand; token.Type = TokType::Ampersand;
@ -628,11 +625,14 @@ namespace Parser
} }
goto FoundToken; goto FoundToken;
}
case ':': case ':':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Assign_Classifer; token.Type = TokType::Assign_Classifer;
// Can be either a classifier (ParentType, Bitfield width), or ternary else
// token.Type = TokType::Colon;
if (left) if (left)
move_forward(); move_forward();
@ -644,8 +644,9 @@ namespace Parser
token.Length++; token.Length++;
} }
goto FoundToken; goto FoundToken;
}
case '{': case '{':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::BraceCurly_Open; token.Type = TokType::BraceCurly_Open;
@ -653,8 +654,9 @@ namespace Parser
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
case '}': case '}':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::BraceCurly_Close; token.Type = TokType::BraceCurly_Close;
@ -664,8 +666,9 @@ namespace Parser
end_line(); end_line();
goto FoundToken; goto FoundToken;
}
case '[': case '[':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::BraceSquare_Open; token.Type = TokType::BraceSquare_Open;
@ -681,8 +684,9 @@ namespace Parser
} }
} }
goto FoundToken; goto FoundToken;
}
case ']': case ']':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::BraceSquare_Close; token.Type = TokType::BraceSquare_Close;
@ -690,8 +694,9 @@ namespace Parser
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
case '(': case '(':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Capture_Start; token.Type = TokType::Capture_Start;
@ -699,8 +704,9 @@ namespace Parser
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
case ')': case ')':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Capture_End; token.Type = TokType::Capture_End;
@ -708,8 +714,9 @@ namespace Parser
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
case '\'': case '\'':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Char; token.Type = TokType::Char;
@ -740,8 +747,9 @@ namespace Parser
token.Length++; token.Length++;
} }
goto FoundToken; goto FoundToken;
}
case ',': case ',':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Comma; token.Type = TokType::Comma;
@ -749,8 +757,9 @@ namespace Parser
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
case '*': case '*':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Star; token.Type = TokType::Star;
@ -758,8 +767,9 @@ namespace Parser
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
case ';': case ';':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Statement_End; token.Type = TokType::Statement_End;
@ -769,8 +779,9 @@ namespace Parser
end_line(); end_line();
goto FoundToken; goto FoundToken;
}
case '"': case '"':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::String; token.Type = TokType::String;
@ -801,24 +812,28 @@ namespace Parser
token.Length++; token.Length++;
} }
goto FoundToken; goto FoundToken;
}
case '?': case '?':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Operator; token.Type = TokType::Operator;
// token.Type = TokType::Ternary;
token.IsAssign = false; token.IsAssign = false;
if (left) if (left)
move_forward(); move_forward();
goto FoundToken; goto FoundToken;
}
// All other operators we just label as an operator and move forward.
case '=': case '=':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Operator; token.Type = TokType::Operator;
// token.Type = TokType::Assign;
token.IsAssign = true; token.IsAssign = true;
// token.Flags |= TokFlags::Assignment;
if (left) if (left)
move_forward(); move_forward();
@ -833,18 +848,46 @@ namespace Parser
} }
goto FoundToken; goto FoundToken;
}
case '+': case '+':
{
// token.Type = TokType::Add
}
case '%': case '%':
{
// token.Type = TokType::Modulo;
}
case '^': case '^':
{
// token.Type = TokType::B_XOr;
}
case '~': case '~':
{
// token.Type = TokType::Unary_Not;
}
case '!': case '!':
{
// token.Type = TokType::L_Not;
}
case '<': case '<':
{
// token.Type = TokType::Lesser;
}
case '>': case '>':
{
// token.Type = TokType::Greater;
}
case '|': case '|':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Operator; token.Type = TokType::Operator;
// token.Type = TokType::L_Or;
if (left) if (left)
move_forward(); move_forward();
@ -853,6 +896,8 @@ namespace Parser
{ {
token.Length++; token.Length++;
token.IsAssign = true; token.IsAssign = true;
// token.Flags |= TokFlags::Assignment;
// token.Type = TokType::Assign_L_Or;
if (left) if (left)
move_forward(); move_forward();
@ -865,12 +910,15 @@ namespace Parser
move_forward(); move_forward();
} }
goto FoundToken; goto FoundToken;
}
// Dash is unfortunatlly a bit more complicated... // Dash is unfortunatlly a bit more complicated...
case '-': case '-':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Operator; token.Type = TokType::Operator;
// token.Type = TokType::Subtract;
if ( left ) if ( left )
{ {
move_forward(); move_forward();
@ -890,6 +938,8 @@ namespace Parser
{ {
token.Length++; token.Length++;
token.IsAssign = true; token.IsAssign = true;
// token.Flags |= TokFlags::Assignment;
// token.Type = TokType::Assign_Subtract;
if (left) if (left)
move_forward(); move_forward();
@ -903,11 +953,13 @@ namespace Parser
} }
} }
goto FoundToken; goto FoundToken;
}
case '/': case '/':
{
token.Text = scanner; token.Text = scanner;
token.Length = 1; token.Length = 1;
token.Type = TokType::Operator; token.Type = TokType::Operator;
// token.Type = TokType::Divide;
move_forward(); move_forward();
if ( left ) if ( left )
@ -970,12 +1022,13 @@ namespace Parser
token.Length++; token.Length++;
} }
Tokens.append( token ); Tokens.append( token );
end_line(); // end_line();
continue; continue;
} }
} }
goto FoundToken; goto FoundToken;
} }
}
if ( char_is_alpha( current ) || current == '_' ) if ( char_is_alpha( current ) || current == '_' )
{ {
@ -1148,7 +1201,7 @@ namespace Parser
} }
defines.clear(); defines.clear();
defines_map_arena.free(); // defines_map_arena.free();
return { Tokens, 0 }; return { Tokens, 0 };
# undef current # undef current
# undef move_forward # undef move_forward
@ -1199,7 +1252,7 @@ if ( def.Ptr == nullptr ) \
# define check( Type_ ) ( left && currtok.Type == Type_ ) # define check( Type_ ) ( left && currtok.Type == Type_ )
# define push_scope() \ # define push_scope() \
StackNode scope { nullptr, currtok, NullToken, txt( __func__ ) }; \ StackNode scope { nullptr, currtok_noskip, NullToken, txt( __func__ ) }; \
Context.push( & scope ) Context.push( & scope )
#pragma endregion Helper Macros #pragma endregion Helper Macros
@ -1258,7 +1311,6 @@ constexpr bool strip_formatting_dont_preserve_newlines = false;
It has edge case failures that prevent it from being used in function bodies. It has edge case failures that prevent it from being used in function bodies.
*/ */
String strip_formatting( StrC raw_text, bool preserve_newlines = true ) String strip_formatting( StrC raw_text, bool preserve_newlines = true )
//, bool for_preprocess_define = false )
{ {
String content = String::make_reserve( GlobalAllocator, raw_text.Len ); String content = String::make_reserve( GlobalAllocator, raw_text.Len );
@ -2261,7 +2313,7 @@ CodeFn parse_function_after_name(
Token stmt_end = currtok; Token stmt_end = currtok;
eat( TokType::Statement_End ); eat( TokType::Statement_End );
if ( currtok_noskip.Type && TokType::Comment && currtok_noskip.Line == stmt_end.Line ) if ( currtok_noskip.Type == TokType::Comment && currtok_noskip.Line == stmt_end.Line )
inline_cmt = parse_comment(); inline_cmt = parse_comment();
} }
@ -3417,7 +3469,9 @@ Code parse_static_assert()
eat( TokType::Statement_End ); eat( TokType::Statement_End );
content.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)content.Text; content.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)content.Text;
assert->Content = get_cached_string( content );
char const* str = str_fmt_buf( "%.*s\n", content.Length, content.Text );
assert->Content = get_cached_string( { content.Length + 1, str } );
assert->Name = assert->Content; assert->Name = assert->Content;
Context.pop(); Context.pop();

View File

@ -485,7 +485,7 @@ struct FixedArena
static static
FixedArena init() FixedArena init()
{ {
FixedArena result = { Arena::init_from_memory( result.memory, Size ), 0 }; FixedArena result = { Arena::init_from_memory( result.memory, Size ), {0} };
return result; return result;
} }