| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 library dev_compiler.src.codegen.side_effect_analysis; | 5 library dev_compiler.src.codegen.side_effect_analysis; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/constant.dart'; | 8 import 'package:analyzer/src/generated/constant.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; | 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart' show ErrorReporter; | 10 import 'package:analyzer/src/generated/error.dart' show ErrorReporter; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 /// | 29 /// |
| 30 /// This method is conservative: it should never return `true` unless it is | 30 /// This method is conservative: it should never return `true` unless it is |
| 31 /// certain the [node] is stateless, because generated code may rely on the | 31 /// certain the [node] is stateless, because generated code may rely on the |
| 32 /// correctness of a `true` value. However it may return `false` for things | 32 /// correctness of a `true` value. However it may return `false` for things |
| 33 /// that are in fact, stateless. | 33 /// that are in fact, stateless. |
| 34 bool isStateless(Expression node, [AstNode context]) { | 34 bool isStateless(Expression node, [AstNode context]) { |
| 35 // `this` and `super` cannot be reassigned. | 35 // `this` and `super` cannot be reassigned. |
| 36 if (node is ThisExpression || node is SuperExpression) return true; | 36 if (node is ThisExpression || node is SuperExpression) return true; |
| 37 if (node is SimpleIdentifier) { | 37 if (node is SimpleIdentifier) { |
| 38 var e = node.staticElement; | 38 var e = node.staticElement; |
| 39 if (e is PropertyAccessorElement) e = e.variable; | 39 if (e is PropertyAccessorElement) e = |
| 40 (e as PropertyAccessorElement).variable; |
| 40 if (e is VariableElement && !e.isSynthetic) { | 41 if (e is VariableElement && !e.isSynthetic) { |
| 41 if (e.isFinal) return true; | 42 if (e.isFinal) return true; |
| 42 if (e is LocalVariableElement || e is ParameterElement) { | 43 if (e is LocalVariableElement || e is ParameterElement) { |
| 43 // make sure the local isn't mutated in the context. | 44 // make sure the local isn't mutated in the context. |
| 44 return !_isPotentiallyMutated(e, context); | 45 return !_isPotentiallyMutated(e, context); |
| 45 } | 46 } |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 return false; | 49 return false; |
| 49 } | 50 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // ConstantEvaluator will not compute constants for non-const fields, | 115 // ConstantEvaluator will not compute constants for non-const fields, |
| 115 // so run ConstantVisitor for those to figure out if the initializer is | 116 // so run ConstantVisitor for those to figure out if the initializer is |
| 116 // actually a constant (and therefore side effect free to evaluate). | 117 // actually a constant (and therefore side effect free to evaluate). |
| 117 assert(!field.isConst); | 118 assert(!field.isConst); |
| 118 | 119 |
| 119 var initializer = field.initializer; | 120 var initializer = field.initializer; |
| 120 if (initializer == null) return null; | 121 if (initializer == null) return null; |
| 121 return initializer.accept(_constantVisitor); | 122 return initializer.accept(_constantVisitor); |
| 122 } | 123 } |
| 123 } | 124 } |
| OLD | NEW |