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

Unified Diff: lib/compiler/implementation/compile_time_constants.dart

Issue 10908287: Make identical(a,b) a compile-time constant in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comment. Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | lib/compiler/implementation/compiler.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/compile_time_constants.dart
diff --git a/lib/compiler/implementation/compile_time_constants.dart b/lib/compiler/implementation/compile_time_constants.dart
index 13e7a0a078470e36a77739f295c0a2e5e88e378c..ec699ac8c3217e77aec7cf784c142162c082ec7e 100644
--- a/lib/compiler/implementation/compile_time_constants.dart
+++ b/lib/compiler/implementation/compile_time_constants.dart
@@ -389,24 +389,33 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
// TODO(floitsch): provide better error-messages.
Constant visitSend(Send send) {
Element element = elements[send];
- if (Elements.isStaticOrTopLevelField(element)) {
- Constant result;
- if (element.modifiers !== null) {
- if (element.modifiers.isConst()) {
- result = compiler.compileConstant(element);
- } else if (element.modifiers.isFinal() && !isEvaluatingConstant) {
- result = compiler.compileVariable(element);
+ if (send.isPropertyAccess) {
+ if (Elements.isStaticOrTopLevelFunction(element)) {
+ compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
+ Constant constant = new FunctionConstant(element);
+ compiler.constantHandler.registerCompileTimeConstant(constant);
+ compiler.enqueuer.codegen.registerStaticUse(element);
+ return constant;
+ } else if (Elements.isStaticOrTopLevelField(element)) {
+ Constant result;
+ if (element.modifiers !== null) {
+ if (element.modifiers.isConst()) {
+ result = compiler.compileConstant(element);
+ } else if (element.modifiers.isFinal() && !isEvaluatingConstant) {
+ result = compiler.compileVariable(element);
+ }
}
+ if (result !== null) return result;
}
- if (result == null) return signalNotCompileTimeConstant(send);
- return result;
- } else if (Elements.isStaticOrTopLevelFunction(element)
- && send.isPropertyAccess) {
- compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
- Constant constant = new FunctionConstant(element);
- compiler.constantHandler.registerCompileTimeConstant(constant);
- compiler.enqueuer.codegen.registerStaticUse(element);
- return constant;
+ return signalNotCompileTimeConstant(send);
+ } else if (send.isCall) {
+ if (element === compiler.identicalFunction && send.argumentCount() == 2) {
+ Constant left = evaluate(send.argumentsNode.nodes.head);
+ Constant right = evaluate(send.argumentsNode.nodes.tail.head);
+ Constant result = constantSystem.identity.fold(left, right);
+ if (result !== null) return result;
+ }
+ return signalNotCompileTimeConstant(send);
} else if (send.isPrefix) {
assert(send.isOperator);
Constant receiverConstant = evaluate(send.receiver);
@@ -494,9 +503,7 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
}
break;
case "===":
- if (left.isPrimitive() && right.isPrimitive()) {
- folded = constantSystem.identity.fold(left, right);
- }
+ folded = constantSystem.identity.fold(left, right);
break;
case "!=":
if (left.isPrimitive() && right.isPrimitive()) {
@@ -509,14 +516,12 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
}
break;
case "!==":
- if (left.isPrimitive() && right.isPrimitive()) {
- BoolConstant areIdentical =
- constantSystem.identity.fold(left, right);
- if (areIdentical === null) {
- folded = null;
- } else {
- folded = areIdentical.negate();
- }
+ BoolConstant areIdentical =
+ constantSystem.identity.fold(left, right);
+ if (areIdentical === null) {
+ folded = null;
+ } else {
+ folded = areIdentical.negate();
}
break;
}
« no previous file with comments | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | lib/compiler/implementation/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698