| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Properties that result from Strong Mode analysis on an AST. | 5 /// Properties that result from Strong Mode analysis on an AST. |
| 6 /// | 6 /// |
| 7 /// These properties are not public, but provided by use of back-ends such as | 7 /// These properties are not public, but provided by use of back-ends such as |
| 8 /// Dart Dev Compiler. | 8 /// Dart Dev Compiler. |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 11 import 'package:analyzer/dart/element/type.dart'; |
| 11 | 12 |
| 12 const String _hasImplicitCasts = '_hasImplicitCasts'; | 13 const String _hasImplicitCasts = '_hasImplicitCasts'; |
| 13 const String _implicitAssignmentCast = '_implicitAssignmentCast'; | 14 const String _implicitOperationCast = '_implicitAssignmentCast'; |
| 14 const String _implicitCast = '_implicitCast'; | 15 const String _implicitCast = '_implicitCast'; |
| 15 const String _isDynamicInvoke = '_isDynamicInvoke'; | 16 const String _isDynamicInvoke = '_isDynamicInvoke'; |
| 17 const String _classCovariantParameters = '_classCovariantParameters'; |
| 18 const String _superclassCovariantParameters = '_superclassCovariantParameters'; |
| 19 const String _covariantGenericReturn = '_covariantGenericReturn'; |
| 20 const String _covariantPrivateFields = '_covariantPrivateFields'; |
| 21 const String _covariantPrivateMembers = '_covariantPrivateMembers'; |
| 16 | 22 |
| 17 /// If this op-assign has an implicit cast on the assignment, returns the type | 23 /// If this expression needs an implicit cast on a subexpression that cannot be |
| 18 /// it is coerced to, otherwise returns null. | 24 /// expressed anywhere else, returns the type it is coerced to. |
| 19 DartType getImplicitAssignmentCast(Expression node) { | 25 /// |
| 20 return node.getProperty/*<DartType>*/(_implicitAssignmentCast); | 26 /// For example, op-assign can have an implicit cast on the final assignment, |
| 27 /// and MethodInvocation calls on functions (`obj.f()` where `obj.f` is an |
| 28 /// accessor and not a real method) can need a cast on the function. |
| 29 DartType getImplicitOperationCast(Expression node) { |
| 30 return node.getProperty/*<DartType>*/(_implicitOperationCast); |
| 21 } | 31 } |
| 22 | 32 |
| 23 /// If this expression has an implicit cast, returns the type it is coerced to, | 33 /// If this expression has an implicit cast, returns the type it is coerced to, |
| 24 /// otherwise returns null. | 34 /// otherwise returns null. |
| 25 DartType getImplicitCast(Expression node) { | 35 DartType getImplicitCast(Expression node) { |
| 26 return node.getProperty/*<DartType>*/(_implicitCast); | 36 return node.getProperty/*<DartType>*/(_implicitCast); |
| 27 } | 37 } |
| 28 | 38 |
| 29 /// True if this compilation unit has any implicit casts, otherwise false. | 39 /// True if this compilation unit has any implicit casts, otherwise false. |
| 30 /// | 40 /// |
| 31 /// See also [getImplicitCast]. | 41 /// See also [getImplicitCast]. |
| 32 bool hasImplicitCasts(CompilationUnit node) { | 42 bool hasImplicitCasts(CompilationUnit node) { |
| 33 return node.getProperty/*<bool>*/(_hasImplicitCasts) ?? false; | 43 return node.getProperty/*<bool>*/(_hasImplicitCasts) ?? false; |
| 34 } | 44 } |
| 35 | 45 |
| 36 /// True if this node is a dynamic operation that requires dispatch and/or | 46 /// True if this node is a dynamic operation that requires dispatch and/or |
| 37 /// checking at runtime. | 47 /// checking at runtime. |
| 38 bool isDynamicInvoke(Expression node) { | 48 bool isDynamicInvoke(Expression node) { |
| 39 return node.getProperty/*<bool>*/(_isDynamicInvoke) ?? false; | 49 return node.getProperty/*<bool>*/(_isDynamicInvoke) ?? false; |
| 40 } | 50 } |
| 41 | 51 |
| 42 /// Sets [hasImplicitCasts] property for this compilation unit. | 52 /// Sets [hasImplicitCasts] property for this compilation unit. |
| 43 void setHasImplicitCasts(CompilationUnit node, bool value) { | 53 void setHasImplicitCasts(CompilationUnit node, bool value) { |
| 44 node.setProperty(_hasImplicitCasts, value == true ? true : null); | 54 node.setProperty(_hasImplicitCasts, value == true ? true : null); |
| 45 } | 55 } |
| 46 | 56 |
| 47 /// Sets the result of [getImplicitAssignmentCast] for this node. | 57 /// Sets the result of [getImplicitOperationCast] for this node. |
| 48 void setImplicitAssignmentCast(Expression node, DartType type) { | 58 void setImplicitOperationCast(Expression node, DartType type) { |
| 49 node.setProperty(_implicitAssignmentCast, type); | 59 node.setProperty(_implicitOperationCast, type); |
| 50 } | 60 } |
| 51 | 61 |
| 52 /// Sets the result of [getImplicitCast] for this node. | 62 /// Sets the result of [getImplicitCast] for this node. |
| 53 void setImplicitCast(Expression node, DartType type) { | 63 void setImplicitCast(Expression node, DartType type) { |
| 54 node.setProperty(_implicitCast, type); | 64 node.setProperty(_implicitCast, type); |
| 55 } | 65 } |
| 56 | 66 |
| 57 /// Sets [isDynamicInvoke] property for this expression | 67 /// Sets [isDynamicInvoke] property for this expression. |
| 58 void setIsDynamicInvoke(Expression node, bool value) { | 68 void setIsDynamicInvoke(Expression node, bool value) { |
| 59 node.setProperty(_isDynamicInvoke, value == true ? true : null); | 69 node.setProperty(_isDynamicInvoke, value == true ? true : null); |
| 60 } | 70 } |
| 71 |
| 72 /// Returns a list of parameters and method type parameters in this class |
| 73 /// declaration that need a check at runtime to ensure soundness. |
| 74 Set<Element> getClassCovariantParameters(Declaration node) { |
| 75 return node.getProperty(_classCovariantParameters); |
| 76 } |
| 77 |
| 78 /// Sets [getClassCovariantParameters] property for this class. |
| 79 void setClassCovariantParameters(Declaration node, Set<Element> value) { |
| 80 node.setProperty(_classCovariantParameters, value); |
| 81 } |
| 82 |
| 83 /// Returns a list of parameters and method type parameters from mixins and |
| 84 /// superclasses of this class that need a stub method to check their type at |
| 85 /// runtime for soundness. |
| 86 Set<Element> getSuperclassCovariantParameters(Declaration node) { |
| 87 return node.getProperty(_superclassCovariantParameters); |
| 88 } |
| 89 |
| 90 /// Sets [getSuperclassCovariantParameters] property for this class. |
| 91 void setSuperclassCovariantParameters(Declaration node, Set<Element> value) { |
| 92 node.setProperty(_superclassCovariantParameters, value); |
| 93 } |
| 94 |
| 95 /// Gets the private setters and methods that are accessed unsafely from |
| 96 /// this compilation unit. |
| 97 /// |
| 98 /// These members will require a check. |
| 99 Set<ExecutableElement> getCovariantPrivateMembers(CompilationUnit node) { |
| 100 return node.getProperty(_covariantPrivateMembers); |
| 101 } |
| 102 |
| 103 /// Sets [getCovariantPrivateMembers] property for this compilation unit. |
| 104 void setCovariantPrivateMembers( |
| 105 CompilationUnit node, Set<ExecutableElement> value) { |
| 106 node.setProperty(_covariantPrivateMembers, value); |
| 107 } |
| OLD | NEW |