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

Side by Side Diff: pkg/compiler/lib/src/universe/use.dart

Issue 2900263002: Use failedAt in more places (constants, universe) (Closed)
Patch Set: Created 3 years, 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// This library defines individual world impacts. 5 /// This library defines individual world impacts.
6 /// 6 ///
7 /// We call these building blocks `uses`. Each `use` is a single impact of the 7 /// We call these building blocks `uses`. Each `use` is a single impact of the
8 /// world. Some example uses are: 8 /// world. Some example uses are:
9 /// 9 ///
10 /// * an invocation of a top level function 10 /// * an invocation of a top level function
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 final Entity element; 92 final Entity element;
93 final StaticUseKind kind; 93 final StaticUseKind kind;
94 final int hashCode; 94 final int hashCode;
95 final DartType type; 95 final DartType type;
96 96
97 StaticUse.internal(Entity element, StaticUseKind kind, [DartType type = null]) 97 StaticUse.internal(Entity element, StaticUseKind kind, [DartType type = null])
98 : this.element = element, 98 : this.element = element,
99 this.kind = kind, 99 this.kind = kind,
100 this.type = type, 100 this.type = type,
101 this.hashCode = Hashing.objectsHash(element, kind, type) { 101 this.hashCode = Hashing.objectsHash(element, kind, type) {
102 assert(invariant(element, !(element is Element && !element.isDeclaration), 102 assert(
103 message: "Static use element $element must be " 103 !(element is Element && !element.isDeclaration),
104 "the declaration element.")); 104 failedAt(element,
105 "Static use element $element must be the declaration element."));
105 } 106 }
106 107
107 /// Invocation of a static or top-level [element] with the given 108 /// Invocation of a static or top-level [element] with the given
108 /// [callStructure]. 109 /// [callStructure].
109 factory StaticUse.staticInvoke( 110 factory StaticUse.staticInvoke(
110 FunctionEntity element, CallStructure callStructure) { 111 FunctionEntity element, CallStructure callStructure) {
111 // TODO(johnniwinther): Use the [callStructure]. 112 // TODO(johnniwinther): Use the [callStructure].
112 assert(invariant(element, element.isStatic || element.isTopLevel, 113 assert(
113 message: "Static invoke element $element must be a top-level " 114 element.isStatic || element.isTopLevel,
115 failedAt(
116 element,
117 "Static invoke element $element must be a top-level "
114 "or static method.")); 118 "or static method."));
115 return new StaticUse.internal(element, StaticUseKind.GENERAL); 119 return new StaticUse.internal(element, StaticUseKind.GENERAL);
116 } 120 }
117 121
118 /// Closurization of a static or top-level function [element]. 122 /// Closurization of a static or top-level function [element].
119 factory StaticUse.staticTearOff(FunctionEntity element) { 123 factory StaticUse.staticTearOff(FunctionEntity element) {
120 assert(invariant(element, element.isStatic || element.isTopLevel, 124 assert(
121 message: "Static tear-off element $element must be a top-level " 125 element.isStatic || element.isTopLevel,
126 failedAt(
127 element,
128 "Static tear-off element $element must be a top-level "
122 "or static method.")); 129 "or static method."));
123 return new StaticUse.internal(element, StaticUseKind.STATIC_TEAR_OFF); 130 return new StaticUse.internal(element, StaticUseKind.STATIC_TEAR_OFF);
124 } 131 }
125 132
126 /// Read access of a static or top-level field or getter [element]. 133 /// Read access of a static or top-level field or getter [element].
127 factory StaticUse.staticGet(MemberEntity element) { 134 factory StaticUse.staticGet(MemberEntity element) {
128 assert(invariant(element, element.isStatic || element.isTopLevel, 135 assert(
129 message: "Static get element $element must be a top-level " 136 element.isStatic || element.isTopLevel,
137 failedAt(
138 element,
139 "Static get element $element must be a top-level "
130 "or static method.")); 140 "or static method."));
131 assert(invariant(element, element.isField || element.isGetter, 141 assert(
132 message: "Static get element $element must be a field or a getter.")); 142 element.isField || element.isGetter,
143 failedAt(element,
144 "Static get element $element must be a field or a getter."));
133 return new StaticUse.internal(element, StaticUseKind.GENERAL); 145 return new StaticUse.internal(element, StaticUseKind.GENERAL);
134 } 146 }
135 147
136 /// Write access of a static or top-level field or setter [element]. 148 /// Write access of a static or top-level field or setter [element].
137 factory StaticUse.staticSet(MemberEntity element) { 149 factory StaticUse.staticSet(MemberEntity element) {
138 assert(invariant(element, element.isStatic || element.isTopLevel, 150 assert(
139 message: "Static set element $element must be a top-level " 151 element.isStatic || element.isTopLevel,
140 "or static method.")); 152 failedAt(
141 assert(invariant(element, element.isField || element.isSetter, 153 element,
142 message: "Static set element $element must be a field or a setter.")); 154 "Static set element $element "
155 "must be a top-level or static method."));
156 assert(
157 element.isField || element.isSetter,
158 failedAt(element,
159 "Static set element $element must be a field or a setter."));
143 return new StaticUse.internal(element, StaticUseKind.GENERAL); 160 return new StaticUse.internal(element, StaticUseKind.GENERAL);
144 } 161 }
145 162
146 /// Invocation of the lazy initializer for a static or top-level field 163 /// Invocation of the lazy initializer for a static or top-level field
147 /// [element]. 164 /// [element].
148 factory StaticUse.staticInit(FieldEntity element) { 165 factory StaticUse.staticInit(FieldEntity element) {
149 assert(invariant(element, element.isStatic || element.isTopLevel, 166 assert(
150 message: "Static init element $element must be a top-level " 167 element.isStatic || element.isTopLevel,
168 failedAt(
169 element,
170 "Static init element $element must be a top-level "
151 "or static method.")); 171 "or static method."));
152 assert(invariant(element, element.isField, 172 assert(element.isField,
153 message: "Static init element $element must be a field.")); 173 failedAt(element, "Static init element $element must be a field."));
154 return new StaticUse.internal(element, StaticUseKind.GENERAL); 174 return new StaticUse.internal(element, StaticUseKind.GENERAL);
155 } 175 }
156 176
157 /// Invocation of a super method [element] with the given [callStructure]. 177 /// Invocation of a super method [element] with the given [callStructure].
158 factory StaticUse.superInvoke( 178 factory StaticUse.superInvoke(
159 FunctionEntity element, CallStructure callStructure) { 179 FunctionEntity element, CallStructure callStructure) {
160 // TODO(johnniwinther): Use the [callStructure]. 180 // TODO(johnniwinther): Use the [callStructure].
161 assert(invariant(element, element.isInstanceMember, 181 assert(
162 message: "Super invoke element $element must be an instance method.")); 182 element.isInstanceMember,
183 failedAt(element,
184 "Super invoke element $element must be an instance method."));
163 return new StaticUse.internal(element, StaticUseKind.GENERAL); 185 return new StaticUse.internal(element, StaticUseKind.GENERAL);
164 } 186 }
165 187
166 /// Read access of a super field or getter [element]. 188 /// Read access of a super field or getter [element].
167 factory StaticUse.superGet(MemberEntity element) { 189 factory StaticUse.superGet(MemberEntity element) {
168 assert(invariant(element, element.isInstanceMember, 190 assert(
169 message: "Super get element $element must be an instance method.")); 191 element.isInstanceMember,
170 assert(invariant(element, element.isField || element.isGetter, 192 failedAt(
171 message: "Super get element $element must be a field or a getter.")); 193 element, "Super get element $element must be an instance method."));
194 assert(
195 element.isField || element.isGetter,
196 failedAt(element,
197 "Super get element $element must be a field or a getter."));
172 return new StaticUse.internal(element, StaticUseKind.GENERAL); 198 return new StaticUse.internal(element, StaticUseKind.GENERAL);
173 } 199 }
174 200
175 /// Write access of a super field [element]. 201 /// Write access of a super field [element].
176 factory StaticUse.superFieldSet(FieldEntity element) { 202 factory StaticUse.superFieldSet(FieldEntity element) {
177 assert(invariant(element, element.isInstanceMember, 203 assert(
178 message: "Super set element $element must be an instance method.")); 204 element.isInstanceMember,
179 assert(invariant(element, element.isField, 205 failedAt(
180 message: "Super set element $element must be a field.")); 206 element, "Super set element $element must be an instance method."));
207 assert(element.isField,
208 failedAt(element, "Super set element $element must be a field."));
181 return new StaticUse.internal(element, StaticUseKind.SUPER_FIELD_SET); 209 return new StaticUse.internal(element, StaticUseKind.SUPER_FIELD_SET);
182 } 210 }
183 211
184 /// Write access of a super setter [element]. 212 /// Write access of a super setter [element].
185 factory StaticUse.superSetterSet(FunctionEntity element) { 213 factory StaticUse.superSetterSet(FunctionEntity element) {
186 assert(invariant(element, element.isInstanceMember, 214 assert(
187 message: "Super set element $element must be an instance method.")); 215 element.isInstanceMember,
188 assert(invariant(element, element.isSetter, 216 failedAt(
189 message: "Super set element $element must be a setter.")); 217 element, "Super set element $element must be an instance method."));
218 assert(element.isSetter,
219 failedAt(element, "Super set element $element must be a setter."));
190 return new StaticUse.internal(element, StaticUseKind.GENERAL); 220 return new StaticUse.internal(element, StaticUseKind.GENERAL);
191 } 221 }
192 222
193 /// Closurization of a super method [element]. 223 /// Closurization of a super method [element].
194 factory StaticUse.superTearOff(FunctionEntity element) { 224 factory StaticUse.superTearOff(FunctionEntity element) {
195 assert(invariant(element, element.isInstanceMember && element.isFunction, 225 assert(
196 message: "Super invoke element $element must be an instance method.")); 226 element.isInstanceMember && element.isFunction,
227 failedAt(element,
228 "Super invoke element $element must be an instance method."));
197 return new StaticUse.internal(element, StaticUseKind.SUPER_TEAR_OFF); 229 return new StaticUse.internal(element, StaticUseKind.SUPER_TEAR_OFF);
198 } 230 }
199 231
200 /// Invocation of a constructor [element] through a this or super 232 /// Invocation of a constructor [element] through a this or super
201 /// constructor call with the given [callStructure]. 233 /// constructor call with the given [callStructure].
202 factory StaticUse.superConstructorInvoke( 234 factory StaticUse.superConstructorInvoke(
203 ConstructorEntity element, CallStructure callStructure) { 235 ConstructorEntity element, CallStructure callStructure) {
204 // TODO(johnniwinther): Use the [callStructure]. 236 // TODO(johnniwinther): Use the [callStructure].
205 assert(invariant(element, element.isGenerativeConstructor, 237 assert(
206 message: "Constructor invoke element $element must be a " 238 element.isGenerativeConstructor,
239 failedAt(
240 element,
241 "Constructor invoke element $element must be a "
207 "generative constructor.")); 242 "generative constructor."));
208 return new StaticUse.internal(element, StaticUseKind.GENERAL); 243 return new StaticUse.internal(element, StaticUseKind.GENERAL);
209 } 244 }
210 245
211 /// Invocation of a constructor (body) [element] through a this or super 246 /// Invocation of a constructor (body) [element] through a this or super
212 /// constructor call with the given [callStructure]. 247 /// constructor call with the given [callStructure].
213 factory StaticUse.constructorBodyInvoke( 248 factory StaticUse.constructorBodyInvoke(
214 ConstructorBodyElement element, CallStructure callStructure) { 249 ConstructorBodyElement element, CallStructure callStructure) {
215 // TODO(johnniwinther): Use the [callStructure]. 250 // TODO(johnniwinther): Use the [callStructure].
216 return new StaticUse.internal(element, StaticUseKind.GENERAL); 251 return new StaticUse.internal(element, StaticUseKind.GENERAL);
217 } 252 }
218 253
219 /// Direct invocation of a method [element] with the given [callStructure]. 254 /// Direct invocation of a method [element] with the given [callStructure].
220 factory StaticUse.directInvoke( 255 factory StaticUse.directInvoke(
221 FunctionEntity element, CallStructure callStructure) { 256 FunctionEntity element, CallStructure callStructure) {
222 // TODO(johnniwinther): Use the [callStructure]. 257 // TODO(johnniwinther): Use the [callStructure].
223 assert(invariant(element, element.isInstanceMember, 258 assert(
224 message: "Direct invoke element $element must be an instance member.")); 259 element.isInstanceMember,
225 assert(invariant(element, element.isFunction, 260 failedAt(element,
226 message: "Direct invoke element $element must be a method.")); 261 "Direct invoke element $element must be an instance member."));
262 assert(element.isFunction,
263 failedAt(element, "Direct invoke element $element must be a method."));
227 return new StaticUse.internal(element, StaticUseKind.DIRECT_INVOKE); 264 return new StaticUse.internal(element, StaticUseKind.DIRECT_INVOKE);
228 } 265 }
229 266
230 /// Direct read access of a field or getter [element]. 267 /// Direct read access of a field or getter [element].
231 factory StaticUse.directGet(MemberEntity element) { 268 factory StaticUse.directGet(MemberEntity element) {
232 assert(invariant(element, element.isInstanceMember, 269 assert(
233 message: "Direct get element $element must be an instance member.")); 270 element.isInstanceMember,
234 assert(invariant(element, element.isField || element.isGetter, 271 failedAt(element,
235 message: "Direct get element $element must be a field or a getter.")); 272 "Direct get element $element must be an instance member."));
273 assert(
274 element.isField || element.isGetter,
275 failedAt(element,
276 "Direct get element $element must be a field or a getter."));
236 return new StaticUse.internal(element, StaticUseKind.GENERAL); 277 return new StaticUse.internal(element, StaticUseKind.GENERAL);
237 } 278 }
238 279
239 /// Direct write access of a field [element]. 280 /// Direct write access of a field [element].
240 factory StaticUse.directSet(FieldEntity element) { 281 factory StaticUse.directSet(FieldEntity element) {
241 assert(invariant(element, element.isInstanceMember, 282 assert(
242 message: "Direct set element $element must be an instance member.")); 283 element.isInstanceMember,
243 assert(invariant(element, element.isField, 284 failedAt(element,
244 message: "Direct set element $element must be a field.")); 285 "Direct set element $element must be an instance member."));
286 assert(element.isField,
287 failedAt(element, "Direct set element $element must be a field."));
245 return new StaticUse.internal(element, StaticUseKind.GENERAL); 288 return new StaticUse.internal(element, StaticUseKind.GENERAL);
246 } 289 }
247 290
248 /// Constructor invocation of [element] with the given [callStructure]. 291 /// Constructor invocation of [element] with the given [callStructure].
249 factory StaticUse.constructorInvoke( 292 factory StaticUse.constructorInvoke(
250 ConstructorEntity element, CallStructure callStructure) { 293 ConstructorEntity element, CallStructure callStructure) {
251 assert(invariant(element, element.isConstructor, 294 assert(
252 message: "Constructor invocation element $element " 295 element.isConstructor,
253 "must be a constructor.")); 296 failedAt(element,
297 "Constructor invocation element $element must be a constructor."));
254 // TODO(johnniwinther): Use the [callStructure]. 298 // TODO(johnniwinther): Use the [callStructure].
255 return new StaticUse.internal(element, StaticUseKind.GENERAL); 299 return new StaticUse.internal(element, StaticUseKind.GENERAL);
256 } 300 }
257 301
258 /// Constructor invocation of [element] with the given [callStructure] on 302 /// Constructor invocation of [element] with the given [callStructure] on
259 /// [type]. 303 /// [type].
260 factory StaticUse.typedConstructorInvoke( 304 factory StaticUse.typedConstructorInvoke(
261 ConstructorEntity element, CallStructure callStructure, DartType type) { 305 ConstructorEntity element, CallStructure callStructure, DartType type) {
262 assert(invariant(element, type != null, 306 assert(type != null,
263 message: "No type provided for constructor invocation.")); 307 failedAt(element, "No type provided for constructor invocation."));
264 assert(invariant(element, element.isConstructor, 308 assert(
265 message: "Typed constructor invocation element $element " 309 element.isConstructor,
310 failedAt(
311 element,
312 "Typed constructor invocation element $element "
266 "must be a constructor.")); 313 "must be a constructor."));
267 // TODO(johnniwinther): Use the [callStructure]. 314 // TODO(johnniwinther): Use the [callStructure].
268 return new StaticUse.internal( 315 return new StaticUse.internal(
269 element, StaticUseKind.CONSTRUCTOR_INVOKE, type); 316 element, StaticUseKind.CONSTRUCTOR_INVOKE, type);
270 } 317 }
271 318
272 /// Constant constructor invocation of [element] with the given 319 /// Constant constructor invocation of [element] with the given
273 /// [callStructure] on [type]. 320 /// [callStructure] on [type].
274 factory StaticUse.constConstructorInvoke( 321 factory StaticUse.constConstructorInvoke(
275 ConstructorEntity element, CallStructure callStructure, DartType type) { 322 ConstructorEntity element, CallStructure callStructure, DartType type) {
276 assert(invariant(element, type != null, 323 assert(type != null,
277 message: "No type provided for constructor invocation.")); 324 failedAt(element, "No type provided for constructor invocation."));
278 assert(invariant(element, element.isConstructor, 325 assert(
279 message: "Const constructor invocation element $element " 326 element.isConstructor,
327 failedAt(
328 element,
329 "Const constructor invocation element $element "
280 "must be a constructor.")); 330 "must be a constructor."));
281 // TODO(johnniwinther): Use the [callStructure]. 331 // TODO(johnniwinther): Use the [callStructure].
282 return new StaticUse.internal( 332 return new StaticUse.internal(
283 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type); 333 element, StaticUseKind.CONST_CONSTRUCTOR_INVOKE, type);
284 } 334 }
285 335
286 /// Constructor redirection to [element] on [type]. 336 /// Constructor redirection to [element] on [type].
287 factory StaticUse.constructorRedirect( 337 factory StaticUse.constructorRedirect(
288 ConstructorEntity element, InterfaceType type) { 338 ConstructorEntity element, InterfaceType type) {
289 assert(invariant(element, type != null, 339 assert(type != null,
290 message: "No type provided for constructor redirection.")); 340 failedAt(element, "No type provided for constructor redirection."));
291 assert(invariant(element, element.isConstructor, 341 assert(
292 message: "Constructor redirection element $element " 342 element.isConstructor,
293 "must be a constructor.")); 343 failedAt(element,
344 "Constructor redirection element $element must be a constructor."));
294 return new StaticUse.internal(element, StaticUseKind.REDIRECTION, type); 345 return new StaticUse.internal(element, StaticUseKind.REDIRECTION, type);
295 } 346 }
296 347
297 /// Initialization of an instance field [element]. 348 /// Initialization of an instance field [element].
298 factory StaticUse.fieldInit(FieldEntity element) { 349 factory StaticUse.fieldInit(FieldEntity element) {
299 assert(invariant(element, element.isInstanceMember, 350 assert(
300 message: "Field init element $element must be an instance field.")); 351 element.isInstanceMember,
352 failedAt(
353 element, "Field init element $element must be an instance field."));
301 return new StaticUse.internal(element, StaticUseKind.GENERAL); 354 return new StaticUse.internal(element, StaticUseKind.GENERAL);
302 } 355 }
303 356
304 /// Read access of an instance field or boxed field [element]. 357 /// Read access of an instance field or boxed field [element].
305 factory StaticUse.fieldGet(FieldEntity element) { 358 factory StaticUse.fieldGet(FieldEntity element) {
306 assert(invariant( 359 assert(
307 element, element.isInstanceMember || element is BoxFieldElement, 360 element.isInstanceMember || element is BoxFieldElement,
308 message: "Field init element $element must be an instance " 361 failedAt(element,
309 "or boxed field.")); 362 "Field init element $element must be an instance or boxed field."));
310 return new StaticUse.internal(element, StaticUseKind.FIELD_GET); 363 return new StaticUse.internal(element, StaticUseKind.FIELD_GET);
311 } 364 }
312 365
313 /// Write access of an instance field or boxed field [element]. 366 /// Write access of an instance field or boxed field [element].
314 factory StaticUse.fieldSet(FieldEntity element) { 367 factory StaticUse.fieldSet(FieldEntity element) {
315 assert(invariant( 368 assert(
316 element, element.isInstanceMember || element is BoxFieldElement, 369 element.isInstanceMember || element is BoxFieldElement,
317 message: "Field init element $element must be an instance " 370 failedAt(element,
318 "or boxed field.")); 371 "Field init element $element must be an instance or boxed field."));
319 return new StaticUse.internal(element, StaticUseKind.FIELD_SET); 372 return new StaticUse.internal(element, StaticUseKind.FIELD_SET);
320 } 373 }
321 374
322 /// Read of a local function [element]. 375 /// Read of a local function [element].
323 factory StaticUse.closure(Local element) { 376 factory StaticUse.closure(Local element) {
324 return new StaticUse.internal(element, StaticUseKind.CLOSURE); 377 return new StaticUse.internal(element, StaticUseKind.CLOSURE);
325 } 378 }
326 379
327 /// Use of [element] through reflection. 380 /// Use of [element] through reflection.
328 factory StaticUse.mirrorUse(MemberEntity element) { 381 factory StaticUse.mirrorUse(MemberEntity element) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 : this._(value, ConstantUseKind.DIRECT); 520 : this._(value, ConstantUseKind.DIRECT);
468 521
469 bool operator ==(other) { 522 bool operator ==(other) {
470 if (identical(this, other)) return true; 523 if (identical(this, other)) return true;
471 if (other is! ConstantUse) return false; 524 if (other is! ConstantUse) return false;
472 return value == other.value; 525 return value == other.value;
473 } 526 }
474 527
475 String toString() => 'ConstantUse(${value.toStructuredText()},$kind)'; 528 String toString() => 'ConstantUse(${value.toStructuredText()},$kind)';
476 } 529 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698