Change filename filtering so that we still have access to everything.
authorBobby Holley <bobbyholley@gmail.com>
Wed, 08 Feb 2012 13:46:41 -0800
changeset 86463 bab09b5e0e9fb52b17668a3aac86e1baf27b3138
parent 86462 6fb6b364892fe283c35433e454613ba492d263f5
child 86464 979451d9d4167e15d2eb787458652e673877e394
push id99
push userbobbyholley@gmail.com
push dateWed, 08 Feb 2012 21:46:58 +0000
milestone13.0a1
Change filename filtering so that we still have access to everything.
dom/bindings/BindingGen.py
dom/bindings/Codegen.py
dom/bindings/Configuration.py
--- a/dom/bindings/BindingGen.py
+++ b/dom/bindings/BindingGen.py
@@ -3,39 +3,39 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
 import cPickle
 import WebIDL
 from Configuration import *
 from Codegen import CGBindingRoot
 
-def generate_binding_header(config, outputprefix):
+def generate_binding_header(config, outputprefix, webidlfile):
     """
     |config| Is the configuration object.
     |outputprefix| is a prefix to use for the header guards and filename.
     """
 
     filename = outputprefix + ".h"
     print "Generating binding header: %s" % (filename)
     f = open(filename, 'w')
-    root = CGBindingRoot(config, outputprefix)
+    root = CGBindingRoot(config, outputprefix, webidlfile)
     f.write(root.declare())
     f.close()
 
-def generate_binding_cpp(config, outputprefix):
+def generate_binding_cpp(config, outputprefix, webidlfile):
     """
     |config| Is the configuration object.
     |outputprefix| is a prefix to use for the header guards and filename.
     """
 
     filename = outputprefix + ".cpp"
     print "Generating binding implementation: %s" % (filename)
     f = open(filename, 'w')
-    root = CGBindingRoot(config, outputprefix)
+    root = CGBindingRoot(config, outputprefix, webidlfile)
     f.write(root.define())
     f.close()
 
 def main():
 
     # Parse arguments.
     from optparse import OptionParser
     usagestring = "usage: %prog [header|cpp] configFile outputPrefix webIDLFile"
@@ -50,25 +50,20 @@ def main():
     outputPrefix = args[2]
     webIDLFile = os.path.normpath(args[3])
 
     # Load the parsing results
     f = open('ParserResults.pkl', 'rb')
     parserData = cPickle.load(f)
     f.close()
 
-    # Filter the parsing results to this file.
-    filteredData = dict()
-    filteredData = filter(lambda x: x.filename() == webIDLFile, parserData)
-    assert(len(filteredData) > 0)
-
-    # Mix in the configuration data.
-    config = Configuration(configFile, filteredData)
+    # Create the configuration data.
+    config = Configuration(configFile, parserData)
 
     # Generate the prototype classes.
     if buildTarget == "header":
-        generate_binding_header(config, outputPrefix);
+        generate_binding_header(config, outputPrefix, webIDLFile);
     else:
         assert(buildTarget == "cpp")
-        generate_binding_cpp(config, outputPrefix);
+        generate_binding_cpp(config, outputPrefix, webIDLFile);
 
 if __name__ == '__main__':
     main()
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -947,27 +947,27 @@ class CGNamespacedEnum(CGThing):
     def define(self):
         assert False # Only for headers.
 
 class CGBindingRoot(CGThing):
     """
     Root codegen class for binding generation. Instantiate the class, and call
     declare or define to generate header or cpp code (respectively).
     """
-    def __init__(self, config, prefix):
+    def __init__(self, config, prefix, webIDLFile):
 
         # Do codegen for all the descriptors.
-        curr = CGList([CGDescriptor(x) for x in config.getConcreteDescriptors()])
+        curr = CGList([CGDescriptor(x) for x in config.getConcreteDescriptors(webIDLFile)])
 
         # Wrap all of that in our namespaces.
         curr = CGNamespace.build(['mozilla', 'dom', 'bindings', 'prototypes'],
                                  CGWrapper(curr, pre="\n"))
 
         # Add header includes.
-        curr = CGHeaders(config.getConcreteDescriptors(), ['DOMJSClass.h', 'Utils.h'], curr)
+        curr = CGHeaders(config.getConcreteDescriptors(webIDLFile), ['DOMJSClass.h', 'Utils.h'], curr)
 
         # Add include guards.
         curr = CGIncludeGuard(prefix, curr)
 
         # Add the auto-generated comment.
         curr = CGWrapper(curr, pre="/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
 
         # Store the final result.
--- a/dom/bindings/Configuration.py
+++ b/dom/bindings/Configuration.py
@@ -31,20 +31,23 @@ class Configuration:
                 entry = [entry]
             self.descriptors.extend([Descriptor(iface, x) for x in entry])
 
         # Keep the descriptor list sorted for determinism.
         self.descriptors.sort(lambda x,y: cmp(x.name, y.name))
 
     def getInterface(self, ifname):
         return self.interfaces[ifname]
-    def getAllDescriptors(self):
-        return self.descriptors
-    def getConcreteDescriptors(self):
-        return filter(lambda x: x.concrete, self.descriptors)
+    def getAllDescriptors(self, webIDLFile=None):
+        if not webIDLFile:
+            return self.descriptors
+        else:
+            return filter(lambda x: x.interface.filename() == webIDLFile, self.descriptors)
+    def getConcreteDescriptors(self, webIDLFile=None):
+        return filter(lambda x: x.concrete, self.getAllDescriptors(webIDLFile))
     def getDesciptorsForInterface(self, iface):
         return filter(lambda x: x.interface is iface, self.descriptors)
 
 class Descriptor:
     """
     Represents a single descriptor for an interface. See Bindings.conf.
     """
     def __init__(self, interface, desc):