mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-02 15:41:24 +00:00
webidl: add support for typedefs
This commit is contained in:
parent
3710d87f3b
commit
d065f4b05d
@ -10,6 +10,7 @@ pub struct Program {
|
|||||||
pub imports: Vec<Import>,
|
pub imports: Vec<Import>,
|
||||||
pub enums: Vec<Enum>,
|
pub enums: Vec<Enum>,
|
||||||
pub structs: Vec<Struct>,
|
pub structs: Vec<Struct>,
|
||||||
|
pub type_aliases: Vec<TypeAlias>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
|
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
|
||||||
@ -120,6 +121,13 @@ pub enum TypeLocation {
|
|||||||
ExportRet,
|
ExportRet,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
|
||||||
|
pub struct TypeAlias {
|
||||||
|
pub vis: syn::Visibility,
|
||||||
|
pub dest: Ident,
|
||||||
|
pub src: syn::Type,
|
||||||
|
}
|
||||||
|
|
||||||
impl Program {
|
impl Program {
|
||||||
pub fn push_item(
|
pub fn push_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -59,6 +59,9 @@ impl ToTokens for ast::Program {
|
|||||||
for e in self.enums.iter() {
|
for e in self.enums.iter() {
|
||||||
e.to_tokens(tokens);
|
e.to_tokens(tokens);
|
||||||
}
|
}
|
||||||
|
for a in self.type_aliases.iter() {
|
||||||
|
a.to_tokens(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
// Generate a static which will eventually be what lives in a custom section
|
// Generate a static which will eventually be what lives in a custom section
|
||||||
// of the wasm executable. For now it's just a plain old static, but we'll
|
// of the wasm executable. For now it's just a plain old static, but we'll
|
||||||
@ -823,3 +826,15 @@ impl ToTokens for ast::ImportStatic {
|
|||||||
}).to_tokens(into);
|
}).to_tokens(into);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToTokens for ast::TypeAlias {
|
||||||
|
fn to_tokens(&self, into: &mut TokenStream) {
|
||||||
|
let vis = &self.vis;
|
||||||
|
let dest = &self.dest;
|
||||||
|
let src = &self.src;
|
||||||
|
(quote! {
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#vis type #dest = #src;
|
||||||
|
}).to_tokens(into);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -123,6 +123,7 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition {
|
|||||||
webidl::ast::Definition::Interface(ref interface) => {
|
webidl::ast::Definition::Interface(ref interface) => {
|
||||||
interface.webidl_parse(program, ())
|
interface.webidl_parse(program, ())
|
||||||
}
|
}
|
||||||
|
webidl::ast::Definition::Typedef(ref typedef) => typedef.webidl_parse(program, ()),
|
||||||
// TODO
|
// TODO
|
||||||
webidl::ast::Definition::Callback(..)
|
webidl::ast::Definition::Callback(..)
|
||||||
| webidl::ast::Definition::Dictionary(..)
|
| webidl::ast::Definition::Dictionary(..)
|
||||||
@ -130,8 +131,7 @@ impl<'a> WebidlParse<'a> for webidl::ast::Definition {
|
|||||||
| webidl::ast::Definition::Implements(..)
|
| webidl::ast::Definition::Implements(..)
|
||||||
| webidl::ast::Definition::Includes(..)
|
| webidl::ast::Definition::Includes(..)
|
||||||
| webidl::ast::Definition::Mixin(..)
|
| webidl::ast::Definition::Mixin(..)
|
||||||
| webidl::ast::Definition::Namespace(..)
|
| webidl::ast::Definition::Namespace(..) => {
|
||||||
| webidl::ast::Definition::Typedef(..) => {
|
|
||||||
warn!("Unsupported WebIDL definition: {:?}", self);
|
warn!("Unsupported WebIDL definition: {:?}", self);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -156,6 +156,34 @@ impl<'a> WebidlParse<'a> for webidl::ast::Interface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> WebidlParse<'a> for webidl::ast::Typedef {
|
||||||
|
type Extra = ();
|
||||||
|
|
||||||
|
fn webidl_parse(&self, program: &mut backend::ast::Program, _: ()) -> Result<()> {
|
||||||
|
let dest = rust_ident(&self.name);
|
||||||
|
let src = match webidl_ty_to_syn_ty(&self.type_, TypePosition::Return) {
|
||||||
|
Some(src) => src,
|
||||||
|
None => {
|
||||||
|
warn!(
|
||||||
|
"typedef's source type is not yet supported: {:?}. Skipping typedef {:?}",
|
||||||
|
*self.type_, self
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
program.type_aliases.push(backend::ast::TypeAlias {
|
||||||
|
vis: syn::Visibility::Public(syn::VisPublic {
|
||||||
|
pub_token: Default::default(),
|
||||||
|
}),
|
||||||
|
dest,
|
||||||
|
src,
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> WebidlParse<'a> for webidl::ast::NonPartialInterface {
|
impl<'a> WebidlParse<'a> for webidl::ast::NonPartialInterface {
|
||||||
type Extra = ();
|
type Extra = ();
|
||||||
|
|
||||||
|
@ -224,6 +224,8 @@ impl Event {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub type DOMHighResTimeStamp = f64;
|
||||||
#[allow(non_upper_case_globals)]
|
#[allow(non_upper_case_globals)]
|
||||||
#[wasm_custom_section = "__wasm_bindgen_unstable"]
|
#[wasm_custom_section = "__wasm_bindgen_unstable"]
|
||||||
const __WASM_BINDGEN_GENERATED_wasm_bindgen_webidl_0_2_11_0 : [ u8 ; 1299usize ] = * b"\x0F\x05\0\0{\"exports\":[],\"enums\":[],\"imports\":[{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"type\"}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_stopPropagation_stop_propagation_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"stopPropagation\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_stopImmediatePropagation_stop_immediate_propagation_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"stopImmediatePropagation\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_preventDefault_prevent_default_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"preventDefault\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_initEvent_init_event_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"initEvent\"}}}],\"structs\":[],\"version\":\"0.2.11 (71107b8e8)\",\"schema_version\":\"4\"}" ;
|
const __WASM_BINDGEN_GENERATED_wasm_bindgen_webidl_0_2_11_0 : [ u8 ; 1299usize ] = * b"\x0F\x05\0\0{\"exports\":[],\"enums\":[],\"imports\":[{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"type\"}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_stopPropagation_stop_propagation_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"stopPropagation\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_stopImmediatePropagation_stop_immediate_propagation_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"stopImmediatePropagation\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_preventDefault_prevent_default_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"preventDefault\"}}},{\"module\":null,\"version\":null,\"js_namespace\":null,\"kind\":{\"kind\":\"function\",\"shim\":\"__wbg_f_initEvent_init_event_Event\",\"catch\":false,\"method\":true,\"js_new\":false,\"structural\":false,\"getter\":null,\"setter\":null,\"class\":\"Event\",\"function\":{\"name\":\"initEvent\"}}}],\"structs\":[],\"version\":\"0.2.11 (71107b8e8)\",\"schema_version\":\"4\"}" ;
|
||||||
|
3
crates/webidl/tests/fixtures/Event.webidl
vendored
3
crates/webidl/tests/fixtures/Event.webidl
vendored
@ -10,6 +10,9 @@
|
|||||||
* liability, trademark and document use rules apply.
|
* liability, trademark and document use rules apply.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO: don't include this here, use Performance.webidl instead
|
||||||
|
typedef double DOMHighResTimeStamp;
|
||||||
|
|
||||||
[Constructor(DOMString type, optional EventInit eventInitDict),
|
[Constructor(DOMString type, optional EventInit eventInitDict),
|
||||||
Exposed=(Window,Worker,System), ProbablyShortLivingWrapper]
|
Exposed=(Window,Worker,System), ProbablyShortLivingWrapper]
|
||||||
interface Event {
|
interface Event {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user