/*1* Copyright © 2020 Red Hat Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifdef __cplusplus2425#include "macros.h"26#include <type_traits>2728// some enum helpers29#define MESA_DEFINE_CPP_ENUM_BINARY_OPERATOR(Enum, op) \30extern "C++" { \31UNUSED static constexpr \32Enum operator op (Enum a, Enum b) \33{ \34using IntType = std::underlying_type_t<Enum>; \35IntType ua = static_cast<IntType>(a); \36IntType ub = static_cast<IntType>(b); \37return static_cast<Enum>(ua op ub); \38} \39\40UNUSED static constexpr \41Enum& operator op##= (Enum &a, Enum b) \42{ \43using IntType = std::underlying_type_t<Enum>; \44IntType ua = static_cast<IntType>(a); \45IntType ub = static_cast<IntType>(b); \46ua op##= ub; \47a = static_cast<Enum>(ua); \48return a; \49} \50}5152#define MESA_DEFINE_CPP_ENUM_UNARY_OPERATOR(Enum, op) \53extern "C++" { \54UNUSED static constexpr \55Enum operator op (Enum a) \56{ \57using IntType = std::underlying_type_t<Enum>; \58IntType ua = static_cast<IntType>(a); \59return static_cast<Enum>(op ua); \60} \61}6263#define MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(Enum) \64MESA_DEFINE_CPP_ENUM_BINARY_OPERATOR(Enum, |) \65MESA_DEFINE_CPP_ENUM_BINARY_OPERATOR(Enum, &) \66MESA_DEFINE_CPP_ENUM_BINARY_OPERATOR(Enum, ^) \67MESA_DEFINE_CPP_ENUM_UNARY_OPERATOR(Enum, ~)6869#else7071#define MESA_DEFINE_CPP_ENUM_BITFIELD_OPERATORS(Enum)7273#endif747576