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

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

Issue 380023005: Mojo: Mojom: Add Import, ImportList, and Mojom AST types. (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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 class Attribute(NodeBase): 72 class Attribute(NodeBase):
73 """Represents an attribute.""" 73 """Represents an attribute."""
74 74
75 def __init__(self, key, value, **kwargs): 75 def __init__(self, key, value, **kwargs):
76 assert isinstance(key, str) 76 assert isinstance(key, str)
77 NodeBase.__init__(self, **kwargs) 77 NodeBase.__init__(self, **kwargs)
78 self.key = key 78 self.key = key
79 self.value = value 79 self.value = value
80 80
81 def __eq__(self, other): 81 def __eq__(self, other):
82 return self.key == other.key and self.value == other.value 82 return type(self) == type(other) and \
83 self.key == other.key and \
84 self.value == other.value
83 85
84 86
85 class AttributeList(NodeListBase): 87 class AttributeList(NodeListBase):
86 """Represents a list attributes.""" 88 """Represents a list attributes."""
87 89
88 _list_item_type = Attribute 90 _list_item_type = Attribute
89 91
90 92
91 class Import(NodeBase): 93 class Import(NodeBase):
92 """Represents an import statement.""" 94 """Represents an import statement."""
93 95
94 def __init__(self, import_filename, **kwargs): 96 def __init__(self, import_filename, **kwargs):
95 assert isinstance(import_filename, str) 97 assert isinstance(import_filename, str)
96 NodeBase.__init__(self, **kwargs) 98 NodeBase.__init__(self, **kwargs)
97 self.import_filename = import_filename 99 self.import_filename = import_filename
98 100
99 def __eq__(self, other): 101 def __eq__(self, other):
100 return self.import_filename == other.import_filename 102 return type(self) == type(other) and \
103 self.import_filename == other.import_filename
101 104
102 105
103 class ImportList(NodeListBase): 106 class ImportList(NodeListBase):
104 """Represents a list (i.e., sequence) of import statements.""" 107 """Represents a list (i.e., sequence) of import statements."""
105 108
106 _list_item_type = Import 109 _list_item_type = Import
107 110
108 111
109 class Module(NodeBase): 112 class Module(NodeBase):
110 """Represents a module statement.""" 113 """Represents a module statement."""
111 114
112 def __init__(self, name, attribute_list, **kwargs): 115 def __init__(self, name, attribute_list, **kwargs):
113 # |name| is either none or a "wrapped identifier". 116 # |name| is either none or a "wrapped identifier".
114 assert name is None or isinstance(name, tuple) 117 assert name is None or isinstance(name, tuple)
115 assert attribute_list is None or isinstance(attribute_list, AttributeList) 118 assert attribute_list is None or isinstance(attribute_list, AttributeList)
116 NodeBase.__init__(self, **kwargs) 119 NodeBase.__init__(self, **kwargs)
117 self.name = name 120 self.name = name
118 self.attribute_list = attribute_list 121 self.attribute_list = attribute_list
119 122
120 def __eq__(self, other): 123 def __eq__(self, other):
121 return self.name == other.name and \ 124 return type(self) == type(other) and \
125 self.name == other.name and \
122 self.attribute_list == other.attribute_list 126 self.attribute_list == other.attribute_list
123 127
124 128
129 class Mojom(NodeBase):
130 """Represents an entire .mojom file. (This is the root node."""
131
132 def __init__(self, module, import_list, definition_list, **kwargs):
133 assert module is None or isinstance(module, Module)
134 assert isinstance(import_list, ImportList)
135 assert isinstance(definition_list, list)
136 NodeBase.__init__(self, **kwargs)
137 self.module = module
138 self.import_list = import_list
139 self.definition_list = definition_list
140
141 def __eq__(self, other):
142 return type(self) == type(other) and \
143 self.module == other.module and \
144 self.import_list == other.import_list and \
145 self.definition_list == other.definition_list
146
147 def __repr__(self):
148 return "%s(%r, %r, %r)" % (self.__class__.__name__, self.module,
149 self.import_list, self.definition_list)
150
151
125 class Ordinal(NodeBase): 152 class Ordinal(NodeBase):
126 """Represents an ordinal value labeling, e.g., a struct field.""" 153 """Represents an ordinal value labeling, e.g., a struct field."""
127 154
128 def __init__(self, value, **kwargs): 155 def __init__(self, value, **kwargs):
129 assert value is None or isinstance(value, int) 156 assert value is None or isinstance(value, int)
130 NodeBase.__init__(self, **kwargs) 157 NodeBase.__init__(self, **kwargs)
131 self.value = value 158 self.value = value
132 159
133 def __eq__(self, other): 160 def __eq__(self, other):
134 return self.value == other.value 161 return type(self) == type(other) and self.value == other.value
135 162
136 163
137 class Parameter(NodeBase): 164 class Parameter(NodeBase):
138 """Represents a method request or response parameter.""" 165 """Represents a method request or response parameter."""
139 166
140 def __init__(self, typename, name, ordinal, **kwargs): 167 def __init__(self, typename, name, ordinal, **kwargs):
141 assert isinstance(ordinal, Ordinal) 168 assert isinstance(ordinal, Ordinal)
142 NodeBase.__init__(self, **kwargs) 169 NodeBase.__init__(self, **kwargs)
143 self.typename = typename 170 self.typename = typename
144 self.name = name 171 self.name = name
145 self.ordinal = ordinal 172 self.ordinal = ordinal
146 173
147 def __eq__(self, other): 174 def __eq__(self, other):
148 return self.typename == other.typename and \ 175 return type(self) == type(other) and \
176 self.typename == other.typename and \
149 self.name == other.name and \ 177 self.name == other.name and \
150 self.ordinal == other.ordinal 178 self.ordinal == other.ordinal
151 179
152 180
153 class ParameterList(NodeListBase): 181 class ParameterList(NodeListBase):
154 """Represents a list of (method request or response) parameters.""" 182 """Represents a list of (method request or response) parameters."""
155 183
156 _list_item_type = Parameter 184 _list_item_type = Parameter
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