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 library elements; | 5 library elements; |
6 | 6 |
7 import 'dart:uri'; | 7 import 'dart:uri'; |
8 | 8 |
9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. | 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. |
10 import '../../compiler.dart' as api_e; | 10 import '../../compiler.dart' as api_e; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 get patch => unsupported(); | 418 get patch => unsupported(); |
419 get origin => unsupported(); | 419 get origin => unsupported(); |
420 get defaultImplementation => unsupported(); | 420 get defaultImplementation => unsupported(); |
421 bool get isPatched => unsupported(); | 421 bool get isPatched => unsupported(); |
422 bool get isPatch => unsupported(); | 422 bool get isPatch => unsupported(); |
423 setPatch(patch) => unsupported(); | 423 setPatch(patch) => unsupported(); |
424 computeSignature(compiler) => unsupported(); | 424 computeSignature(compiler) => unsupported(); |
425 requiredParameterCount(compiler) => unsupported(); | 425 requiredParameterCount(compiler) => unsupported(); |
426 optionalParameterCount(compiler) => unsupported(); | 426 optionalParameterCount(compiler) => unsupported(); |
427 parameterCount(copmiler) => unsupported(); | 427 parameterCount(copmiler) => unsupported(); |
| 428 |
| 429 get redirectionTarget => this; |
428 } | 430 } |
429 | 431 |
430 /** | 432 /** |
431 * An ambiguous element represent multiple elements accessible by the same name. | 433 * An ambiguous element represent multiple elements accessible by the same name. |
432 * | 434 * |
433 * Ambiguous elements are created during handling of import/export scopes. If an | 435 * Ambiguous elements are created during handling of import/export scopes. If an |
434 * ambiguous element is encountered during resolution a warning/error should be | 436 * ambiguous element is encountered during resolution a warning/error should be |
435 * reported. | 437 * reported. |
436 */ | 438 */ |
437 class AmbiguousElement extends Element { | 439 class AmbiguousElement extends Element { |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1134 /** | 1136 /** |
1135 * A function declaration that should be parsed instead of the current one. | 1137 * A function declaration that should be parsed instead of the current one. |
1136 * The patch should be parsed as if it was in the current scope. Its | 1138 * The patch should be parsed as if it was in the current scope. Its |
1137 * signature must match this function's signature. | 1139 * signature must match this function's signature. |
1138 */ | 1140 */ |
1139 // TODO(lrn): Consider using [defaultImplementation] to store the patch. | 1141 // TODO(lrn): Consider using [defaultImplementation] to store the patch. |
1140 FunctionElement patch = null; | 1142 FunctionElement patch = null; |
1141 FunctionElement origin = null; | 1143 FunctionElement origin = null; |
1142 | 1144 |
1143 /** | 1145 /** |
1144 * If this is an interface constructor, [defaultImplementation] will | 1146 * If this is a redirecting factory, [defaultImplementation] will be |
1145 * changed by the resolver to point to the default | 1147 * changed by the resolver to point to the redirection target. If |
1146 * implementation. Otherwise, [:defaultImplementation === this:]. | 1148 * this is an interface constructor, [defaultImplementation] will be |
| 1149 * changed by the resolver to point to the default implementation. |
| 1150 * Otherwise, [:defaultImplementation === this:]. |
1147 */ | 1151 */ |
| 1152 // TODO(ahe): Rename this field to redirectionTarget and remove |
| 1153 // mention of interface constructors above. |
1148 FunctionElement defaultImplementation; | 1154 FunctionElement defaultImplementation; |
1149 | 1155 |
1150 FunctionElement(SourceString name, | 1156 FunctionElement(SourceString name, |
1151 ElementKind kind, | 1157 ElementKind kind, |
1152 Modifiers modifiers, | 1158 Modifiers modifiers, |
1153 Element enclosing) | 1159 Element enclosing) |
1154 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null); | 1160 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null); |
1155 | 1161 |
1156 FunctionElement.node(SourceString name, | 1162 FunctionElement.node(SourceString name, |
1157 FunctionExpression node, | 1163 FunctionExpression node, |
(...skipping 16 matching lines...) Expand all Loading... |
1174 Element enclosing, | 1180 Element enclosing, |
1175 FunctionSignature this.functionSignature) | 1181 FunctionSignature this.functionSignature) |
1176 : super(name, kind, enclosing) { | 1182 : super(name, kind, enclosing) { |
1177 assert(modifiers != null); | 1183 assert(modifiers != null); |
1178 defaultImplementation = this; | 1184 defaultImplementation = this; |
1179 } | 1185 } |
1180 | 1186 |
1181 bool get isPatched => patch != null; | 1187 bool get isPatched => patch != null; |
1182 bool get isPatch => origin != null; | 1188 bool get isPatch => origin != null; |
1183 | 1189 |
| 1190 FunctionElement get redirectionTarget { |
| 1191 if (this == defaultImplementation) return this; |
| 1192 Element target = defaultImplementation; |
| 1193 Set<Element> seen = new Set<Element>(); |
| 1194 seen.add(target); |
| 1195 while (!target.isErroneous() && target != target.defaultImplementation) { |
| 1196 target = target.defaultImplementation; |
| 1197 if (seen.contains(target)) { |
| 1198 // TODO(ahe): This is expedient for now, but it should be |
| 1199 // checked by the resolver. Keeping http://dartbug.com/3970 |
| 1200 // open to track this. |
| 1201 throw new SpannableAssertionFailure( |
| 1202 target, 'redirecting factory leads to cycle'); |
| 1203 } |
| 1204 } |
| 1205 return target; |
| 1206 } |
| 1207 |
1184 /** | 1208 /** |
1185 * Applies a patch function to this function. The patch function's body | 1209 * Applies a patch function to this function. The patch function's body |
1186 * is used as replacement when parsing this function's body. | 1210 * is used as replacement when parsing this function's body. |
1187 * This method must not be called after the function has been parsed, | 1211 * This method must not be called after the function has been parsed, |
1188 * and it must be called at most once. | 1212 * and it must be called at most once. |
1189 */ | 1213 */ |
1190 void setPatch(FunctionElement patchElement) { | 1214 void setPatch(FunctionElement patchElement) { |
1191 // Sanity checks. The caller must check these things before calling. | 1215 // Sanity checks. The caller must check these things before calling. |
1192 assert(patch == null); | 1216 assert(patch == null); |
1193 this.patch = patchElement; | 1217 this.patch = patchElement; |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 | 2020 |
1997 MetadataAnnotation ensureResolved(Compiler compiler) { | 2021 MetadataAnnotation ensureResolved(Compiler compiler) { |
1998 if (resolutionState == STATE_NOT_STARTED) { | 2022 if (resolutionState == STATE_NOT_STARTED) { |
1999 compiler.resolver.resolveMetadataAnnotation(this); | 2023 compiler.resolver.resolveMetadataAnnotation(this); |
2000 } | 2024 } |
2001 return this; | 2025 return this; |
2002 } | 2026 } |
2003 | 2027 |
2004 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 2028 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
2005 } | 2029 } |
OLD | NEW |