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

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

Issue 2880453005: Build up and pass MemoryFileSystem to fasta frontend. (Closed)
Patch Set: Use integer division 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
« no previous file with comments | « pkg/front_end/lib/src/fasta/fasta.dart ('k') | utils/kernel-service/kernel-service.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 /// API for compiling Dart source code to .dill (Kernel IR) files. 5 /// API for compiling Dart source code to .dill (Kernel IR) files.
6 library front_end.vm; 6 library front_end.vm;
7 // TODO(ahe): Convert this file to use the API in `../../kernel_generator.dart` 7 // TODO(ahe): Convert this file to use the API in `../../kernel_generator.dart`
8 // and `../../compiler_options.dart`. 8 // and `../../compiler_options.dart`.
9 9
10 import 'dart:async' show Future; 10 import 'dart:async' show Future;
11 11
12 import 'dart:io' show File, Platform; 12 import 'dart:io' show File, Platform;
13 13
14 import 'dart:typed_data' show Uint8List; 14 import 'dart:typed_data' show Uint8List;
15 15
16 import 'package:front_end/physical_file_system.dart';
17
16 import 'fasta.dart' as fasta; 18 import 'fasta.dart' as fasta;
17 19
18 /// Compilation status codes. 20 /// Compilation status codes.
19 /// 21 ///
20 /// Note: The [index] property of these constants must match 22 /// Note: The [index] property of these constants must match
21 /// `Dart_KernelCompilationStatus` in 23 /// `Dart_KernelCompilationStatus` in
22 /// [dart_api.h](../../../../runtime/include/dart_api.h). 24 /// [dart_api.h](../../../../runtime/include/dart_api.h).
23 enum Status { 25 enum Status {
24 /// Compilation was successful. 26 /// Compilation was successful.
25 ok, 27 ok,
(...skipping 21 matching lines...) Expand all
47 49
48 Status get status; 50 Status get status;
49 51
50 get payload; 52 get payload;
51 53
52 List toResponse() => [status.index, payload]; 54 List toResponse() => [status.index, payload];
53 } 55 }
54 56
55 Future<CompilationResult> parseScript(Uri script, 57 Future<CompilationResult> parseScript(Uri script,
56 {bool verbose: false, bool strongMode: false}) async { 58 {bool verbose: false, bool strongMode: false}) async {
59 return parseScriptInFileSystem(script, PhysicalFileSystem.instance,
60 verbose: verbose, strongMode: strongMode);
61 }
62
63 Future<CompilationResult> parseScriptInFileSystem(
64 Uri script, FileSystem fileSystem,
65 {bool verbose: false, bool strongMode: false}) async {
57 final Uri packagesUri = (Platform.packageConfig != null) 66 final Uri packagesUri = (Platform.packageConfig != null)
58 ? Uri.parse(Platform.packageConfig) 67 ? Uri.parse(Platform.packageConfig)
59 : await _findPackagesFile(script); 68 : await _findPackagesFile(fileSystem, script);
60 if (packagesUri == null) { 69 if (packagesUri == null) {
61 throw "Could not find .packages"; 70 throw "Could not find .packages";
62 } 71 }
63 72
64 final Uri patchedSdk = Uri.base 73 final Uri patchedSdk = Uri.base
65 .resolveUri(new Uri.file(Platform.resolvedExecutable)) 74 .resolveUri(new Uri.file(Platform.resolvedExecutable))
66 .resolveUri(new Uri.directory("patched_sdk")); 75 .resolveUri(new Uri.directory("patched_sdk"));
67 76
68 if (verbose) { 77 if (verbose) {
69 print("""DFE: Requesting compilation { 78 print("""DFE: Requesting compilation {
70 scriptUri: ${script} 79 scriptUri: ${script}
71 packagesUri: ${packagesUri} 80 packagesUri: ${packagesUri}
72 patchedSdk: ${patchedSdk} 81 patchedSdk: ${patchedSdk}
73 }"""); 82 }""");
74 } 83 }
75 84
76 try { 85 try {
77 return await fasta.parseScript(script, packagesUri, patchedSdk, 86 return await fasta.parseScriptInFileSystem(
87 script, fileSystem, packagesUri, patchedSdk,
78 verbose: verbose, strongMode: strongMode); 88 verbose: verbose, strongMode: strongMode);
79 } catch (err, stack) { 89 } catch (err, stack) {
80 return new CompilationResult.crash(err, stack); 90 return new CompilationResult.crash(err, stack);
81 } 91 }
82 } 92 }
83 93
84 class _CompilationOk extends CompilationResult { 94 class _CompilationOk extends CompilationResult {
85 final Uint8List bytes; 95 final Uint8List bytes;
86 96
87 _CompilationOk(this.bytes) : super._(); 97 _CompilationOk(this.bytes) : super._();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 Status get status => Status.crash; 138 Status get status => Status.crash;
129 139
130 @override 140 @override
131 String get errorString => "${exception}\n${stack}"; 141 String get errorString => "${exception}\n${stack}";
132 142
133 String toString() => "_CompilationCrash(${errorString})"; 143 String toString() => "_CompilationCrash(${errorString})";
134 } 144 }
135 145
136 /// This duplicates functionality from the Loader which we can't easily 146 /// This duplicates functionality from the Loader which we can't easily
137 /// access from here. 147 /// access from here.
138 Future<Uri> _findPackagesFile(Uri base) async { 148 Future<Uri> _findPackagesFile(FileSystem fileSystem, Uri base) async {
139 var dir = new File.fromUri(base).parent; 149 var dir = new File.fromUri(base).parent;
140 while (true) { 150 while (true) {
141 final packagesFile = dir.uri.resolve(".packages"); 151 final packagesFile = dir.uri.resolve(".packages");
142 if (await new File.fromUri(packagesFile).exists()) { 152 if (await fileSystem.entityForUri(packagesFile).exists()) {
143 return packagesFile; 153 return packagesFile;
144 } 154 }
145 if (dir.parent.path == dir.path) { 155 if (dir.parent.path == dir.path) {
146 break; 156 break;
147 } 157 }
148 dir = dir.parent; 158 dir = dir.parent;
149 } 159 }
150 return null; 160 return null;
151 } 161 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/fasta.dart ('k') | utils/kernel-service/kernel-service.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698