Пример #1
0
    def __init__(self, definitions, interface_name, output_directory, relative_dir_posix, idl_directories, verbose=False):
        self.idl_definitions = definitions
        self.interface_name = interface_name
        self.idl_directories = idl_directories
        self.output_directory = output_directory
        self.verbose = verbose
        # FIXME: remove definitions check when remove write_dummy_header_and_cpp
        if not definitions:
            return
        try:
            self.interface = definitions.interfaces[interface_name]
        except KeyError:
            raise Exception('%s not in IDL definitions' % interface_name)
        if self.interface.is_callback:
            header_template_filename = 'callback_interface.h'
            cpp_template_filename = 'callback_interface.cpp'
            self.generate_contents = v8_callback_interface.generate_callback_interface
        else:
            header_template_filename = 'interface.h'
            cpp_template_filename = 'interface.cpp'
            self.generate_contents = v8_interface.generate_interface
        # FIXME: update to Jinja 2.7 and use:
        # keep_trailing_newline=True,  # newline-terminate generated files
        # lstrip_blocks=True,  # so can indent control flow tags
        jinja_env = jinja2.Environment(
            loader=jinja2.FileSystemLoader(templates_dir),
            trim_blocks=True)
        self.header_template = jinja_env.get_template(header_template_filename)
        self.cpp_template = jinja_env.get_template(cpp_template_filename)

        class_name = cpp_class_name(self.interface)
        self.include_for_cpp_class = posixpath.join(relative_dir_posix, class_name + '.h')
Пример #2
0
def generate_interface(interface):
    header_includes = INTERFACE_H_INCLUDES
    cpp_includes = INTERFACE_CPP_INCLUDES

    template_contents = {
        'interface_name': interface.name,
        'cpp_class_name': cpp_class_name(interface),
        'v8_class_name': v8_class_name(interface),
        'constants': [generate_constant(constant) for constant in interface.constants],
        'do_not_check_constants': 'DoNotCheckConstants' in interface.extended_attributes,
        # Includes are modified in-place after generating members
        'header_includes': header_includes,
        'cpp_includes': cpp_includes,
    }
    attributes_contents, attributes_includes = v8_attributes.generate_attributes(interface)
    template_contents.update(attributes_contents)
    cpp_includes |= attributes_includes
    return template_contents