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

Unified Diff: sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart

Issue 14890026: Handle switch statement in simple types inferrer. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart (revision 22849)
+++ sdk/lib/_internal/compiler/implementation/types/simple_types_inferrer.dart (working copy)
@@ -2437,4 +2437,45 @@
void internalError(String reason, {Node node}) {
compiler.internalError(reason, node: node);
}
+
+ TypeMask visitSwitchStatement(SwitchStatement node) {
+ visit(node.parenthesizedExpression);
+
+ if (Elements.switchStatementHasContinue(node, elements)) {
+ // If the switch statement has a continue, we conservatively
+ // visit all cases and update [locals] until we have reached a
+ // fixed point.
+ bool changed;
+ do {
+ changed = false;
+ for (Node switchCase in node.cases) {
+ LocalsHandler saved = new LocalsHandler.from(locals);
+ visit(switchCase);
+ changed = saved.merge(locals) || changed;
+ locals = saved;
+ }
+ } while (changed);
+ } else {
+ LocalsHandler saved = new LocalsHandler.from(locals);
+ // If there is a default case, the current values of the local
+ // variable might be overwritten, so we don't need the current
+ // [locals] for the join block.
+ LocalsHandler result = Elements.switchStatementHasDefault(node)
+ ? null
+ : new LocalsHandler.from(locals);
+
+ for (Node switchCase in node.cases) {
+ locals = saved;
+ visit(switchCase);
+ if (result == null) {
+ result = locals;
+ } else {
+ result.merge(locals);
+ }
+ }
+
+ locals = result;
+ }
+ return inferrer.dynamicType;
+ }
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/elements/elements.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698