Example #1
0
 def generate_code_internal(self, definitions, definition_name):
     if not definition_name in definitions.dictionaries:
         raise ValueError('%s is not an IDL dictionary' % definition_name)
     interfaces_info = self.info_provider.interfaces_info
     dictionary = definitions.dictionaries[definition_name]
     interface_info = interfaces_info[definition_name]
     header_template = self.jinja_env.get_template('dictionary_impl.h.tmpl')
     cpp_template = self.jinja_env.get_template('dictionary_impl.cc.tmpl')
     template_context = v8_dictionary.dictionary_impl_context(
         dictionary, interfaces_info)
     include_paths = interface_info.get('dependencies_include_paths')
     if not is_testing_target(interface_info.get('full_path')):
         template_context['exported'] = \
             self.info_provider.specifier_for_export
         template_context['header_includes'].add(
             self.info_provider.include_path_for_export)
     template_context['header_includes'].update(
         interface_info.get('additional_header_includes', []))
     header_path, cpp_path = self.output_paths(definition_name,
                                               interface_info)
     this_include_header_path = self.normalize_this_header_path(header_path)
     template_context['this_include_header_path'] = this_include_header_path
     template_context['header_guard'] = to_header_guard(
         this_include_header_path)
     header_text, cpp_text = self.render_templates(include_paths,
                                                   header_template,
                                                   cpp_template,
                                                   template_context)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
Example #2
0
 def generate_dictionary_code(self, definitions, dictionary_name,
                              dictionary):
     # pylint: disable=unused-argument
     interfaces_info = self.info_provider.interfaces_info
     header_template = self.jinja_env.get_template('dictionary_v8.h.tmpl')
     cpp_template = self.jinja_env.get_template('dictionary_v8.cc.tmpl')
     interface_info = interfaces_info[dictionary_name]
     component_info = self.info_provider.component_info
     template_context = v8_dictionary.dictionary_context(
         dictionary, interfaces_info, component_info)
     include_paths = interface_info.get('dependencies_include_paths')
     # Add the include for interface itself
     template_context['header_includes'].add(interface_info['include_path'])
     if not is_testing_target(interface_info.get('full_path')):
         template_context['header_includes'].add(
             self.info_provider.include_path_for_export)
         template_context['exported'] = \
             self.info_provider.specifier_for_export
     header_path, cpp_path = self.output_paths(dictionary_name)
     this_include_header_path = self.normalize_this_header_path(header_path)
     template_context['this_include_header_path'] = this_include_header_path
     template_context['header_guard'] = to_header_guard(
         this_include_header_path)
     header_text, cpp_text = self.render_templates(include_paths,
                                                   header_template,
                                                   cpp_template,
                                                   template_context)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
Example #3
0
    def generate_code_internal(self, callback_function, path):
        self.typedef_resolver.resolve(callback_function, callback_function.name)
        header_template = self.jinja_env.get_template('callback_function.h.tmpl')
        cpp_template = self.jinja_env.get_template('callback_function.cc.tmpl')
        template_context = v8_callback_function.callback_function_context(
            callback_function)
        if not is_testing_target(path):
            template_context['exported'] = self.info_provider.specifier_for_export
            template_context['header_includes'].append(
                self.info_provider.include_path_for_export)

        # TODO(bashi): Dependency resolution shouldn't happen here.
        # Move this into includes_for_type() families.
        for argument in callback_function.arguments:
            if argument.idl_type.is_union_type:
                template_context['header_includes'].append(
                    self.info_provider.include_path_for_union_types(argument.idl_type))

        snake_base_name = to_snake_case('V8%s' % callback_function.name)
        header_path = posixpath.join(self.output_dir, '%s.h' % snake_base_name)
        cpp_path = posixpath.join(self.output_dir, '%s.cc' % snake_base_name)
        this_include_header_path = self.normalize_this_header_path(header_path)
        template_context['this_include_header_path'] = this_include_header_path
        template_context['header_guard'] = to_header_guard(this_include_header_path)
        header_text, cpp_text = self.render_templates(
            [], header_template, cpp_template, template_context)
        return (
            (header_path, header_text),
            (cpp_path, cpp_text),
        )
Example #4
0
    def generate_interface_code(self, definitions, interface_name, interface):
        interface_info = self.info_provider.interfaces_info[interface_name]
        full_path = interface_info.get('full_path')
        component = idl_filename_to_component(full_path)
        include_paths = interface_info.get('dependencies_include_paths')

        # Select appropriate Jinja template and contents function
        if interface.is_callback:
            header_template_filename = 'callback_interface.h.tmpl'
            cpp_template_filename = 'callback_interface.cc.tmpl'
            interface_context = v8_callback_interface.callback_interface_context
        elif interface.is_partial:
            interface_context = v8_interface.interface_context
            header_template_filename = 'partial_interface.h.tmpl'
            cpp_template_filename = 'partial_interface.cc.tmpl'
            interface_name += 'Partial'
            assert component == 'core'
            component = 'modules'
            include_paths = interface_info.get(
                'dependencies_other_component_include_paths')
        else:
            header_template_filename = 'interface.h.tmpl'
            cpp_template_filename = 'interface.cc.tmpl'
            interface_context = v8_interface.interface_context

        template_context = interface_context(interface, definitions.interfaces)
        includes.update(
            interface_info.get('cpp_includes', {}).get(component, set()))
        if not interface.is_partial and not is_testing_target(full_path):
            template_context['header_includes'].add(
                self.info_provider.include_path_for_export)
            template_context[
                'exported'] = self.info_provider.specifier_for_export
        # Add the include for interface itself
        if IdlType(interface_name).is_typed_array:
            template_context['header_includes'].add(
                'core/typed_arrays/dom_typed_array.h')
        elif interface.is_callback:
            pass
        else:
            template_context['header_includes'].add(
                interface_info['include_path'])
        template_context['header_includes'].update(
            interface_info.get('additional_header_includes', []))
        header_path, cpp_path = self.output_paths(interface_name)
        this_include_header_path = self.normalize_this_header_path(header_path)
        template_context['this_include_header_path'] = this_include_header_path
        template_context['header_guard'] = to_header_guard(
            this_include_header_path)
        header_template = self.jinja_env.get_template(header_template_filename)
        cpp_template = self.jinja_env.get_template(cpp_template_filename)
        header_text, cpp_text = self.render_templates(include_paths,
                                                      header_template,
                                                      cpp_template,
                                                      template_context,
                                                      component)
        return (
            (header_path, header_text),
            (cpp_path, cpp_text),
        )
Example #5
0
 def _generate_container_code(self, union_type):
     includes.clear()
     union_type = union_type.resolve_typedefs(self.typedefs)
     header_template = self.jinja_env.get_template('union_container.h.tmpl')
     cpp_template = self.jinja_env.get_template('union_container.cc.tmpl')
     template_context = v8_union.container_context(union_type, self.info_provider)
     template_context['header_includes'].append(
         self.info_provider.include_path_for_export)
     template_context['exported'] = self.info_provider.specifier_for_export
     snake_base_name = to_snake_case(shorten_union_name(union_type))
     header_path = posixpath.join(self.output_dir, '%s.h' % snake_base_name)
     cpp_path = posixpath.join(self.output_dir, '%s.cc' % snake_base_name)
     this_include_header_path = self.normalize_this_header_path(header_path)
     template_context['this_include_header_path'] = this_include_header_path
     template_context['header_guard'] = to_header_guard(this_include_header_path)
     header_text, cpp_text = self.render_templates(
         [], header_template, cpp_template, template_context)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )