Greg Clayton | ea3b0ae | 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 | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTContext.h" |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 12 | #include "clang/AST/RecordLayout.h" |
Greg Clayton | ee4b5dd | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Greg Clayton | 747bcb0 | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Module.h" |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 15 | #include "lldb/Core/ModuleList.h" |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 16 | #include "lldb/Expression/ASTDumper.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Expression/ClangASTSource.h" |
| 18 | #include "lldb/Expression/ClangExpression.h" |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 19 | #include "lldb/Symbol/ClangNamespaceDecl.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/Function.h" |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/SymbolVendor.h" |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 22 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace clang; |
| 26 | using namespace lldb_private; |
| 27 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 28 | ClangASTSource::~ClangASTSource() |
| 29 | { |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 30 | m_ast_importer->ForgetDestination(m_ast_context); |
| 31 | |
Johnny Chen | 60e2c6a | 2011-11-30 23:18:53 +0000 | [diff] [blame] | 32 | // We are in the process of destruction, don't create clang ast context on demand |
| 33 | // by passing false to Target::GetScratchClangASTContext(create_on_demand). |
| 34 | ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false); |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 35 | |
| 36 | if (!scratch_clang_ast_context) |
| 37 | return; |
| 38 | |
| 39 | clang::ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext(); |
| 40 | |
| 41 | if (!scratch_ast_context) |
| 42 | return; |
| 43 | |
| 44 | if (m_ast_context != scratch_ast_context) |
| 45 | m_ast_importer->ForgetSource(scratch_ast_context, m_ast_context); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 46 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 48 | void |
| 49 | ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) |
| 50 | { |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 51 | if (!m_ast_context) |
| 52 | return; |
| 53 | |
| 54 | m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 55 | m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | // The core lookup interface. |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 59 | bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 60 | ClangASTSource::FindExternalVisibleDeclsByName |
Greg Clayton | ee4b5dd | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 61 | ( |
| 62 | const DeclContext *decl_ctx, |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 63 | DeclarationName clang_decl_name |
Greg Clayton | ee4b5dd | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 64 | ) |
| 65 | { |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 66 | if (!m_ast_context) |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 67 | { |
| 68 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 69 | return false; |
| 70 | } |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 71 | |
| 72 | if (GetImportInProgress()) |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 73 | { |
| 74 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 75 | return false; |
| 76 | } |
| 77 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 78 | std::string decl_name (clang_decl_name.getAsString()); |
| 79 | |
| 80 | // if (m_decl_map.DoingASTImport ()) |
| 81 | // return DeclContext::lookup_result(); |
| 82 | // |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 83 | switch (clang_decl_name.getNameKind()) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | // Normal identifiers. |
| 85 | case DeclarationName::Identifier: |
Sean Callanan | e8dea98 | 2012-04-25 17:46:01 +0000 | [diff] [blame] | 86 | { |
| 87 | clang::IdentifierInfo *identifier_info = clang_decl_name.getAsIdentifierInfo(); |
| 88 | |
| 89 | if (!identifier_info || |
| 90 | identifier_info->getBuiltinID() != 0) |
| 91 | { |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 92 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 93 | return false; |
Sean Callanan | e8dea98 | 2012-04-25 17:46:01 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 96 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | |
| 98 | // Operator names. Not important for now. |
| 99 | case DeclarationName::CXXOperatorName: |
| 100 | case DeclarationName::CXXLiteralOperatorName: |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 101 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 102 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 103 | |
| 104 | // Using directives found in this context. |
| 105 | // Tell Sema we didn't find any or we'll end up getting asked a *lot*. |
| 106 | case DeclarationName::CXXUsingDirective: |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 107 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 108 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 110 | case DeclarationName::ObjCZeroArgSelector: |
| 111 | case DeclarationName::ObjCOneArgSelector: |
| 112 | case DeclarationName::ObjCMultiArgSelector: |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 113 | { |
| 114 | llvm::SmallVector<NamedDecl*, 1> method_decls; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 116 | NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx); |
| 117 | |
| 118 | FindObjCMethodDecls(method_search_context); |
| 119 | |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 120 | SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls); |
| 121 | return (method_decls.size() > 0); |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 122 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | // These aren't possible in the global context. |
| 124 | case DeclarationName::CXXConstructorName: |
| 125 | case DeclarationName::CXXDestructorName: |
| 126 | case DeclarationName::CXXConversionFunctionName: |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 127 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 128 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | } |
Greg Clayton | ee4b5dd | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 130 | |
Greg Clayton | ee4b5dd | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 131 | |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 132 | if (!GetLookupsEnabled()) |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 133 | { |
| 134 | // Wait until we see a '$' at the start of a name before we start doing |
| 135 | // any lookups so we can avoid lookup up all of the builtin types. |
| 136 | if (!decl_name.empty() && decl_name[0] == '$') |
| 137 | { |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 138 | SetLookupsEnabled (true); |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 139 | } |
| 140 | else |
| 141 | { |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 142 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 143 | return false; |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 144 | } |
Greg Clayton | ee4b5dd | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 145 | } |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 146 | |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 147 | ConstString const_decl_name(decl_name.c_str()); |
Greg Clayton | 580c5da | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 148 | |
| 149 | const char *uniqued_const_decl_name = const_decl_name.GetCString(); |
| 150 | if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end()) |
| 151 | { |
| 152 | // We are currently looking up this name... |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 153 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 154 | return false; |
Greg Clayton | 580c5da | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 155 | } |
| 156 | m_active_lookups.insert(uniqued_const_decl_name); |
Greg Clayton | 471da24 | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 157 | // static uint32_t g_depth = 0; |
| 158 | // ++g_depth; |
| 159 | // printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name); |
Greg Clayton | 580c5da | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 160 | llvm::SmallVector<NamedDecl*, 4> name_decls; |
| 161 | NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx); |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 162 | FindExternalVisibleDecls(name_search_context); |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 163 | SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls); |
Greg Clayton | 471da24 | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 164 | // --g_depth; |
Greg Clayton | 580c5da | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 165 | m_active_lookups.erase (uniqued_const_decl_name); |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 166 | return (name_decls.size() != 0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 169 | void |
| 170 | ClangASTSource::CompleteType (TagDecl *tag_decl) |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 171 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 172 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 173 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 174 | static unsigned int invocation_id = 0; |
| 175 | unsigned int current_id = invocation_id++; |
| 176 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 177 | if (log) |
| 178 | { |
Sean Callanan | a6e61a7 | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 179 | log->Printf(" CompleteTagDecl[%u] on (ASTContext*)%p Completing (TagDecl*)%p named %s", |
| 180 | current_id, |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 181 | m_ast_context, |
Sean Callanan | a6e61a7 | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 182 | tag_decl, |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 183 | tag_decl->getName().str().c_str()); |
| 184 | |
| 185 | log->Printf(" CTD[%u] Before:", current_id); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 186 | ASTDumper dumper((Decl*)tag_decl); |
| 187 | dumper.ToLog(log, " [CTD] "); |
| 188 | } |
| 189 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 190 | if (!m_ast_importer->CompleteTagDecl (tag_decl)) |
| 191 | { |
| 192 | // We couldn't complete the type. Maybe there's a definition |
| 193 | // somewhere else that can be completed. |
| 194 | |
| 195 | if (log) |
| 196 | log->Printf(" CTD[%u] Type could not be completed in the module in which it was first found.", current_id); |
| 197 | |
| 198 | bool found = false; |
| 199 | |
| 200 | DeclContext *decl_ctx = tag_decl->getDeclContext(); |
| 201 | |
| 202 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx)) |
| 203 | { |
| 204 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 205 | |
| 206 | if (log && log->GetVerbose()) |
| 207 | log->Printf(" CTD[%u] Inspecting namespace map %p (%d entries)", |
| 208 | current_id, |
| 209 | namespace_map.get(), |
| 210 | (int)namespace_map->size()); |
| 211 | |
| 212 | if (!namespace_map) |
| 213 | return; |
| 214 | |
| 215 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 216 | i != e && !found; |
| 217 | ++i) |
| 218 | { |
| 219 | if (log) |
| 220 | log->Printf(" CTD[%u] Searching namespace %s in module %s", |
| 221 | current_id, |
| 222 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 223 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 224 | |
| 225 | TypeList types; |
| 226 | |
| 227 | SymbolContext null_sc; |
| 228 | ConstString name(tag_decl->getName().str().c_str()); |
| 229 | |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 230 | i->first->FindTypesInNamespace(null_sc, name, &i->second, UINT32_MAX, types); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 231 | |
| 232 | for (uint32_t ti = 0, te = types.GetSize(); |
| 233 | ti != te && !found; |
| 234 | ++ti) |
| 235 | { |
| 236 | lldb::TypeSP type = types.GetTypeAtIndex(ti); |
| 237 | |
| 238 | if (!type) |
| 239 | continue; |
| 240 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 241 | ClangASTType clang_type (type->GetClangFullType()); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 242 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 243 | if (!clang_type) |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 244 | continue; |
| 245 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 246 | const TagType *tag_type = clang_type.GetQualType()->getAs<TagType>(); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 247 | |
| 248 | if (!tag_type) |
| 249 | continue; |
| 250 | |
| 251 | TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl()); |
| 252 | |
| 253 | if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl)) |
| 254 | found = true; |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | TypeList types; |
| 261 | |
| 262 | SymbolContext null_sc; |
| 263 | ConstString name(tag_decl->getName().str().c_str()); |
| 264 | ClangNamespaceDecl namespace_decl; |
| 265 | |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 266 | const ModuleList &module_list = m_target->GetImages(); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 267 | |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 268 | bool exact_match = false; |
Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame] | 269 | module_list.FindTypes (null_sc, name, exact_match, UINT32_MAX, types); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 270 | |
| 271 | for (uint32_t ti = 0, te = types.GetSize(); |
| 272 | ti != te && !found; |
| 273 | ++ti) |
| 274 | { |
| 275 | lldb::TypeSP type = types.GetTypeAtIndex(ti); |
| 276 | |
| 277 | if (!type) |
| 278 | continue; |
| 279 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 280 | ClangASTType clang_type (type->GetClangFullType()); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 281 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 282 | if (!clang_type) |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 283 | continue; |
| 284 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 285 | const TagType *tag_type = clang_type.GetQualType()->getAs<TagType>(); |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 286 | |
| 287 | if (!tag_type) |
| 288 | continue; |
| 289 | |
| 290 | TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl()); |
| 291 | |
| 292 | if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl)) |
| 293 | found = true; |
| 294 | } |
| 295 | } |
| 296 | } |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 297 | |
| 298 | if (log) |
| 299 | { |
| 300 | log->Printf(" [CTD] After:"); |
| 301 | ASTDumper dumper((Decl*)tag_decl); |
| 302 | dumper.ToLog(log, " [CTD] "); |
| 303 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 307 | ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl) |
| 308 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 309 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 310 | |
| 311 | if (log) |
| 312 | { |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 313 | log->Printf(" [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing an ObjCInterfaceDecl named %s", m_ast_context, interface_decl->getName().str().c_str()); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 314 | log->Printf(" [COID] Before:"); |
| 315 | ASTDumper dumper((Decl*)interface_decl); |
| 316 | dumper.ToLog(log, " [COID] "); |
| 317 | } |
| 318 | |
Sean Callanan | e3236a1 | 2014-03-11 19:34:04 +0000 | [diff] [blame^] | 319 | Decl *original_decl = NULL; |
| 320 | ASTContext *original_ctx = NULL; |
| 321 | |
| 322 | if (m_ast_importer->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx)) |
| 323 | { |
| 324 | if (ObjCInterfaceDecl *original_iface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl)) |
| 325 | { |
| 326 | ObjCInterfaceDecl *complete_iface_decl = GetCompleteObjCInterface(original_iface_decl); |
| 327 | |
| 328 | if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) |
| 329 | { |
| 330 | m_ast_importer->SetDeclOrigin(interface_decl, original_iface_decl); |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 335 | m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); |
| 336 | |
Sean Callanan | f4c0a22 | 2013-12-20 04:09:05 +0000 | [diff] [blame] | 337 | if (interface_decl->getSuperClass() && |
| 338 | interface_decl->getSuperClass() != interface_decl) |
| 339 | CompleteType(interface_decl->getSuperClass()); |
| 340 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 341 | if (log) |
| 342 | { |
| 343 | log->Printf(" [COID] After:"); |
| 344 | ASTDumper dumper((Decl*)interface_decl); |
| 345 | dumper.ToLog(log, " [COID] "); |
| 346 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 347 | } |
| 348 | |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 349 | clang::ObjCInterfaceDecl * |
| 350 | ClangASTSource::GetCompleteObjCInterface (clang::ObjCInterfaceDecl *interface_decl) |
| 351 | { |
| 352 | lldb::ProcessSP process(m_target->GetProcessSP()); |
| 353 | |
| 354 | if (!process) |
| 355 | return NULL; |
| 356 | |
| 357 | ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime()); |
| 358 | |
| 359 | if (!language_runtime) |
| 360 | return NULL; |
| 361 | |
| 362 | ConstString class_name(interface_decl->getNameAsString().c_str()); |
| 363 | |
| 364 | lldb::TypeSP complete_type_sp(language_runtime->LookupInCompleteClassCache(class_name)); |
| 365 | |
| 366 | if (!complete_type_sp) |
| 367 | return NULL; |
| 368 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 369 | TypeFromUser complete_type = TypeFromUser(complete_type_sp->GetClangFullType()); |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 370 | lldb::clang_type_t complete_opaque_type = complete_type.GetOpaqueQualType(); |
| 371 | |
| 372 | if (!complete_opaque_type) |
| 373 | return NULL; |
| 374 | |
| 375 | const clang::Type *complete_clang_type = QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr(); |
| 376 | const ObjCInterfaceType *complete_interface_type = dyn_cast<ObjCInterfaceType>(complete_clang_type); |
| 377 | |
| 378 | if (!complete_interface_type) |
| 379 | return NULL; |
| 380 | |
| 381 | ObjCInterfaceDecl *complete_iface_decl(complete_interface_type->getDecl()); |
| 382 | |
| 383 | return complete_iface_decl; |
| 384 | } |
| 385 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 386 | clang::ExternalLoadResult |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 387 | ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context, |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 388 | bool (*predicate)(Decl::Kind), |
| 389 | llvm::SmallVectorImpl<Decl*> &decls) |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 390 | { |
| 391 | ClangASTMetrics::RegisterLexicalQuery(); |
| 392 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 393 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 394 | |
| 395 | const Decl *context_decl = dyn_cast<Decl>(decl_context); |
| 396 | |
| 397 | if (!context_decl) |
| 398 | return ELR_Failure; |
| 399 | |
| 400 | static unsigned int invocation_id = 0; |
| 401 | unsigned int current_id = invocation_id++; |
| 402 | |
| 403 | if (log) |
| 404 | { |
| 405 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 406 | log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate", |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 407 | current_id, |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 408 | m_ast_context, |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 409 | context_named_decl->getNameAsString().c_str(), |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 410 | context_decl->getDeclKindName(), |
| 411 | context_decl, |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 412 | (predicate ? "non-null" : "null")); |
| 413 | else if(context_decl) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 414 | log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p with %s predicate", |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 415 | current_id, |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 416 | m_ast_context, |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 417 | context_decl->getDeclKindName(), |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 418 | context_decl, |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 419 | (predicate ? "non-null" : "null")); |
| 420 | else |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 421 | log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate", |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 422 | current_id, |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 423 | m_ast_context, |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 424 | (predicate ? "non-null" : "null")); |
| 425 | } |
| 426 | |
| 427 | Decl *original_decl = NULL; |
| 428 | ASTContext *original_ctx = NULL; |
| 429 | |
| 430 | if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) |
| 431 | return ELR_Failure; |
| 432 | |
| 433 | if (log) |
| 434 | { |
Sean Callanan | 933ca2e | 2013-02-28 03:12:58 +0000 | [diff] [blame] | 435 | log->Printf(" FELD[%u] Original decl (ASTContext*)%p (Decl*)%p:", current_id, original_ctx, original_decl); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 436 | ASTDumper(original_decl).ToLog(log, " "); |
| 437 | } |
| 438 | |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 439 | if (ObjCInterfaceDecl *original_iface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl)) |
| 440 | { |
| 441 | ObjCInterfaceDecl *complete_iface_decl = GetCompleteObjCInterface(original_iface_decl); |
| 442 | |
| 443 | if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) |
| 444 | { |
| 445 | original_decl = complete_iface_decl; |
| 446 | original_ctx = &complete_iface_decl->getASTContext(); |
| 447 | |
| 448 | m_ast_importer->SetDeclOrigin(context_decl, original_iface_decl); |
| 449 | } |
| 450 | } |
| 451 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 452 | if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) |
| 453 | { |
| 454 | ExternalASTSource *external_source = original_ctx->getExternalSource(); |
| 455 | |
| 456 | if (external_source) |
| 457 | external_source->CompleteType (original_tag_decl); |
| 458 | } |
| 459 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 460 | const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 461 | |
| 462 | if (!original_decl_context) |
| 463 | return ELR_Failure; |
| 464 | |
| 465 | for (TagDecl::decl_iterator iter = original_decl_context->decls_begin(); |
| 466 | iter != original_decl_context->decls_end(); |
| 467 | ++iter) |
| 468 | { |
| 469 | Decl *decl = *iter; |
| 470 | |
| 471 | if (!predicate || predicate(decl->getKind())) |
| 472 | { |
| 473 | if (log) |
| 474 | { |
| 475 | ASTDumper ast_dumper(decl); |
| 476 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 477 | log->Printf(" FELD[%d] Adding [to %sDecl %s] lexical %sDecl %s", current_id, context_named_decl->getDeclKindName(), context_named_decl->getNameAsString().c_str(), decl->getDeclKindName(), ast_dumper.GetCString()); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 478 | else |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 479 | log->Printf(" FELD[%d] Adding lexical %sDecl %s", current_id, decl->getDeclKindName(), ast_dumper.GetCString()); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 482 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, original_ctx, decl); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 483 | |
Sean Callanan | 61b33f7 | 2012-03-20 21:11:12 +0000 | [diff] [blame] | 484 | if (!copied_decl) |
| 485 | continue; |
| 486 | |
Sean Callanan | cf12862 | 2012-03-15 01:53:17 +0000 | [diff] [blame] | 487 | if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl)) |
| 488 | { |
| 489 | QualType copied_field_type = copied_field->getType(); |
| 490 | |
Sean Callanan | 6b200d0 | 2013-03-21 22:15:41 +0000 | [diff] [blame] | 491 | m_ast_importer->RequireCompleteType(copied_field_type); |
Sean Callanan | cf12862 | 2012-03-15 01:53:17 +0000 | [diff] [blame] | 492 | } |
| 493 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 494 | decls.push_back(copied_decl); |
Sean Callanan | 04b2bfa | 2013-05-09 01:09:49 +0000 | [diff] [blame] | 495 | |
| 496 | DeclContext *decl_context_non_const = const_cast<DeclContext *>(decl_context); |
| 497 | |
| 498 | if (copied_decl->getDeclContext() != decl_context) |
| 499 | { |
| 500 | if (copied_decl->getDeclContext()->containsDecl(copied_decl)) |
| 501 | copied_decl->getDeclContext()->removeDecl(copied_decl); |
| 502 | copied_decl->setDeclContext(decl_context_non_const); |
| 503 | } |
| 504 | |
| 505 | if (!decl_context_non_const->containsDecl(copied_decl)) |
| 506 | decl_context_non_const->addDeclInternal(copied_decl); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
| 510 | return ELR_AlreadyLoaded; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 513 | void |
| 514 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context) |
| 515 | { |
| 516 | assert (m_ast_context); |
| 517 | |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 518 | ClangASTMetrics::RegisterVisibleQuery(); |
| 519 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 520 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 521 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 522 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 523 | |
| 524 | static unsigned int invocation_id = 0; |
| 525 | unsigned int current_id = invocation_id++; |
| 526 | |
| 527 | if (log) |
| 528 | { |
| 529 | if (!context.m_decl_context) |
Sean Callanan | a6e61a7 | 2012-01-13 22:05:55 +0000 | [diff] [blame] | 530 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a NULL DeclContext", current_id, m_ast_context, name.GetCString()); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 531 | else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context)) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 532 | 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 | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 533 | else |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 534 | 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 | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap); |
| 538 | |
| 539 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context)) |
| 540 | { |
| 541 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 542 | |
| 543 | if (log && log->GetVerbose()) |
| 544 | log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)", |
| 545 | current_id, |
| 546 | namespace_map.get(), |
| 547 | (int)namespace_map->size()); |
| 548 | |
| 549 | if (!namespace_map) |
| 550 | return; |
| 551 | |
| 552 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 553 | i != e; |
| 554 | ++i) |
| 555 | { |
| 556 | if (log) |
| 557 | log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s", |
| 558 | current_id, |
| 559 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 560 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 561 | |
| 562 | FindExternalVisibleDecls(context, |
| 563 | i->first, |
| 564 | i->second, |
| 565 | current_id); |
| 566 | } |
| 567 | } |
Sean Callanan | 100d74e | 2011-11-15 21:50:18 +0000 | [diff] [blame] | 568 | else if (isa<ObjCInterfaceDecl>(context.m_decl_context)) |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 569 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 570 | FindObjCPropertyAndIvarDecls(context); |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 571 | } |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 572 | else if (!isa<TranslationUnitDecl>(context.m_decl_context)) |
| 573 | { |
| 574 | // we shouldn't be getting FindExternalVisibleDecls calls for these |
| 575 | return; |
| 576 | } |
| 577 | else |
| 578 | { |
| 579 | ClangNamespaceDecl namespace_decl; |
| 580 | |
| 581 | if (log) |
| 582 | log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id); |
| 583 | |
| 584 | FindExternalVisibleDecls(context, |
| 585 | lldb::ModuleSP(), |
| 586 | namespace_decl, |
| 587 | current_id); |
| 588 | } |
| 589 | |
| 590 | if (!context.m_namespace_map->empty()) |
| 591 | { |
| 592 | if (log && log->GetVerbose()) |
| 593 | log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)", |
| 594 | current_id, |
| 595 | context.m_namespace_map.get(), |
| 596 | (int)context.m_namespace_map->size()); |
| 597 | |
| 598 | NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map); |
| 599 | |
| 600 | if (clang_namespace_decl) |
| 601 | clang_namespace_decl->setHasExternalVisibleStorage(); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | void |
| 606 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context, |
| 607 | lldb::ModuleSP module_sp, |
| 608 | ClangNamespaceDecl &namespace_decl, |
| 609 | unsigned int current_id) |
| 610 | { |
| 611 | assert (m_ast_context); |
| 612 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 613 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 614 | |
| 615 | SymbolContextList sc_list; |
| 616 | |
| 617 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 618 | |
| 619 | const char *name_unique_cstr = name.GetCString(); |
| 620 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 621 | static ConstString id_name("id"); |
| 622 | static ConstString Class_name("Class"); |
| 623 | |
| 624 | if (name == id_name || name == Class_name) |
| 625 | return; |
| 626 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 627 | if (name_unique_cstr == NULL) |
| 628 | return; |
| 629 | |
| 630 | // The ClangASTSource is not responsible for finding $-names. |
| 631 | if (name_unique_cstr[0] == '$') |
| 632 | return; |
| 633 | |
| 634 | if (module_sp && namespace_decl) |
| 635 | { |
| 636 | ClangNamespaceDecl found_namespace_decl; |
| 637 | |
| 638 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 639 | |
| 640 | if (symbol_vendor) |
| 641 | { |
| 642 | SymbolContext null_sc; |
| 643 | |
| 644 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 645 | |
| 646 | if (found_namespace_decl) |
| 647 | { |
| 648 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 649 | |
| 650 | if (log) |
| 651 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 652 | current_id, |
| 653 | name.GetCString(), |
| 654 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | else |
| 659 | { |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 660 | const ModuleList &target_images = m_target->GetImages(); |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 661 | Mutex::Locker modules_locker (target_images.GetMutex()); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 662 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 663 | for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 664 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 665 | lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 666 | |
| 667 | if (!image) |
| 668 | continue; |
| 669 | |
| 670 | ClangNamespaceDecl found_namespace_decl; |
| 671 | |
| 672 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 673 | |
| 674 | if (!symbol_vendor) |
| 675 | continue; |
| 676 | |
| 677 | SymbolContext null_sc; |
| 678 | |
| 679 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 680 | |
| 681 | if (found_namespace_decl) |
| 682 | { |
| 683 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 684 | |
| 685 | if (log) |
| 686 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 687 | current_id, |
| 688 | name.GetCString(), |
| 689 | image->GetFileSpec().GetFilename().GetCString()); |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 694 | do |
| 695 | { |
| 696 | TypeList types; |
| 697 | SymbolContext null_sc; |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 698 | const bool exact_match = false; |
Sean Callanan | bfb7c68 | 2011-12-19 19:38:39 +0000 | [diff] [blame] | 699 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 700 | if (module_sp && namespace_decl) |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 701 | module_sp->FindTypesInNamespace(null_sc, name, &namespace_decl, 1, types); |
Sean Callanan | bfb7c68 | 2011-12-19 19:38:39 +0000 | [diff] [blame] | 702 | else |
Greg Clayton | 29399a2 | 2012-04-06 17:41:13 +0000 | [diff] [blame] | 703 | m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, types); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 704 | |
| 705 | if (types.GetSize()) |
| 706 | { |
| 707 | lldb::TypeSP type_sp = types.GetTypeAtIndex(0); |
| 708 | |
| 709 | if (log) |
| 710 | { |
| 711 | const char *name_string = type_sp->GetName().GetCString(); |
| 712 | |
| 713 | log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s", |
| 714 | current_id, |
| 715 | name.GetCString(), |
| 716 | (name_string ? name_string : "<anonymous>")); |
| 717 | } |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 718 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 719 | ClangASTType full_type = type_sp->GetClangFullType(); |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 720 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 721 | ClangASTType copied_clang_type (GuardedCopyType(full_type)); |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 722 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 723 | if (!copied_clang_type) |
Sean Callanan | e0a64f7 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 724 | { |
| 725 | if (log) |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 726 | log->Printf(" CAS::FEVD[%u] - Couldn't export a type", |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 727 | current_id); |
| 728 | |
Sean Callanan | e0a64f7 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 729 | break; |
| 730 | } |
| 731 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 732 | context.AddTypeDecl(copied_clang_type); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 733 | } |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 734 | else |
| 735 | { |
| 736 | do |
| 737 | { |
| 738 | // Couldn't find any types elsewhere. Try the Objective-C runtime if one exists. |
| 739 | |
| 740 | lldb::ProcessSP process(m_target->GetProcessSP()); |
| 741 | |
| 742 | if (!process) |
| 743 | break; |
| 744 | |
| 745 | ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime()); |
| 746 | |
| 747 | if (!language_runtime) |
| 748 | break; |
| 749 | |
| 750 | TypeVendor *type_vendor = language_runtime->GetTypeVendor(); |
| 751 | |
| 752 | if (!type_vendor) |
| 753 | break; |
| 754 | |
| 755 | bool append = false; |
| 756 | uint32_t max_matches = 1; |
| 757 | std::vector <ClangASTType> types; |
| 758 | |
| 759 | if (!type_vendor->FindTypes(name, |
| 760 | append, |
| 761 | max_matches, |
| 762 | types)) |
| 763 | break; |
| 764 | |
| 765 | if (log) |
| 766 | { |
| 767 | log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\" in the runtime", |
| 768 | current_id, |
| 769 | name.GetCString()); |
| 770 | } |
| 771 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 772 | ClangASTType copied_clang_type (GuardedCopyType(types[0])); |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 773 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 774 | if (!copied_clang_type) |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 775 | { |
| 776 | if (log) |
| 777 | log->Printf(" CAS::FEVD[%u] - Couldn't export a type from the runtime", |
| 778 | current_id); |
| 779 | |
| 780 | break; |
| 781 | } |
| 782 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 783 | context.AddTypeDecl(copied_clang_type); |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 784 | } |
| 785 | while(0); |
| 786 | } |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 787 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 788 | } while(0); |
| 789 | } |
| 790 | |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 791 | template <class D> class TaggedASTDecl { |
| 792 | public: |
| 793 | TaggedASTDecl() : decl(NULL) { } |
| 794 | TaggedASTDecl(D *_decl) : decl(_decl) { } |
| 795 | bool IsValid() const { return (decl != NULL); } |
| 796 | bool IsInvalid() const { return !IsValid(); } |
| 797 | D *operator->() const { return decl; } |
| 798 | D *decl; |
| 799 | }; |
| 800 | |
| 801 | template <class D2, template <class D> class TD, class D1> |
| 802 | TD<D2> |
| 803 | DynCast(TD<D1> source) |
| 804 | { |
| 805 | return TD<D2> (dyn_cast<D2>(source.decl)); |
| 806 | } |
| 807 | |
| 808 | template <class D = Decl> class DeclFromParser; |
| 809 | template <class D = Decl> class DeclFromUser; |
| 810 | |
| 811 | template <class D> class DeclFromParser : public TaggedASTDecl<D> { |
| 812 | public: |
| 813 | DeclFromParser() : TaggedASTDecl<D>() { } |
| 814 | DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) { } |
| 815 | |
| 816 | DeclFromUser<D> GetOrigin(ClangASTImporter *importer); |
| 817 | }; |
| 818 | |
| 819 | template <class D> class DeclFromUser : public TaggedASTDecl<D> { |
| 820 | public: |
| 821 | DeclFromUser() : TaggedASTDecl<D>() { } |
| 822 | DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) { } |
| 823 | |
| 824 | DeclFromParser<D> Import(ClangASTImporter *importer, ASTContext &dest_ctx); |
| 825 | }; |
| 826 | |
| 827 | template <class D> |
| 828 | DeclFromUser<D> |
| 829 | DeclFromParser<D>::GetOrigin(ClangASTImporter *importer) |
| 830 | { |
| 831 | DeclFromUser <> origin_decl; |
| 832 | importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL); |
| 833 | if (origin_decl.IsInvalid()) |
| 834 | return DeclFromUser<D>(); |
| 835 | return DeclFromUser<D>(dyn_cast<D>(origin_decl.decl)); |
| 836 | } |
| 837 | |
| 838 | template <class D> |
| 839 | DeclFromParser<D> |
| 840 | DeclFromUser<D>::Import(ClangASTImporter *importer, ASTContext &dest_ctx) |
| 841 | { |
| 842 | DeclFromParser <> parser_generic_decl(importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl)); |
| 843 | if (parser_generic_decl.IsInvalid()) |
| 844 | return DeclFromParser<D>(); |
| 845 | return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl)); |
| 846 | } |
| 847 | |
Sean Callanan | c83e341 | 2012-11-28 03:23:20 +0000 | [diff] [blame] | 848 | static bool |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 849 | FindObjCMethodDeclsWithOrigin (unsigned int current_id, |
| 850 | NameSearchContext &context, |
| 851 | ObjCInterfaceDecl *original_interface_decl, |
| 852 | clang::ASTContext *ast_context, |
| 853 | ClangASTImporter *ast_importer, |
| 854 | const char *log_info) |
| 855 | { |
| 856 | const DeclarationName &decl_name(context.m_decl_name); |
| 857 | clang::ASTContext *original_ctx = &original_interface_decl->getASTContext(); |
| 858 | |
| 859 | Selector original_selector; |
| 860 | |
| 861 | if (decl_name.isObjCZeroArgSelector()) |
| 862 | { |
| 863 | IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString()); |
| 864 | original_selector = original_ctx->Selectors.getSelector(0, &ident); |
| 865 | } |
| 866 | else if (decl_name.isObjCOneArgSelector()) |
| 867 | { |
| 868 | const std::string &decl_name_string = decl_name.getAsString(); |
| 869 | std::string decl_name_string_without_colon(decl_name_string.c_str(), decl_name_string.length() - 1); |
| 870 | IdentifierInfo *ident = &original_ctx->Idents.get(decl_name_string_without_colon.c_str()); |
| 871 | original_selector = original_ctx->Selectors.getSelector(1, &ident); |
| 872 | } |
| 873 | else |
| 874 | { |
| 875 | SmallVector<IdentifierInfo *, 4> idents; |
| 876 | |
| 877 | clang::Selector sel = decl_name.getObjCSelector(); |
| 878 | |
Andy Gibbs | a297a97 | 2013-06-19 19:04:53 +0000 | [diff] [blame] | 879 | unsigned num_args = sel.getNumArgs(); |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 880 | |
| 881 | for (unsigned i = 0; |
| 882 | i != num_args; |
| 883 | ++i) |
| 884 | { |
| 885 | idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i))); |
| 886 | } |
| 887 | |
| 888 | original_selector = original_ctx->Selectors.getSelector(num_args, idents.data()); |
| 889 | } |
| 890 | |
| 891 | DeclarationName original_decl_name(original_selector); |
| 892 | |
| 893 | ObjCInterfaceDecl::lookup_result result = original_interface_decl->lookup(original_decl_name); |
| 894 | |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 895 | if (result.empty()) |
Sean Callanan | c83e341 | 2012-11-28 03:23:20 +0000 | [diff] [blame] | 896 | return false; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 897 | |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 898 | if (!result[0]) |
Sean Callanan | c83e341 | 2012-11-28 03:23:20 +0000 | [diff] [blame] | 899 | return false; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 900 | |
Sean Callanan | 01c8cb8 | 2013-09-04 23:25:26 +0000 | [diff] [blame] | 901 | for (NamedDecl *named_decl : result) |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 902 | { |
Sean Callanan | 01c8cb8 | 2013-09-04 23:25:26 +0000 | [diff] [blame] | 903 | ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl); |
| 904 | |
| 905 | if (!result_method) |
| 906 | return false; |
| 907 | |
| 908 | Decl *copied_decl = ast_importer->CopyDecl(ast_context, &result_method->getASTContext(), result_method); |
| 909 | |
| 910 | if (!copied_decl) |
| 911 | return false; |
| 912 | |
| 913 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); |
| 914 | |
| 915 | if (!copied_method_decl) |
| 916 | return false; |
| 917 | |
| 918 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 919 | |
| 920 | if (log) |
| 921 | { |
| 922 | ASTDumper dumper((Decl*)copied_method_decl); |
| 923 | log->Printf(" CAS::FOMD[%d] found (%s) %s", current_id, log_info, dumper.GetCString()); |
| 924 | } |
| 925 | |
| 926 | context.AddNamedDecl(copied_method_decl); |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Sean Callanan | c83e341 | 2012-11-28 03:23:20 +0000 | [diff] [blame] | 929 | return true; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 930 | } |
| 931 | |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 932 | void |
| 933 | ClangASTSource::FindObjCMethodDecls (NameSearchContext &context) |
| 934 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 935 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 936 | |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 937 | static unsigned int invocation_id = 0; |
| 938 | unsigned int current_id = invocation_id++; |
| 939 | |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 940 | const DeclarationName &decl_name(context.m_decl_name); |
| 941 | const DeclContext *decl_ctx(context.m_decl_context); |
| 942 | |
| 943 | const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx); |
| 944 | |
| 945 | if (!interface_decl) |
| 946 | return; |
| 947 | |
Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 948 | do |
| 949 | { |
| 950 | Decl *original_decl = NULL; |
| 951 | ASTContext *original_ctx = NULL; |
| 952 | |
| 953 | m_ast_importer->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx); |
| 954 | |
| 955 | if (!original_decl) |
| 956 | break; |
| 957 | |
| 958 | ObjCInterfaceDecl *original_interface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl); |
| 959 | |
Sean Callanan | c83e341 | 2012-11-28 03:23:20 +0000 | [diff] [blame] | 960 | if (FindObjCMethodDeclsWithOrigin(current_id, |
| 961 | context, |
| 962 | original_interface_decl, |
| 963 | m_ast_context, |
| 964 | m_ast_importer, |
| 965 | "at origin")) |
| 966 | return; // found it, no need to look any further |
Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 967 | } while (0); |
| 968 | |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 969 | StreamString ss; |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 970 | |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 971 | if (decl_name.isObjCZeroArgSelector()) |
| 972 | { |
| 973 | ss.Printf("%s", decl_name.getAsString().c_str()); |
| 974 | } |
| 975 | else if (decl_name.isObjCOneArgSelector()) |
| 976 | { |
Sean Callanan | 4fb79b7 | 2011-11-14 18:29:46 +0000 | [diff] [blame] | 977 | ss.Printf("%s", decl_name.getAsString().c_str()); |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 978 | } |
| 979 | else |
| 980 | { |
| 981 | clang::Selector sel = decl_name.getObjCSelector(); |
| 982 | |
| 983 | for (unsigned i = 0, e = sel.getNumArgs(); |
| 984 | i != e; |
| 985 | ++i) |
| 986 | { |
| 987 | llvm::StringRef r = sel.getNameForSlot(i); |
| 988 | ss.Printf("%s:", r.str().c_str()); |
| 989 | } |
| 990 | } |
| 991 | ss.Flush(); |
| 992 | |
Sean Callanan | d6be708 | 2014-02-06 22:24:11 +0000 | [diff] [blame] | 993 | if (strstr(ss.GetData(), "$__lldb")) |
| 994 | return; // we don't need any results |
| 995 | |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 996 | ConstString selector_name(ss.GetData()); |
| 997 | |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 998 | if (log) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 999 | log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]", |
| 1000 | current_id, |
| 1001 | m_ast_context, |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1002 | interface_decl->getNameAsString().c_str(), |
| 1003 | selector_name.AsCString()); |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1004 | SymbolContextList sc_list; |
| 1005 | |
| 1006 | const bool include_symbols = false; |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1007 | const bool include_inlines = false; |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1008 | const bool append = false; |
| 1009 | |
Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 1010 | std::string interface_name = interface_decl->getNameAsString(); |
| 1011 | |
| 1012 | do |
| 1013 | { |
| 1014 | StreamString ms; |
| 1015 | ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString()); |
| 1016 | ms.Flush(); |
| 1017 | ConstString instance_method_name(ms.GetData()); |
| 1018 | |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1019 | m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); |
Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 1020 | |
| 1021 | if (sc_list.GetSize()) |
| 1022 | break; |
| 1023 | |
| 1024 | ms.Clear(); |
| 1025 | ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString()); |
| 1026 | ms.Flush(); |
| 1027 | ConstString class_method_name(ms.GetData()); |
| 1028 | |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1029 | m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list); |
Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 1030 | |
| 1031 | if (sc_list.GetSize()) |
| 1032 | break; |
| 1033 | |
| 1034 | // Fall back and check for methods in categories. If we find methods this way, we need to check that they're actually in |
| 1035 | // categories on the desired class. |
| 1036 | |
| 1037 | SymbolContextList candidate_sc_list; |
| 1038 | |
Sean Callanan | 9df05fb | 2012-02-10 22:52:19 +0000 | [diff] [blame] | 1039 | m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list); |
Sean Callanan | a9bc065 | 2012-01-19 02:17:40 +0000 | [diff] [blame] | 1040 | |
| 1041 | for (uint32_t ci = 0, ce = candidate_sc_list.GetSize(); |
| 1042 | ci != ce; |
| 1043 | ++ci) |
| 1044 | { |
| 1045 | SymbolContext candidate_sc; |
| 1046 | |
| 1047 | if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc)) |
| 1048 | continue; |
| 1049 | |
| 1050 | if (!candidate_sc.function) |
| 1051 | continue; |
| 1052 | |
| 1053 | const char *candidate_name = candidate_sc.function->GetName().AsCString(); |
| 1054 | |
| 1055 | const char *cursor = candidate_name; |
| 1056 | |
| 1057 | if (*cursor != '+' && *cursor != '-') |
| 1058 | continue; |
| 1059 | |
| 1060 | ++cursor; |
| 1061 | |
| 1062 | if (*cursor != '[') |
| 1063 | continue; |
| 1064 | |
| 1065 | ++cursor; |
| 1066 | |
| 1067 | size_t interface_len = interface_name.length(); |
| 1068 | |
| 1069 | if (strncmp(cursor, interface_name.c_str(), interface_len)) |
| 1070 | continue; |
| 1071 | |
| 1072 | cursor += interface_len; |
| 1073 | |
| 1074 | if (*cursor == ' ' || *cursor == '(') |
| 1075 | sc_list.Append(candidate_sc); |
| 1076 | } |
| 1077 | } |
| 1078 | while (0); |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1079 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1080 | if (sc_list.GetSize()) |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1081 | { |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1082 | // We found a good function symbol. Use that. |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1083 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1084 | for (uint32_t i = 0, e = sc_list.GetSize(); |
| 1085 | i != e; |
| 1086 | ++i) |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1087 | { |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1088 | SymbolContext sc; |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1089 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1090 | if (!sc_list.GetContextAtIndex(i, sc)) |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1091 | continue; |
| 1092 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1093 | if (!sc.function) |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1094 | continue; |
| 1095 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1096 | DeclContext *function_ctx = sc.function->GetClangDeclContext(); |
| 1097 | |
| 1098 | if (!function_ctx) |
| 1099 | continue; |
| 1100 | |
| 1101 | ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx); |
| 1102 | |
| 1103 | if (!method_decl) |
| 1104 | continue; |
| 1105 | |
| 1106 | ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface(); |
| 1107 | |
| 1108 | if (!found_interface_decl) |
| 1109 | continue; |
| 1110 | |
| 1111 | if (found_interface_decl->getName() == interface_decl->getName()) |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1112 | { |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1113 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl); |
| 1114 | |
| 1115 | if (!copied_decl) |
| 1116 | continue; |
| 1117 | |
| 1118 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); |
| 1119 | |
| 1120 | if (!copied_method_decl) |
| 1121 | continue; |
| 1122 | |
| 1123 | if (log) |
| 1124 | { |
| 1125 | ASTDumper dumper((Decl*)copied_method_decl); |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1126 | log->Printf(" CAS::FOMD[%d] found (in symbols) %s", current_id, dumper.GetCString()); |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | context.AddNamedDecl(copied_method_decl); |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1130 | } |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1131 | } |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1132 | |
| 1133 | return; |
Sean Callanan | 46198ff | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 1134 | } |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1135 | |
| 1136 | // Try the debug information. |
| 1137 | |
| 1138 | do |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1139 | { |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1140 | ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface(const_cast<ObjCInterfaceDecl*>(interface_decl)); |
| 1141 | |
| 1142 | if (!complete_interface_decl) |
| 1143 | break; |
| 1144 | |
| 1145 | // We found the complete interface. The runtime never needs to be queried in this scenario. |
| 1146 | |
| 1147 | DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_decl); |
| 1148 | |
| 1149 | if (complete_interface_decl == interface_decl) |
| 1150 | break; // already checked this one |
| 1151 | |
| 1152 | if (log) |
| 1153 | log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...", |
| 1154 | current_id, |
| 1155 | complete_interface_decl, |
| 1156 | &complete_iface_decl->getASTContext()); |
| 1157 | |
| 1158 | FindObjCMethodDeclsWithOrigin(current_id, |
| 1159 | context, |
| 1160 | complete_interface_decl, |
| 1161 | m_ast_context, |
| 1162 | m_ast_importer, |
| 1163 | "in debug info"); |
| 1164 | |
| 1165 | return; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1166 | } |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1167 | while (0); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1168 | |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1169 | do |
| 1170 | { |
| 1171 | // Check the runtime only if the debug information didn't have a complete interface. |
| 1172 | |
| 1173 | lldb::ProcessSP process(m_target->GetProcessSP()); |
| 1174 | |
| 1175 | if (!process) |
| 1176 | break; |
| 1177 | |
| 1178 | ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime()); |
| 1179 | |
Sean Callanan | 7be70e8 | 2012-12-19 23:05:01 +0000 | [diff] [blame] | 1180 | if (!language_runtime) |
| 1181 | break; |
| 1182 | |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1183 | TypeVendor *type_vendor = language_runtime->GetTypeVendor(); |
| 1184 | |
| 1185 | if (!type_vendor) |
| 1186 | break; |
| 1187 | |
| 1188 | ConstString interface_name(interface_decl->getNameAsString().c_str()); |
| 1189 | bool append = false; |
| 1190 | uint32_t max_matches = 1; |
| 1191 | std::vector <ClangASTType> types; |
| 1192 | |
| 1193 | if (!type_vendor->FindTypes(interface_name, |
| 1194 | append, |
| 1195 | max_matches, |
| 1196 | types)) |
| 1197 | break; |
| 1198 | |
| 1199 | const clang::Type *runtime_clang_type = QualType::getFromOpaquePtr(types[0].GetOpaqueQualType()).getTypePtr(); |
| 1200 | |
| 1201 | const ObjCInterfaceType *runtime_interface_type = dyn_cast<ObjCInterfaceType>(runtime_clang_type); |
| 1202 | |
| 1203 | if (!runtime_interface_type) |
| 1204 | break; |
| 1205 | |
| 1206 | ObjCInterfaceDecl *runtime_interface_decl = runtime_interface_type->getDecl(); |
| 1207 | |
| 1208 | FindObjCMethodDeclsWithOrigin(current_id, |
| 1209 | context, |
| 1210 | runtime_interface_decl, |
| 1211 | m_ast_context, |
| 1212 | m_ast_importer, |
| 1213 | "in runtime"); |
| 1214 | } |
| 1215 | while(0); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1216 | } |
| 1217 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1218 | static bool |
| 1219 | FindObjCPropertyAndIvarDeclsWithOrigin (unsigned int current_id, |
| 1220 | NameSearchContext &context, |
| 1221 | clang::ASTContext &ast_context, |
| 1222 | ClangASTImporter *ast_importer, |
| 1223 | DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl) |
| 1224 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1225 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1226 | |
| 1227 | if (origin_iface_decl.IsInvalid()) |
| 1228 | return false; |
| 1229 | |
| 1230 | std::string name_str = context.m_decl_name.getAsString(); |
| 1231 | StringRef name(name_str.c_str()); |
| 1232 | IdentifierInfo &name_identifier(origin_iface_decl->getASTContext().Idents.get(name)); |
| 1233 | |
| 1234 | DeclFromUser<ObjCPropertyDecl> origin_property_decl(origin_iface_decl->FindPropertyDeclaration(&name_identifier)); |
| 1235 | |
| 1236 | bool found = false; |
| 1237 | |
| 1238 | if (origin_property_decl.IsValid()) |
| 1239 | { |
| 1240 | DeclFromParser<ObjCPropertyDecl> parser_property_decl(origin_property_decl.Import(ast_importer, ast_context)); |
| 1241 | if (parser_property_decl.IsValid()) |
| 1242 | { |
| 1243 | if (log) |
| 1244 | { |
| 1245 | ASTDumper dumper((Decl*)parser_property_decl.decl); |
| 1246 | log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); |
| 1247 | } |
| 1248 | |
| 1249 | context.AddNamedDecl(parser_property_decl.decl); |
| 1250 | found = true; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | DeclFromUser<ObjCIvarDecl> origin_ivar_decl(origin_iface_decl->getIvarDecl(&name_identifier)); |
| 1255 | |
| 1256 | if (origin_ivar_decl.IsValid()) |
| 1257 | { |
| 1258 | DeclFromParser<ObjCIvarDecl> parser_ivar_decl(origin_ivar_decl.Import(ast_importer, ast_context)); |
| 1259 | if (parser_ivar_decl.IsValid()) |
| 1260 | { |
| 1261 | if (log) |
| 1262 | { |
| 1263 | ASTDumper dumper((Decl*)parser_ivar_decl.decl); |
| 1264 | log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); |
| 1265 | } |
| 1266 | |
| 1267 | context.AddNamedDecl(parser_ivar_decl.decl); |
| 1268 | found = true; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | return found; |
| 1273 | } |
| 1274 | |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1275 | void |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1276 | ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context) |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1277 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1278 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1279 | |
| 1280 | static unsigned int invocation_id = 0; |
| 1281 | unsigned int current_id = invocation_id++; |
| 1282 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1283 | DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl(cast<ObjCInterfaceDecl>(context.m_decl_context)); |
| 1284 | DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl(parser_iface_decl.GetOrigin(m_ast_importer)); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1285 | |
| 1286 | ConstString class_name(parser_iface_decl->getNameAsString().c_str()); |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1287 | |
| 1288 | if (log) |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1289 | log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on (ASTContext*)%p for '%s.%s'", |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1290 | current_id, |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1291 | m_ast_context, |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1292 | parser_iface_decl->getNameAsString().c_str(), |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1293 | context.m_decl_name.getAsString().c_str()); |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1294 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1295 | if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id, |
| 1296 | context, |
| 1297 | *m_ast_context, |
| 1298 | m_ast_importer, |
| 1299 | origin_iface_decl)) |
| 1300 | return; |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1301 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1302 | if (log) |
| 1303 | log->Printf("CAS::FOPD[%d] couldn't find the property on origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p, searching elsewhere...", |
| 1304 | current_id, |
| 1305 | origin_iface_decl.decl, |
| 1306 | &origin_iface_decl->getASTContext()); |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1307 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1308 | SymbolContext null_sc; |
| 1309 | TypeList type_list; |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1310 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1311 | do |
| 1312 | { |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 1313 | ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface(const_cast<ObjCInterfaceDecl*>(parser_iface_decl.decl)); |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1314 | |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 1315 | if (!complete_interface_decl) |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1316 | break; |
| 1317 | |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1318 | // We found the complete interface. The runtime never needs to be queried in this scenario. |
| 1319 | |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 1320 | DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_decl); |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1321 | |
| 1322 | if (complete_iface_decl.decl == origin_iface_decl.decl) |
| 1323 | break; // already checked this one |
| 1324 | |
| 1325 | if (log) |
| 1326 | log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...", |
| 1327 | current_id, |
| 1328 | complete_iface_decl.decl, |
| 1329 | &complete_iface_decl->getASTContext()); |
| 1330 | |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1331 | FindObjCPropertyAndIvarDeclsWithOrigin(current_id, |
| 1332 | context, |
| 1333 | *m_ast_context, |
| 1334 | m_ast_importer, |
| 1335 | complete_iface_decl); |
| 1336 | |
| 1337 | return; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1338 | } |
| 1339 | while(0); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 1340 | |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1341 | do |
| 1342 | { |
Sean Callanan | 5540094 | 2012-11-02 17:09:58 +0000 | [diff] [blame] | 1343 | // Check the runtime only if the debug information didn't have a complete interface. |
| 1344 | |
| 1345 | lldb::ProcessSP process(m_target->GetProcessSP()); |
| 1346 | |
| 1347 | if (!process) |
| 1348 | return; |
| 1349 | |
| 1350 | ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime()); |
| 1351 | |
| 1352 | if (!language_runtime) |
| 1353 | return; |
Sean Callanan | bc47dfc | 2012-09-11 21:44:01 +0000 | [diff] [blame] | 1354 | |
| 1355 | TypeVendor *type_vendor = language_runtime->GetTypeVendor(); |
| 1356 | |
| 1357 | if (!type_vendor) |
| 1358 | break; |
| 1359 | |
| 1360 | bool append = false; |
| 1361 | uint32_t max_matches = 1; |
| 1362 | std::vector <ClangASTType> types; |
| 1363 | |
| 1364 | if (!type_vendor->FindTypes(class_name, |
| 1365 | append, |
| 1366 | max_matches, |
| 1367 | types)) |
| 1368 | break; |
| 1369 | |
| 1370 | const clang::Type *runtime_clang_type = QualType::getFromOpaquePtr(types[0].GetOpaqueQualType()).getTypePtr(); |
| 1371 | |
| 1372 | const ObjCInterfaceType *runtime_interface_type = dyn_cast<ObjCInterfaceType>(runtime_clang_type); |
| 1373 | |
| 1374 | if (!runtime_interface_type) |
| 1375 | break; |
| 1376 | |
| 1377 | DeclFromUser<const ObjCInterfaceDecl> runtime_iface_decl(runtime_interface_type->getDecl()); |
| 1378 | |
| 1379 | if (log) |
| 1380 | log->Printf("CAS::FOPD[%d] trying runtime (ObjCInterfaceDecl*)%p/(ASTContext*)%p...", |
| 1381 | current_id, |
| 1382 | runtime_iface_decl.decl, |
| 1383 | &runtime_iface_decl->getASTContext()); |
| 1384 | |
| 1385 | if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id, |
| 1386 | context, |
| 1387 | *m_ast_context, |
| 1388 | m_ast_importer, |
| 1389 | runtime_iface_decl)) |
| 1390 | return; |
| 1391 | } |
| 1392 | while(0); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | typedef llvm::DenseMap <const FieldDecl *, uint64_t> FieldOffsetMap; |
| 1396 | typedef llvm::DenseMap <const CXXRecordDecl *, CharUnits> BaseOffsetMap; |
| 1397 | |
| 1398 | template <class D, class O> |
| 1399 | static bool |
| 1400 | ImportOffsetMap (llvm::DenseMap <const D*, O> &destination_map, |
| 1401 | llvm::DenseMap <const D*, O> &source_map, |
| 1402 | ClangASTImporter *importer, |
| 1403 | ASTContext &dest_ctx) |
| 1404 | { |
| 1405 | typedef llvm::DenseMap <const D*, O> MapType; |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1406 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1407 | for (typename MapType::iterator fi = source_map.begin(), fe = source_map.end(); |
| 1408 | fi != fe; |
| 1409 | ++fi) |
| 1410 | { |
| 1411 | DeclFromUser <D> user_decl(const_cast<D*>(fi->first)); |
| 1412 | DeclFromParser <D> parser_decl(user_decl.Import(importer, dest_ctx)); |
| 1413 | if (parser_decl.IsInvalid()) |
| 1414 | return false; |
| 1415 | destination_map.insert(std::pair<const D *, O>(parser_decl.decl, fi->second)); |
| 1416 | } |
| 1417 | |
| 1418 | return true; |
| 1419 | } |
| 1420 | |
| 1421 | template <bool IsVirtual> bool ExtractBaseOffsets (const ASTRecordLayout &record_layout, |
| 1422 | DeclFromUser<const CXXRecordDecl> &record, |
| 1423 | BaseOffsetMap &base_offsets) |
| 1424 | { |
| 1425 | for (CXXRecordDecl::base_class_const_iterator |
| 1426 | bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()), |
| 1427 | be = (IsVirtual ? record->vbases_end() : record->bases_end()); |
| 1428 | bi != be; |
| 1429 | ++bi) |
| 1430 | { |
| 1431 | if (!IsVirtual && bi->isVirtual()) |
| 1432 | continue; |
| 1433 | |
| 1434 | const clang::Type *origin_base_type = bi->getType().getTypePtr(); |
| 1435 | const clang::RecordType *origin_base_record_type = origin_base_type->getAs<RecordType>(); |
| 1436 | |
| 1437 | if (!origin_base_record_type) |
| 1438 | return false; |
| 1439 | |
| 1440 | DeclFromUser <RecordDecl> origin_base_record(origin_base_record_type->getDecl()); |
| 1441 | |
| 1442 | if (origin_base_record.IsInvalid()) |
| 1443 | return false; |
| 1444 | |
| 1445 | DeclFromUser <CXXRecordDecl> origin_base_cxx_record(DynCast<CXXRecordDecl>(origin_base_record)); |
| 1446 | |
| 1447 | if (origin_base_cxx_record.IsInvalid()) |
| 1448 | return false; |
| 1449 | |
| 1450 | CharUnits base_offset; |
| 1451 | |
| 1452 | if (IsVirtual) |
| 1453 | base_offset = record_layout.getVBaseClassOffset(origin_base_cxx_record.decl); |
| 1454 | else |
| 1455 | base_offset = record_layout.getBaseClassOffset(origin_base_cxx_record.decl); |
| 1456 | |
| 1457 | base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>(origin_base_cxx_record.decl, base_offset)); |
| 1458 | } |
| 1459 | |
| 1460 | return true; |
| 1461 | } |
| 1462 | |
| 1463 | bool |
| 1464 | ClangASTSource::layoutRecordType(const RecordDecl *record, |
| 1465 | uint64_t &size, |
| 1466 | uint64_t &alignment, |
| 1467 | FieldOffsetMap &field_offsets, |
| 1468 | BaseOffsetMap &base_offsets, |
| 1469 | BaseOffsetMap &virtual_base_offsets) |
| 1470 | { |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 1471 | ClangASTMetrics::RegisterRecordLayout(); |
| 1472 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1473 | static unsigned int invocation_id = 0; |
| 1474 | unsigned int current_id = invocation_id++; |
| 1475 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1476 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1477 | |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1478 | if (log) |
| 1479 | { |
Sean Callanan | 933ca2e | 2013-02-28 03:12:58 +0000 | [diff] [blame] | 1480 | log->Printf("LayoutRecordType[%u] on (ASTContext*)%p for (RecordDecl*)%p [name = '%s']", |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1481 | current_id, |
| 1482 | m_ast_context, |
Sean Callanan | 933ca2e | 2013-02-28 03:12:58 +0000 | [diff] [blame] | 1483 | record, |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1484 | record->getNameAsString().c_str()); |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1485 | } |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1486 | |
| 1487 | |
| 1488 | DeclFromParser <const RecordDecl> parser_record(record); |
| 1489 | DeclFromUser <const RecordDecl> origin_record(parser_record.GetOrigin(m_ast_importer)); |
| 1490 | |
| 1491 | if (origin_record.IsInvalid()) |
| 1492 | return false; |
| 1493 | |
| 1494 | FieldOffsetMap origin_field_offsets; |
| 1495 | BaseOffsetMap origin_base_offsets; |
| 1496 | BaseOffsetMap origin_virtual_base_offsets; |
| 1497 | |
Sean Callanan | bf81ea5 | 2012-04-07 00:06:00 +0000 | [diff] [blame] | 1498 | ClangASTContext::GetCompleteDecl(&origin_record->getASTContext(), const_cast<RecordDecl*>(origin_record.decl)); |
| 1499 | |
| 1500 | if (!origin_record.decl->getDefinition()) |
| 1501 | return false; |
| 1502 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1503 | const ASTRecordLayout &record_layout(origin_record->getASTContext().getASTRecordLayout(origin_record.decl)); |
| 1504 | |
Sean Callanan | eb7b27d | 2013-03-25 18:27:07 +0000 | [diff] [blame] | 1505 | int field_idx = 0, field_count = record_layout.getFieldCount(); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1506 | |
| 1507 | for (RecordDecl::field_iterator fi = origin_record->field_begin(), fe = origin_record->field_end(); |
| 1508 | fi != fe; |
| 1509 | ++fi) |
| 1510 | { |
Sean Callanan | eb7b27d | 2013-03-25 18:27:07 +0000 | [diff] [blame] | 1511 | if (field_idx >= field_count) |
| 1512 | return false; // Layout didn't go well. Bail out. |
| 1513 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1514 | uint64_t field_offset = record_layout.getFieldOffset(field_idx); |
| 1515 | |
| 1516 | origin_field_offsets.insert(std::pair<const FieldDecl *, uint64_t>(*fi, field_offset)); |
| 1517 | |
| 1518 | field_idx++; |
| 1519 | } |
| 1520 | |
| 1521 | ASTContext &parser_ast_context(record->getASTContext()); |
| 1522 | |
| 1523 | DeclFromUser <const CXXRecordDecl> origin_cxx_record(DynCast<const CXXRecordDecl>(origin_record)); |
| 1524 | |
| 1525 | if (origin_cxx_record.IsValid()) |
| 1526 | { |
| 1527 | if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record, origin_base_offsets) || |
| 1528 | !ExtractBaseOffsets<true>(record_layout, origin_cxx_record, origin_virtual_base_offsets)) |
| 1529 | return false; |
| 1530 | } |
| 1531 | |
| 1532 | if (!ImportOffsetMap(field_offsets, origin_field_offsets, m_ast_importer, parser_ast_context) || |
| 1533 | !ImportOffsetMap(base_offsets, origin_base_offsets, m_ast_importer, parser_ast_context) || |
| 1534 | !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, m_ast_importer, parser_ast_context)) |
| 1535 | return false; |
| 1536 | |
| 1537 | size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth(); |
| 1538 | alignment = record_layout.getAlignment().getQuantity() * m_ast_context->getCharWidth(); |
| 1539 | |
| 1540 | if (log) |
| 1541 | { |
| 1542 | log->Printf("LRT[%u] returned:", current_id); |
| 1543 | log->Printf("LRT[%u] Original = (RecordDecl*)%p", current_id, origin_record.decl); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1544 | log->Printf("LRT[%u] Size = %" PRId64, current_id, size); |
| 1545 | log->Printf("LRT[%u] Alignment = %" PRId64, current_id, alignment); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1546 | log->Printf("LRT[%u] Fields:", current_id); |
| 1547 | for (RecordDecl::field_iterator fi = record->field_begin(), fe = record->field_end(); |
| 1548 | fi != fe; |
| 1549 | ++fi) |
| 1550 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1551 | log->Printf("LRT[%u] (FieldDecl*)%p, Name = '%s', Offset = %" PRId64 " bits", |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1552 | current_id, |
| 1553 | *fi, |
| 1554 | fi->getNameAsString().c_str(), |
| 1555 | field_offsets[*fi]); |
| 1556 | } |
| 1557 | DeclFromParser <const CXXRecordDecl> parser_cxx_record = DynCast<const CXXRecordDecl>(parser_record); |
| 1558 | if (parser_cxx_record.IsValid()) |
| 1559 | { |
| 1560 | log->Printf("LRT[%u] Bases:", current_id); |
| 1561 | for (CXXRecordDecl::base_class_const_iterator bi = parser_cxx_record->bases_begin(), be = parser_cxx_record->bases_end(); |
| 1562 | bi != be; |
| 1563 | ++bi) |
| 1564 | { |
| 1565 | bool is_virtual = bi->isVirtual(); |
| 1566 | |
| 1567 | QualType base_type = bi->getType(); |
| 1568 | const RecordType *base_record_type = base_type->getAs<RecordType>(); |
| 1569 | DeclFromParser <RecordDecl> base_record(base_record_type->getDecl()); |
| 1570 | DeclFromParser <CXXRecordDecl> base_cxx_record = DynCast<CXXRecordDecl>(base_record); |
| 1571 | |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1572 | log->Printf("LRT[%u] %s(CXXRecordDecl*)%p, Name = '%s', Offset = %" PRId64 " chars", |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1573 | current_id, |
| 1574 | (is_virtual ? "Virtual " : ""), |
| 1575 | base_cxx_record.decl, |
| 1576 | base_cxx_record.decl->getNameAsString().c_str(), |
| 1577 | (is_virtual ? virtual_base_offsets[base_cxx_record.decl].getQuantity() : |
| 1578 | base_offsets[base_cxx_record.decl].getQuantity())); |
| 1579 | } |
| 1580 | } |
| 1581 | else |
| 1582 | { |
| 1583 | log->Printf("LRD[%u] Not a CXXRecord, so no bases", current_id); |
| 1584 | } |
| 1585 | } |
| 1586 | |
| 1587 | return true; |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1590 | void |
| 1591 | ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, |
| 1592 | const ConstString &name, |
| 1593 | ClangASTImporter::NamespaceMapSP &parent_map) const |
| 1594 | { |
| 1595 | static unsigned int invocation_id = 0; |
| 1596 | unsigned int current_id = invocation_id++; |
| 1597 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1598 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1599 | |
| 1600 | if (log) |
| 1601 | { |
| 1602 | if (parent_map && parent_map->size()) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1603 | log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s", |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1604 | current_id, |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1605 | m_ast_context, |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1606 | name.GetCString(), |
| 1607 | parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str()); |
| 1608 | else |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1609 | log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s", |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1610 | current_id, |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1611 | m_ast_context, |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1612 | name.GetCString()); |
| 1613 | } |
| 1614 | |
| 1615 | |
| 1616 | if (parent_map) |
| 1617 | { |
| 1618 | for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end(); |
| 1619 | i != e; |
| 1620 | ++i) |
| 1621 | { |
| 1622 | ClangNamespaceDecl found_namespace_decl; |
| 1623 | |
| 1624 | lldb::ModuleSP module_sp = i->first; |
| 1625 | ClangNamespaceDecl module_parent_namespace_decl = i->second; |
| 1626 | |
| 1627 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 1628 | |
| 1629 | if (!symbol_vendor) |
| 1630 | continue; |
| 1631 | |
| 1632 | SymbolContext null_sc; |
| 1633 | |
| 1634 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl); |
| 1635 | |
| 1636 | if (!found_namespace_decl) |
| 1637 | continue; |
| 1638 | |
| 1639 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 1640 | |
| 1641 | if (log) |
| 1642 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 1643 | current_id, |
| 1644 | name.GetCString(), |
| 1645 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 1646 | } |
| 1647 | } |
| 1648 | else |
| 1649 | { |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1650 | const ModuleList &target_images = m_target->GetImages(); |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 1651 | Mutex::Locker modules_locker(target_images.GetMutex()); |
| 1652 | |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1653 | ClangNamespaceDecl null_namespace_decl; |
| 1654 | |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 1655 | for (size_t i = 0, e = target_images.GetSize(); i < e; ++i) |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1656 | { |
Jim Ingham | 3ee12ef | 2012-05-30 02:19:25 +0000 | [diff] [blame] | 1657 | lldb::ModuleSP image = target_images.GetModuleAtIndexUnlocked(i); |
Sean Callanan | 1ee44b7 | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 1658 | |
| 1659 | if (!image) |
| 1660 | continue; |
| 1661 | |
| 1662 | ClangNamespaceDecl found_namespace_decl; |
| 1663 | |
| 1664 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 1665 | |
| 1666 | if (!symbol_vendor) |
| 1667 | continue; |
| 1668 | |
| 1669 | SymbolContext null_sc; |
| 1670 | |
| 1671 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl); |
| 1672 | |
| 1673 | if (!found_namespace_decl) |
| 1674 | continue; |
| 1675 | |
| 1676 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 1677 | |
| 1678 | if (log) |
| 1679 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 1680 | current_id, |
| 1681 | name.GetCString(), |
| 1682 | image->GetFileSpec().GetFilename().GetCString()); |
| 1683 | } |
| 1684 | } |
| 1685 | } |
| 1686 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1687 | NamespaceDecl * |
| 1688 | ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls) |
| 1689 | { |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 1690 | if (!namespace_decls) |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1691 | return NULL; |
| 1692 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1693 | const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; |
| 1694 | |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 1695 | Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl()); |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1696 | |
Sean Callanan | 61b33f7 | 2012-03-20 21:11:12 +0000 | [diff] [blame] | 1697 | if (!copied_decl) |
| 1698 | return NULL; |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 1699 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1700 | NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); |
| 1701 | |
Sean Callanan | eeffea4 | 2013-02-12 08:01:13 +0000 | [diff] [blame] | 1702 | if (!copied_namespace_decl) |
| 1703 | return NULL; |
| 1704 | |
| 1705 | context.m_decls.push_back(copied_namespace_decl); |
| 1706 | |
Sean Callanan | ba0aca7 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 1707 | m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); |
| 1708 | |
| 1709 | return dyn_cast<NamespaceDecl>(copied_decl); |
| 1710 | } |
| 1711 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1712 | ClangASTType |
| 1713 | ClangASTSource::GuardedCopyType (const ClangASTType &src_type) |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 1714 | { |
| 1715 | ClangASTMetrics::RegisterLLDBImport(); |
| 1716 | |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1717 | SetImportInProgress(true); |
| 1718 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1719 | QualType copied_qual_type = m_ast_importer->CopyType (m_ast_context, src_type.GetASTContext(), src_type.GetQualType()); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1720 | |
| 1721 | SetImportInProgress(false); |
| 1722 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1723 | if (copied_qual_type.getAsOpaquePtr() && copied_qual_type->getCanonicalTypeInternal().isNull()) |
Sean Callanan | 8b66598 | 2012-02-27 19:22:39 +0000 | [diff] [blame] | 1724 | // this shouldn't happen, but we're hardening because the AST importer seems to be generating bad types |
| 1725 | // on occasion. |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1726 | return ClangASTType(); |
Sean Callanan | 8b66598 | 2012-02-27 19:22:39 +0000 | [diff] [blame] | 1727 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1728 | return ClangASTType(m_ast_context, copied_qual_type); |
Sean Callanan | fb3e430 | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1731 | clang::NamedDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1732 | NameSearchContext::AddVarDecl(const ClangASTType &type) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1733 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1734 | assert (type && "Type for variable must be valid!"); |
| 1735 | |
| 1736 | if (!type.IsValid()) |
| 1737 | return NULL; |
| 1738 | |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1739 | IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo(); |
Sean Callanan | 348b589 | 2010-11-30 00:27:43 +0000 | [diff] [blame] | 1740 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1741 | clang::ASTContext *ast = type.GetASTContext(); |
| 1742 | |
| 1743 | clang::NamedDecl *Decl = VarDecl::Create(*ast, |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1744 | const_cast<DeclContext*>(m_decl_context), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1745 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1746 | SourceLocation(), |
Sean Callanan | 44096b1 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 1747 | ii, |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1748 | type.GetQualType(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1749 | 0, |
Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 1750 | SC_Static); |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1751 | m_decls.push_back(Decl); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1752 | |
| 1753 | return Decl; |
| 1754 | } |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1755 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1756 | clang::NamedDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1757 | NameSearchContext::AddFunDecl (const ClangASTType &type) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1758 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1759 | assert (type && "Type for variable must be valid!"); |
Sean Callanan | e2d4748 | 2012-03-21 17:13:20 +0000 | [diff] [blame] | 1760 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1761 | if (!type.IsValid()) |
| 1762 | return NULL; |
| 1763 | |
Sean Callanan | 485f732 | 2013-04-24 00:34:41 +0000 | [diff] [blame] | 1764 | if (m_function_types.count(type)) |
| 1765 | return NULL; |
| 1766 | |
| 1767 | m_function_types.insert(type); |
| 1768 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1769 | QualType qual_type (type.GetQualType()); |
| 1770 | |
| 1771 | clang::ASTContext *ast = type.GetASTContext(); |
| 1772 | |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1773 | const bool isInlineSpecified = false; |
| 1774 | const bool hasWrittenPrototype = true; |
| 1775 | const bool isConstexprSpecified = false; |
| 1776 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1777 | clang::FunctionDecl *func_decl = FunctionDecl::Create (*ast, |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1778 | const_cast<DeclContext*>(m_decl_context), |
| 1779 | SourceLocation(), |
Jim Ingham | 6843e59 | 2013-06-28 22:21:22 +0000 | [diff] [blame] | 1780 | SourceLocation(), |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1781 | m_decl_name.getAsIdentifierInfo(), |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1782 | qual_type, |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1783 | NULL, |
| 1784 | SC_Static, |
Greg Clayton | 0d55104 | 2013-06-28 21:08:47 +0000 | [diff] [blame] | 1785 | isInlineSpecified, |
| 1786 | hasWrittenPrototype, |
| 1787 | isConstexprSpecified); |
| 1788 | |
Sean Callanan | 04949cc | 2010-08-12 23:45:38 +0000 | [diff] [blame] | 1789 | // We have to do more than just synthesize the FunctionDecl. We have to |
| 1790 | // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do |
| 1791 | // this, we raid the function's FunctionProtoType for types. |
| 1792 | |
Sean Callanan | fc4f2fb | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1793 | const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>(); |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1794 | |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1795 | if (func_proto_type) |
Sean Callanan | d448c1b | 2010-06-23 18:58:10 +0000 | [diff] [blame] | 1796 | { |
Alp Toker | f747ff1 | 2014-01-20 21:14:57 +0000 | [diff] [blame] | 1797 | unsigned NumArgs = func_proto_type->getNumParams(); |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1798 | unsigned ArgIndex; |
| 1799 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1800 | SmallVector<ParmVarDecl *, 5> parm_var_decls; |
| 1801 | |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1802 | for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex) |
| 1803 | { |
Alp Toker | f747ff1 | 2014-01-20 21:14:57 +0000 | [diff] [blame] | 1804 | QualType arg_qual_type (func_proto_type->getParamType(ArgIndex)); |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1805 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1806 | parm_var_decls.push_back(ParmVarDecl::Create (*ast, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1807 | const_cast<DeclContext*>(m_decl_context), |
| 1808 | SourceLocation(), |
| 1809 | SourceLocation(), |
| 1810 | NULL, |
| 1811 | arg_qual_type, |
| 1812 | NULL, |
| 1813 | SC_Static, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1814 | NULL)); |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1815 | } |
| 1816 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1817 | func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls)); |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1818 | } |
Sean Callanan | e0a64f7 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 1819 | else |
| 1820 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1821 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | e0a64f7 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 1822 | |
Sean Callanan | 8ef1977 | 2013-04-25 18:50:43 +0000 | [diff] [blame] | 1823 | if (log) |
| 1824 | log->Printf("Function type wasn't a FunctionProtoType"); |
Sean Callanan | e0a64f7 | 2011-12-01 21:04:37 +0000 | [diff] [blame] | 1825 | } |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1826 | |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1827 | m_decls.push_back(func_decl); |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1828 | |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1829 | return func_decl; |
Sean Callanan | 468574b | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 1830 | } |
Sean Callanan | 8ade104 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1831 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1832 | clang::NamedDecl * |
| 1833 | NameSearchContext::AddGenericFunDecl() |
Sean Callanan | 8ade104 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1834 | { |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1835 | FunctionProtoType::ExtProtoInfo proto_info; |
| 1836 | |
| 1837 | proto_info.Variadic = true; |
| 1838 | |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1839 | QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result |
Sylvestre Ledru | 1573b1b | 2013-03-10 20:13:16 +0000 | [diff] [blame] | 1840 | ArrayRef<QualType>(), // argument types |
Sean Callanan | eddeb3b | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 1841 | proto_info)); |
Greg Clayton | 7b462cc | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 1842 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1843 | return AddFunDecl(ClangASTType (m_ast_source.m_ast_context, generic_function_type)); |
Sean Callanan | 8ade104 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 1844 | } |
Sean Callanan | 5666b67 | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1845 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1846 | clang::NamedDecl * |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1847 | NameSearchContext::AddTypeDecl(const ClangASTType &clang_type) |
Sean Callanan | 5666b67 | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1848 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1849 | if (clang_type) |
Greg Clayton | 1b03cb5 | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1850 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1851 | QualType qual_type = clang_type.GetQualType(); |
Sean Callanan | 5666b67 | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1852 | |
Sean Callanan | 6b2f22d | 2013-06-25 22:36:17 +0000 | [diff] [blame] | 1853 | if (const TypedefType *typedef_type = llvm::dyn_cast<TypedefType>(qual_type)) |
| 1854 | { |
| 1855 | TypedefNameDecl *typedef_name_decl = typedef_type->getDecl(); |
| 1856 | |
| 1857 | m_decls.push_back(typedef_name_decl); |
| 1858 | |
| 1859 | return (NamedDecl*)typedef_name_decl; |
| 1860 | } |
| 1861 | else if (const TagType *tag_type = qual_type->getAs<TagType>()) |
Greg Clayton | 1b03cb5 | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1862 | { |
| 1863 | TagDecl *tag_decl = tag_type->getDecl(); |
| 1864 | |
| 1865 | m_decls.push_back(tag_decl); |
| 1866 | |
| 1867 | return tag_decl; |
| 1868 | } |
Sean Callanan | fc4f2fb | 2011-12-14 01:13:04 +0000 | [diff] [blame] | 1869 | else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>()) |
Greg Clayton | 1b03cb5 | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1870 | { |
| 1871 | ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface(); |
| 1872 | |
| 1873 | m_decls.push_back((NamedDecl*)interface_decl); |
| 1874 | |
| 1875 | return (NamedDecl*)interface_decl; |
| 1876 | } |
Sean Callanan | 5666b67 | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1877 | } |
Greg Clayton | 1b03cb5 | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 1878 | return NULL; |
Sean Callanan | 5666b67 | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 1879 | } |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 1880 | |
| 1881 | void |
| 1882 | NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result) |
| 1883 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1884 | for (clang::NamedDecl *decl : result) |
| 1885 | m_decls.push_back (decl); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | void |
| 1889 | NameSearchContext::AddNamedDecl (clang::NamedDecl *decl) |
| 1890 | { |
| 1891 | m_decls.push_back (decl); |
| 1892 | } |