diff options
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 151d1d785..6b71738ee 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -10,6 +10,7 @@ pub mod either; | |||
10 | pub mod name; | 10 | pub mod name; |
11 | pub mod hygiene; | 11 | pub mod hygiene; |
12 | pub mod diagnostics; | 12 | pub mod diagnostics; |
13 | pub mod builtin_macro; | ||
13 | 14 | ||
14 | use std::hash::{Hash, Hasher}; | 15 | use std::hash::{Hash, Hasher}; |
15 | use std::sync::Arc; | 16 | use std::sync::Arc; |
@@ -21,6 +22,7 @@ use ra_syntax::{ | |||
21 | }; | 22 | }; |
22 | 23 | ||
23 | use crate::ast_id_map::FileAstId; | 24 | use crate::ast_id_map::FileAstId; |
25 | use crate::builtin_macro::BuiltinExpander; | ||
24 | 26 | ||
25 | /// Input to the analyzer is a set of files, where each file is identified by | 27 | /// Input to the analyzer is a set of files, where each file is identified by |
26 | /// `FileId` and contains source code. However, another source of source code in | 28 | /// `FileId` and contains source code. However, another source of source code in |
@@ -75,9 +77,15 @@ impl HirFileId { | |||
75 | HirFileIdRepr::MacroFile(macro_file) => { | 77 | HirFileIdRepr::MacroFile(macro_file) => { |
76 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); | 78 | let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id); |
77 | 79 | ||
80 | // FIXME: Do we support expansion information in builtin macro? | ||
81 | let macro_decl = match loc.def { | ||
82 | MacroDefId::DeclarativeMacro(it) => (it), | ||
83 | MacroDefId::BuiltinMacro(_) => return None, | ||
84 | }; | ||
85 | |||
78 | let arg_start = loc.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); | 86 | let arg_start = loc.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); |
79 | let def_start = | 87 | let def_start = |
80 | loc.def.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); | 88 | macro_decl.ast_id.to_node(db).token_tree()?.syntax().text_range().start(); |
81 | 89 | ||
82 | let macro_def = db.macro_def(loc.def)?; | 90 | let macro_def = db.macro_def(loc.def)?; |
83 | let shift = macro_def.0.shift(); | 91 | let shift = macro_def.0.shift(); |
@@ -85,7 +93,7 @@ impl HirFileId { | |||
85 | let macro_arg = db.macro_arg(macro_file.macro_call_id)?; | 93 | let macro_arg = db.macro_arg(macro_file.macro_call_id)?; |
86 | 94 | ||
87 | let arg_start = (loc.ast_id.file_id, arg_start); | 95 | let arg_start = (loc.ast_id.file_id, arg_start); |
88 | let def_start = (loc.def.ast_id.file_id, def_start); | 96 | let def_start = (macro_decl.ast_id.file_id, def_start); |
89 | 97 | ||
90 | Some(ExpansionInfo { arg_start, def_start, macro_arg, macro_def, exp_map, shift }) | 98 | Some(ExpansionInfo { arg_start, def_start, macro_arg, macro_def, exp_map, shift }) |
91 | } | 99 | } |
@@ -119,9 +127,22 @@ impl salsa::InternKey for MacroCallId { | |||
119 | } | 127 | } |
120 | 128 | ||
121 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 129 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
122 | pub struct MacroDefId { | 130 | pub enum MacroDefId { |
131 | DeclarativeMacro(DeclarativeMacro), | ||
132 | BuiltinMacro(BuiltinMacro), | ||
133 | } | ||
134 | |||
135 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
136 | pub struct DeclarativeMacro { | ||
137 | pub krate: CrateId, | ||
138 | pub ast_id: AstId<ast::MacroCall>, | ||
139 | } | ||
140 | |||
141 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
142 | pub struct BuiltinMacro { | ||
123 | pub krate: CrateId, | 143 | pub krate: CrateId, |
124 | pub ast_id: AstId<ast::MacroCall>, | 144 | pub ast_id: AstId<ast::MacroCall>, |
145 | pub expander: BuiltinExpander, | ||
125 | } | 146 | } |
126 | 147 | ||
127 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 148 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -144,7 +165,7 @@ pub struct ExpansionInfo { | |||
144 | pub(crate) def_start: (HirFileId, TextUnit), | 165 | pub(crate) def_start: (HirFileId, TextUnit), |
145 | pub(crate) shift: u32, | 166 | pub(crate) shift: u32, |
146 | 167 | ||
147 | pub(crate) macro_def: Arc<(mbe::MacroRules, mbe::TokenMap)>, | 168 | pub(crate) macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, |
148 | pub(crate) macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, | 169 | pub(crate) macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, |
149 | pub(crate) exp_map: Arc<mbe::RevTokenMap>, | 170 | pub(crate) exp_map: Arc<mbe::RevTokenMap>, |
150 | } | 171 | } |