blob: e3c0346f935eb60c52d381b74a65ea4ebec18ee1 [file] [log] [blame]
Zachary Turner594c85e2018-12-17 19:43:33 +00001//===-- 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
21namespace clang {
22class TagDecl;
23class DeclContext;
24class Decl;
25class QualType;
26class FunctionDecl;
27class NamespaceDecl;
28} // namespace clang
29
30namespace llvm {
31namespace codeview {
32class ProcSym;
33}
34} // namespace llvm
35
36namespace lldb_private {
37class ClangASTImporter;
38class ObjectFile;
39
40namespace npdb {
41class PdbIndex;
42struct VariableInfo;
43
44struct 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
52class PdbAstBuilder {
53public:
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);
Zachary Turner22566332019-01-02 18:33:54 +000069 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
70 PdbCompilandSymId var_id);
71 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
Zachary Turner44f19512019-01-10 20:57:32 +000072 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
Zachary Turner22566332019-01-02 18:33:54 +000073 void ParseDeclsForContext(clang::DeclContext &context);
Zachary Turner594c85e2018-12-17 19:43:33 +000074
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);
Zachary Turner22566332019-01-02 18:33:54 +000084 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
Zachary Turner594c85e2018-12-17 19:43:33 +000085
86 ClangASTContext &clang() { return m_clang; }
87 ClangASTImporter &importer() { return m_importer; }
88
89 void Dump(Stream &stream);
90
91private:
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);
Zachary Turner37900292018-12-20 23:32:37 +0000113 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
114 llvm::codeview::CVSymbol sym,
115 clang::DeclContext &scope);
Zachary Turner44f19512019-01-10 20:57:32 +0000116 clang::DeclContext *
117 GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym);
Zachary Turner594c85e2018-12-17 19:43:33 +0000118
Zachary Turner22566332019-01-02 18:33:54 +0000119 void ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef> parent);
120 void ParseDeclsForSimpleContext(clang::DeclContext &context);
121 void ParseBlockChildren(PdbCompilandSymId block_id);
122
Zachary Turner594c85e2018-12-17 19:43:33 +0000123 void BuildParentMap();
124 std::pair<clang::DeclContext *, std::string>
125 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
Zachary Turner44f19512019-01-10 20:57:32 +0000126 std::pair<clang::DeclContext *, std::string>
127 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
Zachary Turner594c85e2018-12-17 19:43:33 +0000128 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_