Chromium Code Reviews| Index: third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py |
| diff --git a/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py b/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py |
| index 92ad2b685d94ce61dd043286b2f633b12bc91714..53ed4dc7956e66145b84a59182ffb0370f606120 100644 |
| --- a/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py |
| +++ b/third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py |
| @@ -25,21 +25,71 @@ 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' |
| WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI' |
| +def includes_for_type(idl_type): |
|
haraken
2016/11/12 08:01:37
Would you help me understand why you need to imple
dglazkov
2016/11/13 00:11:45
Sure! `v8_types.includes_for_type` returns very sp
|
| + # TODO(dglazkov): Make this actually work. |
| + name = idl_type.preprocessed_type.base_type |
| + return set([name]) |
| + |
| + |
| +def interface_context(idl_interface): |
| + attributes = [] |
| + methods = [] |
| + includes = set() |
| + for idl_attribute in idl_interface.attributes: |
| + attributes.append(Attribute.create(idl_attribute)) |
| + includes.update(includes_for_type(idl_attribute.idl_type)) |
| + for idl_operation in idl_interface.operations: |
| + if idl_operation.name: |
| + methods.append(Method.create(idl_operation)) |
|
haraken
2016/11/12 08:01:37
bashi@, yukishiino@: Is this an expected way to bu
dglazkov
2016/11/13 00:11:45
Factories seem like a good thing. We use them else
bashi
2016/11/13 23:33:58
We haven't used factories but I'm fine with using
haraken
2016/11/14 01:41:41
Yeah, other places are using attribute_context, me
|
| + return { |
| + 'code_generator': MODULE_PYNAME, |
| + 'class_name': idl_interface.name, |
| + 'cpp_includes': includes, |
| + 'attributes': attributes, |
| + 'methods': methods, |
| + } |
| + |
| + |
| +class Attribute(object): |
|
haraken
2016/11/12 08:01:37
object is unused
dglazkov
2016/11/13 00:11:45
What do you mean? The Attribute.create returns an
|
| + def __init__(self, name, return_type): |
| + self.name = name |
| + self.return_type = return_type |
| + |
| + @staticmethod |
| + def create(idl_attribute): |
| + name = idl_attribute.name |
| + return_type = idl_attribute.idl_type.preprocessed_type.base_type |
| + return Attribute(name, return_type) |
| + |
| + |
| +# TODO(dglazkov): Attribute and Method are both created off |
| +# idl_definitions.TypedObject sub-types, so maybe use inheritance? |
| +class Method(object): |
|
haraken
2016/11/12 08:01:37
Ditto.
dglazkov
2016/11/13 00:11:45
Same here.
|
| + def __init__(self, name, return_type): |
| + self.name = name |
| + self.return_type = return_type |
| + |
| + @staticmethod |
| + def create(idl_operation): |
| + name = idl_operation.name |
| + return_type = idl_operation.idl_type.preprocessed_type.base_type |
| + return Method(name, return_type) |
| + |
| + |
| class CodeGeneratorWebModule(CodeGeneratorBase): |
| 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 = 'web_module_interface.cpp.tmpl' |
| + def get_template(self, file_extension): |
| + template_filename = 'web_module_interface.%s.tmpl' % file_extension |
| return self.jinja_env.get_template(template_filename) |
| # TODO(dglazkov): Move to CodeGeneratorBase. |
| @@ -50,6 +100,25 @@ class CodeGeneratorWebModule(CodeGeneratorBase): |
| 'Web%s.cpp' % definition_name) |
| return header_path, cpp_path |
| + def generate_interface_code(self, interface): |
| + # TODO(dglazkov): Implement callback interfaces. |
| + # TODO(dglazkov): Make sure partial interfaces are handled. |
| + if interface.is_callback and interface.is_partial: |
|
haraken
2016/11/12 08:01:37
and => or ?
dglazkov
2016/11/13 00:11:45
Oops. Thanks! Fixed.
|
| + return None |
|
haraken
2016/11/12 08:01:37
Or you can raise an exception when you hit somethi
dglazkov
2016/11/13 00:11:45
That's a great idea! Fixed.
|
| + |
| + template_context = interface_context(interface) |
| + |
| + cpp_template = self.get_template('cpp') |
| + h_template = self.get_template('h') |
|
haraken
2016/11/12 08:01:37
header_template
dglazkov
2016/11/13 00:11:45
Fixed.
|
| + cpp_text = cpp_template.render(template_context) |
| + h_text = h_template.render(template_context) |
|
haraken
2016/11/12 08:01:37
header_text
dglazkov
2016/11/13 00:11:45
Fixed.
|
| + header_path, cpp_path = self.output_paths(interface.name) |
| + |
| + return ( |
| + (header_path, h_text), |
| + (cpp_path, cpp_text) |
| + ) |
| + |
| def generate_code(self, definitions, definition_name): |
| self.typedef_resolver.resolve(definitions, definition_name) |
| header_path, cpp_path = self.output_paths(definition_name) |
| @@ -63,21 +132,4 @@ class CodeGeneratorWebModule(CodeGeneratorBase): |
| if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: |
| return None |
| - # TODO(dglazkov): Implement callback interfaces. |
| - # TODO(dglazkov): Implement partial interfaces. |
| - if interface.is_callback and interface.is_partial: |
| - return None |
| - |
| - template_context = interface_context(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) |
| - ) |
| + return self.generate_interface_code(interface) |