blob: 04ef8ffc2b34ecd4a2fffda6c67501c32a5c68b8 [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 Callananb2269162011-10-21 22:18:07 +000017#include "lldb/Symbol/ClangNamespaceDecl.h"
Greg Claytona2721472011-06-25 00:44:06 +000018
19using namespace lldb_private;
20using namespace clang;
21
22clang::QualType
Sean Callanan686b2312011-11-16 18:20:47 +000023ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
24 clang::ASTContext *src_ast,
Greg Claytona2721472011-06-25 00:44:06 +000025 clang::QualType type)
26{
Sean Callanan686b2312011-11-16 18:20:47 +000027 MinionSP minion_sp (GetMinion(dst_ast, src_ast));
Sean Callanancc427fa2011-07-30 02:42:06 +000028
Greg Claytondd0649b2011-07-06 18:55:08 +000029 if (minion_sp)
30 return minion_sp->Import(type);
Sean Callanancc427fa2011-07-30 02:42:06 +000031
Greg Claytondd0649b2011-07-06 18:55:08 +000032 return QualType();
Greg Claytona2721472011-06-25 00:44:06 +000033}
34
Sean Callanan80f78672011-11-16 19:07:39 +000035lldb::clang_type_t
36ClangASTImporter::CopyType (clang::ASTContext *dst_ast,
37 clang::ASTContext *src_ast,
38 lldb::clang_type_t type)
39{
40 return CopyType (dst_ast, src_ast, QualType::getFromOpaquePtr(type)).getAsOpaquePtr();
41}
42
Greg Claytona2721472011-06-25 00:44:06 +000043clang::Decl *
Sean Callanan686b2312011-11-16 18:20:47 +000044ClangASTImporter::CopyDecl (clang::ASTContext *dst_ast,
45 clang::ASTContext *src_ast,
Greg Claytona2721472011-06-25 00:44:06 +000046 clang::Decl *decl)
47{
Greg Claytondd0649b2011-07-06 18:55:08 +000048 MinionSP minion_sp;
Greg Claytona2721472011-06-25 00:44:06 +000049
Sean Callanan686b2312011-11-16 18:20:47 +000050 minion_sp = GetMinion(dst_ast, src_ast);
Greg Claytona2721472011-06-25 00:44:06 +000051
Greg Claytondd0649b2011-07-06 18:55:08 +000052 if (minion_sp)
Sean Callananbfb237bc2011-11-04 22:46:46 +000053 {
54 clang::Decl *result = minion_sp->Import(decl);
55
56 if (!result)
57 {
58 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
59
Sean Callanand5145b32011-11-05 00:08:12 +000060 if (log)
61 {
62 if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
63 log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s '%s'", decl->getDeclKindName(), named_decl->getNameAsString().c_str());
64 else
65 log->Printf(" [ClangASTImporter] WARNING: Failed to import a %s", decl->getDeclKindName());
66 }
Sean Callananbfb237bc2011-11-04 22:46:46 +000067 }
68
69 return result;
70 }
Sean Callanancc427fa2011-07-30 02:42:06 +000071
Greg Claytondd0649b2011-07-06 18:55:08 +000072 return NULL;
Greg Claytona2721472011-06-25 00:44:06 +000073}
74
Sean Callananbb120042011-12-16 21:06:35 +000075lldb::clang_type_t
76ClangASTImporter::DeportType (clang::ASTContext *dst_ctx,
77 clang::ASTContext *src_ctx,
78 lldb::clang_type_t type)
79{
80 lldb::clang_type_t result = CopyType(dst_ctx, src_ctx, type);
81
82 if (!result)
83 return NULL;
84
85 QualType qual_type = QualType::getFromOpaquePtr(type);
86
87 if (const TagType *tag_type = qual_type->getAs<TagType>())
88 {
89 TagDecl *tag_decl = tag_type->getDecl();
90 const TagType *result_tag_type = QualType::getFromOpaquePtr(result)->getAs<TagType>();
91 TagDecl *result_tag_decl = result_tag_type->getDecl();
92
93 if (tag_decl)
94 {
95 MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
96
Sean Callanancbbe3ac2012-01-13 22:55:55 +000097 minion_sp->ImportDefinitionTo(result_tag_decl, tag_decl);
Sean Callananbb120042011-12-16 21:06:35 +000098
99 ASTContextMetadataSP to_context_md = GetContextMetadata(dst_ctx);
100
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000101 OriginMap::iterator oi = to_context_md->m_origins.find(result_tag_decl);
102
103 if (oi != to_context_md->m_origins.end() &&
104 oi->second.ctx == src_ctx)
105 to_context_md->m_origins.erase(oi);
Sean Callananbb120042011-12-16 21:06:35 +0000106 }
107 }
108
109 return result;
110}
111
Sean Callanan0eed0d42011-12-06 03:41:14 +0000112clang::Decl *
113ClangASTImporter::DeportDecl (clang::ASTContext *dst_ctx,
114 clang::ASTContext *src_ctx,
115 clang::Decl *decl)
116{
117 clang::Decl *result = CopyDecl(dst_ctx, src_ctx, decl);
118
119 if (!result)
120 return NULL;
121
122 ClangASTContext::GetCompleteDecl (src_ctx, decl);
123
124 MinionSP minion_sp (GetMinion (dst_ctx, src_ctx));
125
126 if (minion_sp && isa<TagDecl>(decl))
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000127 minion_sp->ImportDefinitionTo(result, decl);
Sean Callanan0eed0d42011-12-06 03:41:14 +0000128
129 ASTContextMetadataSP to_context_md = GetContextMetadata(dst_ctx);
130
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000131 OriginMap::iterator oi = to_context_md->m_origins.find(decl);
132
133 if (oi != to_context_md->m_origins.end() &&
134 oi->second.ctx == src_ctx)
135 to_context_md->m_origins.erase(oi);
Sean Callanan0eed0d42011-12-06 03:41:14 +0000136
137 return result;
138}
139
Sean Callanan5b26f272012-02-04 08:49:35 +0000140void
141ClangASTImporter::CompleteDecl (clang::Decl *decl)
142{
143 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
144
145 if (log)
146 log->Printf(" [ClangASTImporter] CompleteDecl called on (%sDecl*)%p",
147 decl->getDeclKindName(),
148 decl);
149
150 if (ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl))
151 {
152 if (!interface_decl->getDefinition())
153 {
154 interface_decl->startDefinition();
155 CompleteObjCInterfaceDecl(interface_decl);
156 }
157 }
158 else if (ObjCProtocolDecl *protocol_decl = dyn_cast<ObjCProtocolDecl>(protocol_decl))
159 {
160 if (!protocol_decl->getDefinition())
161 protocol_decl->startDefinition();
162 }
163 else if (TagDecl *tag_decl = dyn_cast<TagDecl>(decl))
164 {
165 if (!tag_decl->getDefinition() && !tag_decl->isBeingDefined())
166 {
167 tag_decl->startDefinition();
168 CompleteTagDecl(tag_decl);
169 tag_decl->setCompleteDefinition(true);
170 }
171 }
Greg Clayton219cf312012-03-30 00:51:13 +0000172 else
173 {
Sean Callanan5b26f272012-02-04 08:49:35 +0000174 assert (0 && "CompleteDecl called on a Decl that can't be completed");
175 }
176}
177
Sean Callanan12014a02011-12-08 23:45:45 +0000178bool
Sean Callanancc427fa2011-07-30 02:42:06 +0000179ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
Sean Callanan12014a02011-12-08 23:45:45 +0000180{
Sean Callanancc427fa2011-07-30 02:42:06 +0000181 DeclOrigin decl_origin = GetDeclOrigin(decl);
Greg Claytona2721472011-06-25 00:44:06 +0000182
Sean Callanancc427fa2011-07-30 02:42:06 +0000183 if (!decl_origin.Valid())
Sean Callanan12014a02011-12-08 23:45:45 +0000184 return false;
Greg Claytona2721472011-06-25 00:44:06 +0000185
Sean Callanancc427fa2011-07-30 02:42:06 +0000186 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
Sean Callanan12014a02011-12-08 23:45:45 +0000187 return false;
Greg Claytona2721472011-06-25 00:44:06 +0000188
Sean Callanan686b2312011-11-16 18:20:47 +0000189 MinionSP minion_sp (GetMinion(&decl->getASTContext(), decl_origin.ctx));
Greg Claytona2721472011-06-25 00:44:06 +0000190
Greg Claytondd0649b2011-07-06 18:55:08 +0000191 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000192 minion_sp->ImportDefinitionTo(decl, decl_origin.decl);
193
Sean Callanan12014a02011-12-08 23:45:45 +0000194 return true;
Greg Claytona2721472011-06-25 00:44:06 +0000195}
Sean Callanancc427fa2011-07-30 02:42:06 +0000196
Sean Callanan12014a02011-12-08 23:45:45 +0000197bool
198ClangASTImporter::CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin_decl)
199{
200 clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext();
201
202 if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl))
203 return false;
204
205 MinionSP minion_sp (GetMinion(&decl->getASTContext(), origin_ast_ctx));
206
207 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000208 minion_sp->ImportDefinitionTo(decl, origin_decl);
209
Sean Callanan12014a02011-12-08 23:45:45 +0000210 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
211
212 OriginMap &origins = context_md->m_origins;
213
214 origins[decl] = DeclOrigin(origin_ast_ctx, origin_decl);
215
216 return true;
217}
218
219bool
Sean Callanancc427fa2011-07-30 02:42:06 +0000220ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
221{
222 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
223
Sean Callanancc427fa2011-07-30 02:42:06 +0000224 DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
225
226 if (!decl_origin.Valid())
Sean Callanan12014a02011-12-08 23:45:45 +0000227 return false;
Sean Callanancc427fa2011-07-30 02:42:06 +0000228
229 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
Sean Callanan12014a02011-12-08 23:45:45 +0000230 return false;
Sean Callanancc427fa2011-07-30 02:42:06 +0000231
Sean Callanan686b2312011-11-16 18:20:47 +0000232 MinionSP minion_sp (GetMinion(&interface_decl->getASTContext(), decl_origin.ctx));
Sean Callanancc427fa2011-07-30 02:42:06 +0000233
234 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000235 minion_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
236
Sean Callanan12014a02011-12-08 23:45:45 +0000237 return true;
Sean Callanancc427fa2011-07-30 02:42:06 +0000238}
239
Sean Callananf487bd82011-11-16 21:40:57 +0000240ClangASTImporter::DeclOrigin
241ClangASTImporter::GetDeclOrigin(const clang::Decl *decl)
242{
243 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
244
245 OriginMap &origins = context_md->m_origins;
246
247 OriginMap::iterator iter = origins.find(decl);
248
249 if (iter != origins.end())
250 return iter->second;
251 else
252 return DeclOrigin();
253}
254
Sean Callanan503aa522011-10-12 00:12:34 +0000255void
256ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
257 NamespaceMapSP &namespace_map)
258{
Sean Callananf487bd82011-11-16 21:40:57 +0000259 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
260
261 context_md->m_namespace_maps[decl] = namespace_map;
Sean Callanan503aa522011-10-12 00:12:34 +0000262}
263
264ClangASTImporter::NamespaceMapSP
265ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
266{
Sean Callananf487bd82011-11-16 21:40:57 +0000267 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
268
269 NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps;
Sean Callanan503aa522011-10-12 00:12:34 +0000270
Sean Callananf487bd82011-11-16 21:40:57 +0000271 NamespaceMetaMap::iterator iter = namespace_maps.find(decl);
272
273 if (iter != namespace_maps.end())
Sean Callanan503aa522011-10-12 00:12:34 +0000274 return iter->second;
275 else
276 return NamespaceMapSP();
277}
278
Sean Callananb2269162011-10-21 22:18:07 +0000279void
280ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
281{
Sean Callananf487bd82011-11-16 21:40:57 +0000282 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
283
Sean Callananb2269162011-10-21 22:18:07 +0000284 const DeclContext *parent_context = decl->getDeclContext();
285 const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
286 NamespaceMapSP parent_map;
287
288 if (parent_namespace)
289 parent_map = GetNamespaceMap(parent_namespace);
290
291 NamespaceMapSP new_map;
292
293 new_map.reset(new NamespaceMap);
294
Sean Callananf487bd82011-11-16 21:40:57 +0000295 if (context_md->m_map_completer)
Sean Callananb2269162011-10-21 22:18:07 +0000296 {
297 std::string namespace_string = decl->getDeclName().getAsString();
298
Sean Callananf487bd82011-11-16 21:40:57 +0000299 context_md->m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
Sean Callananb2269162011-10-21 22:18:07 +0000300 }
301
Sean Callanan0eed0d42011-12-06 03:41:14 +0000302 context_md->m_namespace_maps[decl] = new_map;
Sean Callananb2269162011-10-21 22:18:07 +0000303}
304
Sean Callanan686b2312011-11-16 18:20:47 +0000305void
Sean Callanan99732312011-11-29 00:42:02 +0000306ClangASTImporter::ForgetDestination (clang::ASTContext *dst_ast)
Sean Callanan686b2312011-11-16 18:20:47 +0000307{
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000308 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
309
310 if (log)
311 log->Printf(" [ClangASTImporter] Forgetting destination (ASTContext*)%p", dst_ast);
312
Sean Callananf487bd82011-11-16 21:40:57 +0000313 m_metadata_map.erase(dst_ast);
Sean Callanan686b2312011-11-16 18:20:47 +0000314}
315
Sean Callanan99732312011-11-29 00:42:02 +0000316void
317ClangASTImporter::ForgetSource (clang::ASTContext *dst_ast, clang::ASTContext *src_ast)
318{
319 ASTContextMetadataSP md = MaybeGetContextMetadata (dst_ast);
320
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000321 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
322
323 if (log)
324 log->Printf(" [ClangASTImporter] Forgetting source->dest (ASTContext*)%p->(ASTContext*)%p", src_ast, dst_ast);
325
Sean Callanan99732312011-11-29 00:42:02 +0000326 if (!md)
327 return;
328
329 md->m_minions.erase(src_ast);
330
331 for (OriginMap::iterator iter = md->m_origins.begin();
332 iter != md->m_origins.end();
333 )
334 {
335 if (iter->second.ctx == src_ast)
336 md->m_origins.erase(iter++);
337 else
338 ++iter;
339 }
340}
341
Sean Callanan0eed0d42011-12-06 03:41:14 +0000342ClangASTImporter::MapCompleter::~MapCompleter ()
Sean Callananb2269162011-10-21 22:18:07 +0000343{
344 return;
345}
346
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000347void
348ClangASTImporter::Minion::ImportDefinitionTo (clang::Decl *to, clang::Decl *from)
349{
350 ASTImporter::Imported(from, to);
Sean Callanan5b26f272012-02-04 08:49:35 +0000351
352 ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to);
353
354 /*
355 if (to_objc_interface)
356 to_objc_interface->startDefinition();
357
358 CXXRecordDecl *to_cxx_record = dyn_cast<CXXRecordDecl>(to);
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000359
Sean Callanan5b26f272012-02-04 08:49:35 +0000360 if (to_cxx_record)
361 to_cxx_record->startDefinition();
362 */
363
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000364 ImportDefinition(from);
Sean Callanan5b26f272012-02-04 08:49:35 +0000365
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000366 // If we're dealing with an Objective-C class, ensure that the inheritance has
367 // been set up correctly. The ASTImporter may not do this correctly if the
368 // class was originally sourced from symbols.
369
Sean Callanan5b26f272012-02-04 08:49:35 +0000370 if (to_objc_interface)
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000371 {
372 do
373 {
374 ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
375
376 if (to_superclass)
377 break; // we're not going to override it if it's set
378
379 ObjCInterfaceDecl *from_objc_interface = dyn_cast<ObjCInterfaceDecl>(from);
380
381 if (!from_objc_interface)
382 break;
383
384 ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
385
386 if (!from_superclass)
387 break;
388
389 Decl *imported_from_superclass_decl = Import(from_superclass);
390
391 if (!imported_from_superclass_decl)
392 break;
393
394 ObjCInterfaceDecl *imported_from_superclass = dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl);
395
396 if (!imported_from_superclass)
397 break;
398
Sean Callanan5b26f272012-02-04 08:49:35 +0000399 if (!to_objc_interface->hasDefinition())
400 to_objc_interface->startDefinition();
401
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000402 to_objc_interface->setSuperClass(imported_from_superclass);
403 }
404 while (0);
405 }
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000406}
407
Sean Callanancc427fa2011-07-30 02:42:06 +0000408clang::Decl
409*ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
410{
411 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Sean Callanan00f43622011-11-18 03:28:09 +0000412
413 if (log)
414 {
415 if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from))
416 {
417 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named %s (from (Decl*)%p)",
418 from->getDeclKindName(),
419 to,
420 from_named_decl->getName().str().c_str(),
421 from);
422 }
423 else
424 {
425 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p (from (Decl*)%p)",
426 from->getDeclKindName(),
427 to,
428 from);
429 }
430 }
431
Sean Callananb0b87a52011-11-16 22:23:28 +0000432 ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&to->getASTContext());
433 ASTContextMetadataSP from_context_md = m_master.MaybeGetContextMetadata(m_source_ctx);
Sean Callananf487bd82011-11-16 21:40:57 +0000434
Sean Callananb0b87a52011-11-16 22:23:28 +0000435 if (from_context_md)
436 {
437 OriginMap &origins = from_context_md->m_origins;
438
439 OriginMap::iterator origin_iter = origins.find(from);
440
441 if (origin_iter != origins.end())
Sean Callanan00f43622011-11-18 03:28:09 +0000442 {
Sean Callananb0b87a52011-11-16 22:23:28 +0000443 to_context_md->m_origins[to] = origin_iter->second;
Sean Callanan00f43622011-11-18 03:28:09 +0000444
Sean Callanan5bc5a762011-12-20 23:55:47 +0000445 MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx);
446
447 if (direct_completer.get() != this)
448 direct_completer->ASTImporter::Imported(origin_iter->second.decl, to);
449
Sean Callanan00f43622011-11-18 03:28:09 +0000450 if (log)
451 log->Printf(" [ClangASTImporter] Propagated origin (Decl*)%p/(ASTContext*)%p from (ASTContext*)%p to (ASTContext*)%p",
452 origin_iter->second.decl,
453 origin_iter->second.ctx,
454 &from->getASTContext(),
455 &to->getASTContext());
456 }
457 else
458 {
Sean Callanan0eed0d42011-12-06 03:41:14 +0000459 to_context_md->m_origins[to] = DeclOrigin(m_source_ctx, from);
460
Sean Callanan00f43622011-11-18 03:28:09 +0000461 if (log)
462 log->Printf(" [ClangASTImporter] Decl has no origin information in (ASTContext*)%p",
463 &from->getASTContext());
464 }
Sean Callananb0b87a52011-11-16 22:23:28 +0000465
466 if (clang::NamespaceDecl *to_namespace = dyn_cast<clang::NamespaceDecl>(to))
467 {
468 clang::NamespaceDecl *from_namespace = dyn_cast<clang::NamespaceDecl>(from);
469
470 NamespaceMetaMap &namespace_maps = from_context_md->m_namespace_maps;
471
472 NamespaceMetaMap::iterator namespace_map_iter = namespace_maps.find(from_namespace);
473
474 if (namespace_map_iter != namespace_maps.end())
475 to_context_md->m_namespace_maps[to_namespace] = namespace_map_iter->second;
476 }
477 }
478 else
479 {
480 to_context_md->m_origins[to] = DeclOrigin (m_source_ctx, from);
Sean Callanan00f43622011-11-18 03:28:09 +0000481
482 if (log)
483 log->Printf(" [ClangASTImporter] Sourced origin (Decl*)%p/(ASTContext*)%p into (ASTContext*)%p",
484 from,
485 m_source_ctx,
486 &to->getASTContext());
Sean Callananb0b87a52011-11-16 22:23:28 +0000487 }
488
Sean Callanancc427fa2011-07-30 02:42:06 +0000489 if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
490 {
491 TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
492
493 to_tag_decl->setHasExternalLexicalStorage();
Sean Callanan0730e9c2011-11-09 19:33:21 +0000494
Sean Callanancc427fa2011-07-30 02:42:06 +0000495 if (log)
Sean Callanan00f43622011-11-18 03:28:09 +0000496 log->Printf(" [ClangASTImporter] To is a TagDecl - attributes %s%s [%s->%s]",
Sean Callanancc427fa2011-07-30 02:42:06 +0000497 (to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
Sean Callanan0730e9c2011-11-09 19:33:21 +0000498 (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
499 (from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
500 (to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
Sean Callanan00f43622011-11-18 03:28:09 +0000501
502 to_tag_decl = NULL;
Sean Callanancc427fa2011-07-30 02:42:06 +0000503 }
504
Sean Callananb2269162011-10-21 22:18:07 +0000505 if (isa<NamespaceDecl>(from))
506 {
507 NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
508
509 m_master.BuildNamespaceMap(to_namespace_decl);
510
511 to_namespace_decl->setHasExternalVisibleStorage();
512 }
513
Sean Callanan00f43622011-11-18 03:28:09 +0000514 if (isa<ObjCInterfaceDecl>(from))
Sean Callanancc427fa2011-07-30 02:42:06 +0000515 {
516 ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
Sean Callanana9bc0652012-01-19 02:17:40 +0000517
Sean Callanand5c17ed2011-11-15 02:11:17 +0000518 to_interface_decl->setHasExternalLexicalStorage();
Sean Callanan0730e9c2011-11-09 19:33:21 +0000519 to_interface_decl->setHasExternalVisibleStorage();
Sean Callanan5b26f272012-02-04 08:49:35 +0000520
521 /*to_interface_decl->setExternallyCompleted();*/
Sean Callanan0eed0d42011-12-06 03:41:14 +0000522
Sean Callanand5c17ed2011-11-15 02:11:17 +0000523 if (log)
Sean Callanan00f43622011-11-18 03:28:09 +0000524 log->Printf(" [ClangASTImporter] To is an ObjCInterfaceDecl - attributes %s%s%s",
Sean Callanand5c17ed2011-11-15 02:11:17 +0000525 (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
526 (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""),
Sean Callanan5b26f272012-02-04 08:49:35 +0000527 (to_interface_decl->hasDefinition() ? " HasDefinition" : ""));
Sean Callanancc427fa2011-07-30 02:42:06 +0000528 }
529
530 return clang::ASTImporter::Imported(from, to);
Greg Clayton3418c852011-08-10 02:10:13 +0000531}