1 //===- TypeTableCollection.cpp -------------------------------- *- C++ --*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
10 
11 #include "llvm/DebugInfo/CodeView/CodeView.h"
12 #include "llvm/DebugInfo/CodeView/RecordName.h"
13 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
14 #include "llvm/Support/ErrorHandling.h"
15 
16 using namespace llvm;
17 using namespace llvm::codeview;
18 
19 TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records)
20     : NameStorage(Allocator), Records(Records) {
21   Names.resize(Records.size());
22 }
23 
24 Optional<TypeIndex> TypeTableCollection::getFirst() {
25   if (empty())
26     return None;
27   return TypeIndex::fromArrayIndex(0);
28 }
29 
30 Optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) {
31   assert(contains(Prev));
32   ++Prev;
33   if (Prev.toArrayIndex() == size())
34     return None;
35   return Prev;
36 }
37 
38 CVType TypeTableCollection::getType(TypeIndex Index) {
39   assert(Index.toArrayIndex() < Records.size());
40   return CVType(Records[Index.toArrayIndex()]);
41 }
42 
43 StringRef TypeTableCollection::getTypeName(TypeIndex Index) {
44   if (Index.isNoneType() || Index.isSimple())
45     return TypeIndex::simpleTypeName(Index);
46 
47   uint32_t I = Index.toArrayIndex();
48   if (Names[I].data() == nullptr) {
49     StringRef Result = NameStorage.save(computeTypeName(*this, Index));
50     Names[I] = Result;
51   }
52   return Names[I];
53 }
54 
55 bool TypeTableCollection::contains(TypeIndex Index) {
56   return Index.toArrayIndex() <= size();
57 }
58 
59 uint32_t TypeTableCollection::size() { return Records.size(); }
60 
61 uint32_t TypeTableCollection::capacity() { return Records.size(); }
62 
63 bool TypeTableCollection::replaceType(TypeIndex &Index, CVType Data,
64                                       bool Stabilize) {
65   llvm_unreachable("Method cannot be called");
66 }
67