]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / NativePDB / PdbAstBuilder.h
1 //===-- PdbAstBuilder.h -----------------------------------*- 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 LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
11 #define LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/StringRef.h"
15
16 #include "lldb/Symbol/ClangASTImporter.h"
17
18 #include "PdbIndex.h"
19 #include "PdbSymUid.h"
20
21 namespace clang {
22 class TagDecl;
23 class DeclContext;
24 class Decl;
25 class QualType;
26 class FunctionDecl;
27 class NamespaceDecl;
28 } // namespace clang
29
30 namespace llvm {
31 namespace codeview {
32 class ProcSym;
33 }
34 } // namespace llvm
35
36 namespace lldb_private {
37 class ClangASTImporter;
38 class ObjectFile;
39
40 namespace npdb {
41 class PdbIndex;
42 struct VariableInfo;
43
44 struct DeclStatus {
45   DeclStatus() = default;
46   DeclStatus(lldb::user_id_t uid, bool resolved)
47       : uid(uid), resolved(resolved) {}
48   lldb::user_id_t uid = 0;
49   bool resolved = false;
50 };
51
52 class PdbAstBuilder {
53 public:
54   //------------------------------------------------------------------
55   // Constructors and Destructors
56   //------------------------------------------------------------------
57   PdbAstBuilder(ObjectFile &obj, PdbIndex &index);
58
59   clang::DeclContext &GetTranslationUnitDecl();
60
61   clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid);
62   clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
63   clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
64
65   clang::NamespaceDecl *GetOrCreateNamespaceDecl(llvm::StringRef name,
66                                                  clang::DeclContext &context);
67   clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
68   clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
69   clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
70                                           PdbCompilandSymId var_id);
71   clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
72   clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
73   void ParseDeclsForContext(clang::DeclContext &context);
74
75   clang::QualType GetBasicType(lldb::BasicType type);
76   clang::QualType GetOrCreateType(PdbTypeSymId type);
77
78   bool CompleteTagDecl(clang::TagDecl &tag);
79   bool CompleteType(clang::QualType qt);
80
81   CompilerDecl ToCompilerDecl(clang::Decl &decl);
82   CompilerType ToCompilerType(clang::QualType qt);
83   CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
84   clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
85
86   ClangASTContext &clang() { return m_clang; }
87   ClangASTImporter &importer() { return m_importer; }
88
89   void Dump(Stream &stream);
90
91 private:
92   clang::Decl *TryGetDecl(PdbSymUid uid) const;
93
94   using TypeIndex = llvm::codeview::TypeIndex;
95
96   clang::QualType
97   CreatePointerType(const llvm::codeview::PointerRecord &pointer);
98   clang::QualType
99   CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
100   clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
101   clang::QualType CreateRecordType(PdbTypeSymId id,
102                                    const llvm::codeview::TagRecord &record);
103   clang::QualType CreateEnumType(PdbTypeSymId id,
104                                  const llvm::codeview::EnumRecord &record);
105   clang::QualType
106   CreateProcedureType(const llvm::codeview::ProcedureRecord &proc);
107   clang::QualType CreateType(PdbTypeSymId type);
108
109   void CreateFunctionParameters(PdbCompilandSymId func_id,
110                                 clang::FunctionDecl &function_decl,
111                                 uint32_t param_count);
112   clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);
113   clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
114                                      llvm::codeview::CVSymbol sym,
115                                      clang::DeclContext &scope);
116   clang::DeclContext *
117   GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym);
118
119   void ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef> parent);
120   void ParseDeclsForSimpleContext(clang::DeclContext &context);
121   void ParseBlockChildren(PdbCompilandSymId block_id);
122
123   void BuildParentMap();
124   std::pair<clang::DeclContext *, std::string>
125   CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
126   std::pair<clang::DeclContext *, std::string>
127   CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
128   clang::QualType CreateSimpleType(TypeIndex ti);
129
130   PdbIndex &m_index;
131   ClangASTContext &m_clang;
132
133   ClangASTImporter m_importer;
134
135   llvm::DenseMap<TypeIndex, TypeIndex> m_parent_types;
136   llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
137   llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
138   llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
139 };
140
141 } // namespace npdb
142 } // namespace lldb_private
143
144 #endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_