Fix for bug 734506 (Fix DOM list binding generation - add includes for all types). r=jst.
authorPeter Van der Beken <peterv@propagandism.org>
Fri, 14 Oct 2011 23:18:41 +0200
changeset 88798 0d866eb9ac2438f2262911ae19c0f202a31a2de9
parent 88797 6aaac780033cddf3df49cdc4e2328509ceaa5477
child 88799 a3b40d32ad975ba75def58e7c46aae23bcd2eccc
push id22223
push usermbrubeck@mozilla.com
push dateMon, 12 Mar 2012 20:31:41 +0000
treeherdermozilla-central@406113c400a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs734506
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Fix for bug 734506 (Fix DOM list binding generation - add includes for all types). r=jst.
js/xpconnect/src/dombindingsgen.py
--- a/js/xpconnect/src/dombindingsgen.py
+++ b/js/xpconnect/src/dombindingsgen.py
@@ -321,33 +321,38 @@ def completeConfiguration(conf, includeP
     for iface in stubbedInterfaces:
         for member in iface.stubMembers:
             checkStubMember(member)
 
     return interfaces
 
 # === Generating the header file
 
-def needsForwardDeclaration(type):
-    return isInterfaceType(type) or (type.kind == 'native' and type.specialtype is None)
-
-def getTypes(classes, map={}):
+def addType(types, type, map):
     def getTranslatedType(type):
         return map.get(type, type)
 
+    type = xpidl.unaliasType(type)
+    if isInterfaceType(type) or (type.kind == 'native' and type.specialtype is None):
+        types.add(getTranslatedType(type.name))
+
+
+def getTypes(classes, map):
     types = set()
     for clazz in classes.itervalues():
-        types.add(getTranslatedType(clazz.nativeClass))
-        if clazz.indexGetter and needsForwardDeclaration(clazz.realIndexGetter.realtype):
-            types.add(getTranslatedType(clazz.realIndexGetter.realtype.name))
-        if clazz.indexSetter and needsForwardDeclaration(clazz.realIndexSetter.realtype):
-            types.add(getTranslatedType(clazz.realIndexSetter.realtype.name))
-        if clazz.nameGetter and needsForwardDeclaration(clazz.realNameGetter.realtype):
-            types.add(getTranslatedType(clazz.realNameGetter.realtype.name))
-    return sorted(types)
+        types.add(map.get(clazz.nativeClass, clazz.nativeClass))
+        if clazz.indexGetter:
+            addType(types, clazz.realIndexGetter.realtype, map)
+        if clazz.indexSetter:
+            addType(types, clazz.realIndexSetter.realtype, map)
+        if clazz.nameGetter:
+            addType(types, clazz.realNameGetter.realtype, map)
+        if clazz.nameSetter:
+            addType(types, clazz.realNameSetter.realtype, map)
+    return types
 
 listDefinitionTemplate = (
 "class ${name} {\n"
 "public:\n"
 "    template<typename I>\n"
 "    static JSObject *create(JSContext *cx, XPCWrappedNativeScope *scope, I *list, bool *triedToWrap)\n"
 "    {\n"
 "        return create(cx, scope, list, GetWrapperCache(list), triedToWrap);\n"
@@ -368,17 +373,17 @@ def writeHeaderFile(filename, config):
     headerMacro = '__gen_%s__' % filename.replace('.', '_')
     f = open(filename, 'w')
     try:
         f.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
                 "#ifndef " + headerMacro + "\n"
                 "#define " + headerMacro + "\n\n")
 
         namespaces = []
-        for type in getTypes(config.classes, {}):
+        for type in sorted(getTypes(config.classes, {})):
             newNamespaces = type.split('::')
             type = newNamespaces.pop()
             j = 0
             for i in range(min(len(namespaces), len(newNamespaces))):
                 if namespaces[i] != newNamespaces[i]:
                     break
                 j += 1
             for i in range(j, len(namespaces)):
@@ -628,40 +633,30 @@ def writeMethodStub(f, classname, method
 
 def writeStubFile(filename, config, interfaces):
     print "Creating stub file", filename
     make_targets.append(filename)
 
     f = open(filename, 'w')
     filesIncluded = set()
 
-    def includeType(type):
-        type = unaliasType(type)
-        if type.kind in ('builtin', 'native'):
-            return None
-        file = conf.irregularFilenames.get(type.name, type.name) + '.h'
-        if file not in filesIncluded:
-            f.write('#include "%s"\n' % file)
-            filesIncluded.add(file)
-        return type
-
-    def writeIncludesForMember(member):
-        assert member.kind in ('attribute', 'method')
-        resulttype = includeType(member.realtype)
-        if member.kind == 'method':
-            for p in member.params:
-                includeType(p.realtype)
-        return resulttype
-
     headerFilename = re.sub(r'(\.cpp)?$', '.h', filename)
 
     try:
         f.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
 
-        f.write("".join([("#include \"%s.h\"\n" % re.sub(r'(([^:]+::)*)', '', type)) for type in getTypes(config.classes, config.irregularFilenames)]))
+        types = getTypes(config.classes, config.irregularFilenames)
+        for clazz in config.classes.itervalues():
+            for member in clazz.members:
+                addType(types, member.realtype, config.irregularFilenames)
+                if member.kind == 'method':
+                    for p in member.params:
+                        addType(types, p.realtype, config.irregularFilenames)
+
+        f.write("".join([("#include \"%s.h\"\n" % re.sub(r'(([^:]+::)*)', '', type)) for type in sorted(types)]))
         f.write("\n")
 
         f.write("namespace mozilla {\n"
                 "namespace dom {\n"
                 "namespace binding {\n\n")
 
         f.write("// Property name ids\n\n")