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

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

Issue 2976543002: Reapply "Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service."" (Closed)
Patch Set: fix Created 3 years, 5 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file 5 // TODO(ahe): Copied from closure_conversion branch of kernel, remove this file
6 // when closure_conversion is merged with master. 6 // when closure_conversion is merged with master.
7 7
8 library fasta.testing.kernel_chain; 8 library fasta.testing.kernel_chain;
9 9
10 import 'dart:async' show Future; 10 import 'dart:async' show Future;
(...skipping 10 matching lines...) Expand all
21 21
22 import 'package:kernel/ast.dart' show Library, Program; 22 import 'package:kernel/ast.dart' show Library, Program;
23 23
24 import '../kernel/verifier.dart' show verifyProgram; 24 import '../kernel/verifier.dart' show verifyProgram;
25 25
26 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; 26 import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
27 27
28 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; 28 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
29 29
30 import 'package:testing/testing.dart' 30 import 'package:testing/testing.dart'
31 show ChainContext, Result, StdioProcess, Step; 31 show ChainContext, Result, StdioProcess, Step, TestDescription;
32 32
33 import 'package:kernel/ast.dart' show Program; 33 import 'package:kernel/ast.dart' show Program;
34 34
35 import 'package:front_end/front_end.dart';
36
37 import 'patched_sdk_location.dart' show computePatchedSdk;
38
35 class Print extends Step<Program, Program, ChainContext> { 39 class Print extends Step<Program, Program, ChainContext> {
36 const Print(); 40 const Print();
37 41
38 String get name => "print"; 42 String get name => "print";
39 43
40 Future<Result<Program>> run(Program program, _) async { 44 Future<Result<Program>> run(Program program, _) async {
41 StringBuffer sb = new StringBuffer(); 45 StringBuffer sb = new StringBuffer();
42 for (Library library in program.libraries) { 46 for (Library library in program.libraries) {
43 Printer printer = new Printer(sb); 47 Printer printer = new Printer(sb);
44 if (library.importUri.scheme != "dart" && 48 if (library.importUri.scheme != "dart" &&
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 Future<Result<Program>> run(Program program, _) async { 167 Future<Result<Program>> run(Program program, _) async {
164 BytesCollector sink = new BytesCollector(); 168 BytesCollector sink = new BytesCollector();
165 new BinaryPrinter(sink).writeProgramFile(program); 169 new BinaryPrinter(sink).writeProgramFile(program);
166 program.unbindCanonicalNames(); 170 program.unbindCanonicalNames();
167 Uint8List bytes = sink.collect(); 171 Uint8List bytes = sink.collect();
168 new BinaryBuilder(bytes).readProgram(program); 172 new BinaryBuilder(bytes).readProgram(program);
169 return pass(program); 173 return pass(program);
170 } 174 }
171 } 175 }
172 176
177 /// A `package:testing` step that runs the `package:front_end` compiler to
178 /// generate a kernel program for an individual file.
179 ///
180 /// Most options are hard-coded, but if necessary they could be moved to the
181 /// [CompileContext] object in the future.
182 class Compile extends Step<TestDescription, Program, CompileContext> {
183 const Compile();
184
185 String get name => "fasta compilation";
186
187 Future<Result<Program>> run(
188 TestDescription description, CompileContext context) async {
189 Result<Program> result;
190 reportError(CompilationError error) {
191 result ??= fail(null, error.message);
192 }
193
194 Uri sdk = await computePatchedSdk();
195 Program p = await kernelForProgram(
196 description.uri,
197 new CompilerOptions()
198 ..sdkRoot = sdk
199 ..packagesFileUri = Uri.base.resolve('.packages')
200 ..strongMode = context.strongMode
201 ..linkedDependencies = [sdk.resolve('platform.dill')]
202 ..onError = reportError);
203 return result ??= pass(p);
204 }
205 }
206
207 abstract class CompileContext implements ChainContext {
208 bool get strongMode;
209 }
210
173 class BytesCollector implements Sink<List<int>> { 211 class BytesCollector implements Sink<List<int>> {
174 final List<List<int>> lists = <List<int>>[]; 212 final List<List<int>> lists = <List<int>>[];
175 213
176 int length = 0; 214 int length = 0;
177 215
178 void add(List<int> data) { 216 void add(List<int> data) {
179 lists.add(data); 217 lists.add(data);
180 length += data.length; 218 length += data.length;
181 } 219 }
182 220
(...skipping 20 matching lines...) Expand all
203 241
204 Future openWrite(Uri uri, f(IOSink sink)) async { 242 Future openWrite(Uri uri, f(IOSink sink)) async {
205 IOSink sink = new File.fromUri(uri).openWrite(); 243 IOSink sink = new File.fromUri(uri).openWrite();
206 try { 244 try {
207 await f(sink); 245 await f(sink);
208 } finally { 246 } finally {
209 await sink.close(); 247 await sink.close();
210 } 248 }
211 print("Wrote $uri"); 249 print("Wrote $uri");
212 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698