@@ -44,8 +44,6 @@ class ASTLoweringStmt : public ASTLoweringBase
44
44
return resolver.translated ;
45
45
}
46
46
47
- virtual ~ASTLoweringStmt () {}
48
-
49
47
void visit (AST::ExprStmtWithBlock &stmt) override
50
48
{
51
49
HIR::ExprWithBlock *expr
@@ -110,6 +108,128 @@ class ASTLoweringStmt : public ASTLoweringBase
110
108
mappings->insert_hir_stmt (crate_num, mapping.get_hirid (), translated);
111
109
}
112
110
111
+ void visit (AST::TupleStruct &struct_decl) override
112
+ {
113
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
114
+ if (struct_decl.has_generics ())
115
+ {
116
+ generic_params
117
+ = lower_generic_params (struct_decl.get_generic_params ());
118
+ }
119
+
120
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
121
+ HIR::WhereClause where_clause (std::move (where_clause_items));
122
+ HIR::Visibility vis = HIR::Visibility::create_public ();
123
+
124
+ std::vector<HIR::TupleField> fields;
125
+ struct_decl.iterate ([&] (AST::TupleField &field) mutable -> bool {
126
+ HIR::Visibility vis = HIR::Visibility::create_public ();
127
+ HIR::Type *type
128
+ = ASTLoweringType::translate (field.get_field_type ().get ());
129
+
130
+ auto crate_num = mappings->get_current_crate ();
131
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
132
+ mappings->get_next_hir_id (crate_num),
133
+ mappings->get_next_localdef_id (
134
+ crate_num));
135
+
136
+ // FIXME
137
+ // AST::TupleField is missing Location info
138
+ Location field_locus;
139
+ HIR::TupleField translated_field (mapping,
140
+ std::unique_ptr<HIR::Type> (type), vis,
141
+ field_locus, field.get_outer_attrs ());
142
+ fields.push_back (std::move (translated_field));
143
+ return true ;
144
+ });
145
+
146
+ auto crate_num = mappings->get_current_crate ();
147
+ Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
148
+ mappings->get_next_hir_id (crate_num),
149
+ mappings->get_next_localdef_id (crate_num));
150
+
151
+ translated = new HIR::TupleStruct (mapping, std::move (fields),
152
+ struct_decl.get_identifier (),
153
+ std::move (generic_params),
154
+ std::move (where_clause), vis,
155
+ struct_decl.get_outer_attrs (),
156
+ struct_decl.get_locus ());
157
+
158
+ mappings->insert_hir_stmt (mapping.get_crate_num (), mapping.get_hirid (),
159
+ translated);
160
+ mappings->insert_location (crate_num, mapping.get_hirid (),
161
+ struct_decl.get_locus ());
162
+ }
163
+
164
+ void visit (AST::StructStruct &struct_decl) override
165
+ {
166
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
167
+ if (struct_decl.has_generics ())
168
+ {
169
+ generic_params
170
+ = lower_generic_params (struct_decl.get_generic_params ());
171
+ }
172
+
173
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
174
+ HIR::WhereClause where_clause (std::move (where_clause_items));
175
+ HIR::Visibility vis = HIR::Visibility::create_public ();
176
+
177
+ bool is_unit = struct_decl.is_unit_struct ();
178
+ std::vector<HIR::StructField> fields;
179
+ struct_decl.iterate ([&] (AST::StructField &field) mutable -> bool {
180
+ HIR::Visibility vis = HIR::Visibility::create_public ();
181
+ HIR::Type *type
182
+ = ASTLoweringType::translate (field.get_field_type ().get ());
183
+
184
+ auto crate_num = mappings->get_current_crate ();
185
+ Analysis::NodeMapping mapping (crate_num, field.get_node_id (),
186
+ mappings->get_next_hir_id (crate_num),
187
+ mappings->get_next_localdef_id (
188
+ crate_num));
189
+
190
+ // FIXME
191
+ // AST::StructField is missing Location info
192
+ Location field_locus;
193
+ HIR::StructField translated_field (mapping, field.get_field_name (),
194
+ std::unique_ptr<HIR::Type> (type), vis,
195
+ field_locus, field.get_outer_attrs ());
196
+ fields.push_back (std::move (translated_field));
197
+ return true ;
198
+ });
199
+
200
+ auto crate_num = mappings->get_current_crate ();
201
+ Analysis::NodeMapping mapping (crate_num, struct_decl.get_node_id (),
202
+ mappings->get_next_hir_id (crate_num),
203
+ mappings->get_next_localdef_id (crate_num));
204
+
205
+ translated = new HIR::StructStruct (mapping, std::move (fields),
206
+ struct_decl.get_identifier (),
207
+ std::move (generic_params),
208
+ std::move (where_clause), is_unit, vis,
209
+ struct_decl.get_outer_attrs (),
210
+ struct_decl.get_locus ());
211
+
212
+ mappings->insert_hir_stmt (mapping.get_crate_num (), mapping.get_hirid (),
213
+ translated);
214
+ mappings->insert_location (crate_num, mapping.get_hirid (),
215
+ struct_decl.get_locus ());
216
+ }
217
+
218
+ void visit (AST::EmptyStmt &empty) override
219
+ {
220
+ auto crate_num = mappings->get_current_crate ();
221
+ Analysis::NodeMapping mapping (crate_num, empty.get_node_id (),
222
+ mappings->get_next_hir_id (crate_num),
223
+ mappings->get_next_localdef_id (crate_num));
224
+
225
+ translated = new HIR::EmptyStmt (mapping, empty.get_locus ());
226
+
227
+ mappings->insert_hir_stmt (mapping.get_crate_num (), mapping.get_hirid (),
228
+ translated);
229
+ mappings->insert_location (crate_num, mapping.get_hirid (),
230
+ empty.get_locus ());
231
+ }
232
+
113
233
private:
114
234
ASTLoweringStmt () : translated (nullptr ), terminated (false ) {}
115
235
0 commit comments