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

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

Issue 9717035: Handle compile-time constants to interfaces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. 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 | tests/language/language-leg.status » ('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 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 } 966 }
967 } 967 }
968 if (classElement.superclass != compiler.coreLibrary.find(Types.OBJECT)) { 968 if (classElement.superclass != compiler.coreLibrary.find(Types.OBJECT)) {
969 compiler.unimplemented("ConstantHandler with super", node: node); 969 compiler.unimplemented("ConstantHandler with super", node: node);
970 } 970 }
971 return jsNewArguments; 971 return jsNewArguments;
972 } 972 }
973 973
974 if (!node.isConst()) error(node); 974 if (!node.isConst()) error(node);
975 975
976 // TODO(floitsch): get the type from somewhere.
977 FunctionElement constructor = elements[node.send]; 976 FunctionElement constructor = elements[node.send];
978 ClassElement classElement = constructor.enclosingElement;
979 TreeElements constructorElements = 977 TreeElements constructorElements =
980 compiler.resolver.resolveMethodElement(constructor); 978 compiler.resolver.resolveMethodElement(constructor);
979 if (constructor != constructor.defaultImplementation) {
980 constructor = constructor.defaultImplementation;
981 constructorElements =
982 compiler.resolver.resolveMethodElement(constructor);
983 }
984
985 ClassElement classElement = constructor.enclosingElement;
981 FunctionExpression functionNode = constructor.parseNode(compiler); 986 FunctionExpression functionNode = constructor.parseNode(compiler);
982 NodeList initializerList = functionNode.initializers; 987 NodeList initializerList = functionNode.initializers;
983 FunctionParameters parameters = constructor.computeParameters(compiler); 988 FunctionParameters parameters = constructor.computeParameters(compiler);
984 989
985 Map<Element, Constant> fieldValues = new Map<Element, Constant>(); 990 Map<Element, Constant> fieldValues = new Map<Element, Constant>();
986 Map<Element, Constant> constructorDefinitions = 991 Map<Element, Constant> constructorDefinitions =
987 new Map<Element, Constant>(); 992 new Map<Element, Constant>();
988 993
989 assignArgumentsToParameters(parameters, constructorDefinitions, 994 assignArgumentsToParameters(parameters, constructorDefinitions,
990 fieldValues); 995 fieldValues);
991 CompileTimeConstantEvaluator initializerEvaluator = 996 CompileTimeConstantEvaluator initializerEvaluator =
992 new CompileTimeConstantEvaluator.insideConstructor( 997 new CompileTimeConstantEvaluator.insideConstructor(
993 constantHandler, constructorElements, compiler, 998 constantHandler, constructorElements, compiler,
994 constructorDefinitions); 999 constructorDefinitions);
995 if (initializerList !== null) { 1000 if (initializerList !== null) {
996 Link<Node> initializers = functionNode.initializers.nodes; 1001 Link<Node> initializers = functionNode.initializers.nodes;
997 compileInitializers(initializers, 1002 compileInitializers(initializers,
998 initializerEvaluator, 1003 initializerEvaluator,
999 constructorElements, 1004 constructorElements,
1000 constructorDefinitions, 1005 constructorDefinitions,
1001 fieldValues); 1006 fieldValues);
1002 } 1007 }
1003 List<Constant> jsNewArguments = 1008 List<Constant> jsNewArguments =
1004 buildJsNewArguments(classElement, fieldValues); 1009 buildJsNewArguments(classElement, fieldValues);
1005 1010
1006 compiler.registerInstantiatedClass(classElement); 1011 compiler.registerInstantiatedClass(classElement);
1007 Type type = new SimpleType(classElement.name, classElement); 1012 // TODO(floitsch): take generic types into account.
1013 Type type = classElement.computeType(compiler);
1008 Constant constant = new ConstructedConstant(type, jsNewArguments); 1014 Constant constant = new ConstructedConstant(type, jsNewArguments);
1009 constantHandler.registerCompileTimeConstant(constant); 1015 constantHandler.registerCompileTimeConstant(constant);
1010 return constant; 1016 return constant;
1011 } 1017 }
1012 1018
1013 error(Node node) { 1019 error(Node node) {
1014 // TODO(floitsch): get the list of constants that are currently compiled 1020 // TODO(floitsch): get the list of constants that are currently compiled
1015 // and present some kind of stack-trace. 1021 // and present some kind of stack-trace.
1016 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT; 1022 MessageKind kind = MessageKind.NOT_A_COMPILE_TIME_CONSTANT;
1017 compiler.reportError(node, new CompileTimeConstantError(kind, const [])); 1023 compiler.reportError(node, new CompileTimeConstantError(kind, const []));
1018 } 1024 }
1019 } 1025 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/language-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698