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

Side by Side Diff: src/ast.h

Issue 3146037: Cleanup the AST code by removing unused parts and get rid of the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 V(Assignment) \ 85 V(Assignment) \
86 V(Throw) \ 86 V(Throw) \
87 V(Property) \ 87 V(Property) \
88 V(Call) \ 88 V(Call) \
89 V(CallNew) \ 89 V(CallNew) \
90 V(CallRuntime) \ 90 V(CallRuntime) \
91 V(UnaryOperation) \ 91 V(UnaryOperation) \
92 V(CountOperation) \ 92 V(CountOperation) \
93 V(BinaryOperation) \ 93 V(BinaryOperation) \
94 V(CompareOperation) \ 94 V(CompareOperation) \
95 V(CompareToNull) \
95 V(ThisFunction) 96 V(ThisFunction)
96 97
97 #define AST_NODE_LIST(V) \ 98 #define AST_NODE_LIST(V) \
98 V(Declaration) \ 99 V(Declaration) \
99 STATEMENT_NODE_LIST(V) \ 100 STATEMENT_NODE_LIST(V) \
100 EXPRESSION_NODE_LIST(V) 101 EXPRESSION_NODE_LIST(V)
101 102
102 // Forward declarations 103 // Forward declarations
103 class TargetCollector; 104 class TargetCollector;
104 class MaterializedLiteral; 105 class MaterializedLiteral;
105 class DefinitionInfo; 106 class DefinitionInfo;
106 class BitVector; 107 class BitVector;
107 108
108 #define DEF_FORWARD_DECLARATION(type) class type; 109 #define DEF_FORWARD_DECLARATION(type) class type;
109 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 110 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
110 #undef DEF_FORWARD_DECLARATION 111 #undef DEF_FORWARD_DECLARATION
111 112
112 113
113 // Typedef only introduced to avoid unreadable code. 114 // Typedef only introduced to avoid unreadable code.
114 // Please do appreciate the required space in "> >". 115 // Please do appreciate the required space in "> >".
115 typedef ZoneList<Handle<String> > ZoneStringList; 116 typedef ZoneList<Handle<String> > ZoneStringList;
116 typedef ZoneList<Handle<Object> > ZoneObjectList; 117 typedef ZoneList<Handle<Object> > ZoneObjectList;
117 118
118 119
119 class AstNode: public ZoneObject { 120 class AstNode: public ZoneObject {
120 public: 121 public:
121 static const int kNoNumber = -1;
122
123 AstNode() : num_(kNoNumber) {}
124
125 explicit AstNode(AstNode* other);
126
127 virtual ~AstNode() { } 122 virtual ~AstNode() { }
128 virtual void Accept(AstVisitor* v) = 0; 123 virtual void Accept(AstVisitor* v) = 0;
129 124
130 // Type testing & conversion. 125 // Type testing & conversion.
131 virtual Statement* AsStatement() { return NULL; } 126 virtual Statement* AsStatement() { return NULL; }
132 virtual Block* AsBlock() { return NULL; } 127 virtual Block* AsBlock() { return NULL; }
133 virtual ExpressionStatement* AsExpressionStatement() { return NULL; } 128 virtual ExpressionStatement* AsExpressionStatement() { return NULL; }
134 virtual EmptyStatement* AsEmptyStatement() { return NULL; } 129 virtual EmptyStatement* AsEmptyStatement() { return NULL; }
135 virtual Expression* AsExpression() { return NULL; } 130 virtual Expression* AsExpression() { return NULL; }
136 virtual Literal* AsLiteral() { return NULL; } 131 virtual Literal* AsLiteral() { return NULL; }
137 virtual Slot* AsSlot() { return NULL; } 132 virtual Slot* AsSlot() { return NULL; }
138 virtual VariableProxy* AsVariableProxy() { return NULL; } 133 virtual VariableProxy* AsVariableProxy() { return NULL; }
139 virtual Property* AsProperty() { return NULL; } 134 virtual Property* AsProperty() { return NULL; }
140 virtual Call* AsCall() { return NULL; } 135 virtual Call* AsCall() { return NULL; }
141 virtual TargetCollector* AsTargetCollector() { return NULL; } 136 virtual TargetCollector* AsTargetCollector() { return NULL; }
142 virtual BreakableStatement* AsBreakableStatement() { return NULL; } 137 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
143 virtual IterationStatement* AsIterationStatement() { return NULL; } 138 virtual IterationStatement* AsIterationStatement() { return NULL; }
144 virtual ForStatement* AsForStatement() { return NULL; } 139 virtual ForStatement* AsForStatement() { return NULL; }
145 virtual UnaryOperation* AsUnaryOperation() { return NULL; } 140 virtual UnaryOperation* AsUnaryOperation() { return NULL; }
146 virtual CountOperation* AsCountOperation() { return NULL; } 141 virtual CountOperation* AsCountOperation() { return NULL; }
147 virtual BinaryOperation* AsBinaryOperation() { return NULL; } 142 virtual BinaryOperation* AsBinaryOperation() { return NULL; }
148 virtual Assignment* AsAssignment() { return NULL; } 143 virtual Assignment* AsAssignment() { return NULL; }
149 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; } 144 virtual FunctionLiteral* AsFunctionLiteral() { return NULL; }
150 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } 145 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
151 virtual ObjectLiteral* AsObjectLiteral() { return NULL; } 146 virtual ObjectLiteral* AsObjectLiteral() { return NULL; }
152 virtual ArrayLiteral* AsArrayLiteral() { return NULL; } 147 virtual ArrayLiteral* AsArrayLiteral() { return NULL; }
153 virtual CompareOperation* AsCompareOperation() { return NULL; } 148 virtual CompareOperation* AsCompareOperation() { return NULL; }
154
155 // True if the AST node is critical (its execution is needed or externally
156 // visible in some way).
157 virtual bool IsCritical() {
158 UNREACHABLE();
159 return true;
160 }
161
162 int num() { return num_; }
163 void set_num(int n) { num_ = n; }
164
165 private:
166 // Support for ast node numbering.
167 int num_;
168 }; 149 };
169 150
170 151
171 class Statement: public AstNode { 152 class Statement: public AstNode {
172 public: 153 public:
173 Statement() : statement_pos_(RelocInfo::kNoPosition) {} 154 Statement() : statement_pos_(RelocInfo::kNoPosition) {}
174 155
175 explicit Statement(Statement* other);
176
177 virtual Statement* AsStatement() { return this; } 156 virtual Statement* AsStatement() { return this; }
178 virtual ReturnStatement* AsReturnStatement() { return NULL; } 157 virtual ReturnStatement* AsReturnStatement() { return NULL; }
179 158
180 virtual Assignment* StatementAsSimpleAssignment() { return NULL; } 159 virtual Assignment* StatementAsSimpleAssignment() { return NULL; }
181 virtual CountOperation* StatementAsCountOperation() { return NULL; } 160 virtual CountOperation* StatementAsCountOperation() { return NULL; }
182 161
183 bool IsEmpty() { return AsEmptyStatement() != NULL; } 162 bool IsEmpty() { return AsEmptyStatement() != NULL; }
184 163
185 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } 164 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
186 int statement_pos() const { return statement_pos_; } 165 int statement_pos() const { return statement_pos_; }
(...skipping 12 matching lines...) Expand all
199 // Evaluated for its side effects. 178 // Evaluated for its side effects.
200 kEffect, 179 kEffect,
201 // Evaluated for its value (and side effects). 180 // Evaluated for its value (and side effects).
202 kValue, 181 kValue,
203 // Evaluated for control flow (and side effects). 182 // Evaluated for control flow (and side effects).
204 kTest 183 kTest
205 }; 184 };
206 185
207 Expression() : bitfields_(0) {} 186 Expression() : bitfields_(0) {}
208 187
209 explicit Expression(Expression* other);
210
211 virtual Expression* AsExpression() { return this; } 188 virtual Expression* AsExpression() { return this; }
212 189
190 virtual bool IsTrivial() { return false; }
213 virtual bool IsValidLeftHandSide() { return false; } 191 virtual bool IsValidLeftHandSide() { return false; }
214 192
215 virtual Variable* AssignedVariable() { return NULL; }
216
217 // Symbols that cannot be parsed as array indices are considered property 193 // Symbols that cannot be parsed as array indices are considered property
218 // names. We do not treat symbols that can be array indexes as property 194 // names. We do not treat symbols that can be array indexes as property
219 // names because [] for string objects is handled only by keyed ICs. 195 // names because [] for string objects is handled only by keyed ICs.
220 virtual bool IsPropertyName() { return false; } 196 virtual bool IsPropertyName() { return false; }
221 197
222 // True if the expression does not have (evaluated) subexpressions.
223 // Function literals are leaves because their subexpressions are not
224 // evaluated.
225 virtual bool IsLeaf() { return false; }
226
227 // True if the expression has no side effects and is safe to
228 // evaluate out of order.
229 virtual bool IsTrivial() { return false; }
230
231 // True if the expression always has one of the non-Object JS types
232 // (Undefined, Null, Boolean, String, or Number).
233 virtual bool IsPrimitive() = 0;
234
235 // Mark the expression as being compiled as an expression 198 // Mark the expression as being compiled as an expression
236 // statement. This is used to transform postfix increments to 199 // statement. This is used to transform postfix increments to
237 // (faster) prefix increments. 200 // (faster) prefix increments.
238 virtual void MarkAsStatement() { /* do nothing */ } 201 virtual void MarkAsStatement() { /* do nothing */ }
239 202
240 // Static type information for this expression. 203 // Static type information for this expression.
241 StaticType* type() { return &type_; } 204 StaticType* type() { return &type_; }
242 205
243 // True if the expression is a loop condition. 206 // True if the expression is a loop condition.
244 bool is_loop_condition() const { 207 bool is_loop_condition() const {
245 return LoopConditionField::decode(bitfields_); 208 return LoopConditionField::decode(bitfields_);
246 } 209 }
247 void set_is_loop_condition(bool flag) { 210 void set_is_loop_condition(bool flag) {
248 bitfields_ = (bitfields_ & ~LoopConditionField::mask()) | 211 bitfields_ = (bitfields_ & ~LoopConditionField::mask()) |
249 LoopConditionField::encode(flag); 212 LoopConditionField::encode(flag);
250 } 213 }
251 214
252 // The value of the expression is guaranteed to be a smi, because the 215 // The value of the expression is guaranteed to be a smi, because the
253 // top operation is a bit operation with a mask, or a shift. 216 // top operation is a bit operation with a mask, or a shift.
254 bool GuaranteedSmiResult(); 217 bool GuaranteedSmiResult();
255 218
256 // AST analysis results 219 // AST analysis results.
220 void CopyAnalysisResultsFrom(Expression* other);
257 221
258 // True if the expression rooted at this node can be compiled by the 222 // True if the expression rooted at this node can be compiled by the
259 // side-effect free compiler. 223 // side-effect free compiler.
260 bool side_effect_free() { return SideEffectFreeField::decode(bitfields_); } 224 bool side_effect_free() { return SideEffectFreeField::decode(bitfields_); }
261 void set_side_effect_free(bool is_side_effect_free) { 225 void set_side_effect_free(bool is_side_effect_free) {
262 bitfields_ &= ~SideEffectFreeField::mask(); 226 bitfields_ &= ~SideEffectFreeField::mask();
263 bitfields_ |= SideEffectFreeField::encode(is_side_effect_free); 227 bitfields_ |= SideEffectFreeField::encode(is_side_effect_free);
264 } 228 }
265 229
266 // Will the use of this expression treat -0 the same as 0 in all cases? 230 // Will the use of this expression treat -0 the same as 0 in all cases?
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 * A sentinel used during pre parsing that represents some expression 271 * A sentinel used during pre parsing that represents some expression
308 * that is a valid left hand side without having to actually build 272 * that is a valid left hand side without having to actually build
309 * the expression. 273 * the expression.
310 */ 274 */
311 class ValidLeftHandSideSentinel: public Expression { 275 class ValidLeftHandSideSentinel: public Expression {
312 public: 276 public:
313 virtual bool IsValidLeftHandSide() { return true; } 277 virtual bool IsValidLeftHandSide() { return true; }
314 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } 278 virtual void Accept(AstVisitor* v) { UNREACHABLE(); }
315 static ValidLeftHandSideSentinel* instance() { return &instance_; } 279 static ValidLeftHandSideSentinel* instance() { return &instance_; }
316 280
317 virtual bool IsPrimitive() {
318 UNREACHABLE();
319 return false;
320 }
321
322 private: 281 private:
323 static ValidLeftHandSideSentinel instance_; 282 static ValidLeftHandSideSentinel instance_;
324 }; 283 };
325 284
326 285
327 class BreakableStatement: public Statement { 286 class BreakableStatement: public Statement {
328 public: 287 public:
329 enum Type { 288 enum Type {
330 TARGET_FOR_ANONYMOUS, 289 TARGET_FOR_ANONYMOUS,
331 TARGET_FOR_NAMED_ONLY 290 TARGET_FOR_NAMED_ONLY
332 }; 291 };
333 292
334 // The labels associated with this statement. May be NULL; 293 // The labels associated with this statement. May be NULL;
335 // if it is != NULL, guaranteed to contain at least one entry. 294 // if it is != NULL, guaranteed to contain at least one entry.
336 ZoneStringList* labels() const { return labels_; } 295 ZoneStringList* labels() const { return labels_; }
337 296
338 // Type testing & conversion. 297 // Type testing & conversion.
339 virtual BreakableStatement* AsBreakableStatement() { return this; } 298 virtual BreakableStatement* AsBreakableStatement() { return this; }
340 299
341 // Code generation 300 // Code generation
342 BreakTarget* break_target() { return &break_target_; } 301 BreakTarget* break_target() { return &break_target_; }
343 302
344 // Testers. 303 // Testers.
345 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } 304 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; }
346 305
347 protected: 306 protected:
348 inline BreakableStatement(ZoneStringList* labels, Type type); 307 inline BreakableStatement(ZoneStringList* labels, Type type);
349 308
350 explicit BreakableStatement(BreakableStatement* other);
351
352 private: 309 private:
353 ZoneStringList* labels_; 310 ZoneStringList* labels_;
354 Type type_; 311 Type type_;
355 BreakTarget break_target_; 312 BreakTarget break_target_;
356 }; 313 };
357 314
358 315
359 class Block: public BreakableStatement { 316 class Block: public BreakableStatement {
360 public: 317 public:
361 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block); 318 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block);
362 319
363 // Construct a clone initialized from the original block and
364 // a deep copy of all statements of the original block.
365 Block(Block* other, ZoneList<Statement*>* statements);
366
367 virtual void Accept(AstVisitor* v); 320 virtual void Accept(AstVisitor* v);
368 321
369 virtual Block* AsBlock() { return this; } 322 virtual Block* AsBlock() { return this; }
370 323
371 virtual Assignment* StatementAsSimpleAssignment() { 324 virtual Assignment* StatementAsSimpleAssignment() {
372 if (statements_.length() != 1) return NULL; 325 if (statements_.length() != 1) return NULL;
373 return statements_[0]->StatementAsSimpleAssignment(); 326 return statements_[0]->StatementAsSimpleAssignment();
374 } 327 }
375 328
376 virtual CountOperation* StatementAsCountOperation() { 329 virtual CountOperation* StatementAsCountOperation() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 373
421 Statement* body() const { return body_; } 374 Statement* body() const { return body_; }
422 void set_body(Statement* stmt) { body_ = stmt; } 375 void set_body(Statement* stmt) { body_ = stmt; }
423 376
424 // Code generation 377 // Code generation
425 BreakTarget* continue_target() { return &continue_target_; } 378 BreakTarget* continue_target() { return &continue_target_; }
426 379
427 protected: 380 protected:
428 explicit inline IterationStatement(ZoneStringList* labels); 381 explicit inline IterationStatement(ZoneStringList* labels);
429 382
430 // Construct a clone initialized from original and
431 // a deep copy of the original body.
432 IterationStatement(IterationStatement* other, Statement* body);
433
434 void Initialize(Statement* body) { 383 void Initialize(Statement* body) {
435 body_ = body; 384 body_ = body;
436 } 385 }
437 386
438 private: 387 private:
439 Statement* body_; 388 Statement* body_;
440 BreakTarget continue_target_; 389 BreakTarget continue_target_;
441 }; 390 };
442 391
443 392
(...skipping 29 matching lines...) Expand all
473 IterationStatement::Initialize(body); 422 IterationStatement::Initialize(body);
474 cond_ = cond; 423 cond_ = cond;
475 } 424 }
476 425
477 virtual void Accept(AstVisitor* v); 426 virtual void Accept(AstVisitor* v);
478 427
479 Expression* cond() const { return cond_; } 428 Expression* cond() const { return cond_; }
480 bool may_have_function_literal() const { 429 bool may_have_function_literal() const {
481 return may_have_function_literal_; 430 return may_have_function_literal_;
482 } 431 }
432 void set_may_have_function_literal(bool value) {
433 may_have_function_literal_ = value;
434 }
483 435
484 private: 436 private:
485 Expression* cond_; 437 Expression* cond_;
486 // True if there is a function literal subexpression in the condition. 438 // True if there is a function literal subexpression in the condition.
487 bool may_have_function_literal_; 439 bool may_have_function_literal_;
488
489 friend class AstOptimizer;
490 }; 440 };
491 441
492 442
493 class ForStatement: public IterationStatement { 443 class ForStatement: public IterationStatement {
494 public: 444 public:
495 explicit inline ForStatement(ZoneStringList* labels); 445 explicit inline ForStatement(ZoneStringList* labels);
496 446
497 // Construct a for-statement initialized from another for-statement
498 // and deep copies of all parts of the original statement.
499 ForStatement(ForStatement* other,
500 Statement* init,
501 Expression* cond,
502 Statement* next,
503 Statement* body);
504
505 virtual ForStatement* AsForStatement() { return this; } 447 virtual ForStatement* AsForStatement() { return this; }
506 448
507 void Initialize(Statement* init, 449 void Initialize(Statement* init,
508 Expression* cond, 450 Expression* cond,
509 Statement* next, 451 Statement* next,
510 Statement* body) { 452 Statement* body) {
511 IterationStatement::Initialize(body); 453 IterationStatement::Initialize(body);
512 init_ = init; 454 init_ = init;
513 cond_ = cond; 455 cond_ = cond;
514 next_ = next; 456 next_ = next;
515 } 457 }
516 458
517 virtual void Accept(AstVisitor* v); 459 virtual void Accept(AstVisitor* v);
518 460
519 Statement* init() const { return init_; } 461 Statement* init() const { return init_; }
520 void set_init(Statement* stmt) { init_ = stmt; } 462 void set_init(Statement* stmt) { init_ = stmt; }
521 Expression* cond() const { return cond_; } 463 Expression* cond() const { return cond_; }
522 void set_cond(Expression* expr) { cond_ = expr; } 464 void set_cond(Expression* expr) { cond_ = expr; }
523 Statement* next() const { return next_; } 465 Statement* next() const { return next_; }
524 void set_next(Statement* stmt) { next_ = stmt; } 466 void set_next(Statement* stmt) { next_ = stmt; }
467
525 bool may_have_function_literal() const { 468 bool may_have_function_literal() const {
526 return may_have_function_literal_; 469 return may_have_function_literal_;
527 } 470 }
471 void set_may_have_function_literal(bool value) {
472 may_have_function_literal_ = value;
473 }
528 474
529 bool is_fast_smi_loop() { return loop_variable_ != NULL; } 475 bool is_fast_smi_loop() { return loop_variable_ != NULL; }
530 Variable* loop_variable() { return loop_variable_; } 476 Variable* loop_variable() { return loop_variable_; }
531 void set_loop_variable(Variable* var) { loop_variable_ = var; } 477 void set_loop_variable(Variable* var) { loop_variable_ = var; }
532 478
533 bool peel_this_loop() { return peel_this_loop_; }
534 void set_peel_this_loop(bool b) { peel_this_loop_ = b; }
535
536 private: 479 private:
537 Statement* init_; 480 Statement* init_;
538 Expression* cond_; 481 Expression* cond_;
539 Statement* next_; 482 Statement* next_;
540 // True if there is a function literal subexpression in the condition. 483 // True if there is a function literal subexpression in the condition.
541 bool may_have_function_literal_; 484 bool may_have_function_literal_;
542 Variable* loop_variable_; 485 Variable* loop_variable_;
543 bool peel_this_loop_;
544
545 friend class AstOptimizer;
546 }; 486 };
547 487
548 488
549 class ForInStatement: public IterationStatement { 489 class ForInStatement: public IterationStatement {
550 public: 490 public:
551 explicit inline ForInStatement(ZoneStringList* labels); 491 explicit inline ForInStatement(ZoneStringList* labels);
552 492
553 void Initialize(Expression* each, Expression* enumerable, Statement* body) { 493 void Initialize(Expression* each, Expression* enumerable, Statement* body) {
554 IterationStatement::Initialize(body); 494 IterationStatement::Initialize(body);
555 each_ = each; 495 each_ = each;
556 enumerable_ = enumerable; 496 enumerable_ = enumerable;
557 } 497 }
558 498
559 virtual void Accept(AstVisitor* v); 499 virtual void Accept(AstVisitor* v);
560 500
561 Expression* each() const { return each_; } 501 Expression* each() const { return each_; }
562 Expression* enumerable() const { return enumerable_; } 502 Expression* enumerable() const { return enumerable_; }
563 503
564 private: 504 private:
565 Expression* each_; 505 Expression* each_;
566 Expression* enumerable_; 506 Expression* enumerable_;
567 }; 507 };
568 508
569 509
570 class ExpressionStatement: public Statement { 510 class ExpressionStatement: public Statement {
571 public: 511 public:
572 explicit ExpressionStatement(Expression* expression) 512 explicit ExpressionStatement(Expression* expression)
573 : expression_(expression) { } 513 : expression_(expression) { }
574 514
575 // Construct an expression statement initialized from another
576 // expression statement and a deep copy of the original expression.
577 ExpressionStatement(ExpressionStatement* other, Expression* expression);
578
579 virtual void Accept(AstVisitor* v); 515 virtual void Accept(AstVisitor* v);
580 516
581 // Type testing & conversion. 517 // Type testing & conversion.
582 virtual ExpressionStatement* AsExpressionStatement() { return this; } 518 virtual ExpressionStatement* AsExpressionStatement() { return this; }
583 519
584 virtual Assignment* StatementAsSimpleAssignment(); 520 virtual Assignment* StatementAsSimpleAssignment();
585 virtual CountOperation* StatementAsCountOperation(); 521 virtual CountOperation* StatementAsCountOperation();
586 522
587 void set_expression(Expression* e) { expression_ = e; } 523 void set_expression(Expression* e) { expression_ = e; }
588 Expression* expression() { return expression_; } 524 Expression* expression() { return expression_; }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 // given if-statement has a then- or an else-part containing code. 644 // given if-statement has a then- or an else-part containing code.
709 class IfStatement: public Statement { 645 class IfStatement: public Statement {
710 public: 646 public:
711 IfStatement(Expression* condition, 647 IfStatement(Expression* condition,
712 Statement* then_statement, 648 Statement* then_statement,
713 Statement* else_statement) 649 Statement* else_statement)
714 : condition_(condition), 650 : condition_(condition),
715 then_statement_(then_statement), 651 then_statement_(then_statement),
716 else_statement_(else_statement) { } 652 else_statement_(else_statement) { }
717 653
718 // Construct an if-statement initialized from another if-statement
719 // and deep copies of all parts of the original.
720 IfStatement(IfStatement* other,
721 Expression* condition,
722 Statement* then_statement,
723 Statement* else_statement);
724
725 virtual void Accept(AstVisitor* v); 654 virtual void Accept(AstVisitor* v);
726 655
727 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } 656 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
728 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } 657 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
729 658
730 Expression* condition() const { return condition_; } 659 Expression* condition() const { return condition_; }
731 Statement* then_statement() const { return then_statement_; } 660 Statement* then_statement() const { return then_statement_; }
732 void set_then_statement(Statement* stmt) { then_statement_ = stmt; } 661 void set_then_statement(Statement* stmt) { then_statement_ = stmt; }
733 Statement* else_statement() const { return else_statement_; } 662 Statement* else_statement() const { return else_statement_; }
734 void set_else_statement(Statement* stmt) { else_statement_ = stmt; } 663 void set_else_statement(Statement* stmt) { else_statement_ = stmt; }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 class DebuggerStatement: public Statement { 750 class DebuggerStatement: public Statement {
822 public: 751 public:
823 virtual void Accept(AstVisitor* v); 752 virtual void Accept(AstVisitor* v);
824 }; 753 };
825 754
826 755
827 class EmptyStatement: public Statement { 756 class EmptyStatement: public Statement {
828 public: 757 public:
829 EmptyStatement() {} 758 EmptyStatement() {}
830 759
831 explicit EmptyStatement(EmptyStatement* other);
832
833 virtual void Accept(AstVisitor* v); 760 virtual void Accept(AstVisitor* v);
834 761
835 // Type testing & conversion. 762 // Type testing & conversion.
836 virtual EmptyStatement* AsEmptyStatement() { return this; } 763 virtual EmptyStatement* AsEmptyStatement() { return this; }
837 }; 764 };
838 765
839 766
840 class Literal: public Expression { 767 class Literal: public Expression {
841 public: 768 public:
842 explicit Literal(Handle<Object> handle) : handle_(handle) { } 769 explicit Literal(Handle<Object> handle) : handle_(handle) { }
843 770
844 virtual void Accept(AstVisitor* v); 771 virtual void Accept(AstVisitor* v);
772 virtual bool IsTrivial() { return true; }
845 773
846 // Type testing & conversion. 774 // Type testing & conversion.
847 virtual Literal* AsLiteral() { return this; } 775 virtual Literal* AsLiteral() { return this; }
848 776
849 // Check if this literal is identical to the other literal. 777 // Check if this literal is identical to the other literal.
850 bool IsIdenticalTo(const Literal* other) const { 778 bool IsIdenticalTo(const Literal* other) const {
851 return handle_.is_identical_to(other->handle_); 779 return handle_.is_identical_to(other->handle_);
852 } 780 }
853 781
854 virtual bool IsPropertyName() { 782 virtual bool IsPropertyName() {
855 if (handle_->IsSymbol()) { 783 if (handle_->IsSymbol()) {
856 uint32_t ignored; 784 uint32_t ignored;
857 return !String::cast(*handle_)->AsArrayIndex(&ignored); 785 return !String::cast(*handle_)->AsArrayIndex(&ignored);
858 } 786 }
859 return false; 787 return false;
860 } 788 }
861 789
862 virtual bool IsLeaf() { return true; }
863 virtual bool IsTrivial() { return true; }
864 virtual bool IsPrimitive();
865 virtual bool IsCritical();
866
867 // Identity testers. 790 // Identity testers.
868 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); } 791 bool IsNull() const { return handle_.is_identical_to(Factory::null_value()); }
869 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); } 792 bool IsTrue() const { return handle_.is_identical_to(Factory::true_value()); }
870 bool IsFalse() const { 793 bool IsFalse() const {
871 return handle_.is_identical_to(Factory::false_value()); 794 return handle_.is_identical_to(Factory::false_value());
872 } 795 }
873 796
874 Handle<Object> handle() const { return handle_; } 797 Handle<Object> handle() const { return handle_; }
875 798
876 private: 799 private:
(...skipping 26 matching lines...) Expand all
903 826
904 // An object literal has a boilerplate object that is used 827 // An object literal has a boilerplate object that is used
905 // for minimizing the work when constructing it at runtime. 828 // for minimizing the work when constructing it at runtime.
906 class ObjectLiteral: public MaterializedLiteral { 829 class ObjectLiteral: public MaterializedLiteral {
907 public: 830 public:
908 // Property is used for passing information 831 // Property is used for passing information
909 // about an object literal's properties from the parser 832 // about an object literal's properties from the parser
910 // to the code generator. 833 // to the code generator.
911 class Property: public ZoneObject { 834 class Property: public ZoneObject {
912 public: 835 public:
913
914 enum Kind { 836 enum Kind {
915 CONSTANT, // Property with constant value (compile time). 837 CONSTANT, // Property with constant value (compile time).
916 COMPUTED, // Property with computed value (execution time). 838 COMPUTED, // Property with computed value (execution time).
917 MATERIALIZED_LITERAL, // Property value is a materialized literal. 839 MATERIALIZED_LITERAL, // Property value is a materialized literal.
918 GETTER, SETTER, // Property is an accessor function. 840 GETTER, SETTER, // Property is an accessor function.
919 PROTOTYPE // Property is __proto__. 841 PROTOTYPE // Property is __proto__.
920 }; 842 };
921 843
922 Property(Literal* key, Expression* value); 844 Property(Literal* key, Expression* value);
923 Property(bool is_getter, FunctionLiteral* value); 845 Property(bool is_getter, FunctionLiteral* value);
(...skipping 17 matching lines...) Expand all
941 bool fast_elements, 863 bool fast_elements,
942 int depth) 864 int depth)
943 : MaterializedLiteral(literal_index, is_simple, depth), 865 : MaterializedLiteral(literal_index, is_simple, depth),
944 constant_properties_(constant_properties), 866 constant_properties_(constant_properties),
945 properties_(properties), 867 properties_(properties),
946 fast_elements_(fast_elements) {} 868 fast_elements_(fast_elements) {}
947 869
948 virtual ObjectLiteral* AsObjectLiteral() { return this; } 870 virtual ObjectLiteral* AsObjectLiteral() { return this; }
949 virtual void Accept(AstVisitor* v); 871 virtual void Accept(AstVisitor* v);
950 872
951 virtual bool IsLeaf() { return properties()->is_empty(); }
952
953 virtual bool IsPrimitive();
954
955 Handle<FixedArray> constant_properties() const { 873 Handle<FixedArray> constant_properties() const {
956 return constant_properties_; 874 return constant_properties_;
957 } 875 }
958 ZoneList<Property*>* properties() const { return properties_; } 876 ZoneList<Property*>* properties() const { return properties_; }
959 877
960 bool fast_elements() const { return fast_elements_; } 878 bool fast_elements() const { return fast_elements_; }
961 879
962 private: 880 private:
963 Handle<FixedArray> constant_properties_; 881 Handle<FixedArray> constant_properties_;
964 ZoneList<Property*>* properties_; 882 ZoneList<Property*>* properties_;
965 bool fast_elements_; 883 bool fast_elements_;
966 }; 884 };
967 885
968 886
969 // Node for capturing a regexp literal. 887 // Node for capturing a regexp literal.
970 class RegExpLiteral: public MaterializedLiteral { 888 class RegExpLiteral: public MaterializedLiteral {
971 public: 889 public:
972 RegExpLiteral(Handle<String> pattern, 890 RegExpLiteral(Handle<String> pattern,
973 Handle<String> flags, 891 Handle<String> flags,
974 int literal_index) 892 int literal_index)
975 : MaterializedLiteral(literal_index, false, 1), 893 : MaterializedLiteral(literal_index, false, 1),
976 pattern_(pattern), 894 pattern_(pattern),
977 flags_(flags) {} 895 flags_(flags) {}
978 896
979 virtual void Accept(AstVisitor* v); 897 virtual void Accept(AstVisitor* v);
980 898
981 virtual bool IsLeaf() { return true; }
982
983 virtual bool IsPrimitive();
984
985 Handle<String> pattern() const { return pattern_; } 899 Handle<String> pattern() const { return pattern_; }
986 Handle<String> flags() const { return flags_; } 900 Handle<String> flags() const { return flags_; }
987 901
988 private: 902 private:
989 Handle<String> pattern_; 903 Handle<String> pattern_;
990 Handle<String> flags_; 904 Handle<String> flags_;
991 }; 905 };
992 906
993 // An array literal has a literals object that is used 907 // An array literal has a literals object that is used
994 // for minimizing the work when constructing it at runtime. 908 // for minimizing the work when constructing it at runtime.
995 class ArrayLiteral: public MaterializedLiteral { 909 class ArrayLiteral: public MaterializedLiteral {
996 public: 910 public:
997 ArrayLiteral(Handle<FixedArray> constant_elements, 911 ArrayLiteral(Handle<FixedArray> constant_elements,
998 ZoneList<Expression*>* values, 912 ZoneList<Expression*>* values,
999 int literal_index, 913 int literal_index,
1000 bool is_simple, 914 bool is_simple,
1001 int depth) 915 int depth)
1002 : MaterializedLiteral(literal_index, is_simple, depth), 916 : MaterializedLiteral(literal_index, is_simple, depth),
1003 constant_elements_(constant_elements), 917 constant_elements_(constant_elements),
1004 values_(values) {} 918 values_(values) {}
1005 919
1006 virtual void Accept(AstVisitor* v); 920 virtual void Accept(AstVisitor* v);
1007 virtual ArrayLiteral* AsArrayLiteral() { return this; } 921 virtual ArrayLiteral* AsArrayLiteral() { return this; }
1008 922
1009 virtual bool IsLeaf() { return values()->is_empty(); }
1010
1011 virtual bool IsPrimitive();
1012
1013 Handle<FixedArray> constant_elements() const { return constant_elements_; } 923 Handle<FixedArray> constant_elements() const { return constant_elements_; }
1014 ZoneList<Expression*>* values() const { return values_; } 924 ZoneList<Expression*>* values() const { return values_; }
1015 925
1016 private: 926 private:
1017 Handle<FixedArray> constant_elements_; 927 Handle<FixedArray> constant_elements_;
1018 ZoneList<Expression*>* values_; 928 ZoneList<Expression*>* values_;
1019 }; 929 };
1020 930
1021 931
1022 // Node for constructing a context extension object for a catch block. 932 // Node for constructing a context extension object for a catch block.
1023 // The catch context extension object has one property, the catch 933 // The catch context extension object has one property, the catch
1024 // variable, which should be DontDelete. 934 // variable, which should be DontDelete.
1025 class CatchExtensionObject: public Expression { 935 class CatchExtensionObject: public Expression {
1026 public: 936 public:
1027 CatchExtensionObject(Literal* key, VariableProxy* value) 937 CatchExtensionObject(Literal* key, VariableProxy* value)
1028 : key_(key), value_(value) { 938 : key_(key), value_(value) {
1029 } 939 }
1030 940
1031 virtual void Accept(AstVisitor* v); 941 virtual void Accept(AstVisitor* v);
1032 942
1033 virtual bool IsPrimitive();
1034
1035 Literal* key() const { return key_; } 943 Literal* key() const { return key_; }
1036 VariableProxy* value() const { return value_; } 944 VariableProxy* value() const { return value_; }
1037 945
1038 private: 946 private:
1039 Literal* key_; 947 Literal* key_;
1040 VariableProxy* value_; 948 VariableProxy* value_;
1041 }; 949 };
1042 950
1043 951
1044 class VariableProxy: public Expression { 952 class VariableProxy: public Expression {
1045 public: 953 public:
1046 virtual void Accept(AstVisitor* v); 954 virtual void Accept(AstVisitor* v);
1047 955
1048 // Type testing & conversion 956 // Type testing & conversion
1049 virtual Property* AsProperty() { 957 virtual Property* AsProperty() {
1050 return var_ == NULL ? NULL : var_->AsProperty(); 958 return var_ == NULL ? NULL : var_->AsProperty();
1051 } 959 }
1052 virtual VariableProxy* AsVariableProxy() { return this; } 960
961 virtual VariableProxy* AsVariableProxy() {
962 return this;
963 }
1053 964
1054 Variable* AsVariable() { 965 Variable* AsVariable() {
1055 return this == NULL || var_ == NULL ? NULL : var_->AsVariable(); 966 return this == NULL || var_ == NULL ? NULL : var_->AsVariable();
1056 } 967 }
1057 968
1058 virtual bool IsValidLeftHandSide() { 969 virtual bool IsValidLeftHandSide() {
1059 return var_ == NULL ? true : var_->IsValidLeftHandSide(); 970 return var_ == NULL ? true : var_->IsValidLeftHandSide();
1060 } 971 }
1061 972
1062 virtual bool IsLeaf() { 973 virtual bool IsTrivial() {
1063 ASSERT(var_ != NULL); // Variable must be resolved. 974 // Reading from a mutable variable is a side effect, but the
1064 return var()->is_global() || var()->rewrite()->IsLeaf(); 975 // variable for 'this' is immutable.
976 return is_this_ || is_trivial_;
1065 } 977 }
1066 978
1067 // Reading from a mutable variable is a side effect, but 'this' is
1068 // immutable.
1069 virtual bool IsTrivial() { return is_trivial_; }
1070
1071 virtual bool IsPrimitive();
1072 virtual bool IsCritical();
1073
1074 void SetIsPrimitive(bool value) { is_primitive_ = value; }
1075
1076 bool IsVariable(Handle<String> n) { 979 bool IsVariable(Handle<String> n) {
1077 return !is_this() && name().is_identical_to(n); 980 return !is_this() && name().is_identical_to(n);
1078 } 981 }
1079 982
1080 bool IsArguments() { 983 bool IsArguments() {
1081 Variable* variable = AsVariable(); 984 Variable* variable = AsVariable();
1082 return (variable == NULL) ? false : variable->is_arguments(); 985 return (variable == NULL) ? false : variable->is_arguments();
1083 } 986 }
1084 987
1085 Handle<String> name() const { return name_; } 988 Handle<String> name() const { return name_; }
1086 Variable* var() const { return var_; } 989 Variable* var() const { return var_; }
1087 bool is_this() const { return is_this_; } 990 bool is_this() const { return is_this_; }
1088 bool inside_with() const { return inside_with_; } 991 bool inside_with() const { return inside_with_; }
1089 bool is_trivial() { return is_trivial_; }
1090 void set_is_trivial(bool b) { is_trivial_ = b; }
1091 992
1092 BitVector* reaching_definitions() { return reaching_definitions_; } 993 void MarkAsTrivial() { is_trivial_ = true; }
1093 void set_reaching_definitions(BitVector* rd) { reaching_definitions_ = rd; }
1094 994
1095 // Bind this proxy to the variable var. 995 // Bind this proxy to the variable var.
1096 void BindTo(Variable* var); 996 void BindTo(Variable* var);
1097 997
1098 protected: 998 protected:
1099 Handle<String> name_; 999 Handle<String> name_;
1100 Variable* var_; // resolved variable, or NULL 1000 Variable* var_; // resolved variable, or NULL
1101 bool is_this_; 1001 bool is_this_;
1102 bool inside_with_; 1002 bool inside_with_;
1103 bool is_trivial_; 1003 bool is_trivial_;
1104 BitVector* reaching_definitions_;
1105 bool is_primitive_;
1106 1004
1107 VariableProxy(Handle<String> name, bool is_this, bool inside_with); 1005 VariableProxy(Handle<String> name, bool is_this, bool inside_with);
1108 explicit VariableProxy(bool is_this); 1006 explicit VariableProxy(bool is_this);
1109 1007
1110 friend class Scope; 1008 friend class Scope;
1111 }; 1009 };
1112 1010
1113 1011
1114 class VariableProxySentinel: public VariableProxy { 1012 class VariableProxySentinel: public VariableProxy {
1115 public: 1013 public:
1116 virtual bool IsValidLeftHandSide() { return !is_this(); } 1014 virtual bool IsValidLeftHandSide() { return !is_this(); }
1117 static VariableProxySentinel* this_proxy() { return &this_proxy_; } 1015 static VariableProxySentinel* this_proxy() { return &this_proxy_; }
1118 static VariableProxySentinel* identifier_proxy() { 1016 static VariableProxySentinel* identifier_proxy() {
1119 return &identifier_proxy_; 1017 return &identifier_proxy_;
1120 } 1018 }
1121 1019
1122 virtual bool IsPrimitive() {
1123 UNREACHABLE();
1124 return false;
1125 }
1126
1127 private: 1020 private:
1128 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { } 1021 explicit VariableProxySentinel(bool is_this) : VariableProxy(is_this) { }
1129 static VariableProxySentinel this_proxy_; 1022 static VariableProxySentinel this_proxy_;
1130 static VariableProxySentinel identifier_proxy_; 1023 static VariableProxySentinel identifier_proxy_;
1131 }; 1024 };
1132 1025
1133 1026
1134 class Slot: public Expression { 1027 class Slot: public Expression {
1135 public: 1028 public:
1136 enum Type { 1029 enum Type {
(...skipping 21 matching lines...) Expand all
1158 Slot(Variable* var, Type type, int index) 1051 Slot(Variable* var, Type type, int index)
1159 : var_(var), type_(type), index_(index) { 1052 : var_(var), type_(type), index_(index) {
1160 ASSERT(var != NULL); 1053 ASSERT(var != NULL);
1161 } 1054 }
1162 1055
1163 virtual void Accept(AstVisitor* v); 1056 virtual void Accept(AstVisitor* v);
1164 1057
1165 // Type testing & conversion 1058 // Type testing & conversion
1166 virtual Slot* AsSlot() { return this; } 1059 virtual Slot* AsSlot() { return this; }
1167 1060
1168 virtual bool IsLeaf() { return true; }
1169
1170 virtual bool IsPrimitive() {
1171 UNREACHABLE();
1172 return false;
1173 }
1174
1175 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } 1061 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; }
1176 1062
1177 // Accessors 1063 // Accessors
1178 Variable* var() const { return var_; } 1064 Variable* var() const { return var_; }
1179 Type type() const { return type_; } 1065 Type type() const { return type_; }
1180 int index() const { return index_; } 1066 int index() const { return index_; }
1181 bool is_arguments() const { return var_->is_arguments(); } 1067 bool is_arguments() const { return var_->is_arguments(); }
1182 1068
1183 private: 1069 private:
1184 Variable* var_; 1070 Variable* var_;
1185 Type type_; 1071 Type type_;
1186 int index_; 1072 int index_;
1187 }; 1073 };
1188 1074
1189 1075
1190 class Property: public Expression { 1076 class Property: public Expression {
1191 public: 1077 public:
1192 // Synthetic properties are property lookups introduced by the system, 1078 // Synthetic properties are property lookups introduced by the system,
1193 // to objects that aren't visible to the user. Function calls to synthetic 1079 // to objects that aren't visible to the user. Function calls to synthetic
1194 // properties should use the global object as receiver, not the base object 1080 // properties should use the global object as receiver, not the base object
1195 // of the resolved Reference. 1081 // of the resolved Reference.
1196 enum Type { NORMAL, SYNTHETIC }; 1082 enum Type { NORMAL, SYNTHETIC };
1197 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) 1083 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL)
1198 : obj_(obj), key_(key), pos_(pos), type_(type) { } 1084 : obj_(obj), key_(key), pos_(pos), type_(type) { }
1199 1085
1200 Property(Property* other, Expression* obj, Expression* key);
1201
1202 virtual void Accept(AstVisitor* v); 1086 virtual void Accept(AstVisitor* v);
1203 1087
1204 // Type testing & conversion 1088 // Type testing & conversion
1205 virtual Property* AsProperty() { return this; } 1089 virtual Property* AsProperty() { return this; }
1206 1090
1207 virtual bool IsValidLeftHandSide() { return true; } 1091 virtual bool IsValidLeftHandSide() { return true; }
1208 1092
1209 virtual bool IsPrimitive();
1210 virtual bool IsCritical();
1211
1212 Expression* obj() const { return obj_; } 1093 Expression* obj() const { return obj_; }
1213 Expression* key() const { return key_; } 1094 Expression* key() const { return key_; }
1214 int position() const { return pos_; } 1095 int position() const { return pos_; }
1215 bool is_synthetic() const { return type_ == SYNTHETIC; } 1096 bool is_synthetic() const { return type_ == SYNTHETIC; }
1216 1097
1217 // Returns a property singleton property access on 'this'. Used 1098 // Returns a property singleton property access on 'this'. Used
1218 // during preparsing. 1099 // during preparsing.
1219 static Property* this_property() { return &this_property_; } 1100 static Property* this_property() { return &this_property_; }
1220 1101
1221 private: 1102 private:
1222 Expression* obj_; 1103 Expression* obj_;
1223 Expression* key_; 1104 Expression* key_;
1224 int pos_; 1105 int pos_;
1225 Type type_; 1106 Type type_;
1226 1107
1227 // Dummy property used during preparsing. 1108 // Dummy property used during preparsing.
1228 static Property this_property_; 1109 static Property this_property_;
1229 }; 1110 };
1230 1111
1231 1112
1232 class Call: public Expression { 1113 class Call: public Expression {
1233 public: 1114 public:
1234 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1115 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1235 : expression_(expression), arguments_(arguments), pos_(pos) { } 1116 : expression_(expression), arguments_(arguments), pos_(pos) { }
1236 1117
1237 Call(Call* other, Expression* expression, ZoneList<Expression*>* arguments);
1238
1239 virtual void Accept(AstVisitor* v); 1118 virtual void Accept(AstVisitor* v);
1240 1119
1241 // Type testing and conversion. 1120 // Type testing and conversion.
1242 virtual Call* AsCall() { return this; } 1121 virtual Call* AsCall() { return this; }
1243 1122
1244 virtual bool IsPrimitive();
1245 virtual bool IsCritical();
1246
1247 Expression* expression() const { return expression_; } 1123 Expression* expression() const { return expression_; }
1248 ZoneList<Expression*>* arguments() const { return arguments_; } 1124 ZoneList<Expression*>* arguments() const { return arguments_; }
1249 int position() { return pos_; } 1125 int position() { return pos_; }
1250 1126
1251 static Call* sentinel() { return &sentinel_; } 1127 static Call* sentinel() { return &sentinel_; }
1252 1128
1253 private: 1129 private:
1254 Expression* expression_; 1130 Expression* expression_;
1255 ZoneList<Expression*>* arguments_; 1131 ZoneList<Expression*>* arguments_;
1256 int pos_; 1132 int pos_;
1257 1133
1258 static Call sentinel_; 1134 static Call sentinel_;
1259 }; 1135 };
1260 1136
1261 1137
1262 class CallNew: public Expression { 1138 class CallNew: public Expression {
1263 public: 1139 public:
1264 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1140 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1265 : expression_(expression), arguments_(arguments), pos_(pos) { } 1141 : expression_(expression), arguments_(arguments), pos_(pos) { }
1266 1142
1267 virtual void Accept(AstVisitor* v); 1143 virtual void Accept(AstVisitor* v);
1268 1144
1269 virtual bool IsPrimitive();
1270
1271 Expression* expression() const { return expression_; } 1145 Expression* expression() const { return expression_; }
1272 ZoneList<Expression*>* arguments() const { return arguments_; } 1146 ZoneList<Expression*>* arguments() const { return arguments_; }
1273 int position() { return pos_; } 1147 int position() { return pos_; }
1274 1148
1275 private: 1149 private:
1276 Expression* expression_; 1150 Expression* expression_;
1277 ZoneList<Expression*>* arguments_; 1151 ZoneList<Expression*>* arguments_;
1278 int pos_; 1152 int pos_;
1279 }; 1153 };
1280 1154
1281 1155
1282 // The CallRuntime class does not represent any official JavaScript 1156 // The CallRuntime class does not represent any official JavaScript
1283 // language construct. Instead it is used to call a C or JS function 1157 // language construct. Instead it is used to call a C or JS function
1284 // with a set of arguments. This is used from the builtins that are 1158 // with a set of arguments. This is used from the builtins that are
1285 // implemented in JavaScript (see "v8natives.js"). 1159 // implemented in JavaScript (see "v8natives.js").
1286 class CallRuntime: public Expression { 1160 class CallRuntime: public Expression {
1287 public: 1161 public:
1288 CallRuntime(Handle<String> name, 1162 CallRuntime(Handle<String> name,
1289 Runtime::Function* function, 1163 Runtime::Function* function,
1290 ZoneList<Expression*>* arguments) 1164 ZoneList<Expression*>* arguments)
1291 : name_(name), function_(function), arguments_(arguments) { } 1165 : name_(name), function_(function), arguments_(arguments) { }
1292 1166
1293 virtual void Accept(AstVisitor* v); 1167 virtual void Accept(AstVisitor* v);
1294 1168
1295 virtual bool IsPrimitive();
1296
1297 Handle<String> name() const { return name_; } 1169 Handle<String> name() const { return name_; }
1298 Runtime::Function* function() const { return function_; } 1170 Runtime::Function* function() const { return function_; }
1299 ZoneList<Expression*>* arguments() const { return arguments_; } 1171 ZoneList<Expression*>* arguments() const { return arguments_; }
1300 bool is_jsruntime() const { return function_ == NULL; } 1172 bool is_jsruntime() const { return function_ == NULL; }
1301 1173
1302 private: 1174 private:
1303 Handle<String> name_; 1175 Handle<String> name_;
1304 Runtime::Function* function_; 1176 Runtime::Function* function_;
1305 ZoneList<Expression*>* arguments_; 1177 ZoneList<Expression*>* arguments_;
1306 }; 1178 };
1307 1179
1308 1180
1309 class UnaryOperation: public Expression { 1181 class UnaryOperation: public Expression {
1310 public: 1182 public:
1311 UnaryOperation(Token::Value op, Expression* expression) 1183 UnaryOperation(Token::Value op, Expression* expression)
1312 : op_(op), expression_(expression) { 1184 : op_(op), expression_(expression) {
1313 ASSERT(Token::IsUnaryOp(op)); 1185 ASSERT(Token::IsUnaryOp(op));
1314 } 1186 }
1315 1187
1316 UnaryOperation(UnaryOperation* other, Expression* expression);
1317
1318 virtual void Accept(AstVisitor* v); 1188 virtual void Accept(AstVisitor* v);
1319 1189
1320 // Type testing & conversion 1190 // Type testing & conversion
1321 virtual UnaryOperation* AsUnaryOperation() { return this; } 1191 virtual UnaryOperation* AsUnaryOperation() { return this; }
1322 1192
1323 virtual bool IsPrimitive();
1324 virtual bool IsCritical();
1325
1326 Token::Value op() const { return op_; } 1193 Token::Value op() const { return op_; }
1327 Expression* expression() const { return expression_; } 1194 Expression* expression() const { return expression_; }
1328 1195
1329 private: 1196 private:
1330 Token::Value op_; 1197 Token::Value op_;
1331 Expression* expression_; 1198 Expression* expression_;
1332 }; 1199 };
1333 1200
1334 1201
1335 class BinaryOperation: public Expression { 1202 class BinaryOperation: public Expression {
1336 public: 1203 public:
1337 BinaryOperation(Token::Value op, Expression* left, Expression* right) 1204 BinaryOperation(Token::Value op, Expression* left, Expression* right)
1338 : op_(op), left_(left), right_(right) { 1205 : op_(op), left_(left), right_(right) {
1339 ASSERT(Token::IsBinaryOp(op)); 1206 ASSERT(Token::IsBinaryOp(op));
1340 } 1207 }
1341 1208
1342 // Construct a binary operation with a given operator and left and right
1343 // subexpressions. The rest of the expression state is copied from
1344 // another expression.
1345 BinaryOperation(Expression* other,
1346 Token::Value op,
1347 Expression* left,
1348 Expression* right);
1349
1350 virtual void Accept(AstVisitor* v); 1209 virtual void Accept(AstVisitor* v);
1351 1210
1352 // Type testing & conversion 1211 // Type testing & conversion
1353 virtual BinaryOperation* AsBinaryOperation() { return this; } 1212 virtual BinaryOperation* AsBinaryOperation() { return this; }
1354 1213
1355 virtual bool IsPrimitive();
1356 virtual bool IsCritical();
1357
1358 // True iff the result can be safely overwritten (to avoid allocation). 1214 // True iff the result can be safely overwritten (to avoid allocation).
1359 // False for operations that can return one of their operands. 1215 // False for operations that can return one of their operands.
1360 bool ResultOverwriteAllowed() { 1216 bool ResultOverwriteAllowed() {
1361 switch (op_) { 1217 switch (op_) {
1362 case Token::COMMA: 1218 case Token::COMMA:
1363 case Token::OR: 1219 case Token::OR:
1364 case Token::AND: 1220 case Token::AND:
1365 return false; 1221 return false;
1366 case Token::BIT_OR: 1222 case Token::BIT_OR:
1367 case Token::BIT_XOR: 1223 case Token::BIT_XOR:
(...skipping 24 matching lines...) Expand all
1392 }; 1248 };
1393 1249
1394 1250
1395 class CountOperation: public Expression { 1251 class CountOperation: public Expression {
1396 public: 1252 public:
1397 CountOperation(bool is_prefix, Token::Value op, Expression* expression) 1253 CountOperation(bool is_prefix, Token::Value op, Expression* expression)
1398 : is_prefix_(is_prefix), op_(op), expression_(expression) { 1254 : is_prefix_(is_prefix), op_(op), expression_(expression) {
1399 ASSERT(Token::IsCountOp(op)); 1255 ASSERT(Token::IsCountOp(op));
1400 } 1256 }
1401 1257
1402 CountOperation(CountOperation* other, Expression* expression);
1403
1404 virtual void Accept(AstVisitor* v); 1258 virtual void Accept(AstVisitor* v);
1405 1259
1406 virtual CountOperation* AsCountOperation() { return this; } 1260 virtual CountOperation* AsCountOperation() { return this; }
1407 1261
1408 virtual Variable* AssignedVariable() {
1409 return expression()->AsVariableProxy()->AsVariable();
1410 }
1411
1412 virtual bool IsPrimitive();
1413 virtual bool IsCritical();
1414
1415 bool is_prefix() const { return is_prefix_; } 1262 bool is_prefix() const { return is_prefix_; }
1416 bool is_postfix() const { return !is_prefix_; } 1263 bool is_postfix() const { return !is_prefix_; }
1417 Token::Value op() const { return op_; } 1264 Token::Value op() const { return op_; }
1418 Token::Value binary_op() { 1265 Token::Value binary_op() {
1419 return op_ == Token::INC ? Token::ADD : Token::SUB; 1266 return op_ == Token::INC ? Token::ADD : Token::SUB;
1420 } 1267 }
1421 Expression* expression() const { return expression_; } 1268 Expression* expression() const { return expression_; }
1422 1269
1423 virtual void MarkAsStatement() { is_prefix_ = true; } 1270 virtual void MarkAsStatement() { is_prefix_ = true; }
1424 1271
1425 private: 1272 private:
1426 bool is_prefix_; 1273 bool is_prefix_;
1427 Token::Value op_; 1274 Token::Value op_;
1428 Expression* expression_; 1275 Expression* expression_;
1429 }; 1276 };
1430 1277
1431 1278
1432 class CompareOperation: public Expression { 1279 class CompareOperation: public Expression {
1433 public: 1280 public:
1434 CompareOperation(Token::Value op, Expression* left, Expression* right) 1281 CompareOperation(Token::Value op, Expression* left, Expression* right)
1435 : op_(op), left_(left), right_(right) { 1282 : op_(op), left_(left), right_(right) {
1436 ASSERT(Token::IsCompareOp(op)); 1283 ASSERT(Token::IsCompareOp(op));
1437 } 1284 }
1438 1285
1439 CompareOperation(CompareOperation* other,
1440 Expression* left,
1441 Expression* right);
1442
1443 virtual void Accept(AstVisitor* v); 1286 virtual void Accept(AstVisitor* v);
1444 1287
1445 virtual bool IsPrimitive();
1446 virtual bool IsCritical();
1447
1448 Token::Value op() const { return op_; } 1288 Token::Value op() const { return op_; }
1449 Expression* left() const { return left_; } 1289 Expression* left() const { return left_; }
1450 Expression* right() const { return right_; } 1290 Expression* right() const { return right_; }
1451 1291
1452 // Type testing & conversion 1292 // Type testing & conversion
1453 virtual CompareOperation* AsCompareOperation() { return this; } 1293 virtual CompareOperation* AsCompareOperation() { return this; }
1454 1294
1455 private: 1295 private:
1456 Token::Value op_; 1296 Token::Value op_;
1457 Expression* left_; 1297 Expression* left_;
1458 Expression* right_; 1298 Expression* right_;
1459 }; 1299 };
1460 1300
1461 1301
1302 class CompareToNull: public Expression {
1303 public:
1304 CompareToNull(bool is_strict, Expression* expression)
1305 : is_strict_(is_strict), expression_(expression) { }
1306
1307 virtual void Accept(AstVisitor* v);
1308
1309 bool is_strict() const { return is_strict_; }
1310 Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; }
1311 Expression* expression() const { return expression_; }
1312
1313 private:
1314 bool is_strict_;
1315 Expression* expression_;
1316 };
1317
1318
1462 class Conditional: public Expression { 1319 class Conditional: public Expression {
1463 public: 1320 public:
1464 Conditional(Expression* condition, 1321 Conditional(Expression* condition,
1465 Expression* then_expression, 1322 Expression* then_expression,
1466 Expression* else_expression, 1323 Expression* else_expression,
1467 int then_expression_position, 1324 int then_expression_position,
1468 int else_expression_position) 1325 int else_expression_position)
1469 : condition_(condition), 1326 : condition_(condition),
1470 then_expression_(then_expression), 1327 then_expression_(then_expression),
1471 else_expression_(else_expression), 1328 else_expression_(else_expression),
1472 then_expression_position_(then_expression_position), 1329 then_expression_position_(then_expression_position),
1473 else_expression_position_(else_expression_position) { } 1330 else_expression_position_(else_expression_position) { }
1474 1331
1475 virtual void Accept(AstVisitor* v); 1332 virtual void Accept(AstVisitor* v);
1476 1333
1477 virtual bool IsPrimitive();
1478
1479 Expression* condition() const { return condition_; } 1334 Expression* condition() const { return condition_; }
1480 Expression* then_expression() const { return then_expression_; } 1335 Expression* then_expression() const { return then_expression_; }
1481 Expression* else_expression() const { return else_expression_; } 1336 Expression* else_expression() const { return else_expression_; }
1482 1337
1483 int then_expression_position() { return then_expression_position_; } 1338 int then_expression_position() { return then_expression_position_; }
1484 int else_expression_position() { return else_expression_position_; } 1339 int else_expression_position() { return else_expression_position_; }
1485 1340
1486 private: 1341 private:
1487 Expression* condition_; 1342 Expression* condition_;
1488 Expression* then_expression_; 1343 Expression* then_expression_;
1489 Expression* else_expression_; 1344 Expression* else_expression_;
1490 int then_expression_position_; 1345 int then_expression_position_;
1491 int else_expression_position_; 1346 int else_expression_position_;
1492 }; 1347 };
1493 1348
1494 1349
1495 class Assignment: public Expression { 1350 class Assignment: public Expression {
1496 public: 1351 public:
1497 Assignment(Token::Value op, Expression* target, Expression* value, int pos) 1352 Assignment(Token::Value op, Expression* target, Expression* value, int pos)
1498 : op_(op), target_(target), value_(value), pos_(pos), 1353 : op_(op), target_(target), value_(value), pos_(pos),
1499 block_start_(false), block_end_(false) { 1354 block_start_(false), block_end_(false) {
1500 ASSERT(Token::IsAssignmentOp(op)); 1355 ASSERT(Token::IsAssignmentOp(op));
1501 } 1356 }
1502 1357
1503 Assignment(Assignment* other, Expression* target, Expression* value);
1504
1505 virtual void Accept(AstVisitor* v); 1358 virtual void Accept(AstVisitor* v);
1506 virtual Assignment* AsAssignment() { return this; } 1359 virtual Assignment* AsAssignment() { return this; }
1507 1360
1508 virtual bool IsPrimitive();
1509 virtual bool IsCritical();
1510
1511 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } 1361 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
1512 1362
1513 virtual Variable* AssignedVariable() {
1514 return target()->AsVariableProxy()->AsVariable();
1515 }
1516
1517 Token::Value binary_op() const; 1363 Token::Value binary_op() const;
1518 1364
1519 Token::Value op() const { return op_; } 1365 Token::Value op() const { return op_; }
1520 Expression* target() const { return target_; } 1366 Expression* target() const { return target_; }
1521 Expression* value() const { return value_; } 1367 Expression* value() const { return value_; }
1522 int position() { return pos_; } 1368 int position() { return pos_; }
1523 // This check relies on the definition order of token in token.h. 1369 // This check relies on the definition order of token in token.h.
1524 bool is_compound() const { return op() > Token::ASSIGN; } 1370 bool is_compound() const { return op() > Token::ASSIGN; }
1525 1371
1526 // An initialization block is a series of statments of the form 1372 // An initialization block is a series of statments of the form
(...skipping 15 matching lines...) Expand all
1542 }; 1388 };
1543 1389
1544 1390
1545 class Throw: public Expression { 1391 class Throw: public Expression {
1546 public: 1392 public:
1547 Throw(Expression* exception, int pos) 1393 Throw(Expression* exception, int pos)
1548 : exception_(exception), pos_(pos) {} 1394 : exception_(exception), pos_(pos) {}
1549 1395
1550 virtual void Accept(AstVisitor* v); 1396 virtual void Accept(AstVisitor* v);
1551 1397
1552 virtual bool IsPrimitive();
1553
1554 Expression* exception() const { return exception_; } 1398 Expression* exception() const { return exception_; }
1555 int position() const { return pos_; } 1399 int position() const { return pos_; }
1556 1400
1557 private: 1401 private:
1558 Expression* exception_; 1402 Expression* exception_;
1559 int pos_; 1403 int pos_;
1560 }; 1404 };
1561 1405
1562 1406
1563 class FunctionLiteral: public Expression { 1407 class FunctionLiteral: public Expression {
(...skipping 27 matching lines...) Expand all
1591 #ifdef DEBUG 1435 #ifdef DEBUG
1592 already_compiled_ = false; 1436 already_compiled_ = false;
1593 #endif 1437 #endif
1594 } 1438 }
1595 1439
1596 virtual void Accept(AstVisitor* v); 1440 virtual void Accept(AstVisitor* v);
1597 1441
1598 // Type testing & conversion 1442 // Type testing & conversion
1599 virtual FunctionLiteral* AsFunctionLiteral() { return this; } 1443 virtual FunctionLiteral* AsFunctionLiteral() { return this; }
1600 1444
1601 virtual bool IsLeaf() { return true; }
1602
1603 virtual bool IsPrimitive();
1604
1605 Handle<String> name() const { return name_; } 1445 Handle<String> name() const { return name_; }
1606 Scope* scope() const { return scope_; } 1446 Scope* scope() const { return scope_; }
1607 ZoneList<Statement*>* body() const { return body_; } 1447 ZoneList<Statement*>* body() const { return body_; }
1608 void set_function_token_position(int pos) { function_token_position_ = pos; } 1448 void set_function_token_position(int pos) { function_token_position_ = pos; }
1609 int function_token_position() const { return function_token_position_; } 1449 int function_token_position() const { return function_token_position_; }
1610 int start_position() const { return start_position_; } 1450 int start_position() const { return start_position_; }
1611 int end_position() const { return end_position_; } 1451 int end_position() const { return end_position_; }
1612 bool is_expression() const { return is_expression_; } 1452 bool is_expression() const { return is_expression_; }
1613 1453
1614 int materialized_literal_count() { return materialized_literal_count_; } 1454 int materialized_literal_count() { return materialized_literal_count_; }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 class SharedFunctionInfoLiteral: public Expression { 1502 class SharedFunctionInfoLiteral: public Expression {
1663 public: 1503 public:
1664 explicit SharedFunctionInfoLiteral( 1504 explicit SharedFunctionInfoLiteral(
1665 Handle<SharedFunctionInfo> shared_function_info) 1505 Handle<SharedFunctionInfo> shared_function_info)
1666 : shared_function_info_(shared_function_info) { } 1506 : shared_function_info_(shared_function_info) { }
1667 1507
1668 Handle<SharedFunctionInfo> shared_function_info() const { 1508 Handle<SharedFunctionInfo> shared_function_info() const {
1669 return shared_function_info_; 1509 return shared_function_info_;
1670 } 1510 }
1671 1511
1672 virtual bool IsLeaf() { return true; }
1673
1674 virtual void Accept(AstVisitor* v); 1512 virtual void Accept(AstVisitor* v);
1675 1513
1676 virtual bool IsPrimitive();
1677
1678 private: 1514 private:
1679 Handle<SharedFunctionInfo> shared_function_info_; 1515 Handle<SharedFunctionInfo> shared_function_info_;
1680 }; 1516 };
1681 1517
1682 1518
1683 class ThisFunction: public Expression { 1519 class ThisFunction: public Expression {
1684 public: 1520 public:
1685 virtual void Accept(AstVisitor* v); 1521 virtual void Accept(AstVisitor* v);
1686 virtual bool IsLeaf() { return true; }
1687 virtual bool IsPrimitive();
1688 }; 1522 };
1689 1523
1690 1524
1691 // ---------------------------------------------------------------------------- 1525 // ----------------------------------------------------------------------------
1692 // Regular expressions 1526 // Regular expressions
1693 1527
1694 1528
1695 class RegExpVisitor BASE_EMBEDDED { 1529 class RegExpVisitor BASE_EMBEDDED {
1696 public: 1530 public:
1697 virtual ~RegExpVisitor() { } 1531 virtual ~RegExpVisitor() { }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2065 // Individual nodes 1899 // Individual nodes
2066 #define DEF_VISIT(type) \ 1900 #define DEF_VISIT(type) \
2067 virtual void Visit##type(type* node) = 0; 1901 virtual void Visit##type(type* node) = 0;
2068 AST_NODE_LIST(DEF_VISIT) 1902 AST_NODE_LIST(DEF_VISIT)
2069 #undef DEF_VISIT 1903 #undef DEF_VISIT
2070 1904
2071 private: 1905 private:
2072 bool stack_overflow_; 1906 bool stack_overflow_;
2073 }; 1907 };
2074 1908
2075
2076 class CopyAstVisitor : public AstVisitor {
2077 public:
2078 Expression* DeepCopyExpr(Expression* expr);
2079
2080 Statement* DeepCopyStmt(Statement* stmt);
2081
2082 private:
2083 ZoneList<Expression*>* DeepCopyExprList(ZoneList<Expression*>* expressions);
2084
2085 ZoneList<Statement*>* DeepCopyStmtList(ZoneList<Statement*>* statements);
2086
2087 // AST node visit functions.
2088 #define DECLARE_VISIT(type) virtual void Visit##type(type* node);
2089 AST_NODE_LIST(DECLARE_VISIT)
2090 #undef DECLARE_VISIT
2091
2092 // Holds the result of copying an expression.
2093 Expression* expr_;
2094 // Holds the result of copying a statement.
2095 Statement* stmt_;
2096 };
2097
2098 } } // namespace v8::internal 1909 } } // namespace v8::internal
2099 1910
2100 #endif // V8_AST_H_ 1911 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/arm/full-codegen-arm.cc ('k') | src/ast.cc » ('j') | src/x64/full-codegen-x64.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698