Chromium Code Reviews| 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element operator[](Node node); | 8 Element operator[](Node node); |
| 9 Selector getSelector(Send send); | 9 Selector getSelector(Send send); |
| 10 DartType getType(Node node); | 10 DartType getType(Node node); |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 int illegalFlags = modifiers.flags & ~Modifiers.FLAG_ABSTRACT; | 502 int illegalFlags = modifiers.flags & ~Modifiers.FLAG_ABSTRACT; |
| 503 if (illegalFlags != 0) { | 503 if (illegalFlags != 0) { |
| 504 Modifiers illegalModifiers = new Modifiers.withFlags(null, illegalFlags); | 504 Modifiers illegalModifiers = new Modifiers.withFlags(null, illegalFlags); |
| 505 CompilationError error = | 505 CompilationError error = |
| 506 MessageKind.ILLEGAL_MIXIN_APPLICATION_MODIFIERS.error( | 506 MessageKind.ILLEGAL_MIXIN_APPLICATION_MODIFIERS.error( |
| 507 [illegalModifiers]); | 507 [illegalModifiers]); |
| 508 compiler.reportMessage(compiler.spanFromSpannable(modifiers), | 508 compiler.reportMessage(compiler.spanFromSpannable(modifiers), |
| 509 error, Diagnostic.ERROR); | 509 error, Diagnostic.ERROR); |
| 510 } | 510 } |
| 511 | 511 |
| 512 // In case of cyclic mixin applications, the mixin chain will have | |
| 513 // been cut. If so, we have already reported the error to the | |
| 514 // user so we just return from here. | |
| 515 ClassElement mixin = mixinApplication.mixin; | |
| 516 if (mixin == null) return; | |
| 517 | |
| 512 // Check that the mixed in class has Object as its superclass. | 518 // Check that the mixed in class has Object as its superclass. |
| 513 ClassElement mixin = mixinApplication.mixin; | |
| 514 if (!mixin.superclass.isObject(compiler)) { | 519 if (!mixin.superclass.isObject(compiler)) { |
| 515 CompilationError error = MessageKind.ILLEGAL_MIXIN_SUPERCLASS.error(); | 520 CompilationError error = MessageKind.ILLEGAL_MIXIN_SUPERCLASS.error(); |
| 516 compiler.reportMessage(compiler.spanFromElement(mixin), | 521 compiler.reportMessage(compiler.spanFromElement(mixin), |
| 517 error, Diagnostic.ERROR); | 522 error, Diagnostic.ERROR); |
| 518 } | 523 } |
| 519 | 524 |
| 520 // Check that the mixed in class doesn't have any constructors. | 525 // Check that the mixed in class doesn't have any constructors. |
| 521 mixin.forEachLocalMember((Element member) { | 526 mixin.forEachLocalMember((Element member) { |
| 522 if (member.isGenerativeConstructor() && !member.isSynthesized) { | 527 if (member.isGenerativeConstructor() && !member.isSynthesized) { |
| 523 CompilationError error = MessageKind.ILLEGAL_MIXIN_CONSTRUCTOR.error(); | 528 CompilationError error = MessageKind.ILLEGAL_MIXIN_CONSTRUCTOR.error(); |
| (...skipping 2370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2894 Link<DartType> interfaces = const Link<DartType>(); | 2899 Link<DartType> interfaces = const Link<DartType>(); |
| 2895 interfaces = interfaces.prepend(mixinType); | 2900 interfaces = interfaces.prepend(mixinType); |
| 2896 assert(mixinApplication.interfaces == null); | 2901 assert(mixinApplication.interfaces == null); |
| 2897 mixinApplication.interfaces = interfaces; | 2902 mixinApplication.interfaces = interfaces; |
| 2898 | 2903 |
| 2899 assert(mixinApplication.mixin == null); | 2904 assert(mixinApplication.mixin == null); |
| 2900 mixinApplication.mixin = mixinType.element; | 2905 mixinApplication.mixin = mixinType.element; |
| 2901 mixinApplication.mixin.ensureResolved(compiler); | 2906 mixinApplication.mixin.ensureResolved(compiler); |
| 2902 mixinApplication.addDefaultConstructorIfNeeded(compiler); | 2907 mixinApplication.addDefaultConstructorIfNeeded(compiler); |
| 2903 calculateAllSupertypes(mixinApplication); | 2908 calculateAllSupertypes(mixinApplication); |
| 2909 | |
| 2910 // Check for cycles in the mixin chain. | |
| 2911 ClassElement previous = mixinApplication; | |
| 2912 ClassElement current = mixinApplication.mixin; | |
| 2913 while (current != null && current.isMixinApplication) { | |
| 2914 MixinApplicationElement currentMixinApplication = current; | |
| 2915 if (currentMixinApplication == mixinApplication) { | |
| 2916 CompilationError error = MessageKind.ILLEGAL_MIXIN_CYCLE.error( | |
| 2917 [current.name, previous.name]); | |
| 2918 compiler.reportMessage(compiler.spanFromElement(mixinApplication), | |
| 2919 error, Diagnostic.ERROR); | |
| 2920 // Set the mixin to null to avoid running into issues where | |
| 2921 // traversing the members will result in infinite recursion. | |
| 2922 mixinApplication.mixin = null; | |
| 2923 break; | |
| 2924 } | |
| 2925 previous = current; | |
| 2926 current = currentMixinApplication.mixin; | |
| 2927 } | |
|
Johnni Winther
2013/01/22 13:16:41
I don't think this handles the case when [mixinApp
| |
| 2904 } | 2928 } |
| 2905 | 2929 |
| 2906 | 2930 |
| 2907 // TODO(johnniwinther): Remove when default class is no longer supported. | 2931 // TODO(johnniwinther): Remove when default class is no longer supported. |
| 2908 DartType visitTypeAnnotation(TypeAnnotation node) { | 2932 DartType visitTypeAnnotation(TypeAnnotation node) { |
| 2909 return visit(node.typeName); | 2933 return visit(node.typeName); |
| 2910 } | 2934 } |
| 2911 | 2935 |
| 2912 // TODO(johnniwinther): Remove when default class is no longer supported. | 2936 // TODO(johnniwinther): Remove when default class is no longer supported. |
| 2913 DartType visitIdentifier(Identifier node) { | 2937 DartType visitIdentifier(Identifier node) { |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3509 return e; | 3533 return e; |
| 3510 } | 3534 } |
| 3511 | 3535 |
| 3512 /// Assumed to be called by [resolveRedirectingFactory]. | 3536 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3513 Element visitReturn(Return node) { | 3537 Element visitReturn(Return node) { |
| 3514 Node expression = node.expression; | 3538 Node expression = node.expression; |
| 3515 return finishConstructorReference(visit(expression), | 3539 return finishConstructorReference(visit(expression), |
| 3516 expression, expression); | 3540 expression, expression); |
| 3517 } | 3541 } |
| 3518 } | 3542 } |
| OLD | NEW |