mirror of
https://github.com/servo/servo.git
synced 2025-06-17 12:54:28 +00:00
Clean up CGImports a bit more.
This commit is contained in:
parent
9677eb292d
commit
9619390ece
1 changed files with 24 additions and 14 deletions
|
@ -1468,34 +1468,44 @@ class CGImports(CGWrapper):
|
||||||
return [type]
|
return [type]
|
||||||
|
|
||||||
def isImportable(type):
|
def isImportable(type):
|
||||||
|
if not type.isType():
|
||||||
|
assert type.isInterface()
|
||||||
|
return not type.isCallback()
|
||||||
return type.isNonCallbackInterface() and not type.builtin
|
return type.isNonCallbackInterface() and not type.builtin
|
||||||
|
|
||||||
|
def relatedTypesForSignatures(method):
|
||||||
types = []
|
types = []
|
||||||
for d in descriptors:
|
for (returnType, arguments) in method.signatures():
|
||||||
if not d.interface.isCallback():
|
|
||||||
imports += ['dom::types::%s' % d.interface.identifier.name]
|
|
||||||
|
|
||||||
methods = d.interface.members + d.interface.namedConstructors
|
|
||||||
constructor = d.interface.ctor()
|
|
||||||
if constructor:
|
|
||||||
methods += [constructor]
|
|
||||||
|
|
||||||
for m in methods:
|
|
||||||
if m.isMethod():
|
|
||||||
for (returnType, arguments) in m.signatures():
|
|
||||||
types += componentTypes(returnType)
|
types += componentTypes(returnType)
|
||||||
for arg in arguments:
|
for arg in arguments:
|
||||||
types += componentTypes(arg.type)
|
types += componentTypes(arg.type)
|
||||||
|
return types
|
||||||
|
|
||||||
|
def getIdentifier(t):
|
||||||
|
if t.isType():
|
||||||
|
return t.inner.identifier
|
||||||
|
assert t.isInterface()
|
||||||
|
return t.identifier
|
||||||
|
|
||||||
|
types = []
|
||||||
|
for d in descriptors:
|
||||||
|
types += [d.interface]
|
||||||
|
|
||||||
|
members = d.interface.members + d.interface.namedConstructors
|
||||||
|
constructor = d.interface.ctor()
|
||||||
|
if constructor:
|
||||||
|
members += [constructor]
|
||||||
|
|
||||||
|
for m in members:
|
||||||
|
if m.isMethod():
|
||||||
|
types += relatedTypesForSignatures(m)
|
||||||
elif m.isAttr():
|
elif m.isAttr():
|
||||||
types += componentTypes(m.type)
|
types += componentTypes(m.type)
|
||||||
|
|
||||||
for c in callbacks:
|
for c in callbacks:
|
||||||
for (returnType, arguments) in c.signatures():
|
types += relatedTypesForSignatures(c)
|
||||||
types += componentTypes(returnType)
|
|
||||||
for arg in arguments:
|
|
||||||
types += componentTypes(arg.type)
|
|
||||||
|
|
||||||
imports += ['dom::types::%s' % t.inner.identifier.name for t in types if isImportable(t)]
|
imports += ['dom::types::%s' % getIdentifier(t).name for t in types if isImportable(t)]
|
||||||
|
|
||||||
statements = ['#![allow(%s)]' % ','.join(ignored_warnings)]
|
statements = ['#![allow(%s)]' % ','.join(ignored_warnings)]
|
||||||
statements.extend('use %s;' % i for i in sorted(set(imports)))
|
statements.extend('use %s;' % i for i in sorted(set(imports)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue