1 //===- PDBSymbolTypeFunctionSig.cpp - --------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
11 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
12 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
13 #include "llvm/DebugInfo/PDB/IPDBSession.h"
14 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
22 using namespace llvm::pdb
;
25 class FunctionArgEnumerator
: public IPDBEnumSymbols
{
27 typedef ConcreteSymbolEnumerator
<PDBSymbolTypeFunctionArg
> ArgEnumeratorType
;
29 FunctionArgEnumerator(const IPDBSession
&PDBSession
,
30 const PDBSymbolTypeFunctionSig
&Sig
)
31 : Session(PDBSession
),
32 Enumerator(Sig
.findAllChildren
<PDBSymbolTypeFunctionArg
>()) {}
34 FunctionArgEnumerator(const IPDBSession
&PDBSession
,
35 std::unique_ptr
<ArgEnumeratorType
> ArgEnumerator
)
36 : Session(PDBSession
), Enumerator(std::move(ArgEnumerator
)) {}
38 uint32_t getChildCount() const override
{
39 return Enumerator
->getChildCount();
42 std::unique_ptr
<PDBSymbol
> getChildAtIndex(uint32_t Index
) const override
{
43 auto FunctionArgSymbol
= Enumerator
->getChildAtIndex(Index
);
44 if (!FunctionArgSymbol
)
46 return Session
.getSymbolById(FunctionArgSymbol
->getTypeId());
49 std::unique_ptr
<PDBSymbol
> getNext() override
{
50 auto FunctionArgSymbol
= Enumerator
->getNext();
51 if (!FunctionArgSymbol
)
53 return Session
.getSymbolById(FunctionArgSymbol
->getTypeId());
56 void reset() override
{ Enumerator
->reset(); }
59 const IPDBSession
&Session
;
60 std::unique_ptr
<ArgEnumeratorType
> Enumerator
;
64 std::unique_ptr
<IPDBEnumSymbols
>
65 PDBSymbolTypeFunctionSig::getArguments() const {
66 return std::make_unique
<FunctionArgEnumerator
>(Session
, *this);
69 void PDBSymbolTypeFunctionSig::dump(PDBSymDumper
&Dumper
) const {
73 void PDBSymbolTypeFunctionSig::dumpRight(PDBSymDumper
&Dumper
) const {
74 Dumper
.dumpRight(*this);
77 bool PDBSymbolTypeFunctionSig::isCVarArgs() const {
78 auto SigArguments
= getArguments();
81 uint32_t NumArgs
= SigArguments
->getChildCount();
84 auto Last
= SigArguments
->getChildAtIndex(NumArgs
- 1);
85 if (auto Builtin
= llvm::dyn_cast_or_null
<PDBSymbolTypeBuiltin
>(Last
.get())) {
86 if (Builtin
->getBuiltinType() == PDB_BuiltinType::None
)
90 // Note that for a variadic template signature, this method always returns
91 // false since the parameters of the template are specialized.