aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/nameres
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-11 10:53:24 +0000
committerGitHub <[email protected]>2019-11-11 10:53:24 +0000
commitef2a9aedb6ac7f0b79e636cff7947935fecb909d (patch)
treea603361f9e6c02d90c0ae8cdfd0902370677f71d /crates/ra_hir_def/src/nameres
parent5ac4ffbc121c8231fe3ea5c2bb918f7aae60f197 (diff)
parent4f7df2aac107c0de2cab851f2a4f1ab369511fc8 (diff)
Merge #2205
2205: Implement bulitin line! macro r=matklad a=edwin0cheng This PR implements bulitin macro `line!` and add basic infra-structure for other bulitin macros: 1. Extend `MacroDefId` to support builtin macros 2. Add a `quote!` macro for simple quasi quoting. Note that for support others builtin macros, eager macro expansion have to be supported first, this PR not try to handle it. :) Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs25
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs7
2 files changed, 29 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 6db9937a4..37d0f3093 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
3use hir_expand::{ 3use 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 HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFileKind,
6}; 7};
7use ra_cfg::CfgOptions; 8use ra_cfg::CfgOptions;
8use ra_db::{CrateId, FileId}; 9use ra_db::{CrateId, FileId};
@@ -692,10 +693,30 @@ where
692 fn collect_macro(&mut self, mac: &raw::MacroData) { 693 fn collect_macro(&mut self, mac: &raw::MacroData) {
693 let ast_id = AstId::new(self.file_id, mac.ast_id); 694 let ast_id = AstId::new(self.file_id, mac.ast_id);
694 695
696 // Case 0: builtin macros
697 if mac.builtin {
698 if let Some(name) = &mac.name {
699 let krate = self.def_collector.def_map.krate;
700 if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) {
701 self.def_collector.define_macro(
702 self.module_id,
703 name.clone(),
704 macro_id,
705 mac.export,
706 );
707 return;
708 }
709 }
710 }
711
695 // Case 1: macro rules, define a macro in crate-global mutable scope 712 // Case 1: macro rules, define a macro in crate-global mutable scope
696 if is_macro_rules(&mac.path) { 713 if is_macro_rules(&mac.path) {
697 if let Some(name) = &mac.name { 714 if let Some(name) = &mac.name {
698 let macro_id = MacroDefId { ast_id, krate: self.def_collector.def_map.krate }; 715 let macro_id = MacroDefId {
716 ast_id,
717 krate: self.def_collector.def_map.krate,
718 kind: MacroDefKind::Declarative,
719 };
699 self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); 720 self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export);
700 } 721 }
701 return; 722 return;
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
205struct RawItemsCollector { 206struct 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