mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
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:
commit
e1a004ee7a
3 changed files with 15 additions and 17 deletions
|
@ -548,11 +548,6 @@ def typeIsSequenceOrHasSequenceMember(type):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def typeNeedsRooting(type, descriptorProvider):
|
|
||||||
return (type.isGeckoInterface() and
|
|
||||||
descriptorProvider.getDescriptor(type.unroll().inner.identifier.name).needsRooting)
|
|
||||||
|
|
||||||
|
|
||||||
def union_native_type(t):
|
def union_native_type(t):
|
||||||
name = t.unroll().name
|
name = t.unroll().name
|
||||||
return 'UnionTypes::%s' % name
|
return 'UnionTypes::%s' % name
|
||||||
|
@ -1422,8 +1417,6 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
|
||||||
nullable = returnType.nullable()
|
nullable = returnType.nullable()
|
||||||
dictName = returnType.inner.name if nullable else returnType.name
|
dictName = returnType.inner.name if nullable else returnType.name
|
||||||
result = CGGeneric(dictName)
|
result = CGGeneric(dictName)
|
||||||
if typeNeedsRooting(returnType, descriptorProvider):
|
|
||||||
raise TypeError("We don't support rootable dictionaries return values")
|
|
||||||
if nullable:
|
if nullable:
|
||||||
result = CGWrapper(result, pre="Option<", post=">")
|
result = CGWrapper(result, pre="Option<", post=">")
|
||||||
return result
|
return result
|
||||||
|
@ -6122,14 +6115,19 @@ class CGBindingRoot(CGThing):
|
||||||
|
|
||||||
# Do codegen for all the typdefs
|
# Do codegen for all the typdefs
|
||||||
for t in typedefs:
|
for t in typedefs:
|
||||||
if t.innerType.isUnion():
|
typeName = getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider())
|
||||||
cgthings.extend([CGGeneric("\npub use dom::bindings::codegen::UnionTypes::%s as %s;\n\n" %
|
substs = {
|
||||||
(t.innerType, t.identifier.name))])
|
"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:
|
else:
|
||||||
assert not typeNeedsRooting(t.innerType, config.getDescriptorProvider)
|
template = "pub type %(name)s = %(type)s;"
|
||||||
cgthings.extend([CGGeneric("\npub type %s = " % (t.identifier.name)),
|
|
||||||
getRetvalDeclarationForType(t.innerType, config.getDescriptorProvider()),
|
cgthings.append(CGGeneric(template % substs))
|
||||||
CGGeneric(";\n\n")])
|
|
||||||
|
|
||||||
# Do codegen for all the dictionaries.
|
# Do codegen for all the dictionaries.
|
||||||
cgthings.extend([CGDictionary(d, config.getDescriptorProvider())
|
cgthings.extend([CGDictionary(d, config.getDescriptorProvider())
|
||||||
|
|
|
@ -201,20 +201,17 @@ class Descriptor(DescriptorProvider):
|
||||||
# Callback and SpiderMonkey types do not use JS smart pointers, so we should not use the
|
# Callback and SpiderMonkey types do not use JS smart pointers, so we should not use the
|
||||||
# built-in rooting mechanisms for them.
|
# built-in rooting mechanisms for them.
|
||||||
if spiderMonkeyInterface:
|
if spiderMonkeyInterface:
|
||||||
self.needsRooting = False
|
|
||||||
self.returnType = 'Rc<%s>' % typeName
|
self.returnType = 'Rc<%s>' % typeName
|
||||||
self.argumentType = '&%s' % typeName
|
self.argumentType = '&%s' % typeName
|
||||||
self.nativeType = typeName
|
self.nativeType = typeName
|
||||||
pathDefault = 'dom::types::%s' % typeName
|
pathDefault = 'dom::types::%s' % typeName
|
||||||
elif self.interface.isCallback():
|
elif self.interface.isCallback():
|
||||||
self.needsRooting = False
|
|
||||||
ty = 'dom::bindings::codegen::Bindings::%sBinding::%s' % (ifaceName, ifaceName)
|
ty = 'dom::bindings::codegen::Bindings::%sBinding::%s' % (ifaceName, ifaceName)
|
||||||
pathDefault = ty
|
pathDefault = ty
|
||||||
self.returnType = "Rc<%s>" % ty
|
self.returnType = "Rc<%s>" % ty
|
||||||
self.argumentType = "???"
|
self.argumentType = "???"
|
||||||
self.nativeType = ty
|
self.nativeType = ty
|
||||||
else:
|
else:
|
||||||
self.needsRooting = True
|
|
||||||
self.returnType = "Root<%s>" % typeName
|
self.returnType = "Root<%s>" % typeName
|
||||||
self.argumentType = "&%s" % typeName
|
self.argumentType = "&%s" % typeName
|
||||||
self.nativeType = "*const %s" % typeName
|
self.nativeType = "*const %s" % typeName
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
enum TestEnum { "", "foo", "bar" };
|
enum TestEnum { "", "foo", "bar" };
|
||||||
typedef (DOMString or URL or Blob) TestTypedef;
|
typedef (DOMString or URL or Blob) TestTypedef;
|
||||||
|
typedef (DOMString or URL or Blob)? TestTypedefNullableUnion;
|
||||||
|
typedef DOMString TestTypedefString;
|
||||||
|
typedef Blob TestTypedefInterface;
|
||||||
|
|
||||||
dictionary TestDictionary {
|
dictionary TestDictionary {
|
||||||
required boolean requiredValue;
|
required boolean requiredValue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue