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

Side by Side Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 2000153002: Handle constant function references. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add invariant from previous CL. Created 4 years, 7 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 | « no previous file | tests/compiler/dart2js/serialization/test_data.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.compile_time_constant_evaluator; 5 library dart2js.compile_time_constant_evaluator;
6 6
7 import 'common.dart'; 7 import 'common.dart';
8 import 'common/resolution.dart' show Resolution; 8 import 'common/resolution.dart' show Resolution;
9 import 'common/tasks.dart' show CompilerTask; 9 import 'common/tasks.dart' show CompilerTask;
10 import 'compiler.dart' show Compiler; 10 import 'compiler.dart' show Compiler;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 /// Compile [element] into a constant expression. If [isConst] is true, 182 /// Compile [element] into a constant expression. If [isConst] is true,
183 /// then [element] is a constant variable. If [checkType] is true, then 183 /// then [element] is a constant variable. If [checkType] is true, then
184 /// report an error if [element] does not typecheck. 184 /// report an error if [element] does not typecheck.
185 ConstantExpression internalCompileVariable( 185 ConstantExpression internalCompileVariable(
186 VariableElement element, bool isConst, bool checkType) { 186 VariableElement element, bool isConst, bool checkType) {
187 if (initialVariableValues.containsKey(element.declaration)) { 187 if (initialVariableValues.containsKey(element.declaration)) {
188 ConstantExpression result = initialVariableValues[element.declaration]; 188 ConstantExpression result = initialVariableValues[element.declaration];
189 return result; 189 return result;
190 } 190 }
191 if (element.hasConstant) { 191 if (element.hasConstant) {
192 if (element.constant != null && 192 if (element.constant != null) {
193 compiler.serialization.supportsDeserialization) { 193 if (compiler.serialization.supportsDeserialization) {
194 evaluate(element.constant); 194 evaluate(element.constant);
195 }
196 assert(invariant(element, hasConstantValue(element.constant),
197 message: "Constant expression has not been evaluated: "
198 "${element.constant.toStructuredText()}."));
195 } 199 }
196 return element.constant; 200 return element.constant;
197 } 201 }
198 AstElement currentElement = element.analyzableElement; 202 AstElement currentElement = element.analyzableElement;
199 return reporter.withCurrentElement(element, () { 203 return reporter.withCurrentElement(element, () {
200 // TODO(johnniwinther): Avoid this eager analysis. 204 // TODO(johnniwinther): Avoid this eager analysis.
201 compiler.resolution.ensureResolved(currentElement.declaration); 205 compiler.resolution.ensureResolved(currentElement.declaration);
202 206
203 ConstantExpression constant = compileVariableWithDefinitions( 207 ConstantExpression constant = compileVariableWithDefinitions(
204 element, currentElement.resolvedAst.elements, 208 element, currentElement.resolvedAst.elements,
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 589 }
586 return signalNotCompileTimeConstant(node); 590 return signalNotCompileTimeConstant(node);
587 } 591 }
588 592
589 // TODO(floitsch): provide better error-messages. 593 // TODO(floitsch): provide better error-messages.
590 AstConstant visitSend(Send send) { 594 AstConstant visitSend(Send send) {
591 Element element = elements[send]; 595 Element element = elements[send];
592 if (send.isPropertyAccess) { 596 if (send.isPropertyAccess) {
593 AstConstant result; 597 AstConstant result;
594 if (Elements.isStaticOrTopLevelFunction(element)) { 598 if (Elements.isStaticOrTopLevelFunction(element)) {
595 FunctionElementX function = element; 599 FunctionElement function = element;
596 function.computeType(resolution); 600 function.computeType(resolution);
597 result = new AstConstant( 601 result = new AstConstant(
598 context, 602 context,
599 send, 603 send,
600 new FunctionConstantExpression(function), 604 new FunctionConstantExpression(function),
601 new FunctionConstantValue(function)); 605 new FunctionConstantValue(function));
602 } else if (Elements.isStaticOrTopLevelField(element)) { 606 } else if (Elements.isStaticOrTopLevelField(element)) {
603 ConstantExpression elementExpression; 607 ConstantExpression elementExpression;
604 if (element.isConst) { 608 if (element.isConst) {
605 elementExpression = handler.compileConstant(element); 609 elementExpression = handler.compileConstant(element);
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 class _CompilerEnvironment implements Environment { 1355 class _CompilerEnvironment implements Environment {
1352 final Compiler compiler; 1356 final Compiler compiler;
1353 1357
1354 _CompilerEnvironment(this.compiler); 1358 _CompilerEnvironment(this.compiler);
1355 1359
1356 @override 1360 @override
1357 String readFromEnvironment(String name) { 1361 String readFromEnvironment(String name) {
1358 return compiler.fromEnvironment(name); 1362 return compiler.fromEnvironment(name);
1359 } 1363 }
1360 } 1364 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/serialization/test_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698