LLVM 19.0.0git
NativeTypeFunctionSig.cpp
Go to the documentation of this file.
1//===- NativeTypeFunctionSig.cpp - info about function signature -*- 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
17
18using namespace llvm;
19using namespace llvm::codeview;
20using namespace llvm::pdb;
21
22namespace {
23// This is kind of a silly class, hence why we keep it private to the file.
24// It's only purpose is to wrap the real type record. I guess this is so that
25// we can have the lexical parent point to the function instead of the global
26// scope.
27class NativeTypeFunctionArg : public NativeRawSymbol {
28public:
29 NativeTypeFunctionArg(NativeSession &Session,
30 std::unique_ptr<PDBSymbol> RealType)
32 RealType(std::move(RealType)) {}
33
34 void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields,
35 PdbSymbolIdField RecurseIdFields) const override {
36 NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
37
38 dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
39 PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
40 }
41
42 SymIndexId getTypeId() const override { return RealType->getSymIndexId(); }
43
44 std::unique_ptr<PDBSymbol> RealType;
45};
46
47class NativeEnumFunctionArgs : public IPDBEnumChildren<PDBSymbol> {
48public:
49 NativeEnumFunctionArgs(NativeSession &Session,
50 std::unique_ptr<NativeEnumTypes> TypeEnumerator)
51 : Session(Session), TypeEnumerator(std::move(TypeEnumerator)) {}
52
53 uint32_t getChildCount() const override {
54 return TypeEnumerator->getChildCount();
55 }
56 std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override {
57 return wrap(TypeEnumerator->getChildAtIndex(Index));
58 }
59 std::unique_ptr<PDBSymbol> getNext() override {
60 return wrap(TypeEnumerator->getNext());
61 }
62
63 void reset() override { TypeEnumerator->reset(); }
64
65private:
66 std::unique_ptr<PDBSymbol> wrap(std::unique_ptr<PDBSymbol> S) const {
67 if (!S)
68 return nullptr;
69 auto NTFA = std::make_unique<NativeTypeFunctionArg>(Session, std::move(S));
70 return PDBSymbol::create(Session, std::move(NTFA));
71 }
72 NativeSession &Session;
73 std::unique_ptr<NativeEnumTypes> TypeEnumerator;
74};
75} // namespace
76
78 SymIndexId Id,
82 Proc(std::move(Proc)), Index(Index), IsMemberFunction(false) {}
83
88 MemberFunc(std::move(MemberFunc)), Index(Index), IsMemberFunction(true) {}
89
91 if (IsMemberFunction) {
92 ClassParentId =
94 initializeArgList(MemberFunc.ArgumentList);
95 } else {
96 initializeArgList(Proc.ArgumentList);
97 }
98}
99
101
102void NativeTypeFunctionSig::initializeArgList(codeview::TypeIndex ArgListTI) {
104 CVType CVT = Tpi.typeCollection().getType(ArgListTI);
105
106 cantFail(TypeDeserializer::deserializeAs<ArgListRecord>(CVT, ArgList));
107}
108
110 PdbSymbolIdField ShowIdFields,
111 PdbSymbolIdField RecurseIdFields) const {
112
113 NativeRawSymbol::dump(OS, Indent, ShowIdFields, RecurseIdFields);
114
115 dumpSymbolIdField(OS, "lexicalParentId", 0, Indent, Session,
117 RecurseIdFields);
118
119 dumpSymbolField(OS, "callingConvention", getCallingConvention(), Indent);
120 dumpSymbolField(OS, "count", getCount(), Indent);
121 dumpSymbolIdField(OS, "typeId", getTypeId(), Indent, Session,
122 PdbSymbolIdField::Type, ShowIdFields, RecurseIdFields);
123 if (IsMemberFunction)
124 dumpSymbolField(OS, "thisAdjust", getThisAdjust(), Indent);
125 dumpSymbolField(OS, "constructor", hasConstructor(), Indent);
126 dumpSymbolField(OS, "constType", isConstType(), Indent);
127 dumpSymbolField(OS, "isConstructorVirtualBase", isConstructorVirtualBase(),
128 Indent);
129 dumpSymbolField(OS, "isCxxReturnUdt", isCxxReturnUdt(), Indent);
130 dumpSymbolField(OS, "unalignedType", isUnalignedType(), Indent);
131 dumpSymbolField(OS, "volatileType", isVolatileType(), Indent);
132}
133
134std::unique_ptr<IPDBEnumSymbols>
137 return std::make_unique<NullEnumerator<PDBSymbol>>();
138
139 auto NET = std::make_unique<NativeEnumTypes>(Session,
140 /* copy */ ArgList.ArgIndices);
141 return std::unique_ptr<IPDBEnumSymbols>(
142 new NativeEnumFunctionArgs(Session, std::move(NET)));
143}
144
146 if (!IsMemberFunction)
147 return 0;
148
149 return ClassParentId;
150}
151
153 return IsMemberFunction ? MemberFunc.CallConv : Proc.CallConv;
154}
155
157 return IsMemberFunction ? (1 + MemberFunc.getParameterCount())
159}
160
162 TypeIndex ReturnTI =
163 IsMemberFunction ? MemberFunc.getReturnType() : Proc.getReturnType();
164
166 return Result;
167}
168
170 return IsMemberFunction ? MemberFunc.getThisPointerAdjustment() : 0;
171}
172
174 if (!IsMemberFunction)
175 return false;
176
177 return (MemberFunc.getOptions() & FunctionOptions::Constructor) !=
178 FunctionOptions::None;
179}
180
181bool NativeTypeFunctionSig::isConstType() const { return false; }
182
184 if (!IsMemberFunction)
185 return false;
186
187 return (MemberFunc.getOptions() &
188 FunctionOptions::ConstructorWithVirtualBases) !=
189 FunctionOptions::None;
190}
191
194 IsMemberFunction ? MemberFunc.getOptions() : Proc.getOptions();
195 return (Options & FunctionOptions::CxxReturnUdt) != FunctionOptions::None;
196}
197
198bool NativeTypeFunctionSig::isUnalignedType() const { return false; }
199
200bool NativeTypeFunctionSig::isVolatileType() const { return false; }
basic Basic Alias true
static LVOptions Options
Definition: LVOptions.cpp:25
raw_pwrite_stream & OS
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
std::vector< TypeIndex > ArgIndices
Definition: TypeRecord.h:246
int32_t getThisPointerAdjustment() const
Definition: TypeRecord.h:193
FunctionOptions getOptions() const
Definition: TypeRecord.h:190
TypeIndex getReturnType() const
Definition: TypeRecord.h:157
uint16_t getParameterCount() const
Definition: TypeRecord.h:160
FunctionOptions getOptions() const
Definition: TypeRecord.h:159
CallingConvention CallConv
Definition: TypeRecord.h:164
A 32-bit type reference.
Definition: TypeIndex.h:96
virtual uint32_t getChildCount() const =0
virtual ChildTypePtr getNext()=0
virtual ChildTypePtr getChildAtIndex(uint32_t Index) const =0
SymIndexId getTypeId() const override
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
SymbolCache & getSymbolCache()
bool isConstructorVirtualBase() const override
SymIndexId getClassParentId() const override
NativeTypeFunctionSig(NativeSession &Session, SymIndexId Id, codeview::TypeIndex TI, codeview::ProcedureRecord Proc)
void dump(raw_ostream &OS, int Indent, PdbSymbolIdField ShowIdFields, PdbSymbolIdField RecurseIdFields) const override
SymIndexId getTypeId() const override
PDB_CallingConv getCallingConvention() const override
std::unique_ptr< IPDBEnumSymbols > findChildren(PDB_SymType Type) const override
codeview::MemberFunctionRecord MemberFunc
Expected< TpiStream & > getPDBTpiStream()
Definition: PDBFile.cpp:301
static std::unique_ptr< PDBSymbol > create(const IPDBSession &PDBSession, std::unique_ptr< IPDBRawSymbol > RawSymbol)
Definition: PDBSymbol.cpp:102
SymIndexId findSymbolByTypeIndex(codeview::TypeIndex TI) const
codeview::LazyRandomTypeCollection & typeCollection()
Definition: TpiStream.h:59
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
Definition: CodeView.h:184
uint32_t SymIndexId
Definition: PDBTypes.h:26
void dumpSymbolField(raw_ostream &OS, StringRef Name, T Value, int Indent)
Definition: PDBExtras.h:47
PDB_SymType
These values correspond to the SymTagEnum enumeration, and are documented here: https://msdn....
Definition: PDBTypes.h:243
void dumpSymbolIdField(raw_ostream &OS, StringRef Name, SymIndexId Value, int Indent, const IPDBSession &Session, PdbSymbolIdField FieldId, PdbSymbolIdField ShowFlags, PdbSymbolIdField RecurseFlags)
Definition: PDBSymbol.cpp:202
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:749
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1858
LLVMAttributeRef wrap(Attribute Attr)
Definition: Attributes.h:282
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858