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 interface TreeElements { | 5 interface TreeElements { |
6 Element operator[](Node node); | 6 Element operator[](Node node); |
7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
8 Type getType(TypeAnnotation annotation); | 8 Type getType(TypeAnnotation annotation); |
9 } | 9 } |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return compiler.withCurrentElement(element, () { | 107 return compiler.withCurrentElement(element, () { |
108 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; | 108 bool isConstructor = element.kind === ElementKind.GENERATIVE_CONSTRUCTOR; |
109 TreeElements elements = | 109 TreeElements elements = |
110 compiler.enqueuer.resolution.getCachedElements(element); | 110 compiler.enqueuer.resolution.getCachedElements(element); |
111 if (elements !== null) { | 111 if (elements !== null) { |
112 assert(isConstructor); | 112 assert(isConstructor); |
113 return elements; | 113 return elements; |
114 } | 114 } |
115 FunctionExpression tree = element.parseNode(compiler); | 115 FunctionExpression tree = element.parseNode(compiler); |
116 if (isConstructor) { | 116 if (isConstructor) { |
| 117 if (tree.returnType !== null) { |
| 118 error(tree, MessageKind.CONSTRUCTOR_WITH_RETURN_TYPE); |
| 119 } |
117 resolveConstructorImplementation(element, tree); | 120 resolveConstructorImplementation(element, tree); |
118 } | 121 } |
119 ResolverVisitor visitor = new ResolverVisitor(compiler, element); | 122 ResolverVisitor visitor = new ResolverVisitor(compiler, element); |
120 visitor.useElement(tree, element); | 123 visitor.useElement(tree, element); |
121 visitor.setupFunction(tree, element); | 124 visitor.setupFunction(tree, element); |
122 | 125 |
123 if (isConstructor) { | 126 if (isConstructor) { |
124 // Even if there is no initializer list we still have to do the | 127 // Even if there is no initializer list we still have to do the |
125 // resolution in case there is an implicit super constructor call. | 128 // resolution in case there is an implicit super constructor call. |
126 InitializerResolver resolver = new InitializerResolver(visitor); | 129 InitializerResolver resolver = new InitializerResolver(visitor); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 ClassResolverVisitor visitor = | 269 ClassResolverVisitor visitor = |
267 new ClassResolverVisitor(compiler, element); | 270 new ClassResolverVisitor(compiler, element); |
268 visitor.visit(tree); | 271 visitor.visit(tree); |
269 element.resolutionState = STATE_DONE; | 272 element.resolutionState = STATE_DONE; |
270 })); | 273 })); |
271 } | 274 } |
272 | 275 |
273 void checkMembers(ClassElement cls) { | 276 void checkMembers(ClassElement cls) { |
274 if (cls === compiler.objectClass) return; | 277 if (cls === compiler.objectClass) return; |
275 cls.forEachMember((holder, member) { | 278 cls.forEachMember((holder, member) { |
| 279 |
| 280 // Check modifiers. |
| 281 if (member.isFunction() && member.modifiers.isFinal()) { |
| 282 compiler.reportMessage( |
| 283 compiler.spanFromElement(member), |
| 284 MessageKind.ILLEGAL_FINAL_METHOD_MODIFIER.error(), |
| 285 api.Diagnostic.ERROR); |
| 286 } |
| 287 if (member.isConstructor()) { |
| 288 final mismatchedFlagsBits = |
| 289 member.modifiers.flags & |
| 290 (Modifiers.FLAG_STATIC | Modifiers.FLAG_ABSTRACT); |
| 291 if (mismatchedFlagsBits != 0) { |
| 292 final mismatchedFlags = |
| 293 new Modifiers.withFlags(null, mismatchedFlagsBits); |
| 294 compiler.reportMessage( |
| 295 compiler.spanFromElement(member), |
| 296 MessageKind.ILLEGAL_CONSTRUCTOR_MODIFIERS.error([mismatchedFlags]), |
| 297 api.Diagnostic.ERROR); |
| 298 } |
| 299 } |
276 checkAbstractField(member); | 300 checkAbstractField(member); |
277 checkValidOverride(member, cls.lookupSuperMember(member.name)); | 301 checkValidOverride(member, cls.lookupSuperMember(member.name)); |
278 }); | 302 }); |
279 } | 303 } |
280 | 304 |
281 void checkAbstractField(Element member) { | 305 void checkAbstractField(Element member) { |
282 // Only check for getters. The test can only fail if there is both a setter | 306 // Only check for getters. The test can only fail if there is both a setter |
283 // and a getter with the same name, and we only need to check each abstract | 307 // and a getter with the same name, and we only need to check each abstract |
284 // field once, so we just ignore setters. | 308 // field once, so we just ignore setters. |
285 if (!member.isGetter()) return; | 309 if (!member.isGetter()) return; |
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 TopScope(LibraryElement library) : super(null, library); | 2606 TopScope(LibraryElement library) : super(null, library); |
2583 Element lookup(SourceString name) { | 2607 Element lookup(SourceString name) { |
2584 return library.find(name); | 2608 return library.find(name); |
2585 } | 2609 } |
2586 | 2610 |
2587 Element add(Element newElement) { | 2611 Element add(Element newElement) { |
2588 throw "Cannot add an element in the top scope"; | 2612 throw "Cannot add an element in the top scope"; |
2589 } | 2613 } |
2590 String toString() => '$element'; | 2614 String toString() => '$element'; |
2591 } | 2615 } |
OLD | NEW |