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

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

Issue 14168003: Implement implicit constructors in mixin applications. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove debug code and rebase Created 7 years, 8 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 | Annotate | Revision Log
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 resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Set<Node> get superUses; 9 Set<Node> get superUses;
10 10
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 if (isConstructor) { 299 if (isConstructor) {
300 if (tree.returnType != null) { 300 if (tree.returnType != null) {
301 error(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE); 301 error(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE);
302 } 302 }
303 resolveConstructorImplementation(element, tree); 303 resolveConstructorImplementation(element, tree);
304 } 304 }
305 ResolverVisitor visitor = visitorFor(element); 305 ResolverVisitor visitor = visitorFor(element);
306 visitor.useElement(tree, element); 306 visitor.useElement(tree, element);
307 visitor.setupFunction(tree, element); 307 visitor.setupFunction(tree, element);
308 308
309 if (isConstructor) { 309 if (isConstructor && element is! ForwardingConstructorElement) {
ahe 2013/04/15 13:36:46 Can you call a method instead?
310 // Even if there is no initializer list we still have to do the 310 // Even if there is no initializer list we still have to do the
311 // resolution in case there is an implicit super constructor call. 311 // resolution in case there is an implicit super constructor call.
312 InitializerResolver resolver = new InitializerResolver(visitor); 312 InitializerResolver resolver = new InitializerResolver(visitor);
313 FunctionElement redirection = 313 FunctionElement redirection =
314 resolver.resolveInitializers(element, tree); 314 resolver.resolveInitializers(element, tree);
315 if (redirection != null) { 315 if (redirection != null) {
316 resolveRedirectingConstructor(resolver, tree, element, redirection); 316 resolveRedirectingConstructor(resolver, tree, element, redirection);
317 } 317 }
318 } else if (element is ForwardingConstructorElement) {
ahe 2013/04/15 13:36:46 Can you call a method instead?
319 // Initializers will be cehcked on the original constructor.
318 } else if (tree.initializers != null) { 320 } else if (tree.initializers != null) {
319 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); 321 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER);
320 } 322 }
321 visitBody(visitor, tree.body); 323 visitBody(visitor, tree.body);
322 324
323 // Get the resolution tree and check that the resolved 325 // Get the resolution tree and check that the resolved
324 // function doesn't use 'super' if it is mixed into another 326 // function doesn't use 'super' if it is mixed into another
325 // class. This is the part of the 'super' mixin check that 327 // class. This is the part of the 'super' mixin check that
326 // happens when a function is resolved after the mixin 328 // happens when a function is resolved after the mixin
327 // application has been performed. 329 // application has been performed.
(...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 resolveSelector(node.send); 2495 resolveSelector(node.send);
2494 resolveArguments(node.send.argumentsNode); 2496 resolveArguments(node.send.argumentsNode);
2495 useElement(node.send, constructor); 2497 useElement(node.send, constructor);
2496 if (Elements.isUnresolved(constructor)) return constructor; 2498 if (Elements.isUnresolved(constructor)) return constructor;
2497 Selector callSelector = mapping.getSelector(node.send); 2499 Selector callSelector = mapping.getSelector(node.send);
2498 if (!callSelector.applies(constructor, compiler)) { 2500 if (!callSelector.applies(constructor, compiler)) {
2499 warnArgumentMismatch(node.send, constructor); 2501 warnArgumentMismatch(node.send, constructor);
2500 compiler.backend.registerThrowNoSuchMethod(mapping); 2502 compiler.backend.registerThrowNoSuchMethod(mapping);
2501 } 2503 }
2502 compiler.withCurrentElement(constructor, () { 2504 compiler.withCurrentElement(constructor, () {
2503 FunctionExpression tree = constructor.parseNode(compiler); 2505 FunctionElement target = constructor;
2506 if (constructor is ForwardingConstructorElement) {
ahe 2013/04/15 13:36:46 Can you call a method instead.
2507 target = constructor.superConstructor;
2508 }
2509 FunctionExpression tree = target.parseNode(compiler);
ahe 2013/04/15 13:36:46 What happens if your superclass is itself a mixin
2504 compiler.resolver.resolveConstructorImplementation(constructor, tree); 2510 compiler.resolver.resolveConstructorImplementation(constructor, tree);
2505 }); 2511 });
2506 2512
2507 if (constructor.defaultImplementation != constructor) { 2513 if (constructor.defaultImplementation != constructor) {
2508 // Support for deprecated interface support. 2514 // Support for deprecated interface support.
2509 // TODO(ngeoffray): Remove once we remove such support. 2515 // TODO(ngeoffray): Remove once we remove such support.
2510 world.registerStaticUse(constructor.declaration); 2516 world.registerStaticUse(constructor.declaration);
2511 world.registerInstantiatedClass( 2517 world.registerInstantiatedClass(
2512 constructor.getEnclosingClass().declaration, mapping); 2518 constructor.getEnclosingClass().declaration, mapping);
2513 constructor = constructor.defaultImplementation; 2519 constructor = constructor.defaultImplementation;
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
3179 3185
3180 // The class that is the result of a mixin application implements 3186 // The class that is the result of a mixin application implements
3181 // the interface of the class that was mixed in so always prepend 3187 // the interface of the class that was mixed in so always prepend
3182 // that to the interface list. 3188 // that to the interface list.
3183 interfaces = interfaces.prepend(mixinType); 3189 interfaces = interfaces.prepend(mixinType);
3184 assert(mixinApplication.interfaces == null); 3190 assert(mixinApplication.interfaces == null);
3185 mixinApplication.interfaces = interfaces; 3191 mixinApplication.interfaces = interfaces;
3186 3192
3187 assert(mixinApplication.mixin == null); 3193 assert(mixinApplication.mixin == null);
3188 mixinApplication.mixin = resolveMixinFor(mixinApplication, mixinType); 3194 mixinApplication.mixin = resolveMixinFor(mixinApplication, mixinType);
3195
3196 // Create forwarding constructors for constructor defined in the super class
ahe 2013/04/15 13:36:46 superclass is one word.
3197 // because they are now hidden by the mixin application.
3198 ClassElement superclass = supertype.element;
3199 bool constructorsAdded = false;
ahe 2013/04/15 13:36:46 Where is this used?
3200 superclass.forEachLocalMember((Element member) {
3201 if (!member.isConstructor() || member.isSynthesized) return;
3202 assert(!member.isFactoryConstructor());
ahe 2013/04/15 13:36:46 Please use assert(invariant(...))
3203 FunctionElement constructor = member;
3204 SourceString constructorName;
3205 if (constructor.name == superclass.name) {
3206 if (constructor.computeSignature(compiler).parameterCount == 0) {
3207 return;
3208 }
3209 constructorName = mixinApplication.name;
3210 } else {
3211 SourceString selector =
3212 Elements.deconstructConstructorName(constructor.name, superclass);
3213 constructorName =
3214 Elements.constructConstructorName(mixinApplication.name, selector);
3215 }
3216 Element forwarder =
3217 new ForwardingConstructorElementX(constructorName, constructor,
3218 mixinApplication);
3219 mixinApplication.addToScope(forwarder, compiler);
3220 constructorsAdded = true;
3221 });
3189 mixinApplication.addDefaultConstructorIfNeeded(compiler); 3222 mixinApplication.addDefaultConstructorIfNeeded(compiler);
3190 calculateAllSupertypes(mixinApplication); 3223 calculateAllSupertypes(mixinApplication);
3191 } 3224 }
3192 3225
3193 ClassElement resolveMixinFor(MixinApplicationElement mixinApplication, 3226 ClassElement resolveMixinFor(MixinApplicationElement mixinApplication,
3194 DartType mixinType) { 3227 DartType mixinType) {
3195 ClassElement mixin = mixinType.element; 3228 ClassElement mixin = mixinType.element;
3196 mixin.ensureResolved(compiler); 3229 mixin.ensureResolved(compiler);
3197 3230
3198 // Check for cycles in the mixin chain. 3231 // Check for cycles in the mixin chain.
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
3876 return e; 3909 return e;
3877 } 3910 }
3878 3911
3879 /// Assumed to be called by [resolveRedirectingFactory]. 3912 /// Assumed to be called by [resolveRedirectingFactory].
3880 Element visitReturn(Return node) { 3913 Element visitReturn(Return node) {
3881 Node expression = node.expression; 3914 Node expression = node.expression;
3882 return finishConstructorReference(visit(expression), 3915 return finishConstructorReference(visit(expression),
3883 expression, expression); 3916 expression, expression);
3884 } 3917 }
3885 } 3918 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698