OSDN Git Service

0734a1f8314acc1f5e8259df0e1a5a63294eadc2
[android-x86/external-llvm.git] / lib / DebugInfo / PDB / PDBSymbolFunc.cpp
1 //===- PDBSymbolFunc.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/PDBSymbolFunc.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/PDBSymbolData.h"
16 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
17 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
18 #include "llvm/DebugInfo/PDB/PDBSymDumper.h"
19 #include "llvm/DebugInfo/PDB/PDBTypes.h"
20
21 #include <unordered_set>
22 #include <utility>
23 #include <vector>
24
25 using namespace llvm;
26 using namespace llvm::pdb;
27
28 namespace {
29 class FunctionArgEnumerator : public IPDBEnumChildren<PDBSymbolData> {
30 public:
31   typedef ConcreteSymbolEnumerator<PDBSymbolData> ArgEnumeratorType;
32
33   FunctionArgEnumerator(const IPDBSession &PDBSession,
34                         const PDBSymbolFunc &PDBFunc)
35       : Session(PDBSession), Func(PDBFunc) {
36     // Arguments can appear multiple times if they have live range
37     // information, so we only take the first occurrence.
38     std::unordered_set<std::string> SeenNames;
39     auto DataChildren = Func.findAllChildren<PDBSymbolData>();
40     while (auto Child = DataChildren->getNext()) {
41       if (Child->getDataKind() == PDB_DataKind::Param) {
42         std::string Name = Child->getName();
43         if (SeenNames.find(Name) != SeenNames.end())
44           continue;
45         Args.push_back(std::move(Child));
46         SeenNames.insert(Name);
47       }
48     }
49     reset();
50   }
51
52   uint32_t getChildCount() const override { return Args.size(); }
53
54   std::unique_ptr<PDBSymbolData>
55   getChildAtIndex(uint32_t Index) const override {
56     if (Index >= Args.size())
57       return nullptr;
58
59     return Session.getConcreteSymbolById<PDBSymbolData>(
60         Args[Index]->getSymIndexId());
61   }
62
63   std::unique_ptr<PDBSymbolData> getNext() override {
64     if (CurIter == Args.end())
65       return nullptr;
66     const auto &Result = **CurIter;
67     ++CurIter;
68     return Session.getConcreteSymbolById<PDBSymbolData>(Result.getSymIndexId());
69   }
70
71   void reset() override { CurIter = Args.empty() ? Args.end() : Args.begin(); }
72
73   FunctionArgEnumerator *clone() const override {
74     return new FunctionArgEnumerator(Session, Func);
75   }
76
77 private:
78   typedef std::vector<std::unique_ptr<PDBSymbolData>> ArgListType;
79   const IPDBSession &Session;
80   const PDBSymbolFunc &Func;
81   ArgListType Args;
82   ArgListType::const_iterator CurIter;
83 };
84 }
85
86 PDBSymbolFunc::PDBSymbolFunc(const IPDBSession &PDBSession,
87                              std::unique_ptr<IPDBRawSymbol> Symbol)
88     : PDBSymbol(PDBSession, std::move(Symbol)) {
89   assert(RawSymbol->getSymTag() == PDB_SymType::Function);
90 }
91
92 std::unique_ptr<IPDBEnumChildren<PDBSymbolData>>
93 PDBSymbolFunc::getArguments() const {
94   return llvm::make_unique<FunctionArgEnumerator>(Session, *this);
95 }
96
97 void PDBSymbolFunc::dump(PDBSymDumper &Dumper) const { Dumper.dump(*this); }
98
99 bool PDBSymbolFunc::isDestructor() const {
100   std::string Name = getName();
101   if (Name.empty())
102     return false;
103   if (Name[0] == '~')
104     return true;
105   if (Name == "__vecDelDtor")
106     return true;
107   return false;
108 }