Fixes towards parsing (getting to line 12575 now of the singleheader.

This commit is contained in:
Edward R. Gonzalez 2023-08-02 12:39:35 -04:00
parent 4c8a0f0005
commit b96b0821c1
14 changed files with 265 additions and 51 deletions

View File

@ -456,6 +456,9 @@ String AST::to_string()
{ {
if ( Specs ) if ( Specs )
{ {
if ( Name && Name.length() )
result.append_fmt( "%.*soperator %s()", Name.length(), Name, EOperator::to_str( Op ));
else
result.append_fmt( "operator %s()", EOperator::to_str( Op ) ); result.append_fmt( "operator %s()", EOperator::to_str( Op ) );
CodeSpecifiers specs = cast<CodeSpecifiers>(); CodeSpecifiers specs = cast<CodeSpecifiers>();
@ -470,6 +473,9 @@ String AST::to_string()
break; break;
} }
if ( Name && Name.length() )
result.append_fmt("%.*soperator %s()\n{\n%s\n}", Name.length(), Name, ValueType->to_string(), Body->to_string() );
else
result.append_fmt("operator %s()\n{\n%s\n}", ValueType->to_string(), Body->to_string() ); result.append_fmt("operator %s()\n{\n%s\n}", ValueType->to_string(), Body->to_string() );
} }
break; break;

View File

@ -20,6 +20,7 @@ namespace ESpecifier
Entry( Internal_Linkage, internal ) \ Entry( Internal_Linkage, internal ) \
Entry( Local_Persist, local_persist ) \ Entry( Local_Persist, local_persist ) \
Entry( Mutable, mutable ) \ Entry( Mutable, mutable ) \
Entry( NeverInline, neverinline ) \
Entry( Ptr, * ) \ Entry( Ptr, * ) \
Entry( Ref, & ) \ Entry( Ref, & ) \
Entry( Register, register ) \ Entry( Register, register ) \
@ -56,9 +57,11 @@ namespace ESpecifier
# pragma push_macro( "global" ) # pragma push_macro( "global" )
# pragma push_macro( "internal" ) # pragma push_macro( "internal" )
# pragma push_macro( "local_persist" ) # pragma push_macro( "local_persist" )
# pragma push_macro( "neverinline" )
# undef global # undef global
# undef internal # undef internal
# undef local_persist # undef local_persist
# undef neverinline
# define Entry( Spec_, Code_ ) { sizeof(stringize(Code_)), stringize(Code_) }, # define Entry( Spec_, Code_ ) { sizeof(stringize(Code_)), stringize(Code_) },
Define_Specifiers Define_Specifiers
@ -67,6 +70,7 @@ namespace ESpecifier
# pragma pop_macro( "global" ) # pragma pop_macro( "global" )
# pragma pop_macro( "internal" ) # pragma pop_macro( "internal" )
# pragma pop_macro( "local_persist" ) # pragma pop_macro( "local_persist" )
# pragma pop_macro( "neverinline" )
}; };
return lookup[ specifier ]; return lookup[ specifier ];

View File

@ -80,6 +80,7 @@ namespace Parser
Entry( Spec_Internal_Linkage, "internal" ) \ Entry( Spec_Internal_Linkage, "internal" ) \
Entry( Spec_LocalPersist, "local_persist" ) \ Entry( Spec_LocalPersist, "local_persist" ) \
Entry( Spec_Mutable, "mutable" ) \ Entry( Spec_Mutable, "mutable" ) \
Entry( Spec_NeverInline, "neverinline" ) \
Entry( Spec_Override, "override" ) \ Entry( Spec_Override, "override" ) \
Entry( Spec_Static, "static" ) \ Entry( Spec_Static, "static" ) \
Entry( Spec_ThreadLocal, "thread_local" ) \ Entry( Spec_ThreadLocal, "thread_local" ) \

View File

@ -468,6 +468,7 @@ extern CodeSpecifiers spec_inline;
extern CodeSpecifiers spec_internal_linkage; extern CodeSpecifiers spec_internal_linkage;
extern CodeSpecifiers spec_local_persist; extern CodeSpecifiers spec_local_persist;
extern CodeSpecifiers spec_mutable; extern CodeSpecifiers spec_mutable;
extern CodeSpecifiers spec_neverinline;
extern CodeSpecifiers spec_override; extern CodeSpecifiers spec_override;
extern CodeSpecifiers spec_ptr; extern CodeSpecifiers spec_ptr;
extern CodeSpecifiers spec_ref; extern CodeSpecifiers spec_ref;

View File

