reduction done on eoperator

This commit is contained in:
Edward R. Gonzalez 2024-12-03 13:51:29 -05:00
parent c6fba23173
commit 72d088c566
10 changed files with 222 additions and 229 deletions

View File

@ -202,7 +202,7 @@ char const* debug_str(Code self)
append_fmt( result, "\n\tNext: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
break;
case Operator:
case ECode::Operator:
case Operator_Member:
if ( self->Prev )
append_fmt( result, "\n\tPrev: %S %S", type_str(self->Prev), self->Prev->Name ? self->Prev->Name : "Null" );
@ -482,7 +482,7 @@ void to_string( Code self, String* result )
to_string(cast(CodeNS, self), result );
break;
case Operator:
case ECode::Operator:
case Operator_Member:
to_string_def(cast(CodeOperator, self), result );
break;
@ -860,7 +860,7 @@ bool is_equal( Code self, Code other )
return true;
}
case Operator:
case ECode::Operator:
case Operator_Member:
{
check_member_val( ModuleFlags );

View File

@ -359,7 +359,7 @@ struct AST
union {
b32 IsFunction; // Used by typedef to not serialize the name field.
b32 IsParamPack; // Used by typename to know if type should be considered a parameter pack.
OperatorT Op;
Operator Op;
AccessSpec ParentAccess;
s32 NumEntries;
s32 VarConstructorInit; // Used by variables to know that initialization is using a constructor expression instead of an assignment expression.

View File

@ -8,7 +8,7 @@
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case ECode::Operator: \
case Operator_Fwd: \
case Parameters: \
case Specifiers: \
@ -30,7 +30,7 @@
case Global_Body: \
case Namespace: \
case Namespace_Body: \
case Operator: \
case ECode::Operator: \
case Operator_Fwd: \
case Operator_Member: \
case Operator_Member_Fwd: \

View File

@ -605,7 +605,7 @@ struct AST_Operator
StringCached Name;
CodeT Type;
ModuleFlag ModuleFlags;
OperatorT Op;
Operator Op;
};
static_assert( sizeof(AST_Operator) == sizeof(AST), "ERROR: AST_Operator is not the same size as AST");

View File

@ -636,7 +636,7 @@ String to_string(CodeOperator self)
switch ( self->Type )
{
using namespace ECode;
case Operator:
case ECode::Operator:
case Operator_Member:
to_string_def( self, & result );
break;

View File

@ -5,114 +5,110 @@
// This file was generated automatially by gencpp's bootstrap.cpp (See: https://github.com/Ed94/gencpp)
namespace EOperator
typedef enum Operator_Def Operator;
enum Operator_Def : u32
{
enum Type : u32
{
Invalid,
Assign,
Assign_Add,
Assign_Subtract,
Assign_Multiply,
Assign_Divide,
Assign_Modulo,
Assign_BAnd,
Assign_BOr,
Assign_BXOr,
Assign_LShift,
Assign_RShift,
Increment,
Decrement,
Unary_Plus,
Unary_Minus,
UnaryNot,
Add,
Subtract,
Multiply,
Divide,
Modulo,
BNot,
BAnd,
BOr,
BXOr,
LShift,
RShift,
LAnd,
LOr,
LEqual,
LNot,
Lesser,
Greater,
LesserEqual,
GreaterEqual,
Subscript,
Indirection,
AddressOf,
MemberOfPointer,
PtrToMemOfPtr,
FunctionCall,
Comma,
New,
NewArray,
Delete,
DeleteArray,
NumOps
Op_Invalid,
Op_Assign,
Op_Assign_Add,
Op_Assign_Subtract,
Op_Assign_Multiply,
Op_Assign_Divide,
Op_Assign_Modulo,
Op_Assign_BAnd,
Op_Assign_BOr,
Op_Assign_BXOr,
Op_Assign_LShift,
Op_Assign_RShift,
Op_Increment,
Op_Decrement,
Op_Unary_Plus,
Op_Unary_Minus,
Op_UnaryNot,
Op_Add,
Op_Subtract,
Op_Multiply,
Op_Divide,
Op_Modulo,
Op_BNot,
Op_BAnd,
Op_BOr,
Op_BXOr,
Op_LShift,
Op_RShift,
Op_LAnd,
Op_LOr,
Op_LEqual,
Op_LNot,
Op_Lesser,
Op_Greater,
Op_LesserEqual,
Op_GreaterEqual,
Op_Subscript,
Op_Indirection,
Op_AddressOf,
Op_MemberOfPointer,
Op_PtrToMemOfPtr,
Op_FunctionCall,
Op_Comma,
Op_New,
Op_NewArray,
Op_Delete,
Op_DeleteArray,
NumOps
};
inline StrC to_str( Operator op )
{
local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" },
{ sizeof( "=" ), "=" },
{ sizeof( "+=" ), "+=" },
{ sizeof( "-=" ), "-=" },
{ sizeof( "*=" ), "*=" },
{ sizeof( "/=" ), "/=" },
{ sizeof( "%=" ), "%=" },
{ sizeof( "&=" ), "&=" },
{ sizeof( "|=" ), "|=" },
{ sizeof( "^=" ), "^=" },
{ sizeof( "<<=" ), "<<=" },
{ sizeof( ">>=" ), ">>=" },
{ sizeof( "++" ), "++" },
{ sizeof( "--" ), "--" },
{ sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" },
{ sizeof( "!" ), "!" },
{ sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" },
{ sizeof( "*" ), "*" },
{ sizeof( "/" ), "/" },
{ sizeof( "%" ), "%" },
{ sizeof( "~" ), "~" },
{ sizeof( "&" ), "&" },
{ sizeof( "|" ), "|" },
{ sizeof( "^" ), "^" },
{ sizeof( "<<" ), "<<" },
{ sizeof( ">>" ), ">>" },
{ sizeof( "&&" ), "&&" },
{ sizeof( "||" ), "||" },
{ sizeof( "==" ), "==" },
{ sizeof( "!=" ), "!=" },
{ sizeof( "<" ), "<" },
{ sizeof( ">" ), ">" },
{ sizeof( "<=" ), "<=" },
{ sizeof( ">=" ), ">=" },
{ sizeof( "[]" ), "[]" },
{ sizeof( "*" ), "*" },
{ sizeof( "&" ), "&" },
{ sizeof( "->" ), "->" },
{ sizeof( "->*" ), "->*" },
{ sizeof( "()" ), "()" },
{ sizeof( "," ), "," },
{ sizeof( "new" ), "new" },
{ sizeof( "new[]" ), "new[]" },
{ sizeof( "delete" ), "delete" },
{ sizeof( "delete[]" ), "delete[]" },
};
inline StrC to_str( Type op )
{
local_persist StrC lookup[] {
{ sizeof( "INVALID" ), "INVALID" },
{ sizeof( "=" ), "=" },
{ sizeof( "+=" ), "+=" },
{ sizeof( "-=" ), "-=" },
{ sizeof( "*=" ), "*=" },
{ sizeof( "/=" ), "/=" },
{ sizeof( "%=" ), "%=" },
{ sizeof( "&=" ), "&=" },
{ sizeof( "|=" ), "|=" },
{ sizeof( "^=" ), "^=" },
{ sizeof( "<<=" ), "<<=" },
{ sizeof( ">>=" ), ">>=" },
{ sizeof( "++" ), "++" },
{ sizeof( "--" ), "--" },
{ sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" },
{ sizeof( "!" ), "!" },
{ sizeof( "+" ), "+" },
{ sizeof( "-" ), "-" },
{ sizeof( "*" ), "*" },
{ sizeof( "/" ), "/" },
{ sizeof( "%" ), "%" },
{ sizeof( "~" ), "~" },
{ sizeof( "&" ), "&" },
{ sizeof( "|" ), "|" },
{ sizeof( "^" ), "^" },
{ sizeof( "<<" ), "<<" },
{ sizeof( ">>" ), ">>" },
{ sizeof( "&&" ), "&&" },
{ sizeof( "||" ), "||" },
{ sizeof( "==" ), "==" },
{ sizeof( "!=" ), "!=" },
{ sizeof( "<" ), "<" },
{ sizeof( ">" ), ">" },
{ sizeof( "<=" ), "<=" },
{ sizeof( ">=" ), ">=" },
{ sizeof( "[]" ), "[]" },
{ sizeof( "*" ), "*" },
{ sizeof( "&" ), "&" },
{ sizeof( "->" ), "->" },
{ sizeof( "->*" ), "->*" },
{ sizeof( "()" ), "()" },
{ sizeof( "," ), "," },
{ sizeof( "new" ), "new" },
{ sizeof( "new[]" ), "new[]" },
{ sizeof( "delete" ), "delete" },
{ sizeof( "delete[]" ), "delete[]" },
};
return lookup[op];
}
} // namespace EOperator
using OperatorT = EOperator::Type;
return lookup[op];
}

View File

@ -106,7 +106,7 @@ struct Opts_def_operator {
CodeAttributes attributes;
ModuleFlag mflags;
};
CodeOperator def_operator( OperatorT op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator opts GEN_PARAM_DEFAULT );
struct Opts_def_operator_cast {
Code body;

View File

@ -12,11 +12,9 @@ enum class OpValidateResult : u32
Member
};
OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeType ret_type, CodeSpecifiers specifier )
OpValidateResult operator__validate( Operator op, CodeParam params_code, CodeType ret_type, CodeSpecifiers specifier )
{
using namespace EOperator;
if ( op == EOperator::Invalid )
if ( op == Op_Invalid )
{
log_failure("gen::def_operator: op cannot be invalid");
return OpValidateResult::Fail;
@ -65,7 +63,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
switch ( op )
{
# define specs( ... ) num_args( __VA_ARGS__ ), __VA_ARGS__
case Assign:
case Op_Assign:
check_params();
if ( params_code->NumEntries > 1 )
@ -81,16 +79,16 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
is_member_symbol = true;
break;
case Assign_Add:
case Assign_Subtract:
case Assign_Multiply:
case Assign_Divide:
case Assign_Modulo:
case Assign_BAnd:
case Assign_BOr:
case Assign_BXOr:
case Assign_LShift:
case Assign_RShift:
case Op_Assign_Add:
case Op_Assign_Subtract:
case Op_Assign_Multiply:
case Op_Assign_Divide:
case Op_Assign_Modulo:
case Op_Assign_BAnd:
case Op_Assign_BOr:
case Op_Assign_BXOr:
case Op_Assign_LShift:
case Op_Assign_RShift:
check_params();
if ( params_code->NumEntries == 1 )
@ -110,8 +108,8 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case Increment:
case Decrement:
case Op_Increment:
case Op_Decrement:
// If its not set, it just means its a prefix member op.
if ( params_code )
{
@ -157,8 +155,8 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case Unary_Plus:
case Unary_Minus:
case Op_Unary_Plus:
case Op_Unary_Minus:
if ( ! params_code )
is_member_symbol = true;
@ -193,7 +191,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case BNot:
case Op_BNot:
{
// Some compilers let you do this...
#if 0
@ -228,16 +226,16 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
break;
}
case Add:
case Subtract:
case Multiply:
case Divide:
case Modulo:
case BAnd:
case BOr:
case BXOr:
case LShift:
case RShift:
case Op_Add:
case Op_Subtract:
case Op_Multiply:
case Op_Divide:
case Op_Modulo:
case Op_BAnd:
case Op_BOr:
case Op_BXOr:
case Op_LShift:
case Op_RShift:
check_params();
switch ( params_code->NumEntries )
@ -269,7 +267,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case UnaryNot:
case Op_UnaryNot:
if ( ! params_code )
is_member_symbol = true;
@ -301,14 +299,14 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case LAnd:
case LOr:
case LEqual:
case LNot:
case Lesser:
case Greater:
case LesserEqual:
case GreaterEqual:
case Op_LAnd:
case Op_LOr:
case Op_LEqual:
case Op_LNot:
case Op_Lesser:
case Op_Greater:
case Op_LesserEqual:
case Op_GreaterEqual:
check_params();
switch ( params_code->NumEntries )
@ -329,9 +327,9 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case Indirection:
case AddressOf:
case MemberOfPointer:
case Op_Indirection:
case Op_AddressOf:
case Op_MemberOfPointer:
if ( params_code && params_code->NumEntries > 1)
{
log_failure("gen::def_operator: operator%s recieved unexpected number of paramters recived %d instead of 0-1"
@ -346,7 +344,7 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case PtrToMemOfPtr:
case Op_PtrToMemOfPtr:
if ( params_code )
{
log_failure("gen::def_operator: operator%s expects no paramters - %s", to_str(op), debug_str(params_code));
@ -354,14 +352,14 @@ OpValidateResult operator__validate( OperatorT op, CodeParam params_code, CodeTy
}
break;
case Subscript:
case FunctionCall:
case Comma:
case Op_Subscript:
case Op_FunctionCall:
case Op_Comma:
check_params();
break;
case New:
case Delete:
case Op_New:
case Op_Delete:
// This library doesn't support validating new and delete yet.
break;
# undef specs
@ -956,7 +954,7 @@ CodeNS def_namespace( StrC name, Code body, Opts_def_namespace p )
return result;
}
CodeOperator def_operator( OperatorT op, StrC nspace, Opts_def_operator p )
CodeOperator def_operator( Operator op, StrC nspace, Opts_def_operator p )
{
CodeParam params_code = p.params;
CodeType ret_type = p.ret_type;

View File

@ -2135,7 +2135,6 @@ CodeOperator parse_operator_after_ret_type(
, CodeType ret_type
)
{
using namespace EOperator;
push_scope();
Token nspace = NullToken;
@ -2171,19 +2170,19 @@ CodeOperator parse_operator_after_ret_type(
bool was_new_or_delete = false;
OperatorT op = Invalid;
Operator op = Op_Invalid;
switch ( currtok.Text[0] )
{
case '+':
{
if ( currtok.Text[1] == '=' )
op = Assign_Add;
op = Op_Assign_Add;
else if ( currtok.Text[1] == '+' )
op = Increment;
op = Op_Increment;
else
op = Add;
op = Op_Add;
}
break;
case '-':
@ -2191,25 +2190,25 @@ CodeOperator parse_operator_after_ret_type(
if ( currtok.Text[1] == '>' )
{
if ( currtok.Text[2] == '*' )
op = MemberOfPointer;
op = Op_MemberOfPointer;
else
op = MemberOfPointer;
op = Op_MemberOfPointer;
break;
}
else if ( currtok.Text[1] == '=' )
op = Assign_Subtract;
op = Op_Assign_Subtract;
else
op = Subtract;
op = Op_Subtract;
}
break;
case '*':
{
if ( currtok.Text[1] == '=' )
op = Assign_Multiply;
op = Op_Assign_Multiply;
else
{
@ -2218,154 +2217,154 @@ CodeOperator parse_operator_after_ret_type(
{
if ( finder.Type == Tok_Identifier)
{
op = Indirection;
op = Op_Indirection;
break;
}
}
if ( op == Invalid)
op = Multiply;
if ( op == Op_Invalid)
op = Op_Multiply;
}
}
break;
case '/':
{
if ( currtok.Text[1] == '=' )
op = Assign_Divide;
op = Op_Assign_Divide;
else
op = Divide;
op = Op_Divide;
}
break;
case '%':
{
if ( currtok.Text[1] == '=' )
op = Assign_Modulo;
op = Op_Assign_Modulo;
else
op = Modulo;
op = Op_Modulo;
}
break;
case '&':
{
if ( currtok.Text[1] == '=' )
op = Assign_BAnd;
op = Op_Assign_BAnd;
else if ( currtok.Text[1] == '&' )
op = LAnd;
op = Op_LAnd;
else
{
if ( op == Invalid )
op = BAnd;
if ( op == Op_Invalid )
op = Op_BAnd;
}
}
break;
case '|':
{
if ( currtok.Text[1] == '=' )
op = Assign_BOr;
op = Op_Assign_BOr;
else if ( currtok.Text[1] == '|' )
op = LOr;
op = Op_LOr;
else
op = BOr;
op = Op_BOr;
}
break;
case '^':
{
if ( currtok.Text[1] == '=' )
op = Assign_BXOr;
op = Op_Assign_BXOr;
else
op = BXOr;
op = Op_BXOr;
}
break;
case '~':
{
op = BNot;
op = Op_BNot;
}
break;
case '!':
{
if ( currtok.Text[1] == '=' )
op = LNot;
op = Op_LNot;
else
op = UnaryNot;
op = Op_UnaryNot;
}
break;
case '=':
{
if ( currtok.Text[1] == '=' )
op = LEqual;
op = Op_LEqual;
else
op = Assign;
op = Op_Assign;
}
break;
case '<':
{
if ( currtok.Text[1] == '=' )
op = LEqual;
op = Op_LEqual;
else if ( currtok.Text[1] == '<' )
{
if ( currtok.Text[2] == '=' )
op = Assign_LShift;
op = Op_Assign_LShift;
else
op = LShift;
op = Op_LShift;
}
else
op = Lesser;
op = Op_Lesser;
}
break;
case '>':
{
if ( currtok.Text[1] == '=' )
op = GreaterEqual;
op = Op_GreaterEqual;
else if ( currtok.Text[1] == '>' )
{
if ( currtok.Text[2] == '=' )
op = Assign_RShift;
op = Op_Assign_RShift;
else
op = RShift;
op = Op_RShift;
}
else
op = Greater;
op = Op_Greater;
}
break;
case '(':
{
if ( currtok.Text[1] == ')' )
op = FunctionCall;
op = Op_FunctionCall;
else
op = Invalid;
op = Op_Invalid;
}
break;
case '[':
{
if ( currtok.Text[1] == ']' )
op = Subscript;
op = Op_Subscript;
else
op = Invalid;
op = Op_Invalid;
}
break;
default:
{
StrC str_new = to_str(OperatorT::New);
StrC str_delete = to_str(OperatorT::Delete);
StrC str_new = to_str(Op_New);
StrC str_delete = to_str(Op_Delete);
if ( str_compare( currtok.Text, str_new.Ptr, max(str_new.Len - 1, currtok.Length)) == 0)
{
op = OperatorT::New;
op = Op_New;
eat( Tok_Identifier );
was_new_or_delete = true;
@ -2378,18 +2377,18 @@ CodeOperator parse_operator_after_ret_type(
if ( currtok.Type == Tok_Operator && str_compare(currtok.Text, "[]", 2) == 0)
{
eat(Tok_Operator);
op = OperatorT::NewArray;
op = Op_NewArray;
}
else if ( currtok.Type == Tok_BraceSquare_Open && next.Type == Tok_BraceSquare_Close)
{
eat(Tok_BraceSquare_Open);
eat(Tok_BraceSquare_Close);
op = OperatorT::NewArray;
op = Op_NewArray;
}
}
else if ( str_compare( currtok.Text, str_delete.Ptr, max(str_delete.Len - 1, currtok.Length )) == 0)
{
op = OperatorT::Delete;
op = Op_Delete;
eat(Tok_Identifier);
was_new_or_delete = true;
@ -2402,18 +2401,18 @@ CodeOperator parse_operator_after_ret_type(
if ( currtok.Type == Tok_Operator && str_compare(currtok.Text, "[]", 2) == 0)
{
eat(Tok_Operator);
op = OperatorT::DeleteArray;
op = Op_DeleteArray;
}
else if ( currtok.Type == Tok_BraceSquare_Open && next.Type == Tok_BraceSquare_Close)
{
eat(Tok_BraceSquare_Open);
eat(Tok_BraceSquare_Close);
op = OperatorT::DeleteArray;
op = Op_DeleteArray;
}
}
else
{
if ( op == Invalid )
if ( op == Op_Invalid )
{
log_failure( "Invalid operator '%s'\n%s", prevtok.Text, to_string(Context) );
pop(& Context);
@ -2423,7 +2422,7 @@ CodeOperator parse_operator_after_ret_type(
}
}
if ( op == Invalid )
if ( op == Op_Invalid )
{
log_failure( "Invalid operator '%s'\n%s", currtok.Text, to_string(Context) );
pop(& Context);
@ -2438,8 +2437,8 @@ CodeOperator parse_operator_after_ret_type(
CodeParam params = parse_params();
// <ExportFlag> <Attributes> <Specifiers> <ReturnType> <Qualifier::...> operator <Op> ( <Parameters> )
if ( params.ast == nullptr && op == EOperator::Multiply )
op = MemberOfPointer;
if ( params.ast == nullptr && op == Op_Multiply )
op = Op_MemberOfPointer;
while ( left && is_specifier(currtok) )
{

View File

@ -76,12 +76,12 @@ CodeBody gen_eoperator( char const* path )
char const* enum_str = enum_strs[idx].string;
char const* entry_to_str = str_strs [idx].string;
append_fmt( & enum_entries, "%s,\n", enum_str );
append_fmt( & enum_entries, "Op_%s,\n", enum_str );
append_fmt( & to_str_entries, "{ sizeof(\"%s\"), \"%s\" },\n", entry_to_str, entry_to_str);
}
CodeEnum enum_code = parse_enum(token_fmt("entries", (StrC)enum_entries, stringize(
enum Type : u32
enum Operator_Def : u32
{
<entries>
NumOps
@ -92,7 +92,7 @@ CodeBody gen_eoperator( char const* path )
#undef local_persist
CodeFn to_str = parse_function(token_fmt("entries", (StrC)to_str_entries, stringize(
inline
StrC to_str( Type op )
StrC to_str( Operator op )
{
local_persist
StrC lookup[] {
@ -104,11 +104,11 @@ CodeBody gen_eoperator( char const* path )
)));
#pragma pop_macro("local_persist")
CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
//CodeNS nspace = def_namespace( name(EOperator), def_namespace_body( args( enum_code, to_str ) ) );
//CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
CodeTypedef operator_t = parse_typedef(code( typedef enum Operator_Def Operator; ));
CodeUsing operator_t = def_using( name(OperatorT), def_type( name(EOperator::Type) ) );
return def_global_body( args( nspace, operator_t, fmt_newline ) );
return def_global_body( args( operator_t, enum_code, to_str, fmt_newline ) );
}
CodeBody gen_especifier( char const* path )