[codeview] Macroify definition of bitwise operators for flags enums.

llvm-svn: 269832
This commit is contained in:
Zachary Turner 2016-05-17 20:21:01 +00:00
parent 22b01febd4
commit 8f02a54e2b
1 changed files with 31 additions and 86 deletions

View File

@ -11,10 +11,35 @@
#define LLVM_DEBUGINFO_CODEVIEW_CODEVIEW_H #define LLVM_DEBUGINFO_CODEVIEW_CODEVIEW_H
#include <cinttypes> #include <cinttypes>
#include <type_traits>
namespace llvm { namespace llvm {
namespace codeview { namespace codeview {
#define CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(Class) \
inline Class operator|(Class a, Class b) { \
return static_cast<Class>( \
static_cast<std::underlying_type<Class>::type>(a) | \
static_cast<std::underlying_type<Class>::type>(b)); \
} \
inline Class operator&(Class a, Class b) { \
return static_cast<Class>( \
static_cast<std::underlying_type<Class>::type>(a) & \
static_cast<std::underlying_type<Class>::type>(b)); \
} \
inline Class operator~(Class a) { \
return static_cast<Class>( \
~static_cast<std::underlying_type<Class>::type>(a)); \
} \
inline Class &operator|=(Class &a, Class b) { \
a = a | b; \
return a; \
} \
inline Class &operator&=(Class &a, Class b) { \
a = a & b; \
return a; \
}
/// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented /// These values correspond to the CV_CPU_TYPE_e enumeration, and are documented
/// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx /// here: https://msdn.microsoft.com/en-us/library/b2fc64ek.aspx
enum class CPUType : uint16_t { enum class CPUType : uint16_t {
@ -149,20 +174,7 @@ enum class ClassOptions : uint16_t {
Sealed = 0x0400, Sealed = 0x0400,
Intrinsic = 0x2000 Intrinsic = 0x2000
}; };
CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ClassOptions)
inline ClassOptions operator|(ClassOptions a, ClassOptions b) {
return static_cast<ClassOptions>(static_cast<uint16_t>(a) |
static_cast<uint16_t>(b));
}
inline ClassOptions operator&(ClassOptions a, ClassOptions b) {
return static_cast<ClassOptions>(static_cast<uint16_t>(a) &
static_cast<uint16_t>(b));
}
inline ClassOptions operator~(ClassOptions a) {
return static_cast<ClassOptions>(~static_cast<uint16_t>(a));
}
enum class FrameProcedureOptions : uint32_t { enum class FrameProcedureOptions : uint32_t {
None = 0x00000000, None = 0x00000000,
@ -186,22 +198,7 @@ enum class FrameProcedureOptions : uint32_t {
GuardCfg = 0x00200000, GuardCfg = 0x00200000,
GuardCfw = 0x00400000 GuardCfw = 0x00400000
}; };
CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FrameProcedureOptions)
inline FrameProcedureOptions operator|(FrameProcedureOptions a,
FrameProcedureOptions b) {
return static_cast<FrameProcedureOptions>(static_cast<uint32_t>(a) |
static_cast<uint32_t>(b));
}
inline FrameProcedureOptions operator&(FrameProcedureOptions a,
FrameProcedureOptions b) {
return static_cast<FrameProcedureOptions>(static_cast<uint32_t>(a) &
static_cast<uint32_t>(b));
}
inline FrameProcedureOptions operator~(FrameProcedureOptions a) {
return static_cast<FrameProcedureOptions>(~static_cast<uint32_t>(a));
}
enum class FunctionOptions : uint8_t { enum class FunctionOptions : uint8_t {
None = 0x00, None = 0x00,
@ -209,20 +206,7 @@ enum class FunctionOptions : uint8_t {
Constructor = 0x02, Constructor = 0x02,
ConstructorWithVirtualBases = 0x04 ConstructorWithVirtualBases = 0x04
}; };
CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(FunctionOptions)
inline FunctionOptions operator|(FunctionOptions a, FunctionOptions b) {
return static_cast<FunctionOptions>(static_cast<uint8_t>(a) |
static_cast<uint8_t>(b));
}
inline FunctionOptions operator&(FunctionOptions a, FunctionOptions b) {
return static_cast<FunctionOptions>(static_cast<uint8_t>(a) &
static_cast<uint8_t>(b));
}
inline FunctionOptions operator~(FunctionOptions a) {
return static_cast<FunctionOptions>(~static_cast<uint8_t>(a));
}
enum class HfaKind : uint8_t { enum class HfaKind : uint8_t {
None = 0x00, None = 0x00,
@ -261,20 +245,7 @@ enum class MethodOptions : uint16_t {
CompilerGenerated = 0x0100, CompilerGenerated = 0x0100,
Sealed = 0x0200 Sealed = 0x0200
}; };
CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(MethodOptions)
inline MethodOptions operator|(MethodOptions a, MethodOptions b) {
return static_cast<MethodOptions>(static_cast<uint16_t>(a) |
static_cast<uint16_t>(b));
}
inline MethodOptions operator&(MethodOptions a, MethodOptions b) {
return static_cast<MethodOptions>(static_cast<uint16_t>(a) &
static_cast<uint16_t>(b));
}
inline MethodOptions operator~(MethodOptions a) {
return static_cast<MethodOptions>(~static_cast<uint16_t>(a));
}
/// Equivalent to CV_modifier_t. /// Equivalent to CV_modifier_t.
enum class ModifierOptions : uint16_t { enum class ModifierOptions : uint16_t {
@ -283,20 +254,7 @@ enum class ModifierOptions : uint16_t {
Volatile = 0x0002, Volatile = 0x0002,
Unaligned = 0x0004 Unaligned = 0x0004
}; };
CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(ModifierOptions)
inline ModifierOptions operator|(ModifierOptions a, ModifierOptions b) {
return static_cast<ModifierOptions>(static_cast<uint16_t>(a) |
static_cast<uint16_t>(b));
}
inline ModifierOptions operator&(ModifierOptions a, ModifierOptions b) {
return static_cast<ModifierOptions>(static_cast<uint16_t>(a) &
static_cast<uint16_t>(b));
}
inline ModifierOptions operator~(ModifierOptions a) {
return static_cast<ModifierOptions>(~static_cast<uint16_t>(a));
}
enum class ModuleSubstreamKind : uint32_t { enum class ModuleSubstreamKind : uint32_t {
Symbols = 0xf1, Symbols = 0xf1,
@ -353,20 +311,7 @@ enum class PointerOptions : uint32_t {
Restrict = 0x00001000, Restrict = 0x00001000,
WinRTSmartPointer = 0x00080000 WinRTSmartPointer = 0x00080000
}; };
CV_DEFINE_ENUM_CLASS_FLAGS_OPERATORS(PointerOptions)
inline PointerOptions operator|(PointerOptions a, PointerOptions b) {
return static_cast<PointerOptions>(static_cast<uint16_t>(a) |
static_cast<uint16_t>(b));
}
inline PointerOptions operator&(PointerOptions a, PointerOptions b) {
return static_cast<PointerOptions>(static_cast<uint16_t>(a) &
static_cast<uint16_t>(b));
}
inline PointerOptions operator~(PointerOptions a) {
return static_cast<PointerOptions>(~static_cast<uint16_t>(a));
}
/// Equivalent to CV_pmtype_e. /// Equivalent to CV_pmtype_e.
enum class PointerToMemberRepresentation : uint16_t { enum class PointerToMemberRepresentation : uint16_t {