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

Side by Side Diff: runtime/vm/scopes.h

Issue 9907001: Implement JumpNode for break/continue in for loops. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
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 #ifndef VM_SCOPES_H_ 5 #ifndef VM_SCOPES_H_
6 #define VM_SCOPES_H_ 6 #define VM_SCOPES_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 class JoinEntryInstr;
14 class LocalScope; 15 class LocalScope;
15 class LocalVariable; 16 class LocalVariable;
16 class SourceLabel; 17 class SourceLabel;
17 18
18 19
19 class LocalVariable : public ZoneAllocated { 20 class LocalVariable : public ZoneAllocated {
20 public: 21 public:
21 LocalVariable(intptr_t token_index, 22 LocalVariable(intptr_t token_index,
22 const String& name, 23 const String& name,
23 const AbstractType& type) 24 const AbstractType& type)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 kForward, 108 kForward,
108 kStatement // Any statement other than the above 109 kStatement // Any statement other than the above
109 }; 110 };
110 111
111 SourceLabel(intptr_t token_index, const String& name, Kind kind) 112 SourceLabel(intptr_t token_index, const String& name, Kind kind)
112 : token_index_(token_index), 113 : token_index_(token_index),
113 name_(name), 114 name_(name),
114 owner_(NULL), 115 owner_(NULL),
115 kind_(kind), 116 kind_(kind),
116 continue_label_(), 117 continue_label_(),
117 break_label_() { 118 break_label_(),
119 is_break_jump_target_(false),
120 join_for_break_(NULL),
121 is_continue_jump_target_(false),
122 join_for_continue_(NULL) {
118 } 123 }
119 124
120 static SourceLabel* New(intptr_t token_index, String* name, Kind kind) { 125 static SourceLabel* New(intptr_t token_index, String* name, Kind kind) {
121 if (name != NULL) { 126 if (name != NULL) {
122 return new SourceLabel(token_index, *name, kind); 127 return new SourceLabel(token_index, *name, kind);
123 } else { 128 } else {
124 return new SourceLabel(token_index, 129 return new SourceLabel(token_index,
125 String::ZoneHandle(String::New(kDefaultLabelName)), 130 String::ZoneHandle(String::New(kDefaultLabelName)),
126 kind); 131 kind);
127 } 132 }
128 } 133 }
129 134
130 intptr_t token_index() const { return token_index_; } 135 intptr_t token_index() const { return token_index_; }
131 const String& name() const { return name_; } 136 const String& name() const { return name_; }
132 LocalScope* owner() const { return owner_; } 137 LocalScope* owner() const { return owner_; }
133 void set_owner(LocalScope* owner) { 138 void set_owner(LocalScope* owner) {
134 ASSERT(owner_ == NULL); 139 ASSERT(owner_ == NULL);
135 owner_ = owner; 140 owner_ = owner;
136 } 141 }
137 142
138 Kind kind() const { return kind_; } 143 Kind kind() const { return kind_; }
139 Label* break_label() { return &break_label_; } 144 Label* break_label() { return &break_label_; }
140 Label* continue_label() { return &continue_label_; } 145 Label* continue_label() { return &continue_label_; }
141 146
147 void SetIsJumpTarget(Token::Kind jump_kind) {
148 ASSERT((jump_kind == Token::kBREAK) || (jump_kind == Token::kCONTINUE));
149 if (jump_kind == Token::kBREAK) {
150 is_break_jump_target_ = true;
151 } else {
152 is_continue_jump_target_ = true;
153 }
154 }
155 bool is_break_jump_target() const { return is_break_jump_target_; }
156 bool is_continue_jump_target() const { return is_continue_jump_target_; }
157
158 void set_join_for_continue(JoinEntryInstr* join) {
159 ASSERT(join_for_continue_ == NULL);
160 join_for_continue_ = join;
161 }
162
163 JoinEntryInstr* join_for_continue() const {
164 return join_for_continue_;
165 }
166
167 void set_join_for_break(JoinEntryInstr* join) {
168 ASSERT(join_for_break_ == NULL);
169 join_for_break_ = join;
170 }
171
172 JoinEntryInstr* join_for_break() const {
173 return join_for_break_;
174 }
175
142 // Returns the function level of the scope in which the label is defined. 176 // Returns the function level of the scope in which the label is defined.
143 int FunctionLevel() const; 177 int FunctionLevel() const;
144 178
145 void ResolveForwardReference() { kind_ = kCase; } 179 void ResolveForwardReference() { kind_ = kCase; }
146 180
147 private: 181 private:
148 const intptr_t token_index_; 182 const intptr_t token_index_;
149 const String& name_; 183 const String& name_;
150 LocalScope* owner_; // Local scope declaring this label. 184 LocalScope* owner_; // Local scope declaring this label.
151 185
152 Kind kind_; 186 Kind kind_;
153 Label continue_label_; 187 Label continue_label_;
154 Label break_label_; 188 Label break_label_;
189 bool is_break_jump_target_;
190 JoinEntryInstr* join_for_break_;
191 bool is_continue_jump_target_;
192 JoinEntryInstr* join_for_continue_;
155 static const char* kDefaultLabelName; 193 static const char* kDefaultLabelName;
156 194
157 DISALLOW_COPY_AND_ASSIGN(SourceLabel); 195 DISALLOW_COPY_AND_ASSIGN(SourceLabel);
158 }; 196 };
159 197
160 198
161 class LocalScope : public ZoneAllocated { 199 class LocalScope : public ZoneAllocated {
162 public: 200 public:
163 LocalScope(LocalScope* parent, int function_level, int loop_level); 201 LocalScope(LocalScope* parent, int function_level, int loop_level);
164 202
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 intptr_t end_token_index_; // Token index of end of scope. 337 intptr_t end_token_index_; // Token index of end of scope.
300 GrowableArray<LocalVariable*> variables_; 338 GrowableArray<LocalVariable*> variables_;
301 GrowableArray<SourceLabel*> labels_; 339 GrowableArray<SourceLabel*> labels_;
302 340
303 DISALLOW_COPY_AND_ASSIGN(LocalScope); 341 DISALLOW_COPY_AND_ASSIGN(LocalScope);
304 }; 342 };
305 343
306 } // namespace dart 344 } // namespace dart
307 345
308 #endif // VM_SCOPES_H_ 346 #endif // VM_SCOPES_H_
OLDNEW
« runtime/vm/flow_graph_builder.cc ('K') | « runtime/vm/flow_graph_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698