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