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

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

Issue 1971193002: Patches to support Dart VM patch files in dart2js. (Closed) Base URL: sso://user/ahe/dart-sdk@master
Patch Set: Created 4 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
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 Uris; 10 import 'common/names.dart' show Uris;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 /// Handle for creating synthesized/patch libraries during library loading. 179 /// Handle for creating synthesized/patch libraries during library loading.
180 abstract class LibraryLoader { 180 abstract class LibraryLoader {
181 /// This method must be called when a new synthesized/patch library has been 181 /// This method must be called when a new synthesized/patch library has been
182 /// created to ensure that [library] will part of library dependency graph 182 /// created to ensure that [library] will part of library dependency graph
183 /// used for computing import/export scopes. 183 /// used for computing import/export scopes.
184 void registerNewLibrary(LibraryElement library); 184 void registerNewLibrary(LibraryElement library);
185 185
186 /// This method must be called when a new synthesized/patch library has been 186 /// This method must be called when a new synthesized/patch library has been
187 /// scanned in order to process the library tags in [library] and thus handle 187 /// scanned in order to process the library tags in [library] and thus handle
188 /// imports/exports/parts in the synthesized/patch library. 188 /// imports/exports/parts in the synthesized/patch library.
189 Future processLibraryTags(LibraryElement library); 189 Future processLibraryTags(
190 LibraryElement library, {bool isPatchLibrary: false});
190 } 191 }
191 192
192 /** 193 /**
193 * [CombinatorFilter] is a succinct representation of a list of combinators from 194 * [CombinatorFilter] is a succinct representation of a list of combinators from
194 * a library dependency tag. 195 * a library dependency tag.
195 */ 196 */
196 class CombinatorFilter { 197 class CombinatorFilter {
197 const CombinatorFilter(); 198 const CombinatorFilter();
198 199
199 /** 200 /**
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 }); 429 });
429 } 430 }
430 431
431 /** 432 /**
432 * Processes the library tags in [library]. 433 * Processes the library tags in [library].
433 * 434 *
434 * The imported/exported libraries are loaded and processed recursively but 435 * The imported/exported libraries are loaded and processed recursively but
435 * the import/export scopes are not set up. 436 * the import/export scopes are not set up.
436 */ 437 */
437 Future processLibraryTags( 438 Future processLibraryTags(
438 LibraryDependencyHandler handler, LibraryElementX library) { 439 LibraryDependencyHandler handler, LibraryElementX library,
440 {bool isPatchLibrary: false}) {
439 TagState tagState = new TagState(); 441 TagState tagState = new TagState();
440 442
441 bool importsDartCore = false; 443 bool importsDartCore = false;
442 LinkBuilder<LibraryDependencyElementX> libraryDependencies = 444 LinkBuilder<LibraryDependencyElementX> libraryDependencies =
443 new LinkBuilder<LibraryDependencyElementX>(); 445 new LinkBuilder<LibraryDependencyElementX>();
444 Uri base = library.entryCompilationUnit.script.readableUri; 446 Uri base = library.entryCompilationUnit.script.readableUri;
445 447
446 return Future.forEach(library.tags, (LibraryTag tag) { 448 return Future.forEach(library.tags, (LibraryTag tag) {
447 return reporter.withCurrentElement(library, () { 449 return reporter.withCurrentElement(library, () {
448 Uri computeUri(LibraryDependency node) { 450 Uri computeUri(LibraryDependency node) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (library.libraryTag == null) { 504 if (library.libraryTag == null) {
503 // Use the first if there are multiple (which is reported as an 505 // Use the first if there are multiple (which is reported as an
504 // error in [TagState.checkTag]). 506 // error in [TagState.checkTag]).
505 library.libraryTag = tag; 507 library.libraryTag = tag;
506 } 508 }
507 } else if (tag.isPart) { 509 } else if (tag.isPart) {
508 Part part = tag; 510 Part part = tag;
509 StringNode uri = part.uri; 511 StringNode uri = part.uri;
510 Uri resolvedUri = base.resolve(uri.dartString.slowToString()); 512 Uri resolvedUri = base.resolve(uri.dartString.slowToString());
511 tagState.checkTag(TagState.PART, part, reporter); 513 tagState.checkTag(TagState.PART, part, reporter);
512 return scanPart(part, resolvedUri, library); 514 return scanPart(
515 part, resolvedUri, library, isPatchLibrary: isPatchLibrary);
513 } else { 516 } else {
514 reporter.internalError(tag, "Unhandled library tag."); 517 reporter.internalError(tag, "Unhandled library tag.");
515 } 518 }
516 }); 519 });
517 }).then((_) { 520 }).then((_) {
518 return listener.onLibraryScanned(library, handler); 521 return listener.onLibraryScanned(library, handler);
519 }).then((_) { 522 }).then((_) {
520 return reporter.withCurrentElement(library, () { 523 return reporter.withCurrentElement(library, () {
521 checkDuplicatedLibraryName(library); 524 checkDuplicatedLibraryName(library);
522 525
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 MessageKind.DUPLICATED_LIBRARY_NAME, {'libraryName': name}); 582 MessageKind.DUPLICATED_LIBRARY_NAME, {'libraryName': name});
580 }); 583 });
581 } 584 }
582 } 585 }
583 } 586 }
584 587
585 /** 588 /**
586 * Handle a part tag in the scope of [library]. The [resolvedUri] given is 589 * Handle a part tag in the scope of [library]. The [resolvedUri] given is
587 * used as is, any URI resolution should be done beforehand. 590 * used as is, any URI resolution should be done beforehand.
588 */ 591 */
589 Future scanPart(Part part, Uri resolvedUri, LibraryElement library) { 592 Future scanPart(
593 Part part, Uri resolvedUri, LibraryElement library,
594 {bool isPatchLibrary: false}) {
590 if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri); 595 if (!resolvedUri.isAbsolute) throw new ArgumentError(resolvedUri);
591 Uri readableUri = uriTranslator.translate(library, resolvedUri, part); 596 Uri readableUri = uriTranslator.translate(library, resolvedUri, part);
592 if (readableUri == null) return new Future.value(); 597 if (readableUri == null) return new Future.value();
593 return reporter.withCurrentElement(library, () { 598 return reporter.withCurrentElement(library, () {
594 return scriptLoader.readScript(readableUri, part).then((Script script) { 599 return scriptLoader.readScript(readableUri, part).then((Script script) {
595 if (script == null) return; 600 if (script == null) return;
596 createUnitSync(script, library); 601 createUnitSync(script, library, isPatchLibrary: isPatchLibrary);
597 }); 602 });
598 }); 603 });
599 } 604 }
600 605
601 /** 606 /**
602 * Handle an import/export tag by loading the referenced library and 607 * Handle an import/export tag by loading the referenced library and
603 * registering its dependency in [handler] for the computation of the import/ 608 * registering its dependency in [handler] for the computation of the import/
604 * export scope. If the tag does not contain a valid URI, then its dependency 609 * export scope. If the tag does not contain a valid URI, then its dependency
605 * is not registered in [handler]. 610 * is not registered in [handler].
606 */ 611 */
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 return reporter.withCurrentElement(element, () { 721 return reporter.withCurrentElement(element, () {
717 if (handler != null) { 722 if (handler != null) {
718 handler.registerNewLibrary(element); 723 handler.registerNewLibrary(element);
719 libraryCanonicalUriMap[resolvedUri] = element; 724 libraryCanonicalUriMap[resolvedUri] = element;
720 } 725 }
721 scanner.scanLibrary(element); 726 scanner.scanLibrary(element);
722 return element; 727 return element;
723 }); 728 });
724 } 729 }
725 730
726 CompilationUnitElement createUnitSync(Script script, LibraryElement library) { 731 CompilationUnitElement createUnitSync(
732 Script script, LibraryElement library, {bool isPatchLibrary: false}) {
727 CompilationUnitElementX unit = new CompilationUnitElementX(script, library); 733 CompilationUnitElementX unit = new CompilationUnitElementX(script, library);
728 reporter.withCurrentElement(unit, () { 734 reporter.withCurrentElement(unit, () {
729 scanner.scanUnit(unit); 735 if (isPatchLibrary) {
730 if (unit.partTag == null && !script.isSynthesized) { 736 compiler.patchParser.scanUnit(unit);
731 reporter.reportErrorMessage(unit, MessageKind.MISSING_PART_OF_TAG); 737 } else {
738 scanner.scanUnit(unit);
739 if (unit.partTag == null && !script.isSynthesized) {
740 reporter.reportErrorMessage(unit, MessageKind.MISSING_PART_OF_TAG);
741 }
732 } 742 }
733 }); 743 });
734 return unit; 744 return unit;
735 } 745 }
736 } 746 }
737 747
738 /// A state machine for checking script tags come in the correct order. 748 /// A state machine for checking script tags come in the correct order.
739 class TagState { 749 class TagState {
740 /// Initial state. 750 /// Initial state.
741 static const int NO_TAG_SEEN = 0; 751 static const int NO_TAG_SEEN = 0;
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 } 1301 }
1292 1302
1293 /** 1303 /**
1294 * Registers all top-level entities of [library] as starting point for the 1304 * Registers all top-level entities of [library] as starting point for the
1295 * fixed-point computation of the import/export scopes. 1305 * fixed-point computation of the import/export scopes.
1296 */ 1306 */
1297 void registerLibraryExports(LibraryElement library) { 1307 void registerLibraryExports(LibraryElement library) {
1298 nodeMap[library].registerInitialExports(); 1308 nodeMap[library].registerInitialExports();
1299 } 1309 }
1300 1310
1301 Future processLibraryTags(LibraryElement library) { 1311 Future processLibraryTags(
1302 return task.processLibraryTags(this, library); 1312 LibraryElement library, {bool isPatchLibrary: false}) {
1313 return task.processLibraryTags(
1314 this, library, isPatchLibrary: isPatchLibrary);
1303 } 1315 }
1304 } 1316 }
1305 1317
1306 /// Information on the bulk of newly loaded libraries through a call to 1318 /// Information on the bulk of newly loaded libraries through a call to
1307 /// [LibraryLoader.loadLibrary]. 1319 /// [LibraryLoader.loadLibrary].
1308 abstract class LoadedLibraries { 1320 abstract class LoadedLibraries {
1309 /// The uri passed to [LibraryLoader.loadLibrary]. 1321 /// The uri passed to [LibraryLoader.loadLibrary].
1310 Uri get rootUri; 1322 Uri get rootUri;
1311 1323
1312 /// Returns `true` if a library with canonical [uri] was loaded in this bulk. 1324 /// Returns `true` if a library with canonical [uri] was loaded in this bulk.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 void computeSuffixes(LibraryElement library, Link<Uri> prefix) { 1381 void computeSuffixes(LibraryElement library, Link<Uri> prefix) {
1370 if (aborted) return; 1382 if (aborted) return;
1371 1383
1372 Uri canonicalUri = library.canonicalUri; 1384 Uri canonicalUri = library.canonicalUri;
1373 prefix = prefix.prepend(canonicalUri); 1385 prefix = prefix.prepend(canonicalUri);
1374 if (suffixChainMap.containsKey(library)) return; 1386 if (suffixChainMap.containsKey(library)) return;
1375 suffixChainMap[library] = const <Link<Uri>>[]; 1387 suffixChainMap[library] = const <Link<Uri>>[];
1376 List<Link<Uri>> suffixes = []; 1388 List<Link<Uri>> suffixes = [];
1377 if (targetUri != canonicalUri) { 1389 if (targetUri != canonicalUri) {
1378 LibraryDependencyNode node = nodeMap[library]; 1390 LibraryDependencyNode node = nodeMap[library];
1391 if (node == null) return;
1379 1392
1380 /// Process the import (or export) of [importedLibrary]. 1393 /// Process the import (or export) of [importedLibrary].
1381 void processLibrary(LibraryElement importedLibrary) { 1394 void processLibrary(LibraryElement importedLibrary) {
1382 bool suffixesArePrecomputed = 1395 bool suffixesArePrecomputed =
1383 suffixChainMap.containsKey(importedLibrary); 1396 suffixChainMap.containsKey(importedLibrary);
1384 1397
1385 if (!suffixesArePrecomputed) { 1398 if (!suffixesArePrecomputed) {
1386 computeSuffixes(importedLibrary, prefix); 1399 computeSuffixes(importedLibrary, prefix);
1387 if (aborted) return; 1400 if (aborted) return;
1388 } 1401 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 /// Called after a request to load a library. The [results] will include all 1516 /// Called after a request to load a library. The [results] will include all
1504 /// transitive libraries loaded as a result of the initial request. 1517 /// transitive libraries loaded as a result of the initial request.
1505 Future onLibrariesLoaded(LoadedLibraries results); 1518 Future onLibrariesLoaded(LoadedLibraries results);
1506 1519
1507 /// Called whenever a library element is created. 1520 /// Called whenever a library element is created.
1508 void onLibraryCreated(LibraryElement library); 1521 void onLibraryCreated(LibraryElement library);
1509 1522
1510 /// Called whenever a library is scanned from a script file. 1523 /// Called whenever a library is scanned from a script file.
1511 Future onLibraryScanned(LibraryElement library, LibraryLoader loader); 1524 Future onLibraryScanned(LibraryElement library, LibraryLoader loader);
1512 } 1525 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/patch_resolver.dart ('k') | pkg/compiler/lib/src/parser/element_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698