aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-11-16 15:18:49 +0000
committerGitHub <noreply@github.com>2021-11-16 15:18:49 +0000
commit5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3 (patch)
tree55051cad7f474f411d79ca1e86cc23d63138716d /gcc/rust/ast
parentdcd758595f646a480947265ccc9833fdd3976b75 (diff)
parent6d1333ef46cba6ed9e1ace817f9cc649b7f7a1df (diff)
downloadgcc-5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3.zip
gcc-5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3.tar.gz
gcc-5514d9cec51d5ec7cc30dd6cdbfadfdddbe0aab3.tar.bz2
Merge #801
801: operator overloading r=philberty a=philberty This change adds operator overloading by following how the C++ front-end does it. We are relying on GCC to inline the operator overloads which does occur once optimizations are enabled. It also brings back the desurgared compound assignment expression (e2b761b13e6ccd3a7af4100183bb13e32b5b0da0) for lang_items such as add_assign. You can find more information on how the algorithm works in: - c47d5cbdee9b701fb7753b44530fcb51f80b20fa - a7fb60bb626f7b936bf117636db777a5f0df30c9 These were refactored in: 0f74fe23c6d602c257ba94b2522bd9d6a594609e Fixes #249 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-ast.h19
-rw-r--r--gcc/rust/ast/rust-expr.h15
2 files changed, 27 insertions, 7 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 72f2609..05779e7 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -542,6 +542,13 @@ protected:
class AttrInput
{
public:
+ enum AttrInputType
+ {
+ LITERAL,
+ META_ITEM,
+ TOKEN_TREE,
+ };
+
virtual ~AttrInput () {}
// Unique pointer custom clone function
@@ -564,6 +571,8 @@ public:
// Returns whether attr input has been parsed to meta item syntax.
virtual bool is_meta_item () const = 0;
+ virtual AttrInputType get_attr_input_type () const = 0;
+
protected:
// pure virtual clone implementation
virtual AttrInput *clone_attr_input_impl () const = 0;
@@ -650,6 +659,11 @@ public:
bool check_cfg_predicate (const Session &session) const override;
+ AttrInputType get_attr_input_type () const final override
+ {
+ return AttrInput::AttrInputType::META_ITEM;
+ }
+
// Clones this object.
std::unique_ptr<AttrInputMetaItemContainer>
clone_attr_input_meta_item_container () const
@@ -767,6 +781,11 @@ public:
}
bool is_meta_item () const override { return false; }
+
+ AttrInputType get_attr_input_type () const final override
+ {
+ return AttrInput::AttrInputType::TOKEN_TREE;
+ }
};
/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 05c78b7..3463f5a 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -102,13 +102,7 @@ protected:
// Literal expression attribute body (non-macro attribute)
class AttrInputLiteral : public AttrInput
{
- // Literal expression WITHOUT SUFFIX
- // std::unique_ptr<LiteralExpr> literal_expr;
- LiteralExpr
- literal_expr; // as not using polymorphic behaviour, doesn't require pointer
- // TODO: will require pointer if LiteralExpr is changed to have subclassing
-
- // TODO: should this store location data?
+ LiteralExpr literal_expr;
public:
AttrInputLiteral (LiteralExpr lit_expr) : literal_expr (std::move (lit_expr))
@@ -127,6 +121,13 @@ public:
bool is_meta_item () const override { return false; }
+ LiteralExpr &get_literal () { return literal_expr; }
+
+ AttrInputType get_attr_input_type () const final override
+ {
+ return AttrInput::AttrInputType::LITERAL;
+ }
+
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */