Branch data Line data Source code
1 : : // Copyright (C) 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-hir-visitor.h"
20 : : #include "rust-name-resolver.h"
21 : : #include "rust-stacked-contexts.h"
22 : : #include "rust-hir-type-check.h"
23 : :
24 : : namespace Rust {
25 : : namespace HIR {
26 : 3990 : class ReadonlyChecker : public DefaultHIRVisitor
27 : : {
28 : : public:
29 : : ReadonlyChecker ();
30 : :
31 : : void go (HIR::Crate &crate);
32 : :
33 : : private:
34 : : enum class lvalue_use
35 : : {
36 : : assign,
37 : : increment,
38 : : decrement,
39 : : };
40 : :
41 : : Resolver::Resolver &resolver;
42 : : Analysis::Mappings &mappings;
43 : : Resolver::TypeCheckContext &context;
44 : : StackedContexts<HirId> mutable_context;
45 : :
46 : : using DefaultHIRVisitor::visit;
47 : :
48 : : virtual void visit (AssignmentExpr &expr) override;
49 : : virtual void visit (PathInExpression &expr) override;
50 : : virtual void visit (FieldAccessExpr &expr) override;
51 : : virtual void visit (ArrayIndexExpr &expr) override;
52 : : virtual void visit (TupleExpr &expr) override;
53 : : virtual void visit (TupleIndexExpr &expr) override;
54 : : virtual void visit (LetStmt &stmt) override;
55 : : virtual void visit (LiteralExpr &expr) override;
56 : : virtual void visit (DereferenceExpr &expr) override;
57 : :
58 : : void collect_assignment (Pattern &pattern, bool has_init_expr);
59 : : void collect_assignment_identifier (IdentifierPattern &pattern,
60 : : bool has_init_expr);
61 : : void collect_assignment_tuple (TuplePattern &pattern, bool has_init_expr);
62 : :
63 : : void check_variable (IdentifierPattern *pattern, location_t assigned_loc);
64 : :
65 : : bool is_mutable_type (TyTy::BaseType *type);
66 : : };
67 : :
68 : : } // namespace HIR
69 : : } // namespace Rust
|