This commit is contained in:
develar
2012-10-23 18:57:54 +04:00
parent af75857523
commit 536803e314
6 changed files with 71 additions and 75 deletions
@@ -100,7 +100,7 @@ public class JsRequiresSemiVisitor extends JsVisitor {
@Override @Override
public boolean visit(JsLabel x, JsContext ctx) { public boolean visit(JsLabel x, JsContext ctx) {
if (x.getStmt() instanceof JsEmpty) { if (x.getStatement() instanceof JsEmpty) {
needsSemicolon = true; needsSemicolon = true;
} }
return false; return false;
@@ -312,10 +312,10 @@ public class JsToStringGenerationVisitor extends JsVisitor {
} }
private void continueOrBreakLabel(JsContinue x) { private void continueOrBreakLabel(JsContinue x) {
JsNameRef label = x.getLabel(); String label = x.getLabel();
if (label != null) { if (label != null) {
space(); space();
_nameRef(label); p.print(label);
} }
} }
@@ -475,8 +475,8 @@ public class JsToStringGenerationVisitor extends JsVisitor {
// The init expressions or var decl. // The init expressions or var decl.
// //
if (x.getInitExpr() != null) { if (x.getInitExpression() != null) {
accept(x.getInitExpr()); accept(x.getInitExpression());
} }
else if (x.getInitVars() != null) { else if (x.getInitVars() != null) {
accept(x.getInitVars()); accept(x.getInitVars());
@@ -495,9 +495,9 @@ public class JsToStringGenerationVisitor extends JsVisitor {
// The incr expression. // The incr expression.
// //
if (x.getIncrExpr() != null) { if (x.getIncrementExpression() != null) {
spaceOpt(); spaceOpt();
accept(x.getIncrExpr()); accept(x.getIncrementExpression());
} }
rightParen(); rightParen();
@@ -619,7 +619,7 @@ public class JsToStringGenerationVisitor extends JsVisitor {
nameOf(x); nameOf(x);
_colon(); _colon();
spaceOpt(); spaceOpt();
accept(x.getStmt()); accept(x.getStatement());
return false; return false;
} }
@@ -12,7 +12,7 @@ public final class JsBreak extends JsContinue {
super(null); super(null);
} }
public JsBreak(JsNameRef label) { public JsBreak(String label) {
super(label); super(label);
} }
@@ -23,11 +23,7 @@ public final class JsBreak extends JsContinue {
@Override @Override
public void traverse(JsVisitor v, JsContext context) { public void traverse(JsVisitor v, JsContext context) {
if (v.visit(this, context)) { v.visit(this, context);
if (label != null) {
v.accept(label);
}
}
v.endVisit(this, context); v.endVisit(this, context);
} }
} }
@@ -10,28 +10,24 @@ import org.jetbrains.annotations.Nullable;
* Represents the JavaScript continue statement. * Represents the JavaScript continue statement.
*/ */
public class JsContinue extends JsNodeImpl implements JsStatement { public class JsContinue extends JsNodeImpl implements JsStatement {
protected final JsNameRef label; protected final String label;
public JsContinue() { public JsContinue() {
this(null); this(null);
} }
public JsContinue(@Nullable JsNameRef label) { public JsContinue(@Nullable String label) {
super(); super();
this.label = label; this.label = label;
} }
public JsNameRef getLabel() { public String getLabel() {
return label; return label;
} }
@Override @Override
public void traverse(JsVisitor v, JsContext context) { public void traverse(JsVisitor v, JsContext context) {
if (v.visit(this, context)) { v.visit(this, context);
if (label != null) {
v.accept(label);
}
}
v.endVisit(this, context); v.endVisit(this, context);
} }
@@ -8,7 +8,7 @@ package com.google.dart.compiler.backend.js.ast;
* A <code>for</code> statement. If specified at all, the initializer part is * A <code>for</code> statement. If specified at all, the initializer part is
* either a declaration of one or more variables, in which case * either a declaration of one or more variables, in which case
* {@link #getInitVars()} is used, or an expression, in which case * {@link #getInitVars()} is used, or an expression, in which case
* {@link #getInitExpr()} is used. In the latter case, the comma operator is * {@link #getInitExpression()} is used. In the latter case, the comma operator is
* often used to create a compound expression. * often used to create a compound expression.
* <p/> * <p/>
* <p/> * <p/>
@@ -18,20 +18,20 @@ package com.google.dart.compiler.backend.js.ast;
public class JsFor extends JsNodeImpl implements JsStatement { public class JsFor extends JsNodeImpl implements JsStatement {
private JsStatement body; private JsStatement body;
private JsExpression condition; private JsExpression condition;
private JsExpression incrExpr; private JsExpression incrementExpression;
private JsExpression initExpr; private JsExpression initExpression;
private JsVars initVars; private JsVars initVars;
public JsFor(JsVars initVars, JsExpression condition, JsExpression incrementExpr) { public JsFor(JsVars initVars, JsExpression condition, JsExpression incrementExpression) {
this.initVars = initVars; this.initVars = initVars;
this.incrExpr = incrementExpr; this.incrementExpression = incrementExpression;
this.condition = condition; this.condition = condition;
initExpr = null; initExpression = null;
} }
public JsFor(JsExpression initExpr, JsExpression condition, JsExpression incrementExpr) { public JsFor(JsExpression initExpression, JsExpression condition, JsExpression incrementExpression) {
this.initExpr = initExpr; this.initExpression = initExpression;
this.incrExpr = incrementExpr; this.incrementExpression = incrementExpression;
this.condition = condition; this.condition = condition;
initVars = null; initVars = null;
} }
@@ -44,12 +44,12 @@ public class JsFor extends JsNodeImpl implements JsStatement {
return condition; return condition;
} }
public JsExpression getIncrExpr() { public JsExpression getIncrementExpression() {
return incrExpr; return incrementExpression;
} }
public JsExpression getInitExpr() { public JsExpression getInitExpression() {
return initExpr; return initExpression;
} }
public JsVars getInitVars() { public JsVars getInitVars() {
@@ -63,10 +63,10 @@ public class JsFor extends JsNodeImpl implements JsStatement {
@Override @Override
public void traverse(JsVisitor v, JsContext context) { public void traverse(JsVisitor v, JsContext context) {
if (v.visit(this, context)) { if (v.visit(this, context)) {
assert (!(initExpr != null && initVars != null)); assert (!(initExpression != null && initVars != null));
if (initExpr != null) { if (initExpression != null) {
initExpr = v.accept(initExpr); initExpression = v.accept(initExpression);
} }
else if (initVars != null) { else if (initVars != null) {
initVars = v.accept(initVars); initVars = v.accept(initVars);
@@ -76,8 +76,8 @@ public class JsFor extends JsNodeImpl implements JsStatement {
condition = v.accept(condition); condition = v.accept(condition);
} }
if (incrExpr != null) { if (incrementExpression != null) {
incrExpr = v.accept(incrExpr); incrementExpression = v.accept(incrementExpression);
} }
body = v.accept(body); body = v.accept(body);
} }
@@ -10,43 +10,47 @@ import com.google.dart.compiler.common.Symbol;
* Represents a JavaScript label statement. * Represents a JavaScript label statement.
*/ */
public class JsLabel extends JsNodeImpl implements JsStatement, HasName { public class JsLabel extends JsNodeImpl implements JsStatement, HasName {
private final JsName label;
private final JsName label; private JsStatement statement;
private JsStatement stmt; public JsLabel(JsName label) {
this.label = label;
public JsLabel(JsName label) {
this.label = label;
}
@Override
public JsName getName() {
return label;
}
@Override
public Symbol getSymbol() {
return label;
}
public JsStatement getStmt() {
return stmt;
}
public void setStmt(JsStatement stmt) {
this.stmt = stmt;
}
@Override
public void traverse(JsVisitor v, JsContext context) {
if (v.visit(this, context)) {
stmt = v.accept(stmt);
} }
v.endVisit(this, context);
}
@Override public JsLabel(JsName label, JsStatement statement) {
public NodeKind getKind() { this.label = label;
return NodeKind.LABEL; this.statement = statement;
} }
@Override
public JsName getName() {
return label;
}
@Override
public Symbol getSymbol() {
return label;
}
public JsStatement getStatement() {
return statement;
}
public void setStatement(JsStatement statement) {
this.statement = statement;
}
@Override
public void traverse(JsVisitor v, JsContext context) {
if (v.visit(this, context)) {
statement = v.accept(statement);
}
v.endVisit(this, context);
}
@Override
public NodeKind getKind() {
return NodeKind.LABEL;
}
} }