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

Unified Diff: frog/leg/compile_time_constants.dart

Issue 9443017: Implement hackish version of const list literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 10 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 | tests/co19/co19-leg.status » ('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 5238ad99662ef570928f438bf90c690dedf3ee51..151610510951f0d00e44f866d2c44ed312b8471a 100644
--- a/frog/leg/compile_time_constants.dart
+++ b/frog/leg/compile_time_constants.dart
@@ -35,6 +35,11 @@ class CompileTimeConstantHandler extends CompilerTask {
super(compiler);
String get name() => 'CompileTimeConstantHandler';
+ void registerCompileTimeConstant(Constant constant) {
+ Function ifAbsentThunk = (() => compiler.namer.getFreshGlobalName("CTC"));
+ compiledConstants.putIfAbsent(constant, ifAbsentThunk);
+ }
+
/**
* Compiles the initial value of the given field and stores it in an internal
* map.
@@ -102,8 +107,27 @@ class CompileTimeConstantHandler extends CompilerTask {
Namer namer = compiler.namer;
String instantiation = "new ${namer.isolatePropertyAccess(classElement)}()";
Constant constant = new Constant(instantiation);
- compiledConstants.putIfAbsent(constant,
- () => namer.getFreshGlobalName("CTC"));
+ registerCompileTimeConstant(constant);
+ return constant;
+ }
+
+ compileListLiteral(Node node, List arguments) {
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < arguments.length; i++) {
+ if (i != 0) buffer.add(", ");
+ if (arguments[i] is Constant) {
+ // TODO(floitsch): canonicalize if the constant is in the
+ // [compiledConstant] set.
+ Constant constant = arguments[i];
+ buffer.add(constant.jsCode);
+ } else {
+ writeJsCode(buffer, arguments[i]);
+ }
+ }
+ // TODO(floitsch): do we have to register 'List' as instantiated class?
+ String array = "[$buffer]";
+ Constant constant = new Constant(array);
+ registerCompileTimeConstant(constant);
return constant;
}
@@ -141,9 +165,7 @@ class CompileTimeConstantHandler extends CompilerTask {
return compiledConstants[constant];
}
- StringBuffer writeJsCodeForVariable(StringBuffer buffer,
- VariableElement element) {
- var value = initialVariableValues[element];
+ StringBuffer writeJsCode(StringBuffer buffer, var value) {
if (value === null) {
buffer.add("(void 0)");
} else if (value is num) {
@@ -175,7 +197,12 @@ class CompileTimeConstantHandler extends CompilerTask {
"writeJsCodeForVariable",
element: element);
}
- return buffer;
+ return buffer;
+ }
+
+ StringBuffer writeJsCodeForVariable(StringBuffer buffer,
+ VariableElement element) {
+ return writeJsCode(buffer, initialVariableValues[element]);
}
/**
@@ -360,6 +387,17 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
arguments);
}
+ visitLiteralList(LiteralList node) {
+ if (!node.isConst()) error(node);
+ List arguments = [];
+ for (Link<Node> link = node.elements.nodes;
+ !link.isEmpty();
+ link = link.tail) {
+ arguments.add(evaluate(link.head));
+ }
+ return constantHandler.compileListLiteral(node, arguments);
+ }
+
error(Node node) {
// TODO(floitsch): get the list of constants that are currently compiled
// and present some kind of stack-trace.
« no previous file with comments | « no previous file | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698