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

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

Issue 1543313002: Delay TypeProvider.objectType access until after dart:core resynthesizing. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Tweaks for review comments. Created 4 years, 12 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.src.summary.summary_sdk;
6
7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/dart/element/type.dart';
10 import 'package:analyzer/src/generated/constant.dart';
11 import 'package:analyzer/src/generated/resolver.dart';
12
13 /**
14 * Implementation of [TypeProvider] which can be initialized separately with
15 * `dart:core` and `dart:async` libraries.
16 */
17 class SummaryTypeProvider implements TypeProvider {
18 bool _isCoreInitialized = false;
19 bool _isAsyncInitialized = false;
20
21 InterfaceType _boolType;
22 InterfaceType _deprecatedType;
23 InterfaceType _doubleType;
24 InterfaceType _functionType;
25 InterfaceType _futureDynamicType;
26 InterfaceType _futureNullType;
27 InterfaceType _futureType;
28 InterfaceType _intType;
29 InterfaceType _iterableDynamicType;
30 InterfaceType _iterableType;
31 InterfaceType _listType;
32 InterfaceType _mapType;
33 DartObjectImpl _nullObject;
34 InterfaceType _nullType;
35 InterfaceType _numType;
36 InterfaceType _objectType;
37 InterfaceType _stackTraceType;
38 InterfaceType _streamDynamicType;
39 InterfaceType _streamType;
40 InterfaceType _stringType;
41 InterfaceType _symbolType;
42 InterfaceType _typeType;
43
44 @override
45 InterfaceType get boolType {
46 assert(_isCoreInitialized);
47 return _boolType;
48 }
49
50 @override
51 DartType get bottomType => BottomTypeImpl.instance;
52
53 @override
54 InterfaceType get deprecatedType {
55 assert(_isCoreInitialized);
56 return _deprecatedType;
57 }
58
59 @override
60 InterfaceType get doubleType {
61 assert(_isCoreInitialized);
62 return _doubleType;
63 }
64
65 @override
66 DartType get dynamicType => DynamicTypeImpl.instance;
67
68 @override
69 InterfaceType get functionType {
70 assert(_isCoreInitialized);
71 return _functionType;
72 }
73
74 @override
75 InterfaceType get futureDynamicType {
76 assert(_isAsyncInitialized);
77 return _futureDynamicType;
78 }
79
80 @override
81 InterfaceType get futureNullType {
82 assert(_isAsyncInitialized);
83 return _futureNullType;
84 }
85
86 @override
87 InterfaceType get futureType {
88 assert(_isAsyncInitialized);
89 return _futureType;
90 }
91
92 @override
93 InterfaceType get intType {
94 assert(_isCoreInitialized);
95 return _intType;
96 }
97
98 @override
99 InterfaceType get iterableDynamicType {
100 assert(_isCoreInitialized);
101 return _iterableDynamicType;
102 }
103
104 @override
105 InterfaceType get iterableType {
106 assert(_isCoreInitialized);
107 return _iterableType;
108 }
109
110 @override
111 InterfaceType get listType {
112 assert(_isCoreInitialized);
113 return _listType;
114 }
115
116 @override
117 InterfaceType get mapType {
118 assert(_isCoreInitialized);
119 return _mapType;
120 }
121
122 @override
123 List<InterfaceType> get nonSubtypableTypes => <InterfaceType>[
124 nullType,
125 numType,
126 intType,
127 doubleType,
128 boolType,
129 stringType
130 ];
131
132 @override
133 DartObjectImpl get nullObject {
134 if (_nullObject == null) {
135 _nullObject = new DartObjectImpl(nullType, NullState.NULL_STATE);
136 }
137 return _nullObject;
138 }
139
140 @override
141 InterfaceType get nullType {
142 assert(_isCoreInitialized);
143 return _nullType;
144 }
145
146 @override
147 InterfaceType get numType {
148 assert(_isCoreInitialized);
149 return _numType;
150 }
151
152 @override
153 InterfaceType get objectType {
154 assert(_isCoreInitialized);
155 return _objectType;
156 }
157
158 @override
159 InterfaceType get stackTraceType {
160 assert(_isCoreInitialized);
161 return _stackTraceType;
162 }
163
164 @override
165 InterfaceType get streamDynamicType {
166 assert(_isAsyncInitialized);
167 return _streamDynamicType;
168 }
169
170 @override
171 InterfaceType get streamType {
172 assert(_isAsyncInitialized);
173 return _streamType;
174 }
175
176 @override
177 InterfaceType get stringType {
178 assert(_isCoreInitialized);
179 return _stringType;
180 }
181
182 @override
183 InterfaceType get symbolType {
184 assert(_isCoreInitialized);
185 return _symbolType;
186 }
187
188 @override
189 InterfaceType get typeType {
190 assert(_isCoreInitialized);
191 return _typeType;
192 }
193
194 @override
195 DartType get undefinedType => UndefinedTypeImpl.instance;
196
197 /**
198 * Initialize the `dart:async` types provided by this type provider.
199 */
200 void initializeAsync(LibraryElement library) {
201 assert(_isCoreInitialized);
202 assert(!_isAsyncInitialized);
203 _isAsyncInitialized = true;
204 _futureType = _getType(library, "Future");
205 _streamType = _getType(library, "Stream");
206 _futureDynamicType = _futureType.substitute4(<DartType>[dynamicType]);
207 _futureNullType = _futureType.substitute4(<DartType>[_nullType]);
208 _streamDynamicType = _streamType.substitute4(<DartType>[dynamicType]);
209 }
210
211 /**
212 * Initialize the `dart:core` types provided by this type provider.
213 */
214 void initializeCore(LibraryElement library) {
215 assert(!_isCoreInitialized);
216 assert(!_isAsyncInitialized);
217 _isCoreInitialized = true;
218 _boolType = _getType(library, "bool");
219 _deprecatedType = _getType(library, "Deprecated");
220 _doubleType = _getType(library, "double");
221 _functionType = _getType(library, "Function");
222 _intType = _getType(library, "int");
223 _iterableType = _getType(library, "Iterable");
224 _listType = _getType(library, "List");
225 _mapType = _getType(library, "Map");
226 _nullType = _getType(library, "Null");
227 _numType = _getType(library, "num");
228 _objectType = _getType(library, "Object");
229 _stackTraceType = _getType(library, "StackTrace");
230 _stringType = _getType(library, "String");
231 _symbolType = _getType(library, "Symbol");
232 _typeType = _getType(library, "Type");
233 _iterableDynamicType = _iterableType.substitute4(<DartType>[dynamicType]);
234 }
235
236 /**
237 * Return the type with the given [name] from the given [library], or
238 * throw a [StateError] if there is no class with the given name.
239 */
240 InterfaceType _getType(LibraryElement library, String name) {
241 Element element = library.getType(name);
242 if (element == null) {
243 throw new StateError("No definition of type $name");
244 }
245 return (element as ClassElement).type;
246 }
247 }
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