Auto merge of #15451 - servo:typedefs, r=nox

Improve code around typedefs.

<!-- 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/15451)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-02-08 04:18:44 -08:00 committed by GitHub
commit e1a004ee7a
3 changed files with 15 additions and 17 deletions

View file

@ -548,11 +548,6 @@ def typeIsSequenceOrHasSequenceMember(type):
return False
def typeNeedsRooting(type, descriptorProvider):
return (type.isGeckoInterface() and
descriptorProvider.getDescriptor(type.unroll().inner.identifier.name).needsRooting)
def union_native_type(t):
name = t.unroll().name
return 'UnionTypes::%s' % name
@ -1422,8 +1417,6 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
nullable = returnType.nullable()
dictName = returnType.inner.name if nullable else returnType.name
result = CGGeneric(dictName)
if typeNeedsRooting(returnType, descriptorProvider):
raise TypeError("We don't support rootable dictionaries return values")
if nullable:
result = CGWrapper(result, pre="Option<", post=">")
return result
@ -6122,14 +6115,19 @@ class CGBindingRoot(CGThing):
# Do codegen for all the typdefs
for t in typedefs:
if t.innerType.isUnion():
cgthings.extend([CGGeneric("\npub use dom::bindings::codegen::UnionTypes::%s as %s;\n\n" %
(t.innerType, t.identifier.name))])
typeName = getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider())
substs = {
"name": t.identifier.name,
"type": typeName.define(),
}
if t.innerType.isUnion() and not t.innerType.nullable():
# Allow using the typedef's name for accessing variants.
template = "pub use self::%(type)s as %(name)s;"
else:
assert not typeNeedsRooting(t.innerType, config.getDescriptorProvider)
cgthings.extend([CGGeneric("\npub type %s = " % (t.identifier.name)),
getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider()),
CGGeneric(";\n\n")])
template = "pub type %(name)s = %(type)s;"
cgthings.append(CGGeneric(template % substs))
# Do codegen for all the dictionaries.
cgthings.extend([CGDictionary(d, config.getDescriptorProvider())

View file

@ -201,20 +201,17 @@ class Descriptor(DescriptorProvider):
# Callback and SpiderMonkey types do not use JS smart pointers, so we should not use the
# built-in rooting mechanisms for them.
if spiderMonkeyInterface:
self.needsRooting = False
self.returnType = 'Rc<%s>' % typeName
self.argumentType = '&%s' % typeName
self.nativeType = typeName
pathDefault = 'dom::types::%s' % typeName
elif self.interface.isCallback():
self.needsRooting = False
ty = 'dom::bindings::codegen::Bindings::%sBinding::%s' % (ifaceName, ifaceName)
pathDefault = ty
self.returnType = "Rc<%s>" % ty
self.argumentType = "???"
self.nativeType = ty
else:
self.needsRooting = True
self.returnType = "Root<%s>" % typeName
self.argumentType = "&%s" % typeName
self.nativeType = "*const %s" % typeName

View file

@ -7,6 +7,9 @@
enum TestEnum { "", "foo", "bar" };
typedef (DOMString or URL or Blob) TestTypedef;
typedef (DOMString or URL or Blob)? TestTypedefNullableUnion;
typedef DOMString TestTypedefString;
typedef Blob TestTypedefInterface;
dictionary TestDictionary {
required boolean requiredValue;