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

Skip to content

Commit 03904bf

Browse files
committed
For overriding C++ methods we also need to know whether a parameter
is an output parameter or not. Added support for that.
1 parent 2bc23f5 commit 03904bf

4 files changed

Lines changed: 45 additions & 22 deletions

File tree

Tools/bgen/bgen/bgenBuffer.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ 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, constmode=False):
41+
def getArgDeclarations(self, name, reference=False, constmode=False, outmode=False):
4242
if reference:
4343
raise RuntimeError, "Cannot pass buffer types by reference"
4444
return (self.getBufferDeclarations(name, constmode) +
45-
self.getSizeDeclarations(name))
45+
self.getSizeDeclarations(name, outmode))
4646

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

5151
def getInputBufferDeclarations(self, name, constmode=False):
5252
if constmode:
@@ -55,13 +55,21 @@ def getInputBufferDeclarations(self, name, constmode=False):
5555
const = ""
5656
return ["%s%s *%s__in__" % (const, self.datatype, name)]
5757

58-
def getOutputBufferDeclarations(self, name, constmode=False):
58+
def getOutputBufferDeclarations(self, name, constmode=False, outmode=False):
5959
if constmode:
6060
raise RuntimeError, "Cannot use const output buffer"
61-
return ["%s %s__out__[%s]" % (self.datatype, name, self.size)]
61+
if outmode:
62+
out = "*"
63+
else:
64+
out = ""
65+
return ["%s%s %s__out__[%s]" % (self.datatype, out, name, self.size)]
6266

63-
def getSizeDeclarations(self, name):
64-
return ["%s %s__len__" %(self.sizetype, name)]
67+
def getSizeDeclarations(self, name, outmode=False):
68+
if outmode:
69+
out = "*"
70+
else:
71+
out = ""
72+
return ["%s%s %s__len__" %(self.sizetype, out, name)]
6573

6674
def getAuxDeclarations(self, name):
6775
return ["int %s__in_len__" %(name)]
@@ -112,7 +120,7 @@ def passOutput(self, name):
112120

113121
class InputOnlyBufferMixIn(InputOnlyMixIn):
114122

115-
def getOutputBufferDeclarations(self, name, constmode=False):
123+
def getOutputBufferDeclarations(self, name, constmode=False, outmode=False):
116124
return []
117125

118126

@@ -200,16 +208,20 @@ def getInputBufferDeclarations(self, name, constmode=False):
200208
const = ""
201209
return ["%s%s *%s__in__" % (const, self.type, name)]
202210

203-
def getSizeDeclarations(self, name):
211+
def getSizeDeclarations(self, name, outmode=False):
204212
return []
205213

206214
def getAuxDeclarations(self, name):
207215
return ["int %s__in_len__" % (name)]
208216

209-
def getOutputBufferDeclarations(self, name, constmode=False):
217+
def getOutputBufferDeclarations(self, name, constmode=False, outmode=False):
210218
if constmode:
211219
raise RuntimeError, "Cannot use const output buffer"
212-
return ["%s %s__out__" % (self.type, name)]
220+
if outmode:
221+
out = "*"
222+
else:
223+
out = ""
224+
return ["%s%s %s__out__" % (self.type, out, name)]
213225

214226
def getargsArgs(self, name):
215227
return "(char **)&%s__in__, &%s__in_len__" % (name, name)
@@ -262,7 +274,7 @@ class StructOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType)
262274
Instantiate with the struct type as parameter.
263275
"""
264276

265-
def getSizeDeclarations(self, name):
277+
def getSizeDeclarations(self, name, outmode=False):
266278
return []
267279

268280
def getAuxDeclarations(self, name):
@@ -279,7 +291,7 @@ class ArrayOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType):
279291
Instantiate with the struct type as parameter.
280292
"""
281293

282-
def getSizeDeclarations(self, name):
294+
def getSizeDeclarations(self, name, outmode=False):
283295
return []
284296

285297
def getAuxDeclarations(self, name):

Tools/bgen/bgen/bgenHeapBuffer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ 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, constmode=False):
19+
def getOutputBufferDeclarations(self, name, constmode=False, outmode=False):
2020
if constmode:
2121
raise RuntimeError, "Cannot use const output buffer"
22-
return ["%s *%s__out__" % (self.datatype, name)]
22+
if outmode:
23+
out = "*"
24+
else:
25+
out = ""
26+
return ["%s%s *%s__out__" % (self.datatype, out, name)]
2327

2428
def getargsCheck(self, name):
2529
Output("if ((%s__out__ = malloc(%s__in_len__)) == NULL)", name, name)

Tools/bgen/bgen/bgenType.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ 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, constmode=False):
32+
def getArgDeclarations(self, name, reference=False, constmode=False, outmode=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:
@@ -40,7 +40,11 @@ def getArgDeclarations(self, name, reference=False, constmode=False):
4040
const = "const "
4141
else:
4242
const = ""
43-
return ["%s%s%s %s" % (const, self.typeName, ref, name)]
43+
if outmode:
44+
out = "*"
45+
else:
46+
out = ""
47+
return ["%s%s%s%s %s" % (const, self.typeName, ref, out, name)]
4448

4549
def getAuxDeclarations(self, name):
4650
"""Return any auxiliary declarations needed for implementing this
@@ -213,7 +217,7 @@ def __init__(self, substitute):
213217
self.substitute = substitute
214218
self.typeName = None # Don't show this argument in __doc__ string
215219

216-
def getArgDeclarations(self, name, reference=False, constmode=False):
220+
def getArgDeclarations(self, name, reference=False, constmode=False, outmode=False):
217221
return []
218222

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

Tools/bgen/bgen/bgenVariable.py

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

48-
def getArgDeclarations(self, constmode=False):
48+
def getArgDeclarations(self, fullmodes=False):
4949
refmode = (self.flags & RefMode)
50-
if constmode:
50+
constmode = False
51+
outmode = False
52+
if fullmodes:
5153
constmode = (self.flags & ConstMode)
54+
outmode = (self.flags & OutMode)
5255
return self.type.getArgDeclarations(self.name,
53-
reference=refmode, constmode=constmode)
56+
reference=refmode, constmode=constmode, outmode=outmode)
5457

5558
def getAuxDeclarations(self):
5659
return self.type.getAuxDeclarations(self.name)

0 commit comments

Comments
 (0)