diff options
Diffstat (limited to 'macros/src/check.rs')
-rw-r--r-- | macros/src/check.rs | 91 |
1 files changed, 8 insertions, 83 deletions
diff --git a/macros/src/check.rs b/macros/src/check.rs index f6fd9cc6..4defb46d 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -1,10 +1,8 @@ use std::collections::HashMap; use syn::{Ident, Path}; -use syntax::check::{self, Idle, Init}; -use syntax::{self, Resources, Statics}; - -use syntax::error::*; +use syntax::check::{self, Idents, Idle, Init, Statics}; +use syntax::{self, Result}; pub struct App { pub device: Path, @@ -51,7 +49,7 @@ pub struct Task { pub kind: Kind, pub path: Path, pub priority: u8, - pub resources: Resources, + pub resources: Idents, } pub fn app(app: check::App) -> Result<App> { @@ -63,80 +61,16 @@ pub fn app(app: check::App) -> Result<App> { tasks: app.tasks .into_iter() .map(|(k, v)| { - let v = - ::check::task(k.as_ref(), v).chain_err(|| format!("checking task `{}`", k))?; + let v = ::check::task(k.as_ref(), v)?; Ok((k, v)) }) .collect::<Result<_>>()?, }; - ::check::resources(&app).chain_err(|| "checking `resources`")?; - Ok(app) } -fn resources(app: &App) -> Result<()> { - for name in &app.init.resources { - if let Some(resource) = app.resources.get(name) { - ensure!( - resource.expr.is_some(), - "resource `{}`, allocated to `init`, must have an initial value", - name - ); - } else { - bail!( - "resource `{}`, allocated to `init`, must be a data resource", - name - ); - } - - ensure!( - !app.idle.resources.contains(name), - "resources assigned to `init` can't be shared with `idle`" - ); - - ensure!( - app.tasks - .iter() - .all(|(_, task)| !task.resources.contains(name)), - "resources assigned to `init` can't be shared with tasks" - ) - } - - for resource in app.resources.keys() { - if app.init.resources.contains(resource) { - continue; - } - - if app.idle.resources.contains(resource) { - continue; - } - - if app.tasks - .values() - .any(|task| task.resources.contains(resource)) - { - continue; - } - - bail!("resource `{}` is unused", resource); - } - - for (name, task) in &app.tasks { - for resource in &task.resources { - ensure!( - app.resources.contains_key(&resource), - "task {} contains an undeclared resource with name {}", - name, - resource - ); - } - } - - Ok(()) -} - fn task(name: &str, task: syntax::check::Task) -> Result<Task> { let kind = match Exception::from(name) { Some(e) => { @@ -147,23 +81,14 @@ fn task(name: &str, task: syntax::check::Task) -> Result<Task> { Kind::Exception(e) } - None => { - if task.enabled == Some(true) { - bail!( - "`enabled: true` is the default value; this line can be \ - omitted" - ); - } - - Kind::Interrupt { - enabled: task.enabled.unwrap_or(true), - } - } + None => Kind::Interrupt { + enabled: task.enabled.unwrap_or(true), + }, }; Ok(Task { kind, - path: task.path.ok_or("`path` field is missing")?, + path: task.path, priority: task.priority.unwrap_or(1), resources: task.resources, }) |