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

Unified Diff: frog/leg/compile_time_constants.dart

Issue 9705025: const constructors with optional arguments. (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/compile_time_constants.dart
diff --git a/frog/leg/compile_time_constants.dart b/frog/leg/compile_time_constants.dart
index cefe2f5f2a70f8d0f44862a181f09597555c33cf..5ac826a602db0f8f5350ace77a2399e441c60bdc 100644
--- a/frog/leg/compile_time_constants.dart
+++ b/frog/leg/compile_time_constants.dart
@@ -900,36 +900,23 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
}
Constant visitNewExpression(NewExpression node) {
- List<Constant> compileArguments() {
- if (!node.isConst()) error(node);
- Send send = node.send;
- List<Constant> arguments;
- if (send.arguments.isEmpty()) {
- arguments = const <Constant>[];
- } else {
- arguments = <Constant>[];
- for (Link<Node> link = send.arguments;
- !link.isEmpty();
- link = link.tail) {
- arguments.add(evaluate(link.head));
- }
- }
- return arguments;
- }
-
void assignArgumentsToParameters(
- List<Constant> arguments,
FunctionParameters parameters,
Map<Element, Constant> constructorDefinitions) {
- if (arguments.length != parameters.parameterCount) {
- if (arguments.length < parameters.parameterCount &&
- arguments.length >= parameters.requiredParameterCount) {
- compiler.unimplemented("ConstantHandler with optional arguments",
- node: node);
- } else {
- error(node);
- }
- }
+ Send send = node.send;
+ if (send.arguments.isEmpty() && parameters.parameterCount == 0) return;
+ List<Constant> arguments = <Constant>[];
+ Selector selector = elements.getSelector(send);
+
+ Constant evaluateConstant(Element element)
+ => constantHandler.compileVariable(element);
+
+ Function visitArgument = evaluate;
+ Function visitConstant = constantHandler.compileVariable;
ngeoffray 2012/03/15 10:24:58 Because this class is a visitor, I'd prefer avoidi
floitsch 2012/03/15 14:30:47 removed evaluateConstant (old dead code). renamed
+ bool succeeded = selector.addSendArgumentsToList(
+ send, arguments, parameters, visitArgument, visitConstant);
+ if (!succeeded) error(node);
+
int index = 0;
parameters.forEachParameter((Element parameter) {
constructorDefinitions[parameter] = arguments[index++];
@@ -980,6 +967,8 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
return fieldValues;
}
+ if (!node.isConst()) error(node);
+
// TODO(floitsch): get the type from somewhere.
FunctionElement constructor = elements[node.send];
ClassElement classElement = constructor.enclosingElement;
@@ -992,8 +981,7 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
Map<Element, Constant> constructorDefinitions =
new Map<Element, Constant>();
- List<Constant> arguments = compileArguments();
- assignArgumentsToParameters(arguments, parameters, constructorDefinitions);
+ assignArgumentsToParameters(parameters, constructorDefinitions);
CompileTimeConstantEvaluator initializerEvaluator =
new CompileTimeConstantEvaluator.insideConstructor(
constantHandler, constructorElements, compiler,
« 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