blob: 19baef0b061cf2f09ad9f379717b20655a5ef430 [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;
584
585 if (decl_name.isObjCZeroArgSelector())
586 {
587 selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str()));
588 }
589 else if (decl_name.isObjCOneArgSelector())
590 {
591 selector_components.push_back (&backing_ast_context.Idents.get(decl_name.getAsString().c_str()));
592 }
593 else
594 {
595 clang::Selector sel = decl_name.getObjCSelector();
596
597 for (unsigned i = 0, e = sel.getNumArgs();
598 i != e;
599 ++i)
600 {
601 llvm::StringRef r = sel.getNameForSlot(i);
602
603 selector_components.push_back (&backing_ast_context.Idents.get(r.str().c_str()));
604 }
605 }
606
607 Selector backing_selector = backing_interface_decl->getASTContext().Selectors.getSelector(selector_components.size(), selector_components.data());
608 DeclarationName backing_decl_name = DeclarationName(backing_selector);
609
610 DeclContext::lookup_const_result lookup_result = backing_interface_decl->lookup(backing_decl_name);
611
612 if (lookup_result.first == lookup_result.second)
613 continue;
614
615 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(*lookup_result.first);
616
617 if (!method_decl)
618 continue;
619
620 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &backing_ast_context, *lookup_result.first);
621
622 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl> (copied_decl);
623
624 if (!copied_method_decl)
625 continue;
626
627 if (log)
628 {
629 ASTDumper dumper((Decl*)copied_method_decl);
630 log->Printf(" CAS::FOMD[%d] found (in symbols) %s", current_id, dumper.GetCString());
631 }
632
633 context.AddNamedDecl(copied_method_decl);
634 }
635 }
636
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000637 SymbolContextList sc_list;
638
639 const bool include_symbols = false;
640 const bool append = false;
641
642 m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, append, sc_list);
643
644 for (uint32_t i = 0, e = sc_list.GetSize();
645 i != e;
646 ++i)
647 {
648 SymbolContext sc;
649
650 if (!sc_list.GetContextAtIndex(i, sc))
651 continue;
652
653 if (!sc.function)
654 continue;
655
656 DeclContext *function_ctx = sc.function->GetClangDeclContext();
657
658 if (!function_ctx)
659 continue;
660
661 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx);
662
663 if (!method_decl)
664 continue;
665
666 ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface();
667
668 if (!found_interface_decl)
669 continue;
670
671 if (found_interface_decl->getName() == interface_decl->getName())
672 {
Sean Callanan4938bd62011-11-16 18:20:47 +0000673 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000674
675 if (!copied_decl)
676 continue;
677
678 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
679
680 if (!copied_method_decl)
681 continue;
682
683 if (log)
684 {
685 ASTDumper dumper((Decl*)copied_method_decl);
Sean Callanane1301a62011-12-06 03:41:14 +0000686 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000687 }
688
689 context.AddNamedDecl(copied_method_decl);
690 }
691 }
Sean Callanan9b714842011-11-09 19:33:21 +0000692}
693
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000694void
695ClangASTSource::FindObjCPropertyDecls (NameSearchContext &context)
696{
697 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
698
699 static unsigned int invocation_id = 0;
700 unsigned int current_id = invocation_id++;
701
702 const ObjCInterfaceDecl *iface_decl = cast<ObjCInterfaceDecl>(context.m_decl_context);
703 Decl *orig_decl;
704 ASTContext *orig_ast_ctx;
705
706 m_ast_importer->ResolveDeclOrigin(iface_decl, &orig_decl, &orig_ast_ctx);
707
708 if (!orig_decl)
709 return;
710
711 ObjCInterfaceDecl *orig_iface_decl = dyn_cast<ObjCInterfaceDecl>(orig_decl);
712
713 if (!orig_iface_decl)
714 return;
715
716 if (!ClangASTContext::GetCompleteDecl(orig_ast_ctx, orig_iface_decl))
717 return;
718
719 std::string property_name_str = context.m_decl_name.getAsString();
720 StringRef property_name(property_name_str.c_str());
721 ObjCPropertyDecl *property_decl = orig_iface_decl->FindPropertyDeclaration(&orig_ast_ctx->Idents.get(property_name));
722
723 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000724 log->Printf("ClangASTSource::FindObjCPropertyDecls[%d] on (ASTContext*)%p for property '%s.%s'",
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000725 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000726 m_ast_context,
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000727 iface_decl->getNameAsString().c_str(),
728 property_name_str.c_str());
729
730 if (!property_decl)
731 return;
732
Sean Callanan4938bd62011-11-16 18:20:47 +0000733 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, orig_ast_ctx, property_decl);
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000734
735 if (!copied_decl)
736 return;
737
738 ObjCPropertyDecl *copied_property_decl = dyn_cast<ObjCPropertyDecl>(copied_decl);
739
740 if (!copied_property_decl)
741 return;
742
743 if (log)
744 {
745 ASTDumper dumper((Decl*)copied_property_decl);
746 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
747 }
748
749 context.AddNamedDecl(copied_property_decl);
750}
751
Sean Callanan73b520f2011-10-29 01:58:46 +0000752void
753ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
754 const ConstString &name,
755 ClangASTImporter::NamespaceMapSP &parent_map) const
756{
757 static unsigned int invocation_id = 0;
758 unsigned int current_id = invocation_id++;
759
760 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
761
762 if (log)
763 {
764 if (parent_map && parent_map->size())
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000765 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +0000766 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000767 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +0000768 name.GetCString(),
769 parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str());
770 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000771 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +0000772 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000773 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +0000774 name.GetCString());
775 }
776
777
778 if (parent_map)
779 {
780 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
781 i != e;
782 ++i)
783 {
784 ClangNamespaceDecl found_namespace_decl;
785
786 lldb::ModuleSP module_sp = i->first;
787 ClangNamespaceDecl module_parent_namespace_decl = i->second;
788
789 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
790
791 if (!symbol_vendor)
792 continue;
793
794 SymbolContext null_sc;
795
796 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
797
798 if (!found_namespace_decl)
799 continue;
800
801 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
802
803 if (log)
804 log->Printf(" CMN[%u] Found namespace %s in module %s",
805 current_id,
806 name.GetCString(),
807 module_sp->GetFileSpec().GetFilename().GetCString());
808 }
809 }
810 else
811 {
812 ModuleList &images = m_target->GetImages();
813 ClangNamespaceDecl null_namespace_decl;
814
815 for (uint32_t i = 0, e = images.GetSize();
816 i != e;
817 ++i)
818 {
819 lldb::ModuleSP image = images.GetModuleAtIndex(i);
820
821 if (!image)
822 continue;
823
824 ClangNamespaceDecl found_namespace_decl;
825
826 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
827
828 if (!symbol_vendor)
829 continue;
830
831 SymbolContext null_sc;
832
833 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
834
835 if (!found_namespace_decl)
836 continue;
837
838 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
839
840 if (log)
841 log->Printf(" CMN[%u] Found namespace %s in module %s",
842 current_id,
843 name.GetCString(),
844 image->GetFileSpec().GetFilename().GetCString());
845 }
846 }
847}
848
Sean Callanane1301a62011-12-06 03:41:14 +0000849void
850ClangASTSource::CompleteObjCInterfaceMap (ClangASTImporter::ObjCInterfaceMapSP &objc_interface_map,
851 const ConstString &name) const
852{
853 SymbolContext null_sc;
854
855 TypeList types;
856
857 m_target->GetImages().FindTypes(null_sc, name, true, UINT32_MAX, types);
858
859 for (uint32_t i = 0, e = types.GetSize();
860 i != e;
861 ++i)
862 {
863 lldb::TypeSP mapped_type_sp = types.GetTypeAtIndex(i);
864
865 if (!mapped_type_sp || !mapped_type_sp->GetClangFullType())
866 continue;
867
868 objc_interface_map->push_back (ClangASTType(mapped_type_sp->GetClangAST(), mapped_type_sp->GetClangFullType()));
869 }
870}
871
Sean Callananbb715f92011-10-29 02:28:18 +0000872NamespaceDecl *
873ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
874{
875 if (namespace_decls.empty())
876 return NULL;
877
878 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
879
880 const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
881
Sean Callanan4938bd62011-11-16 18:20:47 +0000882 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl());
Sean Callananbb715f92011-10-29 02:28:18 +0000883
884 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
885
886 m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
887
888 return dyn_cast<NamespaceDecl>(copied_decl);
889}
890
Sean Callanan9394b5a2011-10-29 19:50:43 +0000891void *
892ClangASTSource::GuardedCopyType (ASTContext *dest_context,
893 ASTContext *source_context,
894 void *clang_type)
895{
896 SetImportInProgress(true);
897
Sean Callanan4938bd62011-11-16 18:20:47 +0000898 QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type));
Sean Callanan9394b5a2011-10-29 19:50:43 +0000899
900 void *ret = ret_qual_type.getAsOpaquePtr();
901
902 SetImportInProgress(false);
903
904 return ret;
905}
906
Greg Claytonb01000f2011-01-17 03:46:26 +0000907clang::NamedDecl *
908NameSearchContext::AddVarDecl(void *type)
909{
Greg Clayton8de27c72010-10-15 22:48:33 +0000910 IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
Sean Callanan1ddd9fe2010-11-30 00:27:43 +0000911
912 assert (type && "Type for variable must be non-NULL!");
Sean Callanancc074622010-09-14 21:59:34 +0000913
Sean Callananf76afff2011-10-28 23:38:38 +0000914 clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +0000915 const_cast<DeclContext*>(m_decl_context),
Chris Lattner24943d22010-06-08 16:52:24 +0000916 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +0000917 SourceLocation(),
Sean Callanancc074622010-09-14 21:59:34 +0000918 ii,
Chris Lattner24943d22010-06-08 16:52:24 +0000919 QualType::getFromOpaquePtr(type),
920 0,
Sean Callanan47a5c4c2010-09-23 03:01:22 +0000921 SC_Static,
922 SC_Static);
Greg Clayton8de27c72010-10-15 22:48:33 +0000923 m_decls.push_back(Decl);
Chris Lattner24943d22010-06-08 16:52:24 +0000924
925 return Decl;
926}
Sean Callanan8f0dc342010-06-22 23:46:24 +0000927
Greg Claytonb01000f2011-01-17 03:46:26 +0000928clang::NamedDecl *
929NameSearchContext::AddFunDecl (void *type)
930{
Sean Callananf76afff2011-10-28 23:38:38 +0000931 clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +0000932 const_cast<DeclContext*>(m_decl_context),
933 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +0000934 SourceLocation(),
Greg Clayton8de27c72010-10-15 22:48:33 +0000935 m_decl_name.getAsIdentifierInfo(),
936 QualType::getFromOpaquePtr(type),
937 NULL,
938 SC_Static,
939 SC_Static,
940 false,
941 true);
Sean Callanan8f0dc342010-06-22 23:46:24 +0000942
Sean Callananb291abe2010-08-12 23:45:38 +0000943 // We have to do more than just synthesize the FunctionDecl. We have to
944 // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
945 // this, we raid the function's FunctionProtoType for types.
946
Greg Clayton8de27c72010-10-15 22:48:33 +0000947 QualType qual_type (QualType::getFromOpaquePtr(type));
Sean Callanandc5fce12011-12-01 21:04:37 +0000948 const FunctionProtoType *func_proto_type = dyn_cast<FunctionProtoType>(qual_type.getTypePtr());
Sean Callanan8f0dc342010-06-22 23:46:24 +0000949
Greg Clayton8de27c72010-10-15 22:48:33 +0000950 if (func_proto_type)
Sean Callanan3c821cc2010-06-23 18:58:10 +0000951 {
Greg Clayton8de27c72010-10-15 22:48:33 +0000952 unsigned NumArgs = func_proto_type->getNumArgs();
Sean Callanan8f0dc342010-06-22 23:46:24 +0000953 unsigned ArgIndex;
954
Sean Callananc1535182011-10-07 23:18:13 +0000955 SmallVector<ParmVarDecl *, 5> parm_var_decls;
956
Sean Callanan8f0dc342010-06-22 23:46:24 +0000957 for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
958 {
Greg Clayton8de27c72010-10-15 22:48:33 +0000959 QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
Sean Callanan8f0dc342010-06-22 23:46:24 +0000960
Sean Callananf76afff2011-10-28 23:38:38 +0000961 parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context,
Sean Callananc1535182011-10-07 23:18:13 +0000962 const_cast<DeclContext*>(m_decl_context),
963 SourceLocation(),
964 SourceLocation(),
965 NULL,
966 arg_qual_type,
967 NULL,
968 SC_Static,
969 SC_Static,
970 NULL));
Sean Callanan8f0dc342010-06-22 23:46:24 +0000971 }
972
Sean Callananc1535182011-10-07 23:18:13 +0000973 func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls));
Sean Callanan8f0dc342010-06-22 23:46:24 +0000974 }
Sean Callanandc5fce12011-12-01 21:04:37 +0000975 else
976 {
977 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
978
979 log->Printf("Function type wasn't a FunctionProtoType");
980 }
Sean Callanan8f0dc342010-06-22 23:46:24 +0000981
Greg Clayton8de27c72010-10-15 22:48:33 +0000982 m_decls.push_back(func_decl);
Sean Callanan8f0dc342010-06-22 23:46:24 +0000983
Greg Clayton8de27c72010-10-15 22:48:33 +0000984 return func_decl;
Sean Callanan8f0dc342010-06-22 23:46:24 +0000985}
Sean Callanan0fc73582010-07-27 00:55:47 +0000986
Greg Claytonb01000f2011-01-17 03:46:26 +0000987clang::NamedDecl *
988NameSearchContext::AddGenericFunDecl()
Sean Callanan0fc73582010-07-27 00:55:47 +0000989{
Sean Callananad293092011-01-18 23:32:05 +0000990 FunctionProtoType::ExtProtoInfo proto_info;
991
992 proto_info.Variadic = true;
993
Sean Callananf76afff2011-10-28 23:38:38 +0000994 QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result
995 NULL, // argument types
996 0, // number of arguments
997 proto_info));
Greg Clayton8de27c72010-10-15 22:48:33 +0000998
Sean Callanan0fc73582010-07-27 00:55:47 +0000999 return AddFunDecl(generic_function_type.getAsOpaquePtr());
1000}
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001001
Greg Claytonb01000f2011-01-17 03:46:26 +00001002clang::NamedDecl *
1003NameSearchContext::AddTypeDecl(void *type)
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001004{
Greg Claytona1aaaff2011-01-23 00:34:52 +00001005 if (type)
1006 {
1007 QualType qual_type = QualType::getFromOpaquePtr(type);
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001008
Sean Callanand5b3c352011-01-27 04:42:51 +00001009 if (const TagType *tag_type = dyn_cast<clang::TagType>(qual_type))
Greg Claytona1aaaff2011-01-23 00:34:52 +00001010 {
1011 TagDecl *tag_decl = tag_type->getDecl();
1012
1013 m_decls.push_back(tag_decl);
1014
1015 return tag_decl;
1016 }
Sean Callanand5b3c352011-01-27 04:42:51 +00001017 else if (const ObjCObjectType *objc_object_type = dyn_cast<clang::ObjCObjectType>(qual_type))
Greg Claytona1aaaff2011-01-23 00:34:52 +00001018 {
1019 ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
1020
1021 m_decls.push_back((NamedDecl*)interface_decl);
1022
1023 return (NamedDecl*)interface_decl;
1024 }
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001025 }
Greg Claytona1aaaff2011-01-23 00:34:52 +00001026 return NULL;
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001027}
Greg Claytone6d72ca2011-06-25 00:44:06 +00001028
1029void
1030NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result)
1031{
1032 for (clang::NamedDecl * const *decl_iterator = result.first;
1033 decl_iterator != result.second;
1034 ++decl_iterator)
1035 m_decls.push_back (*decl_iterator);
1036}
1037
1038void
1039NameSearchContext::AddNamedDecl (clang::NamedDecl *decl)
1040{
1041 m_decls.push_back (decl);
1042}