summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2005-06-28 15:14:35 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2005-06-28 15:14:35 (GMT)
commitb6216dd2e7451093239cd04a985be4130714823e (patch)
tree17b89abb8a3bfe42ecbda48bd29802fc28e47628
parent02c64d5684ac8856dd8f0763324258c5cae6d45e (diff)
downloadcpython-b6216dd2e7451093239cd04a985be4130714823e.zip
cpython-b6216dd2e7451093239cd04a985be4130714823e.tar.gz
cpython-b6216dd2e7451093239cd04a985be4130714823e.tar.bz2
More factorization to help C++ support.
-rw-r--r--Tools/bgen/bgen/bgenBuffer.py22
-rw-r--r--Tools/bgen/bgen/bgenStackBuffer.py3
-rw-r--r--Tools/bgen/bgen/bgenStringBuffer.py3
-rw-r--r--Tools/bgen/bgen/bgenType.py21
-rw-r--r--Tools/bgen/bgen/bgenVariable.py9
-rw-r--r--Tools/bgen/bgen/scantools.py11
6 files changed, 51 insertions, 18 deletions
diff --git a/Tools/bgen/bgen/bgenBuffer.py b/Tools/bgen/bgen/bgenBuffer.py
index f895315..bc11e64 100644
--- a/Tools/bgen/bgen/bgenBuffer.py
+++ b/Tools/bgen/bgen/bgenBuffer.py
@@ -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
diff --git a/Tools/bgen/bgen/bgenStackBuffer.py b/Tools/bgen/bgen/bgenStackBuffer.py
index 32f97f9..431bb73 100644
--- a/Tools/bgen/bgen/bgenStackBuffer.py
+++ b/Tools/bgen/bgen/bgenStackBuffer.py
@@ -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):
diff --git a/Tools/bgen/bgen/bgenStringBuffer.py b/Tools/bgen/bgen/bgenStringBuffer.py
index 01155b3..a232f83 100644
--- a/Tools/bgen/bgen/bgenStringBuffer.py
+++ b/Tools/bgen/bgen/bgenStringBuffer.py
@@ -26,6 +26,9 @@ class StringBufferMixIn:
def getSizeDeclarations(self, name):
return []
+ def getAuxDeclarations(self, name):
+ return []
+
def getargsFormat(self):
return "s"
diff --git a/Tools/bgen/bgen/bgenType.py b/Tools/bgen/bgen/bgenType.py
index a31aa74..f7cb388 100644
--- a/Tools/bgen/bgen/bgenType.py
+++ b/Tools/bgen/bgen/bgenType.py
@@ -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):
diff --git a/Tools/bgen/bgen/bgenVariable.py b/Tools/bgen/bgen/bgenVariable.py
index bc1199c..6edeb87 100644
--- a/Tools/bgen/bgen/bgenVariable.py
+++ b/Tools/bgen/bgen/bgenVariable.py
@@ -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."""
diff --git a/Tools/bgen/bgen/scantools.py b/Tools/bgen/bgen/scantools.py
index 67539e0..1ebf70d 100644
--- a/Tools/bgen/bgen/scantools.py
+++ b/Tools/bgen/bgen/scantools.py
@@ -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()