| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 template_file = 'interface_%s.darttemplate' % self._html_interface_name | 250 template_file = 'interface_%s.darttemplate' % self._html_interface_name |
| 251 interface_template = (self._template_loader.TryLoad(template_file) or | 251 interface_template = (self._template_loader.TryLoad(template_file) or |
| 252 self._template_loader.Load('interface.darttemplate')) | 252 self._template_loader.Load('interface.darttemplate')) |
| 253 | 253 |
| 254 typename = self._html_interface_name | 254 typename = self._html_interface_name |
| 255 | 255 |
| 256 implements = [] | 256 implements = [] |
| 257 suppressed_implements = [] | 257 suppressed_implements = [] |
| 258 | 258 |
| 259 for parent in self._interface.parents: | 259 for parent in self._interface.parents: |
| 260 parent_type_info = self._type_registry.TypeInfo(parent.type.id) |
| 261 parent_interface_name = parent_type_info.interface_name() |
| 260 # TODO(vsm): Remove source_filter. | 262 # TODO(vsm): Remove source_filter. |
| 261 if MatchSourceFilter(parent): | 263 if MatchSourceFilter(parent): |
| 262 # Parent is a DOM type. | 264 # Parent is a DOM type. |
| 263 implements.append(self._DartType(parent.type.id)) | 265 implements.append(parent_interface_name) |
| 264 elif '<' in parent.type.id: | 266 elif '<' in parent.type.id: |
| 265 # Parent is a Dart collection type. | 267 # Parent is a Dart collection type. |
| 266 # TODO(vsm): Make this check more robust. | 268 # TODO(vsm): Make this check more robust. |
| 267 implements.append(self._DartType(parent.type.id)) | 269 implements.append(parent_interface_name) |
| 268 else: | 270 else: |
| 269 suppressed_implements.append('%s.%s' % | 271 suppressed_implements.append('%s.%s' % |
| 270 (self._common_prefix, self._DartType(parent.type.id))) | 272 (self._common_prefix, parent_interface_name)) |
| 271 | 273 |
| 272 if typename in _secure_base_types: | 274 if typename in _secure_base_types: |
| 273 implements.append(_secure_base_types[typename]) | 275 implements.append(_secure_base_types[typename]) |
| 274 | 276 |
| 275 comment = ' extends' | 277 comment = ' extends' |
| 276 implements_str = '' | 278 implements_str = '' |
| 277 if implements: | 279 if implements: |
| 278 implements_str += ' implements ' + ', '.join(implements) | 280 implements_str += ' implements ' + ', '.join(implements) |
| 279 comment = ',' | 281 comment = ',' |
| 280 if suppressed_implements: | 282 if suppressed_implements: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if self._html_interface_name in nativified_classes: | 332 if self._html_interface_name in nativified_classes: |
| 331 name = nativified_classes[self._html_interface_name] | 333 name = nativified_classes[self._html_interface_name] |
| 332 basename = '%sImpl' % name | 334 basename = '%sImpl' % name |
| 333 else: | 335 else: |
| 334 basename = '%sImpl_Merged' % self._html_interface_name | 336 basename = '%sImpl_Merged' % self._html_interface_name |
| 335 implementation_emitter = self._library_emitter.FileEmitter(basename) | 337 implementation_emitter = self._library_emitter.FileEmitter(basename) |
| 336 else: | 338 else: |
| 337 implementation_emitter = emitter.Emitter() | 339 implementation_emitter = emitter.Emitter() |
| 338 | 340 |
| 339 base_class = self._backend.BaseClassName() | 341 base_class = self._backend.BaseClassName() |
| 340 implemented_interfaces = [self._html_interface_name] +\ | 342 interface_type_info = self._type_registry.TypeInfo(self._interface.id) |
| 343 implemented_interfaces = [interface_type_info.interface_name()] +\ |
| 341 self._backend.AdditionalImplementedInterfaces() | 344 self._backend.AdditionalImplementedInterfaces() |
| 342 self._implementation_members_emitter = implementation_emitter.Emit( | 345 self._implementation_members_emitter = implementation_emitter.Emit( |
| 343 self._backend.ImplementationTemplate(), | 346 self._backend.ImplementationTemplate(), |
| 344 CLASSNAME=self._backend.ImplementationClassName(), | 347 CLASSNAME=self._backend.ImplementationClassName(), |
| 345 EXTENDS=' extends %s' % base_class if base_class else '', | 348 EXTENDS=' extends %s' % base_class if base_class else '', |
| 346 IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces), | 349 IMPLEMENTS=' implements ' + ', '.join(implemented_interfaces), |
| 347 NATIVESPEC=self._backend.NativeSpec()) | 350 NATIVESPEC=self._backend.NativeSpec()) |
| 348 self._backend.StartInterface(self._implementation_members_emitter) | 351 self._backend.StartInterface(self._implementation_members_emitter) |
| 349 | 352 |
| 350 for constructor_info in constructors: | 353 for constructor_info in constructors: |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 return None | 624 return None |
| 622 supertype = self._interface.parents[0].type.id | 625 supertype = self._interface.parents[0].type.id |
| 623 if IsDartCollectionType(supertype): | 626 if IsDartCollectionType(supertype): |
| 624 # List methods are injected in AddIndexer. | 627 # List methods are injected in AddIndexer. |
| 625 return None | 628 return None |
| 626 if IsPureInterface(supertype): | 629 if IsPureInterface(supertype): |
| 627 return None | 630 return None |
| 628 elif supertype == 'NodeList': | 631 elif supertype == 'NodeList': |
| 629 # Special case as NodeList gets converted to List<Node>. | 632 # Special case as NodeList gets converted to List<Node>. |
| 630 return '_NodeListImpl' | 633 return '_NodeListImpl' |
| 631 return self._ImplClassName(self._DartType(supertype)) | 634 return self._type_registry.TypeInfo(supertype).implementation_name() |
| 632 | 635 |
| 633 def AdditionalImplementedInterfaces(self): | 636 def AdditionalImplementedInterfaces(self): |
| 634 # TODO: Include all implemented interfaces, including other Lists. | 637 # TODO: Include all implemented interfaces, including other Lists. |
| 635 implements = [] | 638 implements = [] |
| 636 element_type = MaybeTypedArrayElementType(self._interface) | 639 element_type = MaybeTypedArrayElementType(self._interface) |
| 637 if element_type: | 640 if element_type: |
| 638 implements.append('List<%s>' % self._DartType(element_type)) | 641 implements.append('List<%s>' % self._DartType(element_type)) |
| 639 if self._HasJavaScriptIndexingBehaviour(): | 642 if self._HasJavaScriptIndexingBehaviour(): |
| 640 implements.append('JavaScriptIndexingBehavior') | 643 implements.append('JavaScriptIndexingBehavior') |
| 641 return implements | 644 return implements |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 | 1132 |
| 1130 library_emitter = self._multiemitter.FileEmitter(library_file_path) | 1133 library_emitter = self._multiemitter.FileEmitter(library_file_path) |
| 1131 library_file_dir = os.path.dirname(library_file_path) | 1134 library_file_dir = os.path.dirname(library_file_path) |
| 1132 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) | 1135 auxiliary_dir = os.path.relpath(auxiliary_dir, library_file_dir) |
| 1133 imports_emitter = library_emitter.Emit( | 1136 imports_emitter = library_emitter.Emit( |
| 1134 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) | 1137 self._template, AUXILIARY_DIR=massage_path(auxiliary_dir)) |
| 1135 for path in sorted(self._path_to_emitter.keys()): | 1138 for path in sorted(self._path_to_emitter.keys()): |
| 1136 relpath = os.path.relpath(path, library_file_dir) | 1139 relpath = os.path.relpath(path, library_file_dir) |
| 1137 imports_emitter.Emit( | 1140 imports_emitter.Emit( |
| 1138 "#source('$PATH');\n", PATH=massage_path(relpath)) | 1141 "#source('$PATH');\n", PATH=massage_path(relpath)) |
| OLD | NEW |