Updated for 2.1a3
[python/dscho.git] / Tools / bgen / bgen / bgenStackBuffer.py
blob1b6350a99ee1692e11517b6aa6bfcbea2c8293af
1 """Buffers allocated on the stack."""
4 from bgenBuffer import FixedInputBufferType, FixedOutputBufferType
7 class StackOutputBufferType(FixedOutputBufferType):
9 """Fixed output buffer allocated on the stack -- passed as (buffer, size).
11 Instantiate with the buffer size as parameter.
12 """
14 def passOutput(self, name):
15 return "%s__out__, %s" % (name, self.size)
18 class VarStackOutputBufferType(StackOutputBufferType):
20 """Output buffer allocated on the stack -- passed as (buffer, &size).
22 Instantiate with the buffer size as parameter.
23 """
25 def declareSize(self, name):
26 Output("int %s__len__ = %s;", name, self.size)
28 def passOutput(self, name):
29 return "%s__out__, &%s__len__" % (name, name)
31 def mkvalueArgs(self, name):
32 return "%s__out__, (int)%s__len__" % (name, name)
35 class VarVarStackOutputBufferType(VarStackOutputBufferType):
37 """Output buffer allocated on the stack -- passed as (buffer, size, &size).
39 Instantiate with the buffer size as parameter.
40 """
42 def passOutput(self, name):
43 return "%s__out__, %s__len__, &%s__len__" % (name, name, name)
46 class ReturnVarStackOutputBufferType(VarStackOutputBufferType):
48 """Output buffer allocated on the stack -- passed as (buffer, size) -> size.
50 Instantiate with the buffer size as parameter.
51 The function's return value is the size.
52 (XXX Should have a way to suppress returning it separately, too.)
53 """
55 def passOutput(self, name):
56 return "%s__out__, %s__len__" % (name, name)
58 def mkvalueArgs(self, name):
59 return "%s__out__, (int)_rv" % name