Skip to content

Commit

Permalink
[ADT, IR] Fix some Clang-tidy modernize-use-equals-delete and Include…
Browse files Browse the repository at this point in the history
… What You Use warnings; other minor fixes (NFC).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288989 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
EugeneZelenko committed Dec 7, 2016
1 parent 4e51983 commit 553d8c8
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 179 deletions.
4 changes: 2 additions & 2 deletions include/llvm/ADT/BitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <utility>

namespace llvm {

Expand All @@ -45,14 +46,13 @@ class BitVector {
BitWord *WordRef;
unsigned BitPos;

reference(); // Undefined

public:
reference(BitVector &b, unsigned Idx) {
WordRef = &b.Bits[Idx / BITWORD_SIZE];
BitPos = Idx % BITWORD_SIZE;
}

reference() = delete;
reference(const reference&) = default;

reference &operator=(reference t) {
Expand Down
32 changes: 19 additions & 13 deletions include/llvm/ADT/ImmutableList.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@

#include "llvm/ADT/FoldingSet.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/DataTypes.h"
#include <cassert>
#include <cstdint>
#include <new>

namespace llvm {

template <typename T> class ImmutableListFactory;

template <typename T>
class ImmutableListImpl : public FoldingSetNode {
friend class ImmutableListFactory<T>;

T Head;
const ImmutableListImpl* Tail;

ImmutableListImpl(const T& head, const ImmutableListImpl* tail = nullptr)
: Head(head), Tail(tail) {}

friend class ImmutableListFactory<T>;

void operator=(const ImmutableListImpl&) = delete;
ImmutableListImpl(const ImmutableListImpl&) = delete;

public:
ImmutableListImpl(const ImmutableListImpl &) = delete;
ImmutableListImpl &operator=(const ImmutableListImpl &) = delete;

const T& getHead() const { return Head; }
const ImmutableListImpl* getTail() const { return Tail; }

Expand Down Expand Up @@ -79,15 +80,17 @@ class ImmutableList {
}

class iterator {
const ImmutableListImpl<T>* L;
const ImmutableListImpl<T>* L = nullptr;

public:
iterator() : L(nullptr) {}
iterator() = default;
iterator(ImmutableList l) : L(l.getInternalPointer()) {}

iterator& operator++() { L = L->getTail(); return *this; }
bool operator==(const iterator& I) const { return L == I.L; }
bool operator!=(const iterator& I) const { return L != I.L; }
const value_type& operator*() const { return L->getHead(); }

ImmutableList getList() const { return L; }
};

Expand Down Expand Up @@ -121,7 +124,7 @@ class ImmutableList {

/// getHead - Returns the head of the list.
const T& getHead() {
assert (!isEmpty() && "Cannot get the head of an empty list.");
assert(!isEmpty() && "Cannot get the head of an empty list.");
return X->getHead();
}

Expand All @@ -145,7 +148,7 @@ class ImmutableListFactory {
uintptr_t Allocator;

bool ownsAllocator() const {
return Allocator & 0x1 ? false : true;
return (Allocator & 0x1) == 0;
}

BumpPtrAllocator& getAllocator() const {
Expand Down Expand Up @@ -203,27 +206,30 @@ class ImmutableListFactory {
//===----------------------------------------------------------------------===//

template<typename T> struct DenseMapInfo;
template<typename T> struct DenseMapInfo<ImmutableList<T> > {
template<typename T> struct DenseMapInfo<ImmutableList<T>> {
static inline ImmutableList<T> getEmptyKey() {
return reinterpret_cast<ImmutableListImpl<T>*>(-1);
}

static inline ImmutableList<T> getTombstoneKey() {
return reinterpret_cast<ImmutableListImpl<T>*>(-2);
}

static unsigned getHashValue(ImmutableList<T> X) {
uintptr_t PtrVal = reinterpret_cast<uintptr_t>(X.getInternalPointer());
return (unsigned((uintptr_t)PtrVal) >> 4) ^
(unsigned((uintptr_t)PtrVal) >> 9);
}

static bool isEqual(ImmutableList<T> X1, ImmutableList<T> X2) {
return X1 == X2;
}
};

template <typename T> struct isPodLike;
template <typename T>
struct isPodLike<ImmutableList<T> > { static const bool value = true; };
struct isPodLike<ImmutableList<T>> { static const bool value = true; };

} // end llvm namespace
} // end namespace llvm

#endif // LLVM_ADT_IMMUTABLELIST_H
20 changes: 12 additions & 8 deletions include/llvm/ADT/ImmutableMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#ifndef LLVM_ADT_IMMUTABLEMAP_H
#define LLVM_ADT_IMMUTABLEMAP_H

#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/ImmutableSet.h"
#include "llvm/Support/Allocator.h"
#include <utility>

namespace llvm {

Expand Down Expand Up @@ -56,7 +59,7 @@ struct ImutKeyValueInfo {
};

template <typename KeyT, typename ValT,
typename ValInfo = ImutKeyValueInfo<KeyT,ValT> >
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
class ImmutableMap {
public:
typedef typename ValInfo::value_type value_type;
Expand Down Expand Up @@ -106,6 +109,9 @@ class ImmutableMap {
Factory(BumpPtrAllocator &Alloc, bool canonicalize = true)
: F(Alloc), Canonicalize(canonicalize) {}

Factory(const Factory &) = delete;
Factory &operator=(const Factory &) = delete;

ImmutableMap getEmptyMap() { return ImmutableMap(F.getEmptyTree()); }

ImmutableMap add(ImmutableMap Old, key_type_ref K, data_type_ref D) {
Expand All @@ -121,10 +127,6 @@ class ImmutableMap {
typename TreeTy::Factory *getTreeFactory() const {
return const_cast<typename TreeTy::Factory *>(&F);
}

private:
Factory(const Factory& RHS) = delete;
void operator=(const Factory& RHS) = delete;
};

bool contains(key_type_ref K) const {
Expand Down Expand Up @@ -203,9 +205,10 @@ class ImmutableMap {
//===--------------------------------------------------===//

class iterator : public ImutAVLValueIterator<ImmutableMap> {
friend class ImmutableMap;

iterator() = default;
explicit iterator(TreeTy *Tree) : iterator::ImutAVLValueIterator(Tree) {}
friend class ImmutableMap;

public:
key_type_ref getKey() const { return (*this)->first; }
Expand Down Expand Up @@ -248,7 +251,7 @@ class ImmutableMap {

// NOTE: This will possibly become the new implementation of ImmutableMap some day.
template <typename KeyT, typename ValT,
typename ValInfo = ImutKeyValueInfo<KeyT,ValT> >
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
class ImmutableMapRef {
public:
typedef typename ValInfo::value_type value_type;
Expand Down Expand Up @@ -362,9 +365,10 @@ class ImmutableMapRef {
//===--------------------------------------------------===//

class iterator : public ImutAVLValueIterator<ImmutableMapRef> {
friend class ImmutableMapRef;

iterator() = default;
explicit iterator(TreeTy *Tree) : iterator::ImutAVLValueIterator(Tree) {}
friend class ImmutableMapRef;

public:
key_type_ref getKey() const { return (*this)->first; }
Expand Down
8 changes: 5 additions & 3 deletions include/llvm/ADT/PackedVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define LLVM_ADT_PACKEDVECTOR_H

#include "llvm/ADT/BitVector.h"
#include <cassert>
#include <limits>

namespace llvm {
Expand Down Expand Up @@ -83,14 +84,15 @@ class PackedVector : public PackedVectorBase<T, BitNum, BitVectorTy,
PackedVector &Vec;
const unsigned Idx;

reference(); // Undefined
public:
reference() = delete;
reference(PackedVector &vec, unsigned idx) : Vec(vec), Idx(idx) {}

reference &operator=(T val) {
Vec.setValue(Vec.Bits, Idx, val);
return *this;
}

operator T() const {
return Vec.getValue(Vec.Bits, Idx);
}
Expand Down Expand Up @@ -144,6 +146,6 @@ class PackedVector : public PackedVectorBase<T, BitNum, BitVectorTy,
// Leave BitNum=0 undefined.
template <typename T> class PackedVector<T, 0>;

} // end llvm namespace
} // end namespace llvm

#endif
#endif // LLVM_ADT_PACKEDVECTOR_H
24 changes: 15 additions & 9 deletions include/llvm/ADT/ScopedHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
#define LLVM_ADT_SCOPEDHASHTABLE_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/Allocator.h"
#include <cassert>
#include <new>

namespace llvm {

Expand All @@ -46,6 +49,7 @@ class ScopedHashTableVal {
ScopedHashTableVal *NextForKey;
K Key;
V Val;

ScopedHashTableVal(const K &key, const V &val) : Key(key), Val(val) {}

public:
Expand Down Expand Up @@ -89,18 +93,19 @@ class ScopedHashTableScope {
/// LastValInScope - This is the last value that was inserted for this scope
/// or null if none have been inserted yet.
ScopedHashTableVal<K, V> *LastValInScope;
void operator=(ScopedHashTableScope &) = delete;
ScopedHashTableScope(ScopedHashTableScope &) = delete;

public:
ScopedHashTableScope(ScopedHashTable<K, V, KInfo, AllocatorTy> &HT);
ScopedHashTableScope(ScopedHashTableScope &) = delete;
ScopedHashTableScope &operator=(ScopedHashTableScope &) = delete;
~ScopedHashTableScope();

ScopedHashTableScope *getParentScope() { return PrevScope; }
const ScopedHashTableScope *getParentScope() const { return PrevScope; }

private:
friend class ScopedHashTable<K, V, KInfo, AllocatorTy>;

ScopedHashTableVal<K, V> *getLastValInScope() {
return LastValInScope;
}
Expand Down Expand Up @@ -150,19 +155,20 @@ class ScopedHashTable {
typedef unsigned size_type;

private:
friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>;

typedef ScopedHashTableVal<K, V> ValTy;
DenseMap<K, ValTy*, KInfo> TopLevelMap;
ScopeTy *CurScope;
ScopeTy *CurScope = nullptr;

AllocatorTy Allocator;

ScopedHashTable(const ScopedHashTable &); // NOT YET IMPLEMENTED
void operator=(const ScopedHashTable &); // NOT YET IMPLEMENTED
friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>;

public:
ScopedHashTable() : CurScope(nullptr) {}
ScopedHashTable() = default;
ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {}
ScopedHashTable(const ScopedHashTable &) = delete;
ScopedHashTable &operator=(const ScopedHashTable &) = delete;

~ScopedHashTable() {
assert(!CurScope && TopLevelMap.empty() && "Scope imbalance!");
}
Expand Down Expand Up @@ -253,4 +259,4 @@ ScopedHashTableScope<K, V, KInfo, Allocator>::~ScopedHashTableScope() {

} // end namespace llvm

#endif
#endif // LLVM_ADT_SCOPEDHASHTABLE_H
Loading

0 comments on commit 553d8c8

Please sign in to comment.