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

Side by Side Diff: pkg/front_end/lib/src/fasta/dill/dill_loader.dart

Issue 2872903005: Rework DillLoader to allow adding multiple dills. (Closed)
Patch Set: Created 3 years, 7 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 fasta.dill_loader; 5 library fasta.dill_loader;
6 6
7 import 'dart:async' show Future; 7 import 'dart:async' show Future;
8 8
9 import 'dart:io' show File;
10
11 import 'package:kernel/kernel.dart' show loadProgramFromBinary;
12
13 import 'package:kernel/ast.dart' show Library, Program; 9 import 'package:kernel/ast.dart' show Library, Program;
14 10
15 import '../loader.dart' show Loader; 11 import '../loader.dart' show Loader;
16
17 import '../target_implementation.dart' show TargetImplementation; 12 import '../target_implementation.dart' show TargetImplementation;
18
19 import 'dill_library_builder.dart' show DillLibraryBuilder; 13 import 'dill_library_builder.dart' show DillLibraryBuilder;
20 14
21 class DillLoader extends Loader<Library> { 15 class DillLoader extends Loader<Library> {
22 Uri input;
23
24 Program program; 16 Program program;
Siggi Cherem (dart-lang) 2017/05/09 20:14:30 doesn't have to be in this CL, but we probably onl
scheglov 2017/05/09 20:32:21 Yeah, mostly we use libraries. But lib/src/fasta/k
25 17
26 DillLoader(TargetImplementation target) : super(target); 18 DillLoader(TargetImplementation target) : super(target);
27 19
28 DillLibraryBuilder read(Uri uri, [Uri fileUri]) => super.read(uri, fileUri); 20 /// Add already compiled libraries from the given [dill]. If [uris] is
Siggi Cherem (dart-lang) 2017/05/09 20:14:30 nit: a couple suggestions on this comment: - I pr
scheglov 2017/05/09 20:32:21 Done.
Siggi Cherem (dart-lang) 2017/05/09 22:12:37 After talking on VC I just realized something: is
scheglov 2017/05/10 00:47:40 If the idea with serializing just individual stron
29 21 /// `null`, then only libraries these URIs are added (e.g. to add a library
30 Future<Null> buildOutline(DillLibraryBuilder builder) async { 22 /// without all its already added dependencies). It is up to the client to
31 if (program == null) { 23 /// make sure that the added libraries have all their dependencies added
32 byteCount = await new File.fromUri(input).length(); 24 /// before.
33 setProgram(await loadProgramFromBinary(input.toFilePath())); 25 void addDill(Program dill, [Set<Uri> uris]) {
Siggi Cherem (dart-lang) 2017/05/09 20:14:30 some suggestions: - rename addDill => appendProgr
scheglov 2017/05/09 20:32:21 Done.
26 program ??= new Program();
27 dill.unbindCanonicalNames();
28 for (Library library in dill.libraries) {
29 if (uris == null || uris.contains(library.importUri)) {
30 program.libraries.add(library);
31 read(library.importUri).library = library;
32 }
34 } 33 }
35 builder.library.classes.forEach(builder.addClass);
36 builder.library.procedures.forEach(builder.addMember);
37 builder.library.fields.forEach(builder.addMember);
38 } 34 }
39 35
40 Future<Null> buildBody(DillLibraryBuilder builder) { 36 Future<Null> buildBody(DillLibraryBuilder builder) {
41 return buildOutline(builder); 37 return buildOutline(builder);
42 } 38 }
43 39
40 Future<Null> buildOutline(DillLibraryBuilder builder) async {
41 builder.library.classes.forEach(builder.addClass);
42 builder.library.procedures.forEach(builder.addMember);
43 builder.library.fields.forEach(builder.addMember);
44 }
45
46 DillLibraryBuilder read(Uri uri, [Uri fileUri]) => super.read(uri, fileUri);
47
44 void setProgram(Program program) { 48 void setProgram(Program program) {
Siggi Cherem (dart-lang) 2017/05/09 20:14:30 I'd delete this and use `addDill` in testing/suite
scheglov 2017/05/09 20:32:21 Ah... Right, we don't need it anymore!
45 assert(input != null); 49 if (this.program != null) {
50 throw new StateError('The full DILL can be set only once.');
51 }
46 this.program = program; 52 this.program = program;
47 program.unbindCanonicalNames(); 53 program.unbindCanonicalNames();
48 for (Library library in program.libraries) { 54 for (Library library in program.libraries) {
49 read(library.importUri).library = library; 55 read(library.importUri).library = library;
50 } 56 }
51 } 57 }
52 } 58 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/lib/src/fasta/dill/dill_target.dart » ('j') | pkg/front_end/lib/src/fasta/dill/dill_target.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698