OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 '''Generates the many subtypes of Node as well as a NodeVisitor into | 6 '''Generates the many subtypes of Node as well as a NodeVisitor into |
7 tree.g.dart.''' | 7 tree.g.dart.''' |
8 | 8 |
9 from codegen import CodeWriter | 9 from codegen import CodeWriter |
10 | 10 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Expression('Var', 'Identifier name'), | 173 Expression('Var', 'Identifier name'), |
174 | 174 |
175 Expression('This'), | 175 Expression('This'), |
176 Expression('Super'), | 176 Expression('Super'), |
177 | 177 |
178 Expression('Literal', 'Value value'), | 178 Expression('Literal', 'Value value'), |
179 | 179 |
180 Expression('StringInterp', 'List<Expression> pieces'), | 180 Expression('StringInterp', 'List<Expression> pieces'), |
181 | 181 |
182 # TODO(jimhug): Split into Simple and Qualified names | 182 # TODO(jimhug): Split into Simple and Qualified names |
| 183 TypeReference('Simple', 'Type type'), |
183 TypeReference('Name', | 184 TypeReference('Name', |
184 'bool isFinal, Identifier name, List<Identifier> names'), | 185 'bool isFinal, Identifier name, List<Identifier> names'), |
185 | 186 |
186 TypeReference('Generic', | 187 TypeReference('Generic', |
187 'TypeReference baseType, List<TypeReference> typeArguments, int depth'), | 188 'TypeReference baseType, List<TypeReference> typeArguments, int depth'), |
188 TypeReference('Function', | 189 TypeReference('Function', |
189 'bool isFinal, FunctionDefinition func'), | 190 'bool isFinal, FunctionDefinition func'), |
| 191 # TODO(jimhug): This shouldn't be a subtype of TypeReference. |
190 TypeReference('Default', 'bool oldFactory, NameTypeReference baseType, '+ | 192 TypeReference('Default', 'bool oldFactory, NameTypeReference baseType, '+ |
191 'List<ParameterType> typeParameters'), | 193 'List<ParameterType> typeParameters'), |
192 | 194 |
193 Node('Argument', 'Identifier label, Expression value'), | 195 Node('Argument', 'Identifier label, Expression value'), |
194 Node('Formal', | 196 Node('Formal', |
195 'bool isThis, bool isRest, TypeReference type, Identifier name,'+ | 197 'bool isThis, bool isRest, TypeReference type, Identifier name,'+ |
196 'Expression value'), | 198 'Expression value'), |
197 | 199 |
198 Node('Catch', | 200 Node('Catch', |
199 'DeclaredIdentifier exception, DeclaredIdentifier trace, Statement body'), | 201 'DeclaredIdentifier exception, DeclaredIdentifier trace, Statement body'), |
(...skipping 10 matching lines...) Expand all Loading... |
210 Expression('DeclaredIdentifier!', 'TypeReference type, Identifier name'), | 212 Expression('DeclaredIdentifier!', 'TypeReference type, Identifier name'), |
211 ] | 213 ] |
212 | 214 |
213 def main(): | 215 def main(): |
214 cw = CodeWriter(__file__) | 216 cw = CodeWriter(__file__) |
215 | 217 |
216 for node in nodes: | 218 for node in nodes: |
217 node.write(cw) | 219 node.write(cw) |
218 cw.writeln() | 220 cw.writeln() |
219 | 221 |
220 # TypeReference is a bit special: it's a base type, but we also create it | |
221 # directly. Add it to nodes after we've generated the nodes. | |
222 nodes.append(TypeReference('', 'Type type')) | |
223 | |
224 cw.writeln() | 222 cw.writeln() |
225 cw.enterBlock('interface TreeVisitor {') | 223 cw.enterBlock('interface TreeVisitor {') |
226 for node in nodes: | 224 for node in nodes: |
227 node.writeVisitInterfaceMethod(cw) | 225 node.writeVisitInterfaceMethod(cw) |
228 cw.writeln() | 226 cw.writeln() |
229 | 227 |
230 cw.exitBlock('}') | 228 cw.exitBlock('}') |
231 | 229 |
232 cw.writeln() | 230 cw.writeln() |
233 cw.enterBlock('class TreePrinter implements TreeVisitor {') | 231 cw.enterBlock('class TreePrinter implements TreeVisitor {') |
234 | 232 |
235 cw.writeln('var output;') | 233 cw.writeln('var output;') |
236 cw.writeln('TreePrinter(this.output) { output.printer = this; }') | 234 cw.writeln('TreePrinter(this.output) { output.printer = this; }') |
237 for node in nodes: | 235 for node in nodes: |
238 node.writePrettyPrintMethod(cw) | 236 node.writePrettyPrintMethod(cw) |
239 cw.writeln() | 237 cw.writeln() |
240 cw.exitBlock('}') | 238 cw.exitBlock('}') |
241 | 239 |
242 cw.writeToFile('tree') | 240 cw.writeToFile('tree') |
243 | 241 |
244 if __name__ == '__main__': main() | 242 if __name__ == '__main__': main() |
OLD | NEW |