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

Side by Side Diff: dart/lib/compiler/implementation/resolver.dart

Issue 10575033: Implement override checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 6 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 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 222 }
223 223
224 void resolveClass(ClassElement element) { 224 void resolveClass(ClassElement element) {
225 if (element.isResolved) return; 225 if (element.isResolved) return;
226 measure(() { 226 measure(() {
227 ClassNode tree = element.parseNode(compiler); 227 ClassNode tree = element.parseNode(compiler);
228 ClassResolverVisitor visitor = 228 ClassResolverVisitor visitor =
229 new ClassResolverVisitor(compiler, element.getLibrary(), element); 229 new ClassResolverVisitor(compiler, element.getLibrary(), element);
230 visitor.visit(tree); 230 visitor.visit(tree);
231 element.isResolved = true; 231 element.isResolved = true;
232
233 while (!toResolve.isEmpty()) {
234 ClassElement classElement = toResolve.removeFirst();
235 classElement.ensureResolved(compiler);
236 }
237
238 checkOverrides(element);
232 }); 239 });
233 } 240 }
234 241
242 checkOverrides(ClassElement cls) {
243 if (cls === compiler.objectClass) return;
244 cls.forEachMember((holder, member) {
245 Element superMember = cls.lookupSuperMember(member.name);
246 if (superMember !== null) {
247 if (member.modifiers.isStatic()) {
248 compiler.cancel('Static members cannot override', element: member);
249 } else {
250 FunctionElement superFunction = superMember.asFunctionElement();
251 FunctionElement function = member.asFunctionElement();
252 if (superFunction === null || superFunction.isAccessor()) {
253 // Field or accessor in super.
254 if (function !== null && !function.isAccessor()) {
255 // But a plain method in this class.
256 compiler.cancel('Cannot override field with method',
257 element: member);
258 }
259 } else {
260 // Instance method in super.
261 if (function === null || function.isAccessor()) {
262 // But a field in this class.
karlklose 2012/06/20 13:51:31 ... or accessor ...?
ahe 2012/06/22 12:50:33 Done.
263 compiler.cancel('Cannot override method with field',
264 element: member);
265 } else {
266 // Both are plain instance methods.
267 if (superFunction.requiredParameterCount(compiler) !=
268 function.requiredParameterCount(compiler)) {
269 compiler.cancel('Bad override', element: member);
270 }
271 // TODO(ahe): Check optional parameters.
272 }
273 }
274 }
275 }
276 });
277 }
278
235 FunctionSignature resolveSignature(FunctionElement element) { 279 FunctionSignature resolveSignature(FunctionElement element) {
236 return compiler.withCurrentElement(element, () { 280 return compiler.withCurrentElement(element, () {
237 FunctionExpression node = 281 FunctionExpression node =
238 compiler.parser.measure(() => element.parseNode(compiler)); 282 compiler.parser.measure(() => element.parseNode(compiler));
239 return measure(() => SignatureResolver.analyze( 283 return measure(() => SignatureResolver.analyze(
240 compiler, node.parameters, node.returnType, element)); 284 compiler, node.parameters, node.returnType, element));
241 }); 285 });
242 } 286 }
243 287
244 FunctionSignature resolveTypedef(TypedefElement element) { 288 FunctionSignature resolveTypedef(TypedefElement element) {
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 2137
2094 TopScope(LibraryElement library) : super(null, library); 2138 TopScope(LibraryElement library) : super(null, library);
2095 Element lookup(SourceString name) { 2139 Element lookup(SourceString name) {
2096 return library.find(name); 2140 return library.find(name);
2097 } 2141 }
2098 2142
2099 Element add(Element newElement) { 2143 Element add(Element newElement) {
2100 throw "Cannot add an element in the top scope"; 2144 throw "Cannot add an element in the top scope";
2101 } 2145 }
2102 } 2146 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/elements/elements.dart ('k') | dart/lib/isolate/frog/ports.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698