From 19166b2f534da0cdf28f14b1416160e92eabec94 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 29 Apr 2014 21:17:52 +0200 Subject: [PATCH 1/3] Remove C++-specific union codegen code. --- .../dom/bindings/codegen/CodegenRust.py | 58 +------------------ 1 file changed, 3 insertions(+), 55 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index affe5c6ecfb..6dea634cf30 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -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): @@ -1672,20 +1670,8 @@ def UnionTypes(descriptors): 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)) - return (headers, declarations, CGList(SortedDictValues(unionStructs), "\n")) + return CGList(SortedDictValues(unionStructs), "\n") def UnionConversions(descriptors): """ @@ -5343,49 +5329,11 @@ 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 = UnionTypes(config.getDescriptors()) 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 = CGList([curr, UnionConversions(config.getDescriptors())], "\n") curr = CGImports(curr, [ 'dom::bindings::utils::unwrap_jsmanaged', From c51879767e81aecc75d2efceaa72ce5a9a78b172 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 29 Apr 2014 21:18:56 +0200 Subject: [PATCH 2/3] Reuse getTypes in UnionConversions(). This should be equivalent, except that the removed code ignores return values (which we currently don't support). --- .../script/dom/bindings/codegen/CodegenRust.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index 6dea634cf30..c15230725d2 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1688,19 +1688,8 @@ def UnionConversions(descriptors): 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) + for t in getTypes(d): + addUnionTypes(t) return CGWrapper(CGList(SortedDictValues(unionConversions), "\n"), post="\n\n") From 844d48e0af1f6a6cce17f9825a8eb8be83547ba5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 29 Apr 2014 21:33:27 +0200 Subject: [PATCH 3/3] Merge UnionConversions() into UnionTypes(). It's not very useful to have one but not the other, so it makes more sense to deal with them together. --- .../dom/bindings/codegen/CodegenRust.py | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index c15230725d2..a455b7d0b16 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -1669,30 +1669,10 @@ def UnionTypes(descriptors): if t.isUnion(): name = str(t) if not name in unionStructs: - unionStructs[name] = CGUnionStruct(t, d) + unionStructs[name] = CGList([CGUnionStruct(t, d), CGUnionConversionStruct(t, d)]) - return 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) - - for t in getTypes(d): - addUnionTypes(t) - - return CGWrapper(CGList(SortedDictValues(unionConversions), "\n"), - post="\n\n") class Argument(): """ @@ -5320,10 +5300,6 @@ class GlobalGenRoots(): curr = UnionTypes(config.getDescriptors()) - curr = CGWrapper(curr, post='\n') - - curr = CGList([curr, UnionConversions(config.getDescriptors())], "\n") - curr = CGImports(curr, [ 'dom::bindings::utils::unwrap_jsmanaged', 'dom::bindings::codegen::PrototypeList',