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

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

Issue 10689063: Revert "Revert "First step towards having patch files for generic libraries."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/lib/web.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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('../tree/tree.dart'); 7 #import('../tree/tree.dart');
8 #import('../scanner/scannerlib.dart'); 8 #import('../scanner/scannerlib.dart');
9 #import('../leg.dart'); // TODO(karlklose): we only need type. 9 #import('../leg.dart'); // TODO(karlklose): we only need type.
10 #import('../util/util.dart'); 10 #import('../util/util.dart');
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 197
198 Element getOutermostEnclosingMemberOrTopLevel() { 198 Element getOutermostEnclosingMemberOrTopLevel() {
199 for (Element e = this; e !== null; e = e.enclosingElement) { 199 for (Element e = this; e !== null; e = e.enclosingElement) {
200 if (e.isMember() || e.isTopLevel()) { 200 if (e.isMember() || e.isTopLevel()) {
201 return e; 201 return e;
202 } 202 }
203 } 203 }
204 return null; 204 return null;
205 } 205 }
206 206
207 toString() { 207 String toString() {
208 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an 208 // TODO(johnniwinther): Test for nullness of name, or make non-nullness an
209 // invariant for all element types. 209 // invariant for all element types.
210 if (!isTopLevel()) { 210 if (!isTopLevel()) {
211 String holderName = enclosingElement.name.slowToString(); 211 String holderName = enclosingElement.name.slowToString();
212 return '$kind($holderName#${name.slowToString()})'; 212 return '$kind($holderName#${name.slowToString()})';
213 } else { 213 } else {
214 return '$kind(${name.slowToString()})'; 214 return '$kind(${name.slowToString()})';
215 } 215 }
216 } 216 }
217 217
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 class LibraryElement extends CompilationUnitElement { 299 class LibraryElement extends CompilationUnitElement {
300 // TODO(ahe): Library element should not be a subclass of 300 // TODO(ahe): Library element should not be a subclass of
301 // CompilationUnitElement. 301 // CompilationUnitElement.
302 302
303 Link<CompilationUnitElement> compilationUnits = 303 Link<CompilationUnitElement> compilationUnits =
304 const EmptyLink<CompilationUnitElement>(); 304 const EmptyLink<CompilationUnitElement>();
305 Link<ScriptTag> tags = const EmptyLink<ScriptTag>(); 305 Link<ScriptTag> tags = const EmptyLink<ScriptTag>();
306 ScriptTag libraryTag; 306 ScriptTag libraryTag;
307 Map<SourceString, Element> elements; 307 Map<SourceString, Element> elements;
308 bool canUseNative = false; 308 bool canUseNative = false;
309 LibraryElement patch = null;
309 310
310 LibraryElement(Script script) 311 LibraryElement(Script script)
311 : elements = new Map<SourceString, Element>(), 312 : elements = new Map<SourceString, Element>(),
312 super.library(script); 313 super.library(script);
313 314
315 bool get isPatched() => patch !== null;
316
314 void addCompilationUnit(CompilationUnitElement element) { 317 void addCompilationUnit(CompilationUnitElement element) {
315 compilationUnits = compilationUnits.prepend(element); 318 compilationUnits = compilationUnits.prepend(element);
316 } 319 }
317 320
318 void addTag(ScriptTag tag, DiagnosticListener listener) { 321 void addTag(ScriptTag tag, DiagnosticListener listener) {
319 tags = tags.prepend(tag); 322 tags = tags.prepend(tag);
320 } 323 }
321 324
322 void addMember(Element element, DiagnosticListener listener) { 325 void addMember(Element element, DiagnosticListener listener) {
323 topLevelElements = topLevelElements.prepend(element); 326 topLevelElements = topLevelElements.prepend(element);
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 } 594 }
592 595
593 class FunctionElement extends Element { 596 class FunctionElement extends Element {
594 FunctionExpression cachedNode; 597 FunctionExpression cachedNode;
595 Type type; 598 Type type;
596 final Modifiers modifiers; 599 final Modifiers modifiers;
597 600
598 FunctionSignature functionSignature; 601 FunctionSignature functionSignature;
599 602
600 /** 603 /**
604 * A function declaration that should be parsed instead of the current one.
605 * The patch should be parsed as if it was in the current scope. Its
606 * signature must match this function's signature.
607 */
608 // TODO(lrn): Consider using [defaultImplementation] to store the patch.
609 FunctionElement patch = null;
610
611 /**
601 * If this is an interface constructor, [defaultImplementation] will 612 * If this is an interface constructor, [defaultImplementation] will
602 * changed by the resolver to point to the default 613 * changed by the resolver to point to the default
603 * implementation. Otherwise, [:defaultImplementation === this:]. 614 * implementation. Otherwise, [:defaultImplementation === this:].
604 */ 615 */
605 FunctionElement defaultImplementation; 616 FunctionElement defaultImplementation;
606 617
607 FunctionElement(SourceString name, 618 FunctionElement(SourceString name,
608 ElementKind kind, 619 ElementKind kind,
609 Modifiers modifiers, 620 Modifiers modifiers,
610 Element enclosing) 621 Element enclosing)
611 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null); 622 : this.tooMuchOverloading(name, null, kind, modifiers, enclosing, null);
612 623
613 FunctionElement.node(SourceString name, 624 FunctionElement.node(SourceString name,
614 FunctionExpression node, 625 FunctionExpression node,
615 ElementKind kind, 626 ElementKind kind,
616 Modifiers modifiers, 627 Modifiers modifiers,
617 Element enclosing) 628 Element enclosing)
618 : this.tooMuchOverloading(name, node, kind, modifiers, enclosing, null); 629 : this.tooMuchOverloading(name, node, kind, modifiers, enclosing, null);
619 630
620 FunctionElement.from(SourceString name, 631 FunctionElement.from(SourceString name,
621 FunctionElement other, 632 FunctionElement other,
622 Element enclosing) 633 Element enclosing)
623 : this.tooMuchOverloading(name, other.cachedNode, other.kind, 634 : this.tooMuchOverloading(name, other.cachedNode, other.kind,
624 other.modifiers, enclosing, 635 other.modifiers, enclosing,
625 other.functionSignature); 636 other.functionSignature);
626 637
627 FunctionElement.tooMuchOverloading(SourceString name, 638 FunctionElement.tooMuchOverloading(SourceString name,
628 FunctionExpression this.cachedNode, 639 FunctionExpression this.cachedNode,
629 ElementKind kind, 640 ElementKind kind,
630 Modifiers this.modifiers, 641 Modifiers this.modifiers,
631 Element enclosing, 642 Element enclosing,
632 FunctionSignature this.functionSignature) 643 FunctionSignature this.functionSignature)
633 : super(name, kind, enclosing) 644 : super(name, kind, enclosing) {
634 {
635 defaultImplementation = this; 645 defaultImplementation = this;
636 } 646 }
637 647
648 CompilationUnitElement getCompilationUnit() {
649 if (patch !== null) return patch.getCompilationUnit();
650 return super.getCompilationUnit();
651 }
652
653 bool get isPatched() => patch !== null;
654
655 /**
656 * Applies a patch function to this function. The patch function's body
657 * is used as replacement when parsing this function's body.
658 * This method must not be called after the function has been parsed,
659 * and it must be called at most once.
660 */
661 void setPatch(FunctionElement patchElement) {
662 // Sanity checks. The caller must check these things before calling.
663 assert(patch === null);
664 assert(cachedNode === null);
Lasse Reichstein Nielsen 2012/07/02 08:52:12 The asserts were inverted :(
665 this.patch = patchElement;
666 cachedNode = patchElement.cachedNode;
667 }
668
638 bool isInstanceMember() { 669 bool isInstanceMember() {
639 return isMember() 670 return isMember()
640 && kind != ElementKind.GENERATIVE_CONSTRUCTOR 671 && kind != ElementKind.GENERATIVE_CONSTRUCTOR
641 && !modifiers.isFactory() 672 && !modifiers.isFactory()
642 && !modifiers.isStatic(); 673 && !modifiers.isStatic();
643 } 674 }
644 675
645 FunctionSignature computeSignature(Compiler compiler) { 676 FunctionSignature computeSignature(Compiler compiler) {
646 if (functionSignature !== null) return functionSignature; 677 if (functionSignature !== null) return functionSignature;
647 compiler.withCurrentElement(this, () { 678 compiler.withCurrentElement(this, () {
(...skipping 13 matching lines...) Expand all
661 int parameterCount(Compiler compiler) { 692 int parameterCount(Compiler compiler) {
662 return computeSignature(compiler).parameterCount; 693 return computeSignature(compiler).parameterCount;
663 } 694 }
664 695
665 FunctionType computeType(Compiler compiler) { 696 FunctionType computeType(Compiler compiler) {
666 if (type != null) return type; 697 if (type != null) return type;
667 type = compiler.computeFunctionType(this, computeSignature(compiler)); 698 type = compiler.computeFunctionType(this, computeSignature(compiler));
668 return type; 699 return type;
669 } 700 }
670 701
671 Node parseNode(DiagnosticListener listener) => cachedNode; 702 Node parseNode(DiagnosticListener listener) {
703 if (cachedNode !== null) return cachedNode;
704 if (patch !== null) {
705 cachedNode = patch.parseNode(listener);
706 }
707 return cachedNode;
708 }
672 709
673 Token position() => cachedNode.getBeginToken(); 710 Token position() => cachedNode.getBeginToken();
674 711
675 FunctionElement asFunctionElement() => this; 712 FunctionElement asFunctionElement() => this;
676 } 713 }
677 714
678 class ConstructorBodyElement extends FunctionElement { 715 class ConstructorBodyElement extends FunctionElement {
679 FunctionElement constructor; 716 FunctionElement constructor;
680 717
681 ConstructorBodyElement(FunctionElement constructor) 718 ConstructorBodyElement(FunctionElement constructor)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 Map<SourceString, Element> constructors; 768 Map<SourceString, Element> constructors;
732 Link<Type> interfaces = const EmptyLink<Type>(); 769 Link<Type> interfaces = const EmptyLink<Type>();
733 LinkedHashMap<SourceString, TypeVariableElement> typeParameters; 770 LinkedHashMap<SourceString, TypeVariableElement> typeParameters;
734 bool isResolved = false; 771 bool isResolved = false;
735 bool isBeingResolved = false; 772 bool isBeingResolved = false;
736 // backendMembers are members that have been added by the backend to simplify 773 // backendMembers are members that have been added by the backend to simplify
737 // compilation. They don't have any user-side counter-part. 774 // compilation. They don't have any user-side counter-part.
738 Link<Element> backendMembers = const EmptyLink<Element>(); 775 Link<Element> backendMembers = const EmptyLink<Element>();
739 776
740 Link<Type> allSupertypes; 777 Link<Type> allSupertypes;
778 ClassElement patch = null;
741 779
742 ClassElement(SourceString name, CompilationUnitElement enclosing, this.id) 780 ClassElement(SourceString name, CompilationUnitElement enclosing, this.id)
743 : localMembers = new Map<SourceString, Element>(), 781 : localMembers = new Map<SourceString, Element>(),
744 constructors = new Map<SourceString, Element>(), 782 constructors = new Map<SourceString, Element>(),
745 typeParameters = new LinkedHashMap<SourceString, TypeVariableElement>(), 783 typeParameters = new LinkedHashMap<SourceString, TypeVariableElement>(),
746 super(name, ElementKind.CLASS, enclosing); 784 super(name, ElementKind.CLASS, enclosing);
747 785
748 void addMember(Element element, DiagnosticListener listener) { 786 void addMember(Element element, DiagnosticListener listener) {
749 members = members.prepend(element); 787 members = members.prepend(element);
750 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR || 788 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR ||
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 final Node node; 1129 final Node node;
1092 Type bound; 1130 Type bound;
1093 Type type; 1131 Type type;
1094 TypeVariableElement(name, Element enclosing, this.node, this.type, 1132 TypeVariableElement(name, Element enclosing, this.node, this.type,
1095 [this.bound]) 1133 [this.bound])
1096 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 1134 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
1097 Type computeType(compiler) => type; 1135 Type computeType(compiler) => type;
1098 Node parseNode(compiler) => node; 1136 Node parseNode(compiler) => node;
1099 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; 1137 toString() => "${enclosingElement.toString()}.${name.slowToString()}";
1100 } 1138 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/lib/web.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698