blob: 6b3dc56635211e7304ad520aea389282d37a49ae [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 }
172 else {
173 assert (0 && "CompleteDecl called on a Decl that can't be completed");
174 }
175}
176
Sean Callanan12014a02011-12-08 23:45:45 +0000177bool
Sean Callanancc427fa2011-07-30 02:42:06 +0000178ClangASTImporter::CompleteTagDecl (clang::TagDecl *decl)
Sean Callanan12014a02011-12-08 23:45:45 +0000179{
Sean Callanancc427fa2011-07-30 02:42:06 +0000180 DeclOrigin decl_origin = GetDeclOrigin(decl);
Greg Claytona2721472011-06-25 00:44:06 +0000181
Sean Callanancc427fa2011-07-30 02:42:06 +0000182 if (!decl_origin.Valid())
Sean Callanan12014a02011-12-08 23:45:45 +0000183 return false;
Greg Claytona2721472011-06-25 00:44:06 +0000184
Sean Callanancc427fa2011-07-30 02:42:06 +0000185 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
Sean Callanan12014a02011-12-08 23:45:45 +0000186 return false;
Greg Claytona2721472011-06-25 00:44:06 +0000187
Sean Callanan686b2312011-11-16 18:20:47 +0000188 MinionSP minion_sp (GetMinion(&decl->getASTContext(), decl_origin.ctx));
Greg Claytona2721472011-06-25 00:44:06 +0000189
Greg Claytondd0649b2011-07-06 18:55:08 +0000190 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000191 minion_sp->ImportDefinitionTo(decl, decl_origin.decl);
192
Sean Callanan12014a02011-12-08 23:45:45 +0000193 return true;
Greg Claytona2721472011-06-25 00:44:06 +0000194}
Sean Callanancc427fa2011-07-30 02:42:06 +0000195
Sean Callanan12014a02011-12-08 23:45:45 +0000196bool
197ClangASTImporter::CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin_decl)
198{
199 clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext();
200
201 if (!ClangASTContext::GetCompleteDecl(origin_ast_ctx, origin_decl))
202 return false;
203
204 MinionSP minion_sp (GetMinion(&decl->getASTContext(), origin_ast_ctx));
205
206 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000207 minion_sp->ImportDefinitionTo(decl, origin_decl);
208
Sean Callanan12014a02011-12-08 23:45:45 +0000209 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
210
211 OriginMap &origins = context_md->m_origins;
212
213 origins[decl] = DeclOrigin(origin_ast_ctx, origin_decl);
214
215 return true;
216}
217
218bool
Sean Callanancc427fa2011-07-30 02:42:06 +0000219ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface_decl)
220{
221 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
222
Sean Callanancc427fa2011-07-30 02:42:06 +0000223 DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
224
225 if (!decl_origin.Valid())
Sean Callanan12014a02011-12-08 23:45:45 +0000226 return false;
Sean Callanancc427fa2011-07-30 02:42:06 +0000227
228 if (!ClangASTContext::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
Sean Callanan12014a02011-12-08 23:45:45 +0000229 return false;
Sean Callanancc427fa2011-07-30 02:42:06 +0000230
Sean Callanan686b2312011-11-16 18:20:47 +0000231 MinionSP minion_sp (GetMinion(&interface_decl->getASTContext(), decl_origin.ctx));
Sean Callanancc427fa2011-07-30 02:42:06 +0000232
233 if (minion_sp)
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000234 minion_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
235
Sean Callanan12014a02011-12-08 23:45:45 +0000236 return true;
Sean Callanancc427fa2011-07-30 02:42:06 +0000237}
238
Sean Callananf487bd82011-11-16 21:40:57 +0000239ClangASTImporter::DeclOrigin
240ClangASTImporter::GetDeclOrigin(const clang::Decl *decl)
241{
242 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
243
244 OriginMap &origins = context_md->m_origins;
245
246 OriginMap::iterator iter = origins.find(decl);
247
248 if (iter != origins.end())
249 return iter->second;
250 else
251 return DeclOrigin();
252}
253
Sean Callanan503aa522011-10-12 00:12:34 +0000254void
255ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
256 NamespaceMapSP &namespace_map)
257{
Sean Callananf487bd82011-11-16 21:40:57 +0000258 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
259
260 context_md->m_namespace_maps[decl] = namespace_map;
Sean Callanan503aa522011-10-12 00:12:34 +0000261}
262
263ClangASTImporter::NamespaceMapSP
264ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
265{
Sean Callananf487bd82011-11-16 21:40:57 +0000266 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
267
268 NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps;
Sean Callanan503aa522011-10-12 00:12:34 +0000269
Sean Callananf487bd82011-11-16 21:40:57 +0000270 NamespaceMetaMap::iterator iter = namespace_maps.find(decl);
271
272 if (iter != namespace_maps.end())
Sean Callanan503aa522011-10-12 00:12:34 +0000273 return iter->second;
274 else
275 return NamespaceMapSP();
276}
277
Sean Callananb2269162011-10-21 22:18:07 +0000278void
279ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
280{
Sean Callananf487bd82011-11-16 21:40:57 +0000281 ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
282
Sean Callananb2269162011-10-21 22:18:07 +0000283 const DeclContext *parent_context = decl->getDeclContext();
284 const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
285 NamespaceMapSP parent_map;
286
287 if (parent_namespace)
288 parent_map = GetNamespaceMap(parent_namespace);
289
290 NamespaceMapSP new_map;
291
292 new_map.reset(new NamespaceMap);
293
Sean Callananf487bd82011-11-16 21:40:57 +0000294 if (context_md->m_map_completer)
Sean Callananb2269162011-10-21 22:18:07 +0000295 {
296 std::string namespace_string = decl->getDeclName().getAsString();
297
Sean Callananf487bd82011-11-16 21:40:57 +0000298 context_md->m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
Sean Callananb2269162011-10-21 22:18:07 +0000299 }
300
Sean Callanan0eed0d42011-12-06 03:41:14 +0000301 context_md->m_namespace_maps[decl] = new_map;
Sean Callananb2269162011-10-21 22:18:07 +0000302}
303
Sean Callanan686b2312011-11-16 18:20:47 +0000304void
Sean Callanan99732312011-11-29 00:42:02 +0000305ClangASTImporter::ForgetDestination (clang::ASTContext *dst_ast)
Sean Callanan686b2312011-11-16 18:20:47 +0000306{
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000307 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
308
309 if (log)
310 log->Printf(" [ClangASTImporter] Forgetting destination (ASTContext*)%p", dst_ast);
311
Sean Callananf487bd82011-11-16 21:40:57 +0000312 m_metadata_map.erase(dst_ast);
Sean Callanan686b2312011-11-16 18:20:47 +0000313}
314
Sean Callanan99732312011-11-29 00:42:02 +0000315void
316ClangASTImporter::ForgetSource (clang::ASTContext *dst_ast, clang::ASTContext *src_ast)
317{
318 ASTContextMetadataSP md = MaybeGetContextMetadata (dst_ast);
319
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000320 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
321
322 if (log)
323 log->Printf(" [ClangASTImporter] Forgetting source->dest (ASTContext*)%p->(ASTContext*)%p", src_ast, dst_ast);
324
Sean Callanan99732312011-11-29 00:42:02 +0000325 if (!md)
326 return;
327
328 md->m_minions.erase(src_ast);
329
330 for (OriginMap::iterator iter = md->m_origins.begin();
331 iter != md->m_origins.end();
332 )
333 {
334 if (iter->second.ctx == src_ast)
335 md->m_origins.erase(iter++);
336 else
337 ++iter;
338 }
339}
340
Sean Callanan0eed0d42011-12-06 03:41:14 +0000341ClangASTImporter::MapCompleter::~MapCompleter ()
Sean Callananb2269162011-10-21 22:18:07 +0000342{
343 return;
344}
345
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000346void
347ClangASTImporter::Minion::ImportDefinitionTo (clang::Decl *to, clang::Decl *from)
348{
349 ASTImporter::Imported(from, to);
Sean Callanan5b26f272012-02-04 08:49:35 +0000350
351 ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to);
352
353 /*
354 if (to_objc_interface)
355 to_objc_interface->startDefinition();
356
357 CXXRecordDecl *to_cxx_record = dyn_cast<CXXRecordDecl>(to);
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000358
Sean Callanan5b26f272012-02-04 08:49:35 +0000359 if (to_cxx_record)
360 to_cxx_record->startDefinition();
361 */
362
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000363 ImportDefinition(from);
Sean Callanan5b26f272012-02-04 08:49:35 +0000364
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000365 // If we're dealing with an Objective-C class, ensure that the inheritance has
366 // been set up correctly. The ASTImporter may not do this correctly if the
367 // class was originally sourced from symbols.
368
Sean Callanan5b26f272012-02-04 08:49:35 +0000369 if (to_objc_interface)
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000370 {
371 do
372 {
373 ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
374
375 if (to_superclass)
376 break; // we're not going to override it if it's set
377
378 ObjCInterfaceDecl *from_objc_interface = dyn_cast<ObjCInterfaceDecl>(from);
379
380 if (!from_objc_interface)
381 break;
382
383 ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
384
385 if (!from_superclass)
386 break;
387
388 Decl *imported_from_superclass_decl = Import(from_superclass);
389
390 if (!imported_from_superclass_decl)
391 break;
392
393 ObjCInterfaceDecl *imported_from_superclass = dyn_cast<ObjCInterfaceDecl>(imported_from_superclass_decl);
394
395 if (!imported_from_superclass)
396 break;
397
Sean Callanan5b26f272012-02-04 08:49:35 +0000398 if (!to_objc_interface->hasDefinition())
399 to_objc_interface->startDefinition();
400
Sean Callanan2e93a2a2012-01-19 18:23:06 +0000401 to_objc_interface->setSuperClass(imported_from_superclass);
402 }
403 while (0);
404 }
Sean Callanancbbe3ac2012-01-13 22:55:55 +0000405}
406
Sean Callanancc427fa2011-07-30 02:42:06 +0000407clang::Decl
408*ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
409{
410 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
Sean Callanan00f43622011-11-18 03:28:09 +0000411
412 if (log)
413 {
414 if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from))
415 {
416 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p, named %s (from (Decl*)%p)",
417 from->getDeclKindName(),
418 to,
419 from_named_decl->getName().str().c_str(),
420 from);
421 }
422 else
423 {
424 log->Printf(" [ClangASTImporter] Imported (%sDecl*)%p (from (Decl*)%p)",
425 from->getDeclKindName(),
426 to,
427 from);
428 }
429 }
430
Sean Callananb0b87a52011-11-16 22:23:28 +0000431 ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&to->getASTContext());
432 ASTContextMetadataSP from_context_md = m_master.MaybeGetContextMetadata(m_source_ctx);
Sean Callananf487bd82011-11-16 21:40:57 +0000433
Sean Callananb0b87a52011-11-16 22:23:28 +0000434 if (from_context_md)
435 {
436 OriginMap &origins = from_context_md->m_origins;
437
438 OriginMap::iterator origin_iter = origins.find(from);
439
440 if (origin_iter != origins.end())
Sean Callanan00f43622011-11-18 03:28:09 +0000441 {
Sean Callananb0b87a52011-11-16 22:23:28 +0000442 to_context_md->m_origins[to] = origin_iter->second;
Sean Callanan00f43622011-11-18 03:28:09 +0000443
Sean Callanan5bc5a762011-12-20 23:55:47 +0000444 MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx);
445
446 if (direct_completer.get() != this)
447 direct_completer->ASTImporter::Imported(origin_iter->second.decl, to);
448
Sean Callanan00f43622011-11-18 03:28:09 +0000449 if (log)
450 log->Printf(" [ClangASTImporter] Propagated origin (Decl*)%p/(ASTContext*)%p from (ASTContext*)%p to (ASTContext*)%p",
451 origin_iter->second.decl,
452 origin_iter->second.ctx,
453 &from->getASTContext(),
454 &to->getASTContext());
455 }
456 else
457 {
Sean Callanan0eed0d42011-12-06 03:41:14 +0000458 to_context_md->m_origins[to] = DeclOrigin(m_source_ctx, from);
459
Sean Callanan00f43622011-11-18 03:28:09 +0000460 if (log)
461 log->Printf(" [ClangASTImporter] Decl has no origin information in (ASTContext*)%p",
462 &from->getASTContext());
463 }
Sean Callananb0b87a52011-11-16 22:23:28 +0000464
465 if (clang::NamespaceDecl *to_namespace = dyn_cast<clang::NamespaceDecl>(to))
466 {
467 clang::NamespaceDecl *from_namespace = dyn_cast<clang::NamespaceDecl>(from);
468
469 NamespaceMetaMap &namespace_maps = from_context_md->m_namespace_maps;
470
471 NamespaceMetaMap::iterator namespace_map_iter = namespace_maps.find(from_namespace);
472
473 if (namespace_map_iter != namespace_maps.end())
474 to_context_md->m_namespace_maps[to_namespace] = namespace_map_iter->second;
475 }
476 }
477 else
478 {
479 to_context_md->m_origins[to] = DeclOrigin (m_source_ctx, from);
Sean Callanan00f43622011-11-18 03:28:09 +0000480
481 if (log)
482 log->Printf(" [ClangASTImporter] Sourced origin (Decl*)%p/(ASTContext*)%p into (ASTContext*)%p",
483 from,
484 m_source_ctx,
485 &to->getASTContext());
Sean Callananb0b87a52011-11-16 22:23:28 +0000486 }
487
Sean Callanancc427fa2011-07-30 02:42:06 +0000488 if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
489 {
490 TagDecl *to_tag_decl = dyn_cast<TagDecl>(to);
491
492 to_tag_decl->setHasExternalLexicalStorage();
Sean Callanan0730e9c2011-11-09 19:33:21 +0000493
Sean Callanancc427fa2011-07-30 02:42:06 +0000494 if (log)
Sean Callanan00f43622011-11-18 03:28:09 +0000495 log->Printf(" [ClangASTImporter] To is a TagDecl - attributes %s%s [%s->%s]",
Sean Callanancc427fa2011-07-30 02:42:06 +0000496 (to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
Sean Callanan0730e9c2011-11-09 19:33:21 +0000497 (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
498 (from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
499 (to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
Sean Callanan00f43622011-11-18 03:28:09 +0000500
501 to_tag_decl = NULL;
Sean Callanancc427fa2011-07-30 02:42:06 +0000502 }
503
Sean Callananb2269162011-10-21 22:18:07 +0000504 if (isa<NamespaceDecl>(from))
505 {
506 NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
507
508 m_master.BuildNamespaceMap(to_namespace_decl);
509
510 to_namespace_decl->setHasExternalVisibleStorage();
511 }
512
Sean Callanan00f43622011-11-18 03:28:09 +0000513 if (isa<ObjCInterfaceDecl>(from))
Sean Callanancc427fa2011-07-30 02:42:06 +0000514 {
515 ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);
Sean Callanana9bc0652012-01-19 02:17:40 +0000516
Sean Callanand5c17ed2011-11-15 02:11:17 +0000517 to_interface_decl->setHasExternalLexicalStorage();
Sean Callanan0730e9c2011-11-09 19:33:21 +0000518 to_interface_decl->setHasExternalVisibleStorage();
Sean Callanan5b26f272012-02-04 08:49:35 +0000519
520 /*to_interface_decl->setExternallyCompleted();*/
Sean Callanan0eed0d42011-12-06 03:41:14 +0000521
Sean Callanand5c17ed2011-11-15 02:11:17 +0000522 if (log)
Sean Callanan00f43622011-11-18 03:28:09 +0000523 log->Printf(" [ClangASTImporter] To is an ObjCInterfaceDecl - attributes %s%s%s",
Sean Callanand5c17ed2011-11-15 02:11:17 +0000524 (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
525 (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""),
Sean Callanan5b26f272012-02-04 08:49:35 +0000526 (to_interface_decl->hasDefinition() ? " HasDefinition" : ""));
Sean Callanancc427fa2011-07-30 02:42:06 +0000527 }
528
529 return clang::ASTImporter::Imported(from, to);
Greg Clayton3418c852011-08-10 02:10:13 +0000530}