Greg Clayton | 1e591ce | 2010-07-16 18:28:27 +0000 | [diff] [blame] | 1 | //===-- ClangASTSource.cpp ---------------------------------------*- 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 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTContext.h" |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Log.h" |
Greg Clayton | 6e0101c | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ModuleList.h" |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 15 | #include "lldb/Expression/ASTDumper.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Expression/ClangASTSource.h" |
| 17 | #include "lldb/Expression/ClangExpression.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/ClangNamespaceDecl.h" |
| 19 | #include "lldb/Symbol/SymbolVendor.h" |
Sean Callanan | 673f3db | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 20 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang; |
| 24 | using namespace lldb_private; |
| 25 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 26 | ClangASTSource::~ClangASTSource() |
| 27 | { |
Sean Callanan | a3d0447 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 28 | m_ast_importer->ForgetDestination(m_ast_context); |
| 29 | |
Johnny Chen | fa21ffd | 2011-11-30 23:18:53 +0000 | [diff] [blame] | 30 | // We are in the process of destruction, don't create clang ast context on demand |
| 31 | // by passing false to Target::GetScratchClangASTContext(create_on_demand). |
| 32 | ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false); |
Sean Callanan | a3d0447 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 33 | |
| 34 | if (!scratch_clang_ast_context) |
| 35 | return; |
| 36 | |
| 37 | clang::ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); |
| 38 | |
| 39 | if (!scratch_ast_context) |
| 40 | return; |
| 41 | |
| 42 | if (m_ast_context != scratch_ast_context) |
| 43 | m_ast_importer->ForgetSource(scratch_ast_context, m_ast_context); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 44 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 46 | void |
| 47 | ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) |
| 48 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 49 | if (!m_ast_context) |
| 50 | return; |
| 51 | |
| 52 | m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 53 | m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | // The core lookup interface. |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 57 | DeclContext::lookup_result |
| 58 | ClangASTSource::FindExternalVisibleDeclsByName |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 59 | ( |
| 60 | const DeclContext *decl_ctx, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 61 | DeclarationName clang_decl_name |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 62 | ) |
| 63 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 64 | if (!m_ast_context) |
| 65 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 66 | |
| 67 | if (GetImportInProgress()) |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 68 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 69 | |
| 70 | std::string decl_name (clang_decl_name.getAsString()); |
| 71 | |
| 72 | // if (m_decl_map.DoingASTImport ()) |
| 73 | // return DeclContext::lookup_result(); |
| 74 | // |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 75 | switch (clang_decl_name.getNameKind()) { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | // Normal identifiers. |
| 77 | case DeclarationName::Identifier: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 78 | if (clang_decl_name.getAsIdentifierInfo()->getBuiltinID() != 0) |
| 79 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 80 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | |
| 82 | // Operator names. Not important for now. |
| 83 | case DeclarationName::CXXOperatorName: |
| 84 | case DeclarationName::CXXLiteralOperatorName: |
| 85 | return DeclContext::lookup_result(); |
| 86 | |
| 87 | // Using directives found in this context. |
| 88 | // Tell Sema we didn't find any or we'll end up getting asked a *lot*. |
| 89 | case DeclarationName::CXXUsingDirective: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 90 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | case DeclarationName::ObjCZeroArgSelector: |
| 93 | case DeclarationName::ObjCOneArgSelector: |
| 94 | case DeclarationName::ObjCMultiArgSelector: |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 95 | { |
| 96 | llvm::SmallVector<NamedDecl*, 1> method_decls; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 98 | NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx); |
| 99 | |
| 100 | FindObjCMethodDecls(method_search_context); |
| 101 | |
| 102 | return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls); |
| 103 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | // These aren't possible in the global context. |
| 105 | case DeclarationName::CXXConstructorName: |
| 106 | case DeclarationName::CXXDestructorName: |
| 107 | case DeclarationName::CXXConversionFunctionName: |
| 108 | return DeclContext::lookup_result(); |
| 109 | } |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 110 | |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 111 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 112 | if (!GetLookupsEnabled()) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 113 | { |
| 114 | // Wait until we see a '$' at the start of a name before we start doing |
| 115 | // any lookups so we can avoid lookup up all of the builtin types. |
| 116 | if (!decl_name.empty() && decl_name[0] == '$') |
| 117 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 118 | SetLookupsEnabled (true); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 119 | } |
| 120 | else |
| 121 | { |
| 122 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 123 | } |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 124 | } |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 125 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 126 | ConstString const_decl_name(decl_name.c_str()); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 127 | |
| 128 | const char *uniqued_const_decl_name = const_decl_name.GetCString(); |
| 129 | if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end()) |
| 130 | { |
| 131 | // We are currently looking up this name... |
| 132 | return DeclContext::lookup_result(); |
| 133 | } |
| 134 | m_active_lookups.insert(uniqued_const_decl_name); |
Greg Clayton | a8b278a | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 135 | // static uint32_t g_depth = 0; |
| 136 | // ++g_depth; |
| 137 | // printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 138 | llvm::SmallVector<NamedDecl*, 4> name_decls; |
| 139 | NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx); |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 140 | FindExternalVisibleDecls(name_search_context); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 141 | DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls)); |
Greg Clayton | a8b278a | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 142 | // --g_depth; |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 143 | m_active_lookups.erase (uniqued_const_decl_name); |
| 144 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 147 | void |
| 148 | ClangASTSource::CompleteType (TagDecl *tag_decl) |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 149 | { |
| 150 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 151 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 152 | static unsigned int invocation_id = 0; |
| 153 | unsigned int current_id = invocation_id++; |
| 154 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 155 | if (log) |
| 156 | { |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 157 | log->Printf(" CompleteTagDecl[%u] on (ASTContext*)%p Completing a TagDecl named %s", |
| 158 | invocation_id, |
| 159 | m_ast_context, |
| 160 | tag_decl->getName().str().c_str()); |
| 161 | |
| 162 | log->Printf(" CTD[%u] Before:", current_id); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 163 | ASTDumper dumper((Decl*)tag_decl); |
| 164 | dumper.ToLog(log, " [CTD] "); |
| 165 | } |
| 166 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 167 | if (!m_ast_importer->CompleteTagDecl (tag_decl)) |
| 168 | { |
| 169 | // We couldn't complete the type. Maybe there's a definition |
| 170 | // somewhere else that can be completed. |
| 171 | |
| 172 | if (log) |
| 173 | log->Printf(" CTD[%u] Type could not be completed in the module in which it was first found.", current_id); |
| 174 | |
| 175 | bool found = false; |
| 176 | |
| 177 | DeclContext *decl_ctx = tag_decl->getDeclContext(); |
| 178 | |
| 179 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx)) |
| 180 | { |
| 181 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 182 | |
| 183 | if (log && log->GetVerbose()) |
| 184 | log->Printf(" CTD[%u] Inspecting namespace map %p (%d entries)", |
| 185 | current_id, |
| 186 | namespace_map.get(), |
| 187 | (int)namespace_map->size()); |
| 188 | |
| 189 | if (!namespace_map) |
| 190 | return; |
| 191 | |
| 192 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 193 | i != e && !found; |
| 194 | ++i) |
| 195 | { |
| 196 | if (log) |
| 197 | log->Printf(" CTD[%u] Searching namespace %s in module %s", |
| 198 | current_id, |
| 199 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 200 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 201 | |
| 202 | TypeList types; |
| 203 | |
| 204 | SymbolContext null_sc; |
| 205 | ConstString name(tag_decl->getName().str().c_str()); |
| 206 | |
| 207 | i->first->FindTypes(null_sc, name, &i->second, true, UINT32_MAX, types); |
| 208 | |
| 209 | for (uint32_t ti = 0, te = types.GetSize(); |
| 210 | ti != te && !found; |
| 211 | ++ti) |
| 212 | { |
| 213 | lldb::TypeSP type = types.GetTypeAtIndex(ti); |
| 214 | |
| 215 | if (!type) |
| 216 | continue; |
| 217 | |
| 218 | lldb::clang_type_t opaque_type = type->GetClangFullType(); |
| 219 | |
| 220 | if (!opaque_type) |
| 221 | continue; |
| 222 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 223 | const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>(); |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 224 | |
| 225 | if (!tag_type) |
| 226 | continue; |
| 227 | |
| 228 | TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl()); |
| 229 | |
| 230 | if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl)) |
| 231 | found = true; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | TypeList types; |
| 238 | |
| 239 | SymbolContext null_sc; |
| 240 | ConstString name(tag_decl->getName().str().c_str()); |
| 241 | ClangNamespaceDecl namespace_decl; |
| 242 | |
| 243 | ModuleList &module_list = m_target->GetImages(); |
| 244 | |
| 245 | module_list.FindTypes(null_sc, name, true, UINT32_MAX, types); |
| 246 | |
| 247 | for (uint32_t ti = 0, te = types.GetSize(); |
| 248 | ti != te && !found; |
| 249 | ++ti) |
| 250 | { |
| 251 | lldb::TypeSP type = types.GetTypeAtIndex(ti); |
| 252 | |
| 253 | if (!type) |
| 254 | continue; |
| 255 | |
| 256 | lldb::clang_type_t opaque_type = type->GetClangFullType(); |
| 257 | |
| 258 | if (!opaque_type) |
| 259 | continue; |
| 260 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 261 | const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>(); |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 262 | |
| 263 | if (!tag_type) |
| 264 | continue; |
| 265 | |
| 266 | TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl()); |
| 267 | |
| 268 | if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl)) |
| 269 | found = true; |
| 270 | } |
| 271 | } |
| 272 | } |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 273 | |
| 274 | if (log) |
| 275 | { |
| 276 | log->Printf(" [CTD] After:"); |
| 277 | ASTDumper dumper((Decl*)tag_decl); |
| 278 | dumper.ToLog(log, " [CTD] "); |
| 279 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 283 | ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl) |
| 284 | { |
| 285 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 286 | |
| 287 | if (log) |
| 288 | { |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 289 | log->Printf(" [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing an ObjCInterfaceDecl named %s", m_ast_context, interface_decl->getName().str().c_str()); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 290 | log->Printf(" [COID] Before:"); |
| 291 | ASTDumper dumper((Decl*)interface_decl); |
| 292 | dumper.ToLog(log, " [COID] "); |
| 293 | } |
| 294 | |
| 295 | m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); |
| 296 | |
| 297 | if (log) |
| 298 | { |
| 299 | log->Printf(" [COID] After:"); |
| 300 | ASTDumper dumper((Decl*)interface_decl); |
| 301 | dumper.ToLog(log, " [COID] "); |
| 302 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 305 | clang::ExternalLoadResult |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 306 | ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context, |
| 307 | bool (*predicate)(Decl::Kind), |
| 308 | llvm::SmallVectorImpl<Decl*> &decls) |
| 309 | { |
| 310 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 311 | |
| 312 | const Decl *context_decl = dyn_cast<Decl>(decl_context); |
| 313 | |
| 314 | if (!context_decl) |
| 315 | return ELR_Failure; |
| 316 | |
| 317 | static unsigned int invocation_id = 0; |
| 318 | unsigned int current_id = invocation_id++; |
| 319 | |
| 320 | if (log) |
| 321 | { |
| 322 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 323 | log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate", |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 324 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 325 | m_ast_context, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 326 | context_named_decl->getNameAsString().c_str(), |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 327 | context_decl->getDeclKindName(), |
| 328 | context_decl, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 329 | (predicate ? "non-null" : "null")); |
| 330 | else if(context_decl) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 331 | log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p with %s predicate", |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 332 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 333 | m_ast_context, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 334 | context_decl->getDeclKindName(), |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 335 | context_decl, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 336 | (predicate ? "non-null" : "null")); |
| 337 | else |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 338 | log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate", |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 339 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 340 | m_ast_context, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 341 | (predicate ? "non-null" : "null")); |
| 342 | } |
| 343 | |
| 344 | Decl *original_decl = NULL; |
| 345 | ASTContext *original_ctx = NULL; |
| 346 | |
| 347 | if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) |
| 348 | return ELR_Failure; |
| 349 | |
| 350 | if (log) |
| 351 | { |
| 352 | log->Printf(" FELD[%u] Original decl:", current_id); |
| 353 | ASTDumper(original_decl).ToLog(log, " "); |
| 354 | } |
| 355 | |
| 356 | if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) |
| 357 | { |
| 358 | ExternalASTSource *external_source = original_ctx->getExternalSource(); |
| 359 | |
| 360 | if (external_source) |
| 361 | external_source->CompleteType (original_tag_decl); |
| 362 | } |
| 363 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 364 | const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 365 | |
| 366 | if (!original_decl_context) |
| 367 | return ELR_Failure; |
| 368 | |
| 369 | for (TagDecl::decl_iterator iter = original_decl_context->decls_begin(); |
| 370 | iter != original_decl_context->decls_end(); |
| 371 | ++iter) |
| 372 | { |
| 373 | Decl *decl = *iter; |
| 374 | |
| 375 | if (!predicate || predicate(decl->getKind())) |
| 376 | { |
| 377 | if (log) |
| 378 | { |
| 379 | ASTDumper ast_dumper(decl); |
| 380 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
| 381 | log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString()); |
| 382 | else |
| 383 | log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString()); |
| 384 | } |
| 385 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 386 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, original_ctx, decl); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 387 | |
| 388 | decls.push_back(copied_decl); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | return ELR_AlreadyLoaded; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | } |
| 394 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 395 | void |
| 396 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context) |
| 397 | { |
| 398 | assert (m_ast_context); |
| 399 | |
| 400 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 401 | |
| 402 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 403 | |
| 404 | static unsigned int invocation_id = 0; |
| 405 | unsigned int current_id = invocation_id++; |
| 406 | |
| 407 | if (log) |
| 408 | { |
| 409 | if (!context.m_decl_context) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 410 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a NULL DeclContext", current_id, m_ast_context, name.GetCString()); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 411 | else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context)) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 412 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in '%s'", current_id, m_ast_context, name.GetCString(), context_named_decl->getNameAsString().c_str()); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 413 | else |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 414 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a '%s'", current_id, m_ast_context, name.GetCString(), context.m_decl_context->getDeclKindName()); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap); |
| 418 | |
| 419 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context)) |
| 420 | { |
| 421 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 422 | |
| 423 | if (log && log->GetVerbose()) |
| 424 | log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)", |
| 425 | current_id, |
| 426 | namespace_map.get(), |
| 427 | (int)namespace_map->size()); |
| 428 | |
| 429 | if (!namespace_map) |
| 430 | return; |
| 431 | |
| 432 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 433 | i != e; |
| 434 | ++i) |
| 435 | { |
| 436 | if (log) |
| 437 | log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s", |
| 438 | current_id, |
| 439 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 440 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 441 | |
| 442 | FindExternalVisibleDecls(context, |
| 443 | i->first, |
| 444 | i->second, |
| 445 | current_id); |
| 446 | } |
| 447 | } |
Sean Callanan | d3812fa | 2011-11-15 21:50:18 +0000 | [diff] [blame] | 448 | else if (isa<ObjCInterfaceDecl>(context.m_decl_context)) |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 449 | { |
| 450 | FindObjCPropertyDecls(context); |
| 451 | } |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 452 | else if (!isa<TranslationUnitDecl>(context.m_decl_context)) |
| 453 | { |
| 454 | // we shouldn't be getting FindExternalVisibleDecls calls for these |
| 455 | return; |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | ClangNamespaceDecl namespace_decl; |
| 460 | |
| 461 | if (log) |
| 462 | log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id); |
| 463 | |
| 464 | FindExternalVisibleDecls(context, |
| 465 | lldb::ModuleSP(), |
| 466 | namespace_decl, |
| 467 | current_id); |
| 468 | } |
| 469 | |
| 470 | if (!context.m_namespace_map->empty()) |
| 471 | { |
| 472 | if (log && log->GetVerbose()) |
| 473 | log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)", |
| 474 | current_id, |
| 475 | context.m_namespace_map.get(), |
| 476 | (int)context.m_namespace_map->size()); |
| 477 | |
| 478 | NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map); |
| 479 | |
| 480 | if (clang_namespace_decl) |
| 481 | clang_namespace_decl->setHasExternalVisibleStorage(); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | void |
| 486 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context, |
| 487 | lldb::ModuleSP module_sp, |
| 488 | ClangNamespaceDecl &namespace_decl, |
| 489 | unsigned int current_id) |
| 490 | { |
| 491 | assert (m_ast_context); |
| 492 | |
| 493 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 494 | |
| 495 | SymbolContextList sc_list; |
| 496 | |
| 497 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 498 | |
| 499 | const char *name_unique_cstr = name.GetCString(); |
| 500 | |
| 501 | if (name_unique_cstr == NULL) |
| 502 | return; |
| 503 | |
| 504 | // The ClangASTSource is not responsible for finding $-names. |
| 505 | if (name_unique_cstr[0] == '$') |
| 506 | return; |
| 507 | |
| 508 | if (module_sp && namespace_decl) |
| 509 | { |
| 510 | ClangNamespaceDecl found_namespace_decl; |
| 511 | |
| 512 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 513 | |
| 514 | if (symbol_vendor) |
| 515 | { |
| 516 | SymbolContext null_sc; |
| 517 | |
| 518 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 519 | |
| 520 | if (found_namespace_decl) |
| 521 | { |
| 522 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 523 | |
| 524 | if (log) |
| 525 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 526 | current_id, |
| 527 | name.GetCString(), |
| 528 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | else |
| 533 | { |
| 534 | ModuleList &images = m_target->GetImages(); |
| 535 | |
| 536 | for (uint32_t i = 0, e = images.GetSize(); |
| 537 | i != e; |
| 538 | ++i) |
| 539 | { |
| 540 | lldb::ModuleSP image = images.GetModuleAtIndex(i); |
| 541 | |
| 542 | if (!image) |
| 543 | continue; |
| 544 | |
| 545 | ClangNamespaceDecl found_namespace_decl; |
| 546 | |
| 547 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 548 | |
| 549 | if (!symbol_vendor) |
| 550 | continue; |
| 551 | |
| 552 | SymbolContext null_sc; |
| 553 | |
| 554 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 555 | |
| 556 | if (found_namespace_decl) |
| 557 | { |
| 558 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 559 | |
| 560 | if (log) |
| 561 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 562 | current_id, |
| 563 | name.GetCString(), |
| 564 | image->GetFileSpec().GetFilename().GetCString()); |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | static ConstString id_name("id"); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 570 | static ConstString Class_name("Class"); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 571 | |
| 572 | do |
| 573 | { |
| 574 | TypeList types; |
| 575 | SymbolContext null_sc; |
| 576 | |
Sean Callanan | 0f71d19 | 2011-12-19 19:38:39 +0000 | [diff] [blame^] | 577 | if (name == id_name || name == Class_name) |
| 578 | break; |
| 579 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 580 | if (module_sp && namespace_decl) |
| 581 | module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types); |
Sean Callanan | 0f71d19 | 2011-12-19 19:38:39 +0000 | [diff] [blame^] | 582 | else |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 583 | m_target->GetImages().FindTypes(null_sc, name, true, 1, types); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 584 | |
| 585 | if (types.GetSize()) |
| 586 | { |
| 587 | lldb::TypeSP type_sp = types.GetTypeAtIndex(0); |
| 588 | |
| 589 | if (log) |
| 590 | { |
| 591 | const char *name_string = type_sp->GetName().GetCString(); |
| 592 | |
| 593 | log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s", |
| 594 | current_id, |
| 595 | name.GetCString(), |
| 596 | (name_string ? name_string : "<anonymous>")); |
| 597 | } |
| 598 | |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 599 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 600 | void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType()); |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 601 | |
Sean Callanan | dc5fce1 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 602 | if (!copied_type) |
| 603 | { |
| 604 | if (log) |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 605 | log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result", |
| 606 | current_id); |
| 607 | |
Sean Callanan | dc5fce1 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 608 | break; |
| 609 | } |
| 610 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 611 | context.AddTypeDecl(copied_type); |
| 612 | } |
Sean Callanan | 673f3db | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 613 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 614 | } while(0); |
| 615 | } |
| 616 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 617 | void |
| 618 | ClangASTSource::FindObjCMethodDecls (NameSearchContext &context) |
| 619 | { |
| 620 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 621 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 622 | static unsigned int invocation_id = 0; |
| 623 | unsigned int current_id = invocation_id++; |
| 624 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 625 | const DeclarationName &decl_name(context.m_decl_name); |
| 626 | const DeclContext *decl_ctx(context.m_decl_context); |
| 627 | |
| 628 | const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx); |
| 629 | |
| 630 | if (!interface_decl) |
| 631 | return; |
| 632 | |
| 633 | StreamString ss; |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 634 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 635 | if (decl_name.isObjCZeroArgSelector()) |
| 636 | { |
| 637 | ss.Printf("%s", decl_name.getAsString().c_str()); |
| 638 | } |
| 639 | else if (decl_name.isObjCOneArgSelector()) |
| 640 | { |
Sean Callanan | 1d9ffe2 | 2011-11-14 18:29:46 +0000 | [diff] [blame] | 641 | ss.Printf("%s", decl_name.getAsString().c_str()); |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 642 | } |
| 643 | else |
| 644 | { |
| 645 | clang::Selector sel = decl_name.getObjCSelector(); |
| 646 | |
| 647 | for (unsigned i = 0, e = sel.getNumArgs(); |
| 648 | i != e; |
| 649 | ++i) |
| 650 | { |
| 651 | llvm::StringRef r = sel.getNameForSlot(i); |
| 652 | ss.Printf("%s:", r.str().c_str()); |
| 653 | } |
| 654 | } |
| 655 | ss.Flush(); |
| 656 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 657 | ConstString selector_name(ss.GetData()); |
| 658 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 659 | if (log) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 660 | log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]", |
| 661 | current_id, |
| 662 | m_ast_context, |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 663 | interface_decl->getNameAsString().c_str(), |
| 664 | selector_name.AsCString()); |
| 665 | |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 666 | ClangASTImporter::ObjCInterfaceMapSP interface_map = m_ast_importer->GetObjCInterfaceMap(interface_decl); |
| 667 | |
| 668 | if (interface_map) |
| 669 | { |
| 670 | for (ClangASTImporter::ObjCInterfaceMap::iterator i = interface_map->begin(), e = interface_map->end(); |
| 671 | i != e; |
| 672 | ++i) |
| 673 | { |
| 674 | lldb::clang_type_t backing_type = i->GetOpaqueQualType(); |
| 675 | |
| 676 | if (!backing_type) |
| 677 | continue; |
| 678 | |
| 679 | QualType backing_qual_type = QualType::getFromOpaquePtr(backing_type); |
| 680 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 681 | const ObjCInterfaceType *backing_interface_type = backing_qual_type.getTypePtr()->getAs<ObjCInterfaceType>(); |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 682 | |
| 683 | if (!backing_interface_type) |
| 684 | continue; |
| 685 | |
| 686 | const ObjCInterfaceDecl *backing_interface_decl = backing_interface_type->getDecl(); |
| 687 | |
| 688 | if (!backing_interface_decl) |
| 689 | continue; |
| 690 | |
| 691 | if (backing_interface_decl->decls_begin() == backing_interface_decl->decls_end()) |
| 692 | continue; // don't waste time creating a DeclarationName here |
| 693 | |
| 694 | clang::ASTContext &backing_ast_context = backing_interface_decl->getASTContext(); |
| 695 | |
| 696 | llvm::SmallVector<clang::IdentifierInfo *, 3> selector_components; |
Sean Callanan | 3d8540a | 2011-12-07 22:39:39 +0000 | [diff] [blame] | 697 | int num_arguments = 0; |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 698 | |
| 699 | if (decl_name.isObjCZeroArgSelector()) |
| 700 | { |
| 701 | selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str())); |
| 702 | } |
| 703 | else if (decl_name.isObjCOneArgSelector()) |
| 704 | { |
| 705 | selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str())); |
Sean Callanan | 3d8540a | 2011-12-07 22:39:39 +0000 | [diff] [blame] | 706 | num_arguments = 1; |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 707 | } |
| 708 | else |
| 709 | { |
| 710 | clang::Selector sel = decl_name.getObjCSelector(); |
| 711 | |
| 712 | for (unsigned i = 0, e = sel.getNumArgs(); |
| 713 | i != e; |
| 714 | ++i) |
| 715 | { |
| 716 | llvm::StringRef r = sel.getNameForSlot(i); |
| 717 | |
| 718 | selector_components.push_back (&backing_ast_context.Idents.get(r.str().c_str())); |
Sean Callanan | 3d8540a | 2011-12-07 22:39:39 +0000 | [diff] [blame] | 719 | num_arguments++; |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
Sean Callanan | 3d8540a | 2011-12-07 22:39:39 +0000 | [diff] [blame] | 723 | Selector backing_selector = backing_interface_decl->getASTContext().Selectors.getSelector(num_arguments, selector_components.data()); |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 724 | DeclarationName backing_decl_name = DeclarationName(backing_selector); |
| 725 | |
| 726 | DeclContext::lookup_const_result lookup_result = backing_interface_decl->lookup(backing_decl_name); |
| 727 | |
| 728 | if (lookup_result.first == lookup_result.second) |
| 729 | continue; |
| 730 | |
| 731 | ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(*lookup_result.first); |
| 732 | |
| 733 | if (!method_decl) |
| 734 | continue; |
| 735 | |
| 736 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &backing_ast_context, *lookup_result.first); |
| 737 | |
Sean Callanan | 3d8540a | 2011-12-07 22:39:39 +0000 | [diff] [blame] | 738 | if (!copied_decl) |
| 739 | { |
Greg Clayton | 2e87f6a | 2011-12-08 01:32:28 +0000 | [diff] [blame] | 740 | if (log) |
| 741 | log->Printf(" CAS::FOMD[%d] couldn't import method from symbols", current_id); |
Sean Callanan | 3d8540a | 2011-12-07 22:39:39 +0000 | [diff] [blame] | 742 | continue; |
| 743 | } |
| 744 | |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 745 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl> (copied_decl); |
| 746 | |
| 747 | if (!copied_method_decl) |
| 748 | continue; |
| 749 | |
| 750 | if (log) |
| 751 | { |
| 752 | ASTDumper dumper((Decl*)copied_method_decl); |
| 753 | log->Printf(" CAS::FOMD[%d] found (in symbols) %s", current_id, dumper.GetCString()); |
| 754 | } |
| 755 | |
| 756 | context.AddNamedDecl(copied_method_decl); |
| 757 | } |
| 758 | } |
| 759 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 760 | SymbolContextList sc_list; |
| 761 | |
| 762 | const bool include_symbols = false; |
| 763 | const bool append = false; |
| 764 | |
| 765 | m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, append, sc_list); |
| 766 | |
| 767 | for (uint32_t i = 0, e = sc_list.GetSize(); |
| 768 | i != e; |
| 769 | ++i) |
| 770 | { |
| 771 | SymbolContext sc; |
| 772 | |
| 773 | if (!sc_list.GetContextAtIndex(i, sc)) |
| 774 | continue; |
| 775 | |
| 776 | if (!sc.function) |
| 777 | continue; |
| 778 | |
| 779 | DeclContext *function_ctx = sc.function->GetClangDeclContext(); |
| 780 | |
| 781 | if (!function_ctx) |
| 782 | continue; |
| 783 | |
| 784 | ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx); |
| 785 | |
| 786 | if (!method_decl) |
| 787 | continue; |
| 788 | |
| 789 | ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface(); |
| 790 | |
| 791 | if (!found_interface_decl) |
| 792 | continue; |
| 793 | |
| 794 | if (found_interface_decl->getName() == interface_decl->getName()) |
| 795 | { |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 796 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 797 | |
| 798 | if (!copied_decl) |
| 799 | continue; |
| 800 | |
| 801 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); |
| 802 | |
| 803 | if (!copied_method_decl) |
| 804 | continue; |
| 805 | |
| 806 | if (log) |
| 807 | { |
| 808 | ASTDumper dumper((Decl*)copied_method_decl); |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 809 | log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString()); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | context.AddNamedDecl(copied_method_decl); |
| 813 | } |
| 814 | } |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 817 | void |
| 818 | ClangASTSource::FindObjCPropertyDecls (NameSearchContext &context) |
| 819 | { |
| 820 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 821 | |
| 822 | static unsigned int invocation_id = 0; |
| 823 | unsigned int current_id = invocation_id++; |
| 824 | |
| 825 | const ObjCInterfaceDecl *iface_decl = cast<ObjCInterfaceDecl>(context.m_decl_context); |
| 826 | Decl *orig_decl; |
| 827 | ASTContext *orig_ast_ctx; |
| 828 | |
| 829 | m_ast_importer->ResolveDeclOrigin(iface_decl, &orig_decl, &orig_ast_ctx); |
| 830 | |
| 831 | if (!orig_decl) |
| 832 | return; |
| 833 | |
| 834 | ObjCInterfaceDecl *orig_iface_decl = dyn_cast<ObjCInterfaceDecl>(orig_decl); |
| 835 | |
| 836 | if (!orig_iface_decl) |
| 837 | return; |
| 838 | |
| 839 | if (!ClangASTContext::GetCompleteDecl(orig_ast_ctx, orig_iface_decl)) |
| 840 | return; |
| 841 | |
| 842 | std::string property_name_str = context.m_decl_name.getAsString(); |
| 843 | StringRef property_name(property_name_str.c_str()); |
| 844 | ObjCPropertyDecl *property_decl = orig_iface_decl->FindPropertyDeclaration(&orig_ast_ctx->Idents.get(property_name)); |
| 845 | |
| 846 | if (log) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 847 | log->Printf("ClangASTSource::FindObjCPropertyDecls[%d] on (ASTContext*)%p for property '%s.%s'", |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 848 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 849 | m_ast_context, |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 850 | iface_decl->getNameAsString().c_str(), |
| 851 | property_name_str.c_str()); |
| 852 | |
| 853 | if (!property_decl) |
| 854 | return; |
| 855 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 856 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, orig_ast_ctx, property_decl); |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 857 | |
| 858 | if (!copied_decl) |
| 859 | return; |
| 860 | |
| 861 | ObjCPropertyDecl *copied_property_decl = dyn_cast<ObjCPropertyDecl>(copied_decl); |
| 862 | |
| 863 | if (!copied_property_decl) |
| 864 | return; |
| 865 | |
| 866 | if (log) |
| 867 | { |
| 868 | ASTDumper dumper((Decl*)copied_property_decl); |
| 869 | log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); |
| 870 | } |
| 871 | |
| 872 | context.AddNamedDecl(copied_property_decl); |
| 873 | } |
| 874 | |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 875 | void |
| 876 | ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, |
| 877 | const ConstString &name, |
| 878 | ClangASTImporter::NamespaceMapSP &parent_map) const |
| 879 | { |
| 880 | static unsigned int invocation_id = 0; |
| 881 | unsigned int current_id = invocation_id++; |
| 882 | |
| 883 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 884 | |
| 885 | if (log) |
| 886 | { |
| 887 | if (parent_map && parent_map->size()) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 888 | log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s", |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 889 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 890 | m_ast_context, |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 891 | name.GetCString(), |
| 892 | parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str()); |
| 893 | else |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 894 | log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s", |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 895 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 896 | m_ast_context, |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 897 | name.GetCString()); |
| 898 | } |
| 899 | |
| 900 | |
| 901 | if (parent_map) |
| 902 | { |
| 903 | for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end(); |
| 904 | i != e; |
| 905 | ++i) |
| 906 | { |
| 907 | ClangNamespaceDecl found_namespace_decl; |
| 908 | |
| 909 | lldb::ModuleSP module_sp = i->first; |
| 910 | ClangNamespaceDecl module_parent_namespace_decl = i->second; |
| 911 | |
| 912 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 913 | |
| 914 | if (!symbol_vendor) |
| 915 | continue; |
| 916 | |
| 917 | SymbolContext null_sc; |
| 918 | |
| 919 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl); |
| 920 | |
| 921 | if (!found_namespace_decl) |
| 922 | continue; |
| 923 | |
| 924 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 925 | |
| 926 | if (log) |
| 927 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 928 | current_id, |
| 929 | name.GetCString(), |
| 930 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 931 | } |
| 932 | } |
| 933 | else |
| 934 | { |
| 935 | ModuleList &images = m_target->GetImages(); |
| 936 | ClangNamespaceDecl null_namespace_decl; |
| 937 | |
| 938 | for (uint32_t i = 0, e = images.GetSize(); |
| 939 | i != e; |
| 940 | ++i) |
| 941 | { |
| 942 | lldb::ModuleSP image = images.GetModuleAtIndex(i); |
| 943 | |
| 944 | if (!image) |
| 945 | continue; |
| 946 | |
| 947 | ClangNamespaceDecl found_namespace_decl; |
| 948 | |
| 949 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 950 | |
| 951 | if (!symbol_vendor) |
| 952 | continue; |
| 953 | |
| 954 | SymbolContext null_sc; |
| 955 | |
| 956 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl); |
| 957 | |
| 958 | if (!found_namespace_decl) |
| 959 | continue; |
| 960 | |
| 961 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 962 | |
| 963 | if (log) |
| 964 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 965 | current_id, |
| 966 | name.GetCString(), |
| 967 | image->GetFileSpec().GetFilename().GetCString()); |
| 968 | } |
| 969 | } |
| 970 | } |
| 971 | |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 972 | void |
| 973 | ClangASTSource::CompleteObjCInterfaceMap (ClangASTImporter::ObjCInterfaceMapSP &objc_interface_map, |
| 974 | const ConstString &name) const |
| 975 | { |
| 976 | SymbolContext null_sc; |
| 977 | |
| 978 | TypeList types; |
| 979 | |
| 980 | m_target->GetImages().FindTypes(null_sc, name, true, UINT32_MAX, types); |
| 981 | |
| 982 | for (uint32_t i = 0, e = types.GetSize(); |
| 983 | i != e; |
| 984 | ++i) |
| 985 | { |
| 986 | lldb::TypeSP mapped_type_sp = types.GetTypeAtIndex(i); |
| 987 | |
| 988 | if (!mapped_type_sp || !mapped_type_sp->GetClangFullType()) |
| 989 | continue; |
| 990 | |
| 991 | objc_interface_map->push_back (ClangASTType(mapped_type_sp->GetClangAST(), mapped_type_sp->GetClangFullType())); |
| 992 | } |
| 993 | } |
| 994 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 995 | NamespaceDecl * |
| 996 | ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls) |
| 997 | { |
| 998 | if (namespace_decls.empty()) |
| 999 | return NULL; |
| 1000 | |
| 1001 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1002 | |
| 1003 | const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; |
| 1004 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1005 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl()); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1006 | |
| 1007 | NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); |
| 1008 | |
| 1009 | m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); |
| 1010 | |
| 1011 | return dyn_cast<NamespaceDecl>(copied_decl); |
| 1012 | } |
| 1013 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1014 | void * |
| 1015 | ClangASTSource::GuardedCopyType (ASTContext *dest_context, |
| 1016 | ASTContext *source_context, |
| 1017 | void *clang_type) |
| 1018 | { |
| 1019 | SetImportInProgress(true); |
| 1020 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1021 | QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type)); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1022 | |
| 1023 | void *ret = ret_qual_type.getAsOpaquePtr(); |
| 1024 | |
| 1025 | SetImportInProgress(false); |
| 1026 | |
| 1027 | return ret; |
| 1028 | } |
| 1029 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1030 | clang::NamedDecl * |
| 1031 | NameSearchContext::AddVarDecl(void *type) |
| 1032 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1033 | IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo(); |
Sean Callanan | 1ddd9fe | 2010-11-30 00:27:43 +0000 | [diff] [blame] | 1034 | |
| 1035 | assert (type && "Type for variable must be non-NULL!"); |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 1036 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1037 | clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1038 | const_cast<DeclContext*>(m_decl_context), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1039 | SourceLocation(), |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1040 | SourceLocation(), |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 1041 | ii, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1042 | QualType::getFromOpaquePtr(type), |
| 1043 | 0, |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 1044 | SC_Static, |
| 1045 | SC_Static); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1046 | m_decls.push_back(Decl); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1047 | |
| 1048 | return Decl; |
| 1049 | } |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1050 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1051 | clang::NamedDecl * |
| 1052 | NameSearchContext::AddFunDecl (void *type) |
| 1053 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1054 | clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1055 | const_cast<DeclContext*>(m_decl_context), |
| 1056 | SourceLocation(), |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1057 | SourceLocation(), |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1058 | m_decl_name.getAsIdentifierInfo(), |
| 1059 | QualType::getFromOpaquePtr(type), |
| 1060 | NULL, |
| 1061 | SC_Static, |
| 1062 | SC_Static, |
| 1063 | false, |
| 1064 | true); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1065 | |
Sean Callanan | b291abe | 2010-08-12 23:45:38 +0000 | [diff] [blame] | 1066 | // We have to do more than just synthesize the FunctionDecl. We have to |
| 1067 | // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do |
| 1068 | // this, we raid the function's FunctionProtoType for types. |
| 1069 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1070 | QualType qual_type (QualType::getFromOpaquePtr(type)); |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1071 | const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>(); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1072 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1073 | if (func_proto_type) |
Sean Callanan | 3c821cc | 2010-06-23 18:58:10 +0000 | [diff] [blame] | 1074 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1075 | unsigned NumArgs = func_proto_type->getNumArgs(); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1076 | unsigned ArgIndex; |
| 1077 | |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1078 | SmallVector<ParmVarDecl *, 5> parm_var_decls; |
| 1079 | |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1080 | for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex) |
| 1081 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1082 | QualType arg_qual_type (func_proto_type->getArgType(ArgIndex)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1083 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1084 | parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context, |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1085 | const_cast<DeclContext*>(m_decl_context), |
| 1086 | SourceLocation(), |
| 1087 | SourceLocation(), |
| 1088 | NULL, |
| 1089 | arg_qual_type, |
| 1090 | NULL, |
| 1091 | SC_Static, |
| 1092 | SC_Static, |
| 1093 | NULL)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1096 | func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1097 | } |
Sean Callanan | dc5fce1 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 1098 | else |
| 1099 | { |
| 1100 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1101 | |
| 1102 | log->Printf("Function type wasn't a FunctionProtoType"); |
| 1103 | } |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1104 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1105 | m_decls.push_back(func_decl); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1106 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1107 | return func_decl; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1108 | } |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1109 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1110 | clang::NamedDecl * |
| 1111 | NameSearchContext::AddGenericFunDecl() |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1112 | { |
Sean Callanan | ad29309 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1113 | FunctionProtoType::ExtProtoInfo proto_info; |
| 1114 | |
| 1115 | proto_info.Variadic = true; |
| 1116 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1117 | QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result |
| 1118 | NULL, // argument types |
| 1119 | 0, // number of arguments |
| 1120 | proto_info)); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1121 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1122 | return AddFunDecl(generic_function_type.getAsOpaquePtr()); |
| 1123 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1124 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1125 | clang::NamedDecl * |
| 1126 | NameSearchContext::AddTypeDecl(void *type) |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1127 | { |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1128 | if (type) |
| 1129 | { |
| 1130 | QualType qual_type = QualType::getFromOpaquePtr(type); |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1131 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1132 | if (const TagType *tag_type = qual_type->getAs<TagType>()) |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1133 | { |
| 1134 | TagDecl *tag_decl = tag_type->getDecl(); |
| 1135 | |
| 1136 | m_decls.push_back(tag_decl); |
| 1137 | |
| 1138 | return tag_decl; |
| 1139 | } |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1140 | else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>()) |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1141 | { |
| 1142 | ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface(); |
| 1143 | |
| 1144 | m_decls.push_back((NamedDecl*)interface_decl); |
| 1145 | |
| 1146 | return (NamedDecl*)interface_decl; |
| 1147 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1148 | } |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1149 | return NULL; |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1150 | } |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 1151 | |
| 1152 | void |
| 1153 | NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result) |
| 1154 | { |
| 1155 | for (clang::NamedDecl * const *decl_iterator = result.first; |
| 1156 | decl_iterator != result.second; |
| 1157 | ++decl_iterator) |
| 1158 | m_decls.push_back (*decl_iterator); |
| 1159 | } |
| 1160 | |
| 1161 | void |
| 1162 | NameSearchContext::AddNamedDecl (clang::NamedDecl *decl) |
| 1163 | { |
| 1164 | m_decls.push_back (decl); |
| 1165 | } |