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_HIR_TYPE_CHECK_IMPLITEM_H
20 : : #define RUST_HIR_TYPE_CHECK_IMPLITEM_H
21 : :
22 : : #include "rust-hir-type-check-base.h"
23 : : #include "rust-hir-visitor.h"
24 : :
25 : : namespace Rust {
26 : : namespace Resolver {
27 : :
28 : 1590 : class TypeCheckTopLevelExternItem : public TypeCheckBase,
29 : : public HIR::HIRExternalItemVisitor
30 : : {
31 : : public:
32 : : static TyTy::BaseType *Resolve (HIR::ExternalItem *item,
33 : : const HIR::ExternBlock &parent);
34 : :
35 : : void visit (HIR::ExternalStaticItem &item) override;
36 : : void visit (HIR::ExternalFunctionItem &function) override;
37 : :
38 : : private:
39 : : TypeCheckTopLevelExternItem (const HIR::ExternBlock &parent);
40 : :
41 : : const HIR::ExternBlock &parent;
42 : : TyTy::BaseType *resolved;
43 : : };
44 : :
45 : 4097 : class TypeCheckImplItem : public TypeCheckBase, public HIR::HIRImplVisitor
46 : : {
47 : : public:
48 : : static TyTy::BaseType *
49 : : Resolve (HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self,
50 : : std::vector<TyTy::SubstitutionParamMapping> substitutions);
51 : :
52 : : void visit (HIR::Function &function) override;
53 : : void visit (HIR::ConstantItem &const_item) override;
54 : : void visit (HIR::TypeAlias &type_alias) override;
55 : :
56 : : protected:
57 : : TypeCheckImplItem (HIR::ImplBlock *parent, TyTy::BaseType *self,
58 : : std::vector<TyTy::SubstitutionParamMapping> substitutions);
59 : :
60 : : HIR::ImplBlock *parent;
61 : : TyTy::BaseType *self;
62 : : std::vector<TyTy::SubstitutionParamMapping> substitutions;
63 : :
64 : : TyTy::BaseType *result = nullptr;
65 : : };
66 : :
67 : : class TypeCheckImplItemWithTrait : public TypeCheckBase,
68 : : public HIR::HIRImplVisitor
69 : : {
70 : : public:
71 : : static TyTy::TypeBoundPredicateItem
72 : : Resolve (HIR::ImplBlock *parent, HIR::ImplItem *item, TyTy::BaseType *self,
73 : : TyTy::TypeBoundPredicate &trait_reference,
74 : : std::vector<TyTy::SubstitutionParamMapping> substitutions);
75 : :
76 : : void visit (HIR::ConstantItem &constant) override;
77 : : void visit (HIR::TypeAlias &type) override;
78 : : void visit (HIR::Function &function) override;
79 : :
80 : : protected:
81 : : // this allows us to inherit the must_use specified on a trait definition onto
82 : : // its implementation
83 : : void merge_attributes (AST::AttrVec &impl_item_attrs,
84 : : const HIR::TraitItem &trait_item);
85 : :
86 : : private:
87 : : TypeCheckImplItemWithTrait (
88 : : HIR::ImplBlock *parent, TyTy::BaseType *self,
89 : : TyTy::TypeBoundPredicate &trait_reference,
90 : : std::vector<TyTy::SubstitutionParamMapping> substitutions);
91 : :
92 : : bool is_trait_impl_block () const;
93 : :
94 : : TyTy::TypeBoundPredicate &trait_reference;
95 : : TyTy::TypeBoundPredicateItem resolved_trait_item;
96 : :
97 : : HIR::ImplBlock *parent;
98 : : TyTy::BaseType *self;
99 : : std::vector<TyTy::SubstitutionParamMapping> substitutions;
100 : : TyTy::RegionConstraints region_constraints;
101 : : };
102 : :
103 : : } // namespace Resolver
104 : : } // namespace Rust
105 : :
106 : : #endif // RUST_HIR_TYPE_CHECK_IMPLITEM_H
|