@@ -230,6 +230,91 @@ class ASTLoweringStmt : public ASTLoweringBase
230
230
empty.get_locus ());
231
231
}
232
232
233
+ void visit (AST::Function &function) override
234
+ {
235
+ // ignore for now and leave empty
236
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
237
+ HIR::WhereClause where_clause (std::move (where_clause_items));
238
+ HIR::FunctionQualifiers qualifiers (
239
+ HIR::FunctionQualifiers::AsyncConstStatus::NONE, false );
240
+ HIR::Visibility vis = HIR::Visibility::create_public ();
241
+
242
+ // need
243
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
244
+ if (function.has_generics ())
245
+ {
246
+ generic_params = lower_generic_params (function.get_generic_params ());
247
+ }
248
+
249
+ Identifier function_name = function.get_function_name ();
250
+ Location locus = function.get_locus ();
251
+
252
+ std::unique_ptr<HIR::Type> return_type
253
+ = function.has_return_type () ? std::unique_ptr<HIR::Type> (
254
+ ASTLoweringType::translate (function.get_return_type ().get ()))
255
+ : nullptr ;
256
+
257
+ std::vector<HIR::FunctionParam> function_params;
258
+ for (auto ¶m : function.get_function_params ())
259
+ {
260
+ auto translated_pattern = std::unique_ptr<HIR::Pattern> (
261
+ ASTLoweringPattern::translate (param.get_pattern ().get ()));
262
+ auto translated_type = std::unique_ptr<HIR::Type> (
263
+ ASTLoweringType::translate (param.get_type ().get ()));
264
+
265
+ auto crate_num = mappings->get_current_crate ();
266
+ Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
267
+ mappings->get_next_hir_id (crate_num),
268
+ UNKNOWN_LOCAL_DEFID);
269
+
270
+ auto hir_param
271
+ = HIR::FunctionParam (mapping, std::move (translated_pattern),
272
+ std::move (translated_type),
273
+ param.get_locus ());
274
+ function_params.push_back (hir_param);
275
+ }
276
+
277
+ bool terminated = false ;
278
+ std::unique_ptr<HIR::BlockExpr> function_body
279
+ = std::unique_ptr<HIR::BlockExpr> (
280
+ ASTLoweringBlock::translate (function.get_definition ().get (),
281
+ &terminated));
282
+
283
+ auto crate_num = mappings->get_current_crate ();
284
+ Analysis::NodeMapping mapping (crate_num, function.get_node_id (),
285
+ mappings->get_next_hir_id (crate_num),
286
+ UNKNOWN_LOCAL_DEFID);
287
+
288
+ mappings->insert_location (crate_num,
289
+ function_body->get_mappings ().get_hirid (),
290
+ function.get_locus ());
291
+
292
+ auto fn
293
+ = new HIR::Function (mapping, std::move (function_name),
294
+ std::move (qualifiers), std::move (generic_params),
295
+ std::move (function_params), std::move (return_type),
296
+ std::move (where_clause), std::move (function_body),
297
+ std::move (vis), function.get_outer_attrs (), locus);
298
+
299
+ mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (),
300
+ fn);
301
+ mappings->insert_hir_stmt (mapping.get_crate_num (), mapping.get_hirid (),
302
+ fn);
303
+ mappings->insert_location (crate_num, mapping.get_hirid (),
304
+ function.get_locus ());
305
+
306
+ // add the mappings for the function params at the end
307
+ for (auto ¶m : fn->get_function_params ())
308
+ {
309
+ mappings->insert_hir_param (mapping.get_crate_num (),
310
+ param.get_mappings ().get_hirid (), ¶m);
311
+ mappings->insert_location (crate_num, mapping.get_hirid (),
312
+ param.get_locus ());
313
+ }
314
+
315
+ translated = fn;
316
+ }
317
+
233
318
private:
234
319
ASTLoweringStmt () : translated (nullptr ), terminated (false ) {}
235
320
0 commit comments