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

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

Issue 231863007: Support local variables in dart2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 6 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart_tree; 5 library dart_tree;
6 6
7 import '../dart2jslib.dart' as dart2js; 7 import '../dart2jslib.dart' as dart2js;
8 import '../dart_types.dart'; 8 import '../dart_types.dart';
9 import '../util/util.dart'; 9 import '../util/util.dart';
10 import '../elements/elements.dart' 10 import '../elements/elements.dart'
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 // Uses of IR definitions are replaced with Tree variables. This is the 210 // Uses of IR definitions are replaced with Tree variables. This is the
211 // mapping from definitions to variables. 211 // mapping from definitions to variables.
212 final Map<ir.Definition, Variable> variables = {}; 212 final Map<ir.Definition, Variable> variables = {};
213 213
214 FunctionDefinition function; 214 FunctionDefinition function;
215 ir.Continuation returnContinuation; 215 ir.Continuation returnContinuation;
216 216
217 Builder(this.compiler); 217 Builder(this.compiler);
218 218
219 static final String _bailout = 'Bailout Tree Builder';
220
221 bailout() => throw _bailout;
222
219 FunctionDefinition build(ir.FunctionDefinition node) { 223 FunctionDefinition build(ir.FunctionDefinition node) {
220 visit(node); 224 try {
221 return function; 225 visit(node);
226 return function;
227 } catch (e) {
228 if (e == _bailout) return null;
229 rethrow;
230 }
222 } 231 }
223 232
224 List<Expression> translateArguments(List<ir.Reference> args) { 233 List<Expression> translateArguments(List<ir.Reference> args) {
225 return new List.generate(args.length, 234 return new List.generate(args.length,
226 (int index) => variables[args[index].definition]); 235 (int index) => variables[args[index].definition]);
227 } 236 }
228 237
229 Expression visitFunctionDefinition(ir.FunctionDefinition node) { 238 Expression visitFunctionDefinition(ir.FunctionDefinition node) {
230 returnContinuation = node.returnContinuation; 239 returnContinuation = node.returnContinuation;
231 List<Variable> parameters = <Variable>[]; 240 List<Variable> parameters = <Variable>[];
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 } else { 291 } else {
283 return new Sequence([invoke, visit(cont.body)]); 292 return new Sequence([invoke, visit(cont.body)]);
284 } 293 }
285 } 294 }
286 } 295 }
287 296
288 Expression visitInvokeContinuation(ir.InvokeContinuation node) { 297 Expression visitInvokeContinuation(ir.InvokeContinuation node) {
289 // TODO(kmillikin): Support non-return continuations. These could arise 298 // TODO(kmillikin): Support non-return continuations. These could arise
290 // due to local control flow or due to inlining or other optimization. 299 // due to local control flow or due to inlining or other optimization.
291 assert(node.continuation.definition == returnContinuation); 300 assert(node.continuation.definition == returnContinuation);
292 return new Return(variables[node.argument.definition]); 301 assert(node.arguments.length == 1);
302 return new Return(variables[node.arguments[0].definition]);
303 }
304
305 Expression visitBranch(ir.Branch node) {
306 return bailout();
293 } 307 }
294 308
295 Expression visitConstant(ir.Constant node) { 309 Expression visitConstant(ir.Constant node) {
296 return new Constant(node.value); 310 return new Constant(node.value);
297 } 311 }
298 312
299 Expression visitParameter(ir.Parameter node) { 313 Expression visitParameter(ir.Parameter node) {
300 // Continuation parameters are not visited (continuations themselves are 314 // Continuation parameters are not visited (continuations themselves are
301 // not visited yet). 315 // not visited yet).
302 compiler.internalError(compiler.currentElement, 'Unexpected IR node.'); 316 compiler.internalError(compiler.currentElement, 'Unexpected IR node.');
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } 776 }
763 777
764 ast.Expression visitInterceptor(dart2js.InterceptorConstant constant) { 778 ast.Expression visitInterceptor(dart2js.InterceptorConstant constant) {
765 return unimplemented(); 779 return unimplemented();
766 } 780 }
767 781
768 ast.Expression visitDummy(dart2js.DummyConstant constant) { 782 ast.Expression visitDummy(dart2js.DummyConstant constant) {
769 return unimplemented(); 783 return unimplemented();
770 } 784 }
771 } 785 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698