OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of native; | 5 part of native; |
6 | 6 |
7 /// This class is a temporary work-around until we get a more powerful DartType. | 7 /// This class is a temporary work-around until we get a more powerful DartType. |
8 class SpecialType { | 8 class SpecialType { |
9 final String name; | 9 final String name; |
10 const SpecialType._(this.name); | 10 const SpecialType._(this.name); |
(...skipping 13 matching lines...) Expand all Loading... | |
24 static const NativeThrowBehavior MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS = | 24 static const NativeThrowBehavior MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS = |
25 const NativeThrowBehavior._(1); | 25 const NativeThrowBehavior._(1); |
26 static const NativeThrowBehavior MAY = const NativeThrowBehavior._(2); | 26 static const NativeThrowBehavior MAY = const NativeThrowBehavior._(2); |
27 static const NativeThrowBehavior MUST = const NativeThrowBehavior._(3); | 27 static const NativeThrowBehavior MUST = const NativeThrowBehavior._(3); |
28 | 28 |
29 final int _bits; | 29 final int _bits; |
30 const NativeThrowBehavior._(this._bits); | 30 const NativeThrowBehavior._(this._bits); |
31 | 31 |
32 bool get canThrow => this != NEVER; | 32 bool get canThrow => this != NEVER; |
33 | 33 |
34 /// Does this behavior always throw a noSuchMethod check on a null first | |
35 /// argument before any side effect or other exception? | |
36 // TODO(sra): Extend NativeThrowBehavior with the concept of NSM guard | |
37 // followed by other potential behavior. | |
38 bool get isNullNSMGuard => this == MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS; | |
39 | |
40 /// Does this behavior always act as a null noSuchMethod check, and has no | |
41 /// other throwing behavior? | |
42 bool get onlyNullNSMGuard => this == MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS; | |
floitsch
2015/04/13 08:07:14
nit: isOnlyNullNSMGuard
sra1
2015/04/13 23:59:05
Done.
| |
43 | |
44 /// Returns the behavior if we assume the first argument is not null. | |
45 NativeThrowBehavior get onNonNull { | |
46 if (this == MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS) return NEVER; | |
47 return this; | |
48 } | |
49 | |
34 String toString() { | 50 String toString() { |
35 if (this == NEVER) return 'never'; | 51 if (this == NEVER) return 'never'; |
36 if (this == MAY) return 'may'; | 52 if (this == MAY) return 'may'; |
37 if (this == MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS) return 'null(1)'; | 53 if (this == MAY_THROW_ONLY_ON_FIRST_ARGUMENT_ACCESS) return 'null(1)'; |
38 if (this == MUST) return 'must'; | 54 if (this == MUST) return 'must'; |
39 return 'NativeThrowBehavior($_bits)'; | 55 return 'NativeThrowBehavior($_bits)'; |
40 } | 56 } |
41 } | 57 } |
42 | 58 |
43 /** | 59 /** |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
719 MessageKind.GENERIC, | 735 MessageKind.GENERIC, |
720 {'text': "Type '$typeString' not found."}); | 736 {'text': "Type '$typeString' not found."}); |
721 return const DynamicType(); | 737 return const DynamicType(); |
722 } | 738 } |
723 | 739 |
724 static _errorNode(locationNodeOrElement, compiler) { | 740 static _errorNode(locationNodeOrElement, compiler) { |
725 if (locationNodeOrElement is Node) return locationNodeOrElement; | 741 if (locationNodeOrElement is Node) return locationNodeOrElement; |
726 return locationNodeOrElement.parseNode(compiler); | 742 return locationNodeOrElement.parseNode(compiler); |
727 } | 743 } |
728 } | 744 } |
OLD | NEW |