mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
auto merge of #2268 : Ms2ger/servo/unions, r=jdm
This commit is contained in:
commit
b2e64704e2
1 changed files with 3 additions and 90 deletions
|
@ -1662,8 +1662,6 @@ def UnionTypes(descriptors):
|
|||
|
||||
# Now find all the things we'll need as arguments and return values because
|
||||
# we need to wrap or unwrap them.
|
||||
headers = set()
|
||||
declarations = set()
|
||||
unionStructs = dict()
|
||||
for d in descriptors:
|
||||
for t in getTypes(d):
|
||||
|
@ -1671,53 +1669,10 @@ def UnionTypes(descriptors):
|
|||
if t.isUnion():
|
||||
name = str(t)
|
||||
if not name in unionStructs:
|
||||
unionStructs[name] = CGUnionStruct(t, d)
|
||||
for f in t.flatMemberTypes:
|
||||
f = f.unroll()
|
||||
if f.isInterface():
|
||||
if f.isSpiderMonkeyInterface():
|
||||
headers.add("jsfriendapi.h")
|
||||
headers.add("mozilla/dom/TypedArray.h")
|
||||
else:
|
||||
typeDesc = d.getDescriptor(f.inner.identifier.name)
|
||||
if typeDesc is not None:
|
||||
declarations.add((typeDesc.nativeType, False))
|
||||
elif f.isDictionary():
|
||||
declarations.add((f.inner.identifier.name, True))
|
||||
unionStructs[name] = CGList([CGUnionStruct(t, d), CGUnionConversionStruct(t, d)])
|
||||
|
||||
return (headers, declarations, CGList(SortedDictValues(unionStructs), "\n"))
|
||||
return CGList(SortedDictValues(unionStructs), "\n\n")
|
||||
|
||||
def UnionConversions(descriptors):
|
||||
"""
|
||||
Returns a CGThing to declare all union argument conversion helper structs.
|
||||
"""
|
||||
# Now find all the things we'll need as arguments because we
|
||||
# need to unwrap them.
|
||||
unionConversions = dict()
|
||||
for d in descriptors:
|
||||
def addUnionTypes(type):
|
||||
if type.isUnion():
|
||||
type = type.unroll()
|
||||
name = str(type)
|
||||
if not name in unionConversions:
|
||||
unionConversions[name] = CGUnionConversionStruct(type, d)
|
||||
|
||||
members = [m for m in d.interface.members]
|
||||
if d.interface.ctor():
|
||||
members.append(d.interface.ctor())
|
||||
signatures = [s for m in members if m.isMethod() for s in m.signatures()]
|
||||
for s in signatures:
|
||||
assert len(s) == 2
|
||||
(_, arguments) = s
|
||||
for a in arguments:
|
||||
addUnionTypes(a.type)
|
||||
|
||||
for m in members:
|
||||
if m.isAttr() and not m.readonly:
|
||||
addUnionTypes(m.type)
|
||||
|
||||
return CGWrapper(CGList(SortedDictValues(unionConversions), "\n"),
|
||||
post="\n\n")
|
||||
|
||||
class Argument():
|
||||
"""
|
||||
|
@ -5343,49 +5298,7 @@ class GlobalGenRoots():
|
|||
@staticmethod
|
||||
def UnionTypes(config):
|
||||
|
||||
(includes, declarations, unions) = UnionTypes(config.getDescriptors())
|
||||
includes.add("mozilla/dom/BindingUtils.h")
|
||||
|
||||
# Wrap all of that in our namespaces.
|
||||
#curr = CGNamespace.build(['mozilla', 'dom'], unions, public=True)
|
||||
curr = unions
|
||||
|
||||
curr = CGWrapper(curr, post='\n')
|
||||
|
||||
namespaces = []
|
||||
stack = [CGList([])]
|
||||
for (clazz, isStruct) in SortedTuples(declarations):
|
||||
elements = clazz.split("::")
|
||||
elements.pop()
|
||||
#clazz = CGClassForwardDeclare(elements.pop(), isStruct=isStruct)
|
||||
i = 0
|
||||
if len(elements) > 0:
|
||||
common = min(len(namespaces), len(elements))
|
||||
while i < common and namespaces[i] == elements[i]:
|
||||
i += 1
|
||||
|
||||
# pop all the namespaces that should be closed
|
||||
namespaces = namespaces[:i]
|
||||
|
||||
# add all the namespaces that should be opened
|
||||
for j, namespace in enumerate(elements[i:]):
|
||||
namespaces.append(namespace)
|
||||
# every CGNamespace that we add holds a CGList
|
||||
list = CGList([])
|
||||
# add the new namespace to the list on top of the stack
|
||||
stack[i + j].append(CGNamespace(namespace, list))
|
||||
# set the top of the namespace stack to the list of the new
|
||||
# namespace
|
||||
stack[i + j + 1:] = [list]
|
||||
|
||||
#stack[len(elements)].append(clazz)
|
||||
|
||||
curr = CGList([stack[0], curr, UnionConversions(config.getDescriptors())], "\n")
|
||||
|
||||
#curr = CGHeaders([], [], includes, [], curr)
|
||||
|
||||
# Add include guards.
|
||||
#curr = CGIncludeGuard('UnionTypes', curr)
|
||||
curr = UnionTypes(config.getDescriptors())
|
||||
|
||||
curr = CGImports(curr, [
|
||||
'dom::bindings::utils::unwrap_jsmanaged',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue