clang: include/clang/Analysis/Support/BumpVector.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18#ifndef LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H

19#define LLVM_CLANG_ANALYSIS_SUPPORT_BUMPVECTOR_H

20

21#include "llvm/ADT/PointerIntPair.h"

22#include "llvm/Support/Allocator.h"

23#include

24#include

25#include

26#include

27#include

28#include <type_traits>

29

31

33 llvm::PointerIntPair<llvm::BumpPtrAllocator*, 1> Alloc;

34

35public:

36

37

39

41 Other.Alloc.setInt(false);

42 Other.Alloc.setPointer(nullptr);

43 }

44

45

46

48

49

50

53

54

55

56

58

60 if (Alloc.getInt())

61 delete Alloc.getPointer();

62 }

63

64 llvm::BumpPtrAllocator &getAllocator() { return *Alloc.getPointer(); }

65};

66

67template

69 T *Begin = nullptr;

70 T *End = nullptr;

71 T *Capacity = nullptr;

72

73public:

74

77 }

78

80 if (std::is_class::value) {

81

82 destroy_range(Begin, End);

83 }

84 }

85

91

94

99

100

105

106

112 }

113

116

118 assert(Begin + idx < End);

119 return Begin[idx];

120 }

122 assert(Begin + idx < End);

123 return Begin[idx];

124 }

125

127 return begin()[0];

128 }

130 return begin()[0];

131 }

132

134 return end()[-1];

135 }

137 return end()[-1];

138 }

139

141 --End;

142 End->~T();

143 }

144

149 }

150

152 if (std::is_class::value) {

153 destroy_range(Begin, End);

154 }

156 }

157

158

161 }

162

163

166 }

167

169 if (End < Capacity) {

170 Retry:

171 new (End) T(Elt);

172 ++End;

173 return;

174 }

175 grow(C);

176 goto Retry;

177 }

178

179

180

183 assert(I >= Begin && I <= End && "Iterator out of bounds.");

184 if (End + Cnt <= Capacity) {

185 Retry:

186 move_range_right(I, End, Cnt);

187 construct_range(I, I + Cnt, E);

188 End += Cnt;

189 return I + Cnt;

190 }

192 grow(C, size() + Cnt);

194 goto Retry;

195 }

196

198 if (unsigned(Capacity-Begin) < N)

199 grow(C, N);

200 }

201

202

203

205

206private:

207

208

210

211 void construct_range(T *S, T *E, const T &Elt) {

212 for (; S != E; ++S)

213 new (S) T(Elt);

214 }

215

216 void destroy_range(T *S, T *E) {

217 while (S != E) {

218 --E;

219 E->~T();

220 }

221 }

222

223 void move_range_right(T *S, T *E, size_t D) {

224 for (T *I = E + D - 1, *IL = S + D - 1; I != IL; --I) {

225 --E;

226 new (I) T(*E);

227 E->~T();

228 }

229 }

230};

231

232

233template

234void BumpVector::grow(BumpVectorContext &C, size_t MinSize) {

235 size_t CurCapacity = Capacity-Begin;

236 size_t CurSize = size();

237 size_t NewCapacity = 2*CurCapacity;

238 if (NewCapacity < MinSize)

239 NewCapacity = MinSize;

240

241

242 T *NewElts = C.getAllocator().template Allocate(NewCapacity);

243

244

245 if (Begin != End) {

246 if (std::is_class::value) {

247 std::uninitialized_copy(Begin, End, NewElts);

248

249 destroy_range(Begin, End);

250 } else {

251

253 }

254 }

255

256

257

259 End = NewElts+CurSize;

260 Capacity = Begin+NewCapacity;

261}

262

263}

264

265#endif

__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)

__PTRDIFF_TYPE__ ptrdiff_t

BumpVectorContext(const BumpVectorContext &)=delete

BumpVectorContext(llvm::BumpPtrAllocator &A)

Construct a new BumpVectorContext that reuses an existing BumpPtrAllocator.

BumpVectorContext & operator=(const BumpVectorContext &)=delete

BumpVectorContext(BumpVectorContext &&Other)

BumpVectorContext & operator=(BumpVectorContext &&)=delete

llvm::BumpPtrAllocator & getAllocator()

BumpVectorContext()

Construct a new BumpVectorContext that creates a new BumpPtrAllocator and destroys it when the BumpVe...

std::reverse_iterator< const_iterator > const_reverse_iterator

reference operator[](unsigned idx)

ptrdiff_t difference_type

const_reference operator[](unsigned idx) const

const_reference front() const

const_iterator begin() const

const_iterator end() const

iterator insert(iterator I, size_t Cnt, const_reference E, BumpVectorContext &C)

insert - Insert some number of copies of element into a position.

pointer data()

data - Return a pointer to the vector's buffer, even if empty().

BumpVector(BumpVectorContext &C, unsigned N)

void reserve(BumpVectorContext &C, unsigned N)

const T & const_reference

const_reverse_iterator rbegin() const

reverse_iterator rbegin()

std::reverse_iterator< iterator > reverse_iterator

const_pointer data() const

data - Return a pointer to the vector's buffer, even if empty().

const_reference back() const

const_reverse_iterator rend() const

void push_back(const_reference Elt, BumpVectorContext &C)

size_t capacity() const

capacity - Return the total number of elements in the currently allocated buffer.

The JSON file list parser is used to communicate input to InstallAPI.

@ Result

The result type of a method or function.

const FunctionProtoType * T

@ Other

Other implicit parameter.

Diagnostic wrappers for TextAPI types for error reporting.