Generate DOM bindings imports for webidl typedefs

This commit is contained in:
Fernando Jiménez Moreno 2017-08-02 11:48:49 +02:00
parent 5fff90c73f
commit 354d94059b

View file

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