mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 12:31:22 +00:00
Backend refactor (#411)
* remove BindgenAttrs from other backend::ast structs This is primarily a tool for use with the macro crate. Most of these attributes were ignored in the actual codegen, but a few were still being used. This is confusing when trying to add other sources for codegen (such as webidl and typescript). * move parsing logic to macro crate This makes the backend crate solely concerned with having an ast for which we can generate code.
This commit is contained in:
committed by
Alex Crichton
parent
056b45aeed
commit
2d50d5209b
@ -3,21 +3,27 @@
|
||||
extern crate proc_macro;
|
||||
extern crate proc_macro2;
|
||||
extern crate quote;
|
||||
extern crate wasm_bindgen_shared as shared;
|
||||
#[macro_use]
|
||||
extern crate syn;
|
||||
extern crate wasm_bindgen_backend as backend;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::ToTokens;
|
||||
|
||||
mod parser;
|
||||
|
||||
use parser::MacroParse;
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn wasm_bindgen(attr: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let item = syn::parse::<syn::Item>(input.clone()).expect("expected a valid Rust item");
|
||||
let opts = syn::parse::<backend::ast::BindgenAttrs>(attr)
|
||||
.expect("invalid arguments to #[wasm_bindgen]");
|
||||
let opts =
|
||||
syn::parse::<parser::BindgenAttrs>(attr).expect("invalid arguments to #[wasm_bindgen]");
|
||||
|
||||
let mut ret = proc_macro2::TokenStream::new();
|
||||
let mut program = backend::ast::Program::default();
|
||||
program.push_item(item, Some(opts), &mut ret);
|
||||
item.macro_parse(&mut program, (Some(opts), &mut ret));
|
||||
program.to_tokens(&mut ret);
|
||||
|
||||
if cfg!(feature = "xxx_debug_only_print_generated_code") {
|
||||
|
Reference in New Issue
Block a user