@ -169,9 +169,11 @@ void define_constants()
# pragma push_macro( "global" ) # pragma push_macro( "global" )
# pragma push_macro( "internal" ) # pragma push_macro( "internal" )
# pragma push_macro( "local_persist" ) # pragma push_macro( "local_persist" )
# pragma push_macro( "neverinline" )
# undef global # undef global
# undef internal # undef internal
# undef local_persist # undef local_persist
# undef neverinline
# define def_constant_spec( Type_, ... ) \ # define def_constant_spec( Type_, ... ) \
spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \ spec_##Type_ = def_specifiers( num_args(__VA_ARGS__), __VA_ARGS__); \
@ -188,6 +190,7 @@ void define_constants()
def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage ); def_constant_spec( internal_linkage, ESpecifier::Internal_Linkage );
def_constant_spec( local_persist, ESpecifier::Local_Persist ); def_constant_spec( local_persist, ESpecifier::Local_Persist );
def_constant_spec( mutable, ESpecifier::Mutable ); def_constant_spec( mutable, ESpecifier::Mutable );
def_constant_spec( neverinline, ESpecifier::NeverInline );
def_constant_spec( override, ESpecifier::Override ); def_constant_spec( override, ESpecifier::Override );
def_constant_spec( ptr, ESpecifier::Ptr ); def_constant_spec( ptr, ESpecifier::Ptr );
def_constant_spec( ref, ESpecifier::Ref ); def_constant_spec( ref, ESpecifier::Ref );
@ -204,6 +207,7 @@ void define_constants()
# pragma pop_macro( "global" ) # pragma pop_macro( "global" )
# pragma pop_macro( "internal" ) # pragma pop_macro( "internal" )
# pragma pop_macro( "local_persist" ) # pragma pop_macro( "local_persist" )
# pragma pop_macro( "neverinline" )
# undef def_constant_spec # undef def_constant_spec
} }

View File

@ -65,7 +65,7 @@ CodeInclude def_include ( StrC content );
CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None ); CodeModule def_module ( StrC name, ModuleFlag mflags = ModuleFlag::None );
CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None ); CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags = ModuleFlag::None );
CodeOperator def_operator( OperatorT op CodeOperator def_operator( OperatorT op, StrC nspace
, CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode , CodeParam params = NoCode, CodeType ret_type = NoCode, Code body = NoCode
, CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode , CodeSpecifiers specifiers = NoCode, CodeAttributes attributes = NoCode
, ModuleFlag mflags = ModuleFlag::None ); , ModuleFlag mflags = ModuleFlag::None );

View File

