]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/rust/resolve/rust-ast-verify-assignee.h
1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of GCC.
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
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
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/>.
19 #ifndef RUST_AST_VERIFY_ASSIGNEE
20 #define RUST_AST_VERIFY_ASSIGNEE
22 #include "rust-ast-resolve-base.h"
23 #include "rust-ast-full.h"
28 class VerifyAsignee
: public ResolverBase
30 using Rust::Resolver::ResolverBase::visit
;
33 static bool go (AST::Expr
*assignee
, NodeId parent
)
35 VerifyAsignee
checker (parent
);
36 assignee
->accept_vis (checker
);
38 rust_error_at (assignee
->get_locus (),
39 "invalid left-hand side of assignment");
43 void visit (AST::ArrayIndexExpr
&expr
) override
45 expr
.get_array_expr ()->accept_vis (*this);
48 void visit (AST::FieldAccessExpr
&expr
) override
50 expr
.get_receiver_expr ()->accept_vis (*this);
53 void visit (AST::TupleIndexExpr
&expr
) override
55 expr
.get_tuple_expr ()->accept_vis (*this);
58 void visit (AST::IdentifierExpr
&expr
) override
60 if (!resolver
->get_name_scope ().lookup (
61 CanonicalPath::new_seg (expr
.get_node_id (), expr
.as_string ()),
68 void visit (AST::DereferenceExpr
&expr
) override
70 expr
.get_dereferenced_expr ()->accept_vis (*this);
73 void visit (AST::PathInExpression
&expr
) override
{ ok
= true; }
76 VerifyAsignee (NodeId parent
) : ResolverBase (), ok (false) {}
81 } // namespace Resolver
84 #endif // RUST_AST_VERIFY_ASSIGNEE