xref: /llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h (revision 263fed7ce9d2c155af44829018673caa67fa4f47)
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.
30   bool isA(const void *ClassID) const override { return ClassID == &ID; }
31   static bool classof(const clang::ExternalASTSource *s) { return s->isA(&ID); }
32 
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
41   FindExternalVisibleDeclsByName(const clang::DeclContext *DC,
42                                  clang::DeclarationName Name,
43                                  const clang::DeclContext *OriginalDC) override;
44 
45   void CompleteType(clang::TagDecl *tag_decl) override;
46 
47   void CompleteType(clang::ObjCInterfaceDecl *objc_decl) override;
48 
49   bool layoutRecordType(
50       const clang::RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
51       llvm::DenseMap<const clang::FieldDecl *, uint64_t> &FieldOffsets,
52       llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
53           &BaseOffsets,
54       llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
55           &VirtualBaseOffsets) override;
56 
57   TypeSystemClang &GetTypeSystem() const { return m_ast; }
58 
59   /// Module-related methods.
60   /// \{
61   std::optional<clang::ASTSourceDescriptor>
62   getSourceDescriptor(unsigned ID) override;
63   clang::Module *getModule(unsigned ID) override;
64   OptionalClangModuleID RegisterModule(clang::Module *module);
65   OptionalClangModuleID GetIDForModule(clang::Module *module);
66   /// \}
67 private:
68   TypeSystemClang &m_ast;
69   std::vector<clang::Module *> m_modules;
70   llvm::DenseMap<clang::Module *, unsigned> m_ids;
71 };
72 
73 } // namespace lldb_private
74 
75 #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H
76