Chromium Code Reviews| 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 const Visitor(); | 6 const Visitor(); |
| 7 | 7 |
| 8 abstract R visitNode(Node node); | 8 abstract R visitNode(Node node); |
| 9 | 9 |
| 10 R visitBlock(Block node) => visitStatement(node); | 10 R visitBlock(Block node) => visitStatement(node); |
| 11 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node); | 11 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node); |
| 12 R visitCascade(Cascade node) => visitExpression(node); | 12 R visitCascade(Cascade node) => visitExpression(node); |
| 13 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node); | 13 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node); |
| 14 R visitCaseMatch(CaseMatch node) => visitNode(node); | 14 R visitCaseMatch(CaseMatch node) => visitNode(node); |
| 15 R visitCatchBlock(CatchBlock node) => visitNode(node); | 15 R visitCatchBlock(CatchBlock node) => visitNode(node); |
| 16 R visitClassNode(ClassNode node) => visitNode(node); | 16 R visitClassNode(ClassNode node) => visitNode(node); |
| 17 R visitCombinator(Combinator node) => visitNode(node); | 17 R visitCombinator(Combinator node) => visitNode(node); |
| 18 R visitConditional(Conditional node) => visitExpression(node); | 18 R visitConditional(Conditional node) => visitExpression(node); |
| 19 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node); | 19 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node); |
| 20 R visitDoWhile(DoWhile node) => visitLoop(node); | 20 R visitDoWhile(DoWhile node) => visitLoop(node); |
| 21 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); | 21 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); |
| 22 R visitExport(Export node) => visitLibraryTag(node); | 22 R visitExport(Export node) => visitLibraryTag(node); |
|
ahe
2012/10/10 12:06:27
Should return "visitLibraryDependency(node)"
Johnni Winther
2012/10/10 14:56:00
Done.
| |
| 23 R visitExpression(Expression node) => visitNode(node); | 23 R visitExpression(Expression node) => visitNode(node); |
| 24 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); | 24 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); |
| 25 R visitFor(For node) => visitLoop(node); | 25 R visitFor(For node) => visitLoop(node); |
| 26 R visitForIn(ForIn node) => visitLoop(node); | 26 R visitForIn(ForIn node) => visitLoop(node); |
| 27 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node); | 27 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node); |
| 28 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); | 28 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); |
| 29 R visitGotoStatement(GotoStatement node) => visitStatement(node); | 29 R visitGotoStatement(GotoStatement node) => visitStatement(node); |
| 30 R visitIdentifier(Identifier node) => visitExpression(node); | 30 R visitIdentifier(Identifier node) => visitExpression(node); |
| 31 R visitIf(If node) => visitStatement(node); | 31 R visitIf(If node) => visitStatement(node); |
| 32 R visitImport(Import node) => visitLibraryTag(node); | 32 R visitImport(Import node) => visitLibraryTag(node); |
|
ahe
2012/10/10 12:06:27
Ditto.
Johnni Winther
2012/10/10 14:56:00
Done.
| |
| 33 R visitLabel(Label node) => visitNode(node); | 33 R visitLabel(Label node) => visitNode(node); |
| 34 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); | 34 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); |
| 35 R visitLibraryName(LibraryName node) => visitLibraryTag(node); | 35 R visitLibraryName(LibraryName node) => visitLibraryTag(node); |
| 36 R visitLibraryTag(LibraryTag node) => visitNode(node); | 36 R visitLibraryTag(LibraryTag node) => visitNode(node); |
| 37 R visitLiteral(Literal node) => visitExpression(node); | 37 R visitLiteral(Literal node) => visitExpression(node); |
| 38 R visitLiteralBool(LiteralBool node) => visitLiteral(node); | 38 R visitLiteralBool(LiteralBool node) => visitLiteral(node); |
| 39 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); | 39 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); |
| 40 R visitLiteralInt(LiteralInt node) => visitLiteral(node); | 40 R visitLiteralInt(LiteralInt node) => visitLiteral(node); |
| 41 R visitLiteralList(LiteralList node) => visitExpression(node); | 41 R visitLiteralList(LiteralList node) => visitExpression(node); |
| 42 R visitLiteralMap(LiteralMap node) => visitExpression(node); | 42 R visitLiteralMap(LiteralMap node) => visitExpression(node); |
| (...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1675 | 1675 |
| 1676 accept(Visitor visitor) => visitor.visitLibraryName(this); | 1676 accept(Visitor visitor) => visitor.visitLibraryName(this); |
| 1677 | 1677 |
| 1678 visitChildren(Visitor visitor) => name.accept(visitor); | 1678 visitChildren(Visitor visitor) => name.accept(visitor); |
| 1679 | 1679 |
| 1680 Token getBeginToken() => libraryKeyword; | 1680 Token getBeginToken() => libraryKeyword; |
| 1681 | 1681 |
| 1682 Token getEndToken() => name.getEndToken().next; | 1682 Token getEndToken() => name.getEndToken().next; |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 class Import extends LibraryTag { | 1685 /** |
| 1686 * This tag describes a dependency between one library and the exported | |
| 1687 * identifiers of another library. The other library is specified by the [uri]. | |
| 1688 * Combinators filter away some identifiers from the other library. | |
| 1689 */ | |
| 1690 abstract class LibraryDependency extends LibraryTag { | |
| 1686 final LiteralString uri; | 1691 final LiteralString uri; |
| 1687 final Identifier prefix; | |
| 1688 final NodeList combinators; | 1692 final NodeList combinators; |
| 1689 | 1693 |
| 1694 LibraryDependency(this.uri, this.combinators); | |
| 1695 } | |
| 1696 | |
| 1697 /** | |
| 1698 * An [:import:] library tag. | |
| 1699 * | |
| 1700 * An import tag is dependency on another library where the exported identifiers | |
| 1701 * are put into the import scope of the importing library. The import scope is | |
| 1702 * only visible inside the library. | |
| 1703 */ | |
| 1704 class Import extends LibraryDependency { | |
| 1705 final Identifier prefix; | |
| 1690 final Token importKeyword; | 1706 final Token importKeyword; |
| 1691 | 1707 |
| 1692 Import(this.importKeyword, this.uri, this.prefix, this.combinators); | 1708 Import(this.importKeyword, LiteralString uri, |
| 1709 this.prefix, NodeList combinators) | |
| 1710 : super(uri, combinators); | |
| 1693 | 1711 |
| 1694 bool get isImport => true; | 1712 bool get isImport => true; |
| 1695 | 1713 |
| 1696 Import asImport() => this; | 1714 Import asImport() => this; |
| 1697 | 1715 |
| 1698 Token get asKeyword => prefix == null ? null : uri.getEndToken().next; | 1716 Token get asKeyword => prefix == null ? null : uri.getEndToken().next; |
| 1699 | 1717 |
| 1700 accept(Visitor visitor) => visitor.visitImport(this); | 1718 accept(Visitor visitor) => visitor.visitImport(this); |
| 1701 | 1719 |
| 1702 visitChildren(Visitor visitor) { | 1720 visitChildren(Visitor visitor) { |
| 1703 uri.accept(visitor); | 1721 uri.accept(visitor); |
| 1704 if (prefix !== null) prefix.accept(visitor); | 1722 if (prefix !== null) prefix.accept(visitor); |
| 1705 if (combinators !== null) combinators.accept(visitor); | 1723 if (combinators !== null) combinators.accept(visitor); |
| 1706 } | 1724 } |
| 1707 | 1725 |
| 1708 Token getBeginToken() => importKeyword; | 1726 Token getBeginToken() => importKeyword; |
| 1709 | 1727 |
| 1710 Token getEndToken() { | 1728 Token getEndToken() { |
| 1711 if (combinators !== null) return combinators.getEndToken().next; | 1729 if (combinators !== null) return combinators.getEndToken().next; |
| 1712 if (prefix !== null) return prefix.getEndToken().next; | 1730 if (prefix !== null) return prefix.getEndToken().next; |
| 1713 return uri.getEndToken().next; | 1731 return uri.getEndToken().next; |
| 1714 } | 1732 } |
| 1715 } | 1733 } |
| 1716 | 1734 |
| 1717 class Export extends LibraryTag { | 1735 /** |
| 1718 final LiteralString uri; | 1736 * An [:export:] library tag. |
| 1719 final NodeList combinators; | 1737 * |
| 1720 | 1738 * An export tag is dependency on another library where the exported identifiers |
| 1739 * are put into the export scope of the exporting library. The export scope is | |
| 1740 * not visible inside the library. | |
| 1741 */ | |
| 1742 class Export extends LibraryDependency { | |
| 1721 final Token exportKeyword; | 1743 final Token exportKeyword; |
| 1722 | 1744 |
| 1723 Export(this.exportKeyword, this.uri, this.combinators); | 1745 Export(this.exportKeyword, LiteralString uri, NodeList combinators) |
| 1746 : super(uri, combinators); | |
| 1724 | 1747 |
| 1725 bool get isExport => true; | 1748 bool get isExport => true; |
| 1726 | 1749 |
| 1727 Export asExport() => this; | 1750 Export asExport() => this; |
| 1728 | 1751 |
| 1729 accept(Visitor visitor) => visitor.visitExport(this); | 1752 accept(Visitor visitor) => visitor.visitExport(this); |
| 1730 | 1753 |
| 1731 visitChildren(Visitor visitor) { | 1754 visitChildren(Visitor visitor) { |
| 1732 uri.accept(visitor); | 1755 uri.accept(visitor); |
| 1733 if (combinators !== null) combinators.accept(visitor); | 1756 if (combinators !== null) combinators.accept(visitor); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1979 * argument). | 2002 * argument). |
| 1980 * | 2003 * |
| 1981 * TODO(ahe): This method is controversial, the team needs to discuss | 2004 * TODO(ahe): This method is controversial, the team needs to discuss |
| 1982 * if top-level methods are acceptable and what naming conventions to | 2005 * if top-level methods are acceptable and what naming conventions to |
| 1983 * use. | 2006 * use. |
| 1984 */ | 2007 */ |
| 1985 initializerDo(Node node, f(Node node)) { | 2008 initializerDo(Node node, f(Node node)) { |
| 1986 SendSet send = node.asSendSet(); | 2009 SendSet send = node.asSendSet(); |
| 1987 if (send !== null) return f(send.arguments.head); | 2010 if (send !== null) return f(send.arguments.head); |
| 1988 } | 2011 } |
| OLD | NEW |