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

Side by Side Diff: pkg/compiler/lib/src/tree/nodes.dart

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

Powered by Google App Engine
This is Rietveld 408576698