| 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 import systembase | 11 import systembase |
| 12 from generator import * | 12 from generator import * |
| 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared | 13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents, HtmlSystemShared |
| 14 from systemhtml import HtmlElementConstructorInfos | 14 from systemhtml import HtmlElementConstructorInfos |
| 15 from systemhtml import EmitHtmlElementFactoryConstructors | 15 from systemhtml import EmitHtmlElementFactoryConstructors |
| 16 | 16 |
| 17 class NativeImplementationSystem(systembase.System): | 17 class NativeImplementationSystem(systembase.System): |
| 18 | 18 |
| 19 def __init__(self, templates, database, emitters, output_dir): | 19 def __init__(self, templates, database, emitters, output_dir): |
| 20 super(NativeImplementationSystem, self).__init__( | 20 super(NativeImplementationSystem, self).__init__( |
| 21 templates, database, emitters, output_dir) | 21 templates, database, emitters, output_dir) |
| 22 | 22 |
| 23 self._dom_impl_files = [] | 23 self._dom_impl_files = [] |
| 24 self._cpp_header_files = [] | 24 self._cpp_header_files = [] |
| 25 self._cpp_impl_files = [] | 25 self._cpp_impl_files = [] |
| 26 self._html_system = HtmlSystemShared(database) | 26 self._html_system = HtmlSystemShared(database) |
| 27 self._factory_provider_emitters = {} | 27 self._factory_provider_emitters = {} |
| 28 | 28 |
| 29 def InterfaceGenerator(self, | 29 def ProcessInterface(self, interface): |
| 30 interface, | |
| 31 common_prefix, | |
| 32 super_interface_name, | |
| 33 source_filter): | |
| 34 interface_name = interface.id | 30 interface_name = interface.id |
| 35 | 31 |
| 36 if IsPureInterface(interface_name): | 32 if IsPureInterface(interface_name): |
| 37 return None | 33 return None |
| 38 | 34 |
| 39 dart_impl_path = self._FilePathForDartImplementation(interface_name) | 35 dart_impl_path = self._FilePathForDartImplementation(interface_name) |
| 40 self._dom_impl_files.append(dart_impl_path) | 36 self._dom_impl_files.append(dart_impl_path) |
| 41 | 37 |
| 42 cpp_header_path = self._FilePathForCppHeader(interface_name) | 38 cpp_header_path = self._FilePathForCppHeader(interface_name) |
| 43 self._cpp_header_files.append(cpp_header_path) | 39 self._cpp_header_files.append(cpp_header_path) |
| 44 | 40 |
| 45 cpp_impl_path = self._FilePathForCppImplementation(interface_name) | 41 cpp_impl_path = self._FilePathForCppImplementation(interface_name) |
| 46 self._cpp_impl_files.append(cpp_impl_path) | 42 self._cpp_impl_files.append(cpp_impl_path) |
| 47 | 43 |
| 48 return NativeImplementationGenerator(self, interface, | 44 generator = NativeImplementationGenerator(self, interface, |
| 49 self._emitters.FileEmitter(dart_impl_path), | 45 self._emitters.FileEmitter(dart_impl_path), |
| 50 self._emitters.FileEmitter(cpp_header_path), | 46 self._emitters.FileEmitter(cpp_header_path), |
| 51 self._emitters.FileEmitter(cpp_impl_path), | 47 self._emitters.FileEmitter(cpp_impl_path), |
| 52 self._BaseDefines(interface), | 48 self._BaseDefines(interface), |
| 53 self._templates) | 49 self._templates) |
| 50 generator.Generate() |
| 54 | 51 |
| 55 def ProcessCallback(self, interface, info): | 52 def ProcessCallback(self, interface, info): |
| 56 self._interface = interface | 53 self._interface = interface |
| 57 | 54 |
| 58 if IsPureInterface(self._interface.id): | 55 if IsPureInterface(self._interface.id): |
| 59 return None | 56 return None |
| 60 | 57 |
| 61 cpp_impl_includes = set() | 58 cpp_impl_includes = set() |
| 62 cpp_header_handlers_emitter = emitter.Emitter() | 59 cpp_header_handlers_emitter = emitter.Emitter() |
| 63 cpp_impl_handlers_emitter = emitter.Emitter() | 60 cpp_impl_handlers_emitter = emitter.Emitter() |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 been converted to Dart types (e.g. int, String), unless they are in | 201 been converted to Dart types (e.g. int, String), unless they are in |
| 205 the same package as the interface. | 202 the same package as the interface. |
| 206 dart_impl_emitter: an Emitter for the file containing the Dart | 203 dart_impl_emitter: an Emitter for the file containing the Dart |
| 207 implementation class. | 204 implementation class. |
| 208 cpp_header_emitter: an Emitter for the file containing the C++ header. | 205 cpp_header_emitter: an Emitter for the file containing the C++ header. |
| 209 cpp_impl_emitter: an Emitter for the file containing the C++ | 206 cpp_impl_emitter: an Emitter for the file containing the C++ |
| 210 implementation. | 207 implementation. |
| 211 base_members: a set of names of members defined in a base class. This is | 208 base_members: a set of names of members defined in a base class. This is |
| 212 used to avoid static member 'overriding' in the generated Dart code. | 209 used to avoid static member 'overriding' in the generated Dart code. |
| 213 """ | 210 """ |
| 214 super(NativeImplementationGenerator, self).__init__(system._database) | 211 super(NativeImplementationGenerator, self).__init__( |
| 212 system._database, interface) |
| 215 self._system = system | 213 self._system = system |
| 216 self._interface = interface | |
| 217 self._dart_impl_emitter = dart_impl_emitter | 214 self._dart_impl_emitter = dart_impl_emitter |
| 218 self._cpp_header_emitter = cpp_header_emitter | 215 self._cpp_header_emitter = cpp_header_emitter |
| 219 self._cpp_impl_emitter = cpp_impl_emitter | 216 self._cpp_impl_emitter = cpp_impl_emitter |
| 220 self._base_members = base_members | 217 self._base_members = base_members |
| 221 self._templates = templates | 218 self._templates = templates |
| 222 self._current_secondary_parent = None | 219 self._current_secondary_parent = None |
| 223 self._html_system = self._system._html_system | 220 self._html_system = self._system._html_system |
| 224 self._html_renames = self._html_system._html_renames | 221 self._html_renames = self._html_system._html_renames |
| 225 | 222 |
| 226 def StartInterface(self): | 223 def StartInterface(self): |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 for (i, argument) in enumerate(constructor_info.idl_args): | 296 for (i, argument) in enumerate(constructor_info.idl_args): |
| 300 argument_expression = self._GenerateToNative( | 297 argument_expression = self._GenerateToNative( |
| 301 parameter_definitions_emitter, argument, i) | 298 parameter_definitions_emitter, argument, i) |
| 302 arguments.append(argument_expression) | 299 arguments.append(argument_expression) |
| 303 | 300 |
| 304 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) | 301 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c
reate_function) |
| 305 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, | 302 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, |
| 306 self._interface.id, ext_attrs, raises_dom_exceptions) | 303 self._interface.id, ext_attrs, raises_dom_exceptions) |
| 307 | 304 |
| 308 runtime_check = None | 305 runtime_check = None |
| 309 database = self._system._database | 306 database = self._database |
| 310 assert (not ( | 307 assert (not ( |
| 311 'synthesizedV8EnabledPerContext' in ext_attrs and | 308 'synthesizedV8EnabledPerContext' in ext_attrs and |
| 312 'synthesizedV8EnabledAtRuntime' in ext_attrs)) | 309 'synthesizedV8EnabledAtRuntime' in ext_attrs)) |
| 313 if 'synthesizedV8EnabledPerContext' in ext_attrs: | 310 if 'synthesizedV8EnabledPerContext' in ext_attrs: |
| 314 raises_exceptions = True | 311 raises_exceptions = True |
| 315 self._cpp_impl_includes.add('"ContextFeatures.h"') | 312 self._cpp_impl_includes.add('"ContextFeatures.h"') |
| 316 runtime_check = emitter.Format( | 313 runtime_check = emitter.Format( |
| 317 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin
dowForCurrentIsolate()->document())) {\n' | 314 ' if (!ContextFeatures::$(FEATURE)Enabled(DartUtilities::domWin
dowForCurrentIsolate()->document())) {\n' |
| 318 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' | 315 ' exception = Dart_NewString("Feature $FEATURE is not enabl
ed");\n' |
| 319 ' goto fail;\n' | 316 ' goto fail;\n' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return | 349 return |
| 353 | 350 |
| 354 events_attributes = [attr for attr in self._interface.attributes | 351 events_attributes = [attr for attr in self._interface.attributes |
| 355 if attr.type.id == 'EventListener'] | 352 if attr.type.id == 'EventListener'] |
| 356 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: | 353 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes: |
| 357 return | 354 return |
| 358 | 355 |
| 359 def IsEventTarget(interface): | 356 def IsEventTarget(interface): |
| 360 return ('EventTarget' in interface.ext_attrs and | 357 return ('EventTarget' in interface.ext_attrs and |
| 361 interface.id != 'EventTarget') | 358 interface.id != 'EventTarget') |
| 362 is_root = not _FindParent(self._interface, self._system._database, IsEventTa
rget) | 359 is_root = not _FindParent(self._interface, self._database, IsEventTarget) |
| 363 if is_root: | 360 if is_root: |
| 364 self._members_emitter.Emit(' _EventsImpl _on;\n') | 361 self._members_emitter.Emit(' _EventsImpl _on;\n') |
| 365 | 362 |
| 366 if not events_attributes: | 363 if not events_attributes: |
| 367 if is_root: | 364 if is_root: |
| 368 self._EmitEventGetter('_EventsImpl') | 365 self._EmitEventGetter('_EventsImpl') |
| 369 return | 366 return |
| 370 | 367 |
| 371 events_class = '_%sEventsImpl' % self._interface.id | 368 events_class = '_%sEventsImpl' % self._interface.id |
| 372 self._EmitEventGetter(events_class) | 369 self._EmitEventGetter(events_class) |
| 373 | 370 |
| 374 def HasEventAttributes(interface): | 371 def HasEventAttributes(interface): |
| 375 return any([a.type.id == 'EventListener' for a in interface.attributes]) | 372 return any([a.type.id == 'EventListener' for a in interface.attributes]) |
| 376 parent = _FindParent(self._interface, self._system._database, HasEventAttrib
utes) | 373 parent = _FindParent(self._interface, self._database, HasEventAttributes) |
| 377 if parent: | 374 if parent: |
| 378 parent_events_class = '_%sEventsImpl' % parent.id | 375 parent_events_class = '_%sEventsImpl' % parent.id |
| 379 else: | 376 else: |
| 380 parent_events_class = '_EventsImpl' | 377 parent_events_class = '_EventsImpl' |
| 381 | 378 |
| 382 html_inteface = self._HTMLInterfaceName(self._interface.id) | 379 html_inteface = self._HTMLInterfaceName(self._interface.id) |
| 383 events_members = self._dart_impl_emitter.Emit( | 380 events_members = self._dart_impl_emitter.Emit( |
| 384 '\n' | 381 '\n' |
| 385 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT
ERFACE {\n' | 382 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT
ERFACE {\n' |
| 386 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n' | 383 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n' |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 template, | 462 template, |
| 466 FACTORYPROVIDER='_%sFactoryProvider' % html_interface_name, | 463 FACTORYPROVIDER='_%sFactoryProvider' % html_interface_name, |
| 467 INTERFACE=html_interface_name, | 464 INTERFACE=html_interface_name, |
| 468 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), | 465 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), |
| 469 ARGUMENTS=constructor_info.ParametersAsArgumentList(), | 466 ARGUMENTS=constructor_info.ParametersAsArgumentList(), |
| 470 NATIVE_NAME=native_implementation_function) | 467 NATIVE_NAME=native_implementation_function) |
| 471 | 468 |
| 472 def FinishInterface(self): | 469 def FinishInterface(self): |
| 473 html_interface_name = self._HTMLInterfaceName(self._interface.id) | 470 html_interface_name = self._HTMLInterfaceName(self._interface.id) |
| 474 template = None | 471 template = None |
| 475 if html_interface_name == self._interface.id or not self._system._database.H
asInterface(html_interface_name): | 472 if html_interface_name == self._interface.id or not self._database.HasInterf
ace(html_interface_name): |
| 476 template_file = 'impl_%s.darttemplate' % html_interface_name | 473 template_file = 'impl_%s.darttemplate' % html_interface_name |
| 477 template = self._templates.TryLoad(template_file) | 474 template = self._templates.TryLoad(template_file) |
| 478 if not template: | 475 if not template: |
| 479 template = self._templates.Load('dart_implementation.darttemplate') | 476 template = self._templates.Load('dart_implementation.darttemplate') |
| 480 | 477 |
| 481 class_name = self._ImplClassName(self._interface.id) | 478 class_name = self._ImplClassName(self._interface.id) |
| 482 members_emitter = self._dart_impl_emitter.Emit( | 479 members_emitter = self._dart_impl_emitter.Emit( |
| 483 template, | 480 template, |
| 484 CLASSNAME=class_name, | 481 CLASSNAME=class_name, |
| 485 EXTENDS=' extends ' + self._BaseClassName(), | 482 EXTENDS=' extends ' + self._BaseClassName(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 ' static Dart_Handle toDart(NativeType* value);\n') | 517 ' static Dart_Handle toDart(NativeType* value);\n') |
| 521 else: | 518 else: |
| 522 to_dart_emitter.Emit( | 519 to_dart_emitter.Emit( |
| 523 ' static Dart_Handle toDart(NativeType* value)\n' | 520 ' static Dart_Handle toDart(NativeType* value)\n' |
| 524 ' {\n' | 521 ' {\n' |
| 525 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' | 522 ' return DartDOMWrapper::toDart<Dart$(INTERFACE)>(value);\n' |
| 526 ' }\n', | 523 ' }\n', |
| 527 INTERFACE=self._interface.id) | 524 INTERFACE=self._interface.id) |
| 528 | 525 |
| 529 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in
cludes()) | 526 webcore_includes = _GenerateCPPIncludes(self._interface_type_info.webcore_in
cludes()) |
| 530 wrapper_type = _DOMWrapperType(self._system._database, self._interface) | 527 wrapper_type = _DOMWrapperType(self._database, self._interface) |
| 531 self._cpp_header_emitter.Emit( | 528 self._cpp_header_emitter.Emit( |
| 532 self._templates.Load('cpp_header.template'), | 529 self._templates.Load('cpp_header.template'), |
| 533 INTERFACE=self._interface.id, | 530 INTERFACE=self._interface.id, |
| 534 WEBCORE_INCLUDES=webcore_includes, | 531 WEBCORE_INCLUDES=webcore_includes, |
| 535 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), | 532 WEBCORE_CLASS_NAME=self._interface_type_info.native_type(), |
| 536 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), | 533 DECLARATIONS=self._cpp_declarations_emitter.Fragments(), |
| 537 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type, | 534 NATIVE_TRAITS_TYPE='DartDOMWrapper::%sTraits' % wrapper_type, |
| 538 TO_NATIVE=to_native_emitter.Fragments(), | 535 TO_NATIVE=to_native_emitter.Fragments(), |
| 539 TO_DART=to_dart_emitter.Fragments()) | 536 TO_DART=to_dart_emitter.Fragments()) |
| 540 | 537 |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 | 1086 |
| 1090 def _IsArgumentOptionalInWebCore(argument): | 1087 def _IsArgumentOptionalInWebCore(argument): |
| 1091 return IsOptional(argument) and not 'Callback' in argument.ext_attrs | 1088 return IsOptional(argument) and not 'Callback' in argument.ext_attrs |
| 1092 | 1089 |
| 1093 def _ToWebKitName(name): | 1090 def _ToWebKitName(name): |
| 1094 name = name[0].lower() + name[1:] | 1091 name = name[0].lower() + name[1:] |
| 1095 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), | 1092 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), |
| 1096 name) | 1093 name) |
| 1097 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, | 1094 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize()
, |
| 1098 name) | 1095 name) |
| OLD | NEW |