blob: e3bcc9ae826adf2c79184dd8b22ab81407f24c72 [file] [log] [blame]
Zachary Turner594c85e2018-12-17 19:43:33 +00001//===-- PdbAstBuilder.h -----------------------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Zachary Turner594c85e2018-12-17 19:43:33 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
10#define LLDB_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/StringRef.h"
14
15#include "lldb/Symbol/ClangASTImporter.h"
16
17#include "PdbIndex.h"
18#include "PdbSymUid.h"
19
20namespace clang {
21class TagDecl;
22class DeclContext;
23class Decl;
24class QualType;
25class FunctionDecl;
26class NamespaceDecl;
27} // namespace clang
28
29namespace llvm {
30namespace codeview {
31class ProcSym;
32}
33} // namespace llvm
34
35namespace lldb_private {
36class ClangASTImporter;
37class ObjectFile;
38
39namespace npdb {
40class PdbIndex;
41struct VariableInfo;
42
43struct DeclStatus {
44 DeclStatus() = default;
45 DeclStatus(lldb::user_id_t uid, bool resolved)
46 : uid(uid), resolved(resolved) {}
47 lldb::user_id_t uid = 0;
48 bool resolved = false;
49};
50
51class PdbAstBuilder {
52public:
53 //------------------------------------------------------------------
54 // Constructors and Destructors
55 //------------------------------------------------------------------
56 PdbAstBuilder(ObjectFile &obj, PdbIndex &index);
57
58 clang::DeclContext &GetTranslationUnitDecl();
59
60 clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid);
61 clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
62 clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
63
64 clang::NamespaceDecl *GetOrCreateNamespaceDecl(llvm::StringRef name,
65 clang::DeclContext &context);
66 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
67 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
Zachary Turner22566332019-01-02 18:33:54 +000068 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
69 PdbCompilandSymId var_id);
70 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
Zachary Turner44f19512019-01-10 20:57:32 +000071 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
Zachary Turner22566332019-01-02 18:33:54 +000072 void ParseDeclsForContext(clang::DeclContext &context);
Zachary Turner594c85e2018-12-17 19:43:33 +000073
74 clang::QualType GetBasicType(lldb::BasicType type);
75 clang::QualType GetOrCreateType(PdbTypeSymId type);
76
77 bool CompleteTagDecl(clang::TagDecl &tag);
78 bool CompleteType(clang::QualType qt);
79
80 CompilerDecl ToCompilerDecl(clang::Decl &decl);
81 CompilerType ToCompilerType(clang::QualType qt);
82 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
Zachary Turner22566332019-01-02 18:33:54 +000083 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
Zachary Turner594c85e2018-12-17 19:43:33 +000084
85 ClangASTContext &clang() { return m_clang; }
86 ClangASTImporter &importer() { return m_importer; }
87
88 void Dump(Stream &stream);
89
90private:
91 clang::Decl *TryGetDecl(PdbSymUid uid) const;
92
93 using TypeIndex = llvm::codeview::TypeIndex;
94
95 clang::QualType
96 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
97 clang::QualType
98 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
99 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
100 clang::QualType CreateRecordType(PdbTypeSymId id,
101 const llvm::codeview::TagRecord &record);
102 clang::QualType CreateEnumType(PdbTypeSymId id,
103 const llvm::codeview::EnumRecord &record);
104 clang::QualType
105 CreateProcedureType(const llvm::codeview::ProcedureRecord &proc);
106 clang::QualType CreateType(PdbTypeSymId type);
107
108 void CreateFunctionParameters(PdbCompilandSymId func_id,
109 clang::FunctionDecl &function_decl,
110 uint32_t param_count);
111 clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);
Zachary Turner37900292018-12-20 23:32:37 +0000112 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
113 llvm::codeview::CVSymbol sym,
114 clang::DeclContext &scope);
Zachary Turner44f19512019-01-10 20:57:32 +0000115 clang::DeclContext *
116 GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym);
Zachary Turner594c85e2018-12-17 19:43:33 +0000117
Zachary Turner22566332019-01-02 18:33:54 +0000118 void ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef> parent);
119 void ParseDeclsForSimpleContext(clang::DeclContext &context);
120 void ParseBlockChildren(PdbCompilandSymId block_id);
121
Zachary Turner594c85e2018-12-17 19:43:33 +0000122 void BuildParentMap();
123 std::pair<clang::DeclContext *, std::string>
124 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
Zachary Turner44f19512019-01-10 20:57:32 +0000125 std::pair<clang::DeclContext *, std::string>
126 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
Zachary Turner594c85e2018-12-17 19:43:33 +0000127 clang::QualType CreateSimpleType(TypeIndex ti);
128
129 PdbIndex &m_index;
130 ClangASTContext &m_clang;
131
132 ClangASTImporter m_importer;
133
134 llvm::DenseMap<TypeIndex, TypeIndex> m_parent_types;
135 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
136 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
137 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
138};
139
140} // namespace npdb
141} // namespace lldb_private
142
143#endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_