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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/sdk_io.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/summary_sdk.dart
diff --git a/pkg/analyzer/lib/src/summary/summary_sdk.dart b/pkg/analyzer/lib/src/summary/summary_sdk.dart
index da2ca8eee76e335705456147e94407ae3da85282..70b7bddb736f613411070ce41e64c5be6557887d 100644
--- a/pkg/analyzer/lib/src/summary/summary_sdk.dart
+++ b/pkg/analyzer/lib/src/summary/summary_sdk.dart
@@ -6,9 +6,117 @@ library analyzer.src.summary.summary_sdk;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
+import 'package:analyzer/src/context/cache.dart' show CacheEntry;
+import 'package:analyzer/src/context/context.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/resolver.dart';
+import 'package:analyzer/src/generated/source.dart' show Source, SourceKind;
+import 'package:analyzer/src/summary/format.dart';
+import 'package:analyzer/src/summary/resynthesize.dart';
+import 'package:analyzer/src/task/dart.dart'
+ show
+ LIBRARY_ELEMENT1,
+ LIBRARY_ELEMENT2,
+ LIBRARY_ELEMENT3,
+ LIBRARY_ELEMENT4,
+ LIBRARY_ELEMENT5,
+ LIBRARY_ELEMENT6,
+ LIBRARY_ELEMENT7,
+ LIBRARY_ELEMENT8,
+ READY_LIBRARY_ELEMENT2,
+ READY_LIBRARY_ELEMENT5,
+ READY_LIBRARY_ELEMENT6,
+ TYPE_PROVIDER;
+import 'package:analyzer/task/dart.dart';
+import 'package:analyzer/task/model.dart'
+ show AnalysisTarget, ResultDescriptor, TargetedResult;
+
+/**
+ * An [SdkAnalysisContext] for Dart SDK with a summary [SdkBundle].
+ */
+class SummarySdkAnalysisContext extends SdkAnalysisContext {
+ final SdkBundle bundle;
+ final SummaryTypeProvider typeProvider = new SummaryTypeProvider();
+
+ SummaryResynthesizer resynthesizer;
+
+ SummarySdkAnalysisContext(this.bundle);
+
+ @override
+ bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) {
+ if (resynthesizer == null) {
+ resynthesizer = new SummaryResynthesizer(this, typeProvider,
+ _getPrelinkedSummary, _getUnlinkedSummary, sourceFactory);
+ _buildCoreLibrary();
+ _buildAsyncLibrary();
+ }
+ if (result == TYPE_PROVIDER) {
+ entry.setValue(result, typeProvider, TargetedResult.EMPTY_LIST);
+ return true;
+ }
+ AnalysisTarget target = entry.target;
+// print('SummarySdkAnalysisContext: $result of $target');
+ if (target is Source && target.isInSystemLibrary) {
+ if (result == LIBRARY_ELEMENT1 ||
+ result == LIBRARY_ELEMENT2 ||
+ result == LIBRARY_ELEMENT3 ||
+ result == LIBRARY_ELEMENT4 ||
+ result == LIBRARY_ELEMENT5 ||
+ result == LIBRARY_ELEMENT6 ||
+ result == LIBRARY_ELEMENT7 ||
+ result == LIBRARY_ELEMENT8 ||
+ result == LIBRARY_ELEMENT) {
+ // TODO(scheglov) try to find a way to avoid listing every result
+ // e.g. "result.whenComplete == LIBRARY_ELEMENT"
+ String uri = target.uri.toString();
+ LibraryElement libraryElement = resynthesizer.getLibraryElement(uri);
+ entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST);
+ return true;
+ } else if (result == READY_LIBRARY_ELEMENT2 ||
+ result == READY_LIBRARY_ELEMENT5 ||
+ result == READY_LIBRARY_ELEMENT6) {
+ entry.setValue(result, true, TargetedResult.EMPTY_LIST);
+ return true;
+ } else if (result == SOURCE_KIND) {
+ // TODO(scheglov) not every source is a library
+ entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST);
+ return true;
+ } else {
+// throw new UnimplementedError('$result of $target');
+ }
+ }
+ return false;
+ }
+
+ void _buildAsyncLibrary() {
+ LibraryElement library = resynthesizer.getLibraryElement('dart:async');
+ typeProvider.initializeAsync(library);
+ }
+
+ void _buildCoreLibrary() {
+ LibraryElement library = resynthesizer.getLibraryElement('dart:core');
+ typeProvider.initializeCore(library);
+ }
+
+ PrelinkedLibrary _getPrelinkedSummary(String uri) {
+ for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) {
+ if (bundle.prelinkedLibraryUris[i] == uri) {
+ return bundle.prelinkedLibraries[i];
+ }
+ }
+ throw new StateError('Unable to find prelinked summary for $uri');
+ }
+
+ UnlinkedUnit _getUnlinkedSummary(String uri) {
+ for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) {
+ if (bundle.unlinkedUnitUris[i] == uri) {
+ return bundle.unlinkedUnits[i];
+ }
+ }
+ throw new StateError('Unable to find unlinked summary for $uri');
+ }
+}
/**
* Implementation of [TypeProvider] which can be initialized separately with
« 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