pregress on fixing regressions with unreal parsing

https://github.com/Ed94/gencpp/issues/64 is required. Resolving it next
This commit is contained in:
2024-12-14 11:24:21 -05:00
parent 683f13deab
commit 3c249d2fae
16 changed files with 439 additions and 161 deletions

View File

@ -1165,7 +1165,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type)
{
GEN_AST_BODY_CLASS_UNALLOWED_TYPES:
GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(code_entry));
return false;
@ -1192,7 +1192,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type)
{
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES:
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(code_entry));
return false;
@ -1206,7 +1206,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type)
{
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES:
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(code_entry));
return false;
@ -1220,7 +1220,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for (Code code_entry = begin_CodeBody(body); code_entry != end_CodeBody(body); next_CodeBody(body, code_entry)) switch (code_entry->Type)
{
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES:
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(code_entry));
return false;
@ -1234,7 +1234,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) )switch (entry->Type)
{
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES:
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(entry));
return false;
}
@ -1245,7 +1245,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) ) switch (entry->Type)
{
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES:
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(entry));
return false;
}
@ -1256,7 +1256,7 @@ bool code_validate_body(Code self)
CodeBody body = cast(CodeBody, self);
for ( Code entry = begin_CodeBody(body); entry != end_CodeBody(body); next_CodeBody(body, entry) ) switch (entry->Type)
{
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES:
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES_CASES:
log_failure("AST::validate_body: Invalid entry in body %S", code_debug_str(entry));
return false;
}

View File

@ -1,6 +1,6 @@
// These macros are used in the swtich cases are used within ast.cpp, inteface.upfront.cpp, parser.cpp
// These macros are used in the swtich cases within ast.cpp, inteface.upfront.cpp, parser.cpp
# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES \
# define GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES \
case CT_PlatformAttributes: \
case CT_Class_Body: \
case CT_Enum_Body: \
@ -16,9 +16,9 @@
case CT_Specifiers: \
case CT_Struct_Body: \
case CT_Typename
# define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES GEN_AST_BODY_CLASS_UNALLOWED_TYPES
# define GEN_AST_BODY_STRUCT_UNALLOWED_TYPES_CASES GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES
# define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES \
# define GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES_CASES \
case CT_Access_Public: \
case CT_Access_Protected: \
case CT_Access_Private: \
@ -41,7 +41,7 @@
case CT_Struct_Body: \
case CT_Typename
# define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES \
# define GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES \
case CT_Access_Public: \
case CT_Access_Protected: \
case CT_Access_Private: \
@ -58,10 +58,10 @@
case CT_Specifiers: \
case CT_Struct_Body: \
case CT_Typename
# define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
# define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES
# define GEN_AST_BODY_EXPORT_UNALLOWED_TYPES_CASES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES
# define GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES_CASES GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES
# define GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES \
# define GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES_CASES \
case CT_Access_Public: \
case CT_Access_Protected: \
case CT_Access_Private: \

View File

