Debian Codegraph @

gcc/rust/typecheck/rust-hir-type-check-type.h

raw
1 // Copyright (C) 2020-2025 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_TYPE
20 #define RUST_HIR_TYPE_CHECK_TYPE
21
22 #include "rust-hir-type-check-base.h"
23 #include "rust-hir-visitor.h"
24
25 namespace Rust {
26 namespace Resolver {
27
28 // FIXME
29 // This simply fetches the HIR:::GenericArgs from the base class. Check to see
30 // if we can get rid of this class
31 class TypeCheckResolveGenericArguments : public TypeCheckBase
32 {
33 public:
34 static HIR::GenericArgs resolve (HIR::TypePathSegment &segment);
35
36 void visit (HIR::TypePathSegmentGeneric &generic);
37
38 private:
39 TypeCheckResolveGenericArguments (location_t locus)
40 : TypeCheckBase (), args (HIR::GenericArgs::create_empty (locus))
41 {}
42
43 HIR::GenericArgs args;
44 };
45
46 class TypeCheckType : public TypeCheckBase, public HIR::HIRTypeVisitor
47 {
48 public:
49 static TyTy::BaseType *Resolve (HIR::Type &type);
50
51 void visit (HIR::BareFunctionType &fntype) override;
52 void visit (HIR::TupleType &tuple) override;
53 void visit (HIR::TypePath &path) override;
54 void visit (HIR::QualifiedPathInType &path) override;
55 void visit (HIR::ArrayType &type) override;
56 void visit (HIR::SliceType &type) override;
57 void visit (HIR::ReferenceType &type) override;
58 void visit (HIR::RawPointerType &type) override;
59 void visit (HIR::InferredType &type) override;
60 void visit (HIR::NeverType &type) override;
61 void visit (HIR::TraitObjectType &type) override;
62 void visit (HIR::ParenthesisedType &type) override;
63 void visit (HIR::ImplTraitType &type) override;
64
65 // These dont need to be implemented as they are segments or part of types
66 void visit (HIR::TypePathSegmentFunction &segment) override {}
67 void visit (HIR::TraitBound &bound) override {}
68
69 private:
70 TypeCheckType (HirId id)
71 : TypeCheckBase (), translated (new TyTy::ErrorType (id))
72 {}
73
74 TyTy::BaseType *resolve_root_path (HIR::TypePath &path, size_t *offset,
75 bool *wasBigSelf);
76
77 TyTy::BaseType *resolve_segments (
78 HirId expr_id, std::vector<std::unique_ptr<HIR::TypePathSegment>> &segments,
79 size_t offset, TyTy::BaseType *tyseg,
80 const Analysis::NodeMapping &expr_mappings, location_t expr_locus,
81 bool tySegIsBigSelf);
82
83 bool resolve_associated_type (const std::string &search,
84 TypeCheckBlockContextItem &ctx,
85 TyTy::BaseType **result);
86
87 TyTy::BaseType *translated;
88 };
89
90 class TypeResolveGenericParam : public TypeCheckBase
91 {
92 public:
93 static TyTy::ParamType *Resolve (HIR::GenericParam &param,
94 bool resolve_trait_bounds = true,
95 bool apply_sized = true);
96
97 static void ApplyAnyTraitBounds (HIR::TypeParam &param, TyTy::ParamType *pty);
98
99 protected:
100 void visit (HIR::TypeParam &param);
101 void visit (HIR::LifetimeParam &param);
102 void visit (HIR::ConstGenericParam &param);
103
104 void apply_trait_bounds (HIR::TypeParam &param, TyTy::ParamType *pty);
105
106 private:
107 TypeResolveGenericParam (bool apply_sized, bool resolve_trait_bounds)
108 : TypeCheckBase (), resolved (nullptr), apply_sized (apply_sized),
109 resolve_trait_bounds (resolve_trait_bounds)
110 {}
111
112 TyTy::ParamType *resolved;
113 bool apply_sized;
114 bool resolve_trait_bounds;
115 };
116
117 class ResolveWhereClauseItem : public TypeCheckBase
118 {
119 // pair(a, b) => a: b
120 TyTy::RegionConstraints &region_constraints;
121
122 public:
123 static void Resolve (HIR::WhereClauseItem &item,
124 TyTy::RegionConstraints &region_constraints);
125
126 protected:
127 void visit (HIR::LifetimeWhereClauseItem &item);
128 void visit (HIR::TypeBoundWhereClauseItem &item);
129
130 private:
131 ResolveWhereClauseItem (TyTy::RegionConstraints &region_constraints)
132 : region_constraints (region_constraints)
133 {}
134 };
135
136 } // namespace Resolver
137 } // namespace Rust
138
139 #endif // RUST_HIR_TYPE_CHECK_TYPE