| 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 IdlArrayOrSequenceType | 10 IdlArrayOrSequenceType |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 def __getattr__(self, name): | 117 def __getattr__(self, name): |
| 118 # Default undefined attributes to None (analogous to Jinja variables). | 118 # Default undefined attributes to None (analogous to Jinja variables). |
| 119 # This allows us to not define default properties in the base class, and | 119 # This allows us to not define default properties in the base class, and |
| 120 # allows us to relay __getattr__ in IdlNullableType to the inner type. | 120 # allows us to relay __getattr__ in IdlNullableType to the inner type. |
| 121 return None | 121 return None |
| 122 | 122 |
| 123 def resolve_typedefs(self, typedefs): | 123 def resolve_typedefs(self, typedefs): |
| 124 raise NotImplementedError( | 124 raise NotImplementedError( |
| 125 'resolve_typedefs should be defined in subclasses') | 125 'resolve_typedefs should be defined in subclasses') |
| 126 | 126 |
| 127 def idl_types(self): |
| 128 """A generator which yields IdlTypes which are referenced from |self|, |
| 129 including itself.""" |
| 130 yield self |
| 131 |
| 127 | 132 |
| 128 ################################################################################ | 133 ################################################################################ |
| 129 # IdlType | 134 # IdlType |
| 130 ################################################################################ | 135 ################################################################################ |
| 131 | 136 |
| 132 class IdlType(IdlTypeBase): | 137 class IdlType(IdlTypeBase): |
| 133 # FIXME: incorporate Nullable, etc. | 138 # FIXME: incorporate Nullable, etc. |
| 134 # to support types like short?[] vs. short[]?, instead of treating these | 139 # to support types like short?[] vs. short[]?, instead of treating these |
| 135 # as orthogonal properties (via flags). | 140 # as orthogonal properties (via flags). |
| 136 callback_functions = set(STANDARD_CALLBACK_FUNCTIONS) | 141 callback_functions = set(STANDARD_CALLBACK_FUNCTIONS) |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 http://heycam.github.io/webidl/#dfn-type-name | 319 http://heycam.github.io/webidl/#dfn-type-name |
| 315 """ | 320 """ |
| 316 return 'Or'.join(member_type.name for member_type in self.member_types) | 321 return 'Or'.join(member_type.name for member_type in self.member_types) |
| 317 | 322 |
| 318 def resolve_typedefs(self, typedefs): | 323 def resolve_typedefs(self, typedefs): |
| 319 self.member_types = [ | 324 self.member_types = [ |
| 320 typedefs.get(member_type, member_type) | 325 typedefs.get(member_type, member_type) |
| 321 for member_type in self.member_types] | 326 for member_type in self.member_types] |
| 322 return self | 327 return self |
| 323 | 328 |
| 329 def idl_types(self): |
| 330 yield self |
| 331 for member_type in self.member_types: |
| 332 for idl_type in member_type.idl_types(): |
| 333 yield idl_type |
| 334 |
| 324 | 335 |
| 325 ################################################################################ | 336 ################################################################################ |
| 326 # IdlArrayOrSequenceType, IdlArrayType, IdlSequenceType | 337 # IdlArrayOrSequenceType, IdlArrayType, IdlSequenceType |
| 327 ################################################################################ | 338 ################################################################################ |
| 328 | 339 |
| 329 class IdlArrayOrSequenceType(IdlTypeBase): | 340 class IdlArrayOrSequenceType(IdlTypeBase): |
| 330 """Base class for IdlArrayType and IdlSequenceType.""" | 341 """Base class for IdlArrayType and IdlSequenceType.""" |
| 331 | 342 |
| 332 def __init__(self, element_type): | 343 def __init__(self, element_type): |
| 333 super(IdlArrayOrSequenceType, self).__init__() | 344 super(IdlArrayOrSequenceType, self).__init__() |
| (...skipping 16 matching lines...) Expand all Loading... |
| 350 return True | 361 return True |
| 351 | 362 |
| 352 @property | 363 @property |
| 353 def enum_values(self): | 364 def enum_values(self): |
| 354 return self.element_type.enum_values | 365 return self.element_type.enum_values |
| 355 | 366 |
| 356 @property | 367 @property |
| 357 def enum_type(self): | 368 def enum_type(self): |
| 358 return self.element_type.enum_type | 369 return self.element_type.enum_type |
| 359 | 370 |
| 371 def idl_types(self): |
| 372 yield self |
| 373 for idl_type in self.element_type.idl_types(): |
| 374 yield idl_type |
| 375 |
| 360 | 376 |
| 361 class IdlArrayType(IdlArrayOrSequenceType): | 377 class IdlArrayType(IdlArrayOrSequenceType): |
| 362 def __init__(self, element_type): | 378 def __init__(self, element_type): |
| 363 super(IdlArrayType, self).__init__(element_type) | 379 super(IdlArrayType, self).__init__(element_type) |
| 364 | 380 |
| 365 def __str__(self): | 381 def __str__(self): |
| 366 return '%s[]' % self.element_type | 382 return '%s[]' % self.element_type |
| 367 | 383 |
| 368 @property | 384 @property |
| 369 def name(self): | 385 def name(self): |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 def is_nullable(self): | 430 def is_nullable(self): |
| 415 return True | 431 return True |
| 416 | 432 |
| 417 @property | 433 @property |
| 418 def name(self): | 434 def name(self): |
| 419 return self.inner_type.name + 'OrNull' | 435 return self.inner_type.name + 'OrNull' |
| 420 | 436 |
| 421 def resolve_typedefs(self, typedefs): | 437 def resolve_typedefs(self, typedefs): |
| 422 self.inner_type = self.inner_type.resolve_typedefs(typedefs) | 438 self.inner_type = self.inner_type.resolve_typedefs(typedefs) |
| 423 return self | 439 return self |
| 440 |
| 441 def idl_types(self): |
| 442 yield self |
| 443 for idl_type in self.inner_type.idl_types(): |
| 444 yield idl_type |
| OLD | NEW |