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

Side by Side Diff: runtime/vm/flow_graph_builder.cc

Issue 308053012: Fix try-catch and continue in switch statements. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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 | « no previous file | tests/language/switch_try_catch_test.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/flow_graph_builder.h" 5 #include "vm/flow_graph_builder.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/ast_printer.h" 8 #include "vm/ast_printer.h"
9 #include "vm/bit_vector.h" 9 #include "vm/bit_vector.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 virtual intptr_t ContextLevel() const; 82 virtual intptr_t ContextLevel() const;
83 83
84 virtual JoinEntryInstr* BreakTargetFor(SourceLabel* label); 84 virtual JoinEntryInstr* BreakTargetFor(SourceLabel* label);
85 virtual JoinEntryInstr* ContinueTargetFor(SourceLabel* label); 85 virtual JoinEntryInstr* ContinueTargetFor(SourceLabel* label);
86 86
87 protected: 87 protected:
88 NestedStatement(FlowGraphBuilder* owner, const SourceLabel* label) 88 NestedStatement(FlowGraphBuilder* owner, const SourceLabel* label)
89 : owner_(owner), 89 : owner_(owner),
90 label_(label), 90 label_(label),
91 outer_(owner->nesting_stack_), 91 outer_(owner->nesting_stack_),
92 break_target_(NULL) { 92 break_target_(NULL),
93 try_index_(owner->try_index()) {
93 // Push on the owner's nesting stack. 94 // Push on the owner's nesting stack.
94 owner->nesting_stack_ = this; 95 owner->nesting_stack_ = this;
95 } 96 }
96 97
98 intptr_t try_index() const { return try_index_; }
99
97 virtual ~NestedStatement() { 100 virtual ~NestedStatement() {
98 // Pop from the owner's nesting stack. 101 // Pop from the owner's nesting stack.
99 ASSERT(owner_->nesting_stack_ == this); 102 ASSERT(owner_->nesting_stack_ == this);
100 owner_->nesting_stack_ = outer_; 103 owner_->nesting_stack_ = outer_;
101 } 104 }
102 105
103 private: 106 private:
104 FlowGraphBuilder* owner_; 107 FlowGraphBuilder* owner_;
105 const SourceLabel* label_; 108 const SourceLabel* label_;
106 NestedStatement* outer_; 109 NestedStatement* outer_;
107 110
108 JoinEntryInstr* break_target_; 111 JoinEntryInstr* break_target_;
112 intptr_t try_index_;
srdjan 2014/06/02 18:29:31 const?
Florian Schneider 2014/06/03 10:50:18 Yes, I will add it in my next cl.
109 }; 113 };
110 114
111 115
112 intptr_t NestedStatement::ContextLevel() const { 116 intptr_t NestedStatement::ContextLevel() const {
113 // Context level is determined by the innermost nested statement having one. 117 // Context level is determined by the innermost nested statement having one.
114 return (outer() == NULL) ? 0 : outer()->ContextLevel(); 118 return (outer() == NULL) ? 0 : outer()->ContextLevel();
115 } 119 }
116 120
117 121
118 intptr_t FlowGraphBuilder::context_level() const { 122 intptr_t FlowGraphBuilder::context_level() const {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 178
175 private: 179 private:
176 JoinEntryInstr* continue_target_; 180 JoinEntryInstr* continue_target_;
177 }; 181 };
178 182
179 183
180 JoinEntryInstr* NestedLoop::ContinueTargetFor(SourceLabel* label) { 184 JoinEntryInstr* NestedLoop::ContinueTargetFor(SourceLabel* label) {
181 if (label != this->label()) return NULL; 185 if (label != this->label()) return NULL;
182 if (continue_target_ == NULL) { 186 if (continue_target_ == NULL) {
183 continue_target_ = 187 continue_target_ =
184 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index()); 188 new JoinEntryInstr(owner()->AllocateBlockId(), try_index());
185 } 189 }
186 return continue_target_; 190 return continue_target_;
187 } 191 }
188 192
189 193
190 // A nested switch which can be the target of a break if labeled, and whose 194 // A nested switch which can be the target of a break if labeled, and whose
191 // cases can be the targets of continues. 195 // cases can be the targets of continues.
192 class NestedSwitch : public NestedStatement { 196 class NestedSwitch : public NestedStatement {
193 public: 197 public:
194 NestedSwitch(FlowGraphBuilder* owner, SwitchNode* node); 198 NestedSwitch(FlowGraphBuilder* owner, SwitchNode* node);
(...skipping 22 matching lines...) Expand all
217 221
218 222
219 JoinEntryInstr* NestedSwitch::ContinueTargetFor(SourceLabel* label) { 223 JoinEntryInstr* NestedSwitch::ContinueTargetFor(SourceLabel* label) {
220 // Allocate a join for a case clause that matches the label. This block 224 // Allocate a join for a case clause that matches the label. This block
221 // is not necessarily targeted by a continue, but we always use a join in 225 // is not necessarily targeted by a continue, but we always use a join in
222 // the graph anyway. 226 // the graph anyway.
223 for (intptr_t i = 0; i < case_labels_.length(); ++i) { 227 for (intptr_t i = 0; i < case_labels_.length(); ++i) {
224 if (label != case_labels_[i]) continue; 228 if (label != case_labels_[i]) continue;
225 if (case_targets_[i] == NULL) { 229 if (case_targets_[i] == NULL) {
226 case_targets_[i] = 230 case_targets_[i] =
227 new JoinEntryInstr(owner()->AllocateBlockId(), owner()->try_index()); 231 new JoinEntryInstr(owner()->AllocateBlockId(), try_index());
228 } 232 }
229 return case_targets_[i]; 233 return case_targets_[i];
230 } 234 }
231 return NULL; 235 return NULL;
232 } 236 }
233 237
234 238
235 FlowGraphBuilder::FlowGraphBuilder(ParsedFunction* parsed_function, 239 FlowGraphBuilder::FlowGraphBuilder(ParsedFunction* parsed_function,
236 const Array& ic_data_array, 240 const Array& ic_data_array,
237 InlineExitCollector* exit_collector, 241 InlineExitCollector* exit_collector,
(...skipping 3747 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 LanguageError::kBailout, 3989 LanguageError::kBailout,
3986 Heap::kNew, 3990 Heap::kNew,
3987 "FlowGraphBuilder Bailout: %s %s", 3991 "FlowGraphBuilder Bailout: %s %s",
3988 String::Handle(I, function.name()).ToCString(), 3992 String::Handle(I, function.name()).ToCString(),
3989 reason)); 3993 reason));
3990 I->long_jump_base()->Jump(1, error); 3994 I->long_jump_base()->Jump(1, error);
3991 UNREACHABLE(); 3995 UNREACHABLE();
3992 } 3996 }
3993 3997
3994 } // namespace dart 3998 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/switch_try_catch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698