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

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

Issue 1555093005: Use SummarySdkAnalysisContext if the SDK has the analysis_summary file. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/sdk_io.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
10 import 'package:analyzer/src/context/context.dart';
9 import 'package:analyzer/src/dart/element/type.dart'; 11 import 'package:analyzer/src/dart/element/type.dart';
10 import 'package:analyzer/src/generated/constant.dart'; 12 import 'package:analyzer/src/generated/constant.dart';
11 import 'package:analyzer/src/generated/resolver.dart'; 13 import 'package:analyzer/src/generated/resolver.dart';
14 import 'package:analyzer/src/generated/source.dart' show Source, SourceKind;
15 import 'package:analyzer/src/summary/format.dart';
16 import 'package:analyzer/src/summary/resynthesize.dart';
17 import 'package:analyzer/src/task/dart.dart'
18 show
19 LIBRARY_ELEMENT1,
20 LIBRARY_ELEMENT2,
21 LIBRARY_ELEMENT3,
22 LIBRARY_ELEMENT4,
23 LIBRARY_ELEMENT5,
24 LIBRARY_ELEMENT6,
25 LIBRARY_ELEMENT7,
26 LIBRARY_ELEMENT8,
27 READY_LIBRARY_ELEMENT2,
28 READY_LIBRARY_ELEMENT5,
29 READY_LIBRARY_ELEMENT6,
30 TYPE_PROVIDER;
31 import 'package:analyzer/task/dart.dart';
32 import 'package:analyzer/task/model.dart'
33 show AnalysisTarget, ResultDescriptor, TargetedResult;
34
35 /**
36 * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle].
37 */
38 class SummarySdkAnalysisContext extends SdkAnalysisContext {
39 final SdkBundle bundle;
40 final SummaryTypeProvider typeProvider = new SummaryTypeProvider();
41
42 SummaryResynthesizer resynthesizer;
43
44 SummarySdkAnalysisContext(this.bundle);
45
46 @override
47 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) {
48 if (resynthesizer == null) {
49 resynthesizer = new SummaryResynthesizer(this, typeProvider,
50 _getPrelinkedSummary, _getUnlinkedSummary, sourceFactory);
51 _buildCoreLibrary();
52 _buildAsyncLibrary();
53 }
54 if (result == TYPE_PROVIDER) {
55 entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST);
56 return true;
57 }
58 AnalysisTarget target = entry.target;
59 // print('SummarySdkAnalysisContext: $result of $target');
60 if (target is Source && target.isInSystemLibrary) {
61 if (result == LIBRARY_ELEMENT1 ||
62 result == LIBRARY_ELEMENT2 ||
63 result == LIBRARY_ELEMENT3 ||
64 result == LIBRARY_ELEMENT4 ||
65 result == LIBRARY_ELEMENT5 ||
66 result == LIBRARY_ELEMENT6 ||
67 result == LIBRARY_ELEMENT7 ||
68 result == LIBRARY_ELEMENT8 ||
69 result == LIBRARY_ELEMENT) {
70 // TODO(scheglov) try to find a way to avoid listing every result
71 // e.g. "result.whenComplete == LIBRARY_ELEMENT"
72 String uri = target.uri.toString();
73 LibraryElement libraryElement = resynthesizer.getLibraryElement(uri);
74 entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST);
75 return true;
76 } else if (result == READY_LIBRARY_ELEMENT2 ||
77 result == READY_LIBRARY_ELEMENT5 ||
78 result == READY_LIBRARY_ELEMENT6) {
79 entry.setValue(result, true, TargetedResult.EMPTY_LIST);
80 return true;
81 } else if (result == SOURCE_KIND) {
82 // TODO(scheglov) not every source is a library
83 entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST);
84 return true;
85 } else {
86 // throw new UnimplementedError('$result of $target');
87 }
88 }
89 return false;
90 }
91
92 void _buildAsyncLibrary() {
93 LibraryElement library = resynthesizer.getLibraryElement('dart:async');
94 typeProvider.initializeAsync(library);
95 }
96
97 void _buildCoreLibrary() {
98 LibraryElement library = resynthesizer.getLibraryElement('dart:core');
99 typeProvider.initializeCore(library);
100 }
101
102 PrelinkedLibrary _getPrelinkedSummary(String uri) {
103 for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) {
104 if (bundle.prelinkedLibraryUris[i] == uri) {
105 return bundle.prelinkedLibraries[i];
106 }
107 }
108 throw new StateError('Unable to find prelinked summary for $uri');
109 }
110
111 UnlinkedUnit _getUnlinkedSummary(String uri) {
112 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
113 if (bundle.unlinkedUnitUris[i] == uri) {
114 return bundle.unlinkedUnits[i];
115 }
116 }
117 throw new StateError('Unable to find unlinked summary for $uri');
118 }
119 }
12 120
13 /** 121 /**
14 * Implementation of [TypeProvider] which can be initialized separately with 122 * Implementation of [TypeProvider] which can be initialized separately with
15 * `dart:core` and `dart:async` libraries. 123 * `dart:core` and `dart:async` libraries.
16 */ 124 */
17 class SummaryTypeProvider implements TypeProvider { 125 class SummaryTypeProvider implements TypeProvider {
18 bool _isCoreInitialized = false; 126 bool _isCoreInitialized = false;
19 bool _isAsyncInitialized = false; 127 bool _isAsyncInitialized = false;
20 128
21 InterfaceType _boolType; 129 InterfaceType _boolType;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 * throw a [StateError] if there is no class with the given name. 346 * throw a [StateError] if there is no class with the given name.
239 */ 347 */
240 InterfaceType _getType(LibraryElement library, String name) { 348 InterfaceType _getType(LibraryElement library, String name) {
241 Element element = library.getType(name); 349 Element element = library.getType(name);
242 if (element == null) { 350 if (element == null) {
243 throw new StateError("No definition of type $name"); 351 throw new StateError("No definition of type $name");
244 } 352 }
245 return (element as ClassElement).type; 353 return (element as ClassElement).type;
246 } 354 }
247 } 355 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/sdk_io.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698