Revision: 23578
Author:   [email protected]
Date:     Tue Sep  2 06:53:14 2014 UTC
Log:      Add support for storage type to base::Flags.

Also drop the DEFINE_FLAGS() macro, and use the typedef explicitly.

TEST=base-unittests
[email protected]

Review URL: https://codereview.chromium.org/527173002
https://code.google.com/p/v8/source/detail?r=23578

Modified:
 /branches/bleeding_edge/src/base/flags-unittest.cc
 /branches/bleeding_edge/src/base/flags.h
 /branches/bleeding_edge/src/compiler/linkage.h

=======================================
--- /branches/bleeding_edge/src/base/flags-unittest.cc Fri Aug 29 10:53:08 2014 UTC +++ /branches/bleeding_edge/src/base/flags-unittest.cc Tue Sep 2 06:53:14 2014 UTC
@@ -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 @@
   kFlag1Second = 1u << 2,
   kFlag1All = kFlag1None | kFlag1First | kFlag1Second
 };
-DEFINE_FLAGS(Flags1, Flag1);
+typedef Flags<Flag1> Flags1;


 DEFINE_OPERATORS_FOR_FLAGS(Flags1)
@@ -60,7 +61,7 @@
   kOption2 = 2,
   kAllOptions = kNoOptions | kOption1 | kOption2
 };
-DEFINE_FLAGS(Options, Option);
+typedef Flags<Option> Options;

 }  // namespace foo

@@ -82,7 +83,7 @@

 struct Foo {
   enum Enum { kEnum1 = 1, kEnum2 = 2 };
-  DEFINE_FLAGS(Enums, Enum);
+  typedef Flags<Enum, uint32_t> Enums;
 };


=======================================
--- /branches/bleeding_edge/src/base/flags.h    Wed Aug 27 12:16:36 2014 UTC
+++ /branches/bleeding_edge/src/base/flags.h    Tue Sep  2 06:53:14 2014 UTC
@@ -11,18 +11,19 @@
 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)
@@ -62,8 +63,6 @@
   mask_type mask_;
 };

-
-#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&( \
=======================================
--- /branches/bleeding_edge/src/compiler/linkage.h Mon Sep 1 09:31:14 2014 UTC +++ /branches/bleeding_edge/src/compiler/linkage.h Tue Sep 2 06:53:14 2014 UTC
@@ -50,7 +50,7 @@
     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.

Reply via email to