mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-19 16:01:23 +00:00
Merge remote-tracking branch 'origin/master' into webidl_partial_mixins
This commit is contained in:
@ -30,11 +30,11 @@ use std::path::Path;
|
||||
use backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports};
|
||||
use backend::util::{ident_ty, rust_ident, wrap_import_function};
|
||||
use failure::ResultExt;
|
||||
use heck::CamelCase;
|
||||
use heck::{CamelCase, ShoutySnakeCase};
|
||||
use quote::ToTokens;
|
||||
|
||||
use first_pass::{FirstPass, FirstPassRecord};
|
||||
use util::{public, TypePosition};
|
||||
use util::{public, webidl_const_ty_to_syn_ty, webidl_const_v_to_backend_const_v, TypePosition};
|
||||
|
||||
/// Either `Ok(t)` or `Err(failure::Error)`.
|
||||
pub type Result<T> = ::std::result::Result<T, failure::Error>;
|
||||
@ -250,7 +250,7 @@ impl WebidlParse<()> for webidl::ast::NonPartialInterface {
|
||||
js_namespace: None,
|
||||
kind: backend::ast::ImportKind::Type(backend::ast::ImportType {
|
||||
vis: public(),
|
||||
name: rust_ident(&self.name),
|
||||
name: rust_ident(self.name.to_camel_case().as_str()),
|
||||
attrs: Vec::new(),
|
||||
}),
|
||||
});
|
||||
@ -343,7 +343,8 @@ impl<'a> WebidlParse<&'a webidl::ast::NonPartialInterface> for webidl::ast::Exte
|
||||
match self {
|
||||
webidl::ast::ExtendedAttribute::ArgumentList(
|
||||
webidl::ast::ArgumentListExtendedAttribute { arguments, name },
|
||||
) if name == "Constructor" =>
|
||||
)
|
||||
if name == "Constructor" =>
|
||||
{
|
||||
add_constructor(arguments, &interface.name)
|
||||
}
|
||||
@ -358,7 +359,8 @@ impl<'a> WebidlParse<&'a webidl::ast::NonPartialInterface> for webidl::ast::Exte
|
||||
rhs_arguments,
|
||||
rhs_name,
|
||||
},
|
||||
) if lhs_name == "NamedConstructor" =>
|
||||
)
|
||||
if lhs_name == "NamedConstructor" =>
|
||||
{
|
||||
add_constructor(rhs_arguments, rhs_name)
|
||||
}
|
||||
@ -389,9 +391,11 @@ impl<'a> WebidlParse<&'a str> for webidl::ast::InterfaceMember {
|
||||
webidl::ast::InterfaceMember::Operation(op) => {
|
||||
op.webidl_parse(program, first_pass, self_name)
|
||||
}
|
||||
webidl::ast::InterfaceMember::Const(cnst) => {
|
||||
cnst.webidl_parse(program, first_pass, self_name)
|
||||
}
|
||||
// TODO
|
||||
webidl::ast::InterfaceMember::Const(_)
|
||||
| webidl::ast::InterfaceMember::Iterable(_)
|
||||
webidl::ast::InterfaceMember::Iterable(_)
|
||||
| webidl::ast::InterfaceMember::Maplike(_)
|
||||
| webidl::ast::InterfaceMember::Setlike(_) => {
|
||||
warn!("Unsupported WebIDL interface member: {:?}", self);
|
||||
@ -637,3 +641,29 @@ impl<'a> WebidlParse<()> for webidl::ast::Enum {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> WebidlParse<&'a str> for webidl::ast::Const {
|
||||
fn webidl_parse(
|
||||
&self,
|
||||
program: &mut backend::ast::Program,
|
||||
_: &FirstPassRecord<'_>,
|
||||
interface_name: &'a str,
|
||||
) -> Result<()> {
|
||||
let syn_ty = webidl_const_ty_to_syn_ty(&self.type_);
|
||||
program.imports.push(backend::ast::Import {
|
||||
module: None,
|
||||
version: None,
|
||||
js_namespace: None,
|
||||
kind: backend::ast::ImportKind::Const(backend::ast::Const {
|
||||
vis: syn::Visibility::Public(syn::VisPublic {
|
||||
pub_token: Default::default(),
|
||||
}),
|
||||
name: rust_ident(self.name.to_shouty_snake_case().as_str()),
|
||||
interface_name: rust_ident(interface_name.to_camel_case().as_str()),
|
||||
ty: syn_ty,
|
||||
value: webidl_const_v_to_backend_const_v(&self.value),
|
||||
}),
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,35 @@ fn shared_ref(ty: syn::Type) -> syn::Type {
|
||||
}.into()
|
||||
}
|
||||
|
||||
pub fn webidl_const_ty_to_syn_ty(ty: &webidl::ast::ConstType) -> syn::Type {
|
||||
use webidl::ast::ConstType::*;
|
||||
|
||||
// similar to webidl_ty_to_syn_ty
|
||||
match ty {
|
||||
Boolean => ident_ty(raw_ident("bool")),
|
||||
Byte => ident_ty(raw_ident("i8")),
|
||||
Octet => ident_ty(raw_ident("u8")),
|
||||
RestrictedDouble | UnrestrictedDouble => ident_ty(raw_ident("f64")),
|
||||
RestrictedFloat | UnrestrictedFloat => ident_ty(raw_ident("f32")),
|
||||
SignedLong => ident_ty(raw_ident("i32")),
|
||||
SignedLongLong => ident_ty(raw_ident("i64")),
|
||||
SignedShort => ident_ty(raw_ident("i16")),
|
||||
UnsignedLong => ident_ty(raw_ident("u32")),
|
||||
UnsignedLongLong => ident_ty(raw_ident("u64")),
|
||||
UnsignedShort => ident_ty(raw_ident("u16")),
|
||||
Identifier(ref id) => ident_ty(rust_ident(id)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn webidl_const_v_to_backend_const_v(v: &webidl::ast::ConstValue) -> backend::ast::ConstValue {
|
||||
match *v {
|
||||
webidl::ast::ConstValue::BooleanLiteral(b) => backend::ast::ConstValue::BooleanLiteral(b),
|
||||
webidl::ast::ConstValue::FloatLiteral(f) => backend::ast::ConstValue::FloatLiteral(f),
|
||||
webidl::ast::ConstValue::IntegerLiteral(i) => backend::ast::ConstValue::IntegerLiteral(i),
|
||||
webidl::ast::ConstValue::Null => backend::ast::ConstValue::Null,
|
||||
}
|
||||
}
|
||||
|
||||
fn simple_fn_arg(ident: Ident, ty: syn::Type) -> syn::ArgCaptured {
|
||||
syn::ArgCaptured {
|
||||
pat: syn::Pat::Ident(syn::PatIdent {
|
||||
|
Reference in New Issue
Block a user