Line data Source code
1 :
2 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
3 :
4 : // This file is part of GCC.
5 :
6 : // GCC is free software; you can redistribute it and/or modify it under
7 : // the terms of the GNU General Public License as published by the Free
8 : // Software Foundation; either version 3, or (at your option) any later
9 : // version.
10 :
11 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : // for more details.
15 :
16 : // You should have received a copy of the GNU General Public License
17 : // along with GCC; see the file COPYING3. If not see
18 : // <http://www.gnu.org/licenses/>.
19 :
20 : #ifndef RUST_AST_DEFAULT_RESOLVER_H
21 : #define RUST_AST_DEFAULT_RESOLVER_H
22 :
23 : #include "rust-ast-visitor.h"
24 : #include "rust-name-resolution-context.h"
25 :
26 : namespace Rust {
27 : namespace Resolver2_0 {
28 :
29 : /**
30 : * The `DefaultResolver` is a base visitor for all passes of our name resolution
31 : * algorithm: `TopLevel`, `Easy` and `Late`. It does not do a lot, apart from
32 : * visiting each node's subnodes - a block's statements, a function call's
33 : * arguments...
34 : */
35 : class DefaultResolver : public AST::DefaultASTVisitor
36 : {
37 : public:
38 : using AST::DefaultASTVisitor::visit;
39 :
40 4505 : virtual ~DefaultResolver () {}
41 :
42 : void visit (AST::Crate &) override;
43 : // First, our lexical scope expressions - these visit their sub nodes, always
44 : // these nodes create new scopes and ribs - they are often used to declare new
45 : // variables, such as a for loop's iterator, or a function's arguments
46 : void visit (AST::BlockExpr &) override;
47 : void visit (AST::Module &) override;
48 : void visit (AST::Function &) override;
49 : void visit (AST::ForLoopExpr &expr) override;
50 : virtual void visit_if_let_patterns (AST::IfLetExpr &expr);
51 : void visit (AST::IfLetExpr &expr) override;
52 : void visit (AST::IfLetExprConseqElse &expr) override;
53 : void visit (AST::Trait &) override;
54 : // used to handle Self insertion in TopLevel
55 18994 : virtual void maybe_insert_big_self (AST::Impl &) {}
56 32383 : virtual void visit_impl_type (AST::Type &type) { visit (type); }
57 : void visit (AST::InherentImpl &) override;
58 : void visit (AST::TraitImpl &) override;
59 :
60 : void visit (AST::TypeParam &) override;
61 :
62 : virtual void visit_extern_crate (AST::ExternCrate &, AST::Crate &, CrateNum);
63 : void visit (AST::ExternCrate &) override;
64 :
65 : // type dec nodes, which visit their fields or variants by default
66 : void visit (AST::StructStruct &) override;
67 : void visit (AST::TupleStruct &) override;
68 : void visit (AST::EnumItem &) override;
69 : void visit (AST::EnumItemTuple &) override;
70 : void visit (AST::EnumItemStruct &) override;
71 : void visit (AST::EnumItemDiscriminant &) override;
72 : void visit (AST::Enum &) override;
73 : void visit (AST::Union &) override;
74 : void visit (AST::TypeAlias &) override;
75 :
76 : // Visitors that visit their expression node(s)
77 : virtual void visit_closure_params (AST::ClosureExpr &);
78 : virtual void visit (AST::ClosureExpr &);
79 : void visit (AST::ClosureExprInner &) override;
80 : void visit (AST::ClosureExprInnerTyped &) override;
81 : void visit (AST::MatchExpr &) override;
82 :
83 : // Leaf visitors, which do nothing by default
84 : void visit (AST::ConstantItem &) override;
85 : void visit (AST::StaticItem &) override;
86 :
87 : protected:
88 29726 : DefaultResolver (NameResolutionContext &ctx) : ctx (ctx) {}
89 :
90 : NameResolutionContext &ctx;
91 : };
92 :
93 : } // namespace Resolver2_0
94 : } // namespace Rust
95 :
96 : #endif // RUST_AST_DEFAULT_RESOLVER_H
|