From 4345c105963cee061acf26bec207fab2859fb164 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 16 Dec 2018 18:37:36 +0100 Subject: properly handle #[cfg] (conditional compilation) on resources --- macros/src/syntax.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'macros/src/syntax.rs') diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index c1b0d5d..0e6c606 100644 --- a/macros/src/syntax.rs +++ b/macros/src/syntax.rs @@ -47,7 +47,7 @@ impl Parse for AppArgs { return Err(parse::Error::new( ident.span(), "expected `device`; other keys are not accepted", - )) + )); } } @@ -228,7 +228,7 @@ impl App { return Err(parse::Error::new( item.span(), "this item must live outside the `#[app]` module", - )) + )); } } } @@ -526,7 +526,7 @@ impl Parse for InitArgs { return Err(parse::Error::new( ident.span(), "expected one of: resources, schedule or spawn", - )) + )); } } @@ -597,6 +597,7 @@ impl Parse for InitArgs { } pub struct Assign { + pub attrs: Vec, pub left: Ident, pub right: Box, } @@ -649,7 +650,7 @@ pub struct Exception { pub args: ExceptionArgs, pub attrs: Vec, pub unsafety: Option, - pub statics: Statics, + pub statics: HashMap, pub stmts: Vec, } @@ -727,7 +728,7 @@ impl Exception { args, attrs: item.attrs, unsafety: item.unsafety, - statics, + statics: Static::parse(statics)?, stmts, }) } @@ -737,7 +738,7 @@ pub struct Interrupt { pub args: InterruptArgs, pub attrs: Vec, pub unsafety: Option, - pub statics: Statics, + pub statics: HashMap, pub stmts: Vec, } @@ -780,7 +781,7 @@ impl Interrupt { args, attrs: item.attrs, unsafety: item.unsafety, - statics, + statics: Static::parse(statics)?, stmts, }) } @@ -788,6 +789,7 @@ impl Interrupt { pub struct Resource { pub singleton: bool, + pub cfgs: Vec, pub attrs: Vec, pub mutability: Option, pub ty: Box, @@ -817,9 +819,12 @@ impl Resource { ); } + let (cfgs, attrs) = extract_cfgs(item.attrs); + Ok(Resource { singleton: pos.is_some(), - attrs: item.attrs, + cfgs, + attrs, mutability: item.mutability, ty: item.ty, expr: if uninitialized { None } else { Some(item.expr) }, @@ -981,7 +986,7 @@ fn parse_args(input: ParseStream, accept_capacity: bool) -> parse::Result) -> (Vec, Vec) { if let Expr::Path(ref expr) = *assign.left { if expr.path.segments.len() == 1 { assigns.push(Assign { + attrs: assign.attrs, left: expr.path.segments[0].ident.clone(), right: assign.right, }); -- cgit v1.2.3 From 8e9a91d0b09313eee0f7fa44cc827dced0ea1806 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 16 Dec 2018 19:10:36 +0100 Subject: properly handle `#[cfg]` (conditional compilation) on tasks --- macros/src/syntax.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'macros/src/syntax.rs') diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index 0e6c606..b9424fb 100644 --- a/macros/src/syntax.rs +++ b/macros/src/syntax.rs @@ -1047,6 +1047,7 @@ impl Static { pub struct Task { pub args: TaskArgs, + pub cfgs: Vec, pub attrs: Vec, pub unsafety: Option, pub inputs: Vec, @@ -1098,9 +1099,11 @@ impl Task { _ => {} } + let (cfgs, attrs) = extract_cfgs(item.attrs); Ok(Task { args, - attrs: item.attrs, + cfgs, + attrs, unsafety: item.unsafety, inputs, statics: Static::parse(statics)?, -- cgit v1.2.3 From 56d09a12dd645166af7d6def6b95bf71ae7962bd Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 16 Dec 2018 19:13:22 +0100 Subject: move macros crate to the 2018 edition --- macros/src/syntax.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'macros/src/syntax.rs') diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index b9424fb..85f3caa 100644 --- a/macros/src/syntax.rs +++ b/macros/src/syntax.rs @@ -20,7 +20,7 @@ pub struct AppArgs { } impl Parse for AppArgs { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { let mut device = None; loop { if input.is_empty() { @@ -80,8 +80,8 @@ pub struct Input { } impl Parse for Input { - fn parse(input: ParseStream) -> parse::Result { - fn parse_items(input: ParseStream) -> parse::Result> { + fn parse(input: ParseStream<'_>) -> parse::Result { + fn parse_items(input: ParseStream<'_>) -> parse::Result> { let mut items = vec![]; while !input.is_empty() { @@ -254,7 +254,7 @@ impl App { pub fn resource_accesses(&self) -> impl Iterator { self.idle .as_ref() - .map(|idle| -> Box> { + .map(|idle| -> Box> { Box::new(idle.args.resources.iter().map(|res| (0, res))) }) .unwrap_or_else(|| Box::new(iter::empty())) @@ -293,7 +293,7 @@ impl App { .chain( self.idle .as_ref() - .map(|idle| -> Box> { + .map(|idle| -> Box> { Box::new(idle.args.spawn.iter().map(|s| (Some(0), s))) }) .unwrap_or_else(|| Box::new(iter::empty())), @@ -329,7 +329,7 @@ impl App { .chain( self.idle .as_ref() - .map(|idle| -> Box> { + .map(|idle| -> Box> { Box::new(idle.args.schedule.iter().map(|s| (Some(0), s))) }) .unwrap_or_else(|| Box::new(iter::empty())), @@ -358,7 +358,7 @@ impl App { pub fn schedule_callers(&self) -> impl Iterator { self.idle .as_ref() - .map(|idle| -> Box> { + .map(|idle| -> Box> { Box::new(iter::once(( Ident::new("idle", Span::call_site()), &idle.args.schedule, @@ -389,7 +389,7 @@ impl App { pub fn spawn_callers(&self) -> impl Iterator { self.idle .as_ref() - .map(|idle| -> Box> { + .map(|idle| -> Box> { Box::new(iter::once(( Ident::new("idle", Span::call_site()), &idle.args.spawn, @@ -492,7 +492,7 @@ impl Default for InitArgs { } impl Parse for InitArgs { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { if input.is_empty() { return Ok(InitArgs::default()); } @@ -662,7 +662,7 @@ pub struct ExceptionArgs { } impl Parse for ExceptionArgs { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { parse_args(input, false).map( |TaskArgs { priority, @@ -853,13 +853,13 @@ impl Default for TaskArgs { } impl Parse for TaskArgs { - fn parse(input: ParseStream) -> parse::Result { + fn parse(input: ParseStream<'_>) -> parse::Result { parse_args(input, true) } } // Parser shared by TaskArgs and ExceptionArgs / InterruptArgs -fn parse_args(input: ParseStream, accept_capacity: bool) -> parse::Result { +fn parse_args(input: ParseStream<'_>, accept_capacity: bool) -> parse::Result { if input.is_empty() { return Ok(TaskArgs::default()); } -- cgit v1.2.3