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

Side by Side Diff: lib/dom/scripts/systemnative.py

Issue 10442125: Rework Element constructors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review and rebase Created 8 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
3 # for details. All rights reserved. Use of this source code is governed by a 3 # for details. All rights reserved. Use of this source code is governed by a
4 # BSD-style license that can be found in the LICENSE file. 4 # BSD-style license that can be found in the LICENSE file.
5 5
6 """This module provides shared functionality for the systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
11 from generator import * 11 from generator import *
12 from systembase import * 12 from systembase import *
13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared
14 from systemhtml import HtmlElementConstructorInfos
15 from systemhtml import EmitHtmlElementFactoryConstructors
14 16
15 class NativeImplementationSystem(System): 17 class NativeImplementationSystem(System):
16 18
17 def __init__(self, templates, database, html_database, html_renames, 19 def __init__(self, templates, database, html_database, html_renames,
18 emitters, output_dir): 20 emitters, output_dir):
19 super(NativeImplementationSystem, self).__init__( 21 super(NativeImplementationSystem, self).__init__(
20 templates, database, emitters, output_dir) 22 templates, database, emitters, output_dir)
21 23
22 self._html_renames = html_renames 24 self._html_renames = html_renames
23 self._dom_impl_files = [] 25 self._dom_impl_files = []
24 self._cpp_header_files = [] 26 self._cpp_header_files = []
25 self._cpp_impl_files = [] 27 self._cpp_impl_files = []
26 self._html_system = HtmlSystemShared(html_database) 28 self._html_system = HtmlSystemShared(html_database)
29 self._factory_provider_emitters = {}
27 30
28 def InterfaceGenerator(self, 31 def InterfaceGenerator(self,
29 interface, 32 interface,
30 common_prefix, 33 common_prefix,
31 super_interface_name, 34 super_interface_name,
32 source_filter): 35 source_filter):
33 interface_name = interface.id 36 interface_name = interface.id
34 37
35 if IsPureInterface(interface_name): 38 if IsPureInterface(interface_name):
36 return None 39 return None
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 def _FilePathForDartFactoryProviderImplementation(self, interface_name): 172 def _FilePathForDartFactoryProviderImplementation(self, interface_name):
170 return os.path.join(self._output_dir, 'dart', 173 return os.path.join(self._output_dir, 'dart',
171 '%sFactoryProviderImplementation.dart' % interface_name) 174 '%sFactoryProviderImplementation.dart' % interface_name)
172 175
173 def _FilePathForCppHeader(self, interface_name): 176 def _FilePathForCppHeader(self, interface_name):
174 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name) 177 return os.path.join(self._output_dir, 'cpp', 'Dart%s.h' % interface_name)
175 178
176 def _FilePathForCppImplementation(self, interface_name): 179 def _FilePathForCppImplementation(self, interface_name):
177 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name) 180 return os.path.join(self._output_dir, 'cpp', 'Dart%s.cpp' % interface_name)
178 181
182 def _EmitterForFactoryProviderBody(self, name):
183 if name not in self._factory_provider_emitters:
184 file_name = self._FilePathForDartFactoryProviderImplementation(name)
185 self._dom_impl_files.append(file_name)
186 template = self._templates.Load('factoryprovider_%s.darttemplate' % name)
187 file_emitter = self._emitters.FileEmitter(file_name)
188 self._factory_provider_emitters[name] = file_emitter.Emit(template)
189 return self._factory_provider_emitters[name]
190
179 def DartImplementationFiles(self): 191 def DartImplementationFiles(self):
180 return self._dom_impl_files 192 return self._dom_impl_files
181 193
182 194
183 class NativeImplementationGenerator(object): 195 class NativeImplementationGenerator(object):
184 """Generates Dart implementation for one DOM IDL interface.""" 196 """Generates Dart implementation for one DOM IDL interface."""
185 197
186 def __init__(self, system, interface, 198 def __init__(self, system, interface,
187 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter, 199 dart_impl_emitter, cpp_header_emitter, cpp_impl_emitter,
188 base_members, templates): 200 base_members, templates):
(...skipping 27 matching lines...) Expand all
216 self._members_emitter = emitter.Emitter() 228 self._members_emitter = emitter.Emitter()
217 self._cpp_declarations_emitter = emitter.Emitter() 229 self._cpp_declarations_emitter = emitter.Emitter()
218 self._cpp_impl_includes = set() 230 self._cpp_impl_includes = set()
219 self._cpp_definitions_emitter = emitter.Emitter() 231 self._cpp_definitions_emitter = emitter.Emitter()
220 self._cpp_resolver_emitter = emitter.Emitter() 232 self._cpp_resolver_emitter = emitter.Emitter()
221 233
222 self._GenerateConstructors() 234 self._GenerateConstructors()
223 self._GenerateEvents() 235 self._GenerateEvents()
224 236
225 def _GenerateConstructors(self): 237 def _GenerateConstructors(self):
238 html_interface_name = self._HTMLInterfaceName(self._interface.id)
239 infos = HtmlElementConstructorInfos(html_interface_name)
240 if infos:
241 self._EmitHtmlElementFactoryConstructors(infos, html_interface_name)
242
226 if not self._IsConstructable(): 243 if not self._IsConstructable():
227 return 244 return
228 245
229 # TODO(antonm): currently we don't have information about number of argument s expected by 246 # TODO(antonm): currently we don't have information about number of argument s expected by
230 # the constructor, so name only dispatch. 247 # the constructor, so name only dispatch.
231 self._cpp_resolver_emitter.Emit( 248 self._cpp_resolver_emitter.Emit(
232 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' 249 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
233 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', 250 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
234 INTERFACE_NAME=self._interface.id) 251 INTERFACE_NAME=self._interface.id)
235 252
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 arguments.append(argument_expression) 300 arguments.append(argument_expression)
284 301
285 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 302 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
286 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 303 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
287 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 304 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
288 self._GenerateNativeCallback(callback_name='constructorCallback', 305 self._GenerateNativeCallback(callback_name='constructorCallback',
289 parameter_definitions=parameter_definitions_emitter.Fragments(), 306 parameter_definitions=parameter_definitions_emitter.Fragments(),
290 needs_receiver=False, invocation=invocation, 307 needs_receiver=False, invocation=invocation,
291 raises_exceptions=raises_exceptions) 308 raises_exceptions=raises_exceptions)
292 309
310 def _EmitHtmlElementFactoryConstructors(self, infos, html_interface_name):
311 EmitHtmlElementFactoryConstructors(
312 self._system._EmitterForFactoryProviderBody(
313 infos[0].factory_provider_name),
314 infos,
315 html_interface_name,
316 html_interface_name)
317
293 def _GenerateEvents(self): 318 def _GenerateEvents(self):
294 if self._interface.id == 'DocumentFragment': 319 if self._interface.id == 'DocumentFragment':
295 # Interface DocumentFragment extends Element in dart:html but this fact 320 # Interface DocumentFragment extends Element in dart:html but this fact
296 # is not reflected in idls. 321 # is not reflected in idls.
297 self._EmitEventGetter('_ElementEventsImpl') 322 self._EmitEventGetter('_ElementEventsImpl')
298 return 323 return
299 324
300 events_attributes = [attr for attr in self._interface.attributes 325 events_attributes = [attr for attr in self._interface.attributes
301 if attr.type.id == 'EventListener'] 326 if attr.type.id == 'EventListener']
302 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: 327 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 for parent in interface.parents: 1194 for parent in interface.parents:
1170 parent_name = parent.type.id 1195 parent_name = parent.type.id
1171 if not database.HasInterface(parent.type.id): 1196 if not database.HasInterface(parent.type.id):
1172 continue 1197 continue
1173 parent_interface = database.GetInterface(parent.type.id) 1198 parent_interface = database.GetInterface(parent.type.id)
1174 if callback(parent_interface): 1199 if callback(parent_interface):
1175 return parent_interface 1200 return parent_interface
1176 parent_interface = _FindParent(parent_interface, database, callback) 1201 parent_interface = _FindParent(parent_interface, database, callback)
1177 if parent_interface: 1202 if parent_interface:
1178 return parent_interface 1203 return parent_interface
OLDNEW
« no previous file with comments | « lib/dom/scripts/systemhtml.py ('k') | lib/dom/templates/html/dartium/factoryprovider__Elements.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698