Exemple #1
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.cpp.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)
     template_context['header_includes'] = normalize_and_sort_includes(
         template_context['header_includes'])
     template_context['code_generator'] = MODULE_PYNAME
     header_text = render_template(header_template, template_context)
     cpp_text = render_template(cpp_template, template_context)
     header_path = posixpath.join(self.output_dir,
                                  '%s.h' % callback_function.name)
     cpp_path = posixpath.join(self.output_dir,
                               '%s.cpp' % callback_function.name)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
Exemple #2
0
def generate_origin_trial_features(info_provider, options, idl_filenames):
    reader = IdlReader(info_provider.interfaces_info, options.cache_directory)
    jinja_env = initialize_jinja_env(options.cache_directory)

    # Extract the bidirectional mapping of conditional features <-> interfaces
    # from the global info provider and the supplied list of IDL files.
    feature_info = origin_trial_features_info(info_provider, reader,
                                              idl_filenames,
                                              options.target_component)

    # Convert that mapping into the context required for the Jinja2 templates.
    template_context = origin_trial_features_context(MODULE_PYNAME,
                                                     feature_info)

    file_basename = 'origin_trial_features_for_%s' % options.target_component

    # Generate and write out the header file
    header_text = render_template(
        jinja_env.get_template(file_basename + '.h.tmpl'), template_context)
    header_path = posixpath.join(options.output_directory,
                                 file_basename + '.h')
    write_file(header_text, header_path)

    # Generate and write out the implementation file
    cpp_text = render_template(
        jinja_env.get_template(file_basename + '.cc.tmpl'), template_context)
    cpp_path = posixpath.join(options.output_directory, file_basename + '.cc')
    write_file(cpp_text, cpp_path)
def generate_conditional_features(info_provider, options, idl_filenames):
    reader = IdlReader(info_provider.interfaces_info, options.cache_directory)
    jinja_env = initialize_jinja_env(options.cache_directory)

    # Extract the bidirectional mapping of conditional features <-> interfaces
    # from the global info provider and the supplied list of IDL files.
    feature_info = conditional_features_info(info_provider, reader,
                                             idl_filenames,
                                             options.target_component.lower())

    # Convert that mapping into the context required for the Jinja2 templates.
    template_context = conditional_features_context(MODULE_PYNAME,
                                                    feature_info)

    # Generate and write out the header file
    header_text = render_template(
        jinja_env.get_template("ConditionalFeaturesFor%s.h.tmpl" %
                               options.target_component.title()),
        template_context)
    header_path = posixpath.join(
        options.output_directory,
        "ConditionalFeaturesFor%s.h" % options.target_component.title())
    write_file(header_text, header_path)

    # Generate and write out the implementation file
    cpp_text = render_template(
        jinja_env.get_template("ConditionalFeaturesFor%s.cpp.tmpl" %
                               options.target_component.title()),
        template_context)
    cpp_path = posixpath.join(
        options.output_directory,
        "ConditionalFeaturesFor%s.cpp" % options.target_component.title())
    write_file(cpp_text, cpp_path)
    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.cpp.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))

        template_context['header_includes'] = normalize_and_sort_includes(
            template_context['header_includes'])
        template_context['cpp_includes'] = normalize_and_sort_includes(
            template_context['cpp_includes'])
        template_context['code_generator'] = MODULE_PYNAME
        header_text = render_template(header_template, template_context)
        cpp_text = render_template(cpp_template, template_context)
        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)
        return (
            (header_path, header_text),
            (cpp_path, cpp_text),
        )
 def _generate_container_code(self, union_type):
     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.cpp.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['header_includes'] = normalize_and_sort_includes(
         template_context['header_includes'],
         self.snake_case_generated_files)
     template_context['cpp_includes'] = normalize_and_sort_includes(
         template_context['cpp_includes'], self.snake_case_generated_files)
     template_context['code_generator'] = self.generator_name
     template_context['exported'] = self.info_provider.specifier_for_export
     snake_base_name = to_snake_case(shorten_union_name(union_type))
     template_context['this_include_header_name'] = snake_base_name
     header_text = render_template(header_template, template_context)
     cpp_text = render_template(cpp_template, template_context)
     header_path = posixpath.join(self.output_dir, '%s.h' % snake_base_name)
     cpp_path = posixpath.join(self.output_dir, '%s.cc' % snake_base_name)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
