| 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 system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import os | 10 import os |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 self._members_emitter, | 305 self._members_emitter, |
| 306 self._top_level_emitter) = interface_emitter.Emit( | 306 self._top_level_emitter) = interface_emitter.Emit( |
| 307 interface_template + '$!TOP_LEVEL', | 307 interface_template + '$!TOP_LEVEL', |
| 308 ID=interface_name, | 308 ID=interface_name, |
| 309 EXTENDS=implements_str) | 309 EXTENDS=implements_str) |
| 310 | 310 |
| 311 self._type_comment_emitter.Emit("/// @domName $DOMNAME", | 311 self._type_comment_emitter.Emit("/// @domName $DOMNAME", |
| 312 DOMNAME=self._interface.doc_js_name) | 312 DOMNAME=self._interface.doc_js_name) |
| 313 | 313 |
| 314 implementation_emitter = self._ImplementationEmitter() | 314 implementation_emitter = self._ImplementationEmitter() |
| 315 base_class = self._backend.BaseClassName() | 315 |
| 316 interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 316 base_class = self._backend.RootClassName() |
| 317 implemented_interfaces = [interface_type_info.interface_name()] +\ | 317 if self._interface.parents: |
| 318 supertype = self._interface.parents[0].type.id |
| 319 if not IsDartCollectionType(supertype) and not IsPureInterface(supertype): |
| 320 type_info = self._type_registry.TypeInfo(supertype) |
| 321 if type_info.merged_into() and self._backend.ImplementsMergedMembers(): |
| 322 type_info = self._type_registry.TypeInfo(type_info.merged_into()) |
| 323 base_class = type_info.implementation_name() |
| 324 |
| 325 implemented_interfaces = [interface_name] +\ |
| 318 self._backend.AdditionalImplementedInterfaces() | 326 self._backend.AdditionalImplementedInterfaces() |
| 319 self._implementation_members_emitter = implementation_emitter.Emit( | 327 self._implementation_members_emitter = implementation_emitter.Emit( |
| 320 self._backend.ImplementationTemplate(), | 328 self._backend.ImplementationTemplate(), |
| 321 CLASSNAME=self._interface_type_info.implementation_name(), | 329 CLASSNAME=self._interface_type_info.implementation_name(), |
| 322 EXTENDS=' extends %s' % base_class if base_class else '', | 330 EXTENDS=' extends %s' % base_class if base_class else '', |
| 323 IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces), | 331 IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces), |
| 324 NATIVESPEC=self._backend.NativeSpec()) | 332 NATIVESPEC=self._backend.NativeSpec()) |
| 325 self._backend.StartInterface(self._implementation_members_emitter) | 333 self._backend.StartInterface(self._implementation_members_emitter) |
| 326 | 334 |
| 327 for constructor_info in constructors: | 335 for constructor_info in constructors: |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 self._type_registry = options.type_registry | 592 self._type_registry = options.type_registry |
| 585 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) | 593 self._interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 586 self._current_secondary_parent = None | 594 self._current_secondary_parent = None |
| 587 | 595 |
| 588 def ImplementsMergedMembers(self): | 596 def ImplementsMergedMembers(self): |
| 589 return True | 597 return True |
| 590 | 598 |
| 591 def GenerateCallback(self, info): | 599 def GenerateCallback(self, info): |
| 592 pass | 600 pass |
| 593 | 601 |
| 594 def BaseClassName(self): | 602 def RootClassName(self): |
| 595 if not self._interface.parents: | 603 return None |
| 596 return None | |
| 597 supertype = self._interface.parents[0].type.id | |
| 598 if IsDartCollectionType(supertype): | |
| 599 # List methods are injected in AddIndexer. | |
| 600 return None | |
| 601 if IsPureInterface(supertype): | |
| 602 return None | |
| 603 type_info = self._type_registry.TypeInfo(supertype) | |
| 604 if type_info.merged_into(): | |
| 605 type_info = self._type_registry.TypeInfo(type_info.merged_into()) | |
| 606 return type_info.implementation_name() | |
| 607 | 604 |
| 608 def AdditionalImplementedInterfaces(self): | 605 def AdditionalImplementedInterfaces(self): |
| 609 # TODO: Include all implemented interfaces, including other Lists. | 606 # TODO: Include all implemented interfaces, including other Lists. |
| 610 implements = [] | 607 implements = [] |
| 611 element_type = MaybeTypedArrayElementType(self._interface) | 608 element_type = MaybeTypedArrayElementType(self._interface) |
| 612 if element_type: | 609 if element_type: |
| 613 implements.append('List<%s>' % self._DartType(element_type)) | 610 implements.append('List<%s>' % self._DartType(element_type)) |
| 614 if self._HasJavaScriptIndexingBehaviour(): | 611 if self._HasJavaScriptIndexingBehaviour(): |
| 615 implements.append('JavaScriptIndexingBehavior') | 612 implements.append('JavaScriptIndexingBehavior') |
| 616 return implements | 613 return implements |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 | 1097 |
| 1101 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1098 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1102 library_file_dir = os.path.dirname(library_file_path) | 1099 library_file_dir = os.path.dirname(library_file_path) |
| 1103 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1100 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1104 imports_emitter = library_emitter.Emit( | 1101 imports_emitter = library_emitter.Emit( |
| 1105 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1102 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1106 for path in sorted(self._path_to_emitter.keys()): | 1103 for path in sorted(self._path_to_emitter.keys()): |
| 1107 relpath = os.path.relpath(path, library_file_dir) | 1104 relpath = os.path.relpath(path, library_file_dir) |
| 1108 imports_emitter.Emit( | 1105 imports_emitter.Emit( |
| 1109 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1106 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |