| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 | 924 |
| 925 | 925 |
| 926 // A poor man's version of STL's bitset: A bit set of enums E (without explicit | 926 // A poor man's version of STL's bitset: A bit set of enums E (without explicit |
| 927 // values), fitting into an integral type T. | 927 // values), fitting into an integral type T. |
| 928 template <class E, class T = int> | 928 template <class E, class T = int> |
| 929 class EnumSet { | 929 class EnumSet { |
| 930 public: | 930 public: |
| 931 explicit EnumSet(T bits = 0) : bits_(bits) {} | 931 explicit EnumSet(T bits = 0) : bits_(bits) {} |
| 932 bool IsEmpty() const { return bits_ == 0; } | 932 bool IsEmpty() const { return bits_ == 0; } |
| 933 bool Contains(E element) const { return (bits_ & Mask(element)) != 0; } | 933 bool Contains(E element) const { return (bits_ & Mask(element)) != 0; } |
| 934 bool ContainsAnyOf(const EnumSet& set) const { |
| 935 return (bits_ & set.bits_) != 0; |
| 936 } |
| 934 void Add(E element) { bits_ |= Mask(element); } | 937 void Add(E element) { bits_ |= Mask(element); } |
| 938 void Add(const EnumSet& set) { bits_ |= set.bits_; } |
| 935 void Remove(E element) { bits_ &= ~Mask(element); } | 939 void Remove(E element) { bits_ &= ~Mask(element); } |
| 940 void Remove(const EnumSet& set) { bits_ &= ~set.bits_; } |
| 941 void RemoveAll() { bits_ = 0; } |
| 942 void Intersect(const EnumSet& set) { bits_ &= set.bits_; } |
| 936 T ToIntegral() const { return bits_; } | 943 T ToIntegral() const { return bits_; } |
| 944 bool operator==(const EnumSet& set) { return bits_ == set.bits_; } |
| 937 | 945 |
| 938 private: | 946 private: |
| 939 T Mask(E element) const { | 947 T Mask(E element) const { |
| 940 // The strange typing in ASSERT is necessary to avoid stupid warnings, see: | 948 // The strange typing in ASSERT is necessary to avoid stupid warnings, see: |
| 941 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680 | 949 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43680 |
| 942 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); | 950 ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT)); |
| 943 return 1 << element; | 951 return 1 << element; |
| 944 } | 952 } |
| 945 | 953 |
| 946 T bits_; | 954 T bits_; |
| 947 }; | 955 }; |
| 948 | 956 |
| 949 } } // namespace v8::internal | 957 } } // namespace v8::internal |
| 950 | 958 |
| 951 #endif // V8_UTILS_H_ | 959 #endif // V8_UTILS_H_ |
| OLD | NEW |