diff options
Diffstat (limited to 'macros/src/syntax.rs')
| -rw-r--r-- | macros/src/syntax.rs | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index c1b0d5d..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<Self> { + fn parse(input: ParseStream<'_>) -> parse::Result<Self> { let mut device = None; loop { if input.is_empty() { @@ -47,7 +47,7 @@ impl Parse for AppArgs { return Err(parse::Error::new( ident.span(), "expected `device`; other keys are not accepted", - )) + )); } } @@ -80,8 +80,8 @@ pub struct Input { } impl Parse for Input { - fn parse(input: ParseStream) -> parse::Result<Self> { - fn parse_items(input: ParseStream) -> parse::Result<Vec<Item>> { + fn parse(input: ParseStream<'_>) -> parse::Result<Self> { + fn parse_items(input: ParseStream<'_>) -> parse::Result<Vec<Item>> { let mut items = vec![]; while !input.is_empty() { @@ -228,7 +228,7 @@ impl App { return Err(parse::Error::new( item.span(), "this item must live outside the `#[app]` module", - )) + )); } } } @@ -254,7 +254,7 @@ impl App { pub fn resource_accesses(&self) -> impl Iterator<Item = (u8, &Ident)> { self.idle .as_ref() - .map(|idle| -> Box<Iterator<Item = _>> { + .map(|idle| -> Box<dyn Iterator<Item = _>> { 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<Iterator<Item = _>> { + .map(|idle| -> Box<dyn Iterator<Item = _>> { 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<Iterator<Item = _>> { + .map(|idle| -> Box<dyn Iterator<Item = _>> { 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<Item = (Ident, &Idents)> { self.idle .as_ref() - .map(|idle| -> Box<Iterator<Item = _>> { + .map(|idle| -> Box<dyn Iterator<Item = _>> { 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<Item = (Ident, &Idents)> { self.idle .as_ref() - .map(|idle| -> Box<Iterator<Item = _>> { + .map(|idle| -> Box<dyn Iterator<Item = _>> { 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<InitArgs> { + fn parse(input: ParseStream<'_>) -> parse::Result<InitArgs> { if input.is_empty() { return Ok(InitArgs::default()); } @@ -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<Attribute>, pub left: Ident, pub right: Box<Expr>, } @@ -649,7 +650,7 @@ pub struct Exception { pub args: ExceptionArgs, pub attrs: Vec<Attribute>, pub unsafety: Option<Token![unsafe]>, - pub statics: Statics, + pub statics: HashMap<Ident, Static>, pub stmts: Vec<Stmt>, } @@ -661,7 +662,7 @@ pub struct ExceptionArgs { } impl Parse for ExceptionArgs { - fn parse(input: ParseStream) -> parse::Result<Self> { + fn parse(input: ParseStream<'_>) -> parse::Result<Self> { parse_args(input, false).map( |TaskArgs { priority, @@ -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<Attribute>, pub unsafety: Option<Token![unsafe]>, - pub statics: Statics, + pub statics: HashMap<Ident, Static>, pub stmts: Vec<Stmt>, } @@ -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<Attribute>, pub attrs: Vec<Attribute>, pub mutability: Option<Token![mut]>, pub ty: Box<Type>, @@ -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) }, @@ -848,13 +853,13 @@ impl Default for TaskArgs { } impl Parse for TaskArgs { - fn parse(input: ParseStream) -> parse::Result<Self> { + fn parse(input: ParseStream<'_>) -> parse::Result<Self> { parse_args(input, true) } } // Parser shared by TaskArgs and ExceptionArgs / InterruptArgs -fn parse_args(input: ParseStream, accept_capacity: bool) -> parse::Result<TaskArgs> { +fn parse_args(input: ParseStream<'_>, accept_capacity: bool) -> parse::Result<TaskArgs> { if input.is_empty() { return Ok(TaskArgs::default()); } @@ -981,7 +986,7 @@ fn parse_args(input: ParseStream, accept_capacity: bool) -> parse::Result<TaskAr return Err(parse::Error::new( ident.span(), "expected one of: priority, resources, schedule or spawn", - )) + )); } } @@ -1042,6 +1047,7 @@ impl Static { pub struct Task { pub args: TaskArgs, + pub cfgs: Vec<Attribute>, pub attrs: Vec<Attribute>, pub unsafety: Option<Token![unsafe]>, pub inputs: Vec<ArgCaptured>, @@ -1093,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)?, @@ -1210,6 +1218,7 @@ fn extract_assignments(stmts: Vec<Stmt>) -> (Vec<Stmt>, Vec<Assign>) { 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, }); |
