def my_module_gen(out_file): out = FileCodeSink(out_file) #pybindgen.write_preamble(out) out.writeln("#include \"hello.h\"") module_parser = ModuleParser('hello') module_parser.add_pre_scan_hook(pre_scan_hook) module = module_parser.parse(sys.argv[1:]) module.generate(out)
def get_section_code_sink(self, section_name): if section_name == "__main__": return self.main_sink try: return self.section_sinks[section_name] except KeyError: file_name = os.path.join(os.path.dirname(self.main_file_name), "src/%s.cc" % section_name) sink = FileCodeSink(open(file_name, "wt")) self.section_sinks[section_name] = sink sink.writeln(self._header) return sink
def get_section_code_sink(self, section_name): if section_name == '__main__': return self.main_sink try: return self.section_sinks[section_name] except KeyError: file_name = os.path.join(os.path.dirname(self.main_file_name), "src/%s.cc" % section_name) sink = FileCodeSink(open(file_name, "wt")) self.section_sinks[section_name] = sink sink.writeln(self._header) return sink
def my_module_gen(out_file, pygccxml_mode): if pygccxml_mode == 'castxml': from pybindgen.castxmlparser import ModuleParser else: from pybindgen.gccxmlparser import ModuleParser out = FileCodeSink(out_file) #pybindgen.write_preamble(out) out.writeln("#include \"hello.h\"") module_parser = ModuleParser('hello') module_parser.add_pre_scan_hook(pre_scan_hook) module = module_parser.parse(sys.argv[2:]) module.generate(out)
class TrMultiSectionFactory(MultiSectionFactory): _header = ( "/* ** GENERATED CODE -- DO NOT EDIT **\n" " *\n" " * Copyright (c) 2012 Dan Eicher\n" " *\n" " * Permission is hereby granted, free of charge, to any person obtaining a\n" ' * copy of this software and associated documentation files (the "Software"),\n' " * to deal in the Software without restriction, including without limitation\n" " * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n" " * and/or sell copies of the Software, and to permit persons to whom the\n" " * Software is furnished to do so, subject to the following conditions:\n" " *\n" " * The above copyright notice and this permission notice shall be included in\n" " * all copies or substantial portions of the Software.\n" " *\n" ' * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n' " * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" " * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" " * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" " * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n" " * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n" " * DEALINGS IN THE SOFTWARE.\n" " *\n" " */\n" ) def __init__(self, main_file_name): self.main_file_name = main_file_name self.main_sink = FileCodeSink(open("src/" + main_file_name, "wt")) self.header_name = "tr_module.h" header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name) self.header_sink = FileCodeSink(open("src/" + header_file_name, "wt")) self.section_sinks = {} self.main_sink.writeln(self._header) self.header_sink.writeln(self._header) def get_section_code_sink(self, section_name): if section_name == "__main__": return self.main_sink try: return self.section_sinks[section_name] except KeyError: file_name = os.path.join(os.path.dirname(self.main_file_name), "src/%s.cc" % section_name) sink = FileCodeSink(open(file_name, "wt")) self.section_sinks[section_name] = sink sink.writeln(self._header) return sink def get_main_code_sink(self): return self.main_sink def get_common_header_code_sink(self): return self.header_sink def get_common_header_include(self): return '"%s"' % self.header_name def close(self): self.header_sink.file.close() self.main_sink.file.close() for sink in self.section_sinks.itervalues(): sink.file.close()
class TrMultiSectionFactory(MultiSectionFactory): _header = ( "/* ** GENERATED CODE -- DO NOT EDIT **\n" " *\n" " * Copyright (c) 2012 Dan Eicher\n" " *\n" " * Permission is hereby granted, free of charge, to any person obtaining a\n" " * copy of this software and associated documentation files (the \"Software\"),\n" " * to deal in the Software without restriction, including without limitation\n" " * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n" " * and/or sell copies of the Software, and to permit persons to whom the\n" " * Software is furnished to do so, subject to the following conditions:\n" " *\n" " * The above copyright notice and this permission notice shall be included in\n" " * all copies or substantial portions of the Software.\n" " *\n" " * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" " * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" " * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" " * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" " * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n" " * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n" " * DEALINGS IN THE SOFTWARE.\n" " *\n" " */\n") def __init__(self, main_file_name): self.main_file_name = main_file_name self.main_sink = FileCodeSink(open('src/' + main_file_name, "wt")) self.header_name = "tr_module.h" header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name) self.header_sink = FileCodeSink(open('src/' + header_file_name, "wt")) self.section_sinks = {} self.main_sink.writeln(self._header) self.header_sink.writeln(self._header) def get_section_code_sink(self, section_name): if section_name == '__main__': return self.main_sink try: return self.section_sinks[section_name] except KeyError: file_name = os.path.join(os.path.dirname(self.main_file_name), "src/%s.cc" % section_name) sink = FileCodeSink(open(file_name, "wt")) self.section_sinks[section_name] = sink sink.writeln(self._header) return sink def get_main_code_sink(self): return self.main_sink def get_common_header_code_sink(self): return self.header_sink def get_common_header_include(self): return '"%s"' % self.header_name def close(self): self.header_sink.file.close() self.main_sink.file.close() for sink in self.section_sinks.itervalues(): sink.file.close()