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

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

Issue 1562023002: Add test of unittests. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Cleanup Created 4 years, 11 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
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.library_loader; 5 library dart2js.library_loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'common.dart'; 9 import 'common.dart';
10 import 'common/names.dart' show 10 import 'common/names.dart' show
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 /// Looks up the library with the [canonicalUri]. 140 /// Looks up the library with the [canonicalUri].
141 LibraryElement lookupLibrary(Uri canonicalUri); 141 LibraryElement lookupLibrary(Uri canonicalUri);
142 142
143 /// Loads the library specified by the [resolvedUri] and returns its 143 /// Loads the library specified by the [resolvedUri] and returns its
144 /// [LibraryElement]. 144 /// [LibraryElement].
145 /// 145 ///
146 /// If the library is not already loaded, the method creates the 146 /// If the library is not already loaded, the method creates the
147 /// [LibraryElement] for the library and computes the import/export scope, 147 /// [LibraryElement] for the library and computes the import/export scope,
148 /// loading and computing the import/export scopes of all required libraries 148 /// loading and computing the import/export scopes of all required libraries
149 /// in the process. The method handles cyclic dependency between libraries. 149 /// in the process. The method handles cyclic dependency between libraries.
150 Future<LibraryElement> loadLibrary(Uri resolvedUri); 150 ///
151 /// If [skipLibraryWithPartOfTag] is `true`, `null` is returned if the
152 /// compilation unit for [resolvedUri] contains a `part of` tag.
sigurdm 2016/01/06 11:25:09 Add that this is for the analysis path only.
Johnni Winther 2016/01/06 12:32:53 Done.
153 Future<LibraryElement> loadLibrary(
154 Uri resolvedUri,
155 {bool skipLibraryWithPartOfTag: false});
sigurdm 2016/01/06 11:25:09 Perhaps rename to `skipFileWithPartOfTag`
Johnni Winther 2016/01/06 12:32:53 Done.
151 156
152 /// Reset the library loader task to prepare for compilation. If provided, 157 /// Reset the library loader task to prepare for compilation. If provided,
153 /// libraries matching [reuseLibrary] are reused. 158 /// libraries matching [reuseLibrary] are reused.
154 /// 159 ///
155 /// This method is used for incremental compilation. 160 /// This method is used for incremental compilation.
156 void reset({bool reuseLibrary(LibraryElement library)}); 161 void reset({bool reuseLibrary(LibraryElement library)});
157 162
158 /// Asynchronous version of [reset]. 163 /// Asynchronous version of [reset].
159 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)); 164 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library));
160 } 165 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 }); 337 });
333 } 338 }
334 339
335 /// Insert [library] in the internal maps. Used for compiler reuse. 340 /// Insert [library] in the internal maps. Used for compiler reuse.
336 void mapLibrary(LibraryElement library) { 341 void mapLibrary(LibraryElement library) {
337 libraryCanonicalUriMap[library.canonicalUri] = library; 342 libraryCanonicalUriMap[library.canonicalUri] = library;
338 343
339 Uri resourceUri = library.entryCompilationUnit.script.resourceUri; 344 Uri resourceUri = library.entryCompilationUnit.script.resourceUri;
340 libraryResourceUriMap[resourceUri] = library; 345 libraryResourceUriMap[resourceUri] = library;
341 346
342 String name = library.libraryOrScriptName; 347 if (library.hasLibraryName) {
343 libraryNames[name] = library; 348 String name = library.libraryName;
349 libraryNames[name] = library;
350 }
344 } 351 }
345 352
346 Future<LibraryElement> loadLibrary(Uri resolvedUri) { 353 Future<LibraryElement> loadLibrary(
354 Uri resolvedUri,
355 {bool skipLibraryWithPartOfTag: false}) {
347 return measure(() { 356 return measure(() {
348 assert(currentHandler == null); 357 assert(currentHandler == null);
349 // TODO(johnniwinther): Ensure that currentHandler correctly encloses the 358 // TODO(johnniwinther): Ensure that currentHandler correctly encloses the
350 // loading of a library cluster. 359 // loading of a library cluster.
351 currentHandler = new LibraryDependencyHandler(this); 360 currentHandler = new LibraryDependencyHandler(this);
352 return createLibrary(currentHandler, null, resolvedUri) 361 return createLibrary(currentHandler, null, resolvedUri,
362 skipLibraryWithPartOfTag: skipLibraryWithPartOfTag)
353 .then((LibraryElement library) { 363 .then((LibraryElement library) {
364 if (library == null) {
365 currentHandler = null;
366 return null;
367 }
354 return reporter.withCurrentElement(library, () { 368 return reporter.withCurrentElement(library, () {
355 return measure(() { 369 return measure(() {
356 currentHandler.computeExports(); 370 currentHandler.computeExports();
357 LoadedLibraries loadedLibraries = 371 LoadedLibraries loadedLibraries =
358 new _LoadedLibraries(library, currentHandler.nodeMap, this); 372 new _LoadedLibraries(library, currentHandler.nodeMap, this);
359 currentHandler = null; 373 currentHandler = null;
360 return compiler.onLibrariesLoaded(loadedLibraries) 374 return compiler.onLibrariesLoaded(loadedLibraries)
361 .then((_) => library); 375 .then((_) => library);
362 }); 376 });
363 }); 377 });
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 }); 513 });
500 } else { 514 } else {
501 reporter.reportHintMessage( 515 reporter.reportHintMessage(
502 library, 516 library,
503 MessageKind.DUPLICATED_RESOURCE, 517 MessageKind.DUPLICATED_RESOURCE,
504 {'resourceUri': resourceUri, 518 {'resourceUri': resourceUri,
505 'canonicalUri1': library.canonicalUri, 519 'canonicalUri1': library.canonicalUri,
506 'canonicalUri2': existing.canonicalUri}); 520 'canonicalUri2': existing.canonicalUri});
507 } 521 }
508 } else if (library.hasLibraryName) { 522 } else if (library.hasLibraryName) {
509 String name = library.libraryOrScriptName; 523 String name = library.libraryName;
510 existing = libraryNames.putIfAbsent(name, () => library); 524 existing = libraryNames.putIfAbsent(name, () => library);
511 if (!identical(existing, library)) { 525 if (!identical(existing, library)) {
512 reporter.withCurrentElement(library, () { 526 reporter.withCurrentElement(library, () {
513 reporter.reportWarningMessage( 527 reporter.reportWarningMessage(
514 library, 528 library,
515 MessageKind.DUPLICATED_LIBRARY_NAME, 529 MessageKind.DUPLICATED_LIBRARY_NAME,
516 {'libraryName': name}); 530 {'libraryName': name});
517 }); 531 });
518 reporter.withCurrentElement(existing, () { 532 reporter.withCurrentElement(existing, () {
519 reporter.reportWarningMessage( 533 reporter.reportWarningMessage(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 * registering its dependency in [handler] for the computation of the import/ 570 * registering its dependency in [handler] for the computation of the import/
557 * export scope. If the tag does not contain a valid URI, then its dependency 571 * export scope. If the tag does not contain a valid URI, then its dependency
558 * is not registered in [handler]. 572 * is not registered in [handler].
559 */ 573 */
560 Future<Null> registerLibraryFromImportExport( 574 Future<Null> registerLibraryFromImportExport(
561 LibraryDependencyHandler handler, 575 LibraryDependencyHandler handler,
562 LibraryElement library, 576 LibraryElement library,
563 LibraryDependencyElementX libraryDependency) { 577 LibraryDependencyElementX libraryDependency) {
564 Uri base = library.canonicalUri; 578 Uri base = library.canonicalUri;
565 Uri resolvedUri = base.resolveUri(libraryDependency.uri); 579 Uri resolvedUri = base.resolveUri(libraryDependency.uri);
566 return createLibrary(handler, library, resolvedUri, libraryDependency) 580 return createLibrary(handler, library, resolvedUri, node: libraryDependency)
567 .then((LibraryElement loadedLibrary) { 581 .then((LibraryElement loadedLibrary) {
568 if (loadedLibrary == null) return; 582 if (loadedLibrary == null) return;
569 reporter.withCurrentElement(library, () { 583 reporter.withCurrentElement(library, () {
570 libraryDependency.libraryDependency = loadedLibrary; 584 libraryDependency.libraryDependency = loadedLibrary;
571 handler.registerDependency( 585 handler.registerDependency(
572 library, libraryDependency, loadedLibrary); 586 library, libraryDependency, loadedLibrary);
573 }); 587 });
574 }); 588 });
575 } 589 }
576 590
(...skipping 16 matching lines...) Expand all
593 }); 607 });
594 }); 608 });
595 } 609 }
596 610
597 /** 611 /**
598 * Create (or reuse) a library element for the library specified by the 612 * Create (or reuse) a library element for the library specified by the
599 * [resolvedUri]. 613 * [resolvedUri].
600 * 614 *
601 * If a new library is created, the [handler] is notified. 615 * If a new library is created, the [handler] is notified.
602 */ 616 */
603 Future<LibraryElement> createLibrary(LibraryDependencyHandler handler, 617 Future<LibraryElement> createLibrary(
604 LibraryElement importingLibrary, 618 LibraryDependencyHandler handler,
605 Uri resolvedUri, 619 LibraryElement importingLibrary,
606 [Spannable node]) { 620 Uri resolvedUri,
621 {Spannable node,
622 bool skipLibraryWithPartOfTag: false}) {
607 Uri readableUri = 623 Uri readableUri =
608 compiler.translateResolvedUri(importingLibrary, resolvedUri, node); 624 compiler.translateResolvedUri(importingLibrary, resolvedUri, node);
609 LibraryElement library = libraryCanonicalUriMap[resolvedUri]; 625 LibraryElement library = libraryCanonicalUriMap[resolvedUri];
610 if (library != null) { 626 if (library != null) {
611 return new Future.value(library); 627 return new Future.value(library);
612 } 628 }
613 library = compiler.serialization.readLibrary(resolvedUri); 629 library = compiler.serialization.readLibrary(resolvedUri);
614 if (library != null) { 630 if (library != null) {
615 return loadDeserializedLibrary(handler, library); 631 return loadDeserializedLibrary(handler, library);
616 } 632 }
617 var readScript = compiler.readScript; 633 var readScript = compiler.readScript;
618 if (readableUri == null) { 634 if (readableUri == null) {
619 readableUri = resolvedUri; 635 readableUri = resolvedUri;
620 readScript = compiler.synthesizeScript; 636 readScript = compiler.synthesizeScript;
621 } 637 }
622 return reporter.withCurrentElement(importingLibrary, () { 638 return reporter.withCurrentElement(importingLibrary, () {
623 return readScript(node, readableUri).then((Script script) { 639 return readScript(node, readableUri).then((Script script) {
624 if (script == null) return null; 640 if (script == null) return null;
625 LibraryElement element = 641 LibraryElement element =
626 createLibrarySync(handler, script, resolvedUri); 642 createLibrarySync(handler, script, resolvedUri);
627 CompilationUnitElementX compilationUnit = element.entryCompilationUnit; 643 CompilationUnitElementX compilationUnit = element.entryCompilationUnit;
628 if (compilationUnit.partTag != null) { 644 if (compilationUnit.partTag != null) {
645 if (skipLibraryWithPartOfTag) {
646 // TODO(johnniwinther): Avoid calling [Compiler.onLibraryCreated]
647 // for this library.
648 libraryCanonicalUriMap.remove(resolvedUri);
649 return null;
650 }
629 DiagnosticMessage error = reporter.withCurrentElement( 651 DiagnosticMessage error = reporter.withCurrentElement(
630 compilationUnit, 652 compilationUnit,
631 () => reporter.createMessage( 653 () => reporter.createMessage(
632 compilationUnit.partTag, MessageKind.IMPORT_PART_OF)); 654 compilationUnit.partTag, MessageKind.IMPORT_PART_OF));
633 DiagnosticMessage info = reporter.withCurrentElement( 655 DiagnosticMessage info = reporter.withCurrentElement(
634 importingLibrary, 656 importingLibrary,
635 () => reporter.createMessage( 657 () => reporter.createMessage(
636 node, 658 node,
637 MessageKind.IMPORT_PART_OF_HERE)); 659 MessageKind.IMPORT_PART_OF_HERE));
638 reporter.reportError(error, <DiagnosticMessage>[info]); 660 reporter.reportError(error, <DiagnosticMessage>[info]);
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 } 1391 }
1370 suffixes.add(const Link<Uri>().prepend(canonicalUri)); 1392 suffixes.add(const Link<Uri>().prepend(canonicalUri));
1371 } 1393 }
1372 suffixChainMap[library] = suffixes; 1394 suffixChainMap[library] = suffixes;
1373 return; 1395 return;
1374 } 1396 }
1375 1397
1376 computeSuffixes(rootLibrary, const Link<Uri>()); 1398 computeSuffixes(rootLibrary, const Link<Uri>());
1377 } 1399 }
1378 } 1400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698