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