Auto merge of #17945 - ferjm:typedef.dom.binding, r=jdm

Generate DOM bindings imports for webidl typedefs

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17945)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-02 13:22:32 -05:00 committed by GitHub
commit 3ef182ca36

View file

@ -1848,7 +1848,8 @@ class CGImports(CGWrapper):
"""
Generates the appropriate import/use statements.
"""
def __init__(self, child, descriptors, callbacks, dictionaries, enums, imports, config, ignored_warnings=None):
def __init__(self, child, descriptors, callbacks, dictionaries, enums, typedefs, imports, config,
ignored_warnings=None):
"""
Adds a set of imports.
"""
@ -1937,6 +1938,11 @@ class CGImports(CGWrapper):
for d in dictionaries:
types += componentTypes(d)
# Import the type names used in the typedefs that are being defined.
for t in typedefs:
if not t.innerType.isCallback():
types += componentTypes(t.innerType)
# Normalize the types we've collected and remove any ones which can't be imported.
types = removeWrapperAndNullableTypes(types)
@ -2292,6 +2298,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
callbacks=[],
dictionaries=[],
enums=[],
typedefs=[],
imports=imports,
config=config,
ignored_warnings=[])
@ -5507,15 +5514,17 @@ class CGWeakReferenceableTrait(CGThing):
return self.code
def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries=None, enums=None):
def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries=None, enums=None, typedefs=None):
if not callbacks:
callbacks = []
if not dictionaries:
dictionaries = []
if not enums:
enums = []
if not typedefs:
typedefs = []
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, [
return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [
'core::nonzero::NonZero',
'js',
'js::JSCLASS_GLOBAL_SLOT_COUNT',
@ -6220,7 +6229,7 @@ class CGBindingRoot(CGThing):
# Do codegen for all the enums.
cgthings = [CGEnum(e) for e in enums]
# Do codegen for all the typdefs
# Do codegen for all the typedefs
for t in typedefs:
typeName = getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider())
substs = {
@ -6258,7 +6267,7 @@ class CGBindingRoot(CGThing):
# Add imports
curr = generate_imports(config, curr, callbackDescriptors, mainCallbacks,
dictionaries, enums)
dictionaries, enums, typedefs)
# Add the auto-generated comment.
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
@ -7060,7 +7069,7 @@ class GlobalGenRoots():
CGRegisterProxyHandlers(config),
], "\n")
return CGImports(code, descriptors=[], callbacks=[], dictionaries=[], enums=[], imports=[
return CGImports(code, descriptors=[], callbacks=[], dictionaries=[], enums=[], typedefs=[], imports=[
'dom::bindings::codegen::Bindings',
'dom::bindings::codegen::PrototypeList::Proxies',
'libc',