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

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

Issue 16146008: Simplify AST by extending LetNode and replace CommaNode. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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 | runtime/vm/ast.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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 V(LoadLocalNode, "load local") \ 49 V(LoadLocalNode, "load local") \
50 V(StoreLocalNode, "store local") \ 50 V(StoreLocalNode, "store local") \
51 V(LoadInstanceFieldNode, "load field") \ 51 V(LoadInstanceFieldNode, "load field") \
52 V(StoreInstanceFieldNode, "store field") \ 52 V(StoreInstanceFieldNode, "store field") \
53 V(LoadStaticFieldNode, "load static field") \ 53 V(LoadStaticFieldNode, "load static field") \
54 V(StoreStaticFieldNode, "store static field") \ 54 V(StoreStaticFieldNode, "store static field") \
55 V(LoadIndexedNode, "load indexed") \ 55 V(LoadIndexedNode, "load indexed") \
56 V(StoreIndexedNode, "store indexed") \ 56 V(StoreIndexedNode, "store indexed") \
57 V(SequenceNode, "seq") \ 57 V(SequenceNode, "seq") \
58 V(LetNode, "let") \ 58 V(LetNode, "let") \
59 V(CommaNode, "comma") \
60 V(CatchClauseNode, "catch clause block") \ 59 V(CatchClauseNode, "catch clause block") \
61 V(TryCatchNode, "try catch block") \ 60 V(TryCatchNode, "try catch block") \
62 V(ThrowNode, "throw") \ 61 V(ThrowNode, "throw") \
63 V(InlinedFinallyNode, "inlined finally") \ 62 V(InlinedFinallyNode, "inlined finally") \
64 63
65 64
66 #define DEFINE_FORWARD_DECLARATION(type, name) class type; 65 #define DEFINE_FORWARD_DECLARATION(type, name) class type;
67 NODE_LIST(DEFINE_FORWARD_DECLARATION) 66 NODE_LIST(DEFINE_FORWARD_DECLARATION)
68 #undef DEFINE_FORWARD_DECLARATION 67 #undef DEFINE_FORWARD_DECLARATION
69 68
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 174
176 private: 175 private:
177 LocalScope* scope_; 176 LocalScope* scope_;
178 GrowableArray<AstNode*> nodes_; 177 GrowableArray<AstNode*> nodes_;
179 SourceLabel* label_; 178 SourceLabel* label_;
180 179
181 DISALLOW_COPY_AND_ASSIGN(SequenceNode); 180 DISALLOW_COPY_AND_ASSIGN(SequenceNode);
182 }; 181 };
183 182
184 183
185 // Comma node represents a pair of expressions evaluated in sequence
186 // and return the value of the second expression.
187 class CommaNode : public AstNode {
188 public:
189 CommaNode(intptr_t token_pos,
190 AstNode* first,
191 AstNode* second)
192 : AstNode(token_pos),
193 first_(first),
194 second_(second) { }
195
196 AstNode* first() const { return first_; }
197 AstNode* second() const { return second_; }
198
199 void VisitChildren(AstNodeVisitor* visitor) const {
200 first_->Visit(visitor);
201 second_->Visit(visitor);
202 }
203
204 DECLARE_COMMON_NODE_FUNCTIONS(CommaNode);
205
206 private:
207 AstNode* first_;
208 AstNode* second_;
209
210 DISALLOW_COPY_AND_ASSIGN(CommaNode);
211 };
212
213
214 class CloneContextNode : public AstNode { 184 class CloneContextNode : public AstNode {
215 public: 185 public:
216 explicit CloneContextNode(intptr_t token_pos) 186 explicit CloneContextNode(intptr_t token_pos)
217 : AstNode(token_pos) { 187 : AstNode(token_pos) {
218 } 188 }
219 189
220 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 190 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
221 191
222 DECLARE_COMMON_NODE_FUNCTIONS(CloneContextNode); 192 DECLARE_COMMON_NODE_FUNCTIONS(CloneContextNode);
223 193
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 266
297 class LetNode : public AstNode { 267 class LetNode : public AstNode {
298 public: 268 public:
299 explicit LetNode(intptr_t token_pos); 269 explicit LetNode(intptr_t token_pos);
300 270
301 LocalVariable* TempAt(intptr_t i) const { return vars_[i]; } 271 LocalVariable* TempAt(intptr_t i) const { return vars_[i]; }
302 AstNode* InitializerAt(intptr_t i) const { return initializers_[i]; } 272 AstNode* InitializerAt(intptr_t i) const { return initializers_[i]; }
303 273
304 LocalVariable* AddInitializer(AstNode* node); 274 LocalVariable* AddInitializer(AstNode* node);
305 275
276 const GrowableArray<AstNode*>& nodes() const { return nodes_; }
277
278 void AddNode(AstNode* node) { nodes_.Add(node); }
279
306 intptr_t num_temps() const { 280 intptr_t num_temps() const {
307 return vars_.length(); 281 return vars_.length();
308 } 282 }
309 283
310 AstNode* body() const { return body_; }
311 void set_body(AstNode* node) { body_ = node; }
312
313 void VisitChildren(AstNodeVisitor* visitor) const; 284 void VisitChildren(AstNodeVisitor* visitor) const;
314 285
315 DECLARE_COMMON_NODE_FUNCTIONS(LetNode); 286 DECLARE_COMMON_NODE_FUNCTIONS(LetNode);
316 287
317 private: 288 private:
318 GrowableArray<LocalVariable*> vars_; 289 GrowableArray<LocalVariable*> vars_;
319 GrowableArray<AstNode*> initializers_; 290 GrowableArray<AstNode*> initializers_;
320 AstNode* body_; 291 GrowableArray<AstNode*> nodes_;
321 292
322 DISALLOW_COPY_AND_ASSIGN(LetNode); 293 DISALLOW_COPY_AND_ASSIGN(LetNode);
323 }; 294 };
324 295
325 296
326 class ArrayNode : public AstNode { 297 class ArrayNode : public AstNode {
327 public: 298 public:
328 ArrayNode(intptr_t token_pos, const AbstractType& type) 299 ArrayNode(intptr_t token_pos, const AbstractType& type)
329 : AstNode(token_pos), 300 : AstNode(token_pos),
330 type_(type), 301 type_(type),
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 const LocalVariable& context_var_; 1727 const LocalVariable& context_var_;
1757 1728
1758 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1729 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1759 }; 1730 };
1760 1731
1761 } // namespace dart 1732 } // namespace dart
1762 1733
1763 #undef DECLARE_COMMON_NODE_FUNCTIONS 1734 #undef DECLARE_COMMON_NODE_FUNCTIONS
1764 1735
1765 #endif // VM_AST_H_ 1736 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | runtime/vm/flow_graph_builder.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698