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

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

Issue 48323003: Implement fromEnvironment on bool, int, String in dart2js. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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
Index: sdk/lib/_internal/compiler/implementation/compile_time_constants.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/compile_time_constants.dart (revision 29517)
+++ sdk/lib/_internal/compiler/implementation/compile_time_constants.dart (working copy)
@@ -634,7 +634,60 @@
return evaluateArgumentsToConstructor(
node, selector, send.arguments, constructor);
}
- return makeConstructedConstant(node, type, constructor, evaluateArguments);
+
+ if (constructor == compiler.intEnvironment
+ || constructor == compiler.boolEnvironment
+ || constructor == compiler.stringEnvironment) {
+ List<Constant> arguments = evaluateArguments(constructor);
+ Constant firstArgument = arguments[0];
+
+ if (constructor == compiler.intEnvironment
+ && !(arguments[1] is NullConstant
+ || arguments[1] is IntConstant)) {
+ DartType type = arguments[1].computeType(compiler);
+ compiler.reportFatalError(
+ send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error,
+ {'fromType': type, 'toType': compiler.intClass.rawType});
+ }
+ if (constructor == compiler.stringEnvironment
+ && !(arguments[1] is NullConstant
+ || arguments[1] is StringConstant)) {
+ DartType type = arguments[1].computeType(compiler);
+ compiler.reportFatalError(
+ send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error,
+ {'fromType': type, 'toType': compiler.stringClass.rawType});
+ }
+
+ var value = firstArgument is StringConstant
+ ? compiler.fromEnvironment(firstArgument.value.slowToString())
+ : null;
+
+ if (value == null) {
kasperl 2013/10/30 13:35:25 Not sure I understand why we want to be so forgivi
Søren Gjesse 2013/10/30 13:59:14 In the VM implementation we throw an error if the
+ if (constructor == compiler.boolEnvironment) {
kasperl 2013/10/30 13:35:25 I'd add a few comments here to explain the behavio
+ return constantSystem.createBool(false);
+ } else {
+ assert(arguments.length == 2);
+ return arguments[1];
kasperl 2013/10/30 13:35:25 Add local variable for arguments[1] and call it de
ngeoffray 2013/10/30 15:13:59 Done.
+ }
+ } else if (constructor == compiler.intEnvironment) {
+ return value is int
+ ? constantSystem.createInt(value)
+ : arguments[1];
+ } else if (constructor == compiler.boolEnvironment) {
+ return value is bool
+ ? constantSystem.createBool(value)
+ : constantSystem.createBool(false);
+ } else {
+ assert(constructor == compiler.stringEnvironment);
+ return value is String
+ ? constantSystem.createString(
+ new DartString.literal(value), node)
+ : arguments[1];
+ }
+ } else {
+ return makeConstructedConstant(
+ node, type, constructor, evaluateArguments);
+ }
}
Constant makeConstructedConstant(

Powered by Google App Engine
This is Rietveld 408576698