| 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 | 4 |
| 5 """Node classes for the AST for a Mojo IDL file.""" | 5 """Node classes for the AST for a Mojo IDL file.""" |
| 6 | 6 |
| 7 # Note: For convenience of testing, you probably want to define __eq__() methods | 7 # Note: For convenience of testing, you probably want to define __eq__() methods |
| 8 # for all node types; it's okay to be slightly lax (e.g., not compare filename | 8 # for all node types; it's okay to be slightly lax (e.g., not compare filename |
| 9 # and lineno). You may also define __repr__() to help with analyzing test | 9 # and lineno). You may also define __repr__() to help with analyzing test |
| 10 # failures, especially for more complex types. | 10 # failures, especially for more complex types. |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 self.ordinal == other.ordinal and \ | 345 self.ordinal == other.ordinal and \ |
| 346 self.typename == other.typename and \ | 346 self.typename == other.typename and \ |
| 347 self.default_value == other.default_value | 347 self.default_value == other.default_value |
| 348 | 348 |
| 349 | 349 |
| 350 # This needs to be declared after |StructField|. | 350 # This needs to be declared after |StructField|. |
| 351 class StructBody(NodeListBase): | 351 class StructBody(NodeListBase): |
| 352 """Represents the body of (i.e., list of definitions inside) a struct.""" | 352 """Represents the body of (i.e., list of definitions inside) a struct.""" |
| 353 | 353 |
| 354 _list_item_type = (Const, Enum, StructField) | 354 _list_item_type = (Const, Enum, StructField) |
| 355 |
| 356 |
| 357 class Union(Definition): |
| 358 """Represents a union definition.""" |
| 359 |
| 360 def __init__(self, name, body, **kwargs): |
| 361 assert isinstance(body, UnionBody) |
| 362 super(Union, self).__init__(name, **kwargs) |
| 363 self.body = body |
| 364 |
| 365 def __eq__(self, other): |
| 366 return super(Union, self).__eq__(other) and \ |
| 367 self.body == other.body |
| 368 |
| 369 |
| 370 class UnionField(Definition): |
| 371 |
| 372 def __init__(self, name, ordinal, typename, **kwargs): |
| 373 assert isinstance(name, str) |
| 374 assert ordinal is None or isinstance(ordinal, Ordinal) |
| 375 assert isinstance(typename, str) |
| 376 super(UnionField, self).__init__(name, **kwargs) |
| 377 self.ordinal = ordinal |
| 378 self.typename = typename |
| 379 |
| 380 def __eq__(self, other): |
| 381 return super(UnionField, self).__eq__(other) and \ |
| 382 self.ordinal == other.ordinal and \ |
| 383 self.typename == other.typename |
| 384 |
| 385 |
| 386 class UnionBody(NodeListBase): |
| 387 |
| 388 _list_item_type = UnionField |
| OLD | NEW |