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

Side by Side Diff: pkg/analyzer/lib/src/summary/summary_sdk.dart

Issue 1591483002: Prepare for chaining resynthesizers from AC to SDK AC. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fallback to the SDK. Created 4 years, 11 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) 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 analyzer.src.summary.summary_sdk; 5 library analyzer.src.summary.summary_sdk;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/context/cache.dart' show CacheEntry; 9 import 'package:analyzer/src/context/cache.dart' show CacheEntry;
10 import 'package:analyzer/src/context/context.dart'; 10 import 'package:analyzer/src/context/context.dart';
11 import 'package:analyzer/src/dart/element/type.dart'; 11 import 'package:analyzer/src/dart/element/type.dart';
12 import 'package:analyzer/src/generated/constant.dart'; 12 import 'package:analyzer/src/generated/constant.dart';
13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/resolver.dart'; 14 import 'package:analyzer/src/generated/resolver.dart';
14 import 'package:analyzer/src/generated/source.dart' show Source, SourceKind; 15 import 'package:analyzer/src/generated/source.dart'
16 show DartUriResolver, Source, SourceFactory, SourceKind;
15 import 'package:analyzer/src/summary/format.dart'; 17 import 'package:analyzer/src/summary/format.dart';
16 import 'package:analyzer/src/summary/resynthesize.dart'; 18 import 'package:analyzer/src/summary/resynthesize.dart';
17 import 'package:analyzer/src/task/dart.dart' 19 import 'package:analyzer/src/task/dart.dart'
18 show 20 show
19 LIBRARY_ELEMENT1, 21 LIBRARY_ELEMENT1,
20 LIBRARY_ELEMENT2, 22 LIBRARY_ELEMENT2,
21 LIBRARY_ELEMENT3, 23 LIBRARY_ELEMENT3,
22 LIBRARY_ELEMENT4, 24 LIBRARY_ELEMENT4,
23 LIBRARY_ELEMENT5, 25 LIBRARY_ELEMENT5,
24 LIBRARY_ELEMENT6, 26 LIBRARY_ELEMENT6,
25 LIBRARY_ELEMENT7, 27 LIBRARY_ELEMENT7,
26 LIBRARY_ELEMENT8, 28 LIBRARY_ELEMENT8,
27 READY_LIBRARY_ELEMENT2, 29 READY_LIBRARY_ELEMENT2,
28 READY_LIBRARY_ELEMENT5, 30 READY_LIBRARY_ELEMENT5,
29 READY_LIBRARY_ELEMENT6, 31 READY_LIBRARY_ELEMENT6,
30 TYPE_PROVIDER; 32 TYPE_PROVIDER;
31 import 'package:analyzer/task/dart.dart'; 33 import 'package:analyzer/task/dart.dart';
32 import 'package:analyzer/task/model.dart' 34 import 'package:analyzer/task/model.dart'
33 show AnalysisTarget, ResultDescriptor, TargetedResult; 35 show AnalysisTarget, ResultDescriptor, TargetedResult;
34 36
35 /** 37 class SdkSummaryResultProvider extends AboutToComputeResultHelper {
36 * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle].
37 */
38 class SummarySdkAnalysisContext extends SdkAnalysisContext {
39 final SdkBundle bundle; 38 final SdkBundle bundle;
40 final SummaryTypeProvider typeProvider = new SummaryTypeProvider(); 39 final SummaryTypeProvider typeProvider = new SummaryTypeProvider();
40 SummaryResynthesizer summaryResynthesizer;
41 41
42 SummaryResynthesizer resynthesizer; 42 SdkSummaryResultProvider(InternalAnalysisContext context, this.bundle)
43 43 : super(context) {
44 SummarySdkAnalysisContext(this.bundle); 44 summaryResynthesizer = new SummaryResynthesizer(
45 null,
46 context,
47 typeProvider,
48 (String uri) => uri.startsWith('dart:'),
49 _getPrelinkedSummary,
50 _getUnlinkedSummary,
51 context.sourceFactory);
52 _buildCoreLibrary();
53 _buildAsyncLibrary();
54 summaryResynthesizer.finalizeCoreAsyncLibraries();
55 }
45 56
46 @override 57 @override
47 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) { 58 bool compute(CacheEntry entry, ResultDescriptor result) {
48 if (resynthesizer == null) {
49 resynthesizer = new SummaryResynthesizer(
50 null,
51 this,
52 typeProvider,
53 (String uri) => uri.startsWith('dart:'),
54 _getPrelinkedSummary,
55 _getUnlinkedSummary,
56 sourceFactory);
57 _buildCoreLibrary();
58 _buildAsyncLibrary();
59 }
60 if (result == TYPE_PROVIDER) { 59 if (result == TYPE_PROVIDER) {
60 // print('SummarySdkAnalysisContext: $result');
61 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST); 61 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST);
62 return true; 62 return true;
63 } 63 }
64 AnalysisTarget target = entry.target; 64 AnalysisTarget target = entry.target;
65 // print('SummarySdkAnalysisContext: $result of $target');
66 if (target is Source && target.isInSystemLibrary) { 65 if (target is Source && target.isInSystemLibrary) {
66 // print('SummarySdkAnalysisContext: $result of $target');
67 if (result == LIBRARY_ELEMENT1 || 67 if (result == LIBRARY_ELEMENT1 ||
68 result == LIBRARY_ELEMENT2 || 68 result == LIBRARY_ELEMENT2 ||
69 result == LIBRARY_ELEMENT3 || 69 result == LIBRARY_ELEMENT3 ||
70 result == LIBRARY_ELEMENT4 || 70 result == LIBRARY_ELEMENT4 ||
71 result == LIBRARY_ELEMENT5 || 71 result == LIBRARY_ELEMENT5 ||
72 result == LIBRARY_ELEMENT6 || 72 result == LIBRARY_ELEMENT6 ||
73 result == LIBRARY_ELEMENT7 || 73 result == LIBRARY_ELEMENT7 ||
74 result == LIBRARY_ELEMENT8 || 74 result == LIBRARY_ELEMENT8 ||
75 result == LIBRARY_ELEMENT) { 75 result == LIBRARY_ELEMENT) {
76 // TODO(scheglov) try to find a way to avoid listing every result 76 // TODO(scheglov) try to find a way to avoid listing every result
77 // e.g. "result.whenComplete == LIBRARY_ELEMENT" 77 // e.g. "result.whenComplete == LIBRARY_ELEMENT"
78 String uri = target.uri.toString(); 78 String uri = target.uri.toString();
79 LibraryElement libraryElement = resynthesizer.getLibraryElement(uri); 79 LibraryElement libraryElement =
80 summaryResynthesizer.getLibraryElement(uri);
80 entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST); 81 entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST);
81 return true; 82 return true;
82 } else if (result == READY_LIBRARY_ELEMENT2 || 83 } else if (result == READY_LIBRARY_ELEMENT2 ||
83 result == READY_LIBRARY_ELEMENT5 || 84 result == READY_LIBRARY_ELEMENT5 ||
84 result == READY_LIBRARY_ELEMENT6) { 85 result == READY_LIBRARY_ELEMENT6) {
85 entry.setValue(result, true, TargetedResult.EMPTY_LIST); 86 entry.setValue(result, true, TargetedResult.EMPTY_LIST);
86 return true; 87 return true;
87 } else if (result == SOURCE_KIND) { 88 } else if (result == SOURCE_KIND) {
88 String uri = target.uri.toString(); 89 String uri = target.uri.toString();
89 if (bundle.prelinkedLibraryUris.contains(uri)) { 90 SourceKind kind = _getSourceKind(uri);
90 entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST); 91 if (kind != null) {
91 return true; 92 entry.setValue(result, kind, TargetedResult.EMPTY_LIST);
92 }
93 if (bundle.unlinkedUnitUris.contains(uri)) {
94 entry.setValue(result, SourceKind.PART, TargetedResult.EMPTY_LIST);
95 return true; 93 return true;
96 } 94 }
97 return false; 95 return false;
98 } else { 96 } else {
99 // throw new UnimplementedError('$result of $target'); 97 // throw new UnimplementedError('$result of $target');
100 } 98 }
101 } 99 }
102 return false; 100 return false;
103 } 101 }
104 102
105 void _buildAsyncLibrary() { 103 void _buildAsyncLibrary() {
106 LibraryElement library = resynthesizer.getLibraryElement('dart:async'); 104 LibraryElement library =
105 summaryResynthesizer.getLibraryElement('dart:async');
107 typeProvider.initializeAsync(library); 106 typeProvider.initializeAsync(library);
108 } 107 }
109 108
110 void _buildCoreLibrary() { 109 void _buildCoreLibrary() {
111 LibraryElement library = resynthesizer.getLibraryElement('dart:core'); 110 LibraryElement library =
111 summaryResynthesizer.getLibraryElement('dart:core');
112 typeProvider.initializeCore(library); 112 typeProvider.initializeCore(library);
113 } 113 }
114 114
115 /**
116 * Return the [PrelinkedLibrary] for the given [uri] or throw [StateError].
117 */
115 PrelinkedLibrary _getPrelinkedSummary(String uri) { 118 PrelinkedLibrary _getPrelinkedSummary(String uri) {
116 for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) { 119 for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) {
117 if (bundle.prelinkedLibraryUris[i] == uri) { 120 if (bundle.prelinkedLibraryUris[i] == uri) {
118 return bundle.prelinkedLibraries[i]; 121 return bundle.prelinkedLibraries[i];
119 } 122 }
120 } 123 }
121 throw new StateError('Unable to find prelinked summary for $uri'); 124 throw new StateError('Unable to find prelinked summary for $uri');
122 } 125 }
123 126
127 /**
128 * Return the [SourceKind] of the given [uri] or `null` if it is unknown.
129 */
130 SourceKind _getSourceKind(String uri) {
131 if (bundle.prelinkedLibraryUris.contains(uri)) {
132 return SourceKind.LIBRARY;
133 }
134 if (bundle.unlinkedUnitUris.contains(uri)) {
135 return SourceKind.PART;
136 }
137 return null;
138 }
139
140 /**
141 * Return the [UnlinkedUnit] for the given [uri] or throw [StateError].
142 */
124 UnlinkedUnit _getUnlinkedSummary(String uri) { 143 UnlinkedUnit _getUnlinkedSummary(String uri) {
125 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { 144 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
126 if (bundle.unlinkedUnitUris[i] == uri) { 145 if (bundle.unlinkedUnitUris[i] == uri) {
127 return bundle.unlinkedUnits[i]; 146 return bundle.unlinkedUnits[i];
128 } 147 }
129 } 148 }
130 throw new StateError('Unable to find unlinked summary for $uri'); 149 throw new StateError('Unable to find unlinked summary for $uri');
131 } 150 }
132 } 151 }
133 152
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 * throw a [StateError] if there is no class with the given name. 378 * throw a [StateError] if there is no class with the given name.
360 */ 379 */
361 InterfaceType _getType(LibraryElement library, String name) { 380 InterfaceType _getType(LibraryElement library, String name) {
362 Element element = library.getType(name); 381 Element element = library.getType(name);
363 if (element == null) { 382 if (element == null) {
364 throw new StateError("No definition of type $name"); 383 throw new StateError("No definition of type $name");
365 } 384 }
366 return (element as ClassElement).type; 385 return (element as ClassElement).type;
367 } 386 }
368 } 387 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698