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

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: Update and fix status files. Implement missing functions. Created 5 years 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/patch_parser.dart ('k') | pkg/compiler/lib/src/tree/prettyprint.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);
11 11
12 R visitAssert(Assert node) => visitStatement(node); 12 R visitAssert(Assert node) => visitStatement(node);
13 R visitAsyncForIn(AsyncForIn node) => visitLoop(node); 13 R visitAsyncForIn(AsyncForIn node) => visitLoop(node);
14 R visitAsyncModifier(AsyncModifier node) => visitNode(node); 14 R visitAsyncModifier(AsyncModifier node) => visitNode(node);
15 R visitAwait(Await node) => visitExpression(node); 15 R visitAwait(Await node) => visitExpression(node);
16 R visitBlock(Block node) => visitStatement(node); 16 R visitBlock(Block node) => visitStatement(node);
17 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node); 17 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node);
18 R visitCascade(Cascade node) => visitExpression(node); 18 R visitCascade(Cascade node) => visitExpression(node);
19 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node); 19 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node);
20 R visitCaseMatch(CaseMatch node) => visitNode(node); 20 R visitCaseMatch(CaseMatch node) => visitNode(node);
21 R visitCatchBlock(CatchBlock node) => visitNode(node); 21 R visitCatchBlock(CatchBlock node) => visitNode(node);
22 R visitClassNode(ClassNode node) => visitNode(node); 22 R visitClassNode(ClassNode node) => visitNode(node);
23 R visitCombinator(Combinator node) => visitNode(node); 23 R visitCombinator(Combinator node) => visitNode(node);
24 R visitConditional(Conditional node) => visitExpression(node); 24 R visitConditional(Conditional node) => visitExpression(node);
25 R visitConditionalUri(ConditionalUri node) => visitNode(node);
25 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node); 26 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node);
27 R visitDottedName(DottedName node) => visitExpression(node);
26 R visitDoWhile(DoWhile node) => visitLoop(node); 28 R visitDoWhile(DoWhile node) => visitLoop(node);
27 R visitEmptyStatement(EmptyStatement node) => visitStatement(node); 29 R visitEmptyStatement(EmptyStatement node) => visitStatement(node);
28 R visitEnum(Enum node) => visitNode(node); 30 R visitEnum(Enum node) => visitNode(node);
29 R visitExport(Export node) => visitLibraryDependency(node); 31 R visitExport(Export node) => visitLibraryDependency(node);
30 R visitExpression(Expression node) => visitNode(node); 32 R visitExpression(Expression node) => visitNode(node);
31 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node); 33 R visitExpressionStatement(ExpressionStatement node) => visitStatement(node);
32 R visitFor(For node) => visitLoop(node); 34 R visitFor(For node) => visitLoop(node);
33 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node); 35 R visitFunctionDeclaration(FunctionDeclaration node) => visitStatement(node);
34 R visitFunctionExpression(FunctionExpression node) => visitExpression(node); 36 R visitFunctionExpression(FunctionExpression node) => visitExpression(node);
35 R visitGotoStatement(GotoStatement node) => visitStatement(node); 37 R visitGotoStatement(GotoStatement node) => visitStatement(node);
36 R visitIdentifier(Identifier node) => visitExpression(node); 38 R visitIdentifier(Identifier node) => visitExpression(node);
39 R visitImport(Import node) => visitLibraryDependency(node);
37 R visitIf(If node) => visitStatement(node); 40 R visitIf(If node) => visitStatement(node);
38 R visitImport(Import node) => visitLibraryDependency(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 DottedName asDottedName() => 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 be a DottedNamed.
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 DottedName extends Expression {
1078 final Token token;
1079 final NodeList identifiers;
1080
1081 DottedName(this.token, this.identifiers);
1082
1083 DottedName asDottedName() => this;
1084
1085 void visitChildren(Visitor visitor) {
1086 identifiers.accept(visitor);
1087 }
1088
1089 accept(Visitor visitor) => visitor.visitDottedName(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;
2008
2009 bool get hasConditionalUris => conditionalUris != null;
1975 } 2010 }
1976 2011
1977 /** 2012 /**
1978 * An [:import:] library tag. 2013 * An [:import:] library tag.
1979 * 2014 *
1980 * An import tag is dependency on another library where the exported identifiers 2015 * 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 2016 * are put into the import scope of the importing library. The import scope is
1982 * only visible inside the library. 2017 * only visible inside the library.
1983 */ 2018 */
1984 class Import extends LibraryDependency { 2019 class Import extends LibraryDependency {
1985 final Identifier prefix; 2020 final Identifier prefix;
1986 final Token importKeyword; 2021 final Token importKeyword;
1987 final bool isDeferred; 2022 final bool isDeferred;
1988 2023
1989 Import(this.importKeyword, StringNode uri, 2024 Import(this.importKeyword, StringNode uri, NodeList conditionalUris,
1990 this.prefix, NodeList combinators, 2025 this.prefix, NodeList combinators,
1991 List<MetadataAnnotation> metadata, 2026 List<MetadataAnnotation> metadata,
1992 {this.isDeferred}) 2027 {this.isDeferred})
1993 : super(uri, combinators, metadata); 2028 : super(uri, conditionalUris, combinators, metadata);
1994 2029
1995 bool get isImport => true; 2030 bool get isImport => true;
1996 2031
1997 Import asImport() => this; 2032 Import asImport() => this;
1998 2033
1999 accept(Visitor visitor) => visitor.visitImport(this); 2034 accept(Visitor visitor) => visitor.visitImport(this);
2000 2035
2001 visitChildren(Visitor visitor) { 2036 visitChildren(Visitor visitor) {
2002 uri.accept(visitor); 2037 uri.accept(visitor);
2003 if (prefix != null) prefix.accept(visitor); 2038 if (prefix != null) prefix.accept(visitor);
2004 if (combinators != null) combinators.accept(visitor); 2039 if (combinators != null) combinators.accept(visitor);
2005 } 2040 }
2006 2041
2007 Token getBeginToken() => importKeyword; 2042 Token getBeginToken() => importKeyword;
2008 2043
2009 Token getEndToken() { 2044 Token getEndToken() {
2010 if (combinators != null) return combinators.getEndToken().next; 2045 if (combinators != null) return combinators.getEndToken().next;
2011 if (prefix != null) return prefix.getEndToken().next; 2046 if (prefix != null) return prefix.getEndToken().next;
2047 if (conditionalUris != null) return conditionalUris.getEndToken().next;
2012 return uri.getEndToken().next; 2048 return uri.getEndToken().next;
2013 } 2049 }
2014 } 2050 }
2015 2051
2016 /** 2052 /**
2053 * A conditional uri inside an import or export clause.
2054 *
2055 * Example:
2056 *
2057 * import 'foo.dart'
2058 * if (some.condition == "someValue") 'bar.dart'
2059 * if (other.condition) 'gee.dart';
2060 */
2061 class ConditionalUri extends Node {
2062 final Token ifToken;
2063 final DottedName key;
2064 // Value may be null.
2065 final LiteralString value;
2066 final StringNode uri;
2067
2068 ConditionalUri(this.ifToken, this.key, this.value, this.uri);
2069
2070 ConditionalUri asConditionalUri() => this;
2071
2072 accept(Visitor visitor) => visitor.visitConditionalUri(this);
2073
2074 visitChildren(Visitor visitor) {
2075 key.accept(visitor);
2076 if (value != null) value.accept(visitor);
2077 uri.accept(visitor);
2078 }
2079
2080 Token getBeginToken() => ifToken;
2081
2082 Token getEndToken() => uri.getEndToken();
2083 }
2084
2085 /**
2017 * An `enum` declaration. 2086 * An `enum` declaration.
2018 * 2087 *
2019 * An `enum` defines a number of named constants inside a non-extensible class 2088 * An `enum` defines a number of named constants inside a non-extensible class
2020 */ 2089 */
2021 class Enum extends Node { 2090 class Enum extends Node {
2022 /** The name of the enum class. */ 2091 /** The name of the enum class. */
2023 final Identifier name; 2092 final Identifier name;
2024 /** The names of the enum constants. */ 2093 /** The names of the enum constants. */
2025 final NodeList names; 2094 final NodeList names;
2026 final Token enumToken; 2095 final Token enumToken;
(...skipping 18 matching lines...) Expand all
2045 * 2114 *
2046 * An export tag is dependency on another library where the exported identifiers 2115 * 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 2116 * are put into the export scope of the exporting library. The export scope is
2048 * not visible inside the library. 2117 * not visible inside the library.
2049 */ 2118 */
2050 class Export extends LibraryDependency { 2119 class Export extends LibraryDependency {
2051 final Token exportKeyword; 2120 final Token exportKeyword;
2052 2121
2053 Export(this.exportKeyword, 2122 Export(this.exportKeyword,
2054 StringNode uri, 2123 StringNode uri,
2124 NodeList conditionalUris,
2055 NodeList combinators, 2125 NodeList combinators,
2056 List<MetadataAnnotation> metadata) 2126 List<MetadataAnnotation> metadata)
2057 : super(uri, combinators, metadata); 2127 : super(uri, conditionalUris, combinators, metadata);
2058 2128
2059 bool get isExport => true; 2129 bool get isExport => true;
2060 2130
2061 Export asExport() => this; 2131 Export asExport() => this;
2062 2132
2063 accept(Visitor visitor) => visitor.visitExport(this); 2133 accept(Visitor visitor) => visitor.visitExport(this);
2064 2134
2065 visitChildren(Visitor visitor) { 2135 visitChildren(Visitor visitor) {
2066 uri.accept(visitor); 2136 uri.accept(visitor);
2067 if (combinators != null) combinators.accept(visitor); 2137 if (combinators != null) combinators.accept(visitor);
2068 } 2138 }
2069 2139
2070 Token getBeginToken() => exportKeyword; 2140 Token getBeginToken() => exportKeyword;
2071 2141
2072 Token getEndToken() { 2142 Token getEndToken() {
2073 if (combinators != null) return combinators.getEndToken().next; 2143 if (combinators != null) return combinators.getEndToken().next;
2144 if (conditionalUris != null) return conditionalUris.getEndToken().next;
2074 return uri.getEndToken().next; 2145 return uri.getEndToken().next;
2075 } 2146 }
2076 } 2147 }
2077 2148
2078 class Part extends LibraryTag { 2149 class Part extends LibraryTag {
2079 final StringNode uri; 2150 final StringNode uri;
2080 2151
2081 final Token partKeyword; 2152 final Token partKeyword;
2082 2153
2083 Part(this.partKeyword, this.uri, List<MetadataAnnotation> metadata) 2154 Part(this.partKeyword, this.uri, List<MetadataAnnotation> metadata)
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 2444
2374 // VariableDefinitions. 2445 // VariableDefinitions.
2375 get metadata => null; 2446 get metadata => null;
2376 get type => null; 2447 get type => null;
2377 2448
2378 // Typedef. 2449 // Typedef.
2379 get typeParameters => null; 2450 get typeParameters => null;
2380 get formals => null; 2451 get formals => null;
2381 get typedefKeyword => null; 2452 get typedefKeyword => null;
2382 } 2453 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/patch_parser.dart ('k') | pkg/compiler/lib/src/tree/prettyprint.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698