Line data Source code
1 : // Copyright (C) 2020-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_HIR_TYPE_CHECK_ITEM
20 : #define RUST_HIR_TYPE_CHECK_ITEM
21 :
22 : #include "rust-hir-type-check-base.h"
23 : #include "rust-hir-visitor.h"
24 :
25 : namespace Rust {
26 : namespace Resolver {
27 :
28 24372 : class TypeCheckItem : private TypeCheckBase, private HIR::HIRVisItemVisitor
29 : {
30 : public:
31 : static TyTy::BaseType *Resolve (HIR::Item &item);
32 :
33 : static TyTy::FnType *ResolveFunctionSignature (HIR::Function &function);
34 :
35 : static TyTy::BaseType *ResolveTraitSignature (HIR::Trait &trait);
36 :
37 : static TyTy::BaseType *ResolveImplItem (HIR::ImplBlock &impl_block,
38 : HIR::ImplItem &item);
39 :
40 : static TyTy::BaseType *ResolveImplBlockSelf (HIR::ImplBlock &impl_block);
41 :
42 : static TyTy::BaseType *ResolveImplBlockSelfWithInference (
43 : HIR::ImplBlock &impl, location_t locus,
44 : TyTy::SubstitutionArgumentMappings *infer_arguments);
45 :
46 : static std::vector<TyTy::SubstitutionParamMapping>
47 : ResolveImplBlockSubstitutions (HIR::ImplBlock &impl_block,
48 : bool &failure_flag);
49 :
50 : static void ResolveImplTraitAssociatedTypes (
51 : TypeCheckContext *context, HIR::ImplBlock &impl_block,
52 : TyTy::TypeBoundPredicate &specified_bound, TyTy::BaseType *self,
53 : std::vector<TyTy::SubstitutionParamMapping> &substitutions,
54 : std::map<DefId, AssocTypeEntry> &assoc_types_by_trait_item,
55 : std::vector<const TraitItemReference *> &trait_item_refs);
56 :
57 : void visit (HIR::Module &module) override;
58 : void visit (HIR::Function &function) override;
59 : void visit (HIR::TypeAlias &alias) override;
60 : void visit (HIR::TupleStruct &struct_decl) override;
61 : void visit (HIR::StructStruct &struct_decl) override;
62 : void visit (HIR::Enum &enum_decl) override;
63 : void visit (HIR::Union &union_decl) override;
64 : void visit (HIR::StaticItem &var) override;
65 : void visit (HIR::ConstantItem &constant) override;
66 : void visit (HIR::ImplBlock &impl_block) override;
67 : void visit (HIR::ExternBlock &extern_block) override;
68 : void visit (HIR::Trait &trait_block) override;
69 : void visit (HIR::ExternCrate &extern_crate) override;
70 :
71 : // nothing to do
72 0 : void visit (HIR::UseDeclaration &) override {}
73 :
74 : protected:
75 : void resolve_impl_block (HIR::ImplBlock &impl_block);
76 : void resolve_trait_impl_block (HIR::ImplBlock &impl_block);
77 :
78 : std::pair<std::vector<TyTy::SubstitutionParamMapping>,
79 : TyTy::RegionConstraints>
80 : resolve_impl_block_substitutions (HIR::ImplBlock &impl_block,
81 : bool &failure_flag);
82 :
83 : void validate_trait_impl_block (
84 : const TyTy::TypeBoundPredicate &specified_bound,
85 : std::vector<const TraitItemReference *> trait_item_refs,
86 : TraitReference *trait_reference, HIR::ImplBlock &impl_block,
87 : TyTy::BaseType *self,
88 : std::vector<TyTy::SubstitutionParamMapping> &substitutions);
89 :
90 : TyTy::BaseType *resolve_impl_item (HIR::ImplBlock &impl_block,
91 : HIR::ImplItem &item);
92 :
93 : TyTy::BaseType *resolve_impl_block_self (HIR::ImplBlock &impl_block);
94 :
95 : TyTy::FnType *resolve_function_signature (HIR::Function &function);
96 :
97 : TyTy::BaseType *resolve_trait (HIR::Trait &trait, bool resolve_bodies);
98 :
99 : bool validate_repr_simd (const std::vector<TyTy::StructFieldType *> &fields,
100 : location_t locus);
101 :
102 : private:
103 : TypeCheckItem ();
104 :
105 : TyTy::BaseType *infered;
106 : };
107 :
108 : } // namespace Resolver
109 : } // namespace Rust
110 :
111 : #endif // RUST_HIR_TYPE_CHECK_ITEM
|