Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(832)

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/parse/ast.py

Issue 396783002: Mojo: Mojom: Add AST types for methods, interface bodies, and interfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/tools/bindings/pylib/mojom/parse/parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return super(Import, self).__eq__(other) and \ 178 return super(Import, self).__eq__(other) and \
179 self.import_filename == other.import_filename 179 self.import_filename == other.import_filename
180 180
181 181
182 class ImportList(NodeListBase): 182 class ImportList(NodeListBase):
183 """Represents a list (i.e., sequence) of import statements.""" 183 """Represents a list (i.e., sequence) of import statements."""
184 184
185 _list_item_type = Import 185 _list_item_type = Import
186 186
187 187
188 class Interface(Definition):
189 """Represents an interface definition."""
190
191 def __init__(self, name, attribute_list, body, **kwargs):
192 assert attribute_list is None or isinstance(attribute_list, AttributeList)
193 assert isinstance(body, InterfaceBody)
194 super(Interface, self).__init__(name, **kwargs)
195 self.attribute_list = attribute_list
196 self.body = body
197
198 def __eq__(self, other):
199 return super(Interface, self).__eq__(other) and \
200 self.attribute_list == other.attribute_list and \
201 self.body == other.body
202
203
204 class Method(Definition):
205 """Represents a method definition."""
206
207 def __init__(self, name, ordinal, parameter_list, response_parameter_list,
208 **kwargs):
209 assert ordinal is None or isinstance(ordinal, Ordinal)
210 assert isinstance(parameter_list, ParameterList)
211 assert response_parameter_list is None or \
212 isinstance(response_parameter_list, ParameterList)
213 super(Method, self).__init__(name, **kwargs)
214 self.ordinal = ordinal
215 self.parameter_list = parameter_list
216 self.response_parameter_list = response_parameter_list
217
218 def __eq__(self, other):
219 return super(Method, self).__eq__(other) and \
220 self.ordinal == other.ordinal and \
221 self.parameter_list == other.parameter_list and \
222 self.response_parameter_list == other.response_parameter_list
223
224
225 # This needs to be declared after |Method|.
226 class InterfaceBody(NodeListBase):
227 """Represents the body of (i.e., list of definitions inside) an interface."""
228
229 _list_item_type = (Const, Enum, Method)
230
231
188 class Module(NodeBase): 232 class Module(NodeBase):
189 """Represents a module statement.""" 233 """Represents a module statement."""
190 234
191 def __init__(self, name, attribute_list, **kwargs): 235 def __init__(self, name, attribute_list, **kwargs):
192 # |name| is either none or a "wrapped identifier". 236 # |name| is either none or a "wrapped identifier".
193 assert name is None or isinstance(name, tuple) 237 assert name is None or isinstance(name, tuple)
194 assert attribute_list is None or isinstance(attribute_list, AttributeList) 238 assert attribute_list is None or isinstance(attribute_list, AttributeList)
195 super(Module, self).__init__(**kwargs) 239 super(Module, self).__init__(**kwargs)
196 self.name = name 240 self.name = name
197 self.attribute_list = attribute_list 241 self.attribute_list = attribute_list
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 self.ordinal == other.ordinal and \ 343 self.ordinal == other.ordinal and \
300 self.typename == other.typename and \ 344 self.typename == other.typename and \
301 self.default_value == other.default_value 345 self.default_value == other.default_value
302 346
303 347
304 # This needs to be declared after |StructField|. 348 # This needs to be declared after |StructField|.
305 class StructBody(NodeListBase): 349 class StructBody(NodeListBase):
306 """Represents the body of (i.e., list of definitions inside) a struct.""" 350 """Represents the body of (i.e., list of definitions inside) a struct."""
307 351
308 _list_item_type = (Const, Enum, StructField) 352 _list_item_type = (Const, Enum, StructField)
OLDNEW
« no previous file with comments | « no previous file | mojo/public/tools/bindings/pylib/mojom/parse/parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698