Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: src/base/flags.h

Issue 526223002: Use Chrome compatible naming for compiler specifics. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: mips Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/base/cpu.cc ('k') | src/base/macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_BASE_FLAGS_H_ 5 #ifndef V8_BASE_FLAGS_H_
6 #define V8_BASE_FLAGS_H_ 6 #define V8_BASE_FLAGS_H_
7 7
8 #include "include/v8config.h" 8 #include "src/base/compiler-specific.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace base { 11 namespace base {
12 12
13 // The Flags class provides a type-safe way of storing OR-combinations of enum 13 // The Flags class provides a type-safe way of storing OR-combinations of enum
14 // values. The Flags<T, S> class is a template class, where T is an enum type, 14 // values. The Flags<T, S> class is a template class, where T is an enum type,
15 // and S is the underlying storage type (usually int). 15 // and S is the underlying storage type (usually int).
16 // 16 //
17 // The traditional C++ approach for storing OR-combinations of enum values is to 17 // The traditional C++ approach for storing OR-combinations of enum values is to
18 // use an int or unsigned int variable. The inconvenience with this approach is 18 // use an int or unsigned int variable. The inconvenience with this approach is
19 // that there's no type checking at all; any enum value can be OR'd with any 19 // that there's no type checking at all; any enum value can be OR'd with any
20 // other enum value and passed on to a function that takes an int or unsigned 20 // other enum value and passed on to a function that takes an int or unsigned
21 // int. 21 // int.
22 template <typename T, typename S = int> 22 template <typename T, typename S = int>
23 class Flags V8_FINAL { 23 class Flags FINAL {
24 public: 24 public:
25 typedef T flag_type; 25 typedef T flag_type;
26 typedef S mask_type; 26 typedef S mask_type;
27 27
28 Flags() : mask_(0) {} 28 Flags() : mask_(0) {}
29 Flags(flag_type flag) : mask_(flag) {} // NOLINT(runtime/explicit) 29 Flags(flag_type flag) : mask_(flag) {} // NOLINT(runtime/explicit)
30 explicit Flags(mask_type mask) : mask_(mask) {} 30 explicit Flags(mask_type mask) : mask_(mask) {}
31 31
32 Flags& operator&=(const Flags& flags) { 32 Flags& operator&=(const Flags& flags) {
33 mask_ &= flags.mask_; 33 mask_ &= flags.mask_;
(...skipping 26 matching lines...) Expand all
60 bool operator!() const { return !mask_; } 60 bool operator!() const { return !mask_; }
61 61
62 private: 62 private:
63 mask_type mask_; 63 mask_type mask_;
64 }; 64 };
65 65
66 66
67 #define DEFINE_OPERATORS_FOR_FLAGS(Type) \ 67 #define DEFINE_OPERATORS_FOR_FLAGS(Type) \
68 inline ::v8::base::Flags<Type::flag_type> operator&( \ 68 inline ::v8::base::Flags<Type::flag_type> operator&( \
69 Type::flag_type lhs, \ 69 Type::flag_type lhs, \
70 Type::flag_type rhs)V8_UNUSED V8_WARN_UNUSED_RESULT; \ 70 Type::flag_type rhs)ALLOW_UNUSED WARN_UNUSED_RESULT; \
71 inline ::v8::base::Flags<Type::flag_type> operator&(Type::flag_type lhs, \ 71 inline ::v8::base::Flags<Type::flag_type> operator&(Type::flag_type lhs, \
72 Type::flag_type rhs) { \ 72 Type::flag_type rhs) { \
73 return ::v8::base::Flags<Type::flag_type>(lhs) & rhs; \ 73 return ::v8::base::Flags<Type::flag_type>(lhs) & rhs; \
74 } \ 74 } \
75 inline ::v8::base::Flags<Type::flag_type> operator&( \ 75 inline ::v8::base::Flags<Type::flag_type> operator&( \
76 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) \ 76 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) \
77 V8_UNUSED V8_WARN_UNUSED_RESULT; \ 77 ALLOW_UNUSED WARN_UNUSED_RESULT; \
78 inline ::v8::base::Flags<Type::flag_type> operator&( \ 78 inline ::v8::base::Flags<Type::flag_type> operator&( \
79 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) { \ 79 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) { \
80 return rhs & lhs; \ 80 return rhs & lhs; \
81 } \ 81 } \
82 inline void operator&(Type::flag_type lhs, Type::mask_type rhs)V8_UNUSED; \ 82 inline void operator&(Type::flag_type lhs, Type::mask_type rhs)ALLOW_UNUSED; \
83 inline void operator&(Type::flag_type lhs, Type::mask_type rhs) {} \ 83 inline void operator&(Type::flag_type lhs, Type::mask_type rhs) {} \
84 inline ::v8::base::Flags<Type::flag_type> operator|(Type::flag_type lhs, \ 84 inline ::v8::base::Flags<Type::flag_type> operator|(Type::flag_type lhs, \
85 Type::flag_type rhs) \ 85 Type::flag_type rhs) \
86 V8_UNUSED V8_WARN_UNUSED_RESULT; \ 86 ALLOW_UNUSED WARN_UNUSED_RESULT; \
87 inline ::v8::base::Flags<Type::flag_type> operator|(Type::flag_type lhs, \ 87 inline ::v8::base::Flags<Type::flag_type> operator|(Type::flag_type lhs, \
88 Type::flag_type rhs) { \ 88 Type::flag_type rhs) { \
89 return ::v8::base::Flags<Type::flag_type>(lhs) | rhs; \ 89 return ::v8::base::Flags<Type::flag_type>(lhs) | rhs; \
90 } \ 90 } \
91 inline ::v8::base::Flags<Type::flag_type> operator|( \ 91 inline ::v8::base::Flags<Type::flag_type> operator|( \
92 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) \ 92 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) \
93 V8_UNUSED V8_WARN_UNUSED_RESULT; \ 93 ALLOW_UNUSED WARN_UNUSED_RESULT; \
94 inline ::v8::base::Flags<Type::flag_type> operator|( \ 94 inline ::v8::base::Flags<Type::flag_type> operator|( \
95 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) { \ 95 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) { \
96 return rhs | lhs; \ 96 return rhs | lhs; \
97 } \ 97 } \
98 inline void operator|(Type::flag_type lhs, Type::mask_type rhs) V8_UNUSED; \ 98 inline void operator|(Type::flag_type lhs, Type::mask_type rhs) \
99 ALLOW_UNUSED; \
99 inline void operator|(Type::flag_type lhs, Type::mask_type rhs) {} \ 100 inline void operator|(Type::flag_type lhs, Type::mask_type rhs) {} \
100 inline ::v8::base::Flags<Type::flag_type> operator^(Type::flag_type lhs, \ 101 inline ::v8::base::Flags<Type::flag_type> operator^(Type::flag_type lhs, \
101 Type::flag_type rhs) \ 102 Type::flag_type rhs) \
102 V8_UNUSED V8_WARN_UNUSED_RESULT; \ 103 ALLOW_UNUSED WARN_UNUSED_RESULT; \
103 inline ::v8::base::Flags<Type::flag_type> operator^(Type::flag_type lhs, \ 104 inline ::v8::base::Flags<Type::flag_type> operator^(Type::flag_type lhs, \
104 Type::flag_type rhs) { \ 105 Type::flag_type rhs) { \
105 return ::v8::base::Flags<Type::flag_type>(lhs) ^ rhs; \ 106 return ::v8::base::Flags<Type::flag_type>(lhs) ^ rhs; \
106 } inline ::v8::base::Flags<Type::flag_type> \ 107 } inline ::v8::base::Flags<Type::flag_type> \
107 operator^(Type::flag_type lhs, \ 108 operator^(Type::flag_type lhs, \
108 const ::v8::base::Flags<Type::flag_type>& rhs) \ 109 const ::v8::base::Flags<Type::flag_type>& rhs) \
109 V8_UNUSED V8_WARN_UNUSED_RESULT; \ 110 ALLOW_UNUSED WARN_UNUSED_RESULT; \
110 inline ::v8::base::Flags<Type::flag_type> operator^( \ 111 inline ::v8::base::Flags<Type::flag_type> operator^( \
111 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) { \ 112 Type::flag_type lhs, const ::v8::base::Flags<Type::flag_type>& rhs) { \
112 return rhs ^ lhs; \ 113 return rhs ^ lhs; \
113 } inline void operator^(Type::flag_type lhs, Type::mask_type rhs) V8_UNUSED; \ 114 } inline void operator^(Type::flag_type lhs, Type::mask_type rhs) \
115 ALLOW_UNUSED; \
114 inline void operator^(Type::flag_type lhs, Type::mask_type rhs) {} 116 inline void operator^(Type::flag_type lhs, Type::mask_type rhs) {}
115 117
116 } // namespace base 118 } // namespace base
117 } // namespace v8 119 } // namespace v8
118 120
119 #endif // V8_BASE_FLAGS_H_ 121 #endif // V8_BASE_FLAGS_H_
OLDNEW
« no previous file with comments | « src/base/cpu.cc ('k') | src/base/macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698