Also drop the DEFINE_FLAGS() macro, and use the typedef explicitly.
TEST=base-unittests
R=svenpanne@chromium.org
Review URL: https://codereview.chromium.org/
527173002
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23578
ce2b1a6d-e550-0410-aec6-
3dcde31c8c00
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "include/v8stdint.h"
#include "src/base/flags.h"
#include "testing/gtest/include/gtest/gtest.h"
kFlag1Second = 1u << 2,
kFlag1All = kFlag1None | kFlag1First | kFlag1Second
};
-DEFINE_FLAGS(Flags1, Flag1);
+typedef Flags<Flag1> Flags1;
DEFINE_OPERATORS_FOR_FLAGS(Flags1)
kOption2 = 2,
kAllOptions = kNoOptions | kOption1 | kOption2
};
-DEFINE_FLAGS(Options, Option);
+typedef Flags<Option> Options;
} // namespace foo
struct Foo {
enum Enum { kEnum1 = 1, kEnum2 = 2 };
- DEFINE_FLAGS(Enums, Enum);
+ typedef Flags<Enum, uint32_t> Enums;
};
namespace base {
// The Flags class provides a type-safe way of storing OR-combinations of enum
-// values. The Flags<T> class is a template class, where T is an enum type.
+// values. The Flags<T, S> class is a template class, where T is an enum type,
+// and S is the underlying storage type (usually int).
//
// The traditional C++ approach for storing OR-combinations of enum values is to
// use an int or unsigned int variable. The inconvenience with this approach is
// that there's no type checking at all; any enum value can be OR'd with any
// other enum value and passed on to a function that takes an int or unsigned
// int.
-template <typename T>
+template <typename T, typename S = int>
class Flags V8_FINAL {
public:
typedef T flag_type;
- typedef int mask_type;
+ typedef S mask_type;
Flags() : mask_(0) {}
Flags(flag_type flag) : mask_(flag) {} // NOLINT(runtime/explicit)
};
-#define DEFINE_FLAGS(Type, Enum) typedef ::v8::base::Flags<Enum> Type
-
#define DEFINE_OPERATORS_FOR_FLAGS(Type) \
inline ::v8::base::Flags<Type::flag_type> operator&( \
Type::flag_type lhs, \
kNeedsNopAfterCall = 1u << 2,
kPatchableCallSiteWithNop = kPatchableCallSite | kNeedsNopAfterCall
};
- DEFINE_FLAGS(Flags, Flag);
+ typedef base::Flags<Flag> Flags;
CallDescriptor(Kind kind, int8_t return_count, int16_t parameter_count,
int16_t input_count, LinkageLocation* locations,