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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/closure.dart

Issue 19676002: Implement top-level getters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments Created 7 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
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 closureToClassMapper; 5 library closureToClassMapper;
6 6
7 import "elements/elements.dart"; 7 import "elements/elements.dart";
8 import "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "dart_types.dart"; 9 import "dart_types.dart";
10 import "scanner/scannerlib.dart" show Token; 10 import "scanner/scannerlib.dart" show Token;
11 import "tree/tree.dart"; 11 import "tree/tree.dart";
12 import "util/util.dart"; 12 import "util/util.dart";
13 import "elements/modelx.dart" show ElementX, FunctionElementX, ClassElementX; 13 import "elements/modelx.dart" show ElementX, FunctionElementX, ClassElementX;
14 14
15 class ClosureNamer { 15 class ClosureNamer {
16 SourceString getClosureVariableName(SourceString name, int id) { 16 SourceString getClosureVariableName(SourceString name, int id) {
17 return new SourceString("${name.slowToString()}_$id"); 17 return new SourceString("${name.slowToString()}_$id");
18 } 18 }
19 } 19 }
20 20
21
22 class ClosureTask extends CompilerTask { 21 class ClosureTask extends CompilerTask {
23 Map<Node, ClosureClassMap> closureMappingCache; 22 Map<Node, ClosureClassMap> closureMappingCache;
24 ClosureNamer namer; 23 ClosureNamer namer;
25 ClosureTask(Compiler compiler, this.namer) 24 ClosureTask(Compiler compiler, this.namer)
26 : closureMappingCache = new Map<Node, ClosureClassMap>(), 25 : closureMappingCache = new Map<Node, ClosureClassMap>(),
27 super(compiler); 26 super(compiler);
28 27
29 String get name => "Closure Simplifier"; 28 String get name => "Closure Simplifier";
30 29
31 ClosureClassMap computeClosureToClassMapping(Element element, 30 ClosureClassMap computeClosureToClassMapping(Element element,
(...skipping 29 matching lines...) Expand all
61 compiler.internalError("No closure cache", node: node); 60 compiler.internalError("No closure cache", node: node);
62 } 61 }
63 return nestedClosureData; 62 return nestedClosureData;
64 }); 63 });
65 } 64 }
66 } 65 }
67 66
68 // TODO(ahe): These classes continuously cause problems. We need to 67 // TODO(ahe): These classes continuously cause problems. We need to
69 // move these classes to elements/modelx.dart or see if we can find a 68 // move these classes to elements/modelx.dart or see if we can find a
70 // more general solution. 69 // more general solution.
71 class ClosureFieldElement extends ElementX { 70 class ClosureFieldElement extends ElementX implements VariableElement {
71 /// The source variable this element refers to.
72 final Element variableElement;
73
72 ClosureFieldElement(SourceString name, 74 ClosureFieldElement(SourceString name,
73 this.variableElement, 75 this.variableElement,
74 ClassElement enclosing) 76 ClassElement enclosing)
75 : super(name, ElementKind.FIELD, enclosing); 77 : super(name, ElementKind.FIELD, enclosing);
76 78
79 VariableListElement get variables {
80 throw new SpannableAssertionFailure(
81 variableElement, 'Should not access variables of ClosureFieldElement.');
82 }
83
84 Expression get cachedNode {
85 throw new SpannableAssertionFailure(
86 variableElement,
87 'Should not access cachedNode of ClosureFieldElement.');
88 }
89
77 bool isInstanceMember() => true; 90 bool isInstanceMember() => true;
78 bool isAssignable() => false; 91 bool isAssignable() => false;
79 // The names of closure variables don't need renaming, since their use is very 92 // The names of closure variables don't need renaming, since their use is very
80 // simple and they have 1-character names in the minified mode. 93 // simple and they have 1-character names in the minified mode.
81 bool hasFixedBackendName() => true; 94 bool hasFixedBackendName() => true;
82 String fixedBackendName() => name.slowToString(); 95 String fixedBackendName() => name.slowToString();
83 96
84 DartType computeType(Compiler compiler) { 97 DartType computeType(Compiler compiler) {
85 return variableElement.computeType(compiler); 98 return variableElement.computeType(compiler);
86 } 99 }
87 100
88 String toString() => "ClosureFieldElement($name)"; 101 String toString() => "ClosureFieldElement($name)";
89
90 /**
91 * The source variable this element refers to.
92 */
93 final Element variableElement;
94 } 102 }
95 103
96 // TODO(ahe): These classes continuously cause problems. We need to 104 // TODO(ahe): These classes continuously cause problems. We need to
97 // move these classes to elements/modelx.dart or see if we can find a 105 // move these classes to elements/modelx.dart or see if we can find a
98 // more general solution. 106 // more general solution.
99 class ClosureClassElement extends ClassElementX { 107 class ClosureClassElement extends ClassElementX {
100 DartType rawType; 108 DartType rawType;
101 DartType thisType; 109 DartType thisType;
102 /// Node that corresponds to this closure, used for source position. 110 /// Node that corresponds to this closure, used for source position.
103 final FunctionExpression node; 111 final FunctionExpression node;
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 825 }
818 826
819 visitTryStatement(TryStatement node) { 827 visitTryStatement(TryStatement node) {
820 // TODO(ngeoffray): implement finer grain state. 828 // TODO(ngeoffray): implement finer grain state.
821 bool oldInTryStatement = inTryStatement; 829 bool oldInTryStatement = inTryStatement;
822 inTryStatement = true; 830 inTryStatement = true;
823 node.visitChildren(this); 831 node.visitChildren(this);
824 inTryStatement = oldInTryStatement; 832 inTryStatement = oldInTryStatement;
825 } 833 }
826 } 834 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698