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

Side by Side Diff: pkg/compiler/lib/src/compile_time_constants.dart

Issue 1115183002: Add ConstantConstructor to ConstantExpression system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 5 years, 7 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 library dart2js.compile_time_constant_evaluator; 5 library dart2js.compile_time_constant_evaluator;
6 6
7 import 'constant_system_dart.dart'; 7 import 'constant_system_dart.dart';
8 import 'constants/constant_system.dart'; 8 import 'constants/constant_system.dart';
9 import 'constants/expressions.dart'; 9 import 'constants/expressions.dart';
10 import 'constants/values.dart'; 10 import 'constants/values.dart';
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 evaluateArgumentsToConstructor( 748 evaluateArgumentsToConstructor(
749 node, callStructure, send.arguments, constructor.implementation, 749 node, callStructure, send.arguments, constructor.implementation,
750 compileArgument: (node) => concreteArgumentMap[node]); 750 compileArgument: (node) => concreteArgumentMap[node]);
751 List<AstConstant> concreteArguments = 751 List<AstConstant> concreteArguments =
752 concreteArgumentMap.values.toList(); 752 concreteArgumentMap.values.toList();
753 753
754 if (constructor == compiler.intEnvironment || 754 if (constructor == compiler.intEnvironment ||
755 constructor == compiler.boolEnvironment || 755 constructor == compiler.boolEnvironment ||
756 constructor == compiler.stringEnvironment) { 756 constructor == compiler.stringEnvironment) {
757 757
758 AstConstant createEvaluatedConstant(ConstantValue value) {
759 return new AstConstant(
760 context, node, new ConstructedConstantExpression(
761 value,
762 type,
763 constructor,
764 elements.getSelector(send).callStructure,
765 concreteArguments.map((e) => e.expression).toList()));
766 }
767
768 var firstArgument = normalizedArguments[0].value; 758 var firstArgument = normalizedArguments[0].value;
769 ConstantValue defaultValue = normalizedArguments[1].value; 759 ConstantValue defaultValue = normalizedArguments[1].value;
770 760
771 if (firstArgument.isNull) { 761 if (firstArgument.isNull) {
772 compiler.reportError( 762 compiler.reportError(
773 send.arguments.head, MessageKind.NULL_NOT_ALLOWED); 763 send.arguments.head, MessageKind.NULL_NOT_ALLOWED);
774 return null; 764 return null;
775 } 765 }
776 766
777 if (!firstArgument.isString) { 767 if (!firstArgument.isString) {
(...skipping 24 matching lines...) Expand all
802 792
803 if (constructor == compiler.stringEnvironment && 793 if (constructor == compiler.stringEnvironment &&
804 !(defaultValue.isNull || defaultValue.isString)) { 794 !(defaultValue.isNull || defaultValue.isString)) {
805 DartType type = defaultValue.getType(compiler.coreTypes); 795 DartType type = defaultValue.getType(compiler.coreTypes);
806 compiler.reportError( 796 compiler.reportError(
807 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE, 797 send.arguments.tail.head, MessageKind.NOT_ASSIGNABLE,
808 {'fromType': type, 'toType': compiler.stringClass.rawType}); 798 {'fromType': type, 'toType': compiler.stringClass.rawType});
809 return null; 799 return null;
810 } 800 }
811 801
802 String name =
803 firstArgument.primitiveValue.slowToString();
812 String value = 804 String value =
813 compiler.fromEnvironment(firstArgument.primitiveValue.slowToString()); 805 compiler.fromEnvironment(name);
806
807 AstConstant createEvaluatedConstant(ConstantValue value) {
808
809 ConstantExpression expression;
810 if (constructor == compiler.intEnvironment) {
811 expression = new IntFromEnvironmentConstantExpression(
812 value, name, normalizedArguments[1].expression);
813 } else if (constructor == compiler.boolEnvironment) {
814 expression = new BoolFromEnvironmentConstantExpression(
815 value, name, normalizedArguments[1].expression);
816 } else if (constructor == compiler.stringEnvironment) {
817 expression = new StringFromEnvironmentConstantExpression(
818 value, name, normalizedArguments[1].expression);
819 }
820 return new AstConstant(context, node, expression);
821 }
814 822
815 if (value == null) { 823 if (value == null) {
816 return createEvaluatedConstant(defaultValue); 824 return createEvaluatedConstant(defaultValue);
817 } else if (constructor == compiler.intEnvironment) { 825 } else if (constructor == compiler.intEnvironment) {
818 int number = int.parse(value, onError: (_) => null); 826 int number = int.parse(value, onError: (_) => null);
819 return createEvaluatedConstant( 827 return createEvaluatedConstant(
820 (number == null) 828 (number == null)
821 ? defaultValue 829 ? defaultValue
822 : constantSystem.createInt(number)); 830 : constantSystem.createInt(number));
823 } else if (constructor == compiler.boolEnvironment) { 831 } else if (constructor == compiler.boolEnvironment) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 ConstantValue get value => expression.value; 1155 ConstantValue get value => expression.value;
1148 1156
1149 String toString() => expression.toString(); 1157 String toString() => expression.toString();
1150 } 1158 }
1151 1159
1152 /// A synthetic constant used to recover from errors. 1160 /// A synthetic constant used to recover from errors.
1153 class ErroneousAstConstant extends AstConstant { 1161 class ErroneousAstConstant extends AstConstant {
1154 ErroneousAstConstant(Element element, Node node) 1162 ErroneousAstConstant(Element element, Node node)
1155 : super(element, node, new ErroneousConstantExpression()); 1163 : super(element, node, new ErroneousConstantExpression());
1156 } 1164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698