本文整理汇总了Python中pybindgen.typehandlers.codesink.MemoryCodeSink方法的典型用法代码示例。如果您正苦于以下问题:Python codesink.MemoryCodeSink方法的具体用法?Python codesink.MemoryCodeSink怎么用?Python codesink.MemoryCodeSink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybindgen.typehandlers.codesink
的用法示例。
在下文中一共展示了codesink.MemoryCodeSink方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def generate(self, code_sink):
"""
code_sink -- a CodeSink instance that will receive the generated code
"""
tmp_sink = codesink.MemoryCodeSink()
self.generate_body(tmp_sink)
code_sink.writeln("static PyObject* %s(%s *self)" % (self.c_function_name,
self.container.iter_pystruct))
code_sink.writeln('{')
code_sink.indent()
tmp_sink.flush_to(code_sink)
code_sink.unindent()
code_sink.writeln('}')
示例2: generate_forward_declarations
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def generate_forward_declarations(self, code_sink_param):
"""
Generate the proxy class (declaration only) to a given code sink
"""
code_sink = MemoryCodeSink()
if self._generate_forward_declarations(code_sink):
code_sink.flush_to(code_sink_param)
else:
self.cannot_be_constructed = True
示例3: __init__
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def __init__(self, error_return, declarations, predecessor=None):
'''
CodeBlock constructor
>>> block = CodeBlock("return NULL;", DeclarationsScope())
>>> block.write_code("foo();")
>>> cleanup1 = block.add_cleanup_code("clean1();")
>>> cleanup2 = block.add_cleanup_code("clean2();")
>>> cleanup3 = block.add_cleanup_code("clean3();")
>>> cleanup2.cancel()
>>> block.write_error_check("error()", "error_clean()")
>>> block.write_code("bar();")
>>> block.write_cleanup()
>>> print block.sink.flush().rstrip()
foo();
if (error()) {
error_clean()
clean3();
clean1();
return NULL;
}
bar();
clean3();
clean1();
:param error_return: code that is generated on error conditions
(detected by write_error_check()); normally
it returns from the wrapper function,
e.g. return NULL;
:param predecessor: optional predecessor code block; a
predecessor is used to search for additional
cleanup actions.
'''
assert isinstance(declarations, DeclarationsScope)
assert predecessor is None or isinstance(predecessor, CodeBlock)
self.sink = codesink.MemoryCodeSink()
self.predecessor = predecessor
self._cleanup_actions = {}
self._last_cleanup_position = 0
self.error_return = error_return
self.declarations = declarations
示例4: clear
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def clear(self):
self._cleanup_actions = {}
self._last_cleanup_position = 0
self.sink = codesink.MemoryCodeSink()
示例5: get_code_sink
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def get_code_sink(self):
"""Returns the internal MemoryCodeSink that holds all declararions."""
return self._declarations
示例6: generate
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
"""
Generates the wrapper code
:param code_sink: a CodeSink instance that will receive the generated code
:param wrapper_name: name of wrapper function
"""
if self.throw: # Bug #780945
self.return_value.REQUIRES_ASSIGNMENT_CONSTRUCTOR = False
self.reset_code_generation_state()
if wrapper_name is None:
self.wrapper_actual_name = self.wrapper_base_name
else:
self.wrapper_actual_name = wrapper_name
tmp_sink = codesink.MemoryCodeSink()
self.generate_body(tmp_sink)
flags = self.get_py_method_def_flags()
self.wrapper_args = []
if 'METH_VARARGS' in flags:
if self.self_parameter_pystruct is None:
self_param = 'PyObject * PYBINDGEN_UNUSED(dummy)'
else:
self_param = '%s *self' % self.self_parameter_pystruct
self.wrapper_args.append(self_param)
self.wrapper_args.append("PyObject *args")
if 'METH_KEYWORDS' in flags:
self.wrapper_args.append("PyObject *kwargs")
self.wrapper_args.extend(extra_wrapper_params)
self.wrapper_return = "PyObject *"
self.write_open_wrapper(code_sink)
tmp_sink.flush_to(code_sink)
self.write_close_wrapper(code_sink)
示例7: generate
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def generate(self, code_sink):
"""
code_sink -- a CodeSink instance that will receive the generated code
"""
tmp_sink = codesink.MemoryCodeSink()
self.generate_body(tmp_sink)
code_sink.writeln("static PyObject* %s(%s *self)" % (self.c_function_name,
self.container.iter_pystruct))
code_sink.writeln('{')
code_sink.indent()
tmp_sink.flush_to(code_sink)
code_sink.unindent()
code_sink.writeln('}')
示例8: generate
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def generate(self, code_sink):
"""
:param code_sink: a CodeSink instance that will receive the generated code
"""
tmp_sink = codesink.MemoryCodeSink()
self.generate_body(tmp_sink)
code_sink.writeln("static PyObject* %s(%s *self, void * PYBINDGEN_UNUSED(closure))"
% (self.c_function_name, self.class_.pystruct))
code_sink.writeln('{')
code_sink.indent()
tmp_sink.flush_to(code_sink)
code_sink.unindent()
code_sink.writeln('}')
示例9: __init__
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def __init__(self, code_sink):
super(_MonolithicSinkManager, self).__init__()
self.final_code_sink = code_sink
self.null_sink = NullCodeSink()
self.includes = MemoryCodeSink()
self.code_sink = MemoryCodeSink()
utils.write_preamble(code_sink)
示例10: generate
# 需要导入模块: from pybindgen.typehandlers import codesink [as 别名]
# 或者: from pybindgen.typehandlers.codesink import MemoryCodeSink [as 别名]
def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
"""
Generates the wrapper code
:param code_sink: a CodeSink instance that will receive the generated code
:returns: the wrapper function name.
"""
if self.visibility == 'private':
raise utils.SkipWrapper("Class %r has a private constructor ->"
" cannot generate a constructor for it" % self._class.full_name)
elif self.visibility == 'protected':
if self._class.helper_class is None:
raise utils.SkipWrapper("Class %r has a protected constructor and no helper class"
" -> cannot generate a constructor for it" % self._class.full_name)
#assert isinstance(class_, CppClass)
tmp_sink = codesink.MemoryCodeSink()
assert self._class is not None
self.generate_body(tmp_sink, gen_call_params=[self._class])
assert ((self.parse_params.get_parameters() == ['""'])
or self.parse_params.get_keywords() is not None), \
("something went wrong with the type handlers;"
" constructors need parameter names, "
"yet no names were given for the class %s constructor"
% self._class.name)
if wrapper_name is None:
self.wrapper_actual_name = self.wrapper_base_name
else:
self.wrapper_actual_name = wrapper_name
self.wrapper_return = 'static int'
self.wrapper_args = ["%s *self" % self._class.pystruct,
"PyObject *args", "PyObject *kwargs"]
self.wrapper_args.extend(extra_wrapper_params)
self.write_open_wrapper(code_sink)
tmp_sink.flush_to(code_sink)
code_sink.writeln('return 0;')
self.write_close_wrapper(code_sink)