ClangASTSource.h revision 3c9c5eb466869ede185e879d14a47335fb43194d
1//===-- ClangASTSource.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_ClangASTSource_h_ 11#define liblldb_ClangASTSource_h_ 12 13#include "clang/Sema/ExternalSemaSource.h" 14 15namespace lldb_private { 16 17class ClangExpressionDeclMap; 18 19//---------------------------------------------------------------------- 20/// @class ClangASTSource ClangASTSource.h "lldb/Expression/ClangASTSource.h" 21/// @brief Provider for named objects defined in the debug info for Clang 22/// 23/// As Clang parses an expression, it may encounter names that are not 24/// defined inside the expression, including variables, functions, and 25/// types. Clang knows the name it is looking for, but nothing else. 26/// The ExternalSemaSource class provides Decls (VarDecl, FunDecl, TypeDecl) 27/// to Clang for these names, consulting the ClangExpressionDeclMap to do 28/// the actual lookups. 29//---------------------------------------------------------------------- 30class ClangASTSource : public clang::ExternalSemaSource { 31 clang::ASTContext &Context; ///< The parser's AST context, for copying types into 32 ClangExpressionDeclMap &DeclMap; ///< The object that looks up named entities in LLDB 33public: 34 friend struct NameSearchContext; 35 36 //------------------------------------------------------------------ 37 /// Constructor 38 /// 39 /// Initializes class variabes. 40 /// 41 /// @param[in] context 42 /// A reference to the AST context provided by the parser. 43 /// 44 /// @param[in] declMap 45 /// A reference to the LLDB object that handles entity lookup. 46 //------------------------------------------------------------------ 47 ClangASTSource(clang::ASTContext &context, 48 ClangExpressionDeclMap &declMap) : 49 Context(context), 50 DeclMap(declMap) {} 51 52 //------------------------------------------------------------------ 53 /// Destructor 54 //------------------------------------------------------------------ 55 ~ClangASTSource(); 56 57 //------------------------------------------------------------------ 58 /// Interface stub that returns NULL. 59 //------------------------------------------------------------------ 60 clang::Decl *GetExternalDecl(uint32_t); 61 62 //------------------------------------------------------------------ 63 /// Interface stub that returns NULL. 64 //------------------------------------------------------------------ 65 clang::Stmt *GetExternalDeclStmt(uint64_t); 66 67 //------------------------------------------------------------------ 68 /// Interface stub that returns an undifferentiated Selector. 69 //------------------------------------------------------------------ 70 clang::Selector GetExternalSelector(uint32_t); 71 72 //------------------------------------------------------------------ 73 /// Interface stub that returns 0. 74 //------------------------------------------------------------------ 75 uint32_t GetNumExternalSelectors(); 76 77 //------------------------------------------------------------------ 78 /// Look up all Decls that match a particular name. Only handles 79 /// Identifiers. Passes the request on to DeclMap, and calls 80 /// SetExternalVisibleDeclsForName with the result. 81 /// 82 /// @param[in] DC 83 /// The DeclContext to register the found Decls in. 84 /// 85 /// @param[in] Name 86 /// The name to find entries for. 87 /// 88 /// @return 89 /// Whatever SetExternalVisibleDeclsForName returns. 90 //------------------------------------------------------------------ 91 clang::DeclContext::lookup_result FindExternalVisibleDeclsByName(const clang::DeclContext *DC, 92 clang::DeclarationName Name); 93 94 //------------------------------------------------------------------ 95 /// Interface stub that returns true. 96 //------------------------------------------------------------------ 97 bool FindExternalLexicalDecls(const clang::DeclContext *DC, 98 llvm::SmallVectorImpl<clang::Decl*> &Decls); 99 100 //------------------------------------------------------------------ 101 /// Called on entering a translation unit. Tells Clang by calling 102 /// setHasExternalVisibleStorage() and setHasExternalLexicalStorage() 103 /// that this object has something to say about undefined names. 104 /// 105 /// @param[in] ASTConsumer 106 /// Unused. 107 //------------------------------------------------------------------ 108 void StartTranslationUnit(clang::ASTConsumer *Consumer); 109}; 110 111//---------------------------------------------------------------------- 112/// @class NameSearchContext ClangASTSource.h "lldb/Expression/ClangASTSource.h" 113/// @brief Container for all objects relevant to a single name lookup 114/// 115/// LLDB needs to create Decls for entities it finds. This class communicates 116/// what name is being searched for and provides helper functions to construct 117/// Decls given appropriate type information. 118//---------------------------------------------------------------------- 119struct NameSearchContext { 120 ClangASTSource &ASTSource; ///< The AST source making the request 121 llvm::SmallVectorImpl<clang::NamedDecl*> &Decls; ///< The list of declarations already constructed 122 clang::DeclarationName &Name; ///< The name being looked for 123 const clang::DeclContext *DC; ///< The DeclContext to put declarations into 124 125 //------------------------------------------------------------------ 126 /// Constructor 127 /// 128 /// Initializes class variables. 129 /// 130 /// @param[in] astSource 131 /// A reference to the AST source making a request. 132 /// 133 /// @param[in] decls 134 /// A reference to a list into which new Decls will be placed. This 135 /// list is typically empty when the function is called. 136 /// 137 /// @param[in] name 138 /// The name being searched for (always an Identifier). 139 /// 140 /// @param[in] dc 141 /// The DeclContext to register Decls in. 142 //------------------------------------------------------------------ 143 NameSearchContext (ClangASTSource &astSource, 144 llvm::SmallVectorImpl<clang::NamedDecl*> &decls, 145 clang::DeclarationName &name, 146 const clang::DeclContext *dc) : 147 ASTSource(astSource), 148 Decls(decls), 149 Name(name), 150 DC(dc) {} 151 152 //------------------------------------------------------------------ 153 /// Return the AST context for the current search. Useful when copying 154 /// types. 155 //------------------------------------------------------------------ 156 clang::ASTContext *GetASTContext(); 157 158 //------------------------------------------------------------------ 159 /// Create a VarDecl with the name being searched for and the provided 160 /// type and register it in the right places. 161 /// 162 /// @param[in] type 163 /// The opaque QualType for the VarDecl being registered. 164 //------------------------------------------------------------------ 165 clang::NamedDecl *AddVarDecl(void *type); 166 167 //------------------------------------------------------------------ 168 /// Create a FunDecl with the name being searched for and the provided 169 /// type and register it in the right places. 170 /// 171 /// @param[in] type 172 /// The opaque QualType for the FunDecl being registered. 173 //------------------------------------------------------------------ 174 clang::NamedDecl *AddFunDecl(void *type); 175 176 //------------------------------------------------------------------ 177 /// Create a FunDecl with the name being searched for and generic 178 /// type (i.e. intptr_t NAME_GOES_HERE(...)) and register it in the 179 /// right places. 180 //------------------------------------------------------------------ 181 clang::NamedDecl *AddGenericFunDecl(); 182 183 //------------------------------------------------------------------ 184 /// Create a TypeDecl with the name being searched for and the provided 185 /// type and register it in the right places. 186 /// 187 /// @param[in] type 188 /// The opaque QualType for the TypeDecl being registered. 189 //------------------------------------------------------------------ 190 clang::NamedDecl *AddTypeDecl(void *type); 191}; 192 193} 194 195#endif