blob: a4242e90810d46016d134c72bf5b1dc4825f7bbf [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
Alex Langford0e252e32019-07-30 22:12:34 +000054 PdbAstBuilder(ObjectFile &obj, PdbIndex &index, ClangASTContext &clang);
Zachary Turner594c85e2018-12-17 19:43:33 +000055
Nathan Lanza06bf5d82019-07-17 07:05:49 +000056 lldb_private::CompilerDeclContext GetTranslationUnitDecl();
Zachary Turner594c85e2018-12-17 19:43:33 +000057
Nathan Lanzafe1b8a02019-07-21 07:46:18 +000058 llvm::Optional<lldb_private::CompilerDecl>
59 GetOrCreateDeclForUid(PdbSymUid uid);
Zachary Turner594c85e2018-12-17 19:43:33 +000060 clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
61 clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
62
Zachary Turner594c85e2018-12-17 19:43:33 +000063 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
64 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
Zachary Turner22566332019-01-02 18:33:54 +000065 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
66 PdbCompilandSymId var_id);
67 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
Zachary Turner44f19512019-01-10 20:57:32 +000068 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
Zachary Turner22566332019-01-02 18:33:54 +000069 void ParseDeclsForContext(clang::DeclContext &context);
Zachary Turner594c85e2018-12-17 19:43:33 +000070
71 clang::QualType GetBasicType(lldb::BasicType type);
72 clang::QualType GetOrCreateType(PdbTypeSymId type);
73
74 bool CompleteTagDecl(clang::TagDecl &tag);
75 bool CompleteType(clang::QualType qt);
76
77 CompilerDecl ToCompilerDecl(clang::Decl &decl);
78 CompilerType ToCompilerType(clang::QualType qt);
79 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
Nathan Lanzafe1b8a02019-07-21 07:46:18 +000080 clang::Decl *FromCompilerDecl(CompilerDecl decl);
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
Aleksandr Urakovee12a752019-04-22 07:14:40 +0000117 clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
118 clang::DeclContext &context);
119
Zachary Turner22566332019-01-02 18:33:54 +0000120 void ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef> parent);
121 void ParseDeclsForSimpleContext(clang::DeclContext &context);
122 void ParseBlockChildren(PdbCompilandSymId block_id);
123
Zachary Turner594c85e2018-12-17 19:43:33 +0000124 void BuildParentMap();
125 std::pair<clang::DeclContext *, std::string>
126 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
Zachary Turner44f19512019-01-10 20:57:32 +0000127 std::pair<clang::DeclContext *, std::string>
128 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
Zachary Turner594c85e2018-12-17 19:43:33 +0000129 clang::QualType CreateSimpleType(TypeIndex ti);
130
131 PdbIndex &m_index;
132 ClangASTContext &m_clang;
133
134 ClangASTImporter m_importer;
135
136 llvm::DenseMap<TypeIndex, TypeIndex> m_parent_types;
137 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
138 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
139 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
140};
141
142} // namespace npdb
143} // namespace lldb_private
144
145#endif // lldb_Plugins_SymbolFile_PDB_SymbolFilePDB_h_