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

Side by Side Diff: src/ast.h

Issue 998001: Loop peeling for inner loops.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 9 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 | src/ast.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Please do appreciate the required space in "> >". 113 // Please do appreciate the required space in "> >".
114 typedef ZoneList<Handle<String> > ZoneStringList; 114 typedef ZoneList<Handle<String> > ZoneStringList;
115 typedef ZoneList<Handle<Object> > ZoneObjectList; 115 typedef ZoneList<Handle<Object> > ZoneObjectList;
116 116
117 117
118 class AstNode: public ZoneObject { 118 class AstNode: public ZoneObject {
119 public: 119 public:
120 static const int kNoNumber = -1; 120 static const int kNoNumber = -1;
121 121
122 AstNode() : num_(kNoNumber) {} 122 AstNode() : num_(kNoNumber) {}
123
124 explicit AstNode(AstNode* other);
125
123 virtual ~AstNode() { } 126 virtual ~AstNode() { }
124 virtual void Accept(AstVisitor* v) = 0; 127 virtual void Accept(AstVisitor* v) = 0;
125 128
126 // Type testing & conversion. 129 // Type testing & conversion.
127 virtual Statement* AsStatement() { return NULL; } 130 virtual Statement* AsStatement() { return NULL; }
131 virtual Block* AsBlock() { return NULL; }
128 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } 132 virtual ExpressionStatement* AsExpressionStatement() { return NULL; }
129 virtual EmptyStatement* AsEmptyStatement() { return NULL; } 133 virtual EmptyStatement* AsEmptyStatement() { return NULL; }
130 virtual Expression* AsExpression() { return NULL; } 134 virtual Expression* AsExpression() { return NULL; }
131 virtual Literal* AsLiteral() { return NULL; } 135 virtual Literal* AsLiteral() { return NULL; }
132 virtual Slot* AsSlot() { return NULL; } 136 virtual Slot* AsSlot() { return NULL; }
133 virtual VariableProxy* AsVariableProxy() { return NULL; } 137 virtual VariableProxy* AsVariableProxy() { return NULL; }
134 virtual Property* AsProperty() { return NULL; } 138 virtual Property* AsProperty() { return NULL; }
135 virtual Call* AsCall() { return NULL; } 139 virtual Call* AsCall() { return NULL; }
136 virtual TargetCollector* AsTargetCollector() { return NULL; } 140 virtual TargetCollector* AsTargetCollector() { return NULL; }
137 virtual BreakableStatement* AsBreakableStatement() { return NULL; } 141 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
138 virtual IterationStatement* AsIterationStatement() { return NULL; } 142 virtual IterationStatement* AsIterationStatement() { return NULL; }
143 virtual ForStatement* AsForStatement() { return NULL; }
139 virtual UnaryOperation* AsUnaryOperation() { return NULL; } 144 virtual UnaryOperation* AsUnaryOperation() { return NULL; }
140 virtual CountOperation* AsCountOperation() { return NULL; } 145 virtual CountOperation* AsCountOperation() { return NULL; }
141 virtual BinaryOperation* AsBinaryOperation() { return NULL; } 146 virtual BinaryOperation* AsBinaryOperation() { return NULL; }
142 virtual Assignment* AsAssignment() { return NULL; } 147 virtual Assignment* AsAssignment() { return NULL; }
143 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } 148 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; }
144 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } 149 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
145 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } 150 virtual ObjectLiteral* AsObjectLiteral() { return NULL; }
146 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } 151 virtual ArrayLiteral* AsArrayLiteral() { return NULL; }
147 virtual CompareOperation* AsCompareOperation() { return NULL; } 152 virtual CompareOperation* AsCompareOperation() { return NULL; }
148 153
149 int num() { return num_; } 154 int num() { return num_; }
150 void set_num(int n) { num_ = n; } 155 void set_num(int n) { num_ = n; }
151 156
152 private: 157 private:
153 // Support for ast node numbering. 158 // Support for ast node numbering.
154 int num_; 159 int num_;
155 }; 160 };
156 161
157 162
158 class Statement: public AstNode { 163 class Statement: public AstNode {
159 public: 164 public:
160 Statement() : statement_pos_(RelocInfo::kNoPosition) {} 165 Statement() : statement_pos_(RelocInfo::kNoPosition) {}
161 166
167 explicit Statement(Statement* other);
168
162 virtual Statement* AsStatement() { return this; } 169 virtual Statement* AsStatement() { return this; }
163 virtual ReturnStatement* AsReturnStatement() { return NULL; } 170 virtual ReturnStatement* AsReturnStatement() { return NULL; }
164 171
165 virtual Assignment* StatementAsSimpleAssignment() { return NULL; } 172 virtual Assignment* StatementAsSimpleAssignment() { return NULL; }
166 virtual CountOperation* StatementAsCountOperation() { return NULL; } 173 virtual CountOperation* StatementAsCountOperation() { return NULL; }
167 174
168 bool IsEmpty() { return AsEmptyStatement() != NULL; } 175 bool IsEmpty() { return AsEmptyStatement() != NULL; }
169 176
170 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } 177 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
171 int statement_pos() const { return statement_pos_; } 178 int statement_pos() const { return statement_pos_; }
(...skipping 21 matching lines...) Expand all
193 // Evaluated for control flow and side effects. Value is also 200 // Evaluated for control flow and side effects. Value is also
194 // needed if false. 201 // needed if false.
195 kTestValue 202 kTestValue
196 }; 203 };
197 204
198 Expression() 205 Expression()
199 : bitfields_(0), 206 : bitfields_(0),
200 def_(NULL), 207 def_(NULL),
201 defined_vars_(NULL) {} 208 defined_vars_(NULL) {}
202 209
210 explicit Expression(Expression* other);
211
203 virtual Expression* AsExpression() { return this; } 212 virtual Expression* AsExpression() { return this; }
204 213
205 virtual bool IsValidLeftHandSide() { return false; } 214 virtual bool IsValidLeftHandSide() { return false; }
206 215
207 virtual Variable* AssignedVar() { return NULL; } 216 virtual Variable* AssignedVar() { return NULL; }
208 217
209 // Symbols that cannot be parsed as array indices are considered property 218 // Symbols that cannot be parsed as array indices are considered property
210 // names. We do not treat symbols that can be array indexes as property 219 // names. We do not treat symbols that can be array indexes as property
211 // names because [] for string objects is handled only by keyed ICs. 220 // names because [] for string objects is handled only by keyed ICs.
212 virtual bool IsPropertyName() { return false; } 221 virtual bool IsPropertyName() { return false; }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 270
262 // Will ToInt32 (ECMA 262-3 9.5) or ToUint32 (ECMA 262-3 9.6) 271 // Will ToInt32 (ECMA 262-3 9.5) or ToUint32 (ECMA 262-3 9.6)
263 // be applied to the value of this expression? 272 // be applied to the value of this expression?
264 // If so, we may be able to optimize the calculation of the value. 273 // If so, we may be able to optimize the calculation of the value.
265 bool to_int32() { return ToInt32Field::decode(bitfields_); } 274 bool to_int32() { return ToInt32Field::decode(bitfields_); }
266 void set_to_int32(bool to_int32) { 275 void set_to_int32(bool to_int32) {
267 bitfields_ &= ~ToInt32Field::mask(); 276 bitfields_ &= ~ToInt32Field::mask();
268 bitfields_ |= ToInt32Field::encode(to_int32); 277 bitfields_ |= ToInt32Field::encode(to_int32);
269 } 278 }
270 279
271
272 private: 280 private:
273 uint32_t bitfields_; 281 uint32_t bitfields_;
274 StaticType type_; 282 StaticType type_;
275 283
276 DefinitionInfo* def_; 284 DefinitionInfo* def_;
277 ZoneList<DefinitionInfo*>* defined_vars_; 285 ZoneList<DefinitionInfo*>* defined_vars_;
278 286
279 // Using template BitField<type, start, size>. 287 // Using template BitField<type, start, size>.
280 class SideEffectFreeField : public BitField<bool, 0, 1> {}; 288 class SideEffectFreeField : public BitField<bool, 0, 1> {};
281 class NoNegativeZeroField : public BitField<bool, 1, 1> {}; 289 class NoNegativeZeroField : public BitField<bool, 1, 1> {};
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 331
324 // Testers. 332 // Testers.
325 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } 333 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; }
326 334
327 protected: 335 protected:
328 BreakableStatement(ZoneStringList* labels, Type type) 336 BreakableStatement(ZoneStringList* labels, Type type)
329 : labels_(labels), type_(type) { 337 : labels_(labels), type_(type) {
330 ASSERT(labels == NULL || labels->length() > 0); 338 ASSERT(labels == NULL || labels->length() > 0);
331 } 339 }
332 340
341 explicit BreakableStatement(BreakableStatement* other);
342
333 private: 343 private:
334 ZoneStringList* labels_; 344 ZoneStringList* labels_;
335 Type type_; 345 Type type_;
336 BreakTarget break_target_; 346 BreakTarget break_target_;
337 }; 347 };
338 348
339 349
340 class Block: public BreakableStatement { 350 class Block: public BreakableStatement {
341 public: 351 public:
342 Block(ZoneStringList* labels, int capacity, bool is_initializer_block) 352 Block(ZoneStringList* labels, int capacity, bool is_initializer_block)
343 : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY), 353 : BreakableStatement(labels, TARGET_FOR_NAMED_ONLY),
344 statements_(capacity), 354 statements_(capacity),
345 is_initializer_block_(is_initializer_block) { } 355 is_initializer_block_(is_initializer_block) { }
346 356
357 // Construct a clone initialized from the original block and
358 // a deep copy of all statements of the original block.
359 Block(Block* other, ZoneList<Statement*>* statements);
360
347 virtual void Accept(AstVisitor* v); 361 virtual void Accept(AstVisitor* v);
348 362
363 virtual Block* AsBlock() { return this; }
364
349 virtual Assignment* StatementAsSimpleAssignment() { 365 virtual Assignment* StatementAsSimpleAssignment() {
350 if (statements_.length() != 1) return NULL; 366 if (statements_.length() != 1) return NULL;
351 return statements_[0]->StatementAsSimpleAssignment(); 367 return statements_[0]->StatementAsSimpleAssignment();
352 } 368 }
353 369
354 virtual CountOperation* StatementAsCountOperation() { 370 virtual CountOperation* StatementAsCountOperation() {
355 if (statements_.length() != 1) return NULL; 371 if (statements_.length() != 1) return NULL;
356 return statements_[0]->StatementAsCountOperation(); 372 return statements_[0]->StatementAsCountOperation();
357 } 373 }
358 374
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 FunctionLiteral* fun_; 406 FunctionLiteral* fun_;
391 }; 407 };
392 408
393 409
394 class IterationStatement: public BreakableStatement { 410 class IterationStatement: public BreakableStatement {
395 public: 411 public:
396 // Type testing & conversion. 412 // Type testing & conversion.
397 virtual IterationStatement* AsIterationStatement() { return this; } 413 virtual IterationStatement* AsIterationStatement() { return this; }
398 414
399 Statement* body() const { return body_; } 415 Statement* body() const { return body_; }
416 void set_body(Statement* stmt) { body_ = stmt; }
400 417
401 // Code generation 418 // Code generation
402 BreakTarget* continue_target() { return &continue_target_; } 419 BreakTarget* continue_target() { return &continue_target_; }
403 420
404 protected: 421 protected:
405 explicit IterationStatement(ZoneStringList* labels) 422 explicit IterationStatement(ZoneStringList* labels)
406 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { } 423 : BreakableStatement(labels, TARGET_FOR_ANONYMOUS), body_(NULL) { }
407 424
425 // Construct a clone initialized from original and
426 // a deep copy of the original body.
427 IterationStatement(IterationStatement* other, Statement* body);
428
408 void Initialize(Statement* body) { 429 void Initialize(Statement* body) {
409 body_ = body; 430 body_ = body;
410 } 431 }
411 432
412 private: 433 private:
413 Statement* body_; 434 Statement* body_;
414 BreakTarget continue_target_; 435 BreakTarget continue_target_;
415 }; 436 };
416 437
417 438
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 492
472 493
473 class ForStatement: public IterationStatement { 494 class ForStatement: public IterationStatement {
474 public: 495 public:
475 explicit ForStatement(ZoneStringList* labels) 496 explicit ForStatement(ZoneStringList* labels)
476 : IterationStatement(labels), 497 : IterationStatement(labels),
477 init_(NULL), 498 init_(NULL),
478 cond_(NULL), 499 cond_(NULL),
479 next_(NULL), 500 next_(NULL),
480 may_have_function_literal_(true), 501 may_have_function_literal_(true),
481 loop_variable_(NULL) {} 502 loop_variable_(NULL),
503 peel_this_loop_(false) {}
504
505 // Construct a for-statement initialized from another for-statement
506 // and deep copies of all parts of the original statement.
507 ForStatement(ForStatement* other,
508 Statement* init,
509 Expression* cond,
510 Statement* next,
511 Statement* body);
512
513 virtual ForStatement* AsForStatement() { return this; }
482 514
483 void Initialize(Statement* init, 515 void Initialize(Statement* init,
484 Expression* cond, 516 Expression* cond,
485 Statement* next, 517 Statement* next,
486 Statement* body) { 518 Statement* body) {
487 IterationStatement::Initialize(body); 519 IterationStatement::Initialize(body);
488 init_ = init; 520 init_ = init;
489 cond_ = cond; 521 cond_ = cond;
490 next_ = next; 522 next_ = next;
491 } 523 }
492 524
493 virtual void Accept(AstVisitor* v); 525 virtual void Accept(AstVisitor* v);
494 526
495 Statement* init() const { return init_; } 527 Statement* init() const { return init_; }
528 void set_init(Statement* stmt) { init_ = stmt; }
496 Expression* cond() const { return cond_; } 529 Expression* cond() const { return cond_; }
530 void set_cond(Expression* expr) { cond_ = expr; }
497 Statement* next() const { return next_; } 531 Statement* next() const { return next_; }
532 void set_next(Statement* stmt) { next_ = stmt; }
498 bool may_have_function_literal() const { 533 bool may_have_function_literal() const {
499 return may_have_function_literal_; 534 return may_have_function_literal_;
500 } 535 }
501 536
502 bool is_fast_smi_loop() { return loop_variable_ != NULL; } 537 bool is_fast_smi_loop() { return loop_variable_ != NULL; }
503 Variable* loop_variable() { return loop_variable_; } 538 Variable* loop_variable() { return loop_variable_; }
504 void set_loop_variable(Variable* var) { loop_variable_ = var; } 539 void set_loop_variable(Variable* var) { loop_variable_ = var; }
505 540
541 bool peel_this_loop() { return peel_this_loop_; }
542 void set_peel_this_loop(bool b) { peel_this_loop_ = b; }
543
506 private: 544 private:
507 Statement* init_; 545 Statement* init_;
508 Expression* cond_; 546 Expression* cond_;
509 Statement* next_; 547 Statement* next_;
510 // True if there is a function literal subexpression in the condition. 548 // True if there is a function literal subexpression in the condition.
511 bool may_have_function_literal_; 549 bool may_have_function_literal_;
512 Variable* loop_variable_; 550 Variable* loop_variable_;
551 bool peel_this_loop_;
513 552
514 friend class AstOptimizer; 553 friend class AstOptimizer;
515 }; 554 };
516 555
517 556
518 class ForInStatement: public IterationStatement { 557 class ForInStatement: public IterationStatement {
519 public: 558 public:
520 explicit ForInStatement(ZoneStringList* labels) 559 explicit ForInStatement(ZoneStringList* labels)
521 : IterationStatement(labels), each_(NULL), enumerable_(NULL) { } 560 : IterationStatement(labels), each_(NULL), enumerable_(NULL) { }
522 561
(...skipping 12 matching lines...) Expand all
535 Expression* each_; 574 Expression* each_;
536 Expression* enumerable_; 575 Expression* enumerable_;
537 }; 576 };
538 577
539 578
540 class ExpressionStatement: public Statement { 579 class ExpressionStatement: public Statement {
541 public: 580 public:
542 explicit ExpressionStatement(Expression* expression) 581 explicit ExpressionStatement(Expression* expression)
543 : expression_(expression) { } 582 : expression_(expression) { }
544 583
584 // Construct an expression statement initialized from another
585 // expression statement and a deep copy of the original expression.
586 ExpressionStatement(ExpressionStatement* other, Expression* expression);
587
545 virtual void Accept(AstVisitor* v); 588 virtual void Accept(AstVisitor* v);
546 589
547 // Type testing & conversion. 590 // Type testing & conversion.
548 virtual ExpressionStatement* AsExpressionStatement() { return this; } 591 virtual ExpressionStatement* AsExpressionStatement() { return this; }
549 592
550 virtual Assignment* StatementAsSimpleAssignment(); 593 virtual Assignment* StatementAsSimpleAssignment();
551 virtual CountOperation* StatementAsCountOperation(); 594 virtual CountOperation* StatementAsCountOperation();
552 595
553 void set_expression(Expression* e) { expression_ = e; } 596 void set_expression(Expression* e) { expression_ = e; }
554 Expression* expression() { return expression_; } 597 Expression* expression() { return expression_; }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 // given if-statement has a then- or an else-part containing code. 720 // given if-statement has a then- or an else-part containing code.
678 class IfStatement: public Statement { 721 class IfStatement: public Statement {
679 public: 722 public:
680 IfStatement(Expression* condition, 723 IfStatement(Expression* condition,
681 Statement* then_statement, 724 Statement* then_statement,
682 Statement* else_statement) 725 Statement* else_statement)
683 : condition_(condition), 726 : condition_(condition),
684 then_statement_(then_statement), 727 then_statement_(then_statement),
685 else_statement_(else_statement) { } 728 else_statement_(else_statement) { }
686 729
730 // Construct an if-statement initialized from another if-statement
731 // and deep copies of all parts of the original.
732 IfStatement(IfStatement* other,
733 Expression* condition,
734 Statement* then_statement,
735 Statement* else_statement);
736
687 virtual void Accept(AstVisitor* v); 737 virtual void Accept(AstVisitor* v);
688 738
689 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } 739 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
690 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } 740 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
691 741
692 Expression* condition() const { return condition_; } 742 Expression* condition() const { return condition_; }
693 Statement* then_statement() const { return then_statement_; } 743 Statement* then_statement() const { return then_statement_; }
744 void set_then_statement(Statement* stmt) { then_statement_ = stmt; }
694 Statement* else_statement() const { return else_statement_; } 745 Statement* else_statement() const { return else_statement_; }
746 void set_else_statement(Statement* stmt) { else_statement_ = stmt; }
695 747
696 private: 748 private:
697 Expression* condition_; 749 Expression* condition_;
698 Statement* then_statement_; 750 Statement* then_statement_;
699 Statement* else_statement_; 751 Statement* else_statement_;
700 }; 752 };
701 753
702 754
703 // NOTE: TargetCollectors are represented as nodes to fit in the target 755 // NOTE: TargetCollectors are represented as nodes to fit in the target
704 // stack in the compiler; this should probably be reworked. 756 // stack in the compiler; this should probably be reworked.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 831
780 832
781 class DebuggerStatement: public Statement { 833 class DebuggerStatement: public Statement {
782 public: 834 public:
783 virtual void Accept(AstVisitor* v); 835 virtual void Accept(AstVisitor* v);
784 }; 836 };
785 837
786 838
787 class EmptyStatement: public Statement { 839 class EmptyStatement: public Statement {
788 public: 840 public:
841 EmptyStatement() {}
842
843 explicit EmptyStatement(EmptyStatement* other);
844
789 virtual void Accept(AstVisitor* v); 845 virtual void Accept(AstVisitor* v);
790 846
791 // Type testing & conversion. 847 // Type testing & conversion.
792 virtual EmptyStatement* AsEmptyStatement() { return this; } 848 virtual EmptyStatement* AsEmptyStatement() { return this; }
793 }; 849 };
794 850
795 851
796 class Literal: public Expression { 852 class Literal: public Expression {
797 public: 853 public:
798 explicit Literal(Handle<Object> handle) : handle_(handle) { } 854 explicit Literal(Handle<Object> handle) : handle_(handle) { }
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 class Property: public Expression { 1193 class Property: public Expression {
1138 public: 1194 public:
1139 // Synthetic properties are property lookups introduced by the system, 1195 // Synthetic properties are property lookups introduced by the system,
1140 // to objects that aren't visible to the user. Function calls to synthetic 1196 // to objects that aren't visible to the user. Function calls to synthetic
1141 // properties should use the global object as receiver, not the base object 1197 // properties should use the global object as receiver, not the base object
1142 // of the resolved Reference. 1198 // of the resolved Reference.
1143 enum Type { NORMAL, SYNTHETIC }; 1199 enum Type { NORMAL, SYNTHETIC };
1144 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) 1200 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL)
1145 : obj_(obj), key_(key), pos_(pos), type_(type) { } 1201 : obj_(obj), key_(key), pos_(pos), type_(type) { }
1146 1202
1203 Property(Property* other, Expression* obj, Expression* key);
1204
1147 virtual void Accept(AstVisitor* v); 1205 virtual void Accept(AstVisitor* v);
1148 1206
1149 // Type testing & conversion 1207 // Type testing & conversion
1150 virtual Property* AsProperty() { return this; } 1208 virtual Property* AsProperty() { return this; }
1151 1209
1152 virtual bool IsValidLeftHandSide() { return true; } 1210 virtual bool IsValidLeftHandSide() { return true; }
1153 1211
1154 virtual bool IsPrimitive(); 1212 virtual bool IsPrimitive();
1155 1213
1156 Expression* obj() const { return obj_; } 1214 Expression* obj() const { return obj_; }
(...skipping 14 matching lines...) Expand all
1171 // Dummy property used during preparsing. 1229 // Dummy property used during preparsing.
1172 static Property this_property_; 1230 static Property this_property_;
1173 }; 1231 };
1174 1232
1175 1233
1176 class Call: public Expression { 1234 class Call: public Expression {
1177 public: 1235 public:
1178 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1236 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1179 : expression_(expression), arguments_(arguments), pos_(pos) { } 1237 : expression_(expression), arguments_(arguments), pos_(pos) { }
1180 1238
1239 Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments);
1240
1181 virtual void Accept(AstVisitor* v); 1241 virtual void Accept(AstVisitor* v);
1182 1242
1183 // Type testing and conversion. 1243 // Type testing and conversion.
1184 virtual Call* AsCall() { return this; } 1244 virtual Call* AsCall() { return this; }
1185 1245
1186 virtual bool IsPrimitive(); 1246 virtual bool IsPrimitive();
1187 1247
1188 Expression* expression() const { return expression_; } 1248 Expression* expression() const { return expression_; }
1189 ZoneList<Expression*>* arguments() const { return arguments_; } 1249 ZoneList<Expression*>* arguments() const { return arguments_; }
1190 int position() { return pos_; } 1250 int position() { return pos_; }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 }; 1307 };
1248 1308
1249 1309
1250 class UnaryOperation: public Expression { 1310 class UnaryOperation: public Expression {
1251 public: 1311 public:
1252 UnaryOperation(Token::Value op, Expression* expression) 1312 UnaryOperation(Token::Value op, Expression* expression)
1253 : op_(op), expression_(expression) { 1313 : op_(op), expression_(expression) {
1254 ASSERT(Token::IsUnaryOp(op)); 1314 ASSERT(Token::IsUnaryOp(op));
1255 } 1315 }
1256 1316
1317 UnaryOperation(UnaryOperation* other, Expression* expression);
1318
1257 virtual void Accept(AstVisitor* v); 1319 virtual void Accept(AstVisitor* v);
1258 1320
1259 // Type testing & conversion 1321 // Type testing & conversion
1260 virtual UnaryOperation* AsUnaryOperation() { return this; } 1322 virtual UnaryOperation* AsUnaryOperation() { return this; }
1261 1323
1262 virtual bool IsPrimitive(); 1324 virtual bool IsPrimitive();
1263 1325
1264 Token::Value op() const { return op_; } 1326 Token::Value op() const { return op_; }
1265 Expression* expression() const { return expression_; } 1327 Expression* expression() const { return expression_; }
1266 1328
1267 private: 1329 private:
1268 Token::Value op_; 1330 Token::Value op_;
1269 Expression* expression_; 1331 Expression* expression_;
1270 }; 1332 };
1271 1333
1272 1334
1273 class BinaryOperation: public Expression { 1335 class BinaryOperation: public Expression {
1274 public: 1336 public:
1275 BinaryOperation(Token::Value op, Expression* left, Expression* right) 1337 BinaryOperation(Token::Value op, Expression* left, Expression* right)
1276 : op_(op), left_(left), right_(right) { 1338 : op_(op), left_(left), right_(right) {
1277 ASSERT(Token::IsBinaryOp(op)); 1339 ASSERT(Token::IsBinaryOp(op));
1278 } 1340 }
1279 1341
1342 BinaryOperation(BinaryOperation* other, Expression* left, Expression* right);
1343
1280 virtual void Accept(AstVisitor* v); 1344 virtual void Accept(AstVisitor* v);
1281 1345
1282 // Type testing & conversion 1346 // Type testing & conversion
1283 virtual BinaryOperation* AsBinaryOperation() { return this; } 1347 virtual BinaryOperation* AsBinaryOperation() { return this; }
1284 1348
1285 virtual bool IsPrimitive(); 1349 virtual bool IsPrimitive();
1286 1350
1287 // True iff the result can be safely overwritten (to avoid allocation). 1351 // True iff the result can be safely overwritten (to avoid allocation).
1288 // False for operations that can return one of their operands. 1352 // False for operations that can return one of their operands.
1289 bool ResultOverwriteAllowed() { 1353 bool ResultOverwriteAllowed() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 }; 1385 };
1322 1386
1323 1387
1324 class CountOperation: public Expression { 1388 class CountOperation: public Expression {
1325 public: 1389 public:
1326 CountOperation(bool is_prefix, Token::Value op, Expression* expression) 1390 CountOperation(bool is_prefix, Token::Value op, Expression* expression)
1327 : is_prefix_(is_prefix), op_(op), expression_(expression) { 1391 : is_prefix_(is_prefix), op_(op), expression_(expression) {
1328 ASSERT(Token::IsCountOp(op)); 1392 ASSERT(Token::IsCountOp(op));
1329 } 1393 }
1330 1394
1395 CountOperation(CountOperation* other, Expression* expression);
1396
1331 virtual void Accept(AstVisitor* v); 1397 virtual void Accept(AstVisitor* v);
1332 1398
1333 virtual CountOperation* AsCountOperation() { return this; } 1399 virtual CountOperation* AsCountOperation() { return this; }
1334 1400
1335 virtual Variable* AssignedVar() { 1401 virtual Variable* AssignedVar() {
1336 return expression()->AsVariableProxy()->AsVariable(); 1402 return expression()->AsVariableProxy()->AsVariable();
1337 } 1403 }
1338 1404
1339 virtual bool IsPrimitive(); 1405 virtual bool IsPrimitive();
1340 1406
(...skipping 14 matching lines...) Expand all
1355 }; 1421 };
1356 1422
1357 1423
1358 class CompareOperation: public Expression { 1424 class CompareOperation: public Expression {
1359 public: 1425 public:
1360 CompareOperation(Token::Value op, Expression* left, Expression* right) 1426 CompareOperation(Token::Value op, Expression* left, Expression* right)
1361 : op_(op), left_(left), right_(right), is_for_loop_condition_(false) { 1427 : op_(op), left_(left), right_(right), is_for_loop_condition_(false) {
1362 ASSERT(Token::IsCompareOp(op)); 1428 ASSERT(Token::IsCompareOp(op));
1363 } 1429 }
1364 1430
1431 CompareOperation(CompareOperation* other,
1432 Expression* left,
1433 Expression* right);
1434
1365 virtual void Accept(AstVisitor* v); 1435 virtual void Accept(AstVisitor* v);
1366 1436
1367 virtual bool IsPrimitive(); 1437 virtual bool IsPrimitive();
1368 1438
1369 Token::Value op() const { return op_; } 1439 Token::Value op() const { return op_; }
1370 Expression* left() const { return left_; } 1440 Expression* left() const { return left_; }
1371 Expression* right() const { return right_; } 1441 Expression* right() const { return right_; }
1372 1442
1373 // Accessors for flag whether this compare operation is hanging of a for loop. 1443 // Accessors for flag whether this compare operation is hanging of a for loop.
1374 bool is_for_loop_condition() const { return is_for_loop_condition_; } 1444 bool is_for_loop_condition() const { return is_for_loop_condition_; }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 1480
1411 1481
1412 class Assignment: public Expression { 1482 class Assignment: public Expression {
1413 public: 1483 public:
1414 Assignment(Token::Value op, Expression* target, Expression* value, int pos) 1484 Assignment(Token::Value op, Expression* target, Expression* value, int pos)
1415 : op_(op), target_(target), value_(value), pos_(pos), 1485 : op_(op), target_(target), value_(value), pos_(pos),
1416 block_start_(false), block_end_(false) { 1486 block_start_(false), block_end_(false) {
1417 ASSERT(Token::IsAssignmentOp(op)); 1487 ASSERT(Token::IsAssignmentOp(op));
1418 } 1488 }
1419 1489
1490 Assignment(Assignment* other, Expression* target, Expression* value);
1491
1420 virtual void Accept(AstVisitor* v); 1492 virtual void Accept(AstVisitor* v);
1421 virtual Assignment* AsAssignment() { return this; } 1493 virtual Assignment* AsAssignment() { return this; }
1422 1494
1423 virtual bool IsPrimitive(); 1495 virtual bool IsPrimitive();
1424 1496
1425 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } 1497 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
1426 1498
1427 virtual Variable* AssignedVar() { 1499 virtual Variable* AssignedVar() {
1428 return target()->AsVariableProxy()->AsVariable(); 1500 return target()->AsVariableProxy()->AsVariable();
1429 } 1501 }
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1985 #define DEF_VISIT(type) \ 2057 #define DEF_VISIT(type) \
1986 virtual void Visit##type(type* node) = 0; 2058 virtual void Visit##type(type* node) = 0;
1987 AST_NODE_LIST(DEF_VISIT) 2059 AST_NODE_LIST(DEF_VISIT)
1988 #undef DEF_VISIT 2060 #undef DEF_VISIT
1989 2061
1990 private: 2062 private:
1991 bool stack_overflow_; 2063 bool stack_overflow_;
1992 }; 2064 };
1993 2065
1994 2066
2067 class CopyAstVisitor : public AstVisitor {
2068 public:
2069 Expression* DeepCopyExpr(Expression* expr);
2070
2071 Statement* DeepCopyStmt(Statement* stmt);
2072
2073 private:
2074 ZoneList<Expression*>* DeepCopyExprList(ZoneList<Expression*>* expressions);
2075
2076 ZoneList<Statement*>* DeepCopyStmtList(ZoneList<Statement*>* statements);
2077
2078 // AST node visit functions.
2079 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
2080 AST_NODE_LIST(DECLARE_VISIT)
2081 #undef DECLARE_VISIT
2082
2083 // Holds the result of copying an expression.
2084 Expression* expr_;
2085 // Holds the result of copying a statement.
2086 Statement* stmt_;
2087 };
2088
1995 } } // namespace v8::internal 2089 } } // namespace v8::internal
1996 2090
1997 #endif // V8_AST_H_ 2091 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698