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

Unified Diff: frog/leg/compile_time_constants.dart

Issue 9595017: Refactor constant part. (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 | frog/leg/ssa/builder.dart » ('j') | frog/leg/ssa/builder.dart » ('J')
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 d040a558db6bf0d8a83224e4d32599b375faf796..e43257d9ec087eb8e5ab0f36c3b9b2df21bac163 100644
--- a/frog/leg/compile_time_constants.dart
+++ b/frog/leg/compile_time_constants.dart
@@ -20,6 +20,16 @@ class Constant implements Hashable {
bool isNum() => isInt() || isDouble();
bool isObject() => isList() || isMap() || isConstructedObject();
+ bool isTrue() {
kasperl 2012/03/05 13:53:16 This smells like you should have two separate Bool
floitsch 2012/03/05 15:43:24 I will do that when I introduce caching for the co
+ if (!isBool()) return false;
+ BoolConstant boolConstant = this;
+ return boolConstant.value;
+ }
+ bool isFalse() {
+ if (!isBool()) return false;
+ BoolConstant boolConstant = this;
+ return !boolConstant.value;
+ }
/**
* Returns [:null:] if the operation is not supported on this constant.
@@ -55,6 +65,8 @@ class PrimitiveConstant extends Constant {
// We use == instead of === so that DartStrings compare correctly.
return value == otherPrimitive.value;
}
+
+ String toString() => value.toString();
}
class NullConstant extends PrimitiveConstant {
@@ -114,8 +126,8 @@ class IntConstant extends PrimitiveConstant {
case "<<":
// TODO(floitsch): find a better way to guard against shifts to the
// left.
- if (right > 100) null;
- if (right < 0) null;
+ if (right > 100) return null;
+ if (right < 0) return null;
return new IntConstant(value << right);
case ">>":
if (right < 0) return null;
@@ -296,14 +308,15 @@ class ListConstant extends ObjectConstant {
void writeJsCode(StringBuffer buffer, CompileTimeConstantHandler handler) {
// TODO(floitsch): we should not need to go through the compiler to make
// the list constant.
- buffer.add(handler.compiler.namer.ISOLATE);
- buffer.add(".prototype.makeConstantList");
+ String isolatePrototype = "${handler.compiler.namer.ISOLATE}.prototype";
+ buffer.add("$isolatePrototype.makeConstantList");
buffer.add("([");
for (int i = 0; i < entries.length; i++) {
if (i != 0) buffer.add(", ");
Constant entry = entries[i];
if (entry.isObject()) {
- handler.getNameForConstant(entry);
+ String name = handler.getNameForConstant(entry);
+ buffer.add("$isolatePrototype.$name");
} else {
entry.writeJsCode(buffer, handler);
}
@@ -418,18 +431,12 @@ class CompileTimeConstantHandler extends CompilerTask {
compileVariable(VariableElement element) {
if (initialVariableValues.containsKey(element)) {
Constant result = initialVariableValues[element];
- // TODO(floitsch): remove the following line once the rest of the
- // compiler has been adapted.
- if (!result.isObject()) return result.dynamic.value;
return result;
}
// TODO(floitsch): keep track of currently compiling elements so that we
// don't end up in an infinite loop: final x = y; final y = x;
TreeElements definitions = compiler.analyzeElement(element);
Constant constant = compileVariableWithDefinitions(element, definitions);
- // TODO(floitsch): remove the following line once the rest of the
- // compiler has been adapted.
- if (!constant.isObject()) return constant.dynamic.value;
return constant;
}
@@ -670,12 +677,7 @@ class CompileTimeConstantEvaluator extends AbstractVisitor {
!element.modifiers.isFinal()) {
error(send);
}
- // TODO(floitsch): compileVariable temporarily returns primitives, so
- // that the rest of the compiler can be adapted incrementally. Therefore
- // we have to get the constant from the hashtable instead of using the
- // returned result directly.
- constantHandler.compileVariable(element);
- return constantHandler.initialVariableValues[element];
+ return constantHandler.compileVariable(element);
} else if (send.isPrefix) {
assert(send.isOperator);
Constant receiverConstant = evaluate(send.receiver);
« no previous file with comments | « no previous file | frog/leg/ssa/builder.dart » ('j') | frog/leg/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698