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_AST_LOWER_TYPE
20 : #define RUST_AST_LOWER_TYPE
21 :
22 : #include "rust-ast-lower-base.h"
23 : #include "rust-ast-lower-expr.h"
24 : #include "rust-hir-path.h"
25 : #include "rust-type.h"
26 :
27 : namespace Rust {
28 : namespace HIR {
29 :
30 53465 : class ASTLowerTypePath : public ASTLoweringBase
31 : {
32 : protected:
33 : using Rust::HIR::ASTLoweringBase::visit;
34 :
35 : public:
36 : static HIR::TypePath *translate (AST::TypePath &type);
37 :
38 : void visit (AST::TypePathSegmentFunction &segment) override;
39 : void visit (AST::TypePathSegment &segment) override;
40 : void visit (AST::TypePathSegmentGeneric &segment) override;
41 : void visit (AST::TypePath &path) override;
42 :
43 : protected:
44 : HIR::TypePathSegment *translated_segment;
45 :
46 : private:
47 : HIR::TypePath *translated;
48 : };
49 :
50 242 : class ASTLowerQualifiedPathInType : public ASTLowerTypePath
51 : {
52 : using ASTLowerTypePath::visit;
53 :
54 : public:
55 : static HIR::QualifiedPathInType *translate (AST::QualifiedPathInType &type);
56 :
57 : void visit (AST::QualifiedPathInType &path) override;
58 :
59 : private:
60 : HIR::QualifiedPathInType *translated;
61 : };
62 :
63 60165 : class ASTLoweringType : public ASTLoweringBase
64 : {
65 : using Rust::HIR::ASTLoweringBase::visit;
66 :
67 : public:
68 : static HIR::Type *translate (AST::Type &type,
69 : bool default_to_static_lifetime = false,
70 : bool impl_trait_allowed = false);
71 :
72 : void visit (AST::BareFunctionType &fntype) override;
73 : void visit (AST::TupleType &tuple) override;
74 : void visit (AST::TypePath &path) override;
75 : void visit (AST::QualifiedPathInType &path) override;
76 : void visit (AST::ArrayType &type) override;
77 : void visit (AST::ReferenceType &type) override;
78 : void visit (AST::RawPointerType &type) override;
79 : void visit (AST::SliceType &type) override;
80 : void visit (AST::InferredType &type) override;
81 : void visit (AST::NeverType &type) override;
82 : void visit (AST::TraitObjectTypeOneBound &type) override;
83 : void visit (AST::TraitObjectType &type) override;
84 : void visit (AST::ParenthesisedType &type) override;
85 : void visit (AST::ImplTraitType &type) override;
86 : void visit (AST::ImplTraitTypeOneBound &type) override;
87 :
88 : void emit_impl_trait_error (location_t locus);
89 :
90 : private:
91 : ASTLoweringType (bool default_to_static_lifetime, bool impl_trait_allowed);
92 :
93 : /** Used when compiling const and static items. */
94 : bool default_to_static_lifetime;
95 : bool impl_trait_allowed;
96 :
97 : HIR::Type *translated;
98 : };
99 :
100 8369 : class ASTLowerGenericParam : public ASTLoweringBase
101 : {
102 : using Rust::HIR::ASTLoweringBase::visit;
103 :
104 : public:
105 : static HIR::GenericParam *translate (AST::GenericParam ¶m);
106 :
107 : void visit (AST::LifetimeParam ¶m) override;
108 : void visit (AST::ConstGenericParam ¶m) override;
109 : void visit (AST::TypeParam ¶m) override;
110 :
111 : private:
112 8369 : ASTLowerGenericParam () : ASTLoweringBase (), translated (nullptr) {}
113 :
114 : HIR::GenericParam *translated;
115 : };
116 :
117 1828 : class ASTLoweringTypeBounds : public ASTLoweringBase
118 : {
119 : using Rust::HIR::ASTLoweringBase::visit;
120 :
121 : public:
122 : static HIR::TypeParamBound *translate (AST::TypeParamBound &type);
123 :
124 : void visit (AST::TraitBound &bound) override;
125 : void visit (AST::Lifetime &bound) override;
126 :
127 : private:
128 1828 : ASTLoweringTypeBounds () : ASTLoweringBase (), translated (nullptr) {}
129 :
130 : HIR::TypeParamBound *translated;
131 : };
132 :
133 143 : class ASTLowerWhereClauseItem : public ASTLoweringBase
134 : {
135 : using Rust::HIR::ASTLoweringBase::visit;
136 :
137 : public:
138 : static HIR::WhereClauseItem *translate (AST::WhereClauseItem &item);
139 :
140 : void visit (AST::LifetimeWhereClauseItem &item) override;
141 : void visit (AST::TypeBoundWhereClauseItem &item) override;
142 :
143 : private:
144 143 : ASTLowerWhereClauseItem () : ASTLoweringBase (), translated (nullptr) {}
145 :
146 : HIR::WhereClauseItem *translated;
147 : };
148 :
149 : } // namespace HIR
150 : } // namespace Rust
151 :
152 : #endif // RUST_AST_LOWER_TYPE
|