@ -6,9 +6,9 @@ namespace Parser
char const* Text; char const* Text;
sptr Length; sptr Length;
TokType Type; TokType Type;
bool IsAssign;
s32 Line; s32 Line;
s32 Column; s32 Column;
bool IsAssign;
// TokFlags Flags; // TokFlags Flags;
operator bool() operator bool()
@ -133,7 +133,10 @@ namespace Parser
sptr length_from_err = dist; sptr length_from_err = dist;
String line_from_err = String::make( GlobalAllocator, { length_from_err, last_valid.Text } ); String line_from_err = String::make( GlobalAllocator, { length_from_err, last_valid.Text } );
if ( length_from_err < 100 )
result.append_fmt("\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' ); result.append_fmt("\t(%d, %d):%*c\n", last_valid.Line, last_valid.Column, length_from_err, '^' );
else
result.append_fmt("\t(%d, %d)\n", last_valid.Line, last_valid.Column );
StackNode* curr_scope = Scope; StackNode* curr_scope = Scope;
s32 level = 0; s32 level = 0;
@ -141,7 +144,7 @@ namespace Parser
{ {
if ( curr_scope->Name ) if ( curr_scope->Name )
{ {
result.append_fmt("\t%d: %s, AST Name: %s\n", level, curr_scope->ProcName.Ptr, (StrC)curr_scope->Name ); result.append_fmt("\t%d: %s, AST Name: %.*s\n", level, curr_scope->ProcName.Ptr, curr_scope->Name.Length, (StrC)curr_scope->Name );
} }
else else
{ {
@ -245,7 +248,12 @@ namespace Parser
while (left ) while (left )
{ {
Token token = { nullptr, 0, TokType::Invalid, false, line, column }; Token token = { nullptr, 0, TokType::Invalid, line, column, false };
if ( line == 4921 )
{
log_fmt("here");
}
bool is_define = false; bool is_define = false;
@ -344,7 +352,7 @@ namespace Parser
if ( token.Type == TokType::Preprocess_Define ) if ( token.Type == TokType::Preprocess_Define )
{ {
Token name = { scanner, 0, TokType::Identifier, false, line, column }; Token name = { scanner, 0, TokType::Identifier, line, column, false };
name.Text = scanner; name.Text = scanner;
name.Length = 1; name.Length = 1;
@ -356,13 +364,19 @@ namespace Parser
name.Length++; name.Length++;
} }
if ( left && current == '(' )
{
move_forward();
name.Length++;
}
Tokens.append( name ); Tokens.append( name );
u64 key = crc32( name.Text, name.Length ); u64 key = crc32( name.Text, name.Length );
defines.set( key, name ); defines.set( key, name );
} }
Token content = { scanner, 0, TokType::Preprocess_Content, false, line, column }; Token content = { scanner, 0, TokType::Preprocess_Content, line, column, false };
if ( token.Type == TokType::Preprocess_Include ) if ( token.Type == TokType::Preprocess_Include )
{ {
@ -920,7 +934,12 @@ namespace Parser
continue; continue;
} }
u64 key = crc32( token.Text, token.Length ); u64 key = 0;
if ( current == '(')
key = crc32( token.Text, token.Length + 1 );
else
key = crc32( token.Text, token.Length );
StrC* define = defines.get( key ); StrC* define = defines.get( key );
if ( define ) if ( define )
{ {
@ -1059,6 +1078,7 @@ CodeDefine parse_define()
return CodeInvalid; return CodeInvalid;
} }
Context.Scope->Name = currtok;
define->Name = get_cached_string( currtok ); define->Name = get_cached_string( currtok );
eat( TokType::Identifier ); eat( TokType::Identifier );
@ -1101,6 +1121,7 @@ CodePreprocessCond parse_preprocess_cond()
return CodeInvalid; return CodeInvalid;
} }
Context.Scope->Name = currtok;
cond->Content = get_cached_string( currtok ); cond->Content = get_cached_string( currtok );
eat( TokType::Preprocess_Content ); eat( TokType::Preprocess_Content );
@ -1125,6 +1146,8 @@ CodeInclude parse_include()
Context.pop(); Context.pop();
return CodeInvalid; return CodeInvalid;
} }
Context.Scope->Name = currtok;
include->Content = get_cached_string( currtok ); include->Content = get_cached_string( currtok );
eat( TokType::String ); eat( TokType::String );
@ -1150,6 +1173,7 @@ CodePragma parse_pragma()
return CodeInvalid; return CodeInvalid;
} }
Context.Scope->Name = currtok;
pragma->Content = get_cached_string( currtok ); pragma->Content = get_cached_string( currtok );
eat( TokType::Preprocess_Content ); eat( TokType::Preprocess_Content );
@ -1169,6 +1193,8 @@ Code parse_static_assert()
Token content = currtok; Token content = currtok;
Context.Scope->Name = content;
eat( TokType::StaticAssert ); eat( TokType::StaticAssert );
eat( TokType::Capture_Start ); eat( TokType::Capture_Start );
@ -1203,6 +1229,15 @@ Code parse_array_decl()
using namespace Parser; using namespace Parser;
push_scope(); push_scope();
if ( check( TokType::Operator ) && currtok.Text[0] == '[' && currtok.Text[1] == ']' )
{
Code array_expr = untyped_str( currtok );
eat( TokType::Operator );
Context.pop();
return array_expr;
}
if ( check( TokType::BraceSquare_Open ) ) if ( check( TokType::BraceSquare_Open ) )
{ {
eat( TokType::BraceSquare_Open ); eat( TokType::BraceSquare_Open );
@ -1333,6 +1368,7 @@ Parser::Token parse_identifier()
push_scope(); push_scope();
Token name = currtok; Token name = currtok;
Context.Scope->Name = name;
eat( TokType::Identifier ); eat( TokType::Identifier );
@ -1460,7 +1496,12 @@ CodeParam parse_params( bool use_template_capture = false )
return CodeInvalid; return CodeInvalid;
} }
Token name = { nullptr, 0, TokType::Invalid, false }; Token name = NullToken;
if ( Context.Tokens.Idx == 18546 )
{
log_fmt("here");
}
if ( check( TokType::Identifier ) ) if ( check( TokType::Identifier ) )
{ {
@ -1473,20 +1514,20 @@ CodeParam parse_params( bool use_template_capture = false )
Token value_tok = currtok; Token value_tok = currtok;
if ( currtok.Type == TokType::Statement_End ) if ( currtok.Type == TokType::Comma )
{ {
log_failure( "Expected value after assignment operator\n%s.", Context.to_string() ); log_failure( "Expected value after assignment operator\n%s.", Context.to_string() );
Context.pop(); Context.pop();
return CodeInvalid; return CodeInvalid;
} }
while ( left && currtok.Type != TokType::Statement_End ) while ( left && currtok.Type != TokType::Comma )
{ {
value_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)value_tok.Text; value_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)value_tok.Text;
eat( currtok.Type ); eat( currtok.Type );
} }
value = parse_type(); value = untyped_str( value_tok );
} }
} }
@ -1541,20 +1582,20 @@ CodeParam parse_params( bool use_template_capture = false )
Token value_tok = currtok; Token value_tok = currtok;
if ( currtok.Type == TokType::Statement_End ) if ( currtok.Type == TokType::Comma )
{ {
log_failure( "Expected value after assignment operator\n%s", Context.to_string() ); log_failure( "Expected value after assignment operator\n%s", Context.to_string() );
Context.pop(); Context.pop();
return CodeInvalid; return CodeInvalid;
} }
while ( left && currtok.Type != TokType::Statement_End ) while ( left && currtok.Type != TokType::Comma )
{ {
value_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)value_tok.Text; value_tok.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)value_tok.Text;
eat( currtok.Type ); eat( currtok.Type );
} }
value = parse_type(); value = untyped_str( value_tok );
} }
} }
@ -1599,7 +1640,7 @@ CodeFn parse_function_after_name(
, CodeAttributes attributes , CodeAttributes attributes
, CodeSpecifiers specifiers , CodeSpecifiers specifiers
, CodeType ret_type , CodeType ret_type
, StrC name , Parser::Token name
) )
{ {
using namespace Parser; using namespace Parser;
@ -1690,7 +1731,21 @@ CodeOperator parse_operator_after_ret_type(
using namespace EOperator; using namespace EOperator;
push_scope(); push_scope();
// Parse Operator Token nspace = NullToken;
if ( check( TokType::Identifier ) )
{
nspace = currtok;
while ( left && currtok.Type == TokType::Identifier )
{
eat( TokType::Identifier );
if ( currtok.Type == TokType::Access_StaticSymbol )
eat( TokType::Access_StaticSymbol );
}
nspace.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)nspace.Text;
}
eat( TokType::Decl_Operator ); eat( TokType::Decl_Operator );
if ( ! left && currtok.Type != TokType::Operator if ( ! left && currtok.Type != TokType::Operator
@ -1703,6 +1758,8 @@ CodeOperator parse_operator_after_ret_type(
return CodeInvalid; return CodeInvalid;
} }
Context.Scope->Name = currtok;
OperatorT op = Invalid; OperatorT op = Invalid;
switch ( currtok.Text[0] ) switch ( currtok.Text[0] )
{ {
@ -1942,7 +1999,7 @@ CodeOperator parse_operator_after_ret_type(
} }
// OpValidateResult check_result = operator__validate( op, params, ret_type, specifiers ); // OpValidateResult check_result = operator__validate( op, params, ret_type, specifiers );
CodeOperator result = def_operator( op, params, ret_type, body, specifiers, attributes, mflags ); CodeOperator result = def_operator( op, nspace, params, ret_type, body, specifiers, attributes, mflags );
Context.pop(); Context.pop();
return result; return result;
} }
@ -2047,11 +2104,40 @@ Code parse_simple_preprocess( Parser::TokType which )
push_scope(); push_scope();
Token tok = currtok; Token tok = currtok;
tok.Text = str_fmt_buf( "%.*s", tok.Length, tok.Text );
tok.Length++;
Code result = untyped_str( tok );
eat( which ); eat( which );
if ( currtok.Type == TokType::BraceCurly_Open )
{
// Eat the block scope right after the macro. Were assuming the macro defines a function definition's signature
eat( TokType::BraceCurly_Open );
s32 level = 0;
while ( left && ( currtok.Type != TokType::BraceCurly_Close || level > 0 ) )
{
if ( currtok.Type == TokType::BraceCurly_Open )
level++;
else if ( currtok.Type == TokType::BraceCurly_Close && level > 0 )
level--;
eat( currtok.Type );
}
eat( TokType::BraceCurly_Close );
tok.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)tok.Text;
}
Code result = untyped_str( tok );
Context.Scope->Name = tok;
if ( str_compare( Context.Scope->Prev->ProcName.Ptr, "parse_typedef", Context.Scope->Prev->ProcName.Len ) != 0 )
{
if ( check( TokType::Statement_End ))
{
eat( TokType::Statement_End );
}
}
Context.pop(); Context.pop();
return result; return result;
} }
@ -2098,6 +2184,14 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
Code result = CodeInvalid; Code result = CodeInvalid;
if ( currtok.Type == TokType::Preprocess_Macro )
{
// Were dealing with a macro after attributes/specifiers.
result = parse_simple_preprocess( TokType::Preprocess_Macro );
Context.pop();
return result;
}
CodeType type = parse_type(); CodeType type = parse_type();
if ( type == CodeInvalid ) if ( type == CodeInvalid )
@ -2106,15 +2200,38 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
return CodeInvalid; return CodeInvalid;
} }
if ( check( TokType::Decl_Operator) ) bool found_operator = false;
s32 idx = Context.Tokens.Idx;
for ( ; idx < Context.Tokens.Arr.num(); idx++ )
{
Token tok = Context.Tokens[ idx ];
if ( tok.Type == TokType::Identifier )
{
idx++;
tok = Context.Tokens[ idx ];
if ( tok.Type == TokType::Access_StaticSymbol )
continue;
break;
}
if ( tok.Type == TokType::Decl_Operator )
found_operator = true;
break;
}
if ( found_operator )
{ {
// Dealing with an operator overload // Dealing with an operator overload
result = parse_operator_after_ret_type( ModuleFlag::None, attributes, specifiers, type ); result = parse_operator_after_ret_type( ModuleFlag::None, attributes, specifiers, type );
} }
else else
{ {
StrC name = currtok; Token name = parse_identifier();
eat( TokType::Identifier ); Context.Scope->Name = name;
if ( check( TokType::Capture_Start) ) if ( check( TokType::Capture_Start) )
{ {
@ -2146,6 +2263,8 @@ Code parse_complicated_definition( Parser::TokType which )
using namespace Parser; using namespace Parser;
push_scope(); push_scope();
bool is_inplace = false;
labeled_scope_start labeled_scope_start
PARSE_FORWARD_OR_DEFINITION: PARSE_FORWARD_OR_DEFINITION:
Code result = CodeInvalid; Code result = CodeInvalid;
@ -2154,22 +2273,22 @@ Code parse_complicated_definition( Parser::TokType which )
switch ( which ) switch ( which )
{ {
case TokType::Decl_Class: case TokType::Decl_Class:
result = parse_class(); result = parse_class( is_inplace );
Context.pop(); Context.pop();
return result; return result;
case TokType::Decl_Enum: case TokType::Decl_Enum:
result = parse_enum(); result = parse_enum( is_inplace );
Context.pop(); Context.pop();
return result; return result;
case TokType::Decl_Struct: case TokType::Decl_Struct:
result = parse_struct(); result = parse_struct( is_inplace );
Context.pop(); Context.pop();
return result; return result;
case TokType::Decl_Union: case TokType::Decl_Union:
result = parse_union(); result = parse_union( is_inplace );
Context.pop(); Context.pop();
return result; return result;
@ -2220,6 +2339,7 @@ Code parse_complicated_definition( Parser::TokType which )
// Its an inplace definition // Its an inplace definition
// <which> <type_identifier> { ... } <identifier>; // <which> <type_identifier> { ... } <identifier>;
ok_to_parse = true; ok_to_parse = true;
is_inplace = true;
} }
else if ( tok.Type == TokType::Identifier && tokens[ idx - 3 ].Type == TokType::Decl_Struct ) else if ( tok.Type == TokType::Identifier && tokens[ idx - 3 ].Type == TokType::Decl_Struct )
{ {
@ -2525,7 +2645,10 @@ Code parse_class_struct( Parser::TokType which, bool inplace_def = false )
attributes = parse_attributes(); attributes = parse_attributes();
if ( check( TokType::Identifier ) ) if ( check( TokType::Identifier ) )
{
name = parse_identifier(); name = parse_identifier();
Context.Scope->Name = name;
}
local_persist local_persist
char interface_arr_mem[ kilobytes(4) ] {0}; char interface_arr_mem[ kilobytes(4) ] {0};
@ -2642,6 +2765,8 @@ CodeBody parse_global_nspace( CodeT which )
bool expects_function = false; bool expects_function = false;
Context.Scope->Start = currtok;
switch ( currtok.Type ) switch ( currtok.Type )
{ {
case TokType::Comment: case TokType::Comment:
@ -2757,6 +2882,7 @@ CodeBody parse_global_nspace( CodeT which )
case TokType::Spec_Global: case TokType::Spec_Global:
case TokType::Spec_Inline: case TokType::Spec_Inline:
case TokType::Spec_Internal_Linkage: case TokType::Spec_Internal_Linkage:
case TokType::Spec_NeverInline:
case TokType::Spec_Static: case TokType::Spec_Static:
{ {
SpecifierT specs_found[16] { ESpecifier::NumSpecifiers }; SpecifierT specs_found[16] { ESpecifier::NumSpecifiers };
@ -2766,13 +2892,18 @@ CodeBody parse_global_nspace( CodeT which )
{ {
SpecifierT spec = ESpecifier::to_type( currtok ); SpecifierT spec = ESpecifier::to_type( currtok );
bool ignore_spec = false;
switch ( spec ) switch ( spec )
{ {
case ESpecifier::Constexpr: case ESpecifier::Constexpr:
case ESpecifier::Constinit: case ESpecifier::Constinit:
case ESpecifier::Global:
case ESpecifier::External_Linkage: case ESpecifier::External_Linkage:
case ESpecifier::Internal_Linkage:
case ESpecifier::Inline: case ESpecifier::Inline:
case ESpecifier::Mutable: case ESpecifier::Mutable:
case ESpecifier::NeverInline:
case ESpecifier::Static: case ESpecifier::Static:
case ESpecifier::Volatile: case ESpecifier::Volatile:
break; break;
@ -2781,11 +2912,20 @@ CodeBody parse_global_nspace( CodeT which )
expects_function = true; expects_function = true;
break; break;
case ESpecifier::Const:
ignore_spec = true;
break;
default: default:
log_failure( "Invalid specifier %s for variable\n%s", ESpecifier::to_str(spec), Context.to_string() ); StrC spec_str = ESpecifier::to_str(spec);
log_failure( "Invalid specifier %.*s for variable\n%s", spec_str.Len, spec_str, Context.to_string() );
return CodeInvalid; return CodeInvalid;
} }
if (ignore_spec)
break;
specs_found[NumSpecifiers] = spec; specs_found[NumSpecifiers] = spec;
NumSpecifiers++; NumSpecifiers++;
eat( currtok.Type ); eat( currtok.Type );
@ -2807,6 +2947,32 @@ CodeBody parse_global_nspace( CodeT which )
case TokType::Type_double: case TokType::Type_double:
case TokType::Type_int: case TokType::Type_int:
{ {
bool found_operator_cast = false;
s32 idx = Context.Tokens.Idx;
for ( ; idx < Context.Tokens.Arr.num(); idx++ )
{
Token tok = Context.Tokens[ idx ];
if ( tok.Type == TokType::Identifier )
{
idx++;
tok = Context.Tokens[ idx ];
if ( tok.Type == TokType::Access_StaticSymbol )
continue;
break;
}
if ( tok.Type == TokType::Decl_Operator )
found_operator_cast = true;
break;
}
if ( found_operator_cast )
member = parse_operator_cast();
member = parse_operator_function_or_variable( expects_function, attributes, specifiers ); member = parse_operator_function_or_variable( expects_function, attributes, specifiers );
} }
} }
@ -2887,6 +3053,7 @@ CodeEnum parse_enum( bool inplace_def )
if ( check( TokType::Identifier ) ) if ( check( TokType::Identifier ) )
{ {
name = currtok; name = currtok;
Context.Scope->Name = currtok;
eat( TokType::Identifier ); eat( TokType::Identifier );
} }
@ -3144,6 +3311,7 @@ CodeFriend parse_friend()
{ {
// Name // Name
Token name = parse_identifier(); Token name = parse_identifier();
Context.Scope->Name = name;
// Parameter list // Parameter list
CodeParam params = parse_params(); CodeParam params = parse_params();
@ -3248,6 +3416,7 @@ CodeFn parse_functon()
} }
Token name = parse_identifier(); Token name = parse_identifier();
Context.Scope->Name = name;
if ( ! name ) if ( ! name )
{ {
Context.pop(); Context.pop();
@ -3298,6 +3467,7 @@ CodeNamespace parse_namespace()
eat( TokType::Decl_Namespace ); eat( TokType::Decl_Namespace );
Token name = parse_identifier(); Token name = parse_identifier();
Context.Scope->Name = name;
CodeBody body = parse_global_nspace( ECode::Namespace_Body ); CodeBody body = parse_global_nspace( ECode::Namespace_Body );
if ( body == Code::Invalid ) if ( body == Code::Invalid )
@ -3409,10 +3579,27 @@ CodeOpCast parse_operator_cast()
using namespace Parser; using namespace Parser;
push_scope(); push_scope();
Token name = NullToken;
if ( check( TokType::Identifier ) )
{
name = currtok;
while ( left && currtok.Type == TokType::Identifier )
{
eat( TokType::Identifier );
if ( currtok.Type == TokType::Access_StaticSymbol )
eat( TokType::Access_StaticSymbol );
}
name.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)name.Text;
}
eat( TokType::Decl_Operator ); eat( TokType::Decl_Operator );
Code type = parse_type(); Code type = parse_type();
Context.Scope->Name = { type->Name.Data, type->Name.length() };
eat( TokType::Capture_Start ); eat( TokType::Capture_Start );
eat( TokType::Capture_End ); eat( TokType::Capture_End );
@ -3443,16 +3630,22 @@ CodeOpCast parse_operator_cast()
eat( currtok.Type ); eat( currtok.Type );
} }
eat( TokType::BraceCurly_Close );
body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text; body_str.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)body_str.Text;
body = untyped_str( body_str ); body = untyped_str( body_str );
}
eat( TokType::BraceCurly_Close ); else
{
eat( TokType::Statement_End );
} }
CodeOpCast result = (CodeOpCast) make_code(); CodeOpCast result = (CodeOpCast) make_code();
if ( name )
result->Name = get_cached_string( name );
if (body) if (body)
{ {
result->Type = ECode::Operator_Cast; result->Type = ECode::Operator_Cast;
@ -3691,6 +3884,7 @@ CodeType parse_type()
name.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)name.Text; name.Length = ( (sptr)currtok.Text + currtok.Length ) - (sptr)name.Text;
eat( TokType::Identifier ); eat( TokType::Identifier );
Context.Scope->Name = name;
} }
else if ( currtok.Type >= TokType::Type_Unsigned && currtok.Type <= TokType::Type_MS_W64 ) else if ( currtok.Type >= TokType::Type_Unsigned && currtok.Type <= TokType::Type_MS_W64 )
{ {
@ -3703,10 +3897,12 @@ CodeType parse_type()
} }
name.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)name.Text; name.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)name.Text;
Context.Scope->Name = name;
} }
else else
{ {
name = parse_identifier(); name = parse_identifier();
Context.Scope->Name = name;
if ( ! name ) if ( ! name )
{ {
log_failure( "Error, failed to type signature\n%s", Context.to_string() ); log_failure( "Error, failed to type signature\n%s", Context.to_string() );
@ -3851,13 +4047,11 @@ CodeTypedef parse_typedef()
constexpr bool from_typedef = true; constexpr bool from_typedef = true;
// TODO : Confirm if this should stay... (Macro abuse, kept because used by zpl library code...)
// TODO : I could refactor the library code to not use this, and just ban it from usage
// TODO : (as I already do for all macros that are not at entries in a body ast...)
if ( check( TokType::Preprocess_Macro )) if ( check( TokType::Preprocess_Macro ))
{ {
type = t_empty; type = t_empty;
name = currtok; name = currtok;
Context.Scope->Name = name;
eat( TokType::Preprocess_Macro ); eat( TokType::Preprocess_Macro );
} }
else else
@ -3947,6 +4141,7 @@ CodeUnion parse_union( bool inplace_def )
if ( check( TokType::Identifier ) ) if ( check( TokType::Identifier ) )
{ {
name = currtok; name = currtok;
Context.Scope->Name = currtok;
eat( TokType::Identifier ); eat( TokType::Identifier );
} }
@ -4094,6 +4289,7 @@ CodeUsing parse_using()
} }
name = currtok; name = currtok;
Context.Scope->Name = name;
eat( TokType::Identifier ); eat( TokType::Identifier );
if ( currtok.IsAssign ) if ( currtok.IsAssign )
@ -4216,8 +4412,7 @@ CodeVar parse_variable()
if ( type == Code::Invalid ) if ( type == Code::Invalid )
return CodeInvalid; return CodeInvalid;
Context.Scope->Name = currtok; Context.Scope->Name = parse_identifier();
eat( TokType::Identifier );
CodeVar result = parse_variable_after_name( mflags, attributes, specifiers, type, Context.Scope->Name ); CodeVar result = parse_variable_after_name( mflags, attributes, specifiers, type, Context.Scope->Name );

View File

@ -783,7 +783,7 @@ CodeNamespace def_namespace( StrC name, Code body, ModuleFlag mflags )
return result; return result;
} }
CodeOperator def_operator( OperatorT op CodeOperator def_operator( OperatorT op, StrC nspace
, CodeParam params_code, CodeType ret_type, Code body , CodeParam params_code, CodeType ret_type, Code body
, CodeSpecifiers specifiers, CodeAttributes attributes , CodeSpecifiers specifiers, CodeAttributes attributes
, ModuleFlag mflags ) , ModuleFlag mflags )
@ -809,7 +809,7 @@ CodeOperator def_operator( OperatorT op
return CodeInvalid; return CodeInvalid;
} }
char const* name = str_fmt_buf( "operator %s", to_str(op) ); char const* name = str_fmt_buf( "%.*soperator %s", nspace.Len, nspace.Ptr, to_str(op) );
CodeOperator CodeOperator
result = (CodeOperator) make_code(); result = (CodeOperator) make_code();

