Line data Source code
1 : // Copyright (C) 2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-system.h"
20 : #include "rust-identifier-path.h"
21 : #include "rust-pattern.h"
22 :
23 : namespace Rust {
24 : namespace Resolver2_0 {
25 :
26 11200 : IdentifierPathPass::IdentifierPathPass (NameResolutionContext &ctx,
27 : std::set<NodeId> ident_path_to_convert)
28 11200 : : ctx (&ctx), ident_path_to_convert (std::move (ident_path_to_convert))
29 11200 : {}
30 :
31 : void
32 11200 : IdentifierPathPass::go (AST::Crate &crate, NameResolutionContext &ctx,
33 : std::set<NodeId> ident_path_to_convert)
34 : {
35 11200 : IdentifierPathPass pass (ctx, std::move (ident_path_to_convert));
36 11200 : pass.visit (crate);
37 11200 : }
38 :
39 : void
40 2550524 : IdentifierPathPass::reseat (std::unique_ptr<AST::Pattern> &ptr)
41 : {
42 2550524 : if (ptr->get_pattern_kind () != AST::Pattern::Kind::Identifier)
43 : {
44 : // bail out, but make sure to still visit
45 1814085 : visit (ptr);
46 1814085 : return;
47 : }
48 :
49 736439 : auto ident_pat = static_cast<AST::IdentifierPattern *> (ptr.get ());
50 :
51 736439 : if (ident_path_to_convert.find (ident_pat->get_node_id ())
52 736439 : != ident_path_to_convert.end ())
53 : {
54 514 : std::vector<AST::PathExprSegment> segments;
55 514 : segments.emplace_back (ident_pat->get_ident ().as_string (),
56 514 : ident_pat->get_locus ());
57 1028 : ptr = std::make_unique<AST::PathInExpression> (
58 514 : std::move (segments), std::vector<AST::Attribute> (),
59 514 : ident_pat->get_locus ());
60 514 : }
61 : else
62 : {
63 735925 : visit (ptr);
64 : }
65 : }
66 :
67 : } // namespace Resolver2_0
68 : } // namespace Rust
|