python/dist/src/Tools/bgen/bgen bgenBuffer.py, 1.10, 1.11 bgenStackBuffer.py, 1.4, 1.5 bgenStringBuffer.py, 1.4, 1.5 bgenType.py, 1.16, 1.17 bgenVariable.py, 1.7, 1.8 scantools.py, 1.38, 1.39
Update of /cvsroot/python/python/dist/src/Tools/bgen/bgen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1216 Modified Files: bgenBuffer.py bgenStackBuffer.py bgenStringBuffer.py bgenType.py bgenVariable.py scantools.py Log Message: More factorization to help C++ support. Index: bgenBuffer.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenBuffer.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- bgenBuffer.py 22 Jun 2005 20:35:23 -0000 1.10 +++ bgenBuffer.py 28 Jun 2005 15:14:34 -0000 1.11 @@ -38,10 +38,11 @@ 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 @@ 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 @@ 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 @@ def getSizeDeclarations(self, name): return [] + def getAuxDeclarations(self, name): + return [] + def passOutput(self, name): return "&%s__out__" % name @@ -262,5 +269,8 @@ def getSizeDeclarations(self, name): return [] + def getAuxDeclarations(self, name): + return [] + def passOutput(self, name): return "%s__out__" % name Index: bgenStackBuffer.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenStackBuffer.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- bgenStackBuffer.py 22 Jun 2005 20:35:23 -0000 1.4 +++ bgenStackBuffer.py 28 Jun 2005 15:14:35 -0000 1.5 @@ -23,6 +23,9 @@ """ def getSizeDeclarations(self, name): + return [] + + def getAuxDeclarations(self, name): return ["int %s__len__ = %s" % (name, self.size)] def passOutput(self, name): Index: bgenStringBuffer.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenStringBuffer.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- bgenStringBuffer.py 22 Jun 2005 20:35:23 -0000 1.4 +++ bgenStringBuffer.py 28 Jun 2005 15:14:35 -0000 1.5 @@ -26,6 +26,9 @@ def getSizeDeclarations(self, name): return [] + def getAuxDeclarations(self, name): + return [] + def getargsFormat(self): return "s" Index: bgenType.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenType.py,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- bgenType.py 24 Jun 2005 19:46:53 -0000 1.16 +++ bgenType.py 28 Jun 2005 15:14:35 -0000 1.17 @@ -24,17 +24,25 @@ 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 @@ 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): Index: bgenVariable.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/bgenVariable.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- bgenVariable.py 24 Jun 2005 19:46:53 -0000 1.7 +++ bgenVariable.py 28 Jun 2005 15:14:35 -0000 1.8 @@ -45,11 +45,12 @@ 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.""" Index: scantools.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Tools/bgen/bgen/scantools.py,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- scantools.py 24 Jun 2005 19:46:53 -0000 1.38 +++ scantools.py 28 Jun 2005 15:14:35 -0000 1.39 @@ -482,8 +482,7 @@ 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 @@ ## 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 @@ 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()
participants (1)
-
jackjansenï¼ users.sourceforge.net