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" |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 12 | #include "clang/AST/RecordLayout.h" |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Greg Clayton | 6e0101c | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ModuleList.h" |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 16 | #include "lldb/Expression/ASTDumper.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Expression/ClangASTSource.h" |
| 18 | #include "lldb/Expression/ClangExpression.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/ClangNamespaceDecl.h" |
| 20 | #include "lldb/Symbol/SymbolVendor.h" |
Sean Callanan | 673f3db | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 21 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 22 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace clang; |
| 25 | using namespace lldb_private; |
| 26 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 27 | ClangASTSource::~ClangASTSource() |
| 28 | { |
Sean Callanan | a3d0447 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 29 | m_ast_importer->ForgetDestination(m_ast_context); |
| 30 | |
Johnny Chen | fa21ffd | 2011-11-30 23:18:53 +0000 | [diff] [blame] | 31 | // We are in the process of destruction, don't create clang ast context on demand |
| 32 | // by passing false to Target::GetScratchClangASTContext(create_on_demand). |
| 33 | ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false); |
Sean Callanan | a3d0447 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 34 | |
| 35 | if (!scratch_clang_ast_context) |
| 36 | return; |
| 37 | |
| 38 | clang::ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); |
| 39 | |
| 40 | if (!scratch_ast_context) |
| 41 | return; |
| 42 | |
| 43 | if (m_ast_context != scratch_ast_context) |
| 44 | m_ast_importer->ForgetSource(scratch_ast_context, m_ast_context); |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 45 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 47 | void |
| 48 | ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) |
| 49 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 50 | if (!m_ast_context) |
| 51 | return; |
| 52 | |
| 53 | m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 54 | m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | // The core lookup interface. |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 58 | DeclContext::lookup_result |
| 59 | ClangASTSource::FindExternalVisibleDeclsByName |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 60 | ( |
| 61 | const DeclContext *decl_ctx, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 62 | DeclarationName clang_decl_name |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 63 | ) |
| 64 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 65 | if (!m_ast_context) |
| 66 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 67 | |
| 68 | if (GetImportInProgress()) |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 69 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 70 | |
| 71 | std::string decl_name (clang_decl_name.getAsString()); |
| 72 | |
| 73 | // if (m_decl_map.DoingASTImport ()) |
| 74 | // return DeclContext::lookup_result(); |
| 75 | // |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 76 | switch (clang_decl_name.getNameKind()) { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | // Normal identifiers. |
| 78 | case DeclarationName::Identifier: |
Sean Callanan | 0ffff1e | 2012-04-25 17:46:01 +0000 | [diff] [blame^] | 79 | { |
| 80 | clang::IdentifierInfo *identifier_info = clang_decl_name.getAsIdentifierInfo(); |
| 81 | |
| 82 | if (!identifier_info || |
| 83 | identifier_info->getBuiltinID() != 0) |
| 84 | { |
| 85 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 86 | } |
| 87 | } |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 88 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | |
| 90 | // Operator names. Not important for now. |
| 91 | case DeclarationName::CXXOperatorName: |
| 92 | case DeclarationName::CXXLiteralOperatorName: |
| 93 | return DeclContext::lookup_result(); |
| 94 | |
| 95 | // Using directives found in this context. |
| 96 | // Tell Sema we didn't find any or we'll end up getting asked a *lot*. |
| 97 | case DeclarationName::CXXUsingDirective: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 98 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | case DeclarationName::ObjCZeroArgSelector: |
| 101 | case DeclarationName::ObjCOneArgSelector: |
| 102 | case DeclarationName::ObjCMultiArgSelector: |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 103 | { |
| 104 | llvm::SmallVector<NamedDecl*, 1> method_decls; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 106 | NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx); |
| 107 | |
| 108 | FindObjCMethodDecls(method_search_context); |
| 109 | |
| 110 | return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls); |
| 111 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 112 | // These aren't possible in the global context. |
| 113 | case DeclarationName::CXXConstructorName: |
| 114 | case DeclarationName::CXXDestructorName: |
| 115 | case DeclarationName::CXXConversionFunctionName: |
| 116 | return DeclContext::lookup_result(); |
| 117 | } |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 118 | |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 119 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 120 | if (!GetLookupsEnabled()) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 121 | { |
| 122 | // Wait until we see a '$' at the start of a name before we start doing |
| 123 | // any lookups so we can avoid lookup up all of the builtin types. |
| 124 | if (!decl_name.empty() && decl_name[0] == '$') |
| 125 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 126 | SetLookupsEnabled (true); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 127 | } |
| 128 | else |
| 129 | { |
| 130 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 131 | } |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 132 | } |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 133 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 134 | ConstString const_decl_name(decl_name.c_str()); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 135 | |
| 136 | const char *uniqued_const_decl_name = const_decl_name.GetCString(); |
| 137 | if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end()) |
| 138 | { |
| 139 | // We are currently looking up this name... |
| 140 | return DeclContext::lookup_result(); |
| 141 | } |
| 142 | m_active_lookups.insert(uniqued_const_decl_name); |
Greg Clayton | a8b278a | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 143 | // static uint32_t g_depth = 0; |
| 144 | // ++g_depth; |
| 145 | // printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 146 | llvm::SmallVector<NamedDecl*, 4> name_decls; |
| 147 | NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx); |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 148 | FindExternalVisibleDecls(name_search_context); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 149 | DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls)); |
Greg Clayton | a8b278a | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 150 | // --g_depth; |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 151 | m_active_lookups.erase (uniqued_const_decl_name); |
| 152 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 155 | void |
| 156 | ClangASTSource::CompleteType (TagDecl *tag_decl) |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 157 | { |
| 158 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 159 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 160 | static unsigned int invocation_id = 0; |
| 161 | unsigned int current_id = invocation_id++; |
| 162 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 163 | if (log) |
| 164 | { |
Sean Callanan | 6e22e8b | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 165 | log->Printf(" CompleteTagDecl[%u] on (ASTContext*)%p Completing (TagDecl*)%p named %s", |
| 166 | current_id, |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 167 | m_ast_context, |
Sean Callanan | 6e22e8b | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 168 | tag_decl, |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 169 | tag_decl->getName().str().c_str()); |
| 170 | |
| 171 | log->Printf(" CTD[%u] Before:", current_id); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 172 | ASTDumper dumper((Decl*)tag_decl); |
| 173 | dumper.ToLog(log, " [CTD] "); |
| 174 | } |
| 175 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 176 | if (!m_ast_importer->CompleteTagDecl (tag_decl)) |
| 177 | { |
| 178 | // We couldn't complete the type. Maybe there's a definition |
| 179 | // somewhere else that can be completed. |
| 180 | |
| 181 | if (log) |
| 182 | log->Printf(" CTD[%u] Type could not be completed in the module in which it was first found.", current_id); |
| 183 | |
| 184 | bool found = false; |
| 185 | |
| 186 | DeclContext *decl_ctx = tag_decl->getDeclContext(); |
| 187 | |
| 188 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx)) |
| 189 | { |
| 190 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 191 | |
| 192 | if (log && log->GetVerbose()) |
| 193 | log->Printf(" CTD[%u] Inspecting namespace map %p (%d entries)", |
| 194 | current_id, |
| 195 | namespace_map.get(), |
| 196 | (int)namespace_map->size()); |
| 197 | |
| 198 | if (!namespace_map) |
| 199 | return; |
| 200 | |
| 201 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 202 | i != e && !found; |
| 203 | ++i) |
| 204 | { |
| 205 | if (log) |
| 206 | log->Printf(" CTD[%u] Searching namespace %s in module %s", |
| 207 | current_id, |
| 208 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 209 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 210 | |
| 211 | TypeList types; |
| 212 | |
| 213 | SymbolContext null_sc; |
| 214 | ConstString name(tag_decl->getName().str().c_str()); |
| 215 | |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 216 | i->first->FindTypesInNamespace(null_sc, name, &i->second, UINT32_MAX, types); |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 217 | |
| 218 | for (uint32_t ti = 0, te = types.GetSize(); |
| 219 | ti != te && !found; |
| 220 | ++ti) |
| 221 | { |
| 222 | lldb::TypeSP type = types.GetTypeAtIndex(ti); |
| 223 | |
| 224 | if (!type) |
| 225 | continue; |
| 226 | |
| 227 | lldb::clang_type_t opaque_type = type->GetClangFullType(); |
| 228 | |
| 229 | if (!opaque_type) |
| 230 | continue; |
| 231 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 232 | const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>(); |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 233 | |
| 234 | if (!tag_type) |
| 235 | continue; |
| 236 | |
| 237 | TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl()); |
| 238 | |
| 239 | if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl)) |
| 240 | found = true; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | else |
| 245 | { |
| 246 | TypeList types; |
| 247 | |
| 248 | SymbolContext null_sc; |
| 249 | ConstString name(tag_decl->getName().str().c_str()); |
| 250 | ClangNamespaceDecl namespace_decl; |
| 251 | |
| 252 | ModuleList &module_list = m_target->GetImages(); |
| 253 | |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 254 | bool exact_match = false; |
Greg Clayton | 9f95fb6 | 2012-04-06 17:41:13 +0000 | [diff] [blame] | 255 | module_list.FindTypes (null_sc, name, exact_match, UINT32_MAX, types); |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 256 | |
| 257 | for (uint32_t ti = 0, te = types.GetSize(); |
| 258 | ti != te && !found; |
| 259 | ++ti) |
| 260 | { |
| 261 | lldb::TypeSP type = types.GetTypeAtIndex(ti); |
| 262 | |
| 263 | if (!type) |
| 264 | continue; |
| 265 | |
| 266 | lldb::clang_type_t opaque_type = type->GetClangFullType(); |
| 267 | |
| 268 | if (!opaque_type) |
| 269 | continue; |
| 270 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 271 | const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>(); |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 272 | |
| 273 | if (!tag_type) |
| 274 | continue; |
| 275 | |
| 276 | TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl()); |
| 277 | |
| 278 | if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl)) |
| 279 | found = true; |
| 280 | } |
| 281 | } |
| 282 | } |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 283 | |
| 284 | if (log) |
| 285 | { |
| 286 | log->Printf(" [CTD] After:"); |
| 287 | ASTDumper dumper((Decl*)tag_decl); |
| 288 | dumper.ToLog(log, " [CTD] "); |
| 289 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | void |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 293 | ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl) |
| 294 | { |
| 295 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 296 | |
| 297 | if (log) |
| 298 | { |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 299 | 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] | 300 | log->Printf(" [COID] Before:"); |
| 301 | ASTDumper dumper((Decl*)interface_decl); |
| 302 | dumper.ToLog(log, " [COID] "); |
| 303 | } |
| 304 | |
| 305 | m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); |
| 306 | |
| 307 | if (log) |
| 308 | { |
| 309 | log->Printf(" [COID] After:"); |
| 310 | ASTDumper dumper((Decl*)interface_decl); |
| 311 | dumper.ToLog(log, " [COID] "); |
| 312 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 315 | clang::ExternalLoadResult |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 316 | ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context, |
| 317 | bool (*predicate)(Decl::Kind), |
| 318 | llvm::SmallVectorImpl<Decl*> &decls) |
| 319 | { |
| 320 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 321 | |
| 322 | const Decl *context_decl = dyn_cast<Decl>(decl_context); |
| 323 | |
| 324 | if (!context_decl) |
| 325 | return ELR_Failure; |
| 326 | |
| 327 | static unsigned int invocation_id = 0; |
| 328 | unsigned int current_id = invocation_id++; |
| 329 | |
| 330 | if (log) |
| 331 | { |
| 332 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 333 | 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] | 334 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 335 | m_ast_context, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 336 | context_named_decl->getNameAsString().c_str(), |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 337 | context_decl->getDeclKindName(), |
| 338 | context_decl, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 339 | (predicate ? "non-null" : "null")); |
| 340 | else if(context_decl) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 341 | 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] | 342 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 343 | m_ast_context, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 344 | context_decl->getDeclKindName(), |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 345 | context_decl, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 346 | (predicate ? "non-null" : "null")); |
| 347 | else |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 348 | 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] | 349 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 350 | m_ast_context, |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 351 | (predicate ? "non-null" : "null")); |
| 352 | } |
| 353 | |
| 354 | Decl *original_decl = NULL; |
| 355 | ASTContext *original_ctx = NULL; |
| 356 | |
| 357 | if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) |
| 358 | return ELR_Failure; |
| 359 | |
| 360 | if (log) |
| 361 | { |
Sean Callanan | 6e22e8b | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 362 | log->Printf(" FELD[%u] Original decl (Decl*)%p:", current_id, original_decl); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 363 | ASTDumper(original_decl).ToLog(log, " "); |
| 364 | } |
| 365 | |
| 366 | if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) |
| 367 | { |
| 368 | ExternalASTSource *external_source = original_ctx->getExternalSource(); |
| 369 | |
| 370 | if (external_source) |
| 371 | external_source->CompleteType (original_tag_decl); |
| 372 | } |
| 373 | |
Sean Callanan | b2027ec | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 374 | const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl); |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 375 | |
| 376 | if (!original_decl_context) |
| 377 | return ELR_Failure; |
| 378 | |
| 379 | for (TagDecl::decl_iterator iter = original_decl_context->decls_begin(); |
| 380 | iter != original_decl_context->decls_end(); |
| 381 | ++iter) |
| 382 | { |
| 383 | Decl *decl = *iter; |
| 384 | |
| 385 | if (!predicate || predicate(decl->getKind())) |
| 386 | { |
| 387 | if (log) |
| 388 | { |
| 389 | ASTDumper ast_dumper(decl); |
| 390 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
| 391 | log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString()); |
| 392 | else |
| 393 | log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString()); |
| 394 | } |
| 395 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 396 | 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] | 397 | |
Sean Callanan | ddb5933 | 2012-03-20 21:11:12 +0000 | [diff] [blame] | 398 | if (!copied_decl) |
| 399 | continue; |
| 400 | |
Sean Callanan | e947839 | 2012-03-15 01:53:17 +0000 | [diff] [blame] | 401 | if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) |
| 402 | { |
| 403 | QualType copied_field_type = copied_field->getType(); |
| 404 | |
| 405 | if (const TagType *copied_field_tag_type = copied_field_type->getAs<TagType>()) |
| 406 | m_ast_importer->CompleteTagDecl(copied_field_tag_type->getDecl()); |
| 407 | if (const ObjCObjectType *copied_field_object_type = copied_field_type->getAs<ObjCObjectType>()) |
| 408 | if (ObjCInterfaceDecl *copied_field_objc_interface_decl = copied_field_object_type->getInterface()) |
| 409 | m_ast_importer->CompleteObjCInterfaceDecl(copied_field_objc_interface_decl); |
| 410 | } |
| 411 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 412 | decls.push_back(copied_decl); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return ELR_AlreadyLoaded; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 419 | void |
| 420 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context) |
| 421 | { |
| 422 | assert (m_ast_context); |
| 423 | |
| 424 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 425 | |
| 426 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 427 | |
| 428 | static unsigned int invocation_id = 0; |
| 429 | unsigned int current_id = invocation_id++; |
| 430 | |
| 431 | if (log) |
| 432 | { |
| 433 | if (!context.m_decl_context) |
Sean Callanan | 6e22e8b | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 434 | 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] | 435 | 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] | 436 | 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] | 437 | else |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 438 | 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] | 439 | } |
| 440 | |
| 441 | context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap); |
| 442 | |
| 443 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context)) |
| 444 | { |
| 445 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 446 | |
| 447 | if (log && log->GetVerbose()) |
| 448 | log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)", |
| 449 | current_id, |
| 450 | namespace_map.get(), |
| 451 | (int)namespace_map->size()); |
| 452 | |
| 453 | if (!namespace_map) |
| 454 | return; |
| 455 | |
| 456 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 457 | i != e; |
| 458 | ++i) |
| 459 | { |
| 460 | if (log) |
| 461 | log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s", |
| 462 | current_id, |
| 463 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 464 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 465 | |
| 466 | FindExternalVisibleDecls(context, |
| 467 | i->first, |
| 468 | i->second, |
| 469 | current_id); |
| 470 | } |
| 471 | } |
Sean Callanan | d3812fa | 2011-11-15 21:50:18 +0000 | [diff] [blame] | 472 | else if (isa<ObjCInterfaceDecl>(context.m_decl_context)) |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 473 | { |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 474 | FindObjCPropertyAndIvarDecls(context); |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 475 | } |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 476 | else if (!isa<TranslationUnitDecl>(context.m_decl_context)) |
| 477 | { |
| 478 | // we shouldn't be getting FindExternalVisibleDecls calls for these |
| 479 | return; |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | ClangNamespaceDecl namespace_decl; |
| 484 | |
| 485 | if (log) |
| 486 | log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id); |
| 487 | |
| 488 | FindExternalVisibleDecls(context, |
| 489 | lldb::ModuleSP(), |
| 490 | namespace_decl, |
| 491 | current_id); |
| 492 | } |
| 493 | |
| 494 | if (!context.m_namespace_map->empty()) |
| 495 | { |
| 496 | if (log && log->GetVerbose()) |
| 497 | log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)", |
| 498 | current_id, |
| 499 | context.m_namespace_map.get(), |
| 500 | (int)context.m_namespace_map->size()); |
| 501 | |
| 502 | NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map); |
| 503 | |
| 504 | if (clang_namespace_decl) |
| 505 | clang_namespace_decl->setHasExternalVisibleStorage(); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void |
| 510 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context, |
| 511 | lldb::ModuleSP module_sp, |
| 512 | ClangNamespaceDecl &namespace_decl, |
| 513 | unsigned int current_id) |
| 514 | { |
| 515 | assert (m_ast_context); |
| 516 | |
| 517 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 518 | |
| 519 | SymbolContextList sc_list; |
| 520 | |
| 521 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 522 | |
| 523 | const char *name_unique_cstr = name.GetCString(); |
| 524 | |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 525 | static ConstString id_name("id"); |
| 526 | static ConstString Class_name("Class"); |
| 527 | |
| 528 | if (name == id_name || name == Class_name) |
| 529 | return; |
| 530 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 531 | if (name_unique_cstr == NULL) |
| 532 | return; |
| 533 | |
| 534 | // The ClangASTSource is not responsible for finding $-names. |
| 535 | if (name_unique_cstr[0] == '$') |
| 536 | return; |
| 537 | |
| 538 | if (module_sp && namespace_decl) |
| 539 | { |
| 540 | ClangNamespaceDecl found_namespace_decl; |
| 541 | |
| 542 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 543 | |
| 544 | if (symbol_vendor) |
| 545 | { |
| 546 | SymbolContext null_sc; |
| 547 | |
| 548 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 549 | |
| 550 | if (found_namespace_decl) |
| 551 | { |
| 552 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 553 | |
| 554 | if (log) |
| 555 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 556 | current_id, |
| 557 | name.GetCString(), |
| 558 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | else |
| 563 | { |
| 564 | ModuleList &images = m_target->GetImages(); |
| 565 | |
| 566 | for (uint32_t i = 0, e = images.GetSize(); |
| 567 | i != e; |
| 568 | ++i) |
| 569 | { |
| 570 | lldb::ModuleSP image = images.GetModuleAtIndex(i); |
| 571 | |
| 572 | if (!image) |
| 573 | continue; |
| 574 | |
| 575 | ClangNamespaceDecl found_namespace_decl; |
| 576 | |
| 577 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 578 | |
| 579 | if (!symbol_vendor) |
| 580 | continue; |
| 581 | |
| 582 | SymbolContext null_sc; |
| 583 | |
| 584 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 585 | |
| 586 | if (found_namespace_decl) |
| 587 | { |
| 588 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 589 | |
| 590 | if (log) |
| 591 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 592 | current_id, |
| 593 | name.GetCString(), |
| 594 | image->GetFileSpec().GetFilename().GetCString()); |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 599 | do |
| 600 | { |
| 601 | TypeList types; |
| 602 | SymbolContext null_sc; |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 603 | const bool exact_match = false; |
Sean Callanan | 0f71d19 | 2011-12-19 19:38:39 +0000 | [diff] [blame] | 604 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 605 | if (module_sp && namespace_decl) |
Greg Clayton | dc0a38c | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 606 | module_sp->FindTypesInNamespace(null_sc, name, &namespace_decl, 1, types); |
Sean Callanan | 0f71d19 | 2011-12-19 19:38:39 +0000 | [diff] [blame] | 607 | else |
Greg Clayton | 9f95fb6 | 2012-04-06 17:41:13 +0000 | [diff] [blame] | 608 | m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, types); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 609 | |
| 610 | if (types.GetSize()) |
| 611 | { |
| 612 | lldb::TypeSP type_sp = types.GetTypeAtIndex(0); |
| 613 | |
| 614 | if (log) |
| 615 | { |
| 616 | const char *name_string = type_sp->GetName().GetCString(); |
| 617 | |
| 618 | log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s", |
| 619 | current_id, |
| 620 | name.GetCString(), |
| 621 | (name_string ? name_string : "<anonymous>")); |
| 622 | } |
| 623 | |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 624 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 625 | 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] | 626 | |
Sean Callanan | dc5fce1 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 627 | if (!copied_type) |
| 628 | { |
| 629 | if (log) |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 630 | log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result", |
| 631 | current_id); |
| 632 | |
Sean Callanan | dc5fce1 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 633 | break; |
| 634 | } |
| 635 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 636 | context.AddTypeDecl(copied_type); |
| 637 | } |
Sean Callanan | 673f3db | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 638 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 639 | } while(0); |
| 640 | } |
| 641 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 642 | void |
| 643 | ClangASTSource::FindObjCMethodDecls (NameSearchContext &context) |
| 644 | { |
| 645 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 646 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 647 | static unsigned int invocation_id = 0; |
| 648 | unsigned int current_id = invocation_id++; |
| 649 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 650 | const DeclarationName &decl_name(context.m_decl_name); |
| 651 | const DeclContext *decl_ctx(context.m_decl_context); |
| 652 | |
| 653 | const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx); |
| 654 | |
| 655 | if (!interface_decl) |
| 656 | return; |
| 657 | |
Sean Callanan | 8d61156 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 658 | do |
| 659 | { |
| 660 | Decl *original_decl = NULL; |
| 661 | ASTContext *original_ctx = NULL; |
| 662 | |
| 663 | m_ast_importer->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx); |
| 664 | |
| 665 | if (!original_decl) |
| 666 | break; |
| 667 | |
| 668 | ObjCInterfaceDecl *original_interface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl); |
| 669 | |
| 670 | Selector original_selector; |
| 671 | |
| 672 | if (decl_name.isObjCZeroArgSelector()) |
| 673 | { |
| 674 | IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString()); |
| 675 | original_selector = original_ctx->Selectors.getSelector(0, &ident); |
| 676 | } |
| 677 | else if (decl_name.isObjCOneArgSelector()) |
| 678 | { |
| 679 | const std::string &decl_name_string = decl_name.getAsString(); |
| 680 | std::string decl_name_string_without_colon(decl_name_string.c_str(), decl_name_string.length() - 1); |
| 681 | IdentifierInfo *ident = &original_ctx->Idents.get(decl_name_string_without_colon.c_str()); |
| 682 | original_selector = original_ctx->Selectors.getSelector(1, &ident); |
| 683 | } |
| 684 | else |
| 685 | { |
| 686 | SmallVector<IdentifierInfo *, 4> idents; |
| 687 | |
| 688 | clang::Selector sel = decl_name.getObjCSelector(); |
| 689 | |
| 690 | int num_args = sel.getNumArgs(); |
| 691 | |
| 692 | for (unsigned i = 0; |
| 693 | i != num_args; |
| 694 | ++i) |
| 695 | { |
| 696 | idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i))); |
| 697 | } |
| 698 | |
| 699 | original_selector = original_ctx->Selectors.getSelector(num_args, idents.data()); |
| 700 | } |
| 701 | |
| 702 | DeclarationName original_decl_name(original_selector); |
| 703 | |
| 704 | ObjCInterfaceDecl::lookup_result result = original_interface_decl->lookup(original_decl_name); |
| 705 | |
| 706 | if (result.first == result.second) |
| 707 | break; |
| 708 | |
| 709 | if (!*result.first) |
| 710 | break; |
| 711 | |
| 712 | ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(*result.first); |
| 713 | |
| 714 | if (!result_method) |
| 715 | break; |
| 716 | |
| 717 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &result_method->getASTContext(), result_method); |
| 718 | |
| 719 | if (!copied_decl) |
| 720 | continue; |
| 721 | |
| 722 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); |
| 723 | |
| 724 | if (!copied_method_decl) |
| 725 | continue; |
| 726 | |
| 727 | if (log) |
| 728 | { |
| 729 | ASTDumper dumper((Decl*)copied_method_decl); |
| 730 | log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString()); |
| 731 | } |
| 732 | |
| 733 | context.AddNamedDecl(copied_method_decl); |
| 734 | |
| 735 | return; |
| 736 | } while (0); |
| 737 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 738 | StreamString ss; |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 739 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 740 | if (decl_name.isObjCZeroArgSelector()) |
| 741 | { |
| 742 | ss.Printf("%s", decl_name.getAsString().c_str()); |
| 743 | } |
| 744 | else if (decl_name.isObjCOneArgSelector()) |
| 745 | { |
Sean Callanan | 1d9ffe2 | 2011-11-14 18:29:46 +0000 | [diff] [blame] | 746 | ss.Printf("%s", decl_name.getAsString().c_str()); |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 747 | } |
| 748 | else |
| 749 | { |
| 750 | clang::Selector sel = decl_name.getObjCSelector(); |
| 751 | |
| 752 | for (unsigned i = 0, e = sel.getNumArgs(); |
| 753 | i != e; |
| 754 | ++i) |
| 755 | { |
| 756 | llvm::StringRef r = sel.getNameForSlot(i); |
| 757 | ss.Printf("%s:", r.str().c_str()); |
| 758 | } |
| 759 | } |
| 760 | ss.Flush(); |
| 761 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 762 | ConstString selector_name(ss.GetData()); |
| 763 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 764 | if (log) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 765 | log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]", |
| 766 | current_id, |
| 767 | m_ast_context, |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 768 | interface_decl->getNameAsString().c_str(), |
| 769 | selector_name.AsCString()); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 770 | SymbolContextList sc_list; |
| 771 | |
| 772 | const bool include_symbols = false; |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 773 | const bool include_inlines = false; |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 774 | const bool append = false; |
| 775 | |
Sean Callanan | e0028b8 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 776 | std::string interface_name = interface_decl->getNameAsString(); |
| 777 | |
| 778 | do |
| 779 | { |
| 780 | StreamString ms; |
| 781 | ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString()); |
| 782 | ms.Flush(); |
| 783 | ConstString instance_method_name(ms.GetData()); |
| 784 | |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 785 | m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); |
Sean Callanan | e0028b8 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 786 | |
| 787 | if (sc_list.GetSize()) |
| 788 | break; |
| 789 | |
| 790 | ms.Clear(); |
| 791 | ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString()); |
| 792 | ms.Flush(); |
| 793 | ConstString class_method_name(ms.GetData()); |
| 794 | |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 795 | m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); |
Sean Callanan | e0028b8 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 796 | |
| 797 | if (sc_list.GetSize()) |
| 798 | break; |
| 799 | |
| 800 | // Fall back and check for methods in categories. If we find methods this way, we need to check that they're actually in |
| 801 | // categories on the desired class. |
| 802 | |
| 803 | SymbolContextList candidate_sc_list; |
| 804 | |
Sean Callanan | 302d78c | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 805 | m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list); |
Sean Callanan | e0028b8 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 806 | |
| 807 | for (uint32_t ci = 0, ce = candidate_sc_list.GetSize(); |
| 808 | ci != ce; |
| 809 | ++ci) |
| 810 | { |
| 811 | SymbolContext candidate_sc; |
| 812 | |
| 813 | if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc)) |
| 814 | continue; |
| 815 | |
| 816 | if (!candidate_sc.function) |
| 817 | continue; |
| 818 | |
| 819 | const char *candidate_name = candidate_sc.function->GetName().AsCString(); |
| 820 | |
| 821 | const char *cursor = candidate_name; |
| 822 | |
| 823 | if (*cursor != '+' && *cursor != '-') |
| 824 | continue; |
| 825 | |
| 826 | ++cursor; |
| 827 | |
| 828 | if (*cursor != '[') |
| 829 | continue; |
| 830 | |
| 831 | ++cursor; |
| 832 | |
| 833 | size_t interface_len = interface_name.length(); |
| 834 | |
| 835 | if (strncmp(cursor, interface_name.c_str(), interface_len)) |
| 836 | continue; |
| 837 | |
| 838 | cursor += interface_len; |
| 839 | |
| 840 | if (*cursor == ' ' || *cursor == '(') |
| 841 | sc_list.Append(candidate_sc); |
| 842 | } |
| 843 | } |
| 844 | while (0); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 845 | |
| 846 | for (uint32_t i = 0, e = sc_list.GetSize(); |
| 847 | i != e; |
| 848 | ++i) |
| 849 | { |
| 850 | SymbolContext sc; |
| 851 | |
| 852 | if (!sc_list.GetContextAtIndex(i, sc)) |
| 853 | continue; |
| 854 | |
| 855 | if (!sc.function) |
| 856 | continue; |
| 857 | |
| 858 | DeclContext *function_ctx = sc.function->GetClangDeclContext(); |
| 859 | |
| 860 | if (!function_ctx) |
| 861 | continue; |
| 862 | |
| 863 | ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx); |
| 864 | |
| 865 | if (!method_decl) |
| 866 | continue; |
| 867 | |
| 868 | ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface(); |
| 869 | |
| 870 | if (!found_interface_decl) |
| 871 | continue; |
| 872 | |
| 873 | if (found_interface_decl->getName() == interface_decl->getName()) |
| 874 | { |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 875 | 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] | 876 | |
| 877 | if (!copied_decl) |
| 878 | continue; |
| 879 | |
| 880 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); |
| 881 | |
| 882 | if (!copied_method_decl) |
| 883 | continue; |
| 884 | |
| 885 | if (log) |
| 886 | { |
| 887 | ASTDumper dumper((Decl*)copied_method_decl); |
Sean Callanan | e1301a6 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 888 | 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] | 889 | } |
Sean Callanan | e0028b8 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 890 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 891 | context.AddNamedDecl(copied_method_decl); |
| 892 | } |
| 893 | } |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 896 | template <class D> class TaggedASTDecl { |
| 897 | public: |
| 898 | TaggedASTDecl() : decl(NULL) { } |
| 899 | TaggedASTDecl(D *_decl) : decl(_decl) { } |
| 900 | bool IsValid() const { return (decl != NULL); } |
| 901 | bool IsInvalid() const { return !IsValid(); } |
| 902 | D *operator->() const { return decl; } |
| 903 | D *decl; |
| 904 | }; |
| 905 | |
| 906 | template <class D2, template <class D> class TD, class D1> |
| 907 | TD<D2> |
| 908 | DynCast(TD<D1> source) |
| 909 | { |
| 910 | return TD<D2> (dyn_cast<D2>(source.decl)); |
| 911 | } |
| 912 | |
| 913 | template <class D = Decl> class DeclFromParser; |
| 914 | template <class D = Decl> class DeclFromUser; |
| 915 | |
| 916 | template <class D> class DeclFromParser : public TaggedASTDecl<D> { |
| 917 | public: |
| 918 | DeclFromParser() : TaggedASTDecl<D>() { } |
| 919 | DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) { } |
| 920 | |
| 921 | DeclFromUser<D> GetOrigin(ClangASTImporter *importer); |
| 922 | }; |
| 923 | |
| 924 | template <class D> class DeclFromUser : public TaggedASTDecl<D> { |
| 925 | public: |
| 926 | DeclFromUser() : TaggedASTDecl<D>() { } |
| 927 | DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) { } |
| 928 | |
| 929 | DeclFromParser<D> Import(ClangASTImporter *importer, ASTContext &dest_ctx); |
| 930 | }; |
| 931 | |
| 932 | template <class D> |
| 933 | DeclFromUser<D> |
| 934 | DeclFromParser<D>::GetOrigin(ClangASTImporter *importer) |
| 935 | { |
| 936 | DeclFromUser <> origin_decl; |
| 937 | importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL); |
| 938 | if (origin_decl.IsInvalid()) |
| 939 | return DeclFromUser<D>(); |
| 940 | return DeclFromUser<D>(dyn_cast<D>(origin_decl.decl)); |
| 941 | } |
| 942 | |
| 943 | template <class D> |
| 944 | DeclFromParser<D> |
| 945 | DeclFromUser<D>::Import(ClangASTImporter *importer, ASTContext &dest_ctx) |
| 946 | { |
| 947 | DeclFromParser <> parser_generic_decl(importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl)); |
| 948 | if (parser_generic_decl.IsInvalid()) |
| 949 | return DeclFromParser<D>(); |
| 950 | return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl)); |
| 951 | } |
| 952 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 953 | static bool |
| 954 | FindObjCPropertyAndIvarDeclsWithOrigin (unsigned int current_id, |
| 955 | NameSearchContext &context, |
| 956 | clang::ASTContext &ast_context, |
| 957 | ClangASTImporter *ast_importer, |
| 958 | DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl) |
| 959 | { |
| 960 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 961 | |
| 962 | if (origin_iface_decl.IsInvalid()) |
| 963 | return false; |
| 964 | |
| 965 | std::string name_str = context.m_decl_name.getAsString(); |
| 966 | StringRef name(name_str.c_str()); |
| 967 | IdentifierInfo &name_identifier(origin_iface_decl->getASTContext().Idents.get(name)); |
| 968 | |
| 969 | DeclFromUser<ObjCPropertyDecl> origin_property_decl(origin_iface_decl->FindPropertyDeclaration(&name_identifier)); |
| 970 | |
| 971 | bool found = false; |
| 972 | |
| 973 | if (origin_property_decl.IsValid()) |
| 974 | { |
| 975 | DeclFromParser<ObjCPropertyDecl> parser_property_decl(origin_property_decl.Import(ast_importer, ast_context)); |
| 976 | if (parser_property_decl.IsValid()) |
| 977 | { |
| 978 | if (log) |
| 979 | { |
| 980 | ASTDumper dumper((Decl*)parser_property_decl.decl); |
| 981 | log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); |
| 982 | } |
| 983 | |
| 984 | context.AddNamedDecl(parser_property_decl.decl); |
| 985 | found = true; |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | DeclFromUser<ObjCIvarDecl> origin_ivar_decl(origin_iface_decl->getIvarDecl(&name_identifier)); |
| 990 | |
| 991 | if (origin_ivar_decl.IsValid()) |
| 992 | { |
| 993 | DeclFromParser<ObjCIvarDecl> parser_ivar_decl(origin_ivar_decl.Import(ast_importer, ast_context)); |
| 994 | if (parser_ivar_decl.IsValid()) |
| 995 | { |
| 996 | if (log) |
| 997 | { |
| 998 | ASTDumper dumper((Decl*)parser_ivar_decl.decl); |
| 999 | log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); |
| 1000 | } |
| 1001 | |
| 1002 | context.AddNamedDecl(parser_ivar_decl.decl); |
| 1003 | found = true; |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | return found; |
| 1008 | } |
| 1009 | |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1010 | void |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1011 | ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context) |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1012 | { |
| 1013 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1014 | |
| 1015 | static unsigned int invocation_id = 0; |
| 1016 | unsigned int current_id = invocation_id++; |
| 1017 | |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1018 | DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl(cast<ObjCInterfaceDecl>(context.m_decl_context)); |
| 1019 | DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl(parser_iface_decl.GetOrigin(m_ast_importer)); |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1020 | |
| 1021 | ConstString class_name(parser_iface_decl->getNameAsString().c_str()); |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1022 | |
| 1023 | if (log) |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1024 | log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on (ASTContext*)%p for '%s.%s'", |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1025 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1026 | m_ast_context, |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1027 | parser_iface_decl->getNameAsString().c_str(), |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1028 | context.m_decl_name.getAsString().c_str()); |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1029 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1030 | if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id, |
| 1031 | context, |
| 1032 | *m_ast_context, |
| 1033 | m_ast_importer, |
| 1034 | origin_iface_decl)) |
| 1035 | return; |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1036 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1037 | if (log) |
| 1038 | log->Printf("CAS::FOPD[%d] couldn't find the property on origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p, searching elsewhere...", |
| 1039 | current_id, |
| 1040 | origin_iface_decl.decl, |
| 1041 | &origin_iface_decl->getASTContext()); |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1042 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1043 | SymbolContext null_sc; |
| 1044 | TypeList type_list; |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1045 | |
Sean Callanan | 931acec | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1046 | lldb::ProcessSP process(m_target->GetProcessSP()); |
| 1047 | |
| 1048 | if (!process) |
| 1049 | return; |
| 1050 | |
| 1051 | ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime()); |
| 1052 | |
| 1053 | if (!language_runtime) |
| 1054 | return; |
| 1055 | |
| 1056 | lldb::TypeSP complete_type_sp(language_runtime->LookupInCompleteClassCache(class_name)); |
| 1057 | |
| 1058 | if (!complete_type_sp) |
| 1059 | return; |
| 1060 | |
| 1061 | TypeFromUser complete_type = TypeFromUser(complete_type_sp->GetClangFullType(), complete_type_sp->GetClangAST()); |
| 1062 | lldb::clang_type_t complete_opaque_type = complete_type.GetOpaqueQualType(); |
| 1063 | |
| 1064 | if (!complete_opaque_type) |
| 1065 | return; |
| 1066 | |
| 1067 | const clang::Type *complete_clang_type = QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr(); |
| 1068 | const ObjCInterfaceType *complete_interface_type = dyn_cast<ObjCInterfaceType>(complete_clang_type); |
| 1069 | |
| 1070 | if (!complete_interface_type) |
| 1071 | return; |
| 1072 | |
| 1073 | DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_type->getDecl()); |
| 1074 | |
| 1075 | if (complete_iface_decl.decl == origin_iface_decl.decl) |
| 1076 | return; // already checked this one |
| 1077 | |
| 1078 | if (log) |
| 1079 | log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...", |
| 1080 | current_id, |
| 1081 | complete_iface_decl.decl, |
| 1082 | &complete_iface_decl->getASTContext()); |
| 1083 | |
| 1084 | |
| 1085 | if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id, |
| 1086 | context, |
| 1087 | *m_ast_context, |
| 1088 | m_ast_importer, |
| 1089 | complete_iface_decl)) |
| 1090 | return; |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | typedef llvm::DenseMap <const FieldDecl *, uint64_t> FieldOffsetMap; |
| 1094 | typedef llvm::DenseMap <const CXXRecordDecl *, CharUnits> BaseOffsetMap; |
| 1095 | |
| 1096 | template <class D, class O> |
| 1097 | static bool |
| 1098 | ImportOffsetMap (llvm::DenseMap <const D*, O> &destination_map, |
| 1099 | llvm::DenseMap <const D*, O> &source_map, |
| 1100 | ClangASTImporter *importer, |
| 1101 | ASTContext &dest_ctx) |
| 1102 | { |
| 1103 | typedef llvm::DenseMap <const D*, O> MapType; |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1104 | |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1105 | for (typename MapType::iterator fi = source_map.begin(), fe = source_map.end(); |
| 1106 | fi != fe; |
| 1107 | ++fi) |
| 1108 | { |
| 1109 | DeclFromUser <D> user_decl(const_cast<D*>(fi->first)); |
| 1110 | DeclFromParser <D> parser_decl(user_decl.Import(importer, dest_ctx)); |
| 1111 | if (parser_decl.IsInvalid()) |
| 1112 | return false; |
| 1113 | destination_map.insert(std::pair<const D *, O>(parser_decl.decl, fi->second)); |
| 1114 | } |
| 1115 | |
| 1116 | return true; |
| 1117 | } |
| 1118 | |
| 1119 | template <bool IsVirtual> bool ExtractBaseOffsets (const ASTRecordLayout &record_layout, |
| 1120 | DeclFromUser<const CXXRecordDecl> &record, |
| 1121 | BaseOffsetMap &base_offsets) |
| 1122 | { |
| 1123 | for (CXXRecordDecl::base_class_const_iterator |
| 1124 | bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()), |
| 1125 | be = (IsVirtual ? record->vbases_end() : record->bases_end()); |
| 1126 | bi != be; |
| 1127 | ++bi) |
| 1128 | { |
| 1129 | if (!IsVirtual && bi->isVirtual()) |
| 1130 | continue; |
| 1131 | |
| 1132 | const clang::Type *origin_base_type = bi->getType().getTypePtr(); |
| 1133 | const clang::RecordType *origin_base_record_type = origin_base_type->getAs<RecordType>(); |
| 1134 | |
| 1135 | if (!origin_base_record_type) |
| 1136 | return false; |
| 1137 | |
| 1138 | DeclFromUser <RecordDecl> origin_base_record(origin_base_record_type->getDecl()); |
| 1139 | |
| 1140 | if (origin_base_record.IsInvalid()) |
| 1141 | return false; |
| 1142 | |
| 1143 | DeclFromUser <CXXRecordDecl> origin_base_cxx_record(DynCast<CXXRecordDecl>(origin_base_record)); |
| 1144 | |
| 1145 | if (origin_base_cxx_record.IsInvalid()) |
| 1146 | return false; |
| 1147 | |
| 1148 | CharUnits base_offset; |
| 1149 | |
| 1150 | if (IsVirtual) |
| 1151 | base_offset = record_layout.getVBaseClassOffset(origin_base_cxx_record.decl); |
| 1152 | else |
| 1153 | base_offset = record_layout.getBaseClassOffset(origin_base_cxx_record.decl); |
| 1154 | |
| 1155 | base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>(origin_base_cxx_record.decl, base_offset)); |
| 1156 | } |
| 1157 | |
| 1158 | return true; |
| 1159 | } |
| 1160 | |
| 1161 | bool |
| 1162 | ClangASTSource::layoutRecordType(const RecordDecl *record, |
| 1163 | uint64_t &size, |
| 1164 | uint64_t &alignment, |
| 1165 | FieldOffsetMap &field_offsets, |
| 1166 | BaseOffsetMap &base_offsets, |
| 1167 | BaseOffsetMap &virtual_base_offsets) |
| 1168 | { |
| 1169 | static unsigned int invocation_id = 0; |
| 1170 | unsigned int current_id = invocation_id++; |
| 1171 | |
| 1172 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1173 | |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1174 | if (log) |
| 1175 | { |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1176 | log->Printf("LayoutRecordType[%u] on (RecordDecl*)%p [name = '%s']", |
| 1177 | current_id, |
| 1178 | m_ast_context, |
| 1179 | record->getNameAsString().c_str()); |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1180 | } |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1181 | |
| 1182 | |
| 1183 | DeclFromParser <const RecordDecl> parser_record(record); |
| 1184 | DeclFromUser <const RecordDecl> origin_record(parser_record.GetOrigin(m_ast_importer)); |
| 1185 | |
| 1186 | if (origin_record.IsInvalid()) |
| 1187 | return false; |
| 1188 | |
| 1189 | FieldOffsetMap origin_field_offsets; |
| 1190 | BaseOffsetMap origin_base_offsets; |
| 1191 | BaseOffsetMap origin_virtual_base_offsets; |
| 1192 | |
Sean Callanan | 33bff9a | 2012-04-07 00:06:00 +0000 | [diff] [blame] | 1193 | ClangASTContext::GetCompleteDecl(&origin_record->getASTContext(), const_cast<RecordDecl*>(origin_record.decl)); |
| 1194 | |
| 1195 | if (!origin_record.decl->getDefinition()) |
| 1196 | return false; |
| 1197 | |
Sean Callanan | 8f2e392 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1198 | const ASTRecordLayout &record_layout(origin_record->getASTContext().getASTRecordLayout(origin_record.decl)); |
| 1199 | |
| 1200 | int field_idx = 0; |
| 1201 | |
| 1202 | for (RecordDecl::field_iterator fi = origin_record->field_begin(), fe = origin_record->field_end(); |
| 1203 | fi != fe; |
| 1204 | ++fi) |
| 1205 | { |
| 1206 | uint64_t field_offset = record_layout.getFieldOffset(field_idx); |
| 1207 | |
| 1208 | origin_field_offsets.insert(std::pair<const FieldDecl *, uint64_t>(*fi, field_offset)); |
| 1209 | |
| 1210 | field_idx++; |
| 1211 | } |
| 1212 | |
| 1213 | ASTContext &parser_ast_context(record->getASTContext()); |
| 1214 | |
| 1215 | DeclFromUser <const CXXRecordDecl> origin_cxx_record(DynCast<const CXXRecordDecl>(origin_record)); |
| 1216 | |
| 1217 | if (origin_cxx_record.IsValid()) |
| 1218 | { |
| 1219 | if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record, origin_base_offsets) || |
| 1220 | !ExtractBaseOffsets<true>(record_layout, origin_cxx_record, origin_virtual_base_offsets)) |
| 1221 | return false; |
| 1222 | } |
| 1223 | |
| 1224 | if (!ImportOffsetMap(field_offsets, origin_field_offsets, m_ast_importer, parser_ast_context) || |
| 1225 | !ImportOffsetMap(base_offsets, origin_base_offsets, m_ast_importer, parser_ast_context) || |
| 1226 | !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, m_ast_importer, parser_ast_context)) |
| 1227 | return false; |
| 1228 | |
| 1229 | size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth(); |
| 1230 | alignment = record_layout.getAlignment().getQuantity() * m_ast_context->getCharWidth(); |
| 1231 | |
| 1232 | if (log) |
| 1233 | { |
| 1234 | log->Printf("LRT[%u] returned:", current_id); |
| 1235 | log->Printf("LRT[%u] Original = (RecordDecl*)%p", current_id, origin_record.decl); |
| 1236 | log->Printf("LRT[%u] Size = %lld", current_id, size); |
| 1237 | log->Printf("LRT[%u] Alignment = %lld", current_id, alignment); |
| 1238 | log->Printf("LRT[%u] Fields:", current_id); |
| 1239 | for (RecordDecl::field_iterator fi = record->field_begin(), fe = record->field_end(); |
| 1240 | fi != fe; |
| 1241 | ++fi) |
| 1242 | { |
| 1243 | log->Printf("LRT[%u] (FieldDecl*)%p, Name = '%s', Offset = %lld bits", |
| 1244 | current_id, |
| 1245 | *fi, |
| 1246 | fi->getNameAsString().c_str(), |
| 1247 | field_offsets[*fi]); |
| 1248 | } |
| 1249 | DeclFromParser <const CXXRecordDecl> parser_cxx_record = DynCast<const CXXRecordDecl>(parser_record); |
| 1250 | if (parser_cxx_record.IsValid()) |
| 1251 | { |
| 1252 | log->Printf("LRT[%u] Bases:", current_id); |
| 1253 | for (CXXRecordDecl::base_class_const_iterator bi = parser_cxx_record->bases_begin(), be = parser_cxx_record->bases_end(); |
| 1254 | bi != be; |
| 1255 | ++bi) |
| 1256 | { |
| 1257 | bool is_virtual = bi->isVirtual(); |
| 1258 | |
| 1259 | QualType base_type = bi->getType(); |
| 1260 | const RecordType *base_record_type = base_type->getAs<RecordType>(); |
| 1261 | DeclFromParser <RecordDecl> base_record(base_record_type->getDecl()); |
| 1262 | DeclFromParser <CXXRecordDecl> base_cxx_record = DynCast<CXXRecordDecl>(base_record); |
| 1263 | |
| 1264 | log->Printf("LRT[%u] %s(CXXRecordDecl*)%p, Name = '%s', Offset = %lld chars", |
| 1265 | current_id, |
| 1266 | (is_virtual ? "Virtual " : ""), |
| 1267 | base_cxx_record.decl, |
| 1268 | base_cxx_record.decl->getNameAsString().c_str(), |
| 1269 | (is_virtual ? virtual_base_offsets[base_cxx_record.decl].getQuantity() : |
| 1270 | base_offsets[base_cxx_record.decl].getQuantity())); |
| 1271 | } |
| 1272 | } |
| 1273 | else |
| 1274 | { |
| 1275 | log->Printf("LRD[%u] Not a CXXRecord, so no bases", current_id); |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1279 | return true; |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1282 | void |
| 1283 | ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, |
| 1284 | const ConstString &name, |
| 1285 | ClangASTImporter::NamespaceMapSP &parent_map) const |
| 1286 | { |
| 1287 | static unsigned int invocation_id = 0; |
| 1288 | unsigned int current_id = invocation_id++; |
| 1289 | |
| 1290 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1291 | |
| 1292 | if (log) |
| 1293 | { |
| 1294 | if (parent_map && parent_map->size()) |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1295 | 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] | 1296 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1297 | m_ast_context, |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1298 | name.GetCString(), |
| 1299 | parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str()); |
| 1300 | else |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1301 | log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s", |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1302 | current_id, |
Sean Callanan | 5a55c7a | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1303 | m_ast_context, |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1304 | name.GetCString()); |
| 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | if (parent_map) |
| 1309 | { |
| 1310 | for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end(); |
| 1311 | i != e; |
| 1312 | ++i) |
| 1313 | { |
| 1314 | ClangNamespaceDecl found_namespace_decl; |
| 1315 | |
| 1316 | lldb::ModuleSP module_sp = i->first; |
| 1317 | ClangNamespaceDecl module_parent_namespace_decl = i->second; |
| 1318 | |
| 1319 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 1320 | |
| 1321 | if (!symbol_vendor) |
| 1322 | continue; |
| 1323 | |
| 1324 | SymbolContext null_sc; |
| 1325 | |
| 1326 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl); |
| 1327 | |
| 1328 | if (!found_namespace_decl) |
| 1329 | continue; |
| 1330 | |
| 1331 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 1332 | |
| 1333 | if (log) |
| 1334 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 1335 | current_id, |
| 1336 | name.GetCString(), |
| 1337 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 1338 | } |
| 1339 | } |
| 1340 | else |
| 1341 | { |
| 1342 | ModuleList &images = m_target->GetImages(); |
| 1343 | ClangNamespaceDecl null_namespace_decl; |
| 1344 | |
| 1345 | for (uint32_t i = 0, e = images.GetSize(); |
| 1346 | i != e; |
| 1347 | ++i) |
| 1348 | { |
| 1349 | lldb::ModuleSP image = images.GetModuleAtIndex(i); |
| 1350 | |
| 1351 | if (!image) |
| 1352 | continue; |
| 1353 | |
| 1354 | ClangNamespaceDecl found_namespace_decl; |
| 1355 | |
| 1356 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 1357 | |
| 1358 | if (!symbol_vendor) |
| 1359 | continue; |
| 1360 | |
| 1361 | SymbolContext null_sc; |
| 1362 | |
| 1363 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl); |
| 1364 | |
| 1365 | if (!found_namespace_decl) |
| 1366 | continue; |
| 1367 | |
| 1368 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 1369 | |
| 1370 | if (log) |
| 1371 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 1372 | current_id, |
| 1373 | name.GetCString(), |
| 1374 | image->GetFileSpec().GetFilename().GetCString()); |
| 1375 | } |
| 1376 | } |
| 1377 | } |
| 1378 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1379 | NamespaceDecl * |
| 1380 | ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls) |
| 1381 | { |
Greg Clayton | 13d24fb | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1382 | if (!namespace_decls) |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1383 | return NULL; |
| 1384 | |
| 1385 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1386 | |
| 1387 | const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; |
| 1388 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1389 | 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] | 1390 | |
Sean Callanan | ddb5933 | 2012-03-20 21:11:12 +0000 | [diff] [blame] | 1391 | if (!copied_decl) |
| 1392 | return NULL; |
| 1393 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1394 | NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); |
| 1395 | |
| 1396 | m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); |
| 1397 | |
| 1398 | return dyn_cast<NamespaceDecl>(copied_decl); |
| 1399 | } |
| 1400 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1401 | void * |
| 1402 | ClangASTSource::GuardedCopyType (ASTContext *dest_context, |
| 1403 | ASTContext *source_context, |
| 1404 | void *clang_type) |
| 1405 | { |
| 1406 | SetImportInProgress(true); |
| 1407 | |
Sean Callanan | 4938bd6 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1408 | 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] | 1409 | |
| 1410 | void *ret = ret_qual_type.getAsOpaquePtr(); |
| 1411 | |
| 1412 | SetImportInProgress(false); |
| 1413 | |
Sean Callanan | ddb5933 | 2012-03-20 21:11:12 +0000 | [diff] [blame] | 1414 | if (ret && ret_qual_type->getCanonicalTypeInternal().isNull()) |
Sean Callanan | aa11af8 | 2012-02-27 19:22:39 +0000 | [diff] [blame] | 1415 | // this shouldn't happen, but we're hardening because the AST importer seems to be generating bad types |
| 1416 | // on occasion. |
| 1417 | return NULL; |
| 1418 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1419 | return ret; |
| 1420 | } |
| 1421 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1422 | clang::NamedDecl * |
| 1423 | NameSearchContext::AddVarDecl(void *type) |
| 1424 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1425 | IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo(); |
Sean Callanan | 1ddd9fe | 2010-11-30 00:27:43 +0000 | [diff] [blame] | 1426 | |
| 1427 | assert (type && "Type for variable must be non-NULL!"); |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 1428 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1429 | clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1430 | const_cast<DeclContext*>(m_decl_context), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1431 | SourceLocation(), |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1432 | SourceLocation(), |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 1433 | ii, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1434 | QualType::getFromOpaquePtr(type), |
| 1435 | 0, |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 1436 | SC_Static, |
| 1437 | SC_Static); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1438 | m_decls.push_back(Decl); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1439 | |
| 1440 | return Decl; |
| 1441 | } |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1442 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1443 | clang::NamedDecl * |
| 1444 | NameSearchContext::AddFunDecl (void *type) |
| 1445 | { |
Sean Callanan | 30a5dd5 | 2012-03-21 17:13:20 +0000 | [diff] [blame] | 1446 | assert (type && "Type for variable must be non-NULL!"); |
| 1447 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1448 | clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1449 | const_cast<DeclContext*>(m_decl_context), |
| 1450 | SourceLocation(), |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1451 | SourceLocation(), |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1452 | m_decl_name.getAsIdentifierInfo(), |
| 1453 | QualType::getFromOpaquePtr(type), |
| 1454 | NULL, |
| 1455 | SC_Static, |
| 1456 | SC_Static, |
| 1457 | false, |
| 1458 | true); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1459 | |
Sean Callanan | b291abe | 2010-08-12 23:45:38 +0000 | [diff] [blame] | 1460 | // We have to do more than just synthesize the FunctionDecl. We have to |
| 1461 | // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do |
| 1462 | // this, we raid the function's FunctionProtoType for types. |
| 1463 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1464 | QualType qual_type (QualType::getFromOpaquePtr(type)); |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1465 | const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>(); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1466 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1467 | if (func_proto_type) |
Sean Callanan | 3c821cc | 2010-06-23 18:58:10 +0000 | [diff] [blame] | 1468 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1469 | unsigned NumArgs = func_proto_type->getNumArgs(); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1470 | unsigned ArgIndex; |
| 1471 | |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1472 | SmallVector<ParmVarDecl *, 5> parm_var_decls; |
| 1473 | |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1474 | for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex) |
| 1475 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1476 | QualType arg_qual_type (func_proto_type->getArgType(ArgIndex)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1477 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1478 | 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] | 1479 | const_cast<DeclContext*>(m_decl_context), |
| 1480 | SourceLocation(), |
| 1481 | SourceLocation(), |
| 1482 | NULL, |
| 1483 | arg_qual_type, |
| 1484 | NULL, |
| 1485 | SC_Static, |
| 1486 | SC_Static, |
| 1487 | NULL)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1490 | func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1491 | } |
Sean Callanan | dc5fce1 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 1492 | else |
| 1493 | { |
| 1494 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 1495 | |
| 1496 | log->Printf("Function type wasn't a FunctionProtoType"); |
| 1497 | } |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1498 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1499 | m_decls.push_back(func_decl); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1500 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1501 | return func_decl; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1502 | } |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1503 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1504 | clang::NamedDecl * |
| 1505 | NameSearchContext::AddGenericFunDecl() |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1506 | { |
Sean Callanan | ad29309 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1507 | FunctionProtoType::ExtProtoInfo proto_info; |
| 1508 | |
| 1509 | proto_info.Variadic = true; |
| 1510 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1511 | QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result |
| 1512 | NULL, // argument types |
| 1513 | 0, // number of arguments |
| 1514 | proto_info)); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1515 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1516 | return AddFunDecl(generic_function_type.getAsOpaquePtr()); |
| 1517 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1518 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1519 | clang::NamedDecl * |
| 1520 | NameSearchContext::AddTypeDecl(void *type) |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1521 | { |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1522 | if (type) |
| 1523 | { |
| 1524 | QualType qual_type = QualType::getFromOpaquePtr(type); |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1525 | |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1526 | if (const TagType *tag_type = qual_type->getAs<TagType>()) |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1527 | { |
| 1528 | TagDecl *tag_decl = tag_type->getDecl(); |
| 1529 | |
| 1530 | m_decls.push_back(tag_decl); |
| 1531 | |
| 1532 | return tag_decl; |
| 1533 | } |
Sean Callanan | 21f2e19 | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1534 | else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>()) |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1535 | { |
| 1536 | ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface(); |
| 1537 | |
| 1538 | m_decls.push_back((NamedDecl*)interface_decl); |
| 1539 | |
| 1540 | return (NamedDecl*)interface_decl; |
| 1541 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1542 | } |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1543 | return NULL; |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1544 | } |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 1545 | |
| 1546 | void |
| 1547 | NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result) |
| 1548 | { |
| 1549 | for (clang::NamedDecl * const *decl_iterator = result.first; |
| 1550 | decl_iterator != result.second; |
| 1551 | ++decl_iterator) |
| 1552 | m_decls.push_back (*decl_iterator); |
| 1553 | } |
| 1554 | |
| 1555 | void |
| 1556 | NameSearchContext::AddNamedDecl (clang::NamedDecl *decl) |
| 1557 | { |
| 1558 | m_decls.push_back (decl); |
| 1559 | } |