| 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/visitor.dart'; | 6 import 'package:analyzer/dart/ast/visitor.dart'; |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/constant.dart'; | 8 import 'package:analyzer/src/generated/constant.dart'; |
| 9 import 'package:analyzer/error/listener.dart' | 9 import 'package:analyzer/error/listener.dart' |
| 10 show AnalysisErrorListener, ErrorReporter; | 10 show AnalysisErrorListener, ErrorReporter; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart' show Source; | 12 import 'package:analyzer/src/generated/source.dart' show Source; |
| 13 import 'package:analyzer/src/dart/ast/ast.dart'; | 13 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 14 | 14 |
| 15 /// True is the expression can be evaluated multiple times without causing | 15 /// True is the expression can be evaluated multiple times without causing |
| 16 /// code execution. This is true for final fields. This can be true for local | 16 /// code execution. This is true for final fields. This can be true for local |
| 17 /// variables, if: | 17 /// variables, if: |
| 18 /// * they are not assigned within the [context]. | |
| 19 /// * they are not assigned in a function closure anywhere. | |
| 20 /// True is the expression can be evaluated multiple times without causing | |
| 21 /// code execution. This is true for final fields. This can be true for local | |
| 22 /// variables, if: | |
| 23 /// | 18 /// |
| 24 /// * they are not assigned within the [context] scope. | 19 /// * they are not assigned within the [context] scope. |
| 25 /// * they are not assigned in a function closure anywhere. | 20 /// * they are not assigned in a function closure anywhere. |
| 26 /// | 21 /// |
| 27 /// This method is used to avoid creating temporaries in cases where we know | 22 /// This method is used to avoid creating temporaries in cases where we know |
| 28 /// we can safely re-evaluate [node] multiple times in [context]. This lets | 23 /// we can safely re-evaluate [node] multiple times in [context]. This lets |
| 29 /// us generate prettier code. | 24 /// us generate prettier code. |
| 30 /// | 25 /// |
| 31 /// This method is conservative: it should never return `true` unless it is | 26 /// This method is conservative: it should never return `true` unless it is |
| 32 /// certain the [node] is stateless, because generated code may rely on the | 27 /// certain the [node] is stateless, because generated code may rely on the |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // ConstantEvaluator will not compute constants for non-const fields, | 125 // ConstantEvaluator will not compute constants for non-const fields, |
| 131 // so run ConstantVisitor for those to figure out if the initializer is | 126 // so run ConstantVisitor for those to figure out if the initializer is |
| 132 // actually a constant (and therefore side effect free to evaluate). | 127 // actually a constant (and therefore side effect free to evaluate). |
| 133 assert(!field.isConst); | 128 assert(!field.isConst); |
| 134 | 129 |
| 135 var initializer = field.initializer; | 130 var initializer = field.initializer; |
| 136 if (initializer == null) return null; | 131 if (initializer == null) return null; |
| 137 return initializer.accept(constantVisitor); | 132 return initializer.accept(constantVisitor); |
| 138 } | 133 } |
| 139 } | 134 } |
| OLD | NEW |