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

Side by Side Diff: pkg/front_end/test/incremental_kernel_generator_test.dart

Issue 2896493002: Add LimitedBinaryPrinter, tests and switch incremental generator to it. (Closed)
Patch Set: Move LimitedBinaryPrinter to kernel, remove comments. Created 3 years, 6 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) 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:front_end/compiler_options.dart'; 7 import 'package:front_end/compiler_options.dart';
8 import 'package:front_end/incremental_kernel_generator.dart'; 8 import 'package:front_end/incremental_kernel_generator.dart';
9 import 'package:front_end/memory_file_system.dart'; 9 import 'package:front_end/memory_file_system.dart';
10 import 'package:front_end/src/incremental/byte_store.dart'; 10 import 'package:front_end/src/incremental/byte_store.dart';
11 import '../../kernel/lib/binary/limited_ast_to_binary.dart';
ahe 2017/05/24 08:36:00 You probably want to use a package URI here.
scheglov 2017/05/25 17:44:09 Fixed. Thanks.
12 import 'package:front_end/src/incremental_kernel_generator_impl.dart';
11 import 'package:kernel/ast.dart'; 13 import 'package:kernel/ast.dart';
14 import 'package:kernel/binary/ast_from_binary.dart';
12 import 'package:kernel/text/ast_to_text.dart'; 15 import 'package:kernel/text/ast_to_text.dart';
16 import 'package:kernel/verifier.dart';
13 import 'package:test/test.dart'; 17 import 'package:test/test.dart';
14 import 'package:test_reflective_loader/test_reflective_loader.dart'; 18 import 'package:test_reflective_loader/test_reflective_loader.dart';
15 19
16 import 'src/incremental/mock_sdk.dart'; 20 import 'src/incremental/mock_sdk.dart';
17 21
18 main() { 22 main() {
19 defineReflectiveSuite(() { 23 defineReflectiveSuite(() {
20 defineReflectiveTests(IncrementalKernelGeneratorTest); 24 defineReflectiveTests(IncrementalKernelGeneratorTest);
21 }); 25 });
22 } 26 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 _getLibraryText(library), 313 _getLibraryText(library),
310 r''' 314 r'''
311 library; 315 library;
312 import self as self; 316 import self as self;
313 import "dart:core" as core; 317 import "dart:core" as core;
314 318
315 static field (core::String) → core::int f; 319 static field (core::String) → core::int f;
316 '''); 320 ''');
317 } 321 }
318 322
323 test_limited_ast_to_binary() async {
324 writeFile('/test/.packages', 'test:lib/');
325 String aPath = '/test/lib/a.dart';
326 String bPath = '/test/lib/b.dart';
327 writeFile(
328 aPath,
329 r'''
330 int topField = 0;
331 int get topGetter => 0;
332 int topFunction({p}) => 0;
333
334 class A {
335 static int staticField;
336 static int get staticGetter => 0;
337 static int staticMethod() => 0;
338
339 int instanceField;
340 int get instanceGetter => 0;
341 int instanceMethod() => 0;
342
343 A();
344 A.named();
345 }
346 ''');
347 Uri bUri = writeFile(
348 bPath,
349 r'''
350 import 'a.dart';
351
352 class B extends A {
353 B() : super();
354 B.named() : super.named();
355
356 void foo() {
357 super.instanceMethod();
358 instanceMethod();
359 }
360
361 int instanceMethod() => 0;
362 }
363
364 main() {
365 topField;
366 topField = 0;
367 var v1 = topGetter;
368 var v2 = topFunction(p: 0);
369
370 A.staticField;
371 A.staticField = 0;
372 var v3 = A.staticGetter;
373 var v4 = A.staticMethod();
374
375 var a = new A();
376 a.instanceField;
377 a.instanceField = 0;
378 var v5 = a.instanceGetter;
379 var v6 = a.instanceMethod();
380 }
381 ''');
382
383 Program program = await getInitialState(bUri);
384
385 String initialKernelText;
386 List<int> bytes;
387 {
388 Library initialLibrary = _getLibrary(program, bUri);
389 initialKernelText = _getLibraryText(initialLibrary);
390
391 var byteSink = new ByteSink();
392 var printer = new LimitedBinaryPrinter(
393 byteSink, (library) => library.importUri == bUri);
394 printer.writeProgramFile(program);
395 bytes = byteSink.builder.takeBytes();
396
397 // Remove b.dart from the program.
398 // So, the program is now ready for re-adding the library.
399 program.libraries.remove(initialLibrary);
400 program.root.removeChild(initialLibrary.importUri.toString());
401 }
402
403 // Load b.dart from bytes using the initial name root, so that
404 // serialized canonical names can be linked to corresponding nodes.
405 Library loadedLibrary;
406 {
407 var programForLoading = new Program(nameRoot: program.root);
408 var reader = new BinaryBuilder(bytes);
409 reader.readProgram(programForLoading);
410 loadedLibrary = _getLibrary(programForLoading, bUri);
411 }
412
413 // Add the library into the program.
414 program.libraries.add(loadedLibrary);
415 loadedLibrary.parent = program;
416
417 expect(_getLibraryText(loadedLibrary), initialKernelText);
418 verifyProgram(program);
419 }
420
319 test_updateEntryPoint() async { 421 test_updateEntryPoint() async {
320 writeFile('/test/.packages', 'test:lib/'); 422 writeFile('/test/.packages', 'test:lib/');
321 String path = '/test/lib/test.dart'; 423 String path = '/test/lib/test.dart';
322 Uri uri = writeFile( 424 Uri uri = writeFile(
323 path, 425 path,
324 r''' 426 r'''
325 main() { 427 main() {
326 var v = 1; 428 var v = 1;
327 } 429 }
328 '''); 430 ''');
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 throw fail('No library found with URI "$uri"'); 609 throw fail('No library found with URI "$uri"');
508 } 610 }
509 611
510 String _getLibraryText(Library library) { 612 String _getLibraryText(Library library) {
511 StringBuffer buffer = new StringBuffer(); 613 StringBuffer buffer = new StringBuffer();
512 new Printer(buffer, syntheticNames: new NameSystem()) 614 new Printer(buffer, syntheticNames: new NameSystem())
513 .writeLibraryFile(library); 615 .writeLibraryFile(library);
514 return buffer.toString(); 616 return buffer.toString();
515 } 617 }
516 } 618 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/incremental_kernel_generator_impl.dart ('k') | pkg/kernel/lib/binary/ast_to_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698