From 4b2c170c000621757eac3bdff7bc8d581870f4a2 Mon Sep 17 00:00:00 2001 From: develar Date: Thu, 25 Oct 2012 09:27:11 +0400 Subject: [PATCH] simplify AST (idea like) --- .../js/JsConstructExpressionVisitor.java | 23 +-- .../backend/js/JsFirstExpressionVisitor.java | 35 ++-- .../backend/js/JsPrecedenceVisitor.java | 177 +++-------------- .../backend/js/JsRequiresSemiVisitor.java | 148 +++++--------- .../js/JsToStringGenerationVisitor.java | 137 +++++-------- .../backend/js/ast/JsArrayAccess.java | 2 +- .../backend/js/ast/JsArrayLiteral.java | 2 +- .../backend/js/ast/JsBinaryOperation.java | 2 +- .../dart/compiler/backend/js/ast/JsBlock.java | 2 +- .../dart/compiler/backend/js/ast/JsBreak.java | 2 +- .../dart/compiler/backend/js/ast/JsCase.java | 2 +- .../dart/compiler/backend/js/ast/JsCatch.java | 2 +- .../backend/js/ast/JsConditional.java | 2 +- .../compiler/backend/js/ast/JsContinue.java | 2 +- .../compiler/backend/js/ast/JsDebugger.java | 2 +- .../compiler/backend/js/ast/JsDefault.java | 2 +- .../compiler/backend/js/ast/JsDoWhile.java | 5 +- .../compiler/backend/js/ast/JsDocComment.java | 3 +- .../dart/compiler/backend/js/ast/JsEmpty.java | 2 +- .../backend/js/ast/JsExpressionStatement.java | 2 +- .../dart/compiler/backend/js/ast/JsFor.java | 2 +- .../dart/compiler/backend/js/ast/JsForIn.java | 4 +- .../compiler/backend/js/ast/JsFunction.java | 2 +- .../dart/compiler/backend/js/ast/JsIf.java | 2 +- .../compiler/backend/js/ast/JsInvocation.java | 2 +- .../dart/compiler/backend/js/ast/JsLabel.java | 2 +- .../compiler/backend/js/ast/JsLiteral.java | 4 +- .../compiler/backend/js/ast/JsNameRef.java | 2 +- .../dart/compiler/backend/js/ast/JsNew.java | 2 +- .../backend/js/ast/JsNullLiteral.java | 2 +- .../backend/js/ast/JsNumberLiteral.java | 4 +- .../backend/js/ast/JsObjectLiteral.java | 2 +- .../compiler/backend/js/ast/JsParameter.java | 2 +- .../backend/js/ast/JsPostfixOperation.java | 2 +- .../backend/js/ast/JsPrefixOperation.java | 2 +- .../compiler/backend/js/ast/JsProgram.java | 2 +- .../backend/js/ast/JsProgramFragment.java | 2 +- .../backend/js/ast/JsPropertyInitializer.java | 2 +- .../compiler/backend/js/ast/JsRegExp.java | 2 +- .../compiler/backend/js/ast/JsReturn.java | 2 +- .../backend/js/ast/JsStringLiteral.java | 2 +- .../dart/compiler/backend/js/ast/JsThrow.java | 2 +- .../dart/compiler/backend/js/ast/JsTry.java | 2 +- .../dart/compiler/backend/js/ast/JsVars.java | 2 +- .../compiler/backend/js/ast/JsVisitor.java | 183 +++++++++--------- .../dart/compiler/backend/js/ast/JsWhile.java | 2 +- .../backend/js/ast/RecursiveJsVisitor.java | 4 + 47 files changed, 278 insertions(+), 519 deletions(-) diff --git a/src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java b/src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java index 38882310ca0..e6422c43d2a 100644 --- a/src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsConstructExpressionVisitor.java @@ -10,7 +10,7 @@ import com.google.dart.compiler.backend.js.ast.*; * Searches for method invocations in constructor expressions that would not * normally be surrounded by parentheses. */ -public class JsConstructExpressionVisitor extends JsVisitor { +public class JsConstructExpressionVisitor extends RecursiveJsVisitor { public static boolean exec(JsExpression expression) { if (JsPrecedenceVisitor.exec(expression) < JsPrecedenceVisitor.PRECEDENCE_NEW) { return true; @@ -29,55 +29,48 @@ public class JsConstructExpressionVisitor extends JsVisitor { * We only look at the array expression since the index has its own scope. */ @Override - public boolean visit(JsArrayAccess x, JsContext ctx) { + public void visitArrayAccess(JsArrayAccess x, JsContext ctx) { accept(x.getArrayExpression()); - return false; } /** * Array literals have their own scoping. */ @Override - public boolean visit(JsArrayLiteral x, JsContext ctx) { - return false; + public void visitArray(JsArrayLiteral x, JsContext ctx) { } /** * Functions have their own scoping. */ @Override - public boolean visit(JsFunction x, JsContext ctx) { - return false; + public void visitFunction(JsFunction x, JsContext ctx) { } @Override - public boolean visit(JsInvocation x, JsContext ctx) { + public void visitInvocation(JsInvocation x, JsContext ctx) { containsInvocation = true; - return false; } @Override - public boolean visit(JsNameRef x, JsContext ctx) { + public void visitNameRef(JsNameRef x, JsContext ctx) { if (!x.isLeaf()) { accept(x.getQualifier()); } - return false; } /** * New constructs bind to the nearest set of parentheses. */ @Override - public boolean visit(JsNew x, JsContext ctx) { - return false; + public void visitNew(JsNew x, JsContext ctx) { } /** * Object literals have their own scope. */ @Override - public boolean visit(JsObjectLiteral x, JsContext ctx) { - return false; + public void visitObjectLiteral(JsObjectLiteral x, JsContext ctx) { } /** diff --git a/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java b/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java index 4b6a80ef4af..4901391d1c4 100644 --- a/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsFirstExpressionVisitor.java @@ -30,7 +30,7 @@ import com.google.dart.compiler.backend.js.ast.JsExpressionStatement; *
  • function() {}
  • * */ -public class JsFirstExpressionVisitor extends JsVisitor { +public class JsFirstExpressionVisitor extends RecursiveJsVisitor { public static boolean exec(JsExpressionStatement statement) { JsExpression expression = statement.getExpression(); // Pure function declarations do not need parentheses @@ -49,67 +49,56 @@ public class JsFirstExpressionVisitor extends JsVisitor { } @Override - public boolean visit(JsArrayAccess x, JsContext ctx) { + public void visitArrayAccess(JsArrayAccess x, JsContext ctx) { accept(x.getArrayExpression()); - return false; } @Override - public boolean visit(JsArrayLiteral x, JsContext ctx) { - return false; + public void visitArray(JsArrayLiteral x, JsContext ctx) { } @Override - public boolean visit(JsBinaryOperation x, JsContext ctx) { + public void visitBinaryExpression(JsBinaryOperation x, JsContext ctx) { accept(x.getArg1()); - return false; } @Override - public boolean visit(JsConditional x, JsContext ctx) { + public void visitConditional(JsConditional x, JsContext ctx) { accept(x.getTestExpression()); - return false; } @Override - public boolean visit(JsFunction x, JsContext ctx) { + public void visitFunction(JsFunction x, JsContext ctx) { needsParentheses = true; - return false; } @Override - public boolean visit(JsInvocation x, JsContext ctx) { + public void visitInvocation(JsInvocation x, JsContext ctx) { accept(x.getQualifier()); - return false; } @Override - public boolean visit(JsNameRef x, JsContext ctx) { + public void visitNameRef(JsNameRef x, JsContext ctx) { if (!x.isLeaf()) { accept(x.getQualifier()); } - return false; } @Override - public boolean visit(JsNew x, JsContext ctx) { - return false; + public void visitNew(JsNew x, JsContext ctx) { } @Override - public boolean visit(JsObjectLiteral x, JsContext ctx) { + public void visitObjectLiteral(JsObjectLiteral x, JsContext ctx) { needsParentheses = true; - return false; } @Override - public boolean visit(JsPostfixOperation x, JsContext ctx) { + public void visitPostfixOperation(JsPostfixOperation x, JsContext ctx) { accept(x.getArg()); - return false; } @Override - public boolean visit(JsPrefixOperation x, JsContext ctx) { - return false; + public void visitPrefixOperation(JsPrefixOperation x, JsContext ctx) { } } diff --git a/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java b/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java index 80698165d3c..28625e07e85 100644 --- a/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsPrecedenceVisitor.java @@ -5,7 +5,6 @@ package com.google.dart.compiler.backend.js; import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; /** * Precedence indices from "JavaScript - The Definitive Guide" 4th Edition (page @@ -31,6 +30,11 @@ import com.google.dart.compiler.backend.js.ast.JsVars.JsVar; class JsPrecedenceVisitor extends JsVisitor { static final int PRECEDENCE_NEW = 15; + private int answer = -1; + + private JsPrecedenceVisitor() { + } + public static int exec(JsExpression expression) { JsPrecedenceVisitor visitor = new JsPrecedenceVisitor(); visitor.accept(expression); @@ -40,237 +44,108 @@ class JsPrecedenceVisitor extends JsVisitor { return visitor.answer; } - private int answer = -1; - - private JsPrecedenceVisitor() { - } - @Override - public boolean visit(JsArrayAccess x, JsContext ctx) { + public void visitArrayAccess(JsArrayAccess x, JsContext ctx) { answer = 16; - return false; } @Override - public boolean visit(JsArrayLiteral x, JsContext ctx) { + public void visitArray(JsArrayLiteral x, JsContext ctx) { answer = 17; // primary - return false; } @Override - public boolean visit(JsBinaryOperation x, JsContext ctx) { + public void visitBinaryExpression(JsBinaryOperation x, JsContext ctx) { answer = x.getOperator().getPrecedence(); - return false; } @Override - public boolean visit(JsBlock x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsLiteral.JsBooleanLiteral x, JsContext ctx) { + public void visitBoolean(JsLiteral.JsBooleanLiteral x, JsContext ctx) { answer = 17; // primary - return false; } @Override - public boolean visit(JsBreak x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsCase x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsCatch x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsConditional x, JsContext ctx) { + public void visitConditional(JsConditional x, JsContext ctx) { answer = 3; - return false; } @Override - public boolean visit(JsContinue x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsDebugger x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsDefault x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsDoWhile x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public void visit(JsEmpty x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsExpressionStatement x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsFor x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsForIn x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsFunction x, JsContext ctx) { + public void visitFunction(JsFunction x, JsContext ctx) { answer = 17; // primary - return false; } @Override - public boolean visit(JsIf x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsInvocation x, JsContext ctx) { + public void visitInvocation(JsInvocation x, JsContext ctx) { answer = 16; - return false; } @Override - public boolean visit(JsLabel x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsNameRef x, JsContext ctx) { + public void visitNameRef(JsNameRef x, JsContext ctx) { if (x.isLeaf()) { answer = 17; // primary } else { answer = 16; // property access } - return false; } @Override - public boolean visit(JsNew x, JsContext ctx) { + public void visitNew(JsNew x, JsContext ctx) { answer = PRECEDENCE_NEW; - return false; } @Override - public void visit(JsNullLiteral x, JsContext ctx) { + public void visitNull(JsNullLiteral x, JsContext ctx) { answer = 17; // primary } @Override - public void visit(JsNumberLiteral.JsIntLiteral x, JsContext ctx) { + public void visitInt(JsNumberLiteral.JsIntLiteral x, JsContext ctx) { answer = 17; // primary } @Override - public void visit(JsNumberLiteral.JsDoubleLiteral x, JsContext ctx) { + public void visitDouble(JsNumberLiteral.JsDoubleLiteral x, JsContext ctx) { answer = 17; // primary } @Override - public boolean visit(JsObjectLiteral x, JsContext ctx) { + public void visitObjectLiteral(JsObjectLiteral x, JsContext ctx) { answer = 17; // primary - return false; } @Override - public boolean visit(JsParameter x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsPostfixOperation x, JsContext ctx) { + public void visitPostfixOperation(JsPostfixOperation x, JsContext ctx) { answer = x.getOperator().getPrecedence(); - return false; } @Override - public boolean visit(JsPrefixOperation x, JsContext ctx) { + public void visitPrefixOperation(JsPrefixOperation x, JsContext ctx) { answer = x.getOperator().getPrecedence(); - return false; } @Override - public boolean visit(JsProgram x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsPropertyInitializer x, JsContext ctx) { - answer = 17; // primary - return false; - } - - @Override - public void visit(JsRegExp x, JsContext ctx) { + public void visitPropertyInitializer(JsPropertyInitializer x, JsContext ctx) { answer = 17; // primary } @Override - public boolean visit(JsReturn x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public void visit(JsStringLiteral x, JsContext ctx) { + public void visitRegExp(JsRegExp x, JsContext ctx) { answer = 17; // primary } @Override - public boolean visit(JsSwitch x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsLiteral.JsThisRef x, JsContext ctx) { + public void visitString(JsStringLiteral x, JsContext ctx) { answer = 17; // primary - return false; } @Override - public boolean visit(JsThrow x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); + public void visitThis(JsLiteral.JsThisRef x, JsContext ctx) { + answer = 17; // primary } @Override - public boolean visit(JsTry x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsVar x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsVars x, JsContext ctx) { - throw new RuntimeException("Only expressions have precedence."); - } - - @Override - public boolean visit(JsWhile x, JsContext ctx) { + protected void visitElement(JsNode node, JsContext context) { 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 7bc6e95da5a..9cebe950c2b 100644 --- a/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsRequiresSemiVisitor.java @@ -5,17 +5,16 @@ package com.google.dart.compiler.backend.js; 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. - * + *

    * For example, the following statements require semicolons:
    *

    - * + *

    * The following do not require semicolons:
    *

    */ public class JsRequiresSemiVisitor extends JsVisitor { + private boolean needsSemicolon; - public static boolean exec(JsStatement lastStatement) { - JsRequiresSemiVisitor visitor = new JsRequiresSemiVisitor(); - visitor.accept(lastStatement); - return visitor.needsSemicolon; - } - - private boolean needsSemicolon = false; - - private JsRequiresSemiVisitor() { - } - - @Override - public boolean visit(JsBlock x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsBreak x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsDebugger x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsDoWhile x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsExpressionStatement x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsFor x, JsContext ctx) { - if (x.getBody() instanceof JsEmpty) { - needsSemicolon = true; + private JsRequiresSemiVisitor() { } - return false; - } - @Override - public boolean visit(JsForIn x, JsContext ctx) { - if (x.getBody() instanceof JsEmpty) { - needsSemicolon = true; + public static boolean exec(JsStatement lastStatement) { + JsRequiresSemiVisitor visitor = new JsRequiresSemiVisitor(); + visitor.accept(lastStatement); + return visitor.needsSemicolon; } - return false; - } - @Override - public boolean visit(JsIf x, JsContext ctx) { - JsStatement thenStmt = x.getThenStatement(); - JsStatement elseStmt = x.getElseStatement(); - JsStatement toCheck = thenStmt; - if (elseStmt != null) { - toCheck = elseStmt; + @Override + public void visitFor(JsFor x, JsContext ctx) { + if (x.getBody() instanceof JsEmpty) { + needsSemicolon = true; + } } - if (toCheck instanceof JsEmpty) { - needsSemicolon = true; - } else { - // Must recurse to determine last statement (possible if-else chain). - accept(toCheck); + + @Override + public void visitForIn(JsForIn x, JsContext ctx) { + if (x.getBody() instanceof JsEmpty) { + needsSemicolon = true; + } } - return false; - } - @Override - public boolean visit(JsLabel x, JsContext ctx) { - if (x.getStatement() instanceof JsEmpty) { - needsSemicolon = true; + @Override + public void visitIf(JsIf x, JsContext ctx) { + JsStatement thenStmt = x.getThenStatement(); + JsStatement elseStmt = x.getElseStatement(); + JsStatement toCheck = thenStmt; + if (elseStmt != null) { + toCheck = elseStmt; + } + if (toCheck instanceof JsEmpty) { + needsSemicolon = true; + } + else { + // Must recurse to determine last statement (possible if-else chain). + accept(toCheck); + } } - return false; - } - @Override - public boolean visit(JsReturn x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsSwitch x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsThrow x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsTry x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsVars x, JsContext ctx) { - return false; - } - - @Override - public boolean visit(JsWhile x, JsContext ctx) { - if (x.getBody() instanceof JsEmpty) { - needsSemicolon = true; + @Override + public void visitLabel(JsLabel x, JsContext ctx) { + if (x.getStatement() instanceof JsEmpty) { + needsSemicolon = true; + } + } + + @Override + public void visitWhile(JsWhile x, JsContext ctx) { + if (x.getBody() instanceof JsEmpty) { + needsSemicolon = true; + } } - 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 b4c0bb5cf4d..09d06545a94 100644 --- a/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java +++ b/src/com/google/dart/compiler/backend/js/JsToStringGenerationVisitor.java @@ -205,20 +205,18 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsArrayAccess x, JsContext context) { + public void visitArrayAccess(JsArrayAccess x, JsContext context) { printPair(x, x.getArrayExpression()); leftSquare(); accept(x.getIndexExpression()); rightSquare(); - return false; } @Override - public boolean visit(JsArrayLiteral x, JsContext ctx) { + public void visitArray(JsArrayLiteral x, JsContext ctx) { leftSquare(); printExpressions(x.getExpressions()); rightSquare(); - return false; } private void printExpressions(List expressions) { @@ -234,7 +232,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsBinaryOperation binaryOperation, JsContext context) { + public void visitBinaryExpression(JsBinaryOperation binaryOperation, JsContext context) { JsBinaryOperator operator = binaryOperation.getOperator(); JsExpression arg1 = binaryOperation.getArg1(); boolean isExpressionEnclosed = parenPush(binaryOperation, arg1, !operator.isLeftAssociative()); @@ -276,39 +274,33 @@ public class JsToStringGenerationVisitor extends JsVisitor { if (isParenOpened) { rightParen(); } - - return false; } @Override - public boolean visit(JsBlock x, JsContext ctx) { + public void visitBlock(JsBlock x, JsContext ctx) { printJsBlock(x, true, true); - return false; } @Override - public boolean visit(JsLiteral.JsBooleanLiteral x, JsContext ctx) { + public void visitBoolean(JsLiteral.JsBooleanLiteral x, JsContext ctx) { if (x.getValue()) { p.print(CHARS_TRUE); } else { p.print(CHARS_FALSE); } - return false; } @Override - public boolean visit(JsBreak x, JsContext ctx) { + public void visitBreak(JsBreak x, JsContext ctx) { p.print(CHARS_BREAK); continueOrBreakLabel(x); - return false; } @Override - public boolean visit(JsContinue x, JsContext ctx) { + public void visitContinue(JsContinue x, JsContext ctx) { p.print(CHARS_CONTINUE); continueOrBreakLabel(x); - return false; } private void continueOrBreakLabel(JsContinue x) { @@ -320,7 +312,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsCase x, JsContext ctx) { + public void visitCase(JsCase x, JsContext ctx) { p.print(CHARS_CASE); space(); accept(x.getCaseExpression()); @@ -328,7 +320,6 @@ public class JsToStringGenerationVisitor extends JsVisitor { newlineOpt(); printSwitchMemberStatements(x); - return false; } private void printSwitchMemberStatements(JsSwitchMember x) { @@ -346,7 +337,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsCatch x, JsContext ctx) { + public void visitCatch(JsCatch x, JsContext ctx) { spaceOpt(); p.print(CHARS_CATCH); spaceOpt(); @@ -366,12 +357,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { rightParen(); spaceOpt(); accept(x.getBody()); - - return false; } @Override - public boolean visit(JsConditional x, JsContext ctx) { + public void visitConditional(JsConditional x, JsContext ctx) { // Associativity: for the then and else branches, it is safe to insert // another // ternary expression, but if the test expression is a ternary, it should @@ -385,7 +374,6 @@ public class JsToStringGenerationVisitor extends JsVisitor { _colon(); spaceOpt(); printPair(x, x.getElseExpression()); - return false; } private void printPair(JsExpression parent, JsExpression expression) { @@ -400,22 +388,20 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsDebugger x, JsContext ctx) { + public void visitDebugger(JsDebugger x, JsContext ctx) { p.print(CHARS_DEBUGGER); - return false; } @Override - public boolean visit(JsDefault x, JsContext ctx) { + public void visitDefault(JsDefault x, JsContext ctx) { p.print(CHARS_DEFAULT); _colon(); printSwitchMemberStatements(x); - return false; } @Override - public boolean visit(JsWhile x, JsContext ctx) { + public void visitWhile(JsWhile x, JsContext ctx) { _while(); spaceOpt(); leftParen(); @@ -424,11 +410,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { _nestedPush(x.getBody()); accept(x.getBody()); _nestedPop(x.getBody()); - return false; } @Override - public boolean visit(JsDoWhile x, JsContext ctx) { + public void visitDoWhile(JsDoWhile x, JsContext ctx) { p.print(CHARS_DO); _nestedPush(x.getBody()); accept(x.getBody()); @@ -446,15 +431,14 @@ public class JsToStringGenerationVisitor extends JsVisitor { leftParen(); accept(x.getCondition()); rightParen(); - return false; } @Override - public void visit(JsEmpty x, JsContext ctx) { + public void visitEmpty(JsEmpty x, JsContext ctx) { } @Override - public boolean visit(JsExpressionStatement x, JsContext ctx) { + public void visitExpressionStatement(JsExpressionStatement x, JsContext ctx) { boolean surroundWithParentheses = JsFirstExpressionVisitor.exec(x); if (surroundWithParentheses) { leftParen(); @@ -463,11 +447,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { if (surroundWithParentheses) { rightParen(); } - return false; } @Override - public boolean visit(JsFor x, JsContext ctx) { + public void visitFor(JsFor x, JsContext ctx) { _for(); spaceOpt(); leftParen(); @@ -503,11 +486,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { _nestedPush(x.getBody()); accept(x.getBody()); _nestedPop(x.getBody()); - return false; } @Override - public boolean visit(JsForIn x, JsContext ctx) { + public void visitForIn(JsForIn x, JsContext ctx) { _for(); spaceOpt(); leftParen(); @@ -539,11 +521,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { _nestedPush(x.getBody()); accept(x.getBody()); _nestedPop(x.getBody()); - return false; } @Override - public boolean visit(JsFunction x, JsContext ctx) { + public void visitFunction(JsFunction x, JsContext ctx) { p.print(CHARS_FUNCTION); space(); if (x.getName() != null) { @@ -563,11 +544,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { lineBreakAfterBlock = false; accept(x.getBody()); needSemi = true; - return false; } @Override - public boolean visit(JsIf x, JsContext ctx) { + public void visitIf(JsIf x, JsContext ctx) { _if(); spaceOpt(); leftParen(); @@ -600,30 +580,27 @@ public class JsToStringGenerationVisitor extends JsVisitor { _nestedPop(elseStatement); } } - return false; } @Override - public boolean visit(JsInvocation x, JsContext ctx) { + public void visitInvocation(JsInvocation x, JsContext ctx) { printPair(x, x.getQualifier()); leftParen(); printExpressions(x.getArguments()); rightParen(); - return false; } @Override - public boolean visit(JsLabel x, JsContext ctx) { + public void visitLabel(JsLabel x, JsContext ctx) { nameOf(x); _colon(); spaceOpt(); accept(x.getStatement()); - return false; } @Override - public boolean visit(JsNameRef x, JsContext ctx) { + public void visitNameRef(JsNameRef x, JsContext ctx) { JsExpression q = x.getQualifier(); if (q != null) { parenPush(x, q, false); @@ -641,11 +618,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { p.print('.'); } _nameRef(x); - return false; } @Override - public boolean visit(JsNew x, JsContext ctx) { + public void visitNew(JsNew x, JsContext ctx) { p.print(CHARS_NEW); space(); @@ -662,27 +638,25 @@ public class JsToStringGenerationVisitor extends JsVisitor { leftParen(); printExpressions(x.getArguments()); rightParen(); - - return false; } @Override - public void visit(JsNullLiteral x, JsContext ctx) { + public void visitNull(JsNullLiteral x, JsContext ctx) { p.print(CHARS_NULL); } @Override - public void visit(JsIntLiteral x, JsContext ctx) { + public void visitInt(JsIntLiteral x, JsContext ctx) { p.print(x.value); } @Override - public void visit(JsDoubleLiteral x, JsContext ctx) { + public void visitDouble(JsDoubleLiteral x, JsContext ctx) { p.print(x.value); } @Override - public boolean visit(JsObjectLiteral objectLiteral, JsContext context) { + public void visitObjectLiteral(JsObjectLiteral objectLiteral, JsContext context) { p.print('{'); if (objectLiteral.isMultiline()) { p.indentIn(); @@ -731,27 +705,24 @@ public class JsToStringGenerationVisitor extends JsVisitor { } p.print('}'); - return false; } @Override - public boolean visit(JsParameter x, JsContext ctx) { + public void visitParameter(JsParameter x, JsContext ctx) { nameOf(x); - return false; } @Override - public boolean visit(JsPostfixOperation x, JsContext ctx) { + public void visitPostfixOperation(JsPostfixOperation x, JsContext ctx) { JsUnaryOperator op = x.getOperator(); JsExpression arg = x.getArg(); // unary operators always associate correctly (I think) printPair(x, arg); p.print(op.getSymbol()); - return false; } @Override - public boolean visit(JsPrefixOperation x, JsContext ctx) { + public void visitPrefixOperation(JsPrefixOperation x, JsContext ctx) { JsUnaryOperator op = x.getOperator(); p.print(op.getSymbol()); JsExpression arg = x.getArg(); @@ -760,31 +731,20 @@ public class JsToStringGenerationVisitor extends JsVisitor { } // unary operators always associate correctly (I think) printPair(x, arg); - return false; } @Override - public boolean visit(JsProgram x, JsContext ctx) { + public void visitProgram(JsProgram x, JsContext ctx) { p.print(""); - return false; } @Override - public boolean visit(JsProgramFragment x, JsContext ctx) { + public void visitProgramFragment(JsProgramFragment x, JsContext ctx) { p.print(""); - return false; } @Override - public boolean visit(JsPropertyInitializer x, JsContext ctx) { - // Since there are separators, we actually print the property init - // in visit(JsObjectLiteral). - // - return false; - } - - @Override - public void visit(JsRegExp x, JsContext ctx) { + public void visitRegExp(JsRegExp x, JsContext ctx) { _slash(); p.print(x.getPattern()); _slash(); @@ -795,23 +755,22 @@ public class JsToStringGenerationVisitor extends JsVisitor { } @Override - public boolean visit(JsReturn x, JsContext ctx) { + public void visitReturn(JsReturn x, JsContext ctx) { p.print(CHARS_RETURN); JsExpression expr = x.getExpression(); if (expr != null) { space(); accept(expr); } - return false; } @Override - public void visit(JsStringLiteral x, JsContext ctx) { + public void visitString(JsStringLiteral x, JsContext ctx) { p.print(javaScriptString(x.getValue())); } @Override - public boolean visit(JsSwitch x, JsContext ctx) { + public void visit(JsSwitch x, JsContext ctx) { p.print(CHARS_SWITCH); spaceOpt(); leftParen(); @@ -821,25 +780,22 @@ public class JsToStringGenerationVisitor extends JsVisitor { _blockOpen(); acceptList(x.getCases()); _blockClose(); - return false; } @Override - public boolean visit(JsLiteral.JsThisRef x, JsContext ctx) { + public void visitThis(JsLiteral.JsThisRef x, JsContext ctx) { p.print(CHARS_THIS); - return false; } @Override - public boolean visit(JsThrow x, JsContext ctx) { + public void visitThrow(JsThrow x, JsContext ctx) { p.print(CHARS_THROW); space(); accept(x.getExpression()); - return false; } @Override - public boolean visit(JsTry x, JsContext ctx) { + public void visitTry(JsTry x, JsContext ctx) { p.print(CHARS_TRY); spaceOpt(); accept(x.getTryBlock()); @@ -852,12 +808,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { spaceOpt(); accept(finallyBlock); } - - return false; } @Override - public boolean visit(JsVar var, JsContext ctx) { + public void visit(JsVar var, JsContext ctx) { nameOf(var); JsExpression initExpr = var.getInitExpression(); if (initExpr != null) { @@ -870,11 +824,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { rightParen(); } } - return false; } @Override - public boolean visit(JsVars vars, JsContext context) { + public void visitVars(JsVars vars, JsContext context) { var(); space(); boolean sep = false; @@ -892,11 +845,10 @@ public class JsToStringGenerationVisitor extends JsVisitor { accept(var); } - return false; } @Override - public boolean visit(JsDocComment comment, JsContext context) { + public void visitDocComment(JsDocComment comment, JsContext context) { boolean asSingleLine = comment.getTags().size() == 1; if (!asSingleLine) { newlineOpt(); @@ -929,7 +881,7 @@ public class JsToStringGenerationVisitor extends JsVisitor { p.print((CharSequence) value); } else { - visit((JsNameRef) value, context); + visitNameRef((JsNameRef) value, context); } } @@ -950,7 +902,6 @@ public class JsToStringGenerationVisitor extends JsVisitor { if (asSingleLine) { spaceOpt(); } - return false; } protected final void newlineOpt() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java b/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java index 3e668bf3fe1..617282de797 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java @@ -53,7 +53,7 @@ public final class JsArrayAccess extends JsExpressionImpl { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitArrayAccess(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java b/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java index 50603f0bfbc..fc79e5be9b0 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java @@ -58,7 +58,7 @@ public final class JsArrayLiteral extends JsLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitArray(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java b/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java index aea44e2e35c..36a6084d738 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java @@ -70,7 +70,7 @@ public final class JsBinaryOperation extends JsExpressionImpl { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitBinaryExpression(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBlock.java b/src/com/google/dart/compiler/backend/js/ast/JsBlock.java index 7b6874df47c..2f41e6dee11 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBlock.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsBlock.java @@ -45,7 +45,7 @@ public class JsBlock extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitBlock(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsBreak.java b/src/com/google/dart/compiler/backend/js/ast/JsBreak.java index 8932788e3fe..117e2e72964 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsBreak.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsBreak.java @@ -23,6 +23,6 @@ public final class JsBreak extends JsContinue { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitBreak(this, context); } } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsCase.java b/src/com/google/dart/compiler/backend/js/ast/JsCase.java index feaaa5d847c..dabd7329d40 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsCase.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsCase.java @@ -24,7 +24,7 @@ public final class JsCase extends JsSwitchMember { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitCase(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsCatch.java b/src/com/google/dart/compiler/backend/js/ast/JsCatch.java index 24a729051f8..a779f797da9 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsCatch.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsCatch.java @@ -49,7 +49,7 @@ public class JsCatch extends JsNodeImpl implements HasCondition { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitCatch(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsConditional.java b/src/com/google/dart/compiler/backend/js/ast/JsConditional.java index 7c82a97726d..24e30ffa8b7 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsConditional.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsConditional.java @@ -62,7 +62,7 @@ public final class JsConditional extends JsExpressionImpl { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitConditional(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsContinue.java b/src/com/google/dart/compiler/backend/js/ast/JsContinue.java index bd7aebbf5ca..00706fd77fb 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsContinue.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsContinue.java @@ -24,7 +24,7 @@ public class JsContinue extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitContinue(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java b/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java index 6d48cef820e..0a3a45b8733 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java @@ -14,7 +14,7 @@ public class JsDebugger extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitDebugger(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDefault.java b/src/com/google/dart/compiler/backend/js/ast/JsDefault.java index 227228df2e1..f20fab4572f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDefault.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsDefault.java @@ -10,7 +10,7 @@ package com.google.dart.compiler.backend.js.ast; public final class JsDefault extends JsSwitchMember { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitDefault(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java b/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java index e860a699f8b..97523c3d605 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java @@ -22,9 +22,6 @@ public class JsDoWhile extends JsWhile { @Override public void accept(JsVisitor v, JsContext context) { - if (v.visit(this, context)) { - condition = v.accept(condition); - body = v.accept(body); - } + v.visitDoWhile(this, context); } } diff --git a/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java b/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java index b432b45a6d1..92ec026b93b 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java @@ -29,12 +29,11 @@ public class JsDocComment extends JsExpressionImpl { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitDocComment(this, context); } @Override public void acceptChildren(JsVisitor visitor, JsContext context) { - } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java b/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java index 31ab7908cd0..8229617fe6d 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java @@ -10,7 +10,7 @@ public class JsEmpty extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitEmpty(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java b/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java index deb413ee43d..ae680e65afa 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java @@ -17,7 +17,7 @@ public final class JsExpressionStatement extends AbstractNode implements JsState @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitExpressionStatement(this, context); } @Override 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 d76f7ec50f9..c7bca577adb 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFor.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsFor.java @@ -72,7 +72,7 @@ public class JsFor extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitFor(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsForIn.java b/src/com/google/dart/compiler/backend/js/ast/JsForIn.java index 7fa3edd4fa9..68e7d598be4 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsForIn.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsForIn.java @@ -53,9 +53,7 @@ public class JsForIn extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - if (v.visit(this, context)) { - - } + v.visitForIn(this, context); } @Override 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 ae1a1ef85b2..21b0fdbe98e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsFunction.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsFunction.java @@ -91,7 +91,7 @@ public final class JsFunction extends JsLiteral implements HasName { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitFunction(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsIf.java b/src/com/google/dart/compiler/backend/js/ast/JsIf.java index d7e93226d57..aa4bc22bc22 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsIf.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsIf.java @@ -52,7 +52,7 @@ public final class JsIf extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitIf(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java b/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java index 3c9bc107e87..3e887940b0f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java @@ -68,7 +68,7 @@ public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArgument @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitInvocation(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsLabel.java b/src/com/google/dart/compiler/backend/js/ast/JsLabel.java index b4dd4ca2355..dbe63cc237e 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsLabel.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsLabel.java @@ -43,7 +43,7 @@ public class JsLabel extends JsNodeImpl implements JsStatement, HasName { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitLabel(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java b/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java index bc9eee97cd1..edfd17a1a90 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java @@ -44,7 +44,7 @@ public abstract class JsLiteral extends JsExpressionImpl implements CanBooleanEv @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitThis(this, context); } @Override @@ -87,7 +87,7 @@ public abstract class JsLiteral extends JsExpressionImpl implements CanBooleanEv @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitBoolean(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java b/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java index c877630db1c..ce9eeca248b 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java @@ -95,7 +95,7 @@ public final class JsNameRef extends JsExpressionImpl implements CanBooleanEval, @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitNameRef(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNew.java b/src/com/google/dart/compiler/backend/js/ast/JsNew.java index dac28938a62..e5adf766a7f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNew.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsNew.java @@ -43,7 +43,7 @@ public final class JsNew extends JsExpressionImpl.JsExpressionHasArguments { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitNew(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java b/src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java index 3974b1a5965..a17ac877ef6 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsNullLiteral.java @@ -30,7 +30,7 @@ public final class JsNullLiteral extends JsLiteral.JsValueLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitNull(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java b/src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java index 8df65c40b7e..e77dceefb17 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsNumberLiteral.java @@ -39,7 +39,7 @@ public abstract class JsNumberLiteral extends JsLiteral.JsValueLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitDouble(this, context); } public String toString() { @@ -66,7 +66,7 @@ public abstract class JsNumberLiteral extends JsLiteral.JsValueLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitInt(this, context); } public String toString() { diff --git a/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java b/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java index bbae493479a..7cc65fc7b8a 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java @@ -70,7 +70,7 @@ public final class JsObjectLiteral extends JsLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitObjectLiteral(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsParameter.java b/src/com/google/dart/compiler/backend/js/ast/JsParameter.java index 5d87432ce7f..68e3b313375 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsParameter.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsParameter.java @@ -28,7 +28,7 @@ public final class JsParameter extends JsNodeImpl implements HasName { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitParameter(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java b/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java index 177b6f79b60..72efa7868c4 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java @@ -29,7 +29,7 @@ public final class JsPostfixOperation extends JsUnaryOperation { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitPostfixOperation(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java b/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java index 6c0724af93d..ba0e3458c76 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java @@ -47,7 +47,7 @@ public final class JsPrefixOperation extends JsUnaryOperation implements CanBool @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitPrefixOperation(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsProgram.java b/src/com/google/dart/compiler/backend/js/ast/JsProgram.java index 6b71bea47a2..5eaee9c19c3 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsProgram.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsProgram.java @@ -110,7 +110,7 @@ public final class JsProgram extends JsNodeImpl { @Override public void accept(JsVisitor v, @Nullable JsContext context) { - v.visit(this, context); + v.visitProgram(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java b/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java index 3de7dfda2a7..3f1b8d0ce77 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java @@ -20,7 +20,7 @@ public class JsProgramFragment extends JsNodeImpl { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitProgramFragment(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java b/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java index e057f6e8ecf..5e184f071f6 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java @@ -40,7 +40,7 @@ public class JsPropertyInitializer extends JsNodeImpl { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitPropertyInitializer(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsRegExp.java b/src/com/google/dart/compiler/backend/js/ast/JsRegExp.java index 18a7ca46b56..2015a5f8b8c 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsRegExp.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsRegExp.java @@ -52,7 +52,7 @@ public final class JsRegExp extends JsLiteral.JsValueLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitRegExp(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsReturn.java b/src/com/google/dart/compiler/backend/js/ast/JsReturn.java index a347f8bd547..ee798d5573f 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsReturn.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsReturn.java @@ -27,7 +27,7 @@ public final class JsReturn extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitReturn(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java b/src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java index d063843a626..68448bda891 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsStringLiteral.java @@ -42,7 +42,7 @@ public final class JsStringLiteral extends JsLiteral.JsValueLiteral { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitString(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsThrow.java b/src/com/google/dart/compiler/backend/js/ast/JsThrow.java index 9345d31d15f..164d2dae0f2 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsThrow.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsThrow.java @@ -24,7 +24,7 @@ public class JsThrow extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitThrow(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/JsTry.java b/src/com/google/dart/compiler/backend/js/ast/JsTry.java index ebd3d1b2888..3625bd0ebca 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsTry.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsTry.java @@ -49,7 +49,7 @@ public class JsTry extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitTry(this, context); } @Override 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 359199e77b3..c88016f0de7 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsVars.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsVars.java @@ -119,7 +119,7 @@ public class JsVars extends JsNodeImpl implements JsStatement, Iterable T accept(T node) { - doTraverse(node, UNMODIFIABLE_CONTEXT); + doAccept(node, UNMODIFIABLE_CONTEXT); return node; } public final void acceptList(List collection) { for (T node : collection) { - doTraverse(node, UNMODIFIABLE_CONTEXT); + doAccept(node, UNMODIFIABLE_CONTEXT); } } public JsExpression acceptLvalue(JsExpression expr) { - doTraverse(expr, LVALUE_CONTEXT); + doAccept(expr, LVALUE_CONTEXT); return expr; } public final void acceptWithInsertRemove(List collection) { for (T node : collection) { - doTraverse(node, UNMODIFIABLE_CONTEXT); + doAccept(node, UNMODIFIABLE_CONTEXT); } } - public boolean visit(JsArrayAccess x, JsContext ctx) { - return true; + public void visitArrayAccess(JsArrayAccess x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsArrayLiteral x, JsContext ctx) { - return true; + public void visitArray(JsArrayLiteral x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsBinaryOperation x, JsContext ctx) { - return true; + public void visitBinaryExpression(JsBinaryOperation x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsBlock x, JsContext ctx) { - return true; + public void visitBlock(JsBlock x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsLiteral.JsBooleanLiteral x, JsContext ctx) { - return true; + public void visitBoolean(JsLiteral.JsBooleanLiteral x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsBreak x, JsContext ctx) { - return true; + public void visitBreak(JsBreak x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsCase x, JsContext ctx) { - return true; + public void visitCase(JsCase x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsCatch x, JsContext ctx) { - return true; + public void visitCatch(JsCatch x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsConditional x, JsContext ctx) { - return true; + public void visitConditional(JsConditional x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsContinue x, JsContext ctx) { - return true; + public void visitContinue(JsContinue x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsDebugger x, JsContext ctx) { - return true; + public void visitDebugger(JsDebugger x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsDefault x, JsContext ctx) { - return true; + public void visitDefault(JsDefault x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsDoWhile x, JsContext ctx) { - return true; + public void visitDoWhile(JsDoWhile x, JsContext ctx) { + visitElement(x, ctx); } - public void visit(JsEmpty x, JsContext ctx) { + public void visitEmpty(JsEmpty x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsExpressionStatement x, JsContext ctx) { - return true; + public void visitExpressionStatement(JsExpressionStatement x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsFor x, JsContext ctx) { - return true; + public void visitFor(JsFor x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsForIn x, JsContext ctx) { - return true; + public void visitForIn(JsForIn x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsFunction x, JsContext ctx) { - return true; + public void visitFunction(JsFunction x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsIf x, JsContext ctx) { - return true; + public void visitIf(JsIf x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsInvocation x, JsContext ctx) { - return true; + public void visitInvocation(JsInvocation x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsLabel x, JsContext ctx) { - return true; + public void visitLabel(JsLabel x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsNameRef x, JsContext ctx) { - return true; + public void visitNameRef(JsNameRef x, JsContext ctx) { + visitElement(x, ctx); } - public boolean visit(JsNew x, JsContext ctx) { - return true; + public void visitNew(JsNew x, JsContext ctx) { + visitElement(x, ctx); } - public void visit(JsNullLiteral x, JsContext ctx) { + public void visitNull(JsNullLiteral x, JsContext ctx) { + visitElement(x, ctx); } - public void visit(JsNumberLiteral.JsIntLiteral x, JsContext ctx) { + public void visitInt(JsNumberLiteral.JsIntLiteral x, JsContext context) { + visitElement(x, context); } - public void visit(JsNumberLiteral.JsDoubleLiteral x, JsContext ctx) { + public void visitDouble(JsNumberLiteral.JsDoubleLiteral x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsObjectLiteral x, JsContext ctx) { - return true; + public void visitObjectLiteral(JsObjectLiteral x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsParameter x, JsContext ctx) { - return true; + public void visitParameter(JsParameter x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsPostfixOperation x, JsContext ctx) { - return true; + public void visitPostfixOperation(JsPostfixOperation x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsPrefixOperation x, JsContext ctx) { - return true; + public void visitPrefixOperation(JsPrefixOperation x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsProgram x, JsContext ctx) { - return true; + public void visitProgram(JsProgram x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsProgramFragment x, JsContext ctx) { - return true; + public void visitProgramFragment(JsProgramFragment x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsPropertyInitializer x, JsContext ctx) { - return true; + public void visitPropertyInitializer(JsPropertyInitializer x, JsContext context) { + visitElement(x, context); } - public void visit(JsRegExp x, JsContext ctx) { + public void visitRegExp(JsRegExp x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsReturn x, JsContext ctx) { - return true; + public void visitReturn(JsReturn x, JsContext context) { + visitElement(x, context); } - public void visit(JsStringLiteral x, JsContext ctx) { + public void visitString(JsStringLiteral x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsSwitch x, JsContext ctx) { - return true; + public void visit(JsSwitch x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsLiteral.JsThisRef x, JsContext ctx) { - return true; + public void visitThis(JsLiteral.JsThisRef x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsThrow x, JsContext ctx) { - return true; + public void visitThrow(JsThrow x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsTry x, JsContext ctx) { - return true; + public void visitTry(JsTry x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsVar x, JsContext ctx) { - return true; + public void visit(JsVar x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsVars x, JsContext ctx) { - return true; + public void visitVars(JsVars x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsWhile x, JsContext ctx) { - return true; + public void visitWhile(JsWhile x, JsContext context) { + visitElement(x, context); } - public boolean visit(JsDocComment x, JsContext context) { - return true; + public void visitDocComment(JsDocComment comment, JsContext context) { + visitElement(comment, context); } - protected void doTraverse(JsNode node, JsContext context) { + protected void visitElement(JsNode node, JsContext context) { + } + + protected void doAccept(JsNode node, JsContext context) { node.accept(this, context); } } \ No newline at end of file diff --git a/src/com/google/dart/compiler/backend/js/ast/JsWhile.java b/src/com/google/dart/compiler/backend/js/ast/JsWhile.java index 6e7d24d0d61..646870dae1a 100644 --- a/src/com/google/dart/compiler/backend/js/ast/JsWhile.java +++ b/src/com/google/dart/compiler/backend/js/ast/JsWhile.java @@ -37,7 +37,7 @@ public class JsWhile extends JsNodeImpl implements JsStatement { @Override public void accept(JsVisitor v, JsContext context) { - v.visit(this, context); + v.visitWhile(this, context); } @Override diff --git a/src/com/google/dart/compiler/backend/js/ast/RecursiveJsVisitor.java b/src/com/google/dart/compiler/backend/js/ast/RecursiveJsVisitor.java index 6f3b9c4f495..c148969f425 100644 --- a/src/com/google/dart/compiler/backend/js/ast/RecursiveJsVisitor.java +++ b/src/com/google/dart/compiler/backend/js/ast/RecursiveJsVisitor.java @@ -1,4 +1,8 @@ package com.google.dart.compiler.backend.js.ast; public abstract class RecursiveJsVisitor extends JsVisitor { + @Override + protected void visitElement(JsNode node, JsContext context) { + node.acceptChildren(this, context); + } }