Chromium Code Reviews| OLD | NEW |
|---|---|
| 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) { | |
|
Brian Wilkerson
2016/01/05 18:46:18
Is there any reason to do this lazily? It seems li
scheglov
2016/01/05 20:27:57
The property "sourceFactory" is set after the cont
| |
| 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 if (target is Source && target.isInSystemLibrary) { | |
| 60 if (result == LIBRARY_ELEMENT1 || | |
| 61 result == LIBRARY_ELEMENT2 || | |
| 62 result == LIBRARY_ELEMENT3 || | |
| 63 result == LIBRARY_ELEMENT4 || | |
| 64 result == LIBRARY_ELEMENT5 || | |
| 65 result == LIBRARY_ELEMENT6 || | |
| 66 result == LIBRARY_ELEMENT7 || | |
| 67 result == LIBRARY_ELEMENT8 || | |
| 68 result == LIBRARY_ELEMENT) { | |
|
Paul Berry
2016/01/05 19:33:43
Is it going to be a maintenance burden to keep thi
scheglov
2016/01/05 20:27:57
Sounds interesting.
| |
| 69 String uri = target.uri.toString(); | |
| 70 LibraryElement libraryElement = resynthesizer.getLibraryElement(uri); | |
| 71 entry.setValue(result, libraryElement, TargetedResult.EMPTY_LIST); | |
| 72 return true; | |
| 73 } else if (result == READY_LIBRARY_ELEMENT2 || | |
| 74 result == READY_LIBRARY_ELEMENT5 || | |
| 75 result == READY_LIBRARY_ELEMENT6) { | |
| 76 entry.setValue(result, true, TargetedResult.EMPTY_LIST); | |
| 77 return true; | |
| 78 } else if (result == SOURCE_KIND) { | |
| 79 // TODO(scheglov) not every source is a library | |
|
Paul Berry
2016/01/05 19:33:43
I think the only way this could be reached is if t
scheglov
2016/01/05 20:27:57
Yes.
For now it is just a placeholder.
Once we wil
| |
| 80 print(target.source.uri); | |
|
Brian Wilkerson
2016/01/05 18:46:18
Remove?
scheglov
2016/01/05 20:27:57
Done.
| |
| 81 entry.setValue(result, SourceKind.LIBRARY, TargetedResult.EMPTY_LIST); | |
| 82 return true; | |
|
Brian Wilkerson
2016/01/05 18:46:18
Should this return `false` for now until we can co
scheglov
2016/01/05 20:27:57
Returning `false` mean that we cannot provide this
Brian Wilkerson
2016/01/05 20:42:51
Could we implement it correctly by just testing wh
| |
| 83 } else { | |
| 84 throw new UnimplementedError('$result of $target'); | |
|
Brian Wilkerson
2016/01/05 18:46:18
Is this for debugging? If so, perhaps comment it o
scheglov
2016/01/05 20:27:57
Done.
| |
| 85 } | |
| 86 } | |
| 87 return false; | |
| 88 } | |
| 89 | |
| 90 void _buildAsyncLibrary() { | |
| 91 LibraryElement library = resynthesizer.getLibraryElement('dart:async'); | |
| 92 typeProvider.initializeAsync(library); | |
| 93 } | |
| 94 | |
| 95 void _buildCoreLibrary() { | |
| 96 LibraryElement library = resynthesizer.getLibraryElement('dart:core'); | |
| 97 typeProvider.initializeCore(library); | |
| 98 } | |
| 99 | |
| 100 PrelinkedLibrary _getPrelinkedSummary(String uri) { | |
| 101 for (int i = 0; i < bundle.prelinkedLibraryUris.length; i++) { | |
| 102 if (bundle.prelinkedLibraryUris[i] == uri) { | |
| 103 return bundle.prelinkedLibraries[i]; | |
| 104 } | |
| 105 } | |
| 106 throw new StateError('Unable to find prelinked summary for $uri'); | |
|
Paul Berry
2016/01/05 19:33:43
Is there a danger of this code getting triggered i
scheglov
2016/01/05 20:27:57
No, if a URI is not resolved to an existing Source
| |
| 107 } | |
| 108 | |
| 109 UnlinkedUnit _getUnlinkedSummary(String uri) { | |
| 110 for (int i = 0; i < bundle.unlinkedUnitUris.length; i++) { | |
| 111 if (bundle.unlinkedUnitUris[i] == uri) { | |
| 112 return bundle.unlinkedUnits[i]; | |
| 113 } | |
| 114 } | |
| 115 throw new StateError('Unable to find unlinked summary for $uri'); | |
| 116 } | |
| 117 } | |
| 12 | 118 |
| 13 /** | 119 /** |
| 14 * Implementation of [TypeProvider] which can be initialized separately with | 120 * Implementation of [TypeProvider] which can be initialized separately with |
| 15 * `dart:core` and `dart:async` libraries. | 121 * `dart:core` and `dart:async` libraries. |
| 16 */ | 122 */ |
| 17 class SummaryTypeProvider implements TypeProvider { | 123 class SummaryTypeProvider implements TypeProvider { |
| 18 bool _isCoreInitialized = false; | 124 bool _isCoreInitialized = false; |
| 19 bool _isAsyncInitialized = false; | 125 bool _isAsyncInitialized = false; |
| 20 | 126 |
| 21 InterfaceType _boolType; | 127 InterfaceType _boolType; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 238 * throw a [StateError] if there is no class with the given name. | 344 * throw a [StateError] if there is no class with the given name. |
| 239 */ | 345 */ |
| 240 InterfaceType _getType(LibraryElement library, String name) { | 346 InterfaceType _getType(LibraryElement library, String name) { |
| 241 Element element = library.getType(name); | 347 Element element = library.getType(name); |
| 242 if (element == null) { | 348 if (element == null) { |
| 243 throw new StateError("No definition of type $name"); | 349 throw new StateError("No definition of type $name"); |
| 244 } | 350 } |
| 245 return (element as ClassElement).type; | 351 return (element as ClassElement).type; |
| 246 } | 352 } |
| 247 } | 353 } |
| OLD | NEW |