1 //===- PDBSymbolTypeFunctionSig.cpp - --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
12 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBSession.h"
15 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
18 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
23 using namespace llvm::pdb;
26 class FunctionArgEnumerator : public IPDBEnumSymbols {
28 typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType;
30 FunctionArgEnumerator(const IPDBSession &PDBSession,
31 const PDBSymbolTypeFunctionSig &Sig)
32 : Session(PDBSession),
33 Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {}
35 FunctionArgEnumerator(const IPDBSession &PDBSession,
36 std::unique_ptr<ArgEnumeratorType> ArgEnumerator)
37 : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {}
39 uint32_t getChildCount() const override {
40 return Enumerator->getChildCount();
43 std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override {
44 auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index);
45 if (!FunctionArgSymbol)
47 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
50 std::unique_ptr<PDBSymbol> getNext() override {
51 auto FunctionArgSymbol = Enumerator->getNext();
52 if (!FunctionArgSymbol)
54 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
57 void reset() override { Enumerator->reset(); }
59 MyType *clone() const override {
60 std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone());
61 return new FunctionArgEnumerator(Session, std::move(Clone));
65 const IPDBSession &Session;
66 std::unique_ptr<ArgEnumeratorType> Enumerator;
70 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
71 const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
72 : PDBSymbol(PDBSession, std::move(Symbol)) {
73 assert(RawSymbol->getSymTag() == PDB_SymType::FunctionSig);
76 std::unique_ptr<IPDBEnumSymbols>
77 PDBSymbolTypeFunctionSig::getArguments() const {
78 return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
81 void PDBSymbolTypeFunctionSig::dump(PDBSymDumper &Dumper) const {
85 void PDBSymbolTypeFunctionSig::dumpRight(PDBSymDumper &Dumper) const {
86 Dumper.dumpRight(*this);
89 bool PDBSymbolTypeFunctionSig::isCVarArgs() const {
90 auto SigArguments = getArguments();
93 uint32_t NumArgs = SigArguments->getChildCount();
96 auto Last = SigArguments->getChildAtIndex(NumArgs - 1);
97 if (auto Builtin = llvm::dyn_cast_or_null<PDBSymbolTypeBuiltin>(Last.get())) {
98 if (Builtin->getBuiltinType() == PDB_BuiltinType::None)
102 // Note that for a variadic template signature, this method always returns
103 // false since the parameters of the template are specialized.