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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1530303005: Separate prelinked and unlinked parts of summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library test.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'package:analyzer/src/generated/element.dart'; 7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/src/generated/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/summary/builder.dart'; 9 import 'package:analyzer/src/summary/builder.dart';
10 import 'package:analyzer/src/summary/format.dart'; 10 import 'package:analyzer/src/summary/format.dart';
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 expect(resynthesized.uri, original.uri); 410 expect(resynthesized.uri, original.uri);
411 } 411 }
412 412
413 void compareVariableElements(VariableElementImpl resynthesized, 413 void compareVariableElements(VariableElementImpl resynthesized,
414 VariableElementImpl original, String desc) { 414 VariableElementImpl original, String desc) {
415 compareElements(resynthesized, original, desc); 415 compareElements(resynthesized, original, desc);
416 compareTypes(resynthesized.type, original.type, desc); 416 compareTypes(resynthesized.type, original.type, desc);
417 // TODO(paulberry): test initializer 417 // TODO(paulberry): test initializer
418 } 418 }
419 419
420 PrelinkedLibrary getSummaryFor(LibraryElement lib) {
421 BuilderContext ctx = new BuilderContext();
422 List<int> summary = serializeLibrary(ctx, lib, typeProvider).toBuffer();
423 return new PrelinkedLibrary.fromBuffer(summary);
424 }
425
426 LibraryElementImpl resynthesizeLibrary( 420 LibraryElementImpl resynthesizeLibrary(
427 Source source, LibraryElementImpl original, bool allowErrors) { 421 Source source, LibraryElementImpl original, bool allowErrors) {
428 if (!allowErrors) { 422 if (!allowErrors) {
429 assertNoErrors(source); 423 assertNoErrors(source);
430 } 424 }
431 String uri = source.uri.toString(); 425 String uri = source.uri.toString();
432 addLibrary('dart:core'); 426 addLibrary('dart:core');
433 return resynthesizeLibraryElement(uri, original); 427 return resynthesizeLibraryElement(uri, original);
434 } 428 }
435 429
436 LibraryElementImpl resynthesizeLibraryElement( 430 LibraryElementImpl resynthesizeLibraryElement(
437 String uri, LibraryElementImpl original) { 431 String uri, LibraryElementImpl original) {
438 Map<String, PrelinkedLibrary> summaries = <String, PrelinkedLibrary>{ 432 Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{};
439 uri: getSummaryFor(original) 433 PrelinkedLibrary getPrelinkedSummaryFor(LibraryElement lib) {
440 }; 434 BuilderContext ctx = new BuilderContext();
435 LibrarySerializationResult serialized =
436 serializeLibrary(ctx, lib, typeProvider);
437 for (int i = 0; i < serialized.unlinkedUnits.length; i++) {
438 unlinkedSummaries[serialized.unitUris[i]] =
439 new UnlinkedUnit.fromBuffer(serialized.unlinkedUnits[i].toBuffer());
440 }
441 return new PrelinkedLibrary.fromBuffer(serialized.prelinked.toBuffer());
442 }
443 Map<String, PrelinkedLibrary> prelinkedSummaries =
444 <String, PrelinkedLibrary>{uri: getPrelinkedSummaryFor(original)};
441 for (Source source in otherLibrarySources) { 445 for (Source source in otherLibrarySources) {
442 LibraryElement original = resolve2(source); 446 LibraryElement original = resolve2(source);
443 String uri = source.uri.toString(); 447 String uri = source.uri.toString();
444 summaries[uri] = getSummaryFor(original); 448 prelinkedSummaries[uri] = getPrelinkedSummaryFor(original);
445 } 449 }
446 PrelinkedLibrary getSummary(String uri) { 450 PrelinkedLibrary getPrelinkedSummary(String uri) {
447 PrelinkedLibrary serializedLibrary = summaries[uri]; 451 PrelinkedLibrary serializedLibrary = prelinkedSummaries[uri];
448 if (serializedLibrary == null) { 452 if (serializedLibrary == null) {
449 fail('Unexpectedly tried to get serialized library for $uri'); 453 fail('Unexpectedly tried to get prelinked summary for $uri');
450 } 454 }
451 return serializedLibrary; 455 return serializedLibrary;
452 } 456 }
457 UnlinkedUnit getUnlinkedSummary(String uri) {
458 UnlinkedUnit serializedUnit = unlinkedSummaries[uri];
459 if (serializedUnit == null) {
460 fail('Unexpectedly tried to get unlinked summary for $uri');
461 }
462 return serializedUnit;
463 }
453 SummaryResynthesizer resynthesizer = new SummaryResynthesizer( 464 SummaryResynthesizer resynthesizer = new SummaryResynthesizer(
454 analysisContext, getSummary, analysisContext.sourceFactory); 465 analysisContext,
466 getPrelinkedSummary,
467 getUnlinkedSummary,
468 analysisContext.sourceFactory);
455 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri); 469 LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri);
456 // Check that no other summaries needed to be resynthesized to resynthesize 470 // Check that no other summaries needed to be resynthesized to resynthesize
457 // the library element. 471 // the library element.
458 expect(resynthesizer.resynthesisCount, 1); 472 expect(resynthesizer.resynthesisCount, 1);
459 return resynthesized; 473 return resynthesized;
460 } 474 }
461 475
462 test_class_alias() { 476 test_class_alias() {
463 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); 477 checkLibrary('class C = D with E, F; class D {} class E {} class F {}');
464 } 478 }
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 } 1031 }
1018 1032
1019 test_variable_const() { 1033 test_variable_const() {
1020 checkLibrary('const int i = 0;'); 1034 checkLibrary('const int i = 0;');
1021 } 1035 }
1022 1036
1023 test_variables() { 1037 test_variables() {
1024 checkLibrary('int i; int j;'); 1038 checkLibrary('int i; int j;');
1025 } 1039 }
1026 } 1040 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/test/src/summary/summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698