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

Unified Diff: frog/leg/ssa/codegen.dart

Issue 9592009: Reapply "Refactor constant part." (r4958) with fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add TODO. 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 | « frog/leg/ssa/builder.dart ('k') | frog/leg/ssa/nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/ssa/codegen.dart
diff --git a/frog/leg/ssa/codegen.dart b/frog/leg/ssa/codegen.dart
index c96ac9a21bd0a1333df6c3423358cadbea440f33..193208ed74ba4c8cf297afc9e529fba31a586bfe 100644
--- a/frog/leg/ssa/codegen.dart
+++ b/frog/leg/ssa/codegen.dart
@@ -660,35 +660,19 @@ class SsaCodeGenerator implements HVisitor {
endExpression(JSPrecedence.MEMBER_PRECEDENCE);
}
- visitLiteral(HLiteral node) {
- if (node.isLiteralNull()) {
- beginExpression(JSPrecedence.PREFIX_PRECEDENCE);
- buffer.add("void 0");
- endExpression(JSPrecedence.PREFIX_PRECEDENCE);
- } else if (node.value is num) {
- int precedence = JSPrecedence.PRIMARY_PRECEDENCE;
- if (node.value < 0 ||
- expectedPrecedence == JSPrecedence.MEMBER_PRECEDENCE) {
- // Negative constants are really unary minus operator expressions.
- // If the constant appear as a MemberExpression, it might be subject
- // to the '.' operator, which shouldn't be put next to a number
- // literal. It might be mistaken for a decimal point. Setting
- // precedence to PREFIX_PRECEDENCE forces parentheses in this case.
- precedence = JSPrecedence.PREFIX_PRECEDENCE;
- }
- beginExpression(precedence);
- buffer.add(node.value);
- endExpression(precedence);
- } else if (node.isLiteralString()) {
- DartString string = node.value;
- buffer.add("'");
- CompileTimeConstantHandler.writeEscapedString(string, buffer,
- (String reason) {
- compiler.cancel(reason, instruction: node);
- });
- buffer.add("'");
+ visitConstant(HConstant node) {
+ // TODO(floitsch): the compile-time constant handler and the codegen
+ // need to work together to avoid the parenthesis. See r4928 for an
+ // implementation that still dealt with precedence.
+ ConstantHandler handler = compiler.constantHandler;
+ String name = handler.getNameForConstant(node.constant);
+ if (name === null) {
+ assert(!node.constant.isObject());
+ node.constant.writeJsCode(buffer, handler);
} else {
- buffer.add(node.value);
+ buffer.add(compiler.namer.CURRENT_ISOLATE);
+ buffer.add(".");
+ buffer.add(name);
}
}
@@ -729,7 +713,7 @@ class SsaCodeGenerator implements HVisitor {
visitReturn(HReturn node) {
assert(node.inputs.length == 1);
HInstruction input = node.inputs[0];
- if (input.isLiteralNull()) {
+ if (input.isConstantNull()) {
buffer.add('return;\n');
} else {
buffer.add('return ');
« no previous file with comments | « frog/leg/ssa/builder.dart ('k') | frog/leg/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698