Fix "Could not find Op in proc_macro"

This commit is contained in:
Ferdia McKeogh 2018-06-07 11:45:11 +01:00
parent 53dbbad891
commit 14b1811182
4 changed files with 25 additions and 22 deletions

View file

@ -17,6 +17,10 @@ cortex-m = "0.4.0"
cortex-m-rtfm-macros = { path = "macros", version = "0.3.1" }
rtfm-core = "0.2.0"
untagged-option = "0.1.1"
syn = "0.14.2"
quote = "0.6.3"
proc-macro2 = "0.4.6"
failure = "0.1.1"
[target.'cfg(target_arch = "x86_64")'.dev-dependencies]
compiletest_rs = "0.3.5"

View file

@ -11,10 +11,10 @@ version = "0.3.1"
[dependencies]
failure = "0.1.1"
proc-macro2 = "0.3.6"
quote = "0.5.1"
rtfm-syntax = "0.3.0"
syn = "0.13.1"
proc-macro2 = "0.4.6"
quote = "0.6.3"
rtfm-syntax = {git = "https://github.com/chocol4te/rtfm-syntax.git"}
syn = "0.14.2"
[lib]
proc-macro = true

View file

@ -61,7 +61,7 @@ pub fn app(app: check::App) -> Result<App> {
tasks: app.tasks
.into_iter()
.map(|(k, v)| {
let v = ::check::task(k.as_ref(), v)?;
let v = ::check::task(&k.to_string(), v)?;
Ok((k, v))
})

View file

@ -1,15 +1,14 @@
use proc_macro2::Span;
use quote::Tokens;
use proc_macro2::{TokenStream, Span};
use syn::{Ident, LitStr};
use analyze::Ownerships;
use check::{App, Kind};
fn krate() -> Ident {
Ident::from("rtfm")
Ident::new("rtfm", Span::call_site())
}
pub fn app(app: &App, ownerships: &Ownerships) -> Tokens {
pub fn app(app: &App, ownerships: &Ownerships) -> TokenStream {
let mut root = vec![];
let mut main = vec![quote!(#![allow(path_statements)])];
@ -28,7 +27,7 @@ pub fn app(app: &App, ownerships: &Ownerships) -> Tokens {
quote!(#(#root)*)
}
fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<TokenStream>, root: &mut Vec<TokenStream>) {
let krate = krate();
let mut mod_items = vec![];
@ -54,7 +53,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, root: &mut V
let super_ = if needs_reexport {
None
} else {
Some(Ident::from("super"))
Some(Ident::new("super", Span::call_site()))
};
let mut rexprs = vec![];
let mut rfields = vec![];
@ -70,7 +69,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, root: &mut V
pub #name: &'static mut #ty,
});
let _name = Ident::from(format!("_{}", name.as_ref()));
let _name = Ident::new(&name.to_string(), Span::call_site());
rexprs.push(if resource.expr.is_some() {
quote! {
#name: &mut #super_::#_name,
@ -136,7 +135,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, root: &mut V
continue;
}
let _name = Ident::from(format!("_{}", name.as_ref()));
let _name = Ident::new(&name.to_string(), Span::call_site());
let resource = app.resources
.get(name)
.expect(&format!("BUG: resource {} has no definition", name));
@ -224,7 +223,7 @@ fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, root: &mut V
});
}
fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
fn init(app: &App, main: &mut Vec<TokenStream>, root: &mut Vec<TokenStream>) {
let device = &app.device;
let krate = krate();
@ -263,7 +262,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
&mut #name
},));
} else {
let _name = Ident::from(format!("_{}", name.as_ref()));
let _name = Ident::new(&name.to_string(), Span::call_site());
lifetime = Some(quote!('a));
fields.push(quote! {
@ -310,7 +309,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
let mut fields = vec![];
for (name, resource) in late_resources {
let _name = Ident::from(format!("_{}", name.as_ref()));
let _name = Ident::new(&name.to_string(), Span::call_site());
let ty = &resource.ty;
@ -415,11 +414,11 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
});
}
fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<TokenStream>) {
let krate = krate();
for name in ownerships.keys() {
let _name = Ident::from(format!("_{}", name.as_ref()));
let _name = Ident::new(&name.to_string(), Span::call_site());
// Declare the static that holds the resource
let resource = app.resources
@ -442,7 +441,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
}
}
fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>, main: &mut Vec<Tokens>) {
fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<TokenStream>, main: &mut Vec<TokenStream>) {
let device = &app.device;
let krate = krate();
@ -456,7 +455,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>, main: &mut
if has_resources {
for rname in &task.resources {
let ceiling = ownerships[rname].ceiling();
let _rname = Ident::from(format!("_{}", rname.as_ref()));
let _rname = Ident::new(&rname.to_string(), Span::call_site());
let resource = app.resources
.get(rname)
.expect(&format!("BUG: resource {} has no definition", rname));
@ -594,8 +593,8 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>, main: &mut
}
let path = &task.path;
let _tname = Ident::from(format!("_{}", tname));
let export_name = LitStr::new(tname.as_ref(), Span::call_site());
let _tname = Ident::new(&tname.to_string(), Span::call_site());
let export_name = LitStr::new(&tname.to_string(), Span::call_site());
root.push(quote! {
#[allow(non_snake_case)]
#[allow(unsafe_code)]