brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.3 KiB · 16247fc Raw
171 lines · c
1//===-- PdbAstBuilder.h -----------------------------------*- C++ -*-===//2//3// 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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H11 12#include "llvm/ADT/DenseMap.h"13#include "llvm/ADT/StringRef.h"14#include "llvm/Support/Threading.h"15 16#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"17 18#include "PdbIndex.h"19#include "PdbSymUid.h"20#include <optional>21 22namespace clang {23class TagDecl;24class DeclContext;25class Decl;26class QualType;27class FunctionDecl;28class NamespaceDecl;29} // namespace clang30 31namespace llvm {32namespace codeview {33class ProcSym;34}35} // namespace llvm36 37namespace lldb_private {38class ClangASTImporter;39class ObjectFile;40 41namespace npdb {42class PdbIndex;43struct VariableInfo;44 45struct DeclStatus {46  DeclStatus() = default;47  DeclStatus(lldb::user_id_t uid, bool resolved)48      : uid(uid), resolved(resolved) {}49  lldb::user_id_t uid = 0;50  bool resolved = false;51};52 53class PdbAstBuilder {54public:55  // Constructors and Destructors56  PdbAstBuilder(TypeSystemClang &clang);57 58  lldb_private::CompilerDeclContext GetTranslationUnitDecl();59 60  std::optional<lldb_private::CompilerDecl>61  GetOrCreateDeclForUid(PdbSymUid uid);62  clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);63  clang::DeclContext *GetParentDeclContext(PdbSymUid uid);64 65  clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);66  clang::FunctionDecl *67  GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id);68  clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);69  clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,70                                          PdbCompilandSymId var_id);71  clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);72  clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);73  void ParseDeclsForContext(clang::DeclContext &context);74 75  clang::QualType GetBasicType(lldb::BasicType type);76  clang::QualType GetOrCreateType(PdbTypeSymId type);77 78  bool CompleteTagDecl(clang::TagDecl &tag);79  bool CompleteType(clang::QualType qt);80 81  CompilerDecl ToCompilerDecl(clang::Decl &decl);82  CompilerType ToCompilerType(clang::QualType qt);83  CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);84  clang::Decl *FromCompilerDecl(CompilerDecl decl);85  clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);86 87  TypeSystemClang &clang() { return m_clang; }88  ClangASTImporter &GetClangASTImporter() { return m_importer; }89 90  void Dump(Stream &stream, llvm::StringRef filter, bool show_color);91 92  clang::NamespaceDecl *FindNamespaceDecl(const clang::DeclContext *parent,93                                          llvm::StringRef name);94 95private:96  clang::Decl *TryGetDecl(PdbSymUid uid) const;97 98  using TypeIndex = llvm::codeview::TypeIndex;99 100  clang::QualType101  CreatePointerType(const llvm::codeview::PointerRecord &pointer);102  clang::QualType103  CreateModifierType(const llvm::codeview::ModifierRecord &modifier);104  clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);105  clang::QualType CreateRecordType(PdbTypeSymId id,106                                   const llvm::codeview::TagRecord &record);107  clang::QualType CreateEnumType(PdbTypeSymId id,108                                 const llvm::codeview::EnumRecord &record);109  clang::QualType110  CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,111                     llvm::codeview::CallingConvention calling_convention);112  clang::QualType CreateType(PdbTypeSymId type);113 114  void CreateFunctionParameters(PdbCompilandSymId func_id,115                                clang::FunctionDecl &function_decl,116                                uint32_t param_count);117  clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);118  clang::VarDecl *CreateVariableDecl(PdbSymUid uid,119                                     llvm::codeview::CVSymbol sym,120                                     clang::DeclContext &scope);121  clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,122                                                 clang::DeclContext &context);123  clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,124                                                PdbCompilandSymId func_sid);125  clang::FunctionDecl *126  CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,127                     TypeIndex func_ti, CompilerType func_ct,128                     uint32_t param_count, clang::StorageClass func_storage,129                     bool is_inline, clang::DeclContext *parent);130  void ParseNamespace(clang::DeclContext &parent);131  void ParseAllTypes();132  void ParseAllFunctionsAndNonLocalVars();133  void ParseDeclsForSimpleContext(clang::DeclContext &context);134  void ParseBlockChildren(PdbCompilandSymId block_id);135 136  std::pair<clang::DeclContext *, std::string>137  CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);138  std::pair<clang::DeclContext *, std::string>139  CreateDeclInfoForUndecoratedName(llvm::StringRef uname);140  clang::QualType CreateSimpleType(TypeIndex ti);141 142  TypeSystemClang &m_clang;143 144  ClangASTImporter m_importer;145  llvm::once_flag m_parse_functions_and_non_local_vars;146  llvm::once_flag m_parse_all_types;147  llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;148  llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;149  llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;150 151  // From class/struct's opaque_compiler_type_t to a set containing the pairs of152  // method's name and CompilerType.153  llvm::DenseMap<lldb::opaque_compiler_type_t,154                 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>155      m_cxx_record_map;156 157  using NamespaceSet = llvm::DenseSet<clang::NamespaceDecl *>;158 159  // These namespaces are fully parsed160  NamespaceSet m_parsed_namespaces;161 162  // We know about these namespaces, but they might not be completely parsed yet163  NamespaceSet m_known_namespaces;164  llvm::DenseMap<clang::DeclContext *, NamespaceSet> m_parent_to_namespaces;165};166 167} // namespace npdb168} // namespace lldb_private169 170#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H171