Chromium Code Reviews| 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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 534 |
| 535 def FindConversion(idl_type, direction, interface, member): | 535 def FindConversion(idl_type, direction, interface, member): |
| 536 table = dart2js_conversions | 536 table = dart2js_conversions |
| 537 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or | 537 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or |
| 538 table.get('%s %s %s.*' % (idl_type, direction, interface)) or | 538 table.get('%s %s %s.*' % (idl_type, direction, interface)) or |
| 539 table.get('%s %s' % (idl_type, direction))) | 539 table.get('%s %s' % (idl_type, direction))) |
| 540 return None | 540 return None |
| 541 | 541 |
| 542 # ------------------------------------------------------------------------------ | 542 # ------------------------------------------------------------------------------ |
| 543 | 543 |
| 544 # Annotations to be placed on members. The table is indexed by the IDL | |
| 545 # interface and member name, and by IDL return or field type name. Both are | |
| 546 # used to assemble the annotations: | |
| 547 # | |
| 548 # INTERFACE.MEMBER: annotations for member. | |
| 549 # +TYPE: add annotations only if there are member annotations. | |
| 550 # TYPE: add regardless of member annotations. | |
| 551 | |
| 552 dart2js_annotations = { | |
| 553 | |
| 554 # Rather than have the result of an IDBRequest as a union over all possible | |
| 555 # results, we mark the result as git instantiating any classes, and mark | |
|
blois
2012/11/19 20:46:48
git?
sra1
2012/11/19 23:15:07
Done.
| |
| 556 # each operation with the classes that it could cause to be asynchronously | |
| 557 # instantiated. | |
| 558 'IDBRequest.result': "@Creates('Null')", | |
| 559 | |
| 560 # The source is usually a participant in the operation that generated the | |
| 561 # IDBRequest. | |
| 562 'IDBRequest.source': "@Creates('Null')", | |
| 563 | |
| 564 'IDBFactory.open': "@Creates('IDBDatabase')", | |
| 565 | |
| 566 'IDBObjectStore.put': "@annotation_Creates_IDBKey", | |
| 567 'IDBObjectStore.add': "@annotation_Creates_IDBKey", | |
| 568 'IDBObjectStore.get': "@annotation_Creates_SerializedScriptValue", | |
| 569 'IDBObjectStore.openCursor': "@Creates('IDBCursor')", | |
| 570 | |
| 571 'IDBIndex.get': "@annotation_Creates_SerializedScriptValue", | |
| 572 'IDBIndex.getKey': | |
| 573 "@annotation_Creates_SerializedScriptValue " | |
| 574 # The source is the object store behind the index. | |
| 575 "@Creates('IDBObjectStore')", | |
| 576 'IDBIndex.openCursor': "@Creates('IDBCursor')", | |
| 577 'IDBIndex.openKeyCursor': "@Creates('IDBCursor')", | |
| 578 | |
| 579 'IDBCursorWithValue.value': | |
| 580 '@annotation_Creates_SerializedScriptValue ' | |
| 581 '@annotation_Returns_SerializedScriptValue', | |
| 582 | |
| 583 'IDBCursor.key': "@annotation_Creates_IDBKey @annotation_Returns_IDBKey", | |
| 584 | |
| 585 '+IDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | |
| 586 | |
| 587 '+IDBOpenDBRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | |
| 588 '+IDBVersionChangeRequest': "@Returns('IDBRequest') @Creates('IDBRequest')", | |
| 589 | |
| 590 | |
| 591 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", | |
| 592 | |
| 593 'CanvasRenderingContext2D.createImageData': | |
| 594 "@Creates('ImageData|=Object')", | |
| 595 | |
| 596 'CanvasRenderingContext2D.getImageData': | |
| 597 "@Creates('ImageData|=Object')", | |
| 598 | |
| 599 'CanvasRenderingContext2D.webkitGetImageDataHD': | |
| 600 "@Creates('ImageData|=Object')", | |
| 601 | |
| 602 'XMLHttpRequest.response': | |
| 603 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", | |
| 604 | |
| 605 'SQLResultSetRowList.item': "@Creates('=Object')", | |
| 606 } | |
| 607 | |
| 608 def FindAnnotations(idl_type, interface_name, member_name): | |
| 609 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | |
| 610 if ann1: | |
| 611 ann2 = dart2js_annotations.get('+' + idl_type) | |
| 612 if ann2: | |
| 613 return ann2 + ' ' + ann1 | |
| 614 ann2 = dart2js_annotations.get(idl_type) | |
| 615 if ann2: | |
| 616 return ann2 + ' ' + ann1 | |
| 617 return ann1 | |
| 618 | |
| 619 ann2 = dart2js_annotations.get(idl_type) | |
| 620 return ann2 | |
| 621 | |
| 622 # ------------------------------------------------------------------------------ | |
| 623 | |
| 544 class IDLTypeInfo(object): | 624 class IDLTypeInfo(object): |
| 545 def __init__(self, idl_type, data): | 625 def __init__(self, idl_type, data): |
| 546 self._idl_type = idl_type | 626 self._idl_type = idl_type |
| 547 self._data = data | 627 self._data = data |
| 548 | 628 |
| 549 def idl_type(self): | 629 def idl_type(self): |
| 550 return self._idl_type | 630 return self._idl_type |
| 551 | 631 |
| 552 def dart_type(self): | 632 def dart_type(self): |
| 553 return self._data.dart_type or self._idl_type | 633 return self._data.dart_type or self._idl_type |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1082 else: | 1162 else: |
| 1083 dart_interface_name = type_name | 1163 dart_interface_name = type_name |
| 1084 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, | 1164 return InterfaceIDLTypeInfo(type_name, type_data, dart_interface_name, |
| 1085 self) | 1165 self) |
| 1086 | 1166 |
| 1087 if type_data.clazz == 'SVGTearOff': | 1167 if type_data.clazz == 'SVGTearOff': |
| 1088 return SVGTearOffIDLTypeInfo(type_name, type_data, self) | 1168 return SVGTearOffIDLTypeInfo(type_name, type_data, self) |
| 1089 | 1169 |
| 1090 class_name = '%sIDLTypeInfo' % type_data.clazz | 1170 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1091 return globals()[class_name](type_name, type_data) | 1171 return globals()[class_name](type_name, type_data) |
| OLD | NEW |