def __generate_constructor(self, out: FileGenerator):
     out.put_line('Initialization(const char* shared_library_name)')
     with IndentScope(out):
         out.put_line('load_module(shared_library_name);')
     if self.params.shared_library_name:
         out.put_line('Initialization()')
         with IndentScope(out):
             out.put_line('#ifdef _WIN32')
             with Indent(out):
                 out.put_line(
                     'load_module("{shared_library_name}.dll");'.format(
                         shared_library_name=self.params.shared_library_name
                     ))
             out.put_line('#elif __APPLE__')
             with Indent(out):
                 out.put_line(
                     'load_module("lib{shared_library_name}.dylib");'.
                     format(shared_library_name=self.params.
                            shared_library_name))
             out.put_line('#else')
             with Indent(out):
                 out.put_line(
                     'load_module("lib{shared_library_name}.so");'.format(
                         shared_library_name=self.params.shared_library_name
                     ))
             out.put_line('#endif')
 def __create_check_and_throw_exceptions_body(self, out: FileGenerator,
                                              throw_generator):
     out.put_line('switch (exception_code)')
     with IndentScope(out):
         out.put_line('case 0:')
         with Indent(out):
             out.put_line('return;')
         out.put_line('case 1:')
         with Indent(out):
             out.put_line('throw std::runtime_error("unknown exception");')
         out.put_line('case 2:')
         with Indent(out):
             out.put_line(
                 'throw std::runtime_error("exception during copying exception object");'
             )
         code_to_exception = {
             exception_class.exception_code: exception_class
             for exception_class in self.exception_classes
         }
         for code, exception_class in code_to_exception.items():
             out.put_line('case {0}:'.format(code))
             with Indent(out):
                 throw_generator(out, exception_class)
         out.put_line('default:')
         with Indent(out):
             out.put_line('assert(false);')
             out.put_line(
                 'throw std::runtime_error("unknown exception code");')
 def __put_define_apple_or_linux(self, out: FileGenerator):
     out.put_line('#if defined(__GNUC__) && __GNUC__ >= 4')
     with Indent(out):
         out.put_line('#define {0} {1} __attribute__ ((visibility ("default")))'.format(
             self.cur_api_define, self.cur_capi_prefix))
     out.put_line('#else')
     with Indent(out):
         out.put_line('#define {0} {1}'.format(self.cur_api_define, self.cur_capi_prefix))
     out.put_line('#endif')
     if_def_then_else(out, '__i386__',
                      self.__generate_posix_i386_attribute,
                      self.__generate_posix_non_i386_attribute)
 def __generate_function_pointers(self, out: FileGenerator, define: bool):
     out.put_line('')
     for c_function in self.cur_namespace_info.c_functions:
         if define:
             out.put_line('#ifdef {name}_define_function_pointer_var'.format(name=c_function.name))
             with Indent(out):
                 out.put_line('{name}_define_function_pointer_var'.format(name=c_function.name))
             out.put_line('#else')
             with Indent(out):
                 out.put_line('{name}_function_type {name} = 0;'.format(
                     name=c_function.name, define_to_null_str=' = 0' if define else ''))
             out.put_line('#endif')
         else:
             out.put_line('extern {name}_function_type {name};'.format(name=c_function.name))
     out.put_line('')
Example #5
0
 def __generate_root_initializer(self, out: FileGenerator, namespace_generators: []):
     out.put_line('class {0}'.format(self.params_description.root_header_initializer))
     with IndentScope(out, '};'):
         member_names = []
         for namespace_generator in namespace_generators:
             member_name = namespace_generator.wrap_name.lower() + '_module_init'
             out.put_line('{namespace}::Initialization {member};'.format(
                 namespace=namespace_generator.wrap_name,
                 member=member_name))
             member_names.append(member_name)
         out.put_line('')
         if not self.params_description.shared_library_name:
             out.put_line('{0}();'.format(self.params_description.root_header_initializer))
         with Unindent(out):
             out.put_line('public:')
         if member_names:
             with IfDefScope(out, '{0}_LIBRARY_USE_DYNAMIC_LOADER'.format(
                     self.api_description.project_name.upper()), False):
                 out.put_line('{0}(const char* shared_library_name) :'.format(
                     self.params_description.root_header_initializer))
                 with Indent(out):
                     for member_name in member_names[:-1]:
                         out.put_line('{member_name}(shared_library_name),'.format(member_name=member_name))
                     out.put_line('{member_name}(shared_library_name)'.format(member_name=member_names[-1]))
                 with IndentScope(out):
                     pass
             if self.params_description.shared_library_name:
                 out.put_line('{0}()'.format(self.params_description.root_header_initializer))
                 with IndentScope(out):
                     pass
