blob: 8b4be06acb19bcd27b4408e8b081dfec9198bc07 [file] [log] [blame]
Greg Claytona2721472011-06-25 00:44:06 +00001//===-- 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 Callanancbbe3ac2012-01-13 22:55:55 +000011#include "clang/AST/DeclCXX.h"
Sean Callanancc427fa2011-07-30 02:42:06 +000012#include "clang/AST/DeclObjC.h"
13#include "lldb/Core/Log.h"
Greg Clayton7c6d7b82011-10-21 23:04:20 +000014#include "lldb/Core/Module.h"
Greg Claytona2721472011-06-25 00:44:06 +000015#include "lldb/Symbol/ClangASTContext.h"
16#include "lldb/Symbol/ClangASTImporter.h"
Sean Callanan60217122012-04-13 00:10:03 +000017#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
Sean Callananb2269162011-10-21 22:18:07 +000018#include "lldb/Symbol/ClangNamespaceDecl.h"
Greg Claytona2721472011-06-25 00:44:06 +000019
20using namespace lldb_private;
21using namespace clang;
22
23clang::QualType
Sean Callanan686b2312011-11-16 18:20:47 +000024ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
25 clang::ASTContext *src_ast,
Greg Claytona2721472011-06-25 00:44:06 +000026 clang::QualType type)
27{
Sean Callanan686b2312011-11-16 18:20:47 +000028 MinionSP minion_sp (GetMinion(dst_ast, src_ast));
Sean Callanancc427fa2011-07-30 02:42:06 +000029
Greg Claytondd0649b2011-07-06 18:55:08 +000030 if (minion_sp)
31 return minion_sp->Import(type);
Sean Callanancc427fa2011-07-30 02:42:06 +000032
Greg Claytondd0649b2011-07-06 18:55:08 +000033 return QualType();
Greg Claytona2721472011-06-25 00:44:06 +000034}
35
Sean Callanan80f78672011-11-16 19:07:39 +000036lldb::clang_type_t
37ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
38 clang::ASTContext *src_ast,
39 lldb::clang_type_t type)
40{
41 return CopyType (dst_ast, src_ast, QualType::getFromOpaquePtr(type)).getAsOpaquePtr();
42}
43
Greg Claytona2721472011-06-25 00:44:06 +000044clang::Decl *
Sean Callanan686b2312011-11-16 18:20:47 +000045ClangASTImporter::CopyDecl (clang::ASTContext *dst_ast,
46 clang::ASTContext *src_ast,
Greg Claytona2721472011-06-25 00:44:06 +000047 clang::Decl *decl)
48{
Greg Claytondd0649b2011-07-06 18:55:08 +000049 MinionSP minion_sp;
Greg Claytona2721472011-06-25 00:44:06 +000050
Sean Callanan686b2312011-11-16 18:20:47 +000051 minion_sp = GetMinion(dst_ast, src_ast);
Greg Claytona2721472011-06-25 00:44:06 +000052
Greg Claytondd0649b2011-07-06 18:55:08 +000053 if (minion_sp)
Sean Callananbfb237bc2011-11-04 22:46:46 +000054 {
55 clang::Decl *result = minion_sp->Import(decl);
56
57 if (!result)
58 {
59 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
60
Sean Callanand5145b32011-11-05 00:08:12 +000061 if (log)
62 {
63 if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
Sean Callanand9804fb2012-04-17 22:30:04 +000064 log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s '%s', metadata 0x%llx",
65 decl->getDeclKindName(),
66 named_decl->getNameAsString().c_str(),
67 GetDeclMetadata(decl));
Sean Callanand5145b32011-11-05 00:08:12 +000068 else
Sean Callanand9804fb2012-04-17 22:30:04 +000069 log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s, metadata 0x%llx",
70 decl->getDeclKindName(),
71 GetDeclMetadata(decl));
Sean Callanand5145b32011-11-05 00:08:12 +000072 }
Sean Callananbfb237bc2011-11-04 22:46:46 +000073 }
74
75 return result;
76 }
Sean Callanancc427fa2011-07-30 02:42:06 +000077
Greg Claytondd0649b2011-07-06 18:55:08 +000078 return NULL;
Greg Claytona2721472011-06-25 00:44:06 +000079}
80
Sean Callananbb120042011-12-16 21:06:35 +000081lldb::clang_type_t
82ClangASTImporter::DeportType (clang::ASTContext *dst_ctx,
83 clang::ASTContext *src_ctx,
84 lldb::clang_type_t type)
85{
86 lldb::clang_type_t result = CopyType(dst_ctx, src_ctx, type);
87
88 if (!result)
89 return NULL;
90
91 QualType qual_type = QualType::getFromOpaquePtr(type);
92
93 if (const TagType *tag_type = qual_type->getAs<TagType>())
94 {
95 TagDecl *tag_decl = tag_type->getDecl();
96 const TagType *result_tag_type = QualType::getFromOpaquePtr(result)->getAs<TagType>();
97 TagDecl *result_tag_decl = result_tag_type->getDecl();
98
99 if (tag_decl)
100 {
101 MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
102
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000103 minion_sp->ImportDefinitionTo(result_tag_decl, tag_decl);
Sean Callananbb120042011-12-16 21:06:35 +0000104
105 ASTContextMetadataSP to_context_md = GetContextMetadata(dst_ctx);
106
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000107 OriginMap::iterator oi = to_context_md->m_origins.find(result_tag_decl);
108
109 if (oi != to_context_md->m_origins.end() &&
110 oi->second.ctx == src_ctx)
111 to_context_md->m_origins.erase(oi);
Sean Callananbb120042011-12-16 21:06:35 +0000112 }
113 }
114
115 return result;
116}
117
Sean Callanan0eed0d42011-12-06 03:41:14 +0000118clang::Decl *
119ClangASTImporter::DeportDecl (clang::ASTContext *dst_ctx,
120 clang::ASTContext *src_ctx,
121 clang::Decl *decl)
122{
123 clang::Decl *result = CopyDecl(dst_ctx, src_ctx, decl);
124
125 if (!result)
126 return NULL;
127
128 ClangASTContext::GetCompleteDecl (src_ctx, decl);
129
130 MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
131
132 if (minion_sp && isa<TagDecl>(decl))
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000133 minion_sp->ImportDefinitionTo(result, decl);
Sean Callanan0eed0d42011-12-06 03:41:14 +0000134
135 ASTContextMetadataSP to_context_md = GetContextMetadata(dst_ctx);
136
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000137 OriginMap::iterator oi = to_context_md->m_origins.find(decl);
138
139 if (oi != to_context_md->m_origins.end() &&
140 oi->second.ctx == src_ctx)
141 to_context_md->m_origins.erase(oi);
Sean Callanan0eed0d42011-12-06 03:41:14 +0000142
143 return result;
144}
145
Sean Callanan5b26f272012-02-04 08:49:35 +0000146void
147ClangASTImporter::CompleteDecl (clang::Decl *decl)
148{
149 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
150
151 if (log)
152 log->Printf(" [ClangASTImporter] CompleteDecl called on (%sDecl*)%p",
153 decl->getDeclKindName(),
154 decl);
155
156 if (ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl))
157 {
158 if (!interface_decl->getDefinition())
159 {
160 interface_decl->startDefinition();
161 CompleteObjCInterfaceDecl(interface_decl);
162 }
163 }
164 else if (ObjCProtocolDecl *protocol_decl = dyn_cast<ObjCProtocolDecl>(protocol_decl))
165 {
166 if (!protocol_decl->getDefinition())
167 protocol_decl->startDefinition();
168 }
169 else if (TagDecl *tag_decl = dyn_cast<TagDecl>(decl))
170 {
171 if (!tag_decl->getDefinition() && !tag_decl->isBeingDefined())
172 {
173 tag_decl->startDefinition();
174 CompleteTagDecl(tag_decl);
175 tag_decl->setCompleteDefinition(true);
176 }
177 }
Greg Clayton219cf312012-03-30 00:51:13 +0000178 else
179 {
Sean Callanan5b26f272012-02-04 08:49:35 +0000180 assert (0 && "CompleteDecl called on a Decl that can't be completed");
181 }
182}
183
Sean Callanan12014a02011-12-08 23:45:45 +0000184bool
Sean Callanancc427fa2011-07-30 02:42:06 +0000185ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
Sean Callanan12014a02011-12-08 23:45:45 +0000186{
Sean Callanancc427fa2011-07-30 02:42:06 +0000187 DeclOrigin decl_origin = GetDeclOrigin(decl);
Greg Claytona2721472011-06-25 00:44:06 +0000188
Sean Callanancc427fa2011-07-30 02:42:06 +0000189 if (!decl_origin.Valid())
Sean Callanan12014a02011-12-08 23:45:45 +0000190 return false;
Greg Claytona2721472011-06-25 00:44:06 +0000191
Sean Callanancc427fa2011-07-30 02:42:06 +0000192 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
Sean Callanan12014a02011-12-08 23:45:45 +0000193 return false;
Greg Claytona2721472011-06-25 00:44:06 +0000194
Sean Callanan686b2312011-11-16 18:20:47 +0000195 MinionSP minion_sp (GetMinion(&decl->getASTContext(), decl_origin.ctx));
Greg Claytona2721472011-06-25 00:44:06 +0000196
Greg Claytondd0649b2011-07-06 18:55:08 +0000197 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000198 minion_sp->ImportDefinitionTo(decl, decl_origin.decl);
199
Sean Callanan12014a02011-12-08 23:45:45 +0000200 return true;
Greg Claytona2721472011-06-25 00:44:06 +0000201}
Sean Callanancc427fa2011-07-30 02:42:06 +0000202
Sean Callanan12014a02011-12-08 23:45:45 +0000203bool
204ClangASTImporter::CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin_decl)
205{
206 clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext();
207
208 if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl))
209 return false;
210
211 MinionSP minion_sp (GetMinion(&decl->getASTContext(), origin_ast_ctx));
212
213 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000214 minion_sp->ImportDefinitionTo(decl, origin_decl);
215
Sean Callanan12014a02011-12-08 23:45:45 +0000216 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
217
218 OriginMap &origins = context_md->m_origins;
219
220 origins[decl] = DeclOrigin(origin_ast_ctx, origin_decl);
221
222 return true;
223}
224
225bool
Sean Callanancc427fa2011-07-30 02:42:06 +0000226ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
227{
228 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
229
Sean Callanancc427fa2011-07-30 02:42:06 +0000230 DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
231
232 if (!decl_origin.Valid())
Sean Callanan12014a02011-12-08 23:45:45 +0000233 return false;
Sean Callanancc427fa2011-07-30 02:42:06 +0000234
235 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
Sean Callanan12014a02011-12-08 23:45:45 +0000236 return false;
Sean Callanancc427fa2011-07-30 02:42:06 +0000237
Sean Callanan686b2312011-11-16 18:20:47 +0000238 MinionSP minion_sp (GetMinion(&interface_decl->getASTContext(), decl_origin.ctx));
Sean Callanancc427fa2011-07-30 02:42:06 +0000239
240 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000241 minion_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
242
Sean Callanan12014a02011-12-08 23:45:45 +0000243 return true;
Sean Callanancc427fa2011-07-30 02:42:06 +0000244}
245
Sean Callanan60217122012-04-13 00:10:03 +0000246uint64_t
247ClangASTImporter::GetDeclMetadata (const clang::Decl *decl)
248{
249 DeclOrigin decl_origin = GetDeclOrigin(decl);
250
251 if (decl_origin.Valid())
252 return ClangASTContext::GetMetadata(decl_origin.ctx, (uintptr_t)decl_origin.decl);
253 else
254 return ClangASTContext::GetMetadata(&decl->getASTContext(), (uintptr_t)decl);
255}
256
Sean Callananf487bd82011-11-16 21:40:57 +0000257ClangASTImporter::DeclOrigin
258ClangASTImporter::GetDeclOrigin(const clang::Decl *decl)
259{
260 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
261
262 OriginMap &origins = context_md->m_origins;
263
264 OriginMap::iterator iter = origins.find(decl);
265
266 if (iter != origins.end())
267 return iter->second;
268 else
269 return DeclOrigin();
270}
271
Sean Callanan503aa522011-10-12 00:12:34 +0000272void
273ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
274 NamespaceMapSP &namespace_map)
275{
Sean Callananf487bd82011-11-16 21:40:57 +0000276 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
277
278 context_md->m_namespace_maps[decl] = namespace_map;
Sean Callanan503aa522011-10-12 00:12:34 +0000279}
280
281ClangASTImporter::NamespaceMapSP
282ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
283{
Sean Callananf487bd82011-11-16 21:40:57 +0000284 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
285
286 NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps;
Sean Callanan503aa522011-10-12 00:12:34 +0000287
Sean Callananf487bd82011-11-16 21:40:57 +0000288 NamespaceMetaMap::iterator iter = namespace_maps.find(decl);
289
290 if (iter != namespace_maps.end())
Sean Callanan503aa522011-10-12 00:12:34 +0000291 return iter->second;
292 else
293 return NamespaceMapSP();
294}
295
Sean Callananb2269162011-10-21 22:18:07 +0000296void
297ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
298{
Sean Callananf487bd82011-11-16 21:40:57 +0000299 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
300
Sean Callananb2269162011-10-21 22:18:07 +0000301 const DeclContext *parent_context = decl->getDeclContext();
302 const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
303 NamespaceMapSP parent_map;
304
305 if (parent_namespace)
306 parent_map = GetNamespaceMap(parent_namespace);
307
308 NamespaceMapSP new_map;
309
310 new_map.reset(new NamespaceMap);
311
Sean Callananf487bd82011-11-16 21:40:57 +0000312 if (context_md->m_map_completer)
Sean Callananb2269162011-10-21 22:18:07 +0000313 {
314 std::string namespace_string = decl->getDeclName().getAsString();
315
Sean Callananf487bd82011-11-16 21:40:57 +0000316 context_md->m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
Sean Callananb2269162011-10-21 22:18:07 +0000317 }
318
Sean Callanan0eed0d42011-12-06 03:41:14 +0000319 context_md->m_namespace_maps[decl] = new_map;
Sean Callananb2269162011-10-21 22:18:07 +0000320}
321
Sean Callanan686b2312011-11-16 18:20:47 +0000322void
Sean Callanan99732312011-11-29 00:42:02 +0000323ClangASTImporter::ForgetDestination (clang::ASTContext *dst_ast)
Sean Callanan686b2312011-11-16 18:20:47 +0000324{
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000325 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
326
327 if (log)
328 log->Printf(" [ClangASTImporter] Forgetting destination (ASTContext*)%p", dst_ast);
329
Sean Callananf487bd82011-11-16 21:40:57 +0000330 m_metadata_map.erase(dst_ast);
Sean Callanan686b2312011-11-16 18:20:47 +0000331}
332
Sean Callanan99732312011-11-29 00:42:02 +0000333void
334ClangASTImporter::ForgetSource (clang::ASTContext *dst_ast, clang::ASTContext *src_ast)
335{
336 ASTContextMetadataSP md = MaybeGetContextMetadata (dst_ast);
337
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000338 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
339
340 if (log)
341 log->Printf(" [ClangASTImporter] Forgetting source->dest (ASTContext*)%p->(ASTContext*)%p", src_ast, dst_ast);
342
Sean Callanan99732312011-11-29 00:42:02 +0000343 if (!md)
344 return;
345
346 md->m_minions.erase(src_ast);
347
348 for (OriginMap::iterator iter = md->m_origins.begin();
349 iter != md->m_origins.end();
350 )
351 {
352 if (iter->second.ctx == src_ast)
353 md->m_origins.erase(iter++);
354 else
355 ++iter;
356 }
357}
358
Sean Callanan0eed0d42011-12-06 03:41:14 +0000359ClangASTImporter::MapCompleter::~MapCompleter ()
Sean Callananb2269162011-10-21 22:18:07 +0000360{
361 return;
362}
363
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000364void
365ClangASTImporter::Minion::ImportDefinitionTo (clang::Decl *to, clang::Decl *from)
366{
367 ASTImporter::Imported(from, to);
Sean Callanan5b26f272012-02-04 08:49:35 +0000368
369 ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to);
370
371 /*
372 if (to_objc_interface)
373 to_objc_interface->startDefinition();
374
375 CXXRecordDecl *to_cxx_record = dyn_cast<CXXRecordDecl>(to);
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000376
Sean Callanan5b26f272012-02-04 08:49:35 +0000377 if (to_cxx_record)
378 to_cxx_record->startDefinition();
379 */
380
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000381 ImportDefinition(from);
Sean Callanan5b26f272012-02-04 08:49:35 +0000382
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000383 // If we're dealing with an Objective-C class, ensure that the inheritance has
384 // been set up correctly. The ASTImporter may not do this correctly if the
385 // class was originally sourced from symbols.
386
Sean Callanan5b26f272012-02-04 08:49:35 +0000387 if (to_objc_interface)
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000388 {
389 do
390 {
391 ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
392
393 if (to_superclass)
394 break; // we're not going to override it if it's set
395
396 ObjCInterfaceDecl *from_objc_interface = dyn_cast<ObjCInterfaceDecl>(from);
397
398 if (!from_objc_interface)
399 break;
400
401 ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
402
403 if (!from_superclass)
404 break;
405
406 Decl *imported_from_superclass_decl = Import(from_superclass);
407
408 if (!imported_from_superclass_decl)
409 break;
410
411 ObjCInterfaceDecl *imported_from_superclass = dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl);
412
413 if (!imported_from_superclass)
414 break;
415
Sean Callanan5b26f272012-02-04 08:49:35 +0000416 if (!to_objc_interface->hasDefinition())
417 to_objc_interface->startDefinition();
418
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000419 to_objc_interface->setSuperClass(imported_from_superclass);
420 }
421 while (0);
422 }
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000423}
424
Sean Callanancc427fa2011-07-30 02:42:06 +0000425clang::Decl
426*ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
427{
428 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Sean Callanan00f43622011-11-18 03:28:09 +0000429
430 if (log)
431 {
432 if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from))
433 {
Sean Callanan60217122012-04-13 00:10:03 +0000434 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named %s (from (Decl*)%p), metadata 0x%llx",
Sean Callanan00f43622011-11-18 03:28:09 +0000435 from->getDeclKindName(),
436 to,
437 from_named_decl->getName().str().c_str(),
Sean Callanan60217122012-04-13 00:10:03 +0000438 from,
439 m_master.GetDeclMetadata(from));
Sean Callanan00f43622011-11-18 03:28:09 +0000440 }
441 else
442 {
Sean Callanan60217122012-04-13 00:10:03 +0000443 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p (from (Decl*)%p), metadata 0x%llx",
Sean Callanan00f43622011-11-18 03:28:09 +0000444 from->getDeclKindName(),
445 to,
Sean Callanan60217122012-04-13 00:10:03 +0000446 from,
447 m_master.GetDeclMetadata(from));
Sean Callanan00f43622011-11-18 03:28:09 +0000448 }
449 }
450
Sean Callananb0b87a52011-11-16 22:23:28 +0000451 ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&to->getASTContext());
452 ASTContextMetadataSP from_context_md = m_master.MaybeGetContextMetadata(m_source_ctx);
Sean Callananf487bd82011-11-16 21:40:57 +0000453
Sean Callananb0b87a52011-11-16 22:23:28 +0000454 if (from_context_md)
455 {
456 OriginMap &origins = from_context_md->m_origins;
457
458 OriginMap::iterator origin_iter = origins.find(from);
459
460 if (origin_iter != origins.end())
Sean Callanan00f43622011-11-18 03:28:09 +0000461 {
Sean Callananb0b87a52011-11-16 22:23:28 +0000462 to_context_md->m_origins[to] = origin_iter->second;
Sean Callanan00f43622011-11-18 03:28:09 +0000463
Sean Callanan5bc5a762011-12-20 23:55:47 +0000464 MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx);
465
466 if (direct_completer.get() != this)
467 direct_completer->ASTImporter::Imported(origin_iter->second.decl, to);
468
Sean Callanan00f43622011-11-18 03:28:09 +0000469 if (log)
470 log->Printf(" [ClangASTImporter] Propagated origin (Decl*)%p/(ASTContext*)%p from (ASTContext*)%p to (ASTContext*)%p",
471 origin_iter->second.decl,
472 origin_iter->second.ctx,
473 &from->getASTContext(),
474 &to->getASTContext());
475 }
476 else
477 {
Sean Callanan0eed0d42011-12-06 03:41:14 +0000478 to_context_md->m_origins[to] = DeclOrigin(m_source_ctx, from);
479
Sean Callanan00f43622011-11-18 03:28:09 +0000480 if (log)
481 log->Printf(" [ClangASTImporter] Decl has no origin information in (ASTContext*)%p",
482 &from->getASTContext());
483 }
Sean Callananb0b87a52011-11-16 22:23:28 +0000484
485 if (clang::NamespaceDecl *to_namespace = dyn_cast<clang::NamespaceDecl>(to))
486 {
487 clang::NamespaceDecl *from_namespace = dyn_cast<clang::NamespaceDecl>(from);
488
489 NamespaceMetaMap &namespace_maps = from_context_md->m_namespace_maps;
490
491 NamespaceMetaMap::iterator namespace_map_iter = namespace_maps.find(from_namespace);
492
493 if (namespace_map_iter != namespace_maps.end())
494 to_context_md->m_namespace_maps[to_namespace] = namespace_map_iter->second;
495 }
496 }
497 else
498 {
499 to_context_md->m_origins[to] = DeclOrigin (m_source_ctx, from);
Sean Callanan00f43622011-11-18 03:28:09 +0000500
501 if (log)
502 log->Printf(" [ClangASTImporter] Sourced origin (Decl*)%p/(ASTContext*)%p into (ASTContext*)%p",
503 from,
504 m_source_ctx,
505 &to->getASTContext());
Sean Callananb0b87a52011-11-16 22:23:28 +0000506 }
507
Sean Callanancc427fa2011-07-30 02:42:06 +0000508 if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
509 {
510 TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
511
512 to_tag_decl->setHasExternalLexicalStorage();
Sean Callanan0730e9c2011-11-09 19:33:21 +0000513
Sean Callanancc427fa2011-07-30 02:42:06 +0000514 if (log)
Sean Callanan00f43622011-11-18 03:28:09 +0000515 log->Printf(" [ClangASTImporter] To is a TagDecl - attributes %s%s [%s->%s]",
Sean Callanancc427fa2011-07-30 02:42:06 +0000516 (to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
Sean Callanan0730e9c2011-11-09 19:33:21 +0000517 (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
518 (from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
519 (to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
Sean Callanan00f43622011-11-18 03:28:09 +0000520
521 to_tag_decl = NULL;
Sean Callanancc427fa2011-07-30 02:42:06 +0000522 }
523
Sean Callananb2269162011-10-21 22:18:07 +0000524 if (isa<NamespaceDecl>(from))
525 {
526 NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
527
528 m_master.BuildNamespaceMap(to_namespace_decl);
529
530 to_namespace_decl->setHasExternalVisibleStorage();
531 }
532
Sean Callanan00f43622011-11-18 03:28:09 +0000533 if (isa<ObjCInterfaceDecl>(from))
Sean Callanancc427fa2011-07-30 02:42:06 +0000534 {
535 ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
Sean Callanana9bc0652012-01-19 02:17:40 +0000536
Sean Callanand5c17ed2011-11-15 02:11:17 +0000537 to_interface_decl->setHasExternalLexicalStorage();
Sean Callanan0730e9c2011-11-09 19:33:21 +0000538 to_interface_decl->setHasExternalVisibleStorage();
Sean Callanan5b26f272012-02-04 08:49:35 +0000539
540 /*to_interface_decl->setExternallyCompleted();*/
Sean Callanan0eed0d42011-12-06 03:41:14 +0000541
Sean Callanand5c17ed2011-11-15 02:11:17 +0000542 if (log)
Sean Callanan00f43622011-11-18 03:28:09 +0000543 log->Printf(" [ClangASTImporter] To is an ObjCInterfaceDecl - attributes %s%s%s",
Sean Callanand5c17ed2011-11-15 02:11:17 +0000544 (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
545 (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""),
Sean Callanan5b26f272012-02-04 08:49:35 +0000546 (to_interface_decl->hasDefinition() ? " HasDefinition" : ""));
Sean Callanancc427fa2011-07-30 02:42:06 +0000547 }
548
549 return clang::ASTImporter::Imported(from, to);
Greg Clayton3418c852011-08-10 02:10:13 +0000550}