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

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

Issue 10830117: Port the remaining of dart:core to the unified corelib. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed a issue where we tried to resolve the patch classes. Created 8 years, 4 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 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
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), 574 original.addGetterOrSetter(clonePatch(patchField.getter, original),
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), 587 original.addGetterOrSetter(clonePatch(patchField.setter, original),
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), this); 599 original.addMember(clonePatch(patchElement, original), 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) { 613 Element clonePatch(Element patchElement, Element enclosing) {
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 }
622 // TODO(lrn): Create a copy of patchElement that isn't added to any 636 // TODO(lrn): Create a copy of patchElement that isn't added to any
623 // object/library yet, but which takes its source from patchElement. 637 // object/library yet, but which takes its source from patchElement.
624 throw "Adding members from patch is unsupported"; 638 throw "Adding ${patchElement.kind} from patch is unsupported";
625 } 639 }
626 640
627 void patchMember(Element originalElement, Element patchElement) { 641 void patchMember(Element originalElement, Element patchElement) {
628 // The original library has an element with the same name as the patch 642 // The original library has an element with the same name as the patch
629 // library element. 643 // library element.
630 // In this case, the patch library element must be a function marked as 644 // In this case, the patch library element must be a function marked as
631 // "patch" and it must have the same signature as the function it patches. 645 // "patch" and it must have the same signature as the function it patches.
632 if (!isPatchElement(patchElement)) { 646 if (!isPatchElement(patchElement)) {
633 internalError("Cannot overwrite existing '" 647 internalError("Cannot overwrite existing '"
634 "${originalElement.name.slowToString()}' with non-patch."); 648 "${originalElement.name.slowToString()}' with non-patch.");
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 final endOffset = end.charOffset + end.slowCharCount; 1109 final endOffset = end.charOffset + end.slowCharCount;
1096 1110
1097 // [begin] and [end] might be the same for the same empty token. This 1111 // [begin] and [end] might be the same for the same empty token. This
1098 // happens for instance when scanning '$$'. 1112 // happens for instance when scanning '$$'.
1099 assert(endOffset >= beginOffset); 1113 assert(endOffset >= beginOffset);
1100 return f(beginOffset, endOffset); 1114 return f(beginOffset, endOffset);
1101 } 1115 }
1102 1116
1103 String toString() => 'SourceSpan($uri, $begin, $end)'; 1117 String toString() => 'SourceSpan($uri, $begin, $end)';
1104 } 1118 }
OLDNEW
« no previous file with comments | « corelib/unified/core/implementation/stopwatch.dart ('k') | lib/compiler/implementation/elements/elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698