Wiggle: tweaks to internal interfaces (#1469)

* [wiggle]: wiggle-generate internal interface for Names simplified

im using it in other libraries where I don't want to construct a
wiggle_generate::Config just to use the ctx_type out of it.

* wiggle: define_func can get trait name as argument

this flexibility needed for some customization over in lucet
This commit is contained in:
Pat Hickey
2020-04-06 07:51:17 -07:00
committed by GitHub
parent 45b3ed142c
commit c2cb4ea3ff
3 changed files with 17 additions and 10 deletions

View File

@@ -15,13 +15,18 @@ pub use names::Names;
pub use types::define_datatype;
pub fn generate(doc: &witx::Document, config: &Config) -> TokenStream {
let names = Names::new(config); // TODO parse the names from the invocation of the macro, or from a file?
// TODO at some point config should grow more ability to configure name
// overrides.
let names = Names::new(&config.ctx.name);
let types = doc.typenames().map(|t| define_datatype(&names, &t));
let modules = doc.modules().map(|module| {
let modname = names.module(&module.name);
let fs = module.funcs().map(|f| define_func(&names, &f));
let trait_name = names.trait_name(&module.name);
let fs = module
.funcs()
.map(|f| define_func(&names, &f, quote!(#trait_name)));
let modtrait = define_module_trait(&names, &module);
let ctx_type = names.ctx_type();
quote!(