mirror of https://github.com/python/cpython
Allow for (optional) const declaration.
This commit is contained in:
parent
82cb9a235d
commit
0257424a2a
|
@ -38,19 +38,26 @@ class FixedInputOutputBufferType(InputOnlyType):
|
||||||
self.sizeformat = sizeformat or type2format[sizetype]
|
self.sizeformat = sizeformat or type2format[sizetype]
|
||||||
self.label_needed = 0
|
self.label_needed = 0
|
||||||
|
|
||||||
def getArgDeclarations(self, name, reference=False):
|
def getArgDeclarations(self, name, reference=False, constmode=False):
|
||||||
if reference:
|
if reference:
|
||||||
raise RuntimeError, "Cannot pass buffer types by reference"
|
raise RuntimeError, "Cannot pass buffer types by reference"
|
||||||
return (self.getBufferDeclarations(name) +
|
return (self.getBufferDeclarations(name, constmode) +
|
||||||
self.getSizeDeclarations(name))
|
self.getSizeDeclarations(name))
|
||||||
|
|
||||||
def getBufferDeclarations(self, name):
|
def getBufferDeclarations(self, name, constmode=False):
|
||||||
return self.getInputBufferDeclarations(name) + self.getOutputBufferDeclarations(name)
|
return self.getInputBufferDeclarations(name, constmode) + \
|
||||||
|
self.getOutputBufferDeclarations(name, constmode)
|
||||||
|
|
||||||
def getInputBufferDeclarations(self, name):
|
def getInputBufferDeclarations(self, name, constmode=False):
|
||||||
return ["%s *%s__in__" % (self.datatype, name)]
|
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)]
|
return ["%s %s__out__[%s]" % (self.datatype, name, self.size)]
|
||||||
|
|
||||||
def getSizeDeclarations(self, name):
|
def getSizeDeclarations(self, name):
|
||||||
|
@ -105,13 +112,13 @@ class FixedCombinedInputOutputBufferType(FixedInputOutputBufferType):
|
||||||
|
|
||||||
class InputOnlyBufferMixIn(InputOnlyMixIn):
|
class InputOnlyBufferMixIn(InputOnlyMixIn):
|
||||||
|
|
||||||
def getOutputBufferDeclarations(self, name):
|
def getOutputBufferDeclarations(self, name, constmode=False):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
class OutputOnlyBufferMixIn(OutputOnlyMixIn):
|
class OutputOnlyBufferMixIn(OutputOnlyMixIn):
|
||||||
|
|
||||||
def getInputBufferDeclarations(self, name):
|
def getInputBufferDeclarations(self, name, constmode=False):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
class OptionalInputBufferMixIn:
|
class OptionalInputBufferMixIn:
|
||||||
|
@ -186,8 +193,12 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
|
||||||
FixedInputOutputBufferType.__init__(self, "sizeof(%s)" % type)
|
FixedInputOutputBufferType.__init__(self, "sizeof(%s)" % type)
|
||||||
self.typeName = self.type = type
|
self.typeName = self.type = type
|
||||||
|
|
||||||
def getInputBufferDeclarations(self, name):
|
def getInputBufferDeclarations(self, name, constmode=False):
|
||||||
return ["%s *%s__in__" % (self.type, name)]
|
if constmode:
|
||||||
|
const = "const "
|
||||||
|
else:
|
||||||
|
const = ""
|
||||||
|
return ["%s%s *%s__in__" % (const, self.type, name)]
|
||||||
|
|
||||||
def getSizeDeclarations(self, name):
|
def getSizeDeclarations(self, name):
|
||||||
return []
|
return []
|
||||||
|
@ -195,7 +206,9 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
|
||||||
def getAuxDeclarations(self, name):
|
def getAuxDeclarations(self, name):
|
||||||
return ["int %s__in_len__" % (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)]
|
return ["%s %s__out__" % (self.type, name)]
|
||||||
|
|
||||||
def getargsArgs(self, name):
|
def getargsArgs(self, name):
|
||||||
|
|
|
@ -16,7 +16,9 @@ class HeapInputOutputBufferType(FixedInputOutputBufferType):
|
||||||
def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None):
|
def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None):
|
||||||
FixedInputOutputBufferType.__init__(self, "0", datatype, sizetype, sizeformat)
|
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)]
|
return ["%s *%s__out__" % (self.datatype, name)]
|
||||||
|
|
||||||
def getargsCheck(self, name):
|
def getargsCheck(self, name):
|
||||||
|
@ -74,7 +76,7 @@ class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType):
|
||||||
Call from Python with buffer size.
|
Call from Python with buffer size.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def getInputBufferDeclarations(self, name):
|
def getInputBufferDeclarations(self, name, constmode=False):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def getargsFormat(self):
|
def getargsFormat(self):
|
||||||
|
|
|
@ -29,13 +29,18 @@ class Type:
|
||||||
for decl in self.getAuxDeclarations(name):
|
for decl in self.getAuxDeclarations(name):
|
||||||
Output("%s;", decl)
|
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
|
"""Return the main part of the declarations for this type: the items
|
||||||
that will be passed as arguments in the C/C++ function call."""
|
that will be passed as arguments in the C/C++ function call."""
|
||||||
if reference:
|
if reference:
|
||||||
return ["%s& %s" % (self.typeName, name)]
|
ref = "&"
|
||||||
else:
|
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):
|
def getAuxDeclarations(self, name):
|
||||||
"""Return any auxiliary declarations needed for implementing this
|
"""Return any auxiliary declarations needed for implementing this
|
||||||
|
@ -208,7 +213,7 @@ class FakeType(InputOnlyType):
|
||||||
self.substitute = substitute
|
self.substitute = substitute
|
||||||
self.typeName = None # Don't show this argument in __doc__ string
|
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 []
|
return []
|
||||||
|
|
||||||
def getAuxDeclarations(self, name, reference=False):
|
def getAuxDeclarations(self, name, reference=False):
|
||||||
|
|
|
@ -45,9 +45,12 @@ class Variable:
|
||||||
elif self.flags != SelfMode:
|
elif self.flags != SelfMode:
|
||||||
self.type.declare(self.name)
|
self.type.declare(self.name)
|
||||||
|
|
||||||
def getArgDeclarations(self):
|
def getArgDeclarations(self, constmode=False):
|
||||||
refmode = (self.flags & RefMode)
|
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):
|
def getAuxDeclarations(self):
|
||||||
return self.type.getAuxDeclarations(self.name)
|
return self.type.getAuxDeclarations(self.name)
|
||||||
|
|
Loading…
Reference in New Issue