Skip to content

Commit e479863

Browse files
committed
[scudo] Minor macro clean up
1 parent 159c068 commit e479863

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

compiler-rt/lib/scudo/standalone/allocator_config_wrapper.h

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,34 @@ template <typename T> struct removeConst<const T> {
2626

2727
namespace scudo {
2828

29-
#define OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT) \
29+
#define OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, MEMBER) \
3030
template <typename Config, typename = TYPE> struct NAME##State { \
3131
static constexpr removeConst<TYPE>::type getValue() { return DEFAULT; } \
3232
}; \
3333
template <typename Config> \
34-
struct NAME##State<Config, decltype(Config::NAME)> { \
34+
struct NAME##State<Config, decltype(Config::MEMBER)> { \
3535
static constexpr removeConst<TYPE>::type getValue() { \
36-
return Config::NAME; \
36+
return Config::MEMBER; \
3737
} \
3838
};
3939

40-
#define OPTIONAL_TYPE_TEMPLATE(NAME, DEFAULT) \
40+
#define OPTIONAL_TYPE_TEMPLATE(NAME, DEFAULT, MEMBER) \
4141
template <typename Config, typename Void = Config> struct NAME##Type { \
4242
static constexpr bool enabled() { return false; } \
4343
using NAME = DEFAULT; \
4444
}; \
4545
template <typename Config> \
46-
struct NAME##Type<Config, typename Config::NAME> { \
46+
struct NAME##Type<Config, typename Config::MEMBER> { \
4747
static constexpr bool enabled() { return true; } \
48-
using NAME = typename Config::NAME; \
48+
using NAME = typename Config::MEMBER; \
4949
};
5050

5151
template <typename AllocatorConfig> struct BaseConfig {
5252
#define BASE_REQUIRED_TEMPLATE_TYPE(NAME) \
5353
template <typename T> using NAME = typename AllocatorConfig::template NAME<T>;
5454

5555
#define BASE_OPTIONAL(TYPE, NAME, DEFAULT) \
56-
OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT) \
56+
OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, NAME) \
5757
static constexpr removeConst<TYPE>::type get##NAME() { \
5858
return NAME##State<AllocatorConfig>::getValue(); \
5959
}
@@ -77,13 +77,13 @@ template <typename AllocatorConfig> struct PrimaryConfig {
7777
}
7878

7979
#define PRIMARY_OPTIONAL(TYPE, NAME, DEFAULT) \
80-
OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT) \
80+
OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, NAME) \
8181
static constexpr removeConst<TYPE>::type get##NAME() { \
8282
return NAME##State<typename AllocatorConfig::Primary>::getValue(); \
8383
}
8484

8585
#define PRIMARY_OPTIONAL_TYPE(NAME, DEFAULT) \
86-
OPTIONAL_TYPE_TEMPLATE(NAME, DEFAULT) \
86+
OPTIONAL_TYPE_TEMPLATE(NAME, DEFAULT, NAME) \
8787
static constexpr bool has##NAME() { \
8888
return NAME##Type<typename AllocatorConfig::Primary>::enabled(); \
8989
} \
@@ -113,22 +113,17 @@ template <typename AllocatorConfig> struct SecondaryConfig {
113113
}
114114

115115
#define SECONDARY_CACHE_OPTIONAL(TYPE, NAME, DEFAULT) \
116-
template <typename Config, typename = TYPE> struct NAME##State { \
117-
static constexpr removeConst<TYPE>::type getValue() { return DEFAULT; } \
118-
}; \
119-
template <typename Config> \
120-
struct NAME##State<Config, decltype(Config::Cache)> { \
121-
static constexpr removeConst<TYPE>::type getValue() { \
122-
return Config::Cache::NAME; \
123-
} \
124-
}; \
116+
OPTIONAL_TEMPLATE(TYPE, NAME, DEFAULT, Cache::NAME) \
125117
static constexpr removeConst<TYPE>::type get##NAME() { \
126118
return NAME##State<typename AllocatorConfig::Secondary>::getValue(); \
127119
}
128120
#include "allocator_config.def"
129-
};
121+
}; // CacheConfig
130122
}; // SecondaryConfig
131123

124+
#undef OPTIONAL_TEMPLATE
125+
#undef OPTIONAL_TEMPLATE_TYPE
126+
132127
} // namespace scudo
133128

134129
#endif // SCUDO_ALLOCATOR_CONFIG_WRAPPER_H_

0 commit comments

Comments
 (0)