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