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

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,73 @@
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);
+ var firstArgument = arguments[0];
+ Constant defaultValue = arguments[1];
+
+ if (firstArgument is NullConstant) {
+ compiler.reportFatalError(
+ send.arguments.head, MessageKind.NULL_NOT_ALLOWED);
+ }
+
+ if (firstArgument is! StringConstant) {
+ DartType type = defaultValue.computeType(compiler);
+ compiler.reportFatalError(
+ send.arguments.head, MessageKind.NOT_ASSIGNABLE.error,
+ {'fromType': type, 'toType': compiler.stringClass.rawType});
+ }
+
+ if (constructor == compiler.intEnvironment
+ && !(defaultValue is NullConstant || defaultValue is IntConstant)) {
+ DartType type = defaultValue.computeType(compiler);
+ compiler.reportFatalError(
+ send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error,
+ {'fromType': type, 'toType': compiler.intClass.rawType});
+ }
+
+ if (constructor == compiler.boolEnvironment
+ && !(defaultValue is NullConstant || defaultValue is BoolConstant)) {
+ DartType type = defaultValue.computeType(compiler);
+ compiler.reportFatalError(
+ send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error,
+ {'fromType': type, 'toType': compiler.boolClass.rawType});
+ }
+
+ if (constructor == compiler.stringEnvironment
+ && !(defaultValue is NullConstant
+ || defaultValue is StringConstant)) {
+ DartType type = defaultValue.computeType(compiler);
+ compiler.reportFatalError(
+ send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE.error,
+ {'fromType': type, 'toType': compiler.stringClass.rawType});
+ }
+
+ String value =
+ compiler.fromEnvironment(firstArgument.value.slowToString());
+
+ if (value == null) {
+ return defaultValue;
+ } else if (constructor == compiler.intEnvironment) {
+ int number = int.parse(value, onError: (_) => null);
Lasse Reichstein Nielsen 2013/10/31 06:58:20 It should be fine to just do: return constantSys
ngeoffray 2013/10/31 07:41:18 Done.
+ return (number == null)
Søren Gjesse 2013/10/30 15:21:49 Re-reading the specification non-parseable integer
Lasse Reichstein Nielsen 2013/10/31 06:58:20 I'm open to changing it. I was working on the assu
+ ? defaultValue
+ : constantSystem.createInt(number);
+ } else if (constructor == compiler.boolEnvironment) {
+ return (value == 'true')
+ ? constantSystem.createBool(true)
+ : constantSystem.createBool(false);
+ } else {
+ assert(constructor == compiler.stringEnvironment);
+ return constantSystem.createString(new DartString.literal(value), node);
+ }
+ } else {
+ return makeConstructedConstant(
+ node, type, constructor, evaluateArguments);
+ }
}
Constant makeConstructedConstant(
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/apiimpl.dart ('k') | sdk/lib/_internal/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698