OLD | NEW |
---|---|
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 'package:front_end/src/incremental/limited_ast_to_binary.dart'; | |
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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
256 _getLibraryText(library), | 260 _getLibraryText(library), |
257 r''' | 261 r''' |
258 library; | 262 library; |
259 import self as self; | 263 import self as self; |
260 import "dart:core" as core; | 264 import "dart:core" as core; |
261 | 265 |
262 static field (core::String) → core::int f; | 266 static field (core::String) → core::int f; |
263 '''); | 267 '''); |
264 } | 268 } |
265 | 269 |
270 test_limited_ast_to_binary() async { | |
271 writeFile('/test/.packages', 'test:lib/'); | |
272 String aPath = '/test/lib/a.dart'; | |
273 String bPath = '/test/lib/b.dart'; | |
274 writeFile( | |
275 aPath, | |
276 r''' | |
277 int topField = 0; | |
278 int get topGetter => 0; | |
279 int topFunction({p}) => 0; | |
280 | |
281 class A { | |
282 static int staticField; | |
283 static int get staticGetter => 0; | |
284 static int staticMethod() => 0; | |
285 | |
286 int instanceField; | |
287 int get instanceGetter => 0; | |
288 int instanceMethod() => 0; | |
289 | |
290 A(); | |
291 A.named(); | |
292 } | |
293 '''); | |
294 Uri bUri = writeFile( | |
295 bPath, | |
296 r''' | |
297 import 'a.dart'; | |
298 | |
299 class B extends A { | |
300 B() : super(); | |
301 B.named() : super.named(); | |
302 | |
303 void foo() { | |
304 super.instanceMethod(); | |
305 instanceMethod(); | |
306 } | |
307 | |
308 int instanceMethod() => 0; | |
309 } | |
310 | |
311 main() { | |
312 topField; | |
313 topField = 0; | |
314 var v1 = topGetter; | |
315 var v2 = topFunction(p: 0); | |
316 | |
317 A.staticField; | |
318 A.staticField = 0; | |
319 var v3 = A.staticGetter; | |
320 var v4 = A.staticMethod(); | |
321 | |
322 var a = new A(); | |
323 a.instanceField; | |
324 a.instanceField = 0; | |
325 var v5 = a.instanceGetter; | |
326 var v6 = a.instanceMethod(); | |
327 } | |
328 '''); | |
329 | |
330 Program initialProgram = await getInitialState(bUri); | |
331 | |
332 String initialKernelText; | |
333 List<int> bytes; | |
334 { | |
335 Library initialLibrary = _getLibrary(initialProgram, bUri); | |
336 initialKernelText = _getLibraryText(initialLibrary); | |
337 | |
338 var byteSink = new ByteSink(); | |
339 var printer = new LimitedBinaryPrinter( | |
340 byteSink, (library) => library.importUri == bUri); | |
341 printer.writeProgramFile(initialProgram); | |
342 bytes = byteSink.builder.takeBytes(); | |
343 | |
344 // Remove b.dart from the initial program. | |
345 // So, the program is now ready for re-adding the library. | |
346 initialProgram.libraries.remove(initialLibrary); | |
347 initialProgram.root.removeChild(initialLibrary.importUri.toString()); | |
348 } | |
349 | |
350 // Load b.dart from bytes using the initial name root, so that | |
351 // serialized canonical names can be linked to corresponding nodes. | |
352 Library loadedLibrary; | |
353 { | |
354 var programForLoading = new Program(nameRoot: initialProgram.root); | |
355 var reader = new BinaryBuilder(bytes); | |
356 reader.readProgram(programForLoading); | |
357 loadedLibrary = _getLibrary(programForLoading, bUri); | |
358 } | |
359 | |
360 // Add the library into the initial program. | |
361 initialProgram.libraries.add(loadedLibrary); | |
Siggi Cherem (dart-lang)
2017/05/23 20:54:51
nit: either rename initialProgram or add a second
scheglov
2017/05/23 21:54:43
I renamed it to just "program".
| |
362 loadedLibrary.parent = initialProgram; | |
363 | |
364 // The loaded library has the same text. | |
365 expect(_getLibraryText(loadedLibrary), initialKernelText); | |
366 | |
367 // The program with re-added library passes verification. | |
Siggi Cherem (dart-lang)
2017/05/23 20:54:51
I'd delete this and the comment above, I think the
scheglov
2017/05/23 21:54:43
OK, I removed both comments.
A second variable na
| |
368 verifyProgram(initialProgram); | |
369 } | |
370 | |
266 test_updateEntryPoint() async { | 371 test_updateEntryPoint() async { |
267 writeFile('/test/.packages', 'test:lib/'); | 372 writeFile('/test/.packages', 'test:lib/'); |
268 String path = '/test/lib/test.dart'; | 373 String path = '/test/lib/test.dart'; |
269 Uri uri = writeFile( | 374 Uri uri = writeFile( |
270 path, | 375 path, |
271 r''' | 376 r''' |
272 main() { | 377 main() { |
273 var v = 1; | 378 var v = 1; |
274 } | 379 } |
275 '''); | 380 '''); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 throw fail('No library found with URI "$uri"'); | 559 throw fail('No library found with URI "$uri"'); |
455 } | 560 } |
456 | 561 |
457 String _getLibraryText(Library library) { | 562 String _getLibraryText(Library library) { |
458 StringBuffer buffer = new StringBuffer(); | 563 StringBuffer buffer = new StringBuffer(); |
459 new Printer(buffer, syntheticNames: new NameSystem()) | 564 new Printer(buffer, syntheticNames: new NameSystem()) |
460 .writeLibraryFile(library); | 565 .writeLibraryFile(library); |
461 return buffer.toString(); | 566 return buffer.toString(); |
462 } | 567 } |
463 } | 568 } |
OLD | NEW |