| 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, html_database, html_renames, | 19 def __init__(self, templates, database, emitters, output_dir): |
| 20 emitters, output_dir): | |
| 21 super(NativeImplementationSystem, self).__init__( | 20 super(NativeImplementationSystem, self).__init__( |
| 22 templates, database, emitters, output_dir) | 21 templates, database, emitters, output_dir) |
| 23 | 22 |
| 24 self._html_renames = html_renames | |
| 25 self._dom_impl_files = [] | 23 self._dom_impl_files = [] |
| 26 self._cpp_header_files = [] | 24 self._cpp_header_files = [] |
| 27 self._cpp_impl_files = [] | 25 self._cpp_impl_files = [] |
| 28 self._html_system = HtmlSystemShared(html_database) | 26 self._html_system = HtmlSystemShared(database) |
| 29 self._factory_provider_emitters = {} | 27 self._factory_provider_emitters = {} |
| 30 | 28 |
| 31 def InterfaceGenerator(self, | 29 def InterfaceGenerator(self, |
| 32 interface, | 30 interface, |
| 33 common_prefix, | 31 common_prefix, |
| 34 super_interface_name, | 32 super_interface_name, |
| 35 source_filter): | 33 source_filter): |
| 36 interface_name = interface.id | 34 interface_name = interface.id |
| 37 | 35 |
| 38 if IsPureInterface(interface_name): | 36 if IsPureInterface(interface_name): |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 super(NativeImplementationGenerator, self).__init__(system._database) | 214 super(NativeImplementationGenerator, self).__init__(system._database) |
| 217 self._system = system | 215 self._system = system |
| 218 self._interface = interface | 216 self._interface = interface |
| 219 self._dart_impl_emitter = dart_impl_emitter | 217 self._dart_impl_emitter = dart_impl_emitter |
| 220 self._cpp_header_emitter = cpp_header_emitter | 218 self._cpp_header_emitter = cpp_header_emitter |
| 221 self._cpp_impl_emitter = cpp_impl_emitter | 219 self._cpp_impl_emitter = cpp_impl_emitter |
| 222 self._base_members = base_members | 220 self._base_members = base_members |
| 223 self._templates = templates | 221 self._templates = templates |
| 224 self._current_secondary_parent = None | 222 self._current_secondary_parent = None |
| 225 self._html_system = self._system._html_system | 223 self._html_system = self._system._html_system |
| 224 self._html_renames = self._html_system._html_renames |
| 226 | 225 |
| 227 def StartInterface(self): | 226 def StartInterface(self): |
| 228 self._interface_type_info = GetIDLTypeInfo(self._interface.id) | 227 self._interface_type_info = GetIDLTypeInfo(self._interface.id) |
| 229 self._members_emitter = emitter.Emitter() | 228 self._members_emitter = emitter.Emitter() |
| 230 self._cpp_declarations_emitter = emitter.Emitter() | 229 self._cpp_declarations_emitter = emitter.Emitter() |
| 231 self._cpp_impl_includes = set() | 230 self._cpp_impl_includes = set() |
| 232 self._cpp_definitions_emitter = emitter.Emitter() | 231 self._cpp_definitions_emitter = emitter.Emitter() |
| 233 self._cpp_resolver_emitter = emitter.Emitter() | 232 self._cpp_resolver_emitter = emitter.Emitter() |
| 234 | 233 |
| 235 self._GenerateConstructors() | 234 self._GenerateConstructors() |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 ' $EVENTS_CLASS get on() {\n' | 374 ' $EVENTS_CLASS get on() {\n' |
| 376 ' if (_on === null) _on = new $EVENTS_CLASS(this);\n' | 375 ' if (_on === null) _on = new $EVENTS_CLASS(this);\n' |
| 377 ' return _on;\n' | 376 ' return _on;\n' |
| 378 ' }\n', | 377 ' }\n', |
| 379 EVENTS_CLASS=events_class) | 378 EVENTS_CLASS=events_class) |
| 380 | 379 |
| 381 def _ImplClassName(self, interface_name): | 380 def _ImplClassName(self, interface_name): |
| 382 return '_%sImpl' % interface_name | 381 return '_%sImpl' % interface_name |
| 383 | 382 |
| 384 def _DartType(self, idl_type): | 383 def _DartType(self, idl_type): |
| 385 type_info = GetIDLTypeInfo(idl_type) | 384 return self._html_system.DartType(idl_type) |
| 386 return self._HTMLInterfaceName(type_info.dart_type()) | |
| 387 | 385 |
| 388 def _BaseClassName(self): | 386 def _BaseClassName(self): |
| 389 if not self._interface.parents: | 387 if not self._interface.parents: |
| 390 return '_DOMWrapperBase' | 388 return '_DOMWrapperBase' |
| 391 | 389 |
| 392 supertype = self._interface.parents[0].type.id | 390 supertype = self._interface.parents[0].type.id |
| 393 | 391 |
| 394 if IsPureInterface(supertype): # The class is a root. | 392 if IsPureInterface(supertype): # The class is a root. |
| 395 return '_DOMWrapperBase' | 393 return '_DOMWrapperBase' |
| 396 | 394 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 408 # EventTarget implementation. | 406 # EventTarget implementation. |
| 409 # | 407 # |
| 410 # Applies to MessagePort. | 408 # Applies to MessagePort. |
| 411 if not [op for op in self._interface.operations if op.id == 'addEventListe
ner']: | 409 if not [op for op in self._interface.operations if op.id == 'addEventListe
ner']: |
| 412 return self._ImplClassName(supertype) | 410 return self._ImplClassName(supertype) |
| 413 return '_DOMWrapperBase' | 411 return '_DOMWrapperBase' |
| 414 | 412 |
| 415 return self._ImplClassName(supertype) | 413 return self._ImplClassName(supertype) |
| 416 | 414 |
| 417 def _HTMLInterfaceName(self, interface_name): | 415 def _HTMLInterfaceName(self, interface_name): |
| 418 return self._system._html_renames.get(interface_name, interface_name) | 416 return self._html_renames.get(interface_name, interface_name) |
| 419 | 417 |
| 420 def _IsConstructable(self): | 418 def _IsConstructable(self): |
| 421 # FIXME: support ConstructorTemplate. | 419 # FIXME: support ConstructorTemplate. |
| 422 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) | 420 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name
dConstructor']) & set(self._interface.ext_attrs) |
| 423 | 421 |
| 424 def _EmitFactoryProvider(self, interface_name, constructor_info): | 422 def _EmitFactoryProvider(self, interface_name, constructor_info): |
| 425 dart_impl_path = self._system._FilePathForDartFactoryProviderImplementation( | 423 dart_impl_path = self._system._FilePathForDartFactoryProviderImplementation( |
| 426 interface_name) | 424 interface_name) |
| 427 self._system._dom_impl_files.append(dart_impl_path) | 425 self._system._dom_impl_files.append(dart_impl_path) |
| 428 | 426 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 548 |
| 551 def AddConstant(self, constant): | 549 def AddConstant(self, constant): |
| 552 # Constants are already defined on the interface. | 550 # Constants are already defined on the interface. |
| 553 pass | 551 pass |
| 554 | 552 |
| 555 def AddAttribute(self, getter, setter): | 553 def AddAttribute(self, getter, setter): |
| 556 if 'CheckSecurityForNode' in (getter or setter).ext_attrs: | 554 if 'CheckSecurityForNode' in (getter or setter).ext_attrs: |
| 557 # FIXME: exclude from interface as well. | 555 # FIXME: exclude from interface as well. |
| 558 return | 556 return |
| 559 | 557 |
| 560 html_interface_name = self._HTMLInterfaceName(self._interface.id) | |
| 561 dom_name = DartDomNameOfAttribute(getter or setter) | 558 dom_name = DartDomNameOfAttribute(getter or setter) |
| 562 html_getter_name = self._html_system.RenameInHtmlLibrary( | 559 html_getter_name = self._html_system.RenameInHtmlLibrary( |
| 563 html_interface_name, dom_name, 'get:', implementation_class=True) | 560 self._interface.id, dom_name, 'get:', implementation_class=True) |
| 564 html_setter_name = self._html_system.RenameInHtmlLibrary( | 561 html_setter_name = self._html_system.RenameInHtmlLibrary( |
| 565 html_interface_name, dom_name, 'set:', implementation_class=True) | 562 self._interface.id, dom_name, 'set:', implementation_class=True) |
| 566 | 563 |
| 567 if getter and html_getter_name: | 564 if getter and html_getter_name: |
| 568 self._AddGetter(getter, html_getter_name) | 565 self._AddGetter(getter, html_getter_name) |
| 569 if setter and html_setter_name: | 566 if setter and html_setter_name: |
| 570 self._AddSetter(setter, html_setter_name) | 567 self._AddSetter(setter, html_setter_name) |
| 571 | 568 |
| 572 def AddSecondaryAttribute(self, interface, getter, setter): | 569 def AddSecondaryAttribute(self, interface, getter, setter): |
| 573 self.AddAttribute(getter, setter) | 570 self.AddAttribute(getter, setter) |
| 574 | 571 |
| 575 def _AddGetter(self, attr, html_name): | 572 def _AddGetter(self, attr, html_name): |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 Arguments: | 738 Arguments: |
| 742 info: An OperationInfo object. | 739 info: An OperationInfo object. |
| 743 """ | 740 """ |
| 744 | 741 |
| 745 operation = info.operations[0] | 742 operation = info.operations[0] |
| 746 | 743 |
| 747 if 'CheckSecurityForNode' in operation.ext_attrs: | 744 if 'CheckSecurityForNode' in operation.ext_attrs: |
| 748 # FIXME: exclude from interface as well. | 745 # FIXME: exclude from interface as well. |
| 749 return | 746 return |
| 750 | 747 |
| 751 html_interface_name = self._HTMLInterfaceName(self._interface.id) | |
| 752 html_name = self._html_system.RenameInHtmlLibrary( | 748 html_name = self._html_system.RenameInHtmlLibrary( |
| 753 html_interface_name, info.name, implementation_class=True) | 749 self._interface.id, info.name, implementation_class=True) |
| 754 | 750 |
| 755 if not html_name and info.name == 'item': | 751 if not html_name and info.name == 'item': |
| 756 # FIXME: item should be renamed to operator[], not removed. | 752 # FIXME: item should be renamed to operator[], not removed. |
| 757 html_name = '_item' | 753 html_name = '_item' |
| 758 | 754 |
| 759 if not html_name: | 755 if not html_name: |
| 760 return | 756 return |
| 761 | 757 |
| 762 dart_declaration = '%s%s %s(%s)' % ( | 758 dart_declaration = '%s%s %s(%s)' % ( |
| 763 'static ' if info.IsStatic() else '', | 759 'static ' if info.IsStatic() else '', |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 for parent in interface.parents: | 1042 for parent in interface.parents: |
| 1047 parent_name = parent.type.id | 1043 parent_name = parent.type.id |
| 1048 if not database.HasInterface(parent.type.id): | 1044 if not database.HasInterface(parent.type.id): |
| 1049 continue | 1045 continue |
| 1050 parent_interface = database.GetInterface(parent.type.id) | 1046 parent_interface = database.GetInterface(parent.type.id) |
| 1051 if callback(parent_interface): | 1047 if callback(parent_interface): |
| 1052 return parent_interface | 1048 return parent_interface |
| 1053 parent_interface = _FindParent(parent_interface, database, callback) | 1049 parent_interface = _FindParent(parent_interface, database, callback) |
| 1054 if parent_interface: | 1050 if parent_interface: |
| 1055 return parent_interface | 1051 return parent_interface |
| OLD | NEW |