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 12513 : IdentifierPathPass::IdentifierPathPass (NameResolutionContext &ctx,
27 : std::set<NodeId> ident_path_to_convert)
28 12513 : : ctx (&ctx), ident_path_to_convert (std::move (ident_path_to_convert))
29 12513 : {}
30 :
31 : void
32 12513 : IdentifierPathPass::go (AST::Crate &crate, NameResolutionContext &ctx,
33 : std::set<NodeId> ident_path_to_convert)
34 : {
35 12513 : IdentifierPathPass pass (ctx, std::move (ident_path_to_convert));
36 12513 : pass.visit (crate);
37 12513 : }
38 :
39 : void
40 29868783 : IdentifierPathPass::reseat (std::unique_ptr<AST::Pattern> &ptr)
41 : {
42 29868783 : if (ptr->get_pattern_kind () != AST::Pattern::Kind::Identifier)
43 : {
44 : // bail out, but make sure to still visit
45 21643394 : visit (ptr);
46 21643394 : return;
47 : }
48 :
49 8225389 : auto ident_pat = static_cast<AST::IdentifierPattern *> (ptr.get ());
50 :
51 8225389 : if (ident_path_to_convert.find (ident_pat->get_node_id ())
52 8225389 : != ident_path_to_convert.end ())
53 : {
54 5927 : std::vector<AST::PathExprSegment> segments;
55 5927 : segments.emplace_back (ident_pat->get_ident ().as_string (),
56 5927 : ident_pat->get_locus ());
57 11854 : ptr = std::make_unique<AST::PathInExpression> (
58 5927 : std::move (segments), std::vector<AST::Attribute> (),
59 5927 : ident_pat->get_locus ());
60 5927 : }
61 : else
62 : {
63 8219462 : visit (ptr);
64 : }
65 : }
66 :
67 : } // namespace Resolver2_0
68 : } // namespace Rust
|