| 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 | 5 |
| 6 /** | 6 /** |
| 7 * If true, print a warning for each method that was resolved, but not | 7 * If true, print a warning for each method that was resolved, but not |
| 8 * compiled. | 8 * compiled. |
| 9 */ | 9 */ |
| 10 final bool REPORT_EXCESS_RESOLUTION = false; | 10 final bool REPORT_EXCESS_RESOLUTION = false; |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 // Getters and setters are kept inside a synthetic field. | 564 // Getters and setters are kept inside a synthetic field. |
| 565 if (originalElement !== null && | 565 if (originalElement !== null && |
| 566 originalElement.kind !== ElementKind.ABSTRACT_FIELD) { | 566 originalElement.kind !== ElementKind.ABSTRACT_FIELD) { |
| 567 internalError("Cannot patch non-getter/setter with getter/setter", | 567 internalError("Cannot patch non-getter/setter with getter/setter", |
| 568 element: originalElement); | 568 element: originalElement); |
| 569 } | 569 } |
| 570 AbstractFieldElement patchField = patchElement; | 570 AbstractFieldElement patchField = patchElement; |
| 571 AbstractFieldElement originalField = originalElement; | 571 AbstractFieldElement originalField = originalElement; |
| 572 if (patchField.getter !== null) { | 572 if (patchField.getter !== null) { |
| 573 if (originalField === null || originalField.getter === null) { | 573 if (originalField === null || originalField.getter === null) { |
| 574 original.addGetterOrSetter(clonePatch(patchField.getter, original), | 574 original.addGetterOrSetter(clonePatch(patchField.getter), |
| 575 originalField, | 575 originalField, |
| 576 this); | 576 this); |
| 577 if (originalField === null && patchField.setter !== null) { | 577 if (originalField === null && patchField.setter !== null) { |
| 578 // It exists now, so find it for the setter patching. | 578 // It exists now, so find it for the setter patching. |
| 579 originalField = lookup(patchElement.name); | 579 originalField = lookup(patchElement.name); |
| 580 } | 580 } |
| 581 } else { | 581 } else { |
| 582 patchMember(originalField.getter, patchField.getter); | 582 patchMember(originalField.getter, patchField.getter); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 if (patchField.setter !== null) { | 585 if (patchField.setter !== null) { |
| 586 if (originalField === null || originalField.setter === null) { | 586 if (originalField === null || originalField.setter === null) { |
| 587 original.addGetterOrSetter(clonePatch(patchField.setter, original), | 587 original.addGetterOrSetter(clonePatch(patchField.setter), |
| 588 originalField, | 588 originalField, |
| 589 this); | 589 this); |
| 590 } else { | 590 } else { |
| 591 patchMember(originalField.setter, patchField.setter); | 591 patchMember(originalField.setter, patchField.setter); |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 } else if (originalElement === null) { | 594 } else if (originalElement === null) { |
| 595 if (isPatchElement(patchElement)) { | 595 if (isPatchElement(patchElement)) { |
| 596 internalError("Cannot patch non-existing member '" | 596 internalError("Cannot patch non-existing member '" |
| 597 "${patchElement.name.slowToString()}'."); | 597 "${patchElement.name.slowToString()}'."); |
| 598 } | 598 } |
| 599 original.addMember(clonePatch(patchElement, original), this); | 599 original.addMember(clonePatch(patchElement), this); |
| 600 } else { | 600 } else { |
| 601 patchMember(originalElement, patchElement); | 601 patchMember(originalElement, patchElement); |
| 602 } | 602 } |
| 603 patches = patches.tail; | 603 patches = patches.tail; |
| 604 } | 604 } |
| 605 } | 605 } |
| 606 | 606 |
| 607 bool isPatchElement(Element element) { | 607 bool isPatchElement(Element element) { |
| 608 // TODO(lrn): More checks needed if we introduce metadata for real. | 608 // TODO(lrn): More checks needed if we introduce metadata for real. |
| 609 // In that case, it must have the identifier "native" as metadata. | 609 // In that case, it must have the identifier "native" as metadata. |
| 610 return !element.metadata.isEmpty(); | 610 return !element.metadata.isEmpty(); |
| 611 } | 611 } |
| 612 | 612 |
| 613 Element clonePatch(Element patchElement, Element enclosing) { | 613 Element clonePatch(Element patchElement) { |
| 614 // The original library does not have an element with the same name | 614 // The original library does not have an element with the same name |
| 615 // as the patch library element. | 615 // as the patch library element. |
| 616 // In this case, the patch library element must not be marked as "patch", | 616 // In this case, the patch library element must not be marked as "patch", |
| 617 // and its name must make it private. | 617 // and its name must make it private. |
| 618 if (!patchElement.name.isPrivate()) { | 618 if (!patchElement.name.isPrivate()) { |
| 619 internalError("Cannot add non-private member '" | 619 internalError("Cannot add non-private member '" |
| 620 "${patchElement.name.slowToString()}' from patch."); | 620 "${patchElement.name.slowToString()}' from patch."); |
| 621 } | 621 } |
| 622 if (patchElement.isFunction()) { | |
| 623 var function = new FunctionElement.from(patchElement.name, | |
| 624 patchElement, | |
| 625 enclosing); | |
| 626 // Give the cloned function a patch reference, so it gets the correct | |
| 627 // compilation unit for reporting diagnostics. | |
| 628 function.setPatch(patchElement); | |
| 629 return function; | |
| 630 } else if (patchElement.isField()) { | |
| 631 // TODO(ajohnsen): Decide if a VariableElement should have a patch field. | |
| 632 return new VariableElement.from(patchElement.name, | |
| 633 patchElement, | |
| 634 enclosing); | |
| 635 } | |
| 636 // TODO(lrn): Create a copy of patchElement that isn't added to any | 622 // TODO(lrn): Create a copy of patchElement that isn't added to any |
| 637 // object/library yet, but which takes its source from patchElement. | 623 // object/library yet, but which takes its source from patchElement. |
| 638 throw "Adding ${patchElement.kind} from patch is unsupported"; | 624 throw "Adding members from patch is unsupported"; |
| 639 } | 625 } |
| 640 | 626 |
| 641 void patchMember(Element originalElement, Element patchElement) { | 627 void patchMember(Element originalElement, Element patchElement) { |
| 642 // The original library has an element with the same name as the patch | 628 // The original library has an element with the same name as the patch |
| 643 // library element. | 629 // library element. |
| 644 // In this case, the patch library element must be a function marked as | 630 // In this case, the patch library element must be a function marked as |
| 645 // "patch" and it must have the same signature as the function it patches. | 631 // "patch" and it must have the same signature as the function it patches. |
| 646 if (!isPatchElement(patchElement)) { | 632 if (!isPatchElement(patchElement)) { |
| 647 internalError("Cannot overwrite existing '" | 633 internalError("Cannot overwrite existing '" |
| 648 "${originalElement.name.slowToString()}' with non-patch."); | 634 "${originalElement.name.slowToString()}' with non-patch."); |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1109 final endOffset = end.charOffset + end.slowCharCount; | 1095 final endOffset = end.charOffset + end.slowCharCount; |
| 1110 | 1096 |
| 1111 // [begin] and [end] might be the same for the same empty token. This | 1097 // [begin] and [end] might be the same for the same empty token. This |
| 1112 // happens for instance when scanning '$$'. | 1098 // happens for instance when scanning '$$'. |
| 1113 assert(endOffset >= beginOffset); | 1099 assert(endOffset >= beginOffset); |
| 1114 return f(beginOffset, endOffset); | 1100 return f(beginOffset, endOffset); |
| 1115 } | 1101 } |
| 1116 | 1102 |
| 1117 String toString() => 'SourceSpan($uri, $begin, $end)'; | 1103 String toString() => 'SourceSpan($uri, $begin, $end)'; |
| 1118 } | 1104 } |
| OLD | NEW |