Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 1 | //===-- ClangASTImporter.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 | |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 10 | #include "lldb/Symbol/ClangASTImporter.h" |
| 11 | #include "lldb/Core/Log.h" |
| 12 | #include "lldb/Core/Module.h" |
| 13 | #include "lldb/Symbol/ClangASTContext.h" |
| 14 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
| 15 | #include "lldb/Symbol/ClangUtil.h" |
| 16 | #include "lldb/Utility/LLDBAssert.h" |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclObjC.h" |
Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace lldb_private; |
| 23 | using namespace clang; |
| 24 | |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 25 | ClangASTMetrics::Counters ClangASTMetrics::global_counters = { 0, 0, 0, 0, 0, 0 }; |
| 26 | ClangASTMetrics::Counters ClangASTMetrics::local_counters = { 0, 0, 0, 0, 0, 0 }; |
| 27 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 28 | void ClangASTMetrics::DumpCounters (Log *log, ClangASTMetrics::Counters &counters) |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 29 | { |
Matt Kopec | 787d162 | 2013-03-12 17:45:38 +0000 | [diff] [blame] | 30 | log->Printf(" Number of visible Decl queries by name : %" PRIu64, counters.m_visible_query_count); |
| 31 | log->Printf(" Number of lexical Decl queries : %" PRIu64, counters.m_lexical_query_count); |
| 32 | log->Printf(" Number of imports initiated by LLDB : %" PRIu64, counters.m_lldb_import_count); |
| 33 | log->Printf(" Number of imports conducted by Clang : %" PRIu64, counters.m_clang_import_count); |
| 34 | log->Printf(" Number of Decls completed : %" PRIu64, counters.m_decls_completed_count); |
| 35 | log->Printf(" Number of records laid out : %" PRIu64, counters.m_record_layout_count); |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 38 | void ClangASTMetrics::DumpCounters (Log *log) |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 39 | { |
| 40 | if (!log) |
| 41 | return; |
| 42 | |
| 43 | log->Printf("== ClangASTMetrics output =="); |
| 44 | log->Printf("-- Global metrics --"); |
| 45 | DumpCounters (log, global_counters); |
| 46 | log->Printf("-- Local metrics --"); |
| 47 | DumpCounters (log, local_counters); |
| 48 | } |
| 49 | |
| 50 | clang::QualType |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 51 | ClangASTImporter::CopyType (clang::ASTContext *dst_ast, |
| 52 | clang::ASTContext *src_ast, |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 53 | clang::QualType type) |
| 54 | { |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 55 | MinionSP minion_sp (GetMinion(dst_ast, src_ast)); |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 56 | |
Greg Clayton | dd0649b | 2011-07-06 18:55:08 +0000 | [diff] [blame] | 57 | if (minion_sp) |
| 58 | return minion_sp->Import(type); |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 59 | |
Greg Clayton | dd0649b | 2011-07-06 18:55:08 +0000 | [diff] [blame] | 60 | return QualType(); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Bruce Mitchener | 23a3b0e | 2015-09-22 17:04:24 +0000 | [diff] [blame] | 63 | lldb::opaque_compiler_type_t |
Sean Callanan | 80f7867 | 2011-11-16 19:07:39 +0000 | [diff] [blame] | 64 | ClangASTImporter::CopyType (clang::ASTContext *dst_ast, |
| 65 | clang::ASTContext *src_ast, |
Bruce Mitchener | 23a3b0e | 2015-09-22 17:04:24 +0000 | [diff] [blame] | 66 | lldb::opaque_compiler_type_t type) |
Sean Callanan | 80f7867 | 2011-11-16 19:07:39 +0000 | [diff] [blame] | 67 | { |
| 68 | return CopyType (dst_ast, src_ast, QualType::getFromOpaquePtr(type)).getAsOpaquePtr(); |
| 69 | } |
| 70 | |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 71 | CompilerType |
| 72 | ClangASTImporter::CopyType (ClangASTContext &dst_ast, |
| 73 | const CompilerType &src_type) |
| 74 | { |
| 75 | clang::ASTContext *dst_clang_ast = dst_ast.getASTContext(); |
| 76 | if (dst_clang_ast) |
| 77 | { |
| 78 | ClangASTContext *src_ast = llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem()); |
| 79 | if (src_ast) |
| 80 | { |
| 81 | clang::ASTContext *src_clang_ast = src_ast->getASTContext(); |
| 82 | if (src_clang_ast) |
| 83 | { |
| 84 | lldb::opaque_compiler_type_t dst_clang_type = CopyType(dst_clang_ast, |
| 85 | src_clang_ast, |
| 86 | src_type.GetOpaqueQualType()); |
| 87 | |
| 88 | if (dst_clang_type) |
| 89 | return CompilerType(&dst_ast, dst_clang_type); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | return CompilerType(); |
| 94 | } |
| 95 | |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 96 | clang::Decl * |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 97 | ClangASTImporter::CopyDecl (clang::ASTContext *dst_ast, |
| 98 | clang::ASTContext *src_ast, |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 99 | clang::Decl *decl) |
| 100 | { |
Greg Clayton | dd0649b | 2011-07-06 18:55:08 +0000 | [diff] [blame] | 101 | MinionSP minion_sp; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 102 | |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 103 | minion_sp = GetMinion(dst_ast, src_ast); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 104 | |
Greg Clayton | dd0649b | 2011-07-06 18:55:08 +0000 | [diff] [blame] | 105 | if (minion_sp) |
Sean Callanan | bfb237bc | 2011-11-04 22:46:46 +0000 | [diff] [blame] | 106 | { |
| 107 | clang::Decl *result = minion_sp->Import(decl); |
| 108 | |
| 109 | if (!result) |
| 110 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 111 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | bfb237bc | 2011-11-04 22:46:46 +0000 | [diff] [blame] | 112 | |
Sean Callanan | d5145b3 | 2011-11-05 00:08:12 +0000 | [diff] [blame] | 113 | if (log) |
| 114 | { |
Jason Molenda | 900dbdc | 2014-10-15 23:27:12 +0000 | [diff] [blame] | 115 | lldb::user_id_t user_id = LLDB_INVALID_UID; |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 116 | ClangASTMetadata *metadata = GetDeclMetadata(decl); |
| 117 | if (metadata) |
| 118 | user_id = metadata->GetUserID(); |
| 119 | |
Sean Callanan | d5145b3 | 2011-11-05 00:08:12 +0000 | [diff] [blame] | 120 | if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl)) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 121 | log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s '%s', metadata 0x%" PRIx64, |
Sean Callanan | d9804fb | 2012-04-17 22:30:04 +0000 | [diff] [blame] | 122 | decl->getDeclKindName(), |
| 123 | named_decl->getNameAsString().c_str(), |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 124 | user_id); |
Sean Callanan | d5145b3 | 2011-11-05 00:08:12 +0000 | [diff] [blame] | 125 | else |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 126 | log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s, metadata 0x%" PRIx64, |
Sean Callanan | d9804fb | 2012-04-17 22:30:04 +0000 | [diff] [blame] | 127 | decl->getDeclKindName(), |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 128 | user_id); |
Sean Callanan | d5145b3 | 2011-11-05 00:08:12 +0000 | [diff] [blame] | 129 | } |
Sean Callanan | bfb237bc | 2011-11-04 22:46:46 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | return result; |
| 133 | } |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 134 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 135 | return nullptr; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Sean Callanan | 83b8ad0 | 2015-07-08 18:03:41 +0000 | [diff] [blame] | 138 | class DeclContextOverride |
| 139 | { |
| 140 | private: |
| 141 | struct Backup |
| 142 | { |
| 143 | clang::DeclContext *decl_context; |
| 144 | clang::DeclContext *lexical_decl_context; |
| 145 | }; |
| 146 | |
| 147 | std::map<clang::Decl *, Backup> m_backups; |
| 148 | |
| 149 | void OverrideOne(clang::Decl *decl) |
| 150 | { |
| 151 | if (m_backups.find(decl) != m_backups.end()) |
| 152 | { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | m_backups[decl] = { decl->getDeclContext(), decl->getLexicalDeclContext() }; |
| 157 | |
| 158 | decl->setDeclContext(decl->getASTContext().getTranslationUnitDecl()); |
| 159 | decl->setLexicalDeclContext(decl->getASTContext().getTranslationUnitDecl()); |
| 160 | } |
| 161 | |
| 162 | bool ChainPassesThrough(clang::Decl *decl, |
| 163 | clang::DeclContext *base, |
| 164 | clang::DeclContext *(clang::Decl::*contextFromDecl)(), |
| 165 | clang::DeclContext *(clang::DeclContext::*contextFromContext)()) |
| 166 | { |
| 167 | for (DeclContext *decl_ctx = (decl->*contextFromDecl)(); |
| 168 | decl_ctx; |
| 169 | decl_ctx = (decl_ctx->*contextFromContext)()) |
| 170 | { |
| 171 | if (decl_ctx == base) |
| 172 | { |
| 173 | return true; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | clang::Decl *GetEscapedChild(clang::Decl *decl, clang::DeclContext *base = nullptr) |
| 181 | { |
| 182 | if (base) |
| 183 | { |
| 184 | // decl's DeclContext chains must pass through base. |
| 185 | |
| 186 | if (!ChainPassesThrough(decl, base, &clang::Decl::getDeclContext, &clang::DeclContext::getParent) || |
| 187 | !ChainPassesThrough(decl, base, &clang::Decl::getLexicalDeclContext, &clang::DeclContext::getLexicalParent)) |
| 188 | { |
| 189 | return decl; |
| 190 | } |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | base = clang::dyn_cast<clang::DeclContext>(decl); |
| 195 | |
| 196 | if (!base) |
| 197 | { |
| 198 | return nullptr; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (clang::DeclContext *context = clang::dyn_cast<clang::DeclContext>(decl)) |
| 203 | { |
| 204 | for (clang::Decl *decl : context->decls()) |
| 205 | { |
| 206 | if (clang::Decl *escaped_child = GetEscapedChild(decl)) |
| 207 | { |
| 208 | return escaped_child; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | return nullptr; |
| 214 | } |
| 215 | |
| 216 | void Override(clang::Decl *decl) |
| 217 | { |
| 218 | if (clang::Decl *escaped_child = GetEscapedChild(decl)) |
| 219 | { |
| 220 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 221 | |
| 222 | if (log) |
| 223 | log->Printf(" [ClangASTImporter] DeclContextOverride couldn't override (%sDecl*)%p - its child (%sDecl*)%p escapes", |
| 224 | decl->getDeclKindName(), static_cast<void*>(decl), |
| 225 | escaped_child->getDeclKindName(), static_cast<void*>(escaped_child)); |
| 226 | lldbassert(0 && "Couldn't override!"); |
| 227 | } |
| 228 | |
| 229 | OverrideOne(decl); |
| 230 | } |
| 231 | |
| 232 | public: |
| 233 | DeclContextOverride() |
| 234 | { |
| 235 | } |
| 236 | |
| 237 | void OverrideAllDeclsFromContainingFunction(clang::Decl *decl) |
| 238 | { |
| 239 | for (DeclContext *decl_context = decl->getLexicalDeclContext(); |
| 240 | decl_context; |
| 241 | decl_context = decl_context->getLexicalParent()) |
| 242 | { |
| 243 | DeclContext *redecl_context = decl_context->getRedeclContext(); |
| 244 | |
| 245 | if (llvm::isa<FunctionDecl>(redecl_context) && |
| 246 | llvm::isa<TranslationUnitDecl>(redecl_context->getLexicalParent())) |
| 247 | { |
| 248 | for (clang::Decl *child_decl : decl_context->decls()) |
| 249 | { |
| 250 | Override(child_decl); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | ~DeclContextOverride() |
| 257 | { |
| 258 | for (const std::pair<clang::Decl *, Backup> &backup : m_backups) |
| 259 | { |
| 260 | backup.first->setDeclContext(backup.second.decl_context); |
| 261 | backup.first->setLexicalDeclContext(backup.second.lexical_decl_context); |
| 262 | } |
| 263 | } |
| 264 | }; |
| 265 | |
Bruce Mitchener | 23a3b0e | 2015-09-22 17:04:24 +0000 | [diff] [blame] | 266 | lldb::opaque_compiler_type_t |
Sean Callanan | bb12004 | 2011-12-16 21:06:35 +0000 | [diff] [blame] | 267 | ClangASTImporter::DeportType (clang::ASTContext *dst_ctx, |
| 268 | clang::ASTContext *src_ctx, |
Bruce Mitchener | 23a3b0e | 2015-09-22 17:04:24 +0000 | [diff] [blame] | 269 | lldb::opaque_compiler_type_t type) |
Sean Callanan | 4a2a71f | 2015-09-02 16:39:23 +0000 | [diff] [blame] | 270 | { |
| 271 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 272 | |
| 273 | if (log) |
| 274 | log->Printf(" [ClangASTImporter] DeportType called on (%sType*)0x%llx from (ASTContext*)%p to (ASTContext*)%p", |
| 275 | QualType::getFromOpaquePtr(type)->getTypeClassName(), (unsigned long long)type, |
| 276 | static_cast<void*>(src_ctx), |
| 277 | static_cast<void*>(dst_ctx)); |
| 278 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 279 | MinionSP minion_sp (GetMinion (dst_ctx, src_ctx)); |
| 280 | |
| 281 | if (!minion_sp) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 282 | return nullptr; |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 283 | |
| 284 | std::set<NamedDecl *> decls_to_deport; |
| 285 | std::set<NamedDecl *> decls_already_deported; |
| 286 | |
Sean Callanan | 83b8ad0 | 2015-07-08 18:03:41 +0000 | [diff] [blame] | 287 | DeclContextOverride decl_context_override; |
| 288 | |
| 289 | if (const clang::TagType *tag_type = clang::QualType::getFromOpaquePtr(type)->getAs<TagType>()) |
| 290 | { |
| 291 | decl_context_override.OverrideAllDeclsFromContainingFunction(tag_type->getDecl()); |
| 292 | } |
| 293 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 294 | minion_sp->InitDeportWorkQueues(&decls_to_deport, |
| 295 | &decls_already_deported); |
| 296 | |
Bruce Mitchener | 23a3b0e | 2015-09-22 17:04:24 +0000 | [diff] [blame] | 297 | lldb::opaque_compiler_type_t result = CopyType(dst_ctx, src_ctx, type); |
Sean Callanan | bb12004 | 2011-12-16 21:06:35 +0000 | [diff] [blame] | 298 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 299 | minion_sp->ExecuteDeportWorkQueues(); |
| 300 | |
Sean Callanan | bb12004 | 2011-12-16 21:06:35 +0000 | [diff] [blame] | 301 | if (!result) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 302 | return nullptr; |
Sean Callanan | bb12004 | 2011-12-16 21:06:35 +0000 | [diff] [blame] | 303 | |
Sean Callanan | bb12004 | 2011-12-16 21:06:35 +0000 | [diff] [blame] | 304 | return result; |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 305 | |
Sean Callanan | bb12004 | 2011-12-16 21:06:35 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 308 | clang::Decl * |
| 309 | ClangASTImporter::DeportDecl (clang::ASTContext *dst_ctx, |
| 310 | clang::ASTContext *src_ctx, |
| 311 | clang::Decl *decl) |
| 312 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 313 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 314 | |
Sean Callanan | 933ca2e | 2013-02-28 03:12:58 +0000 | [diff] [blame] | 315 | if (log) |
Sean Callanan | 4a2a71f | 2015-09-02 16:39:23 +0000 | [diff] [blame] | 316 | log->Printf(" [ClangASTImporter] DeportDecl called on (%sDecl*)%p from (ASTContext*)%p to (ASTContext*)%p", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 317 | decl->getDeclKindName(), static_cast<void*>(decl), |
| 318 | static_cast<void*>(src_ctx), |
| 319 | static_cast<void*>(dst_ctx)); |
| 320 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 321 | MinionSP minion_sp (GetMinion (dst_ctx, src_ctx)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 322 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 323 | if (!minion_sp) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 324 | return nullptr; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 325 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 326 | std::set<NamedDecl *> decls_to_deport; |
| 327 | std::set<NamedDecl *> decls_already_deported; |
Sean Callanan | 83b8ad0 | 2015-07-08 18:03:41 +0000 | [diff] [blame] | 328 | |
| 329 | DeclContextOverride decl_context_override; |
| 330 | |
| 331 | decl_context_override.OverrideAllDeclsFromContainingFunction(decl); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 332 | |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 333 | minion_sp->InitDeportWorkQueues(&decls_to_deport, |
| 334 | &decls_already_deported); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 335 | |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 336 | clang::Decl *result = CopyDecl(dst_ctx, src_ctx, decl); |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 337 | |
| 338 | minion_sp->ExecuteDeportWorkQueues(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 339 | |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 340 | if (!result) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 341 | return nullptr; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 342 | |
Sean Callanan | 933ca2e | 2013-02-28 03:12:58 +0000 | [diff] [blame] | 343 | if (log) |
| 344 | log->Printf(" [ClangASTImporter] DeportDecl deported (%sDecl*)%p to (%sDecl*)%p", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 345 | decl->getDeclKindName(), static_cast<void*>(decl), |
| 346 | result->getDeclKindName(), static_cast<void*>(result)); |
| 347 | |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 348 | return result; |
| 349 | } |
| 350 | |
Zachary Turner | d133f6a | 2016-03-28 22:53:41 +0000 | [diff] [blame] | 351 | bool |
| 352 | ClangASTImporter::CanImport(const CompilerType &type) |
| 353 | { |
| 354 | if (!ClangUtil::IsClangType(type)) |
| 355 | return false; |
| 356 | |
| 357 | // TODO: remove external completion BOOL |
| 358 | // CompleteAndFetchChildren should get the Decl out and check for the |
| 359 | |
| 360 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(ClangUtil::RemoveFastQualifiers(type))); |
| 361 | |
| 362 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 363 | switch (type_class) |
| 364 | { |
| 365 | case clang::Type::Record: |
| 366 | { |
| 367 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 368 | if (cxx_record_decl) |
| 369 | { |
| 370 | if (ResolveDeclOrigin(cxx_record_decl, NULL, NULL)) |
| 371 | return true; |
| 372 | } |
| 373 | } |
| 374 | break; |
| 375 | |
| 376 | case clang::Type::Enum: |
| 377 | { |
| 378 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 379 | if (enum_decl) |
| 380 | { |
| 381 | if (ResolveDeclOrigin(enum_decl, NULL, NULL)) |
| 382 | return true; |
| 383 | } |
| 384 | } |
| 385 | break; |
| 386 | |
| 387 | case clang::Type::ObjCObject: |
| 388 | case clang::Type::ObjCInterface: |
| 389 | { |
| 390 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 391 | if (objc_class_type) |
| 392 | { |
| 393 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 394 | // We currently can't complete objective C types through the newly added ASTContext |
| 395 | // because it only supports TagDecl objects right now... |
| 396 | if (class_interface_decl) |
| 397 | { |
| 398 | if (ResolveDeclOrigin(class_interface_decl, NULL, NULL)) |
| 399 | return true; |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | break; |
| 404 | |
| 405 | case clang::Type::Typedef: |
| 406 | return CanImport(CompilerType( |
| 407 | type.GetTypeSystem(), |
| 408 | llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr())); |
| 409 | |
| 410 | case clang::Type::Auto: |
| 411 | return CanImport(CompilerType(type.GetTypeSystem(), |
| 412 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr())); |
| 413 | |
| 414 | case clang::Type::Elaborated: |
| 415 | return CanImport(CompilerType( |
| 416 | type.GetTypeSystem(), llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr())); |
| 417 | |
| 418 | case clang::Type::Paren: |
| 419 | return CanImport(CompilerType(type.GetTypeSystem(), |
| 420 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); |
| 421 | |
| 422 | default: |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | bool |
| 430 | ClangASTImporter::Import(const CompilerType &type) |
| 431 | { |
| 432 | if (!ClangUtil::IsClangType(type)) |
| 433 | return false; |
| 434 | // TODO: remove external completion BOOL |
| 435 | // CompleteAndFetchChildren should get the Decl out and check for the |
| 436 | |
| 437 | clang::QualType qual_type(ClangUtil::GetCanonicalQualType(ClangUtil::RemoveFastQualifiers(type))); |
| 438 | |
| 439 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 440 | switch (type_class) |
| 441 | { |
| 442 | case clang::Type::Record: |
| 443 | { |
| 444 | const clang::CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 445 | if (cxx_record_decl) |
| 446 | { |
| 447 | if (ResolveDeclOrigin(cxx_record_decl, NULL, NULL)) |
| 448 | return CompleteAndFetchChildren(qual_type); |
| 449 | } |
| 450 | } |
| 451 | break; |
| 452 | |
| 453 | case clang::Type::Enum: |
| 454 | { |
| 455 | clang::EnumDecl *enum_decl = llvm::cast<clang::EnumType>(qual_type)->getDecl(); |
| 456 | if (enum_decl) |
| 457 | { |
| 458 | if (ResolveDeclOrigin(enum_decl, NULL, NULL)) |
| 459 | return CompleteAndFetchChildren(qual_type); |
| 460 | } |
| 461 | } |
| 462 | break; |
| 463 | |
| 464 | case clang::Type::ObjCObject: |
| 465 | case clang::Type::ObjCInterface: |
| 466 | { |
| 467 | const clang::ObjCObjectType *objc_class_type = llvm::dyn_cast<clang::ObjCObjectType>(qual_type); |
| 468 | if (objc_class_type) |
| 469 | { |
| 470 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 471 | // We currently can't complete objective C types through the newly added ASTContext |
| 472 | // because it only supports TagDecl objects right now... |
| 473 | if (class_interface_decl) |
| 474 | { |
| 475 | if (ResolveDeclOrigin(class_interface_decl, NULL, NULL)) |
| 476 | return CompleteAndFetchChildren(qual_type); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | break; |
| 481 | |
| 482 | case clang::Type::Typedef: |
| 483 | return Import(CompilerType( |
| 484 | type.GetTypeSystem(), |
| 485 | llvm::cast<clang::TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr())); |
| 486 | |
| 487 | case clang::Type::Auto: |
| 488 | return Import(CompilerType(type.GetTypeSystem(), |
| 489 | llvm::cast<clang::AutoType>(qual_type)->getDeducedType().getAsOpaquePtr())); |
| 490 | |
| 491 | case clang::Type::Elaborated: |
| 492 | return Import(CompilerType(type.GetTypeSystem(), |
| 493 | llvm::cast<clang::ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr())); |
| 494 | |
| 495 | case clang::Type::Paren: |
| 496 | return Import(CompilerType(type.GetTypeSystem(), |
| 497 | llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr())); |
| 498 | |
| 499 | default: |
| 500 | break; |
| 501 | } |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | bool |
| 506 | ClangASTImporter::CompleteType(const CompilerType &compiler_type) |
| 507 | { |
| 508 | if (!CanImport(compiler_type)) |
| 509 | return false; |
| 510 | |
| 511 | if (Import(compiler_type)) |
| 512 | { |
| 513 | ClangASTContext::CompleteTagDeclarationDefinition(compiler_type); |
| 514 | return true; |
| 515 | } |
| 516 | |
| 517 | ClangASTContext::SetHasExternalStorage(compiler_type.GetOpaqueQualType(), false); |
| 518 | return false; |
| 519 | } |
| 520 | |
| 521 | bool |
| 522 | ClangASTImporter::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, |
| 523 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
| 524 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, |
| 525 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) |
| 526 | { |
| 527 | RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find(record_decl); |
| 528 | bool success = false; |
| 529 | base_offsets.clear(); |
| 530 | vbase_offsets.clear(); |
| 531 | if (pos != m_record_decl_to_layout_map.end()) |
| 532 | { |
| 533 | bit_size = pos->second.bit_size; |
| 534 | alignment = pos->second.alignment; |
| 535 | field_offsets.swap(pos->second.field_offsets); |
| 536 | base_offsets.swap(pos->second.base_offsets); |
| 537 | vbase_offsets.swap(pos->second.vbase_offsets); |
| 538 | m_record_decl_to_layout_map.erase(pos); |
| 539 | success = true; |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | bit_size = 0; |
| 544 | alignment = 0; |
| 545 | field_offsets.clear(); |
| 546 | } |
| 547 | return success; |
| 548 | } |
| 549 | |
| 550 | void |
| 551 | ClangASTImporter::InsertRecordDecl(clang::RecordDecl *decl, const LayoutInfo &layout) |
| 552 | { |
| 553 | m_record_decl_to_layout_map.insert(std::make_pair(decl, layout)); |
| 554 | } |
| 555 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 556 | void |
| 557 | ClangASTImporter::CompleteDecl (clang::Decl *decl) |
| 558 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 559 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 560 | |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 561 | if (log) |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 562 | log->Printf(" [ClangASTImporter] CompleteDecl called on (%sDecl*)%p", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 563 | decl->getDeclKindName(), static_cast<void*>(decl)); |
| 564 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 565 | if (ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl)) |
| 566 | { |
| 567 | if (!interface_decl->getDefinition()) |
| 568 | { |
| 569 | interface_decl->startDefinition(); |
| 570 | CompleteObjCInterfaceDecl(interface_decl); |
| 571 | } |
| 572 | } |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 573 | else if (ObjCProtocolDecl *protocol_decl = dyn_cast<ObjCProtocolDecl>(decl)) |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 574 | { |
| 575 | if (!protocol_decl->getDefinition()) |
| 576 | protocol_decl->startDefinition(); |
| 577 | } |
| 578 | else if (TagDecl *tag_decl = dyn_cast<TagDecl>(decl)) |
| 579 | { |
| 580 | if (!tag_decl->getDefinition() && !tag_decl->isBeingDefined()) |
| 581 | { |
| 582 | tag_decl->startDefinition(); |
| 583 | CompleteTagDecl(tag_decl); |
| 584 | tag_decl->setCompleteDefinition(true); |
| 585 | } |
| 586 | } |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 587 | else |
| 588 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 589 | assert (0 && "CompleteDecl called on a Decl that can't be completed"); |
| 590 | } |
| 591 | } |
| 592 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 593 | bool |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 594 | ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl) |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 595 | { |
| 596 | ClangASTMetrics::RegisterDeclCompletion(); |
| 597 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 598 | DeclOrigin decl_origin = GetDeclOrigin(decl); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 599 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 600 | if (!decl_origin.Valid()) |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 601 | return false; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 602 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 603 | if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 604 | return false; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 605 | |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 606 | MinionSP minion_sp (GetMinion(&decl->getASTContext(), decl_origin.ctx)); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 607 | |
Greg Clayton | dd0649b | 2011-07-06 18:55:08 +0000 | [diff] [blame] | 608 | if (minion_sp) |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 609 | minion_sp->ImportDefinitionTo(decl, decl_origin.decl); |
| 610 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 611 | return true; |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 612 | } |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 613 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 614 | bool |
| 615 | ClangASTImporter::CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin_decl) |
| 616 | { |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 617 | ClangASTMetrics::RegisterDeclCompletion(); |
| 618 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 619 | clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext(); |
| 620 | |
| 621 | if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl)) |
| 622 | return false; |
| 623 | |
| 624 | MinionSP minion_sp (GetMinion(&decl->getASTContext(), origin_ast_ctx)); |
| 625 | |
| 626 | if (minion_sp) |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 627 | minion_sp->ImportDefinitionTo(decl, origin_decl); |
| 628 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 629 | ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); |
| 630 | |
| 631 | OriginMap &origins = context_md->m_origins; |
| 632 | |
| 633 | origins[decl] = DeclOrigin(origin_ast_ctx, origin_decl); |
| 634 | |
| 635 | return true; |
| 636 | } |
| 637 | |
| 638 | bool |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 639 | ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl) |
| 640 | { |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 641 | ClangASTMetrics::RegisterDeclCompletion(); |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 642 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 643 | DeclOrigin decl_origin = GetDeclOrigin(interface_decl); |
| 644 | |
| 645 | if (!decl_origin.Valid()) |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 646 | return false; |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 647 | |
| 648 | if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl)) |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 649 | return false; |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 650 | |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 651 | MinionSP minion_sp (GetMinion(&interface_decl->getASTContext(), decl_origin.ctx)); |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 652 | |
| 653 | if (minion_sp) |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 654 | minion_sp->ImportDefinitionTo(interface_decl, decl_origin.decl); |
Greg Clayton | 6292b30b | 2015-04-13 18:32:54 +0000 | [diff] [blame] | 655 | |
| 656 | if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass()) |
| 657 | RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0)); |
| 658 | |
Sean Callanan | 12014a0 | 2011-12-08 23:45:45 +0000 | [diff] [blame] | 659 | return true; |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Sean Callanan | 6b200d0 | 2013-03-21 22:15:41 +0000 | [diff] [blame] | 662 | bool |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 663 | ClangASTImporter::CompleteAndFetchChildren (clang::QualType type) |
| 664 | { |
| 665 | if (!RequireCompleteType(type)) |
| 666 | return false; |
| 667 | |
| 668 | if (const TagType *tag_type = type->getAs<TagType>()) |
| 669 | { |
| 670 | TagDecl *tag_decl = tag_type->getDecl(); |
| 671 | |
| 672 | DeclOrigin decl_origin = GetDeclOrigin(tag_decl); |
| 673 | |
| 674 | if (!decl_origin.Valid()) |
| 675 | return false; |
| 676 | |
| 677 | MinionSP minion_sp (GetMinion(&tag_decl->getASTContext(), decl_origin.ctx)); |
| 678 | |
| 679 | TagDecl *origin_tag_decl = llvm::dyn_cast<TagDecl>(decl_origin.decl); |
| 680 | |
| 681 | for (Decl *origin_child_decl : origin_tag_decl->decls()) |
| 682 | { |
| 683 | minion_sp->Import(origin_child_decl); |
| 684 | } |
| 685 | |
| 686 | if (RecordDecl *record_decl = dyn_cast<RecordDecl>(origin_tag_decl)) |
| 687 | { |
| 688 | record_decl->setHasLoadedFieldsFromExternalStorage(true); |
| 689 | } |
| 690 | |
| 691 | return true; |
| 692 | } |
| 693 | |
| 694 | if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>()) |
| 695 | { |
| 696 | if (ObjCInterfaceDecl *objc_interface_decl = objc_object_type->getInterface()) |
| 697 | { |
| 698 | DeclOrigin decl_origin = GetDeclOrigin(objc_interface_decl); |
| 699 | |
| 700 | if (!decl_origin.Valid()) |
| 701 | return false; |
| 702 | |
| 703 | MinionSP minion_sp (GetMinion(&objc_interface_decl->getASTContext(), decl_origin.ctx)); |
| 704 | |
| 705 | ObjCInterfaceDecl *origin_interface_decl = llvm::dyn_cast<ObjCInterfaceDecl>(decl_origin.decl); |
| 706 | |
| 707 | for (Decl *origin_child_decl : origin_interface_decl->decls()) |
| 708 | { |
| 709 | minion_sp->Import(origin_child_decl); |
| 710 | } |
| 711 | |
| 712 | return true; |
| 713 | } |
| 714 | else |
| 715 | { |
| 716 | return false; |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | return true; |
| 721 | } |
| 722 | |
| 723 | |
| 724 | bool |
Sean Callanan | 6b200d0 | 2013-03-21 22:15:41 +0000 | [diff] [blame] | 725 | ClangASTImporter::RequireCompleteType (clang::QualType type) |
| 726 | { |
| 727 | if (type.isNull()) |
| 728 | return false; |
| 729 | |
| 730 | if (const TagType *tag_type = type->getAs<TagType>()) |
| 731 | { |
Stephane Sezer | 9901e9c | 2015-04-08 21:52:45 +0000 | [diff] [blame] | 732 | TagDecl *tag_decl = tag_type->getDecl(); |
| 733 | |
| 734 | if (tag_decl->getDefinition() || tag_decl->isBeingDefined()) |
| 735 | return true; |
| 736 | |
| 737 | return CompleteTagDecl(tag_decl); |
Sean Callanan | 6b200d0 | 2013-03-21 22:15:41 +0000 | [diff] [blame] | 738 | } |
| 739 | if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>()) |
| 740 | { |
| 741 | if (ObjCInterfaceDecl *objc_interface_decl = objc_object_type->getInterface()) |
| 742 | return CompleteObjCInterfaceDecl(objc_interface_decl); |
| 743 | else |
| 744 | return false; |
| 745 | } |
| 746 | if (const ArrayType *array_type = type->getAsArrayTypeUnsafe()) |
| 747 | { |
| 748 | return RequireCompleteType(array_type->getElementType()); |
| 749 | } |
| 750 | if (const AtomicType *atomic_type = type->getAs<AtomicType>()) |
| 751 | { |
| 752 | return RequireCompleteType(atomic_type->getPointeeType()); |
| 753 | } |
| 754 | |
| 755 | return true; |
| 756 | } |
| 757 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 758 | ClangASTMetadata * |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 759 | ClangASTImporter::GetDeclMetadata (const clang::Decl *decl) |
| 760 | { |
| 761 | DeclOrigin decl_origin = GetDeclOrigin(decl); |
| 762 | |
| 763 | if (decl_origin.Valid()) |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 764 | return ClangASTContext::GetMetadata(decl_origin.ctx, decl_origin.decl); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 765 | else |
Greg Clayton | d002944 | 2013-03-27 01:48:02 +0000 | [diff] [blame] | 766 | return ClangASTContext::GetMetadata(&decl->getASTContext(), decl); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 767 | } |
| 768 | |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 769 | ClangASTImporter::DeclOrigin |
| 770 | ClangASTImporter::GetDeclOrigin(const clang::Decl *decl) |
| 771 | { |
| 772 | ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); |
| 773 | |
| 774 | OriginMap &origins = context_md->m_origins; |
| 775 | |
| 776 | OriginMap::iterator iter = origins.find(decl); |
| 777 | |
| 778 | if (iter != origins.end()) |
| 779 | return iter->second; |
| 780 | else |
| 781 | return DeclOrigin(); |
| 782 | } |
| 783 | |
Sean Callanan | 2cb5e52 | 2012-09-20 23:21:16 +0000 | [diff] [blame] | 784 | void |
| 785 | ClangASTImporter::SetDeclOrigin (const clang::Decl *decl, clang::Decl *original_decl) |
| 786 | { |
| 787 | ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); |
| 788 | |
| 789 | OriginMap &origins = context_md->m_origins; |
| 790 | |
| 791 | OriginMap::iterator iter = origins.find(decl); |
| 792 | |
| 793 | if (iter != origins.end()) |
| 794 | { |
| 795 | iter->second.decl = original_decl; |
| 796 | iter->second.ctx = &original_decl->getASTContext(); |
| 797 | } |
| 798 | else |
| 799 | { |
| 800 | origins[decl] = DeclOrigin(&original_decl->getASTContext(), original_decl); |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | void |
Sean Callanan | 503aa52 | 2011-10-12 00:12:34 +0000 | [diff] [blame] | 805 | ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl, |
| 806 | NamespaceMapSP &namespace_map) |
| 807 | { |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 808 | ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); |
| 809 | |
| 810 | context_md->m_namespace_maps[decl] = namespace_map; |
Sean Callanan | 503aa52 | 2011-10-12 00:12:34 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | ClangASTImporter::NamespaceMapSP |
| 814 | ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl) |
| 815 | { |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 816 | ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); |
| 817 | |
| 818 | NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps; |
Sean Callanan | 503aa52 | 2011-10-12 00:12:34 +0000 | [diff] [blame] | 819 | |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 820 | NamespaceMetaMap::iterator iter = namespace_maps.find(decl); |
| 821 | |
| 822 | if (iter != namespace_maps.end()) |
Sean Callanan | 503aa52 | 2011-10-12 00:12:34 +0000 | [diff] [blame] | 823 | return iter->second; |
| 824 | else |
| 825 | return NamespaceMapSP(); |
| 826 | } |
| 827 | |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 828 | void |
| 829 | ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl) |
| 830 | { |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 831 | assert (decl); |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 832 | ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext()); |
| 833 | |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 834 | const DeclContext *parent_context = decl->getDeclContext(); |
| 835 | const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context); |
| 836 | NamespaceMapSP parent_map; |
| 837 | |
| 838 | if (parent_namespace) |
| 839 | parent_map = GetNamespaceMap(parent_namespace); |
| 840 | |
| 841 | NamespaceMapSP new_map; |
| 842 | |
| 843 | new_map.reset(new NamespaceMap); |
| 844 | |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 845 | if (context_md->m_map_completer) |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 846 | { |
| 847 | std::string namespace_string = decl->getDeclName().getAsString(); |
| 848 | |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 849 | context_md->m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map); |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 852 | context_md->m_namespace_maps[decl] = new_map; |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 855 | void |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 856 | ClangASTImporter::ForgetDestination (clang::ASTContext *dst_ast) |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 857 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 858 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 859 | |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 860 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 861 | log->Printf(" [ClangASTImporter] Forgetting destination (ASTContext*)%p", |
| 862 | static_cast<void*>(dst_ast)); |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 863 | |
Sean Callanan | f487bd8 | 2011-11-16 21:40:57 +0000 | [diff] [blame] | 864 | m_metadata_map.erase(dst_ast); |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 865 | } |
| 866 | |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 867 | void |
| 868 | ClangASTImporter::ForgetSource (clang::ASTContext *dst_ast, clang::ASTContext *src_ast) |
| 869 | { |
| 870 | ASTContextMetadataSP md = MaybeGetContextMetadata (dst_ast); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 871 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 872 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 873 | |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 874 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 875 | log->Printf(" [ClangASTImporter] Forgetting source->dest (ASTContext*)%p->(ASTContext*)%p", |
| 876 | static_cast<void*>(src_ast), static_cast<void*>(dst_ast)); |
| 877 | |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 878 | if (!md) |
| 879 | return; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 880 | |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 881 | md->m_minions.erase(src_ast); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 882 | |
Sean Callanan | 9973231 | 2011-11-29 00:42:02 +0000 | [diff] [blame] | 883 | for (OriginMap::iterator iter = md->m_origins.begin(); |
| 884 | iter != md->m_origins.end(); |
| 885 | ) |
| 886 | { |
| 887 | if (iter->second.ctx == src_ast) |
| 888 | md->m_origins.erase(iter++); |
| 889 | else |
| 890 | ++iter; |
| 891 | } |
| 892 | } |
| 893 | |
Sean Callanan | 0eed0d4 | 2011-12-06 03:41:14 +0000 | [diff] [blame] | 894 | ClangASTImporter::MapCompleter::~MapCompleter () |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 895 | { |
| 896 | return; |
| 897 | } |
| 898 | |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 899 | void |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 900 | ClangASTImporter::Minion::InitDeportWorkQueues (std::set<clang::NamedDecl *> *decls_to_deport, |
| 901 | std::set<clang::NamedDecl *> *decls_already_deported) |
| 902 | { |
Sean Callanan | ecb1798 | 2015-09-02 16:40:59 +0000 | [diff] [blame] | 903 | assert(!m_decls_to_deport); |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 904 | assert(!m_decls_already_deported); |
| 905 | |
| 906 | m_decls_to_deport = decls_to_deport; |
| 907 | m_decls_already_deported = decls_already_deported; |
| 908 | } |
| 909 | |
| 910 | void |
| 911 | ClangASTImporter::Minion::ExecuteDeportWorkQueues () |
| 912 | { |
Sean Callanan | ecb1798 | 2015-09-02 16:40:59 +0000 | [diff] [blame] | 913 | assert(m_decls_to_deport); |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 914 | assert(m_decls_already_deported); |
| 915 | |
| 916 | ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&getToContext()); |
| 917 | |
| 918 | while (!m_decls_to_deport->empty()) |
| 919 | { |
| 920 | NamedDecl *decl = *m_decls_to_deport->begin(); |
| 921 | |
| 922 | m_decls_already_deported->insert(decl); |
| 923 | m_decls_to_deport->erase(decl); |
| 924 | |
| 925 | DeclOrigin &origin = to_context_md->m_origins[decl]; |
Bruce Mitchener | 8a67bf7 | 2015-07-24 00:23:29 +0000 | [diff] [blame] | 926 | UNUSED_IF_ASSERT_DISABLED(origin); |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 927 | |
| 928 | assert (origin.ctx == m_source_ctx); // otherwise we should never have added this |
| 929 | // because it doesn't need to be deported |
| 930 | |
| 931 | Decl *original_decl = to_context_md->m_origins[decl].decl; |
| 932 | |
| 933 | ClangASTContext::GetCompleteDecl (m_source_ctx, original_decl); |
| 934 | |
| 935 | if (TagDecl *tag_decl = dyn_cast<TagDecl>(decl)) |
| 936 | { |
| 937 | if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) |
Sean Callanan | d0234c4 | 2016-03-26 00:37:55 +0000 | [diff] [blame] | 938 | { |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 939 | if (original_tag_decl->isCompleteDefinition()) |
Sean Callanan | d0234c4 | 2016-03-26 00:37:55 +0000 | [diff] [blame] | 940 | { |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 941 | ImportDefinitionTo(tag_decl, original_tag_decl); |
Sean Callanan | d0234c4 | 2016-03-26 00:37:55 +0000 | [diff] [blame] | 942 | tag_decl->setCompleteDefinition(true); |
| 943 | } |
| 944 | } |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 945 | |
| 946 | tag_decl->setHasExternalLexicalStorage(false); |
| 947 | tag_decl->setHasExternalVisibleStorage(false); |
| 948 | } |
Sean Callanan | 3f9de74 | 2016-02-10 22:00:32 +0000 | [diff] [blame] | 949 | else if (ObjCContainerDecl *container_decl = dyn_cast<ObjCContainerDecl>(decl)) |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 950 | { |
Sean Callanan | 3f9de74 | 2016-02-10 22:00:32 +0000 | [diff] [blame] | 951 | container_decl->setHasExternalLexicalStorage(false); |
| 952 | container_decl->setHasExternalVisibleStorage(false); |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | to_context_md->m_origins.erase(decl); |
| 956 | } |
| 957 | |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 958 | m_decls_to_deport = nullptr; |
| 959 | m_decls_already_deported = nullptr; |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | void |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 963 | ClangASTImporter::Minion::ImportDefinitionTo (clang::Decl *to, clang::Decl *from) |
| 964 | { |
| 965 | ASTImporter::Imported(from, to); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 966 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 967 | /* |
| 968 | if (to_objc_interface) |
| 969 | to_objc_interface->startDefinition(); |
| 970 | |
| 971 | CXXRecordDecl *to_cxx_record = dyn_cast<CXXRecordDecl>(to); |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 972 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 973 | if (to_cxx_record) |
| 974 | to_cxx_record->startDefinition(); |
| 975 | */ |
| 976 | |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 977 | ImportDefinition(from); |
Sean Callanan | d0234c4 | 2016-03-26 00:37:55 +0000 | [diff] [blame] | 978 | |
| 979 | if (clang::TagDecl *to_tag = dyn_cast<clang::TagDecl>(to)) |
| 980 | { |
| 981 | if (clang::TagDecl *from_tag = dyn_cast<clang::TagDecl>(from)) |
| 982 | { |
| 983 | to_tag->setCompleteDefinition(from_tag->isCompleteDefinition()); |
| 984 | } |
| 985 | } |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 986 | |
Sean Callanan | 2e93a2a | 2012-01-19 18:23:06 +0000 | [diff] [blame] | 987 | // If we're dealing with an Objective-C class, ensure that the inheritance has |
| 988 | // been set up correctly. The ASTImporter may not do this correctly if the |
| 989 | // class was originally sourced from symbols. |
| 990 | |
Sean Callanan | d0234c4 | 2016-03-26 00:37:55 +0000 | [diff] [blame] | 991 | if (ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to)) |
Sean Callanan | 2e93a2a | 2012-01-19 18:23:06 +0000 | [diff] [blame] | 992 | { |
| 993 | do |
| 994 | { |
| 995 | ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass(); |
| 996 | |
| 997 | if (to_superclass) |
| 998 | break; // we're not going to override it if it's set |
| 999 | |
| 1000 | ObjCInterfaceDecl *from_objc_interface = dyn_cast<ObjCInterfaceDecl>(from); |
| 1001 | |
| 1002 | if (!from_objc_interface) |
| 1003 | break; |
| 1004 | |
| 1005 | ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass(); |
| 1006 | |
| 1007 | if (!from_superclass) |
| 1008 | break; |
| 1009 | |
| 1010 | Decl *imported_from_superclass_decl = Import(from_superclass); |
| 1011 | |
| 1012 | if (!imported_from_superclass_decl) |
| 1013 | break; |
| 1014 | |
| 1015 | ObjCInterfaceDecl *imported_from_superclass = dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl); |
| 1016 | |
| 1017 | if (!imported_from_superclass) |
| 1018 | break; |
| 1019 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1020 | if (!to_objc_interface->hasDefinition()) |
| 1021 | to_objc_interface->startDefinition(); |
| 1022 | |
Pavel Labath | 67add94 | 2015-07-07 10:11:16 +0000 | [diff] [blame] | 1023 | to_objc_interface->setSuperClass( |
| 1024 | m_source_ctx->getTrivialTypeSourceInfo(m_source_ctx->getObjCInterfaceType(imported_from_superclass))); |
Sean Callanan | 2e93a2a | 2012-01-19 18:23:06 +0000 | [diff] [blame] | 1025 | } |
| 1026 | while (0); |
| 1027 | } |
Sean Callanan | cbbe3ac | 2012-01-13 22:55:55 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1030 | clang::Decl * |
| 1031 | ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to) |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1032 | { |
Sean Callanan | 8106d80 | 2013-03-08 20:04:57 +0000 | [diff] [blame] | 1033 | ClangASTMetrics::RegisterClangImport(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1034 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1035 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1036 | |
Sean Callanan | 608fb39 | 2014-08-01 22:42:38 +0000 | [diff] [blame] | 1037 | lldb::user_id_t user_id = LLDB_INVALID_UID; |
| 1038 | ClangASTMetadata *metadata = m_master.GetDeclMetadata(from); |
| 1039 | if (metadata) |
| 1040 | user_id = metadata->GetUserID(); |
| 1041 | |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1042 | if (log) |
| 1043 | { |
| 1044 | if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) |
| 1045 | { |
Sean Callanan | 48e894b | 2012-05-25 18:12:26 +0000 | [diff] [blame] | 1046 | std::string name_string; |
| 1047 | llvm::raw_string_ostream name_stream(name_string); |
| 1048 | from_named_decl->printName(name_stream); |
| 1049 | name_stream.flush(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1050 | |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1051 | log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named %s (from (Decl*)%p), metadata 0x%" PRIx64, |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1052 | from->getDeclKindName(), static_cast<void*>(to), |
| 1053 | name_string.c_str(), static_cast<void*>(from), |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1054 | user_id); |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1055 | } |
| 1056 | else |
| 1057 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1058 | log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p (from (Decl*)%p), metadata 0x%" PRIx64, |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1059 | from->getDeclKindName(), static_cast<void*>(to), |
| 1060 | static_cast<void*>(from), user_id); |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1061 | } |
| 1062 | } |
| 1063 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1064 | ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&to->getASTContext()); |
| 1065 | ASTContextMetadataSP from_context_md = m_master.MaybeGetContextMetadata(m_source_ctx); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1066 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1067 | if (from_context_md) |
| 1068 | { |
| 1069 | OriginMap &origins = from_context_md->m_origins; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1070 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1071 | OriginMap::iterator origin_iter = origins.find(from); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1072 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1073 | if (origin_iter != origins.end()) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1074 | { |
Sean Callanan | 608fb39 | 2014-08-01 22:42:38 +0000 | [diff] [blame] | 1075 | if (to_context_md->m_origins.find(to) == to_context_md->m_origins.end() || |
| 1076 | user_id != LLDB_INVALID_UID) |
| 1077 | { |
Sean Callanan | abe140c | 2015-07-20 16:55:19 +0000 | [diff] [blame] | 1078 | if (origin_iter->second.ctx != &to->getASTContext()) |
| 1079 | to_context_md->m_origins[to] = origin_iter->second; |
Sean Callanan | 608fb39 | 2014-08-01 22:42:38 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
Sean Callanan | 5bc5a76 | 2011-12-20 23:55:47 +0000 | [diff] [blame] | 1082 | MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1083 | |
Sean Callanan | 5bc5a76 | 2011-12-20 23:55:47 +0000 | [diff] [blame] | 1084 | if (direct_completer.get() != this) |
| 1085 | direct_completer->ASTImporter::Imported(origin_iter->second.decl, to); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1086 | |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1087 | if (log) |
| 1088 | log->Printf(" [ClangASTImporter] Propagated origin (Decl*)%p/(ASTContext*)%p from (ASTContext*)%p to (ASTContext*)%p", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1089 | static_cast<void*>(origin_iter->second.decl), |
| 1090 | static_cast<void*>(origin_iter->second.ctx), |
| 1091 | static_cast<void*>(&from->getASTContext()), |
| 1092 | static_cast<void*>(&to->getASTContext())); |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1093 | } |
| 1094 | else |
| 1095 | { |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 1096 | if (m_decls_to_deport && m_decls_already_deported) |
| 1097 | { |
| 1098 | if (isa<TagDecl>(to) || isa<ObjCInterfaceDecl>(to)) |
| 1099 | { |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 1100 | RecordDecl *from_record_decl = dyn_cast<RecordDecl>(from); |
| 1101 | if (from_record_decl == nullptr || from_record_decl->isInjectedClassName() == false) |
| 1102 | { |
| 1103 | NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1104 | |
Greg Clayton | e6b36cd | 2015-12-08 01:02:08 +0000 | [diff] [blame] | 1105 | if (!m_decls_already_deported->count(to_named_decl)) |
| 1106 | m_decls_to_deport->insert(to_named_decl); |
| 1107 | } |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 1108 | } |
Sean Callanan | e55bc8a | 2013-03-30 02:31:21 +0000 | [diff] [blame] | 1109 | } |
Sean Callanan | 608fb39 | 2014-08-01 22:42:38 +0000 | [diff] [blame] | 1110 | |
| 1111 | if (to_context_md->m_origins.find(to) == to_context_md->m_origins.end() || |
| 1112 | user_id != LLDB_INVALID_UID) |
| 1113 | { |
| 1114 | to_context_md->m_origins[to] = DeclOrigin(m_source_ctx, from); |
| 1115 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1116 | |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1117 | if (log) |
| 1118 | log->Printf(" [ClangASTImporter] Decl has no origin information in (ASTContext*)%p", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1119 | static_cast<void*>(&from->getASTContext())); |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1120 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1121 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1122 | if (clang::NamespaceDecl *to_namespace = dyn_cast<clang::NamespaceDecl>(to)) |
| 1123 | { |
| 1124 | clang::NamespaceDecl *from_namespace = dyn_cast<clang::NamespaceDecl>(from); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1125 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1126 | NamespaceMetaMap &namespace_maps = from_context_md->m_namespace_maps; |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1127 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1128 | NamespaceMetaMap::iterator namespace_map_iter = namespace_maps.find(from_namespace); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1129 | |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1130 | if (namespace_map_iter != namespace_maps.end()) |
| 1131 | to_context_md->m_namespace_maps[to_namespace] = namespace_map_iter->second; |
| 1132 | } |
| 1133 | } |
| 1134 | else |
| 1135 | { |
| 1136 | to_context_md->m_origins[to] = DeclOrigin (m_source_ctx, from); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1137 | |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1138 | if (log) |
| 1139 | log->Printf(" [ClangASTImporter] Sourced origin (Decl*)%p/(ASTContext*)%p into (ASTContext*)%p", |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1140 | static_cast<void*>(from), |
| 1141 | static_cast<void*>(m_source_ctx), |
| 1142 | static_cast<void*>(&to->getASTContext())); |
Sean Callanan | b0b87a5 | 2011-11-16 22:23:28 +0000 | [diff] [blame] | 1143 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1144 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1145 | if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from)) |
| 1146 | { |
| 1147 | TagDecl *to_tag_decl = dyn_cast<TagDecl>(to); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1148 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1149 | to_tag_decl->setHasExternalLexicalStorage(); |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1150 | to_tag_decl->setMustBuildLookupTable(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1151 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1152 | if (log) |
Sean Callanan | 00f4362 | 2011-11-18 03:28:09 +0000 | [diff] [blame] | 1153 | log->Printf(" [ClangASTImporter] To is a TagDecl - attributes %s%s [%s->%s]", |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1154 | (to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""), |
Sean Callanan | 0730e9c | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 1155 | (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""), |
| 1156 | (from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"), |
| 1157 | (to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete")); |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1158 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1159 | |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 1160 | if (isa<NamespaceDecl>(from)) |
| 1161 | { |
| 1162 | NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1163 | |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 1164 | m_master.BuildNamespaceMap(to_namespace_decl); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1165 | |
Sean Callanan | b226916 | 2011-10-21 22:18:07 +0000 | [diff] [blame] | 1166 | to_namespace_decl->setHasExternalVisibleStorage(); |
| 1167 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1168 | |
Sean Callanan | 3f9de74 | 2016-02-10 22:00:32 +0000 | [diff] [blame] | 1169 | if (isa<ObjCContainerDecl>(from)) |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1170 | { |
Sean Callanan | 3f9de74 | 2016-02-10 22:00:32 +0000 | [diff] [blame] | 1171 | ObjCContainerDecl *to_container_decl = dyn_cast<ObjCContainerDecl>(to); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1172 | |
Sean Callanan | 3f9de74 | 2016-02-10 22:00:32 +0000 | [diff] [blame] | 1173 | to_container_decl->setHasExternalLexicalStorage(); |
| 1174 | to_container_decl->setHasExternalVisibleStorage(); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1175 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1176 | /*to_interface_decl->setExternallyCompleted();*/ |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1177 | |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 1178 | if (log) |
Sean Callanan | 3f9de74 | 2016-02-10 22:00:32 +0000 | [diff] [blame] | 1179 | { |
| 1180 | if (ObjCInterfaceDecl *to_interface_decl = llvm::dyn_cast<ObjCInterfaceDecl>(to_container_decl)) |
| 1181 | { |
| 1182 | log->Printf(" [ClangASTImporter] To is an ObjCInterfaceDecl - attributes %s%s%s", |
| 1183 | (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""), |
| 1184 | (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""), |
| 1185 | (to_interface_decl->hasDefinition() ? " HasDefinition" : "")); |
| 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | log->Printf(" [ClangASTImporter] To is an %sDecl - attributes %s%s", |
| 1190 | ((Decl*)to_container_decl)->getDeclKindName(), |
| 1191 | (to_container_decl->hasExternalLexicalStorage() ? " Lexical" : ""), |
| 1192 | (to_container_decl->hasExternalVisibleStorage() ? " Visible" : "")); |
| 1193 | } |
| 1194 | } |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1195 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 1196 | |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 1197 | return clang::ASTImporter::Imported(from, to); |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 1198 | } |
Sean Callanan | 931a0de | 2013-10-09 22:33:34 +0000 | [diff] [blame] | 1199 | |
| 1200 | clang::Decl *ClangASTImporter::Minion::GetOriginalDecl (clang::Decl *To) |
| 1201 | { |
| 1202 | ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&To->getASTContext()); |
| 1203 | |
| 1204 | if (!to_context_md) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1205 | return nullptr; |
Sean Callanan | 931a0de | 2013-10-09 22:33:34 +0000 | [diff] [blame] | 1206 | |
| 1207 | OriginMap::iterator iter = to_context_md->m_origins.find(To); |
| 1208 | |
| 1209 | if (iter == to_context_md->m_origins.end()) |
Ed Maste | d4612ad | 2014-04-20 13:17:36 +0000 | [diff] [blame] | 1210 | return nullptr; |
Sean Callanan | 931a0de | 2013-10-09 22:33:34 +0000 | [diff] [blame] | 1211 | |
| 1212 | return const_cast<clang::Decl*>(iter->second.decl); |
| 1213 | } |