aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-20 10:56:59 +0000
committerGitHub <[email protected]>2019-12-20 10:56:59 +0000
commit6e9335d311c058986c4bbef5aadbe208b87f63c7 (patch)
tree00ecd85453675103fe415a7b28c565a2a9e94853 /crates/ra_hir_def/src/body
parent08c6933104baca84fd4135a76cdc7daf60a0c631 (diff)
parent67c2aea182c375108ebb8b923f5679e4f7fef1df (diff)
Merge #2607
2607: More ground work for local defs r=matklad a=matklad bors r+ Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 86960186f..17efa10e2 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -2,11 +2,12 @@
2//! representation. 2//! representation.
3 3
4use either::Either; 4use either::Either;
5
5use hir_expand::name::{name, AsName, Name}; 6use hir_expand::name::{name, AsName, Name};
6use ra_arena::Arena; 7use ra_arena::Arena;
7use ra_syntax::{ 8use ra_syntax::{
8 ast::{ 9 ast::{
9 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, NameOwner, 10 self, ArgListOwner, ArrayExprKind, LiteralKind, LoopBodyOwner, ModuleItemOwner, NameOwner,
10 TypeAscriptionOwner, 11 TypeAscriptionOwner,
11 }, 12 },
12 AstNode, AstPtr, 13 AstNode, AstPtr,
@@ -24,17 +25,20 @@ use crate::{
24 path::GenericArgs, 25 path::GenericArgs,
25 path::Path, 26 path::Path,
26 type_ref::{Mutability, TypeRef}, 27 type_ref::{Mutability, TypeRef},
28 ContainerId, DefWithBodyId, FunctionLoc, Intern,
27}; 29};
28 30
29pub(super) fn lower( 31pub(super) fn lower(
30 db: &impl DefDatabase, 32 db: &impl DefDatabase,
33 def: DefWithBodyId,
31 expander: Expander, 34 expander: Expander,
32 params: Option<ast::ParamList>, 35 params: Option<ast::ParamList>,
33 body: Option<ast::Expr>, 36 body: Option<ast::Expr>,
34) -> (Body, BodySourceMap) { 37) -> (Body, BodySourceMap) {
35 ExprCollector { 38 ExprCollector {
36 expander,
37 db, 39 db,
40 def,
41 expander,
38 source_map: BodySourceMap::default(), 42 source_map: BodySourceMap::default(),
39 body: Body { 43 body: Body {
40 exprs: Arena::default(), 44 exprs: Arena::default(),
@@ -49,6 +53,7 @@ pub(super) fn lower(
49 53
50struct ExprCollector<DB> { 54struct ExprCollector<DB> {
51 db: DB, 55 db: DB,
56 def: DefWithBodyId,
52 expander: Expander, 57 expander: Expander,
53 58
54 body: Body, 59 body: Body,
@@ -467,6 +472,7 @@ where
467 Some(block) => block, 472 Some(block) => block,
468 None => return self.alloc_expr(Expr::Missing, syntax_node_ptr), 473 None => return self.alloc_expr(Expr::Missing, syntax_node_ptr),
469 }; 474 };
475 self.collect_block_items(&block);
470 let statements = block 476 let statements = block
471 .statements() 477 .statements()
472 .map(|s| match s { 478 .map(|s| match s {
@@ -483,6 +489,20 @@ where
483 self.alloc_expr(Expr::Block { statements, tail }, syntax_node_ptr) 489 self.alloc_expr(Expr::Block { statements, tail }, syntax_node_ptr)
484 } 490 }
485 491
492 fn collect_block_items(&mut self, block: &ast::Block) {
493 let container = ContainerId::DefWithBodyId(self.def);
494 for item in block.items() {
495 match item {
496 ast::ModuleItem::FnDef(def) => {
497 let ast_id = self.expander.ast_id(&def);
498 self.body.defs.push(FunctionLoc { container, ast_id }.intern(self.db).into())
499 }
500 // FIXME: handle other items
501 _ => (),
502 }
503 }
504 }
505
486 fn collect_block_opt(&mut self, expr: Option<ast::BlockExpr>) -> ExprId { 506 fn collect_block_opt(&mut self, expr: Option<ast::BlockExpr>) -> ExprId {
487 if let Some(block) = expr { 507 if let Some(block) = expr {
488 self.collect_block(block) 508 self.collect_block(block)