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

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 29652)
+++ sdk/lib/_internal/compiler/implementation/compile_time_constants.dart (working copy)
@@ -634,7 +634,77 @@
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);
+ return (number == null)
+ ? defaultValue
+ : constantSystem.createInt(number);
+ } else if (constructor == compiler.boolEnvironment) {
+ if (value == 'true') {
+ return constantSystem.createBool(true);
+ } else if (value == 'false') {
+ return constantSystem.createBool(false);
+ } else {
+ return defaultValue;
+ }
+ } 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