Example #6
0
def generate_callback_implementation_default_constructor(
        out: FileGenerator, callback_names, impl_class_name):
    out.put_line('{0}() :'.format(impl_class_name))
    with Indent(out):
        for callback_name in callback_names:
            out.put_line(
                '{callback_name}(0),'.format(callback_name=callback_name))
        out.put_line('mObject(0)')
    with IndentScope(out):
        pass
Example #7
0
def generate_callback_implementation_copy_constructor(out: FileGenerator,
                                                      callback, callback_names,
                                                      impl_class_name,
                                                      class_generator):
    out.put_line('{0}(const {0}& other) :'.format(impl_class_name))
    with Indent(out):
        for callback_name in callback_names:
            out.put_line('{0}(other.{0}),'.format(callback_name))
        out.put_line('mObject(other.mObject)')
    with IndentScope(out):
        generate_callback_implementation_copy_constructor_body(
            out, callback, class_generator)
 def __put_api_define(self, out: FileGenerator, dll_import_or_export):
     out.put_line('#ifdef _WIN32')
     with Indent(out):
         out.put_line('#ifdef __GNUC__')
         with Indent(out):
             out.put_line('#define {0} {1} __attribute__ (({2}))'.format(
                 self.cur_api_define, self.cur_capi_prefix, dll_import_or_export))
             out.put_line('#define {0} __attribute__ ((cdecl))'.format(self.cur_api_convention))
         out.put_line('#else')
         with Indent(out):
             out.put_line('#define {0} {1} __declspec({2})'.format(
                 self.cur_api_define, self.cur_capi_prefix, dll_import_or_export))
             out.put_line('#define {0} __cdecl'.format(self.cur_api_convention))
         out.put_line('#endif')
     out.put_line('#elif __APPLE__')
     with Indent(out):
         self.__put_define_apple_or_linux(out)
     out.put_line('#elif __unix__ || __linux__')
     with Indent(out):
         self.__put_define_apple_or_linux(out)
     out.put_line('#else')
     with Indent(out):
         out.put_line('#error "Unknown platform"')
     out.put_line('#endif')
     out.put_line('')
Example #9
0
    def __build_table(self, caption: str, columns_names: [str],
                      rows: [(str, )]):
        self.output_file.put_line('<table>')
        with Indent(self.output_file):
            self.output_file.put_line(
                '<caption>{caption}</caption>'.format(caption=caption))
            self.output_file.put_line('<tr>')
            with Indent(self.output_file):
                for column_name in columns_names:
                    self.output_file.put_line(
                        '<td> {title} </td>'.format(title=column_name))
            self.output_file.put_line('</tr>')

            for row in rows:
                self.output_file.put_line('<tr>')
                with Indent(self.output_file):
                    for cell in row:
                        self.output_file.put_line('<td>')
                        with Indent(self.output_file):
                            self.output_file.put_line(cell)
                        self.output_file.put_line('</td>')
                self.output_file.put_line('</tr>')
        self.output_file.put_line('</table>\n')
 def __generate_body(self, out: FileGenerator):
     out.put_line('class Initialization')
     with IndentScope(out, '};'):
         self.__generate_members(out)
         self.__generate_load_function(out)
         self.__generate_load_module(out)
         if not self.params.shared_library_name:
             out.put_line('Initialization();')
         out.put_line('Initialization(const Initialization&);')
         if self.params.enable_cpp11_features_in_wrap_code:
             move_constructors_delete_condition = '{ns}_CPP_COMPILER_HAS_MOVE_CONSTRUCTOR_DELETE'.format(
                 ns=self.namespace_name)
             with IfDefScope(out, move_constructors_delete_condition,
                             False):
                 with Indent(out):
                     out.put_line(
                         'Initialization(Initialization &&) = delete;')
         with Unindent(out):
             out.put_line('public:')
         self.__generate_constructor(out)
         self.__generate_destructor(out)
 def __generate_compiler_traits(self, out: FileGenerator):
     if self.params.enable_cpp11_features_in_wrap_code:
         with IfDefScope(out, '__cplusplus', False):
             with Indent(out):
                 if_def_then_else(out, '_MSC_VER', self.__generate_msvc_traits, self.__generate_non_msvc_traits)
         out.put_line('')