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-system.h"
24 : #include "rust-ast-visitor.h"
25 : #include "rust-name-resolution-context.h"
26 :
27 : namespace Rust {
28 : namespace Resolver2_0 {
29 :
30 : /**
31 : * The `DefaultResolver` is a base visitor for all passes of our name resolution
32 : * algorithm: `TopLevel`, `Easy` and `Late`. It does not do a lot, apart from
33 : * visiting each node's subnodes - a block's statements, a function call's
34 : * arguments...
35 : */
36 : class DefaultResolver : public AST::DefaultASTVisitor
37 : {
38 : public:
39 : using AST::DefaultASTVisitor::visit;
40 :
41 4863 : virtual ~DefaultResolver () {}
42 :
43 : void visit (AST::Crate &) override;
44 : // First, our lexical scope expressions - these visit their sub nodes, always
45 : // these nodes create new scopes and ribs - they are often used to declare new
46 : // variables, such as a for loop's iterator, or a function's arguments
47 : void visit (AST::BlockExpr &) override;
48 35278 : virtual void maybe_prelude_import () {}
49 : void visit (AST::Module &) override;
50 : void visit (AST::Function &) override;
51 : void visit (AST::LoopExpr &expr) override;
52 : void visit (AST::WhileLoopExpr &expr) override;
53 : void visit (AST::WhileLetLoopExpr &expr) override;
54 : void visit (AST::ForLoopExpr &expr) override;
55 : virtual void visit_if_let_patterns (AST::IfLetExpr &expr);
56 : void visit (AST::IfLetExpr &expr) override;
57 : void visit (AST::IfLetExprConseqElse &expr) override;
58 : void visit (AST::Trait &) override;
59 : // used to handle Self insertion in TopLevel
60 258774 : virtual void maybe_insert_big_self (AST::Impl &) {}
61 504787 : virtual void visit_impl_type (AST::Type &type) { visit (type); }
62 : void visit (AST::InherentImpl &) override;
63 : void visit (AST::TraitImpl &) override;
64 :
65 : void visit (AST::TypeParam &) override;
66 :
67 : virtual void visit_extern_crate (AST::ExternCrate &, AST::Crate &, CrateNum);
68 : void visit (AST::ExternCrate &) override;
69 :
70 : // type dec nodes, which visit their fields or variants by default
71 : void visit (AST::StructStruct &) override;
72 : void visit (AST::TupleStruct &) override;
73 : void visit (AST::EnumItem &) override;
74 : void visit (AST::EnumItemTuple &) override;
75 : void visit (AST::EnumItemStruct &) override;
76 : void visit (AST::EnumItemDiscriminant &) override;
77 : void visit (AST::Enum &) override;
78 : void visit (AST::Union &) override;
79 : void visit (AST::TypeAlias &) override;
80 :
81 : // Visitors that visit their expression node(s)
82 : virtual void visit_closure_params (AST::ClosureExpr &);
83 : virtual void visit (AST::ClosureExpr &);
84 : void visit (AST::ClosureExprInner &) override;
85 : void visit (AST::ClosureExprInnerTyped &) override;
86 : void visit (AST::MatchExpr &) override;
87 : void visit (AST::MatchCase &) override;
88 :
89 : // Leaf visitors, which do nothing by default
90 : void visit (AST::ConstantItem &) override;
91 : void visit (AST::StaticItem &) override;
92 :
93 : protected:
94 32012 : DefaultResolver (NameResolutionContext &ctx) : ctx (ctx) {}
95 :
96 : NameResolutionContext &ctx;
97 :
98 : std::set<NodeId> visited_crates;
99 : };
100 :
101 : } // namespace Resolver2_0
102 : } // namespace Rust
103 :
104 : #endif // RUST_AST_DEFAULT_RESOLVER_H
|