Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_TYPES_H_ | 5 #ifndef V8_COMPILER_TYPES_H_ |
| 6 #define V8_COMPILER_TYPES_H_ | 6 #define V8_COMPILER_TYPES_H_ |
| 7 | 7 |
| 8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 } | 506 } |
| 507 static Type* For(i::Handle<i::Map> map) { return For(*map); } | 507 static Type* For(i::Handle<i::Map> map) { return For(*map); } |
| 508 | 508 |
| 509 // Predicates. | 509 // Predicates. |
| 510 bool IsInhabited() { return BitsetType::IsInhabited(this->BitsetLub()); } | 510 bool IsInhabited() { return BitsetType::IsInhabited(this->BitsetLub()); } |
| 511 | 511 |
| 512 bool Is(Type* that) { return this == that || this->SlowIs(that); } | 512 bool Is(Type* that) { return this == that || this->SlowIs(that); } |
| 513 bool Maybe(Type* that); | 513 bool Maybe(Type* that); |
| 514 bool Equals(Type* that) { return this->Is(that) && that->Is(this); } | 514 bool Equals(Type* that) { return this->Is(that) && that->Is(this); } |
| 515 | 515 |
| 516 // Equivalent to Constant(val)->Is(this), but avoiding allocation. | |
| 517 bool Contains(i::Object* val); | |
| 518 bool Contains(i::Handle<i::Object> val) { return this->Contains(*val); } | |
| 519 | |
| 520 // Inspection. | 516 // Inspection. |
| 521 bool IsRange() { return IsKind(TypeBase::kRange); } | 517 bool IsRange() { return IsKind(TypeBase::kRange); } |
| 522 bool IsConstant() { return IsKind(TypeBase::kConstant); } | 518 bool IsConstant() { return IsKind(TypeBase::kConstant); } |
| 523 bool IsTuple() { return IsKind(TypeBase::kTuple); } | 519 bool IsTuple() { return IsKind(TypeBase::kTuple); } |
| 524 | 520 |
| 525 ConstantType* AsConstant() { return ConstantType::cast(this); } | 521 ConstantType* AsConstant() { return ConstantType::cast(this); } |
| 526 RangeType* AsRange() { return RangeType::cast(this); } | 522 RangeType* AsRange() { return RangeType::cast(this); } |
| 527 TupleType* AsTuple() { return TupleType::cast(this); } | 523 TupleType* AsTuple() { return TupleType::cast(this); } |
| 528 | 524 |
| 529 // Minimum and maximum of a numeric type. | 525 // Minimum and maximum of a numeric type. |
| 530 // These functions do not distinguish between -0 and +0. If the type equals | 526 // These functions do not distinguish between -0 and +0. If the type equals |
| 531 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these | 527 // kNaN, they return NaN; otherwise kNaN is ignored. Only call these |
| 532 // functions on subtypes of Number. | 528 // functions on subtypes of Number. |
| 533 double Min(); | 529 double Min(); |
| 534 double Max(); | 530 double Max(); |
| 535 | 531 |
| 536 // Extracts a range from the type: if the type is a range or a union | 532 // Extracts a range from the type: if the type is a range or a union |
| 537 // containing a range, that range is returned; otherwise, NULL is returned. | 533 // containing a range, that range is returned; otherwise, NULL is returned. |
| 538 Type* GetRange(); | 534 Type* GetRange(); |
| 539 | 535 |
| 540 static bool IsInteger(i::Object* x); | 536 static bool IsInteger(i::Object* x); |
| 541 static bool IsInteger(double x) { | 537 static bool IsInteger(double x) { |
| 542 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. | 538 return nearbyint(x) == x && !i::IsMinusZero(x); // Allows for infinities. |
| 543 } | 539 } |
| 544 | 540 |
| 545 int NumConstants(); | 541 int NumConstants(); |
|
Jarin
2016/09/28 13:27:02
Is this necessary?
mvstanton
2016/09/28 13:46:08
It gets used by tests, I'd prefer to keep it for n
| |
| 546 | 542 |
| 547 template <class T> | |
| 548 class Iterator { | |
| 549 public: | |
| 550 bool Done() const { return index_ < 0; } | |
| 551 i::Handle<T> Current(); | |
| 552 void Advance(); | |
| 553 | |
| 554 private: | |
| 555 friend class Type; | |
| 556 | |
| 557 Iterator() : index_(-1) {} | |
| 558 explicit Iterator(Type* type) : type_(type), index_(-1) { Advance(); } | |
| 559 | |
| 560 inline bool matches(Type* type); | |
| 561 inline Type* get_type(); | |
| 562 | |
| 563 Type* type_; | |
| 564 int index_; | |
| 565 }; | |
| 566 | |
| 567 Iterator<i::Object> Constants() { | |
| 568 if (this->IsBitset()) return Iterator<i::Object>(); | |
| 569 return Iterator<i::Object>(this); | |
| 570 } | |
| 571 | |
| 572 // Printing. | 543 // Printing. |
| 573 | 544 |
| 574 void PrintTo(std::ostream& os); | 545 void PrintTo(std::ostream& os); |
| 575 | 546 |
| 576 #ifdef DEBUG | 547 #ifdef DEBUG |
| 577 void Print(); | 548 void Print(); |
| 578 #endif | 549 #endif |
| 579 | 550 |
| 580 // Helpers for testing. | 551 // Helpers for testing. |
| 581 bool IsBitsetForTesting() { return IsBitset(); } | 552 bool IsBitsetForTesting() { return IsBitset(); } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 RangeType::Limits* limits, Zone* zone); | 598 RangeType::Limits* limits, Zone* zone); |
| 628 static Type* NormalizeUnion(Type* unioned, int size, Zone* zone); | 599 static Type* NormalizeUnion(Type* unioned, int size, Zone* zone); |
| 629 static Type* NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone); | 600 static Type* NormalizeRangeAndBitset(Type* range, bitset* bits, Zone* zone); |
| 630 }; | 601 }; |
| 631 | 602 |
| 632 } // namespace compiler | 603 } // namespace compiler |
| 633 } // namespace internal | 604 } // namespace internal |
| 634 } // namespace v8 | 605 } // namespace v8 |
| 635 | 606 |
| 636 #endif // V8_COMPILER_TYPES_H_ | 607 #endif // V8_COMPILER_TYPES_H_ |
| OLD | NEW |