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

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

Issue 10968010: Import scope rules updated. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 #library('elements'); 5 #library('elements');
6 6
7 #import('dart:uri'); 7 #import('dart:uri');
8 8
9 #import('../tree/tree.dart'); 9 #import('../tree/tree.dart');
10 #import('../scanner/scannerlib.dart'); 10 #import('../scanner/scannerlib.dart');
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 * except [isErroneous] will currently throw an exception. (This might 309 * except [isErroneous] will currently throw an exception. (This might
310 * change when we actually want more information on the erroneous element, 310 * change when we actually want more information on the erroneous element,
311 * e.g., the name of the element we were trying to resolve.) 311 * e.g., the name of the element we were trying to resolve.)
312 * 312 *
313 * Code that cannot not handle an [ErroneousElement] should use 313 * Code that cannot not handle an [ErroneousElement] should use
314 * [: Element.isInvalid(element) :] 314 * [: Element.isInvalid(element) :]
315 * to check for unresolvable elements instead of 315 * to check for unresolvable elements instead of
316 * [: element == null :]. 316 * [: element == null :].
317 */ 317 */
318 class ErroneousElement extends Element { 318 class ErroneousElement extends Element {
319 final Message errorMessage; 319 final MessageKind messageKind;
320 final List messageArguments;
320 final SourceString targetName; 321 final SourceString targetName;
321 322
322 ErroneousElement(this.errorMessage, this.targetName, Element enclosing) 323 ErroneousElement(this.messageKind, this.messageArguments,
324 this.targetName, Element enclosing)
323 : super(const SourceString('erroneous element'), null, enclosing); 325 : super(const SourceString('erroneous element'), null, enclosing);
324 326
325 isErroneous() => true; 327 isErroneous() => true;
326 328
327 unsupported() { 329 unsupported() {
328 throw 'unsupported operation on erroneous element'; 330 throw 'unsupported operation on erroneous element';
329 } 331 }
330 332
331 SourceString get name => unsupported(); 333 SourceString get name => unsupported();
332 ElementKind get kind => unsupported(); 334 ElementKind get kind => unsupported();
333 Link<MetadataAnnotation> get metadata => unsupported(); 335 Link<MetadataAnnotation> get metadata => unsupported();
334 336
335 getLibrary() => enclosingElement.getLibrary(); 337 getLibrary() => enclosingElement.getLibrary();
336 } 338 }
337 339
338 class ErroneousFunctionElement extends ErroneousElement 340 class ErroneousFunctionElement extends ErroneousElement
339 implements FunctionElement { 341 implements FunctionElement {
340 ErroneousFunctionElement(Message errorMessage, SourceString targetName, 342 ErroneousFunctionElement(MessageKind messageKind, List messageArguments,
341 Element enclosing) 343 SourceString targetName, Element enclosing)
342 : super(errorMessage, targetName, enclosing); 344 : super(messageKind, messageArguments, targetName, enclosing);
343 345
344 get type => unsupported(); 346 get type => unsupported();
345 get cachedNode => unsupported(); 347 get cachedNode => unsupported();
346 get functionSignature => unsupported(); 348 get functionSignature => unsupported();
347 get patch => unsupported(); 349 get patch => unsupported();
348 get defaultImplementation => unsupported(); 350 get defaultImplementation => unsupported();
349 bool get isPatched => unsupported(); 351 bool get isPatched => unsupported();
350 setPatch(patch) => unsupported(); 352 setPatch(patch) => unsupported();
351 computeSignature(compiler) => unsupported(); 353 computeSignature(compiler) => unsupported();
352 requiredParameterCount(compiler) => unsupported(); 354 requiredParameterCount(compiler) => unsupported();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 481
480 class LibraryElement extends ScopeContainerElement { 482 class LibraryElement extends ScopeContainerElement {
481 final Uri uri; 483 final Uri uri;
482 CompilationUnitElement entryCompilationUnit; 484 CompilationUnitElement entryCompilationUnit;
483 Link<CompilationUnitElement> compilationUnits = 485 Link<CompilationUnitElement> compilationUnits =
484 const EmptyLink<CompilationUnitElement>(); 486 const EmptyLink<CompilationUnitElement>();
485 Link<ScriptTag> tags = const EmptyLink<ScriptTag>(); 487 Link<ScriptTag> tags = const EmptyLink<ScriptTag>();
486 ScriptTag libraryTag; 488 ScriptTag libraryTag;
487 bool canUseNative = false; 489 bool canUseNative = false;
488 LibraryElement patch = null; 490 LibraryElement patch = null;
491 final Map<SourceString, Element> importScope;
Lasse Reichstein Nielsen 2012/09/20 12:21:08 Documentation. What is the meaning of this field?
Johnni Winther 2012/09/21 14:00:05 Comment added.
489 492
490 LibraryElement(Script script, [Uri uri]) 493 LibraryElement(Script script, [Uri uri])
491 : this.uri = ((uri === null) ? script.uri : uri), 494 : this.uri = ((uri === null) ? script.uri : uri),
495 importScope = new Map<SourceString, Element>(),
492 super(new SourceString(script.name), ElementKind.LIBRARY, null) { 496 super(new SourceString(script.name), ElementKind.LIBRARY, null) {
493 entryCompilationUnit = new CompilationUnitElement(script, this); 497 entryCompilationUnit = new CompilationUnitElement(script, this);
494 } 498 }
495 499
496 500
497 bool get isPatched => patch !== null; 501 bool get isPatched => patch !== null;
498 502
499 void addCompilationUnit(CompilationUnitElement element) { 503 void addCompilationUnit(CompilationUnitElement element) {
500 compilationUnits = compilationUnits.prepend(element); 504 compilationUnits = compilationUnits.prepend(element);
501 } 505 }
502 506
503 void addTag(ScriptTag tag, DiagnosticListener listener) { 507 void addTag(ScriptTag tag, DiagnosticListener listener) {
504 tags = tags.prepend(tag); 508 tags = tags.prepend(tag);
505 } 509 }
506 510
507 /** Look up a top-level element in this library. The element could 511 /**
508 * potentially have been imported from another library. Returns 512 * Adds [element] to the imported scope of this library.
Lasse Reichstein Nielsen 2012/09/20 12:21:08 "imported scope" -> "import scope". You don't impo
Johnni Winther 2012/09/21 14:00:05 Done.
509 * null if no such element exist. */ 513 *
514 * If an element by the same name is already in the imported scope, an
515 * [ErroneousElement] will be put in the imported scope, allowing for the
516 * detection of ambiguous uses of imported names.
517 */
518 void addImport(Element element, DiagnosticListener listener) {
519 Element existing = importScope.putIfAbsent(element.name, () => element);
520 if (existing !== element && existing !== null) {
Lasse Reichstein Nielsen 2012/09/20 12:21:08 Adding the same element twice is an error (accordi
Lasse Reichstein Nielsen 2012/09/20 14:03:36 ... actual value, even.
Johnni Winther 2012/09/21 14:00:05 I don't understand. Did you mean '... is not an er
521 if (!existing.isErroneous()) {
522 // TODO(johnniwinther): Provide access to both the new and existing
523 // elements.
524 importScope[element.name] = new ErroneousElement(
525 MessageKind.DUPLICATE_IMPORT,
526 [element.name], element.name, this);
527 }
528 }
529 }
530
531
532 /**
533 * Look up a top-level element in this library. The element could
534 * potentially have been imported from another library. Returns
535 * null if no such element exist and an [ErroneousElement] if multiple
536 * elements have been imported.
537 */
510 Element find(SourceString elementName) { 538 Element find(SourceString elementName) {
511 return localScope[elementName]; 539 Element result = localScope[elementName];
540 if (result === null) {
541 result = importScope[elementName];
542 }
543 return result;
512 } 544 }
513 545
514 /** Look up a top-level element in this library, but only look for 546 /** Look up a top-level element in this library, but only look for
515 * non-imported elements. Returns null if no such element exist. */ 547 * non-imported elements. Returns null if no such element exist. */
516 Element findLocal(SourceString elementName) { 548 Element findLocal(SourceString elementName) {
517 Element result = localScope[elementName]; 549 Element result = localScope[elementName];
518 if (result === null || result.getLibrary() != this) return null; 550 if (result === null || result.getLibrary() != this) return null;
519 return result; 551 return result;
520 } 552 }
521 553
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 1723
1692 MetadataAnnotation ensureResolved(Compiler compiler) { 1724 MetadataAnnotation ensureResolved(Compiler compiler) {
1693 if (resolutionState == STATE_NOT_STARTED) { 1725 if (resolutionState == STATE_NOT_STARTED) {
1694 compiler.resolver.resolveMetadataAnnotation(this); 1726 compiler.resolver.resolveMetadataAnnotation(this);
1695 } 1727 }
1696 return this; 1728 return this;
1697 } 1729 }
1698 1730
1699 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 1731 String toString() => 'MetadataAnnotation($value, $resolutionState)';
1700 } 1732 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/resolver.dart » ('j') | lib/compiler/implementation/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698