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/PDBSymbol.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
23 class FunctionArgEnumerator : public IPDBEnumSymbols {
25 typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType;
27 FunctionArgEnumerator(const IPDBSession &PDBSession,
28 const PDBSymbolTypeFunctionSig &Sig)
29 : Session(PDBSession),
30 Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {}
32 FunctionArgEnumerator(const IPDBSession &PDBSession,
33 std::unique_ptr<ArgEnumeratorType> ArgEnumerator)
34 : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {}
36 uint32_t getChildCount() const { return Enumerator->getChildCount(); }
38 std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const {
39 auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index);
40 if (!FunctionArgSymbol)
42 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
45 std::unique_ptr<PDBSymbol> getNext() {
46 auto FunctionArgSymbol = Enumerator->getNext();
47 if (!FunctionArgSymbol)
49 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
52 void reset() { Enumerator->reset(); }
54 MyType *clone() const {
55 std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone());
56 return new FunctionArgEnumerator(Session, std::move(Clone));
60 const IPDBSession &Session;
61 std::unique_ptr<ArgEnumeratorType> Enumerator;
65 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
66 const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
67 : PDBSymbol(PDBSession, std::move(Symbol)) {}
69 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const {
70 return Session.getSymbolById(getTypeId());
73 std::unique_ptr<IPDBEnumSymbols>
74 PDBSymbolTypeFunctionSig::getArguments() const {
75 return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
78 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const {
79 uint32_t ClassId = getClassParentId();
82 return Session.getSymbolById(ClassId);
85 void PDBSymbolTypeFunctionSig::dumpArgList(raw_ostream &OS) const {
87 if (auto ChildEnum = getArguments()) {
89 while (auto Arg = ChildEnum->getNext()) {
90 Arg->dump(OS, 0, PDB_DumpLevel::Compact);
91 if (++Index < ChildEnum->getChildCount())
102 void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent,
103 PDB_DumpLevel Level) const {
104 OS << stream_indent(Indent);
106 if (auto ReturnType = getReturnType()) {
107 ReturnType->dump(OS, 0, PDB_DumpLevel::Compact);
111 OS << getCallingConvention() << " ";
112 if (auto ClassParent = getClassParent()) {
114 ClassParent->dump(OS, 0, PDB_DumpLevel::Compact);