Line data Source code
1 : // Copyright (C) 2024-2026 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_COLLECT_LANG_ITEMS_H
20 : #define RUST_COLLECT_LANG_ITEMS_H
21 :
22 : #include "rust-ast-visitor.h"
23 : #include "rust-ast.h"
24 : #include "rust-hir-map.h"
25 : #include "rust-item.h"
26 :
27 : namespace Rust {
28 : namespace AST {
29 :
30 : // This class collects lang items ahead of lowering, as they are now needed for
31 : // some parts of name resolution
32 : class CollectLangItems : public DefaultASTVisitor
33 : {
34 : public:
35 4510 : CollectLangItems () : mappings (Analysis::Mappings::get ()){};
36 :
37 4510 : void go (AST::Crate &crate) { DefaultASTVisitor::visit (crate); }
38 :
39 : Analysis::Mappings &mappings;
40 :
41 : // We must implement visitors for all constructs that could be lang items.
42 : // Lang items can be traits, but also enums, and even enum variants.
43 : //
44 : // https://github.com/rust-lang/rust/blob/master/compiler/rustc_hir/src/lang_items.rs
45 :
46 : using DefaultASTVisitor::visit;
47 :
48 : void visit (AST::Trait &item) override;
49 : void visit (AST::TraitItemType &item) override;
50 : void visit (AST::Function &item) override;
51 : void visit (AST::StructStruct &item) override;
52 : void visit (AST::EnumItem &item) override;
53 : void visit (AST::EnumItemTuple &item) override;
54 : void visit (AST::EnumItemStruct &item) override;
55 : void visit (AST::EnumItemDiscriminant &item) override;
56 :
57 : private:
58 : template <typename T> void maybe_add_lang_item (const T &item);
59 : };
60 :
61 : } // namespace AST
62 : } // namespace Rust
63 :
64 : #endif // ! RUST_COLLECT_LANG_ITEMS_H
|