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

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

Issue 2719913002: bindings: Add idl_types.IdlRecordType. (Closed)
Patch Set: Add some tests to idl_types_test Created 3 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/idl_types.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
11 # in the documentation and/or other materials provided with the 11 # in the documentation and/or other materials provided with the
12 # distribution. 12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its 13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from 14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission. 15 # this software without specific prior written permission.
16 # 16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 28
29 # pylint: disable=relative-import
30
29 """Blink IDL Intermediate Representation (IR) classes. 31 """Blink IDL Intermediate Representation (IR) classes.
30 32
31 Classes are primarily constructors, which build an IdlDefinitions object 33 Classes are primarily constructors, which build an IdlDefinitions object
32 (and various contained objects) from an AST (produced by blink_idl_parser). 34 (and various contained objects) from an AST (produced by blink_idl_parser).
33 35
34 IR stores typedefs and they are resolved by the code generator. 36 IR stores typedefs and they are resolved by the code generator.
35 37
36 Typedef resolution uses some auxiliary classes and OOP techniques to make this 38 Typedef resolution uses some auxiliary classes and OOP techniques to make this
37 a generic call. See TypedefResolver class in code_generator_v8.py. 39 a generic call. See TypedefResolver class in code_generator_v8.py.
38 40
(...skipping 18 matching lines...) Expand all
57 59
58 TypedObject :: Object with one or more attributes that is a type. 60 TypedObject :: Object with one or more attributes that is a type.
59 61
60 IdlArgument is 'picklable', as it is stored in interfaces_info. 62 IdlArgument is 'picklable', as it is stored in interfaces_info.
61 63
62 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 64 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
63 """ 65 """
64 66
65 import abc 67 import abc
66 68
67 from idl_types import IdlType, IdlUnionType, IdlArrayType, IdlSequenceType, IdlF rozenArrayType, IdlNullableType 69 from idl_types import IdlArrayType
70 from idl_types import IdlFrozenArrayType
71 from idl_types import IdlNullableType
72 from idl_types import IdlRecordType
73 from idl_types import IdlSequenceType
74 from idl_types import IdlType
75 from idl_types import IdlUnionType
68 76
69 SPECIAL_KEYWORD_LIST = ['LEGACYCALLER', 'GETTER', 'SETTER', 'DELETER'] 77 SPECIAL_KEYWORD_LIST = ['LEGACYCALLER', 'GETTER', 'SETTER', 'DELETER']
70 78
71 79
72 ################################################################################ 80 ################################################################################
73 # TypedObject 81 # TypedObject
74 ################################################################################ 82 ################################################################################
75 83
76 class TypedObject(object): 84 class TypedObject(object):
77 """Object with a type, such as an Attribute or Operation (return value). 85 """Object with a type, such as an Attribute or Operation (return value).
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 is_unrestricted = bool(node.GetProperty('UNRESTRICTED')) 1028 is_unrestricted = bool(node.GetProperty('UNRESTRICTED'))
1021 return IdlType(node.GetName(), is_unrestricted=is_unrestricted) 1029 return IdlType(node.GetName(), is_unrestricted=is_unrestricted)
1022 elif node_class == 'Any': 1030 elif node_class == 'Any':
1023 return IdlType('any') 1031 return IdlType('any')
1024 elif node_class in ['Sequence', 'FrozenArray']: 1032 elif node_class in ['Sequence', 'FrozenArray']:
1025 return sequence_node_to_type(node) 1033 return sequence_node_to_type(node)
1026 elif node_class == 'UnionType': 1034 elif node_class == 'UnionType':
1027 return union_type_node_to_idl_union_type(node) 1035 return union_type_node_to_idl_union_type(node)
1028 elif node_class == 'Promise': 1036 elif node_class == 'Promise':
1029 return IdlType('Promise') 1037 return IdlType('Promise')
1038 elif node_class == 'Record':
1039 return record_node_to_type(node)
1030 raise ValueError('Unrecognized node class: %s' % node_class) 1040 raise ValueError('Unrecognized node class: %s' % node_class)
1031 1041
1032 1042
1043 def record_node_to_type(node):
1044 children = node.GetChildren()
1045 if len(children) != 2:
1046 raise ValueError('record<K,V> node expects exactly 2 children, got %d' % (len(children)))
1047 key_child = children[0]
1048 value_child = children[1]
1049 if key_child.GetClass() != 'StringType':
1050 raise ValueError('Keys in record<K,V> nodes must be string types.')
1051 if value_child.GetClass() != 'Type':
1052 raise ValueError('Unrecognized node class for record<K,V> value: %s' % v alue_child.GetClass())
1053 return IdlRecordType(IdlType(key_child.GetName()), type_node_to_type(value_c hild))
1054
1055
1033 def sequence_node_to_type(node): 1056 def sequence_node_to_type(node):
1034 children = node.GetChildren() 1057 children = node.GetChildren()
1035 class_name = node.GetClass() 1058 class_name = node.GetClass()
1036 if len(children) != 1: 1059 if len(children) != 1:
1037 raise ValueError('%s node expects exactly 1 child, got %s' % (class_name , len(children))) 1060 raise ValueError('%s node expects exactly 1 child, got %s' % (class_name , len(children)))
1038 sequence_child = children[0] 1061 sequence_child = children[0]
1039 sequence_child_class = sequence_child.GetClass() 1062 sequence_child_class = sequence_child.GetClass()
1040 if sequence_child_class != 'Type': 1063 if sequence_child_class != 'Type':
1041 raise ValueError('Unrecognized node class: %s' % sequence_child_class) 1064 raise ValueError('Unrecognized node class: %s' % sequence_child_class)
1042 element_type = type_node_to_type(sequence_child) 1065 element_type = type_node_to_type(sequence_child)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 self.visit_typed_object(argument) 1138 self.visit_typed_object(argument)
1116 1139
1117 def visit_iterable(self, iterable): 1140 def visit_iterable(self, iterable):
1118 self.visit_typed_object(iterable) 1141 self.visit_typed_object(iterable)
1119 1142
1120 def visit_maplike(self, maplike): 1143 def visit_maplike(self, maplike):
1121 self.visit_typed_object(maplike) 1144 self.visit_typed_object(maplike)
1122 1145
1123 def visit_setlike(self, setlike): 1146 def visit_setlike(self, setlike):
1124 self.visit_typed_object(setlike) 1147 self.visit_typed_object(setlike)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/idl_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698