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

Side by Side Diff: dart/pkg/compiler/lib/src/elements/modelx.dart

Issue 841303002: Non fatal errors on duplicated accessors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42766. Created 5 years, 11 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
« no previous file with comments | « no previous file | dart/pkg/compiler/lib/src/resolution/class_members.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library elements.modelx; 5 library elements.modelx;
6 6
7 import 'elements.dart'; 7 import 'elements.dart';
8 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
9 import '../helpers/helpers.dart'; // Included for debug helpers. 9 import '../helpers/helpers.dart'; // Included for debug helpers.
10 import '../tree/tree.dart'; 10 import '../tree/tree.dart';
11 import '../util/util.dart'; 11 import '../util/util.dart';
12 import '../resolution/resolution.dart'; 12 import '../resolution/resolution.dart';
13 import '../resolution/class_members.dart' show ClassMemberMixin; 13 import '../resolution/class_members.dart' show ClassMemberMixin;
14 14
15 import '../dart2jslib.dart' show 15 import '../dart2jslib.dart' show
16 Backend, 16 Backend,
17 Compiler, 17 Compiler,
18 CompilerCancelledException,
19 Constant, 18 Constant,
20 DartType, 19 DartType,
21 DiagnosticListener, 20 DiagnosticListener,
22 DualKind, 21 DualKind,
23 FunctionType, 22 FunctionType,
24 InterfaceType, 23 InterfaceType,
25 MessageKind, 24 MessageKind,
26 Script, 25 Script,
27 Selector, 26 Selector,
28 TypeVariableType, 27 TypeVariableType,
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 392 }
394 if (unwrapped.isWarnOnUse) { 393 if (unwrapped.isWarnOnUse) {
395 unwrapped = unwrapped.unwrap(listener, usageSpannable); 394 unwrapped = unwrapped.unwrap(listener, usageSpannable);
396 } 395 }
397 return unwrapped; 396 return unwrapped;
398 } 397 }
399 398
400 accept(ElementVisitor visitor) => visitor.visitWarnOnUseElement(this); 399 accept(ElementVisitor visitor) => visitor.visitWarnOnUseElement(this);
401 } 400 }
402 401
403 class AmbiguousElementX extends ElementX implements AmbiguousElement { 402 abstract class AmbiguousElementX extends ElementX implements AmbiguousElement {
404 /** 403 /**
405 * The message to report on resolving this element. 404 * The message to report on resolving this element.
406 */ 405 */
407 final MessageKind messageKind; 406 final MessageKind messageKind;
408 407
409 /** 408 /**
410 * The message arguments to report on resolving this element. 409 * The message arguments to report on resolving this element.
411 */ 410 */
412 final Map messageArguments; 411 final Map messageArguments;
413 412
(...skipping 18 matching lines...) Expand all
432 var set = new Setlet(); 431 var set = new Setlet();
433 while (element.isAmbiguous) { 432 while (element.isAmbiguous) {
434 AmbiguousElement ambiguous = element; 433 AmbiguousElement ambiguous = element;
435 set.add(ambiguous.newElement); 434 set.add(ambiguous.newElement);
436 element = ambiguous.existingElement; 435 element = ambiguous.existingElement;
437 } 436 }
438 set.add(element); 437 set.add(element);
439 return set; 438 return set;
440 } 439 }
441 440
441 accept(ElementVisitor visitor) => visitor.visitAmbiguousElement(this);
442
443 bool get isTopLevel => false;
444 }
445
446 /// Element synthesized to diagnose an ambiguous import.
447 class AmbiguousImportX extends AmbiguousElementX {
448 AmbiguousImportX(
449 MessageKind messageKind,
450 Map messageArguments,
451 Element enclosingElement, Element existingElement, Element newElement)
452 : super(messageKind, messageArguments, enclosingElement, existingElement,
453 newElement);
454
442 void diagnose(Element context, DiagnosticListener listener) { 455 void diagnose(Element context, DiagnosticListener listener) {
443 Setlet ambiguousElements = flatten(); 456 Setlet ambiguousElements = flatten();
444 MessageKind code = (ambiguousElements.length == 1) 457 MessageKind code = (ambiguousElements.length == 1)
445 ? MessageKind.AMBIGUOUS_REEXPORT : MessageKind.AMBIGUOUS_LOCATION; 458 ? MessageKind.AMBIGUOUS_REEXPORT : MessageKind.AMBIGUOUS_LOCATION;
446 LibraryElementX importer = context.library; 459 LibraryElementX importer = context.library;
447 for (Element element in ambiguousElements) { 460 for (Element element in ambiguousElements) {
448 var arguments = {'name': element.name}; 461 var arguments = {'name': element.name};
449 listener.reportInfo(element, code, arguments); 462 listener.reportInfo(element, code, arguments);
450 Link<Import> importers = importer.importers.getImports(element); 463 Link<Import> importers = importer.importers.getImports(element);
451 listener.withCurrentElement(importer, () { 464 listener.withCurrentElement(importer, () {
452 for (; !importers.isEmpty; importers = importers.tail) { 465 for (; !importers.isEmpty; importers = importers.tail) {
453 listener.reportInfo( 466 listener.reportInfo(
454 importers.head, MessageKind.IMPORTED_HERE, arguments); 467 importers.head, MessageKind.IMPORTED_HERE, arguments);
455 } 468 }
456 }); 469 });
457 } 470 }
458 } 471 }
472 }
459 473
460 accept(ElementVisitor visitor) => visitor.visitAmbiguousElement(this); 474 /// Element synthesized to recover from a duplicated member of an element.
461 475 class DuplicatedElementX extends AmbiguousElementX {
462 bool get isTopLevel => false; 476 DuplicatedElementX(
477 MessageKind messageKind,
478 Map messageArguments,
479 Element enclosingElement, Element existingElement, Element newElement)
480 : super(messageKind, messageArguments, enclosingElement, existingElement,
481 newElement);
463 } 482 }
464 483
465 class ScopeX { 484 class ScopeX {
466 final Map<String, Element> contents = new Map<String, Element>(); 485 final Map<String, Element> contents = new Map<String, Element>();
467 486
468 bool get isEmpty => contents.isEmpty; 487 bool get isEmpty => contents.isEmpty;
469 Iterable<Element> get values => contents.values; 488 Iterable<Element> get values => contents.values;
470 489
471 Element lookup(String name) { 490 Element lookup(String name) {
472 return contents[name]; 491 return contents[name];
(...skipping 29 matching lines...) Expand all
502 */ 521 */
503 void addAccessor(FunctionElementX accessor, 522 void addAccessor(FunctionElementX accessor,
504 Element existing, 523 Element existing,
505 DiagnosticListener listener) { 524 DiagnosticListener listener) {
506 void reportError(Element other) { 525 void reportError(Element other) {
507 listener.reportError(accessor, 526 listener.reportError(accessor,
508 MessageKind.DUPLICATE_DEFINITION, 527 MessageKind.DUPLICATE_DEFINITION,
509 {'name': accessor.name}); 528 {'name': accessor.name});
510 listener.reportInfo( 529 listener.reportInfo(
511 other, MessageKind.EXISTING_DEFINITION, {'name': accessor.name}); 530 other, MessageKind.EXISTING_DEFINITION, {'name': accessor.name});
512 // TODO(ahe): Don't throw, recover from error. 531
513 throw new CompilerCancelledException(null); 532 contents[accessor.name] = new DuplicatedElementX(
533 MessageKind.DUPLICATE_DEFINITION, {'name': accessor.name},
534 accessor.memberContext.enclosingElement, other, accessor);
514 } 535 }
515 536
516 if (existing != null) { 537 if (existing != null) {
517 if (!identical(existing.kind, ElementKind.ABSTRACT_FIELD)) { 538 if (!identical(existing.kind, ElementKind.ABSTRACT_FIELD)) {
518 reportError(existing); 539 reportError(existing);
519 return; 540 return;
520 } else { 541 } else {
521 AbstractFieldElementX field = existing; 542 AbstractFieldElementX field = existing;
522 accessor.abstractField = field; 543 accessor.abstractField = field;
523 if (accessor.isGetter) { 544 if (accessor.isGetter) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 if (import == null) { 732 if (import == null) {
712 // [element] is imported implicitly (probably through dart:core). 733 // [element] is imported implicitly (probably through dart:core).
713 registerWarnOnUseElement( 734 registerWarnOnUseElement(
714 existingImport, MessageKind.HIDDEN_IMPLICIT_IMPORT, 735 existingImport, MessageKind.HIDDEN_IMPLICIT_IMPORT,
715 existing, element); 736 existing, element);
716 } else { 737 } else {
717 registerWarnOnUseElement( 738 registerWarnOnUseElement(
718 import, MessageKind.HIDDEN_IMPORT, existing, element); 739 import, MessageKind.HIDDEN_IMPORT, existing, element);
719 } 740 }
720 } else { 741 } else {
721 Element ambiguousElement = new AmbiguousElementX( 742 Element ambiguousElement = new AmbiguousImportX(
722 MessageKind.DUPLICATE_IMPORT, {'name': name}, 743 MessageKind.DUPLICATE_IMPORT, {'name': name},
723 enclosingElement, existing, element); 744 enclosingElement, existing, element);
724 importScope[name] = ambiguousElement; 745 importScope[name] = ambiguousElement;
725 importers.registerImport(ambiguousElement, import); 746 importers.registerImport(ambiguousElement, import);
726 importers.registerImport(ambiguousElement, existingImport); 747 importers.registerImport(ambiguousElement, existingImport);
727 } 748 }
728 } 749 }
729 } 750 }
730 751
731 Element operator [](String name) => importScope[name]; 752 Element operator [](String name) => importScope[name];
(...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 AstElement get definingElement; 2938 AstElement get definingElement;
2918 2939
2919 bool get hasResolvedAst => definingElement.hasTreeElements; 2940 bool get hasResolvedAst => definingElement.hasTreeElements;
2920 2941
2921 ResolvedAst get resolvedAst { 2942 ResolvedAst get resolvedAst {
2922 return new ResolvedAst(declaration, 2943 return new ResolvedAst(declaration,
2923 definingElement.node, definingElement.treeElements); 2944 definingElement.node, definingElement.treeElements);
2924 } 2945 }
2925 2946
2926 } 2947 }
OLDNEW
« no previous file with comments | « no previous file | dart/pkg/compiler/lib/src/resolution/class_members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698