OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.ir_nodes; | 4 library dart2js.ir_nodes; |
5 | 5 |
6 import '../constants/expressions.dart'; | 6 import '../constants/expressions.dart'; |
7 import '../constants/values.dart' as values show ConstantValue; | 7 import '../constants/values.dart' as values show ConstantValue; |
8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../io/source_information.dart' show SourceInformation; | 10 import '../io/source_information.dart' show SourceInformation; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 List<Primitive> args, | 357 List<Primitive> args, |
358 Continuation cont) | 358 Continuation cont) |
359 : arguments = _referenceList(args), | 359 : arguments = _referenceList(args), |
360 continuation = new Reference<Continuation>(cont); | 360 continuation = new Reference<Continuation>(cont); |
361 | 361 |
362 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); | 362 accept(Visitor visitor) => visitor.visitInvokeConstructor(this); |
363 } | 363 } |
364 | 364 |
365 /// An "is" type test. | 365 /// An "is" type test. |
366 /// | 366 /// |
367 /// Returns `true` if [value] not `null` and is an instance of [type]. | 367 /// Returns `true` if [value] is an instance of [type]. |
368 /// | 368 /// |
369 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might | 369 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might |
370 /// be a type variable containing one of these types). This design is chosen | 370 /// be a type variable containing one of these types). This design is chosen |
371 /// to simplify code generation for type tests. | 371 /// to simplify code generation for type tests. |
372 class TypeTest extends Primitive { | 372 class TypeTest extends Primitive { |
373 Reference<Primitive> value; | 373 Reference<Primitive> value; |
374 final DartType type; | 374 final DartType type; |
375 | 375 |
376 /// If [type] is an [InterfaceType], this holds the internal representation of | 376 /// If [type] is an [InterfaceType], this holds the internal representation of |
377 /// the type arguments to [type]. Since these may reference type variables | 377 /// the type arguments to [type]. Since these may reference type variables |
378 /// from the enclosing class, they are not constant. | 378 /// from the enclosing class, they are not constant. |
379 /// | 379 /// |
380 /// If [type] is a [TypeVariableType], this is a singleton list with | 380 /// If [type] is a [TypeVariableType], this is a singleton list with |
381 /// the internal representation of the type held in that type variable. | 381 /// the internal representation of the type held in that type variable. |
382 /// | 382 /// |
| 383 /// If [type] is a [FunctionType], this is a singleton list with the |
| 384 /// internal representation of that type, |
| 385 /// |
383 /// Otherwise the list is empty. | 386 /// Otherwise the list is empty. |
384 final List<Reference<Primitive>> typeArguments; | 387 final List<Reference<Primitive>> typeArguments; |
385 | 388 |
386 TypeTest(Primitive value, | 389 TypeTest(Primitive value, |
387 this.type, | 390 this.type, |
388 List<Primitive> typeArguments) | 391 List<Primitive> typeArguments) |
389 : this.value = new Reference<Primitive>(value), | 392 : this.value = new Reference<Primitive>(value), |
390 this.typeArguments = _referenceList(typeArguments); | 393 this.typeArguments = _referenceList(typeArguments); |
391 | 394 |
392 accept(Visitor visitor) => visitor.visitTypeTest(this); | 395 accept(Visitor visitor) => visitor.visitTypeTest(this); |
393 } | 396 } |
394 | 397 |
395 /// An "as" type cast. | 398 /// An "as" type cast. |
396 /// | 399 /// |
397 /// If [value] is `null` or is an instance of [type], [continuation] is invoked | 400 /// If [value] is `null` or is an instance of [type], [continuation] is invoked |
398 /// with [value] as argument. Otherwise, a [CastError] is thrown. | 401 /// with [value] as argument. Otherwise, a [CastError] is thrown. |
399 /// | 402 /// |
400 /// Discussion: | 403 /// Discussion: |
401 /// The parameter to [continuation] is redundant since it will always equal | 404 /// The parameter to [continuation] is redundant since it will always equal |
402 /// [value], which is typically in scope in the continuation. However, it might | 405 /// [value], which is typically in scope in the continuation. However, it might |
403 /// simplify type propagation, since a better type can be computed for the | 406 /// simplify type propagation, since a better type can be computed for the |
404 /// continuation parameter without needing flow-sensitive analysis. | 407 /// continuation parameter without needing flow-sensitive analysis. |
405 class TypeCast extends Expression { | 408 class TypeCast extends Expression { |
406 Reference<Primitive> value; | 409 Reference<Primitive> value; |
407 final DartType type; | 410 final DartType type; |
408 | 411 |
409 /// If [type] is an [InterfaceType], this holds the internal representation of | 412 /// See the corresponding field on [TypeTest]. |
410 /// the type arguments to [type]. Since these may reference type variables | |
411 /// from the enclosing class, they are not constant. | |
412 /// | |
413 /// If [type] is a [TypeVariableType], this is a singleton list with | |
414 /// the internal representation of the type held in that type variable. | |
415 /// | |
416 /// Otherwise the list is empty. | |
417 final List<Reference<Primitive>> typeArguments; | 413 final List<Reference<Primitive>> typeArguments; |
418 final Reference<Continuation> continuation; | 414 final Reference<Continuation> continuation; |
419 | 415 |
420 TypeCast(Primitive value, | 416 TypeCast(Primitive value, |
421 this.type, | 417 this.type, |
422 List<Primitive> typeArguments, | 418 List<Primitive> typeArguments, |
423 Continuation cont) | 419 Continuation cont) |
424 : this.value = new Reference<Primitive>(value), | 420 : this.value = new Reference<Primitive>(value), |
425 this.typeArguments = _referenceList(typeArguments), | 421 this.typeArguments = _referenceList(typeArguments), |
426 this.continuation = new Reference<Continuation>(cont); | 422 this.continuation = new Reference<Continuation>(cont); |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 const RemovalVisitor(); | 1256 const RemovalVisitor(); |
1261 | 1257 |
1262 processReference(Reference reference) { | 1258 processReference(Reference reference) { |
1263 reference.unlink(); | 1259 reference.unlink(); |
1264 } | 1260 } |
1265 | 1261 |
1266 static void remove(Node node) { | 1262 static void remove(Node node) { |
1267 (const RemovalVisitor()).visit(node); | 1263 (const RemovalVisitor()).visit(node); |
1268 } | 1264 } |
1269 } | 1265 } |
OLD | NEW |