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

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

Issue 460763002: Fix returning from async functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add scope via sequencenode add method Created 6 years, 4 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 | runtime/vm/flow_graph_builder.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')
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 #ifndef VM_AST_H_ 5 #ifndef VM_AST_H_
6 #define VM_AST_H_ 6 #define VM_AST_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 protected: 140 protected:
141 friend class ParsedFunction; 141 friend class ParsedFunction;
142 142
143 private: 143 private:
144 const intptr_t token_pos_; 144 const intptr_t token_pos_;
145 DISALLOW_COPY_AND_ASSIGN(AstNode); 145 DISALLOW_COPY_AND_ASSIGN(AstNode);
146 }; 146 };
147 147
148 148
149 class LiteralNode : public AstNode {
150 public:
151 LiteralNode(intptr_t token_pos, const Instance& literal)
152 : AstNode(token_pos), literal_(literal) {
153 ASSERT(literal_.IsNotTemporaryScopedHandle());
154 ASSERT(literal_.IsSmi() || literal_.IsOld());
155 #if defined(DEBUG)
156 if (literal_.IsString()) {
157 ASSERT(String::Cast(literal_).IsSymbol());
158 }
159 #endif // defined(DEBUG)
160 ASSERT(literal_.IsNull() ||
161 Class::Handle(literal_.clazz()).is_finalized() ||
162 Class::Handle(literal_.clazz()).is_prefinalized());
163 }
164
165 const Instance& literal() const { return literal_; }
166
167 virtual bool IsPotentiallyConst() const;
168 virtual const Instance* EvalConstExpr() const {
169 return &literal();
170 }
171
172 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
173
174 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind);
175
176 DECLARE_COMMON_NODE_FUNCTIONS(LiteralNode);
177
178 private:
179 const Instance& literal_;
180
181 DISALLOW_IMPLICIT_CONSTRUCTORS(LiteralNode);
182 };
183
184
185 class ReturnNode : public AstNode {
186 public:
187 // Return from a void function returns the null object.
188 explicit ReturnNode(intptr_t token_pos)
189 : AstNode(token_pos),
190 value_(new LiteralNode(token_pos, Instance::ZoneHandle())),
191 inlined_finally_list_(),
192 saved_return_value_var_(NULL),
193 scope_(NULL) { }
194 // Return from a non-void function.
195 ReturnNode(intptr_t token_pos,
196 AstNode* value)
197 : AstNode(token_pos),
198 value_(value),
199 inlined_finally_list_(),
200 saved_return_value_var_(NULL),
201 scope_(NULL) {
202 ASSERT(value_ != NULL);
203 }
204
205 AstNode* value() const { return value_; }
206
207 intptr_t inlined_finally_list_length() const {
208 return inlined_finally_list_.length();
209 }
210 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const {
211 return inlined_finally_list_[index];
212 }
213 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) {
214 inlined_finally_list_.Add(finally_node);
215 }
216
217 LocalVariable* saved_return_value_var() const {
218 return saved_return_value_var_;
219 }
220 void set_saved_return_value_var(LocalVariable* var) {
221 saved_return_value_var_ = var;
222 }
223
224 virtual void VisitChildren(AstNodeVisitor* visitor) const {
225 if (value() != NULL) {
226 value()->Visit(visitor);
227 }
228 }
229
230 void set_scope(LocalScope* scope) { scope_ = scope; }
231 LocalScope* scope() const { return scope_; }
232
233 DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode);
234
235 private:
236 AstNode* value_;
237 GrowableArray<InlinedFinallyNode*> inlined_finally_list_;
238 LocalVariable* saved_return_value_var_;
239 LocalScope* scope_;
240
241 DISALLOW_COPY_AND_ASSIGN(ReturnNode);
242 };
243
244
149 class SequenceNode : public AstNode { 245 class SequenceNode : public AstNode {
150 public: 246 public:
151 SequenceNode(intptr_t token_pos, LocalScope* scope) 247 SequenceNode(intptr_t token_pos, LocalScope* scope)
152 : AstNode(token_pos), 248 : AstNode(token_pos),
153 scope_(scope), 249 scope_(scope),
154 nodes_(4), 250 nodes_(4),
155 label_(NULL) { 251 label_(NULL) {
156 } 252 }
157 253
158 LocalScope* scope() const { return scope_; } 254 LocalScope* scope() const { return scope_; }
159 255
160 SourceLabel* label() const { return label_; } 256 SourceLabel* label() const { return label_; }
161 void set_label(SourceLabel* value) { label_ = value; } 257 void set_label(SourceLabel* value) { label_ = value; }
162 258
163 void VisitChildren(AstNodeVisitor* visitor) const; 259 void VisitChildren(AstNodeVisitor* visitor) const;
164 260
165 void Add(AstNode* node) { nodes_.Add(node); } 261 void Add(AstNode* node) {
hausner 2014/08/12 20:51:26 This should now maybe go into the .cc file. Then y
Michael Lippautz (Google) 2014/08/12 21:13:57 Done.
262 if (node->IsReturnNode()) {
263 node->AsReturnNode()->set_scope(scope());
264 }
265 nodes_.Add(node);
266 }
166 intptr_t length() const { return nodes_.length(); } 267 intptr_t length() const { return nodes_.length(); }
167 AstNode* NodeAt(intptr_t index) const { return nodes_[index]; } 268 AstNode* NodeAt(intptr_t index) const { return nodes_[index]; }
168 void ReplaceNodeAt(intptr_t index, AstNode* value) { nodes_[index] = value; } 269 void ReplaceNodeAt(intptr_t index, AstNode* value) { nodes_[index] = value; }
169 270
170 DECLARE_COMMON_NODE_FUNCTIONS(SequenceNode); 271 DECLARE_COMMON_NODE_FUNCTIONS(SequenceNode);
171 272
172 // Collects all nodes accessible from this sequence node into array 'nodes'. 273 // Collects all nodes accessible from this sequence node into array 'nodes'.
173 void CollectAllNodes(GrowableArray<AstNode*>* nodes); 274 void CollectAllNodes(GrowableArray<AstNode*>* nodes);
174 275
175 private: 276 private:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 423
323 DECLARE_COMMON_NODE_FUNCTIONS(StringInterpolateNode); 424 DECLARE_COMMON_NODE_FUNCTIONS(StringInterpolateNode);
324 425
325 private: 426 private:
326 ArrayNode* value_; 427 ArrayNode* value_;
327 428
328 DISALLOW_IMPLICIT_CONSTRUCTORS(StringInterpolateNode); 429 DISALLOW_IMPLICIT_CONSTRUCTORS(StringInterpolateNode);
329 }; 430 };
330 431
331 432
332 class LiteralNode : public AstNode {
333 public:
334 LiteralNode(intptr_t token_pos, const Instance& literal)
335 : AstNode(token_pos), literal_(literal) {
336 ASSERT(literal_.IsNotTemporaryScopedHandle());
337 ASSERT(literal_.IsSmi() || literal_.IsOld());
338 #if defined(DEBUG)
339 if (literal_.IsString()) {
340 ASSERT(String::Cast(literal_).IsSymbol());
341 }
342 #endif // defined(DEBUG)
343 ASSERT(literal_.IsNull() ||
344 Class::Handle(literal_.clazz()).is_finalized() ||
345 Class::Handle(literal_.clazz()).is_prefinalized());
346 }
347
348 const Instance& literal() const { return literal_; }
349
350 virtual bool IsPotentiallyConst() const;
351 virtual const Instance* EvalConstExpr() const {
352 return &literal();
353 }
354
355 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
356
357 virtual AstNode* ApplyUnaryOp(Token::Kind unary_op_kind);
358
359 DECLARE_COMMON_NODE_FUNCTIONS(LiteralNode);
360
361 private:
362 const Instance& literal_;
363
364 DISALLOW_IMPLICIT_CONSTRUCTORS(LiteralNode);
365 };
366
367
368 class TypeNode : public AstNode { 433 class TypeNode : public AstNode {
369 public: 434 public:
370 TypeNode(intptr_t token_pos, const AbstractType& type) 435 TypeNode(intptr_t token_pos, const AbstractType& type)
371 : AstNode(token_pos), type_(type) { 436 : AstNode(token_pos), type_(type) {
372 ASSERT(type_.IsZoneHandle()); 437 ASSERT(type_.IsZoneHandle());
373 ASSERT(!type_.IsNull()); 438 ASSERT(!type_.IsNull());
374 ASSERT(type_.IsFinalized()); 439 ASSERT(type_.IsFinalized());
375 // A wellformed literal Type must be canonical. 440 // A wellformed literal Type must be canonical.
376 ASSERT(!type_.IsType() || 441 ASSERT(!type_.IsType() ||
377 type_.IsMalformedOrMalbounded() || 442 type_.IsMalformedOrMalbounded() ||
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode); 573 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode);
509 574
510 private: 575 private:
511 const Object& primary_; 576 const Object& primary_;
512 bool is_deferred_reference_; 577 bool is_deferred_reference_;
513 578
514 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode); 579 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode);
515 }; 580 };
516 581
517 582
518 class ReturnNode : public AstNode {
519 public:
520 // Return from a void function returns the null object.
521 explicit ReturnNode(intptr_t token_pos)
522 : AstNode(token_pos),
523 value_(new LiteralNode(token_pos, Instance::ZoneHandle())),
524 inlined_finally_list_(),
525 saved_return_value_var_(NULL) { }
526 // Return from a non-void function.
527 ReturnNode(intptr_t token_pos,
528 AstNode* value)
529 : AstNode(token_pos),
530 value_(value),
531 inlined_finally_list_(),
532 saved_return_value_var_(NULL) {
533 ASSERT(value_ != NULL);
534 }
535
536 AstNode* value() const { return value_; }
537
538 intptr_t inlined_finally_list_length() const {
539 return inlined_finally_list_.length();
540 }
541 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const {
542 return inlined_finally_list_[index];
543 }
544 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) {
545 inlined_finally_list_.Add(finally_node);
546 }
547
548 LocalVariable* saved_return_value_var() const {
549 return saved_return_value_var_;
550 }
551 void set_saved_return_value_var(LocalVariable* var) {
552 saved_return_value_var_ = var;
553 }
554
555 virtual void VisitChildren(AstNodeVisitor* visitor) const {
556 if (value() != NULL) {
557 value()->Visit(visitor);
558 }
559 }
560
561 DECLARE_COMMON_NODE_FUNCTIONS(ReturnNode);
562
563 private:
564 AstNode* value_;
565 GrowableArray<InlinedFinallyNode*> inlined_finally_list_;
566 LocalVariable* saved_return_value_var_;
567
568 DISALLOW_COPY_AND_ASSIGN(ReturnNode);
569 };
570
571
572 class ComparisonNode : public AstNode { 583 class ComparisonNode : public AstNode {
573 public: 584 public:
574 ComparisonNode(intptr_t token_pos, 585 ComparisonNode(intptr_t token_pos,
575 Token::Kind kind, 586 Token::Kind kind,
576 AstNode* left, 587 AstNode* left,
577 AstNode* right) 588 AstNode* right)
578 : AstNode(token_pos), kind_(kind), left_(left), right_(right) { 589 : AstNode(token_pos), kind_(kind), left_(left), right_(right) {
579 ASSERT(left_ != NULL); 590 ASSERT(left_ != NULL);
580 ASSERT(right_ != NULL); 591 ASSERT(right_ != NULL);
581 ASSERT(IsKindValid()); 592 ASSERT(IsKindValid());
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 const intptr_t try_index_; 1815 const intptr_t try_index_;
1805 1816
1806 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1817 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1807 }; 1818 };
1808 1819
1809 } // namespace dart 1820 } // namespace dart
1810 1821
1811 #undef DECLARE_COMMON_NODE_FUNCTIONS 1822 #undef DECLARE_COMMON_NODE_FUNCTIONS
1812 1823
1813 #endif // VM_AST_H_ 1824 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/flow_graph_builder.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698