| 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'; |
| 11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
| 12 import 'package:analyzer/src/generated/java_core.dart' as java_core; | 12 import 'package:analyzer/src/generated/java_core.dart' as java_core; |
| 13 import 'package:analyzer/src/generated/scanner.dart' show Token; | 13 import 'package:analyzer/src/generated/scanner.dart' show Token; |
| 14 import 'package:dart_style/dart_style.dart'; | 14 import 'package:dart_style/dart_style.dart'; |
| 15 import 'package:logging/logging.dart' as logger; | 15 import 'package:logging/logging.dart' as logger; |
| 16 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
| 17 | 17 |
| 18 import 'package:dev_compiler/src/info.dart'; | 18 import 'package:dev_compiler/src/info.dart'; |
| 19 import 'package:dev_compiler/src/checker/rules.dart'; | 19 import 'package:dev_compiler/src/checker/rules.dart'; |
| 20 import 'package:dev_compiler/src/options.dart'; | 20 import 'package:dev_compiler/src/options.dart'; |
| 21 import 'package:dev_compiler/src/report.dart'; | |
| 22 import 'package:dev_compiler/src/utils.dart' as utils; | 21 import 'package:dev_compiler/src/utils.dart' as utils; |
| 23 import 'ast_builder.dart'; | 22 import 'ast_builder.dart'; |
| 24 import 'code_generator.dart' as codegenerator; | 23 import 'code_generator.dart' as codegenerator; |
| 25 import 'reify_coercions.dart' as reifier; | 24 import 'reify_coercions.dart' as reifier; |
| 26 | 25 |
| 27 final _log = new logger.Logger('dev_compiler.dart_codegen'); | 26 final _log = new logger.Logger('dev_compiler.dart_codegen'); |
| 28 | 27 |
| 29 class DevCompilerRuntime { | 28 class DevCompilerRuntime { |
| 30 Identifier _runtimeId = AstBuilder.identifierFromString("DEVC\$RT"); | 29 Identifier _runtimeId = AstBuilder.identifierFromString("DEVC\$RT"); |
| 31 | 30 |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 options, path.join(libraryDir, '${uri.pathSegments.last}')); | 427 options, path.join(libraryDir, '${uri.pathSegments.last}')); |
| 429 var tm = new reifier.TypeManager(_vm); | 428 var tm = new reifier.TypeManager(_vm); |
| 430 var r = new reifier.UnitCoercionReifier(tm, _vm, _rules); | 429 var r = new reifier.UnitCoercionReifier(tm, _vm, _rules); |
| 431 r.reify(unit); | 430 r.reify(unit); |
| 432 var ids = new Set<Identifier>.from(tm.addedTypes.map((tn) => tn.name)); | 431 var ids = new Set<Identifier>.from(tm.addedTypes.map((tn) => tn.name)); |
| 433 var unitGen = new UnitGenerator(unit, out, outDir, _extraImports, ids); | 432 var unitGen = new UnitGenerator(unit, out, outDir, _extraImports, ids); |
| 434 unitGen.generate(); | 433 unitGen.generate(); |
| 435 out.finalize(); | 434 out.finalize(); |
| 436 } | 435 } |
| 437 | 436 |
| 438 String generateLibrary( | 437 String generateLibrary(LibraryUnit library, LibraryInfo info) { |
| 439 LibraryUnit library, LibraryInfo info, CheckerReporter reporter) { | |
| 440 _vm = new reifier.VariableManager(); | 438 _vm = new reifier.VariableManager(); |
| 441 _extraImports = new Set<LibraryElement>(); | 439 _extraImports = new Set<LibraryElement>(); |
| 442 | 440 |
| 443 for (var unit in library.partsThenLibrary) { | 441 for (var unit in library.partsThenLibrary) { |
| 444 var outputDir = makeOutputDirectory(info, unit); | 442 var outputDir = makeOutputDirectory(info, unit); |
| 445 reporter.enterSource(unit.element.source); | |
| 446 generateUnit(unit, info, outputDir); | 443 generateUnit(unit, info, outputDir); |
| 447 reporter.leaveSource(); | |
| 448 } | 444 } |
| 449 | 445 |
| 450 _extraImports = null; | 446 _extraImports = null; |
| 451 _vm = null; | 447 _vm = null; |
| 452 return null; | 448 return null; |
| 453 } | 449 } |
| 454 } | 450 } |
| 455 | 451 |
| 456 class EmptyUnitGenerator extends UnitGeneratorCommon { | 452 class EmptyUnitGenerator extends UnitGeneratorCommon { |
| 457 final java_core.PrintWriter _out; | 453 final java_core.PrintWriter _out; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 469 } | 465 } |
| 470 } | 466 } |
| 471 | 467 |
| 472 // This class emits the code unchanged, for comparison purposes. | 468 // This class emits the code unchanged, for comparison purposes. |
| 473 class EmptyDartGenerator extends codegenerator.CodeGenerator { | 469 class EmptyDartGenerator extends codegenerator.CodeGenerator { |
| 474 final CompilerOptions options; | 470 final CompilerOptions options; |
| 475 | 471 |
| 476 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options) | 472 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options) |
| 477 : super(outDir, root, rules); | 473 : super(outDir, root, rules); |
| 478 | 474 |
| 479 String generateLibrary( | 475 String generateLibrary(LibraryUnit library, LibraryInfo info) { |
| 480 LibraryUnit library, LibraryInfo info, CheckerReporter reporter) { | |
| 481 for (var unit in library.partsThenLibrary) { | 476 for (var unit in library.partsThenLibrary) { |
| 482 var outputDir = makeOutputDirectory(info, unit); | 477 var outputDir = makeOutputDirectory(info, unit); |
| 483 reporter.enterSource(unit.element.source); | |
| 484 generateUnit(unit, info, outputDir); | 478 generateUnit(unit, info, outputDir); |
| 485 reporter.leaveSource(); | |
| 486 } | 479 } |
| 487 return null; | 480 return null; |
| 488 } | 481 } |
| 489 | 482 |
| 490 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { | 483 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { |
| 491 var uri = unit.element.source.uri; | 484 var uri = unit.element.source.uri; |
| 492 _log.fine("Emitting original unit " + uri.toString()); | 485 _log.fine("Emitting original unit " + uri.toString()); |
| 493 FileWriter out = new FileWriter( | 486 FileWriter out = new FileWriter( |
| 494 options, path.join(libraryDir, '${uri.pathSegments.last}')); | 487 options, path.join(libraryDir, '${uri.pathSegments.last}')); |
| 495 var unitGen = new EmptyUnitGenerator(unit, out); | 488 var unitGen = new EmptyUnitGenerator(unit, out); |
| 496 unitGen.generate(); | 489 unitGen.generate(); |
| 497 out.finalize(); | 490 out.finalize(); |
| 498 } | 491 } |
| 499 } | 492 } |
| OLD | NEW |