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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 var importPath = imports.getImportPath(library); | 295 var importPath = imports.getImportPath(library); |
296 if (importPath == "") { | 296 if (importPath == "") { |
297 var prefix = | 297 var prefix = |
298 syntheticNames.nameLibraryPrefix(library, proposedName: 'self'); | 298 syntheticNames.nameLibraryPrefix(library, proposedName: 'self'); |
299 endLine('import self as $prefix;'); | 299 endLine('import self as $prefix;'); |
300 } else { | 300 } else { |
301 var prefix = syntheticNames.nameLibraryPrefix(library); | 301 var prefix = syntheticNames.nameLibraryPrefix(library); |
302 endLine('import "$importPath" as $prefix;'); | 302 endLine('import "$importPath" as $prefix;'); |
303 } | 303 } |
304 } | 304 } |
| 305 for (var import in library.deferredImports) { |
| 306 import.accept(this); |
| 307 } |
305 endLine(); | 308 endLine(); |
306 var inner = new Printer._inner(this, imports); | 309 var inner = new Printer._inner(this, imports); |
307 library.classes.forEach(inner.writeNode); | 310 library.classes.forEach(inner.writeNode); |
308 library.fields.forEach(inner.writeNode); | 311 library.fields.forEach(inner.writeNode); |
309 library.procedures.forEach(inner.writeNode); | 312 library.procedures.forEach(inner.writeNode); |
310 } | 313 } |
311 | 314 |
312 void writeProgramFile(Program program) { | 315 void writeProgramFile(Program program) { |
313 ImportTable imports = new ProgramImportTable(program); | 316 ImportTable imports = new ProgramImportTable(program); |
314 var inner = new Printer._inner(this, imports); | 317 var inner = new Printer._inner(this, imports); |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 writeWord('null'); | 981 writeWord('null'); |
979 } | 982 } |
980 | 983 |
981 visitLet(Let node) { | 984 visitLet(Let node) { |
982 writeWord('let'); | 985 writeWord('let'); |
983 writeVariableDeclaration(node.variable); | 986 writeVariableDeclaration(node.variable); |
984 writeSpaced('in'); | 987 writeSpaced('in'); |
985 writeExpression(node.body); | 988 writeExpression(node.body); |
986 } | 989 } |
987 | 990 |
| 991 visitLoadLibrary(LoadLibrary node) { |
| 992 writeWord('LoadLibrary'); |
| 993 writeSymbol('('); |
| 994 writeWord(node.import.name); |
| 995 writeSymbol(')'); |
| 996 state = WORD; |
| 997 } |
| 998 |
| 999 visitCheckLibraryIsLoaded(CheckLibraryIsLoaded node) { |
| 1000 writeWord('CheckLibraryIsLoaded'); |
| 1001 writeSymbol('('); |
| 1002 writeWord(node.import.name); |
| 1003 writeSymbol(')'); |
| 1004 state = WORD; |
| 1005 } |
| 1006 |
| 1007 visitDeferredImport(DeferredImport node) { |
| 1008 write('import "'); |
| 1009 write('${node.importedLibrary.importUri}'); |
| 1010 write('" deferred as '); |
| 1011 write(node.name); |
| 1012 endLine(';'); |
| 1013 } |
| 1014 |
988 defaultExpression(Expression node) { | 1015 defaultExpression(Expression node) { |
989 writeWord('${node.runtimeType}'); | 1016 writeWord('${node.runtimeType}'); |
990 } | 1017 } |
991 | 1018 |
992 visitVariableGet(VariableGet node) { | 1019 visitVariableGet(VariableGet node) { |
993 writeVariableReference(node.variable); | 1020 writeVariableReference(node.variable); |
994 if (node.promotedType != null) { | 1021 if (node.promotedType != null) { |
995 writeSymbol('{'); | 1022 writeSymbol('{'); |
996 writeNode(node.promotedType); | 1023 writeNode(node.promotedType); |
997 writeSymbol('}'); | 1024 writeSymbol('}'); |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 } | 1580 } |
1554 throw 'illegal ProcedureKind: $kind'; | 1581 throw 'illegal ProcedureKind: $kind'; |
1555 } | 1582 } |
1556 | 1583 |
1557 class ExpressionPrinter { | 1584 class ExpressionPrinter { |
1558 final Printer writeer; | 1585 final Printer writeer; |
1559 final int minimumPrecedence; | 1586 final int minimumPrecedence; |
1560 | 1587 |
1561 ExpressionPrinter(this.writeer, this.minimumPrecedence); | 1588 ExpressionPrinter(this.writeer, this.minimumPrecedence); |
1562 } | 1589 } |
OLD | NEW |