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

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

Issue 474173002: IDL: Use IdlNullableType wrapper to represent nullable types (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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
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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 748
749 ################################################################################ 749 ################################################################################
750 # Types 750 # Types
751 ################################################################################ 751 ################################################################################
752 752
753 def type_node_to_type(node): 753 def type_node_to_type(node):
754 children = node.GetChildren() 754 children = node.GetChildren()
755 if len(children) < 1 or len(children) > 2: 755 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)) 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 757
758 is_nullable = node.GetProperty('NULLABLE') or False # syntax: T? 758 base_type = type_node_inner_to_type(children[0])
759 type_node_child = children[0] 759
760 base_type = type_node_inner_to_type(type_node_child, is_nullable=is_nullable ) 760 if node.GetProperty('NULLABLE'):
761 base_type = IdlNullableType(base_type)
761 762
762 if len(children) == 2: 763 if len(children) == 2:
763 array_node = children[1] 764 array_node = children[1]
764 array_node_class = array_node.GetClass() 765 array_node_class = array_node.GetClass()
765 if array_node_class != 'Array': 766 if array_node_class != 'Array':
766 raise ValueError('Expected Array node as TypeSuffix, got %s node.' % array_node_class) 767 raise ValueError('Expected Array node as TypeSuffix, got %s node.' % array_node_class)
767 array_is_nullable = array_node.GetProperty('NULLABLE') or False 768 array_type = IdlArrayType(base_type)
768 return IdlArrayType(base_type, is_nullable=array_is_nullable) 769 if array_node.GetProperty('NULLABLE'):
770 return IdlNullableType(array_type)
771 return array_type
769 772
770 return base_type 773 return base_type
771 774
772 775
773 def type_node_inner_to_type(node, is_nullable=False): 776 def type_node_inner_to_type(node):
774 # FIXME: remove is_nullable once have IdlNullableType
775 node_class = node.GetClass() 777 node_class = node.GetClass()
776 # Note Type*r*ef, not Typedef, meaning the type is an identifier, thus 778 # 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 779 # 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. 780 # interface type. We do not distinguish these, and just use the type name.
779 if node_class in ['PrimitiveType', 'Typeref']: 781 if node_class in ['PrimitiveType', 'Typeref']:
780 # unrestricted syntax: unrestricted double | unrestricted float 782 # unrestricted syntax: unrestricted double | unrestricted float
781 is_unrestricted = node.GetProperty('UNRESTRICTED') or False 783 is_unrestricted = node.GetProperty('UNRESTRICTED') or False
782 return IdlType(node.GetName(), is_nullable=is_nullable, is_unrestricted= is_unrestricted) 784 return IdlType(node.GetName(), is_unrestricted=is_unrestricted)
783 elif node_class == 'Any': 785 elif node_class == 'Any':
784 return IdlType('any', is_nullable=is_nullable) 786 return IdlType('any')
785 elif node_class == 'Sequence': 787 elif node_class == 'Sequence':
786 sequence_is_nullable = node.GetProperty('NULLABLE') or False 788 return sequence_node_to_type(node)
787 return sequence_node_to_type(node, is_nullable=sequence_is_nullable)
788 elif node_class == 'UnionType': 789 elif node_class == 'UnionType':
789 return union_type_node_to_idl_union_type(node, is_nullable=is_nullable) 790 return union_type_node_to_idl_union_type(node)
790 raise ValueError('Unrecognized node class: %s' % node_class) 791 raise ValueError('Unrecognized node class: %s' % node_class)
791 792
792 793
793 def sequence_node_to_type(node, is_nullable=False): 794 def sequence_node_to_type(node):
794 children = node.GetChildren() 795 children = node.GetChildren()
795 if len(children) != 1: 796 if len(children) != 1:
796 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c hildren)) 797 raise ValueError('Sequence node expects exactly 1 child, got %s' % len(c hildren))
797 sequence_child = children[0] 798 sequence_child = children[0]
798 sequence_child_class = sequence_child.GetClass() 799 sequence_child_class = sequence_child.GetClass()
799 if sequence_child_class != 'Type': 800 if sequence_child_class != 'Type':
800 raise ValueError('Unrecognized node class: %s' % sequence_child_class) 801 raise ValueError('Unrecognized node class: %s' % sequence_child_class)
801 element_type = type_node_to_type(sequence_child) 802 element_type = type_node_to_type(sequence_child)
haraken 2014/08/15 07:43:57 Nit: element_type => sequence_type (or remove elem
Jens Widell 2014/08/15 08:00:08 It *is* the element type of the sequence (i.e. seq
802 return IdlSequenceType(element_type, is_nullable=is_nullable) 803 sequence_type = IdlSequenceType(element_type)
804 if node.GetProperty('NULLABLE'):
805 return IdlNullableType(sequence_type)
806 return sequence_type
803 807
804 808
805 def typedef_node_to_type(node): 809 def typedef_node_to_type(node):
806 children = node.GetChildren() 810 children = node.GetChildren()
807 if len(children) != 1: 811 if len(children) != 1:
808 raise ValueError('Typedef node with %s children, expected 1' % len(child ren)) 812 raise ValueError('Typedef node with %s children, expected 1' % len(child ren))
809 child = children[0] 813 child = children[0]
810 child_class = child.GetClass() 814 child_class = child.GetClass()
811 if child_class != 'Type': 815 if child_class != 'Type':
812 raise ValueError('Unrecognized node class: %s' % child_class) 816 raise ValueError('Unrecognized node class: %s' % child_class)
813 return type_node_to_type(child) 817 return type_node_to_type(child)
814 818
815 819
816 def union_type_node_to_idl_union_type(node, is_nullable=False): 820 def union_type_node_to_idl_union_type(node):
817 member_types = [type_node_to_type(member_type_node) 821 member_types = [type_node_to_type(member_type_node)
818 for member_type_node in node.GetChildren()] 822 for member_type_node in node.GetChildren()]
819 return IdlUnionType(member_types, is_nullable=is_nullable) 823 return IdlUnionType(member_types)
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/scripts/idl_types.py » ('j') | Source/bindings/scripts/idl_types.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698