Skip to content

Commit fdd69a6

Browse files
committed
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
1 parent 766f989 commit fdd69a6

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 19 additions & 0 deletions
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

Lines changed: 8 additions & 7 deletions
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)