Skip to content

Commit 3413f63

Browse files
ast_fragment: Add take_type_fragment() method
Co-authored-by: philberty <philip.herron@embecosm.com>
1 parent b6bbf1f commit 3413f63

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,18 @@ class ASTFragment
18271827
std::vector<SingleASTNode> nodes;
18281828
bool fragment_is_error;
18291829

1830+
/**
1831+
* We need to make a special case for Expression and Type fragments as only
1832+
* one Node will be extracted from the `nodes` vector
1833+
*/
1834+
1835+
bool is_single_fragment () const { return nodes.size () == 1; }
1836+
1837+
bool is_single_fragment_kind (SingleASTNode::NodeType kind) const
1838+
{
1839+
return is_single_fragment () && nodes[0].get_kind () == kind;
1840+
}
1841+
18301842
public:
18311843
ASTFragment (std::vector<SingleASTNode> nodes, bool fragment_is_error = false)
18321844
: nodes (std::move (nodes)), fragment_is_error (fragment_is_error)
@@ -1867,21 +1879,16 @@ class ASTFragment
18671879

18681880
bool should_expand () const { return !is_error () && !nodes.empty (); }
18691881

1870-
/**
1871-
* We need to make a special case for Expression fragments as only one
1872-
* Node will be extracted from the `nodes` vector
1873-
*/
1874-
1875-
bool is_expression_fragment () const
1882+
std::unique_ptr<Expr> take_expression_fragment ()
18761883
{
1877-
return nodes.size () == 1
1878-
&& nodes[0].get_kind () == SingleASTNode::NodeType::EXPRESSION;
1884+
rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::EXPRESSION));
1885+
return nodes[0].take_expr ();
18791886
}
18801887

1881-
std::unique_ptr<Expr> take_expression_fragment ()
1888+
std::unique_ptr<Type> take_type_fragment ()
18821889
{
1883-
rust_assert (is_expression_fragment ());
1884-
return nodes[0].take_expr ();
1890+
rust_assert (is_single_fragment_kind (SingleASTNode::NodeType::TYPE));
1891+
return nodes[0].take_type ();
18851892
}
18861893

18871894
void accept_vis (ASTVisitor &vis)

0 commit comments

Comments
 (0)