OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 """IDL type handling. | 4 """IDL type handling. |
5 | 5 |
6 Classes: | 6 Classes: |
7 IdlTypeBase | 7 IdlTypeBase |
8 IdlType | 8 IdlType |
9 IdlUnionType | 9 IdlUnionType |
10 """ | 10 """ |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 @property | 115 @property |
116 def is_basic_type(self): | 116 def is_basic_type(self): |
117 return False | 117 return False |
118 | 118 |
119 @property | 119 @property |
120 def is_callback_function(self): | 120 def is_callback_function(self): |
121 return False | 121 return False |
122 | 122 |
123 @property | 123 @property |
| 124 def is_dictionary(self): |
| 125 return False |
| 126 |
| 127 @property |
124 def is_enum(self): | 128 def is_enum(self): |
125 return False | 129 return False |
126 | 130 |
127 @property | 131 @property |
128 def is_integer_type(self): | 132 def is_integer_type(self): |
129 return False | 133 return False |
130 | 134 |
131 @property | 135 @property |
132 def is_numeric_type(self): | 136 def is_numeric_type(self): |
133 return False | 137 return False |
(...skipping 28 matching lines...) Expand all Loading... |
162 # IdlType | 166 # IdlType |
163 ################################################################################ | 167 ################################################################################ |
164 | 168 |
165 class IdlType(IdlTypeBase): | 169 class IdlType(IdlTypeBase): |
166 # FIXME: incorporate Nullable, etc. | 170 # FIXME: incorporate Nullable, etc. |
167 # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType | 171 # FIXME: use nested types: IdlArrayType, IdlNullableType, IdlSequenceType |
168 # to support types like short?[] vs. short[]?, instead of treating these | 172 # to support types like short?[] vs. short[]?, instead of treating these |
169 # as orthogonal properties (via flags). | 173 # as orthogonal properties (via flags). |
170 callback_functions = set() | 174 callback_functions = set() |
171 callback_interfaces = set() | 175 callback_interfaces = set() |
| 176 dictionaries = set() |
172 enums = {} # name -> values | 177 enums = {} # name -> values |
173 | 178 |
174 def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable
=False, is_unrestricted=False): | 179 def __init__(self, base_type, is_array=False, is_sequence=False, is_nullable
=False, is_unrestricted=False): |
175 super(IdlType, self).__init__(is_array=is_array, is_sequence=is_sequence
, is_nullable=is_nullable) | 180 super(IdlType, self).__init__(is_array=is_array, is_sequence=is_sequence
, is_nullable=is_nullable) |
176 if is_array and is_sequence: | 181 if is_array and is_sequence: |
177 raise ValueError('Array of Sequences are not allowed.') | 182 raise ValueError('Array of Sequences are not allowed.') |
178 if is_unrestricted: | 183 if is_unrestricted: |
179 self.base_type = 'unrestricted %s' % base_type | 184 self.base_type = 'unrestricted %s' % base_type |
180 else: | 185 else: |
181 self.base_type = base_type | 186 self.base_type = base_type |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 219 |
215 @property | 220 @property |
216 def is_callback_function(self): | 221 def is_callback_function(self): |
217 return self.base_type in IdlType.callback_functions | 222 return self.base_type in IdlType.callback_functions |
218 | 223 |
219 @property | 224 @property |
220 def is_callback_interface(self): | 225 def is_callback_interface(self): |
221 return self.base_type in IdlType.callback_interfaces | 226 return self.base_type in IdlType.callback_interfaces |
222 | 227 |
223 @property | 228 @property |
| 229 def is_dictionary(self): |
| 230 return self.base_type in IdlType.dictionaries |
| 231 |
| 232 @property |
224 def is_composite_type(self): | 233 def is_composite_type(self): |
225 return (self.name == 'Any' or | 234 return (self.name == 'Any' or |
226 self.array_element_type or | 235 self.array_element_type or |
227 self.sequence_element_type or | 236 self.sequence_element_type or |
228 self.is_union_type) | 237 self.is_union_type) |
229 | 238 |
230 @property | 239 @property |
231 def is_enum(self): | 240 def is_enum(self): |
232 # FIXME: add an IdlEnumType class and a resolve_enums step at end of | 241 # FIXME: add an IdlEnumType class and a resolve_enums step at end of |
233 # IdlDefinitions constructor | 242 # IdlDefinitions constructor |
(...skipping 17 matching lines...) Expand all Loading... |
251 | 260 |
252 @property | 261 @property |
253 def is_interface_type(self): | 262 def is_interface_type(self): |
254 # Anything that is not another type is an interface type. | 263 # Anything that is not another type is an interface type. |
255 # http://www.w3.org/TR/WebIDL/#idl-types | 264 # http://www.w3.org/TR/WebIDL/#idl-types |
256 # http://www.w3.org/TR/WebIDL/#idl-interface | 265 # http://www.w3.org/TR/WebIDL/#idl-interface |
257 # In C++ these are RefPtr or PassRefPtr types. | 266 # In C++ these are RefPtr or PassRefPtr types. |
258 return not(self.is_basic_type or | 267 return not(self.is_basic_type or |
259 self.is_composite_type or | 268 self.is_composite_type or |
260 self.is_callback_function or | 269 self.is_callback_function or |
| 270 self.is_dictionary or |
261 self.is_enum or | 271 self.is_enum or |
262 self.name == 'Object' or | 272 self.name == 'Object' or |
263 self.name == 'Promise') # Promise will be basic in future | 273 self.name == 'Promise') # Promise will be basic in future |
264 | 274 |
265 @property | 275 @property |
266 def is_string_type(self): | 276 def is_string_type(self): |
267 return self.base_type_name in STRING_TYPES | 277 return self.base_type_name in STRING_TYPES |
268 | 278 |
269 @property | 279 @property |
270 def may_raise_exception_on_conversion(self): | 280 def may_raise_exception_on_conversion(self): |
(...skipping 26 matching lines...) Expand all Loading... |
297 | 307 |
298 @classmethod | 308 @classmethod |
299 def set_callback_functions(cls, new_callback_functions): | 309 def set_callback_functions(cls, new_callback_functions): |
300 cls.callback_functions.update(new_callback_functions) | 310 cls.callback_functions.update(new_callback_functions) |
301 | 311 |
302 @classmethod | 312 @classmethod |
303 def set_callback_interfaces(cls, new_callback_interfaces): | 313 def set_callback_interfaces(cls, new_callback_interfaces): |
304 cls.callback_interfaces.update(new_callback_interfaces) | 314 cls.callback_interfaces.update(new_callback_interfaces) |
305 | 315 |
306 @classmethod | 316 @classmethod |
| 317 def set_dictionaries(cls, new_dictionaries): |
| 318 cls.dictionaries.update(new_dictionaries) |
| 319 |
| 320 @classmethod |
307 def set_enums(cls, new_enums): | 321 def set_enums(cls, new_enums): |
308 cls.enums.update(new_enums) | 322 cls.enums.update(new_enums) |
309 | 323 |
310 def resolve_typedefs(self, typedefs): | 324 def resolve_typedefs(self, typedefs): |
311 if self.base_type not in typedefs: | 325 if self.base_type not in typedefs: |
312 return self | 326 return self |
313 new_type = typedefs[self.base_type] | 327 new_type = typedefs[self.base_type] |
314 if type(new_type) != type(self): | 328 if type(new_type) != type(self): |
315 # If type changes, need to return a different object, | 329 # If type changes, need to return a different object, |
316 # since can't change type(self) | 330 # since can't change type(self) |
(...skipping 28 matching lines...) Expand all Loading... |
345 | 359 |
346 @property | 360 @property |
347 def name(self): | 361 def name(self): |
348 return 'Or'.join(member_type.name for member_type in self.member_types) | 362 return 'Or'.join(member_type.name for member_type in self.member_types) |
349 | 363 |
350 def resolve_typedefs(self, typedefs): | 364 def resolve_typedefs(self, typedefs): |
351 self.member_types = [ | 365 self.member_types = [ |
352 typedefs.get(member_type, member_type) | 366 typedefs.get(member_type, member_type) |
353 for member_type in self.member_types] | 367 for member_type in self.member_types] |
354 return self | 368 return self |
OLD | NEW |