2019-06-13 23:56:59 +02:00
|
|
|
use proc_macro2::TokenStream as TokenStream2;
|
|
|
|
use quote::quote;
|
|
|
|
|
2020-08-27 13:21:56 +02:00
|
|
|
use crate::analyze::Analysis;
|
2020-12-10 20:33:13 +01:00
|
|
|
use rtic_syntax::ast::App;
|
2019-06-13 23:56:59 +02:00
|
|
|
|
|
|
|
/// Generates compile-time assertions that check that types implement the `Send` / `Sync` traits
|
2020-12-10 20:33:13 +01:00
|
|
|
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
2019-06-13 23:56:59 +02:00
|
|
|
let mut stmts = vec![];
|
|
|
|
|
2020-09-01 16:39:05 +02:00
|
|
|
for ty in &analysis.send_types {
|
|
|
|
stmts.push(quote!(rtic::export::assert_send::<#ty>();));
|
|
|
|
}
|
2019-06-13 23:56:59 +02:00
|
|
|
|
2020-09-01 16:39:05 +02:00
|
|
|
for ty in &analysis.sync_types {
|
|
|
|
stmts.push(quote!(rtic::export::assert_sync::<#ty>();));
|
|
|
|
}
|
2019-06-24 14:09:12 +02:00
|
|
|
|
2020-12-10 20:33:13 +01:00
|
|
|
for (_, monotonic) in &app.monotonics {
|
|
|
|
let ty = &monotonic.ty;
|
|
|
|
stmts.push(quote!(rtic::export::assert_monotonic::<#ty>();));
|
|
|
|
}
|
|
|
|
|
2019-06-13 23:56:59 +02:00
|
|
|
stmts
|
|
|
|
}
|