Chromium Code Reviews| 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. | |
| 10 #import('../../compiler.dart', prefix: 'api_e'); | |
| 9 #import('../tree/tree.dart'); | 11 #import('../tree/tree.dart'); |
| 10 #import('../scanner/scannerlib.dart'); | 12 #import('../scanner/scannerlib.dart'); |
| 11 #import('../leg.dart'); // TODO(karlklose): we only need type. | 13 #import('../leg.dart'); // TODO(karlklose): we only need type. |
| 12 #import('../universe/universe.dart'); | 14 #import('../universe/universe.dart'); |
| 13 #import('../util/util.dart'); | 15 #import('../util/util.dart'); |
| 14 | 16 |
| 15 const int STATE_NOT_STARTED = 0; | 17 const int STATE_NOT_STARTED = 0; |
| 16 const int STATE_STARTED = 1; | 18 const int STATE_STARTED = 1; |
| 17 const int STATE_DONE = 2; | 19 const int STATE_DONE = 2; |
| 18 | 20 |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 } else { | 488 } else { |
| 487 field.setter = accessor; | 489 field.setter = accessor; |
| 488 } | 490 } |
| 489 addToScope(field, listener); | 491 addToScope(field, listener); |
| 490 } | 492 } |
| 491 } | 493 } |
| 492 } | 494 } |
| 493 | 495 |
| 494 class CompilationUnitElement extends ContainerElement { | 496 class CompilationUnitElement extends ContainerElement { |
| 495 final Script script; | 497 final Script script; |
| 498 PartOf partTag; | |
| 496 | 499 |
| 497 CompilationUnitElement(Script script, LibraryElement library) | 500 CompilationUnitElement(Script script, LibraryElement library) |
| 498 : this.script = script, | 501 : this.script = script, |
| 499 super(new SourceString(script.name), | 502 super(new SourceString(script.name), |
| 500 ElementKind.COMPILATION_UNIT, | 503 ElementKind.COMPILATION_UNIT, |
| 501 library) { | 504 library) { |
| 502 library.addCompilationUnit(this); | 505 library.addCompilationUnit(this); |
| 503 } | 506 } |
| 504 | 507 |
| 505 void addMember(Element element, DiagnosticListener listener) { | 508 void addMember(Element element, DiagnosticListener listener) { |
| 506 // Keep a list of top level members. | 509 // Keep a list of top level members. |
| 507 super.addMember(element, listener); | 510 super.addMember(element, listener); |
| 508 // Provide the member to the library to build scope. | 511 // Provide the member to the library to build scope. |
| 509 if (enclosingElement.isPatch) { | 512 if (enclosingElement.isPatch) { |
| 510 getImplementationLibrary().addMember(element, listener); | 513 getImplementationLibrary().addMember(element, listener); |
| 511 } else { | 514 } else { |
| 512 getLibrary().addMember(element, listener); | 515 getLibrary().addMember(element, listener); |
| 513 } | 516 } |
| 514 } | 517 } |
| 518 | |
| 519 void setPartOf(PartOf tag, DiagnosticListener listener) { | |
| 520 LibraryElement library = enclosingElement; | |
| 521 if (library.entryCompilationUnit == this) { | |
| 522 listener.reportMessage( | |
| 523 listener.spanFromNode(tag), | |
| 524 MessageKind.ILLEGAL_DIRECTIVE.error(), | |
| 525 api_e.Diagnostic.WARNING); | |
| 526 return; | |
| 527 } | |
| 528 if (!localMembers.isEmpty()) { | |
| 529 listener.reportMessage( | |
| 530 listener.spanFromNode(tag), | |
| 531 MessageKind.BEFORE_TOP_LEVEL.error(), | |
| 532 api_e.Diagnostic.ERROR); | |
| 533 return; | |
| 534 } | |
| 535 if (partTag != null) { | |
| 536 listener.reportMessage( | |
| 537 listener.spanFromNode(tag), | |
| 538 MessageKind.DUPLICATED_PART_OF.error(), | |
| 539 api_e.Diagnostic.WARNING); | |
| 540 return; | |
| 541 } | |
| 542 partTag = tag; | |
| 543 LibraryName libraryTag = getLibrary().libraryTag; | |
| 544 if (libraryTag != null) { | |
|
Johnni Winther
2012/10/09 07:43:36
Isn't it also an error if the library does not hav
ahe
2012/10/09 07:48:09
A script may have parts, but no library name:
scr
| |
| 545 String expectedName = tag.name.toString(); | |
| 546 String actualName = libraryTag.name.toString(); | |
| 547 if (expectedName != actualName) { | |
| 548 listener.reportMessage( | |
| 549 listener.spanFromNode(tag.name), | |
| 550 MessageKind.LIBRARY_NAME_MISMATCH.error([expectedName]), | |
| 551 api_e.Diagnostic.WARNING); | |
| 552 } | |
| 553 } | |
| 554 } | |
| 515 } | 555 } |
| 516 | 556 |
| 517 class LibraryElement extends ScopeContainerElement { | 557 class LibraryElement extends ScopeContainerElement { |
| 518 final Uri uri; | 558 final Uri uri; |
| 519 CompilationUnitElement entryCompilationUnit; | 559 CompilationUnitElement entryCompilationUnit; |
| 520 Link<CompilationUnitElement> compilationUnits = | 560 Link<CompilationUnitElement> compilationUnits = |
| 521 const EmptyLink<CompilationUnitElement>(); | 561 const EmptyLink<CompilationUnitElement>(); |
| 522 Link<LibraryTag> tags = const EmptyLink<LibraryTag>(); | 562 Link<LibraryTag> tags = const EmptyLink<LibraryTag>(); |
| 523 LibraryName libraryTag; | 563 LibraryName libraryTag; |
| 524 bool canUseNative = false; | 564 bool canUseNative = false; |
| (...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1873 | 1913 |
| 1874 MetadataAnnotation ensureResolved(Compiler compiler) { | 1914 MetadataAnnotation ensureResolved(Compiler compiler) { |
| 1875 if (resolutionState == STATE_NOT_STARTED) { | 1915 if (resolutionState == STATE_NOT_STARTED) { |
| 1876 compiler.resolver.resolveMetadataAnnotation(this); | 1916 compiler.resolver.resolveMetadataAnnotation(this); |
| 1877 } | 1917 } |
| 1878 return this; | 1918 return this; |
| 1879 } | 1919 } |
| 1880 | 1920 |
| 1881 String toString() => 'MetadataAnnotation($value, $resolutionState)'; | 1921 String toString() => 'MetadataAnnotation($value, $resolutionState)'; |
| 1882 } | 1922 } |
| OLD | NEW |