[llvm-exegesis][NFC] Fix typo
[llvm-complete.git] / lib / DebugInfo / CodeView / TypeTableCollection.cpp
blobcf951baa5111ca9b68bbdab99d98938e005a2663
1 //===- TypeTableCollection.cpp -------------------------------- *- C++ --*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
12 #include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
13 #include "llvm/DebugInfo/CodeView/RecordName.h"
14 #include "llvm/Support/BinaryStreamReader.h"
16 using namespace llvm;
17 using namespace llvm::codeview;
19 TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records)
20 : NameStorage(Allocator), Records(Records) {
21 Names.resize(Records.size());
24 Optional<TypeIndex> TypeTableCollection::getFirst() {
25 if (empty())
26 return None;
27 return TypeIndex::fromArrayIndex(0);
30 Optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) {
31 assert(contains(Prev));
32 ++Prev;
33 if (Prev.toArrayIndex() == size())
34 return None;
35 return Prev;
38 CVType TypeTableCollection::getType(TypeIndex Index) {
39 assert(Index.toArrayIndex() < Records.size());
40 ArrayRef<uint8_t> Bytes = Records[Index.toArrayIndex()];
41 const RecordPrefix *Prefix =
42 reinterpret_cast<const RecordPrefix *>(Bytes.data());
43 TypeLeafKind Kind = static_cast<TypeLeafKind>(uint16_t(Prefix->RecordKind));
44 return CVType(Kind, Bytes);
47 StringRef TypeTableCollection::getTypeName(TypeIndex Index) {
48 if (Index.isNoneType() || Index.isSimple())
49 return TypeIndex::simpleTypeName(Index);
51 uint32_t I = Index.toArrayIndex();
52 if (Names[I].data() == nullptr) {
53 StringRef Result = NameStorage.save(computeTypeName(*this, Index));
54 Names[I] = Result;
56 return Names[I];
59 bool TypeTableCollection::contains(TypeIndex Index) {
60 return Index.toArrayIndex() <= size();
63 uint32_t TypeTableCollection::size() { return Records.size(); }
65 uint32_t TypeTableCollection::capacity() { return Records.size(); }