]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/rust/resolve/rust-ast-verify-assignee.h
Update copyright years.
[thirdparty/gcc.git] / gcc / rust / resolve / rust-ast-verify-assignee.h
1 // Copyright (C) 2020-2023 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 #ifndef RUST_AST_VERIFY_ASSIGNEE
20 #define RUST_AST_VERIFY_ASSIGNEE
21
22 #include "rust-ast-resolve-base.h"
23 #include "rust-ast-full.h"
24
25 namespace Rust {
26 namespace Resolver {
27
28 class VerifyAsignee : public ResolverBase
29 {
30 using Rust::Resolver::ResolverBase::visit;
31
32 public:
33 static bool go (AST::Expr *assignee, NodeId parent)
34 {
35 VerifyAsignee checker (parent);
36 assignee->accept_vis (checker);
37 if (!checker.ok)
38 rust_error_at (assignee->get_locus (),
39 "invalid left-hand side of assignment");
40 return checker.ok;
41 }
42
43 void visit (AST::ArrayIndexExpr &expr) override
44 {
45 expr.get_array_expr ()->accept_vis (*this);
46 }
47
48 void visit (AST::FieldAccessExpr &expr) override
49 {
50 expr.get_receiver_expr ()->accept_vis (*this);
51 }
52
53 void visit (AST::TupleIndexExpr &expr) override
54 {
55 expr.get_tuple_expr ()->accept_vis (*this);
56 }
57
58 void visit (AST::IdentifierExpr &expr) override
59 {
60 if (!resolver->get_name_scope ().lookup (
61 CanonicalPath::new_seg (expr.get_node_id (), expr.as_string ()),
62 &resolved_node))
63 return;
64
65 ok = true;
66 }
67
68 void visit (AST::DereferenceExpr &expr) override
69 {
70 expr.get_dereferenced_expr ()->accept_vis (*this);
71 }
72
73 void visit (AST::PathInExpression &expr) override { ok = true; }
74
75 private:
76 VerifyAsignee (NodeId parent) : ResolverBase (), ok (false) {}
77
78 bool ok;
79 };
80
81 } // namespace Resolver
82 } // namespace Rust
83
84 #endif // RUST_AST_VERIFY_ASSIGNEE