Initial work on abstract method generation. Nothing hooked up yet.
authorBobby Holley <bobbyholley@gmail.com>
Thu, 26 Jan 2012 17:18:43 +0100
changeset 85148 fdee219a75502a61e28f8d2990ec4d91385e4dbd
parent 85147 62e78467654014cce6d4e71913d6199483f0f864
child 85149 4119ff5bd1104150455174319f6f1edba3d41c8f
push id50
push userbobbyholley@gmail.com
push dateThu, 26 Jan 2012 16:18:59 +0000
milestone12.0a1
Initial work on abstract method generation. Nothing hooked up yet.
dom/bindings/BindingGen.py
dom/bindings/Codegen.py
dom/bindings/ConfigurationParser.py
dom/bindings/GlobalGen.py
dom/bindings/Makefile.in
--- a/dom/bindings/BindingGen.py
+++ b/dom/bindings/BindingGen.py
@@ -1,16 +1,16 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import os
 import cPickle
 import WebIDL
-from ConfigurationParser import Configuration, DOMClass, DOMClassImplementation
+from Codegen import Configuration, DOMClass, DOMClassImplementation
 
 def generate_binding_header(config, outputprefix):
     """
     protoList is the list of prototypes defined by this binding
     outputprefix is a prefix to use for the header guards and filename
     """
 
     filename = outputprefix + ".h"
rename from dom/bindings/ConfigurationParser.py
rename to dom/bindings/Codegen.py
--- a/dom/bindings/ConfigurationParser.py
+++ b/dom/bindings/Codegen.py
@@ -1,13 +1,57 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# Classes for handling our configuration data
+# Common codegen classes.
+
+class CodegenThing():
+    """
+    Abstract base case for things that spit out code within a class.
+    """
+    def __init__(self, implementation):
+        self.implementation = implementation
+    def declare(self):
+        """Produce code for a header file."""
+        return "" # Override me!
+    def implement(self):
+        """Produce code for a cpp file."""
+        return "" # Override me!
+
+class Argument():
+    def __init__(self, argType, name):
+        self.argType = argType
+        self.name = name
+    def __str__(self):
+        return self.argType + ' ' + self.name
+
+class AbstractMethod(CodegenThing):
+    def __init__(self, implementation, name, returnType, args):
+        CodegenThing.__init__(self, implementation)
+        self.name = name
+        self.returnType = returnType
+        self.args = args
+    def declare(self):
+        return "%s %s(%s);\n" % (self.returnType, self.name, ', '.join(self.args))
+    def define(self):
+        return self.definition_prologue() + self.definition_body() + self.definition_epilogue()
+    def definition_prologue(self):
+        return "%s\n%s(%s)\n{\n"
+    def definition_epilogue(self):
+        return "\n}\n"
+    def definition_body(self):
+        return "" # Override me!
+
+class InstallMethod(AbstractMethod):
+    def __init__(self, implementation):
+        args = [Argument('JSContext*', 'aCx'), Argument('JSObject*', 'aGlobal')]
+        AbstractMethod.__init__(self, implementation, 'Install', 'bool', args)
+    def definition_body(self):
+        return 'return false;\n'
 
 class DOMClassImplementation():
     def __init__(self, domClass, implConf):
         self.domClass = domClass
         self.nativeClass = implConf['nativeClass']
         self.workers = implConf.get('workers', False)
         if self.workers:
             self.name = domClass.name + '_workers'
--- a/dom/bindings/GlobalGen.py
+++ b/dom/bindings/GlobalGen.py
@@ -4,17 +4,17 @@
 
 # We do one global pass over all the WebIDL to generate our prototype enum
 # and generate information for subsequent phases.
 
 import os
 import cStringIO
 import WebIDL
 import cPickle
-from ConfigurationParser import Configuration, DOMClass, DOMClassImplementation
+from Codegen import Configuration, DOMClass, DOMClassImplementation
 
 def generate_prototype_list(config, filename):
 
     # Read a copy of the old file, so that we don't touch it if it hasn't changed.
     oldFileContents = ""
     try:
         oldFile = open(filename, 'r')
         oldFileContents = ''.join(oldFile.readlines())
--- a/dom/bindings/Makefile.in
+++ b/dom/bindings/Makefile.in
@@ -32,17 +32,17 @@ EXPORTS_$(bindingsIncludePath) = \
   Utils.h \
   $(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
 $(BINDING_CPP_FILES): %Binding.cpp: BindingGen.py \
                       Bindings.conf \
                       PrototypeList.h \
-                      ConfigurationParser.py \
+                      Codegen.py \
                       $(WEBIDL_BASE)/%.webidl
 	$(PYTHON) $(topsrcdir)/config/pythonpath.py -I$(topsrcdir)/other-licenses/ply -I$(srcdir)/parser \
 		$(srcdir)/BindingGen.py $(srcdir)/Bindings.conf $*Binding $(WEBIDL_BASE)/$*.webidl
 
 # The global phase generates PrototypeList.h, which is used in the per-file
 # bindings phase. We need to re-run the global phase whenever any of the
 # webIDL files change in order to keep PrototypeList.h up to date. But if
 # the list itself doesn't change, we don't need to rebuild all of the
@@ -64,17 +64,17 @@ export:: .GlobalPhaseIndicator
 	$(INSTALL) $(IFLAGS1) PrototypeList.h $(DIST)/include/$(bindingsIncludePath)
 
 GLOBAL_PHASE_TARGETS = \
   PrototypeList.h \
   ParserResults.pkl \
   .GlobalPhaseIndicator \
   $(NULL)
 .GlobalPhaseIndicator: GlobalGen.py \
-                       ConfigurationParser.py \
+                       Codegen.py \
                        $(addprefix $(WEBIDL_BASE)/, $(WEBIDL_FILES))
 	$(PYTHON_PATH) -I$(topsrcdir)/other-licenses/ply -I$(srcdir)/parser \
     $(srcdir)/GlobalGen.py $(srcdir)/Bindings.conf $(WEBIDL_BASE) $(WEBIDL_FILES)
 	touch .GlobalPhaseIndicator
 
 GARBAGE += \
   $(GLOBAL_PHASE_TARGETS) \
   $(BINDING_HEADER_FILES) \