aboutsummaryrefslogtreecommitdiff
path: root/macros/src/syntax.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-12-15 22:04:30 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-12-15 22:04:30 +0100
commit4f00d8bd781455535e0710879bc31c197e51c71b (patch)
treec8aa311dfde52894f76732734554798cee94e413 /macros/src/syntax.rs
parenteba691a5f2ac42d6a50203f58632209a27ab9566 (diff)
downloadrtic-4f00d8bd781455535e0710879bc31c197e51c71b.tar.gz
rtic-4f00d8bd781455535e0710879bc31c197e51c71b.tar.zst
rtic-4f00d8bd781455535e0710879bc31c197e51c71b.zip
codegen/statics: forward #[cfg] attributes
fixes #110
Diffstat (limited to 'macros/src/syntax.rs')
-rw-r--r--macros/src/syntax.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs
index 24586dcf..c1b0d5d2 100644
--- a/macros/src/syntax.rs
+++ b/macros/src/syntax.rs
@@ -1003,6 +1003,9 @@ fn parse_args(input: ParseStream, accept_capacity: bool) -> parse::Result<TaskAr
}
pub struct Static {
+ /// `#[cfg]` attributes
+ pub cfgs: Vec<Attribute>,
+ /// Attributes that are not `#[cfg]`
pub attrs: Vec<Attribute>,
pub ty: Box<Type>,
pub expr: Box<Expr>,
@@ -1020,10 +1023,13 @@ impl Static {
));
}
+ let (cfgs, attrs) = extract_cfgs(item.attrs);
+
statics.insert(
item.ident,
Static {
- attrs: item.attrs,
+ cfgs,
+ attrs,
ty: item.ty,
expr: item.expr,
},
@@ -1150,6 +1156,21 @@ fn eq(attr: &Attribute, name: &str) -> bool {
}
}
+fn extract_cfgs(attrs: Vec<Attribute>) -> (Vec<Attribute>, Vec<Attribute>) {
+ let mut cfgs = vec![];
+ let mut not_cfgs = vec![];
+
+ for attr in attrs {
+ if eq(&attr, "cfg") {
+ cfgs.push(attr);
+ } else {
+ not_cfgs.push(attr);
+ }
+ }
+
+ (cfgs, not_cfgs)
+}
+
/// Extracts `static mut` vars from the beginning of the given statements
fn extract_statics(stmts: Vec<Stmt>) -> (Statics, Vec<Stmt>) {
let mut istmts = stmts.into_iter();