aboutsummaryrefslogtreecommitdiff
path: root/macros/src/syntax.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-12-16 18:37:36 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-12-16 18:37:36 +0100
commit4345c105963cee061acf26bec207fab2859fb164 (patch)
tree741bd7d418f9bca9ee942367047b68d45eb62389 /macros/src/syntax.rs
parent9757c33b0051900fa6c5581be413880d07a237d2 (diff)
downloadrtic-4345c105963cee061acf26bec207fab2859fb164.tar.gz
rtic-4345c105963cee061acf26bec207fab2859fb164.tar.zst
rtic-4345c105963cee061acf26bec207fab2859fb164.zip
properly handle #[cfg] (conditional compilation) on resources
Diffstat (limited to 'macros/src/syntax.rs')
-rw-r--r--macros/src/syntax.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs
index c1b0d5d2..0e6c606b 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<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>,
}
@@ -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) },
@@ -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",
- ))
+ ));
}
}
@@ -1210,6 +1215,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,
});