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
16using namespace llvm;
17using namespace llvm::codeview;
18
19TypeTableCollection::TypeTableCollection(ArrayRef<ArrayRef<uint8_t>> Records)
20 : NameStorage(Allocator), Records(Records) {
21 Names.resize(new_size: Records.size());
22}
23
24std::optional<TypeIndex> TypeTableCollection::getFirst() {
25 if (empty())
26 return std::nullopt;
27 return TypeIndex::fromArrayIndex(Index: 0);
28}
29
30std::optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) {
31 assert(contains(Prev));
32 ++Prev;
33 if (Prev.toArrayIndex() == size())
34 return std::nullopt;
35 return Prev;
36}
37
38CVType TypeTableCollection::getType(TypeIndex Index) {
39 assert(Index.toArrayIndex() < Records.size());
40 return CVType(Records[Index.toArrayIndex()]);
41}
42
43StringRef TypeTableCollection::getTypeName(TypeIndex Index) {
44 if (Index.isNoneType() || Index.isSimple())
45 return TypeIndex::simpleTypeName(TI: Index);
46
47 uint32_t I = Index.toArrayIndex();
48 if (Names[I].data() == nullptr) {
49 StringRef Result = NameStorage.save(S: computeTypeName(Types&: *this, Index));
50 Names[I] = Result;
51 }
52 return Names[I];
53}
54
55bool TypeTableCollection::contains(TypeIndex Index) {
56 return Index.toArrayIndex() <= size();
57}
58
59uint32_t TypeTableCollection::size() { return Records.size(); }
60
61uint32_t TypeTableCollection::capacity() { return Records.size(); }
62
63bool TypeTableCollection::replaceType(TypeIndex &Index, CVType Data,
64 bool Stabilize) {
65 llvm_unreachable("Method cannot be called");
66}
67

source code of llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp