OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, 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 import os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
9 import idl_definitions | 9 import idl_definitions |
10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type | 10 from idl_types import IdlType, IdlNullableType, IdlUnionType, IdlArrayOrSequence
Type |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 '__delete__': "Deleter", | 51 '__delete__': "Deleter", |
52 } | 52 } |
53 | 53 |
54 class IDLNode(object): | 54 class IDLNode(object): |
55 """Base class for all IDL elements. | 55 """Base class for all IDL elements. |
56 IDLNode may contain various child nodes, and have properties. Examples | 56 IDLNode may contain various child nodes, and have properties. Examples |
57 of IDLNode are interfaces, interface members, function arguments, | 57 of IDLNode are interfaces, interface members, function arguments, |
58 etc. | 58 etc. |
59 """ | 59 """ |
60 | 60 |
61 def __init__(self, ast): | 61 def __init__(self, ast, id=None): |
62 """Initializes an IDLNode from a PegParser AST output.""" | 62 """Initializes an IDLNode from a PegParser AST output.""" |
63 self.id = self._find_first(ast, 'Id') if ast is not None else None | 63 if ast: |
64 | 64 self.id = self._find_first(ast, 'Id') if ast is not None else None |
| 65 else: |
| 66 # Support synthesized IDLNode created w/o an AST (e.g., setlike support). |
| 67 self.id = id |
65 | 68 |
66 def __repr__(self): | 69 def __repr__(self): |
67 """Generates string of the form <class id extra extra ... 0x12345678>.""" | 70 """Generates string of the form <class id extra extra ... 0x12345678>.""" |
68 extras = self._extra_repr() | 71 extras = self._extra_repr() |
69 if isinstance(extras, list): | 72 if isinstance(extras, list): |
70 extras = ' '.join([str(e) for e in extras]) | 73 extras = ' '.join([str(e) for e in extras]) |
71 try: | 74 try: |
72 if self.id: | 75 if self.id: |
73 return '<%s %s 0x%x>' % ( | 76 return '<%s %s 0x%x>' % ( |
74 type(self).__name__, | 77 type(self).__name__, |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 self.arguments = [] | 566 self.arguments = [] |
564 for argument in arg_list_ast: | 567 for argument in arg_list_ast: |
565 self.arguments.append(IDLArgument(argument)) | 568 self.arguments.append(IDLArgument(argument)) |
566 else: | 569 else: |
567 self.arguments = self._convert_all(arg_list_ast, 'Argument', IDLArgument) | 570 self.arguments = self._convert_all(arg_list_ast, 'Argument', IDLArgument) |
568 | 571 |
569 | 572 |
570 class IDLType(IDLNode): | 573 class IDLType(IDLNode): |
571 """IDLType is used to describe constants, attributes and operations' | 574 """IDLType is used to describe constants, attributes and operations' |
572 return and input types. IDLType matches AST labels such as ScopedName, | 575 return and input types. IDLType matches AST labels such as ScopedName, |
573 StringType, VoidType, IntegerType, etc.""" | 576 StringType, VoidType, IntegerType, etc. |
| 577 NOTE: AST of None implies synthesize IDLType the id is passed in used by |
| 578 setlike.""" |
574 | 579 |
575 def __init__(self, ast): | 580 def __init__(self, ast, id=None): |
576 global _unions_to_any | 581 global _unions_to_any |
577 | 582 |
578 IDLNode.__init__(self, ast) | 583 IDLNode.__init__(self, ast, id) |
579 | 584 |
580 if ast: | 585 if not ast: |
581 self.nullable = self._has(ast, 'Nullable') | 586 # Support synthesized IDLType with no AST (e.g., setlike support). |
582 # Search for a 'ScopedName' or any label ending with 'Type'. | 587 return |
583 if isinstance(ast, list): | 588 |
584 self.id = self._find_first(ast, 'ScopedName') | 589 self.nullable = self._has(ast, 'Nullable') |
585 if not self.id: | 590 # Search for a 'ScopedName' or any label ending with 'Type'. |
586 # FIXME: use regexp search instead | 591 if isinstance(ast, list): |
587 def findType(ast): | 592 self.id = self._find_first(ast, 'ScopedName') |
588 for label, childAst in ast: | 593 if not self.id: |
589 if label.endswith('Type'): | 594 # FIXME: use regexp search instead |
590 type = self._label_to_type(label, ast) | 595 def findType(ast): |
591 if type != 'sequence': | 596 for label, childAst in ast: |
592 return type | 597 if label.endswith('Type'): |
593 type_ast = self._find_first(childAst, 'Type') | 598 type = self._label_to_type(label, ast) |
594 if not type_ast: | 599 if type != 'sequence': |
595 return type | 600 return type |
596 return 'sequence<%s>' % findType(type_ast) | 601 type_ast = self._find_first(childAst, 'Type') |
597 raise Exception('No type declaration found in %s' % ast) | 602 if not type_ast: |
598 self.id = findType(ast) | 603 return type |
599 # TODO(terry): Remove array_modifiers id has [] appended, keep for old | 604 return 'sequence<%s>' % findType(type_ast) |
600 # parsing. | 605 raise Exception('No type declaration found in %s' % ast) |
601 array_modifiers = self._find_first(ast, 'ArrayModifiers') | 606 self.id = findType(ast) |
602 if array_modifiers: | 607 # TODO(terry): Remove array_modifiers id has [] appended, keep for old |
603 self.id += array_modifiers | 608 # parsing. |
604 elif isinstance(ast, tuple): | 609 array_modifiers = self._find_first(ast, 'ArrayModifiers') |
605 (label, value) = ast | 610 if array_modifiers: |
606 if label == 'ScopedName': | 611 self.id += array_modifiers |
607 self.id = value | 612 elif isinstance(ast, tuple): |
| 613 (label, value) = ast |
| 614 if label == 'ScopedName': |
| 615 self.id = value |
| 616 else: |
| 617 self.id = self._label_to_type(label, ast) |
| 618 elif isinstance(ast, str): |
| 619 self.id = ast |
| 620 # New blink handling. |
| 621 elif ast.__module__ == "idl_types": |
| 622 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) or
\ |
| 623 isinstance(ast, IdlNullableType): |
| 624 if isinstance(ast, IdlNullableType) and ast.inner_type.is_union_type: |
| 625 # Report of union types mapped to any. |
| 626 if not(self.id in _unions_to_any): |
| 627 _unions_to_any.append(self.id) |
| 628 # TODO(terry): For union types use any otherwise type is unionType is |
| 629 # not found and is removed during merging. |
| 630 self.id = 'any' |
608 else: | 631 else: |
609 self.id = self._label_to_type(label, ast) | 632 type_name = str(ast) |
610 elif isinstance(ast, str): | 633 # TODO(terry): For now don't handle unrestricted types see |
611 self.id = ast | 634 # https://code.google.com/p/chromium/issues/detail?id=354
298 |
612 # New blink handling. | 635 type_name = type_name.replace('unrestricted ', '', 1); |
613 elif ast.__module__ == "idl_types": | 636 |
614 if isinstance(ast, IdlType) or isinstance(ast, IdlArrayOrSequenceType) o
r \ | 637 # TODO(terry): Handled USVString as a DOMString. |
615 isinstance(ast, IdlNullableType): | 638 type_name = type_name.replace('USVString', 'DOMString', 1) |
616 if isinstance(ast, IdlNullableType) and ast.inner_type.is_union_type: | 639 |
617 # Report of union types mapped to any. | 640 # TODO(terry); WindowTimers setInterval/setTimeout overloads with a |
618 if not(self.id in _unions_to_any): | 641 # Function type - map to any until the IDL uses union. |
619 _unions_to_any.append(self.id) | 642 type_name = type_name.replace('Function', 'any', 1) |
620 # TODO(terry): For union types use any otherwise type is unionType i
s | 643 |
621 # not found and is removed during merging. | 644 self.id = type_name |
622 self.id = 'any' | 645 else: |
623 else: | 646 # IdlUnionType |
624 type_name = str(ast) | 647 if ast.is_union_type: |
625 # TODO(terry): For now don't handle unrestricted types see | 648 if not(self.id in _unions_to_any): |
626 # https://code.google.com/p/chromium/issues/detail?id=3
54298 | 649 _unions_to_any.append(self.id) |
627 type_name = type_name.replace('unrestricted ', '', 1); | 650 # TODO(terry): For union types use any otherwise type is unionType is |
628 | 651 # not found and is removed during merging. |
629 # TODO(terry): Handled USVString as a DOMString. | 652 self.id = 'any' |
630 type_name = type_name.replace('USVString', 'DOMString', 1) | 653 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', |
631 | 654 # 'typedef (Type1 or Type2) UnionType' |
632 # TODO(terry); WindowTimers setInterval/setTimeout overloads with a | 655 # Is a problem we need to extend IDLType and IDLTypeDef to handle more |
633 # Function type - map to any until the IDL uses union. | 656 # than one type. |
634 type_name = type_name.replace('Function', 'any', 1) | 657 # |
635 | 658 # Also for typedef's e.g., |
636 self.id = type_name | 659 # typedef (Type1 or Type2) UnionType |
637 else: | 660 # should consider synthesizing a new interface (e.g., UnionType) that'
s |
638 # IdlUnionType | 661 # both Type1 and Type2. |
639 if ast.is_union_type: | 662 if not self.id: |
640 if not(self.id in _unions_to_any): | 663 print '>>>> __module__ %s' % ast.__module__ |
641 _unions_to_any.append(self.id) | 664 raise SyntaxError('Could not parse type %s' % (ast)) |
642 # TODO(terry): For union types use any otherwise type is unionType i
s | |
643 # not found and is removed during merging. | |
644 self.id = 'any' | |
645 # TODO(terry): Any union type e.g. 'type1 or type2 or type2', | |
646 # 'typedef (Type1 or Type2) UnionType' | |
647 # Is a problem we need to extend IDLType and IDLTypeDef to handle mo
re | |
648 # than one type. | |
649 # | |
650 # Also for typedef's e.g., | |
651 # typedef (Type1 or Type2) UnionType | |
652 # should consider synthesizing a new interface (e.g., UnionType) tha
t's | |
653 # both Type1 and Type2. | |
654 if not self.id: | |
655 print '>>>> __module__ %s' % ast.__module__ | |
656 raise SyntaxError('Could not parse type %s' % (ast)) | |
657 | 665 |
658 def _label_to_type(self, label, ast): | 666 def _label_to_type(self, label, ast): |
659 if label == 'LongLongType': | 667 if label == 'LongLongType': |
660 label = 'long long' | 668 label = 'long long' |
661 elif label.endswith('Type'): | 669 elif label.endswith('Type'): |
662 # Omit 'Type' suffix and lowercase the rest. | 670 # Omit 'Type' suffix and lowercase the rest. |
663 label = '%s%s' % (label[0].lower(), label[1:-4]) | 671 label = '%s%s' % (label[0].lower(), label[1:-4]) |
664 | 672 |
665 # Add unsigned qualifier. | 673 # Add unsigned qualifier. |
666 if self._has(ast, 'Unsigned'): | 674 if self._has(ast, 'Unsigned'): |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 def __init__(self, ast=None, js_name=None): | 718 def __init__(self, ast=None, js_name=None): |
711 IDLDictNode.__init__(self, ast) | 719 IDLDictNode.__init__(self, ast) |
712 self.id = None | 720 self.id = None |
713 if not ast: | 721 if not ast: |
714 return | 722 return |
715 for member in self._find_all(ast, 'Member'): | 723 for member in self._find_all(ast, 'Member'): |
716 name = self._find_first(member, 'Id') | 724 name = self._find_first(member, 'Id') |
717 value = IDLDictionaryMember(member, js_name) | 725 value = IDLDictionaryMember(member, js_name) |
718 self[name] = value | 726 self[name] = value |
719 | 727 |
| 728 def generate_operation(interface_name, result_type_name, oper_name, arguments): |
| 729 """ Synthesize an IDLOperation with no AST used for support of setlike.""" |
| 730 """ Arguments is a list of argument where each argument is: |
| 731 [IDLType, argument_name, optional_boolean] """ |
| 732 |
| 733 syn_op = IDLOperation(None, interface_name, oper_name) |
| 734 |
| 735 syn_op.type = IDLType(None, result_type_name) |
| 736 syn_op.type = resolveTypedef(syn_op.type) |
| 737 |
| 738 for argument in arguments: |
| 739 arg = IDLArgument(None, argument[1]); |
| 740 arg.type = argument[0]; |
| 741 arg.optional = argument[2] if len(argument) > 2 else False |
| 742 syn_op.arguments.append(arg) |
| 743 |
| 744 return syn_op |
| 745 |
| 746 def generate_setLike_operations_properties(interface, set_like): |
| 747 """ |
| 748 Need to create (in our database) a number of operations. This is a new IDL |
| 749 syntax, the implied operations for a set now use setlike<T> where T is a known |
| 750 type e.g., setlike<FontFace> setlike implies these operations are generated: |
| 751 |
| 752 void forEach(any callback, optional any thisArg); |
| 753 boolean has(FontFace fontFace); |
| 754 boolean has(FontFace fontFace); |
| 755 |
| 756 if setlike is not read-only these operations are generated: |
| 757 |
| 758 FontFaceSet add(FontFace value); |
| 759 boolean delete(FontFace value); |
| 760 void clear(); |
| 761 """ |
| 762 setlike_ops = [] |
| 763 """ |
| 764 Need to create a typedef for a function callback e.g., |
| 765 a setlike will need a callback that has the proper args in FontFaceSet that is |
| 766 three arguments, etc. |
| 767 |
| 768 typedef void FontFaceSetForEachCallback( |
| 769 FontFace fontFace, FontFace fontFaceAgain, FontFaceSet set); |
| 770 |
| 771 void forEach(FontFaceSetForEachCallback callback, [Object thisArg]); |
| 772 """ |
| 773 callback_name = '%sForEachCallback' % interface.id |
| 774 set_op = generate_operation(interface.id, 'void', 'forEach', |
| 775 [[IDLType(None, callback_name), 'callback'], |
| 776 [IDLType(None, 'any'), 'thisArg', True]]) |
| 777 setlike_ops.append(set_op) |
| 778 |
| 779 set_op = generate_operation(interface.id, 'boolean', 'has', |
| 780 [[IDLType(None, set_like.value_type.base_type), 'a
rg']]) |
| 781 setlike_ops.append(set_op) |
| 782 |
| 783 if not set_like.is_read_only: |
| 784 set_op = generate_operation(interface.id, interface.id, 'add', |
| 785 [[IDLType(None, set_like.value_type.base_type),
'arg']]) |
| 786 setlike_ops.append(set_op) |
| 787 set_op = generate_operation(interface.id, 'boolean', 'delete', |
| 788 [[IDLType(None, set_like.value_type.base_type),
'arg']]) |
| 789 setlike_ops.append(set_op) |
| 790 set_op = generate_operation(interface.id, 'void', 'clear', []) |
| 791 setlike_ops.append(set_op) |
| 792 |
| 793 return setlike_ops |
720 | 794 |
721 class IDLInterface(IDLNode): | 795 class IDLInterface(IDLNode): |
722 """IDLInterface node contains operations, attributes, constants, | 796 """IDLInterface node contains operations, attributes, constants, |
723 as well as parent references.""" | 797 as well as parent references.""" |
724 | 798 |
725 def __init__(self, ast): | 799 def __init__(self, ast): |
726 IDLNode.__init__(self, ast) | 800 IDLNode.__init__(self, ast) |
727 self._convert_ext_attrs(ast) | 801 self._convert_ext_attrs(ast) |
728 self._convert_annotations(ast) | 802 self._convert_annotations(ast) |
729 | 803 |
730 self.parents = self._convert_all(ast, 'ParentInterface', | 804 self.parents = self._convert_all(ast, 'ParentInterface', |
731 IDLParentInterface) | 805 IDLParentInterface) |
732 | 806 |
733 javascript_interface_name = self.ext_attrs.get('InterfaceName', self.id) | 807 javascript_interface_name = self.ext_attrs.get('InterfaceName', self.id) |
734 self.javascript_binding_name = javascript_interface_name | 808 self.javascript_binding_name = javascript_interface_name |
735 self.doc_js_name = javascript_interface_name | 809 self.doc_js_name = javascript_interface_name |
736 | 810 |
737 if not (self._find_first(ast, 'Callback') is None): | 811 if not (self._find_first(ast, 'Callback') is None): |
738 self.ext_attrs['Callback'] = None | 812 self.ext_attrs['Callback'] = None |
739 if not (self._find_first(ast, 'Partial') is None): | 813 if not (self._find_first(ast, 'Partial') is None): |
740 self.is_supplemental = True | 814 self.is_supplemental = True |
741 self.ext_attrs['DartSupplemental'] = None | 815 self.ext_attrs['DartSupplemental'] = None |
742 | 816 |
743 self.operations = self._convert_all(ast, 'Operation', | 817 self.operations = self._convert_all(ast, 'Operation', |
744 lambda ast: IDLOperation(ast, self.doc_js_name)) | 818 lambda ast: IDLOperation(ast, self.doc_js_name)) |
| 819 |
| 820 if ast.setlike: |
| 821 setlike_ops = generate_setLike_operations_properties(self, ast.setlike) |
| 822 for op in setlike_ops: |
| 823 self.operations.append(op) |
| 824 |
745 self.attributes = self._convert_all(ast, 'Attribute', | 825 self.attributes = self._convert_all(ast, 'Attribute', |
746 lambda ast: IDLAttribute(ast, self.doc_js_name)) | 826 lambda ast: IDLAttribute(ast, self.doc_js_name)) |
747 self.constants = self._convert_all(ast, 'Const', | 827 self.constants = self._convert_all(ast, 'Const', |
748 lambda ast: IDLConstant(ast, self.doc_js_name)) | 828 lambda ast: IDLConstant(ast, self.doc_js_name)) |
749 self.is_supplemental = 'DartSupplemental' in self.ext_attrs | 829 self.is_supplemental = 'DartSupplemental' in self.ext_attrs |
750 self.is_no_interface_object = 'NoInterfaceObject' in self.ext_attrs | 830 self.is_no_interface_object = 'NoInterfaceObject' in self.ext_attrs |
751 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. | 831 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. |
752 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ | 832 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ |
753 'DartSuppress' in self.ext_attrs | 833 'DartSuppress' in self.ext_attrs |
754 | 834 |
755 | |
756 def reset_id(self, new_id): | 835 def reset_id(self, new_id): |
757 """Reset the id of the Interface and corresponding the JS names.""" | 836 """Reset the id of the Interface and corresponding the JS names.""" |
758 if self.id != new_id: | 837 if self.id != new_id: |
759 self.id = new_id | 838 self.id = new_id |
760 self.doc_js_name = new_id | 839 self.doc_js_name = new_id |
761 self.javascript_binding_name = new_id | 840 self.javascript_binding_name = new_id |
762 for member in self.operations: | 841 for member in self.operations: |
763 member.doc_js_interface_name = new_id | 842 member.doc_js_interface_name = new_id |
764 for member in self.attributes: | 843 for member in self.attributes: |
765 member.doc_js_interface_name = new_id | 844 member.doc_js_interface_name = new_id |
(...skipping 12 matching lines...) Expand all Loading... |
778 """This IDLNode specialization is for 'Interface Child : Parent {}' | 857 """This IDLNode specialization is for 'Interface Child : Parent {}' |
779 declarations.""" | 858 declarations.""" |
780 def __init__(self, ast): | 859 def __init__(self, ast): |
781 IDLNode.__init__(self, ast) | 860 IDLNode.__init__(self, ast) |
782 self._convert_annotations(ast) | 861 self._convert_annotations(ast) |
783 self.type = self._convert_first(ast, 'InterfaceType', IDLType) | 862 self.type = self._convert_first(ast, 'InterfaceType', IDLType) |
784 | 863 |
785 | 864 |
786 class IDLMember(IDLNode): | 865 class IDLMember(IDLNode): |
787 """A base class for constants, attributes and operations.""" | 866 """A base class for constants, attributes and operations.""" |
788 | 867 def __init__(self, ast, doc_js_interface_name, member_id=None): |
789 def __init__(self, ast, doc_js_interface_name): | 868 if ast: |
790 IDLNode.__init__(self, ast) | 869 IDLNode.__init__(self, ast) |
| 870 else: |
| 871 # The ast is None to support synthesizing an IDLMember, member_id is only |
| 872 # used when ast is None. |
| 873 IDLNode.__init__(self, ast, member_id) |
| 874 self.type = None |
| 875 self.doc_js_interface_name = doc_js_interface_name |
| 876 return |
791 | 877 |
792 self.type = self._convert_first(ast, 'Type', IDLType) | 878 self.type = self._convert_first(ast, 'Type', IDLType) |
793 self.type = resolveTypedef(self.type) | 879 self.type = resolveTypedef(self.type) |
794 | 880 |
795 self._convert_ext_attrs(ast) | 881 self._convert_ext_attrs(ast) |
796 self._convert_annotations(ast) | 882 self._convert_annotations(ast) |
797 self.doc_js_interface_name = doc_js_interface_name | 883 self.doc_js_interface_name = doc_js_interface_name |
798 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. | 884 # TODO(terry): Can eliminate Suppressed when we're only using blink parser. |
799 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ | 885 self.is_fc_suppressed = 'Suppressed' in self.ext_attrs or \ |
800 'DartSuppress' in self.ext_attrs | 886 'DartSuppress' in self.ext_attrs |
801 self.is_static = self._has(ast, 'Static') | 887 self.is_static = self._has(ast, 'Static') |
802 | 888 |
803 class IDLOperation(IDLMember): | 889 class IDLOperation(IDLMember): |
804 """IDLNode specialization for 'type name(args)' declarations.""" | 890 """IDLNode specialization for 'type name(args)' declarations.""" |
805 def __init__(self, ast, doc_js_interface_name): | 891 def __init__(self, ast, doc_js_interface_name, id=None): |
806 IDLMember.__init__(self, ast, doc_js_interface_name) | 892 IDLMember.__init__(self, ast, doc_js_interface_name, id) |
| 893 |
| 894 if not ast: |
| 895 # Synthesize an IDLOperation with no ast used for setlike. |
| 896 self.ext_attrs = IDLExtAttrs() |
| 897 self.annotations = IDLAnnotations() |
| 898 self.is_fc_suppressed = False |
| 899 self.specials = [] |
| 900 self.is_static = False |
| 901 self.arguments = [] |
| 902 return; |
807 | 903 |
808 self.type = self._convert_first(ast, 'ReturnType', IDLType) | 904 self.type = self._convert_first(ast, 'ReturnType', IDLType) |
809 self.type = resolveTypedef(self.type) | 905 self.type = resolveTypedef(self.type) |
810 | 906 |
811 self.arguments = self._convert_all(ast, 'Argument', IDLArgument) | 907 self.arguments = self._convert_all(ast, 'Argument', IDLArgument) |
812 self.specials = self._find_all(ast, 'Special') | 908 self.specials = self._find_all(ast, 'Special') |
813 # Special case: there are getters of the form | 909 # Special case: there are getters of the form |
814 # getter <ReturnType>(args). For now force the name to be __getter__, | 910 # getter <ReturnType>(args). For now force the name to be __getter__, |
815 # but it should be operator[] later. | 911 # but it should be operator[] later. |
816 if self.id is None: | 912 if self.id is None: |
(...skipping 13 matching lines...) Expand all Loading... |
830 elif self.specials == ['deleter']: | 926 elif self.specials == ['deleter']: |
831 self.id = '__delete__' | 927 self.id = '__delete__' |
832 else: | 928 else: |
833 raise Exception('Cannot handle %s: operation has no id' % ast) | 929 raise Exception('Cannot handle %s: operation has no id' % ast) |
834 | 930 |
835 if len(self.arguments) >= 1 and (self.id in _operation_suffix_map) and not
self.ext_attrs.get('ImplementedAs'): | 931 if len(self.arguments) >= 1 and (self.id in _operation_suffix_map) and not
self.ext_attrs.get('ImplementedAs'): |
836 arg = self.arguments[0] | 932 arg = self.arguments[0] |
837 operation_category = 'Named' if arg.type.id == 'DOMString' else 'Indexed
' | 933 operation_category = 'Named' if arg.type.id == 'DOMString' else 'Indexed
' |
838 self.ext_attrs.setdefault('ImplementedAs', 'anonymous%s%s' % (operation_
category, _operation_suffix_map[self.id])) | 934 self.ext_attrs.setdefault('ImplementedAs', 'anonymous%s%s' % (operation_
category, _operation_suffix_map[self.id])) |
839 | 935 |
| 936 def __repr__(self): |
| 937 return '<IDLOperation(id = %s)>' % (self.id) |
| 938 |
840 def _extra_repr(self): | 939 def _extra_repr(self): |
841 return [self.arguments] | 940 return [self.arguments] |
842 | 941 |
843 def SameSignatureAs(self, operation): | 942 def SameSignatureAs(self, operation): |
844 if self.type != operation.type: | 943 if self.type != operation.type: |
845 return False | 944 return False |
846 return [a.type for a in self.arguments] == [a.type for a in operation.argume
nts] | 945 return [a.type for a in self.arguments] == [a.type for a in operation.argume
nts] |
847 | 946 |
848 class IDLAttribute(IDLMember): | 947 class IDLAttribute(IDLMember): |
849 """IDLNode specialization for 'attribute type name' declarations.""" | 948 """IDLNode specialization for 'attribute type name' declarations.""" |
(...skipping 10 matching lines...) Expand all Loading... |
860 | 959 |
861 class IDLConstant(IDLMember): | 960 class IDLConstant(IDLMember): |
862 """IDLNode specialization for 'const type name = value' declarations.""" | 961 """IDLNode specialization for 'const type name = value' declarations.""" |
863 def __init__(self, ast, doc_js_interface_name): | 962 def __init__(self, ast, doc_js_interface_name): |
864 IDLMember.__init__(self, ast, doc_js_interface_name) | 963 IDLMember.__init__(self, ast, doc_js_interface_name) |
865 self.value = self._find_first(ast, 'ConstExpr') | 964 self.value = self._find_first(ast, 'ConstExpr') |
866 | 965 |
867 | 966 |
868 class IDLArgument(IDLNode): | 967 class IDLArgument(IDLNode): |
869 """IDLNode specialization for operation arguments.""" | 968 """IDLNode specialization for operation arguments.""" |
870 def __init__(self, ast): | 969 def __init__(self, ast, id=None): |
871 IDLNode.__init__(self, ast) | 970 if ast: |
| 971 IDLNode.__init__(self, ast) |
| 972 else: |
| 973 # Synthesize an IDLArgument with no ast used for setlike. |
| 974 IDLNode.__init__(self, ast, id) |
| 975 self.ext_attrs = IDLExtAttrs() |
| 976 self.default_value = None |
| 977 self.default_value_is_null = False |
| 978 return |
872 | 979 |
873 self.default_value = None | 980 self.default_value = None |
874 self.default_value_is_null = False | 981 self.default_value_is_null = False |
875 # Handle the 'argType arg = default'. IDL syntax changed from | 982 # Handle the 'argType arg = default'. IDL syntax changed from |
876 # [default=NullString]. | 983 # [default=NullString]. |
877 if not isinstance(ast, list): | 984 if not isinstance(ast, list): |
878 if isinstance(ast.default_value, idl_definitions.IdlLiteral) and ast.defau
lt_value: | 985 if isinstance(ast.default_value, idl_definitions.IdlLiteral) and ast.defau
lt_value: |
879 self.default_value = ast.default_value.value | 986 self.default_value = ast.default_value.value |
880 self.default_value_is_null = ast.default_value.is_null | 987 self.default_value_is_null = ast.default_value.is_null |
881 elif 'Default' in ast.extended_attributes: | 988 elif 'Default' in ast.extended_attributes: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 """IDLDictNode specialization for one annotation.""" | 1038 """IDLDictNode specialization for one annotation.""" |
932 def __init__(self, ast=None): | 1039 def __init__(self, ast=None): |
933 IDLDictNode.__init__(self, ast) | 1040 IDLDictNode.__init__(self, ast) |
934 self.id = None | 1041 self.id = None |
935 if not ast: | 1042 if not ast: |
936 return | 1043 return |
937 for arg in self._find_all(ast, 'AnnotationArg'): | 1044 for arg in self._find_all(ast, 'AnnotationArg'): |
938 name = self._find_first(arg, 'Id') | 1045 name = self._find_first(arg, 'Id') |
939 value = self._find_first(arg, 'AnnotationArgValue') | 1046 value = self._find_first(arg, 'AnnotationArgValue') |
940 self[name] = value | 1047 self[name] = value |
OLD | NEW |