mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 19:11:45 +03:00
Update to syn master
This commit is contained in:
parent
e03ef1c2a4
commit
8ba64bab68
@ -49,13 +49,11 @@ pub struct Method {
|
|||||||
|
|
||||||
impl Program {
|
impl Program {
|
||||||
pub fn push_impl(&mut self, item: &syn::ItemImpl) {
|
pub fn push_impl(&mut self, item: &syn::ItemImpl) {
|
||||||
match item.defaultness {
|
if item.defaultness.is_some() {
|
||||||
syn::Defaultness::Final => {}
|
panic!("default impls are not supported");
|
||||||
_ => panic!("default impls are not supported"),
|
|
||||||
}
|
}
|
||||||
match item.unsafety {
|
if item.unsafety.is_some() {
|
||||||
syn::Unsafety::Normal => {}
|
panic!("unsafe impls are not supported");
|
||||||
_ => panic!("unsafe impls are not supported"),
|
|
||||||
}
|
}
|
||||||
if item.trait_.is_some() {
|
if item.trait_.is_some() {
|
||||||
panic!("trait impls are not supported");
|
panic!("trait impls are not supported");
|
||||||
@ -77,8 +75,8 @@ impl Program {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_foreign_mod(&mut self, f: &syn::ItemForeignMod) {
|
pub fn push_foreign_mod(&mut self, f: &syn::ItemForeignMod) {
|
||||||
match f.abi.kind {
|
match f.abi.name {
|
||||||
syn::AbiKind::Named(ref l) if l.to_string() == "\"JS\"" => {}
|
Some(ref l) if l.to_string() == "\"JS\"" => {}
|
||||||
_ => panic!("only foreign mods with the `JS` ABI are allowed"),
|
_ => panic!("only foreign mods with the `JS` ABI are allowed"),
|
||||||
}
|
}
|
||||||
for item in f.items.iter() {
|
for item in f.items.iter() {
|
||||||
@ -116,13 +114,11 @@ impl Function {
|
|||||||
syn::Visibility::Public(_) => {}
|
syn::Visibility::Public(_) => {}
|
||||||
_ => panic!("can only bindgen public functions"),
|
_ => panic!("can only bindgen public functions"),
|
||||||
}
|
}
|
||||||
match input.constness {
|
if input.constness.is_some() {
|
||||||
syn::Constness::NotConst => {}
|
panic!("can only bindgen non-const functions");
|
||||||
_ => panic!("can only bindgen non-const functions"),
|
|
||||||
}
|
}
|
||||||
match input.unsafety {
|
if input.unsafety.is_some() {
|
||||||
syn::Unsafety::Normal => {}
|
panic!("can only bindgen safe functions");
|
||||||
_ => panic!("can only bindgen safe functions"),
|
|
||||||
}
|
}
|
||||||
if !input.abi.is_none() {
|
if !input.abi.is_none() {
|
||||||
panic!("can only bindgen Rust ABI functions")
|
panic!("can only bindgen Rust ABI functions")
|
||||||
@ -135,7 +131,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_decl(name: syn::Ident, decl: &syn::FnDecl) -> Function {
|
pub fn from_decl(name: syn::Ident, decl: &syn::FnDecl) -> Function {
|
||||||
if decl.variadic {
|
if decl.variadic.is_some() {
|
||||||
panic!("can't bindgen variadic functions")
|
panic!("can't bindgen variadic functions")
|
||||||
}
|
}
|
||||||
if decl.generics.params.len() > 0 {
|
if decl.generics.params.len() > 0 {
|
||||||
@ -155,7 +151,7 @@ impl Function {
|
|||||||
|
|
||||||
let ret = match decl.output {
|
let ret = match decl.output {
|
||||||
syn::ReturnType::Default => None,
|
syn::ReturnType::Default => None,
|
||||||
syn::ReturnType::Type(ref t, _) => Some(Type::from(t)),
|
syn::ReturnType::Type(_, ref t) => Some(Type::from(t)),
|
||||||
};
|
};
|
||||||
|
|
||||||
Function { name, arguments, ret }
|
Function { name, arguments, ret }
|
||||||
@ -170,7 +166,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn struct_function_export_name(&self, s: syn::Ident) -> syn::Lit {
|
pub fn struct_function_export_name(&self, s: syn::Ident) -> syn::Lit {
|
||||||
let name = self.shared().struct_function_export_name(s.sym.as_str());
|
let name = self.shared().struct_function_export_name(s.as_ref());
|
||||||
syn::Lit {
|
syn::Lit {
|
||||||
value: syn::LitKind::Other(Literal::string(&name)),
|
value: syn::LitKind::Other(Literal::string(&name)),
|
||||||
span: Default::default(),
|
span: Default::default(),
|
||||||
@ -181,16 +177,16 @@ impl Function {
|
|||||||
let mut generated_name = format!("__wasm_bindgen_generated");
|
let mut generated_name = format!("__wasm_bindgen_generated");
|
||||||
if let Some(ns) = namespace {
|
if let Some(ns) = namespace {
|
||||||
generated_name.push_str("_");
|
generated_name.push_str("_");
|
||||||
generated_name.push_str(ns.sym.as_str());
|
generated_name.push_str(ns.as_ref());
|
||||||
}
|
}
|
||||||
generated_name.push_str("_");
|
generated_name.push_str("_");
|
||||||
generated_name.push_str(self.name.sym.as_str());
|
generated_name.push_str(self.name.as_ref());
|
||||||
syn::Ident::from(generated_name)
|
syn::Ident::from(generated_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shared(&self) -> shared::Function {
|
fn shared(&self) -> shared::Function {
|
||||||
shared::Function {
|
shared::Function {
|
||||||
name: self.name.sym.as_str().to_string(),
|
name: self.name.as_ref().to_string(),
|
||||||
arguments: self.arguments.iter().map(|t| t.shared()).collect(),
|
arguments: self.arguments.iter().map(|t| t.shared()).collect(),
|
||||||
ret: self.ret.as_ref().map(|t| t.shared()),
|
ret: self.ret.as_ref().map(|t| t.shared()),
|
||||||
}
|
}
|
||||||
@ -204,11 +200,11 @@ pub fn extract_path_ident(path: &syn::Path) -> syn::Ident {
|
|||||||
if path.segments.len() != 1 {
|
if path.segments.len() != 1 {
|
||||||
panic!("unsupported path that needs name resolution")
|
panic!("unsupported path that needs name resolution")
|
||||||
}
|
}
|
||||||
match path.segments.get(0).item().arguments {
|
match path.segments.first().unwrap().item().arguments {
|
||||||
syn::PathArguments::None => {}
|
syn::PathArguments::None => {}
|
||||||
_ => panic!("unsupported path that has path arguments")
|
_ => panic!("unsupported path that has path arguments")
|
||||||
}
|
}
|
||||||
path.segments.get(0).item().ident
|
path.segments.first().unwrap().item().ident
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Type {
|
impl Type {
|
||||||
@ -218,14 +214,11 @@ impl Type {
|
|||||||
if r.lifetime.is_some() {
|
if r.lifetime.is_some() {
|
||||||
panic!("can't have lifetimes on references yet");
|
panic!("can't have lifetimes on references yet");
|
||||||
}
|
}
|
||||||
let mutable = match r.ty.mutability {
|
let mutable = r.mutability.is_some();
|
||||||
syn::Mutability::Immutable => false,
|
match *r.elem {
|
||||||
syn::Mutability::Mutable(_) => true,
|
|
||||||
};
|
|
||||||
match r.ty.ty {
|
|
||||||
syn::Type::Path(syn::TypePath { qself: None, ref path }) => {
|
syn::Type::Path(syn::TypePath { qself: None, ref path }) => {
|
||||||
let ident = extract_path_ident(path);
|
let ident = extract_path_ident(path);
|
||||||
match ident.sym.as_str() {
|
match ident.as_ref() {
|
||||||
"str" => {
|
"str" => {
|
||||||
if mutable {
|
if mutable {
|
||||||
panic!("mutable strings not allowed");
|
panic!("mutable strings not allowed");
|
||||||
@ -245,7 +238,7 @@ impl Type {
|
|||||||
}
|
}
|
||||||
syn::Type::Ptr(ref p) => {
|
syn::Type::Ptr(ref p) => {
|
||||||
let mutable = p.const_token.is_none();
|
let mutable = p.const_token.is_none();
|
||||||
let ident = match p.ty.ty {
|
let ident = match *p.elem {
|
||||||
syn::Type::Path(syn::TypePath { qself: None, ref path }) => {
|
syn::Type::Path(syn::TypePath { qself: None, ref path }) => {
|
||||||
extract_path_ident(path)
|
extract_path_ident(path)
|
||||||
}
|
}
|
||||||
@ -259,7 +252,7 @@ impl Type {
|
|||||||
}
|
}
|
||||||
syn::Type::Path(syn::TypePath { qself: None, ref path }) => {
|
syn::Type::Path(syn::TypePath { qself: None, ref path }) => {
|
||||||
let ident = extract_path_ident(path);
|
let ident = extract_path_ident(path);
|
||||||
match ident.sym.as_str() {
|
match ident.as_ref() {
|
||||||
"i8" |
|
"i8" |
|
||||||
"u8" |
|
"u8" |
|
||||||
"u16" |
|
"u16" |
|
||||||
@ -318,25 +311,23 @@ impl Struct {
|
|||||||
syn::ImplItem::Type(_) => panic!("type definitions in impls aren't supported"),
|
syn::ImplItem::Type(_) => panic!("type definitions in impls aren't supported"),
|
||||||
syn::ImplItem::Method(ref m) => m,
|
syn::ImplItem::Method(ref m) => m,
|
||||||
syn::ImplItem::Macro(_) => panic!("macros in impls aren't supported"),
|
syn::ImplItem::Macro(_) => panic!("macros in impls aren't supported"),
|
||||||
|
syn::ImplItem::Verbatim(_) => panic!("unparsed impl item?"),
|
||||||
};
|
};
|
||||||
match method.vis {
|
match method.vis {
|
||||||
syn::Visibility::Public(_) => {}
|
syn::Visibility::Public(_) => {}
|
||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
match method.defaultness {
|
if method.defaultness.is_some() {
|
||||||
syn::Defaultness::Final => {}
|
panic!("default methods are not supported");
|
||||||
_ => panic!("default methods are not supported"),
|
|
||||||
}
|
}
|
||||||
match method.sig.constness {
|
if method.sig.constness.is_some() {
|
||||||
syn::Constness::NotConst => {}
|
panic!("can only bindgen non-const functions");
|
||||||
_ => panic!("can only bindgen non-const functions"),
|
|
||||||
}
|
}
|
||||||
match method.sig.unsafety {
|
if method.sig.unsafety.is_some() {
|
||||||
syn::Unsafety::Normal => {}
|
panic!("can only bindgen safe functions");
|
||||||
_ => panic!("can only bindgen safe functions"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if method.sig.decl.variadic {
|
if method.sig.decl.variadic.is_some() {
|
||||||
panic!("can't bindgen variadic functions")
|
panic!("can't bindgen variadic functions")
|
||||||
}
|
}
|
||||||
if method.sig.decl.generics.params.len() > 0 {
|
if method.sig.decl.generics.params.len() > 0 {
|
||||||
@ -354,10 +345,7 @@ impl Struct {
|
|||||||
}
|
}
|
||||||
syn::FnArg::SelfRef(ref a) => {
|
syn::FnArg::SelfRef(ref a) => {
|
||||||
assert!(mutable.is_none());
|
assert!(mutable.is_none());
|
||||||
mutable = Some(match a.mutbl {
|
mutable = Some(a.mutability.is_some());
|
||||||
syn::Mutability::Mutable(_) => true,
|
|
||||||
syn::Mutability::Immutable => false,
|
|
||||||
});
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
_ => panic!("arguments cannot be `self` or ignored"),
|
_ => panic!("arguments cannot be `self` or ignored"),
|
||||||
@ -368,7 +356,7 @@ impl Struct {
|
|||||||
|
|
||||||
let ret = match method.sig.decl.output {
|
let ret = match method.sig.decl.output {
|
||||||
syn::ReturnType::Default => None,
|
syn::ReturnType::Default => None,
|
||||||
syn::ReturnType::Type(ref t, _) => Some(Type::from(t)),
|
syn::ReturnType::Type(_, ref t) => Some(Type::from(t)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let function = Function { name: method.sig.ident, arguments, ret };
|
let function = Function { name: method.sig.ident, arguments, ret };
|
||||||
|
@ -435,7 +435,7 @@ fn bindgen_import(import: &ast::Import, tokens: &mut Tokens) {
|
|||||||
.map(|arg| {
|
.map(|arg| {
|
||||||
match arg.pat {
|
match arg.pat {
|
||||||
syn::Pat::Ident(syn::PatIdent {
|
syn::Pat::Ident(syn::PatIdent {
|
||||||
mode: syn::BindingMode::ByValue(_),
|
by_ref: None,
|
||||||
ident,
|
ident,
|
||||||
subpat: None,
|
subpat: None,
|
||||||
..
|
..
|
||||||
|
Loading…
Reference in New Issue
Block a user