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 using namespace llvm::pdb;
23
24 namespace {
25 class FunctionArgEnumerator : public IPDBEnumSymbols {
26 public:
27 typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType;
28
FunctionArgEnumerator(const IPDBSession & PDBSession,const PDBSymbolTypeFunctionSig & Sig)29 FunctionArgEnumerator(const IPDBSession &PDBSession,
30 const PDBSymbolTypeFunctionSig &Sig)
31 : Session(PDBSession),
32 Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {}
33
FunctionArgEnumerator(const IPDBSession & PDBSession,std::unique_ptr<ArgEnumeratorType> ArgEnumerator)34 FunctionArgEnumerator(const IPDBSession &PDBSession,
35 std::unique_ptr<ArgEnumeratorType> ArgEnumerator)
36 : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {}
37
getChildCount() const38 uint32_t getChildCount() const override {
39 return Enumerator->getChildCount();
40 }
41
getChildAtIndex(uint32_t Index) const42 std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const override {
43 auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index);
44 if (!FunctionArgSymbol)
45 return nullptr;
46 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
47 }
48
getNext()49 std::unique_ptr<PDBSymbol> getNext() override {
50 auto FunctionArgSymbol = Enumerator->getNext();
51 if (!FunctionArgSymbol)
52 return nullptr;
53 return Session.getSymbolById(FunctionArgSymbol->getTypeId());
54 }
55
reset()56 void reset() override { Enumerator->reset(); }
57
clone() const58 MyType *clone() const override {
59 std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone());
60 return new FunctionArgEnumerator(Session, std::move(Clone));
61 }
62
63 private:
64 const IPDBSession &Session;
65 std::unique_ptr<ArgEnumeratorType> Enumerator;
66 };
67 }
68
PDBSymbolTypeFunctionSig(const IPDBSession & PDBSession,std::unique_ptr<IPDBRawSymbol> Symbol)69 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
70 const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
71 : PDBSymbol(PDBSession, std::move(Symbol)) {}
72
getReturnType() const73 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const {
74 return Session.getSymbolById(getTypeId());
75 }
76
77 std::unique_ptr<IPDBEnumSymbols>
getArguments() const78 PDBSymbolTypeFunctionSig::getArguments() const {
79 return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
80 }
81
getClassParent() const82 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const {
83 uint32_t ClassId = getClassParentId();
84 if (ClassId == 0)
85 return nullptr;
86 return Session.getSymbolById(ClassId);
87 }
88
dump(PDBSymDumper & Dumper) const89 void PDBSymbolTypeFunctionSig::dump(PDBSymDumper &Dumper) const {
90 Dumper.dump(*this);
91 }
92