Skip to content

Commit

Permalink
Allow for (optional) const declaration.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackjansen committed Jul 5, 2005
1 parent 82cb9a2 commit 0257424
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
37 changes: 25 additions & 12 deletions Tools/bgen/bgen/bgenBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,26 @@ def __init__(self, size, datatype = 'char', sizetype = 'int', sizeformat = None)
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):
Expand Down Expand Up @@ -105,13 +112,13 @@ def passOutput(self, name):

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:
Expand Down Expand Up @@ -186,16 +193,22 @@ def __init__(self, type):
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 []

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):
Expand Down
6 changes: 4 additions & 2 deletions Tools/bgen/bgen/bgenHeapBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 9 additions & 4 deletions Tools/bgen/bgen/bgenType.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ def declare(self, name, reference=False):
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
Expand Down Expand Up @@ -208,7 +213,7 @@ def __init__(self, substitute):
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):
Expand Down
7 changes: 5 additions & 2 deletions Tools/bgen/bgen/bgenVariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ def declare(self):
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)
Expand Down

0 comments on commit 0257424

Please sign in to comment.