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 part of tree; | 5 part of tree; |
6 | 6 |
7 abstract class Visitor<R> { | 7 abstract class Visitor<R> { |
8 const Visitor(); | 8 const Visitor(); |
9 | 9 |
10 R visitNode(Node node); | 10 R visitNode(Node node); |
(...skipping 16 matching lines...) Expand all Loading... |
27 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); | 27 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); |
28 R visitEnum(Enum node) => visitNode(node); | 28 R visitEnum(Enum node) => visitNode(node); |
29 R visitExport(Export node) => visitLibraryDependency(node); | 29 R visitExport(Export node) => visitLibraryDependency(node); |
30 R visitExpression(Expression node) => visitNode(node); | 30 R visitExpression(Expression node) => visitNode(node); |
31 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); | 31 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); |
32 R visitFor(For node) => visitLoop(node); | 32 R visitFor(For node) => visitLoop(node); |
33 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node); | 33 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node); |
34 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); | 34 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); |
35 R visitGotoStatement(GotoStatement node) => visitStatement(node); | 35 R visitGotoStatement(GotoStatement node) => visitStatement(node); |
36 R visitIdentifier(Identifier node) => visitExpression(node); | 36 R visitIdentifier(Identifier node) => visitExpression(node); |
37 R visitDottedName(DottedName node) => visitExpression(node); | |
38 R visitIf(If node) => visitStatement(node); | 37 R visitIf(If node) => visitStatement(node); |
39 R visitConditionalUri(ConditionalUri node) => visitNode(node); | 38 R visitImport(Import node) => visitLibraryDependency(node); |
40 R visitLabel(Label node) => visitNode(node); | 39 R visitLabel(Label node) => visitNode(node); |
41 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); | 40 R visitLabeledStatement(LabeledStatement node) => visitStatement(node); |
42 R visitLibraryDependency(LibraryDependency node) => visitLibraryTag(node); | 41 R visitLibraryDependency(LibraryDependency node) => visitLibraryTag(node); |
43 R visitLibraryName(LibraryName node) => visitLibraryTag(node); | 42 R visitLibraryName(LibraryName node) => visitLibraryTag(node); |
44 R visitLibraryTag(LibraryTag node) => visitNode(node); | 43 R visitLibraryTag(LibraryTag node) => visitNode(node); |
45 R visitLiteral(Literal node) => visitExpression(node); | 44 R visitLiteral(Literal node) => visitExpression(node); |
46 R visitLiteralBool(LiteralBool node) => visitLiteral(node); | 45 R visitLiteralBool(LiteralBool node) => visitLiteral(node); |
47 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); | 46 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); |
48 R visitLiteralInt(LiteralInt node) => visitLiteral(node); | 47 R visitLiteralInt(LiteralInt node) => visitLiteral(node); |
49 R visitLiteralList(LiteralList node) => visitExpression(node); | 48 R visitLiteralList(LiteralList node) => visitExpression(node); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 Await asAwait() => null; | 152 Await asAwait() => null; |
154 Block asBlock() => null; | 153 Block asBlock() => null; |
155 BreakStatement asBreakStatement() => null; | 154 BreakStatement asBreakStatement() => null; |
156 Cascade asCascade() => null; | 155 Cascade asCascade() => null; |
157 CascadeReceiver asCascadeReceiver() => null; | 156 CascadeReceiver asCascadeReceiver() => null; |
158 CaseMatch asCaseMatch() => null; | 157 CaseMatch asCaseMatch() => null; |
159 CatchBlock asCatchBlock() => null; | 158 CatchBlock asCatchBlock() => null; |
160 ClassNode asClassNode() => null; | 159 ClassNode asClassNode() => null; |
161 Combinator asCombinator() => null; | 160 Combinator asCombinator() => null; |
162 Conditional asConditional() => null; | 161 Conditional asConditional() => null; |
163 ConditionalUri asConditionalUri() => null; | |
164 ContinueStatement asContinueStatement() => null; | 162 ContinueStatement asContinueStatement() => null; |
165 DottedName asDottedName() => null; | |
166 DoWhile asDoWhile() => null; | 163 DoWhile asDoWhile() => null; |
167 EmptyStatement asEmptyStatement() => null; | 164 EmptyStatement asEmptyStatement() => null; |
168 Enum asEnum() => null; | 165 Enum asEnum() => null; |
169 ErrorExpression asErrorExpression() => null; | 166 ErrorExpression asErrorExpression() => null; |
170 Export asExport() => null; | 167 Export asExport() => null; |
171 Expression asExpression() => null; | 168 Expression asExpression() => null; |
172 ExpressionStatement asExpressionStatement() => null; | 169 ExpressionStatement asExpressionStatement() => null; |
173 For asFor() => null; | 170 For asFor() => null; |
174 SyncForIn asSyncForIn() => null; | 171 SyncForIn asSyncForIn() => null; |
175 AsyncForIn asAsyncForIn() => null; | 172 AsyncForIn asAsyncForIn() => null; |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 Token getBeginToken() { | 1015 Token getBeginToken() { |
1019 if (constKeyword != null) return constKeyword; | 1016 if (constKeyword != null) return constKeyword; |
1020 return firstBeginToken(typeArguments, elements); | 1017 return firstBeginToken(typeArguments, elements); |
1021 } | 1018 } |
1022 | 1019 |
1023 Token getEndToken() => elements.getEndToken(); | 1020 Token getEndToken() => elements.getEndToken(); |
1024 } | 1021 } |
1025 | 1022 |
1026 class LiteralSymbol extends Expression { | 1023 class LiteralSymbol extends Expression { |
1027 final Token hashToken; | 1024 final Token hashToken; |
1028 // TODO: this could be a DottedNamed. | |
1029 final NodeList identifiers; | 1025 final NodeList identifiers; |
1030 | 1026 |
1031 LiteralSymbol(this.hashToken, this.identifiers); | 1027 LiteralSymbol(this.hashToken, this.identifiers); |
1032 | 1028 |
1033 LiteralSymbol asLiteralSymbol() => this; | 1029 LiteralSymbol asLiteralSymbol() => this; |
1034 | 1030 |
1035 void visitChildren(Visitor visitor) { | 1031 void visitChildren(Visitor visitor) { |
1036 if (identifiers != null) identifiers.accept(visitor); | 1032 if (identifiers != null) identifiers.accept(visitor); |
1037 } | 1033 } |
1038 | 1034 |
(...skipping 25 matching lines...) Expand all Loading... |
1064 | 1060 |
1065 accept(Visitor visitor) => visitor.visitIdentifier(this); | 1061 accept(Visitor visitor) => visitor.visitIdentifier(this); |
1066 | 1062 |
1067 visitChildren(Visitor visitor) {} | 1063 visitChildren(Visitor visitor) {} |
1068 | 1064 |
1069 Token getBeginToken() => token; | 1065 Token getBeginToken() => token; |
1070 | 1066 |
1071 Token getEndToken() => token; | 1067 Token getEndToken() => token; |
1072 } | 1068 } |
1073 | 1069 |
1074 // TODO(floitsch): a dotted identifier isn't really an expression. Should it | |
1075 // inherit from Node instead? | |
1076 class DottedName extends Expression { | |
1077 final Token token; | |
1078 final NodeList identifiers; | |
1079 | |
1080 DottedName(this.token, this.identifiers); | |
1081 | |
1082 DottedName asDottedName() => this; | |
1083 | |
1084 void visitChildren(Visitor visitor) { | |
1085 identifiers.accept(visitor); | |
1086 } | |
1087 | |
1088 accept(Visitor visitor) => visitor.visitDottedName(this); | |
1089 | |
1090 Token getBeginToken() => token; | |
1091 Token getEndToken() => identifiers.getEndToken(); | |
1092 | |
1093 String get slowNameString { | |
1094 Unparser unparser = new Unparser(); | |
1095 unparser.unparseNodeListOfIdentifiers(identifiers); | |
1096 return unparser.result; | |
1097 } | |
1098 } | |
1099 | |
1100 class Operator extends Identifier { | 1070 class Operator extends Identifier { |
1101 static const COMPLEX_OPERATORS = | 1071 static const COMPLEX_OPERATORS = |
1102 const ["--", "++", '+=', "-=", "*=", "/=", "%=", "&=", "|=", "~/=", "^=", | 1072 const ["--", "++", '+=', "-=", "*=", "/=", "%=", "&=", "|=", "~/=", "^=", |
1103 ">>=", "<<=", "??="]; | 1073 ">>=", "<<=", "??="]; |
1104 | 1074 |
1105 static const INCREMENT_OPERATORS = const <String>["++", "--"]; | 1075 static const INCREMENT_OPERATORS = const <String>["++", "--"]; |
1106 | 1076 |
1107 Operator(Token token) : super(token); | 1077 Operator(Token token) : super(token); |
1108 | 1078 |
1109 Operator asOperator() => this; | 1079 Operator asOperator() => this; |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 Token getEndToken() => name.getEndToken().next; | 1957 Token getEndToken() => name.getEndToken().next; |
1988 } | 1958 } |
1989 | 1959 |
1990 /** | 1960 /** |
1991 * This tag describes a dependency between one library and the exported | 1961 * This tag describes a dependency between one library and the exported |
1992 * identifiers of another library. The other library is specified by the [uri]. | 1962 * identifiers of another library. The other library is specified by the [uri]. |
1993 * Combinators filter away some identifiers from the other library. | 1963 * Combinators filter away some identifiers from the other library. |
1994 */ | 1964 */ |
1995 abstract class LibraryDependency extends LibraryTag { | 1965 abstract class LibraryDependency extends LibraryTag { |
1996 final StringNode uri; | 1966 final StringNode uri; |
1997 final NodeList conditionalUris; | |
1998 final NodeList combinators; | 1967 final NodeList combinators; |
1999 | 1968 |
2000 LibraryDependency(this.uri, | 1969 LibraryDependency(this.uri, |
2001 this.conditionalUris, | |
2002 this.combinators, | 1970 this.combinators, |
2003 List<MetadataAnnotation> metadata) | 1971 List<MetadataAnnotation> metadata) |
2004 : super(metadata); | 1972 : super(metadata); |
2005 | 1973 |
2006 LibraryDependency asLibraryDependency() => this; | 1974 LibraryDependency asLibraryDependency() => this; |
2007 | |
2008 bool get hasConditionalUris => conditionalUris != null; | |
2009 } | 1975 } |
2010 | 1976 |
2011 /** | 1977 /** |
2012 * An [:import:] library tag. | 1978 * An [:import:] library tag. |
2013 * | 1979 * |
2014 * An import tag is dependency on another library where the exported identifiers | 1980 * An import tag is dependency on another library where the exported identifiers |
2015 * are put into the import scope of the importing library. The import scope is | 1981 * are put into the import scope of the importing library. The import scope is |
2016 * only visible inside the library. | 1982 * only visible inside the library. |
2017 */ | 1983 */ |
2018 class Import extends LibraryDependency { | 1984 class Import extends LibraryDependency { |
2019 final Identifier prefix; | 1985 final Identifier prefix; |
2020 final Token importKeyword; | 1986 final Token importKeyword; |
2021 final bool isDeferred; | 1987 final bool isDeferred; |
2022 | 1988 |
2023 Import(this.importKeyword, StringNode uri, NodeList conditionalUris, | 1989 Import(this.importKeyword, StringNode uri, |
2024 this.prefix, NodeList combinators, | 1990 this.prefix, NodeList combinators, |
2025 List<MetadataAnnotation> metadata, | 1991 List<MetadataAnnotation> metadata, |
2026 {this.isDeferred}) | 1992 {this.isDeferred}) |
2027 : super(uri, conditionalUris, combinators, metadata); | 1993 : super(uri, combinators, metadata); |
2028 | 1994 |
2029 bool get isImport => true; | 1995 bool get isImport => true; |
2030 | 1996 |
2031 Import asImport() => this; | 1997 Import asImport() => this; |
2032 | 1998 |
2033 accept(Visitor visitor) => visitor.visitImport(this); | 1999 accept(Visitor visitor) => visitor.visitImport(this); |
2034 | 2000 |
2035 visitChildren(Visitor visitor) { | 2001 visitChildren(Visitor visitor) { |
2036 uri.accept(visitor); | 2002 uri.accept(visitor); |
2037 if (prefix != null) prefix.accept(visitor); | 2003 if (prefix != null) prefix.accept(visitor); |
2038 if (combinators != null) combinators.accept(visitor); | 2004 if (combinators != null) combinators.accept(visitor); |
2039 } | 2005 } |
2040 | 2006 |
2041 Token getBeginToken() => importKeyword; | 2007 Token getBeginToken() => importKeyword; |
2042 | 2008 |
2043 Token getEndToken() { | 2009 Token getEndToken() { |
2044 if (combinators != null) return combinators.getEndToken().next; | 2010 if (combinators != null) return combinators.getEndToken().next; |
2045 if (prefix != null) return prefix.getEndToken().next; | 2011 if (prefix != null) return prefix.getEndToken().next; |
2046 if (conditionalUris != null) return conditionalUris.getEndToken().next; | |
2047 return uri.getEndToken().next; | 2012 return uri.getEndToken().next; |
2048 } | 2013 } |
2049 } | 2014 } |
2050 | 2015 |
2051 /** | 2016 /** |
2052 * A conditional uri inside an import or export clause. | |
2053 * | |
2054 * Example: | |
2055 * | |
2056 * import 'foo.dart' | |
2057 * if (some.condition == "someValue") 'bar.dart' | |
2058 * if (other.condition) 'gee.dart'; | |
2059 */ | |
2060 class ConditionalUri extends Node { | |
2061 final Token ifToken; | |
2062 final DottedName key; | |
2063 // Value may be null. | |
2064 final LiteralString value; | |
2065 final StringNode uri; | |
2066 | |
2067 ConditionalUri(this.ifToken, this.key, this.value, this.uri); | |
2068 | |
2069 ConditionalUri asConditionalUri() => this; | |
2070 | |
2071 accept(Visitor visitor) => visitor.visitConditionalUri(this); | |
2072 | |
2073 visitChildren(Visitor visitor) { | |
2074 key.accept(visitor); | |
2075 if (value != null) value.accept(visitor); | |
2076 uri.accept(visitor); | |
2077 } | |
2078 | |
2079 Token getBeginToken() => ifToken; | |
2080 | |
2081 Token getEndToken() => uri.getEndToken(); | |
2082 } | |
2083 | |
2084 /** | |
2085 * An `enum` declaration. | 2017 * An `enum` declaration. |
2086 * | 2018 * |
2087 * An `enum` defines a number of named constants inside a non-extensible class | 2019 * An `enum` defines a number of named constants inside a non-extensible class |
2088 */ | 2020 */ |
2089 class Enum extends Node { | 2021 class Enum extends Node { |
2090 /** The name of the enum class. */ | 2022 /** The name of the enum class. */ |
2091 final Identifier name; | 2023 final Identifier name; |
2092 /** The names of the enum constants. */ | 2024 /** The names of the enum constants. */ |
2093 final NodeList names; | 2025 final NodeList names; |
2094 final Token enumToken; | 2026 final Token enumToken; |
(...skipping 18 matching lines...) Expand all Loading... |
2113 * | 2045 * |
2114 * An export tag is dependency on another library where the exported identifiers | 2046 * An export tag is dependency on another library where the exported identifiers |
2115 * are put into the export scope of the exporting library. The export scope is | 2047 * are put into the export scope of the exporting library. The export scope is |
2116 * not visible inside the library. | 2048 * not visible inside the library. |
2117 */ | 2049 */ |
2118 class Export extends LibraryDependency { | 2050 class Export extends LibraryDependency { |
2119 final Token exportKeyword; | 2051 final Token exportKeyword; |
2120 | 2052 |
2121 Export(this.exportKeyword, | 2053 Export(this.exportKeyword, |
2122 StringNode uri, | 2054 StringNode uri, |
2123 NodeList conditionalUris, | |
2124 NodeList combinators, | 2055 NodeList combinators, |
2125 List<MetadataAnnotation> metadata) | 2056 List<MetadataAnnotation> metadata) |
2126 : super(uri, conditionalUris, combinators, metadata); | 2057 : super(uri, combinators, metadata); |
2127 | 2058 |
2128 bool get isExport => true; | 2059 bool get isExport => true; |
2129 | 2060 |
2130 Export asExport() => this; | 2061 Export asExport() => this; |
2131 | 2062 |
2132 accept(Visitor visitor) => visitor.visitExport(this); | 2063 accept(Visitor visitor) => visitor.visitExport(this); |
2133 | 2064 |
2134 visitChildren(Visitor visitor) { | 2065 visitChildren(Visitor visitor) { |
2135 uri.accept(visitor); | 2066 uri.accept(visitor); |
2136 if (combinators != null) combinators.accept(visitor); | 2067 if (combinators != null) combinators.accept(visitor); |
2137 } | 2068 } |
2138 | 2069 |
2139 Token getBeginToken() => exportKeyword; | 2070 Token getBeginToken() => exportKeyword; |
2140 | 2071 |
2141 Token getEndToken() { | 2072 Token getEndToken() { |
2142 if (combinators != null) return combinators.getEndToken().next; | 2073 if (combinators != null) return combinators.getEndToken().next; |
2143 if (conditionalUris != null) return conditionalUris.getEndToken().next; | |
2144 return uri.getEndToken().next; | 2074 return uri.getEndToken().next; |
2145 } | 2075 } |
2146 } | 2076 } |
2147 | 2077 |
2148 class Part extends LibraryTag { | 2078 class Part extends LibraryTag { |
2149 final StringNode uri; | 2079 final StringNode uri; |
2150 | 2080 |
2151 final Token partKeyword; | 2081 final Token partKeyword; |
2152 | 2082 |
2153 Part(this.partKeyword, this.uri, List<MetadataAnnotation> metadata) | 2083 Part(this.partKeyword, this.uri, List<MetadataAnnotation> metadata) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2443 | 2373 |
2444 // VariableDefinitions. | 2374 // VariableDefinitions. |
2445 get metadata => null; | 2375 get metadata => null; |
2446 get type => null; | 2376 get type => null; |
2447 | 2377 |
2448 // Typedef. | 2378 // Typedef. |
2449 get typeParameters => null; | 2379 get typeParameters => null; |
2450 get formals => null; | 2380 get formals => null; |
2451 get typedefKeyword => null; | 2381 get typedefKeyword => null; |
2452 } | 2382 } |
OLD | NEW |