Attempt to fix Linux builds after r228960.
[oota-llvm.git] / include / llvm / DebugInfo / PDB / PDBSymbol.h
1 //===- PDBSymbol.h - base class for user-facing symbol types -----*- 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 #ifndef LLVM_DEBUGINFO_PDB_IPDBSYMBOL_H
11 #define LLVM_DEBUGINFO_PDB_IPDBSYMBOL_H
12
13 #include <unordered_map>
14
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/Casting.h"
18
19 #include "ConcreteSymbolEnumerator.h"
20 #include "IPDBRawSymbol.h"
21 #include "PDBExtras.h"
22 #include "PDBTypes.h"
23
24 #define FORWARD_SYMBOL_METHOD(MethodName)                                      \
25   auto MethodName() const->decltype(RawSymbol->MethodName()) {                 \
26     return RawSymbol->MethodName();                                            \
27   }
28
29 namespace llvm {
30
31 class IPDBRawSymbol;
32 class raw_ostream;
33
34 #define DECLARE_PDB_SYMBOL_CONCRETE_TYPE(TagValue)                             \
35   static const PDB_SymType Tag = TagValue;                                     \
36   static bool classof(const PDBSymbol *S) { return S->getSymTag() == Tag; }
37
38 /// PDBSymbol defines the base of the inheritance hierarchy for concrete symbol
39 /// types (e.g. functions, executables, vtables, etc).  All concrete symbol
40 /// types inherit from PDBSymbol and expose the exact set of methods that are
41 /// valid for that particular symbol type, as described in the Microsoft
42 /// reference "Lexical and Class Hierarchy of Symbol Types":
43 /// https://msdn.microsoft.com/en-us/library/370hs6k4.aspx
44 class PDBSymbol {
45 protected:
46   PDBSymbol(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
47
48 public:
49   static std::unique_ptr<PDBSymbol>
50   create(const IPDBSession &PDBSession, std::unique_ptr<IPDBRawSymbol> Symbol);
51
52   virtual ~PDBSymbol();
53
54   /// Dumps the contents of a symbol a raw_ostream.  By default this will just
55   /// call dump() on the underlying RawSymbol, which allows us to discover
56   /// unknown properties, but individual implementations of PDBSymbol may
57   /// override the behavior to only dump known fields.
58   virtual void dump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const = 0;
59   void defaultDump(raw_ostream &OS, int Indent, PDB_DumpLevel Level) const;
60
61   PDB_SymType getSymTag() const;
62
63   template <typename T> std::unique_ptr<T> findOneChild() const {
64     auto Enumerator(findAllChildren<T>());
65     return Enumerator->getNext();
66   }
67
68   template <typename T>
69   std::unique_ptr<ConcreteSymbolEnumerator<T>> findAllChildren() const {
70     auto BaseIter = RawSymbol->findChildren(T::Tag);
71     return llvm::make_unique<ConcreteSymbolEnumerator<T>>(std::move(BaseIter));
72   }
73
74   std::unique_ptr<IPDBEnumSymbols> findAllChildren() const;
75   std::unique_ptr<IPDBEnumSymbols>
76   findChildren(PDB_SymType Type, StringRef Name,
77                PDB_NameSearchFlags Flags) const;
78   std::unique_ptr<IPDBEnumSymbols> findChildrenByRVA(PDB_SymType Type,
79                                                      StringRef Name,
80                                                      PDB_NameSearchFlags Flags,
81                                                      uint32_t RVA) const;
82   std::unique_ptr<IPDBEnumSymbols> findInlineFramesByRVA(uint32_t RVA) const;
83
84   const IPDBRawSymbol &getRawSymbol() const { return *RawSymbol; }
85   IPDBRawSymbol &getRawSymbol() { return *RawSymbol; }
86
87 protected:
88   std::unique_ptr<IPDBEnumSymbols> getChildStats(TagStats &Stats) const;
89
90   const IPDBSession &Session;
91   const std::unique_ptr<IPDBRawSymbol> RawSymbol;
92 };
93
94 } // namespace llvm
95
96 #endif