diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-11-16 13:24:41 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-11-16 14:04:03 +0000 |
commit | fdd69a69f870bbb01a141cef0776169f3acd7663 (patch) | |
tree | 0060d8c88da79843b8552f1c768c0dfaf6dd2bc5 | |
parent | 766f989251a87673d80831521fac002e0263f122 (diff) | |
download | gcc-fdd69a69f870bbb01a141cef0776169f3acd7663.zip gcc-fdd69a69f870bbb01a141cef0776169f3acd7663.tar.gz gcc-fdd69a69f870bbb01a141cef0776169f3acd7663.tar.bz2 |
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
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 19 | ||||
-rw-r--r-- | 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 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 */ |