Add basic support for IDL method codegen.
authorBobby Holley <bobbyholley@gmail.com>
Fri, 27 Jan 2012 20:54:46 +0100
changeset 85176 7adc9bb9ca5800d1dfa70ed2da1b7dd7ce5fa123
parent 85175 4b066ec84e0f15932ce1ab7275f9d8c67c9ce8b4
child 85177 379ad3ace1ce2e4e1a5889fd9700ee60636a450f
push id75
push userbobbyholley@gmail.com
push dateFri, 27 Jan 2012 20:06:15 +0000
milestone12.0a1
Add basic support for IDL method codegen.
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -43,35 +43,45 @@ class DOMJSClass(CodegenThing):
 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, inline=False):
+    def __init__(self, implementation, name, returnType, args, inline=False, static=False):
         CodegenThing.__init__(self, implementation)
         self.name = name
         self.returnType = returnType
         self.args = args
         self.inline = inline
+        self.static = static
     def _argstring(self):
         return ', '.join([str(a) for a in self.args])
+    def _decorators(self):
+        decorators = []
+        if self.inline:
+            decorators.append('inline')
+        if self.static:
+            decorators.append('static')
+        decorators.append(self.returnType)
+        return ' '.join(decorators)
     def declare(self):
         if self.inline:
             return self._define()
-        return "%s %s(%s);\n" % (self.returnType, self.name, self._argstring())
+        return "%s %s(%s);\n" % (self._decorators(), self.name, self._argstring())
     def _define(self):
         return self.definition_prologue() + self.definition_body() + self.definition_epilogue()
     def define(self):
         return "" if self.inline else self._define()
     def definition_prologue(self):
         maybeNewline = " " if self.inline else "\n"
-        return "%s%s%s(%s)\n{" % (self.returnType, maybeNewline, self.name, self._argstring())
+        return "%s%s%s(%s)\n{" % (self._decorators(), maybeNewline,
+                                  self.name, self._argstring())
     def definition_epilogue(self):
         return "\n}\n"
     def definition_body(self):
         assert(False) # Override me!
 
 class MethodDefiner:
     def __init__(self, implementation):
         self.implementation = implementation