Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tools/dom/scripts/generator.py

Issue 12024002: Fixing cleanup of dart:html annotation generation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/web_audio/dart2js/web_audio_dart2js.dart ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 # interface and member name, and by IDL return or field type name. Both are 507 # interface and member name, and by IDL return or field type name. Both are
508 # used to assemble the annotations: 508 # used to assemble the annotations:
509 # 509 #
510 # INTERFACE.MEMBER: annotations for member. 510 # INTERFACE.MEMBER: annotations for member.
511 # +TYPE: add annotations only if there are member annotations. 511 # +TYPE: add annotations only if there are member annotations.
512 # -TYPE: add annotations only if there are no member annotations. 512 # -TYPE: add annotations only if there are no member annotations.
513 # TYPE: add regardless of member annotations. 513 # TYPE: add regardless of member annotations.
514 514
515 dart2js_annotations = { 515 dart2js_annotations = {
516 516
517 'CanvasRenderingContext2D.createImageData': 517 'CanvasRenderingContext2D.createImageData': [
518 "@Creates('ImageData|=Object')", 518 "@Creates('ImageData|=Object')",
519 ],
519 520
520 'CanvasRenderingContext2D.getImageData': 521 'CanvasRenderingContext2D.getImageData': [
521 "@Creates('ImageData|=Object')", 522 "@Creates('ImageData|=Object')",
523 ],
522 524
523 'CanvasRenderingContext2D.webkitGetImageDataHD': 525 'CanvasRenderingContext2D.webkitGetImageDataHD': [
524 "@Creates('ImageData|=Object')", 526 "@Creates('ImageData|=Object')",
527 ],
525 528
526 'CanvasRenderingContext2D.fillStyle': 529 'CanvasRenderingContext2D.fillStyle': [
527 "@Creates('String|CanvasGradient|CanvasPattern') " 530 "@Creates('String|CanvasGradient|CanvasPattern')",
528 "@Returns('String|CanvasGradient|CanvasPattern')", 531 "@Returns('String|CanvasGradient|CanvasPattern')",
532 ],
529 533
530 'CanvasRenderingContext2D.strokeStyle': 534 'CanvasRenderingContext2D.strokeStyle': [
531 "@Creates('String|CanvasGradient|CanvasPattern') " 535 "@Creates('String|CanvasGradient|CanvasPattern')",
532 "@Returns('String|CanvasGradient|CanvasPattern')", 536 "@Returns('String|CanvasGradient|CanvasPattern')",
537 ],
533 538
534 # Methods returning Window can return a local window, or a cross-frame 539 # Methods returning Window can return a local window, or a cross-frame
535 # window (=Object) that needs wrapping. 540 # window (=Object) that needs wrapping.
536 'DOMWindow': 541 'DOMWindow': [
537 "@Creates('Window|=Object') @Returns('Window|=Object')", 542 "@Creates('Window|=Object')",
543 "@Returns('Window|=Object')",
544 ],
538 545
539 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", 546 'DOMWindow.openDatabase': [
547 "@Creates('Database')",
548 "@Creates('DatabaseSync')",
549 ],
540 550
541 # Cross-frame windows are EventTargets. 551 # Cross-frame windows are EventTargets.
542 '-EventTarget': 552 '-EventTarget': [
543 "@Creates('EventTarget|=Object') @Returns('EventTarget|=Object')", 553 "@Creates('EventTarget|=Object')",
554 "@Returns('EventTarget|=Object')",
555 ],
544 556
545 # To be in callback with the browser-created Event, we had to have called 557 # To be in callback with the browser-created Event, we had to have called
546 # addEventListener on the target, so we avoid 558 # addEventListener on the target, so we avoid
547 'Event.currentTarget': 559 'Event.currentTarget': [
548 "@Creates('Null') @Returns('EventTarget|=Object')", 560 "@Creates('Null')",
561 "@Returns('EventTarget|=Object')",
562 ],
549 563
550 # Only nodes in the DOM bubble and have target !== currentTarget. 564 # Only nodes in the DOM bubble and have target !== currentTarget.
551 'Event.target': 565 'Event.target': [
552 "@Creates('Node') @Returns('EventTarget|=Object')", 566 "@Creates('Node')",
567 "@Returns('EventTarget|=Object')",
568 ],
553 569
554 'MouseEvent.relatedTarget': 570 'MouseEvent.relatedTarget': [
555 "@Creates('Node') @Returns('EventTarget|=Object')", 571 "@Creates('Node')",
572 "@Returns('EventTarget|=Object')",
573 ],
556 574
557 # Touch targets are Elements in a Document, or the Document. 575 # Touch targets are Elements in a Document, or the Document.
558 'Touch.target': 576 'Touch.target': [
559 "@Creates('Element|Document') @Returns('Element|Document')", 577 "@Creates('Element|Document')",
578 "@Returns('Element|Document')",
579 ],
560 580
561 581
562 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", 582 'FileReader.result': ["@Creates('String|ArrayBuffer|Null')"],
563 583
564 # Rather than have the result of an IDBRequest as a union over all possible 584 # Rather than have the result of an IDBRequest as a union over all possible
565 # results, we mark the result as instantiating any classes, and mark 585 # results, we mark the result as instantiating any classes, and mark
566 # each operation with the classes that it could cause to be asynchronously 586 # each operation with the classes that it could cause to be asynchronously
567 # instantiated. 587 # instantiated.
568 'IDBRequest.result': "@Creates('Null')", 588 'IDBRequest.result': ["@Creates('Null')"],
569 589
570 # The source is usually a participant in the operation that generated the 590 # The source is usually a participant in the operation that generated the
571 # IDBRequest. 591 # IDBRequest.
572 'IDBRequest.source': "@Creates('Null')", 592 'IDBRequest.source': ["@Creates('Null')"],
573 593
574 'IDBFactory.open': "@Creates('Database')", 594 'IDBFactory.open': ["@Creates('Database')"],
575 595
576 'IDBObjectStore.put': "@_annotation_Creates_IDBKey", 596 'IDBObjectStore.put': ["@_annotation_Creates_IDBKey"],
577 'IDBObjectStore.add': "@_annotation_Creates_IDBKey", 597 'IDBObjectStore.add': ["@_annotation_Creates_IDBKey"],
578 'IDBObjectStore.get': "@annotation_Creates_SerializedScriptValue", 598 'IDBObjectStore.get': ["@annotation_Creates_SerializedScriptValue"],
579 'IDBObjectStore.openCursor': "@Creates('Cursor')", 599 'IDBObjectStore.openCursor': ["@Creates('Cursor')"],
580 600
581 'IDBIndex.get': "@annotation_Creates_SerializedScriptValue", 601 'IDBIndex.get': ["@annotation_Creates_SerializedScriptValue"],
582 'IDBIndex.getKey': 602 'IDBIndex.getKey': [
583 "@annotation_Creates_SerializedScriptValue " 603 "@annotation_Creates_SerializedScriptValue",
584 # The source is the object store behind the index. 604 # The source is the object store behind the index.
585 "@Creates('ObjectStore')", 605 "@Creates('ObjectStore')",
586 'IDBIndex.openCursor': "@Creates('Cursor')", 606 ],
587 'IDBIndex.openKeyCursor': "@Creates('Cursor')", 607 'IDBIndex.openCursor': ["@Creates('Cursor')"],
608 'IDBIndex.openKeyCursor': ["@Creates('Cursor')"],
588 609
589 'IDBCursorWithValue.value': 610 'IDBCursorWithValue.value': [
590 '@annotation_Creates_SerializedScriptValue ' 611 '@annotation_Creates_SerializedScriptValue',
591 '@annotation_Returns_SerializedScriptValue', 612 '@annotation_Returns_SerializedScriptValue',
613 ],
592 614
593 'IDBCursor.key': "@_annotation_Creates_IDBKey @_annotation_Returns_IDBKey", 615 'IDBCursor.key': [
616 "@_annotation_Creates_IDBKey",
617 "@_annotation_Returns_IDBKey",
618 ],
594 619
595 '+IDBRequest': "@Returns('Request') @Creates('Request')", 620 '+IDBRequest': [
621 "@Returns('Request')",
622 "@Creates('Request')",
623 ],
596 624
597 '+IDBOpenDBRequest': "@Returns('Request') @Creates('Request')", 625 '+IDBOpenDBRequest': [
598 '+IDBVersionChangeRequest': "@Returns('Request') @Creates('Request')", 626 "@Returns('Request')",
627 "@Creates('Request')",
628 ],
629 '+IDBVersionChangeRequest': [
630 "@Returns('Request')",
631 "@Creates('Request')",
632 ],
599 633
634 'MessageEvent.ports': ["@Creates('=List')"],
600 635
601 'MessageEvent.ports': "@Creates('=List')", 636 'MessageEvent.data': [
637 "@annotation_Creates_SerializedScriptValue",
638 "@annotation_Returns_SerializedScriptValue",
639 ],
640 'PopStateEvent.state': [
641 "@annotation_Creates_SerializedScriptValue",
642 "@annotation_Returns_SerializedScriptValue",
643 ],
644 'SerializedScriptValue': [
645 "@annotation_Creates_SerializedScriptValue",
646 "@annotation_Returns_SerializedScriptValue",
647 ],
602 648
603 'MessageEvent.data': 649 'SQLResultSetRowList.item': ["@Creates('=Object')"],
604 "@annotation_Creates_SerializedScriptValue "
605 "@annotation_Returns_SerializedScriptValue",
606 'PopStateEvent.state':
607 "@annotation_Creates_SerializedScriptValue "
608 "@annotation_Returns_SerializedScriptValue",
609 'SerializedScriptValue':
610 "@annotation_Creates_SerializedScriptValue "
611 "@annotation_Returns_SerializedScriptValue",
612 650
613 'SQLResultSetRowList.item': "@Creates('=Object')", 651 'XMLHttpRequest.response': [
614
615 'XMLHttpRequest.response':
616 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')", 652 "@Creates('ArrayBuffer|Blob|Document|=Object|=List|String|num')",
653 ],
617 } 654 }
618 655
619 # Placeholder to add experimental flag, implementation for this is 656 # Placeholder to add experimental flag, implementation for this is
620 # pending in a separate CL. 657 # pending in a separate CL.
621 dart_annotations = { 658 dart_annotations = {
622 'Element.webkitMatchesSelector': ['@Experimental()'], 659 'Element.webkitMatchesSelector': ['@Experimental()'],
623 } 660 }
624 661
625 _indexed_db_annotations = [ 662 _indexed_db_annotations = [
626 "@SupportedBrowser(SupportedBrowser.CHROME)", 663 "@SupportedBrowser(SupportedBrowser.CHROME)",
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", 751 "@SupportedBrowser(SupportedBrowser.CHROME, '25')",
715 "@Experimental()", 752 "@Experimental()",
716 ], 753 ],
717 'HTMLTrackElement': [ 754 'HTMLTrackElement': [
718 "@SupportedBrowser(SupportedBrowser.CHROME)", 755 "@SupportedBrowser(SupportedBrowser.CHROME)",
719 "@SupportedBrowser(SupportedBrowser.IE, '10')", 756 "@SupportedBrowser(SupportedBrowser.IE, '10')",
720 "@SupportedBrowser(SupportedBrowser.SAFARI)", 757 "@SupportedBrowser(SupportedBrowser.SAFARI)",
721 ], 758 ],
722 'IDBFactory': _indexed_db_annotations, 759 'IDBFactory': _indexed_db_annotations,
723 'IDBDatabase': _indexed_db_annotations, 760 'IDBDatabase': _indexed_db_annotations,
761 'MutationObserver': [
762 "@SupportedBrowser(SupportedBrowser.CHROME)",
763 "@SupportedBrowser(SupportedBrowser.FIREFOX)",
764 "@SupportedBrowser(SupportedBrowser.SAFARI)",
765 "@Experimental()",
766 ],
724 'NotificationCenter': _webkit_experimental_annotations, 767 'NotificationCenter': _webkit_experimental_annotations,
725 'Performance': _performance_annotations, 768 'Performance': _performance_annotations,
726 'ShadowRoot': [ 769 'ShadowRoot': [
727 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", 770 "@SupportedBrowser(SupportedBrowser.CHROME, '25')",
728 "@Experimental()", 771 "@Experimental()",
729 ], 772 ],
730 'WebSocket': _all_but_ie9_annotations, 773 'WebSocket': _all_but_ie9_annotations,
731 'WorkerContext.indexedDB': _indexed_db_annotations, 774 'WorkerContext.indexedDB': _indexed_db_annotations,
732 'WorkerContext.webkitRequestFileSystem': _file_system_annotations, 775 'WorkerContext.webkitRequestFileSystem': _file_system_annotations,
733 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations, 776 'WorkerContext.webkitRequestFileSystemSync': _file_system_annotations,
(...skipping 14 matching lines...) Expand all
748 if (dart_annotations.get(key) != None): 791 if (dart_annotations.get(key) != None):
749 annotations.extend(dart_annotations.get(key)) 792 annotations.extend(dart_annotations.get(key))
750 793
751 return annotations 794 return annotations
752 795
753 def FindDart2JSAnnotations(idl_type, interface_name, member_name): 796 def FindDart2JSAnnotations(idl_type, interface_name, member_name):
754 """ Finds all annotations for Dart2JS members- including annotations for 797 """ Finds all annotations for Dart2JS members- including annotations for
755 both dart2js and dartium. 798 both dart2js and dartium.
756 """ 799 """
757 annotations = FindCommonAnnotations(interface_name, member_name) 800 annotations = FindCommonAnnotations(interface_name, member_name)
758 if annotations:
759 annotations = ' '.join(annotations)
760 801
761 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) 802 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)
762 if ann2: 803 if ann2:
763 if annotations: 804 if annotations:
764 annotations = annotations + ' ' + ann2 805 annotations.extend(ann2)
765 else: 806 else:
766 annotations = ann2 807 annotations = ann2
767 return annotations 808 return annotations
768 809
769 def AnyConversionAnnotations(idl_type, interface_name, member_name): 810 def AnyConversionAnnotations(idl_type, interface_name, member_name):
770 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or 811 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or
771 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): 812 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)):
772 return True 813 return True
773 else: 814 else:
774 return False 815 return False
775 816
817 def FormatAnnotations(annotations, indentation):
818 if annotations:
819 newline = '\n%s' % indentation
820 result = newline.join(annotations) + newline
821 return result
822 return ''
823
776 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): 824 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name):
777 """ Finds dart2js-specific annotations. This does not include ones shared with 825 """ Finds dart2js-specific annotations. This does not include ones shared with
778 dartium. 826 dartium.
779 """ 827 """
780 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) 828 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name))
781 if ann1: 829 if ann1:
782 ann2 = dart2js_annotations.get('+' + idl_type) 830 ann2 = dart2js_annotations.get('+' + idl_type)
783 if ann2: 831 if ann2:
784 return ann2 + ' ' + ann1 832 return ann2 + ann1
785 ann2 = dart2js_annotations.get(idl_type) 833 ann2 = dart2js_annotations.get(idl_type)
786 if ann2: 834 if ann2:
787 return ann2 + ' ' + ann1 835 return ann2 + ann1
788 return ann1 836 return ann1
789 837
790 ann2 = dart2js_annotations.get('-' + idl_type) 838 ann2 = dart2js_annotations.get('-' + idl_type)
791 if ann2: 839 if ann2:
792 return ann2 840 return ann2
793 ann2 = dart2js_annotations.get(idl_type) 841 ann2 = dart2js_annotations.get(idl_type)
794 return ann2 842 return ann2
795 843
796 # ------------------------------------------------------------------------------ 844 # ------------------------------------------------------------------------------
797 845
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 self) 1368 self)
1321 1369
1322 if type_data.clazz == 'SVGTearOff': 1370 if type_data.clazz == 'SVGTearOff':
1323 dart_interface_name = self._renamer.RenameInterface( 1371 dart_interface_name = self._renamer.RenameInterface(
1324 self._database.GetInterface(type_name)) 1372 self._database.GetInterface(type_name))
1325 return SVGTearOffIDLTypeInfo( 1373 return SVGTearOffIDLTypeInfo(
1326 type_name, type_data, dart_interface_name, self) 1374 type_name, type_data, dart_interface_name, self)
1327 1375
1328 class_name = '%sIDLTypeInfo' % type_data.clazz 1376 class_name = '%sIDLTypeInfo' % type_data.clazz
1329 return globals()[class_name](type_name, type_data) 1377 return globals()[class_name](type_name, type_data)
OLDNEW
« no previous file with comments | « sdk/lib/web_audio/dart2js/web_audio_dart2js.dart ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698