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 objects for the AST for a Mojo IDL file.""" | 5 """Node objects 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). | 9 # and lineno). |
10 | 10 |
11 | 11 |
12 class BaseNode(object): | 12 class BaseNode(object): |
| 13 """Base class for nodes in the AST.""" |
| 14 |
13 def __init__(self, filename=None, lineno=None): | 15 def __init__(self, filename=None, lineno=None): |
14 self.filename = filename | 16 self.filename = filename |
15 self.lineno = lineno | 17 self.lineno = lineno |
16 | 18 |
17 | 19 |
18 class Ordinal(BaseNode): | 20 class Ordinal(BaseNode): |
19 """Represents an ordinal value labeling, e.g., a struct field.""" | 21 """Represents an ordinal value labeling, e.g., a struct field.""" |
| 22 |
20 def __init__(self, value, **kwargs): | 23 def __init__(self, value, **kwargs): |
21 BaseNode.__init__(self, **kwargs) | 24 BaseNode.__init__(self, **kwargs) |
22 self.value = value | 25 self.value = value |
23 | 26 |
24 def __eq__(self, other): | 27 def __eq__(self, other): |
25 return self.value == other.value | 28 return self.value == other.value |
26 | 29 |
| 30 |
27 class Parameter(BaseNode): | 31 class Parameter(BaseNode): |
28 """Represents a method request or response parameter.""" | 32 """Represents a method request or response parameter.""" |
| 33 |
29 def __init__(self, typename, name, ordinal, **kwargs): | 34 def __init__(self, typename, name, ordinal, **kwargs): |
30 assert isinstance(ordinal, Ordinal) | 35 assert isinstance(ordinal, Ordinal) |
31 BaseNode.__init__(self, **kwargs) | 36 BaseNode.__init__(self, **kwargs) |
32 self.typename = typename | 37 self.typename = typename |
33 self.name = name | 38 self.name = name |
34 self.ordinal = ordinal | 39 self.ordinal = ordinal |
35 | 40 |
36 def __eq__(self, other): | 41 def __eq__(self, other): |
37 return self.typename == other.typename and \ | 42 return self.typename == other.typename and \ |
38 self.name == other.name and \ | 43 self.name == other.name and \ |
39 self.ordinal == other.ordinal | 44 self.ordinal == other.ordinal |
OLD | NEW |