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 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 Loading... |
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 Loading... |
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 Loading... |
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 first element that this ambiguous element might refer to. |
| 450 */ |
| 451 final Element existingElement; |
| 452 |
| 453 /** |
| 454 * The second element that this ambiguous element might refer to. |
| 455 */ |
| 456 final Element newElement; |
| 457 |
| 458 AmbiguousElement(this.messageKind, this.messageArguments, |
| 459 Element enclosingElement, Element existingElement, Element newElement) |
| 460 : this.existingElement = existingElement, |
| 461 this.newElement = newElement, |
| 462 super(existingElement.name, ElementKind.AMBIGUOUS, enclosingElement); |
| 463 |
| 464 bool isAmbiguous() => true; |
| 465 } |
| 466 |
425 class ContainerElement extends Element { | 467 class ContainerElement extends Element { |
426 Link<Element> localMembers = const Link<Element>(); | 468 Link<Element> localMembers = const Link<Element>(); |
427 | 469 |
428 ContainerElement(name, kind, enclosingElement) | 470 ContainerElement(name, kind, enclosingElement) |
429 : super(name, kind, enclosingElement); | 471 : super(name, kind, enclosingElement); |
430 | 472 |
431 void addMember(Element element, DiagnosticListener listener) { | 473 void addMember(Element element, DiagnosticListener listener) { |
432 localMembers = localMembers.prepend(element); | 474 localMembers = localMembers.prepend(element); |
433 } | 475 } |
434 } | 476 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 /** | 695 /** |
654 * Adds [element] to the import scope of this library. | 696 * Adds [element] to the import scope of this library. |
655 * | 697 * |
656 * If an element by the same name is already in the imported scope, an | 698 * 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 | 699 * [ErroneousElement] will be put in the imported scope, allowing for the |
658 * detection of ambiguous uses of imported names. | 700 * detection of ambiguous uses of imported names. |
659 */ | 701 */ |
660 void addImport(Element element, DiagnosticListener listener) { | 702 void addImport(Element element, DiagnosticListener listener) { |
661 Element existing = importScope[element.name]; | 703 Element existing = importScope[element.name]; |
662 if (existing != null) { | 704 if (existing != null) { |
663 if (!existing.isErroneous()) { | 705 // TODO(johnniwinther): Provide access to the import tags from which |
664 // TODO(johnniwinther): Provide access to both the new and existing | 706 // the elements came. |
665 // elements. | 707 importScope[element.name] = new AmbiguousElement( |
666 importScope[element.name] = new ErroneousElement( | 708 MessageKind.DUPLICATE_IMPORT, [element.name], |
667 MessageKind.DUPLICATE_IMPORT, | 709 this, existing, element); |
668 [element.name], element.name, this); | |
669 } | |
670 } else { | 710 } else { |
671 importScope[element.name] = element; | 711 importScope[element.name] = element; |
672 } | 712 } |
673 } | 713 } |
674 | 714 |
675 /** | 715 /** |
676 * Returns [:true:] if the export scope has already been computed for this | 716 * Returns [:true:] if the export scope has already been computed for this |
677 * library. | 717 * library. |
678 */ | 718 */ |
679 bool get exportsHandled => slotForExports != null; | 719 bool get exportsHandled => slotForExports != null; |
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 | 1996 |
1957 MetadataAnnotation ensureResolved(Compiler compiler) { | 1997 MetadataAnnotation ensureResolved(Compiler compiler) { |
1958 if (resolutionState == STATE_NOT_STARTED) { | 1998 if (resolutionState == STATE_NOT_STARTED) { |
1959 compiler.resolver.resolveMetadataAnnotation(this); | 1999 compiler.resolver.resolveMetadataAnnotation(this); |
1960 } | 2000 } |
1961 return this; | 2001 return this; |
1962 } | 2002 } |
1963 | 2003 |
1964 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 2004 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
1965 } | 2005 } |
OLD | NEW |