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