aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/expr.rs4
-rw-r--r--crates/ra_hir_def/src/body.rs16
-rw-r--r--crates/ra_hir_def/src/body/lower.rs34
3 files changed, 25 insertions, 29 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index d1af8ee39..d19f5d14c 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -40,8 +40,8 @@ pub(crate) fn body_with_source_map_query(
40 (src.file_id, src.ast.body()) 40 (src.file_id, src.ast.body())
41 } 41 }
42 }; 42 };
43 let resolver = hir_def::body::MacroResolver::new(db, file_id, def.module(db).id); 43 let expander = hir_def::body::Expander::new(db, file_id, def.module(db).id);
44 let (body, source_map) = Body::new(db, resolver, params, body); 44 let (body, source_map) = Body::new(db, expander, params, body);
45 (Arc::new(body), Arc::new(source_map)) 45 (Arc::new(body), Arc::new(source_map))
46} 46}
47 47
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 7e84e9113..5d8c299ba 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -16,20 +16,16 @@ use crate::{
16 ModuleId, 16 ModuleId,
17}; 17};
18 18
19pub struct MacroResolver { 19pub struct Expander {
20 crate_def_map: Arc<CrateDefMap>, 20 crate_def_map: Arc<CrateDefMap>,
21 current_file_id: HirFileId, 21 current_file_id: HirFileId,
22 module: ModuleId, 22 module: ModuleId,
23} 23}
24 24
25impl MacroResolver { 25impl Expander {
26 pub fn new( 26 pub fn new(db: &impl DefDatabase2, current_file_id: HirFileId, module: ModuleId) -> Expander {
27 db: &impl DefDatabase2,
28 current_file_id: HirFileId,
29 module: ModuleId,
30 ) -> MacroResolver {
31 let crate_def_map = db.crate_def_map(module.krate); 27 let crate_def_map = db.crate_def_map(module.krate);
32 MacroResolver { crate_def_map, current_file_id, module } 28 Expander { crate_def_map, current_file_id, module }
33 } 29 }
34 30
35 fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> { 31 fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option<MacroDefId> {
@@ -82,11 +78,11 @@ pub struct BodySourceMap {
82impl Body { 78impl Body {
83 pub fn new( 79 pub fn new(
84 db: &impl DefDatabase2, 80 db: &impl DefDatabase2,
85 resolver: MacroResolver, 81 expander: Expander,
86 params: Option<ast::ParamList>, 82 params: Option<ast::ParamList>,
87 body: Option<ast::Expr>, 83 body: Option<ast::Expr>,
88 ) -> (Body, BodySourceMap) { 84 ) -> (Body, BodySourceMap) {
89 lower::lower(db, resolver, params, body) 85 lower::lower(db, expander, params, body)
90 } 86 }
91 87
92 pub fn params(&self) -> &[PatId] { 88 pub fn params(&self) -> &[PatId] {
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 1a990101f..cc4bbe11a 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -16,7 +16,7 @@ use ra_syntax::{
16}; 16};
17 17
18use crate::{ 18use crate::{
19 body::{Body, BodySourceMap, MacroResolver, PatPtr}, 19 body::{Body, BodySourceMap, Expander, PatPtr},
20 builtin_type::{BuiltinFloat, BuiltinInt}, 20 builtin_type::{BuiltinFloat, BuiltinInt},
21 db::DefDatabase2, 21 db::DefDatabase2,
22 expr::{ 22 expr::{
@@ -30,14 +30,14 @@ use crate::{
30 30
31pub(super) fn lower( 31pub(super) fn lower(
32 db: &impl DefDatabase2, 32 db: &impl DefDatabase2,
33 resolver: MacroResolver, 33 expander: Expander,
34 params: Option<ast::ParamList>, 34 params: Option<ast::ParamList>,
35 body: Option<ast::Expr>, 35 body: Option<ast::Expr>,
36) -> (Body, BodySourceMap) { 36) -> (Body, BodySourceMap) {
37 let original_file_id = resolver.current_file_id; 37 let original_file_id = expander.current_file_id;
38 38
39 ExprCollector { 39 ExprCollector {
40 resolver, 40 expander,
41 db, 41 db,
42 original_file_id, 42 original_file_id,
43 source_map: BodySourceMap::default(), 43 source_map: BodySourceMap::default(),
@@ -53,7 +53,7 @@ pub(super) fn lower(
53 53
54struct ExprCollector<DB> { 54struct ExprCollector<DB> {
55 db: DB, 55 db: DB,
56 resolver: MacroResolver, 56 expander: Expander,
57 original_file_id: HirFileId, 57 original_file_id: HirFileId,
58 58
59 body: Body, 59 body: Body,
@@ -100,12 +100,12 @@ where
100 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 {
101 let ptr = Either::A(ptr); 101 let ptr = Either::A(ptr);
102 let id = self.body.exprs.alloc(expr); 102 let id = self.body.exprs.alloc(expr);
103 if self.resolver.current_file_id == self.original_file_id { 103 if self.expander.current_file_id == self.original_file_id {
104 self.source_map.expr_map.insert(ptr, id); 104 self.source_map.expr_map.insert(ptr, id);
105 } 105 }
106 self.source_map 106 self.source_map
107 .expr_map_back 107 .expr_map_back
108 .insert(id, Source { file_id: self.resolver.current_file_id, ast: ptr }); 108 .insert(id, Source { file_id: self.expander.current_file_id, ast: ptr });
109 id 109 id
110 } 110 }
111 // 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
@@ -116,22 +116,22 @@ where
116 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 {
117 let ptr = Either::B(ptr); 117 let ptr = Either::B(ptr);
118 let id = self.body.exprs.alloc(expr); 118 let id = self.body.exprs.alloc(expr);
119 if self.resolver.current_file_id == self.original_file_id { 119 if self.expander.current_file_id == self.original_file_id {
120 self.source_map.expr_map.insert(ptr, id); 120 self.source_map.expr_map.insert(ptr, id);
121 } 121 }
122 self.source_map 122 self.source_map
123 .expr_map_back 123 .expr_map_back
124 .insert(id, Source { file_id: self.resolver.current_file_id, ast: ptr }); 124 .insert(id, Source { file_id: self.expander.current_file_id, ast: ptr });
125 id 125 id
126 } 126 }
127 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { 127 fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId {
128 let id = self.body.pats.alloc(pat); 128 let id = self.body.pats.alloc(pat);
129 if self.resolver.current_file_id == self.original_file_id { 129 if self.expander.current_file_id == self.original_file_id {
130 self.source_map.pat_map.insert(ptr, id); 130 self.source_map.pat_map.insert(ptr, id);
131 } 131 }
132 self.source_map 132 self.source_map
133 .pat_map_back 133 .pat_map_back
134 .insert(id, Source { file_id: self.resolver.current_file_id, ast: ptr }); 134 .insert(id, Source { file_id: self.expander.current_file_id, ast: ptr });
135 id 135 id
136 } 136 }
137 137
@@ -446,21 +446,21 @@ where
446 ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 446 ast::Expr::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
447 ast::Expr::MacroCall(e) => { 447 ast::Expr::MacroCall(e) => {
448 let ast_id = AstId::new( 448 let ast_id = AstId::new(
449 self.resolver.current_file_id, 449 self.expander.current_file_id,
450 self.db.ast_id_map(self.resolver.current_file_id).ast_id(&e), 450 self.db.ast_id_map(self.expander.current_file_id).ast_id(&e),
451 ); 451 );
452 452
453 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)) {
454 if let Some(def) = self.resolver.resolve_path_as_macro(self.db, &path) { 454 if let Some(def) = self.expander.resolve_path_as_macro(self.db, &path) {
455 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id }); 455 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id });
456 let file_id = call_id.as_file(MacroFileKind::Expr); 456 let file_id = call_id.as_file(MacroFileKind::Expr);
457 if let Some(node) = self.db.parse_or_expand(file_id) { 457 if let Some(node) = self.db.parse_or_expand(file_id) {
458 if let Some(expr) = ast::Expr::cast(node) { 458 if let Some(expr) = ast::Expr::cast(node) {
459 log::debug!("macro expansion {:#?}", expr.syntax()); 459 log::debug!("macro expansion {:#?}", expr.syntax());
460 let old_file_id = 460 let old_file_id =
461 std::mem::replace(&mut self.resolver.current_file_id, file_id); 461 std::mem::replace(&mut self.expander.current_file_id, file_id);
462 let id = self.collect_expr(expr); 462 let id = self.collect_expr(expr);
463 self.resolver.current_file_id = old_file_id; 463 self.expander.current_file_id = old_file_id;
464 return id; 464 return id;
465 } 465 }
466 } 466 }
@@ -582,7 +582,7 @@ where
582 } 582 }
583 583
584 fn parse_path(&mut self, path: ast::Path) -> Option<Path> { 584 fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
585 let hygiene = Hygiene::new(self.db, self.resolver.current_file_id); 585 let hygiene = Hygiene::new(self.db, self.expander.current_file_id);
586 Path::from_src(path, &hygiene) 586 Path::from_src(path, &hygiene)
587 } 587 }
588} 588}