From fdd69a69f870bbb01a141cef0776169f3acd7663 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 16 Nov 2021 13:24:41 +0000 Subject: 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 --- gcc/rust/ast/rust-ast.h | 19 +++++++++++++++++++ gcc/rust/ast/rust-expr.h | 15 ++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) (limited to 'gcc/rust/ast') 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 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 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 */ -- cgit v1.1