Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 class Constant implements Hashable { | 5 class Constant implements Hashable { |
| 6 const Constant(); | 6 const Constant(); |
| 7 | 7 |
| 8 bool isNull() => false; | 8 bool isNull() => false; |
| 9 bool isBool() => false; | 9 bool isBool() => false; |
| 10 bool isTrue() => false; | 10 bool isTrue() => false; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 } | 502 } |
| 503 // TODO(floitsch): keep track of currently compiling elements so that we | 503 // TODO(floitsch): keep track of currently compiling elements so that we |
| 504 // don't end up in an infinite loop: final x = y; final y = x; | 504 // don't end up in an infinite loop: final x = y; final y = x; |
| 505 TreeElements definitions = compiler.analyzeElement(element); | 505 TreeElements definitions = compiler.analyzeElement(element); |
| 506 Constant constant = compileVariableWithDefinitions(element, definitions); | 506 Constant constant = compileVariableWithDefinitions(element, definitions); |
| 507 return constant; | 507 return constant; |
| 508 } | 508 } |
| 509 | 509 |
| 510 Constant compileVariableWithDefinitions(VariableElement element, | 510 Constant compileVariableWithDefinitions(VariableElement element, |
| 511 TreeElements definitions) { | 511 TreeElements definitions) { |
| 512 | |
|
ngeoffray
2012/03/20 08:26:07
Why is this one not measuring anymore? Even if it
floitsch
2012/03/21 07:14:24
done.
Wanted to do the same for compileVariable, b
| |
| 513 Node node = element.parseNode(compiler); | |
| 514 if (pendingVariables.contains(element)) { | |
| 515 MessageKind kind = MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS; | |
| 516 compiler.reportError(node, | |
| 517 new CompileTimeConstantError(kind, const [])); | |
|
ahe
2012/03/20 08:28:40
While trying to make our errors non-fatal, I notic
ngeoffray
2012/03/20 08:30:52
IMO, I don't see any trouble in returning somethin
floitsch
2012/03/21 07:14:24
It could lead to another cryptic error right after
ngeoffray
2012/03/21 07:41:11
Considering what Peter is trying to achieve (makin
ahe
2012/03/21 10:13:37
Which is definitely an improvement over the same e
| |
| 518 } | |
| 519 pendingVariables.add(element); | |
| 520 | |
| 521 SendSet assignment = node.asSendSet(); | |
| 522 Constant value; | |
| 523 if (assignment === null) { | |
| 524 // No initial value. | |
| 525 value = new NullConstant(); | |
| 526 } else { | |
| 527 Node right = assignment.arguments.head; | |
| 528 value = compileNodeWithDefinitions(right, definitions); | |
| 529 } | |
| 530 initialVariableValues[element] = value; | |
| 531 pendingVariables.remove(element); | |
| 532 return value; | |
| 533 } | |
| 534 | |
| 535 Constant compileNodeWithDefinitions(Node node, TreeElements definitions) { | |
| 512 return measure(() { | 536 return measure(() { |
| 513 Node node = element.parseNode(compiler); | |
| 514 assert(node !== null); | 537 assert(node !== null); |
| 515 SendSet assignment = node.asSendSet(); | 538 CompileTimeConstantEvaluator evaluator = |
| 516 var value; | 539 new CompileTimeConstantEvaluator(this, definitions, compiler); |
| 517 if (assignment === null) { | 540 return evaluator.evaluate(node); |
| 518 // No initial value. | |
| 519 value = new NullConstant(); | |
| 520 } else { | |
| 521 if (pendingVariables.contains(element)) { | |
| 522 MessageKind kind = MessageKind.CYCLIC_COMPILE_TIME_CONSTANTS; | |
| 523 compiler.reportError(node, | |
| 524 new CompileTimeConstantError(kind, const [])); | |
| 525 } | |
| 526 pendingVariables.add(element); | |
| 527 | |
| 528 Node right = assignment.arguments.head; | |
| 529 CompileTimeConstantEvaluator evaluator = | |
| 530 new CompileTimeConstantEvaluator(this, definitions, compiler); | |
| 531 value = evaluator.evaluate(right); | |
| 532 | |
| 533 pendingVariables.remove(element); | |
| 534 } | |
| 535 initialVariableValues[element] = value; | |
| 536 return value; | |
| 537 }); | 541 }); |
| 538 } | 542 } |
| 539 | 543 |
| 540 /** | 544 /** |
| 541 * Returns a [List] of static non final fields that need to be initialized. | 545 * Returns a [List] of static non final fields that need to be initialized. |
| 542 * The list must be evaluated in order since the fields might depend on each | 546 * The list must be evaluated in order since the fields might depend on each |
| 543 * other. | 547 * other. |
| 544 */ | 548 */ |
| 545 List<VariableElement> getStaticNonFinalFieldsForEmission() { | 549 List<VariableElement> getStaticNonFinalFieldsForEmission() { |
| 546 return initialVariableValues.getKeys().filter((element) { | 550 return initialVariableValues.getKeys().filter((element) { |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1016 return constant; | 1020 return constant; |
| 1017 } | 1021 } |
| 1018 | 1022 |
| 1019 error(Node node) { | 1023 error(Node node) { |
| 1020 // TODO(floitsch): get the list of constants that are currently compiled | 1024 // TODO(floitsch): get the list of constants that are currently compiled |
| 1021 // and present some kind of stack-trace. | 1025 // and present some kind of stack-trace. |
| 1022 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; | 1026 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; |
| 1023 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); | 1027 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); |
| 1024 } | 1028 } |
| 1025 } | 1029 } |
| OLD | NEW |