blob: 552c54575a77d50948b3e83ce306732e7bb1c5fa [file] [log] [blame]
Greg Clayton1e591ce2010-07-16 18:28:27 +00001//===-- ClangASTSource.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
Chris Lattner24943d22010-06-08 16:52:24 +000010
Chris Lattner24943d22010-06-08 16:52:24 +000011#include "clang/AST/ASTContext.h"
Greg Claytonf4c7ae02010-10-15 03:36:13 +000012#include "lldb/Core/Log.h"
Greg Clayton6e0101c2011-09-17 06:21:20 +000013#include "lldb/Core/Module.h"
Sean Callanan73b520f2011-10-29 01:58:46 +000014#include "lldb/Core/ModuleList.h"
Sean Callananbb715f92011-10-29 02:28:18 +000015#include "lldb/Expression/ASTDumper.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Expression/ClangASTSource.h"
17#include "lldb/Expression/ClangExpression.h"
Sean Callanan73b520f2011-10-29 01:58:46 +000018#include "lldb/Symbol/ClangNamespaceDecl.h"
19#include "lldb/Symbol/SymbolVendor.h"
Sean Callanan673f3db2011-11-30 22:11:59 +000020#include "lldb/Target/ObjCLanguageRuntime.h"
Sean Callanan73b520f2011-10-29 01:58:46 +000021#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23using namespace clang;
24using namespace lldb_private;
25
Greg Claytonb01000f2011-01-17 03:46:26 +000026ClangASTSource::~ClangASTSource()
27{
Sean Callanana3d04472011-11-29 00:42:02 +000028 m_ast_importer->ForgetDestination(m_ast_context);
29
Johnny Chenfa21ffd2011-11-30 23:18:53 +000030 // We are in the process of destruction, don't create clang ast context on demand
31 // by passing false to Target::GetScratchClangASTContext(create_on_demand).
32 ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false);
Sean Callanana3d04472011-11-29 00:42:02 +000033
34 if (!scratch_clang_ast_context)
35 return;
36
37 clang::ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext();
38
39 if (!scratch_ast_context)
40 return;
41
42 if (m_ast_context != scratch_ast_context)
43 m_ast_importer->ForgetSource(scratch_ast_context, m_ast_context);
Greg Claytonb01000f2011-01-17 03:46:26 +000044}
Chris Lattner24943d22010-06-08 16:52:24 +000045
Greg Claytonb01000f2011-01-17 03:46:26 +000046void
47ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer)
48{
Sean Callananf76afff2011-10-28 23:38:38 +000049 if (!m_ast_context)
50 return;
51
52 m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage();
53 m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage();
Chris Lattner24943d22010-06-08 16:52:24 +000054}
55
Chris Lattner24943d22010-06-08 16:52:24 +000056// The core lookup interface.
Greg Claytonb01000f2011-01-17 03:46:26 +000057DeclContext::lookup_result
58ClangASTSource::FindExternalVisibleDeclsByName
Greg Claytonf4c7ae02010-10-15 03:36:13 +000059(
60 const DeclContext *decl_ctx,
Greg Clayton8de27c72010-10-15 22:48:33 +000061 DeclarationName clang_decl_name
Greg Claytonf4c7ae02010-10-15 03:36:13 +000062)
63{
Sean Callananf76afff2011-10-28 23:38:38 +000064 if (!m_ast_context)
65 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
66
67 if (GetImportInProgress())
Greg Claytonb01000f2011-01-17 03:46:26 +000068 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
69
70 std::string decl_name (clang_decl_name.getAsString());
71
72// if (m_decl_map.DoingASTImport ())
73// return DeclContext::lookup_result();
74//
Greg Clayton8de27c72010-10-15 22:48:33 +000075 switch (clang_decl_name.getNameKind()) {
Chris Lattner24943d22010-06-08 16:52:24 +000076 // Normal identifiers.
77 case DeclarationName::Identifier:
Greg Clayton8de27c72010-10-15 22:48:33 +000078 if (clang_decl_name.getAsIdentifierInfo()->getBuiltinID() != 0)
79 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
80 break;
Chris Lattner24943d22010-06-08 16:52:24 +000081
82 // Operator names. Not important for now.
83 case DeclarationName::CXXOperatorName:
84 case DeclarationName::CXXLiteralOperatorName:
85 return DeclContext::lookup_result();
86
87 // Using directives found in this context.
88 // Tell Sema we didn't find any or we'll end up getting asked a *lot*.
89 case DeclarationName::CXXUsingDirective:
Greg Clayton8de27c72010-10-15 22:48:33 +000090 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
Chris Lattner24943d22010-06-08 16:52:24 +000091
Chris Lattner24943d22010-06-08 16:52:24 +000092 case DeclarationName::ObjCZeroArgSelector:
93 case DeclarationName::ObjCOneArgSelector:
94 case DeclarationName::ObjCMultiArgSelector:
Sean Callanan9b714842011-11-09 19:33:21 +000095 {
96 llvm::SmallVector<NamedDecl*, 1> method_decls;
Chris Lattner24943d22010-06-08 16:52:24 +000097
Sean Callanan9b714842011-11-09 19:33:21 +000098 NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx);
99
100 FindObjCMethodDecls(method_search_context);
101
102 return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls);
103 }
Chris Lattner24943d22010-06-08 16:52:24 +0000104 // These aren't possible in the global context.
105 case DeclarationName::CXXConstructorName:
106 case DeclarationName::CXXDestructorName:
107 case DeclarationName::CXXConversionFunctionName:
108 return DeclContext::lookup_result();
109 }
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000110
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000111
Sean Callananf76afff2011-10-28 23:38:38 +0000112 if (!GetLookupsEnabled())
Greg Clayton8de27c72010-10-15 22:48:33 +0000113 {
114 // Wait until we see a '$' at the start of a name before we start doing
115 // any lookups so we can avoid lookup up all of the builtin types.
116 if (!decl_name.empty() && decl_name[0] == '$')
117 {
Sean Callananf76afff2011-10-28 23:38:38 +0000118 SetLookupsEnabled (true);
Greg Clayton8de27c72010-10-15 22:48:33 +0000119 }
120 else
121 {
122 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
123 }
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000124 }
Greg Clayton8de27c72010-10-15 22:48:33 +0000125
Greg Clayton8de27c72010-10-15 22:48:33 +0000126 ConstString const_decl_name(decl_name.c_str());
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000127
128 const char *uniqued_const_decl_name = const_decl_name.GetCString();
129 if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end())
130 {
131 // We are currently looking up this name...
132 return DeclContext::lookup_result();
133 }
134 m_active_lookups.insert(uniqued_const_decl_name);
Greg Claytona8b278a2010-11-15 01:34:18 +0000135// static uint32_t g_depth = 0;
136// ++g_depth;
137// printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name);
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000138 llvm::SmallVector<NamedDecl*, 4> name_decls;
139 NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx);
Sean Callananf76afff2011-10-28 23:38:38 +0000140 FindExternalVisibleDecls(name_search_context);
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000141 DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls));
Greg Claytona8b278a2010-11-15 01:34:18 +0000142// --g_depth;
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000143 m_active_lookups.erase (uniqued_const_decl_name);
144 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000145}
146
Greg Claytonb01000f2011-01-17 03:46:26 +0000147void
148ClangASTSource::CompleteType (TagDecl *tag_decl)
Sean Callananbb715f92011-10-29 02:28:18 +0000149{
150 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
151
152 if (log)
153 {
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000154 log->Printf(" [CompleteTagDecl] on (ASTContext*)%p Completing a TagDecl named %s", m_ast_context, tag_decl->getName().str().c_str());
Sean Callananbb715f92011-10-29 02:28:18 +0000155 log->Printf(" [CTD] Before:");
156 ASTDumper dumper((Decl*)tag_decl);
157 dumper.ToLog(log, " [CTD] ");
158 }
159
160 m_ast_importer->CompleteTagDecl (tag_decl);
161
162 if (log)
163 {
164 log->Printf(" [CTD] After:");
165 ASTDumper dumper((Decl*)tag_decl);
166 dumper.ToLog(log, " [CTD] ");
167 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000168}
169
170void
Sean Callananbb715f92011-10-29 02:28:18 +0000171ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
172{
173 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
174
175 if (log)
176 {
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000177 log->Printf(" [CompleteObjCInterfaceDecl] on (ASTContext*)%p Completing an ObjCInterfaceDecl named %s", m_ast_context, interface_decl->getName().str().c_str());
Sean Callananbb715f92011-10-29 02:28:18 +0000178 log->Printf(" [COID] Before:");
179 ASTDumper dumper((Decl*)interface_decl);
180 dumper.ToLog(log, " [COID] ");
181 }
182
183 m_ast_importer->CompleteObjCInterfaceDecl (interface_decl);
184
185 if (log)
186 {
187 log->Printf(" [COID] After:");
188 ASTDumper dumper((Decl*)interface_decl);
189 dumper.ToLog(log, " [COID] ");
190 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000191}
192
Sean Callanan9b6898f2011-07-30 02:42:06 +0000193clang::ExternalLoadResult
Sean Callananbb715f92011-10-29 02:28:18 +0000194ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context,
195 bool (*predicate)(Decl::Kind),
196 llvm::SmallVectorImpl<Decl*> &decls)
197{
198 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
199
200 const Decl *context_decl = dyn_cast<Decl>(decl_context);
201
202 if (!context_decl)
203 return ELR_Failure;
204
205 static unsigned int invocation_id = 0;
206 unsigned int current_id = invocation_id++;
207
208 if (log)
209 {
210 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000211 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000212 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000213 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000214 context_named_decl->getNameAsString().c_str(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000215 context_decl->getDeclKindName(),
216 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000217 (predicate ? "non-null" : "null"));
218 else if(context_decl)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000219 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000220 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000221 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000222 context_decl->getDeclKindName(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000223 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000224 (predicate ? "non-null" : "null"));
225 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000226 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000227 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000228 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000229 (predicate ? "non-null" : "null"));
230 }
231
232 Decl *original_decl = NULL;
233 ASTContext *original_ctx = NULL;
234
235 if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
236 return ELR_Failure;
237
238 if (log)
239 {
240 log->Printf(" FELD[%u] Original decl:", current_id);
241 ASTDumper(original_decl).ToLog(log, " ");
242 }
243
244 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
245 {
246 ExternalASTSource *external_source = original_ctx->getExternalSource();
247
248 if (external_source)
249 external_source->CompleteType (original_tag_decl);
250 }
251
252 DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
253
254 if (!original_decl_context)
255 return ELR_Failure;
256
257 for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
258 iter != original_decl_context->decls_end();
259 ++iter)
260 {
261 Decl *decl = *iter;
262
263 if (!predicate || predicate(decl->getKind()))
264 {
265 if (log)
266 {
267 ASTDumper ast_dumper(decl);
268 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
269 log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString());
270 else
271 log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString());
272 }
273
Sean Callanan4938bd62011-11-16 18:20:47 +0000274 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, original_ctx, decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000275
276 decls.push_back(copied_decl);
277 }
278 }
279
280 return ELR_AlreadyLoaded;
Chris Lattner24943d22010-06-08 16:52:24 +0000281}
282
Sean Callanan9394b5a2011-10-29 19:50:43 +0000283void
284ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context)
285{
286 assert (m_ast_context);
287
288 const ConstString name(context.m_decl_name.getAsString().c_str());
289
290 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
291
292 static unsigned int invocation_id = 0;
293 unsigned int current_id = invocation_id++;
294
295 if (log)
296 {
297 if (!context.m_decl_context)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000298 log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a NULL DeclContext", current_id, m_ast_context, name.GetCString());
Sean Callanan9394b5a2011-10-29 19:50:43 +0000299 else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000300 log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in '%s'", current_id, m_ast_context, name.GetCString(), context_named_decl->getNameAsString().c_str());
Sean Callanan9394b5a2011-10-29 19:50:43 +0000301 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000302 log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] on (ASTContext*)%p for '%s' in a '%s'", current_id, m_ast_context, name.GetCString(), context.m_decl_context->getDeclKindName());
Sean Callanan9394b5a2011-10-29 19:50:43 +0000303 }
304
305 context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
306
307 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
308 {
309 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
310
311 if (log && log->GetVerbose())
312 log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)",
313 current_id,
314 namespace_map.get(),
315 (int)namespace_map->size());
316
317 if (!namespace_map)
318 return;
319
320 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
321 i != e;
322 ++i)
323 {
324 if (log)
325 log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s",
326 current_id,
327 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
328 i->first->GetFileSpec().GetFilename().GetCString());
329
330 FindExternalVisibleDecls(context,
331 i->first,
332 i->second,
333 current_id);
334 }
335 }
Sean Callanand3812fa2011-11-15 21:50:18 +0000336 else if (isa<ObjCInterfaceDecl>(context.m_decl_context))
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000337 {
338 FindObjCPropertyDecls(context);
339 }
Sean Callanan9394b5a2011-10-29 19:50:43 +0000340 else if (!isa<TranslationUnitDecl>(context.m_decl_context))
341 {
342 // we shouldn't be getting FindExternalVisibleDecls calls for these
343 return;
344 }
345 else
346 {
347 ClangNamespaceDecl namespace_decl;
348
349 if (log)
350 log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id);
351
352 FindExternalVisibleDecls(context,
353 lldb::ModuleSP(),
354 namespace_decl,
355 current_id);
356 }
357
358 if (!context.m_namespace_map->empty())
359 {
360 if (log && log->GetVerbose())
361 log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)",
362 current_id,
363 context.m_namespace_map.get(),
364 (int)context.m_namespace_map->size());
365
366 NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map);
367
368 if (clang_namespace_decl)
369 clang_namespace_decl->setHasExternalVisibleStorage();
370 }
371}
372
373void
374ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
375 lldb::ModuleSP module_sp,
376 ClangNamespaceDecl &namespace_decl,
377 unsigned int current_id)
378{
379 assert (m_ast_context);
380
381 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
382
383 SymbolContextList sc_list;
384
385 const ConstString name(context.m_decl_name.getAsString().c_str());
386
387 const char *name_unique_cstr = name.GetCString();
388
389 if (name_unique_cstr == NULL)
390 return;
391
392 // The ClangASTSource is not responsible for finding $-names.
393 if (name_unique_cstr[0] == '$')
394 return;
395
396 if (module_sp && namespace_decl)
397 {
398 ClangNamespaceDecl found_namespace_decl;
399
400 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
401
402 if (symbol_vendor)
403 {
404 SymbolContext null_sc;
405
406 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
407
408 if (found_namespace_decl)
409 {
410 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
411
412 if (log)
413 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
414 current_id,
415 name.GetCString(),
416 module_sp->GetFileSpec().GetFilename().GetCString());
417 }
418 }
419 }
420 else
421 {
422 ModuleList &images = m_target->GetImages();
423
424 for (uint32_t i = 0, e = images.GetSize();
425 i != e;
426 ++i)
427 {
428 lldb::ModuleSP image = images.GetModuleAtIndex(i);
429
430 if (!image)
431 continue;
432
433 ClangNamespaceDecl found_namespace_decl;
434
435 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
436
437 if (!symbol_vendor)
438 continue;
439
440 SymbolContext null_sc;
441
442 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
443
444 if (found_namespace_decl)
445 {
446 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
447
448 if (log)
449 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
450 current_id,
451 name.GetCString(),
452 image->GetFileSpec().GetFilename().GetCString());
453 }
454 }
455 }
456
457 static ConstString id_name("id");
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000458 static ConstString Class_name("Class");
Sean Callanan9394b5a2011-10-29 19:50:43 +0000459
460 do
461 {
462 TypeList types;
463 SymbolContext null_sc;
464
465 if (module_sp && namespace_decl)
466 module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000467 else if(name != id_name && name != Class_name)
Sean Callanane1301a62011-12-06 03:41:14 +0000468 m_target->GetImages().FindTypes(null_sc, name, true, 1, types);
Sean Callanan9394b5a2011-10-29 19:50:43 +0000469 else
470 break;
471
472 if (types.GetSize())
473 {
474 lldb::TypeSP type_sp = types.GetTypeAtIndex(0);
475
476 if (log)
477 {
478 const char *name_string = type_sp->GetName().GetCString();
479
480 log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s",
481 current_id,
482 name.GetCString(),
483 (name_string ? name_string : "<anonymous>"));
484 }
485
Sean Callanane1301a62011-12-06 03:41:14 +0000486
Sean Callanan9394b5a2011-10-29 19:50:43 +0000487 void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType());
Sean Callanane1301a62011-12-06 03:41:14 +0000488
Sean Callanandc5fce12011-12-01 21:04:37 +0000489 if (!copied_type)
490 {
491 if (log)
Sean Callanane1301a62011-12-06 03:41:14 +0000492 log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result",
493 current_id);
494
Sean Callanandc5fce12011-12-01 21:04:37 +0000495 break;
496 }
497
Sean Callanan9394b5a2011-10-29 19:50:43 +0000498 context.AddTypeDecl(copied_type);
499 }
Sean Callanan673f3db2011-11-30 22:11:59 +0000500
Sean Callanan9394b5a2011-10-29 19:50:43 +0000501 } while(0);
502}
503
Sean Callanan9b714842011-11-09 19:33:21 +0000504void
505ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
506{
507 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
508
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000509 static unsigned int invocation_id = 0;
510 unsigned int current_id = invocation_id++;
511
Sean Callanan9b714842011-11-09 19:33:21 +0000512 const DeclarationName &decl_name(context.m_decl_name);
513 const DeclContext *decl_ctx(context.m_decl_context);
514
515 const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx);
516
517 if (!interface_decl)
518 return;
519
520 StreamString ss;
Sean Callanane1301a62011-12-06 03:41:14 +0000521
Sean Callanan9b714842011-11-09 19:33:21 +0000522 if (decl_name.isObjCZeroArgSelector())
523 {
524 ss.Printf("%s", decl_name.getAsString().c_str());
525 }
526 else if (decl_name.isObjCOneArgSelector())
527 {
Sean Callanan1d9ffe22011-11-14 18:29:46 +0000528 ss.Printf("%s", decl_name.getAsString().c_str());
Sean Callanan9b714842011-11-09 19:33:21 +0000529 }
530 else
531 {
532 clang::Selector sel = decl_name.getObjCSelector();
533
534 for (unsigned i = 0, e = sel.getNumArgs();
535 i != e;
536 ++i)
537 {
538 llvm::StringRef r = sel.getNameForSlot(i);
539 ss.Printf("%s:", r.str().c_str());
540 }
541 }
542 ss.Flush();
543
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000544 ConstString selector_name(ss.GetData());
545
Sean Callanan9b714842011-11-09 19:33:21 +0000546 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000547 log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]",
548 current_id,
549 m_ast_context,
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000550 interface_decl->getNameAsString().c_str(),
551 selector_name.AsCString());
552
Sean Callanane1301a62011-12-06 03:41:14 +0000553 ClangASTImporter::ObjCInterfaceMapSP interface_map = m_ast_importer->GetObjCInterfaceMap(interface_decl);
554
555 if (interface_map)
556 {
557 for (ClangASTImporter::ObjCInterfaceMap::iterator i = interface_map->begin(), e = interface_map->end();
558 i != e;
559 ++i)
560 {
561 lldb::clang_type_t backing_type = i->GetOpaqueQualType();
562
563 if (!backing_type)
564 continue;
565
566 QualType backing_qual_type = QualType::getFromOpaquePtr(backing_type);
567
568 const ObjCInterfaceType *backing_interface_type = dyn_cast<ObjCInterfaceType>(backing_qual_type.getTypePtr());
569
570 if (!backing_interface_type)
571 continue;
572
573 const ObjCInterfaceDecl *backing_interface_decl = backing_interface_type->getDecl();
574
575 if (!backing_interface_decl)
576 continue;
577
578 if (backing_interface_decl->decls_begin() == backing_interface_decl->decls_end())
579 continue; // don't waste time creating a DeclarationName here
580
581 clang::ASTContext &backing_ast_context = backing_interface_decl->getASTContext();
582
583 llvm::SmallVector<clang::IdentifierInfo *, 3> selector_components;
Sean Callanan3d8540a2011-12-07 22:39:39 +0000584 int num_arguments = 0;
Sean Callanane1301a62011-12-06 03:41:14 +0000585
586 if (decl_name.isObjCZeroArgSelector())
587 {
588 selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str()));
589 }
590 else if (decl_name.isObjCOneArgSelector())
591 {
592 selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str()));
Sean Callanan3d8540a2011-12-07 22:39:39 +0000593 num_arguments = 1;
Sean Callanane1301a62011-12-06 03:41:14 +0000594 }
595 else
596 {
597 clang::Selector sel = decl_name.getObjCSelector();
598
599 for (unsigned i = 0, e = sel.getNumArgs();
600 i != e;
601 ++i)
602 {
603 llvm::StringRef r = sel.getNameForSlot(i);
604
605 selector_components.push_back (&backing_ast_context.Idents.get(r.str().c_str()));
Sean Callanan3d8540a2011-12-07 22:39:39 +0000606 num_arguments++;
Sean Callanane1301a62011-12-06 03:41:14 +0000607 }
608 }
609
Sean Callanan3d8540a2011-12-07 22:39:39 +0000610 Selector backing_selector = backing_interface_decl->getASTContext().Selectors.getSelector(num_arguments, selector_components.data());
Sean Callanane1301a62011-12-06 03:41:14 +0000611 DeclarationName backing_decl_name = DeclarationName(backing_selector);
612
613 DeclContext::lookup_const_result lookup_result = backing_interface_decl->lookup(backing_decl_name);
614
615 if (lookup_result.first == lookup_result.second)
616 continue;
617
618 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(*lookup_result.first);
619
620 if (!method_decl)
621 continue;
622
623 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &backing_ast_context, *lookup_result.first);
624
Sean Callanan3d8540a2011-12-07 22:39:39 +0000625 if (!copied_decl)
626 {
Greg Clayton2e87f6a2011-12-08 01:32:28 +0000627 if (log)
628 log->Printf(" CAS::FOMD[%d] couldn't import method from symbols", current_id);
Sean Callanan3d8540a2011-12-07 22:39:39 +0000629 continue;
630 }
631
Sean Callanane1301a62011-12-06 03:41:14 +0000632 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl> (copied_decl);
633
634 if (!copied_method_decl)
635 continue;
636
637 if (log)
638 {
639 ASTDumper dumper((Decl*)copied_method_decl);
640 log->Printf(" CAS::FOMD[%d] found (in symbols) %s", current_id, dumper.GetCString());
641 }
642
643 context.AddNamedDecl(copied_method_decl);
644 }
645 }
646
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000647 SymbolContextList sc_list;
648
649 const bool include_symbols = false;
650 const bool append = false;
651
652 m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, append, sc_list);
653
654 for (uint32_t i = 0, e = sc_list.GetSize();
655 i != e;
656 ++i)
657 {
658 SymbolContext sc;
659
660 if (!sc_list.GetContextAtIndex(i, sc))
661 continue;
662
663 if (!sc.function)
664 continue;
665
666 DeclContext *function_ctx = sc.function->GetClangDeclContext();
667
668 if (!function_ctx)
669 continue;
670
671 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx);
672
673 if (!method_decl)
674 continue;
675
676 ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface();
677
678 if (!found_interface_decl)
679 continue;
680
681 if (found_interface_decl->getName() == interface_decl->getName())
682 {
Sean Callanan4938bd62011-11-16 18:20:47 +0000683 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000684
685 if (!copied_decl)
686 continue;
687
688 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
689
690 if (!copied_method_decl)
691 continue;
692
693 if (log)
694 {
695 ASTDumper dumper((Decl*)copied_method_decl);
Sean Callanane1301a62011-12-06 03:41:14 +0000696 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000697 }
698
699 context.AddNamedDecl(copied_method_decl);
700 }
701 }
Sean Callanan9b714842011-11-09 19:33:21 +0000702}
703
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000704void
705ClangASTSource::FindObjCPropertyDecls (NameSearchContext &context)
706{
707 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
708
709 static unsigned int invocation_id = 0;
710 unsigned int current_id = invocation_id++;
711
712 const ObjCInterfaceDecl *iface_decl = cast<ObjCInterfaceDecl>(context.m_decl_context);
713 Decl *orig_decl;
714 ASTContext *orig_ast_ctx;
715
716 m_ast_importer->ResolveDeclOrigin(iface_decl, &orig_decl, &orig_ast_ctx);
717
718 if (!orig_decl)
719 return;
720
721 ObjCInterfaceDecl *orig_iface_decl = dyn_cast<ObjCInterfaceDecl>(orig_decl);
722
723 if (!orig_iface_decl)
724 return;
725
726 if (!ClangASTContext::GetCompleteDecl(orig_ast_ctx, orig_iface_decl))
727 return;
728
729 std::string property_name_str = context.m_decl_name.getAsString();
730 StringRef property_name(property_name_str.c_str());
731 ObjCPropertyDecl *property_decl = orig_iface_decl->FindPropertyDeclaration(&orig_ast_ctx->Idents.get(property_name));
732
733 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000734 log->Printf("ClangASTSource::FindObjCPropertyDecls[%d] on (ASTContext*)%p for property '%s.%s'",
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000735 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000736 m_ast_context,
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000737 iface_decl->getNameAsString().c_str(),
738 property_name_str.c_str());
739
740 if (!property_decl)
741 return;
742
Sean Callanan4938bd62011-11-16 18:20:47 +0000743 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, orig_ast_ctx, property_decl);
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000744
745 if (!copied_decl)
746 return;
747
748 ObjCPropertyDecl *copied_property_decl = dyn_cast<ObjCPropertyDecl>(copied_decl);
749
750 if (!copied_property_decl)
751 return;
752
753 if (log)
754 {
755 ASTDumper dumper((Decl*)copied_property_decl);
756 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
757 }
758
759 context.AddNamedDecl(copied_property_decl);
760}
761
Sean Callanan73b520f2011-10-29 01:58:46 +0000762void
763ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
764 const ConstString &name,
765 ClangASTImporter::NamespaceMapSP &parent_map) const
766{
767 static unsigned int invocation_id = 0;
768 unsigned int current_id = invocation_id++;
769
770 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
771
772 if (log)
773 {
774 if (parent_map && parent_map->size())
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000775 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +0000776 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000777 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +0000778 name.GetCString(),
779 parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str());
780 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000781 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +0000782 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000783 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +0000784 name.GetCString());
785 }
786
787
788 if (parent_map)
789 {
790 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
791 i != e;
792 ++i)
793 {
794 ClangNamespaceDecl found_namespace_decl;
795
796 lldb::ModuleSP module_sp = i->first;
797 ClangNamespaceDecl module_parent_namespace_decl = i->second;
798
799 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
800
801 if (!symbol_vendor)
802 continue;
803
804 SymbolContext null_sc;
805
806 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
807
808 if (!found_namespace_decl)
809 continue;
810
811 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
812
813 if (log)
814 log->Printf(" CMN[%u] Found namespace %s in module %s",
815 current_id,
816 name.GetCString(),
817 module_sp->GetFileSpec().GetFilename().GetCString());
818 }
819 }
820 else
821 {
822 ModuleList &images = m_target->GetImages();
823 ClangNamespaceDecl null_namespace_decl;
824
825 for (uint32_t i = 0, e = images.GetSize();
826 i != e;
827 ++i)
828 {
829 lldb::ModuleSP image = images.GetModuleAtIndex(i);
830
831 if (!image)
832 continue;
833
834 ClangNamespaceDecl found_namespace_decl;
835
836 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
837
838 if (!symbol_vendor)
839 continue;
840
841 SymbolContext null_sc;
842
843 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
844
845 if (!found_namespace_decl)
846 continue;
847
848 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
849
850 if (log)
851 log->Printf(" CMN[%u] Found namespace %s in module %s",
852 current_id,
853 name.GetCString(),
854 image->GetFileSpec().GetFilename().GetCString());
855 }
856 }
857}
858
Sean Callanane1301a62011-12-06 03:41:14 +0000859void
860ClangASTSource::CompleteObjCInterfaceMap (ClangASTImporter::ObjCInterfaceMapSP &objc_interface_map,
861 const ConstString &name) const
862{
863 SymbolContext null_sc;
864
865 TypeList types;
866
867 m_target->GetImages().FindTypes(null_sc, name, true, UINT32_MAX, types);
868
869 for (uint32_t i = 0, e = types.GetSize();
870 i != e;
871 ++i)
872 {
873 lldb::TypeSP mapped_type_sp = types.GetTypeAtIndex(i);
874
875 if (!mapped_type_sp || !mapped_type_sp->GetClangFullType())
876 continue;
877
878 objc_interface_map->push_back (ClangASTType(mapped_type_sp->GetClangAST(), mapped_type_sp->GetClangFullType()));
879 }
880}
881
Sean Callananbb715f92011-10-29 02:28:18 +0000882NamespaceDecl *
883ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
884{
885 if (namespace_decls.empty())
886 return NULL;
887
888 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
889
890 const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
891
Sean Callanan4938bd62011-11-16 18:20:47 +0000892 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl());
Sean Callananbb715f92011-10-29 02:28:18 +0000893
894 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
895
896 m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
897
898 return dyn_cast<NamespaceDecl>(copied_decl);
899}
900
Sean Callanan9394b5a2011-10-29 19:50:43 +0000901void *
902ClangASTSource::GuardedCopyType (ASTContext *dest_context,
903 ASTContext *source_context,
904 void *clang_type)
905{
906 SetImportInProgress(true);
907
Sean Callanan4938bd62011-11-16 18:20:47 +0000908 QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type));
Sean Callanan9394b5a2011-10-29 19:50:43 +0000909
910 void *ret = ret_qual_type.getAsOpaquePtr();
911
912 SetImportInProgress(false);
913
914 return ret;
915}
916
Greg Claytonb01000f2011-01-17 03:46:26 +0000917clang::NamedDecl *
918NameSearchContext::AddVarDecl(void *type)
919{
Greg Clayton8de27c72010-10-15 22:48:33 +0000920 IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
Sean Callanan1ddd9fe2010-11-30 00:27:43 +0000921
922 assert (type && "Type for variable must be non-NULL!");
Sean Callanancc074622010-09-14 21:59:34 +0000923
Sean Callananf76afff2011-10-28 23:38:38 +0000924 clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +0000925 const_cast<DeclContext*>(m_decl_context),
Chris Lattner24943d22010-06-08 16:52:24 +0000926 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +0000927 SourceLocation(),
Sean Callanancc074622010-09-14 21:59:34 +0000928 ii,
Chris Lattner24943d22010-06-08 16:52:24 +0000929 QualType::getFromOpaquePtr(type),
930 0,
Sean Callanan47a5c4c2010-09-23 03:01:22 +0000931 SC_Static,
932 SC_Static);
Greg Clayton8de27c72010-10-15 22:48:33 +0000933 m_decls.push_back(Decl);
Chris Lattner24943d22010-06-08 16:52:24 +0000934
935 return Decl;
936}
Sean Callanan8f0dc342010-06-22 23:46:24 +0000937
Greg Claytonb01000f2011-01-17 03:46:26 +0000938clang::NamedDecl *
939NameSearchContext::AddFunDecl (void *type)
940{
Sean Callananf76afff2011-10-28 23:38:38 +0000941 clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +0000942 const_cast<DeclContext*>(m_decl_context),
943 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +0000944 SourceLocation(),
Greg Clayton8de27c72010-10-15 22:48:33 +0000945 m_decl_name.getAsIdentifierInfo(),
946 QualType::getFromOpaquePtr(type),
947 NULL,
948 SC_Static,
949 SC_Static,
950 false,
951 true);
Sean Callanan8f0dc342010-06-22 23:46:24 +0000952
Sean Callananb291abe2010-08-12 23:45:38 +0000953 // We have to do more than just synthesize the FunctionDecl. We have to
954 // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
955 // this, we raid the function's FunctionProtoType for types.
956
Greg Clayton8de27c72010-10-15 22:48:33 +0000957 QualType qual_type (QualType::getFromOpaquePtr(type));
Sean Callanandc5fce12011-12-01 21:04:37 +0000958 const FunctionProtoType *func_proto_type = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
Sean Callanan8f0dc342010-06-22 23:46:24 +0000959
Greg Clayton8de27c72010-10-15 22:48:33 +0000960 if (func_proto_type)
Sean Callanan3c821cc2010-06-23 18:58:10 +0000961 {
Greg Clayton8de27c72010-10-15 22:48:33 +0000962 unsigned NumArgs = func_proto_type->getNumArgs();
Sean Callanan8f0dc342010-06-22 23:46:24 +0000963 unsigned ArgIndex;
964
Sean Callananc1535182011-10-07 23:18:13 +0000965 SmallVector<ParmVarDecl *, 5> parm_var_decls;
966
Sean Callanan8f0dc342010-06-22 23:46:24 +0000967 for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
968 {
Greg Clayton8de27c72010-10-15 22:48:33 +0000969 QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
Sean Callanan8f0dc342010-06-22 23:46:24 +0000970
Sean Callananf76afff2011-10-28 23:38:38 +0000971 parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context,
Sean Callananc1535182011-10-07 23:18:13 +0000972 const_cast<DeclContext*>(m_decl_context),
973 SourceLocation(),
974 SourceLocation(),
975 NULL,
976 arg_qual_type,
977 NULL,
978 SC_Static,
979 SC_Static,
980 NULL));
Sean Callanan8f0dc342010-06-22 23:46:24 +0000981 }
982
Sean Callananc1535182011-10-07 23:18:13 +0000983 func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls));
Sean Callanan8f0dc342010-06-22 23:46:24 +0000984 }
Sean Callanandc5fce12011-12-01 21:04:37 +0000985 else
986 {
987 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
988
989 log->Printf("Function type wasn't a FunctionProtoType");
990 }
Sean Callanan8f0dc342010-06-22 23:46:24 +0000991
Greg Clayton8de27c72010-10-15 22:48:33 +0000992 m_decls.push_back(func_decl);
Sean Callanan8f0dc342010-06-22 23:46:24 +0000993
Greg Clayton8de27c72010-10-15 22:48:33 +0000994 return func_decl;
Sean Callanan8f0dc342010-06-22 23:46:24 +0000995}
Sean Callanan0fc73582010-07-27 00:55:47 +0000996
Greg Claytonb01000f2011-01-17 03:46:26 +0000997clang::NamedDecl *
998NameSearchContext::AddGenericFunDecl()
Sean Callanan0fc73582010-07-27 00:55:47 +0000999{
Sean Callananad293092011-01-18 23:32:05 +00001000 FunctionProtoType::ExtProtoInfo proto_info;
1001
1002 proto_info.Variadic = true;
1003
Sean Callananf76afff2011-10-28 23:38:38 +00001004 QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result
1005 NULL, // argument types
1006 0, // number of arguments
1007 proto_info));
Greg Clayton8de27c72010-10-15 22:48:33 +00001008
Sean Callanan0fc73582010-07-27 00:55:47 +00001009 return AddFunDecl(generic_function_type.getAsOpaquePtr());
1010}
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001011
Greg Claytonb01000f2011-01-17 03:46:26 +00001012clang::NamedDecl *
1013NameSearchContext::AddTypeDecl(void *type)
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001014{
Greg Claytona1aaaff2011-01-23 00:34:52 +00001015 if (type)
1016 {
1017 QualType qual_type = QualType::getFromOpaquePtr(type);
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001018
Sean Callanand5b3c352011-01-27 04:42:51 +00001019 if (const TagType *tag_type = dyn_cast<clang::TagType>(qual_type))
Greg Claytona1aaaff2011-01-23 00:34:52 +00001020 {
1021 TagDecl *tag_decl = tag_type->getDecl();
1022
1023 m_decls.push_back(tag_decl);
1024
1025 return tag_decl;
1026 }
Sean Callanand5b3c352011-01-27 04:42:51 +00001027 else if (const ObjCObjectType *objc_object_type = dyn_cast<clang::ObjCObjectType>(qual_type))
Greg Claytona1aaaff2011-01-23 00:34:52 +00001028 {
1029 ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
1030
1031 m_decls.push_back((NamedDecl*)interface_decl);
1032
1033 return (NamedDecl*)interface_decl;
1034 }
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001035 }
Greg Claytona1aaaff2011-01-23 00:34:52 +00001036 return NULL;
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001037}
Greg Claytone6d72ca2011-06-25 00:44:06 +00001038
1039void
1040NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result)
1041{
1042 for (clang::NamedDecl * const *decl_iterator = result.first;
1043 decl_iterator != result.second;
1044 ++decl_iterator)
1045 m_decls.push_back (*decl_iterator);
1046}
1047
1048void
1049NameSearchContext::AddNamedDecl (clang::NamedDecl *decl)
1050{
1051 m_decls.push_back (decl);
1052}