blob: e4241594845a9cbcb2c6e033debc64364f091368 [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
Zachary Turner594c85e2018-12-17 19:43:33 +000062 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
63 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
Zachary Turner22566332019-01-02 18:33:54 +000064 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
65 PdbCompilandSymId var_id);
66 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
Zachary Turner44f19512019-01-10 20:57:32 +000067 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
Zachary Turner22566332019-01-02 18:33:54 +000068 void ParseDeclsForContext(clang::DeclContext &context);
Zachary Turner594c85e2018-12-17 19:43:33 +000069
70 clang::QualType GetBasicType(lldb::BasicType type);
71 clang::QualType GetOrCreateType(PdbTypeSymId type);
72
73 bool CompleteTagDecl(clang::TagDecl &tag);
74 bool CompleteType(clang::QualType qt);
75
76 CompilerDecl ToCompilerDecl(clang::Decl &decl);
77 CompilerType ToCompilerType(clang::QualType qt);
78 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
Zachary Turner22566332019-01-02 18:33:54 +000079 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
Zachary Turner594c85e2018-12-17 19:43:33 +000080
81 ClangASTContext &clang() { return m_clang; }
82 ClangASTImporter &importer() { return m_importer; }
83
84 void Dump(Stream &stream);
85
86private:
87 clang::Decl *TryGetDecl(PdbSymUid uid) const;
88
89 using TypeIndex = llvm::codeview::TypeIndex;
90
91 clang::QualType
92 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
93 clang::QualType
94 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
95 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
96 clang::QualType CreateRecordType(PdbTypeSymId id,
97 const llvm::codeview::TagRecord &record);
98 clang::QualType CreateEnumType(PdbTypeSymId id,
99 const llvm::codeview::EnumRecord &record);
100 clang::QualType
Aleksandr Urakovee7c61f2019-01-29 09:32:23 +0000101 CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
102 llvm::codeview::CallingConvention calling_convention);
Zachary Turner594c85e2018-12-17 19:43:33 +0000103 clang::QualType CreateType(PdbTypeSymId type);
104
105 void CreateFunctionParameters(PdbCompilandSymId func_id,
106 clang::FunctionDecl &function_decl,
107 uint32_t param_count);
108 clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);
Zachary Turner37900292018-12-20 23:32:37 +0000109 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
110 llvm::codeview::CVSymbol sym,
111 clang::DeclContext &scope);
Zachary Turner44f19512019-01-10 20:57:32 +0000112 clang::DeclContext *
113 GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym);
Zachary Turner594c85e2018-12-17 19:43:33 +0000114
Aleksandr Urakovee12a752019-04-22 07:14:40 +0000115 clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
116 clang::DeclContext &context);
117
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_