mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 00:11:23 +00:00
webidl: translate webidl const to backend const
This commit is contained in:
@ -90,6 +90,35 @@ pub fn webidl_ty_to_syn_ty(ty: &webidl::ast::Type, pos: TypePosition) -> Option<
|
||||
})
|
||||
}
|
||||
|
||||
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