public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Update AttrInput with AttrInputType
@ 2022-06-08 11:50 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:fdd69a69f870bbb01a141cef0776169f3acd7663
commit fdd69a69f870bbb01a141cef0776169f3acd7663
Author: Philip Herron <philip.herron@embecosm.com>
Date: Tue Nov 16 13:24:41 2021 +0000
Update AttrInput with AttrInputType
This allows us to switch based on the type which can be used for more complex usage of attributes such as lang_item parsing.
Addresses #742
Diff:
---
gcc/rust/ast/rust-ast.h | 19 +++++++++++++++++++
gcc/rust/ast/rust-expr.h | 15 ++++++++-------
2 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 72f260989ba..05779e7be0b 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 05c78b7b965..3463f5a2f1c 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 */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 11:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:50 [gcc/devel/rust/master] Update AttrInput with AttrInputType Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).