Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0257424

Browse files
committed
Allow for (optional) const declaration.
1 parent 82cb9a2 commit 0257424

4 files changed

Lines changed: 43 additions & 20 deletions

File tree

Tools/bgen/bgen/bgenBuffer.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,26 @@ def __init__(self, size, datatype = 'char', sizetype = 'int', sizeformat = None)
3838
self.sizeformat = sizeformat or type2format[sizetype]
3939
self.label_needed = 0
4040

41-
def getArgDeclarations(self, name, reference=False):
41+
def getArgDeclarations(self, name, reference=False, constmode=False):
4242
if reference:
4343
raise RuntimeError, "Cannot pass buffer types by reference"
44-
return (self.getBufferDeclarations(name) +
44+
return (self.getBufferDeclarations(name, constmode) +
4545
self.getSizeDeclarations(name))
4646

47-
def getBufferDeclarations(self, name):
48-
return self.getInputBufferDeclarations(name) + self.getOutputBufferDeclarations(name)
47+
def getBufferDeclarations(self, name, constmode=False):
48+
return self.getInputBufferDeclarations(name, constmode) + \
49+
self.getOutputBufferDeclarations(name, constmode)
4950

50-
def getInputBufferDeclarations(self, name):
51-
return ["%s *%s__in__" % (self.datatype, name)]
51+
def getInputBufferDeclarations(self, name, constmode=False):
52+
if constmode:
53+
const = "const "
54+
else:
55+
const = ""
56+
return ["%s%s *%s__in__" % (const, self.datatype, name)]
5257

53-
def getOutputBufferDeclarations(self, name):
58+
def getOutputBufferDeclarations(self, name, constmode=False):
59+
if constmode:
60+
raise RuntimeError, "Cannot use const output buffer"
5461
return ["%s %s__out__[%s]" % (self.datatype, name, self.size)]
5562

5663
def getSizeDeclarations(self, name):
@@ -105,13 +112,13 @@ def passOutput(self, name):
105112

106113
class InputOnlyBufferMixIn(InputOnlyMixIn):
107114

108-
def getOutputBufferDeclarations(self, name):
115+
def getOutputBufferDeclarations(self, name, constmode=False):
109116
return []
110117

111118

112119
class OutputOnlyBufferMixIn(OutputOnlyMixIn):
113120

114-
def getInputBufferDeclarations(self, name):
121+
def getInputBufferDeclarations(self, name, constmode=False):
115122
return []
116123

117124
class OptionalInputBufferMixIn:
@@ -186,16 +193,22 @@ def __init__(self, type):
186193
FixedInputOutputBufferType.__init__(self, "sizeof(%s)" % type)
187194
self.typeName = self.type = type
188195

189-
def getInputBufferDeclarations(self, name):
190-
return ["%s *%s__in__" % (self.type, name)]
196+
def getInputBufferDeclarations(self, name, constmode=False):
197+
if constmode:
198+
const = "const "
199+
else:
200+
const = ""
201+
return ["%s%s *%s__in__" % (const, self.type, name)]
191202

192203
def getSizeDeclarations(self, name):
193204
return []
194205

195206
def getAuxDeclarations(self, name):
196207
return ["int %s__in_len__" % (name)]
197208

198-
def getOutputBufferDeclarations(self, name):
209+
def getOutputBufferDeclarations(self, name, constmode=False):
210+
if constmode:
211+
raise RuntimeError, "Cannot use const output buffer"
199212
return ["%s %s__out__" % (self.type, name)]
200213

201214
def getargsArgs(self, name):

Tools/bgen/bgen/bgenHeapBuffer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class HeapInputOutputBufferType(FixedInputOutputBufferType):
1616
def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None):
1717
FixedInputOutputBufferType.__init__(self, "0", datatype, sizetype, sizeformat)
1818

19-
def getOutputBufferDeclarations(self, name):
19+
def getOutputBufferDeclarations(self, name, constmode=False):
20+
if constmode:
21+
raise RuntimeError, "Cannot use const output buffer"
2022
return ["%s *%s__out__" % (self.datatype, name)]
2123

2224
def getargsCheck(self, name):
@@ -74,7 +76,7 @@ class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType):
7476
Call from Python with buffer size.
7577
"""
7678

77-
def getInputBufferDeclarations(self, name):
79+
def getInputBufferDeclarations(self, name, constmode=False):
7880
return []
7981

8082
def getargsFormat(self):

Tools/bgen/bgen/bgenType.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,18 @@ def declare(self, name, reference=False):
2929
for decl in self.getAuxDeclarations(name):
3030
Output("%s;", decl)
3131

32-
def getArgDeclarations(self, name, reference=False):
32+
def getArgDeclarations(self, name, reference=False, constmode=False):
3333
"""Return the main part of the declarations for this type: the items
3434
that will be passed as arguments in the C/C++ function call."""
3535
if reference:
36-
return ["%s& %s" % (self.typeName, name)]
36+
ref = "&"
3737
else:
38-
return ["%s %s" % (self.typeName, name)]
38+
ref = ""
39+
if constmode:
40+
const = "const "
41+
else:
42+
const = ""
43+
return ["%s%s%s %s" % (const, self.typeName, ref, name)]
3944

4045
def getAuxDeclarations(self, name):
4146
"""Return any auxiliary declarations needed for implementing this
@@ -208,7 +213,7 @@ def __init__(self, substitute):
208213
self.substitute = substitute
209214
self.typeName = None # Don't show this argument in __doc__ string
210215

211-
def getArgDeclarations(self, name, reference=False):
216+
def getArgDeclarations(self, name, reference=False, constmode=False):
212217
return []
213218

214219
def getAuxDeclarations(self, name, reference=False):

Tools/bgen/bgen/bgenVariable.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ def declare(self):
4545
elif self.flags != SelfMode:
4646
self.type.declare(self.name)
4747

48-
def getArgDeclarations(self):
48+
def getArgDeclarations(self, constmode=False):
4949
refmode = (self.flags & RefMode)
50-
return self.type.getArgDeclarations(self.name, reference=refmode)
50+
if constmode:
51+
constmode = (self.flags & ConstMode)
52+
return self.type.getArgDeclarations(self.name,
53+
reference=refmode, constmode=constmode)
5154

5255
def getAuxDeclarations(self):
5356
return self.type.getAuxDeclarations(self.name)

0 commit comments

Comments
 (0)