aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/body.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/body.rs')
-rw-r--r--crates/ra_hir_def/src/body.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 401fe0b9b..a92c01f86 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -23,7 +23,7 @@ use crate::{
23 DefWithBodyId, HasModule, Lookup, ModuleDefId, ModuleId, 23 DefWithBodyId, HasModule, Lookup, ModuleDefId, ModuleId,
24}; 24};
25 25
26struct Expander { 26pub(crate) struct Expander {
27 crate_def_map: Arc<CrateDefMap>, 27 crate_def_map: Arc<CrateDefMap>,
28 current_file_id: HirFileId, 28 current_file_id: HirFileId,
29 hygiene: Hygiene, 29 hygiene: Hygiene,
@@ -32,18 +32,22 @@ struct Expander {
32} 32}
33 33
34impl Expander { 34impl Expander {
35 fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { 35 pub(crate) fn new(
36 db: &impl DefDatabase,
37 current_file_id: HirFileId,
38 module: ModuleId,
39 ) -> Expander {
36 let crate_def_map = db.crate_def_map(module.krate); 40 let crate_def_map = db.crate_def_map(module.krate);
37 let hygiene = Hygiene::new(db, current_file_id); 41 let hygiene = Hygiene::new(db, current_file_id);
38 let ast_id_map = db.ast_id_map(current_file_id); 42 let ast_id_map = db.ast_id_map(current_file_id);
39 Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module } 43 Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module }
40 } 44 }
41 45
42 fn enter_expand( 46 pub(crate) fn enter_expand<T: ast::AstNode, DB: DefDatabase>(
43 &mut self, 47 &mut self,
44 db: &impl DefDatabase, 48 db: &DB,
45 macro_call: ast::MacroCall, 49 macro_call: ast::MacroCall,
46 ) -> Option<(Mark, ast::Expr)> { 50 ) -> Option<(Mark, T)> {
47 let ast_id = AstId::new( 51 let ast_id = AstId::new(
48 self.current_file_id, 52 self.current_file_id,
49 db.ast_id_map(self.current_file_id).ast_id(&macro_call), 53 db.ast_id_map(self.current_file_id).ast_id(&macro_call),
@@ -54,7 +58,7 @@ impl Expander {
54 let call_id = def.as_call_id(db, MacroCallKind::FnLike(ast_id)); 58 let call_id = def.as_call_id(db, MacroCallKind::FnLike(ast_id));
55 let file_id = call_id.as_file(); 59 let file_id = call_id.as_file();
56 if let Some(node) = db.parse_or_expand(file_id) { 60 if let Some(node) = db.parse_or_expand(file_id) {
57 if let Some(expr) = ast::Expr::cast(node) { 61 if let Some(expr) = T::cast(node) {
58 log::debug!("macro expansion {:#?}", expr.syntax()); 62 log::debug!("macro expansion {:#?}", expr.syntax());
59 63
60 let mark = Mark { 64 let mark = Mark {
@@ -77,14 +81,14 @@ impl Expander {
77 None 81 None
78 } 82 }
79 83
80 fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) { 84 pub(crate) fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) {
81 self.hygiene = Hygiene::new(db, mark.file_id); 85 self.hygiene = Hygiene::new(db, mark.file_id);
82 self.current_file_id = mark.file_id; 86 self.current_file_id = mark.file_id;
83 self.ast_id_map = mem::take(&mut mark.ast_id_map); 87 self.ast_id_map = mem::take(&mut mark.ast_id_map);
84 mark.bomb.defuse(); 88 mark.bomb.defuse();
85 } 89 }
86 90
87 fn to_source<T>(&self, value: T) -> InFile<T> { 91 pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
88 InFile { file_id: self.current_file_id, value } 92 InFile { file_id: self.current_file_id, value }
89 } 93 }
90 94
@@ -109,7 +113,7 @@ impl Expander {
109 } 113 }
110} 114}
111 115
112struct Mark { 116pub(crate) struct Mark {
113 file_id: HirFileId, 117 file_id: HirFileId,
114 ast_id_map: Arc<AstIdMap>, 118 ast_id_map: Arc<AstIdMap>,
115 bomb: DropBomb, 119 bomb: DropBomb,