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

Side by Side Diff: lib/compiler/implementation/dart2js.dart

Issue 10579019: First shot at source maps generation in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 6 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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('dart2js'); 5 #library('dart2js');
6 6
7 #import('dart:io'); 7 #import('dart:io');
8 #import('dart:uri'); 8 #import('dart:uri');
9 #import('dart:utf'); 9 #import('dart:utf');
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 } 65 }
66 66
67 void compile(List<String> argv) { 67 void compile(List<String> argv) {
68 Uri cwd = getCurrentDirectory(); 68 Uri cwd = getCurrentDirectory();
69 bool throwOnError = false; 69 bool throwOnError = false;
70 bool showWarnings = true; 70 bool showWarnings = true;
71 bool verbose = false; 71 bool verbose = false;
72 Uri libraryRoot = cwd; 72 Uri libraryRoot = cwd;
73 Uri out = cwd.resolve('out.js'); 73 Uri out = cwd.resolve('out.js');
74 Uri sourceMapOut = cwd.resolve('out.js.map');
74 Uri packageRoot = null; 75 Uri packageRoot = null;
75 List<String> options = new List<String>(); 76 List<String> options = new List<String>();
76 bool explicitOut = false; 77 bool explicitOut = false;
77 bool wantHelp = false; 78 bool wantHelp = false;
78 bool enableColors = true; 79 bool enableColors = true;
79 80
80 passThrough(String argument) => options.add(argument); 81 passThrough(String argument) => options.add(argument);
81 82
82 setLibraryRoot(String argument) { 83 setLibraryRoot(String argument) {
83 libraryRoot = cwd.resolve(extractPath(argument)); 84 libraryRoot = cwd.resolve(extractPath(argument));
84 } 85 }
85 86
86 setPackageRoot(String argument) { 87 setPackageRoot(String argument) {
87 packageRoot = cwd.resolve(extractPath(argument)); 88 packageRoot = cwd.resolve(extractPath(argument));
88 } 89 }
89 90
90 setOutput(String argument) { 91 setOutput(String argument) {
91 explicitOut = true; 92 explicitOut = true;
92 out = cwd.resolve(nativeToUriPath(extractParameter(argument))); 93 out = cwd.resolve(nativeToUriPath(extractParameter(argument)));
94 sourceMapOut = new Uri.fromString('$out.map');
93 } 95 }
94 96
95 handleShortOptions(String argument) { 97 handleShortOptions(String argument) {
96 var shortOptions = argument.substring(1).splitChars(); 98 var shortOptions = argument.substring(1).splitChars();
97 for (var shortOption in shortOptions) { 99 for (var shortOption in shortOptions) {
98 switch (shortOption) { 100 switch (shortOption) {
99 case 'v': 101 case 'v':
100 verbose = true; 102 verbose = true;
101 break; 103 break;
102 case 'h': 104 case 'h':
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 176 }
175 177
176 bool isAborting = false; 178 bool isAborting = false;
177 179
178 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal; 180 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal;
179 final int INFO = 181 final int INFO =
180 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal; 182 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal;
181 183
182 void handler(Uri uri, int begin, int end, String message, 184 void handler(Uri uri, int begin, int end, String message,
183 api.Diagnostic kind) { 185 api.Diagnostic kind) {
186 if (kind.name === 'source map') {
187 // TODO(podivilov): We should find a better way to return source maps from
188 // emitter. Using diagnostic handler for that purpose is a temporary hack.
189 writeString(sourceMapOut, message);
190 return;
191 }
192
184 if (isAborting) return; 193 if (isAborting) return;
185 isAborting = kind === api.Diagnostic.CRASH; 194 isAborting = kind === api.Diagnostic.CRASH;
186 bool fatal = (kind.ordinal & FATAL) != 0; 195 bool fatal = (kind.ordinal & FATAL) != 0;
187 bool isInfo = (kind.ordinal & INFO) != 0; 196 bool isInfo = (kind.ordinal & INFO) != 0;
188 if (isInfo) { 197 if (isInfo) {
189 assert(uri === null); 198 assert(uri === null);
190 info(message, kind); 199 info(message, kind);
191 return; 200 return;
192 } 201 }
193 var color; 202 var color;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 info('compiling $uri'); 235 info('compiling $uri');
227 info('package root is $packageRoot'); 236 info('package root is $packageRoot');
228 237
229 // TODO(ahe): We expect the future to be complete and call value 238 // TODO(ahe): We expect the future to be complete and call value
230 // directly. In effect, we don't support truly asynchronous API. 239 // directly. In effect, we don't support truly asynchronous API.
231 String code = api.compile(uri, libraryRoot, packageRoot, provider, handler, 240 String code = api.compile(uri, libraryRoot, packageRoot, provider, handler,
232 options).value; 241 options).value;
233 if (code === null) { 242 if (code === null) {
234 fail('Error: Compilation failed.'); 243 fail('Error: Compilation failed.');
235 } 244 }
245 code = '$code\n//@ sourceMappingURL=${relativize(out, sourceMapOut)}';
236 writeString(out, code); 246 writeString(out, code);
237 int jsBytesWritten = code.length; 247 int jsBytesWritten = code.length;
238 info('compiled $dartBytesRead bytes Dart -> $jsBytesWritten bytes JS ' 248 info('compiled $dartBytesRead bytes Dart -> $jsBytesWritten bytes JS '
239 'in ${relativize(cwd, out)}'); 249 'in ${relativize(cwd, out)}');
240 if (!explicitOut) { 250 if (!explicitOut) {
241 String input = uriPathToNative(arguments[0]); 251 String input = uriPathToNative(arguments[0]);
242 String output = relativize(cwd, out); 252 String output = relativize(cwd, out);
243 print('Dart file $input compiled to JavaScript: $output'); 253 print('Dart file $input compiled to JavaScript: $output');
244 } 254 }
245 } 255 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } catch (var ignored) { 374 } catch (var ignored) {
365 print('Internal error: error while printing exception'); 375 print('Internal error: error while printing exception');
366 } 376 }
367 try { 377 try {
368 print(trace); 378 print(trace);
369 } finally { 379 } finally {
370 exit(253); // 253 is recognized as a crash by our test scripts. 380 exit(253); // 253 is recognized as a crash by our test scripts.
371 } 381 }
372 } 382 }
373 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698