OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library kernel.ast_to_text; | 4 library kernel.ast_to_text; |
5 | 5 |
6 import '../ast.dart'; | 6 import '../ast.dart'; |
7 import '../import_table.dart'; | 7 import '../import_table.dart'; |
8 import '../type_propagation/type_propagation.dart'; | 8 import '../type_propagation/type_propagation.dart'; |
9 | 9 |
10 class Namer<T> { | 10 class Namer<T> { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 String debugVariableDeclarationName(VariableDeclaration node) { | 85 String debugVariableDeclarationName(VariableDeclaration node) { |
86 return node.name ?? globalDebuggingNames.nameVariable(node); | 86 return node.name ?? globalDebuggingNames.nameVariable(node); |
87 } | 87 } |
88 | 88 |
89 String debugNodeToString(Node node) { | 89 String debugNodeToString(Node node) { |
90 StringBuffer buffer = new StringBuffer(); | 90 StringBuffer buffer = new StringBuffer(); |
91 new Printer(buffer, syntheticNames: globalDebuggingNames).writeNode(node); | 91 new Printer(buffer, syntheticNames: globalDebuggingNames).writeNode(node); |
92 return '$buffer'; | 92 return '$buffer'; |
93 } | 93 } |
94 | 94 |
| 95 String programToString(Program node) { |
| 96 StringBuffer buffer = new StringBuffer(); |
| 97 new Printer(buffer, syntheticNames: new NameSystem()).writeProgramFile(node); |
| 98 return '$buffer'; |
| 99 } |
| 100 |
95 class NameSystem { | 101 class NameSystem { |
96 final Namer<VariableDeclaration> variables = | 102 final Namer<VariableDeclaration> variables = |
97 new Namer<VariableDeclaration>('#t'); | 103 new Namer<VariableDeclaration>('#t'); |
98 final Namer<Member> members = new Namer<Member>('#m'); | 104 final Namer<Member> members = new Namer<Member>('#m'); |
99 final Namer<Class> classes = new Namer<Class>('#class'); | 105 final Namer<Class> classes = new Namer<Class>('#class'); |
100 final Namer<Library> libraries = new Namer<Library>('#lib'); | 106 final Namer<Library> libraries = new Namer<Library>('#lib'); |
101 final Namer<TypeParameter> typeParameters = new Namer<TypeParameter>('#T'); | 107 final Namer<TypeParameter> typeParameters = new Namer<TypeParameter>('#T'); |
102 final Namer<TreeNode> labels = new Namer<TreeNode>('#L'); | 108 final Namer<TreeNode> labels = new Namer<TreeNode>('#L'); |
103 final Disambiguator<Library> prefixes = new Disambiguator<Library>(); | 109 final Disambiguator<Library> prefixes = new Disambiguator<Library>(); |
104 | 110 |
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 } | 1535 } |
1530 throw 'illegal ProcedureKind: $kind'; | 1536 throw 'illegal ProcedureKind: $kind'; |
1531 } | 1537 } |
1532 | 1538 |
1533 class ExpressionPrinter { | 1539 class ExpressionPrinter { |
1534 final Printer writeer; | 1540 final Printer writeer; |
1535 final int minimumPrecedence; | 1541 final int minimumPrecedence; |
1536 | 1542 |
1537 ExpressionPrinter(this.writeer, this.minimumPrecedence); | 1543 ExpressionPrinter(this.writeer, this.minimumPrecedence); |
1538 } | 1544 } |
OLD | NEW |