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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 /** 5 /**
6 * The [ConstantHandler] keeps track of compile-time constants, 6 * The [ConstantHandler] keeps track of compile-time constants,
7 * initializations of global and static fields, and default values of 7 * initializations of global and static fields, and default values of
8 * optional parameters. 8 * optional parameters.
9 */ 9 */
10 class ConstantHandler extends CompilerTask { 10 class ConstantHandler extends CompilerTask {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 StringConstant partString = evaluate(part.string); 382 StringConstant partString = evaluate(part.string);
383 if (partString == null) return null; 383 if (partString == null) return null;
384 accumulator = new DartString.concat(accumulator, partString.value); 384 accumulator = new DartString.concat(accumulator, partString.value);
385 }; 385 };
386 return constantSystem.createString(accumulator, node); 386 return constantSystem.createString(accumulator, node);
387 } 387 }
388 388
389 // TODO(floitsch): provide better error-messages. 389 // TODO(floitsch): provide better error-messages.
390 Constant visitSend(Send send) { 390 Constant visitSend(Send send) {
391 Element element = elements[send]; 391 Element element = elements[send];
392 if (Elements.isStaticOrTopLevelField(element)) { 392 if (send.isPropertyAccess) {
393 Constant result; 393 if (Elements.isStaticOrTopLevelFunction(element)) {
394 if (element.modifiers !== null) { 394 compiler.codegenWorld.staticFunctionsNeedingGetter.add(element);
395 if (element.modifiers.isConst()) { 395 Constant constant = new FunctionConstant(element);
396 result = compiler.compileConstant(element); 396 compiler.constantHandler.registerCompileTimeConstant(constant);
397 } else if (element.modifiers.isFinal() && !isEvaluatingConstant) { 397 compiler.enqueuer.codegen.registerStaticUse(element);
398 result = compiler.compileVariable(element); 398 return constant;
399 } else if (Elements.isStaticOrTopLevelField(element)) {
400 Constant result;
401 if (element.modifiers !== null) {
402 if (element.modifiers.isConst()) {
403 result = compiler.compileConstant(element);
404 } else if (element.modifiers.isFinal() && !isEvaluatingConstant) {
405 result = compiler.compileVariable(element);
406 }
399 } 407 }
408 if (result !== null) return result;
400 } 409 }
401 if (result == null) return signalNotCompileTimeConstant(send); 410 return signalNotCompileTimeConstant(send);
402 return result; 411 } else if (send.isCall) {
403 } else if (Elements.isStaticOrTopLevelFunction(element) 412 if (element === compiler.identicalFunction && send.argumentCount() == 2) {
404 && send.isPropertyAccess) { 413 Constant left = evaluate(send.argumentsNode.nodes.head);
405 compiler.codegenWorld.staticFunctionsNeedingGetter.add(element); 414 Constant right = evaluate(send.argumentsNode.nodes.tail.head);
406 Constant constant = new FunctionConstant(element); 415 Constant result = constantSystem.identity.fold(left, right);
407 compiler.constantHandler.registerCompileTimeConstant(constant); 416 if (result !== null) return result;
408 compiler.enqueuer.codegen.registerStaticUse(element); 417 }
409 return constant; 418 return signalNotCompileTimeConstant(send);
410 } else if (send.isPrefix) { 419 } else if (send.isPrefix) {
411 assert(send.isOperator); 420 assert(send.isOperator);
412 Constant receiverConstant = evaluate(send.receiver); 421 Constant receiverConstant = evaluate(send.receiver);
413 if (receiverConstant == null) return null; 422 if (receiverConstant == null) return null;
414 Operator op = send.selector; 423 Operator op = send.selector;
415 Constant folded; 424 Constant folded;
416 switch (op.source.stringValue) { 425 switch (op.source.stringValue) {
417 case "!": 426 case "!":
418 folded = constantSystem.not.fold(receiverConstant); 427 folded = constantSystem.not.fold(receiverConstant);
419 break; 428 break;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 break; 496 break;
488 case ">=": 497 case ">=":
489 folded = constantSystem.greaterEqual.fold(left, right); 498 folded = constantSystem.greaterEqual.fold(left, right);
490 break; 499 break;
491 case "==": 500 case "==":
492 if (left.isPrimitive() && right.isPrimitive()) { 501 if (left.isPrimitive() && right.isPrimitive()) {
493 folded = constantSystem.equal.fold(left, right); 502 folded = constantSystem.equal.fold(left, right);
494 } 503 }
495 break; 504 break;
496 case "===": 505 case "===":
497 if (left.isPrimitive() && right.isPrimitive()) { 506 folded = constantSystem.identity.fold(left, right);
498 folded = constantSystem.identity.fold(left, right);
499 }
500 break; 507 break;
501 case "!=": 508 case "!=":
502 if (left.isPrimitive() && right.isPrimitive()) { 509 if (left.isPrimitive() && right.isPrimitive()) {
503 BoolConstant areEquals = constantSystem.equal.fold(left, right); 510 BoolConstant areEquals = constantSystem.equal.fold(left, right);
504 if (areEquals === null) { 511 if (areEquals === null) {
505 folded = null; 512 folded = null;
506 } else { 513 } else {
507 folded = areEquals.negate(); 514 folded = areEquals.negate();
508 } 515 }
509 } 516 }
510 break; 517 break;
511 case "!==": 518 case "!==":
512 if (left.isPrimitive() && right.isPrimitive()) { 519 BoolConstant areIdentical =
513 BoolConstant areIdentical = 520 constantSystem.identity.fold(left, right);
514 constantSystem.identity.fold(left, right); 521 if (areIdentical === null) {
515 if (areIdentical === null) { 522 folded = null;
516 folded = null; 523 } else {
517 } else { 524 folded = areIdentical.negate();
518 folded = areIdentical.negate();
519 }
520 } 525 }
521 break; 526 break;
522 } 527 }
523 if (folded === null) return signalNotCompileTimeConstant(send); 528 if (folded === null) return signalNotCompileTimeConstant(send);
524 return folded; 529 return folded;
525 } 530 }
526 return signalNotCompileTimeConstant(send); 531 return signalNotCompileTimeConstant(send);
527 } 532 }
528 533
529 Constant visitSendSet(SendSet node) { 534 Constant visitSendSet(SendSet node) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 Constant fieldValue = fieldValues[field]; 783 Constant fieldValue = fieldValues[field];
779 if (fieldValue === null) { 784 if (fieldValue === null) {
780 // Use the default value. 785 // Use the default value.
781 fieldValue = compiler.compileConstant(field); 786 fieldValue = compiler.compileConstant(field);
782 } 787 }
783 jsNewArguments.add(fieldValue); 788 jsNewArguments.add(fieldValue);
784 }); 789 });
785 return jsNewArguments; 790 return jsNewArguments;
786 } 791 }
787 } 792 }
OLDNEW
« 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