From c46768d13dd34bbe878cc62eca4af873ffbb7c22 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sun, 10 Nov 2019 11:03:24 +0800 Subject: Add basic bultin macro infrastructure --- crates/ra_hir_def/src/nameres/collector.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src/nameres/collector.rs') 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 @@ //! FIXME: write short doc here use hir_expand::{ + builtin_macro::find_builtin_macro, name::{self, AsName, Name}, - HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind, + DeclarativeMacro, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind, }; use ra_cfg::CfgOptions; use ra_db::{CrateId, FileId}; @@ -688,11 +689,32 @@ where fn collect_macro(&mut self, mac: &raw::MacroData) { let ast_id = AstId::new(self.file_id, mac.ast_id); + // Case 0: builtin macros + if mac.builtin { + if let Some(name) = &mac.name { + let krate = self.def_collector.def_map.krate; + if let Some(macro_id) = find_builtin_macro(name, krate, ast_id) { + self.def_collector.define_macro( + self.module_id, + name.clone(), + macro_id, + mac.export, + ); + return; + } + } + } + // Case 1: macro rules, define a macro in crate-global mutable scope if is_macro_rules(&mac.path) { if let Some(name) = &mac.name { - let macro_id = MacroDefId { ast_id, krate: self.def_collector.def_map.krate }; - self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); + let macro_id = DeclarativeMacro { ast_id, krate: self.def_collector.def_map.krate }; + self.def_collector.define_macro( + self.module_id, + name.clone(), + MacroDefId::DeclarativeMacro(macro_id), + mac.export, + ); } return; } -- cgit v1.2.3 From 4f7df2aac107c0de2cab851f2a4f1ab369511fc8 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 11 Nov 2019 18:45:55 +0800 Subject: Add MacroDefKind --- crates/ra_hir_def/src/nameres/collector.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir_def/src/nameres/collector.rs') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 5f18e9de3..30664278e 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -3,7 +3,7 @@ use hir_expand::{ builtin_macro::find_builtin_macro, name::{self, AsName, Name}, - DeclarativeMacro, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind, + HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFileKind, }; use ra_cfg::CfgOptions; use ra_db::{CrateId, FileId}; @@ -708,13 +708,12 @@ where // Case 1: macro rules, define a macro in crate-global mutable scope if is_macro_rules(&mac.path) { if let Some(name) = &mac.name { - let macro_id = DeclarativeMacro { ast_id, krate: self.def_collector.def_map.krate }; - self.def_collector.define_macro( - self.module_id, - name.clone(), - MacroDefId::DeclarativeMacro(macro_id), - mac.export, - ); + let macro_id = MacroDefId { + ast_id, + krate: self.def_collector.def_map.krate, + kind: MacroDefKind::Declarative, + }; + self.def_collector.define_macro(self.module_id, name.clone(), macro_id, mac.export); } return; } -- cgit v1.2.3