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