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/ConcreteSymbolEnumerator.h"
11 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
12 #include "llvm/DebugInfo/PDB/IPDBSession.h"
13 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
15 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
21 class FunctionArgEnumerator : public IPDBEnumSymbols {
23 typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType;
25 FunctionArgEnumerator(const IPDBSession &PDBSession,
26 const PDBSymbolTypeFunctionSig &Sig)
27 : Session(PDBSession),
28 Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {}
30 FunctionArgEnumerator(const IPDBSession &PDBSession,
31 std::unique_ptr<ArgEnumeratorType> ArgEnumerator)
32 : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {}
34 uint32_t getChildCount() const { return Enumerator->getChildCount(); }
36 std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const {
37 auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index);
38 if (!FunctionArgSymbol)
40 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
43 std::unique_ptr<PDBSymbol> getNext() {
44 auto FunctionArgSymbol = Enumerator->getNext();
45 if (!FunctionArgSymbol)
47 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
50 void reset() { Enumerator->reset(); }
52 MyType *clone() const {
53 std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone());
54 return new FunctionArgEnumerator(Session, std::move(Clone));
58 const IPDBSession &Session;
59 std::unique_ptr<ArgEnumeratorType> Enumerator;
63 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
64 const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
65 : PDBSymbol(PDBSession, std::move(Symbol)) {}
67 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const {
68 return Session.getSymbolById(getTypeId());
71 std::unique_ptr<IPDBEnumSymbols>
72 PDBSymbolTypeFunctionSig::getArguments() const {
73 return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
76 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const {
77 uint32_t ClassId = getClassParentId();
80 return Session.getSymbolById(ClassId);
83 void PDBSymbolTypeFunctionSig::dumpArgList(raw_ostream &OS) const {
85 if (auto ChildEnum = getArguments()) {
87 while (auto Arg = ChildEnum->getNext()) {
88 Arg->dump(OS, 0, PDB_DumpLevel::Compact);
89 if (++Index < ChildEnum->getChildCount())
100 void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent,
101 PDB_DumpLevel Level) const {
102 OS << stream_indent(Indent);
104 if (auto ReturnType = getReturnType()) {
105 ReturnType->dump(OS, 0, PDB_DumpLevel::Compact);
109 OS << getCallingConvention() << " ";
110 if (auto ClassParent = getClassParent()) {
112 ClassParent->dump(OS, 0, PDB_DumpLevel::Compact);