LLVM  10.0.0svn
NativeTypePointer.cpp
Go to the documentation of this file.
1 //===- NativeTypePointer.cpp - info about pointer type ----------*- 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 
10 
12 
13 #include <cassert>
14 
15 using namespace llvm;
16 using namespace llvm::codeview;
17 using namespace llvm::pdb;
18 
19 NativeTypePointer::NativeTypePointer(NativeSession &Session, SymIndexId Id,
21  : NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI) {
22  assert(TI.isSimple());
23  assert(TI.getSimpleMode() != SimpleTypeMode::Direct);
24 }
25 
29  : NativeRawSymbol(Session, PDB_SymType::PointerType, Id), TI(TI),
30  Record(std::move(Record)) {}
31 
33 
34 void NativeTypePointer::dump(raw_ostream &OS, int Indent,
35  PdbSymbolIdField ShowIdFields,
36  PdbSymbolIdField RecurseIdFields) const {
37  NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
38 
39  if (isMemberPointer()) {
40  dumpSymbolIdField(OS, "classParentId", getClassParentId(), Indent, Session,
41  PdbSymbolIdField::ClassParent, ShowIdFields,
42  RecurseIdFields);
43  }
44  dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
45  PdbSymbolIdField::LexicalParent, ShowIdFields,
46  RecurseIdFields);
47  dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
48  PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
49  dumpSymbolField(OS, "length", getLength(), Indent);
50  dumpSymbolField(OS, "constType", isConstType(), Indent);
51  dumpSymbolField(OS, "isPointerToDataMember", isPointerToDataMember(), Indent);
52  dumpSymbolField(OS, "isPointerToMemberFunction", isPointerToMemberFunction(),
53  Indent);
54  dumpSymbolField(OS, "RValueReference", isRValueReference(), Indent);
55  dumpSymbolField(OS, "reference", isReference(), Indent);
56  dumpSymbolField(OS, "restrictedType", isRestrictedType(), Indent);
57  if (isMemberPointer()) {
58  if (isSingleInheritance())
59  dumpSymbolField(OS, "isSingleInheritance", 1, Indent);
60  else if (isMultipleInheritance())
61  dumpSymbolField(OS, "isMultipleInheritance", 1, Indent);
62  else if (isVirtualInheritance())
63  dumpSymbolField(OS, "isVirtualInheritance", 1, Indent);
64  }
65  dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
66  dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
67 }
68 
70  if (!isMemberPointer())
71  return 0;
72 
73  assert(Record);
74  const MemberPointerInfo &MPI = Record->getMemberInfo();
76 }
77 
78 uint64_t NativeTypePointer::getLength() const {
79  if (Record)
80  return Record->getSize();
81 
82  switch (TI.getSimpleMode()) {
83  case SimpleTypeMode::NearPointer:
84  case SimpleTypeMode::FarPointer:
85  case SimpleTypeMode::HugePointer:
86  return 2;
87  case SimpleTypeMode::NearPointer32:
88  case SimpleTypeMode::FarPointer32:
89  return 4;
90  case SimpleTypeMode::NearPointer64:
91  return 8;
92  case SimpleTypeMode::NearPointer128:
93  return 16;
94  default:
95  assert(false && "invalid simple type mode!");
96  }
97  return 0;
98 }
99 
101  // This is the pointee SymIndexId.
102  TypeIndex Referent = Record ? Record->ReferentType : TI.makeDirect();
103 
104  return Session.getSymbolCache().findSymbolByTypeIndex(Referent);
105 }
106 
108  if (!Record)
109  return false;
110  return Record->getMode() == PointerMode::LValueReference;
111 }
112 
114  if (!Record)
115  return false;
116  return Record->getMode() == PointerMode::RValueReference;
117 }
118 
120  if (!Record)
121  return false;
122  return Record->getMode() == PointerMode::PointerToDataMember;
123 }
124 
126  if (!Record)
127  return false;
128  return Record->getMode() == PointerMode::PointerToMemberFunction;
129 }
130 
132  if (!Record)
133  return false;
134  return (Record->getOptions() & PointerOptions::Const) != PointerOptions::None;
135 }
136 
138  if (!Record)
139  return false;
140  return (Record->getOptions() & PointerOptions::Restrict) !=
142 }
143 
145  if (!Record)
146  return false;
147  return (Record->getOptions() & PointerOptions::Volatile) !=
149 }
150 
152  if (!Record)
153  return false;
154  return (Record->getOptions() & PointerOptions::Unaligned) !=
156 }
157 
158 static inline bool isInheritanceKind(const MemberPointerInfo &MPI,
161  return (MPI.getRepresentation() == P1 || MPI.getRepresentation() == P2);
162 }
163 
165  if (!isMemberPointer())
166  return false;
167  return isInheritanceKind(
168  Record->getMemberInfo(),
169  PointerToMemberRepresentation::SingleInheritanceData,
170  PointerToMemberRepresentation::SingleInheritanceFunction);
171 }
172 
174  if (!isMemberPointer())
175  return false;
176  return isInheritanceKind(
177  Record->getMemberInfo(),
178  PointerToMemberRepresentation::MultipleInheritanceData,
179  PointerToMemberRepresentation::MultipleInheritanceFunction);
180 }
181 
183  if (!isMemberPointer())
184  return false;
185  return isInheritanceKind(
186  Record->getMemberInfo(),
187  PointerToMemberRepresentation::VirtualInheritanceData,
188  PointerToMemberRepresentation::VirtualInheritanceFunction);
189 }
190 
193 }
NativeTypePointer(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI)
uint64_t getLength() const override
TypeIndex makeDirect() const
Definition: TypeIndex.h:136
bool isUnalignedType() const override
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
SimpleTypeMode getSimpleMode() const
Definition: TypeIndex.h:131
Definition: BitVector.h:937
SymIndexId getTypeId() const override
A 32-bit type reference.
Definition: TypeIndex.h:95
Class to represent pointers.
Definition: DerivedTypes.h:570
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bkedss5f.aspx.
Definition: PDBTypes.h:241
PointerToMemberRepresentation getRepresentation() const
Definition: TypeRecord.h:115
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:48
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:185
bool isMultipleInheritance() const override
bool isRestrictedType() const override
SymIndexId getClassParentId() const override
bool isVirtualInheritance() const override
bool isReference() const override
bool isRValueReference() const override
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI)
static bool isInheritanceKind(const MemberPointerInfo &MPI, PointerToMemberRepresentation P1, PointerToMemberRepresentation P2)
SymbolCache & getSymbolCache()
PointerToMemberRepresentation
Equivalent to CV_pmtype_e.
Definition: CodeView.h:371
bool isConstType() const override
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isVolatileType() const override
bool isSingleInheritance() const override
bool isPointerToDataMember() const override
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
bool isPointerToMemberFunction() const override
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override