aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2023-01-03 07:51:35 +0100
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2023-03-01 00:31:04 +0100
commitd7ed7a8b9f78344f6855fa1c2655ae0d85e44068 (patch)
treea5888257f8047b3ba67e143aa5104c1f496ad036
parent9829d0ac07180967208403610bc9a25249b9fe85 (diff)
downloadrtic-d7ed7a8b9f78344f6855fa1c2655ae0d85e44068.tar.gz
rtic-d7ed7a8b9f78344f6855fa1c2655ae0d85e44068.tar.zst
rtic-d7ed7a8b9f78344f6855fa1c2655ae0d85e44068.zip
syntax: Remove parse settings struct
-rw-r--r--macros/src/lib.rs27
-rw-r--r--macros/src/syntax.rs24
-rw-r--r--macros/src/syntax/optimize.rs2
-rw-r--r--macros/src/syntax/parse.rs20
-rw-r--r--macros/src/syntax/parse/app.rs11
-rw-r--r--macros/ui/extern-interrupt-used.rs2
-rw-r--r--macros/ui/interrupt-double.rs2
-rw-r--r--macros/ui/monotonic-binds-collision-task.rs2
-rw-r--r--macros/ui/task-bind.rs7
-rw-r--r--macros/ui/task-bind.stderr5
-rw-r--r--macros/ui/task-interrupt-same-prio-spawn.rs2
-rw-r--r--macros/ui/task-interrupt.rs2
-rw-r--r--macros/ui/task-priority-too-low.rs2
13 files changed, 22 insertions, 86 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 1bda8d2f..34f2bb61 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 09b2ab3d..d6f5a476 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 87a6258d..e83ba31b 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 74f94f2b..ceedaa98 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<App> {
+pub fn app(args: TokenStream2, input: TokenStream2) -> parse::Result<App> {
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<IdleArgs> {
.parse2(tokens)
}
-fn task_args(
- tokens: TokenStream2,
- settings: &Settings,
-) -> parse::Result<Either<HardwareTaskArgs, SoftwareTaskArgs>> {
+fn task_args(tokens: TokenStream2) -> parse::Result<Either<HardwareTaskArgs, SoftwareTaskArgs>> {
(|input: ParseStream<'_>| -> parse::Result<Either<HardwareTaskArgs, SoftwareTaskArgs>> {
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 7eb415d3..dd7c3999 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<Self> {
+ pub(crate) fn parse(args: AppArgs, input: Input) -> parse::Result<Self> {
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 71dc50f3..a6e0b3b2 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 1133c5cf..e2addc7c 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 57c59c1b..1c58f9dd 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 de605243..00000000
--- 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 60cfdc8b..00000000
--- 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 741e60e4..1d5f1f84 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 71fef9ab..5e063def 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 beed4de1..16e05577 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) {}