aboutsummaryrefslogtreecommitdiff
path: root/macros/src/syntax/parse
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/syntax/parse')
-rw-r--r--macros/src/syntax/parse/app.rs58
-rw-r--r--macros/src/syntax/parse/hardware_task.rs44
-rw-r--r--macros/src/syntax/parse/idle.rs18
-rw-r--r--macros/src/syntax/parse/init.rs22
-rw-r--r--macros/src/syntax/parse/software_task.rs26
-rw-r--r--macros/src/syntax/parse/util.rs26
6 files changed, 60 insertions, 134 deletions
diff --git a/macros/src/syntax/parse/app.rs b/macros/src/syntax/parse/app.rs
index dd7c3999..8a9242e9 100644
--- a/macros/src/syntax/parse/app.rs
+++ b/macros/src/syntax/parse/app.rs
@@ -5,14 +5,14 @@ use proc_macro2::TokenStream as TokenStream2;
use syn::{
parse::{self, ParseStream, Parser},
spanned::Spanned,
- Expr, ExprArray, Fields, ForeignItem, Ident, Item, LitBool, Path, Token, Type, Visibility,
+ Expr, ExprArray, Fields, ForeignItem, Ident, Item, LitBool, Path, Token, Visibility,
};
use super::Input;
use crate::syntax::{
ast::{
App, AppArgs, Dispatcher, Dispatchers, HardwareTask, Idle, IdleArgs, Init, InitArgs,
- LocalResource, Monotonic, MonotonicArgs, SharedResource, SoftwareTask,
+ LocalResource, SharedResource, SoftwareTask,
},
parse::{self as syntax_parse, util},
Either, Map, Set,
@@ -150,7 +150,6 @@ impl App {
let mut shared_resources = Map::new();
let mut local_resources_ident = None;
let mut local_resources = Map::new();
- let mut monotonics = Map::new();
let mut hardware_tasks = Map::new();
let mut software_tasks = Map::new();
let mut user_imports = vec![];
@@ -158,7 +157,6 @@ impl App {
let mut seen_idents = HashSet::<Ident>::new();
let mut bindings = HashSet::<Ident>::new();
- let mut monotonic_types = HashSet::<Type>::new();
let mut check_binding = |ident: &Ident| {
if bindings.contains(ident) {
@@ -186,19 +184,6 @@ impl App {
Ok(())
};
- let mut check_monotonic = |ty: &Type| {
- if monotonic_types.contains(ty) {
- return Err(parse::Error::new(
- ty.span(),
- "this type is already used by another monotonic",
- ));
- } else {
- monotonic_types.insert(ty.clone());
- }
-
- Ok(())
- };
-
for mut item in input.items {
match item {
Item::Fn(mut item) => {
@@ -448,44 +433,6 @@ impl App {
// Store the user provided use-statements
user_imports.push(itemuse_.clone());
}
- Item::Type(ref mut type_item) => {
- // Match types with the attribute #[monotonic]
- if let Some(pos) = type_item
- .attrs
- .iter()
- .position(|attr| util::attr_eq(attr, "monotonic"))
- {
- let span = type_item.ident.span();
-
- if monotonics.contains_key(&type_item.ident) {
- return Err(parse::Error::new(
- span,
- "`#[monotonic(...)]` on a specific type must appear at most once",
- ));
- }
-
- if type_item.vis != Visibility::Inherited {
- return Err(parse::Error::new(
- type_item.span(),
- "this item must have inherited / private visibility",
- ));
- }
-
- check_monotonic(&*type_item.ty)?;
-
- let m = type_item.attrs.remove(pos);
- let args = MonotonicArgs::parse(m)?;
-
- check_binding(&args.binds)?;
-
- let monotonic = Monotonic::parse(args, type_item, span)?;
-
- monotonics.insert(type_item.ident.clone(), monotonic);
- }
-
- // All types are passed on
- user_code.push(item.clone());
- }
_ => {
// Anything else within the module should not make any difference
user_code.push(item.clone());
@@ -524,7 +471,6 @@ impl App {
name: input.ident,
init,
idle,
- monotonics,
shared_resources,
local_resources,
user_imports,
diff --git a/macros/src/syntax/parse/hardware_task.rs b/macros/src/syntax/parse/hardware_task.rs
index 304bfcd3..ff94bc51 100644
--- a/macros/src/syntax/parse/hardware_task.rs
+++ b/macros/src/syntax/parse/hardware_task.rs
@@ -23,19 +23,17 @@ impl HardwareTask {
}
if valid_signature {
- if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) {
- if rest.is_empty() {
- let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs);
+ if let Some(context) = util::parse_inputs(item.sig.inputs, &name) {
+ let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs);
- return Ok(HardwareTask {
- args,
- cfgs,
- attrs,
- context,
- stmts: item.block.stmts,
- is_extern: false,
- });
- }
+ return Ok(HardwareTask {
+ args,
+ cfgs,
+ attrs,
+ context,
+ stmts: item.block.stmts,
+ is_extern: false,
+ });
}
}
@@ -69,19 +67,17 @@ impl HardwareTask {
}
if valid_signature {
- if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) {
- if rest.is_empty() {
- let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs);
+ if let Some(context) = util::parse_inputs(item.sig.inputs, &name) {
+ let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs);
- return Ok(HardwareTask {
- args,
- cfgs,
- attrs,
- context,
- stmts: Vec::<Stmt>::new(),
- is_extern: true,
- });
- }
+ return Ok(HardwareTask {
+ args,
+ cfgs,
+ attrs,
+ context,
+ stmts: Vec::<Stmt>::new(),
+ is_extern: true,
+ });
}
}
diff --git a/macros/src/syntax/parse/idle.rs b/macros/src/syntax/parse/idle.rs
index d9f3a99e..ffec358f 100644
--- a/macros/src/syntax/parse/idle.rs
+++ b/macros/src/syntax/parse/idle.rs
@@ -21,16 +21,14 @@ impl Idle {
let name = item.sig.ident.to_string();
if valid_signature {
- if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) {
- if rest.is_empty() {
- return Ok(Idle {
- args,
- attrs: item.attrs,
- context,
- name: item.sig.ident,
- stmts: item.block.stmts,
- });
- }
+ if let Some(context) = util::parse_inputs(item.sig.inputs, &name) {
+ return Ok(Idle {
+ args,
+ attrs: item.attrs,
+ context,
+ name: item.sig.ident,
+ stmts: item.block.stmts,
+ });
}
}
diff --git a/macros/src/syntax/parse/init.rs b/macros/src/syntax/parse/init.rs
index 727ee205..5ec1abaf 100644
--- a/macros/src/syntax/parse/init.rs
+++ b/macros/src/syntax/parse/init.rs
@@ -25,18 +25,16 @@ impl Init {
if let Ok((user_shared_struct, user_local_struct)) =
util::type_is_init_return(&item.sig.output, &name)
{
- if let Some((context, Ok(rest))) = util::parse_inputs(item.sig.inputs, &name) {
- if rest.is_empty() {
- return Ok(Init {
- args,
- attrs: item.attrs,
- context,
- name: item.sig.ident,
- stmts: item.block.stmts,
- user_shared_struct,
- user_local_struct,
- });
- }
+ if let Some(context) = util::parse_inputs(item.sig.inputs, &name) {
+ return Ok(Init {
+ args,
+ attrs: item.attrs,
+ context,
+ name: item.sig.ident,
+ stmts: item.block.stmts,
+ user_shared_struct,
+ user_local_struct,
+ });
}
}
}
diff --git a/macros/src/syntax/parse/software_task.rs b/macros/src/syntax/parse/software_task.rs
index 2b1ac4a5..6be597e8 100644
--- a/macros/src/syntax/parse/software_task.rs
+++ b/macros/src/syntax/parse/software_task.rs
@@ -8,17 +8,16 @@ use crate::syntax::{
impl SoftwareTask {
pub(crate) fn parse(args: SoftwareTaskArgs, item: ItemFn) -> parse::Result<Self> {
- let valid_signature =
- util::check_fn_signature(&item, true) && util::type_is_unit(&item.sig.output);
+ let valid_signature = util::check_fn_signature(&item, true)
+ && util::type_is_unit(&item.sig.output)
+ && item.sig.asyncness.is_some();
let span = item.sig.ident.span();
let name = item.sig.ident.to_string();
- let is_async = item.sig.asyncness.is_some();
-
if valid_signature {
- if let Some((context, Ok(inputs))) = util::parse_inputs(item.sig.inputs, &name) {
+ if let Some(context) = util::parse_inputs(item.sig.inputs, &name) {
let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs);
return Ok(SoftwareTask {
@@ -26,10 +25,8 @@ impl SoftwareTask {
attrs,
cfgs,
context,
- inputs,
stmts: item.block.stmts,
is_extern: false,
- is_async,
});
}
}
@@ -37,7 +34,7 @@ impl SoftwareTask {
Err(parse::Error::new(
span,
&format!(
- "this task handler must have type signature `(async) fn({}::Context, ..)`",
+ "this task handler must have type signature `async fn({}::Context)`",
name
),
))
@@ -49,17 +46,16 @@ impl SoftwareTask {
args: SoftwareTaskArgs,
item: ForeignItemFn,
) -> parse::Result<Self> {
- let valid_signature =
- util::check_foreign_fn_signature(&item, true) && util::type_is_unit(&item.sig.output);
+ let valid_signature = util::check_foreign_fn_signature(&item, true)
+ && util::type_is_unit(&item.sig.output)
+ && item.sig.asyncness.is_some();
let span = item.sig.ident.span();
let name = item.sig.ident.to_string();
- let is_async = item.sig.asyncness.is_some();
-
if valid_signature {
- if let Some((context, Ok(inputs))) = util::parse_inputs(item.sig.inputs, &name) {
+ if let Some(context) = util::parse_inputs(item.sig.inputs, &name) {
let FilterAttrs { cfgs, attrs, .. } = util::filter_attributes(item.attrs);
return Ok(SoftwareTask {
@@ -67,10 +63,8 @@ impl SoftwareTask {
attrs,
cfgs,
context,
- inputs,
stmts: Vec::<Stmt>::new(),
is_extern: true,
- is_async,
});
}
}
@@ -78,7 +72,7 @@ impl SoftwareTask {
Err(parse::Error::new(
span,
&format!(
- "this task handler must have type signature `(async) fn({}::Context, ..)`",
+ "this task handler must have type signature `async fn({}::Context)`",
name
),
))
diff --git a/macros/src/syntax/parse/util.rs b/macros/src/syntax/parse/util.rs
index 3fa51ef8..119129c0 100644
--- a/macros/src/syntax/parse/util.rs
+++ b/macros/src/syntax/parse/util.rs
@@ -3,8 +3,8 @@ use syn::{
parse::{self, ParseStream},
punctuated::Punctuated,
spanned::Spanned,
- Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, PatType, Path,
- PathArguments, ReturnType, Token, Type, Visibility,
+ Abi, AttrStyle, Attribute, Expr, FnArg, ForeignItemFn, Ident, ItemFn, Pat, Path, PathArguments,
+ ReturnType, Token, Type, Visibility,
};
use crate::syntax::{
@@ -231,29 +231,23 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
Ok(resources)
}
-type ParseInputResult = Option<(Box<Pat>, Result<Vec<PatType>, FnArg>)>;
-
-pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> ParseInputResult {
+pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> Option<Box<Pat>> {
let mut inputs = inputs.into_iter();
match inputs.next() {
Some(FnArg::Typed(first)) => {
if type_is_path(&first.ty, &[name, "Context"]) {
- let rest = inputs
- .map(|arg| match arg {
- FnArg::Typed(arg) => Ok(arg),
- _ => Err(arg),
- })
- .collect::<Result<Vec<_>, _>>();
-
- Some((first.pat, rest))
- } else {
- None
+ // No more inputs
+ if inputs.next().is_none() {
+ return Some(first.pat);
+ }
}
}
- _ => None,
+ _ => {}
}
+
+ None
}
pub fn type_is_bottom(ty: &ReturnType) -> bool {