| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (switch_type == SwitchStatement::SMI_SWITCH) { | 199 if (switch_type == SwitchStatement::SMI_SWITCH) { |
| 200 for (int i = 0; i < clauses->length(); ++i) { | 200 for (int i = 0; i < clauses->length(); ++i) { |
| 201 CaseClause* clause = clauses->at(i); | 201 CaseClause* clause = clauses->at(i); |
| 202 if (!clause->is_default()) | 202 if (!clause->is_default()) |
| 203 clause->RecordTypeFeedback(oracle()); | 203 clause->RecordTypeFeedback(oracle()); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 | 208 |
| 209 void AstTyper::VisitCaseClause(CaseClause* clause) { |
| 210 UNREACHABLE(); |
| 211 } |
| 212 |
| 213 |
| 209 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { | 214 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 210 // Collect type feedback. | 215 // Collect type feedback. |
| 211 if (!stmt->cond()->ToBooleanIsTrue()) { | 216 if (!stmt->cond()->ToBooleanIsTrue()) { |
| 212 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); | 217 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); |
| 213 } | 218 } |
| 214 | 219 |
| 215 // TODO(rossberg): refine the unconditional Forget (here and elsewhere) by | 220 // TODO(rossberg): refine the unconditional Forget (here and elsewhere) by |
| 216 // computing the set of variables assigned in only some of the origins of the | 221 // computing the set of variables assigned in only some of the origins of the |
| 217 // control transfer (such as the loop body here). | 222 // control transfer (such as the loop body here). |
| 218 store_.Forget(); // Control may transfer here via looping or 'continue'. | 223 store_.Forget(); // Control may transfer here via looping or 'continue'. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 240 RECURSE(Visit(stmt->init())); | 245 RECURSE(Visit(stmt->init())); |
| 241 } | 246 } |
| 242 store_.Forget(); // Control may transfer here via looping. | 247 store_.Forget(); // Control may transfer here via looping. |
| 243 if (stmt->cond() != NULL) { | 248 if (stmt->cond() != NULL) { |
| 244 // Collect type feedback. | 249 // Collect type feedback. |
| 245 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); | 250 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); |
| 246 | 251 |
| 247 RECURSE(Visit(stmt->cond())); | 252 RECURSE(Visit(stmt->cond())); |
| 248 } | 253 } |
| 249 RECURSE(Visit(stmt->body())); | 254 RECURSE(Visit(stmt->body())); |
| 250 store_.Forget(); // Control may transfer here via 'continue'. | |
| 251 if (stmt->next() != NULL) { | 255 if (stmt->next() != NULL) { |
| 256 store_.Forget(); // Control may transfer here via 'continue'. |
| 252 RECURSE(Visit(stmt->next())); | 257 RECURSE(Visit(stmt->next())); |
| 253 } | 258 } |
| 254 store_.Forget(); // Control may transfer here via termination or 'break'. | 259 store_.Forget(); // Control may transfer here via termination or 'break'. |
| 255 } | 260 } |
| 256 | 261 |
| 257 | 262 |
| 258 void AstTyper::VisitForInStatement(ForInStatement* stmt) { | 263 void AstTyper::VisitForInStatement(ForInStatement* stmt) { |
| 259 // Collect type feedback. | 264 // Collect type feedback. |
| 260 stmt->RecordTypeFeedback(oracle()); | 265 stmt->RecordTypeFeedback(oracle()); |
| 261 | 266 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 store_.Seq(left_effects); | 575 store_.Seq(left_effects); |
| 571 | 576 |
| 572 NarrowType(expr, Bounds::Either( | 577 NarrowType(expr, Bounds::Either( |
| 573 expr->left()->bounds(), expr->right()->bounds(), isolate_)); | 578 expr->left()->bounds(), expr->right()->bounds(), isolate_)); |
| 574 break; | 579 break; |
| 575 } | 580 } |
| 576 case Token::BIT_OR: | 581 case Token::BIT_OR: |
| 577 case Token::BIT_AND: { | 582 case Token::BIT_AND: { |
| 578 RECURSE(Visit(expr->left())); | 583 RECURSE(Visit(expr->left())); |
| 579 RECURSE(Visit(expr->right())); | 584 RECURSE(Visit(expr->right())); |
| 580 Type* upper = Type::Union( | 585 Handle<Type> upper( |
| 581 expr->left()->bounds().upper, expr->right()->bounds().upper); | 586 Type::Union( |
| 582 if (!upper->Is(Type::Signed32())) upper = Type::Signed32(); | 587 expr->left()->bounds().upper, expr->right()->bounds().upper), |
| 583 NarrowType(expr, Bounds(Type::Smi(), upper, isolate_)); | 588 isolate_); |
| 589 if (!upper->Is(Type::Signed32())) |
| 590 upper = handle(Type::Signed32(), isolate_); |
| 591 Handle<Type> lower(Type::Intersect( |
| 592 handle(Type::Smi(), isolate_), upper), isolate_); |
| 593 NarrowType(expr, Bounds(lower, upper)); |
| 584 break; | 594 break; |
| 585 } | 595 } |
| 586 case Token::BIT_XOR: | 596 case Token::BIT_XOR: |
| 587 case Token::SHL: | 597 case Token::SHL: |
| 588 case Token::SAR: | 598 case Token::SAR: |
| 589 RECURSE(Visit(expr->left())); | 599 RECURSE(Visit(expr->left())); |
| 590 RECURSE(Visit(expr->right())); | 600 RECURSE(Visit(expr->right())); |
| 591 NarrowType(expr, Bounds(Type::Smi(), Type::Signed32(), isolate_)); | 601 NarrowType(expr, Bounds(Type::Smi(), Type::Signed32(), isolate_)); |
| 592 break; | 602 break; |
| 593 case Token::SHR: | 603 case Token::SHR: |
| 594 RECURSE(Visit(expr->left())); | 604 RECURSE(Visit(expr->left())); |
| 595 RECURSE(Visit(expr->right())); | 605 RECURSE(Visit(expr->right())); |
| 596 NarrowType(expr, Bounds(Type::Smi(), Type::Unsigned32(), isolate_)); | 606 // TODO(rossberg): The upper bound would be Unsigned32, but since there |
| 607 // is no 'positive Smi' type for the lower bound, we use the smallest |
| 608 // union of Smi and Unsigned32 as upper bound instead. |
| 609 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_)); |
| 597 break; | 610 break; |
| 598 case Token::ADD: { | 611 case Token::ADD: { |
| 599 RECURSE(Visit(expr->left())); | 612 RECURSE(Visit(expr->left())); |
| 600 RECURSE(Visit(expr->right())); | 613 RECURSE(Visit(expr->right())); |
| 601 Bounds l = expr->left()->bounds(); | 614 Bounds l = expr->left()->bounds(); |
| 602 Bounds r = expr->right()->bounds(); | 615 Bounds r = expr->right()->bounds(); |
| 603 Type* lower = | 616 Type* lower = |
| 617 l.lower->Is(Type::None()) || r.lower->Is(Type::None()) ? |
| 618 Type::None() : |
| 619 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? |
| 620 Type::String() : |
| 604 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? | 621 l.lower->Is(Type::Number()) && r.lower->Is(Type::Number()) ? |
| 605 Type::Smi() : | 622 Type::Smi() : Type::None(); |
| 606 l.lower->Is(Type::String()) || r.lower->Is(Type::String()) ? | |
| 607 Type::String() : Type::None(); | |
| 608 Type* upper = | 623 Type* upper = |
| 624 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? |
| 625 Type::String() : |
| 609 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? | 626 l.upper->Is(Type::Number()) && r.upper->Is(Type::Number()) ? |
| 610 Type::Number() : | 627 Type::Number() : Type::NumberOrString(); |
| 611 l.upper->Is(Type::String()) || r.upper->Is(Type::String()) ? | |
| 612 Type::String() : Type::NumberOrString(); | |
| 613 NarrowType(expr, Bounds(lower, upper, isolate_)); | 628 NarrowType(expr, Bounds(lower, upper, isolate_)); |
| 614 break; | 629 break; |
| 615 } | 630 } |
| 616 case Token::SUB: | 631 case Token::SUB: |
| 617 case Token::MUL: | 632 case Token::MUL: |
| 618 case Token::DIV: | 633 case Token::DIV: |
| 619 case Token::MOD: | 634 case Token::MOD: |
| 620 RECURSE(Visit(expr->left())); | 635 RECURSE(Visit(expr->left())); |
| 621 RECURSE(Visit(expr->right())); | 636 RECURSE(Visit(expr->right())); |
| 622 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_)); | 637 NarrowType(expr, Bounds(Type::Smi(), Type::Number(), isolate_)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 void AstTyper::VisitModuleUrl(ModuleUrl* module) { | 710 void AstTyper::VisitModuleUrl(ModuleUrl* module) { |
| 696 } | 711 } |
| 697 | 712 |
| 698 | 713 |
| 699 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { | 714 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { |
| 700 RECURSE(Visit(stmt->body())); | 715 RECURSE(Visit(stmt->body())); |
| 701 } | 716 } |
| 702 | 717 |
| 703 | 718 |
| 704 } } // namespace v8::internal | 719 } } // namespace v8::internal |
| OLD | NEW |