Mark Permissions as a bitmask enum
authorPavel Labath <pavel@labath.sk>
Fri, 14 Dec 2018 13:51:20 +0000 (13:51 +0000)
committerPavel Labath <pavel@labath.sk>
Fri, 14 Dec 2018 13:51:20 +0000 (13:51 +0000)
this allows one to use bitwise operators on the variables of this type
without complicated casting.

The gotcha here is that the combinations of these enums were being used
in some constexpr contexts such as case labels (case
ePermissionsWritable | ePermissionsExecutable:), which is not possible
if the user-defined operator| is not constexpr.

So, this commit also marks these operators as constexpr. I am committing
this as a small standalone patch so it can be easily reverted if some
compiler has an issue with this.

llvm-svn: 349149

lldb/include/lldb/lldb-enumerations.h

index 0ed6340..604f83c 100644 (file)
 // you mark Enum with LLDB_MARK_AS_BITMASK_ENUM(Enum), however, you can simply
 // write Enum a = eFoo | eBar.
 #define LLDB_MARK_AS_BITMASK_ENUM(Enum)                                        \
-  inline Enum operator|(Enum a, Enum b) {                                      \
+  constexpr Enum operator|(Enum a, Enum b) {                                   \
     return static_cast<Enum>(                                                  \
         static_cast<std::underlying_type<Enum>::type>(a) |                     \
         static_cast<std::underlying_type<Enum>::type>(b));                     \
   }                                                                            \
-  inline Enum operator&(Enum a, Enum b) {                                      \
+  constexpr Enum operator&(Enum a, Enum b) {                                   \
     return static_cast<Enum>(                                                  \
         static_cast<std::underlying_type<Enum>::type>(a) &                     \
         static_cast<std::underlying_type<Enum>::type>(b));                     \
   }                                                                            \
-  inline Enum operator~(Enum a) {                                              \
+  constexpr Enum operator~(Enum a) {                                           \
     return static_cast<Enum>(                                                  \
         ~static_cast<std::underlying_type<Enum>::type>(a));                    \
   }                                                                            \
@@ -395,6 +395,7 @@ LLDB_MARK_AS_BITMASK_ENUM(SymbolContextItem)
 FLAGS_ENUM(Permissions){ePermissionsWritable = (1u << 0),
                         ePermissionsReadable = (1u << 1),
                         ePermissionsExecutable = (1u << 2)};
+LLDB_MARK_AS_BITMASK_ENUM(Permissions)
 
 enum InputReaderAction {
   eInputReaderActivate, // reader is newly pushed onto the reader stack