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

Side by Side Diff: frog/leg/compile_time_constants.dart

Issue 9701072: Revert r5529. Breaks frog and web bots. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 class Constant implements Hashable { 5 class Constant implements Hashable {
6 const Constant(); 6 const Constant();
7 7
8 bool isNull() => false; 8 bool isNull() => false;
9 bool isBool() => false; 9 bool isBool() => false;
10 bool isTrue() => false; 10 bool isTrue() => false;
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 return folded; 894 return folded;
895 } 895 }
896 return super.visitSend(send); 896 return super.visitSend(send);
897 } 897 }
898 898
899 visitSendSet(SendSet node) { 899 visitSendSet(SendSet node) {
900 error(node); 900 error(node);
901 } 901 }
902 902
903 Constant visitNewExpression(NewExpression node) { 903 Constant visitNewExpression(NewExpression node) {
904 List<Constant> compileArguments() {
905 if (!node.isConst()) error(node);
906 Send send = node.send;
907 List<Constant> arguments;
908 if (send.arguments.isEmpty()) {
909 arguments = const <Constant>[];
910 } else {
911 arguments = <Constant>[];
912 for (Link<Node> link = send.arguments;
913 !link.isEmpty();
914 link = link.tail) {
915 arguments.add(evaluate(link.head));
916 }
917 }
918 return arguments;
919 }
920
904 void assignArgumentsToParameters( 921 void assignArgumentsToParameters(
922 List<Constant> arguments,
905 FunctionParameters parameters, 923 FunctionParameters parameters,
906 Map<Element, Constant> constructorDefinitions, 924 Map<Element, Constant> constructorDefinitions,
907 Map<Element, Constant> fieldValues) { 925 Map<Element, Constant> fieldValues) {
908 Send send = node.send; 926 if (arguments.length != parameters.parameterCount) {
909 if (send.arguments.isEmpty() && parameters.parameterCount == 0) return; 927 if (arguments.length < parameters.parameterCount &&
910 List<Constant> arguments = <Constant>[]; 928 arguments.length >= parameters.requiredParameterCount) {
911 Selector selector = elements.getSelector(send); 929 compiler.unimplemented("ConstantHandler with optional arguments",
912 930 node: node);
913 Function compileArgument = evaluate; 931 } else {
914 Function compileConstant = constantHandler.compileVariable; 932 error(node);
915 bool succeeded = selector.addSendArgumentsToList( 933 }
916 send, arguments, parameters, compileArgument, compileConstant); 934 }
917 if (!succeeded) error(node);
918
919 int index = 0; 935 int index = 0;
920 parameters.forEachParameter((Element parameter) { 936 parameters.forEachParameter((Element parameter) {
921 Constant argument = arguments[index++]; 937 Constant argument = arguments[index++];
922 constructorDefinitions[parameter] = argument; 938 constructorDefinitions[parameter] = argument;
923 if (parameter.kind == ElementKind.FIELD_PARAMETER) { 939 if (parameter.kind == ElementKind.FIELD_PARAMETER) {
924 FieldParameterElement fieldParameterElement = parameter; 940 FieldParameterElement fieldParameterElement = parameter;
925 fieldValues[fieldParameterElement.fieldElement] = argument; 941 fieldValues[fieldParameterElement.fieldElement] = argument;
926 } 942 }
927 }); 943 });
928 } 944 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 } 980 }
965 jsNewArguments.add(fieldValue); 981 jsNewArguments.add(fieldValue);
966 } 982 }
967 } 983 }
968 if (classElement.superclass != compiler.coreLibrary.find(Types.OBJECT)) { 984 if (classElement.superclass != compiler.coreLibrary.find(Types.OBJECT)) {
969 compiler.unimplemented("ConstantHandler with super", node: node); 985 compiler.unimplemented("ConstantHandler with super", node: node);
970 } 986 }
971 return jsNewArguments; 987 return jsNewArguments;
972 } 988 }
973 989
974 if (!node.isConst()) error(node);
975
976 // TODO(floitsch): get the type from somewhere. 990 // TODO(floitsch): get the type from somewhere.
977 FunctionElement constructor = elements[node.send]; 991 FunctionElement constructor = elements[node.send];
978 ClassElement classElement = constructor.enclosingElement; 992 ClassElement classElement = constructor.enclosingElement;
979 TreeElements constructorElements = 993 TreeElements constructorElements =
980 compiler.resolver.resolveMethodElement(constructor); 994 compiler.resolver.resolveMethodElement(constructor);
981 FunctionExpression functionNode = constructor.parseNode(compiler); 995 FunctionExpression functionNode = constructor.parseNode(compiler);
982 NodeList initializerList = functionNode.initializers; 996 NodeList initializerList = functionNode.initializers;
983 FunctionParameters parameters = constructor.computeParameters(compiler); 997 FunctionParameters parameters = constructor.computeParameters(compiler);
984 998
985 Map<Element, Constant> fieldValues = new Map<Element, Constant>(); 999 Map<Element, Constant> fieldValues = new Map<Element, Constant>();
986 Map<Element, Constant> constructorDefinitions = 1000 Map<Element, Constant> constructorDefinitions =
987 new Map<Element, Constant>(); 1001 new Map<Element, Constant>();
988 1002
989 assignArgumentsToParameters(parameters, constructorDefinitions, 1003 List<Constant> arguments = compileArguments();
990 fieldValues); 1004 assignArgumentsToParameters(arguments, parameters,
1005 constructorDefinitions, fieldValues);
991 CompileTimeConstantEvaluator initializerEvaluator = 1006 CompileTimeConstantEvaluator initializerEvaluator =
992 new CompileTimeConstantEvaluator.insideConstructor( 1007 new CompileTimeConstantEvaluator.insideConstructor(
993 constantHandler, constructorElements, compiler, 1008 constantHandler, constructorElements, compiler,
994 constructorDefinitions); 1009 constructorDefinitions);
995 if (initializerList !== null) { 1010 if (initializerList !== null) {
996 Link<Node> initializers = functionNode.initializers.nodes; 1011 Link<Node> initializers = functionNode.initializers.nodes;
997 compileInitializers(initializers, 1012 compileInitializers(initializers,
998 initializerEvaluator, 1013 initializerEvaluator,
999 constructorElements, 1014 constructorElements,
1000 constructorDefinitions, 1015 constructorDefinitions,
1001 fieldValues); 1016 fieldValues);
1002 } 1017 }
1003 List<Constant> jsNewArguments = 1018 List<Constant> jsNewArguments =
1004 buildJsNewArguments(classElement, fieldValues); 1019 buildJsNewArguments(classElement, fieldValues);
1005 1020
1006 compiler.registerInstantiatedClass(classElement); 1021 compiler.registerInstantiatedClass(classElement);
1007 Type type = new SimpleType(classElement.name, classElement); 1022 Type type = new SimpleType(classElement.name, classElement);
1008 Constant constant = new ConstructedConstant(type, jsNewArguments); 1023 Constant constant = new ConstructedConstant(type, jsNewArguments);
1009 constantHandler.registerCompileTimeConstant(constant); 1024 constantHandler.registerCompileTimeConstant(constant);
1010 return constant; 1025 return constant;
1011 } 1026 }
1012 1027
1013 error(Node node) { 1028 error(Node node) {
1014 // TODO(floitsch): get the list of constants that are currently compiled 1029 // TODO(floitsch): get the list of constants that are currently compiled
1015 // and present some kind of stack-trace. 1030 // and present some kind of stack-trace.
1016 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; 1031 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT;
1017 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); 1032 compiler.reportError(node, new CompileTimeConstantError(kind, const []));
1018 } 1033 }
1019 } 1034 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698