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

Side by Side Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 925943002: Refactor SourceFile, SourceFileProvider and SourceLocation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 5 years, 10 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 | « no previous file | pkg/compiler/lib/src/dart2js.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) 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 leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import '../compiler.dart' as api; 9 import '../compiler.dart' as api;
10 import 'dart2jslib.dart' as leg; 10 import 'dart2jslib.dart' as leg;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 withCurrentElement(element, () { 213 withCurrentElement(element, () {
214 reportError( 214 reportError(
215 node, 215 node,
216 leg.MessageKind.READ_SCRIPT_ERROR, 216 leg.MessageKind.READ_SCRIPT_ERROR,
217 {'uri': readableUri, 'exception': exception}); 217 {'uri': readableUri, 'exception': exception});
218 }); 218 });
219 } 219 }
220 } 220 }
221 221
222 Uri resourceUri = translateUri(node, readableUri); 222 Uri resourceUri = translateUri(node, readableUri);
223 String resourceUriString = '$resourceUri';
224 if (resourceUri.scheme == 'dart-ext') { 223 if (resourceUri.scheme == 'dart-ext') {
225 if (!allowNativeExtensions) { 224 if (!allowNativeExtensions) {
226 withCurrentElement(element, () { 225 withCurrentElement(element, () {
227 reportError(node, leg.MessageKind.DART_EXT_NOT_SUPPORTED); 226 reportError(node, leg.MessageKind.DART_EXT_NOT_SUPPORTED);
228 }); 227 });
229 } 228 }
230 return synthesizeScript(node, readableUri); 229 return synthesizeScript(node, readableUri);
231 } 230 }
232 231
233 // TODO(johnniwinther): Wrap the result from [provider] in a specialized 232 // TODO(johnniwinther): Wrap the result from [provider] in a specialized
234 // [Future] to ensure that we never execute an asynchronous action without 233 // [Future] to ensure that we never execute an asynchronous action without
235 // setting up the current element of the compiler. 234 // setting up the current element of the compiler.
236 return new Future.sync(() => callUserProvider(resourceUri)).then((data) { 235 return new Future.sync(() => callUserProvider(resourceUri)).then((data) {
237 SourceFile sourceFile; 236 SourceFile sourceFile;
238 if (data is List<int>) { 237 if (data is List<int>) {
239 sourceFile = new Utf8BytesSourceFile(resourceUriString, data); 238 sourceFile = new Utf8BytesSourceFile(resourceUri, data);
240 } else if (data is String) { 239 } else if (data is String) {
241 sourceFile = new StringSourceFile(resourceUriString, data); 240 sourceFile = new StringSourceFile.fromUri(resourceUri, data);
242 } else { 241 } else {
243 String message = "Expected a 'String' or a 'List<int>' from the input " 242 String message = "Expected a 'String' or a 'List<int>' from the input "
244 "provider, but got: ${Error.safeToString(data)}."; 243 "provider, but got: ${Error.safeToString(data)}.";
245 reportReadError(message); 244 reportReadError(message);
246 } 245 }
247 // We use [readableUri] as the URI for the script since need to preserve 246 // We use [readableUri] as the URI for the script since need to preserve
248 // the scheme in the script because [Script.uri] is used for resolving 247 // the scheme in the script because [Script.uri] is used for resolving
249 // relative URIs mentioned in the script. See the comment on 248 // relative URIs mentioned in the script. See the comment on
250 // [LibraryLoader] for more details. 249 // [LibraryLoader] for more details.
251 return new leg.Script(readableUri, resourceUri, sourceFile); 250 return new leg.Script(readableUri, resourceUri, sourceFile);
252 }).catchError((error) { 251 }).catchError((error) {
253 reportReadError(error); 252 reportReadError(error);
254 return synthesizeScript(node, readableUri); 253 return synthesizeScript(node, readableUri);
255 }); 254 });
256 } 255 }
257 256
258 Future<leg.Script> synthesizeScript(leg.Spannable node, Uri readableUri) { 257 Future<leg.Script> synthesizeScript(leg.Spannable node, Uri readableUri) {
259 Uri resourceUri = translateUri(node, readableUri); 258 Uri resourceUri = translateUri(node, readableUri);
260 return new Future.value( 259 return new Future.value(
261 new leg.Script( 260 new leg.Script(
262 readableUri, resourceUri, 261 readableUri, resourceUri,
263 new StringSourceFile( 262 new StringSourceFile.fromUri(
264 '$resourceUri', 263 resourceUri,
265 "// Synthetic source file generated for '$readableUri'."), 264 "// Synthetic source file generated for '$readableUri'."),
266 isSynthesized: true)); 265 isSynthesized: true));
267 } 266 }
268 267
269 /** 268 /**
270 * Translates a readable URI into a resource URI. 269 * Translates a readable URI into a resource URI.
271 * 270 *
272 * See [LibraryLoader] for terminology on URIs. 271 * See [LibraryLoader] for terminology on URIs.
273 */ 272 */
274 Uri translateUri(leg.Spannable node, Uri readableUri) { 273 Uri translateUri(leg.Spannable node, Uri readableUri) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 print('$message: ${tryToString(exception)}'); 399 print('$message: ${tryToString(exception)}');
401 print(tryToString(stackTrace)); 400 print(tryToString(stackTrace));
402 } 401 }
403 402
404 fromEnvironment(String name) => environment[name]; 403 fromEnvironment(String name) => environment[name];
405 404
406 LibraryInfo lookupLibraryInfo(String libraryName) { 405 LibraryInfo lookupLibraryInfo(String libraryName) {
407 return library_info.LIBRARIES[libraryName]; 406 return library_info.LIBRARIES[libraryName];
408 } 407 }
409 } 408 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698