@ -1364,7 +1364,7 @@ CodeBody def_class_body( s32 num, ... )
}
switch (entry->Type)
{
GEN_AST_BODY_CLASS_UNALLOWED_TYPES:
GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1396,7 +1396,7 @@ CodeBody def_class_body( s32 num, Code* codes )
}
switch (entry->Type)
{
GEN_AST_BODY_CLASS_UNALLOWED_TYPES:
GEN_AST_BODY_CLASS_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_class_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1486,7 +1486,7 @@ CodeBody def_export_body( s32 num, ... )
}
switch (entry->Type)
{
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES:
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1518,7 +1518,7 @@ CodeBody def_export_body( s32 num, Code* codes )
}
switch (entry->Type)
{
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES:
GEN_AST_BODY_EXPORT_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_export_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1552,7 +1552,7 @@ CodeBody def_extern_link_body( s32 num, ... )
}
switch (entry->Type)
{
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES:
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1585,7 +1585,7 @@ CodeBody def_extern_link_body( s32 num, Code* codes )
}
switch (entry->Type)
{
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES:
GEN_AST_BODY_EXTERN_LINKAGE_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_extern_linkage_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1619,7 +1619,7 @@ CodeBody def_function_body( s32 num, ... )
}
switch (entry->Type)
{
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES:
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES_CASES:
log_failure("gen::" stringize(def_function_body) ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1651,7 +1651,7 @@ CodeBody def_function_body( s32 num, Code* codes )
}
switch (entry->Type)
{
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES:
GEN_AST_BODY_FUNCTION_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_function_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1690,7 +1690,7 @@ CodeBody def_global_body( s32 num, ... )
body_append_body( result, cast(CodeBody, entry) );
continue;
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES:
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1726,7 +1726,7 @@ CodeBody def_global_body( s32 num, Code* codes )
body_append_body(result, cast(CodeBody, entry) );
continue;
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES:
GEN_AST_BODY_GLOBAL_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_global_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1761,7 +1761,7 @@ CodeBody def_namespace_body( s32 num, ... )
}
switch (entry->Type)
{
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES:
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1793,7 +1793,7 @@ CodeBody def_namespace_body( s32 num, Code* codes )
}
switch (entry->Type)
{
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES:
GEN_AST_BODY_NAMESPACE_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_namespace_body" ": Entry type is not allowed: %s", code_debug_str(entry) );
return InvalidCode;
@ -1938,7 +1938,7 @@ CodeBody def_struct_body( s32 num, ... )
}
switch (entry->Type)
{
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES:
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", code_debug_str(entry));
return InvalidCode;
@ -1970,7 +1970,7 @@ CodeBody def_struct_body( s32 num, Code* codes )
}
switch (entry->Type)
{
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES:
GEN_AST_BODY_STRUCT_UNALLOWED_TYPES_CASES:
log_failure("gen::" "def_struct_body" ": Entry type is not allowed: %s", code_debug_str(entry) );
return InvalidCode;

View File

@ -1,6 +1,7 @@
#ifdef GEN_INTELLISENSE_DIRECTIVES
#pragma once
#include "gen/etoktype.cpp"
#include "parser_case_macros.cpp"
#include "interface.upfront.cpp"
#include "lexer.cpp"
#endif
@ -979,17 +980,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
// <Attributes>
}
//! Fallthrough intended
case Tok_Spec_Consteval:
case Tok_Spec_Constexpr:
case Tok_Spec_Constinit:
case Tok_Spec_Explicit:
case Tok_Spec_ForceInline:
case Tok_Spec_Inline:
case Tok_Spec_Mutable:
case Tok_Spec_NeverInline:
case Tok_Spec_Static:
case Tok_Spec_Volatile:
case Tok_Spec_Virtual:
GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES:
{
Specifier specs_found[16] = { Spec_NumSpecifiers };
s32 NumSpecifiers = 0;
@ -1002,16 +993,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
switch ( spec )
{
case Spec_Constexpr:
case Spec_Constinit:
case Spec_Explicit:
case Spec_Inline:
case Spec_ForceInline:
case Spec_Mutable:
case Spec_NeverInline:
case Spec_Static:
case Spec_Volatile:
case Spec_Virtual:
GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_SPECIFIERS_CASES:
break;
case Spec_Consteval:
@ -1023,7 +1005,7 @@ CodeBody parse_class_struct_body( TokType which, Token name )
break;
default:
log_failure( "Invalid specifier %S for variable\n%S", spec_to_str(spec), strbuilder_to_str( parser_to_strbuilder(_ctx->parser)) );
log_failure( "Invalid specifier %S for class/struct member\n%S", spec_to_str(spec), strbuilder_to_str( parser_to_strbuilder(_ctx->parser)) );
parser_pop(& _ctx->parser);
return InvalidCode;
}
@ -1792,16 +1774,7 @@ CodeBody parse_global_nspace( CodeType which )
// <Attributes>
}
//! Fallthrough intentional
case Tok_Spec_Consteval:
case Tok_Spec_Constexpr:
case Tok_Spec_Constinit:
case Tok_Spec_Extern:
case Tok_Spec_ForceInline:
case Tok_Spec_Global:
case Tok_Spec_Inline:
case Tok_Spec_Internal_Linkage:
case Tok_Spec_NeverInline:
case Tok_Spec_Static:
GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES:
{
Specifier specs_found[16] = { Spec_NumSpecifiers };
s32 NumSpecifiers = 0;
@ -1814,17 +1787,7 @@ CodeBody parse_global_nspace( CodeType which )
switch ( spec )
{
case Spec_Constexpr:
case Spec_Constinit:
case Spec_ForceInline:
case Spec_Global:
case Spec_External_Linkage:
case Spec_Internal_Linkage:
case Spec_Inline:
case Spec_Mutable:
case Spec_NeverInline:
case Spec_Static:
case Spec_Volatile:
GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_SPECIFIERS_CASES:
break;
case Spec_Consteval:
@ -2560,7 +2523,7 @@ Code parse_operator_function_or_variable( bool expects_function, CodeAttributes
#ifndef GEN_PARSER_DISABLE_MACRO_FUNCTION_SIGNATURES
b32 lone_macro = false;
if ( currtok.Type == Tok_Preprocess_Macro && nexttok.Type == Tok_Statement_End )
if ( currtok.Type == Tok_Preprocess_Macro && ( nexttok.Type == Tok_Statement_End || nexttok.Type == Tok_Comment ) )
{
// Were dealing with a lone macro after attributes/specifiers, there was a end statement ';' after.
result = parse_simple_preprocess( Tok_Preprocess_Macro, parser_consume_braces );
@ -3971,10 +3934,8 @@ CodeFriend parser_parse_friend()
switch ( spec )
{
case Spec_Const :
case Spec_Inline :
case Spec_ForceInline :
break;
GEN_PARSER_FRIEND_ALLOWED_SPECIFIERS_CASES:
break;
default :
log_failure( "Invalid specifier %S for friend definition\n%S", spec_to_str( spec ), strbuilder_to_str( parser_to_strbuilder(_ctx->parser)) );
@ -4095,14 +4056,7 @@ CodeFn parser_parse_function()
switch ( spec )
{
case Spec_Const:
case Spec_Consteval:
case Spec_Constexpr:
case Spec_External_Linkage:
case Spec_ForceInline:
case Spec_Inline:
case Spec_NeverInline:
case Spec_Static:
GEN_PARSER_FUNCTION_ALLOWED_SPECIFIERS_CASES:
break;
default:
@ -4208,12 +4162,7 @@ CodeOperator parser_parse_operator()
switch ( spec )
{
case Spec_Const:
case Spec_Constexpr:
case Spec_ForceInline:
case Spec_Inline:
case Spec_NeverInline:
case Spec_Static:
GEN_PARSER_OPERATOR_ALLOWED_SPECIFIERS_CASES:
break;
default:
@ -4451,19 +4400,8 @@ CodeTemplate parser_parse_template()
switch ( spec )
{
case Spec_Const :
case Spec_Constexpr :
case Spec_Constinit :
case Spec_External_Linkage :
case Spec_Global :
case Spec_Inline :
case Spec_ForceInline :
case Spec_Local_Persist :
case Spec_Mutable :
case Spec_Static :
case Spec_Thread_Local :
case Spec_Volatile :
break;
GEN_PARSER_TEMPLATE_ALLOWED_SPECIFIERS_CASES:
break;
case Spec_Consteval :
expects_function = true;
@ -5509,17 +5447,7 @@ CodeVar parser_parse_variable()
Specifier spec = str_to_specifier( tok_to_str(currtok) );
switch ( spec )
{
case Spec_Const:
case Spec_Constexpr:
case Spec_Constinit:
case Spec_External_Linkage:
case Spec_Global:
case Spec_Inline:
case Spec_Local_Persist:
case Spec_Mutable:
case Spec_Static:
case Spec_Thread_Local:
case Spec_Volatile:
GEN_PARSER_VARIABLE_ALLOWED_SPECIFIER_CASES:
break;
default:

View File

@ -0,0 +1,105 @@
// These macros are used in the swtich cases within parser.cpp
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES \
case Tok_Spec_Consteval: \
case Tok_Spec_Constexpr: \
case Tok_Spec_Constinit: \
case Tok_Spec_Explicit: \
case Tok_Spec_ForceInline: \
case Tok_Spec_Inline: \
case Tok_Spec_Mutable: \
case Tok_Spec_NeverInline: \
case Tok_Spec_Static: \
case Tok_Spec_Volatile: \
case Tok_Spec_Virtual
#define GEN_PARSER_CLASS_STRUCT_BODY_ALLOWED_MEMBER_SPECIFIERS_CASES \
case Spec_Constexpr: \
case Spec_Constinit: \
case Spec_Explicit: \
case Spec_Inline: \
case Spec_ForceInline: \
case Spec_Mutable: \
case Spec_NeverInline: \
case Spec_Static: \
case Spec_Volatile: \
case Spec_Virtual
#define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_TOK_SPECIFIERS_CASES \
case Tok_Spec_Consteval: \
case Tok_Spec_Constexpr: \
case Tok_Spec_Constinit: \
case Tok_Spec_Extern: \
case Tok_Spec_ForceInline: \
case Tok_Spec_Global: \
case Tok_Spec_Inline: \
case Tok_Spec_Internal_Linkage: \
case Tok_Spec_NeverInline: \
case Tok_Spec_Static
#define GEN_PARSER_CLASS_GLOBAL_NSPACE_ALLOWED_MEMBER_SPECIFIERS_CASES \
case Spec_Constexpr: \
case Spec_Constinit: \
case Spec_ForceInline: \
case Spec_Global: \
case Spec_External_Linkage: \
case Spec_Internal_Linkage: \
case Spec_Inline: \
case Spec_Mutable: \
case Spec_NeverInline: \
case Spec_Static: \
case Spec_Volatile
#define GEN_PARSER_FRIEND_ALLOWED_SPECIFIERS_CASES \
case Spec_Const: \
case Spec_Inline: \
case Spec_ForceInline
#define GEN_PARSER_FUNCTION_ALLOWED_SPECIFIERS_CASES \
case Spec_Const: \
case Spec_Consteval: \
case Spec_Constexpr: \
case Spec_External_Linkage: \
case Spec_Internal_Linkage: \
case Spec_ForceInline: \
case Spec_Inline: \
case Spec_NeverInline: \
case Spec_Static
#define GEN_PARSER_OPERATOR_ALLOWED_SPECIFIERS_CASES \
case Spec_Const: \
case Spec_Constexpr: \
case Spec_ForceInline: \
case Spec_Inline: \
case Spec_NeverInline: \
case Spec_Static
#define GEN_PARSER_TEMPLATE_ALLOWED_SPECIFIERS_CASES \
case Spec_Const: \
case Spec_Constexpr: \
case Spec_Constinit: \
case Spec_External_Linkage: \
case Spec_Global: \
case Spec_Inline: \
case Spec_ForceInline: \
case Spec_Local_Persist: \
case Spec_Mutable: \
case Spec_Static: \
case Spec_Thread_Local: \
case Spec_Volatile
#define GEN_PARSER_VARIABLE_ALLOWED_SPECIFIER_CASES \
case Spec_Const: \
case Spec_Constexpr: \
case Spec_Constinit: \
case Spec_External_Linkage: \
case Spec_Global: \
case Spec_Inline: \
case Spec_Local_Persist: \
case Spec_Mutable: \
case Spec_Static: \
case Spec_Thread_Local: \
case Spec_Volatile

View File

@ -6,6 +6,24 @@
#include "gen/especifier.hpp"
#endif
enum MacroFlags : u32
{
// Can only be one of these at a time (required)
MF_Block_Start = bit(0), // Start of a "block" scope
MF_Block_End = bit(1), // End of a "block" scope
MF_Case_Statement = bit(2), // Used as a case statement (not utilized by the parser yet)
MF_Expression = bit(3), // Used as an expresssion (not utilized by the parser yet)
MF_Statement = bit(4), // Used a statement (will expect to be a lone macro)
MF_Expects_Body = bit(5), // Expects to consume a braced scope
MF_Typename = bit(6), // Behaves as a typename
// Optional
MF_Functional = bit(7),
MF_Null = 0,
MF_UnderlyingType = GEN_U32_MAX,
};
enum TokFlags : u32
{
TF_Operator = bit(0),