more "hygiene"

prepend an underscore to the name of the statics generated in the root of the
crate
This commit is contained in:
Jorge Aparicio 2017-07-24 23:07:11 -05:00
parent a14b0121b7
commit 0e05682d09

View file

@ -184,6 +184,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
let mut rexprs = vec![]; let mut rexprs = vec![];
for (name, resource) in &app.resources { for (name, resource) in &app.resources {
let _name = Ident::new(format!("_{}", name.as_ref()));
lifetime = Some(quote!('a)); lifetime = Some(quote!('a));
let ty = &resource.ty; let ty = &resource.ty;
@ -193,7 +194,7 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
}); });
rexprs.push(quote! { rexprs.push(quote! {
#name: ::#krate::Static::ref_mut(&mut super::#name), #name: ::#krate::Static::ref_mut(&mut ::#_name),
}); });
} }
@ -298,6 +299,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
for (name, ownership) in ownerships { for (name, ownership) in ownerships {
let mut impl_items = vec![]; let mut impl_items = vec![];
let _name = Ident::new(format!("_{}", name.as_ref()));
match *ownership { match *ownership {
Ownership::Owned { .. } => { Ownership::Owned { .. } => {
if let Some(resource) = app.resources.get(name) { if let Some(resource) = app.resources.get(name) {
@ -306,7 +308,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
let ty = &resource.ty; let ty = &resource.ty;
root.push(quote! { root.push(quote! {
static mut #name: #ty = #expr; static mut #_name: #ty = #expr;
}); });
} else { } else {
// Peripheral // Peripheral
@ -319,7 +321,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
let ty = &resource.ty; let ty = &resource.ty;
root.push(quote! { root.push(quote! {
static mut #name: #ty = #expr; static mut #_name: #ty = #expr;
}); });
impl_items.push(quote! { impl_items.push(quote! {
@ -329,7 +331,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
&'cs self, &'cs self,
_cs: &'cs #krate::CriticalSection, _cs: &'cs #krate::CriticalSection,
) -> &'cs #krate::Static<#ty> { ) -> &'cs #krate::Static<#ty> {
unsafe { #krate::Static::ref_(&#name) } unsafe { #krate::Static::ref_(&#_name) }
} }
fn borrow_mut<'cs>( fn borrow_mut<'cs>(
@ -337,7 +339,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
_cs: &'cs #krate::CriticalSection, _cs: &'cs #krate::CriticalSection,
) -> &'cs mut #krate::Static<#ty> { ) -> &'cs mut #krate::Static<#ty> {
unsafe { unsafe {
#krate::Static::ref_mut(&mut #name) #krate::Static::ref_mut(&mut #_name)
} }
} }
@ -353,7 +355,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
{ {
unsafe { unsafe {
#krate::claim( #krate::claim(
#krate::Static::ref_(&#name), #krate::Static::ref_(&#_name),
#ceiling, #ceiling,
#device::NVIC_PRIO_BITS, #device::NVIC_PRIO_BITS,
t, t,
@ -374,7 +376,7 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
{ {
unsafe { unsafe {
#krate::claim( #krate::claim(
#krate::Static::ref_mut(&mut #name), #krate::Static::ref_mut(&mut #_name),
#ceiling, #ceiling,
#device::NVIC_PRIO_BITS, #device::NVIC_PRIO_BITS,
t, t,
@ -503,6 +505,8 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
if has_resources { if has_resources {
for name in &task.resources { for name in &task.resources {
let _name = Ident::new(format!("_{}", name.as_ref()));
match ownerships[name] { match ownerships[name] {
Ownership::Shared { ceiling } Ownership::Shared { ceiling }
if ceiling > task.priority => if ceiling > task.priority =>
@ -530,7 +534,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
}); });
exprs.push(quote! { exprs.push(quote! {
#name: ::#krate::Static::ref_mut(&mut super::#name), #name: ::#krate::Static::ref_mut(&mut ::#_name),
}); });
} else { } else {
fields.push(quote! { fields.push(quote! {