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

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

Issue 10386086: RFC: Start refactoring to provide more than a single backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Next iteration Created 8 years, 7 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 class ClosureFieldElement extends Element { 5 class ClosureFieldElement extends Element {
6 ClosureFieldElement(SourceString name, ClassElement enclosing) 6 ClosureFieldElement(SourceString name, ClassElement enclosing)
7 : super(name, ElementKind.FIELD, enclosing); 7 : super(name, ElementKind.FIELD, enclosing);
8 8
9 bool isInstanceMember() => true; 9 bool isInstanceMember() => true;
10 bool isAssignable() => false; 10 bool isAssignable() => false;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 this.thisElement) 90 this.thisElement)
91 : this.freeVariableMapping = new Map<Element, Element>(), 91 : this.freeVariableMapping = new Map<Element, Element>(),
92 this.capturedFieldMapping = new Map<Element, Element>(), 92 this.capturedFieldMapping = new Map<Element, Element>(),
93 this.capturingScopes = new Map<Node, ClosureScope>(), 93 this.capturingScopes = new Map<Node, ClosureScope>(),
94 this.usedVariablesInTry = new Set<Element>(); 94 this.usedVariablesInTry = new Set<Element>();
95 95
96 bool isClosure() => closureElement !== null; 96 bool isClosure() => closureElement !== null;
97 } 97 }
98 98
99 class ClosureTranslator extends AbstractVisitor { 99 class ClosureTranslator extends AbstractVisitor {
100 final Compiler compiler; 100 final SsaBuilder builder;
101 final TreeElements elements; 101 final TreeElements elements;
102 int closureFieldCounter = 0; 102 int closureFieldCounter = 0;
103 bool inTryCatchOrFinally = false; 103 bool inTryCatchOrFinally = false;
104 final Map<Node, ClosureData> closureDataCache; 104 final Map<Node, ClosureData> closureDataCache;
105 105
106 // Map of captured variables. Initially they will map to themselves. If 106 // Map of captured variables. Initially they will map to themselves. If
107 // a variable needs to be boxed then the scope declaring the variable 107 // a variable needs to be boxed then the scope declaring the variable
108 // will update this mapping. 108 // will update this mapping.
109 Map<Element, Element> capturedVariableMapping; 109 Map<Element, Element> capturedVariableMapping;
110 // List of encountered closures. 110 // List of encountered closures.
111 List<FunctionExpression> closures; 111 List<FunctionExpression> closures;
112 112
113 // The variables that have been declared in the current scope. 113 // The variables that have been declared in the current scope.
114 List<Element> scopeVariables; 114 List<Element> scopeVariables;
115 115
116 FunctionElement currentFunctionElement; 116 FunctionElement currentFunctionElement;
117 // The closureData of the currentFunctionElement. 117 // The closureData of the currentFunctionElement.
118 ClosureData closureData; 118 ClosureData closureData;
119 119
120 bool insideClosure = false; 120 bool insideClosure = false;
121 121
122 ClosureTranslator(Compiler compiler, this.elements) 122 Compiler get compiler() => builder.compiler;
123 : capturedVariableMapping = new Map<Element, Element>(), 123
124 ClosureTranslator(SsaBuilder builder)
125 : this.builder = builder,
126 this.elements = builder.elements,
127 capturedVariableMapping = new Map<Element, Element>(),
124 closures = <FunctionExpression>[], 128 closures = <FunctionExpression>[],
125 this.compiler = compiler, 129 this.closureDataCache = builder.builder.closureDataCache;
126 this.closureDataCache = compiler.builder.closureDataCache;
127 130
128 ClosureData translate(Node node) { 131 ClosureData translate(Node node) {
129 // Closures have already been analyzed when visiting the surrounding 132 // Closures have already been analyzed when visiting the surrounding
130 // method/function. This also shortcuts for bailout functions. 133 // method/function. This also shortcuts for bailout functions.
131 ClosureData cached = closureDataCache[node]; 134 ClosureData cached = closureDataCache[node];
132 if (cached !== null) return cached; 135 if (cached !== null) return cached;
133 136
134 visit(node); 137 visit(node);
135 // When variables need to be boxed their [capturedVariableMapping] is 138 // When variables need to be boxed their [capturedVariableMapping] is
136 // updated, but we delay updating the similar freeVariableMapping in the 139 // updated, but we delay updating the similar freeVariableMapping in the
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 declareLocal(elements[node]); 432 declareLocal(elements[node]);
430 } 433 }
431 434
432 visitTryStatement(TryStatement node) { 435 visitTryStatement(TryStatement node) {
433 // TODO(ngeoffray): implement finer grain state. 436 // TODO(ngeoffray): implement finer grain state.
434 inTryCatchOrFinally = true; 437 inTryCatchOrFinally = true;
435 node.visitChildren(this); 438 node.visitChildren(this);
436 inTryCatchOrFinally = false; 439 inTryCatchOrFinally = false;
437 } 440 }
438 } 441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698