View File

@ -50,6 +50,7 @@ global CodeSpecifiers spec_inline;
global CodeSpecifiers spec_internal_linkage; global CodeSpecifiers spec_internal_linkage;
global CodeSpecifiers spec_local_persist; global CodeSpecifiers spec_local_persist;
global CodeSpecifiers spec_mutable; global CodeSpecifiers spec_mutable;
global CodeSpecifiers spec_neverinline;
global CodeSpecifiers spec_override; global CodeSpecifiers spec_override;
global CodeSpecifiers spec_ptr; global CodeSpecifiers spec_ptr;
global CodeSpecifiers spec_ref; global CodeSpecifiers spec_ref;

View File

@ -224,7 +224,7 @@ internal GEN_FILE_CLOSE_PROC( _posix_file_close )
FileOperations const default_file_operations = { _posix_file_read, _posix_file_write, _posix_file_seek, _posix_file_close }; FileOperations const default_file_operations = { _posix_file_read, _posix_file_write, _posix_file_seek, _posix_file_close };
GEN_NEVER_INLINE GEN_FILE_OPEN_PROC( _posix_file_open ) neverinline GEN_FILE_OPEN_PROC( _posix_file_open )
{ {
s32 os_mode; s32 os_mode;
switch ( mode & GEN_FILE_MODES ) switch ( mode & GEN_FILE_MODES )

View File

@ -9,6 +9,7 @@ Inline, inline
Internal_Linkage, internal Internal_Linkage, internal
Local_Persist, local_persist Local_Persist, local_persist
Mutable, mutable Mutable, mutable
NeverInline, neverinline
Ptr, * Ptr, *
Ref, & Ref, &
Register, register Register, register

1 Invalid INVALID
9 Internal_Linkage internal
10 Local_Persist local_persist
11 Mutable mutable
12 NeverInline neverinline
13 Ptr *
14 Ref &
15 Register register

View File

@ -61,6 +61,7 @@ Spec_Inline, "inline"
Spec_Internal_Linkage, "internal" Spec_Internal_Linkage, "internal"
Spec_LocalPersist, "local_persist" Spec_LocalPersist, "local_persist"
Spec_Mutable, "mutable" Spec_Mutable, "mutable"
Spec_NeverInline, "neverinline"
Spec_Override, "override" Spec_Override, "override"
Spec_Static, "static" Spec_Static, "static"
Spec_ThreadLocal, "thread_local" Spec_ThreadLocal, "thread_local"

1 Invalid __invalid__
61 Spec_Internal_Linkage internal
62 Spec_LocalPersist local_persist
63 Spec_Mutable mutable
64 Spec_NeverInline neverinline
65 Spec_Override override
66 Spec_Static static
67 Spec_ThreadLocal thread_local

View File

@ -36,8 +36,8 @@ AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true BinPackArguments: false
BinPackParameters: true BinPackParameters: false
BitFieldColonSpacing: Both BitFieldColonSpacing: Both
@ -94,13 +94,13 @@ IncludeBlocks: Preserve
IndentCaseBlocks: false IndentCaseBlocks: false
IndentCaseLabels: false IndentCaseLabels: true
IndentExternBlock: AfterExternBlock IndentExternBlock: AfterExternBlock
IndentGotoLabels: true IndentGotoLabels: true
IndentPPDirectives: AfterHash IndentPPDirectives: AfterHash
IndentRequires: true IndentRequires: true
IndentWidth: 4 IndentWidth: 4
IndentWrappedFunctionNames: false IndentWrappedFunctionNames: true
# InsertNewlineAtEOF: true # InsertNewlineAtEOF: true
# InsertTrailingCommas: Wrapped # InsertTrailingCommas: Wrapped

View File

@ -20,12 +20,12 @@ void check_singleheader_ast()
log_fmt("generated AST!!!\n"); log_fmt("generated AST!!!\n");
// s32 idx = 0; s32 idx = 0;
// for ( Code entry : ast ) for ( Code entry : ast )
// { {
// log_fmt("Entry %d: %s", idx, entry.to_string() ); log_fmt("Entry %d: %s\n", idx, entry.to_string() );
// idx++; idx++;
// } }
Builder builder; Builder builder;
builder.open( "singleheader_copy.gen.hpp" ); builder.open( "singleheader_copy.gen.hpp" );