1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ 18 #define ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ 19 20 #include <ostream> 21 22 namespace art { 23 24 // Possible experimental features that might be enabled. 25 struct ExperimentalFlags { 26 // The actual flag values. 27 enum { 28 kNone = 0x0000, 29 kLambdas = 0x0001, 30 }; 31 ExperimentalFlagsExperimentalFlags32 constexpr ExperimentalFlags() : value_(0x0000) {} ExperimentalFlagsExperimentalFlags33 constexpr ExperimentalFlags(decltype(kNone) t) : value_(static_cast<uint32_t>(t)) {} 34 decltypeExperimentalFlags35 constexpr operator decltype(kNone)() const { 36 return static_cast<decltype(kNone)>(value_); 37 } 38 39 constexpr explicit operator bool() const { 40 return value_ != kNone; 41 } 42 43 constexpr ExperimentalFlags operator|(const decltype(kNone)& b) const { 44 return static_cast<decltype(kNone)>(value_ | static_cast<uint32_t>(b)); 45 } 46 constexpr ExperimentalFlags operator|(const ExperimentalFlags& b) const { 47 return static_cast<decltype(kNone)>(value_ | b.value_); 48 } 49 50 constexpr ExperimentalFlags operator&(const ExperimentalFlags& b) const { 51 return static_cast<decltype(kNone)>(value_ & b.value_); 52 } decltypeExperimentalFlags53 constexpr ExperimentalFlags operator&(const decltype(kNone)& b) const { 54 return static_cast<decltype(kNone)>(value_ & static_cast<uint32_t>(b)); 55 } 56 57 constexpr bool operator==(const ExperimentalFlags& b) const { 58 return value_ == b.value_; 59 } 60 61 private: 62 uint32_t value_; 63 }; 64 65 inline std::ostream& operator<<(std::ostream& stream, const ExperimentalFlags& e) { 66 bool started = false; 67 if (e & ExperimentalFlags::kLambdas) { 68 stream << (started ? "|" : "") << "kLambdas"; 69 started = true; 70 } 71 if (!started) { 72 stream << "kNone"; 73 } 74 return stream; 75 } 76 77 inline std::ostream& operator<<(std::ostream& stream, const decltype(ExperimentalFlags::kNone)& e) { 78 return stream << ExperimentalFlags(e); 79 } 80 81 } // namespace art 82 83 #endif // ART_RUNTIME_EXPERIMENTAL_FLAGS_H_ 84