[llvm-pdbdump] Rewrite dumper using visitor pattern.
[oota-llvm.git] / lib / DebugInfo / PDB / PDBSymbolTypeFunctionSig.cpp
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 { return Enumerator->getChildCount(); }
38
39   std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const {
40     auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index);
41     if (!FunctionArgSymbol)
42       return nullptr;
43     return Session.getSymbolById(FunctionArgSymbol->getTypeId());
44   }
45
46   std::unique_ptr<PDBSymbol> getNext() {
47     auto FunctionArgSymbol = Enumerator->getNext();
48     if (!FunctionArgSymbol)
49       return nullptr;
50     return Session.getSymbolById(FunctionArgSymbol->getTypeId());
51   }
52
53   void reset() { Enumerator->reset(); }
54
55   MyType *clone() const {
56     std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone());
57     return new FunctionArgEnumerator(Session, std::move(Clone));
58   }
59
60 private:
61   const IPDBSession &Session;
62   std::unique_ptr<ArgEnumeratorType> Enumerator;
63 };
64 }
65
66 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
67     const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
68     : PDBSymbol(PDBSession, std::move(Symbol)) {}
69
70 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const {
71   return Session.getSymbolById(getTypeId());
72 }
73
74 std::unique_ptr<IPDBEnumSymbols>
75 PDBSymbolTypeFunctionSig::getArguments() const {
76   return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
77 }
78
79 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const {
80   uint32_t ClassId = getClassParentId();
81   if (ClassId == 0)
82     return nullptr;
83   return Session.getSymbolById(ClassId);
84 }
85
86 void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent,
87                                     PDBSymDumper &Dumper) const {
88   Dumper.dump(*this, OS, Indent);
89 }