Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: lib/compiler/implementation/tree/nodes.dart

Issue 10990060: Added support for exports and re-exports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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) => visitLibraryDependency(node);
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) => visitLibraryDependency(node);
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 visitLibraryDependency(LibraryDependency node) => visitLibraryTag(node);
35 R visitLibraryName(LibraryName node) => visitLibraryTag(node); 36 R visitLibraryName(LibraryName node) => visitLibraryTag(node);
36 R visitLibraryTag(LibraryTag node) => visitNode(node); 37 R visitLibraryTag(LibraryTag node) => visitNode(node);
37 R visitLiteral(Literal node) => visitExpression(node); 38 R visitLiteral(Literal node) => visitExpression(node);
38 R visitLiteralBool(LiteralBool node) => visitLiteral(node); 39 R visitLiteralBool(LiteralBool node) => visitLiteral(node);
39 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); 40 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node);
40 R visitLiteralInt(LiteralInt node) => visitLiteral(node); 41 R visitLiteralInt(LiteralInt node) => visitLiteral(node);
41 R visitLiteralList(LiteralList node) => visitExpression(node); 42 R visitLiteralList(LiteralList node) => visitExpression(node);
42 R visitLiteralMap(LiteralMap node) => visitExpression(node); 43 R visitLiteralMap(LiteralMap node) => visitExpression(node);
43 R visitLiteralMapEntry(LiteralMapEntry node) => visitNode(node); 44 R visitLiteralMapEntry(LiteralMapEntry node) => visitNode(node);
44 R visitLiteralNull(LiteralNull node) => visitLiteral(node); 45 R visitLiteralNull(LiteralNull node) => visitLiteral(node);
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 else if (value === 'abstract') flags |= FLAG_ABSTRACT; 1165 else if (value === 'abstract') flags |= FLAG_ABSTRACT;
1165 else if (value === 'final') flags |= FLAG_FINAL; 1166 else if (value === 'final') flags |= FLAG_FINAL;
1166 else if (value === 'var') flags |= FLAG_VAR; 1167 else if (value === 'var') flags |= FLAG_VAR;
1167 else if (value === 'const') flags |= FLAG_CONST; 1168 else if (value === 'const') flags |= FLAG_CONST;
1168 else if (value === 'factory') flags |= FLAG_FACTORY; 1169 else if (value === 'factory') flags |= FLAG_FACTORY;
1169 else if (value === 'external') flags |= FLAG_EXTERNAL; 1170 else if (value === 'external') flags |= FLAG_EXTERNAL;
1170 else throw 'internal error: ${nodes.head}'; 1171 else throw 'internal error: ${nodes.head}';
1171 } 1172 }
1172 return flags; 1173 return flags;
1173 } 1174 }
1174 1175
1175 Node findModifier(String modifier) { 1176 Node findModifier(String modifier) {
1176 Link<Node> nodeList = nodes.nodes; 1177 Link<Node> nodeList = nodes.nodes;
1177 for (; !nodeList.isEmpty(); nodeList = nodeList.tail) { 1178 for (; !nodeList.isEmpty(); nodeList = nodeList.tail) {
1178 String value = nodeList.head.asIdentifier().source.stringValue; 1179 String value = nodeList.head.asIdentifier().source.stringValue;
1179 if(value === modifier) { 1180 if(value === modifier) {
1180 return nodeList.head; 1181 return nodeList.head;
1181 } 1182 }
1182 } 1183 }
1183 return null; 1184 return null;
1184 } 1185 }
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1688 1689
1689 accept(Visitor visitor) => visitor.visitLibraryName(this); 1690 accept(Visitor visitor) => visitor.visitLibraryName(this);
1690 1691
1691 visitChildren(Visitor visitor) => name.accept(visitor); 1692 visitChildren(Visitor visitor) => name.accept(visitor);
1692 1693
1693 Token getBeginToken() => libraryKeyword; 1694 Token getBeginToken() => libraryKeyword;
1694 1695
1695 Token getEndToken() => name.getEndToken().next; 1696 Token getEndToken() => name.getEndToken().next;
1696 } 1697 }
1697 1698
1698 class Import extends LibraryTag { 1699 /**
1700 * This tag describes a dependency between one library and the exported
1701 * identifiers of another library. The other library is specified by the [uri].
1702 * Combinators filter away some identifiers from the other library.
1703 */
1704 abstract class LibraryDependency extends LibraryTag {
1699 final LiteralString uri; 1705 final LiteralString uri;
1700 final Identifier prefix;
1701 final NodeList combinators; 1706 final NodeList combinators;
1702 1707
1708 LibraryDependency(this.uri, this.combinators);
1709 }
1710
1711 /**
1712 * An [:import:] library tag.
1713 *
1714 * An import tag is dependency on another library where the exported identifiers
1715 * are put into the import scope of the importing library. The import scope is
1716 * only visible inside the library.
1717 */
1718 class Import extends LibraryDependency {
1719 final Identifier prefix;
1703 final Token importKeyword; 1720 final Token importKeyword;
1704 1721
1705 Import(this.importKeyword, this.uri, this.prefix, this.combinators); 1722 Import(this.importKeyword, LiteralString uri,
1723 this.prefix, NodeList combinators)
1724 : super(uri, combinators);
1706 1725
1707 bool get isImport => true; 1726 bool get isImport => true;
1708 1727
1709 Import asImport() => this; 1728 Import asImport() => this;
1710 1729
1711 Token get asKeyword => prefix == null ? null : uri.getEndToken().next; 1730 Token get asKeyword => prefix == null ? null : uri.getEndToken().next;
1712 1731
1713 accept(Visitor visitor) => visitor.visitImport(this); 1732 accept(Visitor visitor) => visitor.visitImport(this);
1714 1733
1715 visitChildren(Visitor visitor) { 1734 visitChildren(Visitor visitor) {
1716 uri.accept(visitor); 1735 uri.accept(visitor);
1717 if (prefix !== null) prefix.accept(visitor); 1736 if (prefix !== null) prefix.accept(visitor);
1718 if (combinators !== null) combinators.accept(visitor); 1737 if (combinators !== null) combinators.accept(visitor);
1719 } 1738 }
1720 1739
1721 Token getBeginToken() => importKeyword; 1740 Token getBeginToken() => importKeyword;
1722 1741
1723 Token getEndToken() { 1742 Token getEndToken() {
1724 if (combinators !== null) return combinators.getEndToken().next; 1743 if (combinators !== null) return combinators.getEndToken().next;
1725 if (prefix !== null) return prefix.getEndToken().next; 1744 if (prefix !== null) return prefix.getEndToken().next;
1726 return uri.getEndToken().next; 1745 return uri.getEndToken().next;
1727 } 1746 }
1728 } 1747 }
1729 1748
1730 class Export extends LibraryTag { 1749 /**
1731 final LiteralString uri; 1750 * An [:export:] library tag.
1732 final NodeList combinators; 1751 *
1733 1752 * An export tag is dependency on another library where the exported identifiers
1753 * are put into the export scope of the exporting library. The export scope is
1754 * not visible inside the library.
1755 */
1756 class Export extends LibraryDependency {
1734 final Token exportKeyword; 1757 final Token exportKeyword;
1735 1758
1736 Export(this.exportKeyword, this.uri, this.combinators); 1759 Export(this.exportKeyword, LiteralString uri, NodeList combinators)
1760 : super(uri, combinators);
1737 1761
1738 bool get isExport => true; 1762 bool get isExport => true;
1739 1763
1740 Export asExport() => this; 1764 Export asExport() => this;
1741 1765
1742 accept(Visitor visitor) => visitor.visitExport(this); 1766 accept(Visitor visitor) => visitor.visitExport(this);
1743 1767
1744 visitChildren(Visitor visitor) { 1768 visitChildren(Visitor visitor) {
1745 uri.accept(visitor); 1769 uri.accept(visitor);
1746 if (combinators !== null) combinators.accept(visitor); 1770 if (combinators !== null) combinators.accept(visitor);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 * argument). 2016 * argument).
1993 * 2017 *
1994 * TODO(ahe): This method is controversial, the team needs to discuss 2018 * TODO(ahe): This method is controversial, the team needs to discuss
1995 * if top-level methods are acceptable and what naming conventions to 2019 * if top-level methods are acceptable and what naming conventions to
1996 * use. 2020 * use.
1997 */ 2021 */
1998 initializerDo(Node node, f(Node node)) { 2022 initializerDo(Node node, f(Node node)) {
1999 SendSet send = node.asSendSet(); 2023 SendSet send = node.asSendSet();
2000 if (send !== null) return f(send.arguments.head); 2024 if (send !== null) return f(send.arguments.head);
2001 } 2025 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/scanner/scanner_task.dart ('k') | lib/compiler/implementation/tree/prettyprint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698