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