| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 abstract class Visitor<R> { | 5 abstract class Visitor<R> { |
| 6 R visitBlock(Block node); | 6 const Visitor(); |
| 7 R visitBreakStatement(BreakStatement node); | 7 |
| 8 R visitCascade(Cascade node); | 8 abstract R visitNode(Node node); |
| 9 R visitCascadeReceiver(CascadeReceiver node); | 9 |
| 10 R visitCaseMatch(CaseMatch node); | 10 R visitBlock(Block node) => visitStatement(node); |
| 11 R visitCatchBlock(CatchBlock node); | 11 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node); |
| 12 R visitClassNode(ClassNode node); | 12 R visitCascade(Cascade node) => visitExpression(node); |
| 13 R visitConditional(Conditional node); | 13 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node); |
| 14 R visitContinueStatement(ContinueStatement node); | 14 R visitCaseMatch(CaseMatch node) => visitNode(node); |
| 15 R visitDoWhile(DoWhile node); | 15 R visitCatchBlock(CatchBlock node) => visitNode(node); |
| 16 R visitEmptyStatement(EmptyStatement node); | 16 R visitClassNode(ClassNode node) => visitNode(node); |
| 17 R visitExpressionStatement(ExpressionStatement node); | 17 R visitConditional(Conditional node) => visitExpression(node); |
| 18 R visitFor(For node); | 18 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node); |
| 19 R visitForIn(ForIn node); | 19 R visitDoWhile(DoWhile node) => visitLoop(node); |
| 20 R visitFunctionDeclaration(FunctionDeclaration node); | 20 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); |
| 21 R visitFunctionExpression(FunctionExpression node); | 21 R visitExpression(Expression node) => visitNode(node); |
| 22 R visitIdentifier(Identifier node); | 22 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); |
| 23 R visitIf(If node); | 23 R visitFor(For node) => visitLoop(node); |
| 24 R visitLabel(Label node); | 24 R visitForIn(ForIn node) => visitLoop(node); |
| 25 R visitLabeledStatement(LabeledStatement node); | 25 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node); |
| 26 R visitLiteralBool(LiteralBool node); | 26 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); |
| 27 R visitLiteralDouble(LiteralDouble node); | 27 R visitGotoStatement(GotoStatement node) => visitStatement(node); |
| 28 R visitLiteralInt(LiteralInt node); | 28 R visitIdentifier(Identifier node) => visitExpression(node); |
| 29 R visitLiteralList(LiteralList node); | 29 R visitIf(If node) => visitStatement(node); |
| 30 R visitLiteralMap(LiteralMap node); | 30 R visitLabel(Label node) => visitNode(node); |
| 31 R visitLiteralMapEntry(LiteralMapEntry node); | 31 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); |
| 32 R visitLiteralNull(LiteralNull node); | 32 R visitLiteral(Literal node) => visitExpression(node); |
| 33 R visitLiteralString(LiteralString node); | 33 R visitLiteralBool(LiteralBool node) => visitLiteral(node); |
| 34 R visitModifiers(Modifiers node); | 34 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); |
| 35 R visitNamedArgument(NamedArgument node); | 35 R visitLiteralInt(LiteralInt node) => visitLiteral(node); |
| 36 R visitNewExpression(NewExpression node); | 36 R visitLiteralList(LiteralList node) => visitExpression(node); |
| 37 R visitNodeList(NodeList node); | 37 R visitLiteralMap(LiteralMap node) => visitExpression(node); |
| 38 R visitOperator(Operator node); | 38 R visitLiteralMapEntry(LiteralMapEntry node) => visitNode(node); |
| 39 R visitParenthesizedExpression(ParenthesizedExpression node); | 39 R visitLiteralNull(LiteralNull node) => visitLiteral(node); |
| 40 R visitReturn(Return node); | 40 R visitLiteralString(LiteralString node) => visitStringNode(node); |
| 41 R visitScriptTag(ScriptTag node); | 41 R visitStringJuxtaposition(StringJuxtaposition node) => visitStringNode(node); |
| 42 R visitSend(Send node); | 42 R visitLoop(Loop node) => visitStatement(node); |
| 43 R visitSendSet(SendSet node); | 43 R visitModifiers(Modifiers node) => visitNode(node); |
| 44 R visitStringInterpolation(StringInterpolation node); | 44 R visitNamedArgument(NamedArgument node) => visitExpression(node); |
| 45 R visitStringInterpolationPart(StringInterpolationPart node); | 45 R visitNewExpression(NewExpression node) => visitExpression(node); |
| 46 R visitStringJuxtaposition(StringJuxtaposition node); | 46 R visitNodeList(NodeList node) => visitNode(node); |
| 47 R visitSwitchCase(SwitchCase node); | 47 R visitOperator(Operator node) => visitIdentifier(node); |
| 48 R visitSwitchStatement(SwitchStatement node); | 48 R visitParenthesizedExpression(ParenthesizedExpression node) { |
| 49 R visitThrow(Throw node); | 49 return visitExpression(node); |
| 50 R visitTryStatement(TryStatement node); | 50 } |
| 51 R visitTypeAnnotation(TypeAnnotation node); | 51 R visitPostfix(Postfix node) => visitNodeList(node); |
| 52 R visitTypedef(Typedef node); | 52 R visitPrefix(Prefix node) => visitNodeList(node); |
| 53 R visitTypeVariable(TypeVariable node); | 53 R visitReturn(Return node) => visitStatement(node); |
| 54 R visitVariableDefinitions(VariableDefinitions node); | 54 R visitScriptTag(ScriptTag node) => visitNode(node); |
| 55 R visitWhile(While node); | 55 R visitSend(Send node) => visitExpression(node); |
| 56 R visitSendSet(SendSet node) => visitSend(node); |
| 57 R visitStatement(Statement node) => visitNode(node); |
| 58 R visitStringNode(StringNode node) => visitExpression(node); |
| 59 R visitStringInterpolation(StringInterpolation node) => visitStringNode(node); |
| 60 R visitStringInterpolationPart(StringInterpolationPart node) { |
| 61 return visitNode(node); |
| 62 } |
| 63 R visitSwitchCase(SwitchCase node) => visitNode(node); |
| 64 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); |
| 65 R visitThrow(Throw node) => visitStatement(node); |
| 66 R visitTryStatement(TryStatement node) => visitStatement(node); |
| 67 R visitTypeAnnotation(TypeAnnotation node) => visitNode(node); |
| 68 R visitTypedef(Typedef node) => visitNode(node); |
| 69 R visitTypeVariable(TypeVariable node) => visitNode(node); |
| 70 R visitVariableDefinitions(VariableDefinitions node) => visitStatement(node); |
| 71 R visitWhile(While node) => visitLoop(node); |
| 56 } | 72 } |
| 57 | 73 |
| 58 Token firstBeginToken(Node first, Node second) { | 74 Token firstBeginToken(Node first, Node second) { |
| 59 Token token = null; | 75 Token token = null; |
| 60 if (first !== null) { | 76 if (first !== null) { |
| 61 token = first.getBeginToken(); | 77 token = first.getBeginToken(); |
| 62 } | 78 } |
| 63 if (token === null && second !== null) { | 79 if (token === null && second !== null) { |
| 64 // [token] might be null even when [first] is not, e.g. for empty Modifiers. | 80 // [token] might be null even when [first] is not, e.g. for empty Modifiers. |
| 65 token = second.getBeginToken(); | 81 token = second.getBeginToken(); |
| (...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1865 return (node.receiver === null && | 1881 return (node.receiver === null && |
| 1866 node.selector.asIdentifier() !== null && | 1882 node.selector.asIdentifier() !== null && |
| 1867 node.selector.asIdentifier().isThis()) || | 1883 node.selector.asIdentifier().isThis()) || |
| 1868 (node.receiver !== null && | 1884 (node.receiver !== null && |
| 1869 node.receiver.asIdentifier() !== null && | 1885 node.receiver.asIdentifier() !== null && |
| 1870 node.receiver.asIdentifier().isThis() && | 1886 node.receiver.asIdentifier().isThis() && |
| 1871 node.selector.asIdentifier() !== null); | 1887 node.selector.asIdentifier() !== null); |
| 1872 } | 1888 } |
| 1873 } | 1889 } |
| 1874 | 1890 |
| 1875 class GetDartStringVisitor extends AbstractVisitor<DartString> { | 1891 class GetDartStringVisitor extends Visitor<DartString> { |
| 1876 const GetDartStringVisitor(); | 1892 const GetDartStringVisitor(); |
| 1877 DartString visitNode(Node node) => null; | 1893 DartString visitNode(Node node) => null; |
| 1878 DartString visitStringJuxtaposition(StringJuxtaposition node) | 1894 DartString visitStringJuxtaposition(StringJuxtaposition node) |
| 1879 => node.dartString; | 1895 => node.dartString; |
| 1880 DartString visitLiteralString(LiteralString node) => node.dartString; | 1896 DartString visitLiteralString(LiteralString node) => node.dartString; |
| 1881 } | 1897 } |
| 1882 | 1898 |
| 1883 class IsInterpolationVisitor extends AbstractVisitor<bool> { | 1899 class IsInterpolationVisitor extends Visitor<bool> { |
| 1884 const IsInterpolationVisitor(); | 1900 const IsInterpolationVisitor(); |
| 1885 bool visitNode(Node node) => false; | 1901 bool visitNode(Node node) => false; |
| 1886 bool visitStringInterpolation(StringInterpolation node) => true; | 1902 bool visitStringInterpolation(StringInterpolation node) => true; |
| 1887 bool visitStringJuxtaposition(StringJuxtaposition node) | 1903 bool visitStringJuxtaposition(StringJuxtaposition node) |
| 1888 => node.isInterpolation; | 1904 => node.isInterpolation; |
| 1889 } | 1905 } |
| 1890 | 1906 |
| 1891 /** | 1907 /** |
| 1892 * If the given node is a send set, it visits its initializer (first | 1908 * If the given node is a send set, it visits its initializer (first |
| 1893 * argument). | 1909 * argument). |
| 1894 * | 1910 * |
| 1895 * TODO(ahe): This method is controversial, the team needs to discuss | 1911 * TODO(ahe): This method is controversial, the team needs to discuss |
| 1896 * if top-level methods are acceptable and what naming conventions to | 1912 * if top-level methods are acceptable and what naming conventions to |
| 1897 * use. | 1913 * use. |
| 1898 */ | 1914 */ |
| 1899 initializerDo(Node node, f(Node node)) { | 1915 initializerDo(Node node, f(Node node)) { |
| 1900 SendSet send = node.asSendSet(); | 1916 SendSet send = node.asSendSet(); |
| 1901 if (send !== null) return f(send.arguments.head); | 1917 if (send !== null) return f(send.arguments.head); |
| 1902 } | 1918 } |
| OLD | NEW |