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

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

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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 | « pkg/compiler/lib/compiler_new.dart ('k') | pkg/compiler/lib/src/cache_strategy.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 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:package_config/packages.dart'; 10 import 'package:package_config/packages.dart';
11 import 'package:package_config/packages_file.dart' as pkgs; 11 import 'package:package_config/packages_file.dart' as pkgs;
12 import 'package:package_config/src/packages_impl.dart' show 12 import 'package:package_config/src/packages_impl.dart'
13 MapPackages, 13 show MapPackages, NonFilePackagesDirectoryPackages;
14 NonFilePackagesDirectoryPackages; 14 import 'package:package_config/src/util.dart' show checkValidPackageUri;
15 import 'package:package_config/src/util.dart' show
16 checkValidPackageUri;
17 15
18 import '../compiler_new.dart' as api; 16 import '../compiler_new.dart' as api;
19 import 'common.dart'; 17 import 'common.dart';
20 import 'common/tasks.dart' show 18 import 'common/tasks.dart' show GenericTask;
21 GenericTask;
22 import 'compiler.dart'; 19 import 'compiler.dart';
23 import 'diagnostics/messages.dart' show 20 import 'diagnostics/messages.dart' show Message;
24 Message;
25 import 'elements/elements.dart' as elements; 21 import 'elements/elements.dart' as elements;
26 import 'environment.dart'; 22 import 'environment.dart';
27 import 'io/source_file.dart'; 23 import 'io/source_file.dart';
28 import 'options.dart' show 24 import 'options.dart' show CompilerOptions;
29 CompilerOptions;
30 import 'platform_configuration.dart' as platform_configuration; 25 import 'platform_configuration.dart' as platform_configuration;
31 import 'script.dart'; 26 import 'script.dart';
32 27
33
34 /// Implements the [Compiler] using a [api.CompilerInput] for supplying the 28 /// Implements the [Compiler] using a [api.CompilerInput] for supplying the
35 /// sources. 29 /// sources.
36 class CompilerImpl extends Compiler { 30 class CompilerImpl extends Compiler {
37 api.CompilerInput provider; 31 api.CompilerInput provider;
38 api.CompilerDiagnostics handler; 32 api.CompilerDiagnostics handler;
39 Packages packages; 33 Packages packages;
40 bool mockableLibraryUsed = false; 34 bool mockableLibraryUsed = false;
41 35
42 /// A mapping of the dart: library-names to their location. 36 /// A mapping of the dart: library-names to their location.
43 /// 37 ///
44 /// Initialized in [setupSdk]. 38 /// Initialized in [setupSdk].
45 Map<String, Uri> sdkLibraries; 39 Map<String, Uri> sdkLibraries;
46 40
47 GenericTask userHandlerTask; 41 GenericTask userHandlerTask;
48 GenericTask userProviderTask; 42 GenericTask userProviderTask;
49 GenericTask userPackagesDiscoveryTask; 43 GenericTask userPackagesDiscoveryTask;
50 44
51 Uri get libraryRoot => options.platformConfigUri.resolve("."); 45 Uri get libraryRoot => options.platformConfigUri.resolve(".");
52 46
53 CompilerImpl(this.provider, api.CompilerOutput outputProvider, 47 CompilerImpl(this.provider, api.CompilerOutput outputProvider, this.handler,
54 this.handler, CompilerOptions options) 48 CompilerOptions options)
55 : super(options: options, outputProvider: outputProvider, 49 : super(
56 environment: new _Environment(options.environment)) { 50 options: options,
51 outputProvider: outputProvider,
52 environment: new _Environment(options.environment)) {
57 _Environment env = environment; 53 _Environment env = environment;
58 env.compiler = this; 54 env.compiler = this;
59 tasks.addAll([ 55 tasks.addAll([
60 userHandlerTask = new GenericTask('Diagnostic handler', this), 56 userHandlerTask = new GenericTask('Diagnostic handler', this),
61 userProviderTask = new GenericTask('Input provider', this), 57 userProviderTask = new GenericTask('Input provider', this),
62 userPackagesDiscoveryTask = 58 userPackagesDiscoveryTask = new GenericTask('Package discovery', this),
63 new GenericTask('Package discovery', this),
64 ]); 59 ]);
65 } 60 }
66 61
67
68 void log(message) { 62 void log(message) {
69 callUserHandler( 63 callUserHandler(
70 null, null, null, null, message, api.Diagnostic.VERBOSE_INFO); 64 null, null, null, null, message, api.Diagnostic.VERBOSE_INFO);
71 } 65 }
72 66
73 /// See [Compiler.translateResolvedUri]. 67 /// See [Compiler.translateResolvedUri].
74 Uri translateResolvedUri(elements.LibraryElement importingLibrary, 68 Uri translateResolvedUri(elements.LibraryElement importingLibrary,
75 Uri resolvedUri, Spannable spannable) { 69 Uri resolvedUri, Spannable spannable) {
76 if (resolvedUri.scheme == 'dart') { 70 if (resolvedUri.scheme == 'dart') {
77 return translateDartUri(importingLibrary, resolvedUri, spannable); 71 return translateDartUri(importingLibrary, resolvedUri, spannable);
78 } 72 }
79 return resolvedUri; 73 return resolvedUri;
80 } 74 }
81 75
82 /** 76 /**
83 * Reads the script designated by [readableUri]. 77 * Reads the script designated by [readableUri].
84 */ 78 */
85 Future<Script> readScript(Uri readableUri, [Spannable node]) { 79 Future<Script> readScript(Uri readableUri, [Spannable node]) {
86 if (!readableUri.isAbsolute) { 80 if (!readableUri.isAbsolute) {
87 if (node == null) node = NO_LOCATION_SPANNABLE; 81 if (node == null) node = NO_LOCATION_SPANNABLE;
88 reporter.internalError(node, 82 reporter.internalError(
89 'Relative uri $readableUri provided to readScript(Uri).'); 83 node, 'Relative uri $readableUri provided to readScript(Uri).');
90 } 84 }
91 85
92 // We need to store the current element since we are reporting read errors 86 // We need to store the current element since we are reporting read errors
93 // asynchronously and therefore need to restore the current element for 87 // asynchronously and therefore need to restore the current element for
94 // [node] to be valid. 88 // [node] to be valid.
95 elements.Element element = currentElement; 89 elements.Element element = currentElement;
96 void reportReadError(exception) { 90 void reportReadError(exception) {
97 if (element == null || node == null) { 91 if (element == null || node == null) {
98 reporter.reportErrorMessage( 92 reporter.reportErrorMessage(
99 new SourceSpan(readableUri, 0, 0), 93 new SourceSpan(readableUri, 0, 0),
100 MessageKind.READ_SELF_ERROR, 94 MessageKind.READ_SELF_ERROR,
101 {'uri': readableUri, 'exception': exception}); 95 {'uri': readableUri, 'exception': exception});
102 } else { 96 } else {
103 reporter.withCurrentElement(element, () { 97 reporter.withCurrentElement(element, () {
104 reporter.reportErrorMessage( 98 reporter.reportErrorMessage(node, MessageKind.READ_SCRIPT_ERROR,
105 node,
106 MessageKind.READ_SCRIPT_ERROR,
107 {'uri': readableUri, 'exception': exception}); 99 {'uri': readableUri, 'exception': exception});
108 }); 100 });
109 } 101 }
110 } 102 }
111 103
112 Uri resourceUri = translateUri(node, readableUri); 104 Uri resourceUri = translateUri(node, readableUri);
113 if (resourceUri == null) return _synthesizeScript(readableUri); 105 if (resourceUri == null) return _synthesizeScript(readableUri);
114 if (resourceUri.scheme == 'dart-ext') { 106 if (resourceUri.scheme == 'dart-ext') {
115 if (!options.allowNativeExtensions) { 107 if (!options.allowNativeExtensions) {
116 reporter.withCurrentElement(element, () { 108 reporter.withCurrentElement(element, () {
117 reporter.reportErrorMessage( 109 reporter.reportErrorMessage(node, MessageKind.DART_EXT_NOT_SUPPORTED);
118 node, MessageKind.DART_EXT_NOT_SUPPORTED);
119 }); 110 });
120 } 111 }
121 return _synthesizeScript(readableUri); 112 return _synthesizeScript(readableUri);
122 } 113 }
123 114
124 // TODO(johnniwinther): Wrap the result from [provider] in a specialized 115 // TODO(johnniwinther): Wrap the result from [provider] in a specialized
125 // [Future] to ensure that we never execute an asynchronous action without 116 // [Future] to ensure that we never execute an asynchronous action without
126 // setting up the current element of the compiler. 117 // setting up the current element of the compiler.
127 return new Future.sync(() => callUserProvider(resourceUri)).then((data) { 118 return new Future.sync(() => callUserProvider(resourceUri)).then((data) {
128 SourceFile sourceFile; 119 SourceFile sourceFile;
129 if (data is List<int>) { 120 if (data is List<int>) {
130 sourceFile = new Utf8BytesSourceFile(resourceUri, data); 121 sourceFile = new Utf8BytesSourceFile(resourceUri, data);
131 } else if (data is String) { 122 } else if (data is String) {
132 sourceFile = new StringSourceFile.fromUri(resourceUri, data); 123 sourceFile = new StringSourceFile.fromUri(resourceUri, data);
133 } else { 124 } else {
134 String message = "Expected a 'String' or a 'List<int>' from the input " 125 String message = "Expected a 'String' or a 'List<int>' from the input "
135 "provider, but got: ${Error.safeToString(data)}."; 126 "provider, but got: ${Error.safeToString(data)}.";
136 reportReadError(message); 127 reportReadError(message);
137 } 128 }
138 // We use [readableUri] as the URI for the script since need to preserve 129 // We use [readableUri] as the URI for the script since need to preserve
139 // the scheme in the script because [Script.uri] is used for resolving 130 // the scheme in the script because [Script.uri] is used for resolving
140 // relative URIs mentioned in the script. See the comment on 131 // relative URIs mentioned in the script. See the comment on
141 // [LibraryLoader] for more details. 132 // [LibraryLoader] for more details.
142 return new Script(readableUri, resourceUri, sourceFile); 133 return new Script(readableUri, resourceUri, sourceFile);
143 }).catchError((error) { 134 }).catchError((error) {
144 reportReadError(error); 135 reportReadError(error);
145 return _synthesizeScript(readableUri); 136 return _synthesizeScript(readableUri);
(...skipping 15 matching lines...) Expand all
161 /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative 152 /// Translates "resolvedUri" with scheme "dart" to a [uri] resolved relative
162 /// to `options.platformConfigUri` according to the information in the file at 153 /// to `options.platformConfigUri` according to the information in the file at
163 /// `options.platformConfigUri`. 154 /// `options.platformConfigUri`.
164 /// 155 ///
165 /// Returns null and emits an error if the library could not be found or 156 /// Returns null and emits an error if the library could not be found or
166 /// imported into [importingLibrary]. 157 /// imported into [importingLibrary].
167 /// 158 ///
168 /// Internal libraries (whose name starts with '_') can be only resolved if 159 /// Internal libraries (whose name starts with '_') can be only resolved if
169 /// [importingLibrary] is a platform or patch library. 160 /// [importingLibrary] is a platform or patch library.
170 Uri translateDartUri(elements.LibraryElement importingLibrary, 161 Uri translateDartUri(elements.LibraryElement importingLibrary,
171 Uri resolvedUri, Spannable spannable) { 162 Uri resolvedUri, Spannable spannable) {
172
173 Uri location = lookupLibraryUri(resolvedUri.path); 163 Uri location = lookupLibraryUri(resolvedUri.path);
174 164
175 if (location == null) { 165 if (location == null) {
176 reporter.reportErrorMessage( 166 reporter.reportErrorMessage(spannable, MessageKind.LIBRARY_NOT_FOUND,
177 spannable,
178 MessageKind.LIBRARY_NOT_FOUND,
179 {'resolvedUri': resolvedUri}); 167 {'resolvedUri': resolvedUri});
180 return null; 168 return null;
181 } 169 }
182 170
183 if (resolvedUri.path.startsWith('_') ) { 171 if (resolvedUri.path.startsWith('_')) {
184 bool allowInternalLibraryAccess = importingLibrary != null && 172 bool allowInternalLibraryAccess = importingLibrary != null &&
185 (importingLibrary.isPlatformLibrary || 173 (importingLibrary.isPlatformLibrary ||
186 importingLibrary.isPatch || 174 importingLibrary.isPatch ||
187 importingLibrary.canonicalUri.path 175 importingLibrary.canonicalUri.path
188 .contains('sdk/tests/compiler/dart2js_native')); 176 .contains('sdk/tests/compiler/dart2js_native'));
189 177
190 if (!allowInternalLibraryAccess) { 178 if (!allowInternalLibraryAccess) {
191 if (importingLibrary != null) { 179 if (importingLibrary != null) {
192 reporter.reportErrorMessage( 180 reporter.reportErrorMessage(
193 spannable, 181 spannable, MessageKind.INTERNAL_LIBRARY_FROM, {
194 MessageKind.INTERNAL_LIBRARY_FROM, 182 'resolvedUri': resolvedUri,
195 {'resolvedUri': resolvedUri, 183 'importingUri': importingLibrary.canonicalUri
196 'importingUri': importingLibrary.canonicalUri}); 184 });
197 } else { 185 } else {
198 reporter.reportErrorMessage( 186 reporter.reportErrorMessage(spannable, MessageKind.INTERNAL_LIBRARY,
199 spannable,
200 MessageKind.INTERNAL_LIBRARY,
201 {'resolvedUri': resolvedUri}); 187 {'resolvedUri': resolvedUri});
202 registerDisallowedLibraryUse(resolvedUri); 188 registerDisallowedLibraryUse(resolvedUri);
203 } 189 }
204 return null; 190 return null;
205 } 191 }
206 } 192 }
207 193
208 if (location.scheme == "unsupported") { 194 if (location.scheme == "unsupported") {
209 reporter.reportErrorMessage( 195 reporter.reportErrorMessage(spannable, MessageKind.LIBRARY_NOT_SUPPORTED,
210 spannable,
211 MessageKind.LIBRARY_NOT_SUPPORTED,
212 {'resolvedUri': resolvedUri}); 196 {'resolvedUri': resolvedUri});
213 registerDisallowedLibraryUse(resolvedUri); 197 registerDisallowedLibraryUse(resolvedUri);
214 return null; 198 return null;
215 } 199 }
216 200
217 if (resolvedUri.path == 'html' || 201 if (resolvedUri.path == 'html' || resolvedUri.path == 'io') {
218 resolvedUri.path == 'io') {
219 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart 202 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart
220 // supports this use case better. 203 // supports this use case better.
221 mockableLibraryUsed = true; 204 mockableLibraryUsed = true;
222 } 205 }
223 return location; 206 return location;
224 } 207 }
225 208
226 Uri translatePackageUri(Spannable node, Uri uri) { 209 Uri translatePackageUri(Spannable node, Uri uri) {
227 try { 210 try {
228 checkValidPackageUri(uri); 211 checkValidPackageUri(uri);
229 } on ArgumentError catch (e) { 212 } on ArgumentError catch (e) {
230 reporter.reportErrorMessage( 213 reporter.reportErrorMessage(node, MessageKind.INVALID_PACKAGE_URI,
231 node,
232 MessageKind.INVALID_PACKAGE_URI,
233 {'uri': uri, 'exception': e.message}); 214 {'uri': uri, 'exception': e.message});
234 return null; 215 return null;
235 } 216 }
236 return packages.resolve(uri, 217 return packages.resolve(uri, notFound: (Uri notFound) {
237 notFound: (Uri notFound) { 218 reporter.reportErrorMessage(
238 reporter.reportErrorMessage( 219 node, MessageKind.LIBRARY_NOT_FOUND, {'resolvedUri': uri});
239 node, 220 return null;
240 MessageKind.LIBRARY_NOT_FOUND, 221 });
241 {'resolvedUri': uri});
242 return null;
243 });
244 } 222 }
245 223
246 Future<elements.LibraryElement> analyzeUri( 224 Future<elements.LibraryElement> analyzeUri(Uri uri,
247 Uri uri,
248 {bool skipLibraryWithPartOfTag: true}) { 225 {bool skipLibraryWithPartOfTag: true}) {
249 List<Future> setupFutures = new List<Future>(); 226 List<Future> setupFutures = new List<Future>();
250 if (sdkLibraries == null) { 227 if (sdkLibraries == null) {
251 setupFutures.add(setupSdk()); 228 setupFutures.add(setupSdk());
252 } 229 }
253 if (packages == null) { 230 if (packages == null) {
254 setupFutures.add(setupPackages(uri)); 231 setupFutures.add(setupPackages(uri));
255 } 232 }
256 return Future.wait(setupFutures).then((_) { 233 return Future.wait(setupFutures).then((_) {
257 return super.analyzeUri(uri, 234 return super
258 skipLibraryWithPartOfTag: skipLibraryWithPartOfTag); 235 .analyzeUri(uri, skipLibraryWithPartOfTag: skipLibraryWithPartOfTag);
259 }); 236 });
260 } 237 }
261 238
262 Future setupPackages(Uri uri) { 239 Future setupPackages(Uri uri) {
263 if (options.packageRoot != null) { 240 if (options.packageRoot != null) {
264 // Use "non-file" packages because the file version requires a [Directory] 241 // Use "non-file" packages because the file version requires a [Directory]
265 // and we can't depend on 'dart:io' classes. 242 // and we can't depend on 'dart:io' classes.
266 packages = new NonFilePackagesDirectoryPackages(options.packageRoot); 243 packages = new NonFilePackagesDirectoryPackages(options.packageRoot);
267 } else if (options.packageConfig != null) { 244 } else if (options.packageConfig != null) {
268 return callUserProvider(options.packageConfig).then((configContents) { 245 return callUserProvider(options.packageConfig).then((configContents) {
269 if (configContents is String) { 246 if (configContents is String) {
270 configContents = UTF8.encode(configContents); 247 configContents = UTF8.encode(configContents);
271 } 248 }
272 // The input provider may put a trailing 0 byte when it reads a source 249 // The input provider may put a trailing 0 byte when it reads a source
273 // file, which confuses the package config parser. 250 // file, which confuses the package config parser.
274 if (configContents.length > 0 && 251 if (configContents.length > 0 && configContents.last == 0) {
275 configContents.last == 0) {
276 configContents = configContents.sublist(0, configContents.length - 1); 252 configContents = configContents.sublist(0, configContents.length - 1);
277 } 253 }
278 packages = new MapPackages( 254 packages =
279 pkgs.parse(configContents, options.packageConfig)); 255 new MapPackages(pkgs.parse(configContents, options.packageConfig));
280 }).catchError((error) { 256 }).catchError((error) {
281 reporter.reportErrorMessage( 257 reporter.reportErrorMessage(
282 NO_LOCATION_SPANNABLE, 258 NO_LOCATION_SPANNABLE,
283 MessageKind.INVALID_PACKAGE_CONFIG, 259 MessageKind.INVALID_PACKAGE_CONFIG,
284 {'uri': options.packageConfig, 'exception': error}); 260 {'uri': options.packageConfig, 'exception': error});
285 packages = Packages.noPackages; 261 packages = Packages.noPackages;
286 }); 262 });
287 } else { 263 } else {
288 if (options.packagesDiscoveryProvider == null) { 264 if (options.packagesDiscoveryProvider == null) {
289 packages = Packages.noPackages; 265 packages = Packages.noPackages;
290 } else { 266 } else {
291 return callUserPackagesDiscovery(uri).then((p) { 267 return callUserPackagesDiscovery(uri).then((p) {
292 packages = p; 268 packages = p;
293 }); 269 });
294 } 270 }
295 } 271 }
296 return new Future.value(); 272 return new Future.value();
297 } 273 }
298 274
299 Future<Null> setupSdk() { 275 Future<Null> setupSdk() {
300 if (sdkLibraries == null) { 276 if (sdkLibraries == null) {
301 return platform_configuration.load(options.platformConfigUri, provider) 277 return platform_configuration
278 .load(options.platformConfigUri, provider)
302 .then((Map<String, Uri> mapping) { 279 .then((Map<String, Uri> mapping) {
303 sdkLibraries = mapping; 280 sdkLibraries = mapping;
304 }); 281 });
305 } else { 282 } else {
306 // The incremental compiler sets up the sdk before run. 283 // The incremental compiler sets up the sdk before run.
307 // Therefore this will be called a second time. 284 // Therefore this will be called a second time.
308 return new Future.value(null); 285 return new Future.value(null);
309 } 286 }
310 } 287 }
311 288
(...skipping 19 matching lines...) Expand all
331 } 308 }
332 int total = totalCompileTime.elapsedMilliseconds; 309 int total = totalCompileTime.elapsedMilliseconds;
333 log('Total compile-time ${total}msec;' 310 log('Total compile-time ${total}msec;'
334 ' unaccounted ${total - cumulated}msec'); 311 ' unaccounted ${total - cumulated}msec');
335 return success; 312 return success;
336 }); 313 });
337 }); 314 });
338 } 315 }
339 316
340 void reportDiagnostic(DiagnosticMessage message, 317 void reportDiagnostic(DiagnosticMessage message,
341 List<DiagnosticMessage> infos, 318 List<DiagnosticMessage> infos, api.Diagnostic kind) {
342 api.Diagnostic kind) {
343 _reportDiagnosticMessage(message, kind); 319 _reportDiagnosticMessage(message, kind);
344 for (DiagnosticMessage info in infos) { 320 for (DiagnosticMessage info in infos) {
345 _reportDiagnosticMessage(info, api.Diagnostic.INFO); 321 _reportDiagnosticMessage(info, api.Diagnostic.INFO);
346 } 322 }
347 } 323 }
348 324
349 void _reportDiagnosticMessage(DiagnosticMessage diagnosticMessage, 325 void _reportDiagnosticMessage(
350 api.Diagnostic kind) { 326 DiagnosticMessage diagnosticMessage, api.Diagnostic kind) {
351 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For 327 // [:span.uri:] might be [:null:] in case of a [Script] with no [uri]. For
352 // instance in the [Types] constructor in typechecker.dart. 328 // instance in the [Types] constructor in typechecker.dart.
353 SourceSpan span = diagnosticMessage.sourceSpan; 329 SourceSpan span = diagnosticMessage.sourceSpan;
354 Message message = diagnosticMessage.message; 330 Message message = diagnosticMessage.message;
355 if (span == null || span.uri == null) { 331 if (span == null || span.uri == null) {
356 callUserHandler(message, null, null, null, '$message', kind); 332 callUserHandler(message, null, null, null, '$message', kind);
357 } else { 333 } else {
358 callUserHandler( 334 callUserHandler(
359 message, span.uri, span.begin, span.end, '$message', kind); 335 message, span.uri, span.begin, span.end, '$message', kind);
360 } 336 }
361 } 337 }
362 338
363 bool get isMockCompilation => 339 bool get isMockCompilation =>
364 mockableLibraryUsed && options.allowMockCompilation; 340 mockableLibraryUsed && options.allowMockCompilation;
365 341
366 void callUserHandler(Message message, Uri uri, int begin, int end, 342 void callUserHandler(Message message, Uri uri, int begin, int end,
367 String text, api.Diagnostic kind) { 343 String text, api.Diagnostic kind) {
368 userHandlerTask.measure(() { 344 userHandlerTask.measure(() {
369 handler.report(message, uri, begin, end, text, kind); 345 handler.report(message, uri, begin, end, text, kind);
370 }); 346 });
371 } 347 }
372 348
373 Future callUserProvider(Uri uri) { 349 Future callUserProvider(Uri uri) {
374 return userProviderTask.measure(() => provider.readFromUri(uri)); 350 return userProviderTask.measure(() => provider.readFromUri(uri));
375 } 351 }
376 352
377 Future<Packages> callUserPackagesDiscovery(Uri uri) { 353 Future<Packages> callUserPackagesDiscovery(Uri uri) {
378 return userPackagesDiscoveryTask.measure( 354 return userPackagesDiscoveryTask
379 () => options.packagesDiscoveryProvider(uri)); 355 .measure(() => options.packagesDiscoveryProvider(uri));
380 } 356 }
381 357
382 Uri lookupLibraryUri(String libraryName) { 358 Uri lookupLibraryUri(String libraryName) {
383 assert(invariant(NO_LOCATION_SPANNABLE, 359 assert(invariant(NO_LOCATION_SPANNABLE, sdkLibraries != null,
384 sdkLibraries != null, message: "setupSdk() has not been run")); 360 message: "setupSdk() has not been run"));
385 return sdkLibraries[libraryName]; 361 return sdkLibraries[libraryName];
386 } 362 }
387 363
388 Uri resolvePatchUri(String libraryName) { 364 Uri resolvePatchUri(String libraryName) {
389 return backend.resolvePatchUri(libraryName, options.platformConfigUri); 365 return backend.resolvePatchUri(libraryName, options.platformConfigUri);
390 } 366 }
391 } 367 }
392 368
393 class _Environment implements Environment { 369 class _Environment implements Environment {
394 final Map<String, String> definitions; 370 final Map<String, String> definitions;
395 371
396 // TODO(sigmund): break the circularity here: Compiler needs an environment to 372 // TODO(sigmund): break the circularity here: Compiler needs an environment to
397 // intialize the library loader, but the environment here needs to know about 373 // intialize the library loader, but the environment here needs to know about
398 // how the sdk is set up and about whether the backend supports mirrors. 374 // how the sdk is set up and about whether the backend supports mirrors.
399 CompilerImpl compiler; 375 CompilerImpl compiler;
400 376
401 _Environment(this.definitions); 377 _Environment(this.definitions);
402 378
403 String valueOf(String name) { 379 String valueOf(String name) {
404 assert(invariant(NO_LOCATION_SPANNABLE, 380 assert(invariant(NO_LOCATION_SPANNABLE, compiler.sdkLibraries != null,
405 compiler.sdkLibraries != null, message: "setupSdk() has not been run")); 381 message: "setupSdk() has not been run"));
406 382
407 var result = definitions[name]; 383 var result = definitions[name];
408 if (result != null || definitions.containsKey(name)) return result; 384 if (result != null || definitions.containsKey(name)) return result;
409 if (!name.startsWith(_dartLibraryEnvironmentPrefix)) return null; 385 if (!name.startsWith(_dartLibraryEnvironmentPrefix)) return null;
410 386
411 String libraryName = name.substring(_dartLibraryEnvironmentPrefix.length); 387 String libraryName = name.substring(_dartLibraryEnvironmentPrefix.length);
412 388
413 // Private libraries are not exposed to the users. 389 // Private libraries are not exposed to the users.
414 if (libraryName.startsWith("_")) return null; 390 if (libraryName.startsWith("_")) return null;
415 391
(...skipping 10 matching lines...) Expand all
426 } 402 }
427 } 403 }
428 404
429 /// For every 'dart:' library, a corresponding environment variable is set 405 /// For every 'dart:' library, a corresponding environment variable is set
430 /// to "true". The environment variable's name is the concatenation of 406 /// to "true". The environment variable's name is the concatenation of
431 /// this prefix and the name (without the 'dart:'. 407 /// this prefix and the name (without the 'dart:'.
432 /// 408 ///
433 /// For example 'dart:html' has the environment variable 'dart.library.html' set 409 /// For example 'dart:html' has the environment variable 'dart.library.html' set
434 /// to "true". 410 /// to "true".
435 const String _dartLibraryEnvironmentPrefix = 'dart.library.'; 411 const String _dartLibraryEnvironmentPrefix = 'dart.library.';
OLDNEW
« no previous file with comments | « pkg/compiler/lib/compiler_new.dart ('k') | pkg/compiler/lib/src/cache_strategy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698