]> granicus.if.org Git - python/commitdiff
Allow for (optional) const declaration.
authorJack Jansen <jack.jansen@cwi.nl>
Tue, 5 Jul 2005 10:00:57 +0000 (10:00 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Tue, 5 Jul 2005 10:00:57 +0000 (10:00 +0000)
Tools/bgen/bgen/bgenBuffer.py
Tools/bgen/bgen/bgenHeapBuffer.py
Tools/bgen/bgen/bgenType.py
Tools/bgen/bgen/bgenVariable.py

index bc11e6420f3a6630db7d3965c806be0cdcf4998b..a07e8f0e92ab19ff63b8a9bcab7220afcd16257a 100644 (file)
@@ -38,19 +38,26 @@ class FixedInputOutputBufferType(InputOnlyType):
         self.sizeformat = sizeformat or type2format[sizetype]
         self.label_needed = 0
 
-    def getArgDeclarations(self, name, reference=False):
+    def getArgDeclarations(self, name, reference=False, constmode=False):
         if reference:
             raise RuntimeError, "Cannot pass buffer types by reference"
-        return (self.getBufferDeclarations(name) + 
+        return (self.getBufferDeclarations(name, constmode) + 
                 self.getSizeDeclarations(name))
 
-    def getBufferDeclarations(self, name):
-        return self.getInputBufferDeclarations(name) + self.getOutputBufferDeclarations(name)
+    def getBufferDeclarations(self, name, constmode=False):
+        return self.getInputBufferDeclarations(name, constmode) + \
+               self.getOutputBufferDeclarations(name, constmode)
 
-    def getInputBufferDeclarations(self, name):
-        return ["%s *%s__in__" % (self.datatype, name)]
+    def getInputBufferDeclarations(self, name, constmode=False):
+       if constmode:
+               const = "const "
+       else:
+               const = ""
+        return ["%s%s *%s__in__" % (const, self.datatype, name)]
 
-    def getOutputBufferDeclarations(self, name):
+    def getOutputBufferDeclarations(self, name, constmode=False):
+       if constmode:
+               raise RuntimeError, "Cannot use const output buffer"
         return ["%s %s__out__[%s]" % (self.datatype, name, self.size)]
 
     def getSizeDeclarations(self, name):
@@ -105,13 +112,13 @@ class FixedCombinedInputOutputBufferType(FixedInputOutputBufferType):
 
 class InputOnlyBufferMixIn(InputOnlyMixIn):
 
-    def getOutputBufferDeclarations(self, name):
+    def getOutputBufferDeclarations(self, name, constmode=False):
         return []
 
 
 class OutputOnlyBufferMixIn(OutputOnlyMixIn):
 
-    def getInputBufferDeclarations(self, name):
+    def getInputBufferDeclarations(self, name, constmode=False):
         return []
 
 class OptionalInputBufferMixIn:
@@ -186,8 +193,12 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
         FixedInputOutputBufferType.__init__(self, "sizeof(%s)" % type)
         self.typeName = self.type = type
 
-    def getInputBufferDeclarations(self, name):
-        return ["%s *%s__in__" % (self.type, name)]
+    def getInputBufferDeclarations(self, name, constmode=False):
+       if constmode:
+               const = "const "
+       else:
+               const = ""
+        return ["%s%s *%s__in__" % (const, self.type, name)]
 
     def getSizeDeclarations(self, name):
         return []
@@ -195,7 +206,9 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
     def getAuxDeclarations(self, name):
         return ["int %s__in_len__" % (name)]
 
-    def getOutputBufferDeclarations(self, name):
+    def getOutputBufferDeclarations(self, name, constmode=False):
+       if constmode:
+               raise RuntimeError, "Cannot use const output buffer"
         return ["%s %s__out__" % (self.type, name)]
 
     def getargsArgs(self, name):
index f9b3daf6bfd12f3459ca8cfcce0a4b56b7fe8503..c9c4232a734d79cc50b7981c844caf26bdf49ce4 100644 (file)
@@ -16,7 +16,9 @@ class HeapInputOutputBufferType(FixedInputOutputBufferType):
     def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None):
         FixedInputOutputBufferType.__init__(self, "0", datatype, sizetype, sizeformat)
 
-    def getOutputBufferDeclarations(self, name):
+    def getOutputBufferDeclarations(self, name, constmode=False):
+       if constmode:
+               raise RuntimeError, "Cannot use const output buffer"
         return ["%s *%s__out__" % (self.datatype, name)]
 
     def getargsCheck(self, name):
@@ -74,7 +76,7 @@ class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType):
     Call from Python with buffer size.
     """
 
-    def getInputBufferDeclarations(self, name):
+    def getInputBufferDeclarations(self, name, constmode=False):
         return []
 
     def getargsFormat(self):
index 00dd9d7ad67c3ccf33d3395c0c7569ed5d0dab9d..3cbd18ffd5e3689cfd267754900ea4bb42a0cf1e 100644 (file)
@@ -29,13 +29,18 @@ class Type:
         for decl in self.getAuxDeclarations(name):
             Output("%s;", decl)
 
-    def getArgDeclarations(self, name, reference=False):
+    def getArgDeclarations(self, name, reference=False, constmode=False):
         """Return the main part of the declarations for this type: the items
         that will be passed as arguments in the C/C++ function call."""
         if reference:
-            return ["%s& %s" % (self.typeName, name)]
+            ref = "&"
         else:
-            return ["%s %s" % (self.typeName, name)]
+            ref = ""
+        if constmode:
+            const = "const "
+        else:
+            const = ""
+        return ["%s%s%s %s" % (const, self.typeName, ref, name)]
 
     def getAuxDeclarations(self, name):
         """Return any auxiliary declarations needed for implementing this
@@ -208,7 +213,7 @@ class FakeType(InputOnlyType):
         self.substitute = substitute
         self.typeName = None    # Don't show this argument in __doc__ string
 
-    def getArgDeclarations(self, name, reference=False):
+    def getArgDeclarations(self, name, reference=False, constmode=False):
         return []
 
     def getAuxDeclarations(self, name, reference=False):
index 7848a4fa21f472baa5696c65fc943b5a44df85d4..ef0e6d2a3eb554b17a50a619c6bd97fa68c24d2b 100644 (file)
@@ -45,9 +45,12 @@ class Variable:
         elif self.flags != SelfMode:
             self.type.declare(self.name)
 
-    def getArgDeclarations(self):
+    def getArgDeclarations(self, constmode=False):
         refmode = (self.flags & RefMode)
-        return self.type.getArgDeclarations(self.name, reference=refmode)
+        if constmode:
+               constmode = (self.flags & ConstMode)
+        return self.type.getArgDeclarations(self.name,
+               reference=refmode, constmode=constmode)
     
     def getAuxDeclarations(self):
         return self.type.getAuxDeclarations(self.name)