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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 return super(Enum, self).__eq__(other) and \ | 135 return super(Enum, self).__eq__(other) and \ |
136 self.enum_value_list == other.enum_value_list | 136 self.enum_value_list == other.enum_value_list |
137 | 137 |
138 | 138 |
139 class EnumValue(Definition): | 139 class EnumValue(Definition): |
140 """Represents a definition of an enum value.""" | 140 """Represents a definition of an enum value.""" |
141 | 141 |
142 def __init__(self, name, value, **kwargs): | 142 def __init__(self, name, value, **kwargs): |
143 # The optional value is either an int (which is current a string) or a | 143 # The optional value is either an int (which is current a string) or a |
144 # "wrapped identifier". | 144 # "wrapped identifier". |
145 assert value is None or isinstance(value, str) or isinstance(value, tuple) | 145 assert value is None or isinstance(value, (str, tuple)) |
146 super(EnumValue, self).__init__(name, **kwargs) | 146 super(EnumValue, self).__init__(name, **kwargs) |
147 self.value = value | 147 self.value = value |
148 | 148 |
149 def __eq__(self, other): | 149 def __eq__(self, other): |
150 return super(EnumValue, self).__eq__(other) and \ | 150 return super(EnumValue, self).__eq__(other) and \ |
151 self.value == other.value | 151 self.value == other.value |
152 | 152 |
153 | 153 |
154 class EnumValueList(NodeListBase): | 154 class EnumValueList(NodeListBase): |
155 """Represents a list of enum value definitions (i.e., the "body" of an enum | 155 """Represents a list of enum value definitions (i.e., the "body" of an enum |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 self.value = value | 226 self.value = value |
227 | 227 |
228 def __eq__(self, other): | 228 def __eq__(self, other): |
229 return super(Ordinal, self).__eq__(other) and \ | 229 return super(Ordinal, self).__eq__(other) and \ |
230 self.value == other.value | 230 self.value == other.value |
231 | 231 |
232 | 232 |
233 class Parameter(NodeBase): | 233 class Parameter(NodeBase): |
234 """Represents a method request or response parameter.""" | 234 """Represents a method request or response parameter.""" |
235 | 235 |
236 def __init__(self, typename, name, ordinal, **kwargs): | 236 def __init__(self, name, ordinal, typename, **kwargs): |
| 237 assert isinstance(name, str) |
237 assert ordinal is None or isinstance(ordinal, Ordinal) | 238 assert ordinal is None or isinstance(ordinal, Ordinal) |
| 239 assert isinstance(typename, str) |
238 super(Parameter, self).__init__(**kwargs) | 240 super(Parameter, self).__init__(**kwargs) |
239 self.typename = typename | |
240 self.name = name | 241 self.name = name |
241 self.ordinal = ordinal | 242 self.ordinal = ordinal |
| 243 self.typename = typename |
242 | 244 |
243 def __eq__(self, other): | 245 def __eq__(self, other): |
244 return super(Parameter, self).__eq__(other) and \ | 246 return super(Parameter, self).__eq__(other) and \ |
245 self.typename == other.typename and \ | |
246 self.name == other.name and \ | 247 self.name == other.name and \ |
247 self.ordinal == other.ordinal | 248 self.ordinal == other.ordinal and \ |
| 249 self.typename == other.typename |
248 | 250 |
249 | 251 |
250 class ParameterList(NodeListBase): | 252 class ParameterList(NodeListBase): |
251 """Represents a list of (method request or response) parameters.""" | 253 """Represents a list of (method request or response) parameters.""" |
252 | 254 |
253 _list_item_type = Parameter | 255 _list_item_type = Parameter |
| 256 |
| 257 |
| 258 class StructField(Definition): |
| 259 """Represents a struct field definition.""" |
| 260 |
| 261 def __init__(self, name, ordinal, typename, default_value, **kwargs): |
| 262 assert isinstance(name, str) |
| 263 assert ordinal is None or isinstance(ordinal, Ordinal) |
| 264 assert isinstance(typename, str) |
| 265 # The optional default value is currently either a value as a string or a |
| 266 # "wrapped identifier". |
| 267 assert default_value is None or isinstance(default_value, (str, tuple)) |
| 268 super(StructField, self).__init__(name, **kwargs) |
| 269 self.ordinal = ordinal |
| 270 self.typename = typename |
| 271 self.default_value = default_value |
| 272 |
| 273 def __eq__(self, other): |
| 274 return super(StructField, self).__eq__(other) and \ |
| 275 self.ordinal == other.ordinal and \ |
| 276 self.typename == other.typename and \ |
| 277 self.default_value == other.default_value |
OLD | NEW |