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

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

Issue 10666052: Revert "Implement override checks." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 checkMembers(element);
239 }); 232 });
240 } 233 }
241 234
242 checkMembers(ClassElement cls) {
243 if (cls === compiler.objectClass) return;
244 cls.forEachMember((holder, member) {
245 checkAbstractField(member);
246 checkValidOverride(member, cls.lookupSuperMember(member.name));
247 });
248 }
249
250 void checkAbstractField(Element member) {
251 if (member is !AbstractFieldElement) return;
252 if (member.getter === null) return;
253 if (member.setter === null) return;
254 int getterFlags = member.getter.modifiers.flags | Modifiers.FLAG_ABSTRACT;
255 int setterFlags = member.setter.modifiers.flags | Modifiers.FLAG_ABSTRACT;
256 if (getterFlags !== setterFlags) {
257 final mismatchedFlags =
258 new Modifiers.withFlags(null, getterFlags ^ setterFlags);
259 compiler.reportMessage(
260 compiler.spanFromElement(member.getter),
261 MessageKind.GETTER_MISMATCH.error([mismatchedFlags]),
262 api.Diagnostic.ERROR);
263 compiler.reportMessage(
264 compiler.spanFromElement(member.setter),
265 MessageKind.SETTER_MISMATCH.error([mismatchedFlags]),
266 api.Diagnostic.ERROR);
267 }
268 }
269
270 reportErrorWithContext(Element errorneousElement,
271 MessageKind errorMessage,
272 Element contextElement,
273 MessageKind contextMessage) {
274 compiler.reportMessage(
275 compiler.spanFromElement(errorneousElement),
276 errorMessage.error([contextElement.name,
277 contextElement.getEnclosingClass().name]),
278 api.Diagnostic.ERROR);
279 compiler.reportMessage(
280 compiler.spanFromElement(contextElement),
281 contextMessage.error(),
282 api.Diagnostic.INFO);
283 }
284
285
286 void checkValidOverride(Element member, Element superMember) {
287 if (superMember === null) return;
288 if (member.modifiers.isStatic()) {
289 reportErrorWithContext(
290 member, MessageKind.NO_STATIC_OVERRIDE,
291 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT);
292 } else {
293 FunctionElement superFunction = superMember.asFunctionElement();
294 FunctionElement function = member.asFunctionElement();
295 if (superFunction === null || superFunction.isAccessor()) {
296 // Field or accessor in super.
297 if (function !== null && !function.isAccessor()) {
298 // But a plain method in this class.
299 reportErrorWithContext(
300 member, MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD,
301 superMember, MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT);
302 }
303 } else {
304 // Instance method in super.
305 if (function === null || function.isAccessor()) {
306 // But a field (or accessor) in this class.
307 reportErrorWithContext(
308 member, MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD,
309 superMember, MessageKind.CANNOT_OVERRIDE_METHOD_WITH_FIELD_CONT);
310 } else {
311 // Both are plain instance methods.
312 if (superFunction.requiredParameterCount(compiler) !=
313 function.requiredParameterCount(compiler)) {
314 reportErrorWithContext(
315 member,
316 MessageKind.BAD_ARITY_OVERRIDE,
317 superMember,
318 MessageKind.BAD_ARITY_OVERRIDE_CONT);
319 }
320 // TODO(ahe): Check optional parameters.
321 }
322 }
323 }
324 }
325
326 FunctionSignature resolveSignature(FunctionElement element) { 235 FunctionSignature resolveSignature(FunctionElement element) {
327 return compiler.withCurrentElement(element, () { 236 return compiler.withCurrentElement(element, () {
328 FunctionExpression node = 237 FunctionExpression node =
329 compiler.parser.measure(() => element.parseNode(compiler)); 238 compiler.parser.measure(() => element.parseNode(compiler));
330 return measure(() => SignatureResolver.analyze( 239 return measure(() => SignatureResolver.analyze(
331 compiler, node.parameters, node.returnType, element)); 240 compiler, node.parameters, node.returnType, element));
332 }); 241 });
333 } 242 }
334 243
335 FunctionSignature resolveTypedef(TypedefElement element) { 244 FunctionSignature resolveTypedef(TypedefElement element) {
(...skipping 1849 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 2094
2186 TopScope(LibraryElement library) : super(null, library); 2095 TopScope(LibraryElement library) : super(null, library);
2187 Element lookup(SourceString name) { 2096 Element lookup(SourceString name) {
2188 return library.find(name); 2097 return library.find(name);
2189 } 2098 }
2190 2099
2191 Element add(Element newElement) { 2100 Element add(Element newElement) {
2192 throw "Cannot add an element in the top scope"; 2101 throw "Cannot add an element in the top scope";
2193 } 2102 }
2194 } 2103 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/tree/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698