From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id 415713892D22; Wed, 8 Jun 2022 12:25:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 415713892D22 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] ast_fragment: Add take_type_fragment() method X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: b6bbf1fa724bada60173ea93c5b604cee9c66da0 X-Git-Newrev: 3413f632ec84dca6489fe1ca47545b5543c2a1d5 Message-Id: <20220608122526.415713892D22@sourceware.org> Date: Wed, 8 Jun 2022 12:25:26 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 12:25:26 -0000 https://gcc.gnu.org/g:3413f632ec84dca6489fe1ca47545b5543c2a1d5 commit 3413f632ec84dca6489fe1ca47545b5543c2a1d5 Author: Arthur Cohen Date: Mon Mar 28 10:52:29 2022 +0200 ast_fragment: Add take_type_fragment() method Co-authored-by: philberty Diff: --- gcc/rust/ast/rust-ast.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 0eff6726440..5817a0e8f84 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1827,6 +1827,18 @@ private: std::vector 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 nodes, bool fragment_is_error = false) : nodes (std::move (nodes)), fragment_is_error (fragment_is_error) @@ -1867,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 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 take_expression_fragment () + std::unique_ptr 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)