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 dev_compiler.src.codegen.dart_codegen; | 5 library dev_compiler.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 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 } | 445 } |
446 isLib(unit) => unit.directives.any((d) => d is LibraryDirective); | 446 isLib(unit) => unit.directives.any((d) => d is LibraryDirective); |
447 isNotLib(unit) => !isLib(unit); | 447 isNotLib(unit) => !isLib(unit); |
448 var libs = units.where(isLib); | 448 var libs = units.where(isLib); |
449 var parts = units.where(isNotLib); | 449 var parts = units.where(isNotLib); |
450 assert(libs.length == 1 || (libs.length == 0 && parts.length == 1)); | 450 assert(libs.length == 1 || (libs.length == 0 && parts.length == 1)); |
451 parts.forEach(doOne); | 451 parts.forEach(doOne); |
452 libs.forEach(doOne); | 452 libs.forEach(doOne); |
453 } | 453 } |
454 | 454 |
455 void generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info, | 455 String generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info, |
456 CheckerReporter reporter) { | 456 CheckerReporter reporter) { |
457 _vm = new reifier.VariableManager(); | 457 _vm = new reifier.VariableManager(); |
458 _extraImports = new Set<LibraryElement>(); | 458 _extraImports = new Set<LibraryElement>(); |
459 _generateLibrary(units, info, reporter); | 459 _generateLibrary(units, info, reporter); |
460 _extraImports = null; | 460 _extraImports = null; |
461 _vm = null; | 461 _vm = null; |
| 462 return null; |
462 } | 463 } |
463 } | 464 } |
464 | 465 |
465 class EmptyUnitGenerator extends UnitGeneratorCommon { | 466 class EmptyUnitGenerator extends UnitGeneratorCommon { |
466 final java_core.PrintWriter _out; | 467 final java_core.PrintWriter _out; |
467 CompilationUnit unit; | 468 CompilationUnit unit; |
468 | 469 |
469 EmptyUnitGenerator(this.unit, java_core.PrintWriter out) | 470 EmptyUnitGenerator(this.unit, java_core.PrintWriter out) |
470 : _out = out, | 471 : _out = out, |
471 super(out); | 472 super(out); |
472 | 473 |
473 void output(String s) => _out.print(s); | 474 void output(String s) => _out.print(s); |
474 void outputln(String s) => _out.println(s); | 475 void outputln(String s) => _out.println(s); |
475 | 476 |
476 void generate() { | 477 void generate() { |
477 unit.visitChildren(this); | 478 unit.visitChildren(this); |
478 } | 479 } |
479 } | 480 } |
480 | 481 |
481 // This class emits the code unchanged, for comparison purposes. | 482 // This class emits the code unchanged, for comparison purposes. |
482 class EmptyDartGenerator extends codegenerator.CodeGenerator { | 483 class EmptyDartGenerator extends codegenerator.CodeGenerator { |
483 final CompilerOptions options; | 484 final CompilerOptions options; |
484 | 485 |
485 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options) | 486 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options) |
486 : super(outDir, root, rules); | 487 : super(outDir, root, rules); |
487 | 488 |
488 void generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info, | 489 String generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info, |
489 CheckerReporter reporter) { | 490 CheckerReporter reporter) { |
490 for (var unit in units) { | 491 for (var unit in units) { |
491 var outputDir = makeOutputDirectory(info, unit); | 492 var outputDir = makeOutputDirectory(info, unit); |
492 reporter.enterSource(unit.element.source); | 493 reporter.enterSource(unit.element.source); |
493 generateUnit(unit, info, outputDir); | 494 generateUnit(unit, info, outputDir); |
494 reporter.leaveSource(); | 495 reporter.leaveSource(); |
495 } | 496 } |
| 497 return null; |
496 } | 498 } |
497 | 499 |
498 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { | 500 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { |
499 var uri = unit.element.source.uri; | 501 var uri = unit.element.source.uri; |
500 _log.fine("Emitting original unit " + uri.toString()); | 502 _log.fine("Emitting original unit " + uri.toString()); |
501 FileWriter out = new FileWriter( | 503 FileWriter out = new FileWriter( |
502 options, path.join(libraryDir, '${uri.pathSegments.last}')); | 504 options, path.join(libraryDir, '${uri.pathSegments.last}')); |
503 var unitGen = new EmptyUnitGenerator(unit, out); | 505 var unitGen = new EmptyUnitGenerator(unit, out); |
504 unitGen.generate(); | 506 unitGen.generate(); |
505 out.finalize(); | 507 out.finalize(); |
506 } | 508 } |
507 } | 509 } |
OLD | NEW |