Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: lib/src/codegen/side_effect_analysis.dart

Issue 1266483003: format with dart_style 0.2.0-rc.3 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/codegen/reify_coercions.dart ('k') | lib/src/compiler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 class ConstFieldVisitor { 95 class ConstFieldVisitor {
96 final ConstantVisitor _constantVisitor; 96 final ConstantVisitor _constantVisitor;
97 97
98 ConstFieldVisitor(TypeProvider types, CompilationUnit unit) 98 ConstFieldVisitor(TypeProvider types, CompilationUnit unit)
99 // TODO(jmesserly): support -D variables on the command line 99 // TODO(jmesserly): support -D variables on the command line
100 : _constantVisitor = new ConstantVisitor( 100 : _constantVisitor = new ConstantVisitor(
101 new ConstantEvaluationEngine(types, new DeclaredVariables()), 101 new ConstantEvaluationEngine(types, new DeclaredVariables()),
102 new ErrorReporter(new RecordingErrorListener(), unit.element.source)); 102 new ErrorReporter(
103 new RecordingErrorListener(), unit.element.source));
103 104
104 // TODO(jmesserly): this is used to determine if the field initialization is 105 // TODO(jmesserly): this is used to determine if the field initialization is
105 // side effect free. We should make the check more general, as things like 106 // side effect free. We should make the check more general, as things like
106 // list/map literals/regexp are also side effect free and fairly common 107 // list/map literals/regexp are also side effect free and fairly common
107 // to use as field initializers. 108 // to use as field initializers.
108 bool isFieldInitConstant(VariableDeclaration field) => 109 bool isFieldInitConstant(VariableDeclaration field) =>
109 field.initializer == null || computeConstant(field) != null; 110 field.initializer == null || computeConstant(field) != null;
110 111
111 DartObjectImpl computeConstant(VariableDeclaration field) { 112 DartObjectImpl computeConstant(VariableDeclaration field) {
112 // If the constant is already computed by ConstantEvaluator, just return it. 113 // If the constant is already computed by ConstantEvaluator, just return it.
113 VariableElementImpl element = field.element; 114 VariableElementImpl element = field.element;
114 var result = element.evaluationResult; 115 var result = element.evaluationResult;
115 if (result != null) return result.value; 116 if (result != null) return result.value;
116 117
117 // ConstantEvaluator will not compute constants for non-const fields, 118 // ConstantEvaluator will not compute constants for non-const fields,
118 // so run ConstantVisitor for those to figure out if the initializer is 119 // so run ConstantVisitor for those to figure out if the initializer is
119 // actually a constant (and therefore side effect free to evaluate). 120 // actually a constant (and therefore side effect free to evaluate).
120 assert(!field.isConst); 121 assert(!field.isConst);
121 122
122 var initializer = field.initializer; 123 var initializer = field.initializer;
123 if (initializer == null) return null; 124 if (initializer == null) return null;
124 return initializer.accept(_constantVisitor); 125 return initializer.accept(_constantVisitor);
125 } 126 }
126 } 127 }
OLDNEW
« no previous file with comments | « lib/src/codegen/reify_coercions.dart ('k') | lib/src/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698