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

Side by Side Diff: src/ast.h

Issue 6529055: [Isolates] Merge crankshaft (r5922 from bleeding_edge). (Closed)
Patch Set: Win32 port Created 9 years, 10 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
« no previous file with comments | « src/assembler.cc ('k') | 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 V(ForStatement) \ 68 V(ForStatement) \
69 V(ForInStatement) \ 69 V(ForInStatement) \
70 V(TryCatchStatement) \ 70 V(TryCatchStatement) \
71 V(TryFinallyStatement) \ 71 V(TryFinallyStatement) \
72 V(DebuggerStatement) 72 V(DebuggerStatement)
73 73
74 #define EXPRESSION_NODE_LIST(V) \ 74 #define EXPRESSION_NODE_LIST(V) \
75 V(FunctionLiteral) \ 75 V(FunctionLiteral) \
76 V(SharedFunctionInfoLiteral) \ 76 V(SharedFunctionInfoLiteral) \
77 V(Conditional) \ 77 V(Conditional) \
78 V(Slot) \
79 V(VariableProxy) \ 78 V(VariableProxy) \
80 V(Literal) \ 79 V(Literal) \
81 V(RegExpLiteral) \ 80 V(RegExpLiteral) \
82 V(ObjectLiteral) \ 81 V(ObjectLiteral) \
83 V(ArrayLiteral) \ 82 V(ArrayLiteral) \
84 V(CatchExtensionObject) \ 83 V(CatchExtensionObject) \
85 V(Assignment) \ 84 V(Assignment) \
86 V(Throw) \ 85 V(Throw) \
87 V(Property) \ 86 V(Property) \
88 V(Call) \ 87 V(Call) \
89 V(CallNew) \ 88 V(CallNew) \
90 V(CallRuntime) \ 89 V(CallRuntime) \
91 V(UnaryOperation) \ 90 V(UnaryOperation) \
92 V(IncrementOperation) \ 91 V(IncrementOperation) \
93 V(CountOperation) \ 92 V(CountOperation) \
94 V(BinaryOperation) \ 93 V(BinaryOperation) \
95 V(CompareOperation) \ 94 V(CompareOperation) \
96 V(CompareToNull) \ 95 V(CompareToNull) \
97 V(ThisFunction) 96 V(ThisFunction)
98 97
99 #define AST_NODE_LIST(V) \ 98 #define AST_NODE_LIST(V) \
100 V(Declaration) \ 99 V(Declaration) \
101 STATEMENT_NODE_LIST(V) \ 100 STATEMENT_NODE_LIST(V) \
102 EXPRESSION_NODE_LIST(V) 101 EXPRESSION_NODE_LIST(V)
103 102
104 // Forward declarations 103 // Forward declarations
104 class BitVector;
105 class DefinitionInfo;
106 class MaterializedLiteral;
105 class TargetCollector; 107 class TargetCollector;
106 class MaterializedLiteral; 108 class TypeFeedbackOracle;
107 class DefinitionInfo;
108 class BitVector;
109 109
110 #define DEF_FORWARD_DECLARATION(type) class type; 110 #define DEF_FORWARD_DECLARATION(type) class type;
111 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 111 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
112 #undef DEF_FORWARD_DECLARATION 112 #undef DEF_FORWARD_DECLARATION
113 113
114 114
115 // Typedef only introduced to avoid unreadable code. 115 // Typedef only introduced to avoid unreadable code.
116 // Please do appreciate the required space in "> >". 116 // Please do appreciate the required space in "> >".
117 typedef ZoneList<Handle<String> > ZoneStringList; 117 typedef ZoneList<Handle<String> > ZoneStringList;
118 typedef ZoneList<Handle<Object> > ZoneObjectList; 118 typedef ZoneList<Handle<Object> > ZoneObjectList;
119 119
120 120
121 #define DECLARE_NODE_TYPE(type) \ 121 #define DECLARE_NODE_TYPE(type) \
122 virtual void Accept(AstVisitor* v); \ 122 virtual void Accept(AstVisitor* v); \
123 virtual AstNode::Type node_type() const { return AstNode::k##type; } \ 123 virtual AstNode::Type node_type() const { return AstNode::k##type; } \
124 virtual type* As##type() { return this; } 124 virtual type* As##type() { return this; }
125 125
126 126
127 class AstNode: public ZoneObject { 127 class AstNode: public ZoneObject {
128 public: 128 public:
129 #define DECLARE_TYPE_ENUM(type) k##type, 129 #define DECLARE_TYPE_ENUM(type) k##type,
130 enum Type { 130 enum Type {
131 AST_NODE_LIST(DECLARE_TYPE_ENUM) 131 AST_NODE_LIST(DECLARE_TYPE_ENUM)
132 kInvalid = -1 132 kInvalid = -1
133 }; 133 };
134 #undef DECLARE_TYPE_ENUM 134 #undef DECLARE_TYPE_ENUM
135 135
136 static const int kNoNumber = -1;
137
138 AstNode() : id_(GetNextId()) {
139 Isolate* isolate = Isolate::Current();
140 isolate->set_ast_node_count(isolate->ast_node_count() + 1);
141 }
142
136 virtual ~AstNode() { } 143 virtual ~AstNode() { }
137 144
138 virtual void Accept(AstVisitor* v) = 0; 145 virtual void Accept(AstVisitor* v) = 0;
139 virtual Type node_type() const { return kInvalid; } 146 virtual Type node_type() const { return kInvalid; }
140 147
141 // Type testing & conversion functions overridden by concrete subclasses. 148 // Type testing & conversion functions overridden by concrete subclasses.
142 #define DECLARE_NODE_FUNCTIONS(type) \ 149 #define DECLARE_NODE_FUNCTIONS(type) \
143 virtual type* As##type() { return NULL; } 150 virtual type* As##type() { return NULL; }
144 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 151 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
145 #undef DECLARE_NODE_FUNCTIONS 152 #undef DECLARE_NODE_FUNCTIONS
146 153
147 virtual Statement* AsStatement() { return NULL; } 154 virtual Statement* AsStatement() { return NULL; }
148 virtual Expression* AsExpression() { return NULL; } 155 virtual Expression* AsExpression() { return NULL; }
149 virtual TargetCollector* AsTargetCollector() { return NULL; } 156 virtual TargetCollector* AsTargetCollector() { return NULL; }
150 virtual BreakableStatement* AsBreakableStatement() { return NULL; } 157 virtual BreakableStatement* AsBreakableStatement() { return NULL; }
151 virtual IterationStatement* AsIterationStatement() { return NULL; } 158 virtual IterationStatement* AsIterationStatement() { return NULL; }
152 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } 159 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; }
160 virtual Slot* AsSlot() { return NULL; }
161
162 // True if the node is simple enough for us to inline calls containing it.
163 virtual bool IsInlineable() const { return false; }
164
165 static int Count() { return Isolate::Current()->ast_node_count(); }
166 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); }
167 unsigned id() const { return id_; }
168
169 protected:
170 static unsigned GetNextId() {
171 Isolate* isolate = Isolate::Current();
172 unsigned tmp = isolate->ast_node_id();
173 isolate->set_ast_node_id(tmp + 1);
174 return tmp;
175 }
176 static unsigned ReserveIdRange(int n) {
177 Isolate* isolate = Isolate::Current();
178 unsigned tmp = isolate->ast_node_id();
179 isolate->set_ast_node_id(tmp + n);
180 return tmp;
181 }
182
183 private:
184 unsigned id_;
153 }; 185 };
154 186
155 187
156 class Statement: public AstNode { 188 class Statement: public AstNode {
157 public: 189 public:
158 Statement() : statement_pos_(RelocInfo::kNoPosition) {} 190 Statement() : statement_pos_(RelocInfo::kNoPosition) {}
159 191
160 virtual Statement* AsStatement() { return this; } 192 virtual Statement* AsStatement() { return this; }
161 193
162 virtual Assignment* StatementAsSimpleAssignment() { return NULL; } 194 virtual Assignment* StatementAsSimpleAssignment() { return NULL; }
163 virtual CountOperation* StatementAsCountOperation() { return NULL; } 195 virtual CountOperation* StatementAsCountOperation() { return NULL; }
164 196
165 bool IsEmpty() { return AsEmptyStatement() != NULL; } 197 bool IsEmpty() { return AsEmptyStatement() != NULL; }
166 198
167 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } 199 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; }
168 int statement_pos() const { return statement_pos_; } 200 int statement_pos() const { return statement_pos_; }
169 201
170 private: 202 private:
171 int statement_pos_; 203 int statement_pos_;
172 }; 204 };
173 205
174 206
175 class Expression: public AstNode { 207 class Expression: public AstNode {
176 public: 208 public:
209 enum Context {
210 // Not assigned a context yet, or else will not be visited during
211 // code generation.
212 kUninitialized,
213 // Evaluated for its side effects.
214 kEffect,
215 // Evaluated for its value (and side effects).
216 kValue,
217 // Evaluated for control flow (and side effects).
218 kTest
219 };
220
177 Expression() : bitfields_(0) {} 221 Expression() : bitfields_(0) {}
178 222
179 virtual Expression* AsExpression() { return this; } 223 virtual Expression* AsExpression() { return this; }
180 224
181 virtual bool IsTrivial() { return false; } 225 virtual bool IsTrivial() { return false; }
182 virtual bool IsValidLeftHandSide() { return false; } 226 virtual bool IsValidLeftHandSide() { return false; }
183 227
228 // Helpers for ToBoolean conversion.
229 virtual bool ToBooleanIsTrue() { return false; }
230 virtual bool ToBooleanIsFalse() { return false; }
231
184 // Symbols that cannot be parsed as array indices are considered property 232 // Symbols that cannot be parsed as array indices are considered property
185 // names. We do not treat symbols that can be array indexes as property 233 // names. We do not treat symbols that can be array indexes as property
186 // names because [] for string objects is handled only by keyed ICs. 234 // names because [] for string objects is handled only by keyed ICs.
187 virtual bool IsPropertyName() { return false; } 235 virtual bool IsPropertyName() { return false; }
188 236
189 // Mark the expression as being compiled as an expression 237 // Mark the expression as being compiled as an expression
190 // statement. This is used to transform postfix increments to 238 // statement. This is used to transform postfix increments to
191 // (faster) prefix increments. 239 // (faster) prefix increments.
192 virtual void MarkAsStatement() { /* do nothing */ } 240 virtual void MarkAsStatement() { /* do nothing */ }
193 241
194 // True iff the result can be safely overwritten (to avoid allocation). 242 // True iff the result can be safely overwritten (to avoid allocation).
195 // False for operations that can return one of their operands. 243 // False for operations that can return one of their operands.
196 virtual bool ResultOverwriteAllowed() { return false; } 244 virtual bool ResultOverwriteAllowed() { return false; }
197 245
198 // True iff the expression is a literal represented as a smi. 246 // True iff the expression is a literal represented as a smi.
199 virtual bool IsSmiLiteral() { return false; } 247 virtual bool IsSmiLiteral() { return false; }
200 248
249 // Type feedback information for assignments and properties.
250 virtual bool IsMonomorphic() {
251 UNREACHABLE();
252 return false;
253 }
254 virtual bool IsArrayLength() {
255 UNREACHABLE();
256 return false;
257 }
258 virtual ZoneMapList* GetReceiverTypes() {
259 UNREACHABLE();
260 return NULL;
261 }
262 virtual Handle<Map> GetMonomorphicReceiverType() {
263 UNREACHABLE();
264 return Handle<Map>();
265 }
266
201 // Static type information for this expression. 267 // Static type information for this expression.
202 StaticType* type() { return &type_; } 268 StaticType* type() { return &type_; }
203 269
204 // True if the expression is a loop condition. 270 // True if the expression is a loop condition.
205 bool is_loop_condition() const { 271 bool is_loop_condition() const {
206 return LoopConditionField::decode(bitfields_); 272 return LoopConditionField::decode(bitfields_);
207 } 273 }
208 void set_is_loop_condition(bool flag) { 274 void set_is_loop_condition(bool flag) {
209 bitfields_ = (bitfields_ & ~LoopConditionField::mask()) | 275 bitfields_ = (bitfields_ & ~LoopConditionField::mask()) |
210 LoopConditionField::encode(flag); 276 LoopConditionField::encode(flag);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 356
291 // Type testing & conversion. 357 // Type testing & conversion.
292 virtual BreakableStatement* AsBreakableStatement() { return this; } 358 virtual BreakableStatement* AsBreakableStatement() { return this; }
293 359
294 // Code generation 360 // Code generation
295 BreakTarget* break_target() { return &break_target_; } 361 BreakTarget* break_target() { return &break_target_; }
296 362
297 // Testers. 363 // Testers.
298 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; } 364 bool is_target_for_anonymous() const { return type_ == TARGET_FOR_ANONYMOUS; }
299 365
366 // Bailout support.
367 int EntryId() const { return entry_id_; }
368 int ExitId() const { return exit_id_; }
369
300 protected: 370 protected:
301 inline BreakableStatement(ZoneStringList* labels, Type type); 371 inline BreakableStatement(ZoneStringList* labels, Type type);
302 372
303 private: 373 private:
304 ZoneStringList* labels_; 374 ZoneStringList* labels_;
305 Type type_; 375 Type type_;
306 BreakTarget break_target_; 376 BreakTarget break_target_;
377 int entry_id_;
378 int exit_id_;
307 }; 379 };
308 380
309 381
310 class Block: public BreakableStatement { 382 class Block: public BreakableStatement {
311 public: 383 public:
312 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block); 384 inline Block(ZoneStringList* labels, int capacity, bool is_initializer_block);
313 385
314 DECLARE_NODE_TYPE(Block) 386 DECLARE_NODE_TYPE(Block)
315 387
316 virtual Assignment* StatementAsSimpleAssignment() { 388 virtual Assignment* StatementAsSimpleAssignment() {
317 if (statements_.length() != 1) return NULL; 389 if (statements_.length() != 1) return NULL;
318 return statements_[0]->StatementAsSimpleAssignment(); 390 return statements_[0]->StatementAsSimpleAssignment();
319 } 391 }
320 392
321 virtual CountOperation* StatementAsCountOperation() { 393 virtual CountOperation* StatementAsCountOperation() {
322 if (statements_.length() != 1) return NULL; 394 if (statements_.length() != 1) return NULL;
323 return statements_[0]->StatementAsCountOperation(); 395 return statements_[0]->StatementAsCountOperation();
324 } 396 }
325 397
398 virtual bool IsInlineable() const;
399
326 void AddStatement(Statement* statement) { statements_.Add(statement); } 400 void AddStatement(Statement* statement) { statements_.Add(statement); }
327 401
328 ZoneList<Statement*>* statements() { return &statements_; } 402 ZoneList<Statement*>* statements() { return &statements_; }
329 bool is_initializer_block() const { return is_initializer_block_; } 403 bool is_initializer_block() const { return is_initializer_block_; }
330 404
331 private: 405 private:
332 ZoneList<Statement*> statements_; 406 ZoneList<Statement*> statements_;
333 bool is_initializer_block_; 407 bool is_initializer_block_;
334 }; 408 };
335 409
(...skipping 23 matching lines...) Expand all
359 433
360 434
361 class IterationStatement: public BreakableStatement { 435 class IterationStatement: public BreakableStatement {
362 public: 436 public:
363 // Type testing & conversion. 437 // Type testing & conversion.
364 virtual IterationStatement* AsIterationStatement() { return this; } 438 virtual IterationStatement* AsIterationStatement() { return this; }
365 439
366 Statement* body() const { return body_; } 440 Statement* body() const { return body_; }
367 void set_body(Statement* stmt) { body_ = stmt; } 441 void set_body(Statement* stmt) { body_ = stmt; }
368 442
443 // Bailout support.
444 int OsrEntryId() const { return osr_entry_id_; }
445 virtual int ContinueId() const = 0;
446
369 // Code generation 447 // Code generation
370 BreakTarget* continue_target() { return &continue_target_; } 448 BreakTarget* continue_target() { return &continue_target_; }
371 449
372 protected: 450 protected:
373 explicit inline IterationStatement(ZoneStringList* labels); 451 explicit inline IterationStatement(ZoneStringList* labels);
374 452
375 void Initialize(Statement* body) { 453 void Initialize(Statement* body) {
376 body_ = body; 454 body_ = body;
377 } 455 }
378 456
379 private: 457 private:
380 Statement* body_; 458 Statement* body_;
381 BreakTarget continue_target_; 459 BreakTarget continue_target_;
460 int osr_entry_id_;
382 }; 461 };
383 462
384 463
385 class DoWhileStatement: public IterationStatement { 464 class DoWhileStatement: public IterationStatement {
386 public: 465 public:
387 explicit inline DoWhileStatement(ZoneStringList* labels); 466 explicit inline DoWhileStatement(ZoneStringList* labels);
388 467
389 DECLARE_NODE_TYPE(DoWhileStatement) 468 DECLARE_NODE_TYPE(DoWhileStatement)
390 469
391 void Initialize(Expression* cond, Statement* body) { 470 void Initialize(Expression* cond, Statement* body) {
392 IterationStatement::Initialize(body); 471 IterationStatement::Initialize(body);
393 cond_ = cond; 472 cond_ = cond;
394 } 473 }
395 474
396 Expression* cond() const { return cond_; } 475 Expression* cond() const { return cond_; }
397 476
398 // Position where condition expression starts. We need it to make 477 // Position where condition expression starts. We need it to make
399 // the loop's condition a breakable location. 478 // the loop's condition a breakable location.
400 int condition_position() { return condition_position_; } 479 int condition_position() { return condition_position_; }
401 void set_condition_position(int pos) { condition_position_ = pos; } 480 void set_condition_position(int pos) { condition_position_ = pos; }
402 481
482 // Bailout support.
483 virtual int ContinueId() const { return next_id_; }
484
403 private: 485 private:
404 Expression* cond_; 486 Expression* cond_;
405 int condition_position_; 487 int condition_position_;
488 int next_id_;
406 }; 489 };
407 490
408 491
409 class WhileStatement: public IterationStatement { 492 class WhileStatement: public IterationStatement {
410 public: 493 public:
411 explicit WhileStatement(ZoneStringList* labels); 494 explicit inline WhileStatement(ZoneStringList* labels);
412 495
413 DECLARE_NODE_TYPE(WhileStatement) 496 DECLARE_NODE_TYPE(WhileStatement)
414 497
415 void Initialize(Expression* cond, Statement* body) { 498 void Initialize(Expression* cond, Statement* body) {
416 IterationStatement::Initialize(body); 499 IterationStatement::Initialize(body);
417 cond_ = cond; 500 cond_ = cond;
418 } 501 }
419 502
420 Expression* cond() const { return cond_; } 503 Expression* cond() const { return cond_; }
421 bool may_have_function_literal() const { 504 bool may_have_function_literal() const {
422 return may_have_function_literal_; 505 return may_have_function_literal_;
423 } 506 }
424 void set_may_have_function_literal(bool value) { 507 void set_may_have_function_literal(bool value) {
425 may_have_function_literal_ = value; 508 may_have_function_literal_ = value;
426 } 509 }
427 510
511 // Bailout support.
512 virtual int ContinueId() const { return EntryId(); }
513
428 private: 514 private:
429 Expression* cond_; 515 Expression* cond_;
430 // True if there is a function literal subexpression in the condition. 516 // True if there is a function literal subexpression in the condition.
431 bool may_have_function_literal_; 517 bool may_have_function_literal_;
432 }; 518 };
433 519
434 520
435 class ForStatement: public IterationStatement { 521 class ForStatement: public IterationStatement {
436 public: 522 public:
437 explicit inline ForStatement(ZoneStringList* labels); 523 explicit inline ForStatement(ZoneStringList* labels);
(...skipping 17 matching lines...) Expand all
455 Statement* next() const { return next_; } 541 Statement* next() const { return next_; }
456 void set_next(Statement* stmt) { next_ = stmt; } 542 void set_next(Statement* stmt) { next_ = stmt; }
457 543
458 bool may_have_function_literal() const { 544 bool may_have_function_literal() const {
459 return may_have_function_literal_; 545 return may_have_function_literal_;
460 } 546 }
461 void set_may_have_function_literal(bool value) { 547 void set_may_have_function_literal(bool value) {
462 may_have_function_literal_ = value; 548 may_have_function_literal_ = value;
463 } 549 }
464 550
551 // Bailout support.
552 virtual int ContinueId() const { return next_id_; }
553
465 bool is_fast_smi_loop() { return loop_variable_ != NULL; } 554 bool is_fast_smi_loop() { return loop_variable_ != NULL; }
466 Variable* loop_variable() { return loop_variable_; } 555 Variable* loop_variable() { return loop_variable_; }
467 void set_loop_variable(Variable* var) { loop_variable_ = var; } 556 void set_loop_variable(Variable* var) { loop_variable_ = var; }
468 557
469 private: 558 private:
470 Statement* init_; 559 Statement* init_;
471 Expression* cond_; 560 Expression* cond_;
472 Statement* next_; 561 Statement* next_;
473 // True if there is a function literal subexpression in the condition. 562 // True if there is a function literal subexpression in the condition.
474 bool may_have_function_literal_; 563 bool may_have_function_literal_;
475 Variable* loop_variable_; 564 Variable* loop_variable_;
565 int next_id_;
476 }; 566 };
477 567
478 568
479 class ForInStatement: public IterationStatement { 569 class ForInStatement: public IterationStatement {
480 public: 570 public:
481 explicit inline ForInStatement(ZoneStringList* labels); 571 explicit inline ForInStatement(ZoneStringList* labels);
482 572
483 DECLARE_NODE_TYPE(ForInStatement) 573 DECLARE_NODE_TYPE(ForInStatement)
484 574
485 void Initialize(Expression* each, Expression* enumerable, Statement* body) { 575 void Initialize(Expression* each, Expression* enumerable, Statement* body) {
486 IterationStatement::Initialize(body); 576 IterationStatement::Initialize(body);
487 each_ = each; 577 each_ = each;
488 enumerable_ = enumerable; 578 enumerable_ = enumerable;
489 } 579 }
490 580
491 Expression* each() const { return each_; } 581 Expression* each() const { return each_; }
492 Expression* enumerable() const { return enumerable_; } 582 Expression* enumerable() const { return enumerable_; }
493 583
584 // Bailout support.
585 virtual int ContinueId() const { return EntryId(); }
586
494 private: 587 private:
495 Expression* each_; 588 Expression* each_;
496 Expression* enumerable_; 589 Expression* enumerable_;
497 }; 590 };
498 591
499 592
500 class ExpressionStatement: public Statement { 593 class ExpressionStatement: public Statement {
501 public: 594 public:
502 explicit ExpressionStatement(Expression* expression) 595 explicit ExpressionStatement(Expression* expression)
503 : expression_(expression) { } 596 : expression_(expression) { }
504 597
505 DECLARE_NODE_TYPE(ExpressionStatement) 598 DECLARE_NODE_TYPE(ExpressionStatement)
506 599
600 virtual bool IsInlineable() const;
601
507 virtual Assignment* StatementAsSimpleAssignment(); 602 virtual Assignment* StatementAsSimpleAssignment();
508 virtual CountOperation* StatementAsCountOperation(); 603 virtual CountOperation* StatementAsCountOperation();
509 604
510 void set_expression(Expression* e) { expression_ = e; } 605 void set_expression(Expression* e) { expression_ = e; }
511 Expression* expression() { return expression_; } 606 Expression* expression() const { return expression_; }
512 607
513 private: 608 private:
514 Expression* expression_; 609 Expression* expression_;
515 }; 610 };
516 611
517 612
518 class ContinueStatement: public Statement { 613 class ContinueStatement: public Statement {
519 public: 614 public:
520 explicit ContinueStatement(IterationStatement* target) 615 explicit ContinueStatement(IterationStatement* target)
521 : target_(target) { } 616 : target_(target) { }
(...skipping 21 matching lines...) Expand all
543 }; 638 };
544 639
545 640
546 class ReturnStatement: public Statement { 641 class ReturnStatement: public Statement {
547 public: 642 public:
548 explicit ReturnStatement(Expression* expression) 643 explicit ReturnStatement(Expression* expression)
549 : expression_(expression) { } 644 : expression_(expression) { }
550 645
551 DECLARE_NODE_TYPE(ReturnStatement) 646 DECLARE_NODE_TYPE(ReturnStatement)
552 647
553 Expression* expression() { return expression_; } 648 Expression* expression() const { return expression_; }
649 virtual bool IsInlineable() const;
554 650
555 private: 651 private:
556 Expression* expression_; 652 Expression* expression_;
557 }; 653 };
558 654
559 655
560 class WithEnterStatement: public Statement { 656 class WithEnterStatement: public Statement {
561 public: 657 public:
562 explicit WithEnterStatement(Expression* expression, bool is_catch_block) 658 explicit WithEnterStatement(Expression* expression, bool is_catch_block)
563 : expression_(expression), is_catch_block_(is_catch_block) { } 659 : expression_(expression), is_catch_block_(is_catch_block) { }
(...skipping 13 matching lines...) Expand all
577 class WithExitStatement: public Statement { 673 class WithExitStatement: public Statement {
578 public: 674 public:
579 WithExitStatement() { } 675 WithExitStatement() { }
580 676
581 DECLARE_NODE_TYPE(WithExitStatement) 677 DECLARE_NODE_TYPE(WithExitStatement)
582 }; 678 };
583 679
584 680
585 class CaseClause: public ZoneObject { 681 class CaseClause: public ZoneObject {
586 public: 682 public:
587 CaseClause(Expression* label, ZoneList<Statement*>* statements); 683 CaseClause(Expression* label, ZoneList<Statement*>* statements, int pos);
588 684
589 bool is_default() const { return label_ == NULL; } 685 bool is_default() const { return label_ == NULL; }
590 Expression* label() const { 686 Expression* label() const {
591 CHECK(!is_default()); 687 CHECK(!is_default());
592 return label_; 688 return label_;
593 } 689 }
594 JumpTarget* body_target() { return &body_target_; } 690 JumpTarget* body_target() { return &body_target_; }
595 ZoneList<Statement*>* statements() const { return statements_; } 691 ZoneList<Statement*>* statements() const { return statements_; }
596 692
693 int position() { return position_; }
694 void set_position(int pos) { position_ = pos; }
695
696 // Type feedback information.
697 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
698 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; }
699 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; }
700
597 private: 701 private:
598 Expression* label_; 702 Expression* label_;
599 JumpTarget body_target_; 703 JumpTarget body_target_;
600 ZoneList<Statement*>* statements_; 704 ZoneList<Statement*>* statements_;
705 int position_;
706 enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY };
707 CompareTypeFeedback compare_type_;
601 }; 708 };
602 709
603 710
604 class SwitchStatement: public BreakableStatement { 711 class SwitchStatement: public BreakableStatement {
605 public: 712 public:
606 explicit inline SwitchStatement(ZoneStringList* labels); 713 explicit inline SwitchStatement(ZoneStringList* labels);
607 714
608 DECLARE_NODE_TYPE(SwitchStatement) 715 DECLARE_NODE_TYPE(SwitchStatement)
609 716
610 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { 717 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
(...skipping 19 matching lines...) Expand all
630 public: 737 public:
631 IfStatement(Expression* condition, 738 IfStatement(Expression* condition,
632 Statement* then_statement, 739 Statement* then_statement,
633 Statement* else_statement) 740 Statement* else_statement)
634 : condition_(condition), 741 : condition_(condition),
635 then_statement_(then_statement), 742 then_statement_(then_statement),
636 else_statement_(else_statement) { } 743 else_statement_(else_statement) { }
637 744
638 DECLARE_NODE_TYPE(IfStatement) 745 DECLARE_NODE_TYPE(IfStatement)
639 746
747 virtual bool IsInlineable() const;
748
640 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } 749 bool HasThenStatement() const { return !then_statement()->IsEmpty(); }
641 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } 750 bool HasElseStatement() const { return !else_statement()->IsEmpty(); }
642 751
643 Expression* condition() const { return condition_; } 752 Expression* condition() const { return condition_; }
644 Statement* then_statement() const { return then_statement_; } 753 Statement* then_statement() const { return then_statement_; }
645 void set_then_statement(Statement* stmt) { then_statement_ = stmt; } 754 void set_then_statement(Statement* stmt) { then_statement_ = stmt; }
646 Statement* else_statement() const { return else_statement_; } 755 Statement* else_statement() const { return else_statement_; }
647 void set_else_statement(Statement* stmt) { else_statement_ = stmt; } 756 void set_else_statement(Statement* stmt) { else_statement_ = stmt; }
648 757
649 private: 758 private:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 842
734 class DebuggerStatement: public Statement { 843 class DebuggerStatement: public Statement {
735 public: 844 public:
736 DECLARE_NODE_TYPE(DebuggerStatement) 845 DECLARE_NODE_TYPE(DebuggerStatement)
737 }; 846 };
738 847
739 848
740 class EmptyStatement: public Statement { 849 class EmptyStatement: public Statement {
741 public: 850 public:
742 DECLARE_NODE_TYPE(EmptyStatement) 851 DECLARE_NODE_TYPE(EmptyStatement)
852
853 virtual bool IsInlineable() const { return true; }
743 }; 854 };
744 855
745 856
746 class Literal: public Expression { 857 class Literal: public Expression {
747 public: 858 public:
748 explicit Literal(Handle<Object> handle) : handle_(handle) { } 859 explicit Literal(Handle<Object> handle) : handle_(handle) { }
749 860
750 DECLARE_NODE_TYPE(Literal) 861 DECLARE_NODE_TYPE(Literal)
751 862
863 virtual bool IsTrivial() { return true; }
864 virtual bool IsInlineable() const { return true; }
752 virtual bool IsSmiLiteral() { return handle_->IsSmi(); } 865 virtual bool IsSmiLiteral() { return handle_->IsSmi(); }
753 866
754 // Check if this literal is identical to the other literal. 867 // Check if this literal is identical to the other literal.
755 bool IsIdenticalTo(const Literal* other) const { 868 bool IsIdenticalTo(const Literal* other) const {
756 return handle_.is_identical_to(other->handle_); 869 return handle_.is_identical_to(other->handle_);
757 } 870 }
758 871
759 virtual bool IsPropertyName() { 872 virtual bool IsPropertyName() {
760 if (handle_->IsSymbol()) { 873 if (handle_->IsSymbol()) {
761 uint32_t ignored; 874 uint32_t ignored;
762 return !String::cast(*handle_)->AsArrayIndex(&ignored); 875 return !String::cast(*handle_)->AsArrayIndex(&ignored);
763 } 876 }
764 return false; 877 return false;
765 } 878 }
766 879
880 Handle<String> AsPropertyName() {
881 ASSERT(IsPropertyName());
882 return Handle<String>::cast(handle_);
883 }
884
885 virtual bool ToBooleanIsTrue() { return handle_->ToBoolean()->IsTrue(); }
886 virtual bool ToBooleanIsFalse() { return handle_->ToBoolean()->IsFalse(); }
887
767 // Identity testers. 888 // Identity testers.
768 bool IsNull() const { 889 bool IsNull() const {
769 ASSERT(!handle_.is_null()); 890 ASSERT(!handle_.is_null());
770 return handle_->IsNull(); 891 return handle_->IsNull();
771 } 892 }
772 bool IsTrue() const { 893 bool IsTrue() const {
773 ASSERT(!handle_.is_null()); 894 ASSERT(!handle_.is_null());
774 return handle_->IsTrue(); 895 return handle_->IsTrue();
775 } 896 }
776 bool IsFalse() const { 897 bool IsFalse() const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // for minimizing the work when constructing it at runtime. 1022 // for minimizing the work when constructing it at runtime.
902 class ArrayLiteral: public MaterializedLiteral { 1023 class ArrayLiteral: public MaterializedLiteral {
903 public: 1024 public:
904 ArrayLiteral(Handle<FixedArray> constant_elements, 1025 ArrayLiteral(Handle<FixedArray> constant_elements,
905 ZoneList<Expression*>* values, 1026 ZoneList<Expression*>* values,
906 int literal_index, 1027 int literal_index,
907 bool is_simple, 1028 bool is_simple,
908 int depth) 1029 int depth)
909 : MaterializedLiteral(literal_index, is_simple, depth), 1030 : MaterializedLiteral(literal_index, is_simple, depth),
910 constant_elements_(constant_elements), 1031 constant_elements_(constant_elements),
911 values_(values) {} 1032 values_(values),
1033 first_element_id_(ReserveIdRange(values->length())) {}
912 1034
913 DECLARE_NODE_TYPE(ArrayLiteral) 1035 DECLARE_NODE_TYPE(ArrayLiteral)
914 1036
915 Handle<FixedArray> constant_elements() const { return constant_elements_; } 1037 Handle<FixedArray> constant_elements() const { return constant_elements_; }
916 ZoneList<Expression*>* values() const { return values_; } 1038 ZoneList<Expression*>* values() const { return values_; }
917 1039
1040 // Return an AST id for an element that is used in simulate instructions.
1041 int GetIdForElement(int i) { return first_element_id_ + i; }
1042
918 private: 1043 private:
919 Handle<FixedArray> constant_elements_; 1044 Handle<FixedArray> constant_elements_;
920 ZoneList<Expression*>* values_; 1045 ZoneList<Expression*>* values_;
1046 int first_element_id_;
921 }; 1047 };
922 1048
923 1049
924 // Node for constructing a context extension object for a catch block. 1050 // Node for constructing a context extension object for a catch block.
925 // The catch context extension object has one property, the catch 1051 // The catch context extension object has one property, the catch
926 // variable, which should be DontDelete. 1052 // variable, which should be DontDelete.
927 class CatchExtensionObject: public Expression { 1053 class CatchExtensionObject: public Expression {
928 public: 1054 public:
929 CatchExtensionObject(Literal* key, VariableProxy* value) 1055 CatchExtensionObject(Literal* key, VariableProxy* value)
930 : key_(key), value_(value) { 1056 : key_(key), value_(value) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 virtual bool IsValidLeftHandSide() { 1088 virtual bool IsValidLeftHandSide() {
963 return var_ == NULL ? true : var_->IsValidLeftHandSide(); 1089 return var_ == NULL ? true : var_->IsValidLeftHandSide();
964 } 1090 }
965 1091
966 virtual bool IsTrivial() { 1092 virtual bool IsTrivial() {
967 // Reading from a mutable variable is a side effect, but the 1093 // Reading from a mutable variable is a side effect, but the
968 // variable for 'this' is immutable. 1094 // variable for 'this' is immutable.
969 return is_this_ || is_trivial_; 1095 return is_this_ || is_trivial_;
970 } 1096 }
971 1097
1098 virtual bool IsInlineable() const;
1099
972 bool IsVariable(Handle<String> n) { 1100 bool IsVariable(Handle<String> n) {
973 return !is_this() && name().is_identical_to(n); 1101 return !is_this() && name().is_identical_to(n);
974 } 1102 }
975 1103
976 bool IsArguments() { 1104 bool IsArguments() {
977 Variable* variable = AsVariable(); 1105 Variable* variable = AsVariable();
978 return (variable == NULL) ? false : variable->is_arguments(); 1106 return (variable == NULL) ? false : variable->is_arguments();
979 } 1107 }
980 1108
981 Handle<String> name() const { return name_; } 1109 Handle<String> name() const { return name_; }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 // with lookup starting at the current context. index() 1163 // with lookup starting at the current context. index()
1036 // is invalid. 1164 // is invalid.
1037 LOOKUP 1165 LOOKUP
1038 }; 1166 };
1039 1167
1040 Slot(Variable* var, Type type, int index) 1168 Slot(Variable* var, Type type, int index)
1041 : var_(var), type_(type), index_(index) { 1169 : var_(var), type_(type), index_(index) {
1042 ASSERT(var != NULL); 1170 ASSERT(var != NULL);
1043 } 1171 }
1044 1172
1045 DECLARE_NODE_TYPE(Slot) 1173 virtual void Accept(AstVisitor* v);
1174
1175 virtual Slot* AsSlot() { return this; }
1046 1176
1047 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; } 1177 bool IsStackAllocated() { return type_ == PARAMETER || type_ == LOCAL; }
1048 1178
1049 // Accessors 1179 // Accessors
1050 Variable* var() const { return var_; } 1180 Variable* var() const { return var_; }
1051 Type type() const { return type_; } 1181 Type type() const { return type_; }
1052 int index() const { return index_; } 1182 int index() const { return index_; }
1053 bool is_arguments() const { return var_->is_arguments(); } 1183 bool is_arguments() const { return var_->is_arguments(); }
1054 1184
1055 private: 1185 private:
1056 Variable* var_; 1186 Variable* var_;
1057 Type type_; 1187 Type type_;
1058 int index_; 1188 int index_;
1059 }; 1189 };
1060 1190
1061 1191
1062 class Property: public Expression { 1192 class Property: public Expression {
1063 public: 1193 public:
1064 // Synthetic properties are property lookups introduced by the system, 1194 // Synthetic properties are property lookups introduced by the system,
1065 // to objects that aren't visible to the user. Function calls to synthetic 1195 // to objects that aren't visible to the user. Function calls to synthetic
1066 // properties should use the global object as receiver, not the base object 1196 // properties should use the global object as receiver, not the base object
1067 // of the resolved Reference. 1197 // of the resolved Reference.
1068 enum Type { NORMAL, SYNTHETIC }; 1198 enum Type { NORMAL, SYNTHETIC };
1069 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL) 1199 Property(Expression* obj, Expression* key, int pos, Type type = NORMAL)
1070 : obj_(obj), key_(key), pos_(pos), type_(type) { } 1200 : obj_(obj),
1201 key_(key),
1202 pos_(pos),
1203 type_(type),
1204 is_monomorphic_(false),
1205 receiver_types_(NULL),
1206 is_array_length_(false),
1207 is_arguments_access_(false) { }
1071 1208
1072 DECLARE_NODE_TYPE(Property) 1209 DECLARE_NODE_TYPE(Property)
1073 1210
1074 virtual bool IsValidLeftHandSide() { return true; } 1211 virtual bool IsValidLeftHandSide() { return true; }
1212 virtual bool IsInlineable() const;
1075 1213
1076 Expression* obj() const { return obj_; } 1214 Expression* obj() const { return obj_; }
1077 Expression* key() const { return key_; } 1215 Expression* key() const { return key_; }
1078 int position() const { return pos_; } 1216 int position() const { return pos_; }
1079 bool is_synthetic() const { return type_ == SYNTHETIC; } 1217 bool is_synthetic() const { return type_ == SYNTHETIC; }
1080 1218
1219 // Marks that this is actually an argument rewritten to a keyed property
1220 // accessing the argument through the arguments shadow object.
1221 void set_is_arguments_access(bool is_arguments_access) {
1222 is_arguments_access_ = is_arguments_access;
1223 }
1224 bool is_arguments_access() const { return is_arguments_access_; }
1225
1226 // Type feedback information.
1227 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1228 virtual bool IsMonomorphic() { return is_monomorphic_; }
1229 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
1230 virtual bool IsArrayLength() { return is_array_length_; }
1231 virtual Handle<Map> GetMonomorphicReceiverType() {
1232 return monomorphic_receiver_type_;
1233 }
1234
1081 private: 1235 private:
1082 Expression* obj_; 1236 Expression* obj_;
1083 Expression* key_; 1237 Expression* key_;
1084 int pos_; 1238 int pos_;
1085 Type type_; 1239 Type type_;
1240
1241 bool is_monomorphic_;
1242 ZoneMapList* receiver_types_;
1243 bool is_array_length_;
1244 bool is_arguments_access_;
1245 Handle<Map> monomorphic_receiver_type_;
1086 }; 1246 };
1087 1247
1088 1248
1089 class Call: public Expression { 1249 class Call: public Expression {
1090 public: 1250 public:
1091 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1251 Call(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1092 : expression_(expression), arguments_(arguments), pos_(pos) { } 1252 : expression_(expression),
1253 arguments_(arguments),
1254 pos_(pos),
1255 is_monomorphic_(false),
1256 receiver_types_(NULL),
1257 return_id_(GetNextId()) {
1258 }
1093 1259
1094 DECLARE_NODE_TYPE(Call) 1260 DECLARE_NODE_TYPE(Call)
1095 1261
1262 virtual bool IsInlineable() const;
1263
1096 Expression* expression() const { return expression_; } 1264 Expression* expression() const { return expression_; }
1097 ZoneList<Expression*>* arguments() const { return arguments_; } 1265 ZoneList<Expression*>* arguments() const { return arguments_; }
1098 int position() const { return pos_; } 1266 int position() { return pos_; }
1267
1268 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1269 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
1270 virtual bool IsMonomorphic() { return is_monomorphic_; }
1271 Handle<JSFunction> target() { return target_; }
1272 Handle<JSObject> holder() { return holder_; }
1273 Handle<JSGlobalPropertyCell> cell() { return cell_; }
1274
1275 bool ComputeTarget(Handle<Map> type, Handle<String> name);
1276 bool ComputeGlobalTarget(Handle<GlobalObject> global, Handle<String> name);
1277
1278 // Bailout support.
1279 int ReturnId() const { return return_id_; }
1280
1281 #ifdef DEBUG
1282 // Used to assert that the FullCodeGenerator records the return site.
1283 bool return_is_recorded_;
1284 #endif
1099 1285
1100 private: 1286 private:
1101 Expression* expression_; 1287 Expression* expression_;
1102 ZoneList<Expression*>* arguments_; 1288 ZoneList<Expression*>* arguments_;
1103 int pos_; 1289 int pos_;
1290
1291 bool is_monomorphic_;
1292 ZoneMapList* receiver_types_;
1293 Handle<JSFunction> target_;
1294 Handle<JSObject> holder_;
1295 Handle<JSGlobalPropertyCell> cell_;
1296
1297 int return_id_;
1104 }; 1298 };
1105 1299
1106 1300
1107 class AstSentinels { 1301 class AstSentinels {
1108 public: 1302 public:
1109 ~AstSentinels() { } 1303 ~AstSentinels() { }
1110 1304
1111 // Returns a property singleton property access on 'this'. Used 1305 // Returns a property singleton property access on 'this'. Used
1112 // during preparsing. 1306 // during preparsing.
1113 Property* this_property() { return &this_property_; } 1307 Property* this_property() { return &this_property_; }
(...skipping 20 matching lines...) Expand all
1134 }; 1328 };
1135 1329
1136 1330
1137 class CallNew: public Expression { 1331 class CallNew: public Expression {
1138 public: 1332 public:
1139 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos) 1333 CallNew(Expression* expression, ZoneList<Expression*>* arguments, int pos)
1140 : expression_(expression), arguments_(arguments), pos_(pos) { } 1334 : expression_(expression), arguments_(arguments), pos_(pos) { }
1141 1335
1142 DECLARE_NODE_TYPE(CallNew) 1336 DECLARE_NODE_TYPE(CallNew)
1143 1337
1338 virtual bool IsInlineable() const;
1339
1144 Expression* expression() const { return expression_; } 1340 Expression* expression() const { return expression_; }
1145 ZoneList<Expression*>* arguments() const { return arguments_; } 1341 ZoneList<Expression*>* arguments() const { return arguments_; }
1146 int position() { return pos_; } 1342 int position() { return pos_; }
1147 1343
1148 private: 1344 private:
1149 Expression* expression_; 1345 Expression* expression_;
1150 ZoneList<Expression*>* arguments_; 1346 ZoneList<Expression*>* arguments_;
1151 int pos_; 1347 int pos_;
1152 }; 1348 };
1153 1349
1154 1350
1155 // The CallRuntime class does not represent any official JavaScript 1351 // The CallRuntime class does not represent any official JavaScript
1156 // language construct. Instead it is used to call a C or JS function 1352 // language construct. Instead it is used to call a C or JS function
1157 // with a set of arguments. This is used from the builtins that are 1353 // with a set of arguments. This is used from the builtins that are
1158 // implemented in JavaScript (see "v8natives.js"). 1354 // implemented in JavaScript (see "v8natives.js").
1159 class CallRuntime: public Expression { 1355 class CallRuntime: public Expression {
1160 public: 1356 public:
1161 CallRuntime(Handle<String> name, 1357 CallRuntime(Handle<String> name,
1162 const Runtime::Function* function, 1358 const Runtime::Function* function,
1163 ZoneList<Expression*>* arguments) 1359 ZoneList<Expression*>* arguments)
1164 : name_(name), function_(function), arguments_(arguments) { } 1360 : name_(name), function_(function), arguments_(arguments) { }
1165 1361
1166 DECLARE_NODE_TYPE(CallRuntime) 1362 DECLARE_NODE_TYPE(CallRuntime)
1167 1363
1364 virtual bool IsInlineable() const;
1365
1168 Handle<String> name() const { return name_; } 1366 Handle<String> name() const { return name_; }
1169 const Runtime::Function* function() const { return function_; } 1367 const Runtime::Function* function() const { return function_; }
1170 ZoneList<Expression*>* arguments() const { return arguments_; } 1368 ZoneList<Expression*>* arguments() const { return arguments_; }
1171 bool is_jsruntime() const { return function_ == NULL; } 1369 bool is_jsruntime() const { return function_ == NULL; }
1172 1370
1173 private: 1371 private:
1174 Handle<String> name_; 1372 Handle<String> name_;
1175 const Runtime::Function* function_; 1373 const Runtime::Function* function_;
1176 ZoneList<Expression*>* arguments_; 1374 ZoneList<Expression*>* arguments_;
1177 }; 1375 };
1178 1376
1179 1377
1180 class UnaryOperation: public Expression { 1378 class UnaryOperation: public Expression {
1181 public: 1379 public:
1182 UnaryOperation(Token::Value op, Expression* expression) 1380 UnaryOperation(Token::Value op, Expression* expression)
1183 : op_(op), expression_(expression) { 1381 : op_(op), expression_(expression) {
1184 ASSERT(Token::IsUnaryOp(op)); 1382 ASSERT(Token::IsUnaryOp(op));
1185 } 1383 }
1186 1384
1187 DECLARE_NODE_TYPE(UnaryOperation) 1385 DECLARE_NODE_TYPE(UnaryOperation)
1188 1386
1387 virtual bool IsInlineable() const;
1388
1189 virtual bool ResultOverwriteAllowed(); 1389 virtual bool ResultOverwriteAllowed();
1190 1390
1191 Token::Value op() const { return op_; } 1391 Token::Value op() const { return op_; }
1192 Expression* expression() const { return expression_; } 1392 Expression* expression() const { return expression_; }
1193 1393
1194 private: 1394 private:
1195 Token::Value op_; 1395 Token::Value op_;
1196 Expression* expression_; 1396 Expression* expression_;
1197 }; 1397 };
1198 1398
1199 1399
1200 class BinaryOperation: public Expression { 1400 class BinaryOperation: public Expression {
1201 public: 1401 public:
1202 BinaryOperation(Token::Value op, 1402 BinaryOperation(Token::Value op,
1203 Expression* left, 1403 Expression* left,
1204 Expression* right, 1404 Expression* right,
1205 int pos) 1405 int pos)
1206 : op_(op), left_(left), right_(right), pos_(pos) { 1406 : op_(op), left_(left), right_(right), pos_(pos), is_smi_only_(false) {
1207 ASSERT(Token::IsBinaryOp(op)); 1407 ASSERT(Token::IsBinaryOp(op));
1208 } 1408 }
1209 1409
1210 // Create the binary operation corresponding to a compound assignment. 1410 // Create the binary operation corresponding to a compound assignment.
1211 explicit BinaryOperation(Assignment* assignment); 1411 explicit BinaryOperation(Assignment* assignment);
1212 1412
1213 DECLARE_NODE_TYPE(BinaryOperation) 1413 DECLARE_NODE_TYPE(BinaryOperation)
1214 1414
1415 virtual bool IsInlineable() const;
1416
1215 virtual bool ResultOverwriteAllowed(); 1417 virtual bool ResultOverwriteAllowed();
1216 1418
1217 Token::Value op() const { return op_; } 1419 Token::Value op() const { return op_; }
1218 Expression* left() const { return left_; } 1420 Expression* left() const { return left_; }
1219 Expression* right() const { return right_; } 1421 Expression* right() const { return right_; }
1220 int position() const { return pos_; } 1422 int position() const { return pos_; }
1221 1423
1424 // Type feedback information.
1425 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1426 bool IsSmiOnly() const { return is_smi_only_; }
1427
1222 private: 1428 private:
1223 Token::Value op_; 1429 Token::Value op_;
1224 Expression* left_; 1430 Expression* left_;
1225 Expression* right_; 1431 Expression* right_;
1226 int pos_; 1432 int pos_;
1433 bool is_smi_only_;
1227 }; 1434 };
1228 1435
1229 1436
1230 class IncrementOperation: public Expression { 1437 class IncrementOperation: public Expression {
1231 public: 1438 public:
1232 IncrementOperation(Token::Value op, Expression* expr) 1439 IncrementOperation(Token::Value op, Expression* expr)
1233 : op_(op), expression_(expr) { 1440 : op_(op), expression_(expr) {
1234 ASSERT(Token::IsCountOp(op)); 1441 ASSERT(Token::IsCountOp(op));
1235 } 1442 }
1236 1443
(...skipping 24 matching lines...) Expand all
1261 Token::Value binary_op() { 1468 Token::Value binary_op() {
1262 return (op() == Token::INC) ? Token::ADD : Token::SUB; 1469 return (op() == Token::INC) ? Token::ADD : Token::SUB;
1263 } 1470 }
1264 1471
1265 Expression* expression() const { return increment_->expression(); } 1472 Expression* expression() const { return increment_->expression(); }
1266 IncrementOperation* increment() const { return increment_; } 1473 IncrementOperation* increment() const { return increment_; }
1267 int position() const { return pos_; } 1474 int position() const { return pos_; }
1268 1475
1269 virtual void MarkAsStatement() { is_prefix_ = true; } 1476 virtual void MarkAsStatement() { is_prefix_ = true; }
1270 1477
1478 virtual bool IsInlineable() const;
1479
1271 private: 1480 private:
1272 bool is_prefix_; 1481 bool is_prefix_;
1273 IncrementOperation* increment_; 1482 IncrementOperation* increment_;
1274 int pos_; 1483 int pos_;
1275 }; 1484 };
1276 1485
1277 1486
1278 class CompareOperation: public Expression { 1487 class CompareOperation: public Expression {
1279 public: 1488 public:
1280 CompareOperation(Token::Value op, 1489 CompareOperation(Token::Value op,
1281 Expression* left, 1490 Expression* left,
1282 Expression* right, 1491 Expression* right,
1283 int pos) 1492 int pos)
1284 : op_(op), left_(left), right_(right), pos_(pos) { 1493 : op_(op), left_(left), right_(right), pos_(pos), compare_type_(NONE) {
1285 ASSERT(Token::IsCompareOp(op)); 1494 ASSERT(Token::IsCompareOp(op));
1286 } 1495 }
1287 1496
1288 DECLARE_NODE_TYPE(CompareOperation) 1497 DECLARE_NODE_TYPE(CompareOperation)
1289 1498
1290 Token::Value op() const { return op_; } 1499 Token::Value op() const { return op_; }
1291 Expression* left() const { return left_; } 1500 Expression* left() const { return left_; }
1292 Expression* right() const { return right_; } 1501 Expression* right() const { return right_; }
1293 int position() const { return pos_; } 1502 int position() const { return pos_; }
1294 1503
1504 virtual bool IsInlineable() const;
1505
1506 // Type feedback information.
1507 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1508 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; }
1509 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; }
1510
1295 private: 1511 private:
1296 Token::Value op_; 1512 Token::Value op_;
1297 Expression* left_; 1513 Expression* left_;
1298 Expression* right_; 1514 Expression* right_;
1299 int pos_; 1515 int pos_;
1516
1517 enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY };
1518 CompareTypeFeedback compare_type_;
1300 }; 1519 };
1301 1520
1302 1521
1303 class CompareToNull: public Expression { 1522 class CompareToNull: public Expression {
1304 public: 1523 public:
1305 CompareToNull(bool is_strict, Expression* expression) 1524 CompareToNull(bool is_strict, Expression* expression)
1306 : is_strict_(is_strict), expression_(expression) { } 1525 : is_strict_(is_strict), expression_(expression) { }
1307 1526
1308 DECLARE_NODE_TYPE(CompareToNull) 1527 DECLARE_NODE_TYPE(CompareToNull)
1309 1528
1529 virtual bool IsInlineable() const;
1530
1310 bool is_strict() const { return is_strict_; } 1531 bool is_strict() const { return is_strict_; }
1311 Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; } 1532 Token::Value op() const { return is_strict_ ? Token::EQ_STRICT : Token::EQ; }
1312 Expression* expression() const { return expression_; } 1533 Expression* expression() const { return expression_; }
1313 1534
1314 private: 1535 private:
1315 bool is_strict_; 1536 bool is_strict_;
1316 Expression* expression_; 1537 Expression* expression_;
1317 }; 1538 };
1318 1539
1319 1540
1320 class Conditional: public Expression { 1541 class Conditional: public Expression {
1321 public: 1542 public:
1322 Conditional(Expression* condition, 1543 Conditional(Expression* condition,
1323 Expression* then_expression, 1544 Expression* then_expression,
1324 Expression* else_expression, 1545 Expression* else_expression,
1325 int then_expression_position, 1546 int then_expression_position,
1326 int else_expression_position) 1547 int else_expression_position)
1327 : condition_(condition), 1548 : condition_(condition),
1328 then_expression_(then_expression), 1549 then_expression_(then_expression),
1329 else_expression_(else_expression), 1550 else_expression_(else_expression),
1330 then_expression_position_(then_expression_position), 1551 then_expression_position_(then_expression_position),
1331 else_expression_position_(else_expression_position) { } 1552 else_expression_position_(else_expression_position) { }
1332 1553
1333 DECLARE_NODE_TYPE(Conditional) 1554 DECLARE_NODE_TYPE(Conditional)
1334 1555
1556 virtual bool IsInlineable() const;
1557
1335 Expression* condition() const { return condition_; } 1558 Expression* condition() const { return condition_; }
1336 Expression* then_expression() const { return then_expression_; } 1559 Expression* then_expression() const { return then_expression_; }
1337 Expression* else_expression() const { return else_expression_; } 1560 Expression* else_expression() const { return else_expression_; }
1338 1561
1339 int then_expression_position() { return then_expression_position_; } 1562 int then_expression_position() { return then_expression_position_; }
1340 int else_expression_position() { return else_expression_position_; } 1563 int else_expression_position() { return else_expression_position_; }
1341 1564
1342 private: 1565 private:
1343 Expression* condition_; 1566 Expression* condition_;
1344 Expression* then_expression_; 1567 Expression* then_expression_;
1345 Expression* else_expression_; 1568 Expression* else_expression_;
1346 int then_expression_position_; 1569 int then_expression_position_;
1347 int else_expression_position_; 1570 int else_expression_position_;
1348 }; 1571 };
1349 1572
1350 1573
1351 class Assignment: public Expression { 1574 class Assignment: public Expression {
1352 public: 1575 public:
1353 Assignment(Token::Value op, Expression* target, Expression* value, int pos) 1576 Assignment(Token::Value op, Expression* target, Expression* value, int pos);
1354 : op_(op), target_(target), value_(value), pos_(pos),
1355 block_start_(false), block_end_(false) {
1356 ASSERT(Token::IsAssignmentOp(op));
1357 }
1358 1577
1359 DECLARE_NODE_TYPE(Assignment) 1578 DECLARE_NODE_TYPE(Assignment)
1360 1579
1580 virtual bool IsInlineable() const;
1581
1361 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } 1582 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; }
1362 1583
1363 Token::Value binary_op() const; 1584 Token::Value binary_op() const;
1364 1585
1365 Token::Value op() const { return op_; } 1586 Token::Value op() const { return op_; }
1366 Expression* target() const { return target_; } 1587 Expression* target() const { return target_; }
1367 Expression* value() const { return value_; } 1588 Expression* value() const { return value_; }
1368 int position() { return pos_; } 1589 int position() { return pos_; }
1590 BinaryOperation* binary_operation() const { return binary_operation_; }
1591
1369 // This check relies on the definition order of token in token.h. 1592 // This check relies on the definition order of token in token.h.
1370 bool is_compound() const { return op() > Token::ASSIGN; } 1593 bool is_compound() const { return op() > Token::ASSIGN; }
1371 1594
1372 // An initialization block is a series of statments of the form 1595 // An initialization block is a series of statments of the form
1373 // x.y.z.a = ...; x.y.z.b = ...; etc. The parser marks the beginning and 1596 // x.y.z.a = ...; x.y.z.b = ...; etc. The parser marks the beginning and
1374 // ending of these blocks to allow for optimizations of initialization 1597 // ending of these blocks to allow for optimizations of initialization
1375 // blocks. 1598 // blocks.
1376 bool starts_initialization_block() { return block_start_; } 1599 bool starts_initialization_block() { return block_start_; }
1377 bool ends_initialization_block() { return block_end_; } 1600 bool ends_initialization_block() { return block_end_; }
1378 void mark_block_start() { block_start_ = true; } 1601 void mark_block_start() { block_start_ = true; }
1379 void mark_block_end() { block_end_ = true; } 1602 void mark_block_end() { block_end_ = true; }
1380 1603
1604 // Type feedback information.
1605 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1606 virtual bool IsMonomorphic() { return is_monomorphic_; }
1607 virtual ZoneMapList* GetReceiverTypes() { return receiver_types_; }
1608 virtual Handle<Map> GetMonomorphicReceiverType() {
1609 return monomorphic_receiver_type_;
1610 }
1611
1612 // Bailout support.
1613 int compound_bailout_id() const { return compound_bailout_id_; }
1614
1381 private: 1615 private:
1382 Token::Value op_; 1616 Token::Value op_;
1383 Expression* target_; 1617 Expression* target_;
1384 Expression* value_; 1618 Expression* value_;
1385 int pos_; 1619 int pos_;
1620 BinaryOperation* binary_operation_;
1621 int compound_bailout_id_;
1622
1386 bool block_start_; 1623 bool block_start_;
1387 bool block_end_; 1624 bool block_end_;
1625
1626 bool is_monomorphic_;
1627 ZoneMapList* receiver_types_;
1628 Handle<Map> monomorphic_receiver_type_;
1388 }; 1629 };
1389 1630
1390 1631
1391 class Throw: public Expression { 1632 class Throw: public Expression {
1392 public: 1633 public:
1393 Throw(Expression* exception, int pos) 1634 Throw(Expression* exception, int pos)
1394 : exception_(exception), pos_(pos) {} 1635 : exception_(exception), pos_(pos) {}
1395 1636
1396 DECLARE_NODE_TYPE(Throw) 1637 DECLARE_NODE_TYPE(Throw)
1397 1638
(...skipping 29 matching lines...) Expand all
1427 has_only_simple_this_property_assignments), 1668 has_only_simple_this_property_assignments),
1428 this_property_assignments_(this_property_assignments), 1669 this_property_assignments_(this_property_assignments),
1429 num_parameters_(num_parameters), 1670 num_parameters_(num_parameters),
1430 start_position_(start_position), 1671 start_position_(start_position),
1431 end_position_(end_position), 1672 end_position_(end_position),
1432 is_expression_(is_expression), 1673 is_expression_(is_expression),
1433 contains_loops_(contains_loops), 1674 contains_loops_(contains_loops),
1434 function_token_position_(RelocInfo::kNoPosition), 1675 function_token_position_(RelocInfo::kNoPosition),
1435 inferred_name_(HEAP->empty_string()), 1676 inferred_name_(HEAP->empty_string()),
1436 try_full_codegen_(false), 1677 try_full_codegen_(false),
1437 pretenure_(false) { 1678 pretenure_(false) { }
1438 #ifdef DEBUG
1439 already_compiled_ = false;
1440 #endif
1441 }
1442 1679
1443 DECLARE_NODE_TYPE(FunctionLiteral) 1680 DECLARE_NODE_TYPE(FunctionLiteral)
1444 1681
1445 Handle<String> name() const { return name_; } 1682 Handle<String> name() const { return name_; }
1446 Scope* scope() const { return scope_; } 1683 Scope* scope() const { return scope_; }
1447 ZoneList<Statement*>* body() const { return body_; } 1684 ZoneList<Statement*>* body() const { return body_; }
1448 void set_function_token_position(int pos) { function_token_position_ = pos; } 1685 void set_function_token_position(int pos) { function_token_position_ = pos; }
1449 int function_token_position() const { return function_token_position_; } 1686 int function_token_position() const { return function_token_position_; }
1450 int start_position() const { return start_position_; } 1687 int start_position() const { return start_position_; }
1451 int end_position() const { return end_position_; } 1688 int end_position() const { return end_position_; }
1452 bool is_expression() const { return is_expression_; } 1689 bool is_expression() const { return is_expression_; }
1453 bool contains_loops() const { return contains_loops_; } 1690 bool contains_loops() const { return contains_loops_; }
1454 1691
1455 int materialized_literal_count() { return materialized_literal_count_; } 1692 int materialized_literal_count() { return materialized_literal_count_; }
1456 int expected_property_count() { return expected_property_count_; } 1693 int expected_property_count() { return expected_property_count_; }
1457 bool has_only_simple_this_property_assignments() { 1694 bool has_only_simple_this_property_assignments() {
1458 return has_only_simple_this_property_assignments_; 1695 return has_only_simple_this_property_assignments_;
1459 } 1696 }
1460 Handle<FixedArray> this_property_assignments() { 1697 Handle<FixedArray> this_property_assignments() {
1461 return this_property_assignments_; 1698 return this_property_assignments_;
1462 } 1699 }
1463 int num_parameters() { return num_parameters_; } 1700 int num_parameters() { return num_parameters_; }
1464 1701
1465 bool AllowsLazyCompilation(); 1702 bool AllowsLazyCompilation();
1703 bool AllowOptimize();
1466 1704
1467 Handle<String> debug_name() const { 1705 Handle<String> debug_name() const {
1468 if (name_->length() > 0) return name_; 1706 if (name_->length() > 0) return name_;
1469 return inferred_name(); 1707 return inferred_name();
1470 } 1708 }
1471 1709
1472 Handle<String> inferred_name() const { return inferred_name_; } 1710 Handle<String> inferred_name() const { return inferred_name_; }
1473 void set_inferred_name(Handle<String> inferred_name) { 1711 void set_inferred_name(Handle<String> inferred_name) {
1474 inferred_name_ = inferred_name; 1712 inferred_name_ = inferred_name;
1475 } 1713 }
1476 1714
1477 bool try_full_codegen() { return try_full_codegen_; } 1715 bool try_full_codegen() { return try_full_codegen_; }
1478 void set_try_full_codegen(bool flag) { try_full_codegen_ = flag; } 1716 void set_try_full_codegen(bool flag) { try_full_codegen_ = flag; }
1479 1717
1480 bool pretenure() { return pretenure_; } 1718 bool pretenure() { return pretenure_; }
1481 void set_pretenure(bool value) { pretenure_ = value; } 1719 void set_pretenure(bool value) { pretenure_ = value; }
1482 1720
1483 #ifdef DEBUG
1484 void mark_as_compiled() {
1485 ASSERT(!already_compiled_);
1486 already_compiled_ = true;
1487 }
1488 #endif
1489
1490 private: 1721 private:
1491 Handle<String> name_; 1722 Handle<String> name_;
1492 Scope* scope_; 1723 Scope* scope_;
1493 ZoneList<Statement*>* body_; 1724 ZoneList<Statement*>* body_;
1494 int materialized_literal_count_; 1725 int materialized_literal_count_;
1495 int expected_property_count_; 1726 int expected_property_count_;
1496 bool has_only_simple_this_property_assignments_; 1727 bool has_only_simple_this_property_assignments_;
1497 Handle<FixedArray> this_property_assignments_; 1728 Handle<FixedArray> this_property_assignments_;
1498 int num_parameters_; 1729 int num_parameters_;
1499 int start_position_; 1730 int start_position_;
1500 int end_position_; 1731 int end_position_;
1501 bool is_expression_; 1732 bool is_expression_;
1502 bool contains_loops_; 1733 bool contains_loops_;
1503 int function_token_position_; 1734 int function_token_position_;
1504 Handle<String> inferred_name_; 1735 Handle<String> inferred_name_;
1505 bool try_full_codegen_; 1736 bool try_full_codegen_;
1506 bool pretenure_; 1737 bool pretenure_;
1507 #ifdef DEBUG
1508 bool already_compiled_;
1509 #endif
1510 }; 1738 };
1511 1739
1512 1740
1513 class SharedFunctionInfoLiteral: public Expression { 1741 class SharedFunctionInfoLiteral: public Expression {
1514 public: 1742 public:
1515 explicit SharedFunctionInfoLiteral( 1743 explicit SharedFunctionInfoLiteral(
1516 Handle<SharedFunctionInfo> shared_function_info) 1744 Handle<SharedFunctionInfo> shared_function_info)
1517 : shared_function_info_(shared_function_info) { } 1745 : shared_function_info_(shared_function_info) { }
1518 1746
1519 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) 1747 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral)
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 virtual void VisitExpressions(ZoneList<Expression*>* expressions); 2132 virtual void VisitExpressions(ZoneList<Expression*>* expressions);
1905 2133
1906 // Stack overflow tracking support. 2134 // Stack overflow tracking support.
1907 bool HasStackOverflow() const { return stack_overflow_; } 2135 bool HasStackOverflow() const { return stack_overflow_; }
1908 bool CheckStackOverflow(); 2136 bool CheckStackOverflow();
1909 2137
1910 // If a stack-overflow exception is encountered when visiting a 2138 // If a stack-overflow exception is encountered when visiting a
1911 // node, calling SetStackOverflow will make sure that the visitor 2139 // node, calling SetStackOverflow will make sure that the visitor
1912 // bails out without visiting more nodes. 2140 // bails out without visiting more nodes.
1913 void SetStackOverflow() { stack_overflow_ = true; } 2141 void SetStackOverflow() { stack_overflow_ = true; }
2142 void ClearStackOverflow() { stack_overflow_ = false; }
1914 2143
1915 // Individual nodes 2144 // Nodes not appearing in the AST, including slots.
2145 virtual void VisitSlot(Slot* node) { UNREACHABLE(); }
2146
2147 // Individual AST nodes.
1916 #define DEF_VISIT(type) \ 2148 #define DEF_VISIT(type) \
1917 virtual void Visit##type(type* node) = 0; 2149 virtual void Visit##type(type* node) = 0;
1918 AST_NODE_LIST(DEF_VISIT) 2150 AST_NODE_LIST(DEF_VISIT)
1919 #undef DEF_VISIT 2151 #undef DEF_VISIT
1920 2152
1921 private: 2153 private:
1922 bool stack_overflow_; 2154 bool stack_overflow_;
1923 }; 2155 };
1924 2156
1925 2157
1926 } } // namespace v8::internal 2158 } } // namespace v8::internal
1927 2159
1928 #endif // V8_AST_H_ 2160 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/assembler.cc ('k') | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698