1//===- NativeTypeArray.cpp - info about arrays ------------------*- 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/PDB/Native/NativeTypeArray.h"
10
11#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
12#include "llvm/DebugInfo/PDB/Native/NativeTypeBuiltin.h"
13#include "llvm/DebugInfo/PDB/Native/NativeTypeEnum.h"
14
15using namespace llvm;
16using namespace llvm::codeview;
17using namespace llvm::pdb;
18
19NativeTypeArray::NativeTypeArray(NativeSession &Session, SymIndexId Id,
20                                 codeview::TypeIndex TI,
21                                 codeview::ArrayRecord Record)
22    : NativeRawSymbol(Session, PDB_SymType::ArrayType, Id), Record(Record),
23      Index(TI) {}
24NativeTypeArray::~NativeTypeArray() {}
25
26void NativeTypeArray::dump(raw_ostream &OS, int Indent,
27                           PdbSymbolIdField ShowIdFields,
28                           PdbSymbolIdField RecurseIdFields) const {
29  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
30
31  dumpSymbolField(OS, "arrayIndexTypeId", getArrayIndexTypeId(), Indent);
32  dumpSymbolIdField(OS, "elementTypeId", getTypeId(), Indent, Session,
33                    PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
34
35  dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
36                    PdbSymbolIdField::LexicalParent, ShowIdFields,
37                    RecurseIdFields);
38  dumpSymbolField(OS, "length", getLength(), Indent);
39  dumpSymbolField(OS, "count", getCount(), Indent);
40  dumpSymbolField(OS, "constType", isConstType(), Indent);
41  dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
42  dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
43}
44
45SymIndexId NativeTypeArray::getArrayIndexTypeId() const {
46  return Session.getSymbolCache().findSymbolByTypeIndex(Record.getIndexType());
47}
48
49bool NativeTypeArray::isConstType() const { return false; }
50
51bool NativeTypeArray::isUnalignedType() const { return false; }
52
53bool NativeTypeArray::isVolatileType() const { return false; }
54
55uint32_t NativeTypeArray::getCount() const {
56  NativeRawSymbol &Element =
57      Session.getSymbolCache().getNativeSymbolById(getTypeId());
58  return getLength() / Element.getLength();
59}
60
61SymIndexId NativeTypeArray::getTypeId() const {
62  return Session.getSymbolCache().findSymbolByTypeIndex(
63      Record.getElementType());
64}
65
66uint64_t NativeTypeArray::getLength() const { return Record.Size; }