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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/code_generator_web_module.py

Issue 2573013002: Add inheritance support to Webmodules template. (Closed)
Patch Set: Whoops, forgot 'public'. Created 4 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/code_generator_web_module_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # pylint: disable=import-error,print-statement,relative-import 5 # pylint: disable=import-error,print-statement,relative-import
6 6
7 """Generates Blink Web Module bindings. 7 """Generates Blink Web Module bindings.
8 8
9 The Blink Web Module bindings provide a stable, IDL-generated interface for the 9 The Blink Web Module bindings provide a stable, IDL-generated interface for the
10 Web Modules. 10 Web Modules.
(...skipping 13 matching lines...) Expand all
24 24
25 from code_generator import CodeGeneratorBase 25 from code_generator import CodeGeneratorBase
26 # TODO(dglazkov): Move TypedefResolver to code_generator.py 26 # TODO(dglazkov): Move TypedefResolver to code_generator.py
27 from code_generator_v8 import TypedefResolver 27 from code_generator_v8 import TypedefResolver
28 28
29 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py' 29 MODULE_PYNAME = os.path.splitext(os.path.basename(__file__))[0] + '.py'
30 30
31 WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI' 31 WEB_MODULE_IDL_ATTRIBUTE = 'WebModuleAPI'
32 32
33 33
34 def includes_for_type(idl_type):
35 # TODO(dglazkov): Make this actually work.
36 name = idl_type.preprocessed_type.base_type
37 return set([name])
38
39
40 def interface_context(idl_interface): 34 def interface_context(idl_interface):
41 builder = InterfaceContextBuilder(MODULE_PYNAME) 35 builder = InterfaceContextBuilder(MODULE_PYNAME)
42 builder.set_class_name(idl_interface.name) 36 builder.set_class_name(idl_interface.name)
37 builder.set_inheritance(idl_interface.parent)
43 38
44 for idl_attribute in idl_interface.attributes: 39 for idl_attribute in idl_interface.attributes:
45 builder.add_attribute(idl_attribute) 40 builder.add_attribute(idl_attribute)
46 41
47 for idl_operation in idl_interface.operations: 42 for idl_operation in idl_interface.operations:
48 builder.add_operation(idl_operation) 43 builder.add_operation(idl_operation)
49 44
50 return builder.build() 45 return builder.build()
51 46
52 47
53 class InterfaceContextBuilder(object): 48 class InterfaceContextBuilder(object):
54 def __init__(self, code_generator): 49 def __init__(self, code_generator):
55 self.result = {'code_generator': code_generator} 50 self.result = {'code_generator': code_generator}
56 51
57 def set_class_name(self, class_name): 52 def set_class_name(self, class_name):
58 self.result['class_name'] = class_name 53 self.result['class_name'] = class_name
59 54
55 def set_inheritance(self, base_interface):
56 if base_interface is None:
57 return
58 self.result['inherits_expression'] = ' : public %s' % base_interface
59 self._ensure_set('cpp_includes').update(
60 self._includes_for_type(base_interface))
61
60 def _ensure_set(self, name): 62 def _ensure_set(self, name):
61 return self.result.setdefault(name, set()) 63 return self.result.setdefault(name, set())
62 64
63 def _ensure_list(self, name): 65 def _ensure_list(self, name):
64 return self.result.setdefault(name, []) 66 return self.result.setdefault(name, [])
65 67
68 def _includes_for_type(self, idl_type):
69 # TODO(dglazkov): Make this actually work.
70 name = idl_type
71 return set([name])
72
73 def _get_return_type(self, idl_definition):
74 return idl_definition.idl_type.preprocessed_type.base_type
75
66 def add_attribute(self, idl_attribute): 76 def add_attribute(self, idl_attribute):
67 self._ensure_list('attributes').append( 77 self._ensure_list('attributes').append(
68 self.create_attribute(idl_attribute)) 78 self.create_attribute(idl_attribute))
69 self._ensure_set('cpp_includes').update( 79 self._ensure_set('cpp_includes').update(
70 includes_for_type(idl_attribute.idl_type)) 80 self._includes_for_type(self._get_return_type(idl_attribute)))
71 81
72 def add_operation(self, idl_operation): 82 def add_operation(self, idl_operation):
73 if idl_operation.name: 83 if not idl_operation.name:
74 self._ensure_list('methods').append( 84 return
75 self.create_method(idl_operation)) 85 self._ensure_list('methods').append(
76 self._ensure_set('cpp_includes').update( 86 self.create_method(idl_operation))
77 includes_for_type(idl_operation.idl_type)) 87 self._ensure_set('cpp_includes').update(
88 self._includes_for_type(self._get_return_type(idl_operation)))
78 89
79 def create_method(self, idl_operation): 90 def create_method(self, idl_operation):
80 name = idl_operation.name 91 name = idl_operation.name
81 return_type = idl_operation.idl_type.preprocessed_type.base_type 92 return_type = idl_operation.idl_type.preprocessed_type.base_type
82 return { 93 return {
83 'name': name, 94 'name': name,
84 'return_type': return_type 95 'return_type': return_type
85 } 96 }
86 97
87 def create_attribute(self, idl_attribute): 98 def create_attribute(self, idl_attribute):
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 template_context = {} 151 template_context = {}
141 # TODO(dglazkov): Implement dictionaries 152 # TODO(dglazkov): Implement dictionaries
142 if definition_name not in definitions.interfaces: 153 if definition_name not in definitions.interfaces:
143 return None 154 return None
144 155
145 interface = definitions.interfaces[definition_name] 156 interface = definitions.interfaces[definition_name]
146 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes: 157 if WEB_MODULE_IDL_ATTRIBUTE not in interface.extended_attributes:
147 return None 158 return None
148 159
149 return self.generate_interface_code(interface) 160 return self.generate_interface_code(interface)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/code_generator_web_module_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698