blob: cf98a1fd4a45c19352a2a2c273d635ba5b555399 [file] [log] [blame]
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library fasta.dill_loader;
import 'dart:async' show Future;
import 'package:kernel/ast.dart' show Class, Component, DartType, Library;
import '../builder/class_builder.dart';
import '../builder/library_builder.dart';
import '../builder/type_builder.dart';
import '../fasta_codes.dart'
show SummaryTemplate, Template, templateDillOutlineSummary;
import '../kernel/type_builder_computer.dart' show TypeBuilderComputer;
import '../loader.dart' show Loader;
import '../problems.dart' show unhandled;
import '../source/source_loader.dart' show SourceLoader;
import '../target_implementation.dart' show TargetImplementation;
import 'dill_library_builder.dart' show DillLibraryBuilder;
import 'dill_target.dart' show DillTarget;
class DillLoader extends Loader {
SourceLoader currentSourceLoader;
DillLoader(TargetImplementation target) : super(target);
Template<SummaryTemplate> get outlineSummaryTemplate =>
/// Append compiled libraries from the given [component]. If the [filter] is
/// provided, append only libraries whose [Uri] is accepted by the [filter].
List<DillLibraryBuilder> appendLibraries(Component component,
{bool filter(Uri uri), int byteCount: 0}) {
List<Library> componentLibraries = component.libraries;
List<Uri> requestedLibraries = <Uri>[];
List<Uri> requestedLibrariesFileUri = <Uri>[];
DillTarget target =;
for (int i = 0; i < componentLibraries.length; i++) {
Library library = componentLibraries[i];
Uri uri = library.importUri;
if (filter == null || filter(library.importUri)) {
List<DillLibraryBuilder> result = <DillLibraryBuilder>[];
for (int i = 0; i < requestedLibraries.length; i++) {
result.add(read(requestedLibraries[i], -1,
fileUri: requestedLibrariesFileUri[i]));
this.byteCount += byteCount;
return result;
/// Append single compiled library.
/// Note that as this only takes a library, no new sources is added to the
/// uriToSource map.
DillLibraryBuilder appendLibrary(Library library) {
// Add to list of libraries in the loader, used for e.g. linking.
// Weird interaction begins.
DillTarget target =;
// Create dill library builder (adds it to a map where it's fetched
// again momentarily).
// Set up the dill library builder (fetch it from the map again, add it to
// another map and setup some auxiliary things).
return read(library.importUri, -1, fileUri: library.fileUri);
Future<Null> buildOutline(DillLibraryBuilder builder) async {
if (builder.library == null) {
unhandled("null", "builder.library", 0, builder.fileUri);
Future<Null> buildBody(DillLibraryBuilder builder) {
return buildOutline(builder);
void finalizeExports({bool suppressFinalizationErrors: false}) {
builders.forEach((Uri uri, LibraryBuilder builder) {
DillLibraryBuilder library = builder;
suppressFinalizationErrors: suppressFinalizationErrors);
ClassBuilder computeClassBuilderFromTargetClass(Class cls) {
Library kernelLibrary = cls.enclosingLibrary;
LibraryBuilder library = builders[kernelLibrary.importUri];
if (library == null) {
library = currentSourceLoader?.builders[kernelLibrary.importUri];
return library.lookupLocalMember(, required: true);
TypeBuilder computeTypeBuilder(DartType type) {
return type.accept(new TypeBuilderComputer(this));