Skip to content

Commit d1ad621

Browse files
committed
operator overloading working
Fixes #249
1 parent 57b10ae commit d1ad621

21 files changed

+1029
-291
lines changed

gcc/rust/Make-lang.in

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ GRS_OBJS = \
9090
rust/rust-hir-type-check-path.o \
9191
rust/rust-compile-intrinsic.o \
9292
rust/rust-base62.o \
93+
rust/rust-compile-expr.o \
9394
$(END)
9495
# removed object files from here
9596

gcc/rust/ast/rust-ast.h

+19
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,13 @@ struct Attribute
542542
class AttrInput
543543
{
544544
public:
545+
enum AttrInputType
546+
{
547+
LITERAL,
548+
META_ITEM,
549+
TOKEN_TREE,
550+
};
551+
545552
virtual ~AttrInput () {}
546553

547554
// Unique pointer custom clone function
@@ -564,6 +571,8 @@ class AttrInput
564571
// Returns whether attr input has been parsed to meta item syntax.
565572
virtual bool is_meta_item () const = 0;
566573

574+
virtual AttrInputType get_attr_input_type () const = 0;
575+
567576
protected:
568577
// pure virtual clone implementation
569578
virtual AttrInput *clone_attr_input_impl () const = 0;
@@ -650,6 +659,11 @@ class AttrInputMetaItemContainer : public AttrInput
650659

651660
bool check_cfg_predicate (const Session &session) const override;
652661

662+
AttrInputType get_attr_input_type () const final override
663+
{
664+
return AttrInput::AttrInputType::META_ITEM;
665+
}
666+
653667
// Clones this object.
654668
std::unique_ptr<AttrInputMetaItemContainer>
655669
clone_attr_input_meta_item_container () const
@@ -767,6 +781,11 @@ class DelimTokenTree : public TokenTree, public AttrInput
767781
}
768782

769783
bool is_meta_item () const override { return false; }
784+
785+
AttrInputType get_attr_input_type () const final override
786+
{
787+
return AttrInput::AttrInputType::TOKEN_TREE;
788+
}
770789
};
771790

772791
/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to

gcc/rust/ast/rust-expr.h

+8-7
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,7 @@ class LiteralExpr : public ExprWithoutBlock
102102
// Literal expression attribute body (non-macro attribute)
103103
class AttrInputLiteral : public AttrInput
104104
{
105-
// Literal expression WITHOUT SUFFIX
106-
// std::unique_ptr<LiteralExpr> literal_expr;
107-
LiteralExpr
108-
literal_expr; // as not using polymorphic behaviour, doesn't require pointer
109-
// TODO: will require pointer if LiteralExpr is changed to have subclassing
110-
111-
// TODO: should this store location data?
105+
LiteralExpr literal_expr;
112106

113107
public:
114108
AttrInputLiteral (LiteralExpr lit_expr) : literal_expr (std::move (lit_expr))
@@ -127,6 +121,13 @@ class AttrInputLiteral : public AttrInput
127121

128122
bool is_meta_item () const override { return false; }
129123

124+
LiteralExpr &get_literal () { return literal_expr; }
125+
126+
AttrInputType get_attr_input_type () const final override
127+
{
128+
return AttrInput::AttrInputType::LITERAL;
129+
}
130+
130131
protected:
131132
/* Use covariance to implement clone function as returning this object rather
132133
* than base */

0 commit comments

Comments
 (0)