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 systems to generate | 6 """This module provides shared functionality for systems to generate |
7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
8 | 8 |
9 import copy | 9 import copy |
10 import re | 10 import re |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 # Annotations to be placed on members. The table is indexed by the IDL | 586 # Annotations to be placed on members. The table is indexed by the IDL |
587 # interface and member name, and by IDL return or field type name. Both are | 587 # interface and member name, and by IDL return or field type name. Both are |
588 # used to assemble the annotations: | 588 # used to assemble the annotations: |
589 # | 589 # |
590 # INTERFACE.MEMBER: annotations for member. | 590 # INTERFACE.MEMBER: annotations for member. |
591 # +TYPE: add annotations only if there are member annotations. | 591 # +TYPE: add annotations only if there are member annotations. |
592 # TYPE: add regardless of member annotations. | 592 # TYPE: add regardless of member annotations. |
593 | 593 |
594 dart2js_annotations = { | 594 dart2js_annotations = { |
595 | 595 |
| 596 'CanvasRenderingContext2D.createImageData': |
| 597 "@Creates('ImageData|=Object')", |
| 598 |
| 599 'CanvasRenderingContext2D.getImageData': |
| 600 "@Creates('ImageData|=Object')", |
| 601 |
| 602 'CanvasRenderingContext2D.webkitGetImageDataHD': |
| 603 "@Creates('ImageData|=Object')", |
| 604 |
| 605 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", |
| 606 |
| 607 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", |
| 608 |
596 # Rather than have the result of an IDBRequest as a union over all possible | 609 # Rather than have the result of an IDBRequest as a union over all possible |
597 # results, we mark the result as instantiating any classes, and mark | 610 # results, we mark the result as instantiating any classes, and mark |
598 # each operation with the classes that it could cause to be asynchronously | 611 # each operation with the classes that it could cause to be asynchronously |
599 # instantiated. | 612 # instantiated. |
600 'IDBRequest.result': "@Creates('Null')", | 613 'IDBRequest.result': "@Creates('Null')", |
601 | 614 |
602 # The source is usually a participant in the operation that generated the | 615 # The source is usually a participant in the operation that generated the |
603 # IDBRequest. | 616 # IDBRequest. |
604 'IDBRequest.source': "@Creates('Null')", | 617 'IDBRequest.source': "@Creates('Null')", |
605 | 618 |
(...skipping 17 matching lines...) Expand all Loading... |
623 '@_annotation_Returns_SerializedScriptValue', | 636 '@_annotation_Returns_SerializedScriptValue', |
624 | 637 |
625 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", | 638 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", |
626 | 639 |
627 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 640 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
628 | 641 |
629 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 642 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
630 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | 643 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", |
631 | 644 |
632 | 645 |
633 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", | 646 'MessageEvent.ports': "@Creates('=List')", |
634 | 647 |
635 'CanvasRenderingContext2D.createImageData': | 648 'SQLResultSetRowList.item': "@Creates('=Object')", |
636 "@Creates('ImageData|=Object')", | |
637 | |
638 'CanvasRenderingContext2D.getImageData': | |
639 "@Creates('ImageData|=Object')", | |
640 | |
641 'CanvasRenderingContext2D.webkitGetImageDataHD': | |
642 "@Creates('ImageData|=Object')", | |
643 | 649 |
644 'XMLHttpRequest.response': | 650 'XMLHttpRequest.response': |
645 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", | 651 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", |
646 | |
647 'SQLResultSetRowList.item': "@Creates('=Object')", | |
648 } | 652 } |
649 | 653 |
650 def FindAnnotations(idl_type, interface_name, member_name): | 654 def FindAnnotations(idl_type, interface_name, member_name): |
651 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | 655 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) |
652 if ann1: | 656 if ann1: |
653 ann2 = dart2js_annotations.get('+' + idl_type) | 657 ann2 = dart2js_annotations.get('+' + idl_type) |
654 if ann2: | 658 if ann2: |
655 return ann2 + ' ' + ann1 | 659 return ann2 + ' ' + ann1 |
656 ann2 = dart2js_annotations.get(idl_type) | 660 ann2 = dart2js_annotations.get(idl_type) |
657 if ann2: | 661 if ann2: |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 self._dart_interface_name = dart_interface_name | 788 self._dart_interface_name = dart_interface_name |
785 self._type_registry = type_registry | 789 self._type_registry = type_registry |
786 | 790 |
787 def dart_type(self): | 791 def dart_type(self): |
788 if self.list_item_type() and not self.has_generated_interface(): | 792 if self.list_item_type() and not self.has_generated_interface(): |
789 return 'List<%s>' % self._type_registry.TypeInfo(self._data.item_type).dar
t_type() | 793 return 'List<%s>' % self._type_registry.TypeInfo(self._data.item_type).dar
t_type() |
790 return self._data.dart_type or self._dart_interface_name | 794 return self._data.dart_type or self._dart_interface_name |
791 | 795 |
792 def narrow_dart_type(self): | 796 def narrow_dart_type(self): |
793 if self.list_item_type(): | 797 if self.list_item_type(): |
794 return self.idl_type() | 798 return self.implementation_name() |
795 # TODO(podivilov): only primitive and collection types should override | 799 # TODO(podivilov): only primitive and collection types should override |
796 # dart_type. | 800 # dart_type. |
797 if self._data.dart_type != None: | 801 if self._data.dart_type != None: |
798 return self.dart_type() | 802 return self.dart_type() |
799 if IsPureInterface(self.idl_type()): | 803 if IsPureInterface(self.idl_type()): |
800 return self.idl_type() | 804 return self.idl_type() |
801 return self.interface_name() | 805 return self.interface_name() |
802 | 806 |
803 def interface_name(self): | 807 def interface_name(self): |
804 return self._dart_interface_name | 808 return self._dart_interface_name |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 self) | 1201 self) |
1198 | 1202 |
1199 if type_data.clazz == 'SVGTearOff': | 1203 if type_data.clazz == 'SVGTearOff': |
1200 dart_interface_name = self._renamer.RenameInterface( | 1204 dart_interface_name = self._renamer.RenameInterface( |
1201 self._database.GetInterface(type_name)) | 1205 self._database.GetInterface(type_name)) |
1202 return SVGTearOffIDLTypeInfo( | 1206 return SVGTearOffIDLTypeInfo( |
1203 type_name, type_data, dart_interface_name, self) | 1207 type_name, type_data, dart_interface_name, self) |
1204 | 1208 |
1205 class_name = '%sIDLTypeInfo' % type_data.clazz | 1209 class_name = '%sIDLTypeInfo' % type_data.clazz |
1206 return globals()[class_name](type_name, type_data) | 1210 return globals()[class_name](type_name, type_data) |
OLD | NEW |