Migrate all crates to the 2018 edition

Most of the CLI crates were already in the 2018 edition, and it turns
out that one of the macro crates was already in the 2018 edition so we
may as well move everything to the 2018 edition!

Always nice to remove those `extern crate` statements nowadays!

This commit also does a `cargo fmt --all` to make sure we're conforming
with style again.
This commit is contained in:
Alex Crichton
2019-03-26 08:00:16 -07:00
parent c5d2b2d1fb
commit a6fe0cefa8
53 changed files with 245 additions and 279 deletions

View File

@ -10,6 +10,7 @@ documentation = "https://docs.rs/wasm-bindgen"
description = """
Support for parsing WebIDL specific to wasm-bindgen
"""
edition = "2018"
[dependencies]
failure = "0.1.2"

View File

@ -20,8 +20,8 @@ use weedle::CallbackInterfaceDefinition;
use weedle::{DictionaryDefinition, PartialDictionaryDefinition};
use super::Result;
use util;
use util::camel_case_ident;
use crate::util;
use crate::util::camel_case_ident;
/// Collection of constructs that may use partial.
#[derive(Default)]
@ -191,7 +191,7 @@ impl<'src> FirstPass<'src, ()> for weedle::EnumDefinition<'src> {
}
if record.enums.insert(self.identifier.0, self).is_some() {
info!(
log::info!(
"Encountered multiple enum declarations: {}",
self.identifier.0
);
@ -304,7 +304,7 @@ impl<'src> FirstPass<'src, ()> for weedle::InterfaceDefinition<'src> {
}
if util::is_no_interface_object(&self.attributes) {
info!(
log::info!(
"Skipping because of `NoInterfaceObject` attribute: {:?}",
self.identifier.0
);
@ -431,23 +431,23 @@ impl<'src> FirstPass<'src, &'src str> for weedle::interface::InterfaceMember<'sr
Ok(())
}
InterfaceMember::Iterable(_iterable) => {
warn!("Unsupported WebIDL iterable interface member: {:?}", self);
log::warn!("Unsupported WebIDL iterable interface member: {:?}", self);
Ok(())
}
// TODO
InterfaceMember::Maplike(_) => {
warn!("Unsupported WebIDL Maplike interface member: {:?}", self);
log::warn!("Unsupported WebIDL Maplike interface member: {:?}", self);
Ok(())
}
InterfaceMember::Stringifier(_) => {
warn!(
log::warn!(
"Unsupported WebIDL Stringifier interface member: {:?}",
self
);
Ok(())
}
InterfaceMember::Setlike(_) => {
warn!("Unsupported WebIDL Setlike interface member: {:?}", self);
log::warn!("Unsupported WebIDL Setlike interface member: {:?}", self);
Ok(())
}
}
@ -462,7 +462,7 @@ impl<'src> FirstPass<'src, &'src str> for weedle::interface::OperationInterfaceM
) -> Result<()> {
let is_static = match self.modifier {
Some(StringifierOrStatic::Stringifier(_)) => {
warn!("Unsupported webidl stringifier: {:?}", self);
log::warn!("Unsupported webidl stringifier: {:?}", self);
return Ok(());
}
Some(StringifierOrStatic::Static(_)) => true,
@ -571,7 +571,7 @@ impl<'src> FirstPass<'src, &'src str> for weedle::mixin::MixinMember<'src> {
Ok(())
}
MixinMember::Stringifier(_) => {
warn!("Unsupported WebIDL stringifier mixin member: {:?}", self);
log::warn!("Unsupported WebIDL stringifier mixin member: {:?}", self);
Ok(())
}
}
@ -585,7 +585,7 @@ impl<'src> FirstPass<'src, &'src str> for weedle::mixin::OperationMixinMember<'s
self_name: &'src str,
) -> Result<()> {
if self.stringifier.is_some() {
warn!("Unsupported webidl stringifier: {:?}", self);
log::warn!("Unsupported webidl stringifier: {:?}", self);
return Ok(());
}
@ -633,7 +633,7 @@ impl<'src> FirstPass<'src, ()> for weedle::TypedefDefinition<'src> {
.insert(self.identifier.0, &self.type_.type_)
.is_some()
{
info!(
log::info!(
"Encountered multiple typedef declarations: {}",
self.identifier.0
);
@ -721,7 +721,7 @@ impl<'src> FirstPass<'src, ()> for weedle::CallbackInterfaceDefinition<'src> {
return Ok(());
}
if self.inheritance.is_some() {
warn!(
log::warn!(
"skipping callback interface with inheritance: {}",
self.identifier.0
);

View File

@ -1,12 +1,12 @@
use backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident};
use proc_macro2::{Ident, Span};
use syn;
use wasm_bindgen_backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident};
use weedle::common::Identifier;
use weedle::term;
use weedle::types::*;
use first_pass::FirstPassRecord;
use util::{array, camel_case_ident, option_ty, shared_ref, snake_case_ident, TypePosition};
use crate::first_pass::FirstPassRecord;
use crate::util::{array, camel_case_ident, option_ty, shared_ref, snake_case_ident, TypePosition};
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
pub(crate) enum IdlType<'a> {
@ -329,7 +329,7 @@ impl<'a> ToIdlType<'a> for Identifier<'a> {
// let's translate it as such.
IdlType::Interface("Window")
} else {
warn!("Unrecognized type: {}", self.0);
log::warn!("Unrecognized type: {}", self.0);
IdlType::UnknownInterface(self.0)
}
}

View File

@ -9,53 +9,39 @@ emitted for the types and methods described in the WebIDL.
#![deny(missing_debug_implementations)]
#![doc(html_root_url = "https://docs.rs/wasm-bindgen-webidl/0.2")]
#[macro_use]
extern crate failure;
extern crate heck;
#[macro_use]
extern crate log;
extern crate proc_macro2;
#[macro_use]
extern crate quote;
#[macro_use]
extern crate syn;
extern crate wasm_bindgen_backend as backend;
extern crate weedle;
mod error;
mod first_pass;
mod idl_type;
mod util;
use crate::first_pass::{CallbackInterfaceData, OperationData};
use crate::first_pass::{FirstPass, FirstPassRecord, InterfaceData, OperationId};
use crate::idl_type::ToIdlType;
use crate::util::{
camel_case_ident, mdn_doc, public, shouty_snake_case_ident, snake_case_ident,
webidl_const_v_to_backend_const_v, TypePosition,
};
use failure::format_err;
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};
use std::collections::{BTreeSet, HashSet};
use std::env;
use std::fs;
use std::iter::FromIterator;
use backend::ast;
use backend::defined::ImportedTypeReferences;
use backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports};
use backend::util::{ident_ty, raw_ident, rust_ident, wrap_import_function};
use backend::TryToTokens;
use proc_macro2::{Ident, Span};
use quote::ToTokens;
use wasm_bindgen_backend::ast;
use wasm_bindgen_backend::defined::ImportedTypeReferences;
use wasm_bindgen_backend::defined::{ImportedTypeDefinitions, RemoveUndefinedImports};
use wasm_bindgen_backend::util::{ident_ty, raw_ident, rust_ident, wrap_import_function};
use wasm_bindgen_backend::TryToTokens;
use weedle::attribute::ExtendedAttributeList;
use weedle::dictionary::DictionaryMember;
use weedle::interface::InterfaceMember;
use first_pass::{CallbackInterfaceData, OperationData};
use first_pass::{FirstPass, FirstPassRecord, InterfaceData, OperationId};
use idl_type::ToIdlType;
use util::{
camel_case_ident, mdn_doc, public, shouty_snake_case_ident, snake_case_ident,
webidl_const_v_to_backend_const_v, TypePosition,
};
pub use error::{Error, ErrorKind, Result};
pub use crate::error::{Error, ErrorKind, Result};
struct Program {
main: backend::ast::Program,
submodules: Vec<(String, backend::ast::Program)>,
main: ast::Program,
submodules: Vec<(String, ast::Program)>,
}
/// Parse a string of WebIDL source text into a wasm-bindgen AST.
@ -132,7 +118,7 @@ fn parse(webidl_source: &str, allowed_types: Option<&[&str]>) -> Result<Program>
// prevent the type from being usable entirely. They're just there for
// `AsRef` and such implementations.
for import in program.imports.iter_mut() {
if let backend::ast::ImportKind::Type(t) = &mut import.kind {
if let ast::ImportKind::Type(t) = &mut import.kind {
t.extends.retain(|n| {
let ident = &n.segments.last().unwrap().value().ident;
first_pass_record.builtin_idents.contains(ident) || filter(&ident.to_string())
@ -280,16 +266,12 @@ fn compile_ast(mut ast: Program) -> String {
}
impl<'src> FirstPassRecord<'src> {
fn append_enum(
&self,
program: &mut backend::ast::Program,
enum_: &'src weedle::EnumDefinition<'src>,
) {
fn append_enum(&self, program: &mut ast::Program, enum_: &'src weedle::EnumDefinition<'src>) {
let variants = &enum_.values.body.list;
program.imports.push(backend::ast::Import {
module: backend::ast::ImportModule::None,
program.imports.push(ast::Import {
module: ast::ImportModule::None,
js_namespace: None,
kind: backend::ast::ImportKind::Enum(backend::ast::ImportEnum {
kind: ast::ImportKind::Enum(ast::ImportEnum {
vis: public(),
name: rust_ident(camel_case_ident(enum_.identifier.0).as_str()),
variants: variants
@ -303,7 +285,7 @@ impl<'src> FirstPassRecord<'src> {
})
.collect(),
variant_values: variants.iter().map(|v| v.0.to_string()).collect(),
rust_attrs: vec![parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])],
rust_attrs: vec![syn::parse_quote!(#[derive(Copy, Clone, PartialEq, Debug)])],
}),
});
}
@ -312,7 +294,7 @@ impl<'src> FirstPassRecord<'src> {
// https://www.w3.org/TR/WebIDL-1/#idl-dictionaries
fn append_dictionary(
&self,
program: &mut backend::ast::Program,
program: &mut ast::Program,
data: &first_pass::DictionaryData<'src>,
) {
let def = match data.definition {
@ -358,7 +340,7 @@ impl<'src> FirstPassRecord<'src> {
match self.dictionary_field(member) {
Some(f) => dst.push(f),
None => {
warn!(
log::warn!(
"unsupported dictionary field {:?}",
(dict, member.identifier.0),
);
@ -435,7 +417,7 @@ impl<'src> FirstPassRecord<'src> {
&'src self,
name: &'src str,
ns: &'src first_pass::NamespaceData<'src>,
) -> backend::ast::Program {
) -> ast::Program {
let mut ret = Default::default();
for (id, data) in ns.operations.iter() {
@ -447,7 +429,7 @@ impl<'src> FirstPassRecord<'src> {
fn append_ns_member(
&self,
module: &mut backend::ast::Program,
module: &mut ast::Program,
self_name: &'src str,
id: &OperationId<'src>,
data: &OperationData<'src>,
@ -459,7 +441,7 @@ impl<'src> FirstPassRecord<'src> {
| OperationId::IndexingGetter
| OperationId::IndexingSetter
| OperationId::IndexingDeleter => {
warn!("Unsupported unnamed operation: on {:?}", self_name);
log::warn!("Unsupported unnamed operation: on {:?}", self_name);
return;
}
};
@ -470,24 +452,24 @@ impl<'src> FirstPassRecord<'src> {
mdn_doc(self_name, Some(&name))
);
let kind = backend::ast::ImportFunctionKind::Normal;
let kind = ast::ImportFunctionKind::Normal;
let extra = snake_case_ident(self_name);
let extra = &[&extra[..]];
for mut import_function in self.create_imports(None, kind, id, data) {
let mut doc = Some(doc_comment.clone());
self.append_required_features_doc(&import_function, &mut doc, extra);
import_function.doc_comment = doc;
module.imports.push(backend::ast::Import {
module: backend::ast::ImportModule::None,
module.imports.push(ast::Import {
module: ast::ImportModule::None,
js_namespace: Some(raw_ident(self_name)),
kind: backend::ast::ImportKind::Function(import_function),
kind: ast::ImportKind::Function(import_function),
});
}
}
fn append_const(
&self,
program: &mut backend::ast::Program,
program: &mut ast::Program,
self_name: &'src str,
member: &'src weedle::interface::ConstMember<'src>,
) {
@ -495,15 +477,17 @@ impl<'src> FirstPassRecord<'src> {
let ty = match idl_type.to_syn_type(TypePosition::Return) {
Some(ty) => ty,
None => {
warn!(
log::warn!(
"Cannot convert const type to syn type: {:?} in {:?} on {:?}",
idl_type, member, self_name
idl_type,
member,
self_name
);
return;
}
};
program.consts.push(backend::ast::Const {
program.consts.push(ast::Const {
vis: public(),
name: rust_ident(shouty_snake_case_ident(member.identifier.0).as_str()),
class: Some(rust_ident(camel_case_ident(&self_name).as_str())),
@ -514,16 +498,16 @@ impl<'src> FirstPassRecord<'src> {
fn append_interface(
&self,
program: &mut backend::ast::Program,
program: &mut ast::Program,
name: &'src str,
data: &InterfaceData<'src>,
) {
let mut doc_comment = Some(format!("The `{}` object\n\n{}", name, mdn_doc(name, None),));
let mut attrs = Vec::new();
attrs.push(parse_quote!( #[derive(Debug, Clone)] ));
attrs.push(syn::parse_quote!( #[derive(Debug, Clone)] ));
self.add_deprecated(data, &mut attrs);
let mut import_type = backend::ast::ImportType {
let mut import_type = ast::ImportType {
vis: public(),
rust_name: rust_ident(camel_case_ident(name).as_str()),
js_name: name.to_string(),
@ -553,10 +537,10 @@ impl<'src> FirstPassRecord<'src> {
.collect();
import_type.doc_comment = doc_comment;
program.imports.push(backend::ast::Import {
module: backend::ast::ImportModule::None,
program.imports.push(ast::Import {
module: ast::ImportModule::None,
js_namespace: None,
kind: backend::ast::ImportKind::Type(import_type),
kind: ast::ImportKind::Type(import_type),
});
for (id, op_data) in data.operations.iter() {
@ -608,7 +592,7 @@ impl<'src> FirstPassRecord<'src> {
fn member_attribute(
&self,
program: &mut backend::ast::Program,
program: &mut ast::Program,
self_name: &'src str,
data: &InterfaceData<'src>,
modifier: Option<weedle::interface::StringifierOrInheritOrStatic>,
@ -661,7 +645,7 @@ impl<'src> FirstPassRecord<'src> {
fn member_operation(
&self,
program: &mut backend::ast::Program,
program: &mut ast::Program,
self_name: &str,
data: &InterfaceData<'src>,
id: &OperationId<'src>,
@ -672,21 +656,17 @@ impl<'src> FirstPassRecord<'src> {
let kind = match id {
OperationId::Constructor(ctor_name) => {
let self_ty = ident_ty(rust_ident(&camel_case_ident(self_name)));
backend::ast::ImportFunctionKind::Method {
ast::ImportFunctionKind::Method {
class: ctor_name.0.to_string(),
ty: self_ty.clone(),
kind: backend::ast::MethodKind::Constructor,
kind: ast::MethodKind::Constructor,
}
}
OperationId::Operation(_) => import_function_kind(backend::ast::OperationKind::Regular),
OperationId::IndexingGetter => {
import_function_kind(backend::ast::OperationKind::IndexingGetter)
}
OperationId::IndexingSetter => {
import_function_kind(backend::ast::OperationKind::IndexingSetter)
}
OperationId::Operation(_) => import_function_kind(ast::OperationKind::Regular),
OperationId::IndexingGetter => import_function_kind(ast::OperationKind::IndexingGetter),
OperationId::IndexingSetter => import_function_kind(ast::OperationKind::IndexingSetter),
OperationId::IndexingDeleter => {
import_function_kind(backend::ast::OperationKind::IndexingDeleter)
import_function_kind(ast::OperationKind::IndexingDeleter)
}
};
let doc = match id {
@ -721,7 +701,7 @@ impl<'src> FirstPassRecord<'src> {
Some(s) => s,
None => return,
};
dst.push(parse_quote!( #[deprecated(note = #msg)] ));
dst.push(syn::parse_quote!( #[deprecated(note = #msg)] ));
}
fn append_required_features_doc(
@ -760,7 +740,7 @@ impl<'src> FirstPassRecord<'src> {
fn append_callback_interface(
&self,
program: &mut backend::ast::Program,
program: &mut ast::Program,
item: &CallbackInterfaceData<'src>,
) {
let mut fields = Vec::new();
@ -780,7 +760,7 @@ impl<'src> FirstPassRecord<'src> {
});
}
_ => {
warn!(
log::warn!(
"skipping callback interface member on {}",
item.definition.identifier.0
);

View File

@ -1,17 +1,17 @@
use std::iter::FromIterator;
use std::ptr;
use backend;
use backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident};
use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
use proc_macro2::{Ident, Span};
use syn;
use wasm_bindgen_backend::ast;
use wasm_bindgen_backend::util::{ident_ty, leading_colon_path_ty, raw_ident, rust_ident};
use weedle;
use weedle::attribute::{ExtendedAttribute, ExtendedAttributeList, IdentifierOrString};
use weedle::literal::{ConstValue, FloatLit, IntegerLit};
use first_pass::{FirstPassRecord, OperationData, OperationId, Signature};
use idl_type::{IdlType, ToIdlType};
use crate::first_pass::{FirstPassRecord, OperationData, OperationId, Signature};
use crate::idl_type::{IdlType, ToIdlType};
/// For variadic operations an overload with a `js_sys::Array` argument is generated alongside with
/// `operation_name_0`, `operation_name_1`, `operation_name_2`, ..., `operation_name_n` overloads
@ -81,8 +81,7 @@ pub(crate) fn array(base_ty: &str, pos: TypePosition, immutable: bool) -> syn::T
}
/// Map a webidl const value to the correct wasm-bindgen const value
pub fn webidl_const_v_to_backend_const_v(v: &ConstValue) -> backend::ast::ConstValue {
use backend::ast;
pub fn webidl_const_v_to_backend_const_v(v: &ConstValue) -> ast::ConstValue {
use std::f64::{INFINITY, NAN, NEG_INFINITY};
match *v {
@ -225,12 +224,12 @@ impl<'src> FirstPassRecord<'src> {
rust_name: &str,
idl_arguments: impl Iterator<Item = (&'a str, &'a IdlType<'src>)>,
ret: &IdlType<'src>,
kind: backend::ast::ImportFunctionKind,
kind: ast::ImportFunctionKind,
structural: bool,
catch: bool,
variadic: bool,
doc_comment: Option<String>,
) -> Option<backend::ast::ImportFunction>
) -> Option<ast::ImportFunction>
where
'src: 'a,
{
@ -239,10 +238,10 @@ impl<'src> FirstPassRecord<'src> {
//
// Note that for non-static methods we add a `&self` type placeholder,
// but this type isn't actually used so it's just here for show mostly.
let mut arguments = if let &backend::ast::ImportFunctionKind::Method {
let mut arguments = if let &ast::ImportFunctionKind::Method {
ref ty,
kind:
backend::ast::MethodKind::Operation(backend::ast::Operation {
ast::MethodKind::Operation(ast::Operation {
is_static: false, ..
}),
..
@ -263,9 +262,10 @@ impl<'src> FirstPassRecord<'src> {
let syn_type = match idl_type.to_syn_type(TypePosition::Argument) {
Some(t) => t,
None => {
warn!(
log::warn!(
"Unsupported argument type: {:?} on {:?}",
idl_type, rust_name
idl_type,
rust_name
);
return None;
}
@ -287,7 +287,7 @@ impl<'src> FirstPassRecord<'src> {
ret @ _ => match ret.to_syn_type(TypePosition::Return) {
Some(ret) => Some(ret),
None => {
warn!("Unsupported return type: {:?} on {:?}", ret, rust_name);
log::warn!("Unsupported return type: {:?} on {:?}", ret, rust_name);
return None;
}
},
@ -299,8 +299,8 @@ impl<'src> FirstPassRecord<'src> {
ret
};
Some(backend::ast::ImportFunction {
function: backend::ast::Function {
Some(ast::ImportFunction {
function: ast::Function {
name: js_name.to_string(),
name_span: Span::call_site(),
renamed_via_js_name: false,
@ -316,8 +316,8 @@ impl<'src> FirstPassRecord<'src> {
structural,
shim: {
let ns = match kind {
backend::ast::ImportFunctionKind::Normal => "",
backend::ast::ImportFunctionKind::Method { ref class, .. } => class,
ast::ImportFunctionKind::Normal => "",
ast::ImportFunctionKind::Method { ref class, .. } => class,
};
raw_ident(&format!("__widl_f_{}_{}", rust_name, ns))
},
@ -335,8 +335,8 @@ impl<'src> FirstPassRecord<'src> {
is_static: bool,
attrs: &Option<ExtendedAttributeList>,
container_attrs: Option<&ExtendedAttributeList>,
) -> Option<backend::ast::ImportFunction> {
let kind = backend::ast::OperationKind::Getter(Some(raw_ident(name)));
) -> Option<ast::ImportFunction> {
let kind = ast::OperationKind::Getter(Some(raw_ident(name)));
let kind = self.import_function_kind(self_name, is_static, kind);
let ret = ty.to_idl_type(self);
self.create_one_function(
@ -365,8 +365,8 @@ impl<'src> FirstPassRecord<'src> {
is_static: bool,
attrs: &Option<ExtendedAttributeList>,
container_attrs: Option<&ExtendedAttributeList>,
) -> Option<backend::ast::ImportFunction> {
let kind = backend::ast::OperationKind::Setter(Some(raw_ident(name)));
) -> Option<ast::ImportFunction> {
let kind = ast::OperationKind::Setter(Some(raw_ident(name)));
let kind = self.import_function_kind(self_name, is_static, kind);
let field_ty = field_ty.to_idl_type(self);
self.create_one_function(
@ -390,27 +390,27 @@ impl<'src> FirstPassRecord<'src> {
&self,
self_name: &str,
is_static: bool,
operation_kind: backend::ast::OperationKind,
) -> backend::ast::ImportFunctionKind {
let operation = backend::ast::Operation {
operation_kind: ast::OperationKind,
) -> ast::ImportFunctionKind {
let operation = ast::Operation {
is_static,
kind: operation_kind,
};
let ty = ident_ty(rust_ident(camel_case_ident(&self_name).as_str()));
backend::ast::ImportFunctionKind::Method {
ast::ImportFunctionKind::Method {
class: self_name.to_string(),
ty,
kind: backend::ast::MethodKind::Operation(operation),
kind: ast::MethodKind::Operation(operation),
}
}
pub fn create_imports(
&self,
container_attrs: Option<&ExtendedAttributeList<'src>>,
kind: backend::ast::ImportFunctionKind,
kind: ast::ImportFunctionKind,
id: &OperationId<'src>,
data: &OperationData<'src>,
) -> Vec<backend::ast::ImportFunction> {
) -> Vec<ast::ImportFunction> {
// First up, prune all signatures that reference unsupported arguments.
// We won't consider these until said arguments are implemented.
//
@ -434,7 +434,7 @@ impl<'src> FirstPassRecord<'src> {
signatures.push((signature, idl_args.clone()));
}
let mut idl_type = arg.ty.to_idl_type(self);
let idl_type = arg.ty.to_idl_type(self);
let idl_type = self.maybe_adjust(idl_type, id);
idl_args.push(idl_type);
}
@ -452,7 +452,7 @@ impl<'src> FirstPassRecord<'src> {
let mut actual_signatures = Vec::new();
for (signature, idl_args) in signatures.iter() {
let mut start = actual_signatures.len();
let start = actual_signatures.len();
// Start off with an empty signature, this'll handle zero-argument
// cases and otherwise the loop below will continue to add on to this.
@ -504,7 +504,7 @@ impl<'src> FirstPassRecord<'src> {
OperationId::Constructor(_) => ("new", false, true),
OperationId::Operation(Some(s)) => (*s, false, false),
OperationId::Operation(None) => {
warn!("unsupported unnamed operation");
log::warn!("unsupported unnamed operation");
return Vec::new();
}
OperationId::IndexingGetter => ("get", true, false),