Missing file from previous commit (autoscan unit test)

This commit is contained in:
Gustavo J. A. M. Carneiro committed 2007-11-25 21:07:05 +00:00
1 parent b183023987
commit 78d2aacfae
1 file changed
+63
+63
View File
@@ -0,0 +1,63 @@
#! /usr/bin/env python
import sys
import re
import pybindgen
from pybindgen.typehandlers import base as typehandlers
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
from pybindgen import (CppMethod, CppConstructor, CppClass, Enum)
from pybindgen.gccxmlparser import ModuleParser
class PointerHolderTransformation(typehandlers.TypeTransformation):
def __init__(self):
self.rx = re.compile(r'(?:::)?PointerHolder<(\w+)>')
def get_untransformed_name(self, name):
m = self.rx.match(name)
if m is None:
return None
else:
return m.group(1)+'*'
def create_type_handler(self, type_handler, *args, **kwargs):
if issubclass(type_handler, Parameter):
kwargs['transfer_ownership'] = False
elif issubclass(type_handler, ReturnValue):
kwargs['caller_owns_return'] = True
else:
raise AssertionError
handler = type_handler(*args, **kwargs)
handler.set_tranformation(self, self.get_untransformed_name(args[0]))
return handler
def untransform(self, type_handler, declarations, code_block, expression):
return '(%s).thePointer' % (expression,)
def transform(self, type_handler, declarations, code_block, expression):
assert type_handler.untransformed_ctype[-1] == '*'
var = declarations.declare_variable(
'PointerHolder<%s>' % type_handler.untransformed_ctype[:-1], 'tmp')
return '(%s.thePointer = (%s), %s)' % (var, expression, var)
transf = PointerHolderTransformation()
typehandlers.return_type_matcher.register_transformation(transf)
typehandlers.param_type_matcher.register_transformation(transf)
del transf
def my_module_gen(out_file):
out = FileCodeSink(out_file)
pybindgen.write_preamble(out)
out.writeln("#include \"foo.h\"")
module_parser = ModuleParser('foo2', '::')
module = module_parser.parse(sys.argv[1:])
module.generate(out)
if __name__ == '__main__':
my_module_gen(sys.stdout)