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

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

Issue 9578021: Revert "Refactor constant part." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
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 | « dart/frog/leg/ssa/builder.dart ('k') | dart/frog/leg/ssa/nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/ssa/codegen.dart
diff --git a/dart/frog/leg/ssa/codegen.dart b/dart/frog/leg/ssa/codegen.dart
index 8dcea37326116f6160ad793be17c0b27d6d061c4..80d3b6d3654504a44836b1147322b7590b3a8d7c 100644
--- a/dart/frog/leg/ssa/codegen.dart
+++ b/dart/frog/leg/ssa/codegen.dart
@@ -654,19 +654,35 @@ class SsaCodeGenerator implements HVisitor {
endExpression(JSPrecedence.MEMBER_PRECEDENCE);
}
- 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);
+ 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("'");
} else {
- buffer.add(compiler.namer.CURRENT_ISOLATE);
- buffer.add(".");
- buffer.add(name);
+ buffer.add(node.value);
}
}
@@ -707,7 +723,7 @@ class SsaCodeGenerator implements HVisitor {
visitReturn(HReturn node) {
assert(node.inputs.length == 1);
HInstruction input = node.inputs[0];
- if (input.isConstantNull()) {
+ if (input.isLiteralNull()) {
buffer.add('return;\n');
} else {
buffer.add('return ');
« no previous file with comments | « dart/frog/leg/ssa/builder.dart ('k') | dart/frog/leg/ssa/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698