Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: lib/src/codegen/dart_codegen.dart

Issue 1141013002: Fixes #179 -- compile error if editing files during server mode (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/codegen/code_generator.dart ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/devc.dart' show AbstractCompiler;
18 import 'package:dev_compiler/src/info.dart'; 19 import 'package:dev_compiler/src/info.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/utils.dart' as utils; 21 import 'package:dev_compiler/src/utils.dart' as utils;
22 import 'ast_builder.dart'; 22 import 'ast_builder.dart';
23 import 'code_generator.dart' as codegenerator; 23 import 'code_generator.dart' as codegenerator;
24 import 'reify_coercions.dart' 24 import 'reify_coercions.dart'
25 show CoercionReifier, NewTypeIdDesc, InstrumentedRuntime; 25 show CoercionReifier, NewTypeIdDesc, InstrumentedRuntime;
26 26
27 final _log = new logger.Logger('dev_compiler.dart_codegen'); 27 final _log = new logger.Logger('dev_compiler.dart_codegen');
28 28
29 class DevCompilerRuntime extends InstrumentedRuntime { 29 class DevCompilerRuntime extends InstrumentedRuntime {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 output(id.name); 378 output(id.name);
379 return null; 379 return null;
380 } 380 }
381 381
382 void generate() { 382 void generate() {
383 visitCompilationUnit(unit); 383 visitCompilationUnit(unit);
384 } 384 }
385 } 385 }
386 386
387 class DartGenerator extends codegenerator.CodeGenerator { 387 class DartGenerator extends codegenerator.CodeGenerator {
388 final CompilerOptions options;
389 TypeRules _rules;
390 final DevCompilerRuntime _runtime = new DevCompilerRuntime(); 388 final DevCompilerRuntime _runtime = new DevCompilerRuntime();
391 389
392 DartGenerator(String outDir, Uri root, TypeRules rules, this.options) 390 DartGenerator(AbstractCompiler compiler) : super(compiler);
393 : _rules = rules,
394 super(outDir, root, rules);
395 391
396 Set<LibraryElement> computeExtraImports(Map<Identifier, NewTypeIdDesc> ids) { 392 Set<LibraryElement> computeExtraImports(Map<Identifier, NewTypeIdDesc> ids) {
397 var imports = new Set<LibraryElement>(); 393 var imports = new Set<LibraryElement>();
398 void process(Identifier id, NewTypeIdDesc desc) { 394 void process(Identifier id, NewTypeIdDesc desc) {
399 if (_identifierNeedsQualification(id, desc)) { 395 if (_identifierNeedsQualification(id, desc)) {
400 var library = desc.importedFrom; 396 var library = desc.importedFrom;
401 if (utils.isDartPrivateLibrary(library)) { 397 if (utils.isDartPrivateLibrary(library)) {
402 _log.severe("Dropping import of private library ${library}\n"); 398 _log.severe("Dropping import of private library ${library}\n");
403 return; 399 return;
404 } 400 }
405 imports.add(library); 401 imports.add(library);
406 } 402 }
407 } 403 }
408 ids.forEach(process); 404 ids.forEach(process);
409 return imports; 405 return imports;
410 } 406 }
411 407
412 String generateLibrary(LibraryUnit library, LibraryInfo info) { 408 String generateLibrary(LibraryUnit library, LibraryInfo info) {
413 var r = new CoercionReifier(library, rules, options, _runtime); 409 var r = new CoercionReifier(library, compiler, _runtime);
414 var ids = r.reify(); 410 var ids = r.reify();
415 var extraImports = computeExtraImports(ids); 411 var extraImports = computeExtraImports(ids);
416 412
417 for (var unit in library.partsThenLibrary) { 413 for (var unit in library.partsThenLibrary) {
418 var libraryDir = makeOutputDirectory(info, unit); 414 var libraryDir = makeOutputDirectory(info, unit);
419 var uri = unit.element.source.uri; 415 var uri = unit.element.source.uri;
420 _log.fine("Generating unit $uri"); 416 _log.fine("Generating unit $uri");
421 FileWriter out = new FileWriter( 417 FileWriter out = new FileWriter(
422 options, path.join(libraryDir, '${uri.pathSegments.last}')); 418 options, path.join(libraryDir, '${uri.pathSegments.last}'));
423 var unitGen = 419 var unitGen =
(...skipping 17 matching lines...) Expand all
441 void output(String s) => _out.print(s); 437 void output(String s) => _out.print(s);
442 void outputln(String s) => _out.println(s); 438 void outputln(String s) => _out.println(s);
443 439
444 void generate() { 440 void generate() {
445 unit.visitChildren(this); 441 unit.visitChildren(this);
446 } 442 }
447 } 443 }
448 444
449 // This class emits the code unchanged, for comparison purposes. 445 // This class emits the code unchanged, for comparison purposes.
450 class EmptyDartGenerator extends codegenerator.CodeGenerator { 446 class EmptyDartGenerator extends codegenerator.CodeGenerator {
451 final CompilerOptions options; 447 EmptyDartGenerator(AbstractCompiler compiler) : super(compiler);
452
453 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options)
454 : super(outDir, root, rules);
455 448
456 String generateLibrary(LibraryUnit library, LibraryInfo info) { 449 String generateLibrary(LibraryUnit library, LibraryInfo info) {
457 for (var unit in library.partsThenLibrary) { 450 for (var unit in library.partsThenLibrary) {
458 var outputDir = makeOutputDirectory(info, unit); 451 var outputDir = makeOutputDirectory(info, unit);
459 generateUnit(unit, info, outputDir); 452 generateUnit(unit, info, outputDir);
460 } 453 }
461 return null; 454 return null;
462 } 455 }
463 456
464 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { 457 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) {
465 var uri = unit.element.source.uri; 458 var uri = unit.element.source.uri;
466 _log.fine("Emitting original unit " + uri.toString()); 459 _log.fine("Emitting original unit " + uri.toString());
467 FileWriter out = new FileWriter( 460 FileWriter out = new FileWriter(
468 options, path.join(libraryDir, '${uri.pathSegments.last}')); 461 options, path.join(libraryDir, '${uri.pathSegments.last}'));
469 var unitGen = new EmptyUnitGenerator(unit, out); 462 var unitGen = new EmptyUnitGenerator(unit, out);
470 unitGen.generate(); 463 unitGen.generate();
471 out.finalize(); 464 out.finalize();
472 } 465 }
473 } 466 }
OLDNEW
« no previous file with comments | « lib/src/codegen/code_generator.dart ('k') | lib/src/codegen/js_codegen.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698