Reviewers: Sven Panne,
Description:
Add support for storage type to base::Flags.
Also drop the DEFINE_FLAGS() macro, and use the typedef explicitly.
TEST=base-unittests
[email protected]
Please review this at https://codereview.chromium.org/527173002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+8, -9 lines):
M src/base/flags.h
M src/base/flags-unittest.cc
M src/compiler/linkage.h
Index: src/base/flags-unittest.cc
diff --git a/src/base/flags-unittest.cc b/src/base/flags-unittest.cc
index
da526cb12160faf63bff7a5f41899de46dc15394..93a6bb88eb97e23491b7203e7b15d86bd7f206f1
100644
--- a/src/base/flags-unittest.cc
+++ b/src/base/flags-unittest.cc
@@ -16,7 +16,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 +60,7 @@ enum Option {
kOption2 = 2,
kAllOptions = kNoOptions | kOption1 | kOption2
};
-DEFINE_FLAGS(Options, Option);
+typedef Flags<Option> Options;
} // namespace foo
@@ -82,7 +82,7 @@ namespace {
struct Foo {
enum Enum { kEnum1 = 1, kEnum2 = 2 };
- DEFINE_FLAGS(Enums, Enum);
+ typedef Flags<Enum, uint32_t> Enums;
};
Index: src/base/flags.h
diff --git a/src/base/flags.h b/src/base/flags.h
index
6a2c57f719e1c9127fc309811b85ad0e208d24e3..bf5edbf3f31a17ca7d7faad665972a6d76e5eb88
100644
--- a/src/base/flags.h
+++ b/src/base/flags.h
@@ -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, \
Index: src/compiler/linkage.h
diff --git a/src/compiler/linkage.h b/src/compiler/linkage.h
index
9f3d8347e986c472b5d682b02c0cdf2e4b9a3a30..5389041e04b9658d7690246185189494eac265be
100644
--- a/src/compiler/linkage.h
+++ b/src/compiler/linkage.h
@@ -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,
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.