mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 00:11:23 +00:00
Deindent a few helper functions in dictionaries
No need for it to be an inner function now that it's using methods!
This commit is contained in:
@ -191,7 +191,7 @@ impl<'src> FirstPassRecord<'src> {
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let mut fields = Vec::new();
|
let mut fields = Vec::new();
|
||||||
if !push_members(self, def.identifier.0, &mut fields) {
|
if !self.append_dictionary_members(def.identifier.0, &mut fields) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,90 +199,90 @@ impl<'src> FirstPassRecord<'src> {
|
|||||||
name: rust_ident(&camel_case_ident(def.identifier.0)),
|
name: rust_ident(&camel_case_ident(def.identifier.0)),
|
||||||
fields,
|
fields,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn push_members<'src>(
|
fn append_dictionary_members(
|
||||||
data: &FirstPassRecord<'src>,
|
&self,
|
||||||
dict: &'src str,
|
dict: &'src str,
|
||||||
dst: &mut Vec<ast::DictionaryField>,
|
dst: &mut Vec<ast::DictionaryField>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let dict_data = &data.dictionaries[&dict];
|
let dict_data = &self.dictionaries[&dict];
|
||||||
let definition = dict_data.definition.unwrap();
|
let definition = dict_data.definition.unwrap();
|
||||||
|
|
||||||
// > The order of the dictionary members on a given dictionary is
|
// > The order of the dictionary members on a given dictionary is
|
||||||
// > such that inherited dictionary members are ordered before
|
// > such that inherited dictionary members are ordered before
|
||||||
// > non-inherited members ...
|
// > non-inherited members ...
|
||||||
if let Some(parent) = &definition.inheritance {
|
if let Some(parent) = &definition.inheritance {
|
||||||
if !push_members(data, parent.identifier.0, dst) {
|
if !self.append_dictionary_members(parent.identifier.0, dst) {
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// > ... and the dictionary members on the one dictionary
|
// > ... and the dictionary members on the one dictionary
|
||||||
// > definition (including any partial dictionary definitions) are
|
// > definition (including any partial dictionary definitions) are
|
||||||
// > ordered lexicographically by the Unicode codepoints that
|
// > ordered lexicographically by the Unicode codepoints that
|
||||||
// > comprise their identifiers.
|
// > comprise their identifiers.
|
||||||
let start = dst.len();
|
let start = dst.len();
|
||||||
let members = definition.members.body.iter();
|
let members = definition.members.body.iter();
|
||||||
let partials = dict_data.partials.iter().flat_map(|d| &d.members.body);
|
let partials = dict_data.partials.iter().flat_map(|d| &d.members.body);
|
||||||
for member in members.chain(partials) {
|
for member in members.chain(partials) {
|
||||||
match mkfield(data, member) {
|
match self.dictionary_field(member) {
|
||||||
Some(f) => dst.push(f),
|
Some(f) => dst.push(f),
|
||||||
None => {
|
None => {
|
||||||
warn!(
|
warn!(
|
||||||
"unsupported dictionary field {:?}",
|
"unsupported dictionary field {:?}",
|
||||||
(dict, member.identifier.0),
|
(dict, member.identifier.0),
|
||||||
);
|
);
|
||||||
// If this is required then we can't support the
|
// If this is required then we can't support the
|
||||||
// dictionary at all, but if it's not required we can
|
// dictionary at all, but if it's not required we can
|
||||||
// avoid generating bindings for the field and keep
|
// avoid generating bindings for the field and keep
|
||||||
// going otherwise.
|
// going otherwise.
|
||||||
if member.required.is_some() {
|
if member.required.is_some() {
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note that this sort isn't *quite* right in that it is sorting
|
}
|
||||||
// based on snake case instead of the original casing which could
|
// Note that this sort isn't *quite* right in that it is sorting
|
||||||
// produce inconsistent results, but should work well enough for
|
// based on snake case instead of the original casing which could
|
||||||
// now!
|
// produce inconsistent results, but should work well enough for
|
||||||
dst[start..].sort_by_key(|f| f.name.clone());
|
// now!
|
||||||
|
dst[start..].sort_by_key(|f| f.name.clone());
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dictionary_field(
|
||||||
|
&self,
|
||||||
|
field: &'src DictionaryMember<'src>,
|
||||||
|
) -> Option<ast::DictionaryField> {
|
||||||
|
// use argument position now as we're just binding setters
|
||||||
|
let ty = field.type_.to_idl_type(self)?.to_syn_type(TypePosition::Argument)?;
|
||||||
|
|
||||||
|
// Slice types aren't supported because they don't implement
|
||||||
|
// `Into<JsValue>`
|
||||||
|
if let syn::Type::Reference(ty) = &ty {
|
||||||
|
match &*ty.elem {
|
||||||
|
syn::Type::Slice(_) => return None,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkfield<'src>(
|
// Similarly i64/u64 aren't supported because they don't
|
||||||
data: &FirstPassRecord<'src>,
|
// implement `Into<JsValue>`
|
||||||
field: &'src DictionaryMember<'src>,
|
let mut any_64bit = false;
|
||||||
) -> Option<ast::DictionaryField> {
|
ty.imported_type_references(&mut |i| {
|
||||||
// use argument position now as we're just binding setters
|
any_64bit = any_64bit || i == "u64" || i == "i64";
|
||||||
let ty = field.type_.to_idl_type(data)?.to_syn_type(TypePosition::Argument)?;
|
});
|
||||||
|
if any_64bit {
|
||||||
// Slice types aren't supported because they don't implement
|
return None
|
||||||
// `Into<JsValue>`
|
|
||||||
if let syn::Type::Reference(ty) = &ty {
|
|
||||||
match &*ty.elem {
|
|
||||||
syn::Type::Slice(_) => return None,
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Similarly i64/u64 aren't supported because they don't
|
|
||||||
// implement `Into<JsValue>`
|
|
||||||
let mut any_64bit = false;
|
|
||||||
ty.imported_type_references(&mut |i| {
|
|
||||||
any_64bit = any_64bit || i == "u64" || i == "i64";
|
|
||||||
});
|
|
||||||
if any_64bit {
|
|
||||||
return None
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(ast::DictionaryField {
|
|
||||||
required: field.required.is_some(),
|
|
||||||
name: rust_ident(&field.identifier.0.to_snake_case()),
|
|
||||||
ty,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some(ast::DictionaryField {
|
||||||
|
required: field.required.is_some(),
|
||||||
|
name: rust_ident(&field.identifier.0.to_snake_case()),
|
||||||
|
ty,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn append_ns(
|
fn append_ns(
|
||||||
|
Reference in New Issue
Block a user