Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 4 |
| 5 library ddc.src.codegen.dart_codegen; | 5 library ddc.src.codegen.dart_codegen; |
| 6 | 6 |
| 7 import 'dart:io' show File; | 7 import 'dart:io' show File; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart' as analyzer; | 9 import 'package:analyzer/analyzer.dart' as analyzer; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 var args = oper.arguments; | 60 var args = oper.arguments; |
| 61 return AstBuilder.application(id, args); | 61 return AstBuilder.application(id, args); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 // TODO(leafp) This is kind of a hack, but it works for now. | 65 // TODO(leafp) This is kind of a hack, but it works for now. |
| 66 class FileWriter extends java_core.PrintStringWriter { | 66 class FileWriter extends java_core.PrintStringWriter { |
| 67 bool _format; | 67 bool _format; |
| 68 String _path; | 68 String _path; |
| 69 FileWriter(this._format, this._path); | 69 FileWriter(this._format, this._path); |
| 70 int indent = 0; | |
| 71 | |
| 72 void print(x) { | |
| 73 if (_format) { | |
| 74 super.print(x); | |
| 75 return; | |
| 76 } | |
| 77 | |
| 78 if (x == '{') { | |
|
Siggi Cherem (dart-lang)
2015/02/26 21:03:49
turns out that the ToStringVIsitor class calls pri
Leaf
2015/02/26 21:42:14
Won't this break things? For example, printing a
Jennifer Messerly
2015/02/26 23:49:50
yeah, +1 on changing the visitor ... IMO it should
| |
| 79 indent++; | |
| 80 x = '{\n${" " * indent}'; | |
| 81 } else if (x == ';') { | |
| 82 x = ';\n${" " * indent}'; | |
| 83 } else if (x == '}') { | |
| 84 indent--; | |
| 85 x = '}\n${" " * indent}'; | |
| 86 } | |
| 87 super.print(x); | |
| 88 } | |
| 70 | 89 |
| 71 void finalize() { | 90 void finalize() { |
| 72 String s = toString(); | 91 String s = toString(); |
| 73 if (_format) { | 92 if (_format) { |
| 74 DartFormatter d = new DartFormatter(); | 93 DartFormatter d = new DartFormatter(); |
| 75 try { | 94 try { |
| 76 _log.fine("Formatting file $_path "); | 95 _log.fine("Formatting file $_path "); |
| 77 s = d.format(s, uri: _path); | 96 s = d.format(s, uri: _path); |
| 78 } catch (e) { | 97 } catch (e) { |
| 79 _log.severe("Failed to format $_path: " + e.toString()); | 98 _log.severe("Failed to format $_path: " + e.toString()); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { | 466 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { |
| 448 var uri = unit.element.source.uri; | 467 var uri = unit.element.source.uri; |
| 449 _log.fine("Emitting original unit " + uri.toString()); | 468 _log.fine("Emitting original unit " + uri.toString()); |
| 450 FileWriter out = new FileWriter( | 469 FileWriter out = new FileWriter( |
| 451 _format, path.join(libraryDir, '${uri.pathSegments.last}')); | 470 _format, path.join(libraryDir, '${uri.pathSegments.last}')); |
| 452 var unitGen = new EmptyUnitGenerator(unit, out); | 471 var unitGen = new EmptyUnitGenerator(unit, out); |
| 453 unitGen.generate(); | 472 unitGen.generate(); |
| 454 out.finalize(); | 473 out.finalize(); |
| 455 } | 474 } |
| 456 } | 475 } |
| OLD | NEW |