1 //===-- ClangExternalASTSourceCallbacks.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-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H 10 #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H 11 12 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" 13 #include "clang/Basic/ASTSourceDescriptor.h" 14 #include <optional> 15 16 namespace clang { 17 18 class Module; 19 20 } // namespace clang 21 22 namespace lldb_private { 23 24 class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource { 25 /// LLVM RTTI support. 26 static char ID; 27 28 public: 29 /// LLVM RTTI support. isA(const void * ClassID)30 bool isA(const void *ClassID) const override { return ClassID == &ID; } classof(const clang::ExternalASTSource * s)31 static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); } 32 ClangExternalASTSourceCallbacks(TypeSystemClang & ast)33 ClangExternalASTSourceCallbacks(TypeSystemClang &ast) : m_ast(ast) {} 34 35 void FindExternalLexicalDecls( 36 const clang::DeclContext *DC, 37 llvm::function_ref<bool(clang::Decl::Kind)> IsKindWeWant, 38 llvm::SmallVectorImpl<clang::Decl *> &Result) override; 39 40 bool FindExternalVisibleDeclsByName(const clang::DeclContext *DC, 41 clang::DeclarationName Name) override; 42 43 void CompleteType(clang::TagDecl *tag_decl) override; 44 45 void CompleteType(clang::ObjCInterfaceDecl *objc_decl) override; 46 47 bool layoutRecordType( 48 const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, 49 llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets, 50 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> 51 &BaseOffsets, 52 llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> 53 &VirtualBaseOffsets) override; 54 GetTypeSystem()55 TypeSystemClang &GetTypeSystem() const { return m_ast; } 56 57 /// Module-related methods. 58 /// \{ 59 std::optional<clang::ASTSourceDescriptor> 60 getSourceDescriptor(unsigned ID) override; 61 clang::Module *getModule(unsigned ID) override; 62 OptionalClangModuleID RegisterModule(clang::Module *module); 63 OptionalClangModuleID GetIDForModule(clang::Module *module); 64 /// \} 65 private: 66 TypeSystemClang &m_ast; 67 std::vector<clang::Module *> m_modules; 68 llvm::DenseMap<clang::Module *, unsigned> m_ids; 69 }; 70 71 } // namespace lldb_private 72 73 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H 74