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 code_generator; | 5 library code_generator; |
6 | 6 |
7 import 'glue.dart'; | 7 import 'glue.dart'; |
8 | 8 |
9 import '../../closure.dart' show | 9 import '../../closure.dart' show |
10 ClosureClassElement; | 10 ClosureClassElement; |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 shortContinue.use(); | 526 shortContinue.use(); |
527 accumulator.add(new js.Continue(null)); | 527 accumulator.add(new js.Continue(null)); |
528 } else { | 528 } else { |
529 usedLabels.add(node.target); | 529 usedLabels.add(node.target); |
530 accumulator.add(new js.Break(node.target.name)); | 530 accumulator.add(new js.Break(node.target.name)); |
531 } | 531 } |
532 } | 532 } |
533 | 533 |
534 @override | 534 @override |
535 void visitExpressionStatement(tree_ir.ExpressionStatement node) { | 535 void visitExpressionStatement(tree_ir.ExpressionStatement node) { |
536 accumulator.add(new js.ExpressionStatement( | 536 js.Expression exp = visitExpression(node.expression); |
537 visitExpression(node.expression))); | 537 if (node.next is tree_ir.Unreachable) { |
sra1
2015/11/30 18:59:40
Can we tell if the unreachable code is not conditi
asgerf
2015/12/01 12:40:20
The easy fix was to look at the fallthrough stack,
| |
538 visitStatement(node.next); | 538 // Emit as 'return exp' to assist local analysis in the VM. |
539 accumulator.add(new js.Return(exp)); | |
540 } else { | |
541 accumulator.add(new js.ExpressionStatement(exp)); | |
542 visitStatement(node.next); | |
543 } | |
539 } | 544 } |
540 | 545 |
541 @override | 546 @override |
542 void visitIf(tree_ir.If node) { | 547 void visitIf(tree_ir.If node) { |
543 js.Expression condition = visitExpression(node.condition); | 548 js.Expression condition = visitExpression(node.condition); |
544 int usesBefore = fallthrough.useCount; | 549 int usesBefore = fallthrough.useCount; |
545 js.Statement thenBody = buildBodyStatement(node.thenStatement); | 550 js.Statement thenBody = buildBodyStatement(node.thenStatement); |
546 bool thenHasFallthrough = (fallthrough.useCount > usesBefore); | 551 bool thenHasFallthrough = (fallthrough.useCount > usesBefore); |
547 if (thenHasFallthrough) { | 552 if (thenHasFallthrough) { |
548 js.Statement elseBody = buildBodyStatement(node.elseStatement); | 553 js.Statement elseBody = buildBodyStatement(node.elseStatement); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 accumulator.add(new js.Throw(visitExpression(node.value))); | 680 accumulator.add(new js.Throw(visitExpression(node.value))); |
676 } | 681 } |
677 | 682 |
678 @override | 683 @override |
679 void visitRethrow(tree_ir.Rethrow node) { | 684 void visitRethrow(tree_ir.Rethrow node) { |
680 glue.reportInternalError('rethrow seen in JavaScript output'); | 685 glue.reportInternalError('rethrow seen in JavaScript output'); |
681 } | 686 } |
682 | 687 |
683 @override | 688 @override |
684 void visitUnreachable(tree_ir.Unreachable node) { | 689 void visitUnreachable(tree_ir.Unreachable node) { |
685 // Output nothing. | 690 // Emit a return to assist local analysis in the VM. |
686 // TODO(asgerf): Emit a throw/return to assist local analysis in the VM? | 691 accumulator.add(new js.Return()); |
687 } | 692 } |
688 | 693 |
689 @override | 694 @override |
690 void visitTry(tree_ir.Try node) { | 695 void visitTry(tree_ir.Try node) { |
691 js.Block tryBlock = buildBodyBlock(node.tryBody); | 696 js.Block tryBlock = buildBodyBlock(node.tryBody); |
692 tree_ir.Variable exceptionVariable = node.catchParameters.first; | 697 tree_ir.Variable exceptionVariable = node.catchParameters.first; |
693 js.VariableDeclaration exceptionParameter = | 698 js.VariableDeclaration exceptionParameter = |
694 new js.VariableDeclaration(getVariableName(exceptionVariable)); | 699 new js.VariableDeclaration(getVariableName(exceptionVariable)); |
695 js.Block catchBlock = buildBodyBlock(node.catchBody); | 700 js.Block catchBlock = buildBodyBlock(node.catchBody); |
696 js.Catch catchPart = new js.Catch(exceptionParameter, catchBlock); | 701 js.Catch catchPart = new js.Catch(exceptionParameter, catchBlock); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 void registerDefaultParameterValues(ExecutableElement element) { | 1094 void registerDefaultParameterValues(ExecutableElement element) { |
1090 if (element is! FunctionElement) return; | 1095 if (element is! FunctionElement) return; |
1091 FunctionElement function = element; | 1096 FunctionElement function = element; |
1092 if (function.isStatic) return; // Defaults are inlined at call sites. | 1097 if (function.isStatic) return; // Defaults are inlined at call sites. |
1093 function.functionSignature.forEachOptionalParameter((param) { | 1098 function.functionSignature.forEachOptionalParameter((param) { |
1094 ConstantValue constant = glue.getDefaultParameterValue(param); | 1099 ConstantValue constant = glue.getDefaultParameterValue(param); |
1095 registry.registerCompileTimeConstant(constant); | 1100 registry.registerCompileTimeConstant(constant); |
1096 }); | 1101 }); |
1097 } | 1102 } |
1098 } | 1103 } |
OLD | NEW |