Line data Source code
1 : // Copyright (C) 2025-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-unused-context.h"
20 :
21 : namespace Rust {
22 : namespace Analysis {
23 :
24 : void
25 28 : UnusedContext::add_variable (HirId id)
26 :
27 : {
28 28 : used_vars.emplace (id);
29 28 : }
30 :
31 : bool
32 27 : UnusedContext::is_variable_used (HirId id) const
33 : {
34 27 : return used_vars.find (id) != used_vars.end ();
35 : }
36 :
37 : void
38 15 : UnusedContext::add_assign (HirId id_def, HirId id)
39 : {
40 15 : if (is_variable_assigned (id_def))
41 10 : unused_assigns.emplace (assigned_vars[id_def]);
42 15 : assigned_vars[id_def] = id;
43 15 : }
44 :
45 : void
46 28 : UnusedContext::remove_assign (HirId id_def)
47 : {
48 28 : if (assigned_vars.find (id_def) != assigned_vars.end ())
49 5 : assigned_vars.erase (id_def);
50 28 : }
51 :
52 : bool
53 15 : UnusedContext::is_variable_assigned (HirId id_def)
54 : {
55 15 : return assigned_vars.find (id_def) != assigned_vars.end ();
56 : }
57 :
58 : bool
59 15 : UnusedContext::is_assign_unused (HirId id)
60 : {
61 15 : return unused_assigns.find (id) != unused_assigns.end ();
62 : }
63 :
64 : void
65 8 : UnusedContext::add_mut (HirId id)
66 : {
67 8 : mutable_vars.emplace (id);
68 8 : }
69 :
70 : void
71 15 : UnusedContext::remove_mut (HirId id)
72 : {
73 15 : mutable_vars.erase (id);
74 15 : }
75 :
76 : bool
77 8 : UnusedContext::is_mut_used (HirId id) const
78 : {
79 8 : return mutable_vars.find (id) == mutable_vars.end ();
80 : }
81 :
82 : void
83 3 : UnusedContext::add_label (HirId id)
84 :
85 : {
86 3 : used_labels.emplace (id);
87 3 : }
88 :
89 : bool
90 5 : UnusedContext::is_label_used (HirId id) const
91 : {
92 5 : return used_labels.find (id) != used_labels.end ();
93 : }
94 :
95 : std::string
96 0 : UnusedContext::as_string () const
97 : {
98 0 : std::stringstream ss;
99 0 : ss << "UnusedContext: ";
100 0 : for (const auto &v : used_vars)
101 : {
102 0 : ss << "HirId: " << v << "\n";
103 : }
104 0 : return ss.str ();
105 0 : }
106 :
107 : } // namespace Analysis
108 : } // namespace Rust
|