llvm-pdbdump: Re-order header files according to LLVM style guide.
[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
18 #include <utility>
19
20 using namespace llvm;
21
22 namespace {
23 class FunctionArgEnumerator : public IPDBEnumSymbols {
24 public:
25   typedef ConcreteSymbolEnumerator<PDBSymbolTypeFunctionArg> ArgEnumeratorType;
26
27   FunctionArgEnumerator(const IPDBSession &PDBSession,
28                         const PDBSymbolTypeFunctionSig &Sig)
29       : Session(PDBSession),
30         Enumerator(Sig.findAllChildren<PDBSymbolTypeFunctionArg>()) {}
31
32   FunctionArgEnumerator(const IPDBSession &PDBSession,
33                         std::unique_ptr<ArgEnumeratorType> ArgEnumerator)
34       : Session(PDBSession), Enumerator(std::move(ArgEnumerator)) {}
35
36   uint32_t getChildCount() const { return Enumerator->getChildCount(); }
37
38   std::unique_ptr<PDBSymbol> getChildAtIndex(uint32_t Index) const {
39     auto FunctionArgSymbol = Enumerator->getChildAtIndex(Index);
40     if (!FunctionArgSymbol)
41       return nullptr;
42     return Session.getSymbolById(FunctionArgSymbol->getTypeId());
43   }
44
45   std::unique_ptr<PDBSymbol> getNext() {
46     auto FunctionArgSymbol = Enumerator->getNext();
47     if (!FunctionArgSymbol)
48       return nullptr;
49     return Session.getSymbolById(FunctionArgSymbol->getTypeId());
50   }
51
52   void reset() { Enumerator->reset(); }
53
54   MyType *clone() const {
55     std::unique_ptr<ArgEnumeratorType> Clone(Enumerator->clone());
56     return new FunctionArgEnumerator(Session, std::move(Clone));
57   }
58
59 private:
60   const IPDBSession &Session;
61   std::unique_ptr<ArgEnumeratorType> Enumerator;
62 };
63 }
64
65 PDBSymbolTypeFunctionSig::PDBSymbolTypeFunctionSig(
66     const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol)
67     : PDBSymbol(PDBSession, std::move(Symbol)) {}
68
69 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getReturnType() const {
70   return Session.getSymbolById(getTypeId());
71 }
72
73 std::unique_ptr<IPDBEnumSymbols>
74 PDBSymbolTypeFunctionSig::getArguments() const {
75   return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
76 }
77
78 std::unique_ptr<PDBSymbol> PDBSymbolTypeFunctionSig::getClassParent() const {
79   uint32_t ClassId = getClassParentId();
80   if (ClassId == 0)
81     return nullptr;
82   return Session.getSymbolById(ClassId);
83 }
84
85 void PDBSymbolTypeFunctionSig::dumpArgList(raw_ostream &OS) const {
86   OS << "(";
87   if (auto ChildEnum = getArguments()) {
88     uint32_t Index = 0;
89     while (auto Arg = ChildEnum->getNext()) {
90       Arg->dump(OS, 0, PDB_DumpLevel::Compact);
91       if (++Index < ChildEnum->getChildCount())
92         OS << ", ";
93     }
94   }
95   OS << ")";
96   if (isConstType())
97     OS << " const";
98   if (isVolatileType())
99     OS << " volatile";
100 }
101
102 void PDBSymbolTypeFunctionSig::dump(raw_ostream &OS, int Indent,
103                                     PDB_DumpLevel Level) const {
104   OS << stream_indent(Indent);
105
106   if (auto ReturnType = getReturnType()) {
107     ReturnType->dump(OS, 0, PDB_DumpLevel::Compact);
108     OS << " ";
109   }
110
111   OS << getCallingConvention() << " ";
112   if (auto ClassParent = getClassParent()) {
113     OS << "(";
114     ClassParent->dump(OS, 0, PDB_DumpLevel::Compact);
115     OS << "::*)";
116   }
117
118   dumpArgList(OS);
119 }