From a617f24eae6c02f087759312e9aa08507fbecdf0 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 18 Mar 2020 17:47:59 +0800 Subject: Add ra_proc_macro --- crates/ra_proc_macro/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 crates/ra_proc_macro/src/lib.rs (limited to 'crates/ra_proc_macro/src') diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs new file mode 100644 index 000000000..31e1bb209 --- /dev/null +++ b/crates/ra_proc_macro/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} -- cgit v1.2.3 From d0b6ed4441469acfb6bc6555d78abf12637b6cf4 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 18 Mar 2020 20:56:46 +0800 Subject: Add ProcMacroClient --- crates/ra_proc_macro/src/lib.rs | 81 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 5 deletions(-) (limited to 'crates/ra_proc_macro/src') diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index 31e1bb209..a7a84249f 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs @@ -1,7 +1,78 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); +//! Client-side Proc-Macro crate +//! +//! We separate proc-macro expanding logic to an extern program to allow +//! different implementations (e.g. wasm or dylib loading). And this crate +//! is used for provide basic infra-structure for commnicate between two +//! process: Client (RA itself), Server (the external program) + +use ra_mbe::ExpandError; +use ra_tt::Subtree; +use std::{ + path::{Path, PathBuf}, + sync::Arc, +}; + +trait ProcMacroExpander: std::fmt::Debug + Send + Sync + std::panic::RefUnwindSafe { + fn custom_derive(&self, subtree: &Subtree, derive_name: &str) -> Result; +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ProcMacroProcessExpander { + process_path: PathBuf, +} + +impl ProcMacroExpander for ProcMacroProcessExpander { + fn custom_derive( + &self, + _subtree: &Subtree, + _derive_name: &str, + ) -> Result { + // FIXME: do nothing for now + Ok(Subtree::default()) + } +} + +#[derive(Debug, Clone)] +pub struct ProcMacro { + expander: Arc>, + name: String, +} + +impl Eq for ProcMacro {} +impl PartialEq for ProcMacro { + fn eq(&self, other: &ProcMacro) -> bool { + self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander) + } +} + +impl ProcMacro { + pub fn name(&self) -> String { + self.name.clone() + } + + pub fn custom_derive(&self, subtree: &Subtree) -> Result { + self.expander.custom_derive(subtree, &self.name) + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ProcMacroClient { + Process { expander: Arc }, + Dummy, +} + +impl ProcMacroClient { + pub fn extern_process(process_path: &Path) -> ProcMacroClient { + let expander = ProcMacroProcessExpander { process_path: process_path.into() }; + ProcMacroClient::Process { expander: Arc::new(expander) } + } + + pub fn dummy() -> ProcMacroClient { + ProcMacroClient::Dummy + } + + pub fn by_dylib_path(&self, _dylib_path: &Path) -> Vec { + // FIXME: return empty for now + vec![] } } -- cgit v1.2.3 From 72e68d0caf6e813a19a8d434fb650574b73dbc0a Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 26 Mar 2020 10:49:23 +0800 Subject: Refactoring a bit --- crates/ra_proc_macro/src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'crates/ra_proc_macro/src') diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index a7a84249f..b7fb641c3 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs @@ -2,8 +2,8 @@ //! //! We separate proc-macro expanding logic to an extern program to allow //! different implementations (e.g. wasm or dylib loading). And this crate -//! is used for provide basic infra-structure for commnicate between two -//! process: Client (RA itself), Server (the external program) +//! is used to provide basic infrastructure for communication between two +//! processes: Client (RA itself), Server (the external program) use ra_mbe::ExpandError; use ra_tt::Subtree; @@ -18,7 +18,7 @@ trait ProcMacroExpander: std::fmt::Debug + Send + Sync + std::panic::RefUnwindSa #[derive(Debug, Clone, PartialEq, Eq)] pub struct ProcMacroProcessExpander { - process_path: PathBuf, + process: Arc, } impl ProcMacroExpander for ProcMacroProcessExpander { @@ -34,7 +34,7 @@ impl ProcMacroExpander for ProcMacroProcessExpander { #[derive(Debug, Clone)] pub struct ProcMacro { - expander: Arc>, + expander: Arc, name: String, } @@ -55,16 +55,21 @@ impl ProcMacro { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ProcMacroProcessSrv { + path: PathBuf, +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum ProcMacroClient { - Process { expander: Arc }, + Process { process: Arc }, Dummy, } impl ProcMacroClient { pub fn extern_process(process_path: &Path) -> ProcMacroClient { - let expander = ProcMacroProcessExpander { process_path: process_path.into() }; - ProcMacroClient::Process { expander: Arc::new(expander) } + let process = ProcMacroProcessSrv { path: process_path.into() }; + ProcMacroClient::Process { process: Arc::new(process) } } pub fn dummy() -> ProcMacroClient { -- cgit v1.2.3 From db162df264a222021dbc7f1f93af94029f3948d9 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 27 Mar 2020 00:41:44 +0800 Subject: Remove deps on tt_mbe --- crates/ra_proc_macro/src/lib.rs | 44 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 34 deletions(-) (limited to 'crates/ra_proc_macro/src') diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index b7fb641c3..5e21dd487 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs @@ -5,56 +5,29 @@ //! is used to provide basic infrastructure for communication between two //! processes: Client (RA itself), Server (the external program) -use ra_mbe::ExpandError; -use ra_tt::Subtree; +use ra_tt::{SmolStr, Subtree}; use std::{ path::{Path, PathBuf}, sync::Arc, }; -trait ProcMacroExpander: std::fmt::Debug + Send + Sync + std::panic::RefUnwindSafe { - fn custom_derive(&self, subtree: &Subtree, derive_name: &str) -> Result; -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct ProcMacroProcessExpander { process: Arc, + name: SmolStr, } -impl ProcMacroExpander for ProcMacroProcessExpander { - fn custom_derive( +impl ra_tt::TokenExpander for ProcMacroProcessExpander { + fn expand( &self, _subtree: &Subtree, - _derive_name: &str, - ) -> Result { + _attr: Option<&Subtree>, + ) -> Result { // FIXME: do nothing for now Ok(Subtree::default()) } } -#[derive(Debug, Clone)] -pub struct ProcMacro { - expander: Arc, - name: String, -} - -impl Eq for ProcMacro {} -impl PartialEq for ProcMacro { - fn eq(&self, other: &ProcMacro) -> bool { - self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander) - } -} - -impl ProcMacro { - pub fn name(&self) -> String { - self.name.clone() - } - - pub fn custom_derive(&self, subtree: &Subtree) -> Result { - self.expander.custom_derive(subtree, &self.name) - } -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct ProcMacroProcessSrv { path: PathBuf, @@ -76,7 +49,10 @@ impl ProcMacroClient { ProcMacroClient::Dummy } - pub fn by_dylib_path(&self, _dylib_path: &Path) -> Vec { + pub fn by_dylib_path( + &self, + _dylib_path: &Path, + ) -> Vec<(SmolStr, Arc)> { // FIXME: return empty for now vec![] } -- cgit v1.2.3