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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/elements.dart

Issue 11361124: Introduce AmbiguousElement (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 8 years, 1 month 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 library elements; 5 library elements;
6 6
7 import 'dart:uri'; 7 import 'dart:uri';
8 8
9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed.
10 import '../../compiler.dart' as api_e; 10 import '../../compiler.dart' as api_e;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 static const ElementKind TYPEDEF = 109 static const ElementKind TYPEDEF =
110 const ElementKind('typedef', ElementCategory.ALIAS); 110 const ElementKind('typedef', ElementCategory.ALIAS);
111 111
112 static const ElementKind STATEMENT = 112 static const ElementKind STATEMENT =
113 const ElementKind('statement', ElementCategory.NONE); 113 const ElementKind('statement', ElementCategory.NONE);
114 static const ElementKind LABEL = 114 static const ElementKind LABEL =
115 const ElementKind('label', ElementCategory.NONE); 115 const ElementKind('label', ElementCategory.NONE);
116 static const ElementKind VOID = 116 static const ElementKind VOID =
117 const ElementKind('void', ElementCategory.NONE); 117 const ElementKind('void', ElementCategory.NONE);
118 118
119 static const ElementKind AMBIGUOUS =
120 const ElementKind('ambiguous', ElementCategory.NONE);
119 static const ElementKind ERROR = 121 static const ElementKind ERROR =
120 const ElementKind('error', ElementCategory.NONE); 122 const ElementKind('error', ElementCategory.NONE);
121 123
122 toString() => id; 124 toString() => id;
123 } 125 }
124 126
125 class Element implements Spannable { 127 class Element implements Spannable {
126 static int elementHashCode = 0; 128 static int elementHashCode = 0;
127 129
128 final SourceString name; 130 final SourceString name;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 bool isSetter() => identical(kind, ElementKind.SETTER); 190 bool isSetter() => identical(kind, ElementKind.SETTER);
189 bool isAccessor() => isGetter() || isSetter(); 191 bool isAccessor() => isGetter() || isSetter();
190 bool isForeign() => identical(kind, ElementKind.FOREIGN); 192 bool isForeign() => identical(kind, ElementKind.FOREIGN);
191 bool isLibrary() => identical(kind, ElementKind.LIBRARY); 193 bool isLibrary() => identical(kind, ElementKind.LIBRARY);
192 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0; 194 bool impliesType() => (kind.category & ElementCategory.IMPLIES_TYPE) != 0;
193 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0; 195 bool isExtendable() => (kind.category & ElementCategory.IS_EXTENDABLE) != 0;
194 196
195 /** See [ErroneousElement] for documentation. */ 197 /** See [ErroneousElement] for documentation. */
196 bool isErroneous() => false; 198 bool isErroneous() => false;
197 199
200 /** See [AmbiguousElement] for documentation. */
201 bool isAmbiguous() => false;
202
198 /** 203 /**
199 * Is [:true:] if this element has a corresponding patch. 204 * Is [:true:] if this element has a corresponding patch.
200 * 205 *
201 * If [:true:] this element has a non-null [patch] field. 206 * If [:true:] this element has a non-null [patch] field.
202 * 207 *
203 * See [:patch_parser.dart:] for a description of the terminology. 208 * See [:patch_parser.dart:] for a description of the terminology.
204 */ 209 */
205 bool get isPatched => false; 210 bool get isPatched => false;
206 211
207 /** 212 /**
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 get defaultImplementation => unsupported(); 420 get defaultImplementation => unsupported();
416 bool get isPatched => unsupported(); 421 bool get isPatched => unsupported();
417 bool get isPatch => unsupported(); 422 bool get isPatch => unsupported();
418 setPatch(patch) => unsupported(); 423 setPatch(patch) => unsupported();
419 computeSignature(compiler) => unsupported(); 424 computeSignature(compiler) => unsupported();
420 requiredParameterCount(compiler) => unsupported(); 425 requiredParameterCount(compiler) => unsupported();
421 optionalParameterCount(compiler) => unsupported(); 426 optionalParameterCount(compiler) => unsupported();
422 parameterCount(copmiler) => unsupported(); 427 parameterCount(copmiler) => unsupported();
423 } 428 }
424 429
430 /**
431 * An ambiguous element represent multiple elements accessible by the same name.
432 *
433 * Ambiguous elements are created during handling of import/export scopes. If an
434 * ambiguous element is encountered during resolution a warning/error should be
435 * reported.
436 */
437 class AmbiguousElement extends Element {
438 /**
439 * The message to report on resolving this element.
440 */
441 final MessageKind messageKind;
442
443 /**
444 * The message arguments to report on resolving this element.
445 */
446 final List messageArguments;
447
448 /**
449 * The elements that this ambiguous element might refer to.
450 */
451 Link<Element> elements = const Link<Element>();
452
453 AmbiguousElement(MessageKind this.messageKind, List this.messageArguments,
karlklose 2012/11/07 11:41:24 Initializing formals get the type from the field,
Johnni Winther 2012/11/07 13:02:01 Done.
454 Element enclosingElement, Element existingElement, Element newElement)
455 : super(existingElement.name, ElementKind.AMBIGUOUS, enclosingElement) {
456 addAmbiguousElement(existingElement);
457 addAmbiguousElement(newElement);
458 }
459
460 bool isAmbiguous() => true;
461
462 /**
463 * Adds an element as one of the elements that this ambiguous element might
464 * refer to.
465 */
466 void addAmbiguousElement(Element element) {
467 elements = elements.prepend(element);
468 }
469 }
470
425 class ContainerElement extends Element { 471 class ContainerElement extends Element {
426 Link<Element> localMembers = const Link<Element>(); 472 Link<Element> localMembers = const Link<Element>();
427 473
428 ContainerElement(name, kind, enclosingElement) 474 ContainerElement(name, kind, enclosingElement)
429 : super(name, kind, enclosingElement); 475 : super(name, kind, enclosingElement);
430 476
431 void addMember(Element element, DiagnosticListener listener) { 477 void addMember(Element element, DiagnosticListener listener) {
432 localMembers = localMembers.prepend(element); 478 localMembers = localMembers.prepend(element);
433 } 479 }
434 } 480 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 /** 699 /**
654 * Adds [element] to the import scope of this library. 700 * Adds [element] to the import scope of this library.
655 * 701 *
656 * If an element by the same name is already in the imported scope, an 702 * If an element by the same name is already in the imported scope, an
657 * [ErroneousElement] will be put in the imported scope, allowing for the 703 * [ErroneousElement] will be put in the imported scope, allowing for the
658 * detection of ambiguous uses of imported names. 704 * detection of ambiguous uses of imported names.
659 */ 705 */
660 void addImport(Element element, DiagnosticListener listener) { 706 void addImport(Element element, DiagnosticListener listener) {
661 Element existing = importScope[element.name]; 707 Element existing = importScope[element.name];
662 if (existing != null) { 708 if (existing != null) {
663 if (!existing.isErroneous()) { 709 if (!existing.isAmbiguous()) {
664 // TODO(johnniwinther): Provide access to both the new and existing 710 // TODO(johnniwinther): Provide access to the import tags from which
665 // elements. 711 // the elements came.
666 importScope[element.name] = new ErroneousElement( 712 importScope[element.name] = new AmbiguousElement(
667 MessageKind.DUPLICATE_IMPORT, 713 MessageKind.DUPLICATE_IMPORT, [element.name],
668 [element.name], element.name, this); 714 this, existing, element);
karlklose 2012/11/07 11:41:24 Try fitting this and existing on the previous line
Johnni Winther 2012/11/07 13:02:01 Done.
715 } else {
716 AmbiguousElement ambiguous = existing;
717 ambiguous.addAmbiguousElement(element);
669 } 718 }
670 } else { 719 } else {
671 importScope[element.name] = element; 720 importScope[element.name] = element;
672 } 721 }
673 } 722 }
674 723
675 /** 724 /**
676 * Returns [:true:] if the export scope has already been computed for this 725 * Returns [:true:] if the export scope has already been computed for this
677 * library. 726 * library.
678 */ 727 */
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1956 2005
1957 MetadataAnnotation ensureResolved(Compiler compiler) { 2006 MetadataAnnotation ensureResolved(Compiler compiler) {
1958 if (resolutionState == STATE_NOT_STARTED) { 2007 if (resolutionState == STATE_NOT_STARTED) {
1959 compiler.resolver.resolveMetadataAnnotation(this); 2008 compiler.resolver.resolveMetadataAnnotation(this);
1960 } 2009 }
1961 return this; 2010 return this;
1962 } 2011 }
1963 2012
1964 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2013 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1965 } 2014 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698