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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart

Issue 585173002: dart2js: Support new const operations on strings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add null check. Created 6 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 part of dart2js; 5 part of dart2js;
6 6
7 /// A [ConstantEnvironment] provides access for constants compiled for variable 7 /// A [ConstantEnvironment] provides access for constants compiled for variable
8 /// initializers. 8 /// initializers.
9 abstract class ConstantEnvironment { 9 abstract class ConstantEnvironment {
10 /// Returns the constant for the initializer of [element]. 10 /// Returns the constant for the initializer of [element].
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (element.isConst) { 402 if (element.isConst) {
403 result = handler.compileConstant(element); 403 result = handler.compileConstant(element);
404 } else if (element.isFinal && !isEvaluatingConstant) { 404 } else if (element.isFinal && !isEvaluatingConstant) {
405 result = handler.compileVariable(element); 405 result = handler.compileVariable(element);
406 } 406 }
407 if (result != null) return result; 407 if (result != null) return result;
408 } else if (Elements.isClass(element) || Elements.isTypedef(element)) { 408 } else if (Elements.isClass(element) || Elements.isTypedef(element)) {
409 assert(elements.isTypeLiteral(send)); 409 assert(elements.isTypeLiteral(send));
410 return makeTypeConstant(elements.getTypeLiteralType(send)); 410 return makeTypeConstant(elements.getTypeLiteralType(send));
411 } else if (send.receiver != null) { 411 } else if (send.receiver != null) {
412 if (send.selector.asIdentifier().source == "length") {
413 Constant left = evaluate(send.receiver);
414 if (left != null && left.isString) {
415 StringConstant string = left;
416 return constantSystem.createInt(string.value.length);
417 }
418 }
412 // Fall through to error handling. 419 // Fall through to error handling.
413 } else if (!Elements.isUnresolved(element) 420 } else if (!Elements.isUnresolved(element)
414 && element.isVariable 421 && element.isVariable
415 && element.isConst) { 422 && element.isConst) {
416 Constant result = handler.compileConstant(element); 423 Constant result = handler.compileConstant(element);
417 if (result != null) return result; 424 if (result != null) return result;
418 } 425 }
419 return signalNotCompileTimeConstant(send); 426 return signalNotCompileTimeConstant(send);
420 } else if (send.isCall) { 427 } else if (send.isCall) {
421 if (identical(element, compiler.identicalFunction) 428 if (element == compiler.identicalFunction
422 && send.argumentCount() == 2) { 429 && send.argumentCount() == 2) {
423 Constant left = evaluate(send.argumentsNode.nodes.head); 430 Constant left = evaluate(send.argumentsNode.nodes.head);
424 Constant right = evaluate(send.argumentsNode.nodes.tail.head); 431 Constant right = evaluate(send.argumentsNode.nodes.tail.head);
425 Constant result = constantSystem.identity.fold(left, right); 432 Constant result = constantSystem.identity.fold(left, right);
426 if (result != null) return result; 433 if (result != null) return result;
427 } 434 }
428 return signalNotCompileTimeConstant(send); 435 return signalNotCompileTimeConstant(send);
429 } else if (send.isPrefix) { 436 } else if (send.isPrefix) {
430 assert(send.isOperator); 437 assert(send.isOperator);
431 Constant receiverConstant = evaluate(send.receiver); 438 Constant receiverConstant = evaluate(send.receiver);
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 if (fieldValue == null) { 875 if (fieldValue == null) {
869 // Use the default value. 876 // Use the default value.
870 fieldValue = handler.compileConstant(field); 877 fieldValue = handler.compileConstant(field);
871 } 878 }
872 jsNewArguments.add(fieldValue); 879 jsNewArguments.add(fieldValue);
873 }, 880 },
874 includeSuperAndInjectedMembers: true); 881 includeSuperAndInjectedMembers: true);
875 return jsNewArguments; 882 return jsNewArguments;
876 } 883 }
877 } 884 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698