public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] ast_fragment: Add take_type_fragment() method Date: Wed, 8 Jun 2022 12:25:26 +0000 (GMT) [thread overview] Message-ID: <20220608122526.415713892D22@sourceware.org> (raw) https://gcc.gnu.org/g:3413f632ec84dca6489fe1ca47545b5543c2a1d5 commit 3413f632ec84dca6489fe1ca47545b5543c2a1d5 Author: Arthur Cohen <arthur.cohen@embecosm.com> Date: Mon Mar 28 10:52:29 2022 +0200 ast_fragment: Add take_type_fragment() method Co-authored-by: philberty <philip.herron@embecosm.com> 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<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) @@ -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<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)
reply other threads:[~2022-06-08 12:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608122526.415713892D22@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).