[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / lib / DebugInfo / CodeView / TypeTableCollection.cpp
blob50ac6fc5906d32b8453e38eb0dff389ceeec567a
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 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/TypeTableCollection.h"
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"
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 std::optional<TypeIndex> TypeTableCollection::getFirst() {
25 if (empty())
26 return std::nullopt;
27 return TypeIndex::fromArrayIndex(0);
30 std::optional<TypeIndex> TypeTableCollection::getNext(TypeIndex Prev) {
31 assert(contains(Prev));
32 ++Prev;
33 if (Prev.toArrayIndex() == size())
34 return std::nullopt;
35 return Prev;
38 CVType TypeTableCollection::getType(TypeIndex Index) {
39 assert(Index.toArrayIndex() < Records.size());
40 return CVType(Records[Index.toArrayIndex()]);
43 StringRef TypeTableCollection::getTypeName(TypeIndex Index) {
44 if (Index.isNoneType() || Index.isSimple())
45 return TypeIndex::simpleTypeName(Index);
47 uint32_t I = Index.toArrayIndex();
48 if (Names[I].data() == nullptr) {
49 StringRef Result = NameStorage.save(computeTypeName(*this, Index));
50 Names[I] = Result;
52 return Names[I];
55 bool TypeTableCollection::contains(TypeIndex Index) {
56 return Index.toArrayIndex() <= size();
59 uint32_t TypeTableCollection::size() { return Records.size(); }
61 uint32_t TypeTableCollection::capacity() { return Records.size(); }
63 bool TypeTableCollection::replaceType(TypeIndex &Index, CVType Data,
64 bool Stabilize) {
65 llvm_unreachable("Method cannot be called");