wip having nasty parser issue (fixed nasty lexer bug)

This commit is contained in:
2024-12-04 15:00:37 -05:00
parent f7709bb64e
commit cae1555b11
11 changed files with 94 additions and 31 deletions

View File

@ -159,16 +159,16 @@ extern CodeTypename t_typename;
// Used by the lexer to persistently treat all these identifiers as preprocessor defines.
// Populate with strings via gen::get_cached_string.
// Functional defines must have format: id( ;at minimum to indicate that the define is only valid with arguments.
extern Array< StringCached > PreprocessorDefines;
extern Array(StringCached) PreprocessorDefines;
#ifdef GEN_EXPOSE_BACKEND
// Global allocator used for data with process lifetime.
extern AllocatorInfo GlobalAllocator;
extern Array< Arena > Global_AllocatorBuckets;
extern Array(Arena) Global_AllocatorBuckets;
extern Array< Pool > CodePools;
extern Array< Arena > StringArenas;
extern Array(Pool) CodePools;
extern Array(Arena) StringArenas;
extern StringTable StringCache;

View File

@ -578,16 +578,16 @@ TokArray lex( StrC content )
return { {}, 0 };
}
for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); array_next(PreprocessorDefines, entry))
for ( StringCached* entry = array_begin(PreprocessorDefines); entry != array_end(PreprocessorDefines); entry = array_next(PreprocessorDefines, entry))
{
s32 length = 0;
char const* scanner = * entry;
while ( entry->Len > length && (char_is_alphanumeric( *scanner ) || *scanner == '_') )
char const* entry_scanner = * entry;
while ( entry->Len > length && (char_is_alphanumeric( *entry_scanner ) || *entry_scanner == '_') )
{
c.scanner++;
entry_scanner++;
length ++;
}
if ( c.scanner[0] == '(' )
if ( entry_scanner[0] == '(' )
{
length++;
}

View File

@ -3859,8 +3859,47 @@ CodeFriend parse_friend()
eat( Tok_Decl_Friend );
// friend
CodeFn function = { nullptr };
CodeOperator op = { nullptr };
CodeFn function = { nullptr };
CodeOperator op = { nullptr };
CodeSpecifiers specifiers = { nullptr };
// Specifiers Parsing
{
Specifier specs_found[ 16 ] { Spec_NumSpecifiers };
s32 NumSpecifiers = 0;
while ( left && is_specifier(currtok) )
{
Specifier spec = to_specifier( to_str(currtok) );
switch ( spec )
{
case Spec_Const :
case Spec_Inline :
case Spec_ForceInline :
break;
default :
log_failure( "Invalid specifier %s for friend definition\n%s", to_str( spec ), to_string(Context) );
pop(& Context);
return InvalidCode;
}
// Ignore const it will be handled by the type
if ( spec == Spec_Const )
break;
specs_found[ NumSpecifiers ] = spec;
NumSpecifiers++;
eat( currtok.Type );
}
if ( NumSpecifiers )
{
specifiers = def_specifiers( NumSpecifiers, specs_found );
}
// <friend> <specifiers>
}
// Type declaration or return type
CodeTypename type = parse_type();
@ -3879,7 +3918,7 @@ CodeFriend parse_friend()
Context.Scope->Name = name;
// friend <ReturnType> <Name>
function = parse_function_after_name( ModuleFlag_None, NullCode, NullCode, type, name );
function = parse_function_after_name( ModuleFlag_None, NullCode, specifiers, type, name );
// Parameter list
// CodeParam params = parse_params();
@ -3897,7 +3936,7 @@ CodeFriend parse_friend()
// Operator declaration or definition
if ( currtok.Type == Tok_Decl_Operator )
{
op = parse_operator_after_ret_type( ModuleFlag_None, NullCode, NullCode, type );
op = parse_operator_after_ret_type( ModuleFlag_None, NullCode, specifiers, type );
}
CodeComment inline_cmt = NullCode;

View File

@ -82,7 +82,7 @@ global CodeTypename t_wchar_t;
global CodeTypename t_class;
global CodeTypename t_typename;
global Array< StringCached > PreprocessorDefines;
global Array(StringCached) PreprocessorDefines;
#ifdef GEN_DEFINE_LIBRARY_CODE_CONSTANTS
global CodeTypename t_b32;