mirror of https://github.com/python/cpython
More factorization to help C++ support.
This commit is contained in:
parent
02c64d5684
commit
b6216dd2e7
|
@ -38,10 +38,11 @@ class FixedInputOutputBufferType(InputOnlyType):
|
|||
self.sizeformat = sizeformat or type2format[sizetype]
|
||||
self.label_needed = 0
|
||||
|
||||
def getDeclarations(self, name, reference=False):
|
||||
def getArgDeclarations(self, name, reference=False):
|
||||
if reference:
|
||||
raise RuntimeError, "Cannot pass buffer types by reference"
|
||||
return self.getBufferDeclarations(name) + self.getSizeDeclarations(name)
|
||||
return (self.getBufferDeclarations(name) +
|
||||
self.getSizeDeclarations(name))
|
||||
|
||||
def getBufferDeclarations(self, name):
|
||||
return self.getInputBufferDeclarations(name) + self.getOutputBufferDeclarations(name)
|
||||
|
@ -53,10 +54,10 @@ class FixedInputOutputBufferType(InputOnlyType):
|
|||
return ["%s %s__out__[%s]" % (self.datatype, name, self.size)]
|
||||
|
||||
def getSizeDeclarations(self, name):
|
||||
return [
|
||||
"%s %s__len__" %(self.sizetype, name),
|
||||
"int %s__in_len__" %(name)
|
||||
]
|
||||
return ["%s %s__len__" %(self.sizetype, name)]
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
return ["int %s__in_len__" %(name)]
|
||||
|
||||
def getargsFormat(self):
|
||||
return "s#"
|
||||
|
@ -189,6 +190,9 @@ class StructInputOutputBufferType(FixedInputOutputBufferType):
|
|||
return ["%s *%s__in__" % (self.type, name)]
|
||||
|
||||
def getSizeDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
return ["int %s__in_len__" % (name)]
|
||||
|
||||
def getOutputBufferDeclarations(self, name):
|
||||
|
@ -248,6 +252,9 @@ class StructOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType)
|
|||
def getSizeDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def passOutput(self, name):
|
||||
return "&%s__out__" % name
|
||||
|
||||
|
@ -262,5 +269,8 @@ class ArrayOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType):
|
|||
def getSizeDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def passOutput(self, name):
|
||||
return "%s__out__" % name
|
||||
|
|
|
@ -23,6 +23,9 @@ class VarStackOutputBufferType(StackOutputBufferType):
|
|||
"""
|
||||
|
||||
def getSizeDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
return ["int %s__len__ = %s" % (name, self.size)]
|
||||
|
||||
def passOutput(self, name):
|
||||
|
|
|
@ -26,6 +26,9 @@ class StringBufferMixIn:
|
|||
def getSizeDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
return []
|
||||
|
||||
def getargsFormat(self):
|
||||
return "s"
|
||||
|
||||
|
|
|
@ -24,17 +24,25 @@ class Type:
|
|||
|
||||
Example: int.declare('spam') prints "int spam;"
|
||||
"""
|
||||
for decl in self.getDeclarations(name, reference):
|
||||
for decl in self.getArgDeclarations(name, reference):
|
||||
Output("%s;", decl)
|
||||
for decl in self.getAuxDeclarations(name):
|
||||
Output("%s;", decl)
|
||||
|
||||
def getDeclarations(self, name, reference=False):
|
||||
"""Return a string declaring a variable or argument, without
|
||||
any syntactic adornment"""
|
||||
def getArgDeclarations(self, name, reference=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)]
|
||||
else:
|
||||
return ["%s %s" % (self.typeName, name)]
|
||||
|
||||
def getAuxDeclarations(self, name):
|
||||
"""Return any auxiliary declarations needed for implementing this
|
||||
type, such as helper variables used to hold sizes, etc. These declarations
|
||||
are not part of the C/C++ function call interface."""
|
||||
return []
|
||||
|
||||
def getargs(self):
|
||||
return self.getargsFormat(), self.getargsArgs()
|
||||
|
||||
|
@ -187,7 +195,10 @@ class FakeType(InputOnlyType):
|
|||
self.substitute = substitute
|
||||
self.typeName = None # Don't show this argument in __doc__ string
|
||||
|
||||
def getDeclarations(self, name, reference=False):
|
||||
def getArgDeclarations(self, name, reference=False):
|
||||
return []
|
||||
|
||||
def getAuxDeclarations(self, name, reference=False):
|
||||
return []
|
||||
|
||||
def getargsFormat(self):
|
||||
|
|
|
@ -45,11 +45,12 @@ class Variable:
|
|||
elif self.flags != SelfMode:
|
||||
self.type.declare(self.name)
|
||||
|
||||
def getDeclarations(self):
|
||||
"""Return the unadorned declaration of the variable,
|
||||
suitable for use in a formal parameter list."""
|
||||
def getArgDeclarations(self):
|
||||
refmode = (self.flags & RefMode)
|
||||
return self.type.getDeclarations(self.name, reference=refmode)
|
||||
return self.type.getArgDeclarations(self.name, reference=refmode)
|
||||
|
||||
def getAuxDeclarations(self):
|
||||
return self.type.getAuxDeclarations(self.name)
|
||||
|
||||
def getargsFormat(self):
|
||||
"""Call the type's getargsFormatmethod."""
|
||||
|
|
|
@ -482,8 +482,7 @@ if missing: raise "Missing Types"
|
|||
modifiers = self.getmodifiers(match)
|
||||
type = self.pythonizename(type)
|
||||
name = self.pythonizename(name)
|
||||
if name in self.alreadydone:
|
||||
self.report("Name has already been defined: %r", name)
|
||||
if self.checkduplicate(name):
|
||||
return
|
||||
self.report("==> %s %s <==", type, name)
|
||||
if self.blacklisted(type, name):
|
||||
|
@ -499,7 +498,6 @@ if missing: raise "Missing Types"
|
|||
## self.report(" %r", arg)
|
||||
self.report("*** %s %s unmanageable", type, name)
|
||||
return
|
||||
self.alreadydone.append(name)
|
||||
if modifiers:
|
||||
self.generate(type, name, arglist, modifiers)
|
||||
else:
|
||||
|
@ -508,6 +506,13 @@ if missing: raise "Missing Types"
|
|||
def getmodifiers(self, match):
|
||||
return []
|
||||
|
||||
def checkduplicate(self, name):
|
||||
if name in self.alreadydone:
|
||||
self.report("Name has already been defined: %r", name)
|
||||
return True
|
||||
self.alreadydone.append(name)
|
||||
return False
|
||||
|
||||
def pythonizename(self, name):
|
||||
name = re.sub("\*", " ptr", name)
|
||||
name = name.strip()
|
||||
|
|
Loading…
Reference in New Issue