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; | |
6 | |
7 import 'package:analyzer/src/generated/ast.dart'; | 5 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/constant.dart'; | 6 import 'package:analyzer/src/generated/constant.dart'; |
9 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
10 import 'package:analyzer/src/generated/error.dart' show ErrorReporter; | 8 import 'package:analyzer/src/generated/error.dart' show ErrorReporter; |
11 import 'package:analyzer/src/generated/engine.dart' show RecordingErrorListener; | 9 import 'package:analyzer/src/generated/engine.dart' show RecordingErrorListener; |
12 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; | 10 import 'package:analyzer/src/generated/resolver.dart' show TypeProvider; |
13 | 11 |
14 /// True is the expression can be evaluated multiple times without causing | 12 /// True is the expression can be evaluated multiple times without causing |
15 /// code execution. This is true for final fields. This can be true for local | 13 /// code execution. This is true for final fields. This can be true for local |
16 /// variables, if: | 14 /// variables, if: |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // ConstantEvaluator will not compute constants for non-const fields, | 120 // ConstantEvaluator will not compute constants for non-const fields, |
123 // so run ConstantVisitor for those to figure out if the initializer is | 121 // so run ConstantVisitor for those to figure out if the initializer is |
124 // actually a constant (and therefore side effect free to evaluate). | 122 // actually a constant (and therefore side effect free to evaluate). |
125 assert(!field.isConst); | 123 assert(!field.isConst); |
126 | 124 |
127 var initializer = field.initializer; | 125 var initializer = field.initializer; |
128 if (initializer == null) return null; | 126 if (initializer == null) return null; |
129 return initializer.accept(_constantVisitor); | 127 return initializer.accept(_constantVisitor); |
130 } | 128 } |
131 } | 129 } |
OLD | NEW |