|
| 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 | +IdentifierPathPass::IdentifierPathPass (NameResolutionContext &ctx, |
| 27 | + std::set<NodeId> ident_path_to_convert) |
| 28 | + : ctx (&ctx), ident_path_to_convert (std::move (ident_path_to_convert)) |
| 29 | +{} |
| 30 | + |
| 31 | +void |
| 32 | +IdentifierPathPass::go (AST::Crate &crate, NameResolutionContext &ctx, |
| 33 | + std::set<NodeId> ident_path_to_convert) |
| 34 | +{ |
| 35 | + IdentifierPathPass pass (ctx, std::move (ident_path_to_convert)); |
| 36 | + pass.visit (crate); |
| 37 | +} |
| 38 | + |
| 39 | +void |
| 40 | +IdentifierPathPass::reseat (std::unique_ptr<AST::Pattern> &ptr) |
| 41 | +{ |
| 42 | + AST::IdentifierPattern *ident_pat; |
| 43 | + if (ptr->get_pattern_kind () == AST::Pattern::Kind::Identifier) |
| 44 | + ident_pat = static_cast<AST::IdentifierPattern *> (ptr.get ()); |
| 45 | + else |
| 46 | + return; |
| 47 | + |
| 48 | + if (ident_path_to_convert.find (ident_pat->get_node_id ()) |
| 49 | + != ident_path_to_convert.end ()) |
| 50 | + { |
| 51 | + std::vector<AST::PathExprSegment> segments; |
| 52 | + segments.emplace_back (ident_pat->get_ident ().as_string (), |
| 53 | + ident_pat->get_locus ()); |
| 54 | + ptr = std::make_unique<AST::PathInExpression> ( |
| 55 | + std::move (segments), std::vector<AST::Attribute> (), |
| 56 | + ident_pat->get_locus ()); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +} // namespace Resolver2_0 |
| 61 | +} // namespace Rust |
0 commit comments