Debian Codegraph @

gcc/rust/resolve/rust-ast-resolve-stmt.cc

raw
1 // Copyright (C) 2020-2025 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-ast-resolve-toplevel.h"
20 #include "rust-ast-resolve-item.h"
21 #include "rust-ast-resolve-stmt.h"
22 #include "rust-ast-resolve-implitem.h"
23
24 namespace Rust {
25 namespace Resolver {
26
27 void
28 ResolveStmt::visit (AST::ExternBlock &extern_block)
29 {
30 resolve_visibility (extern_block.get_visibility ());
31 for (auto &item : extern_block.get_extern_items ())
32 {
33 ResolveToplevelExternItem::go (*item, CanonicalPath::create_empty ());
34 ResolveExternItem::go (*item, prefix, canonical_prefix);
35 }
36 }
37
38 void
39 ResolveStmt::visit (AST::Trait &trait)
40 {
41 ResolveTopLevel::go (trait, prefix, canonical_prefix);
42 ResolveItem::go (trait, prefix, canonical_prefix);
43 }
44
45 void
46 ResolveStmt::visit (AST::InherentImpl &impl_block)
47 {
48 ResolveTopLevel::go (impl_block, prefix, canonical_prefix);
49 ResolveItem::go (impl_block, prefix, canonical_prefix);
50 }
51
52 void
53 ResolveStmt::visit (AST::TraitImpl &impl_block)
54 {
55 ResolveTopLevel::go (impl_block, prefix, canonical_prefix);
56 ResolveItem::go (impl_block, prefix, canonical_prefix);
57 }
58
59 void
60 ResolveStmt::visit (AST::StaticItem &var)
61 {
62 auto decl = CanonicalPath::new_seg (var.get_node_id (),
63 var.get_identifier ().as_string ());
64 auto path = decl;
65 auto cpath = canonical_prefix.append (decl);
66 mappings.insert_canonical_path (var.get_node_id (), cpath);
67
68 resolver->get_name_scope ().insert (
69 path, var.get_node_id (), var.get_locus (), false, Rib::ItemType::Static,
70 [&] (const CanonicalPath &, NodeId, location_t locus) -> void {
71 rich_location r (line_table, var.get_locus ());
72 r.add_range (locus);
73 redefined_error (r);
74 });
75
76 ResolveType::go (var.get_type ());
77 ResolveExpr::go (var.get_expr (), path, cpath);
78 }
79
80 } // namespace Resolver
81 } // namespace Rust