bugfixes while testing with unreal (still more needs fixing

This commit is contained in:
2024-12-15 17:52:31 -05:00
parent 0b03b3cd92
commit 868b93cdd0
15 changed files with 103 additions and 49 deletions

View File

@ -262,9 +262,9 @@ forceinline void define_params_append (CodeDefineParams appendee
forceinline CodeDefineParams define_params_get (CodeDefineParams self, s32 idx ) { return (CodeDefineParams) (Code) params_get( cast(CodeParams, self), idx); }
forceinline bool define_params_has_entries(CodeDefineParams self) { return params_has_entries( cast(CodeParams, self)); }
CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
forceinline CodeDefineParams begin_CodeDefineParams(CodeDefineParams params) { return (CodeDefineParams) (Code) begin_CodeParams( cast(CodeParams, (Code)params)); }
forceinline CodeDefineParams end_CodeDefineParams (CodeDefineParams params) { return (CodeDefineParams) (Code) end_CodeParams ( cast(CodeParams, (Code)params)); }
forceinline CodeDefineParams next_CodeDefineParams (CodeDefineParams params, CodeDefineParams entry_iter) { return (CodeDefineParams) (Code) next_CodeParams ( cast(CodeParams, (Code)params), cast(CodeParams, (Code)entry_iter)); }
#if GEN_COMPILER_CPP
forceinline

View File

@ -378,6 +378,10 @@ void deinit(Context* ctx)
-- context_counter;
}
Context* get_context() {
return _ctx;
}
void reset(Context* ctx)
{
s32 index = 0;

View File

@ -100,6 +100,9 @@ GEN_API void init(Context* ctx);
// However on Windows at least, it doesn't need to occur as the OS will clean up after the process.
GEN_API void deinit(Context* ctx);
// Retrieves the active context (not usually needed, but here in case...)
GEN_API Context* get_context();
// Clears the allocations, but doesn't free the memoery, then calls init() again.
// Ease of use.
GEN_API void reset(Context* ctx);

View File

@ -155,7 +155,7 @@ s32 lex_preprocessor_define( LexContext* ctx )
array_append( _ctx->Lexer_Tokens, opening_paren );
move_forward();
Token last_parameter;
Token last_parameter = {};
// We need to tokenize the define's arguments now:
while( ctx->left && * ctx->scanner != ')')
{

View File

@ -2490,7 +2490,40 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
// Example : <Capture_Start> <Value> <Comma>
// idx +1 +2
bool detected_comma = _ctx->parser.Tokens.Arr[ _ctx->parser.Tokens.Idx + 2 ].Type == Tok_Comma;
if ( detected_capture && ! detected_comma )
b32 detected_non_varadic_unpaired_param = detected_comma && nexttok.Type != Tok_Varadic_Argument;
if (! detected_non_varadic_unpaired_param && nexttok.Type == Tok_Preprocess_Macro_Expr) for( s32 break_scope = 0; break_scope == 0; ++ break_scope)
{
Macro* macro = lookup_macro( nexttok.Text );
if (macro == nullptr || ! macro_is_functional(* macro))
break;
// ( <Macro_Expr> (
// Idx +1 +2
s32 idx = _ctx->parser.Tokens.Idx + 1;
s32 level = 0;
// Find end of the token expression
for ( ; idx < array_num(_ctx->parser.Tokens.Arr); idx++ )
{
Token tok = _ctx->parser.Tokens.Arr[ idx ];
if ( tok.Type == Tok_Capture_Start )
level++;
else if ( tok.Type == Tok_Capture_End && level > 0 )
level--;
if (level == 0 && tok.Type == Tok_Capture_End)
break;
}
++ idx; // Will incremnt to possible comma position
if ( _ctx->parser.Tokens.Arr[ idx ].Type != Tok_Comma )
break;
detected_non_varadic_unpaired_param = true;
}
if ( detected_capture && ! detected_non_varadic_unpaired_param )
{
// Dealing with a function
result = cast(Code, parse_function_after_name( ModuleFlag_None, attributes, specifiers, type, name ));
@ -2509,7 +2542,7 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
}
}
parser_pop(& _ctx->parser);
parser_pop(& _ctx->parser);
return result;
}
@ -3002,7 +3035,7 @@ Code parse_simple_preprocess( TokType which )
|| str_contains(calling_proc, txt("parse_class_struct_body"))
)
{
if (peektok.Type == Tok_Statement_End)
if (left && peektok.Type == Tok_Statement_End)
{
Token stmt_end = currtok;
eat( Tok_Statement_End );
@ -5015,7 +5048,6 @@ CodeTypedef parser_parse_typedef()
// valid_macro |= macro && macro_expects_body(* macro));
// }
Code macro;
if ( valid_macro )
#endif
{

View File

@ -9,7 +9,7 @@
enum TokFlags : u32
{
TF_Operator = bit(0),
TF_Operator = bit(0),
TF_Assign = bit(1),
TF_Preprocess = bit(2),
TF_Preprocess_Cond = bit(3),
@ -152,6 +152,7 @@ TokType macrotype_to_toktype( MacroType type ) {
return Tok_Invalid;
}
inline
Str macrotype_to_str( MacroType type )
{
local_persist
@ -216,4 +217,9 @@ b32 macro_expects_body( Macro macro ) {
return bitfield_is_set( b16, macro.Flags, MF_Expects_Body );
}
#if GEN_COMPILER_CPP && ! GEN_C_LIKE_CPP
forceinline b32 is_functional( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Functional ); }
forceinline b32 expects_body ( Macro macro ) { return bitfield_is_set( b16, macro.Flags, MF_Expects_Body ); }
#endif
typedef HashTable(Macro) MacroTable;