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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart

Issue 574683002: Use ConstExp for storing constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove ConstExpBuilder. Created 6 years, 3 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
Index: sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
index 8cf19cc9041cf321923048e918d95763e2ebe8c3..cbc86b0e5c588b079aab7904ae705a3726634c47 100644
--- a/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/dart_backend/backend_ast_emitter.dart
@@ -670,7 +670,7 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
ASTEmitter parent;
ConstantEmitter(this.parent);
- Expression visitPrimitive(PrimitiveConstExp exp) {
+ Expression handlePrimitiveConstant(dart2js.PrimitiveConstant value) {
// Num constants may be negative, while literals must be non-negative:
// Literals are non-negative in the specification, and a negated literal
// parses as a call to unary `-`. The AST unparser assumes literals are
@@ -678,13 +678,17 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
// the predecrement operator.
// Translate such constants into their positive value wrapped by
// the unary minus operator.
- if (exp.constant is dart2js.NumConstant) {
- dart2js.NumConstant numConstant = exp.constant;
+ if (value is dart2js.NumConstant) {
+ dart2js.NumConstant numConstant = value;
if (numConstant.value.isNegative) {
return negatedLiteral(numConstant);
}
}
- return new Literal(exp.constant);
+ return new Literal(value);
+ }
+
+ Expression visitPrimitive(PrimitiveConstExp exp) {
+ return handlePrimitiveConstant(exp.value);
}
/// Given a negative num constant, returns the corresponding positive
@@ -769,6 +773,24 @@ class ConstantEmitter extends ConstExpVisitor<Expression> {
..element = exp.element;
}
+ @override
sigurdm 2014/09/17 10:29:41 Maybe add override to all the overriding methods
Johnni Winther 2014/09/17 12:20:40 Done.
+ Expression visitBinary(BinaryConstExp exp) {
+ return handlePrimitiveConstant(exp.value);
+ }
+
+ @override
+ Expression visitConditional(ConditionalConstExp exp) {
+ if (exp.condition.value.isTrue) {
+ return exp.trueExp.accept(this);
+ } else {
+ return exp.falseExp.accept(this);
+ }
+ }
+
+ @override
+ Expression visitUnary(UnaryConstExp exp) {
+ return handlePrimitiveConstant(exp.value);
+ }
}
/// Moves function parameters into a separate variable if one of its uses is

Powered by Google App Engine
This is Rietveld 408576698