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