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

Side by Side Diff: bindings/scripts/idl_definitions.py

Issue 959933002: Move IDLs to 39 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 5 years, 9 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 | « bindings/scripts/idl_compiler.py ('k') | bindings/scripts/idl_reader.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 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 IdlException < IdlInterface 55 IdlException < IdlInterface
56 (same contents as IdlInterface) 56 (same contents as IdlInterface)
57 57
58 TypedObject :: mixin for typedef resolution 58 TypedObject :: mixin for typedef resolution
59 59
60 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 60 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
61 """ 61 """
62 62
63 import abc 63 import abc
64 64
65 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType 65 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlN ullableType
66 66
67 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER'] 67 SPECIAL_KEYWORD_LIST = ['GETTER', 'SETTER', 'DELETER']
68 STANDARD_TYPEDEFS = { 68 STANDARD_TYPEDEFS = {
69 # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp 69 # http://www.w3.org/TR/WebIDL/#common-DOMTimeStamp
70 'DOMTimeStamp': 'unsigned long long', 70 'DOMTimeStamp': 'unsigned long long',
71 } 71 }
72 72
73 73
74 ################################################################################ 74 ################################################################################
75 # TypedObject (mixin for typedef resolution) 75 # TypedObject (mixin for typedef resolution)
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 630
631 631
632 ################################################################################ 632 ################################################################################
633 # Extended attributes 633 # Extended attributes
634 ################################################################################ 634 ################################################################################
635 635
636 def ext_attributes_node_to_extended_attributes(idl_name, node): 636 def ext_attributes_node_to_extended_attributes(idl_name, node):
637 """ 637 """
638 Returns: 638 Returns:
639 Dictionary of {ExtAttributeName: ExtAttributeValue}. 639 Dictionary of {ExtAttributeName: ExtAttributeValue}.
640 Value is usually a string, with three exceptions: 640 Value is usually a string, with these exceptions:
641 Constructors: value is a list of Arguments nodes, corresponding to 641 Constructors: value is a list of Arguments nodes, corresponding to
642 possible signatures of the constructor. 642 possible signatures of the constructor.
643 CustomConstructors: value is a list of Arguments nodes, corresponding to 643 CustomConstructors: value is a list of Arguments nodes, corresponding to
644 possible signatures of the custom constructor. 644 possible signatures of the custom constructor.
645 NamedConstructor: value is a Call node, corresponding to the single 645 NamedConstructor: value is a Call node, corresponding to the single
646 signature of the named constructor. 646 signature of the named constructor.
647 SetWrapperReferenceTo: value is an Arguments node.
647 """ 648 """
648 # Primarily just make a dictionary from the children. 649 # Primarily just make a dictionary from the children.
649 # The only complexity is handling various types of constructors: 650 # The only complexity is handling various types of constructors:
650 # Constructors and Custom Constructors can have duplicate entries due to 651 # Constructors and Custom Constructors can have duplicate entries due to
651 # overloading, and thus are stored in temporary lists. 652 # overloading, and thus are stored in temporary lists.
652 # However, Named Constructors cannot be overloaded, and thus do not have 653 # However, Named Constructors cannot be overloaded, and thus do not have
653 # a list. 654 # a list.
654 # FIXME: move Constructor logic into separate function, instead of modifying 655 # FIXME: move Constructor logic into separate function, instead of modifying
655 # extended attributes in-place. 656 # extended attributes in-place.
656 constructors = [] 657 constructors = []
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 749
749 ################################################################################ 750 ################################################################################
750 # Types 751 # Types
751 ################################################################################ 752 ################################################################################
752 753
753 def type_node_to_type(node): 754 def type_node_to_type(node):
754 children = node.GetChildren() 755 children = node.GetChildren()
755 if len(children) < 1 or len(children) > 2: 756 if len(children) < 1 or len(children) > 2:
756 raise ValueError('Type node expects 1 or 2 children (type + optional arr ay []), got %s (multi-dimensional arrays are not supported).' % len(children)) 757 raise ValueError('Type node expects 1 or 2 children (type + optional arr ay []), got %s (multi-dimensional arrays are not supported).' % len(children))
757 758
758 is_nullable = node.GetProperty('NULLABLE') or False # syntax: T? 759 base_type = type_node_inner_to_type(children[0])
759 type_node_child = children[0] 760
760 base_type = type_node_inner_to_type(type_node_child, is_nullable=is_nullable ) 761 if node.GetProperty('NULLABLE'):
762 base_type = IdlNullableType(base_type)
761 763
762 if len(children) == 2: 764 if len(children) == 2:
763 array_node = children[1] 765 array_node = children[1]
764 array_node_class = array_node.GetClass() 766 array_node_class = array_node.GetClass()
765 if array_node_class != 'Array': 767 if array_node_class != 'Array':
766 raise ValueError('Expected Array node as TypeSuffix, got %s node.' % array_node_class) 768 raise ValueError('Expected Array node as TypeSuffix, got %s node.' % array_node_class)
767 array_is_nullable = array_node.GetProperty('NULLABLE') or False 769 array_type = IdlArrayType(base_type)
768 return IdlArrayType(base_type, is_nullable=array_is_nullable) 770 if array_node.GetProperty('NULLABLE'):
771 return IdlNullableType(array_type)
772 return array_type
769 773
770 return base_type 774 return base_type
771 775
772 776
773 def type_node_inner_to_type(node, is_nullable=False): 777 def type_node_inner_to_type(node):
774 # FIXME: remove is_nullable once have IdlNullableType
775 node_class = node.GetClass() 778 node_class = node.GetClass()
776 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus 779 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus
777 # either a typedef shorthand (but not a Typedef declaration itself) or an 780 # either a typedef shorthand (but not a Typedef declaration itself) or an
778 # interface type. We do not distinguish these, and just use the type name. 781 # interface type. We do not distinguish these, and just use the type name.
779 if node_class in ['PrimitiveType', 'Typeref']: 782 if node_class in ['PrimitiveType', 'Typeref']:
780 # unrestricted syntax: unrestricted double | unrestricted float 783 # unrestricted syntax: unrestricted double | unrestricted float
781 is_unrestricted = node.GetProperty('UNRESTRICTED') or False 784 is_unrestricted = node.GetProperty('UNRESTRICTED') or False
782 return IdlType(node.GetName(), is_nullable=is_nullable, is_unrestricted= is_unrestricted) 785 return IdlType(node.GetName(), is_unrestricted=is_unrestricted)
783 elif node_class == 'Any': 786 elif node_class == 'Any':
784 return IdlType('any', is_nullable=is_nullable) 787 return IdlType('any')
785 elif node_class == 'Sequence': 788 elif node_class == 'Sequence':
786 sequence_is_nullable = node.GetProperty('NULLABLE') or False 789 return sequence_node_to_type(node)
787 return sequence_node_to_type(node, is_nullable=sequence_is_nullable)
788 elif node_class == 'UnionType': 790 elif node_class == 'UnionType':
789 return union_type_node_to_idl_union_type(node, is_nullable=is_nullable) 791 return union_type_node_to_idl_union_type(node)
790 raise ValueError('Unrecognized node class: %s' % node_class) 792 raise ValueError('Unrecognized node class: %s' % node_class)
791 793
792 794
793 def sequence_node_to_type(node, is_nullable=False): 795 def sequence_node_to_type(node):
794 children = node.GetChildren() 796 children = node.GetChildren()
795 if len(children) != 1: 797 if len(children) != 1:
796 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c hildren)) 798 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c hildren))
797 sequence_child = children[0] 799 sequence_child = children[0]
798 sequence_child_class = sequence_child.GetClass() 800 sequence_child_class = sequence_child.GetClass()
799 if sequence_child_class != 'Type': 801 if sequence_child_class != 'Type':
800 raise ValueError('Unrecognized node class: %s' % sequence_child_class) 802 raise ValueError('Unrecognized node class: %s' % sequence_child_class)
801 element_type = type_node_to_type(sequence_child) 803 element_type = type_node_to_type(sequence_child)
802 return IdlSequenceType(element_type, is_nullable=is_nullable) 804 sequence_type = IdlSequenceType(element_type)
805 if node.GetProperty('NULLABLE'):
806 return IdlNullableType(sequence_type)
807 return sequence_type
803 808
804 809
805 def typedef_node_to_type(node): 810 def typedef_node_to_type(node):
806 children = node.GetChildren() 811 children = node.GetChildren()
807 if len(children) != 1: 812 if len(children) != 1:
808 raise ValueError('Typedef node with %s children, expected 1' % len(child ren)) 813 raise ValueError('Typedef node with %s children, expected 1' % len(child ren))
809 child = children[0] 814 child = children[0]
810 child_class = child.GetClass() 815 child_class = child.GetClass()
811 if child_class != 'Type': 816 if child_class != 'Type':
812 raise ValueError('Unrecognized node class: %s' % child_class) 817 raise ValueError('Unrecognized node class: %s' % child_class)
813 return type_node_to_type(child) 818 return type_node_to_type(child)
814 819
815 820
816 def union_type_node_to_idl_union_type(node, is_nullable=False): 821 def union_type_node_to_idl_union_type(node):
817 member_types = [type_node_to_type(member_type_node) 822 member_types = [type_node_to_type(member_type_node)
818 for member_type_node in node.GetChildren()] 823 for member_type_node in node.GetChildren()]
819 return IdlUnionType(member_types, is_nullable=is_nullable) 824 return IdlUnionType(member_types)
OLDNEW
« no previous file with comments | « bindings/scripts/idl_compiler.py ('k') | bindings/scripts/idl_reader.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698