Fixes to gencpp

This commit is contained in:
Edward R. Gonzalez 2024-10-24 20:27:52 -04:00
parent 001a542521
commit 60a4128df4
2 changed files with 104 additions and 18 deletions

View File

@ -24,7 +24,6 @@
#include "gen.hpp" #include "gen.hpp"
GEN_NS_BEGIN GEN_NS_BEGIN
#pragma region StaticData #pragma region StaticData
// TODO : Convert global allocation strategy to use a slab allocation strategy. // TODO : Convert global allocation strategy to use a slab allocation strategy.
@ -2728,12 +2727,20 @@ void CodeVar::to_string( String& result )
} }
if ( ast->Value ) if ( ast->Value )
{
if ( ast->VarConstructorInit )
result.append_fmt( "( %S ", ast->Value.to_string() );
else
result.append_fmt( " = %S", ast->Value.to_string() ); result.append_fmt( " = %S", ast->Value.to_string() );
}
// Keep the chain going... // Keep the chain going...
if ( ast->NextVar ) if ( ast->NextVar )
result.append_fmt( ", %S", ast->NextVar.to_string() ); result.append_fmt( ", %S", ast->NextVar.to_string() );
if ( ast->VarConstructorInit )
result.append( " )");
return; return;
} }
@ -2766,11 +2773,19 @@ void CodeVar::to_string( String& result )
result.append_fmt( " : %S", ast->BitfieldSize.to_string() ); result.append_fmt( " : %S", ast->BitfieldSize.to_string() );
if ( ast->Value ) if ( ast->Value )
{
if ( ast->VarConstructorInit )
result.append_fmt( "( %S", ast->Value.to_string() );
else
result.append_fmt( " = %S", ast->Value.to_string() ); result.append_fmt( " = %S", ast->Value.to_string() );
}
if ( ast->NextVar ) if ( ast->NextVar )
result.append_fmt( ", %S", ast->NextVar.to_string() ); result.append_fmt( ", %S", ast->NextVar.to_string() );
if ( ast->VarConstructorInit )
result.append( " )" );
if ( ast->InlineCmt ) if ( ast->InlineCmt )
result.append_fmt( "; %S", ast->InlineCmt->Content ); result.append_fmt( "; %S", ast->InlineCmt->Content );
else else
@ -2798,11 +2813,19 @@ void CodeVar::to_string( String& result )
result.append_fmt( "%S %S", ast->ValueType.to_string(), ast->Name ); result.append_fmt( "%S %S", ast->ValueType.to_string(), ast->Name );
if ( ast->Value ) if ( ast->Value )
{
if ( ast->VarConstructorInit )
result.append_fmt( "( %S ", ast->Value.to_string() );
else
result.append_fmt( " = %S", ast->Value.to_string() ); result.append_fmt( " = %S", ast->Value.to_string() );
}
if ( ast->NextVar ) if ( ast->NextVar )
result.append_fmt( ", %S", ast->NextVar.to_string() ); result.append_fmt( ", %S", ast->NextVar.to_string() );
if ( ast->VarConstructorInit )
result.append(")");
result.append( ";" ); result.append( ";" );
if ( ast->InlineCmt ) if ( ast->InlineCmt )
@ -2993,16 +3016,17 @@ internal void define_constants()
spec_##Type_ = def_specifiers( num_args( __VA_ARGS__ ), __VA_ARGS__ ); \ spec_##Type_ = def_specifiers( num_args( __VA_ARGS__ ), __VA_ARGS__ ); \
spec_##Type_.set_global(); spec_##Type_.set_global();
#pragma push_macro( "FORCEINLINE" ) #pragma push_macro("FORCEINLINE")
#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" ) #pragma push_macro("neverinline")
#undef FORCEINLINE #undef FORCEINLINE
#undef global #undef global
#undef internal #undef internal
#undef local_persist #undef local_persist
#undef neverinline #undef neverinline
def_constant_spec( const, ESpecifier::Const ); def_constant_spec( const, ESpecifier::Const );
def_constant_spec( consteval, ESpecifier::Consteval ); def_constant_spec( consteval, ESpecifier::Consteval );
def_constant_spec( constexpr, ESpecifier::Constexpr ); def_constant_spec( constexpr, ESpecifier::Constexpr );
@ -3030,11 +3054,11 @@ internal void define_constants()
spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist ); spec_local_persist = def_specifiers( 1, ESpecifier::Local_Persist );
spec_local_persist.set_global(); spec_local_persist.set_global();
#pragma pop_macro( "FORCEINLINE" ) #pragma pop_macro("FORCEINLINE")
#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" ) #pragma pop_macro("neverinline")
#undef def_constant_spec #undef def_constant_spec
} }
@ -7096,6 +7120,26 @@ namespace parser
move_forward(); move_forward();
token.Length++; token.Length++;
} }
// Handle number literal suffixes in a botched way
if (left && (
current == 'l' || current == 'L' || // long/long long
current == 'u' || current == 'U' || // unsigned
current == 'f' || current == 'F' || // float
current == 'i' || current == 'I' || // imaginary
current == 'z' || current == 'Z')) // complex
{
char prev = current;
move_forward();
token.Length++;
// Handle 'll'/'LL' as a special case when we just processed an 'l'/'L'
if (left && (prev == 'l' || prev == 'L') && (current == 'l' || current == 'L'))
{
move_forward();
token.Length++;
}
}
} }
goto FoundToken; goto FoundToken;
@ -9563,6 +9607,7 @@ namespace parser
return result; return result;
} }
__pragma(optimize("",off))
internal Code parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers ) internal Code parse_operator_function_or_variable( bool expects_function, CodeAttributes attributes, CodeSpecifiers specifiers )
{ {
push_scope(); push_scope();
@ -9623,7 +9668,14 @@ namespace parser
Token name = parse_identifier(); Token name = parse_identifier();
Context.Scope->Name = name; Context.Scope->Name = name;
if ( check( TokType::Capture_Start ) ) bool detected_capture = check( TokType::Capture_Start );
// Check three tokens ahead to make sure that were not dealing with a constructor initialization...
// ( 350.0f , <--- Could be the scenario
// Example : <Capture_Start> <Value> <Comma>
// idx +1 +2
bool detected_comma = Context.Tokens.Arr[ Context.Tokens.Idx + 2 ].Type == TokType::Comma;
if ( detected_capture && ! detected_comma )
{ {
// Dealing with a function // Dealing with a function
result = parse_function_after_name( ModuleFlag::None, attributes, specifiers, type, name ); result = parse_function_after_name( ModuleFlag::None, attributes, specifiers, type, name );
@ -9647,6 +9699,7 @@ namespace parser
Context.pop(); Context.pop();
return result; return result;
} }
__pragma(optimize("",on))
internal CodePragma parse_pragma() internal CodePragma parse_pragma()
{ {
@ -10150,6 +10203,8 @@ namespace parser
Code expr = { nullptr }; Code expr = { nullptr };
Code bitfield_expr = { nullptr }; Code bitfield_expr = { nullptr };
b32 using_constructor_initializer = false;
if ( bitfield_is_equal( u32, currtok.Flags, TF_Assign ) ) if ( bitfield_is_equal( u32, currtok.Flags, TF_Assign ) )
{ {
// <Attributes> <Specifiers> <ValueType> <Name> = <Expression> // <Attributes> <Specifiers> <ValueType> <Name> = <Expression>
@ -10181,6 +10236,33 @@ namespace parser
// <Attributes> <Specifiers> <ValueType> <Name> = { <Expression> } // <Attributes> <Specifiers> <ValueType> <Name> = { <Expression> }
} }
if ( currtok.Type == TokType::Capture_Start )
{
eat( TokType:: Capture_Start);
// <Attributes> <Specifiers> <ValueType> <Name> (
Token expr_token = currtok;
using_constructor_initializer = true;
s32 level = 0;
while ( left && ( currtok.Type != TokType::Capture_End || level > 0 ) )
{
if ( currtok.Type == TokType::Capture_Start )
level++;
else if ( currtok.Type == TokType::Capture_End && level > 0 )
level--;
eat( currtok.Type );
}
expr_token.Length = ( (sptr)prevtok.Text + prevtok.Length ) - (sptr)expr_token.Text;
expr = untyped_str( expr_token );
eat( TokType::Capture_End );
// <Attributes> <Specifiers> <ValueType> <Name> ( <Expression> )
}
if ( currtok.Type == TokType::Assign_Classifer ) if ( currtok.Type == TokType::Assign_Classifer )
{ {
eat( TokType::Assign_Classifer ); eat( TokType::Assign_Classifer );
@ -10274,6 +10356,8 @@ namespace parser
result->NextVar->Parent = result; result->NextVar->Parent = result;
} }
result->VarConstructorInit = using_constructor_initializer;
Context.pop(); Context.pop();
return result; return result;
} }

View File

@ -886,6 +886,7 @@ struct AST
OperatorT Op; OperatorT Op;
AccessSpec ParentAccess; AccessSpec ParentAccess;
s32 NumEntries; s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
}; };
}; };
@ -968,6 +969,7 @@ struct AST_POD
OperatorT Op; OperatorT Op;
AccessSpec ParentAccess; AccessSpec ParentAccess;
s32 NumEntries; s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.
}; };
}; };
@ -3174,7 +3176,7 @@ struct AST_Var
StringCached Name; StringCached Name;
CodeT Type; CodeT Type;
ModuleFlag ModuleFlags; ModuleFlag ModuleFlags;
char _PAD_UNUSED_[sizeof( u32 )]; s32 VarConstructorInit;
}; };
static_assert( sizeof( AST_Var ) == sizeof( AST ), "ERROR: AST_Var is not the same size as AST" ); static_assert( sizeof( AST_Var ) == sizeof( AST ), "ERROR: AST_Var is not the same size as AST" );