Add support for non Specifier enum SuffixSpecs in AST_Fn and parsing (Thanks Unreal)

This commit is contained in:
Edward R. Gonzalez 2025-01-29 01:29:55 -05:00
parent 16fc3fa379
commit ce2be411d7
7 changed files with 34 additions and 3 deletions

View File

@ -400,7 +400,7 @@ struct AST
}; };
union { union {
Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value ) Code NextVar; // Variable; Possible way to handle comma separated variables declarations. ( , NextVar->Specs NextVar->Name NextVar->ArrExpr = NextVar->Value )
Code SuffixSpecs; // Only used with typenames, to store the function suffix if typename is function signature. ( May not be needed ) Code SuffixSpecs; // Typename, Function (Thanks Unreal)
Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal) Code PostNameMacro; // Only used with parameters for specifically UE_REQUIRES (Thanks Unreal)
}; };
}; };

View File

@ -575,7 +575,7 @@ struct AST_Fn
CodeTypename ReturnType; CodeTypename ReturnType;
CodeParams Params; CodeParams Params;
CodeBody Body; CodeBody Body;
char _PAD_PROPERTIES_ [ sizeof(AST*) ]; Code SuffixSpecs; // Thanks Unreal
}; };
}; };
StrCached Name; StrCached Name;

View File

@ -589,6 +589,10 @@ void fn_to_strbuilder_def(CodeFn self, StrBuilder* result )
} }
} }
// This is bodged in for now SOLEY for Unreal's PURE_VIRTUAL functional macro
if ( self->SuffixSpecs )
strbuilder_append_fmt( result, " %SB", code_to_strbuilder(self->SuffixSpecs) );
strbuilder_append_fmt( result, "\n{\n%SB\n}\n", body_to_strbuilder(self->Body) ); strbuilder_append_fmt( result, "\n{\n%SB\n}\n", body_to_strbuilder(self->Body) );
} }
@ -646,7 +650,12 @@ void fn_to_strbuilder_fwd(CodeFn self, StrBuilder* result )
if ( self->Specs && specifiers_has(self->Specs, Spec_Pure ) >= 0 ) if ( self->Specs && specifiers_has(self->Specs, Spec_Pure ) >= 0 )
strbuilder_append_str( result, txt(" = 0;") ); strbuilder_append_str( result, txt(" = 0;") );
else if (self->Body)
// This is bodged in for now SOLEY for Unreal's PURE_VIRTUAL functional macro (I kept it open ended for other jank)
if ( self->SuffixSpecs )
strbuilder_append_fmt( result, " %SB", code_to_strbuilder(self->SuffixSpecs) );
if (self->Body)
strbuilder_append_fmt( result, " = %SB;", body_to_strbuilder(self->Body) ); strbuilder_append_fmt( result, " = %SB;", body_to_strbuilder(self->Body) );
if ( self->InlineCmt ) if ( self->InlineCmt )

View File

@ -550,6 +550,9 @@ void lex_found_token( LexContext* ctx )
if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Attribute) ) { if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Attribute) ) {
ctx->token.Flags |= TF_Attribute; ctx->token.Flags |= TF_Attribute;
} }
if ( bitfield_is_set(MacroFlags, macro->Flags, MF_Allow_As_Specifier ) ) {
ctx->token.Flags |= TF_Specifier;
}
} }
else else
{ {

View File

@ -1403,6 +1403,18 @@ CodeFn parse_function_after_name(
} }
// <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers> // <Attributes> <Specifiers> <ReturnType> <Name> ( <Paraemters> ) <Specifiers>
Code suffix_specs = NullCode;
// For Unreal's PURE_VIRTUAL Support
if ( left )
{
Macro* macro = lookup_macro( currtok.Text );
if (macro && tok_is_specifier(currtok))
{
suffix_specs = parse_simple_preprocess(Tok_Preprocess_Macro_Expr);
}
}
CodeBody body = NullCode; CodeBody body = NullCode;
CodeComment inline_cmt = NullCode; CodeComment inline_cmt = NullCode;
if ( check( Tok_BraceCurly_Open ) ) if ( check( Tok_BraceCurly_Open ) )
@ -1479,6 +1491,9 @@ CodeFn parse_function_after_name(
if ( specifiers ) if ( specifiers )
result->Specs = specifiers; result->Specs = specifiers;
if ( suffix_specs )
result->SuffixSpecs = suffix_specs;
result->ReturnType = ret_type; result->ReturnType = ret_type;
if ( params ) if ( params )

View File

@ -186,6 +186,8 @@ enum EMacroFlags : u16
// (MUST BE OF MT_Statement TYPE) // (MUST BE OF MT_Statement TYPE)
MF_Allow_As_Definition = bit(4), MF_Allow_As_Definition = bit(4),
MF_Allow_As_Specifier = bit(5), // Created for Unreal's PURE_VIRTUAL
MF_Null = 0, MF_Null = 0,
MF_UnderlyingType = GEN_U16_MAX, MF_UnderlyingType = GEN_U16_MAX,
}; };

View File

@ -5,6 +5,7 @@
#pragma region Macros #pragma region Macros
#ifndef GEN_API
#if GEN_COMPILER_MSVC #if GEN_COMPILER_MSVC
#ifdef GEN_DYN_LINK #ifdef GEN_DYN_LINK
#ifdef GEN_DYN_EXPORT #ifdef GEN_DYN_EXPORT
@ -22,6 +23,7 @@
#define GEN_API // Empty for static builds #define GEN_API // Empty for static builds
#endif #endif
#endif #endif
#endif // GEN_API
#ifndef global #ifndef global
#define global static // Global variables #define global static // Global variables