def generate_conditional_features(info_provider, options, idl_filenames):
    reader = IdlReader(info_provider.interfaces_info, options.cache_directory)
    jinja_env = initialize_jinja_env(options.cache_directory)

    # Extract the bidirectional mapping of conditional features <-> interfaces
    # from the global info provider and the supplied list of IDL files.
    feature_info = conditional_features_info(info_provider,
                                             reader, idl_filenames,
                                             options.target_component.lower())

    # Convert that mapping into the context required for the Jinja2 templates.
    template_context = conditional_features_context(
        MODULE_PYNAME, feature_info)

    # Generate and write out the header file
    header_text = render_template(jinja_env.get_template(
        "ConditionalFeaturesFor%s.h.tmpl" % options.target_component.title()), template_context)
    header_path = posixpath.join(options.output_directory,
                                 "ConditionalFeaturesFor%s.h" % options.target_component.title())
    write_file(header_text, header_path)

    # Generate and write out the implementation file
    cpp_text = render_template(jinja_env.get_template(
        "ConditionalFeaturesFor%s.cpp.tmpl" % options.target_component.title()), template_context)
    cpp_path = posixpath.join(options.output_directory,
                              "ConditionalFeaturesFor%s.cpp" % options.target_component.title())
    write_file(cpp_text, cpp_path)
Exemple #7
0
 def generate_file(self, template_context, file_extension):
     template = self.get_template(file_extension)
     path = posixpath.join(
         self.output_dir, '%s.%s' %
         (template_context['class_name']['snake_case'], file_extension))
     text = render_template(template, template_context)
     return (path, text)
Exemple #8
0
    def generate_interface_code(self, interface):
        # TODO(dglazkov): Implement callback interfaces.
        # TODO(dglazkov): Make sure partial interfaces are handled.
        if interface.is_callback or interface.is_partial:
            raise ValueError(
                'Partial or callback interfaces are not supported')

        template_context = interface_context(interface)

        cpp_template = self.get_template('cpp')
        header_template = self.get_template('h')
        cpp_text = render_template(cpp_template, template_context)
        header_text = render_template(header_template, template_context)
        header_path, cpp_path = self.output_paths(interface.name)

        return ((header_path, header_text), (cpp_path, cpp_text))
 def generate_file(self, template_context, file_extension):
     template = self.get_template(file_extension)
     path = posixpath.join(
         self.output_dir,
         '%s.%s' % (template_context['class_name']['snake_case'],
                    file_extension))
     text = render_template(template, template_context)
     return (path, text)
Exemple #10
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.cpp.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)
     template_context['header_includes'] = normalize_and_sort_includes(
         template_context['header_includes'])
     template_context['code_generator'] = MODULE_PYNAME
     header_text = render_template(header_template, template_context)
     cpp_text = render_template(cpp_template, template_context)
     header_path = posixpath.join(self.output_dir, '%s.h' % callback_function.name)
     cpp_path = posixpath.join(self.output_dir, '%s.cpp' % callback_function.name)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
Exemple #11
0
 def _generate_container_code(self, union_type):
     header_template = self.jinja_env.get_template('union_container.h.tmpl')
     cpp_template = self.jinja_env.get_template('union_container.cpp.tmpl')
     template_context = v8_union.container_context(
         union_type, self.info_provider.interfaces_info)
     template_context['header_includes'].append(
         self.info_provider.include_path_for_export)
     template_context['header_includes'] = normalize_and_sort_includes(
         template_context['header_includes'])
     template_context['code_generator'] = self.generator_name
     template_context['exported'] = self.info_provider.specifier_for_export
     name = shorten_union_name(union_type)
     template_context['this_include_header_name'] = name
     header_text = render_template(header_template, template_context)
     cpp_text = render_template(cpp_template, template_context)
     header_path = posixpath.join(self.output_dir, '%s.h' % name)
     cpp_path = posixpath.join(self.output_dir, '%s.cpp' % name)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )
Exemple #12
0
 def _generate_container_code(self, union_type):
     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.cpp.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['header_includes'] = normalize_and_sort_includes(
         template_context['header_includes'])
     template_context['code_generator'] = self.generator_name
     template_context['exported'] = self.info_provider.specifier_for_export
     name = shorten_union_name(union_type)
     template_context['this_include_header_name'] = name
     header_text = render_template(header_template, template_context)
     cpp_text = render_template(cpp_template, template_context)
     header_path = posixpath.join(self.output_dir, '%s.h' % name)
     cpp_path = posixpath.join(self.output_dir, '%s.cpp' % name)
     return (
         (header_path, header_text),
         (cpp_path, cpp_text),
     )