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

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

Issue 231863007: Support local variables in dart2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | « sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree.dart ('k') | no next file » | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.ir_builder; 5 library dart2js.ir_builder;
6 6
7 import 'ir_nodes.dart' as ir; 7 import 'ir_nodes.dart' as ir;
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 412
413 ir.Definition visitTypeReferenceSend(ast.Send node) { 413 ir.Definition visitTypeReferenceSend(ast.Send node) {
414 return giveup(); 414 return giveup();
415 } 415 }
416 416
417 ir.Definition visitSendSet(ast.SendSet node) { 417 ir.Definition visitSendSet(ast.SendSet node) {
418 Element element = elements[node]; 418 Element element = elements[node];
419 if (!Elements.isLocal(element)) return giveup(); 419 if (!Elements.isLocal(element)) return giveup();
420 if (node.assignmentOperator.source != '=') return giveup(); 420 if (node.assignmentOperator.source != '=') return giveup();
421 // Exactly one argument expected for a simple assignment. 421 // Exactly one argument expected for a simple assignment.
422 assert(!node.arguments.isEmpty && node.arguments.tail.isEmpty); 422 assert(!node.arguments.isEmpty);
423 assert(node.arguments.tail.isEmpty);
423 ir.Definition result = node.arguments.head.accept(this); 424 ir.Definition result = node.arguments.head.accept(this);
424 assignedVars[variableIndex[element]] = result; 425 assignedVars[variableIndex[element]] = result;
425 return result; 426 return result;
426 } 427 }
427 428
429 ir.Definition visitVariableDefinitions(ast.VariableDefinitions node) {
430 assert(isOpen);
431 for (ast.Node definition in node.definitions.nodes) {
432 Element element = elements[definition];
433 // Definitions are either SendSets if there is an initializer, or
434 // Identifiers if there is no initializer.
435 if (definition is ast.SendSet) {
436 assert(!definition.arguments.isEmpty);
437 assert(definition.arguments.tail.isEmpty);
438 ir.Definition initialValue = definition.arguments.head.accept(this);
439 if (!isOpen) return null;
karlklose 2014/04/11 09:01:56 Perhaps add a comment.
Kevin Millikin (Google) 2014/04/11 10:28:51 I will.
440 variableIndex[element] = assignedVars.length;
441 assignedVars.add(initialValue);
442 } else {
443 assert(definition is ast.Identifier);
444 // The initial value is null.
445 // TODO(kmillikin): Consider pooling constants.
446 ir.Constant constant = new ir.Constant(constantSystem.createNull());
447 add(new ir.LetPrim(constant));
448 variableIndex[element] = assignedVars.length;
449 assignedVars.add(constant);
450 }
451 }
452 return null;
453 }
454
428 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted"; 455 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted";
429 456
430 ir.Definition giveup() => throw ABORT_IRNODE_BUILDER; 457 ir.Definition giveup() => throw ABORT_IRNODE_BUILDER;
431 458
432 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { 459 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) {
433 try { 460 try {
434 return action(); 461 return action();
435 } catch(e) { 462 } catch(e) {
436 if (e == ABORT_IRNODE_BUILDER) return null; 463 if (e == ABORT_IRNODE_BUILDER) return null;
437 rethrow; 464 rethrow;
438 } 465 }
439 } 466 }
440 467
441 void internalError(String reason, {ast.Node node}) { 468 void internalError(String reason, {ast.Node node}) {
442 giveup(); 469 giveup();
443 } 470 }
444 } 471 }
445 472
446 // Verify that types are ones that can be reconstructed by the type emitter. 473 // Verify that types are ones that can be reconstructed by the type emitter.
447 class SupportedTypeVerifier extends DartTypeVisitor<bool, Null> { 474 class SupportedTypeVerifier extends DartTypeVisitor<bool, Null> {
448 bool visitType(DartType type, Null _) => false; 475 bool visitType(DartType type, Null _) => false;
449 476
450 bool visitVoidType(VoidType type, Null _) => true; 477 bool visitVoidType(VoidType type, Null _) => true;
451 478
452 // Currently, InterfaceType and TypedefType are supported so long as they 479 // Currently, InterfaceType and TypedefType are supported so long as they
453 // do not have type parameters. They are subclasses of GenericType. 480 // do not have type parameters. They are subclasses of GenericType.
454 bool visitGenericType(GenericType type, Null _) => !type.isGeneric; 481 bool visitGenericType(GenericType type, Null _) => !type.isGeneric;
455 } 482 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698