OLD | NEW |
| 1 #!/usr/bin/env python |
1 # 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 |
2 # 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 |
3 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
4 | 5 |
5 '''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 |
6 tree.g.dart.''' | 7 tree.g.dart.''' |
7 | 8 |
8 from codegen import CodeWriter | 9 from codegen import CodeWriter |
9 | 10 |
10 class Node: | 11 class Node: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 92 |
92 class Definition(Node): pass | 93 class Definition(Node): pass |
93 | 94 |
94 class TypeReference(Node): pass | 95 class TypeReference(Node): pass |
95 | 96 |
96 nodes = [ | 97 nodes = [ |
97 Definition('Directive', 'Identifier name, List<ArgumentNode> arguments'), | 98 Definition('Directive', 'Identifier name, List<ArgumentNode> arguments'), |
98 | 99 |
99 Definition('Type', | 100 Definition('Type', |
100 'bool isClass, Identifier name, List<ParameterType> typeParameters, '+ | 101 'bool isClass, Identifier name, List<ParameterType> typeParameters, '+ |
101 'List<TypeReference> extendsTypes, List<TypeReference> implementsTypes,'+ | 102 'List<TypeReference> extendsTypes, List<TypeReference> implementsTypes, '+ |
102 'NativeType nativeType, TypeReference factoryType, List<Statement> body'), | 103 'NativeType nativeType, DefaultTypeReference defaultType, '+ |
| 104 'List<Statement> body'), |
103 | 105 |
104 Definition('FunctionType', | 106 Definition('FunctionType', |
105 'FunctionDefinition func, List<ParameterType> typeParameters'), | 107 'FunctionDefinition func, List<ParameterType> typeParameters'), |
106 | 108 |
107 Definition('Variable', | 109 Definition('Variable', |
108 'List<Token> modifiers, TypeReference type, List<Identifier> names,' + | 110 'List<Token> modifiers, TypeReference type, List<Identifier> names,' + |
109 'List<Expression> values'), | 111 'List<Expression> values'), |
110 | 112 |
111 Definition('Function', | 113 Definition('Function', |
112 'List<Token> modifiers, TypeReference returnType, Identifier name,' + | 114 'List<Token> modifiers, TypeReference returnType, Identifier name,' + |
113 'List<FormalNode> formals, List<ParameterType> typeParameters,' + | 115 'List<FormalNode> formals, List<Expression> initializers, ' + |
114 'List<Expression> initializers, String nativeBody, Statement body'), | 116 'String nativeBody, Statement body'), |
115 | 117 |
116 Statement('Return', 'Expression value'), | 118 Statement('Return', 'Expression value'), |
117 Statement('Throw', 'Expression value'), | 119 Statement('Throw', 'Expression value'), |
118 Statement('Assert', 'Expression test'), | 120 Statement('Assert', 'Expression test'), |
119 | 121 |
120 Statement('Break', 'Identifier label'), | 122 Statement('Break', 'Identifier label'), |
121 Statement('Continue', 'Identifier label'), | 123 Statement('Continue', 'Identifier label'), |
122 | 124 |
123 Statement('If', | 125 Statement('If', |
124 'Expression test, Statement trueBranch, Statement falseBranch'), | 126 'Expression test, Statement trueBranch, Statement falseBranch'), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 Expression('Literal', 'var value, TypeReference type, String text'), | 178 Expression('Literal', 'var value, TypeReference type, String text'), |
177 | 179 |
178 # TODO(jimhug): Split into Simple and Qualified names | 180 # TODO(jimhug): Split into Simple and Qualified names |
179 TypeReference('Name', | 181 TypeReference('Name', |
180 'bool isFinal, Identifier name, List<Identifier> names'), | 182 'bool isFinal, Identifier name, List<Identifier> names'), |
181 | 183 |
182 TypeReference('Generic', | 184 TypeReference('Generic', |
183 'TypeReference baseType, List<TypeReference> typeArguments, int depth'), | 185 'TypeReference baseType, List<TypeReference> typeArguments, int depth'), |
184 TypeReference('Function', | 186 TypeReference('Function', |
185 'bool isFinal, FunctionDefinition func'), | 187 'bool isFinal, FunctionDefinition func'), |
| 188 TypeReference('Default', 'bool oldFactory, NameTypeReference baseType, '+ |
| 189 'List<ParameterType> typeParameters'), |
186 | 190 |
187 Node('Argument', 'Identifier label, Expression value'), | 191 Node('Argument', 'Identifier label, Expression value'), |
188 Node('Formal', | 192 Node('Formal', |
189 'bool isThis, bool isRest, TypeReference type, Identifier name,'+ | 193 'bool isThis, bool isRest, TypeReference type, Identifier name,'+ |
190 'Expression value'), | 194 'Expression value'), |
191 | 195 |
192 Node('Catch', | 196 Node('Catch', |
193 'DeclaredIdentifier exception, DeclaredIdentifier trace, Statement body'), | 197 'DeclaredIdentifier exception, DeclaredIdentifier trace, Statement body'), |
194 Node('Case', | 198 Node('Case', |
195 'Identifier label, List<Expression> cases, List<Statement> statements'), | 199 'Identifier label, List<Expression> cases, List<Statement> statements'), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 cw.writeln('var output;') | 233 cw.writeln('var output;') |
230 cw.writeln('TreePrinter(this.output) { output.printer = this; }') | 234 cw.writeln('TreePrinter(this.output) { output.printer = this; }') |
231 for node in nodes: | 235 for node in nodes: |
232 node.writePrettyPrintMethod(cw) | 236 node.writePrettyPrintMethod(cw) |
233 cw.writeln() | 237 cw.writeln() |
234 cw.exitBlock('}') | 238 cw.exitBlock('}') |
235 | 239 |
236 cw.writeToFile('tree') | 240 cw.writeToFile('tree') |
237 | 241 |
238 if __name__ == '__main__': main() | 242 if __name__ == '__main__': main() |
OLD | NEW |