Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/NativePDB/PdbAstBuilder.h
39642 views
//===-- PdbAstBuilder.h -----------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H1011#include "llvm/ADT/DenseMap.h"12#include "llvm/ADT/StringRef.h"13#include "llvm/Support/Threading.h"1415#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"1617#include "PdbIndex.h"18#include "PdbSymUid.h"19#include <optional>2021namespace clang {22class TagDecl;23class DeclContext;24class Decl;25class QualType;26class FunctionDecl;27class NamespaceDecl;28} // namespace clang2930namespace llvm {31namespace codeview {32class ProcSym;33}34} // namespace llvm3536namespace lldb_private {37class ClangASTImporter;38class ObjectFile;3940namespace npdb {41class PdbIndex;42struct VariableInfo;4344struct DeclStatus {45DeclStatus() = default;46DeclStatus(lldb::user_id_t uid, bool resolved)47: uid(uid), resolved(resolved) {}48lldb::user_id_t uid = 0;49bool resolved = false;50};5152class PdbAstBuilder {53public:54// Constructors and Destructors55PdbAstBuilder(TypeSystemClang &clang);5657lldb_private::CompilerDeclContext GetTranslationUnitDecl();5859std::optional<lldb_private::CompilerDecl>60GetOrCreateDeclForUid(PdbSymUid uid);61clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);62clang::DeclContext *GetParentDeclContext(PdbSymUid uid);6364clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);65clang::FunctionDecl *66GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id);67clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);68clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,69PdbCompilandSymId var_id);70clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);71clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);72void ParseDeclsForContext(clang::DeclContext &context);7374clang::QualType GetBasicType(lldb::BasicType type);75clang::QualType GetOrCreateType(PdbTypeSymId type);7677bool CompleteTagDecl(clang::TagDecl &tag);78bool CompleteType(clang::QualType qt);7980CompilerDecl ToCompilerDecl(clang::Decl &decl);81CompilerType ToCompilerType(clang::QualType qt);82CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);83clang::Decl *FromCompilerDecl(CompilerDecl decl);84clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);8586TypeSystemClang &clang() { return m_clang; }87ClangASTImporter &GetClangASTImporter() { return m_importer; }8889void Dump(Stream &stream);9091private:92clang::Decl *TryGetDecl(PdbSymUid uid) const;9394using TypeIndex = llvm::codeview::TypeIndex;9596clang::QualType97CreatePointerType(const llvm::codeview::PointerRecord &pointer);98clang::QualType99CreateModifierType(const llvm::codeview::ModifierRecord &modifier);100clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);101clang::QualType CreateRecordType(PdbTypeSymId id,102const llvm::codeview::TagRecord &record);103clang::QualType CreateEnumType(PdbTypeSymId id,104const llvm::codeview::EnumRecord &record);105clang::QualType106CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,107llvm::codeview::CallingConvention calling_convention);108clang::QualType CreateType(PdbTypeSymId type);109110void CreateFunctionParameters(PdbCompilandSymId func_id,111clang::FunctionDecl &function_decl,112uint32_t param_count);113clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);114clang::VarDecl *CreateVariableDecl(PdbSymUid uid,115llvm::codeview::CVSymbol sym,116clang::DeclContext &scope);117clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,118clang::DeclContext &context);119clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,120PdbCompilandSymId func_sid);121clang::FunctionDecl *122CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,123TypeIndex func_ti, CompilerType func_ct,124uint32_t param_count, clang::StorageClass func_storage,125bool is_inline, clang::DeclContext *parent);126void ParseNamespace(clang::DeclContext &parent);127void ParseAllTypes();128void ParseAllFunctionsAndNonLocalVars();129void ParseDeclsForSimpleContext(clang::DeclContext &context);130void ParseBlockChildren(PdbCompilandSymId block_id);131132std::pair<clang::DeclContext *, std::string>133CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);134std::pair<clang::DeclContext *, std::string>135CreateDeclInfoForUndecoratedName(llvm::StringRef uname);136clang::QualType CreateSimpleType(TypeIndex ti);137138TypeSystemClang &m_clang;139140ClangASTImporter m_importer;141llvm::once_flag m_parse_functions_and_non_local_vars;142llvm::once_flag m_parse_all_types;143llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;144llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;145llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;146147// From class/struct's opaque_compiler_type_t to a set containing the pairs of148// method's name and CompilerType.149llvm::DenseMap<lldb::opaque_compiler_type_t,150llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>151m_cxx_record_map;152llvm::DenseSet<clang::NamespaceDecl *> m_parsed_namespaces;153};154155} // namespace npdb156} // namespace lldb_private157158#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H159160161