Branch data Line data Source code
1 : : // Copyright (C) 2020-2024 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_TOPLEVEL_NAME_RESOLVER_2_0_H
20 : : #define RUST_TOPLEVEL_NAME_RESOLVER_2_0_H
21 : :
22 : : #include "rust-ast-visitor.h"
23 : : #include "rust-name-resolution-context.h"
24 : : #include "rust-default-resolver.h"
25 : :
26 : : namespace Rust {
27 : : namespace Resolver2_0 {
28 : :
29 : : /**
30 : : * The `TopLevel` visitor takes care of collecting all the definitions in a
31 : : * crate, and inserting them into the proper namespaces. These definitions can
32 : : * then be accessed by subsequent resolvers, such as `Early` or `Late`.
33 : : */
34 : 21 : class TopLevel : public DefaultResolver
35 : : {
36 : : using DefaultResolver::visit;
37 : :
38 : : public:
39 : : TopLevel (NameResolutionContext &resolver);
40 : :
41 : : void go (AST::Crate &crate);
42 : :
43 : : private:
44 : : /**
45 : : * Insert a new definition or error out if a definition with the same name was
46 : : * already present in the same namespace in the same scope.
47 : : *
48 : : * @param identifier The identifier of the definition to add.
49 : : * @param node A reference to the node, so we can get its `NodeId` and
50 : : * location.
51 : : * @param ns The namespace in which to add the definition.
52 : : */
53 : : template <typename T>
54 : : void insert_or_error_out (const Identifier &identifier, const T &node,
55 : : Namespace ns);
56 : : void insert_or_error_out (const Identifier &identifier,
57 : : const location_t &locus, const NodeId &id,
58 : : Namespace ns);
59 : :
60 : : // FIXME: Do we move these to our mappings?
61 : : std::unordered_map<NodeId, location_t> node_locations;
62 : :
63 : : void visit (AST::Module &module) override;
64 : : void visit (AST::MacroRulesDefinition ¯o) override;
65 : : void visit (AST::Function &function) override;
66 : : void visit (AST::BlockExpr &expr) override;
67 : : void visit (AST::StaticItem &static_item) override;
68 : : void visit (AST::StructStruct &struct_item) override;
69 : : void visit (AST::TupleStruct &tuple_struct) override;
70 : : void visit (AST::EnumItem &variant) override;
71 : : void visit (AST::EnumItemTuple &variant) override;
72 : : void visit (AST::EnumItemStruct &variant) override;
73 : : void visit (AST::EnumItemDiscriminant &variant) override;
74 : : void visit (AST::Enum &enum_item) override;
75 : : void visit (AST::Union &union_item) override;
76 : : void visit (AST::ConstantItem &const_item) override;
77 : : void visit (AST::ExternCrate &crate) override;
78 : :
79 : : // FIXME: Documentation
80 : : // Call this on all the paths of a UseDec - so each flattened path in a
81 : : // UseTreeList for example
82 : : // FIXME: Should that return `found`?
83 : : bool handle_use_dec (AST::SimplePath path);
84 : :
85 : : void visit (AST::UseDeclaration &use) override;
86 : : };
87 : :
88 : : } // namespace Resolver2_0
89 : : } // namespace Rust
90 : :
91 : : #endif // !RUST_TOPLEVEL_NAME_RESOLVER_2_0_H
|