1 //===-- ClangExternalASTSourceCallbacks.h -----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_ClangExternalASTSourceCallbacks_h_ 11 #define liblldb_ClangExternalASTSourceCallbacks_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <string> 16 #include <vector> 17 #include <stdint.h> 18 19 // Other libraries and framework includes 20 #include "clang/AST/CharUnits.h" 21 22 // Project includes 23 #include "lldb/lldb-enumerations.h" 24 #include "lldb/Core/ClangForward.h" 25 #include "lldb/Symbol/ClangASTType.h" 26 #include "lldb/Symbol/ClangExternalASTSourceCommon.h" 27 28 namespace lldb_private { 29 30 class ClangExternalASTSourceCallbacks : public ClangExternalASTSourceCommon 31 { 32 public: 33 34 typedef void (*CompleteTagDeclCallback)(void *baton, clang::TagDecl *); 35 typedef void (*CompleteObjCInterfaceDeclCallback)(void *baton, clang::ObjCInterfaceDecl *); 36 typedef void (*FindExternalVisibleDeclsByNameCallback)(void *baton, const clang::DeclContext *DC, clang::DeclarationName Name, llvm::SmallVectorImpl <clang::NamedDecl *> *results); 37 typedef bool (*LayoutRecordTypeCallback)(void *baton, 38 const clang::RecordDecl *Record, 39 uint64_t &Size, 40 uint64_t &Alignment, 41 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &FieldOffsets, 42 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, 43 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets); 44 ClangExternalASTSourceCallbacks(CompleteTagDeclCallback tag_decl_callback,CompleteObjCInterfaceDeclCallback objc_decl_callback,FindExternalVisibleDeclsByNameCallback find_by_name_callback,LayoutRecordTypeCallback layout_record_type_callback,void * callback_baton)45 ClangExternalASTSourceCallbacks (CompleteTagDeclCallback tag_decl_callback, 46 CompleteObjCInterfaceDeclCallback objc_decl_callback, 47 FindExternalVisibleDeclsByNameCallback find_by_name_callback, 48 LayoutRecordTypeCallback layout_record_type_callback, 49 void *callback_baton) : 50 m_callback_tag_decl (tag_decl_callback), 51 m_callback_objc_decl (objc_decl_callback), 52 m_callback_find_by_name (find_by_name_callback), 53 m_callback_layout_record_type (layout_record_type_callback), 54 m_callback_baton (callback_baton) 55 { 56 } 57 58 //------------------------------------------------------------------ 59 // clang::ExternalASTSource 60 //------------------------------------------------------------------ 61 62 virtual clang::Decl * GetExternalDecl(uint32_t ID)63 GetExternalDecl (uint32_t ID) 64 { 65 // This method only needs to be implemented if the AST source ever 66 // passes back decl sets as VisibleDeclaration objects. 67 return 0; 68 } 69 70 virtual clang::Stmt * GetExternalDeclStmt(uint64_t Offset)71 GetExternalDeclStmt (uint64_t Offset) 72 { 73 // This operation is meant to be used via a LazyOffsetPtr. It only 74 // needs to be implemented if the AST source uses methods like 75 // FunctionDecl::setLazyBody when building decls. 76 return 0; 77 } 78 79 virtual clang::Selector GetExternalSelector(uint32_t ID)80 GetExternalSelector (uint32_t ID) 81 { 82 // This operation only needs to be implemented if the AST source 83 // returns non-zero for GetNumKnownSelectors(). 84 return clang::Selector(); 85 } 86 87 virtual uint32_t GetNumExternalSelectors()88 GetNumExternalSelectors() 89 { 90 return 0; 91 } 92 93 virtual clang::CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset)94 GetExternalCXXBaseSpecifiers(uint64_t Offset) 95 { 96 return NULL; 97 } 98 99 virtual void MaterializeVisibleDecls(const clang::DeclContext * decl_ctx)100 MaterializeVisibleDecls (const clang::DeclContext *decl_ctx) 101 { 102 return; 103 } 104 105 virtual clang::ExternalLoadResult FindExternalLexicalDecls(const clang::DeclContext * decl_ctx,bool (* isKindWeWant)(clang::Decl::Kind),llvm::SmallVectorImpl<clang::Decl * > & decls)106 FindExternalLexicalDecls (const clang::DeclContext *decl_ctx, 107 bool (*isKindWeWant)(clang::Decl::Kind), 108 llvm::SmallVectorImpl<clang::Decl*> &decls) 109 { 110 // This is used to support iterating through an entire lexical context, 111 // which isn't something the debugger should ever need to do. 112 return clang::ELR_Failure; 113 } 114 115 virtual bool 116 FindExternalVisibleDeclsByName (const clang::DeclContext *decl_ctx, 117 clang::DeclarationName decl_name); 118 119 virtual void 120 CompleteType (clang::TagDecl *tag_decl); 121 122 virtual void 123 CompleteType (clang::ObjCInterfaceDecl *objc_decl); 124 125 bool 126 layoutRecordType(const clang::RecordDecl *Record, 127 uint64_t &Size, 128 uint64_t &Alignment, 129 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &FieldOffsets, 130 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &BaseOffsets, 131 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &VirtualBaseOffsets); 132 void SetExternalSourceCallbacks(CompleteTagDeclCallback tag_decl_callback,CompleteObjCInterfaceDeclCallback objc_decl_callback,FindExternalVisibleDeclsByNameCallback find_by_name_callback,LayoutRecordTypeCallback layout_record_type_callback,void * callback_baton)133 SetExternalSourceCallbacks (CompleteTagDeclCallback tag_decl_callback, 134 CompleteObjCInterfaceDeclCallback objc_decl_callback, 135 FindExternalVisibleDeclsByNameCallback find_by_name_callback, 136 LayoutRecordTypeCallback layout_record_type_callback, 137 void *callback_baton) 138 { 139 m_callback_tag_decl = tag_decl_callback; 140 m_callback_objc_decl = objc_decl_callback; 141 m_callback_find_by_name = find_by_name_callback; 142 m_callback_layout_record_type = layout_record_type_callback; 143 m_callback_baton = callback_baton; 144 } 145 146 void RemoveExternalSourceCallbacks(void * callback_baton)147 RemoveExternalSourceCallbacks (void *callback_baton) 148 { 149 if (callback_baton == m_callback_baton) 150 { 151 m_callback_tag_decl = NULL; 152 m_callback_objc_decl = NULL; 153 m_callback_find_by_name = NULL; 154 m_callback_layout_record_type = NULL; 155 } 156 } 157 158 protected: 159 //------------------------------------------------------------------ 160 // Classes that inherit from ClangExternalASTSourceCallbacks can see and modify these 161 //------------------------------------------------------------------ 162 CompleteTagDeclCallback m_callback_tag_decl; 163 CompleteObjCInterfaceDeclCallback m_callback_objc_decl; 164 FindExternalVisibleDeclsByNameCallback m_callback_find_by_name; 165 LayoutRecordTypeCallback m_callback_layout_record_type; 166 void * m_callback_baton; 167 }; 168 169 } // namespace lldb_private 170 171 #endif // liblldb_ClangExternalASTSourceCallbacks_h_ 172