| OLD | NEW |
| 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 backend_ast_emitter; | 5 library backend_ast_emitter; |
| 6 | 6 |
| 7 import '../tree_ir/tree_ir_nodes.dart' as tree; | 7 import '../tree_ir/tree_ir_nodes.dart' as tree; |
| 8 import 'backend_ast_nodes.dart'; | 8 import 'backend_ast_nodes.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 337 } |
| 338 | 338 |
| 339 List<Statement> bodyParts = []; | 339 List<Statement> bodyParts = []; |
| 340 if (constants.length > 0) { | 340 if (constants.length > 0) { |
| 341 bodyParts.add(new VariableDeclarations(constants, isConst: true)); | 341 bodyParts.add(new VariableDeclarations(constants, isConst: true)); |
| 342 } | 342 } |
| 343 if (context.variables.length > 0) { | 343 if (context.variables.length > 0) { |
| 344 bodyParts.add(new VariableDeclarations(context.variables)); | 344 bodyParts.add(new VariableDeclarations(context.variables)); |
| 345 } | 345 } |
| 346 bodyParts.addAll(context.statements); | 346 bodyParts.addAll(context.statements); |
| 347 | |
| 348 body = new Block(bodyParts); | 347 body = new Block(bodyParts); |
| 349 | |
| 350 } | 348 } |
| 351 FunctionType functionType = context.currentElement.type; | |
| 352 | |
| 353 return new ConstructorDefinition( | 349 return new ConstructorDefinition( |
| 354 parameters, | 350 parameters, |
| 355 body, | 351 body, |
| 356 initializers, | 352 initializers, |
| 357 context.currentElement.name, definition.element.isConst) | 353 context.currentElement.name, |
| 358 ..element = context.currentElement; | 354 definition.element.isConst)..element = context.currentElement; |
| 359 } | 355 } |
| 360 | 356 |
| 361 @override | 357 @override |
| 362 FunctionExpression visitFunctionDefinition( | 358 FunctionExpression visitFunctionDefinition( |
| 363 tree.FunctionDefinition definition, | 359 tree.FunctionDefinition definition, |
| 364 BuilderContext<Statement> context) { | 360 BuilderContext<Statement> context) { |
| 365 context.currentElement = definition.element; | 361 context.currentElement = definition.element; |
| 366 | 362 |
| 367 Parameters parameters = emitRootParameters( | 363 Parameters parameters = emitRootParameters( |
| 368 definition, definition.defaultParameterValues, context); | 364 definition, definition.defaultParameterValues, context); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 context.declaredVariables.add(assign.variable); | 553 context.declaredVariables.add(assign.variable); |
| 558 | 554 |
| 559 visitStatement(statement.next, context); | 555 visitStatement(statement.next, context); |
| 560 return; | 556 return; |
| 561 } | 557 } |
| 562 | 558 |
| 563 Expression definition = visitExpression(assign.value, context); | 559 Expression definition = visitExpression(assign.value, context); |
| 564 bool isFirstOccurrence = (context.variableNames[assign.variable] == null); | 560 bool isFirstOccurrence = (context.variableNames[assign.variable] == null); |
| 565 bool isDeclaredHere = assign.variable.host == context.currentElement; | 561 bool isDeclaredHere = assign.variable.host == context.currentElement; |
| 566 bool isFirstStatement = context.firstStatement == statement; | 562 bool isFirstStatement = context.firstStatement == statement; |
| 567 String name = context.getVariableName(assign.variable); | |
| 568 | 563 |
| 569 // Try to pull into initializer. | 564 // Try to pull into initializer. |
| 570 if (isFirstStatement && isFirstOccurrence && isDeclaredHere) { | 565 if (isFirstStatement && isFirstOccurrence && isDeclaredHere) { |
| 571 if (isNullLiteral(definition)) definition = null; | 566 if (isNullLiteral(definition)) definition = null; |
| 572 context.addDeclaration(assign.variable, definition); | 567 context.addDeclaration(assign.variable, definition); |
| 573 context.firstStatement = statement.next; | 568 context.firstStatement = statement.next; |
| 574 visitStatement(statement.next, context); | 569 visitStatement(statement.next, context); |
| 575 return; | 570 return; |
| 576 } | 571 } |
| 577 | 572 |
| 578 context.addStatement(new ExpressionStatement(makeAssignment( | 573 context.addStatement(new ExpressionStatement(makeAssignment( |
| 579 context.makeVariableAccess(assign.variable), | 574 context.makeVariableAccess(assign.variable), |
| 580 definition))); | 575 definition))); |
| 581 visitStatement(statement.next, context); | 576 visitStatement(statement.next, context); |
| 582 } | 577 } |
| 583 | 578 |
| 584 @override | 579 @override |
| 585 void visitReturn(tree.Return stmt, | 580 void visitReturn(tree.Return stmt, BuilderContext<Statement> context) { |
| 586 BuilderContext<Statement> context) { | |
| 587 if (context.currentElement.isGenerativeConstructor && | 581 if (context.currentElement.isGenerativeConstructor && |
| 588 !context.inInitializer) { | 582 !context.inInitializer) { |
| 589 assert(() { | 583 assert(() { |
| 590 tree.Expression value = stmt.value; | 584 tree.Expression value = stmt.value; |
| 591 return value is tree.Constant && value.value.isNull; | 585 return value is tree.Constant && value.value.isNull; |
| 592 }); | 586 }); |
| 593 context.addStatement(new Return(null)); | 587 context.addStatement(new Return(null)); |
| 594 } else { | 588 } else { |
| 595 Expression inner = visitExpression(stmt.value, context); | 589 Expression inner = visitExpression(stmt.value, context); |
| 596 context.addStatement(new Return(inner)); | 590 context.addStatement(new Return(inner)); |
| 597 } | 591 } |
| 598 } | 592 } |
| 599 | 593 |
| 600 @override | 594 @override |
| 601 void visitBreak(tree.Break stmt, | 595 void visitThrow(tree.Throw stmt, BuilderContext<Statement> context) { |
| 602 BuilderContext<Statement> context) { | 596 Expression value = visitExpression(stmt.value, context); |
| 597 context.addStatement(new ExpressionStatement(new Throw(value))); |
| 598 } |
| 599 |
| 600 @override |
| 601 void visitRethrow(tree.Rethrow stmt, BuilderContext<Statement> context) { |
| 602 context.addStatement(new Rethrow()); |
| 603 } |
| 604 |
| 605 @override |
| 606 void visitBreak(tree.Break stmt, BuilderContext<Statement> context) { |
| 603 tree.Statement fall = context.fallthrough; | 607 tree.Statement fall = context.fallthrough; |
| 604 if (stmt.target.binding.next == fall) { | 608 if (stmt.target.binding.next == fall) { |
| 605 // Fall through to break target | 609 // Fall through to break target |
| 606 } else if (fall is tree.Break && fall.target == stmt.target) { | 610 } else if (fall is tree.Break && fall.target == stmt.target) { |
| 607 // Fall through to equivalent break | 611 // Fall through to equivalent break |
| 608 } else { | 612 } else { |
| 609 context.useLabel(stmt.target); | 613 context.useLabel(stmt.target); |
| 610 context.addStatement(new Break(stmt.target.name)); | 614 context.addStatement(new Break(stmt.target.name)); |
| 611 } | 615 } |
| 612 } | 616 } |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null); | 1353 : super(name, ElementKind.VARIABLE, enclosingElement, variables, null); |
| 1350 | 1354 |
| 1351 ExecutableElement get executableContext => enclosingElement; | 1355 ExecutableElement get executableContext => enclosingElement; |
| 1352 | 1356 |
| 1353 ExecutableElement get memberContext => executableContext.memberContext; | 1357 ExecutableElement get memberContext => executableContext.memberContext; |
| 1354 | 1358 |
| 1355 bool get isLocal => true; | 1359 bool get isLocal => true; |
| 1356 | 1360 |
| 1357 LibraryElement get implementationLibrary => enclosingElement.library; | 1361 LibraryElement get implementationLibrary => enclosingElement.library; |
| 1358 } | 1362 } |
| OLD | NEW |