mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-30 19:01:02 -07:00
Added support for friend operator definitions
This commit is contained in:
@ -449,7 +449,7 @@ void to_string(CodeFriend self, String* result )
|
||||
{
|
||||
append_fmt( result, "friend %S", to_string(self->Declaration) );
|
||||
|
||||
if ( self->Declaration->Type != CT_Function && (* result)[ length(* result) - 1 ] != ';' )
|
||||
if ( self->Declaration->Type != CT_Function && self->Declaration->Type != CT_Operator && (* result)[ length(* result) - 1 ] != ';' )
|
||||
{
|
||||
append( result, ";" );
|
||||
}
|
||||
|
@ -905,11 +905,11 @@ CodeBody parse_class_struct_body( TokType which, Token name )
|
||||
break;
|
||||
|
||||
case Tok_Operator:
|
||||
if ( currtok.Text[0] != '~' )
|
||||
{
|
||||
log_failure( "Operator token found in global body but not destructor unary negation\n%s", to_string(Context) );
|
||||
return InvalidCode;
|
||||
}
|
||||
//if ( currtok.Text[0] != '~' )
|
||||
//{
|
||||
// log_failure( "Operator token found in global body but not destructor unary negation\n%s", to_string(Context) );
|
||||
// return InvalidCode;
|
||||
//}
|
||||
|
||||
member = parse_destructor();
|
||||
// ~<Name>()
|
||||
@ -3859,7 +3859,8 @@ CodeFriend parse_friend()
|
||||
eat( Tok_Decl_Friend );
|
||||
// friend
|
||||
|
||||
CodeFn function = { nullptr };
|
||||
CodeFn function = { nullptr };
|
||||
CodeOperator op = { nullptr };
|
||||
|
||||
// Type declaration or return type
|
||||
CodeTypename type = parse_type();
|
||||
@ -3892,6 +3893,12 @@ CodeFriend parse_friend()
|
||||
// if ( params )
|
||||
// function->Params = params;
|
||||
}
|
||||
|
||||
// Operator declaration or definition
|
||||
if ( currtok.Type == Tok_Decl_Operator )
|
||||
{
|
||||
op = parse_operator_after_ret_type( ModuleFlag_None, NullCode, type );
|
||||
}
|
||||
|
||||
CodeComment inline_cmt = NullCode;
|
||||
if ( function && function->Type == CT_Function_Fwd )
|
||||
@ -3912,6 +3919,8 @@ CodeFriend parse_friend()
|
||||
|
||||
if ( function )
|
||||
result->Declaration = function;
|
||||
else if ( op )
|
||||
result->Declaration = op;
|
||||
else
|
||||
result->Declaration = type;
|
||||
|
||||
|
@ -25,13 +25,13 @@ struct StrC
|
||||
operator char const* () const { return Ptr; }
|
||||
char const& operator[]( ssize index ) const { return Ptr[index]; }
|
||||
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FUNCTIONS
|
||||
bool is_equal (StrC rhs) { return are_equal(* this, rhs); }
|
||||
char* back () { return back(* this); }
|
||||
bool contains (StrC substring) { return contains(* this, substring); }
|
||||
String duplicate (AllocatorInfo allocator) { return duplicate(* this, allocator); }
|
||||
b32 starts_with (StrC substring) { return starts_with(* this, substring); }
|
||||
String visualize_whitespace() { return visualize_whitespace(* this); }
|
||||
#if GEN_SUPPORT_CPP_MEMBER_FEATURES
|
||||
bool is_equal (StrC rhs) const { return GEN_NS are_equal(* this, rhs); }
|
||||
char const* back () const { return GEN_NS back(* this); }
|
||||
bool contains (StrC substring) const { return GEN_NS contains(* this, substring); }
|
||||
StrC duplicate (AllocatorInfo allocator) const { return GEN_NS duplicate(* this, allocator); }
|
||||
b32 starts_with (StrC substring) const { return GEN_NS starts_with(* this, substring); }
|
||||
StrC visualize_whitespace(AllocatorInfo allocator) const { return GEN_NS visualize_whitespace(* this, allocator); }
|
||||
#endif // GEN_SUPPORT_CPP_MEMBER_FUNCTIONS
|
||||
#endif // GEN_COMPILERC
|
||||
};
|
||||
|
@ -7,6 +7,7 @@
|
||||
# pragma clang diagnostic ignored "-Wunknown-pragmas"
|
||||
# pragma clang diagnostic ignored "-Wvarargs"
|
||||
# pragma clang diagnostic ignored "-Wunused-function"
|
||||
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
Reference in New Issue
Block a user