blob: d7a19264b8826fb1c59faf604441222af99ac567 [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
Sean Callananb2027ec2011-12-08 23:45:45 +0000152 static unsigned int invocation_id = 0;
153 unsigned int current_id = invocation_id++;
154
Sean Callananbb715f92011-10-29 02:28:18 +0000155 if (log)
156 {
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000157 log->Printf(" CompleteTagDecl[%u] on (ASTContext*)%p Completing (TagDecl*)%p named %s",
158 current_id,
Sean Callananb2027ec2011-12-08 23:45:45 +0000159 m_ast_context,
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000160 tag_decl,
Sean Callananb2027ec2011-12-08 23:45:45 +0000161 tag_decl->getName().str().c_str());
162
163 log->Printf(" CTD[%u] Before:", current_id);
Sean Callananbb715f92011-10-29 02:28:18 +0000164 ASTDumper dumper((Decl*)tag_decl);
165 dumper.ToLog(log, " [CTD] ");
166 }
167
Sean Callananb2027ec2011-12-08 23:45:45 +0000168 if (!m_ast_importer->CompleteTagDecl (tag_decl))
169 {
170 // We couldn't complete the type. Maybe there's a definition
171 // somewhere else that can be completed.
172
173 if (log)
174 log->Printf(" CTD[%u] Type could not be completed in the module in which it was first found.", current_id);
175
176 bool found = false;
177
178 DeclContext *decl_ctx = tag_decl->getDeclContext();
179
180 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx))
181 {
182 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
183
184 if (log && log->GetVerbose())
185 log->Printf(" CTD[%u] Inspecting namespace map %p (%d entries)",
186 current_id,
187 namespace_map.get(),
188 (int)namespace_map->size());
189
190 if (!namespace_map)
191 return;
192
193 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
194 i != e && !found;
195 ++i)
196 {
197 if (log)
198 log->Printf(" CTD[%u] Searching namespace %s in module %s",
199 current_id,
200 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
201 i->first->GetFileSpec().GetFilename().GetCString());
202
203 TypeList types;
204
205 SymbolContext null_sc;
206 ConstString name(tag_decl->getName().str().c_str());
207
208 i->first->FindTypes(null_sc, name, &i->second, true, UINT32_MAX, types);
209
210 for (uint32_t ti = 0, te = types.GetSize();
211 ti != te && !found;
212 ++ti)
213 {
214 lldb::TypeSP type = types.GetTypeAtIndex(ti);
215
216 if (!type)
217 continue;
218
219 lldb::clang_type_t opaque_type = type->GetClangFullType();
220
221 if (!opaque_type)
222 continue;
223
Sean Callanan21f2e192011-12-14 01:13:04 +0000224 const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>();
Sean Callananb2027ec2011-12-08 23:45:45 +0000225
226 if (!tag_type)
227 continue;
228
229 TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
230
231 if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
232 found = true;
233 }
234 }
235 }
236 else
237 {
238 TypeList types;
239
240 SymbolContext null_sc;
241 ConstString name(tag_decl->getName().str().c_str());
242 ClangNamespaceDecl namespace_decl;
243
244 ModuleList &module_list = m_target->GetImages();
245
246 module_list.FindTypes(null_sc, name, true, UINT32_MAX, types);
247
248 for (uint32_t ti = 0, te = types.GetSize();
249 ti != te && !found;
250 ++ti)
251 {
252 lldb::TypeSP type = types.GetTypeAtIndex(ti);
253
254 if (!type)
255 continue;
256
257 lldb::clang_type_t opaque_type = type->GetClangFullType();
258
259 if (!opaque_type)
260 continue;
261
Sean Callanan21f2e192011-12-14 01:13:04 +0000262 const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>();
Sean Callananb2027ec2011-12-08 23:45:45 +0000263
264 if (!tag_type)
265 continue;
266
267 TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
268
269 if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
270 found = true;
271 }
272 }
273 }
Sean Callananbb715f92011-10-29 02:28:18 +0000274
275 if (log)
276 {
277 log->Printf(" [CTD] After:");
278 ASTDumper dumper((Decl*)tag_decl);
279 dumper.ToLog(log, " [CTD] ");
280 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000281}
282
283void
Sean Callananbb715f92011-10-29 02:28:18 +0000284ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
285{
286 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
287
288 if (log)
289 {
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000290 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 +0000291 log->Printf(" [COID] Before:");
292 ASTDumper dumper((Decl*)interface_decl);
293 dumper.ToLog(log, " [COID] ");
294 }
295
296 m_ast_importer->CompleteObjCInterfaceDecl (interface_decl);
297
298 if (log)
299 {
300 log->Printf(" [COID] After:");
301 ASTDumper dumper((Decl*)interface_decl);
302 dumper.ToLog(log, " [COID] ");
303 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000304}
305
Sean Callanan9b6898f2011-07-30 02:42:06 +0000306clang::ExternalLoadResult
Sean Callananbb715f92011-10-29 02:28:18 +0000307ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context,
308 bool (*predicate)(Decl::Kind),
309 llvm::SmallVectorImpl<Decl*> &decls)
310{
311 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
312
313 const Decl *context_decl = dyn_cast<Decl>(decl_context);
314
315 if (!context_decl)
316 return ELR_Failure;
317
318 static unsigned int invocation_id = 0;
319 unsigned int current_id = invocation_id++;
320
321 if (log)
322 {
323 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000324 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000325 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000326 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000327 context_named_decl->getNameAsString().c_str(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000328 context_decl->getDeclKindName(),
329 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000330 (predicate ? "non-null" : "null"));
331 else if(context_decl)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000332 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000333 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000334 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000335 context_decl->getDeclKindName(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000336 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000337 (predicate ? "non-null" : "null"));
338 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000339 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000340 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000341 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000342 (predicate ? "non-null" : "null"));
343 }
344
345 Decl *original_decl = NULL;
346 ASTContext *original_ctx = NULL;
347
348 if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
349 return ELR_Failure;
350
351 if (log)
352 {
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000353 log->Printf(" FELD[%u] Original decl (Decl*)%p:", current_id, original_decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000354 ASTDumper(original_decl).ToLog(log, " ");
355 }
356
357 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
358 {
359 ExternalASTSource *external_source = original_ctx->getExternalSource();
360
361 if (external_source)
362 external_source->CompleteType (original_tag_decl);
363 }
364
Sean Callananb2027ec2011-12-08 23:45:45 +0000365 const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000366
367 if (!original_decl_context)
368 return ELR_Failure;
369
370 for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
371 iter != original_decl_context->decls_end();
372 ++iter)
373 {
374 Decl *decl = *iter;
375
376 if (!predicate || predicate(decl->getKind()))
377 {
378 if (log)
379 {
380 ASTDumper ast_dumper(decl);
381 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
382 log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString());
383 else
384 log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString());
385 }
386
Sean Callanan4938bd62011-11-16 18:20:47 +0000387 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, original_ctx, decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000388
389 decls.push_back(copied_decl);
390 }
391 }
392
393 return ELR_AlreadyLoaded;
Chris Lattner24943d22010-06-08 16:52:24 +0000394}
395
Sean Callanan9394b5a2011-10-29 19:50:43 +0000396void
397ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context)
398{
399 assert (m_ast_context);
400
401 const ConstString name(context.m_decl_name.getAsString().c_str());
402
403 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
404
405 static unsigned int invocation_id = 0;
406 unsigned int current_id = invocation_id++;
407
408 if (log)
409 {
410 if (!context.m_decl_context)
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000411 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 +0000412 else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000413 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 +0000414 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000415 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 +0000416 }
417
418 context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
419
420 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
421 {
422 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
423
424 if (log && log->GetVerbose())
425 log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)",
426 current_id,
427 namespace_map.get(),
428 (int)namespace_map->size());
429
430 if (!namespace_map)
431 return;
432
433 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
434 i != e;
435 ++i)
436 {
437 if (log)
438 log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s",
439 current_id,
440 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
441 i->first->GetFileSpec().GetFilename().GetCString());
442
443 FindExternalVisibleDecls(context,
444 i->first,
445 i->second,
446 current_id);
447 }
448 }
Sean Callanand3812fa2011-11-15 21:50:18 +0000449 else if (isa<ObjCInterfaceDecl>(context.m_decl_context))
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000450 {
451 FindObjCPropertyDecls(context);
452 }
Sean Callanan9394b5a2011-10-29 19:50:43 +0000453 else if (!isa<TranslationUnitDecl>(context.m_decl_context))
454 {
455 // we shouldn't be getting FindExternalVisibleDecls calls for these
456 return;
457 }
458 else
459 {
460 ClangNamespaceDecl namespace_decl;
461
462 if (log)
463 log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id);
464
465 FindExternalVisibleDecls(context,
466 lldb::ModuleSP(),
467 namespace_decl,
468 current_id);
469 }
470
471 if (!context.m_namespace_map->empty())
472 {
473 if (log && log->GetVerbose())
474 log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)",
475 current_id,
476 context.m_namespace_map.get(),
477 (int)context.m_namespace_map->size());
478
479 NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map);
480
481 if (clang_namespace_decl)
482 clang_namespace_decl->setHasExternalVisibleStorage();
483 }
484}
485
486void
487ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
488 lldb::ModuleSP module_sp,
489 ClangNamespaceDecl &namespace_decl,
490 unsigned int current_id)
491{
492 assert (m_ast_context);
493
494 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
495
496 SymbolContextList sc_list;
497
498 const ConstString name(context.m_decl_name.getAsString().c_str());
499
500 const char *name_unique_cstr = name.GetCString();
501
502 if (name_unique_cstr == NULL)
503 return;
504
505 // The ClangASTSource is not responsible for finding $-names.
506 if (name_unique_cstr[0] == '$')
507 return;
508
509 if (module_sp && namespace_decl)
510 {
511 ClangNamespaceDecl found_namespace_decl;
512
513 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
514
515 if (symbol_vendor)
516 {
517 SymbolContext null_sc;
518
519 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
520
521 if (found_namespace_decl)
522 {
523 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
524
525 if (log)
526 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
527 current_id,
528 name.GetCString(),
529 module_sp->GetFileSpec().GetFilename().GetCString());
530 }
531 }
532 }
533 else
534 {
535 ModuleList &images = m_target->GetImages();
536
537 for (uint32_t i = 0, e = images.GetSize();
538 i != e;
539 ++i)
540 {
541 lldb::ModuleSP image = images.GetModuleAtIndex(i);
542
543 if (!image)
544 continue;
545
546 ClangNamespaceDecl found_namespace_decl;
547
548 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
549
550 if (!symbol_vendor)
551 continue;
552
553 SymbolContext null_sc;
554
555 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
556
557 if (found_namespace_decl)
558 {
559 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
560
561 if (log)
562 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
563 current_id,
564 name.GetCString(),
565 image->GetFileSpec().GetFilename().GetCString());
566 }
567 }
568 }
569
570 static ConstString id_name("id");
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000571 static ConstString Class_name("Class");
Sean Callanan9394b5a2011-10-29 19:50:43 +0000572
573 do
574 {
575 TypeList types;
576 SymbolContext null_sc;
577
Sean Callanan0f71d192011-12-19 19:38:39 +0000578 if (name == id_name || name == Class_name)
579 break;
580
Sean Callanan9394b5a2011-10-29 19:50:43 +0000581 if (module_sp && namespace_decl)
582 module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types);
Sean Callanan0f71d192011-12-19 19:38:39 +0000583 else
Sean Callanane1301a62011-12-06 03:41:14 +0000584 m_target->GetImages().FindTypes(null_sc, name, true, 1, types);
Sean Callanan9394b5a2011-10-29 19:50:43 +0000585
586 if (types.GetSize())
587 {
588 lldb::TypeSP type_sp = types.GetTypeAtIndex(0);
589
590 if (log)
591 {
592 const char *name_string = type_sp->GetName().GetCString();
593
594 log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s",
595 current_id,
596 name.GetCString(),
597 (name_string ? name_string : "<anonymous>"));
598 }
599
Sean Callanane1301a62011-12-06 03:41:14 +0000600
Sean Callanan9394b5a2011-10-29 19:50:43 +0000601 void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType());
Sean Callanane1301a62011-12-06 03:41:14 +0000602
Sean Callanandc5fce12011-12-01 21:04:37 +0000603 if (!copied_type)
604 {
605 if (log)
Sean Callanane1301a62011-12-06 03:41:14 +0000606 log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result",
607 current_id);
608
Sean Callanandc5fce12011-12-01 21:04:37 +0000609 break;
610 }
611
Sean Callanan9394b5a2011-10-29 19:50:43 +0000612 context.AddTypeDecl(copied_type);
613 }
Sean Callanan673f3db2011-11-30 22:11:59 +0000614
Sean Callanan9394b5a2011-10-29 19:50:43 +0000615 } while(0);
616}
617
Sean Callanan9b714842011-11-09 19:33:21 +0000618void
619ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
620{
621 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
622
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000623 static unsigned int invocation_id = 0;
624 unsigned int current_id = invocation_id++;
625
Sean Callanan9b714842011-11-09 19:33:21 +0000626 const DeclarationName &decl_name(context.m_decl_name);
627 const DeclContext *decl_ctx(context.m_decl_context);
628
629 const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx);
630
631 if (!interface_decl)
632 return;
633
634 StreamString ss;
Sean Callanane1301a62011-12-06 03:41:14 +0000635
Sean Callanan9b714842011-11-09 19:33:21 +0000636 if (decl_name.isObjCZeroArgSelector())
637 {
638 ss.Printf("%s", decl_name.getAsString().c_str());
639 }
640 else if (decl_name.isObjCOneArgSelector())
641 {
Sean Callanan1d9ffe22011-11-14 18:29:46 +0000642 ss.Printf("%s", decl_name.getAsString().c_str());
Sean Callanan9b714842011-11-09 19:33:21 +0000643 }
644 else
645 {
646 clang::Selector sel = decl_name.getObjCSelector();
647
648 for (unsigned i = 0, e = sel.getNumArgs();
649 i != e;
650 ++i)
651 {
652 llvm::StringRef r = sel.getNameForSlot(i);
653 ss.Printf("%s:", r.str().c_str());
654 }
655 }
656 ss.Flush();
657
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000658 ConstString selector_name(ss.GetData());
659
Sean Callanan9b714842011-11-09 19:33:21 +0000660 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000661 log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]",
662 current_id,
663 m_ast_context,
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000664 interface_decl->getNameAsString().c_str(),
665 selector_name.AsCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000666 SymbolContextList sc_list;
667
668 const bool include_symbols = false;
669 const bool append = false;
670
Sean Callanane0028b82012-01-19 02:17:40 +0000671 std::string interface_name = interface_decl->getNameAsString();
672
673 do
674 {
675 StreamString ms;
676 ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString());
677 ms.Flush();
678 ConstString instance_method_name(ms.GetData());
679
680 m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, append, sc_list);
681
682 if (sc_list.GetSize())
683 break;
684
685 ms.Clear();
686 ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString());
687 ms.Flush();
688 ConstString class_method_name(ms.GetData());
689
690 m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, append, sc_list);
691
692 if (sc_list.GetSize())
693 break;
694
695 // Fall back and check for methods in categories. If we find methods this way, we need to check that they're actually in
696 // categories on the desired class.
697
698 SymbolContextList candidate_sc_list;
699
700 m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, append, candidate_sc_list);
701
702 for (uint32_t ci = 0, ce = candidate_sc_list.GetSize();
703 ci != ce;
704 ++ci)
705 {
706 SymbolContext candidate_sc;
707
708 if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc))
709 continue;
710
711 if (!candidate_sc.function)
712 continue;
713
714 const char *candidate_name = candidate_sc.function->GetName().AsCString();
715
716 const char *cursor = candidate_name;
717
718 if (*cursor != '+' && *cursor != '-')
719 continue;
720
721 ++cursor;
722
723 if (*cursor != '[')
724 continue;
725
726 ++cursor;
727
728 size_t interface_len = interface_name.length();
729
730 if (strncmp(cursor, interface_name.c_str(), interface_len))
731 continue;
732
733 cursor += interface_len;
734
735 if (*cursor == ' ' || *cursor == '(')
736 sc_list.Append(candidate_sc);
737 }
738 }
739 while (0);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000740
741 for (uint32_t i = 0, e = sc_list.GetSize();
742 i != e;
743 ++i)
744 {
745 SymbolContext sc;
746
747 if (!sc_list.GetContextAtIndex(i, sc))
748 continue;
749
750 if (!sc.function)
751 continue;
752
753 DeclContext *function_ctx = sc.function->GetClangDeclContext();
754
755 if (!function_ctx)
756 continue;
757
758 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx);
759
760 if (!method_decl)
761 continue;
762
763 ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface();
764
765 if (!found_interface_decl)
766 continue;
767
768 if (found_interface_decl->getName() == interface_decl->getName())
769 {
Sean Callanan4938bd62011-11-16 18:20:47 +0000770 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000771
772 if (!copied_decl)
773 continue;
774
775 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
776
777 if (!copied_method_decl)
778 continue;
779
780 if (log)
781 {
782 ASTDumper dumper((Decl*)copied_method_decl);
Sean Callanane1301a62011-12-06 03:41:14 +0000783 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000784 }
Sean Callanane0028b82012-01-19 02:17:40 +0000785
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000786 context.AddNamedDecl(copied_method_decl);
787 }
788 }
Sean Callanan9b714842011-11-09 19:33:21 +0000789}
790
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000791void
792ClangASTSource::FindObjCPropertyDecls (NameSearchContext &context)
793{
794 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
795
796 static unsigned int invocation_id = 0;
797 unsigned int current_id = invocation_id++;
798
799 const ObjCInterfaceDecl *iface_decl = cast<ObjCInterfaceDecl>(context.m_decl_context);
800 Decl *orig_decl;
801 ASTContext *orig_ast_ctx;
802
803 m_ast_importer->ResolveDeclOrigin(iface_decl, &orig_decl, &orig_ast_ctx);
804
805 if (!orig_decl)
806 return;
807
808 ObjCInterfaceDecl *orig_iface_decl = dyn_cast<ObjCInterfaceDecl>(orig_decl);
809
810 if (!orig_iface_decl)
811 return;
812
813 if (!ClangASTContext::GetCompleteDecl(orig_ast_ctx, orig_iface_decl))
814 return;
815
816 std::string property_name_str = context.m_decl_name.getAsString();
817 StringRef property_name(property_name_str.c_str());
818 ObjCPropertyDecl *property_decl = orig_iface_decl->FindPropertyDeclaration(&orig_ast_ctx->Idents.get(property_name));
819
820 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000821 log->Printf("ClangASTSource::FindObjCPropertyDecls[%d] on (ASTContext*)%p for property '%s.%s'",
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000822 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000823 m_ast_context,
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000824 iface_decl->getNameAsString().c_str(),
825 property_name_str.c_str());
826
827 if (!property_decl)
828 return;
829
Sean Callanan4938bd62011-11-16 18:20:47 +0000830 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, orig_ast_ctx, property_decl);
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000831
832 if (!copied_decl)
833 return;
834
835 ObjCPropertyDecl *copied_property_decl = dyn_cast<ObjCPropertyDecl>(copied_decl);
836
837 if (!copied_property_decl)
838 return;
839
840 if (log)
841 {
842 ASTDumper dumper((Decl*)copied_property_decl);
843 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
844 }
845
846 context.AddNamedDecl(copied_property_decl);
847}
848
Sean Callanan73b520f2011-10-29 01:58:46 +0000849void
850ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
851 const ConstString &name,
852 ClangASTImporter::NamespaceMapSP &parent_map) const
853{
854 static unsigned int invocation_id = 0;
855 unsigned int current_id = invocation_id++;
856
857 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
858
859 if (log)
860 {
861 if (parent_map && parent_map->size())
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000862 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +0000863 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000864 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +0000865 name.GetCString(),
866 parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str());
867 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000868 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +0000869 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000870 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +0000871 name.GetCString());
872 }
873
874
875 if (parent_map)
876 {
877 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
878 i != e;
879 ++i)
880 {
881 ClangNamespaceDecl found_namespace_decl;
882
883 lldb::ModuleSP module_sp = i->first;
884 ClangNamespaceDecl module_parent_namespace_decl = i->second;
885
886 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
887
888 if (!symbol_vendor)
889 continue;
890
891 SymbolContext null_sc;
892
893 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
894
895 if (!found_namespace_decl)
896 continue;
897
898 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
899
900 if (log)
901 log->Printf(" CMN[%u] Found namespace %s in module %s",
902 current_id,
903 name.GetCString(),
904 module_sp->GetFileSpec().GetFilename().GetCString());
905 }
906 }
907 else
908 {
909 ModuleList &images = m_target->GetImages();
910 ClangNamespaceDecl null_namespace_decl;
911
912 for (uint32_t i = 0, e = images.GetSize();
913 i != e;
914 ++i)
915 {
916 lldb::ModuleSP image = images.GetModuleAtIndex(i);
917
918 if (!image)
919 continue;
920
921 ClangNamespaceDecl found_namespace_decl;
922
923 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
924
925 if (!symbol_vendor)
926 continue;
927
928 SymbolContext null_sc;
929
930 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
931
932 if (!found_namespace_decl)
933 continue;
934
935 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
936
937 if (log)
938 log->Printf(" CMN[%u] Found namespace %s in module %s",
939 current_id,
940 name.GetCString(),
941 image->GetFileSpec().GetFilename().GetCString());
942 }
943 }
944}
945
Sean Callananbb715f92011-10-29 02:28:18 +0000946NamespaceDecl *
947ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
948{
949 if (namespace_decls.empty())
950 return NULL;
951
952 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
953
954 const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
955
Sean Callanan4938bd62011-11-16 18:20:47 +0000956 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl());
Sean Callananbb715f92011-10-29 02:28:18 +0000957
958 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
959
960 m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
961
962 return dyn_cast<NamespaceDecl>(copied_decl);
963}
964
Sean Callanan9394b5a2011-10-29 19:50:43 +0000965void *
966ClangASTSource::GuardedCopyType (ASTContext *dest_context,
967 ASTContext *source_context,
968 void *clang_type)
969{
970 SetImportInProgress(true);
971
Sean Callanan4938bd62011-11-16 18:20:47 +0000972 QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type));
Sean Callanan9394b5a2011-10-29 19:50:43 +0000973
974 void *ret = ret_qual_type.getAsOpaquePtr();
975
976 SetImportInProgress(false);
977
978 return ret;
979}
980
Greg Claytonb01000f2011-01-17 03:46:26 +0000981clang::NamedDecl *
982NameSearchContext::AddVarDecl(void *type)
983{
Greg Clayton8de27c72010-10-15 22:48:33 +0000984 IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
Sean Callanan1ddd9fe2010-11-30 00:27:43 +0000985
986 assert (type && "Type for variable must be non-NULL!");
Sean Callanancc074622010-09-14 21:59:34 +0000987
Sean Callananf76afff2011-10-28 23:38:38 +0000988 clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +0000989 const_cast<DeclContext*>(m_decl_context),
Chris Lattner24943d22010-06-08 16:52:24 +0000990 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +0000991 SourceLocation(),
Sean Callanancc074622010-09-14 21:59:34 +0000992 ii,
Chris Lattner24943d22010-06-08 16:52:24 +0000993 QualType::getFromOpaquePtr(type),
994 0,
Sean Callanan47a5c4c2010-09-23 03:01:22 +0000995 SC_Static,
996 SC_Static);
Greg Clayton8de27c72010-10-15 22:48:33 +0000997 m_decls.push_back(Decl);
Chris Lattner24943d22010-06-08 16:52:24 +0000998
999 return Decl;
1000}
Sean Callanan8f0dc342010-06-22 23:46:24 +00001001
Greg Claytonb01000f2011-01-17 03:46:26 +00001002clang::NamedDecl *
1003NameSearchContext::AddFunDecl (void *type)
1004{
Sean Callananf76afff2011-10-28 23:38:38 +00001005 clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +00001006 const_cast<DeclContext*>(m_decl_context),
1007 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +00001008 SourceLocation(),
Greg Clayton8de27c72010-10-15 22:48:33 +00001009 m_decl_name.getAsIdentifierInfo(),
1010 QualType::getFromOpaquePtr(type),
1011 NULL,
1012 SC_Static,
1013 SC_Static,
1014 false,
1015 true);
Sean Callanan8f0dc342010-06-22 23:46:24 +00001016
Sean Callananb291abe2010-08-12 23:45:38 +00001017 // We have to do more than just synthesize the FunctionDecl. We have to
1018 // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
1019 // this, we raid the function's FunctionProtoType for types.
1020
Greg Clayton8de27c72010-10-15 22:48:33 +00001021 QualType qual_type (QualType::getFromOpaquePtr(type));
Sean Callanan21f2e192011-12-14 01:13:04 +00001022 const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>();
Sean Callanan8f0dc342010-06-22 23:46:24 +00001023
Greg Clayton8de27c72010-10-15 22:48:33 +00001024 if (func_proto_type)
Sean Callanan3c821cc2010-06-23 18:58:10 +00001025 {
Greg Clayton8de27c72010-10-15 22:48:33 +00001026 unsigned NumArgs = func_proto_type->getNumArgs();
Sean Callanan8f0dc342010-06-22 23:46:24 +00001027 unsigned ArgIndex;
1028
Sean Callananc1535182011-10-07 23:18:13 +00001029 SmallVector<ParmVarDecl *, 5> parm_var_decls;
1030
Sean Callanan8f0dc342010-06-22 23:46:24 +00001031 for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
1032 {
Greg Clayton8de27c72010-10-15 22:48:33 +00001033 QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001034
Sean Callananf76afff2011-10-28 23:38:38 +00001035 parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context,
Sean Callananc1535182011-10-07 23:18:13 +00001036 const_cast<DeclContext*>(m_decl_context),
1037 SourceLocation(),
1038 SourceLocation(),
1039 NULL,
1040 arg_qual_type,
1041 NULL,
1042 SC_Static,
1043 SC_Static,
1044 NULL));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001045 }
1046
Sean Callananc1535182011-10-07 23:18:13 +00001047 func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001048 }
Sean Callanandc5fce12011-12-01 21:04:37 +00001049 else
1050 {
1051 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1052
1053 log->Printf("Function type wasn't a FunctionProtoType");
1054 }
Sean Callanan8f0dc342010-06-22 23:46:24 +00001055
Greg Clayton8de27c72010-10-15 22:48:33 +00001056 m_decls.push_back(func_decl);
Sean Callanan8f0dc342010-06-22 23:46:24 +00001057
Greg Clayton8de27c72010-10-15 22:48:33 +00001058 return func_decl;
Sean Callanan8f0dc342010-06-22 23:46:24 +00001059}
Sean Callanan0fc73582010-07-27 00:55:47 +00001060
Greg Claytonb01000f2011-01-17 03:46:26 +00001061clang::NamedDecl *
1062NameSearchContext::AddGenericFunDecl()
Sean Callanan0fc73582010-07-27 00:55:47 +00001063{
Sean Callananad293092011-01-18 23:32:05 +00001064 FunctionProtoType::ExtProtoInfo proto_info;
1065
1066 proto_info.Variadic = true;
1067
Sean Callananf76afff2011-10-28 23:38:38 +00001068 QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result
1069 NULL, // argument types
1070 0, // number of arguments
1071 proto_info));
Greg Clayton8de27c72010-10-15 22:48:33 +00001072
Sean Callanan0fc73582010-07-27 00:55:47 +00001073 return AddFunDecl(generic_function_type.getAsOpaquePtr());
1074}
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001075
Greg Claytonb01000f2011-01-17 03:46:26 +00001076clang::NamedDecl *
1077NameSearchContext::AddTypeDecl(void *type)
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001078{
Greg Claytona1aaaff2011-01-23 00:34:52 +00001079 if (type)
1080 {
1081 QualType qual_type = QualType::getFromOpaquePtr(type);
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001082
Sean Callanan21f2e192011-12-14 01:13:04 +00001083 if (const TagType *tag_type = qual_type->getAs<TagType>())
Greg Claytona1aaaff2011-01-23 00:34:52 +00001084 {
1085 TagDecl *tag_decl = tag_type->getDecl();
1086
1087 m_decls.push_back(tag_decl);
1088
1089 return tag_decl;
1090 }
Sean Callanan21f2e192011-12-14 01:13:04 +00001091 else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>())
Greg Claytona1aaaff2011-01-23 00:34:52 +00001092 {
1093 ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
1094
1095 m_decls.push_back((NamedDecl*)interface_decl);
1096
1097 return (NamedDecl*)interface_decl;
1098 }
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001099 }
Greg Claytona1aaaff2011-01-23 00:34:52 +00001100 return NULL;
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001101}
Greg Claytone6d72ca2011-06-25 00:44:06 +00001102
1103void
1104NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result)
1105{
1106 for (clang::NamedDecl * const *decl_iterator = result.first;
1107 decl_iterator != result.second;
1108 ++decl_iterator)
1109 m_decls.push_back (*decl_iterator);
1110}
1111
1112void
1113NameSearchContext::AddNamedDecl (clang::NamedDecl *decl)
1114{
1115 m_decls.push_back (decl);
1116}