Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit b35e220

Browse files
committed
[ADT] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316818 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f94e4f3 commit b35e220

File tree

6 files changed

+195
-185
lines changed

6 files changed

+195
-185
lines changed

include/llvm/ADT/FoldingSet.h

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- llvm/ADT/FoldingSet.h - Uniquing Hash Set ---------------*- C++ -*-===//
1+
//===- llvm/ADT/FoldingSet.h - Uniquing Hash Set ----------------*- C++ -*-===//
22
//
33
// The LLVM Compiler Infrastructure
44
//
@@ -115,11 +115,9 @@ class FoldingSetBase {
115115

116116
protected:
117117
/// Buckets - Array of bucket chains.
118-
///
119118
void **Buckets;
120119

121120
/// NumBuckets - Length of the Buckets array. Always a power of 2.
122-
///
123121
unsigned NumBuckets;
124122

125123
/// NumNodes - Number of nodes in the folding set. Growth occurs when NumNodes
@@ -135,14 +133,13 @@ class FoldingSetBase {
135133
//===--------------------------------------------------------------------===//
136134
/// Node - This class is used to maintain the singly linked bucket list in
137135
/// a folding set.
138-
///
139136
class Node {
140137
private:
141138
// NextInFoldingSetBucket - next link in the bucket list.
142-
void *NextInFoldingSetBucket;
139+
void *NextInFoldingSetBucket = nullptr;
143140

144141
public:
145-
Node() : NextInFoldingSetBucket(nullptr) {}
142+
Node() = default;
146143

147144
// Accessors
148145
void *getNextInBucket() const { return NextInFoldingSetBucket; }
@@ -221,7 +218,6 @@ class FoldingSetBase {
221218

222219
/// DefaultFoldingSetTrait - This class provides default implementations
223220
/// for FoldingSetTrait implementations.
224-
///
225221
template<typename T> struct DefaultFoldingSetTrait {
226222
static void Profile(const T &X, FoldingSetNodeID &ID) {
227223
X.Profile(ID);
@@ -307,7 +303,6 @@ class FoldingSetNodeIDRef {
307303
/// FoldingSetNodeID - This class is used to gather all the unique data bits of
308304
/// a node. When all the bits are gathered this class is used to produce a
309305
/// hash value for the node.
310-
///
311306
class FoldingSetNodeID {
312307
/// Bits - Vector of all the data bits that make the node unique.
313308
/// Use a SmallVector to avoid a heap allocation in the common case.
@@ -320,7 +315,6 @@ class FoldingSetNodeID {
320315
: Bits(Ref.getData(), Ref.getData() + Ref.getSize()) {}
321316

322317
/// Add* - Add various data types to Bit data.
323-
///
324318
void AddPointer(const void *Ptr);
325319
void AddInteger(signed I);
326320
void AddInteger(unsigned I);
@@ -344,7 +338,6 @@ class FoldingSetNodeID {
344338
unsigned ComputeHash() const;
345339

346340
/// operator== - Used to compare two nodes to each other.
347-
///
348341
bool operator==(const FoldingSetNodeID &RHS) const;
349342
bool operator==(const FoldingSetNodeIDRef RHS) const;
350343

@@ -363,7 +356,7 @@ class FoldingSetNodeID {
363356
};
364357

365358
// Convenience type to hide the implementation of the folding set.
366-
typedef FoldingSetBase::Node FoldingSetNode;
359+
using FoldingSetNode = FoldingSetBase::Node;
367360
template<class T> class FoldingSetIterator;
368361
template<class T> class FoldingSetBucketIterator;
369362

@@ -415,15 +408,17 @@ template <class T> class FoldingSetImpl : public FoldingSetBase {
415408
~FoldingSetImpl() = default;
416409

417410
public:
418-
typedef FoldingSetIterator<T> iterator;
411+
using iterator = FoldingSetIterator<T>;
412+
419413
iterator begin() { return iterator(Buckets); }
420414
iterator end() { return iterator(Buckets+NumBuckets); }
421415

422-
typedef FoldingSetIterator<const T> const_iterator;
416+
using const_iterator = FoldingSetIterator<const T>;
417+
423418
const_iterator begin() const { return const_iterator(Buckets); }
424419
const_iterator end() const { return const_iterator(Buckets+NumBuckets); }
425420

426-
typedef FoldingSetBucketIterator<T> bucket_iterator;
421+
using bucket_iterator = FoldingSetBucketIterator<T>;
427422

428423
bucket_iterator bucket_begin(unsigned hash) {
429424
return bucket_iterator(Buckets + (hash & (NumBuckets-1)));
@@ -503,9 +498,7 @@ template <class T> class FoldingSet final : public FoldingSetImpl<T> {
503498
}
504499

505500
public:
506-
explicit FoldingSet(unsigned Log2InitSize = 6)
507-
: Super(Log2InitSize) {}
508-
501+
explicit FoldingSet(unsigned Log2InitSize = 6) : Super(Log2InitSize) {}
509502
FoldingSet(FoldingSet &&Arg) = default;
510503
FoldingSet &operator=(FoldingSet &&RHS) = default;
511504
};
@@ -552,8 +545,7 @@ class ContextualFoldingSet final : public FoldingSetImpl<T> {
552545

553546
public:
554547
explicit ContextualFoldingSet(Ctx Context, unsigned Log2InitSize = 6)
555-
: Super(Log2InitSize), Context(Context)
556-
{}
548+
: Super(Log2InitSize), Context(Context) {}
557549

558550
Ctx getContext() const { return Context; }
559551
};
@@ -569,15 +561,15 @@ class FoldingSetVector {
569561
VectorT Vector;
570562

571563
public:
572-
explicit FoldingSetVector(unsigned Log2InitSize = 6)
573-
: Set(Log2InitSize) {
574-
}
564+
explicit FoldingSetVector(unsigned Log2InitSize = 6) : Set(Log2InitSize) {}
565+
566+
using iterator = pointee_iterator<typename VectorT::iterator>;
575567

576-
typedef pointee_iterator<typename VectorT::iterator> iterator;
577568
iterator begin() { return Vector.begin(); }
578569
iterator end() { return Vector.end(); }
579570

580-
typedef pointee_iterator<typename VectorT::const_iterator> const_iterator;
571+
using const_iterator = pointee_iterator<typename VectorT::const_iterator>;
572+
581573
const_iterator begin() const { return Vector.begin(); }
582574
const_iterator end() const { return Vector.end(); }
583575

@@ -667,15 +659,13 @@ template <class T> class FoldingSetIterator : public FoldingSetIteratorImpl {
667659
/// FoldingSetBucketIteratorImpl - This is the common bucket iterator support
668660
/// shared by all folding sets, which knows how to walk a particular bucket
669661
/// of a folding set hash table.
670-
671662
class FoldingSetBucketIteratorImpl {
672663
protected:
673664
void *Ptr;
674665

675666
explicit FoldingSetBucketIteratorImpl(void **Bucket);
676667

677-
FoldingSetBucketIteratorImpl(void **Bucket, bool)
678-
: Ptr(Bucket) {}
668+
FoldingSetBucketIteratorImpl(void **Bucket, bool) : Ptr(Bucket) {}
679669

680670
void advance() {
681671
void *Probe = static_cast<FoldingSetNode*>(Ptr)->getNextInBucket();

include/llvm/ADT/PointerIntPair.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@
1414
#ifndef LLVM_ADT_POINTERINTPAIR_H
1515
#define LLVM_ADT_POINTERINTPAIR_H
1616

17-
#include "llvm/Support/Compiler.h"
1817
#include "llvm/Support/PointerLikeTypeTraits.h"
1918
#include <cassert>
19+
#include <cstdint>
2020
#include <limits>
2121

2222
namespace llvm {
2323

2424
template <typename T> struct DenseMapInfo;
25-
2625
template <typename PointerT, unsigned IntBits, typename PtrTraits>
2726
struct PointerIntPairInfo;
2827

@@ -39,25 +38,24 @@ struct PointerIntPairInfo;
3938
/// for something else. For example, this allows:
4039
/// PointerIntPair<PointerIntPair<void*, 1, bool>, 1, bool>
4140
/// ... and the two bools will land in different bits.
42-
///
4341
template <typename PointerTy, unsigned IntBits, typename IntType = unsigned,
4442
typename PtrTraits = PointerLikeTypeTraits<PointerTy>,
4543
typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>>
4644
class PointerIntPair {
47-
intptr_t Value;
45+
intptr_t Value = 0;
4846

4947
public:
50-
constexpr PointerIntPair() : Value(0) {}
48+
constexpr PointerIntPair() = default;
49+
5150
PointerIntPair(PointerTy PtrVal, IntType IntVal) {
5251
setPointerAndInt(PtrVal, IntVal);
5352
}
53+
5454
explicit PointerIntPair(PointerTy PtrVal) { initWithPointer(PtrVal); }
5555

5656
PointerTy getPointer() const { return Info::getPointer(Value); }
5757

58-
IntType getInt() const {
59-
return (IntType)Info::getInt(Value);
60-
}
58+
IntType getInt() const { return (IntType)Info::getInt(Value); }
6159

6260
void setPointer(PointerTy PtrVal) {
6361
Value = Info::updatePointer(Value, PtrVal);
@@ -88,6 +86,7 @@ class PointerIntPair {
8886
}
8987

9088
void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); }
89+
9190
void setFromOpaqueValue(void *Val) {
9291
Value = reinterpret_cast<intptr_t>(Val);
9392
}
@@ -108,14 +107,18 @@ class PointerIntPair {
108107
bool operator==(const PointerIntPair &RHS) const {
109108
return Value == RHS.Value;
110109
}
110+
111111
bool operator!=(const PointerIntPair &RHS) const {
112112
return Value != RHS.Value;
113113
}
114+
114115
bool operator<(const PointerIntPair &RHS) const { return Value < RHS.Value; }
115116
bool operator>(const PointerIntPair &RHS) const { return Value > RHS.Value; }
117+
116118
bool operator<=(const PointerIntPair &RHS) const {
117119
return Value <= RHS.Value;
118120
}
121+
119122
bool operator>=(const PointerIntPair &RHS) const {
120123
return Value >= RHS.Value;
121124
}
@@ -180,21 +183,25 @@ struct isPodLike<PointerIntPair<PointerTy, IntBits, IntType>> {
180183
// Provide specialization of DenseMapInfo for PointerIntPair.
181184
template <typename PointerTy, unsigned IntBits, typename IntType>
182185
struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType>> {
183-
typedef PointerIntPair<PointerTy, IntBits, IntType> Ty;
186+
using Ty = PointerIntPair<PointerTy, IntBits, IntType>;
187+
184188
static Ty getEmptyKey() {
185189
uintptr_t Val = static_cast<uintptr_t>(-1);
186190
Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable;
187191
return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val));
188192
}
193+
189194
static Ty getTombstoneKey() {
190195
uintptr_t Val = static_cast<uintptr_t>(-2);
191196
Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
192197
return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val));
193198
}
199+
194200
static unsigned getHashValue(Ty V) {
195201
uintptr_t IV = reinterpret_cast<uintptr_t>(V.getOpaqueValue());
196202
return unsigned(IV) ^ unsigned(IV >> 9);
197203
}
204+
198205
static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; }
199206
};
200207

@@ -207,16 +214,20 @@ struct PointerLikeTypeTraits<
207214
getAsVoidPointer(const PointerIntPair<PointerTy, IntBits, IntType> &P) {
208215
return P.getOpaqueValue();
209216
}
217+
210218
static inline PointerIntPair<PointerTy, IntBits, IntType>
211219
getFromVoidPointer(void *P) {
212220
return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
213221
}
222+
214223
static inline PointerIntPair<PointerTy, IntBits, IntType>
215224
getFromVoidPointer(const void *P) {
216225
return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
217226
}
227+
218228
enum { NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits };
219229
};
220230

221231
} // end namespace llvm
222-
#endif
232+
233+
#endif // LLVM_ADT_POINTERINTPAIR_H

include/llvm/ADT/PointerSumType.h

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#define LLVM_ADT_POINTERSUMTYPE_H
1212

1313
#include "llvm/ADT/DenseMapInfo.h"
14-
#include "llvm/Support/Compiler.h"
1514
#include "llvm/Support/PointerLikeTypeTraits.h"
15+
#include <cassert>
16+
#include <cstdint>
17+
#include <type_traits>
1618

1719
namespace llvm {
1820

@@ -24,16 +26,15 @@ template <uintptr_t N, typename PointerArgT,
2426
typename TraitsArgT = PointerLikeTypeTraits<PointerArgT>>
2527
struct PointerSumTypeMember {
2628
enum { Tag = N };
27-
typedef PointerArgT PointerT;
28-
typedef TraitsArgT TraitsT;
29+
using PointerT = PointerArgT;
30+
using TraitsT = TraitsArgT;
2931
};
3032

3133
namespace detail {
3234

33-
template <typename TagT, typename... MemberTs>
34-
struct PointerSumTypeHelper;
35+
template <typename TagT, typename... MemberTs> struct PointerSumTypeHelper;
3536

36-
}
37+
} // end namespace detail
3738

3839
/// A sum type over pointer-like types.
3940
///
@@ -60,12 +61,12 @@ struct PointerSumTypeHelper;
6061
/// There is no support for constructing or accessing with a dynamic tag as
6162
/// that would fundamentally violate the type safety provided by the sum type.
6263
template <typename TagT, typename... MemberTs> class PointerSumType {
63-
uintptr_t Value;
64+
uintptr_t Value = 0;
6465

65-
typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT;
66+
using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>;
6667

6768
public:
68-
constexpr PointerSumType() : Value(0) {}
69+
constexpr PointerSumType() = default;
6970

7071
/// A typed constructor for a specific tagged member of the sum type.
7172
template <TagT N>
@@ -128,14 +129,14 @@ struct PointerSumTypeHelper : MemberTs... {
128129
template <TagT N> static void LookupOverload(...);
129130
template <TagT N> struct Lookup {
130131
// Compute a particular member type by resolving the lookup helper ovorload.
131-
typedef decltype(LookupOverload<N>(
132-
static_cast<PointerSumTypeHelper *>(nullptr))) MemberT;
132+
using MemberT = decltype(
133+
LookupOverload<N>(static_cast<PointerSumTypeHelper *>(nullptr)));
133134

134135
/// The Nth member's pointer type.
135-
typedef typename MemberT::PointerT PointerT;
136+
using PointerT = typename MemberT::PointerT;
136137

137138
/// The Nth member's traits type.
138-
typedef typename MemberT::TraitsT TraitsT;
139+
using TraitsT = typename MemberT::TraitsT;
139140
};
140141

141142
// Next we need to compute the number of bits available for the discriminant
@@ -171,35 +172,36 @@ struct PointerSumTypeHelper : MemberTs... {
171172
"Each member must pass the checker.");
172173
};
173174

174-
}
175+
} // end namespace detail
175176

176177
// Teach DenseMap how to use PointerSumTypes as keys.
177178
template <typename TagT, typename... MemberTs>
178179
struct DenseMapInfo<PointerSumType<TagT, MemberTs...>> {
179-
typedef PointerSumType<TagT, MemberTs...> SumType;
180-
181-
typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT;
180+
using SumType = PointerSumType<TagT, MemberTs...>;
181+
using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>;
182182
enum { SomeTag = HelperT::MinTag };
183-
typedef typename HelperT::template Lookup<HelperT::MinTag>::PointerT
184-
SomePointerT;
185-
typedef DenseMapInfo<SomePointerT> SomePointerInfo;
183+
using SomePointerT =
184+
typename HelperT::template Lookup<HelperT::MinTag>::PointerT;
185+
using SomePointerInfo = DenseMapInfo<SomePointerT>;
186186

187187
static inline SumType getEmptyKey() {
188188
return SumType::create<SomeTag>(SomePointerInfo::getEmptyKey());
189189
}
190+
190191
static inline SumType getTombstoneKey() {
191-
return SumType::create<SomeTag>(
192-
SomePointerInfo::getTombstoneKey());
192+
return SumType::create<SomeTag>(SomePointerInfo::getTombstoneKey());
193193
}
194+
194195
static unsigned getHashValue(const SumType &Arg) {
195196
uintptr_t OpaqueValue = Arg.getOpaqueValue();
196197
return DenseMapInfo<uintptr_t>::getHashValue(OpaqueValue);
197198
}
199+
198200
static bool isEqual(const SumType &LHS, const SumType &RHS) {
199201
return LHS == RHS;
200202
}
201203
};
202204

203-
}
205+
} // end namespace llvm
204206

205-
#endif
207+
#endif // LLVM_ADT_POINTERSUMTYPE_H

0 commit comments

Comments
 (0)