]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h
1 // Copyright (C) 2020-2024 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_TOPLEVEL_NAME_RESOLVER_2_0_H
20 #define RUST_TOPLEVEL_NAME_RESOLVER_2_0_H
22 #include "rust-ast-visitor.h"
23 #include "rust-name-resolution-context.h"
24 #include "rust-default-resolver.h"
27 namespace Resolver2_0
{
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`.
34 class TopLevel
: public DefaultResolver
36 using DefaultResolver::visit
;
39 TopLevel (NameResolutionContext
&resolver
);
41 void go (AST::Crate
&crate
);
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.
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
51 * @param ns The namespace in which to add the definition.
54 void insert_or_error_out (const Identifier
&identifier
, const T
&node
,
56 void insert_or_error_out (const Identifier
&identifier
,
57 const location_t
&locus
, const NodeId
&id
,
60 // FIXME: Do we move these to our mappings?
61 std::unordered_map
<NodeId
, location_t
> node_locations
;
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
;
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
);
85 void visit (AST::UseDeclaration
&use
) override
;
88 } // namespace Resolver2_0
91 #endif // !RUST_TOPLEVEL_NAME_RESOLVER_2_0_H