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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/elements/elements.dart

Issue 11365108: Implement redirecting constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 8 years, 1 month 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
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/resolution/members.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 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 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 /** 1094 /**
1095 * A function declaration that should be parsed instead of the current one. 1095 * A function declaration that should be parsed instead of the current one.
1096 * The patch should be parsed as if it was in the current scope. Its 1096 * The patch should be parsed as if it was in the current scope. Its
1097 * signature must match this function's signature. 1097 * signature must match this function's signature.
1098 */ 1098 */
1099 // TODO(lrn): Consider using [defaultImplementation] to store the patch. 1099 // TODO(lrn): Consider using [defaultImplementation] to store the patch.
1100 FunctionElement patch = null; 1100 FunctionElement patch = null;
1101 FunctionElement origin = null; 1101 FunctionElement origin = null;
1102 1102
1103 /** 1103 /**
1104 * If this is an interface constructor, [defaultImplementation] will 1104 * If this is a redirecting factory, [defaultImplementation] will be
1105 * changed by the resolver to point to the default 1105 * changed by the resolver to point to the redirection target. If
1106 * implementation. Otherwise, [:defaultImplementation === this:]. 1106 * this is an interface constructor, [defaultImplementation] will
Johnni Winther 2012/11/07 08:15:39 will => will be
ahe 2012/11/07 14:22:16 Done.
1107 * changed by the resolver to point to the default implementation.
1108 * Otherwise, [:defaultImplementation === this:].
1107 */ 1109 */
1110 // TODO(ahe): Rename this field to redirectionTarget and remove
1111 // mention of interface constructors above.
1108 FunctionElement defaultImplementation; 1112 FunctionElement defaultImplementation;
1109 1113
1110 FunctionElement(SourceString name, 1114 FunctionElement(SourceString name,
1111 ElementKind kind, 1115 ElementKind kind,
1112 Modifiers modifiers, 1116 Modifiers modifiers,
1113 Element enclosing) 1117 Element enclosing)
1114 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null); 1118 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null);
1115 1119
1116 FunctionElement.node(SourceString name, 1120 FunctionElement.node(SourceString name,
1117 FunctionExpression node, 1121 FunctionExpression node,
(...skipping 16 matching lines...) Expand all
1134 Element enclosing, 1138 Element enclosing,
1135 FunctionSignature this.functionSignature) 1139 FunctionSignature this.functionSignature)
1136 : super(name, kind, enclosing) { 1140 : super(name, kind, enclosing) {
1137 assert(modifiers != null); 1141 assert(modifiers != null);
1138 defaultImplementation = this; 1142 defaultImplementation = this;
1139 } 1143 }
1140 1144
1141 bool get isPatched => patch != null; 1145 bool get isPatched => patch != null;
1142 bool get isPatch => origin != null; 1146 bool get isPatch => origin != null;
1143 1147
1148 FunctionExpression get redirectionTarget {
1149 if (this == defaultImplementation) return this;
1150 Element target = defaultImplementation;
1151 Set<Element> seen = new Set<Element>();
1152 seen.add(target);
1153 while (target != target.defaultImplementation) {
1154 target = target.defaultImplementation;
1155 if (seen.contains(target)) {
1156 // TODO(ahe): This is expedient for now, but it should be
1157 // checked by the resolver. Keeping http://dartbug.com/3970
1158 // open to track this.
1159 throw new SpannableAssertionFailure(
1160 target, 'redirecting factory leads to cycle');
1161 }
1162 }
1163 return target;
1164 }
1165
1144 /** 1166 /**
1145 * Applies a patch function to this function. The patch function's body 1167 * Applies a patch function to this function. The patch function's body
1146 * is used as replacement when parsing this function's body. 1168 * is used as replacement when parsing this function's body.
1147 * This method must not be called after the function has been parsed, 1169 * This method must not be called after the function has been parsed,
1148 * and it must be called at most once. 1170 * and it must be called at most once.
1149 */ 1171 */
1150 void setPatch(FunctionElement patchElement) { 1172 void setPatch(FunctionElement patchElement) {
1151 // Sanity checks. The caller must check these things before calling. 1173 // Sanity checks. The caller must check these things before calling.
1152 assert(patch == null); 1174 assert(patch == null);
1153 this.patch = patchElement; 1175 this.patch = patchElement;
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 1978
1957 MetadataAnnotation ensureResolved(Compiler compiler) { 1979 MetadataAnnotation ensureResolved(Compiler compiler) {
1958 if (resolutionState == STATE_NOT_STARTED) { 1980 if (resolutionState == STATE_NOT_STARTED) {
1959 compiler.resolver.resolveMetadataAnnotation(this); 1981 compiler.resolver.resolveMetadataAnnotation(this);
1960 } 1982 }
1961 return this; 1983 return this;
1962 } 1984 }
1963 1985
1964 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 1986 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1965 } 1987 }
OLDNEW
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698