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

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

Issue 2665723002: Implement canonical name scheme in kernel. (Closed)
Patch Set: Address Kevin's comments Created 3 years, 10 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 kernel.testing.kernel_chain; 8 library kernel.testing.kernel_chain;
9 9
10 import 'dart:async' show 10 import 'dart:async' show
11 Future; 11 Future;
12 12
13 import 'dart:io' show 13 import 'dart:io' show
14 Directory, 14 Directory,
15 File, 15 File,
16 IOSink, 16 IOSink,
17 Platform; 17 Platform;
18 18
19 import 'dart:typed_data' show 19 import 'dart:typed_data' show
20 Uint8List; 20 Uint8List;
21 21
22 import 'package:kernel/kernel.dart' show 22 import 'package:kernel/kernel.dart' show
23 Repository,
24 loadProgramFromBinary; 23 loadProgramFromBinary;
25 24
26 import 'package:kernel/text/ast_to_text.dart' show 25 import 'package:kernel/text/ast_to_text.dart' show
27 Printer; 26 Printer;
28 27
29 import 'package:testing/testing.dart' show 28 import 'package:testing/testing.dart' show
30 Result, 29 Result,
31 StdioProcess, 30 StdioProcess,
32 Step; 31 Step;
33 32
34 import 'package:kernel/ast.dart' show 33 import 'package:kernel/ast.dart' show
35 Library, 34 Library,
36 Program; 35 Program;
37 36
38 import 'package:kernel/verifier.dart' show 37 import 'package:kernel/verifier.dart' show
39 VerifyingVisitor; 38 VerifyingVisitor;
40 39
41 import 'package:kernel/binary/ast_to_binary.dart' show 40 import 'package:kernel/binary/ast_to_binary.dart' show
42 BinaryPrinter; 41 BinaryPrinter;
43 42
44 import 'package:kernel/binary/ast_from_binary.dart' show 43 import 'package:kernel/binary/ast_from_binary.dart' show
45 BinaryBuilder; 44 BinaryBuilder;
46 45
47 import 'package:kernel/binary/loader.dart' show
48 BinaryLoader;
49
50 import 'package:analyzer/src/generated/sdk.dart' show 46 import 'package:analyzer/src/generated/sdk.dart' show
51 DartSdk; 47 DartSdk;
52 48
53 import 'package:kernel/analyzer/loader.dart' show 49 import 'package:kernel/analyzer/loader.dart' show
54 DartLoader, 50 DartLoader,
55 DartOptions, 51 DartOptions,
56 createDartSdk; 52 createDartSdk;
57 53
58 import 'package:kernel/target/targets.dart' show 54 import 'package:kernel/target/targets.dart' show
59 Target, 55 Target,
60 TargetFlags, 56 TargetFlags,
61 getTarget; 57 getTarget;
62 58
63 import 'package:kernel/repository.dart' show
64 Repository;
65
66 import 'package:testing/testing.dart' show 59 import 'package:testing/testing.dart' show
67 Chain, 60 Chain,
68 ChainContext, 61 ChainContext,
69 Result, 62 Result,
70 StdioProcess, 63 StdioProcess,
71 Step, 64 Step,
72 TestDescription; 65 TestDescription;
73 66
74 import 'package:kernel/ast.dart' show 67 import 'package:kernel/ast.dart' show
75 Program; 68 Program;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 final DartOptions options; 129 final DartOptions options;
137 130
138 final DartSdk dartSdk; 131 final DartSdk dartSdk;
139 132
140 TestContext(Uri sdk, this.vm, Uri packages, bool strongMode, this.dartSdk) 133 TestContext(Uri sdk, this.vm, Uri packages, bool strongMode, this.dartSdk)
141 : packages = packages, 134 : packages = packages,
142 options = new DartOptions(strongMode: strongMode, sdk: sdk.toFilePath(), 135 options = new DartOptions(strongMode: strongMode, sdk: sdk.toFilePath(),
143 packagePath: packages.toFilePath()); 136 packagePath: packages.toFilePath());
144 137
145 Future<DartLoader> createLoader() async { 138 Future<DartLoader> createLoader() async {
146 Repository repository = new Repository(); 139 Program program = new Program();
147 return new DartLoader(repository, options, await loadPackagesFile(packages), 140 return new DartLoader(program, options, await loadPackagesFile(packages),
148 ignoreRedirectingFactories: false, dartSdk: dartSdk); 141 ignoreRedirectingFactories: false, dartSdk: dartSdk);
149 } 142 }
150 143
151 static Future<TestContext> create(Chain suite, 144 static Future<TestContext> create(Chain suite,
152 Map<String, String> environment, 145 Map<String, String> environment,
153 TestContextConstructor constructor) async { 146 TestContextConstructor constructor) async {
154 Uri sdk = await computePatchedSdk(); 147 Uri sdk = await computePatchedSdk();
155 Uri vm = computeDartVm(sdk); 148 Uri vm = computeDartVm(sdk);
156 Uri packages = Uri.base.resolve(".packages"); 149 Uri packages = Uri.base.resolve(".packages");
157 bool strongMode = false; 150 bool strongMode = false;
158 bool updateExpectations = environment["updateExpectations"] == "true"; 151 bool updateExpectations = environment["updateExpectations"] == "true";
159 return constructor(suite, environment, sdk, vm, packages, strongMode, 152 return constructor(suite, environment, sdk, vm, packages, strongMode,
160 createDartSdk(sdk.toFilePath(), strongMode: strongMode), 153 createDartSdk(sdk.toFilePath(), strongMode: strongMode),
161 updateExpectations); 154 updateExpectations);
162 } 155 }
163 } 156 }
164 157
165 class Kernel extends Step<TestDescription, Program, TestContext> { 158 class Kernel extends Step<TestDescription, Program, TestContext> {
166 const Kernel(); 159 const Kernel();
167 160
168 String get name => "kernel"; 161 String get name => "kernel";
169 162
170 Future<Result<Program>> run( 163 Future<Result<Program>> run(
171 TestDescription description, TestContext testContext) async { 164 TestDescription description, TestContext testContext) async {
172 try { 165 try {
173 DartLoader loader = await testContext.createLoader(); 166 DartLoader loader = await testContext.createLoader();
174 Target target = getTarget( 167 Target target = getTarget(
175 "vm", new TargetFlags(strongMode: testContext.options.strongMode)); 168 "vm", new TargetFlags(strongMode: testContext.options.strongMode));
176 Program program = 169 loader.loadProgram(description.uri, target: target);
177 loader.loadProgram(description.uri, target: target); 170 Program program = loader.program;
178 for (var error in loader.errors) { 171 for (var error in loader.errors) {
179 return fail(program, "$error"); 172 return fail(program, "$error");
180 } 173 }
181 target.performModularTransformations(program); 174 target.performModularTransformations(program);
182 target.performGlobalTransformations(program); 175 target.performGlobalTransformations(program);
183 return pass(program); 176 return pass(program);
184 } catch (e, s) { 177 } catch (e, s) {
185 return crash(e, s); 178 return crash(e, s);
186 } 179 }
187 } 180 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 266
274 String get name => "write .dill"; 267 String get name => "write .dill";
275 268
276 Future<Result<Uri>> run(Program program, _) async { 269 Future<Result<Uri>> run(Program program, _) async {
277 Directory tmp = await Directory.systemTemp.createTemp(); 270 Directory tmp = await Directory.systemTemp.createTemp();
278 Uri uri = tmp.uri.resolve("generated.dill"); 271 Uri uri = tmp.uri.resolve("generated.dill");
279 File generated = new File.fromUri(uri); 272 File generated = new File.fromUri(uri);
280 IOSink sink = generated.openWrite(); 273 IOSink sink = generated.openWrite();
281 try { 274 try {
282 new BinaryPrinter(sink).writeProgramFile(program); 275 new BinaryPrinter(sink).writeProgramFile(program);
276 program.unbindCanonicalNames();
283 } catch (e, s) { 277 } catch (e, s) {
284 return fail(uri, e, s); 278 return fail(uri, e, s);
285 } finally { 279 } finally {
286 print("Wrote `${generated.path}`"); 280 print("Wrote `${generated.path}`");
287 await sink.close(); 281 await sink.close();
288 } 282 }
289 return pass(uri); 283 return pass(uri);
290 } 284 }
291 } 285 }
292 286
(...skipping 13 matching lines...) Expand all
306 } 300 }
307 301
308 class Copy extends Step<Program, Program, TestContext> { 302 class Copy extends Step<Program, Program, TestContext> {
309 const Copy(); 303 const Copy();
310 304
311 String get name => "copy program"; 305 String get name => "copy program";
312 306
313 Future<Result<Program>> run(Program program, _) async { 307 Future<Result<Program>> run(Program program, _) async {
314 BytesCollector sink = new BytesCollector(); 308 BytesCollector sink = new BytesCollector();
315 new BinaryPrinter(sink).writeProgramFile(program); 309 new BinaryPrinter(sink).writeProgramFile(program);
310 program.unbindCanonicalNames();
316 Uint8List bytes = sink.collect(); 311 Uint8List bytes = sink.collect();
317 BinaryLoader loader = new BinaryLoader(new Repository()); 312 new BinaryBuilder(bytes).readProgram(program);
318 return pass(new BinaryBuilder(loader, bytes).readProgramFile()); 313 return pass(program);
319 } 314 }
320 } 315 }
321 316
322 class Run extends Step<Uri, int, TestContext> { 317 class Run extends Step<Uri, int, TestContext> {
323 const Run(); 318 const Run();
324 319
325 String get name => "run"; 320 String get name => "run";
326 321
327 bool get isAsync => true; 322 bool get isAsync => true;
328 323
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 370
376 Future openWrite(Uri uri, f(IOSink sink)) async { 371 Future openWrite(Uri uri, f(IOSink sink)) async {
377 IOSink sink = new File.fromUri(uri).openWrite(); 372 IOSink sink = new File.fromUri(uri).openWrite();
378 try { 373 try {
379 await f(sink); 374 await f(sink);
380 } finally { 375 } finally {
381 await sink.close(); 376 await sink.close();
382 } 377 }
383 print("Wrote $uri"); 378 print("Wrote $uri");
384 } 379 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/kernel_target.dart ('k') | pkg/front_end/lib/src/fasta/testing/suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698