1 //===-- ClangASTImporter.cpp ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/AST/Decl.h"
11 #include "clang/AST/DeclCXX.h"
12 #include "clang/AST/DeclObjC.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include "lldb/Core/Log.h"
15 #include "lldb/Core/Module.h"
16 #include "lldb/Symbol/ClangASTContext.h"
17 #include "lldb/Symbol/ClangASTImporter.h"
18 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
19 #include "lldb/Symbol/ClangNamespaceDecl.h"
20 #include "lldb/Utility/LLDBAssert.h"
22 using namespace lldb_private;
23 using namespace clang;
25 ClangASTMetrics::Counters ClangASTMetrics::global_counters = { 0, 0, 0, 0, 0, 0 };
26 ClangASTMetrics::Counters ClangASTMetrics::local_counters = { 0, 0, 0, 0, 0, 0 };
28 void ClangASTMetrics::DumpCounters (Log *log, ClangASTMetrics::Counters &counters)
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);
38 void ClangASTMetrics::DumpCounters (Log *log)
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);
51 ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
52 clang::ASTContext *src_ast,
55 MinionSP minion_sp (GetMinion(dst_ast, src_ast));
58 return minion_sp->Import(type);
64 ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
65 clang::ASTContext *src_ast,
66 lldb::clang_type_t type)
68 return CopyType (dst_ast, src_ast, QualType::getFromOpaquePtr(type)).getAsOpaquePtr();
72 ClangASTImporter::CopyDecl (clang::ASTContext *dst_ast,
73 clang::ASTContext *src_ast,
78 minion_sp = GetMinion(dst_ast, src_ast);
82 clang::Decl *result = minion_sp->Import(decl);
86 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
90 lldb::user_id_t user_id = LLDB_INVALID_UID;
91 ClangASTMetadata *metadata = GetDeclMetadata(decl);
93 user_id = metadata->GetUserID();
95 if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
96 log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s '%s', metadata 0x%" PRIx64,
97 decl->getDeclKindName(),
98 named_decl->getNameAsString().c_str(),
101 log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s, metadata 0x%" PRIx64,
102 decl->getDeclKindName(),
113 class DeclContextOverride
118 clang::DeclContext *decl_context;
119 clang::DeclContext *lexical_decl_context;
122 std::map<clang::Decl *, Backup> m_backups;
124 void OverrideOne(clang::Decl *decl)
126 if (m_backups.find(decl) != m_backups.end())
131 m_backups[decl] = { decl->getDeclContext(), decl->getLexicalDeclContext() };
133 decl->setDeclContext(decl->getASTContext().getTranslationUnitDecl());
134 decl->setLexicalDeclContext(decl->getASTContext().getTranslationUnitDecl());
137 bool ChainPassesThrough(clang::Decl *decl,
138 clang::DeclContext *base,
139 clang::DeclContext *(clang::Decl::*contextFromDecl)(),
140 clang::DeclContext *(clang::DeclContext::*contextFromContext)())
142 for (DeclContext *decl_ctx = (decl->*contextFromDecl)();
144 decl_ctx = (decl_ctx->*contextFromContext)())
146 if (decl_ctx == base)
155 clang::Decl *GetEscapedChild(clang::Decl *decl, clang::DeclContext *base = nullptr)
159 // decl's DeclContext chains must pass through base.
161 if (!ChainPassesThrough(decl, base, &clang::Decl::getDeclContext, &clang::DeclContext::getParent) ||
162 !ChainPassesThrough(decl, base, &clang::Decl::getLexicalDeclContext, &clang::DeclContext::getLexicalParent))
169 base = clang::dyn_cast<clang::DeclContext>(decl);
177 if (clang::DeclContext *context = clang::dyn_cast<clang::DeclContext>(decl))
179 for (clang::Decl *decl : context->decls())
181 if (clang::Decl *escaped_child = GetEscapedChild(decl))
183 return escaped_child;
191 void Override(clang::Decl *decl)
193 if (clang::Decl *escaped_child = GetEscapedChild(decl))
195 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
198 log->Printf(" [ClangASTImporter] DeclContextOverride couldn't override (%sDecl*)%p - its child (%sDecl*)%p escapes",
199 decl->getDeclKindName(), static_cast<void*>(decl),
200 escaped_child->getDeclKindName(), static_cast<void*>(escaped_child));
201 lldbassert(0 && "Couldn't override!");
208 DeclContextOverride()
212 void OverrideAllDeclsFromContainingFunction(clang::Decl *decl)
214 for (DeclContext *decl_context = decl->getLexicalDeclContext();
216 decl_context = decl_context->getLexicalParent())
218 DeclContext *redecl_context = decl_context->getRedeclContext();
220 if (llvm::isa<FunctionDecl>(redecl_context) &&
221 llvm::isa<TranslationUnitDecl>(redecl_context->getLexicalParent()))
223 for (clang::Decl *child_decl : decl_context->decls())
225 Override(child_decl);
231 ~DeclContextOverride()
233 for (const std::pair<clang::Decl *, Backup> &backup : m_backups)
235 backup.first->setDeclContext(backup.second.decl_context);
236 backup.first->setLexicalDeclContext(backup.second.lexical_decl_context);
242 ClangASTImporter::DeportType (clang::ASTContext *dst_ctx,
243 clang::ASTContext *src_ctx,
244 lldb::clang_type_t type)
246 MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
251 std::set<NamedDecl *> decls_to_deport;
252 std::set<NamedDecl *> decls_already_deported;
254 DeclContextOverride decl_context_override;
256 if (const clang::TagType *tag_type = clang::QualType::getFromOpaquePtr(type)->getAs<TagType>())
258 decl_context_override.OverrideAllDeclsFromContainingFunction(tag_type->getDecl());
261 minion_sp->InitDeportWorkQueues(&decls_to_deport,
262 &decls_already_deported);
264 lldb::clang_type_t result = CopyType(dst_ctx, src_ctx, type);
266 minion_sp->ExecuteDeportWorkQueues();
276 ClangASTImporter::DeportDecl (clang::ASTContext *dst_ctx,
277 clang::ASTContext *src_ctx,
280 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
283 log->Printf(" [ClangASTImporter] DeportDecl called on (%sDecl*)%p from (ASTContext*)%p to (ASTContex*)%p",
284 decl->getDeclKindName(), static_cast<void*>(decl),
285 static_cast<void*>(src_ctx),
286 static_cast<void*>(dst_ctx));
288 MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
293 std::set<NamedDecl *> decls_to_deport;
294 std::set<NamedDecl *> decls_already_deported;
296 DeclContextOverride decl_context_override;
298 decl_context_override.OverrideAllDeclsFromContainingFunction(decl);
300 minion_sp->InitDeportWorkQueues(&decls_to_deport,
301 &decls_already_deported);
303 clang::Decl *result = CopyDecl(dst_ctx, src_ctx, decl);
305 minion_sp->ExecuteDeportWorkQueues();
311 log->Printf(" [ClangASTImporter] DeportDecl deported (%sDecl*)%p to (%sDecl*)%p",
312 decl->getDeclKindName(), static_cast<void*>(decl),
313 result->getDeclKindName(), static_cast<void*>(result));
319 ClangASTImporter::CompleteDecl (clang::Decl *decl)
321 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
324 log->Printf(" [ClangASTImporter] CompleteDecl called on (%sDecl*)%p",
325 decl->getDeclKindName(), static_cast<void*>(decl));
327 if (ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl))
329 if (!interface_decl->getDefinition())
331 interface_decl->startDefinition();
332 CompleteObjCInterfaceDecl(interface_decl);
335 else if (ObjCProtocolDecl *protocol_decl = dyn_cast<ObjCProtocolDecl>(decl))
337 if (!protocol_decl->getDefinition())
338 protocol_decl->startDefinition();
340 else if (TagDecl *tag_decl = dyn_cast<TagDecl>(decl))
342 if (!tag_decl->getDefinition() && !tag_decl->isBeingDefined())
344 tag_decl->startDefinition();
345 CompleteTagDecl(tag_decl);
346 tag_decl->setCompleteDefinition(true);
351 assert (0 && "CompleteDecl called on a Decl that can't be completed");
356 ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
358 ClangASTMetrics::RegisterDeclCompletion();
360 DeclOrigin decl_origin = GetDeclOrigin(decl);
362 if (!decl_origin.Valid())
365 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
368 MinionSP minion_sp (GetMinion(&decl->getASTContext(), decl_origin.ctx));
371 minion_sp->ImportDefinitionTo(decl, decl_origin.decl);
377 ClangASTImporter::CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin_decl)
379 ClangASTMetrics::RegisterDeclCompletion();
381 clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext();
383 if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl))
386 MinionSP minion_sp (GetMinion(&decl->getASTContext(), origin_ast_ctx));
389 minion_sp->ImportDefinitionTo(decl, origin_decl);
391 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
393 OriginMap &origins = context_md->m_origins;
395 origins[decl] = DeclOrigin(origin_ast_ctx, origin_decl);
401 ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
403 ClangASTMetrics::RegisterDeclCompletion();
405 DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
407 if (!decl_origin.Valid())
410 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
413 MinionSP minion_sp (GetMinion(&interface_decl->getASTContext(), decl_origin.ctx));
416 minion_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
418 if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass())
419 RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0));
425 ClangASTImporter::RequireCompleteType (clang::QualType type)
430 if (const TagType *tag_type = type->getAs<TagType>())
432 TagDecl *tag_decl = tag_type->getDecl();
434 if (tag_decl->getDefinition() || tag_decl->isBeingDefined())
437 return CompleteTagDecl(tag_decl);
439 if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>())
441 if (ObjCInterfaceDecl *objc_interface_decl = objc_object_type->getInterface())
442 return CompleteObjCInterfaceDecl(objc_interface_decl);
446 if (const ArrayType *array_type = type->getAsArrayTypeUnsafe())
448 return RequireCompleteType(array_type->getElementType());
450 if (const AtomicType *atomic_type = type->getAs<AtomicType>())
452 return RequireCompleteType(atomic_type->getPointeeType());
459 ClangASTImporter::GetDeclMetadata (const clang::Decl *decl)
461 DeclOrigin decl_origin = GetDeclOrigin(decl);
463 if (decl_origin.Valid())
464 return ClangASTContext::GetMetadata(decl_origin.ctx, decl_origin.decl);
466 return ClangASTContext::GetMetadata(&decl->getASTContext(), decl);
469 ClangASTImporter::DeclOrigin
470 ClangASTImporter::GetDeclOrigin(const clang::Decl *decl)
472 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
474 OriginMap &origins = context_md->m_origins;
476 OriginMap::iterator iter = origins.find(decl);
478 if (iter != origins.end())
485 ClangASTImporter::SetDeclOrigin (const clang::Decl *decl, clang::Decl *original_decl)
487 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
489 OriginMap &origins = context_md->m_origins;
491 OriginMap::iterator iter = origins.find(decl);
493 if (iter != origins.end())
495 iter->second.decl = original_decl;
496 iter->second.ctx = &original_decl->getASTContext();
500 origins[decl] = DeclOrigin(&original_decl->getASTContext(), original_decl);
505 ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
506 NamespaceMapSP &namespace_map)
508 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
510 context_md->m_namespace_maps[decl] = namespace_map;
513 ClangASTImporter::NamespaceMapSP
514 ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
516 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
518 NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps;
520 NamespaceMetaMap::iterator iter = namespace_maps.find(decl);
522 if (iter != namespace_maps.end())
525 return NamespaceMapSP();
529 ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
532 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
534 const DeclContext *parent_context = decl->getDeclContext();
535 const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
536 NamespaceMapSP parent_map;
538 if (parent_namespace)
539 parent_map = GetNamespaceMap(parent_namespace);
541 NamespaceMapSP new_map;
543 new_map.reset(new NamespaceMap);
545 if (context_md->m_map_completer)
547 std::string namespace_string = decl->getDeclName().getAsString();
549 context_md->m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
552 context_md->m_namespace_maps[decl] = new_map;
556 ClangASTImporter::ForgetDestination (clang::ASTContext *dst_ast)
558 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
561 log->Printf(" [ClangASTImporter] Forgetting destination (ASTContext*)%p",
562 static_cast<void*>(dst_ast));
564 m_metadata_map.erase(dst_ast);
568 ClangASTImporter::ForgetSource (clang::ASTContext *dst_ast, clang::ASTContext *src_ast)
570 ASTContextMetadataSP md = MaybeGetContextMetadata (dst_ast);
572 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
575 log->Printf(" [ClangASTImporter] Forgetting source->dest (ASTContext*)%p->(ASTContext*)%p",
576 static_cast<void*>(src_ast), static_cast<void*>(dst_ast));
581 md->m_minions.erase(src_ast);
583 for (OriginMap::iterator iter = md->m_origins.begin();
584 iter != md->m_origins.end();
587 if (iter->second.ctx == src_ast)
588 md->m_origins.erase(iter++);
594 ClangASTImporter::MapCompleter::~MapCompleter ()
600 ClangASTImporter::Minion::InitDeportWorkQueues (std::set<clang::NamedDecl *> *decls_to_deport,
601 std::set<clang::NamedDecl *> *decls_already_deported)
603 assert(!m_decls_to_deport); // TODO make debug only
604 assert(!m_decls_already_deported);
606 m_decls_to_deport = decls_to_deport;
607 m_decls_already_deported = decls_already_deported;
611 ClangASTImporter::Minion::ExecuteDeportWorkQueues ()
613 assert(m_decls_to_deport); // TODO make debug only
614 assert(m_decls_already_deported);
616 ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&getToContext());
618 while (!m_decls_to_deport->empty())
620 NamedDecl *decl = *m_decls_to_deport->begin();
622 m_decls_already_deported->insert(decl);
623 m_decls_to_deport->erase(decl);
625 DeclOrigin &origin = to_context_md->m_origins[decl];
627 assert (origin.ctx == m_source_ctx); // otherwise we should never have added this
628 // because it doesn't need to be deported
630 Decl *original_decl = to_context_md->m_origins[decl].decl;
632 ClangASTContext::GetCompleteDecl (m_source_ctx, original_decl);
634 if (TagDecl *tag_decl = dyn_cast<TagDecl>(decl))
636 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
637 if (original_tag_decl->isCompleteDefinition())
638 ImportDefinitionTo(tag_decl, original_tag_decl);
640 tag_decl->setHasExternalLexicalStorage(false);
641 tag_decl->setHasExternalVisibleStorage(false);
643 else if (ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl))
645 interface_decl->setHasExternalLexicalStorage(false);
646 interface_decl->setHasExternalVisibleStorage(false);
649 to_context_md->m_origins.erase(decl);
652 m_decls_to_deport = nullptr;
653 m_decls_already_deported = nullptr;
657 ClangASTImporter::Minion::ImportDefinitionTo (clang::Decl *to, clang::Decl *from)
659 ASTImporter::Imported(from, to);
661 ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to);
664 if (to_objc_interface)
665 to_objc_interface->startDefinition();
667 CXXRecordDecl *to_cxx_record = dyn_cast<CXXRecordDecl>(to);
670 to_cxx_record->startDefinition();
673 ImportDefinition(from);
675 // If we're dealing with an Objective-C class, ensure that the inheritance has
676 // been set up correctly. The ASTImporter may not do this correctly if the
677 // class was originally sourced from symbols.
679 if (to_objc_interface)
683 ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
686 break; // we're not going to override it if it's set
688 ObjCInterfaceDecl *from_objc_interface = dyn_cast<ObjCInterfaceDecl>(from);
690 if (!from_objc_interface)
693 ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
695 if (!from_superclass)
698 Decl *imported_from_superclass_decl = Import(from_superclass);
700 if (!imported_from_superclass_decl)
703 ObjCInterfaceDecl *imported_from_superclass = dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl);
705 if (!imported_from_superclass)
708 if (!to_objc_interface->hasDefinition())
709 to_objc_interface->startDefinition();
711 to_objc_interface->setSuperClass(
712 m_source_ctx->getTrivialTypeSourceInfo(m_source_ctx->getObjCInterfaceType(imported_from_superclass)));
719 ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
721 ClangASTMetrics::RegisterClangImport();
723 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
725 lldb::user_id_t user_id = LLDB_INVALID_UID;
726 ClangASTMetadata *metadata = m_master.GetDeclMetadata(from);
728 user_id = metadata->GetUserID();
732 if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from))
734 std::string name_string;
735 llvm::raw_string_ostream name_stream(name_string);
736 from_named_decl->printName(name_stream);
739 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named %s (from (Decl*)%p), metadata 0x%" PRIx64,
740 from->getDeclKindName(), static_cast<void*>(to),
741 name_string.c_str(), static_cast<void*>(from),
746 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p (from (Decl*)%p), metadata 0x%" PRIx64,
747 from->getDeclKindName(), static_cast<void*>(to),
748 static_cast<void*>(from), user_id);
752 ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&to->getASTContext());
753 ASTContextMetadataSP from_context_md = m_master.MaybeGetContextMetadata(m_source_ctx);
757 OriginMap &origins = from_context_md->m_origins;
759 OriginMap::iterator origin_iter = origins.find(from);
761 if (origin_iter != origins.end())
763 if (to_context_md->m_origins.find(to) == to_context_md->m_origins.end() ||
764 user_id != LLDB_INVALID_UID)
766 to_context_md->m_origins[to] = origin_iter->second;
769 MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx);
771 if (direct_completer.get() != this)
772 direct_completer->ASTImporter::Imported(origin_iter->second.decl, to);
775 log->Printf(" [ClangASTImporter] Propagated origin (Decl*)%p/(ASTContext*)%p from (ASTContext*)%p to (ASTContext*)%p",
776 static_cast<void*>(origin_iter->second.decl),
777 static_cast<void*>(origin_iter->second.ctx),
778 static_cast<void*>(&from->getASTContext()),
779 static_cast<void*>(&to->getASTContext()));
783 if (m_decls_to_deport && m_decls_already_deported)
785 if (isa<TagDecl>(to) || isa<ObjCInterfaceDecl>(to))
787 NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to);
789 if (!m_decls_already_deported->count(to_named_decl))
790 m_decls_to_deport->insert(to_named_decl);
794 if (to_context_md->m_origins.find(to) == to_context_md->m_origins.end() ||
795 user_id != LLDB_INVALID_UID)
797 to_context_md->m_origins[to] = DeclOrigin(m_source_ctx, from);
801 log->Printf(" [ClangASTImporter] Decl has no origin information in (ASTContext*)%p",
802 static_cast<void*>(&from->getASTContext()));
805 if (clang::NamespaceDecl *to_namespace = dyn_cast<clang::NamespaceDecl>(to))
807 clang::NamespaceDecl *from_namespace = dyn_cast<clang::NamespaceDecl>(from);
809 NamespaceMetaMap &namespace_maps = from_context_md->m_namespace_maps;
811 NamespaceMetaMap::iterator namespace_map_iter = namespace_maps.find(from_namespace);
813 if (namespace_map_iter != namespace_maps.end())
814 to_context_md->m_namespace_maps[to_namespace] = namespace_map_iter->second;
819 to_context_md->m_origins[to] = DeclOrigin (m_source_ctx, from);
822 log->Printf(" [ClangASTImporter] Sourced origin (Decl*)%p/(ASTContext*)%p into (ASTContext*)%p",
823 static_cast<void*>(from),
824 static_cast<void*>(m_source_ctx),
825 static_cast<void*>(&to->getASTContext()));
828 if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
830 TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
832 to_tag_decl->setHasExternalLexicalStorage();
833 to_tag_decl->setMustBuildLookupTable();
836 log->Printf(" [ClangASTImporter] To is a TagDecl - attributes %s%s [%s->%s]",
837 (to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
838 (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
839 (from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
840 (to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
843 if (isa<NamespaceDecl>(from))
845 NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
847 m_master.BuildNamespaceMap(to_namespace_decl);
849 to_namespace_decl->setHasExternalVisibleStorage();
852 if (isa<ObjCInterfaceDecl>(from))
854 ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
856 to_interface_decl->setHasExternalLexicalStorage();
857 to_interface_decl->setHasExternalVisibleStorage();
859 /*to_interface_decl->setExternallyCompleted();*/
862 log->Printf(" [ClangASTImporter] To is an ObjCInterfaceDecl - attributes %s%s%s",
863 (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
864 (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""),
865 (to_interface_decl->hasDefinition() ? " HasDefinition" : ""));
868 return clang::ASTImporter::Imported(from, to);
871 clang::Decl *ClangASTImporter::Minion::GetOriginalDecl (clang::Decl *To)
873 ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&To->getASTContext());
878 OriginMap::iterator iter = to_context_md->m_origins.find(To);
880 if (iter == to_context_md->m_origins.end())
883 return const_cast<clang::Decl*>(iter->second.decl);