| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 // The labels associated with this statement. May be NULL; | 195 // The labels associated with this statement. May be NULL; |
| 196 // if it is != NULL, guaranteed to contain at least one entry. | 196 // if it is != NULL, guaranteed to contain at least one entry. |
| 197 ZoneStringList* labels() const { return labels_; } | 197 ZoneStringList* labels() const { return labels_; } |
| 198 | 198 |
| 199 // Type testing & conversion. | 199 // Type testing & conversion. |
| 200 virtual BreakableStatement* AsBreakableStatement() { return this; } | 200 virtual BreakableStatement* AsBreakableStatement() { return this; } |
| 201 | 201 |
| 202 // Code generation | 202 // Code generation |
| 203 JumpTarget* break_target() { return &break_target_; } | 203 BreakTarget* break_target() { return &break_target_; } |
| 204 | 204 |
| 205 // Used during code generation for restoring the stack when a | 205 // Used during code generation for restoring the stack when a |
| 206 // break/continue crosses a statement that keeps stuff on the stack. | 206 // break/continue crosses a statement that keeps stuff on the stack. |
| 207 int break_stack_height() { return break_stack_height_; } | 207 int break_stack_height() { return break_stack_height_; } |
| 208 void set_break_stack_height(int height) { break_stack_height_ = height; } | 208 void set_break_stack_height(int height) { break_stack_height_ = height; } |
| 209 | 209 |
| 210 // Testers. | 210 // Testers. |
| 211 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } | 211 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } |
| 212 | 212 |
| 213 protected: | 213 protected: |
| 214 BreakableStatement(ZoneStringList* labels, Type type) | 214 BreakableStatement(ZoneStringList* labels, Type type) |
| 215 : labels_(labels), type_(type) { | 215 : labels_(labels), type_(type) { |
| 216 ASSERT(labels == NULL || labels->length() > 0); | 216 ASSERT(labels == NULL || labels->length() > 0); |
| 217 } | 217 } |
| 218 | 218 |
| 219 private: | 219 private: |
| 220 ZoneStringList* labels_; | 220 ZoneStringList* labels_; |
| 221 Type type_; | 221 Type type_; |
| 222 JumpTarget break_target_; | 222 BreakTarget break_target_; |
| 223 int break_stack_height_; | 223 int break_stack_height_; |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 | 226 |
| 227 class Block: public BreakableStatement { | 227 class Block: public BreakableStatement { |
| 228 public: | 228 public: |
| 229 Block(ZoneStringList* labels, int capacity, bool is_initializer_block) | 229 Block(ZoneStringList* labels, int capacity, bool is_initializer_block) |
| 230 : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY), | 230 : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY), |
| 231 statements_(capacity), | 231 statements_(capacity), |
| 232 is_initializer_block_(is_initializer_block) { } | 232 is_initializer_block_(is_initializer_block) { } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 269 |
| 270 | 270 |
| 271 class IterationStatement: public BreakableStatement { | 271 class IterationStatement: public BreakableStatement { |
| 272 public: | 272 public: |
| 273 // Type testing & conversion. | 273 // Type testing & conversion. |
| 274 virtual IterationStatement* AsIterationStatement() { return this; } | 274 virtual IterationStatement* AsIterationStatement() { return this; } |
| 275 | 275 |
| 276 Statement* body() const { return body_; } | 276 Statement* body() const { return body_; } |
| 277 | 277 |
| 278 // Code generation | 278 // Code generation |
| 279 JumpTarget* continue_target() { return &continue_target_; } | 279 BreakTarget* continue_target() { return &continue_target_; } |
| 280 | 280 |
| 281 protected: | 281 protected: |
| 282 explicit IterationStatement(ZoneStringList* labels) | 282 explicit IterationStatement(ZoneStringList* labels) |
| 283 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { } | 283 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { } |
| 284 | 284 |
| 285 void Initialize(Statement* body) { | 285 void Initialize(Statement* body) { |
| 286 body_ = body; | 286 body_ = body; |
| 287 } | 287 } |
| 288 | 288 |
| 289 private: | 289 private: |
| 290 Statement* body_; | 290 Statement* body_; |
| 291 JumpTarget continue_target_; | 291 BreakTarget continue_target_; |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 | 294 |
| 295 class LoopStatement: public IterationStatement { | 295 class LoopStatement: public IterationStatement { |
| 296 public: | 296 public: |
| 297 enum Type { DO_LOOP, FOR_LOOP, WHILE_LOOP }; | 297 enum Type { DO_LOOP, FOR_LOOP, WHILE_LOOP }; |
| 298 | 298 |
| 299 LoopStatement(ZoneStringList* labels, Type type) | 299 LoopStatement(ZoneStringList* labels, Type type) |
| 300 : IterationStatement(labels), type_(type), init_(NULL), | 300 : IterationStatement(labels), type_(type), init_(NULL), |
| 301 cond_(NULL), next_(NULL) { } | 301 cond_(NULL), next_(NULL) { } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 class CaseClause: public ZoneObject { | 444 class CaseClause: public ZoneObject { |
| 445 public: | 445 public: |
| 446 CaseClause(Expression* label, ZoneList<Statement*>* statements) | 446 CaseClause(Expression* label, ZoneList<Statement*>* statements) |
| 447 : label_(label), statements_(statements) { } | 447 : label_(label), statements_(statements) { } |
| 448 | 448 |
| 449 bool is_default() const { return label_ == NULL; } | 449 bool is_default() const { return label_ == NULL; } |
| 450 Expression* label() const { | 450 Expression* label() const { |
| 451 CHECK(!is_default()); | 451 CHECK(!is_default()); |
| 452 return label_; | 452 return label_; |
| 453 } | 453 } |
| 454 JumpTarget* body_target() { return &body_target_; } | 454 BreakTarget* body_target() { return &body_target_; } |
| 455 ZoneList<Statement*>* statements() const { return statements_; } | 455 ZoneList<Statement*>* statements() const { return statements_; } |
| 456 | 456 |
| 457 private: | 457 private: |
| 458 Expression* label_; | 458 Expression* label_; |
| 459 JumpTarget body_target_; | 459 BreakTarget body_target_; |
| 460 ZoneList<Statement*>* statements_; | 460 ZoneList<Statement*>* statements_; |
| 461 }; | 461 }; |
| 462 | 462 |
| 463 | 463 |
| 464 class SwitchStatement: public BreakableStatement { | 464 class SwitchStatement: public BreakableStatement { |
| 465 public: | 465 public: |
| 466 explicit SwitchStatement(ZoneStringList* labels) | 466 explicit SwitchStatement(ZoneStringList* labels) |
| 467 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), | 467 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), |
| 468 tag_(NULL), cases_(NULL) { } | 468 tag_(NULL), cases_(NULL) { } |
| 469 | 469 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 Expression* condition_; | 510 Expression* condition_; |
| 511 Statement* then_statement_; | 511 Statement* then_statement_; |
| 512 Statement* else_statement_; | 512 Statement* else_statement_; |
| 513 }; | 513 }; |
| 514 | 514 |
| 515 | 515 |
| 516 // NOTE: TargetCollectors are represented as nodes to fit in the target | 516 // NOTE: TargetCollectors are represented as nodes to fit in the target |
| 517 // stack in the compiler; this should probably be reworked. | 517 // stack in the compiler; this should probably be reworked. |
| 518 class TargetCollector: public Node { | 518 class TargetCollector: public Node { |
| 519 public: | 519 public: |
| 520 explicit TargetCollector(ZoneList<JumpTarget*>* targets) | 520 explicit TargetCollector(ZoneList<BreakTarget*>* targets) |
| 521 : targets_(targets) { | 521 : targets_(targets) { |
| 522 } | 522 } |
| 523 | 523 |
| 524 // Adds a jump target to the collector. The collector stores a pointer not | 524 // Adds a jump target to the collector. The collector stores a pointer not |
| 525 // a copy of the target to make binding work, so make sure not to pass in | 525 // a copy of the target to make binding work, so make sure not to pass in |
| 526 // references to something on the stack. | 526 // references to something on the stack. |
| 527 void AddTarget(JumpTarget* target); | 527 void AddTarget(BreakTarget* target); |
| 528 | 528 |
| 529 // Virtual behaviour. TargetCollectors are never part of the AST. | 529 // Virtual behaviour. TargetCollectors are never part of the AST. |
| 530 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } | 530 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
| 531 virtual TargetCollector* AsTargetCollector() { return this; } | 531 virtual TargetCollector* AsTargetCollector() { return this; } |
| 532 | 532 |
| 533 ZoneList<JumpTarget*>* targets() { return targets_; } | 533 ZoneList<BreakTarget*>* targets() { return targets_; } |
| 534 | 534 |
| 535 private: | 535 private: |
| 536 ZoneList<JumpTarget*>* targets_; | 536 ZoneList<BreakTarget*>* targets_; |
| 537 }; | 537 }; |
| 538 | 538 |
| 539 | 539 |
| 540 class TryStatement: public Statement { | 540 class TryStatement: public Statement { |
| 541 public: | 541 public: |
| 542 explicit TryStatement(Block* try_block) | 542 explicit TryStatement(Block* try_block) |
| 543 : try_block_(try_block), escaping_targets_(NULL) { } | 543 : try_block_(try_block), escaping_targets_(NULL) { } |
| 544 | 544 |
| 545 void set_escaping_targets(ZoneList<JumpTarget*>* targets) { | 545 void set_escaping_targets(ZoneList<BreakTarget*>* targets) { |
| 546 escaping_targets_ = targets; | 546 escaping_targets_ = targets; |
| 547 } | 547 } |
| 548 | 548 |
| 549 Block* try_block() const { return try_block_; } | 549 Block* try_block() const { return try_block_; } |
| 550 ZoneList<JumpTarget*>* escaping_targets() const { return escaping_targets_; } | 550 ZoneList<BreakTarget*>* escaping_targets() const { return escaping_targets_; } |
| 551 | 551 |
| 552 private: | 552 private: |
| 553 Block* try_block_; | 553 Block* try_block_; |
| 554 ZoneList<JumpTarget*>* escaping_targets_; | 554 ZoneList<BreakTarget*>* escaping_targets_; |
| 555 }; | 555 }; |
| 556 | 556 |
| 557 | 557 |
| 558 class TryCatch: public TryStatement { | 558 class TryCatch: public TryStatement { |
| 559 public: | 559 public: |
| 560 TryCatch(Block* try_block, Expression* catch_var, Block* catch_block) | 560 TryCatch(Block* try_block, Expression* catch_var, Block* catch_block) |
| 561 : TryStatement(try_block), | 561 : TryStatement(try_block), |
| 562 catch_var_(catch_var), | 562 catch_var_(catch_var), |
| 563 catch_block_(catch_block) { | 563 catch_block_(catch_block) { |
| 564 ASSERT(catch_var->AsVariableProxy() != NULL); | 564 ASSERT(catch_var->AsVariableProxy() != NULL); |
| (...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1676 #undef DEF_VISIT | 1676 #undef DEF_VISIT |
| 1677 | 1677 |
| 1678 private: | 1678 private: |
| 1679 bool stack_overflow_; | 1679 bool stack_overflow_; |
| 1680 }; | 1680 }; |
| 1681 | 1681 |
| 1682 | 1682 |
| 1683 } } // namespace v8::internal | 1683 } } // namespace v8::internal |
| 1684 | 1684 |
| 1685 #endif // V8_AST_H_ | 1685 #endif // V8_AST_H_ |
| OLD | NEW |