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

Side by Side Diff: dart/site/try/poi/poi.dart

Issue 636903002: Compute an incremental patch to JavaScript code. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use Namer.elementAccess (to address Johnni's comment) Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « dart/site/try/poi/patcher.js ('k') | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 trydart.poi; 5 library trydart.poi;
6 6
7 import 'dart:async' show 7 import 'dart:async' show
8 Completer, 8 Completer,
9 Future; 9 Future;
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 import 'package:compiler/implementation/scanner/scannerlib.dart' show 55 import 'package:compiler/implementation/scanner/scannerlib.dart' show
56 EOF_TOKEN, 56 EOF_TOKEN,
57 IDENTIFIER_TOKEN, 57 IDENTIFIER_TOKEN,
58 KEYWORD_TOKEN, 58 KEYWORD_TOKEN,
59 PartialClassElement, 59 PartialClassElement,
60 PartialElement, 60 PartialElement,
61 Token; 61 Token;
62 62
63 import 'package:compiler/implementation/js/js.dart' show 63 import 'package:compiler/implementation/js/js.dart' show
64 prettyPrint; 64 js;
65 65
66 /// Enabled by the option --enable-dart-mind. Controls if this program should 66 /// Enabled by the option --enable-dart-mind. Controls if this program should
67 /// be querying Dart Mind. 67 /// be querying Dart Mind.
68 bool isDartMindEnabled = false; 68 bool isDartMindEnabled = false;
69 69
70 /// Iterator over lines from standard input (or the argument array). 70 /// Iterator over lines from standard input (or the argument array).
71 Iterator<String> stdin; 71 Iterator<String> stdin;
72 72
73 /// Enabled by the option --simulate-mutation. When true, this program will 73 /// Enabled by the option --simulate-mutation. When true, this program will
74 /// only prompt for one file name, and subsequent runs will read 74 /// only prompt for one file name, and subsequent runs will read
(...skipping 14 matching lines...) Expand all
89 int globalCounter = 0; 89 int globalCounter = 0;
90 90
91 /// Enabled by the option --verbose (or -v). Prints more information than you 91 /// Enabled by the option --verbose (or -v). Prints more information than you
92 /// really need. 92 /// really need.
93 bool isVerbose = false; 93 bool isVerbose = false;
94 94
95 /// Enabled by the option --compile. Also compiles the program after analyzing 95 /// Enabled by the option --compile. Also compiles the program after analyzing
96 /// the POI. 96 /// the POI.
97 bool isCompiler = false; 97 bool isCompiler = false;
98 98
99 /// Enabled by the option --minify. Passes the same option to the compiler to
100 /// generate minified output.
101 bool enableMinification = false;
102
99 /// When true (the default value) print serialized scope information at the 103 /// When true (the default value) print serialized scope information at the
100 /// provided position. 104 /// provided position.
101 const bool PRINT_SCOPE_INFO = 105 const bool PRINT_SCOPE_INFO =
102 const bool.fromEnvironment('PRINT_SCOPE_INFO', defaultValue: true); 106 const bool.fromEnvironment('PRINT_SCOPE_INFO', defaultValue: true);
103 107
104 Stopwatch wallClock = new Stopwatch(); 108 Stopwatch wallClock = new Stopwatch();
105 109
106 PoiTask poiTask; 110 PoiTask poiTask;
107 111
108 Compiler cachedCompiler; 112 Compiler cachedCompiler;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 case '--enable-dart-mind': 157 case '--enable-dart-mind':
154 isDartMindEnabled = true; 158 isDartMindEnabled = true;
155 break; 159 break;
156 case '-v': 160 case '-v':
157 case '--verbose': 161 case '--verbose':
158 isVerbose = true; 162 isVerbose = true;
159 break; 163 break;
160 case '--compile': 164 case '--compile':
161 isCompiler = true; 165 isCompiler = true;
162 break; 166 break;
167 case '--minify':
168 enableMinification = true;
169 break;
163 default: 170 default:
164 throw 'Unknown option: $argument.'; 171 throw 'Unknown option: $argument.';
165 } 172 }
166 } else { 173 } else {
167 nonOptionArguments.add(argument); 174 nonOptionArguments.add(argument);
168 } 175 }
169 } 176 }
170 if (nonOptionArguments.isEmpty) { 177 if (nonOptionArguments.isEmpty) {
171 stdin = new StdinIterator(); 178 stdin = new StdinIterator();
172 } else { 179 } else {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 if (uri == script) { 212 if (uri == script) {
206 if (poiCount == count) { 213 if (poiCount == count) {
207 cachedFileName = uri.toFilePath(); 214 cachedFileName = uri.toFilePath();
208 if (count != 0) { 215 if (count != 0) {
209 cachedFileName = '$cachedFileName.$count.dart'; 216 cachedFileName = '$cachedFileName.$count.dart';
210 } 217 }
211 printVerbose('Not using cached version of $cachedFileName'); 218 printVerbose('Not using cached version of $cachedFileName');
212 cache = new io.File(cachedFileName).readAsBytes().then((data) { 219 cache = new io.File(cachedFileName).readAsBytes().then((data) {
213 printVerbose( 220 printVerbose(
214 'Read file $cachedFileName: ' 221 'Read file $cachedFileName: '
215 '${UTF8.decode(data.sublist(0, 100), allowMalformed: true)}...'); 222 '${UTF8.decode(data.take(100).toList(), allowMalformed: true)}...' );
216 return data; 223 return data;
217 }); 224 });
218 count++; 225 count++;
219 } else { 226 } else {
220 printVerbose('Using cached version of $cachedFileName'); 227 printVerbose('Using cached version of $cachedFileName');
221 } 228 }
222 return cache; 229 return cache;
223 } else { 230 } else {
224 printVerbose('Using original provider for $uri'); 231 printVerbose('Using original provider for $uri');
225 return inputProvider(uri); 232 return inputProvider(uri);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 '--verbose', 386 '--verbose',
380 '--categories=Client,Server', 387 '--categories=Client,Server',
381 '--incremental-support', 388 '--incremental-support',
382 '--disable-type-inference', 389 '--disable-type-inference',
383 ]; 390 ];
384 391
385 if (!isCompiler) { 392 if (!isCompiler) {
386 options.add('--analyze-only'); 393 options.add('--analyze-only');
387 } 394 }
388 395
396 if (enableMinification) {
397 options.add('--minify');
398 }
399
389 LibraryUpdater updater = 400 LibraryUpdater updater =
390 new LibraryUpdater( 401 new LibraryUpdater(
391 cachedCompiler, inputProvider, script, printWallClock, printVerbose); 402 cachedCompiler, inputProvider, script, printWallClock, printVerbose);
392 Future<bool> reuseLibrary(LibraryElement library) { 403 Future<bool> reuseLibrary(LibraryElement library) {
393 return poiTask.measure(() => updater.reuseLibrary(library)); 404 return poiTask.measure(() => updater.reuseLibrary(library));
394 } 405 }
395 406
396 return reuseCompiler( 407 return reuseCompiler(
397 diagnosticHandler: handler, 408 diagnosticHandler: handler,
398 inputProvider: inputProvider, 409 inputProvider: inputProvider,
(...skipping 24 matching lines...) Expand all
423 434
424 if (!isFullCompile) { 435 if (!isFullCompile) {
425 printFormattedTime( 436 printFormattedTime(
426 'Analyzing changes and updating elements took', sw.elapsedMicroseconds); 437 'Analyzing changes and updating elements took', sw.elapsedMicroseconds);
427 } 438 }
428 sw.reset(); 439 sw.reset();
429 440
430 Future<bool> compilation; 441 Future<bool> compilation;
431 442
432 if (updater.hasPendingUpdates) { 443 if (updater.hasPendingUpdates) {
433 List<Element> updatedElements = updater.applyUpdates();
434 compilation = new Future(() { 444 compilation = new Future(() {
435 cachedCompiler.progress.reset(); 445 var node = js.statement(
436 for (Element element in updatedElements) { 446 r'var $dart_patch = #', js.escapedString(updater.computeUpdateJs()));
437 cachedCompiler.enqueuer.resolution.addToWorkList(element); 447 print(updater.prettyPrintJs(node));
438 }
439 cachedCompiler.processQueue(cachedCompiler.enqueuer.resolution, null);
440
441 cachedCompiler.phase = Compiler.PHASE_DONE_RESOLVING;
442
443 for (Element element in updatedElements) {
444 cachedCompiler.enqueuer.codegen.addToWorkList(element);
445 }
446 cachedCompiler.processQueue(cachedCompiler.enqueuer.codegen, null);
447
448 for (Element element in updatedElements) {
449 var node = cachedCompiler.enqueuer.codegen.generatedCode[element];
450 print(prettyPrint(node, cachedCompiler).getText());
451 }
452 448
453 return !cachedCompiler.compilationFailed; 449 return !cachedCompiler.compilationFailed;
454 }); 450 });
455 } else { 451 } else {
456 compilation = cachedCompiler.run(updater.uri); 452 compilation = cachedCompiler.run(updater.uri);
457 } 453 }
458 454
459 return compilation.then((success) { 455 return compilation.then((success) {
460 printVerbose('Compiler queue processed in ${sw.elapsedMicroseconds}us'); 456 printVerbose('Compiler queue processed in ${sw.elapsedMicroseconds}us');
461 if (isVerbose) { 457 if (isVerbose) {
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 783
788 modelx.ImportScope importScope(modelx.LibraryElementX element) { 784 modelx.ImportScope importScope(modelx.LibraryElementX element) {
789 return element.importScope; 785 return element.importScope;
790 } 786 }
791 787
792 class PoiTask extends CompilerTask { 788 class PoiTask extends CompilerTask {
793 PoiTask(Compiler compiler) : super(compiler); 789 PoiTask(Compiler compiler) : super(compiler);
794 790
795 String get name => 'POI'; 791 String get name => 'POI';
796 } 792 }
OLDNEW
« no previous file with comments | « dart/site/try/poi/patcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698