Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/scripts/code_generator_cpp.py |
| diff --git a/third_party/WebKit/Source/bindings/scripts/code_generator_cpp.py b/third_party/WebKit/Source/bindings/scripts/code_generator_cpp.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..632d3b6e70ef3385d0ef38498917cb16b9e99a30 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/bindings/scripts/code_generator_cpp.py |
| @@ -0,0 +1,64 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
|
bashi
2016/11/01 00:14:36
I think we need to add code_generator_cpp.py in So
dglazkov
2016/11/04 21:03:07
Done.
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +# pylint: disable=import-error,print-statement,relative-import |
| + |
| +"""Generates Blink CPP bindings. |
| + |
| +TODO(dglazkov): Write proper description here. |
|
haraken
2016/10/30 18:02:28
I want to write this in this CL :)
dglazkov
2016/11/04 21:03:07
Done.
|
| +""" |
| + |
| +import os |
| +import posixpath |
| + |
| +from code_generator import CodeGeneratorBase |
| +# TODO(dglazkov): Move TypedefResolver to code_generator.py |
| +from code_generator_v8 import TypedefResolver |
| +from v8_interface import interface_context |
| + |
| +MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' |
| + |
| + |
| +class CodeGeneratorCpp(CodeGeneratorBase): |
|
haraken
2016/10/30 18:02:28
Rename "Cpp" to "WebModule", "ServiceAPI" or somet
dglazkov
2016/11/04 21:03:07
Done.
|
| + def __init__(self, info_provider, cache_dir, output_dir): |
| + CodeGeneratorBase.__init__(self, MODULE_PYNAME, info_provider, |
| + cache_dir, output_dir) |
| + self.typedef_resolver = TypedefResolver(info_provider) |
| + |
| + def get_template(self): |
| + template_filename = 'cpp_interface.cpp.tmpl' |
| + return self.jinja_env.get_template(template_filename) |
| + |
| + # TODO(dglazkov): Move to CodeGeneratorBase. |
| + def output_paths(self, definition_name): |
| + header_path = posixpath.join(self.output_dir, |
| + 'Cpp%s.h' % definition_name) |
| + cpp_path = posixpath.join(self.output_dir, 'Cpp%s.cpp' % definition_name) |
| + return header_path, cpp_path |
| + |
| + def generate_code(self, definitions, definition_name): |
| + self.typedef_resolver.resolve(definitions, definition_name) |
| + header_path, cpp_path = self.output_paths(definition_name) |
| + |
| + template_context = {} |
| + # TODO(dglazkov): Implement dictionaries |
| + if definition_name in definitions.interfaces: |
| + interface = definitions.interfaces[definition_name] |
| + # TODO(dglazkov): Implement callback interfaces. |
| + # TODO(dglazkov): Implement partial interfaces. |
| + if not interface.is_callback and not interface.is_partial: |
| + template_context = interface_context( |
|
bashi
2016/11/01 00:14:36
I'm wondering what kind of code CodeGeneratorCpp w
dglazkov
2016/11/04 21:03:07
I wrote up a brief description of the class. Hope
|
| + interface, |
| + definitions.interfaces) |
| + template_context['code_generator'] = MODULE_PYNAME |
| + template_context['class_name'] = definition_name |
| + |
| + cpp_template = self.get_template() |
| + cpp_text = cpp_template.render(template_context) |
| + |
| + header_text = 'header' |
| + return ( |
| + (header_path, header_text), |
| + (cpp_path, cpp_text) |
| + ) |