diff options
Diffstat (limited to 'gcc/rust/ast/rust-ast.h')
-rw-r--r-- | gcc/rust/ast/rust-ast.h | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index a22c2d1..5817a0e 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1515,6 +1515,7 @@ public: TRAIT, IMPL, TRAIT_IMPL, + TYPE, }; private: @@ -1528,6 +1529,7 @@ private: std::unique_ptr<TraitItem> trait_item; std::unique_ptr<InherentImplItem> impl_item; std::unique_ptr<TraitImplItem> trait_impl_item; + std::unique_ptr<Type> type; public: SingleASTNode (std::unique_ptr<Expr> expr) @@ -1558,6 +1560,10 @@ public: : kind (TRAIT_IMPL), trait_impl_item (std::move (trait_impl_item)) {} + SingleASTNode (std::unique_ptr<Type> type) + : kind (TYPE), type (std::move (type)) + {} + SingleASTNode (SingleASTNode const &other) { kind = other.kind; @@ -1590,6 +1596,10 @@ public: case TRAIT_IMPL: trait_impl_item = other.trait_impl_item->clone_trait_impl_item (); break; + + case TYPE: + type = other.type->clone_type (); + break; } } @@ -1625,6 +1635,10 @@ public: case TRAIT_IMPL: trait_impl_item = other.trait_impl_item->clone_trait_impl_item (); break; + + case TYPE: + type = other.type->clone_type (); + break; } return *this; } @@ -1699,6 +1713,12 @@ public: return std::move (trait_impl_item); } + std::unique_ptr<Type> take_type () + { + rust_assert (!is_error ()); + return std::move (type); + } + void accept_vis (ASTVisitor &vis) { switch (kind) @@ -1730,6 +1750,10 @@ public: case TRAIT_IMPL: trait_impl_item->accept_vis (vis); break; + + case TYPE: + type->accept_vis (vis); + break; } } @@ -1751,6 +1775,8 @@ public: return impl_item == nullptr; case TRAIT_IMPL: return trait_impl_item == nullptr; + case TYPE: + return type == nullptr; } gcc_unreachable (); @@ -1774,7 +1800,9 @@ public: case IMPL: return "Impl Item: " + impl_item->as_string (); case TRAIT_IMPL: - return "Trait Impl Item: " + impl_item->as_string (); + return "Trait Impl Item: " + trait_impl_item->as_string (); + case TYPE: + return "Type: " + type->as_string (); } gcc_unreachable (); @@ -1799,6 +1827,18 @@ private: std::vector<SingleASTNode> nodes; bool fragment_is_error; + /** + * We need to make a special case for Expression and Type fragments as only + * one Node will be extracted from the `nodes` vector + */ + + bool is_single_fragment () const { return nodes.size () == 1; } + + bool is_single_fragment_kind (SingleASTNode::NodeType kind) const + { + return is_single_fragment () && nodes[0].get_kind () == kind; + } + public: ASTFragment (std::vector<SingleASTNode> nodes, bool fragment_is_error = false) : nodes (std::move (nodes)), fragment_is_error (fragment_is_error) @@ -1839,21 +1879,16 @@ public: bool should_expand () const { return !is_error () && !nodes.empty (); } - /** - * We need to make a special case for Expression fragments as only one - * Node will be extracted from the `nodes` vector - */ - - bool is_expression_fragment () const + std::unique_ptr<Expr> take_expression_fragment () { - return nodes.size () == 1 - && nodes[0].get_kind () == SingleASTNode::NodeType::EXPRESSION; + rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::EXPRESSION)); + return nodes[0].take_expr (); } - std::unique_ptr<Expr> take_expression_fragment () + std::unique_ptr<Type> take_type_fragment () { - rust_assert (is_expression_fragment ()); - return nodes[0].take_expr (); + rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::TYPE)); + return nodes[0].take_type (); } void accept_vis (ASTVisitor &vis) |