Commit 88d4c2dd authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Add support for storage type to base::Flags.

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
parent 7300a2a3
......@@ -2,6 +2,7 @@
// 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"
......@@ -16,7 +17,7 @@ enum Flag1 {
kFlag1Second = 1u << 2,
kFlag1All = kFlag1None | kFlag1First | kFlag1Second
};
DEFINE_FLAGS(Flags1, Flag1);
typedef Flags<Flag1> Flags1;
DEFINE_OPERATORS_FOR_FLAGS(Flags1)
......@@ -60,7 +61,7 @@ enum Option {
kOption2 = 2,
kAllOptions = kNoOptions | kOption1 | kOption2
};
DEFINE_FLAGS(Options, Option);
typedef Flags<Option> Options;
} // namespace foo
......@@ -82,7 +83,7 @@ namespace {
struct Foo {
enum Enum { kEnum1 = 1, kEnum2 = 2 };
DEFINE_FLAGS(Enums, Enum);
typedef Flags<Enum, uint32_t> Enums;
};
......
......@@ -11,18 +11,19 @@ namespace v8 {
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)
......@@ -63,8 +64,6 @@ class Flags V8_FINAL {
};
#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, \
......
......@@ -50,7 +50,7 @@ class CallDescriptor V8_FINAL : public ZoneObject {
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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment