diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 1bda8d2f78..34f2bb619b 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -18,25 +18,7 @@ mod syntax; #[doc(hidden)] #[proc_macro_attribute] pub fn mock_app(args: TokenStream, input: TokenStream) -> TokenStream { - let mut settings = syntax::Settings::default(); - let mut rtic_args = vec![]; - for arg in args.to_string().split(',') { - if arg.trim() == "parse_binds" { - settings.parse_binds = true; - } else if arg.trim() == "parse_extern_interrupt" { - settings.parse_extern_interrupt = true; - } else { - rtic_args.push(arg.to_string()); - } - } - - // rtic_args.push("device = mock".into()); - - let args = rtic_args.join(", ").parse(); - - println!("args: {:?}", args); - - if let Err(e) = syntax::parse(args.unwrap(), input, settings) { + if let Err(e) = syntax::parse(args, input) { e.to_compile_error().into() } else { "fn main() {}".parse().unwrap() @@ -52,12 +34,7 @@ pub fn mock_app(args: TokenStream, input: TokenStream) -> TokenStream { /// Should never panic, cargo feeds a path which is later converted to a string #[proc_macro_attribute] pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { - let mut settings = syntax::Settings::default(); - settings.optimize_priorities = false; - settings.parse_binds = true; - settings.parse_extern_interrupt = true; - - let (app, analysis) = match syntax::parse(args, input, settings) { + let (app, analysis) = match syntax::parse(args, input) { Err(e) => return e.to_compile_error().into(), Ok(x) => x, }; diff --git a/macros/src/syntax.rs b/macros/src/syntax.rs index 09b2ab3d2c..d6f5a476b5 100644 --- a/macros/src/syntax.rs +++ b/macros/src/syntax.rs @@ -13,7 +13,6 @@ mod accessors; pub mod analyze; pub mod ast; mod check; -mod optimize; mod parse; /// An ordered map keyed by identifier @@ -31,10 +30,10 @@ pub enum Context<'a> { /// The `init`-ialization function Init, - /// A software task: `#[task]` + /// A async software task SoftwareTask(&'a Ident), - /// A hardware task: `#[exception]` or `#[interrupt]` + /// A hardware task HardwareTask(&'a Ident), } @@ -93,36 +92,21 @@ impl<'a> Context<'a> { } } -/// Parser and optimizer configuration -#[derive(Default)] -#[non_exhaustive] -pub struct Settings { - /// Whether to accept the `binds` argument in `#[task]` or not - pub parse_binds: bool, - /// Whether to parse `extern` interrupts (functions) or not - pub parse_extern_interrupt: bool, - /// Whether to "compress" priorities or not - pub optimize_priorities: bool, -} - /// Parses the input of the `#[app]` attribute pub fn parse( args: TokenStream, input: TokenStream, - settings: Settings, ) -> Result<(ast::App, analyze::Analysis), syn::parse::Error> { - parse2(args.into(), input.into(), settings) + parse2(args.into(), input.into()) } /// `proc_macro2::TokenStream` version of `parse` pub fn parse2( args: TokenStream2, input: TokenStream2, - settings: Settings, ) -> Result<(ast::App, analyze::Analysis), syn::parse::Error> { - let mut app = parse::app(args, input, &settings)?; + let app = parse::app(args, input)?; check::app(&app)?; - optimize::app(&mut app, &settings); match analyze::app(&app) { Err(e) => Err(e), diff --git a/macros/src/syntax/optimize.rs b/macros/src/syntax/optimize.rs index 87a6258d21..e83ba31bd1 100644 --- a/macros/src/syntax/optimize.rs +++ b/macros/src/syntax/optimize.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeSet, HashMap}; -use crate::syntax::{ast::App, Settings}; +use crate::syntax::ast::App; pub fn app(app: &mut App, settings: &Settings) { // "compress" priorities diff --git a/macros/src/syntax/parse.rs b/macros/src/syntax/parse.rs index 74f94f2be7..ceedaa9891 100644 --- a/macros/src/syntax/parse.rs +++ b/macros/src/syntax/parse.rs @@ -20,15 +20,15 @@ use crate::syntax::{ App, AppArgs, HardwareTaskArgs, IdleArgs, InitArgs, MonotonicArgs, SoftwareTaskArgs, TaskLocal, }, - Either, Settings, + Either, }; // Parse the app, both app arguments and body (input) -pub fn app(args: TokenStream2, input: TokenStream2, settings: &Settings) -> parse::Result { +pub fn app(args: TokenStream2, input: TokenStream2) -> parse::Result { let args = AppArgs::parse(args)?; let input: Input = syn::parse2(input)?; - App::parse(args, input, settings) + App::parse(args, input) } pub(crate) struct Input { @@ -188,10 +188,7 @@ fn idle_args(tokens: TokenStream2) -> parse::Result { .parse2(tokens) } -fn task_args( - tokens: TokenStream2, - settings: &Settings, -) -> parse::Result> { +fn task_args(tokens: TokenStream2) -> parse::Result> { (|input: ParseStream<'_>| -> parse::Result> { if input.is_empty() { return Ok(Either::Right(SoftwareTaskArgs::default())); @@ -242,14 +239,7 @@ fn task_args( let _: Token![=] = content.parse()?; match &*ident_s { - "binds" if !settings.parse_binds => { - return Err(parse::Error::new( - ident.span(), - "Unexpected bind in task argument. Binds are only parsed if Settings::parse_binds is set.", - )); - } - - "binds" if settings.parse_binds => { + "binds" => { if binds.is_some() { return Err(parse::Error::new( ident.span(), diff --git a/macros/src/syntax/parse/app.rs b/macros/src/syntax/parse/app.rs index 7eb415d337..dd7c399908 100644 --- a/macros/src/syntax/parse/app.rs +++ b/macros/src/syntax/parse/app.rs @@ -15,7 +15,7 @@ use crate::syntax::{ LocalResource, Monotonic, MonotonicArgs, SharedResource, SoftwareTask, }, parse::{self as syntax_parse, util}, - Either, Map, Set, Settings, + Either, Map, Set, }; impl AppArgs { @@ -142,7 +142,7 @@ impl AppArgs { } impl App { - pub(crate) fn parse(args: AppArgs, input: Input, settings: &Settings) -> parse::Result { + pub(crate) fn parse(args: AppArgs, input: Input) -> parse::Result { let mut init = None; let mut idle = None; @@ -253,7 +253,7 @@ impl App { )); } - match syntax_parse::task_args(item.attrs.remove(pos).tokens, settings)? { + match syntax_parse::task_args(item.attrs.remove(pos).tokens)? { Either::Left(args) => { check_binding(&args.binds)?; check_ident(&item.sig.ident)?; @@ -410,10 +410,7 @@ impl App { )); } - match syntax_parse::task_args( - item.attrs.remove(pos).tokens, - settings, - )? { + match syntax_parse::task_args(item.attrs.remove(pos).tokens)? { Either::Left(args) => { check_binding(&args.binds)?; check_ident(&item.sig.ident)?; diff --git a/macros/ui/extern-interrupt-used.rs b/macros/ui/extern-interrupt-used.rs index 71dc50f397..a6e0b3b29a 100644 --- a/macros/ui/extern-interrupt-used.rs +++ b/macros/ui/extern-interrupt-used.rs @@ -1,6 +1,6 @@ #![no_main] -#[rtic_macros::mock_app(parse_extern_interrupt, parse_binds, device = mock, dispatchers = [EXTI0])] +#[rtic_macros::mock_app(device = mock, dispatchers = [EXTI0])] mod app { #[shared] struct Shared {} diff --git a/macros/ui/interrupt-double.rs b/macros/ui/interrupt-double.rs index 1133c5cfd9..e2addc7ce6 100644 --- a/macros/ui/interrupt-double.rs +++ b/macros/ui/interrupt-double.rs @@ -1,6 +1,6 @@ #![no_main] -#[rtic_macros::mock_app(parse_binds, device = mock)] +#[rtic_macros::mock_app(device = mock)] mod app { #[task(binds = UART0)] fn foo(_: foo::Context) {} diff --git a/macros/ui/monotonic-binds-collision-task.rs b/macros/ui/monotonic-binds-collision-task.rs index 57c59c1b01..1c58f9ddaf 100644 --- a/macros/ui/monotonic-binds-collision-task.rs +++ b/macros/ui/monotonic-binds-collision-task.rs @@ -1,6 +1,6 @@ #![no_main] -#[rtic_macros::mock_app(parse_extern_interrupt, parse_binds, device = mock)] +#[rtic_macros::mock_app(device = mock)] mod app { #[monotonic(binds = Tim1)] type Fast1 = hal::Tim1Monotonic; diff --git a/macros/ui/task-bind.rs b/macros/ui/task-bind.rs deleted file mode 100644 index de60524314..0000000000 --- a/macros/ui/task-bind.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![no_main] - -#[rtic_macros::mock_app(device = mock)] -mod app { - #[task(binds = UART0)] - fn foo(_: foo::Context) {} -} diff --git a/macros/ui/task-bind.stderr b/macros/ui/task-bind.stderr deleted file mode 100644 index 60cfdc8b86..0000000000 --- a/macros/ui/task-bind.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: Unexpected bind in task argument. Binds are only parsed if Settings::parse_binds is set. - --> $DIR/task-bind.rs:5:12 - | -5 | #[task(binds = UART0)] - | ^^^^^ diff --git a/macros/ui/task-interrupt-same-prio-spawn.rs b/macros/ui/task-interrupt-same-prio-spawn.rs index 741e60e462..1d5f1f8429 100644 --- a/macros/ui/task-interrupt-same-prio-spawn.rs +++ b/macros/ui/task-interrupt-same-prio-spawn.rs @@ -1,6 +1,6 @@ #![no_main] -#[rtic_macros::mock_app(parse_binds, device = mock)] +#[rtic_macros::mock_app(device = mock)] mod app { #[task(binds = SysTick, only_same_priority_spawn_please_fix_me)] fn foo(_: foo::Context) {} diff --git a/macros/ui/task-interrupt.rs b/macros/ui/task-interrupt.rs index 71fef9aba0..5e063def3b 100644 --- a/macros/ui/task-interrupt.rs +++ b/macros/ui/task-interrupt.rs @@ -1,6 +1,6 @@ #![no_main] -#[rtic_macros::mock_app(parse_binds, device = mock)] +#[rtic_macros::mock_app(device = mock)] mod app { #[task(binds = SysTick)] fn foo(_: foo::Context) {} diff --git a/macros/ui/task-priority-too-low.rs b/macros/ui/task-priority-too-low.rs index beed4de1e1..16e05577ce 100644 --- a/macros/ui/task-priority-too-low.rs +++ b/macros/ui/task-priority-too-low.rs @@ -1,6 +1,6 @@ #![no_main] -#[rtic_macros::mock_app(parse_binds, device = mock)] +#[rtic_macros::mock_app(device = mock)] mod app { #[task(binds = UART0, priority = 0)] fn foo(_: foo::Context) {}