1 //===- PDBSymbolTypeFunctionSig.cpp - --------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h" 11 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" 17 #include "llvm/DebugInfo/PDB/PDBSymDumper.h" 18 19 #include <utility> 20 21 using namespace llvm; 22 23 namespace { 24 class FunctionArgEnumerator : public IPDBEnumSymbols { 25 public: 26 typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType; 27 28 FunctionArgEnumerator(const IPDBSession &PDBSession, 29 const PDBSymbolTypeFunctionSig &Sig) 30 : Session(PDBSession), 31 Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {} 32 33 FunctionArgEnumerator(const IPDBSession &PDBSession, 34 std::unique_ptr<ArgEnumeratorType> ArgEnumerator) 35 : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {} 36 37 uint32_t getChildCount() const override { 38 return Enumerator->getChildCount(); 39 } 40 41 std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override { 42 auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index); 43 if (!FunctionArgSymbol) 44 return nullptr; 45 return Session.getSymbolById(FunctionArgSymbol->getTypeId()); 46 } 47 48 std::unique_ptr<PDBSymbol> getNext() override { 49 auto FunctionArgSymbol = Enumerator->getNext(); 50 if (!FunctionArgSymbol) 51 return nullptr; 52 return Session.getSymbolById(FunctionArgSymbol->getTypeId()); 53 } 54 55 void reset() override { Enumerator->reset(); } 56 57 MyType *clone() const override { 58 std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone()); 59 return new FunctionArgEnumerator(Session, std::move(Clone)); 60 } 61 62 private: 63 const IPDBSession &Session; 64 std::unique_ptr<ArgEnumeratorType> Enumerator; 65 }; 66 } 67 68 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig( 69 const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol) 70 : PDBSymbol(PDBSession, std::move(Symbol)) {} 71 72 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const { 73 return Session.getSymbolById(getTypeId()); 74 } 75 76 std::unique_ptr<IPDBEnumSymbols> 77 PDBSymbolTypeFunctionSig::getArguments() const { 78 return llvm::make_unique<FunctionArgEnumerator>(Session, *this); 79 } 80 81 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const { 82 uint32_t ClassId = getClassParentId(); 83 if (ClassId == 0) 84 return nullptr; 85 return Session.getSymbolById(ClassId); 86 } 87 88 void PDBSymbolTypeFunctionSig::dump(PDBSymDumper &Dumper) const { 89 Dumper.dump(*this); 90 } 91