ProcMacroProcessExpander: support attribute macros

This commit is contained in:
Jonas Schievink 2020-12-07 13:55:41 +01:00
parent 403ed489ff
commit e42e6f9ab9
2 changed files with 11 additions and 21 deletions

View File

@ -42,9 +42,17 @@ impl tt::TokenExpander for ProcMacroProcessExpander {
fn expand(
&self,
subtree: &Subtree,
_attr: Option<&Subtree>,
attr: Option<&Subtree>,
) -> Result<Subtree, tt::ExpansionError> {
self.process.custom_derive(&self.dylib_path, subtree, &self.name)
let task = ExpansionTask {
macro_body: subtree.clone(),
macro_name: self.name.to_string(),
attributes: attr.cloned(),
lib: self.dylib_path.to_path_buf(),
};
let result: ExpansionResult = self.process.send_task(msg::Request::ExpansionMacro(task))?;
Ok(result.expansion)
}
}

View File

@ -10,11 +10,10 @@ use std::{
};
use crossbeam_channel::{bounded, Receiver, Sender};
use tt::Subtree;
use crate::{
msg::{ErrorCode, Message, Request, Response, ResponseError},
rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind},
rpc::{ListMacrosResult, ListMacrosTask, ProcMacroKind},
};
#[derive(Debug, Default)]
@ -58,23 +57,6 @@ impl ProcMacroProcessSrv {
Ok(result.macros)
}
pub(crate) fn custom_derive(
&self,
dylib_path: &Path,
subtree: &Subtree,
derive_name: &str,
) -> Result<Subtree, tt::ExpansionError> {
let task = ExpansionTask {
macro_body: subtree.clone(),
macro_name: derive_name.to_string(),
attributes: None,
lib: dylib_path.to_path_buf(),
};
let result: ExpansionResult = self.send_task(Request::ExpansionMacro(task))?;
Ok(result.expansion)
}
pub(crate) fn send_task<R>(&self, req: Request) -> Result<R, tt::ExpansionError>
where
R: TryFrom<Response, Error = &'static str>,