Skip to content

Commit b2e6470

Browse files
author
bors-servo
committed
auto merge of servo#2268 : Ms2ger/servo/unions, r=jdm
2 parents a1838f8 + 844d48e commit b2e6470

File tree

1 file changed

+5
-92
lines changed

1 file changed

+5
-92
lines changed

src/components/script/dom/bindings/codegen/CodegenRust.py

Lines changed: 5 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,62 +1662,17 @@ def UnionTypes(descriptors):
16621662

16631663
# Now find all the things we'll need as arguments and return values because
16641664
# we need to wrap or unwrap them.
1665-
headers = set()
1666-
declarations = set()
16671665
unionStructs = dict()
16681666
for d in descriptors:
16691667
for t in getTypes(d):
16701668
t = t.unroll()
16711669
if t.isUnion():
16721670
name = str(t)
16731671
if not name in unionStructs:
1674-
unionStructs[name] = CGUnionStruct(t, d)
1675-
for f in t.flatMemberTypes:
1676-
f = f.unroll()
1677-
if f.isInterface():
1678-
if f.isSpiderMonkeyInterface():
1679-
headers.add("jsfriendapi.h")
1680-
headers.add("mozilla/dom/TypedArray.h")
1681-
else:
1682-
typeDesc = d.getDescriptor(f.inner.identifier.name)
1683-
if typeDesc is not None:
1684-
declarations.add((typeDesc.nativeType, False))
1685-
elif f.isDictionary():
1686-
declarations.add((f.inner.identifier.name, True))
1687-
1688-
return (headers, declarations, CGList(SortedDictValues(unionStructs), "\n"))
1689-
1690-
def UnionConversions(descriptors):
1691-
"""
1692-
Returns a CGThing to declare all union argument conversion helper structs.
1693-
"""
1694-
# Now find all the things we'll need as arguments because we
1695-
# need to unwrap them.
1696-
unionConversions = dict()
1697-
for d in descriptors:
1698-
def addUnionTypes(type):
1699-
if type.isUnion():
1700-
type = type.unroll()
1701-
name = str(type)
1702-
if not name in unionConversions:
1703-
unionConversions[name] = CGUnionConversionStruct(type, d)
1704-
1705-
members = [m for m in d.interface.members]
1706-
if d.interface.ctor():
1707-
members.append(d.interface.ctor())
1708-
signatures = [s for m in members if m.isMethod() for s in m.signatures()]
1709-
for s in signatures:
1710-
assert len(s) == 2
1711-
(_, arguments) = s
1712-
for a in arguments:
1713-
addUnionTypes(a.type)
1714-
1715-
for m in members:
1716-
if m.isAttr() and not m.readonly:
1717-
addUnionTypes(m.type)
1718-
1719-
return CGWrapper(CGList(SortedDictValues(unionConversions), "\n"),
1720-
post="\n\n")
1672+
unionStructs[name] = CGList([CGUnionStruct(t, d), CGUnionConversionStruct(t, d)])
1673+
1674+
return CGList(SortedDictValues(unionStructs), "\n\n")
1675+
17211676

17221677
class Argument():
17231678
"""
@@ -5343,49 +5298,7 @@ def InheritTypes(config):
53435298
@staticmethod
53445299
def UnionTypes(config):
53455300

5346-
(includes, declarations, unions) = UnionTypes(config.getDescriptors())
5347-
includes.add("mozilla/dom/BindingUtils.h")
5348-
5349-
# Wrap all of that in our namespaces.
5350-
#curr = CGNamespace.build(['mozilla', 'dom'], unions, public=True)
5351-
curr = unions
5352-
5353-
curr = CGWrapper(curr, post='\n')
5354-
5355-
namespaces = []
5356-
stack = [CGList([])]
5357-
for (clazz, isStruct) in SortedTuples(declarations):
5358-
elements = clazz.split("::")
5359-
elements.pop()
5360-
#clazz = CGClassForwardDeclare(elements.pop(), isStruct=isStruct)
5361-
i = 0
5362-
if len(elements) > 0:
5363-
common = min(len(namespaces), len(elements))
5364-
while i < common and namespaces[i] == elements[i]:
5365-
i += 1
5366-
5367-
# pop all the namespaces that should be closed
5368-
namespaces = namespaces[:i]
5369-
5370-
# add all the namespaces that should be opened
5371-
for j, namespace in enumerate(elements[i:]):
5372-
namespaces.append(namespace)
5373-
# every CGNamespace that we add holds a CGList
5374-
list = CGList([])
5375-
# add the new namespace to the list on top of the stack
5376-
stack[i + j].append(CGNamespace(namespace, list))
5377-
# set the top of the namespace stack to the list of the new
5378-
# namespace
5379-
stack[i + j + 1:] = [list]
5380-
5381-
#stack[len(elements)].append(clazz)
5382-
5383-
curr = CGList([stack[0], curr, UnionConversions(config.getDescriptors())], "\n")
5384-
5385-
#curr = CGHeaders([], [], includes, [], curr)
5386-
5387-
# Add include guards.
5388-
#curr = CGIncludeGuard('UnionTypes', curr)
5301+
curr = UnionTypes(config.getDescriptors())
53895302

53905303
curr = CGImports(curr, [
53915304
'dom::bindings::utils::unwrap_jsmanaged',

0 commit comments

Comments
 (0)