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

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

Issue 1011153002: js: fix core.Object, output order, static const fields (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 9 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';
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 String generateLibrary(
439 CheckerReporter reporter) { 439 LibraryUnit library, LibraryInfo info, CheckerReporter reporter) {
440 doOne(unit) { 440 _vm = new reifier.VariableManager();
441 _extraImports = new Set<LibraryElement>();
442
443 for (var unit in library.partsThenLibrary) {
441 var outputDir = makeOutputDirectory(info, unit); 444 var outputDir = makeOutputDirectory(info, unit);
442 reporter.enterSource(unit.element.source); 445 reporter.enterSource(unit.element.source);
443 generateUnit(unit, info, outputDir); 446 generateUnit(unit, info, outputDir);
444 reporter.leaveSource(); 447 reporter.leaveSource();
445 } 448 }
446 isLib(unit) => unit.directives.any((d) => d is LibraryDirective);
447 isNotLib(unit) => !isLib(unit);
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 }
454 449
455 String generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info,
456 CheckerReporter reporter) {
457 _vm = new reifier.VariableManager();
458 _extraImports = new Set<LibraryElement>();
459 _generateLibrary(units, info, reporter);
460 _extraImports = null; 450 _extraImports = null;
461 _vm = null; 451 _vm = null;
462 return null; 452 return null;
463 } 453 }
464 } 454 }
465 455
466 class EmptyUnitGenerator extends UnitGeneratorCommon { 456 class EmptyUnitGenerator extends UnitGeneratorCommon {
467 final java_core.PrintWriter _out; 457 final java_core.PrintWriter _out;
468 CompilationUnit unit; 458 CompilationUnit unit;
469 459
470 EmptyUnitGenerator(this.unit, java_core.PrintWriter out) 460 EmptyUnitGenerator(this.unit, java_core.PrintWriter out)
471 : _out = out, 461 : _out = out,
472 super(out); 462 super(out);
473 463
474 void output(String s) => _out.print(s); 464 void output(String s) => _out.print(s);
475 void outputln(String s) => _out.println(s); 465 void outputln(String s) => _out.println(s);
476 466
477 void generate() { 467 void generate() {
478 unit.visitChildren(this); 468 unit.visitChildren(this);
479 } 469 }
480 } 470 }
481 471
482 // This class emits the code unchanged, for comparison purposes. 472 // This class emits the code unchanged, for comparison purposes.
483 class EmptyDartGenerator extends codegenerator.CodeGenerator { 473 class EmptyDartGenerator extends codegenerator.CodeGenerator {
484 final CompilerOptions options; 474 final CompilerOptions options;
485 475
486 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options) 476 EmptyDartGenerator(String outDir, Uri root, TypeRules rules, this.options)
487 : super(outDir, root, rules); 477 : super(outDir, root, rules);
488 478
489 String generateLibrary(Iterable<CompilationUnit> units, LibraryInfo info, 479 String generateLibrary(
490 CheckerReporter reporter) { 480 LibraryUnit library, LibraryInfo info, CheckerReporter reporter) {
491 for (var unit in units) { 481 for (var unit in library.partsThenLibrary) {
492 var outputDir = makeOutputDirectory(info, unit); 482 var outputDir = makeOutputDirectory(info, unit);
493 reporter.enterSource(unit.element.source); 483 reporter.enterSource(unit.element.source);
494 generateUnit(unit, info, outputDir); 484 generateUnit(unit, info, outputDir);
495 reporter.leaveSource(); 485 reporter.leaveSource();
496 } 486 }
497 return null; 487 return null;
498 } 488 }
499 489
500 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) { 490 void generateUnit(CompilationUnit unit, LibraryInfo info, String libraryDir) {
501 var uri = unit.element.source.uri; 491 var uri = unit.element.source.uri;
502 _log.fine("Emitting original unit " + uri.toString()); 492 _log.fine("Emitting original unit " + uri.toString());
503 FileWriter out = new FileWriter( 493 FileWriter out = new FileWriter(
504 options, path.join(libraryDir, '${uri.pathSegments.last}')); 494 options, path.join(libraryDir, '${uri.pathSegments.last}'));
505 var unitGen = new EmptyUnitGenerator(unit, out); 495 var unitGen = new EmptyUnitGenerator(unit, out);
506 unitGen.generate(); 496 unitGen.generate();
507 out.finalize(); 497 out.finalize();
508 } 498 }
509 } 499 }
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