Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 * | |
|
sra1
2012/05/14 17:29:15
Please make new imports more specific.
podivilov
2012/05/15 10:24:26
Done.
| |
| 13 | 14 |
| 14 class NativeImplementationSystem(System): | 15 class NativeImplementationSystem(System): |
| 15 | 16 |
| 16 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): | 17 def __init__(self, templates, database, html_renames, emitters, auxiliary_dir, |
| 18 output_dir): | |
| 17 super(NativeImplementationSystem, self).__init__( | 19 super(NativeImplementationSystem, self).__init__( |
| 18 templates, database, emitters, output_dir) | 20 templates, database, emitters, output_dir) |
| 19 | 21 |
| 22 self._html_renames = html_renames | |
| 20 self._auxiliary_dir = auxiliary_dir | 23 self._auxiliary_dir = auxiliary_dir |
| 21 self._dom_public_files = [] | 24 self._dom_public_files = [] |
| 22 self._dom_impl_files = [] | 25 self._dom_impl_files = [] |
| 23 self._cpp_header_files = [] | 26 self._cpp_header_files = [] |
| 24 self._cpp_impl_files = [] | 27 self._cpp_impl_files = [] |
| 25 | 28 |
| 26 def InterfaceGenerator(self, | 29 def InterfaceGenerator(self, |
| 27 interface, | 30 interface, |
| 28 common_prefix, | 31 common_prefix, |
| 29 super_interface_name, | 32 super_interface_name, |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 def StartInterface(self): | 241 def StartInterface(self): |
| 239 self._class_name = self._ImplClassName(self._interface.id) | 242 self._class_name = self._ImplClassName(self._interface.id) |
| 240 self._interface_type_info = GetIDLTypeInfo(self._interface.id) | 243 self._interface_type_info = GetIDLTypeInfo(self._interface.id) |
| 241 self._members_emitter = emitter.Emitter() | 244 self._members_emitter = emitter.Emitter() |
| 242 self._cpp_declarations_emitter = emitter.Emitter() | 245 self._cpp_declarations_emitter = emitter.Emitter() |
| 243 self._cpp_impl_includes = set() | 246 self._cpp_impl_includes = set() |
| 244 self._cpp_definitions_emitter = emitter.Emitter() | 247 self._cpp_definitions_emitter = emitter.Emitter() |
| 245 self._cpp_resolver_emitter = emitter.Emitter() | 248 self._cpp_resolver_emitter = emitter.Emitter() |
| 246 | 249 |
| 247 self._GenerateConstructors() | 250 self._GenerateConstructors() |
| 251 self._GenerateEvents() | |
| 248 | 252 |
| 249 def _GenerateConstructors(self): | 253 def _GenerateConstructors(self): |
| 250 if not self._IsConstructable(): | 254 if not self._IsConstructable(): |
| 251 return | 255 return |
| 252 | 256 |
| 253 # TODO(antonm): currently we don't have information about number of argument s expected by | 257 # TODO(antonm): currently we don't have information about number of argument s expected by |
| 254 # the constructor, so name only dispatch. | 258 # the constructor, so name only dispatch. |
| 255 self._cpp_resolver_emitter.Emit( | 259 self._cpp_resolver_emitter.Emit( |
| 256 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' | 260 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' |
| 257 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', | 261 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 arguments.append(argument_expression) | 311 arguments.append(argument_expression) |
| 308 | 312 |
| 309 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) | 313 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) |
| 310 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, | 314 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
| 311 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) | 315 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) |
| 312 self._GenerateNativeCallback(callback_name='constructorCallback', | 316 self._GenerateNativeCallback(callback_name='constructorCallback', |
| 313 parameter_definitions=parameter_definitions_emitter.Fragments(), | 317 parameter_definitions=parameter_definitions_emitter.Fragments(), |
| 314 needs_receiver=False, invocation=invocation, | 318 needs_receiver=False, invocation=invocation, |
| 315 raises_exceptions=raises_exceptions) | 319 raises_exceptions=raises_exceptions) |
| 316 | 320 |
| 321 def _GenerateEvents(self): | |
| 322 events_attributes = [attr for attr in self._interface.attributes | |
| 323 if attr.type.id == 'EventListener'] | |
| 324 | |
| 325 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: | |
| 326 return | |
| 327 | |
| 328 is_root = not _HasEventTargetParent(self._system._database, self._interface) | |
| 329 if is_root: | |
| 330 self._members_emitter.Emit(' EventsImplementation _on;\n') | |
| 331 | |
| 332 if not events_attributes: | |
| 333 if is_root: | |
| 334 self._EmitEventGetter('EventsImplementation') | |
| 335 return | |
| 336 | |
| 337 events_class = '%sEventsImplementation' % self._interface.id | |
| 338 self._EmitEventGetter(events_class) | |
| 339 | |
| 340 parent = _ParentWithEventAttributes(self._system._database, self._interface) or '' | |
| 341 html_inteface = self._system._html_renames.get(self._interface.id, self._int erface.id) | |
| 342 events_members = self._dart_impl_emitter.Emit( | |
| 343 '\n' | |
| 344 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n' | |
| 345 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n' | |
| 346 '$!MEMBERS\n' | |
| 347 '}\n', | |
| 348 EVENTS_CLASS=events_class, | |
| 349 PARENT_EVENTS_CLASS='%sEventsImplementation' % parent, | |
| 350 EVENTS_INTERFACE='html.%sEvents' % html_inteface) | |
| 351 | |
| 352 events_attributes = DomToHtmlEvents(self._interface.id, events_attributes) | |
| 353 for event_name in events_attributes: | |
| 354 events_members.Emit( | |
| 355 " EventListenerList get $HTML_NAME() => _get('$DOM_NAME');\n", | |
| 356 HTML_NAME=DomToHtmlEvent(event_name), | |
| 357 DOM_NAME=event_name) | |
| 358 | |
| 359 def _EmitEventGetter(self, events_class): | |
| 360 self._members_emitter.Emit( | |
| 361 '\n' | |
| 362 ' $EVENTS_CLASS get on() {\n' | |
| 363 ' if (_on == null) _on = new $EVENTS_CLASS(this);\n' | |
| 364 ' return _on;\n' | |
| 365 ' }\n', | |
| 366 EVENTS_CLASS=events_class) | |
| 367 | |
| 317 def _ImplClassName(self, interface_name): | 368 def _ImplClassName(self, interface_name): |
| 318 return interface_name + 'Implementation' | 369 return interface_name + 'Implementation' |
| 319 | 370 |
| 320 def _BaseClassName(self): | 371 def _BaseClassName(self): |
| 321 if not self._interface.parents: | 372 if not self._interface.parents: |
| 322 return 'DOMWrapperBase' | 373 return 'DOMWrapperBase' |
| 323 | 374 |
| 324 supertype = self._interface.parents[0].type.id | 375 supertype = self._interface.parents[0].type.id |
| 325 | 376 |
| 326 # FIXME: We're currently injecting List<..> and EventTarget as | 377 # FIXME: We're currently injecting List<..> and EventTarget as |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1143 def _InstanceOfNode(database, interface): | 1194 def _InstanceOfNode(database, interface): |
| 1144 if interface.id == 'Node': | 1195 if interface.id == 'Node': |
| 1145 return True | 1196 return True |
| 1146 for parent in interface.parents: | 1197 for parent in interface.parents: |
| 1147 if not database.HasInterface(parent.type.id): | 1198 if not database.HasInterface(parent.type.id): |
| 1148 continue | 1199 continue |
| 1149 parent_interface = database.GetInterface(parent.type.id) | 1200 parent_interface = database.GetInterface(parent.type.id) |
| 1150 if _InstanceOfNode(database, parent_interface): | 1201 if _InstanceOfNode(database, parent_interface): |
| 1151 return True | 1202 return True |
| 1152 return False | 1203 return False |
| 1204 | |
| 1205 def _HasEventTargetParent(database, interface): | |
| 1206 for parent in interface.parents: | |
| 1207 parent_name = parent.type.id | |
| 1208 if parent_name == 'EventTarget' or not database.HasInterface(parent_name): | |
| 1209 continue | |
| 1210 parent_interface = database.GetInterface(parent.type.id) | |
| 1211 if ('EventTarget' in parent_interface.ext_attrs or | |
| 1212 _HasEventTargetParent(database, parent_interface)): | |
| 1213 return True | |
| 1214 return False | |
| 1215 | |
| 1216 def _ParentWithEventAttributes(database, interface): | |
| 1217 for parent in interface.parents: | |
| 1218 parent_name = parent.type.id | |
| 1219 if parent_name == 'EventTarget' or not database.HasInterface(parent_name): | |
| 1220 continue | |
| 1221 parent_interface = database.GetInterface(parent_name) | |
| 1222 for attribute in parent_interface.attributes: | |
| 1223 if attribute.type.id == 'EventListener': | |
| 1224 return parent_interface.id | |
| 1225 parent_interface = _ParentWithEventAttributes(database, parent_interface) | |
| 1226 if parent_interface: | |
| 1227 return parent_interface | |
| 1228 return None | |
| OLD | NEW |