diff options
author | Edwin Cheng <[email protected]> | 2019-11-10 03:03:24 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-11-11 06:13:31 +0000 |
commit | c46768d13dd34bbe878cc62eca4af873ffbb7c22 (patch) | |
tree | 2354a9f6aaf7d09cae9c386f4330852b10cd5d9a /crates/ra_hir_def | |
parent | defc7ad772123a449f7cc384dd46d88c3a45fb53 (diff) |
Add basic bultin macro infrastructure
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 7 |
2 files changed, 31 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index aacd50df8..5f18e9de3 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -1,8 +1,9 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_expand::{ | 3 | use hir_expand::{ |
4 | builtin_macro::find_builtin_macro, | ||
4 | name::{self, AsName, Name}, | 5 | name::{self, AsName, Name}, |
5 | HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind, | 6 | DeclarativeMacro, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind, |
6 | }; | 7 | }; |
7 | use ra_cfg::CfgOptions; | 8 | use ra_cfg::CfgOptions; |
8 | use ra_db::{CrateId, FileId}; | 9 | use ra_db::{CrateId, FileId}; |
@@ -688,11 +689,32 @@ where | |||
688 | fn collect_macro(&mut self, mac: &raw::MacroData) { | 689 | fn collect_macro(&mut self, mac: &raw::MacroData) { |
689 | let ast_id = AstId::new(self.file_id, mac.ast_id); | 690 | let ast_id = AstId::new(self.file_id, mac.ast_id); |
690 | 691 | ||
692 | // Case 0: builtin macros | ||
693 | if mac.builtin { | ||
694 | if let Some(name) = &mac.name { | ||
695 | let krate = self.def_collector.def_map.krate; | ||
696 | if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) { | ||
697 | self.def_collector.define_macro( | ||
698 | self.module_id, | ||
699 | name.clone(), | ||
700 | macro_id, | ||
701 | mac.export, | ||
702 | ); | ||
703 | return; | ||
704 | } | ||
705 | } | ||
706 | } | ||
707 | |||
691 | // Case 1: macro rules, define a macro in crate-global mutable scope | 708 | // Case 1: macro rules, define a macro in crate-global mutable scope |
692 | if is_macro_rules(&mac.path) { | 709 | if is_macro_rules(&mac.path) { |
693 | if let Some(name) = &mac.name { | 710 | if let Some(name) = &mac.name { |
694 | let macro_id = MacroDefId { ast_id, krate: self.def_collector.def_map.krate }; | 711 | let macro_id = DeclarativeMacro { ast_id, krate: self.def_collector.def_map.krate }; |
695 | self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); | 712 | self.def_collector.define_macro( |
713 | self.module_id, | ||
714 | name.clone(), | ||
715 | MacroDefId::DeclarativeMacro(macro_id), | ||
716 | mac.export, | ||
717 | ); | ||
696 | } | 718 | } |
697 | return; | 719 | return; |
698 | } | 720 | } |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 369376f30..f52002bc0 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -200,6 +200,7 @@ pub(super) struct MacroData { | |||
200 | pub(super) path: Path, | 200 | pub(super) path: Path, |
201 | pub(super) name: Option<Name>, | 201 | pub(super) name: Option<Name>, |
202 | pub(super) export: bool, | 202 | pub(super) export: bool, |
203 | pub(super) builtin: bool, | ||
203 | } | 204 | } |
204 | 205 | ||
205 | struct RawItemsCollector { | 206 | struct RawItemsCollector { |
@@ -367,7 +368,11 @@ impl RawItemsCollector { | |||
367 | // FIXME: cfg_attr | 368 | // FIXME: cfg_attr |
368 | let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export"); | 369 | let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export"); |
369 | 370 | ||
370 | let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export }); | 371 | // FIXME: cfg_attr |
372 | let builtin = | ||
373 | m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "rustc_builtin_macro"); | ||
374 | |||
375 | let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export, builtin }); | ||
371 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); | 376 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); |
372 | } | 377 | } |
373 | 378 | ||