Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Unified Diff: third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py

Issue 2495033003: Stop using v8_interface.interface_context in Web modules bindings. (Closed)
Patch Set: Removed the comment. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/templates/web_module_interface.cpp.tmpl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0e44aeacb8778fd8614d51b5451d609949f90de0 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,69 @@ 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):
+ # 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))
+ return {
+ 'code_generator': MODULE_PYNAME,
+ 'class_name': idl_interface.name,
+ 'cpp_includes': includes,
+ 'attributes': attributes,
+ 'methods': methods,
+ }
+
+
+class Attribute(object):
+ 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)
+
+
+class Method(object):
+ 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 +98,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 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 = cpp_template.render(template_context)
+ header_text = header_template.render(template_context)
+ header_path, cpp_path = self.output_paths(interface.name)
+
+ return (
+ (header_path, header_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 +130,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)
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/templates/web_module_interface.cpp.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698