aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-14 06:37:33 +0000
committerAleksey Kladov <[email protected]>2019-11-14 06:37:33 +0000
commitb3175b7077129ca4b6c52e05f0491e65617ae423 (patch)
treea76be37817ca3df2f55e79a237a8d38e5825dcb8 /crates/ra_hir_def/src/body
parentdebf95eb1b79a54ed482ea01f1716e5ff1faf0b6 (diff)
Move current file to MacroResolver
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 2aa863c9e..1a990101f 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -31,15 +31,15 @@ use crate::{
31pub(super) fn lower( 31pub(super) fn lower(
32 db: &impl DefDatabase2, 32 db: &impl DefDatabase2,
33 resolver: MacroResolver, 33 resolver: MacroResolver,
34 file_id: HirFileId,
35 params: Option<ast::ParamList>, 34 params: Option<ast::ParamList>,
36 body: Option<ast::Expr>, 35 body: Option<ast::Expr>,
37) -> (Body, BodySourceMap) { 36) -> (Body, BodySourceMap) {
37 let original_file_id = resolver.current_file_id;
38
38 ExprCollector { 39 ExprCollector {
39 resolver, 40 resolver,
40 db, 41 db,
41 original_file_id: file_id, 42 original_file_id,
42 current_file_id: file_id,
43 source_map: BodySourceMap::default(), 43 source_map: BodySourceMap::default(),
44 body: Body { 44 body: Body {
45 exprs: Arena::default(), 45 exprs: Arena::default(),
@@ -55,7 +55,6 @@ struct ExprCollector<DB> {
55 db: DB, 55 db: DB,
56 resolver: MacroResolver, 56 resolver: MacroResolver,
57 original_file_id: HirFileId, 57 original_file_id: HirFileId,
58 current_file_id: HirFileId,
59 58
60 body: Body, 59 body: Body,
61 source_map: BodySourceMap, 60 source_map: BodySourceMap,
@@ -101,12 +100,12 @@ where
101 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { 100 fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
102 let ptr = Either::A(ptr); 101 let ptr = Either::A(ptr);
103 let id = self.body.exprs.alloc(expr); 102 let id = self.body.exprs.alloc(expr);
104 if self.current_file_id == self.original_file_id { 103 if self.resolver.current_file_id == self.original_file_id {
105 self.source_map.expr_map.insert(ptr, id); 104 self.source_map.expr_map.insert(ptr, id);
106 } 105 }
107 self.source_map 106 self.source_map
108 .expr_map_back 107 .expr_map_back
109 .insert(id, Source { file_id: self.current_file_id, ast: ptr }); 108 .insert(id, Source { file_id: self.resolver.current_file_id, ast: ptr });
110 id 109 id
111 } 110 }
112 // desugared exprs don't have ptr, that's wrong and should be fixed 111 // desugared exprs don't have ptr, that's wrong and should be fixed
@@ -117,20 +116,22 @@ where
117 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { 116 fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId {
118 let ptr = Either::B(ptr); 117 let ptr = Either::B(ptr);
119 let id = self.body.exprs.alloc(expr); 118 let id = self.body.exprs.alloc(expr);
120 if self.current_file_id == self.original_file_id { 119 if self.resolver.current_file_id == self.original_file_id {
121 self.source_map.expr_map.insert(ptr, id); 120 self.source_map.expr_map.insert(ptr, id);
122 } 121 }
123 self.source_map 122 self.source_map
124 .expr_map_back 123 .expr_map_back
125 .insert(id, Source { file_id: self.current_file_id, ast: ptr }); 124 .insert(id, Source { file_id: self.resolver.current_file_id, ast: ptr });
126 id 125 id
127 } 126 }
128 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { 127 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
129 let id = self.body.pats.alloc(pat); 128 let id = self.body.pats.alloc(pat);
130 if self.current_file_id == self.original_file_id { 129 if self.resolver.current_file_id == self.original_file_id {
131 self.source_map.pat_map.insert(ptr, id); 130 self.source_map.pat_map.insert(ptr, id);
132 } 131 }
133 self.source_map.pat_map_back.insert(id, Source { file_id: self.current_file_id, ast: ptr }); 132 self.source_map
133 .pat_map_back
134 .insert(id, Source { file_id: self.resolver.current_file_id, ast: ptr });
134 id 135 id
135 } 136 }
136 137
@@ -445,8 +446,8 @@ where
445 ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 446 ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
446 ast::Expr::MacroCall(e) => { 447 ast::Expr::MacroCall(e) => {
447 let ast_id = AstId::new( 448 let ast_id = AstId::new(
448 self.current_file_id, 449 self.resolver.current_file_id,
449 self.db.ast_id_map(self.current_file_id).ast_id(&e), 450 self.db.ast_id_map(self.resolver.current_file_id).ast_id(&e),
450 ); 451 );
451 452
452 if let Some(path) = e.path().and_then(|path| self.parse_path(path)) { 453 if let Some(path) = e.path().and_then(|path| self.parse_path(path)) {
@@ -457,9 +458,9 @@ where
457 if let Some(expr) = ast::Expr::cast(node) { 458 if let Some(expr) = ast::Expr::cast(node) {
458 log::debug!("macro expansion {:#?}", expr.syntax()); 459 log::debug!("macro expansion {:#?}", expr.syntax());
459 let old_file_id = 460 let old_file_id =
460 std::mem::replace(&mut self.current_file_id, file_id); 461 std::mem::replace(&mut self.resolver.current_file_id, file_id);
461 let id = self.collect_expr(expr); 462 let id = self.collect_expr(expr);
462 self.current_file_id = old_file_id; 463 self.resolver.current_file_id = old_file_id;
463 return id; 464 return id;
464 } 465 }
465 } 466 }
@@ -581,7 +582,7 @@ where
581 } 582 }
582 583
583 fn parse_path(&mut self, path: ast::Path) -> Option<Path> { 584 fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
584 let hygiene = Hygiene::new(self.db, self.current_file_id); 585 let hygiene = Hygiene::new(self.db, self.resolver.current_file_id);
585 Path::from_src(path, &hygiene) 586 Path::from_src(path, &hygiene)
586 } 587 }
587} 588}