blob: 60eece71661906e46dbe8fae8cece3e3cd330be0 [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:
Zachary Turner594c85e2018-12-17 19:43:33 +000053 // Constructors and Destructors
Zachary Turner594c85e2018-12-17 19:43:33 +000054 PdbAstBuilder(ObjectFile &obj, PdbIndex &index);
55
56 clang::DeclContext &GetTranslationUnitDecl();
57
58 clang::Decl *GetOrCreateDeclForUid(PdbSymUid uid);
59 clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
60 clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
61
62 clang::NamespaceDecl *GetOrCreateNamespaceDecl(llvm::StringRef name,
63 clang::DeclContext &context);
64 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
65 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
Zachary Turner22566332019-01-02 18:33:54 +000066 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
67 PdbCompilandSymId var_id);
68 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
Zachary Turner44f19512019-01-10 20:57:32 +000069 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
Zachary Turner22566332019-01-02 18:33:54 +000070 void ParseDeclsForContext(clang::DeclContext &context);
Zachary Turner594c85e2018-12-17 19:43:33 +000071
72 clang::QualType GetBasicType(lldb::BasicType type);
73 clang::QualType GetOrCreateType(PdbTypeSymId type);
74
75 bool CompleteTagDecl(clang::TagDecl &tag);
76 bool CompleteType(clang::QualType qt);
77
78 CompilerDecl ToCompilerDecl(clang::Decl &decl);
79 CompilerType ToCompilerType(clang::QualType qt);
80 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
Zachary Turner22566332019-01-02 18:33:54 +000081 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
Zachary Turner594c85e2018-12-17 19:43:33 +000082
83 ClangASTContext &clang() { return m_clang; }
84 ClangASTImporter &importer() { return m_importer; }
85
86 void Dump(Stream &stream);
87
88private:
89 clang::Decl *TryGetDecl(PdbSymUid uid) const;
90
91 using TypeIndex = llvm::codeview::TypeIndex;
92
93 clang::QualType
94 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
95 clang::QualType
96 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
97 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
98 clang::QualType CreateRecordType(PdbTypeSymId id,
99 const llvm::codeview::TagRecord &record);
100 clang::QualType CreateEnumType(PdbTypeSymId id,
101 const llvm::codeview::EnumRecord &record);
102 clang::QualType
Aleksandr Urakovee7c61f2019-01-29 09:32:23 +0000103 CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
104 llvm::codeview::CallingConvention calling_convention);
Zachary Turner594c85e2018-12-17 19:43:33 +0000105 clang::QualType CreateType(PdbTypeSymId type);
106
107 void CreateFunctionParameters(PdbCompilandSymId func_id,
108 clang::FunctionDecl &function_decl,
109 uint32_t param_count);
110 clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);
Zachary Turner37900292018-12-20 23:32:37 +0000111 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
112 llvm::codeview::CVSymbol sym,
113 clang::DeclContext &scope);
Zachary Turner44f19512019-01-10 20:57:32 +0000114 clang::DeclContext *
115 GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym);
Zachary Turner594c85e2018-12-17 19:43:33 +0000116
Zachary Turner22566332019-01-02 18:33:54 +0000117 void ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef> parent);
118 void ParseDeclsForSimpleContext(clang::DeclContext &context);
119 void ParseBlockChildren(PdbCompilandSymId block_id);
120
Zachary Turner594c85e2018-12-17 19:43:33 +0000121 void BuildParentMap();
122 std::pair<clang::DeclContext *, std::string>
123 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
Zachary Turner44f19512019-01-10 20:57:32 +0000124 std::pair<clang::DeclContext *, std::string>
125 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
Zachary Turner594c85e2018-12-17 19:43:33 +0000126 clang::QualType CreateSimpleType(TypeIndex ti);
127
128 PdbIndex &m_index;
129 ClangASTContext &m_clang;
130
131 ClangASTImporter m_importer;
132
133 llvm::DenseMap<TypeIndex, TypeIndex> m_parent_types;
134 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
135 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
136 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
137};
138
139} // namespace npdb
140} // namespace lldb_private
141
142#endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_