@@ -37,8 +37,9 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
3737 final BytesSink _constantsBytesSink;
3838 BufferedSink _constantsSink;
3939 BufferedSink _sink;
40- bool includeSources;
41- bool includeOffsets;
40+ final bool includeSources;
41+ final bool includeOffsets;
42+ final LibraryFilter libraryFilter;
4243
4344 List <int > libraryOffsets;
4445 List <int > classOffsets;
@@ -60,7 +61,8 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
6061 /// The BinaryPrinter will use its own buffer, so the [sink] does not need
6162 /// one.
6263 BinaryPrinter (Sink <List <int >> sink,
63- {StringIndexer stringIndexer,
64+ {this .libraryFilter,
65+ StringIndexer stringIndexer,
6466 this .includeSources = true ,
6567 this .includeOffsets = true })
6668 : _mainSink = new BufferedSink (sink),
@@ -503,9 +505,10 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
503505 _canonicalNameList = < CanonicalName > [];
504506 for (int i = 0 ; i < component.libraries.length; ++ i) {
505507 Library library = component.libraries[i];
506- if (! shouldWriteLibraryCanonicalNames (library)) continue ;
507- _indexLinkTableInternal (library.canonicalName);
508- _knownCanonicalNameNonRootTops.add (library.canonicalName);
508+ if (libraryFilter == null || libraryFilter (library)) {
509+ _indexLinkTableInternal (library.canonicalName);
510+ _knownCanonicalNameNonRootTops.add (library.canonicalName);
511+ }
509512 }
510513 }
511514
@@ -522,15 +525,14 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
522525
523526 /// Compute canonical names for the whole component or parts of it.
524527 void computeCanonicalNames (Component component) {
525- component.computeCanonicalNames ();
528+ for (int i = 0 ; i < component.libraries.length; ++ i) {
529+ Library library = component.libraries[i];
530+ if (libraryFilter == null || libraryFilter (library)) {
531+ component.computeCanonicalNamesForLibrary (library);
532+ }
533+ }
526534 }
527535
528- /// Return `true` if all canonical names of the [library] should be written
529- /// into the link table. If some libraries of the component are skipped,
530- /// then all the additional names referenced by the libraries that are written
531- /// by [writeLibraries] are automatically added.
532- bool shouldWriteLibraryCanonicalNames (Library library) => true ;
533-
534536 void writeCanonicalNameEntry (CanonicalName node) {
535537 CanonicalName parent = node.parent;
536538 if (parent.isRoot) {
@@ -564,7 +566,16 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
564566 _writeMetadataSection (component);
565567 writeStringTable (stringIndexer);
566568 writeConstantTable (_constantIndexer);
567- writeComponentIndex (component, component.libraries);
569+ List <Library > libraries = component.libraries;
570+ if (libraryFilter != null ) {
571+ List <Library > librariesNew = new List <Library >();
572+ for (int i = 0 ; i < libraries.length; i++ ) {
573+ Library library = libraries[i];
574+ if (libraryFilter (library)) librariesNew.add (library);
575+ }
576+ libraries = librariesNew;
577+ }
578+ writeComponentIndex (component, libraries);
568579
569580 _flush ();
570581 });
@@ -702,7 +713,10 @@ class BinaryPrinter implements Visitor<void>, BinarySink {
702713 /// Write all of some of the libraries of the [component] .
703714 void writeLibraries (Component component) {
704715 for (int i = 0 ; i < component.libraries.length; ++ i) {
705- writeLibraryNode (component.libraries[i]);
716+ Library library = component.libraries[i];
717+ if (libraryFilter == null || libraryFilter (library)) {
718+ writeLibraryNode (library);
719+ }
706720 }
707721 }
708722
0 commit comments