Fixes to gencpp
This commit is contained in:
parent
001a542521
commit
60a4128df4
@ -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 )
|
||||||
@ -3003,6 +3026,7 @@ internal void define_constants()
|
|||||||
#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 );
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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" );
|
||||||
|
Loading…
Reference in New Issue
Block a user