diff --git a/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java b/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java index 0ae823c60e5..9aef75583e0 100644 --- a/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java @@ -4,22 +4,8 @@ package com.google.dart.compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.JsArrayAccess; -import com.google.dart.compiler.backend.js.ast.JsArrayLiteral; -import com.google.dart.compiler.backend.js.ast.JsBinaryOperation; -import com.google.dart.compiler.backend.js.ast.JsConditional; -import com.google.dart.compiler.backend.js.ast.JsContext; -import com.google.dart.compiler.backend.js.ast.JsExprStmt; -import com.google.dart.compiler.backend.js.ast.JsExpression; -import com.google.dart.compiler.backend.js.ast.JsFunction; -import com.google.dart.compiler.backend.js.ast.JsInvocation; -import com.google.dart.compiler.backend.js.ast.JsNameRef; -import com.google.dart.compiler.backend.js.ast.JsNew; -import com.google.dart.compiler.backend.js.ast.JsObjectLiteral; -import com.google.dart.compiler.backend.js.ast.JsPostfixOperation; -import com.google.dart.compiler.backend.js.ast.JsPrefixOperation; -import com.google.dart.compiler.backend.js.ast.JsRegExp; -import com.google.dart.compiler.backend.js.ast.JsVisitor; +import com.google.dart.compiler.backend.js.ast.*; +import com.google.dart.compiler.backend.js.ast.JsExpressionStatement; /** * Determines if an expression statement needs to be surrounded by parentheses. @@ -45,7 +31,7 @@ import com.google.dart.compiler.backend.js.ast.JsVisitor; * */ public class JsFirstExpressionVisitor extends JsVisitor { - public static boolean exec(JsExprStmt statement) { + public static boolean exec(JsExpressionStatement statement) { JsExpression expression = statement.getExpression(); // Pure function declarations do not need parentheses if (expression instanceof JsFunction) { diff --git a/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java b/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java index a9632298819..bd611321d25 100644 --- a/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java @@ -121,7 +121,7 @@ class JsPrecedenceVisitor extends JsVisitor { } @Override - public boolean visit(JsExprStmt x, JsContext ctx) { + public boolean visit(JsExpressionStatement x, JsContext ctx) { throw new RuntimeException("Only expressions have precedence."); } diff --git a/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java b/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java index bd13ea3af72..229dedc5417 100644 --- a/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java @@ -4,25 +4,8 @@ package com.google.dart.compiler.backend.js; -import com.google.dart.compiler.backend.js.ast.JsBlock; -import com.google.dart.compiler.backend.js.ast.JsBreak; -import com.google.dart.compiler.backend.js.ast.JsContext; -import com.google.dart.compiler.backend.js.ast.JsDebugger; -import com.google.dart.compiler.backend.js.ast.JsDoWhile; -import com.google.dart.compiler.backend.js.ast.JsEmpty; -import com.google.dart.compiler.backend.js.ast.JsExprStmt; -import com.google.dart.compiler.backend.js.ast.JsFor; -import com.google.dart.compiler.backend.js.ast.JsForIn; -import com.google.dart.compiler.backend.js.ast.JsIf; -import com.google.dart.compiler.backend.js.ast.JsLabel; -import com.google.dart.compiler.backend.js.ast.JsReturn; -import com.google.dart.compiler.backend.js.ast.JsStatement; -import com.google.dart.compiler.backend.js.ast.JsSwitch; -import com.google.dart.compiler.backend.js.ast.JsThrow; -import com.google.dart.compiler.backend.js.ast.JsTry; -import com.google.dart.compiler.backend.js.ast.JsVars; -import com.google.dart.compiler.backend.js.ast.JsVisitor; -import com.google.dart.compiler.backend.js.ast.JsWhile; +import com.google.dart.compiler.backend.js.ast.*; +import com.google.dart.compiler.backend.js.ast.JsExpressionStatement; /** * Determines if a statement at the end of a block requires a semicolon. @@ -78,7 +61,7 @@ public class JsRequiresSemiVisitor extends JsVisitor { } @Override - public boolean visit(JsExprStmt x, JsContext ctx) { + public boolean visit(JsExpressionStatement x, JsContext ctx) { return false; } diff --git a/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java b/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java index 109664badb2..7e78a15e46a 100644 --- a/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java @@ -459,7 +459,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsExprStmt x, JsContext ctx) { + public boolean visit(JsExpressionStatement x, JsContext ctx) { boolean surroundWithParentheses = JsFirstExpressionVisitor.exec(x); if (surroundWithParentheses) { leftParen(); @@ -1022,7 +1022,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { * a newline instead of a semi. */ boolean functionStmt = - statement instanceof JsExprStmt && ((JsExprStmt) statement).getExpression() instanceof JsFunction; + statement instanceof JsExpressionStatement && ((JsExpressionStatement) statement).getExpression() instanceof JsFunction; /* * Special treatment of the last statement in a block: only a few * statements at the end of a block require semicolons. diff --git a/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java b/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java new file mode 100644 index 00000000000..582b7ac1adb --- /dev/null +++ b/src/com/google/dart/compiler/backend/js/ast/AbstractNode.java @@ -0,0 +1,14 @@ +package com.google.dart.compiler.backend.js.ast; + +import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor; +import com.google.dart.compiler.common.HasSourceInfo; +import com.google.dart.compiler.util.TextOutputImpl; + +abstract class AbstractNode implements JsNode, HasSourceInfo { + @Override + public String toString() { + TextOutputImpl out = new TextOutputImpl(); + new JsToStringGenerationVisitor(out).accept(this); + return out.toString(); + } +} \ No newline at end of file diff --git a/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java b/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java index 9e3238ae2df..00d1eaaf511 100644 --- a/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java +++ b/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java @@ -1,6 +1,5 @@ package com.google.dart.compiler.backend.js.ast; -import com.google.dart.compiler.Source; import com.google.dart.compiler.common.SourceInfo; public class ChameleonJsExpression implements JsExpression { @@ -61,34 +60,4 @@ public class ChameleonJsExpression implements JsExpression { public void setSourceInfo(SourceInfo info) { expression.setSourceInfo(info); } - - @Override - public void setSourceLocation(Source source, int line, int column, int startPosition, int length) { - expression.setSourceLocation(source, line, column, startPosition, length); - } - - @Override - public Source getSource() { - return expression.getSource(); - } - - @Override - public int getLine() { - return 0; - } - - @Override - public int getColumn() { - return expression.getColumn(); - } - - @Override - public int getStart() { - return expression.getStart(); - } - - @Override - public int getLength() { - return expression.getLength(); - } } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExpression.java b/src/com/google/dart/compiler/backend/js/ast/JsExpression.java index 5fb9a7e41f1..def914d6a70 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExpression.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsExpression.java @@ -1,9 +1,8 @@ package com.google.dart.compiler.backend.js.ast; import com.google.dart.compiler.common.HasSourceInfo; -import com.google.dart.compiler.common.SourceInfo; -public interface JsExpression extends JsNode, SourceInfo, HasSourceInfo, JsVisitable { +public interface JsExpression extends JsNode, HasSourceInfo, JsVisitable { /** * Determines whether the expression can cause side effects. */ diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java b/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java index f42ae1c26da..2e46db4bef9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java @@ -22,6 +22,6 @@ abstract class JsExpressionImpl extends JsNodeImpl implements JsExpression { @Override public JsStatement makeStmt() { - return new JsExprStmt(this); + return new JsExpressionStatement(this); } } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExprStmt.java b/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java similarity index 50% rename from src/com/google/dart/compiler/backend/js/ast/JsExprStmt.java rename to src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java index 6ab649f2cb4..1229f30c4db 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExprStmt.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java @@ -4,23 +4,23 @@ package com.google.dart.compiler.backend.js.ast; -public final class JsExprStmt extends JsNodeImpl implements JsStatement { - private JsExpression expr; +import com.google.dart.compiler.common.SourceInfo; - public JsExprStmt(JsExpression expr) { - super(); - this.expr = expr; - this.setSourceInfo(expr); +public final class JsExpressionStatement extends AbstractNode implements JsStatement { + private JsExpression expression; + + public JsExpressionStatement(JsExpression expression) { + this.expression = expression; } public JsExpression getExpression() { - return expr; + return expression; } @Override public void traverse(JsVisitor v, JsContext context) { if (v.visit(this, context)) { - expr = v.accept(expr); + expression = v.accept(expression); } v.endVisit(this, context); } @@ -29,4 +29,14 @@ public final class JsExprStmt extends JsNodeImpl implements JsStatement { public NodeKind getKind() { return NodeKind.EXPRESSION_STMT; } + + @Override + public SourceInfo getSourceInfo() { + return expression.getSourceInfo(); + } + + @Override + public void setSourceInfo(SourceInfo info) { + expression.setSourceInfo(info); + } } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsFor.java b/src/com/google/dart/compiler/backend/js/ast/JsFor.java index 65f24607696..4efb65d93c8 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFor.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsFor.java @@ -4,8 +4,6 @@ package com.google.dart.compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; - /** * A for statement. If specified at all, the initializer part is * either a declaration of one or more variables, in which case @@ -86,12 +84,6 @@ public class JsFor extends JsNodeImpl implements JsStatement { v.endVisit(this, context); } - @Override - public JsFor setSourceRef(SourceInfo info) { - super.setSourceRef(info); - return this; - } - @Override public NodeKind getKind() { return NodeKind.FOR; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsFunction.java b/src/com/google/dart/compiler/backend/js/ast/JsFunction.java index a4e9914100d..1d4bd4da308 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFunction.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsFunction.java @@ -4,7 +4,6 @@ package com.google.dart.compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; import com.google.dart.compiler.common.Symbol; import com.intellij.util.SmartList; import org.jetbrains.annotations.Nullable; @@ -28,7 +27,7 @@ public final class JsFunction extends JsLiteral implements HasName { private JsFunction(JsScope parentScope, @Nullable JsName name) { this.name = name; - this.scope = new JsScope(parentScope, name == null ? null : name.getIdent()); + scope = new JsScope(parentScope, name == null ? null : name.getIdent()); } public JsBlock getBody() { @@ -99,12 +98,6 @@ public final class JsFunction extends JsLiteral implements HasName { v.endVisit(this, context); } - @Override - public JsFunction setSourceRef(SourceInfo info) { - super.setSourceRef(info); - return this; - } - @Override public NodeKind getKind() { return NodeKind.FUNCTION; diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java b/src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java index 583f0e7de08..6128475681e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsNodeImpl.java @@ -1,30 +1,20 @@ package com.google.dart.compiler.backend.js.ast; -import com.google.dart.compiler.backend.js.JsToStringGenerationVisitor; -import com.google.dart.compiler.common.AbstractNode; import com.google.dart.compiler.common.SourceInfo; -import com.google.dart.compiler.util.TextOutputImpl; -abstract class JsNodeImpl extends AbstractNode implements JsNode { +abstract class JsNodeImpl extends AbstractNode { + private SourceInfo sourceInfo; + protected JsNodeImpl() { } @Override - public String toString() { - TextOutputImpl out = new TextOutputImpl(); - new JsToStringGenerationVisitor(out).accept(this); - return out.toString(); + public SourceInfo getSourceInfo() { + return sourceInfo; } @Override - public SourceInfo getSourceInfo() { - return this; + public void setSourceInfo(SourceInfo info) { + sourceInfo = info; } - - public JsNode setSourceRef(SourceInfo info) { - if (info != null) { - setSourceInfo(info); - } - return this; - } -} +} \ No newline at end of file diff --git a/src/com/google/dart/compiler/backend/js/ast/JsVars.java b/src/com/google/dart/compiler/backend/js/ast/JsVars.java index 18617861955..638a50ef496 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsVars.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsVars.java @@ -4,7 +4,6 @@ package com.google.dart.compiler.backend.js.ast; -import com.google.dart.compiler.common.SourceInfo; import com.google.dart.compiler.common.Symbol; import com.intellij.util.SmartList; import org.jetbrains.annotations.Nullable; @@ -91,12 +90,6 @@ public class JsVars extends JsNodeImpl implements JsStatement, Iterable= 0 || startPosition == -1 && length == 0); - //sourceInfo.sourceStart = startPosition; - //sourceInfo.sourceLength = length; - } -} diff --git a/src/com/google/dart/compiler/common/HasSourceInfo.java b/src/com/google/dart/compiler/common/HasSourceInfo.java index c7780f6acee..524ed667467 100644 --- a/src/com/google/dart/compiler/common/HasSourceInfo.java +++ b/src/com/google/dart/compiler/common/HasSourceInfo.java @@ -4,52 +4,15 @@ package com.google.dart.compiler.common; -import com.google.dart.compiler.Source; - -/** - * Abstract view of a class that has source info. - */ public interface HasSourceInfo { - /** * Return the source info associated with this object. */ SourceInfo getSourceInfo(); /** - * Set the source info associated with this object. May only be called once. + * Set the source info associated with this object. * @param info */ void setSourceInfo(SourceInfo info); - - /** - * Sets the source range of the original source file where the source fragment - * corresponding to this node was found. - * - *

- * Each node in the subtree (other than the contrived nodes) carries source - * range(s) information relating back to positions in the given source (the - * given source itself is not remembered with the AST). The source range - * usually begins at the first character of the first token corresponding to - * the node; leading whitespace and comments are not included. The - * source range usually extends through the last character of the last token - * corresponding to the node; trailing whitespace and comments are not - * included. There are a handful of exceptions (including the various body - * declarations). Source ranges nest properly: the source range for a child is - * always within the source range of its parent, and the source ranges of - * sibling nodes never overlap. - * - * @param source the associated source - * @param line the 1-based line index, or -1, if no source - * location is available - * @param column the 1-based column index, or -1, if no source - * location is available - * @param startPosition a 0-based character index, or -1, if no - * source location is available - * @param length a (possibly 0) length, or -1, if no source - * location is available - * @see SourceInfo#getStart() - * @see SourceInfo#getLength() - */ - void setSourceLocation(Source source, int line, int column, int startPosition, int length); }