use proc_macro2::TokenStream as TokenStream2; use quote::quote; use rtic_syntax::{ast::App, Context}; use crate::{ analyze::Analysis, check::Extra, codegen::{locals, module, resources_struct, util}, }; /// Generates support code for `#[init]` functions pub fn codegen( core: u8, app: &App, analysis: &Analysis, extra: &Extra, ) -> ( // const_app_idle -- the `${init}Resources` constructor Option, // root_init -- items that must be placed in the root of the crate: // - the `${init}Locals` struct // - the `${init}Resources` struct // - the `${init}LateResources` struct // - the `${init}` module, which contains types like `${init}::Context` Vec, // user_init -- the `#[init]` function written by the user Option, // call_init -- the call to the user `#[init]` if there's one Option, ) { if let Some(init) = app.inits.get(&core) { let cfg_core = util::cfg_core(core, app.args.cores); let mut needs_lt = false; let name = &init.name; let mut root_init = vec![]; let ret = { let late_fields = analysis .late_resources .get(&core) .map(|resources| { resources .iter() .map(|name| { let ty = &app.late_resources[name].ty; let cfgs = &app.late_resources[name].cfgs; quote!( #(#cfgs)* pub #name: #ty ) }) .collect::>() }) .unwrap_or(vec![]); if !late_fields.is_empty() { let late_resources = util::late_resources_ident(&name); root_init.push(quote!( /// Resources initialized at runtime #cfg_core #[allow(non_snake_case)] pub struct #late_resources { #(#late_fields),* } )); Some(quote!(-> #name::LateResources)) } else { None } }; let mut locals_pat = None; let mut locals_new = None; if !init.locals.is_empty() { let (struct_, pat) = locals::codegen(Context::Init(core), &init.locals, core, app); locals_new = Some(quote!(#name::Locals::new())); locals_pat = Some(pat); root_init.push(struct_); } let context = &init.context; let attrs = &init.attrs; let stmts = &init.stmts; let section = util::link_section("text", core); let locals_pat = locals_pat.iter(); let user_init = Some(quote!( #(#attrs)* #cfg_core #[allow(non_snake_case)] #section fn #name(#(#locals_pat,)* #context: #name::Context) #ret { #(#stmts)* } )); let mut const_app = None; if !init.args.resources.is_empty() { let (item, constructor) = resources_struct::codegen(Context::Init(core), 0, &mut needs_lt, app, analysis); root_init.push(item); const_app = Some(constructor); } let locals_new = locals_new.iter(); let call_init = Some( quote!(let late = crate::#name(#(#locals_new,)* #name::Context::new(core.into()));), ); root_init.push(module::codegen(Context::Init(core), needs_lt, app, extra)); (const_app, root_init, user_init, call_init) } else { (None, vec![], None, None) } } rm>
AgeCommit message (Expand)AuthorFilesLines
2018-06-30Dep ensure -update (#1912)Gravatar Miek Gieben 1-2/+2
2018-06-30plugin/etcdv3: Add etcd v3 plugin (#1702)Gravatar Nitish Tiwari 10327-82/+4196998
2018-06-29request: Add LocalAddr() and LocalPort() (#1907)Gravatar Miek Gieben 1-4/+14
2018-06-29plugin/metadata: some cleanups (#1906)Gravatar Miek Gieben 7-58/+53
2018-06-29update corefile(5) and regen (#1904)Gravatar Miek Gieben 29-42/+58
2018-06-29plugin/metadata: add metadata plugin (#1894)Gravatar Eugen Kleiner 19-130/+655
2018-06-27Fix max-age in http server (#1890)Gravatar Miek Gieben 5-68/+91
2018-06-27Watch feature (#1527)Gravatar John Belamaric 17-57/+977
2018-06-26plugin/cache: Fix: metric `cache miss total` shall include ttl case (#1897)Gravatar Jun Li 1-8/+9
2018-06-24Replace gh-release with curl (#1896)Gravatar Yong Tang 1-3/+10
2018-06-22retry creating dnstest.Server if tcp or udp port is in use (#1799)Gravatar Ruslan Drozhdzh 1-10/+20
2018-06-21plugin/template: fix CNAME upstream handling (#1886)Gravatar Chris O'Haver 4-4/+97
2018-06-21Makefile fixes: (#1892)Gravatar Miek Gieben 4-17/+12
2018-06-21plugin/forward: Increase minimum read timeout to 200ms (#1889)Gravatar Tobias Schmidt 5-10/+10
2018-06-20Rename forward metrics socket_count_total to sockets_open (#1885)Gravatar Tobias Schmidt 1-1/+1
2018-06-20remove deprecated code (#1888)Gravatar Miek Gieben 3-4/+0
2018-06-19Ensure cache.ResponseWriter can be used asynchronously during prefetch (#1884)Gravatar Tobias Schmidt 2-8/+40
2018-06-19Release 1.1.4v1.1.4Gravatar Miek Gieben 3-4/+7
2018-06-18Follow up on #1867 : use one map in backend_lookup (#1869)Gravatar Miek Gieben 1-32/+33
2018-06-18Plugin/Rewrite - review documentation of "append" (#1877)Gravatar Francois Tur 1-2/+2
2018-06-15plugin/forward: add REFUSED test (#1878)Gravatar Miek Gieben 10-10/+62
2018-06-15Plugin/Forward - autotune the dialTimeout for connection (#1852)Gravatar Francois Tur 5-52/+84
2018-06-13Run make -f Makefile.doc (#1875)Gravatar Miek Gieben 9-71/+50
2018-06-13Bump dns version to 1.0.8 (#1873)Gravatar Miek Gieben 1-1/+1
2018-06-12plugin/file: fix local CNAME lookup (#1866)Gravatar Miek Gieben 5-28/+83
2018-06-11Remove dnsutil.Dedup (#1867)Gravatar Miek Gieben 6-61/+66
2018-06-07Update the pr template (#1862)Gravatar Miek Gieben 1-5/+1
2018-06-07Normalizing Response Duration in Log Plugin (#1860)Gravatar Malcolm Akinje 2-1/+5
2018-06-05plugin/forward: fix alignment for sync.Atomic (#1855)Gravatar Miek Gieben 1-3/+3
2018-06-05Update Makefile.release for docker image build (#1856)Gravatar Yong Tang 1-15/+0
2018-06-04Docker: drop alpine (#1843)Gravatar Miek Gieben 1-3/+6
2018-06-02Fix presubmit (#1850)Gravatar Miek Gieben 2-15/+15
2018-06-02presubmit: Check errorf as well (#1845)Gravatar Miek Gieben 19-52/+57