diff options
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/bgen/bgen/bgenBuffer.py | 56 | ||||
-rw-r--r-- | Tools/bgen/bgen/bgenHeapBuffer.py | 8 | ||||
-rw-r--r-- | Tools/bgen/bgen/bgenStackBuffer.py | 4 | ||||
-rw-r--r-- | Tools/bgen/bgen/bgenStringBuffer.py | 4 | ||||
-rw-r--r-- | Tools/bgen/bgen/bgenType.py | 15 | ||||
-rw-r--r-- | Tools/bgen/bgen/bgenVariable.py | 4 |
6 files changed, 47 insertions, 44 deletions
diff --git a/Tools/bgen/bgen/bgenBuffer.py b/Tools/bgen/bgen/bgenBuffer.py index ca7e026..f895315 100644 --- a/Tools/bgen/bgen/bgenBuffer.py +++ b/Tools/bgen/bgen/bgenBuffer.py @@ -38,23 +38,25 @@ class FixedInputOutputBufferType(InputOnlyType): self.sizeformat = sizeformat or type2format[sizetype] self.label_needed = 0 - def declare(self, name): - self.declareBuffer(name) - self.declareSize(name) + def getDeclarations(self, name, reference=False): + if reference: + raise RuntimeError, "Cannot pass buffer types by reference" + return self.getBufferDeclarations(name) + self.getSizeDeclarations(name) - def declareBuffer(self, name): - self.declareInputBuffer(name) - self.declareOutputBuffer(name) + def getBufferDeclarations(self, name): + return self.getInputBufferDeclarations(name) + self.getOutputBufferDeclarations(name) - def declareInputBuffer(self, name): - Output("%s *%s__in__;", self.datatype, name) + def getInputBufferDeclarations(self, name): + return ["%s *%s__in__" % (self.datatype, name)] - def declareOutputBuffer(self, name): - Output("%s %s__out__[%s];", self.datatype, name, self.size) + def getOutputBufferDeclarations(self, name): + return ["%s %s__out__[%s]" % (self.datatype, name, self.size)] - def declareSize(self, name): - Output("%s %s__len__;", self.sizetype, name) - Output("int %s__in_len__;", name) + def getSizeDeclarations(self, name): + return [ + "%s %s__len__" %(self.sizetype, name), + "int %s__in_len__" %(name) + ] def getargsFormat(self): return "s#" @@ -102,14 +104,14 @@ class FixedCombinedInputOutputBufferType(FixedInputOutputBufferType): class InputOnlyBufferMixIn(InputOnlyMixIn): - def declareOutputBuffer(self, name): - pass + def getOutputBufferDeclarations(self, name): + return [] class OutputOnlyBufferMixIn(OutputOnlyMixIn): - def declareInputBuffer(self, name): - pass + def getInputBufferDeclarations(self, name): + return [] class OptionalInputBufferMixIn: @@ -183,14 +185,14 @@ class StructInputOutputBufferType(FixedInputOutputBufferType): FixedInputOutputBufferType.__init__(self, "sizeof(%s)" % type) self.typeName = self.type = type - def declareInputBuffer(self, name): - Output("%s *%s__in__;", self.type, name) + def getInputBufferDeclarations(self, name): + return ["%s *%s__in__" % (self.type, name)] - def declareSize(self, name): - Output("int %s__in_len__;", name) + def getSizeDeclarations(self, name): + return ["int %s__in_len__" % (name)] - def declareOutputBuffer(self, name): - Output("%s %s__out__;", self.type, name) + def getOutputBufferDeclarations(self, name): + return ["%s %s__out__" % (self.type, name)] def getargsArgs(self, name): return "(char **)&%s__in__, &%s__in_len__" % (name, name) @@ -243,8 +245,8 @@ class StructOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType) Instantiate with the struct type as parameter. """ - def declareSize(self, name): - pass + def getSizeDeclarations(self, name): + return [] def passOutput(self, name): return "&%s__out__" % name @@ -257,8 +259,8 @@ class ArrayOutputBufferType(OutputOnlyBufferMixIn, StructInputOutputBufferType): Instantiate with the struct type as parameter. """ - def declareSize(self, name): - pass + def getSizeDeclarations(self, name): + return [] def passOutput(self, name): return "%s__out__" % name diff --git a/Tools/bgen/bgen/bgenHeapBuffer.py b/Tools/bgen/bgen/bgenHeapBuffer.py index 64cf2a4..f9b3daf 100644 --- a/Tools/bgen/bgen/bgenHeapBuffer.py +++ b/Tools/bgen/bgen/bgenHeapBuffer.py @@ -16,8 +16,8 @@ class HeapInputOutputBufferType(FixedInputOutputBufferType): def __init__(self, datatype = 'char', sizetype = 'int', sizeformat = None): FixedInputOutputBufferType.__init__(self, "0", datatype, sizetype, sizeformat) - def declareOutputBuffer(self, name): - Output("%s *%s__out__;", self.datatype, name) + def getOutputBufferDeclarations(self, name): + return ["%s *%s__out__" % (self.datatype, name)] def getargsCheck(self, name): Output("if ((%s__out__ = malloc(%s__in_len__)) == NULL)", name, name) @@ -74,8 +74,8 @@ class HeapOutputBufferType(OutputOnlyMixIn, HeapInputOutputBufferType): Call from Python with buffer size. """ - def declareInputBuffer(self, name): - pass + def getInputBufferDeclarations(self, name): + return [] def getargsFormat(self): return "i" diff --git a/Tools/bgen/bgen/bgenStackBuffer.py b/Tools/bgen/bgen/bgenStackBuffer.py index 9669607..32f97f9 100644 --- a/Tools/bgen/bgen/bgenStackBuffer.py +++ b/Tools/bgen/bgen/bgenStackBuffer.py @@ -22,8 +22,8 @@ class VarStackOutputBufferType(StackOutputBufferType): Instantiate with the buffer size as parameter. """ - def declareSize(self, name): - Output("int %s__len__ = %s;", name, self.size) + def getSizeDeclarations(self, name): + return ["int %s__len__ = %s" % (name, self.size)] def passOutput(self, name): return "%s__out__, &%s__len__" % (name, name) diff --git a/Tools/bgen/bgen/bgenStringBuffer.py b/Tools/bgen/bgen/bgenStringBuffer.py index 683bc0f..01155b3 100644 --- a/Tools/bgen/bgen/bgenStringBuffer.py +++ b/Tools/bgen/bgen/bgenStringBuffer.py @@ -23,8 +23,8 @@ class StringBufferMixIn: less common. I'll write the classes when there is demand.) """ - def declareSize(self, name): - pass + def getSizeDeclarations(self, name): + return [] def getargsFormat(self): return "s" diff --git a/Tools/bgen/bgen/bgenType.py b/Tools/bgen/bgen/bgenType.py index 2f0bc57..3277c5a 100644 --- a/Tools/bgen/bgen/bgenType.py +++ b/Tools/bgen/bgen/bgenType.py @@ -24,15 +24,16 @@ class Type: Example: int.declare('spam') prints "int spam;" """ - Output("%s;", self.getDeclaration(name, reference)) + for decl in self.getDeclarations(name, reference): + Output("%s;", decl) - def getDeclaration(self, name, reference=False): + def getDeclarations(self, name, reference=False): """Return a string declaring a variable or argument, without any syntactic adornment""" if reference: - return "%s& %s" % (self.typeName, name) + return ["%s& %s" % (self.typeName, name)] else: - return "%s %s" % (self.typeName, name) + return ["%s %s" % (self.typeName, name)] def getargs(self): return self.getargsFormat(), self.getargsArgs() @@ -185,9 +186,9 @@ class FakeType(InputOnlyType): def __init__(self, substitute): self.substitute = substitute self.typeName = None # Don't show this argument in __doc__ string - - def declare(self, name, reference=False): - pass + + def getDeclarations(self, name, reference=False): + return [] def getargsFormat(self): return "" diff --git a/Tools/bgen/bgen/bgenVariable.py b/Tools/bgen/bgen/bgenVariable.py index 01cab56..f44340d 100644 --- a/Tools/bgen/bgen/bgenVariable.py +++ b/Tools/bgen/bgen/bgenVariable.py @@ -45,11 +45,11 @@ class Variable: elif self.flags != SelfMode: self.type.declare(self.name) - def getDeclaration(self): + def getDeclarations(self): """Return the unadorned declaration of the variable, suitable for use in a formal parameter list.""" refmode = (self.flags & RefMode) - return self.type.getDeclaration(self.name, reference=refmode) + return self.type.getDeclarations(self.name, reference=refmode) def getargsFormat(self): """Call the type's getargsFormatmethod.""" |