blob: 5461f1918c702eb7d7045a464c7a076b1704df5d [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"
Sean Callanan8f2e3922012-02-04 08:49:35 +000012#include "clang/AST/RecordLayout.h"
Greg Claytonf4c7ae02010-10-15 03:36:13 +000013#include "lldb/Core/Log.h"
Greg Clayton6e0101c2011-09-17 06:21:20 +000014#include "lldb/Core/Module.h"
Sean Callanan73b520f2011-10-29 01:58:46 +000015#include "lldb/Core/ModuleList.h"
Sean Callananbb715f92011-10-29 02:28:18 +000016#include "lldb/Expression/ASTDumper.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Expression/ClangASTSource.h"
18#include "lldb/Expression/ClangExpression.h"
Sean Callanan73b520f2011-10-29 01:58:46 +000019#include "lldb/Symbol/ClangNamespaceDecl.h"
20#include "lldb/Symbol/SymbolVendor.h"
Sean Callanan673f3db2011-11-30 22:11:59 +000021#include "lldb/Target/ObjCLanguageRuntime.h"
Sean Callanan73b520f2011-10-29 01:58:46 +000022#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023
24using namespace clang;
25using namespace lldb_private;
26
Greg Claytonb01000f2011-01-17 03:46:26 +000027ClangASTSource::~ClangASTSource()
28{
Sean Callanana3d04472011-11-29 00:42:02 +000029 m_ast_importer->ForgetDestination(m_ast_context);
30
Johnny Chenfa21ffd2011-11-30 23:18:53 +000031 // We are in the process of destruction, don't create clang ast context on demand
32 // by passing false to Target::GetScratchClangASTContext(create_on_demand).
33 ClangASTContext *scratch_clang_ast_context = m_target->GetScratchClangASTContext(false);
Sean Callanana3d04472011-11-29 00:42:02 +000034
35 if (!scratch_clang_ast_context)
36 return;
37
38 clang::ASTContext *scratch_ast_context = scratch_clang_ast_context->getASTContext();
39
40 if (!scratch_ast_context)
41 return;
42
43 if (m_ast_context != scratch_ast_context)
44 m_ast_importer->ForgetSource(scratch_ast_context, m_ast_context);
Greg Claytonb01000f2011-01-17 03:46:26 +000045}
Chris Lattner24943d22010-06-08 16:52:24 +000046
Greg Claytonb01000f2011-01-17 03:46:26 +000047void
48ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer)
49{
Sean Callananf76afff2011-10-28 23:38:38 +000050 if (!m_ast_context)
51 return;
52
53 m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage();
54 m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage();
Chris Lattner24943d22010-06-08 16:52:24 +000055}
56
Chris Lattner24943d22010-06-08 16:52:24 +000057// The core lookup interface.
Greg Claytonb01000f2011-01-17 03:46:26 +000058DeclContext::lookup_result
59ClangASTSource::FindExternalVisibleDeclsByName
Greg Claytonf4c7ae02010-10-15 03:36:13 +000060(
61 const DeclContext *decl_ctx,
Greg Clayton8de27c72010-10-15 22:48:33 +000062 DeclarationName clang_decl_name
Greg Claytonf4c7ae02010-10-15 03:36:13 +000063)
64{
Sean Callananf76afff2011-10-28 23:38:38 +000065 if (!m_ast_context)
66 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
67
68 if (GetImportInProgress())
Greg Claytonb01000f2011-01-17 03:46:26 +000069 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
70
71 std::string decl_name (clang_decl_name.getAsString());
72
73// if (m_decl_map.DoingASTImport ())
74// return DeclContext::lookup_result();
75//
Greg Clayton8de27c72010-10-15 22:48:33 +000076 switch (clang_decl_name.getNameKind()) {
Chris Lattner24943d22010-06-08 16:52:24 +000077 // Normal identifiers.
78 case DeclarationName::Identifier:
Greg Clayton8de27c72010-10-15 22:48:33 +000079 if (clang_decl_name.getAsIdentifierInfo()->getBuiltinID() != 0)
80 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
81 break;
Chris Lattner24943d22010-06-08 16:52:24 +000082
83 // Operator names. Not important for now.
84 case DeclarationName::CXXOperatorName:
85 case DeclarationName::CXXLiteralOperatorName:
86 return DeclContext::lookup_result();
87
88 // Using directives found in this context.
89 // Tell Sema we didn't find any or we'll end up getting asked a *lot*.
90 case DeclarationName::CXXUsingDirective:
Greg Clayton8de27c72010-10-15 22:48:33 +000091 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
Chris Lattner24943d22010-06-08 16:52:24 +000092
Chris Lattner24943d22010-06-08 16:52:24 +000093 case DeclarationName::ObjCZeroArgSelector:
94 case DeclarationName::ObjCOneArgSelector:
95 case DeclarationName::ObjCMultiArgSelector:
Sean Callanan9b714842011-11-09 19:33:21 +000096 {
97 llvm::SmallVector<NamedDecl*, 1> method_decls;
Chris Lattner24943d22010-06-08 16:52:24 +000098
Sean Callanan9b714842011-11-09 19:33:21 +000099 NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx);
100
101 FindObjCMethodDecls(method_search_context);
102
103 return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls);
104 }
Chris Lattner24943d22010-06-08 16:52:24 +0000105 // These aren't possible in the global context.
106 case DeclarationName::CXXConstructorName:
107 case DeclarationName::CXXDestructorName:
108 case DeclarationName::CXXConversionFunctionName:
109 return DeclContext::lookup_result();
110 }
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000111
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000112
Sean Callananf76afff2011-10-28 23:38:38 +0000113 if (!GetLookupsEnabled())
Greg Clayton8de27c72010-10-15 22:48:33 +0000114 {
115 // Wait until we see a '$' at the start of a name before we start doing
116 // any lookups so we can avoid lookup up all of the builtin types.
117 if (!decl_name.empty() && decl_name[0] == '$')
118 {
Sean Callananf76afff2011-10-28 23:38:38 +0000119 SetLookupsEnabled (true);
Greg Clayton8de27c72010-10-15 22:48:33 +0000120 }
121 else
122 {
123 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
124 }
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000125 }
Greg Clayton8de27c72010-10-15 22:48:33 +0000126
Greg Clayton8de27c72010-10-15 22:48:33 +0000127 ConstString const_decl_name(decl_name.c_str());
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000128
129 const char *uniqued_const_decl_name = const_decl_name.GetCString();
130 if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end())
131 {
132 // We are currently looking up this name...
133 return DeclContext::lookup_result();
134 }
135 m_active_lookups.insert(uniqued_const_decl_name);
Greg Claytona8b278a2010-11-15 01:34:18 +0000136// static uint32_t g_depth = 0;
137// ++g_depth;
138// printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name);
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000139 llvm::SmallVector<NamedDecl*, 4> name_decls;
140 NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx);
Sean Callananf76afff2011-10-28 23:38:38 +0000141 FindExternalVisibleDecls(name_search_context);
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000142 DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls));
Greg Claytona8b278a2010-11-15 01:34:18 +0000143// --g_depth;
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000144 m_active_lookups.erase (uniqued_const_decl_name);
145 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000146}
147
Greg Claytonb01000f2011-01-17 03:46:26 +0000148void
149ClangASTSource::CompleteType (TagDecl *tag_decl)
Sean Callananbb715f92011-10-29 02:28:18 +0000150{
151 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
152
Sean Callananb2027ec2011-12-08 23:45:45 +0000153 static unsigned int invocation_id = 0;
154 unsigned int current_id = invocation_id++;
155
Sean Callananbb715f92011-10-29 02:28:18 +0000156 if (log)
157 {
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000158 log->Printf(" CompleteTagDecl[%u] on (ASTContext*)%p Completing (TagDecl*)%p named %s",
159 current_id,
Sean Callananb2027ec2011-12-08 23:45:45 +0000160 m_ast_context,
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000161 tag_decl,
Sean Callananb2027ec2011-12-08 23:45:45 +0000162 tag_decl->getName().str().c_str());
163
164 log->Printf(" CTD[%u] Before:", current_id);
Sean Callananbb715f92011-10-29 02:28:18 +0000165 ASTDumper dumper((Decl*)tag_decl);
166 dumper.ToLog(log, " [CTD] ");
167 }
168
Sean Callananb2027ec2011-12-08 23:45:45 +0000169 if (!m_ast_importer->CompleteTagDecl (tag_decl))
170 {
171 // We couldn't complete the type. Maybe there's a definition
172 // somewhere else that can be completed.
173
174 if (log)
175 log->Printf(" CTD[%u] Type could not be completed in the module in which it was first found.", current_id);
176
177 bool found = false;
178
179 DeclContext *decl_ctx = tag_decl->getDeclContext();
180
181 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx))
182 {
183 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
184
185 if (log && log->GetVerbose())
186 log->Printf(" CTD[%u] Inspecting namespace map %p (%d entries)",
187 current_id,
188 namespace_map.get(),
189 (int)namespace_map->size());
190
191 if (!namespace_map)
192 return;
193
194 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
195 i != e && !found;
196 ++i)
197 {
198 if (log)
199 log->Printf(" CTD[%u] Searching namespace %s in module %s",
200 current_id,
201 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
202 i->first->GetFileSpec().GetFilename().GetCString());
203
204 TypeList types;
205
206 SymbolContext null_sc;
207 ConstString name(tag_decl->getName().str().c_str());
208
Greg Claytondc0a38c2012-03-26 23:03:23 +0000209 i->first->FindTypesInNamespace(null_sc, name, &i->second, UINT32_MAX, types);
Sean Callananb2027ec2011-12-08 23:45:45 +0000210
211 for (uint32_t ti = 0, te = types.GetSize();
212 ti != te && !found;
213 ++ti)
214 {
215 lldb::TypeSP type = types.GetTypeAtIndex(ti);
216
217 if (!type)
218 continue;
219
220 lldb::clang_type_t opaque_type = type->GetClangFullType();
221
222 if (!opaque_type)
223 continue;
224
Sean Callanan21f2e192011-12-14 01:13:04 +0000225 const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>();
Sean Callananb2027ec2011-12-08 23:45:45 +0000226
227 if (!tag_type)
228 continue;
229
230 TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
231
232 if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
233 found = true;
234 }
235 }
236 }
237 else
238 {
239 TypeList types;
240
241 SymbolContext null_sc;
242 ConstString name(tag_decl->getName().str().c_str());
243 ClangNamespaceDecl namespace_decl;
244
245 ModuleList &module_list = m_target->GetImages();
246
Greg Claytondc0a38c2012-03-26 23:03:23 +0000247 bool exact_match = false;
Greg Clayton9f95fb62012-04-06 17:41:13 +0000248 module_list.FindTypes (null_sc, name, exact_match, UINT32_MAX, types);
Sean Callananb2027ec2011-12-08 23:45:45 +0000249
250 for (uint32_t ti = 0, te = types.GetSize();
251 ti != te && !found;
252 ++ti)
253 {
254 lldb::TypeSP type = types.GetTypeAtIndex(ti);
255
256 if (!type)
257 continue;
258
259 lldb::clang_type_t opaque_type = type->GetClangFullType();
260
261 if (!opaque_type)
262 continue;
263
Sean Callanan21f2e192011-12-14 01:13:04 +0000264 const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>();
Sean Callananb2027ec2011-12-08 23:45:45 +0000265
266 if (!tag_type)
267 continue;
268
269 TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
270
271 if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
272 found = true;
273 }
274 }
275 }
Sean Callananbb715f92011-10-29 02:28:18 +0000276
277 if (log)
278 {
279 log->Printf(" [CTD] After:");
280 ASTDumper dumper((Decl*)tag_decl);
281 dumper.ToLog(log, " [CTD] ");
282 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000283}
284
285void
Sean Callananbb715f92011-10-29 02:28:18 +0000286ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
287{
288 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
289
290 if (log)
291 {
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000292 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 +0000293 log->Printf(" [COID] Before:");
294 ASTDumper dumper((Decl*)interface_decl);
295 dumper.ToLog(log, " [COID] ");
296 }
297
298 m_ast_importer->CompleteObjCInterfaceDecl (interface_decl);
299
300 if (log)
301 {
302 log->Printf(" [COID] After:");
303 ASTDumper dumper((Decl*)interface_decl);
304 dumper.ToLog(log, " [COID] ");
305 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000306}
307
Sean Callanan9b6898f2011-07-30 02:42:06 +0000308clang::ExternalLoadResult
Sean Callananbb715f92011-10-29 02:28:18 +0000309ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context,
310 bool (*predicate)(Decl::Kind),
311 llvm::SmallVectorImpl<Decl*> &decls)
312{
313 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
314
315 const Decl *context_decl = dyn_cast<Decl>(decl_context);
316
317 if (!context_decl)
318 return ELR_Failure;
319
320 static unsigned int invocation_id = 0;
321 unsigned int current_id = invocation_id++;
322
323 if (log)
324 {
325 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000326 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000327 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000328 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000329 context_named_decl->getNameAsString().c_str(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000330 context_decl->getDeclKindName(),
331 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000332 (predicate ? "non-null" : "null"));
333 else if(context_decl)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000334 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000335 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000336 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000337 context_decl->getDeclKindName(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000338 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000339 (predicate ? "non-null" : "null"));
340 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000341 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000342 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000343 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000344 (predicate ? "non-null" : "null"));
345 }
346
347 Decl *original_decl = NULL;
348 ASTContext *original_ctx = NULL;
349
350 if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
351 return ELR_Failure;
352
353 if (log)
354 {
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000355 log->Printf(" FELD[%u] Original decl (Decl*)%p:", current_id, original_decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000356 ASTDumper(original_decl).ToLog(log, " ");
357 }
358
359 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
360 {
361 ExternalASTSource *external_source = original_ctx->getExternalSource();
362
363 if (external_source)
364 external_source->CompleteType (original_tag_decl);
365 }
366
Sean Callananb2027ec2011-12-08 23:45:45 +0000367 const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000368
369 if (!original_decl_context)
370 return ELR_Failure;
371
372 for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
373 iter != original_decl_context->decls_end();
374 ++iter)
375 {
376 Decl *decl = *iter;
377
378 if (!predicate || predicate(decl->getKind()))
379 {
380 if (log)
381 {
382 ASTDumper ast_dumper(decl);
383 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
384 log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString());
385 else
386 log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString());
387 }
388
Sean Callanan4938bd62011-11-16 18:20:47 +0000389 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, original_ctx, decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000390
Sean Callananddb59332012-03-20 21:11:12 +0000391 if (!copied_decl)
392 continue;
393
Sean Callanane9478392012-03-15 01:53:17 +0000394 if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl))
395 {
396 QualType copied_field_type = copied_field->getType();
397
398 if (const TagType *copied_field_tag_type = copied_field_type->getAs<TagType>())
399 m_ast_importer->CompleteTagDecl(copied_field_tag_type->getDecl());
400 if (const ObjCObjectType *copied_field_object_type = copied_field_type->getAs<ObjCObjectType>())
401 if (ObjCInterfaceDecl *copied_field_objc_interface_decl = copied_field_object_type->getInterface())
402 m_ast_importer->CompleteObjCInterfaceDecl(copied_field_objc_interface_decl);
403 }
404
Sean Callananbb715f92011-10-29 02:28:18 +0000405 decls.push_back(copied_decl);
406 }
407 }
408
409 return ELR_AlreadyLoaded;
Chris Lattner24943d22010-06-08 16:52:24 +0000410}
411
Sean Callanan9394b5a2011-10-29 19:50:43 +0000412void
413ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context)
414{
415 assert (m_ast_context);
416
417 const ConstString name(context.m_decl_name.getAsString().c_str());
418
419 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
420
421 static unsigned int invocation_id = 0;
422 unsigned int current_id = invocation_id++;
423
424 if (log)
425 {
426 if (!context.m_decl_context)
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000427 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 +0000428 else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000429 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 +0000430 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000431 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 +0000432 }
433
434 context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
435
436 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
437 {
438 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
439
440 if (log && log->GetVerbose())
441 log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)",
442 current_id,
443 namespace_map.get(),
444 (int)namespace_map->size());
445
446 if (!namespace_map)
447 return;
448
449 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
450 i != e;
451 ++i)
452 {
453 if (log)
454 log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s",
455 current_id,
456 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
457 i->first->GetFileSpec().GetFilename().GetCString());
458
459 FindExternalVisibleDecls(context,
460 i->first,
461 i->second,
462 current_id);
463 }
464 }
Sean Callanand3812fa2011-11-15 21:50:18 +0000465 else if (isa<ObjCInterfaceDecl>(context.m_decl_context))
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000466 {
Sean Callanan8f2e3922012-02-04 08:49:35 +0000467 FindObjCPropertyAndIvarDecls(context);
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000468 }
Sean Callanan9394b5a2011-10-29 19:50:43 +0000469 else if (!isa<TranslationUnitDecl>(context.m_decl_context))
470 {
471 // we shouldn't be getting FindExternalVisibleDecls calls for these
472 return;
473 }
474 else
475 {
476 ClangNamespaceDecl namespace_decl;
477
478 if (log)
479 log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id);
480
481 FindExternalVisibleDecls(context,
482 lldb::ModuleSP(),
483 namespace_decl,
484 current_id);
485 }
486
487 if (!context.m_namespace_map->empty())
488 {
489 if (log && log->GetVerbose())
490 log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)",
491 current_id,
492 context.m_namespace_map.get(),
493 (int)context.m_namespace_map->size());
494
495 NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map);
496
497 if (clang_namespace_decl)
498 clang_namespace_decl->setHasExternalVisibleStorage();
499 }
500}
501
502void
503ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
504 lldb::ModuleSP module_sp,
505 ClangNamespaceDecl &namespace_decl,
506 unsigned int current_id)
507{
508 assert (m_ast_context);
509
510 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
511
512 SymbolContextList sc_list;
513
514 const ConstString name(context.m_decl_name.getAsString().c_str());
515
516 const char *name_unique_cstr = name.GetCString();
517
Sean Callanan8f2e3922012-02-04 08:49:35 +0000518 static ConstString id_name("id");
519 static ConstString Class_name("Class");
520
521 if (name == id_name || name == Class_name)
522 return;
523
Sean Callanan9394b5a2011-10-29 19:50:43 +0000524 if (name_unique_cstr == NULL)
525 return;
526
527 // The ClangASTSource is not responsible for finding $-names.
528 if (name_unique_cstr[0] == '$')
529 return;
530
531 if (module_sp && namespace_decl)
532 {
533 ClangNamespaceDecl found_namespace_decl;
534
535 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
536
537 if (symbol_vendor)
538 {
539 SymbolContext null_sc;
540
541 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
542
543 if (found_namespace_decl)
544 {
545 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
546
547 if (log)
548 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
549 current_id,
550 name.GetCString(),
551 module_sp->GetFileSpec().GetFilename().GetCString());
552 }
553 }
554 }
555 else
556 {
557 ModuleList &images = m_target->GetImages();
558
559 for (uint32_t i = 0, e = images.GetSize();
560 i != e;
561 ++i)
562 {
563 lldb::ModuleSP image = images.GetModuleAtIndex(i);
564
565 if (!image)
566 continue;
567
568 ClangNamespaceDecl found_namespace_decl;
569
570 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
571
572 if (!symbol_vendor)
573 continue;
574
575 SymbolContext null_sc;
576
577 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
578
579 if (found_namespace_decl)
580 {
581 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
582
583 if (log)
584 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
585 current_id,
586 name.GetCString(),
587 image->GetFileSpec().GetFilename().GetCString());
588 }
589 }
590 }
591
Sean Callanan9394b5a2011-10-29 19:50:43 +0000592 do
593 {
594 TypeList types;
595 SymbolContext null_sc;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000596 const bool exact_match = false;
Sean Callanan0f71d192011-12-19 19:38:39 +0000597
Sean Callanan9394b5a2011-10-29 19:50:43 +0000598 if (module_sp && namespace_decl)
Greg Claytondc0a38c2012-03-26 23:03:23 +0000599 module_sp->FindTypesInNamespace(null_sc, name, &namespace_decl, 1, types);
Sean Callanan0f71d192011-12-19 19:38:39 +0000600 else
Greg Clayton9f95fb62012-04-06 17:41:13 +0000601 m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, types);
Sean Callanan9394b5a2011-10-29 19:50:43 +0000602
603 if (types.GetSize())
604 {
605 lldb::TypeSP type_sp = types.GetTypeAtIndex(0);
606
607 if (log)
608 {
609 const char *name_string = type_sp->GetName().GetCString();
610
611 log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s",
612 current_id,
613 name.GetCString(),
614 (name_string ? name_string : "<anonymous>"));
615 }
616
Sean Callanane1301a62011-12-06 03:41:14 +0000617
Sean Callanan9394b5a2011-10-29 19:50:43 +0000618 void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType());
Sean Callanane1301a62011-12-06 03:41:14 +0000619
Sean Callanandc5fce12011-12-01 21:04:37 +0000620 if (!copied_type)
621 {
622 if (log)
Sean Callanane1301a62011-12-06 03:41:14 +0000623 log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result",
624 current_id);
625
Sean Callanandc5fce12011-12-01 21:04:37 +0000626 break;
627 }
628
Sean Callanan9394b5a2011-10-29 19:50:43 +0000629 context.AddTypeDecl(copied_type);
630 }
Sean Callanan673f3db2011-11-30 22:11:59 +0000631
Sean Callanan9394b5a2011-10-29 19:50:43 +0000632 } while(0);
633}
634
Sean Callanan9b714842011-11-09 19:33:21 +0000635void
636ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
637{
638 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
639
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000640 static unsigned int invocation_id = 0;
641 unsigned int current_id = invocation_id++;
642
Sean Callanan9b714842011-11-09 19:33:21 +0000643 const DeclarationName &decl_name(context.m_decl_name);
644 const DeclContext *decl_ctx(context.m_decl_context);
645
646 const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx);
647
648 if (!interface_decl)
649 return;
650
Sean Callanan8d611562012-04-05 00:12:52 +0000651 do
652 {
653 Decl *original_decl = NULL;
654 ASTContext *original_ctx = NULL;
655
656 m_ast_importer->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx);
657
658 if (!original_decl)
659 break;
660
661 ObjCInterfaceDecl *original_interface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl);
662
663 Selector original_selector;
664
665 if (decl_name.isObjCZeroArgSelector())
666 {
667 IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString());
668 original_selector = original_ctx->Selectors.getSelector(0, &ident);
669 }
670 else if (decl_name.isObjCOneArgSelector())
671 {
672 const std::string &decl_name_string = decl_name.getAsString();
673 std::string decl_name_string_without_colon(decl_name_string.c_str(), decl_name_string.length() - 1);
674 IdentifierInfo *ident = &original_ctx->Idents.get(decl_name_string_without_colon.c_str());
675 original_selector = original_ctx->Selectors.getSelector(1, &ident);
676 }
677 else
678 {
679 SmallVector<IdentifierInfo *, 4> idents;
680
681 clang::Selector sel = decl_name.getObjCSelector();
682
683 int num_args = sel.getNumArgs();
684
685 for (unsigned i = 0;
686 i != num_args;
687 ++i)
688 {
689 idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
690 }
691
692 original_selector = original_ctx->Selectors.getSelector(num_args, idents.data());
693 }
694
695 DeclarationName original_decl_name(original_selector);
696
697 ObjCInterfaceDecl::lookup_result result = original_interface_decl->lookup(original_decl_name);
698
699 if (result.first == result.second)
700 break;
701
702 if (!*result.first)
703 break;
704
705 ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(*result.first);
706
707 if (!result_method)
708 break;
709
710 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &result_method->getASTContext(), result_method);
711
712 if (!copied_decl)
713 continue;
714
715 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
716
717 if (!copied_method_decl)
718 continue;
719
720 if (log)
721 {
722 ASTDumper dumper((Decl*)copied_method_decl);
723 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
724 }
725
726 context.AddNamedDecl(copied_method_decl);
727
728 return;
729 } while (0);
730
Sean Callanan9b714842011-11-09 19:33:21 +0000731 StreamString ss;
Sean Callanane1301a62011-12-06 03:41:14 +0000732
Sean Callanan9b714842011-11-09 19:33:21 +0000733 if (decl_name.isObjCZeroArgSelector())
734 {
735 ss.Printf("%s", decl_name.getAsString().c_str());
736 }
737 else if (decl_name.isObjCOneArgSelector())
738 {
Sean Callanan1d9ffe22011-11-14 18:29:46 +0000739 ss.Printf("%s", decl_name.getAsString().c_str());
Sean Callanan9b714842011-11-09 19:33:21 +0000740 }
741 else
742 {
743 clang::Selector sel = decl_name.getObjCSelector();
744
745 for (unsigned i = 0, e = sel.getNumArgs();
746 i != e;
747 ++i)
748 {
749 llvm::StringRef r = sel.getNameForSlot(i);
750 ss.Printf("%s:", r.str().c_str());
751 }
752 }
753 ss.Flush();
754
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000755 ConstString selector_name(ss.GetData());
756
Sean Callanan9b714842011-11-09 19:33:21 +0000757 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000758 log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]",
759 current_id,
760 m_ast_context,
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000761 interface_decl->getNameAsString().c_str(),
762 selector_name.AsCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000763 SymbolContextList sc_list;
764
765 const bool include_symbols = false;
Sean Callanan302d78c2012-02-10 22:52:19 +0000766 const bool include_inlines = false;
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000767 const bool append = false;
768
Sean Callanane0028b82012-01-19 02:17:40 +0000769 std::string interface_name = interface_decl->getNameAsString();
770
771 do
772 {
773 StreamString ms;
774 ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString());
775 ms.Flush();
776 ConstString instance_method_name(ms.GetData());
777
Sean Callanan302d78c2012-02-10 22:52:19 +0000778 m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list);
Sean Callanane0028b82012-01-19 02:17:40 +0000779
780 if (sc_list.GetSize())
781 break;
782
783 ms.Clear();
784 ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString());
785 ms.Flush();
786 ConstString class_method_name(ms.GetData());
787
Sean Callanan302d78c2012-02-10 22:52:19 +0000788 m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list);
Sean Callanane0028b82012-01-19 02:17:40 +0000789
790 if (sc_list.GetSize())
791 break;
792
793 // Fall back and check for methods in categories. If we find methods this way, we need to check that they're actually in
794 // categories on the desired class.
795
796 SymbolContextList candidate_sc_list;
797
Sean Callanan302d78c2012-02-10 22:52:19 +0000798 m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list);
Sean Callanane0028b82012-01-19 02:17:40 +0000799
800 for (uint32_t ci = 0, ce = candidate_sc_list.GetSize();
801 ci != ce;
802 ++ci)
803 {
804 SymbolContext candidate_sc;
805
806 if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc))
807 continue;
808
809 if (!candidate_sc.function)
810 continue;
811
812 const char *candidate_name = candidate_sc.function->GetName().AsCString();
813
814 const char *cursor = candidate_name;
815
816 if (*cursor != '+' && *cursor != '-')
817 continue;
818
819 ++cursor;
820
821 if (*cursor != '[')
822 continue;
823
824 ++cursor;
825
826 size_t interface_len = interface_name.length();
827
828 if (strncmp(cursor, interface_name.c_str(), interface_len))
829 continue;
830
831 cursor += interface_len;
832
833 if (*cursor == ' ' || *cursor == '(')
834 sc_list.Append(candidate_sc);
835 }
836 }
837 while (0);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000838
839 for (uint32_t i = 0, e = sc_list.GetSize();
840 i != e;
841 ++i)
842 {
843 SymbolContext sc;
844
845 if (!sc_list.GetContextAtIndex(i, sc))
846 continue;
847
848 if (!sc.function)
849 continue;
850
851 DeclContext *function_ctx = sc.function->GetClangDeclContext();
852
853 if (!function_ctx)
854 continue;
855
856 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx);
857
858 if (!method_decl)
859 continue;
860
861 ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface();
862
863 if (!found_interface_decl)
864 continue;
865
866 if (found_interface_decl->getName() == interface_decl->getName())
867 {
Sean Callanan4938bd62011-11-16 18:20:47 +0000868 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000869
870 if (!copied_decl)
871 continue;
872
873 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
874
875 if (!copied_method_decl)
876 continue;
877
878 if (log)
879 {
880 ASTDumper dumper((Decl*)copied_method_decl);
Sean Callanane1301a62011-12-06 03:41:14 +0000881 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000882 }
Sean Callanane0028b82012-01-19 02:17:40 +0000883
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000884 context.AddNamedDecl(copied_method_decl);
885 }
886 }
Sean Callanan9b714842011-11-09 19:33:21 +0000887}
888
Sean Callanan8f2e3922012-02-04 08:49:35 +0000889template <class D> class TaggedASTDecl {
890public:
891 TaggedASTDecl() : decl(NULL) { }
892 TaggedASTDecl(D *_decl) : decl(_decl) { }
893 bool IsValid() const { return (decl != NULL); }
894 bool IsInvalid() const { return !IsValid(); }
895 D *operator->() const { return decl; }
896 D *decl;
897};
898
899template <class D2, template <class D> class TD, class D1>
900TD<D2>
901DynCast(TD<D1> source)
902{
903 return TD<D2> (dyn_cast<D2>(source.decl));
904}
905
906template <class D = Decl> class DeclFromParser;
907template <class D = Decl> class DeclFromUser;
908
909template <class D> class DeclFromParser : public TaggedASTDecl<D> {
910public:
911 DeclFromParser() : TaggedASTDecl<D>() { }
912 DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) { }
913
914 DeclFromUser<D> GetOrigin(ClangASTImporter *importer);
915};
916
917template <class D> class DeclFromUser : public TaggedASTDecl<D> {
918public:
919 DeclFromUser() : TaggedASTDecl<D>() { }
920 DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) { }
921
922 DeclFromParser<D> Import(ClangASTImporter *importer, ASTContext &dest_ctx);
923};
924
925template <class D>
926DeclFromUser<D>
927DeclFromParser<D>::GetOrigin(ClangASTImporter *importer)
928{
929 DeclFromUser <> origin_decl;
930 importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL);
931 if (origin_decl.IsInvalid())
932 return DeclFromUser<D>();
933 return DeclFromUser<D>(dyn_cast<D>(origin_decl.decl));
934}
935
936template <class D>
937DeclFromParser<D>
938DeclFromUser<D>::Import(ClangASTImporter *importer, ASTContext &dest_ctx)
939{
940 DeclFromParser <> parser_generic_decl(importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl));
941 if (parser_generic_decl.IsInvalid())
942 return DeclFromParser<D>();
943 return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl));
944}
945
Sean Callanan931acec2012-02-22 23:57:45 +0000946static bool
947FindObjCPropertyAndIvarDeclsWithOrigin (unsigned int current_id,
948 NameSearchContext &context,
949 clang::ASTContext &ast_context,
950 ClangASTImporter *ast_importer,
951 DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl)
952{
953 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
954
955 if (origin_iface_decl.IsInvalid())
956 return false;
957
958 std::string name_str = context.m_decl_name.getAsString();
959 StringRef name(name_str.c_str());
960 IdentifierInfo &name_identifier(origin_iface_decl->getASTContext().Idents.get(name));
961
962 DeclFromUser<ObjCPropertyDecl> origin_property_decl(origin_iface_decl->FindPropertyDeclaration(&name_identifier));
963
964 bool found = false;
965
966 if (origin_property_decl.IsValid())
967 {
968 DeclFromParser<ObjCPropertyDecl> parser_property_decl(origin_property_decl.Import(ast_importer, ast_context));
969 if (parser_property_decl.IsValid())
970 {
971 if (log)
972 {
973 ASTDumper dumper((Decl*)parser_property_decl.decl);
974 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
975 }
976
977 context.AddNamedDecl(parser_property_decl.decl);
978 found = true;
979 }
980 }
981
982 DeclFromUser<ObjCIvarDecl> origin_ivar_decl(origin_iface_decl->getIvarDecl(&name_identifier));
983
984 if (origin_ivar_decl.IsValid())
985 {
986 DeclFromParser<ObjCIvarDecl> parser_ivar_decl(origin_ivar_decl.Import(ast_importer, ast_context));
987 if (parser_ivar_decl.IsValid())
988 {
989 if (log)
990 {
991 ASTDumper dumper((Decl*)parser_ivar_decl.decl);
992 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
993 }
994
995 context.AddNamedDecl(parser_ivar_decl.decl);
996 found = true;
997 }
998 }
999
1000 return found;
1001}
1002
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001003void
Sean Callanan8f2e3922012-02-04 08:49:35 +00001004ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context)
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001005{
1006 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1007
1008 static unsigned int invocation_id = 0;
1009 unsigned int current_id = invocation_id++;
1010
Sean Callanan8f2e3922012-02-04 08:49:35 +00001011 DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl(cast<ObjCInterfaceDecl>(context.m_decl_context));
1012 DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl(parser_iface_decl.GetOrigin(m_ast_importer));
Sean Callanan931acec2012-02-22 23:57:45 +00001013
1014 ConstString class_name(parser_iface_decl->getNameAsString().c_str());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001015
1016 if (log)
Sean Callanan8f2e3922012-02-04 08:49:35 +00001017 log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on (ASTContext*)%p for '%s.%s'",
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001018 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001019 m_ast_context,
Sean Callanan8f2e3922012-02-04 08:49:35 +00001020 parser_iface_decl->getNameAsString().c_str(),
Sean Callanan931acec2012-02-22 23:57:45 +00001021 context.m_decl_name.getAsString().c_str());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001022
Sean Callanan931acec2012-02-22 23:57:45 +00001023 if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
1024 context,
1025 *m_ast_context,
1026 m_ast_importer,
1027 origin_iface_decl))
1028 return;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001029
Sean Callanan931acec2012-02-22 23:57:45 +00001030 if (log)
1031 log->Printf("CAS::FOPD[%d] couldn't find the property on origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p, searching elsewhere...",
1032 current_id,
1033 origin_iface_decl.decl,
1034 &origin_iface_decl->getASTContext());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001035
Sean Callanan931acec2012-02-22 23:57:45 +00001036 SymbolContext null_sc;
1037 TypeList type_list;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001038
Sean Callanan931acec2012-02-22 23:57:45 +00001039 lldb::ProcessSP process(m_target->GetProcessSP());
1040
1041 if (!process)
1042 return;
1043
1044 ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
1045
1046 if (!language_runtime)
1047 return;
1048
1049 lldb::TypeSP complete_type_sp(language_runtime->LookupInCompleteClassCache(class_name));
1050
1051 if (!complete_type_sp)
1052 return;
1053
1054 TypeFromUser complete_type = TypeFromUser(complete_type_sp->GetClangFullType(), complete_type_sp->GetClangAST());
1055 lldb::clang_type_t complete_opaque_type = complete_type.GetOpaqueQualType();
1056
1057 if (!complete_opaque_type)
1058 return;
1059
1060 const clang::Type *complete_clang_type = QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr();
1061 const ObjCInterfaceType *complete_interface_type = dyn_cast<ObjCInterfaceType>(complete_clang_type);
1062
1063 if (!complete_interface_type)
1064 return;
1065
1066 DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_type->getDecl());
1067
1068 if (complete_iface_decl.decl == origin_iface_decl.decl)
1069 return; // already checked this one
1070
1071 if (log)
1072 log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
1073 current_id,
1074 complete_iface_decl.decl,
1075 &complete_iface_decl->getASTContext());
1076
1077
1078 if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
1079 context,
1080 *m_ast_context,
1081 m_ast_importer,
1082 complete_iface_decl))
1083 return;
Sean Callanan8f2e3922012-02-04 08:49:35 +00001084}
1085
1086typedef llvm::DenseMap <const FieldDecl *, uint64_t> FieldOffsetMap;
1087typedef llvm::DenseMap <const CXXRecordDecl *, CharUnits> BaseOffsetMap;
1088
1089template <class D, class O>
1090static bool
1091ImportOffsetMap (llvm::DenseMap <const D*, O> &destination_map,
1092 llvm::DenseMap <const D*, O> &source_map,
1093 ClangASTImporter *importer,
1094 ASTContext &dest_ctx)
1095{
1096 typedef llvm::DenseMap <const D*, O> MapType;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001097
Sean Callanan8f2e3922012-02-04 08:49:35 +00001098 for (typename MapType::iterator fi = source_map.begin(), fe = source_map.end();
1099 fi != fe;
1100 ++fi)
1101 {
1102 DeclFromUser <D> user_decl(const_cast<D*>(fi->first));
1103 DeclFromParser <D> parser_decl(user_decl.Import(importer, dest_ctx));
1104 if (parser_decl.IsInvalid())
1105 return false;
1106 destination_map.insert(std::pair<const D *, O>(parser_decl.decl, fi->second));
1107 }
1108
1109 return true;
1110}
1111
1112template <bool IsVirtual> bool ExtractBaseOffsets (const ASTRecordLayout &record_layout,
1113 DeclFromUser<const CXXRecordDecl> &record,
1114 BaseOffsetMap &base_offsets)
1115{
1116 for (CXXRecordDecl::base_class_const_iterator
1117 bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()),
1118 be = (IsVirtual ? record->vbases_end() : record->bases_end());
1119 bi != be;
1120 ++bi)
1121 {
1122 if (!IsVirtual && bi->isVirtual())
1123 continue;
1124
1125 const clang::Type *origin_base_type = bi->getType().getTypePtr();
1126 const clang::RecordType *origin_base_record_type = origin_base_type->getAs<RecordType>();
1127
1128 if (!origin_base_record_type)
1129 return false;
1130
1131 DeclFromUser <RecordDecl> origin_base_record(origin_base_record_type->getDecl());
1132
1133 if (origin_base_record.IsInvalid())
1134 return false;
1135
1136 DeclFromUser <CXXRecordDecl> origin_base_cxx_record(DynCast<CXXRecordDecl>(origin_base_record));
1137
1138 if (origin_base_cxx_record.IsInvalid())
1139 return false;
1140
1141 CharUnits base_offset;
1142
1143 if (IsVirtual)
1144 base_offset = record_layout.getVBaseClassOffset(origin_base_cxx_record.decl);
1145 else
1146 base_offset = record_layout.getBaseClassOffset(origin_base_cxx_record.decl);
1147
1148 base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>(origin_base_cxx_record.decl, base_offset));
1149 }
1150
1151 return true;
1152}
1153
1154bool
1155ClangASTSource::layoutRecordType(const RecordDecl *record,
1156 uint64_t &size,
1157 uint64_t &alignment,
1158 FieldOffsetMap &field_offsets,
1159 BaseOffsetMap &base_offsets,
1160 BaseOffsetMap &virtual_base_offsets)
1161{
1162 static unsigned int invocation_id = 0;
1163 unsigned int current_id = invocation_id++;
1164
1165 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1166
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001167 if (log)
1168 {
Sean Callanan8f2e3922012-02-04 08:49:35 +00001169 log->Printf("LayoutRecordType[%u] on (RecordDecl*)%p [name = '%s']",
1170 current_id,
1171 m_ast_context,
1172 record->getNameAsString().c_str());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001173 }
Sean Callanan8f2e3922012-02-04 08:49:35 +00001174
1175
1176 DeclFromParser <const RecordDecl> parser_record(record);
1177 DeclFromUser <const RecordDecl> origin_record(parser_record.GetOrigin(m_ast_importer));
1178
1179 if (origin_record.IsInvalid())
1180 return false;
1181
1182 FieldOffsetMap origin_field_offsets;
1183 BaseOffsetMap origin_base_offsets;
1184 BaseOffsetMap origin_virtual_base_offsets;
1185
Sean Callanan33bff9a2012-04-07 00:06:00 +00001186 ClangASTContext::GetCompleteDecl(&origin_record->getASTContext(), const_cast<RecordDecl*>(origin_record.decl));
1187
1188 if (!origin_record.decl->getDefinition())
1189 return false;
1190
Sean Callanan8f2e3922012-02-04 08:49:35 +00001191 const ASTRecordLayout &record_layout(origin_record->getASTContext().getASTRecordLayout(origin_record.decl));
1192
1193 int field_idx = 0;
1194
1195 for (RecordDecl::field_iterator fi = origin_record->field_begin(), fe = origin_record->field_end();
1196 fi != fe;
1197 ++fi)
1198 {
1199 uint64_t field_offset = record_layout.getFieldOffset(field_idx);
1200
1201 origin_field_offsets.insert(std::pair<const FieldDecl *, uint64_t>(*fi, field_offset));
1202
1203 field_idx++;
1204 }
1205
1206 ASTContext &parser_ast_context(record->getASTContext());
1207
1208 DeclFromUser <const CXXRecordDecl> origin_cxx_record(DynCast<const CXXRecordDecl>(origin_record));
1209
1210 if (origin_cxx_record.IsValid())
1211 {
1212 if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record, origin_base_offsets) ||
1213 !ExtractBaseOffsets<true>(record_layout, origin_cxx_record, origin_virtual_base_offsets))
1214 return false;
1215 }
1216
1217 if (!ImportOffsetMap(field_offsets, origin_field_offsets, m_ast_importer, parser_ast_context) ||
1218 !ImportOffsetMap(base_offsets, origin_base_offsets, m_ast_importer, parser_ast_context) ||
1219 !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, m_ast_importer, parser_ast_context))
1220 return false;
1221
1222 size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth();
1223 alignment = record_layout.getAlignment().getQuantity() * m_ast_context->getCharWidth();
1224
1225 if (log)
1226 {
1227 log->Printf("LRT[%u] returned:", current_id);
1228 log->Printf("LRT[%u] Original = (RecordDecl*)%p", current_id, origin_record.decl);
1229 log->Printf("LRT[%u] Size = %lld", current_id, size);
1230 log->Printf("LRT[%u] Alignment = %lld", current_id, alignment);
1231 log->Printf("LRT[%u] Fields:", current_id);
1232 for (RecordDecl::field_iterator fi = record->field_begin(), fe = record->field_end();
1233 fi != fe;
1234 ++fi)
1235 {
1236 log->Printf("LRT[%u] (FieldDecl*)%p, Name = '%s', Offset = %lld bits",
1237 current_id,
1238 *fi,
1239 fi->getNameAsString().c_str(),
1240 field_offsets[*fi]);
1241 }
1242 DeclFromParser <const CXXRecordDecl> parser_cxx_record = DynCast<const CXXRecordDecl>(parser_record);
1243 if (parser_cxx_record.IsValid())
1244 {
1245 log->Printf("LRT[%u] Bases:", current_id);
1246 for (CXXRecordDecl::base_class_const_iterator bi = parser_cxx_record->bases_begin(), be = parser_cxx_record->bases_end();
1247 bi != be;
1248 ++bi)
1249 {
1250 bool is_virtual = bi->isVirtual();
1251
1252 QualType base_type = bi->getType();
1253 const RecordType *base_record_type = base_type->getAs<RecordType>();
1254 DeclFromParser <RecordDecl> base_record(base_record_type->getDecl());
1255 DeclFromParser <CXXRecordDecl> base_cxx_record = DynCast<CXXRecordDecl>(base_record);
1256
1257 log->Printf("LRT[%u] %s(CXXRecordDecl*)%p, Name = '%s', Offset = %lld chars",
1258 current_id,
1259 (is_virtual ? "Virtual " : ""),
1260 base_cxx_record.decl,
1261 base_cxx_record.decl->getNameAsString().c_str(),
1262 (is_virtual ? virtual_base_offsets[base_cxx_record.decl].getQuantity() :
1263 base_offsets[base_cxx_record.decl].getQuantity()));
1264 }
1265 }
1266 else
1267 {
1268 log->Printf("LRD[%u] Not a CXXRecord, so no bases", current_id);
1269 }
1270 }
1271
1272 return true;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001273}
1274
Sean Callanan73b520f2011-10-29 01:58:46 +00001275void
1276ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
1277 const ConstString &name,
1278 ClangASTImporter::NamespaceMapSP &parent_map) const
1279{
1280 static unsigned int invocation_id = 0;
1281 unsigned int current_id = invocation_id++;
1282
1283 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1284
1285 if (log)
1286 {
1287 if (parent_map && parent_map->size())
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001288 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +00001289 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001290 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +00001291 name.GetCString(),
1292 parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str());
1293 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001294 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +00001295 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001296 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +00001297 name.GetCString());
1298 }
1299
1300
1301 if (parent_map)
1302 {
1303 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
1304 i != e;
1305 ++i)
1306 {
1307 ClangNamespaceDecl found_namespace_decl;
1308
1309 lldb::ModuleSP module_sp = i->first;
1310 ClangNamespaceDecl module_parent_namespace_decl = i->second;
1311
1312 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
1313
1314 if (!symbol_vendor)
1315 continue;
1316
1317 SymbolContext null_sc;
1318
1319 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
1320
1321 if (!found_namespace_decl)
1322 continue;
1323
1324 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
1325
1326 if (log)
1327 log->Printf(" CMN[%u] Found namespace %s in module %s",
1328 current_id,
1329 name.GetCString(),
1330 module_sp->GetFileSpec().GetFilename().GetCString());
1331 }
1332 }
1333 else
1334 {
1335 ModuleList &images = m_target->GetImages();
1336 ClangNamespaceDecl null_namespace_decl;
1337
1338 for (uint32_t i = 0, e = images.GetSize();
1339 i != e;
1340 ++i)
1341 {
1342 lldb::ModuleSP image = images.GetModuleAtIndex(i);
1343
1344 if (!image)
1345 continue;
1346
1347 ClangNamespaceDecl found_namespace_decl;
1348
1349 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
1350
1351 if (!symbol_vendor)
1352 continue;
1353
1354 SymbolContext null_sc;
1355
1356 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
1357
1358 if (!found_namespace_decl)
1359 continue;
1360
1361 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
1362
1363 if (log)
1364 log->Printf(" CMN[%u] Found namespace %s in module %s",
1365 current_id,
1366 name.GetCString(),
1367 image->GetFileSpec().GetFilename().GetCString());
1368 }
1369 }
1370}
1371
Sean Callananbb715f92011-10-29 02:28:18 +00001372NamespaceDecl *
1373ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
1374{
Greg Clayton13d24fb2012-01-29 20:56:30 +00001375 if (!namespace_decls)
Sean Callananbb715f92011-10-29 02:28:18 +00001376 return NULL;
1377
1378 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1379
1380 const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
1381
Sean Callanan4938bd62011-11-16 18:20:47 +00001382 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl());
Sean Callananbb715f92011-10-29 02:28:18 +00001383
Sean Callananddb59332012-03-20 21:11:12 +00001384 if (!copied_decl)
1385 return NULL;
1386
Sean Callananbb715f92011-10-29 02:28:18 +00001387 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
1388
1389 m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
1390
1391 return dyn_cast<NamespaceDecl>(copied_decl);
1392}
1393
Sean Callanan9394b5a2011-10-29 19:50:43 +00001394void *
1395ClangASTSource::GuardedCopyType (ASTContext *dest_context,
1396 ASTContext *source_context,
1397 void *clang_type)
1398{
1399 SetImportInProgress(true);
1400
Sean Callanan4938bd62011-11-16 18:20:47 +00001401 QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type));
Sean Callanan9394b5a2011-10-29 19:50:43 +00001402
1403 void *ret = ret_qual_type.getAsOpaquePtr();
1404
1405 SetImportInProgress(false);
1406
Sean Callananddb59332012-03-20 21:11:12 +00001407 if (ret && ret_qual_type->getCanonicalTypeInternal().isNull())
Sean Callananaa11af82012-02-27 19:22:39 +00001408 // this shouldn't happen, but we're hardening because the AST importer seems to be generating bad types
1409 // on occasion.
1410 return NULL;
1411
Sean Callanan9394b5a2011-10-29 19:50:43 +00001412 return ret;
1413}
1414
Greg Claytonb01000f2011-01-17 03:46:26 +00001415clang::NamedDecl *
1416NameSearchContext::AddVarDecl(void *type)
1417{
Greg Clayton8de27c72010-10-15 22:48:33 +00001418 IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
Sean Callanan1ddd9fe2010-11-30 00:27:43 +00001419
1420 assert (type && "Type for variable must be non-NULL!");
Sean Callanancc074622010-09-14 21:59:34 +00001421
Sean Callananf76afff2011-10-28 23:38:38 +00001422 clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +00001423 const_cast<DeclContext*>(m_decl_context),
Chris Lattner24943d22010-06-08 16:52:24 +00001424 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +00001425 SourceLocation(),
Sean Callanancc074622010-09-14 21:59:34 +00001426 ii,
Chris Lattner24943d22010-06-08 16:52:24 +00001427 QualType::getFromOpaquePtr(type),
1428 0,
Sean Callanan47a5c4c2010-09-23 03:01:22 +00001429 SC_Static,
1430 SC_Static);
Greg Clayton8de27c72010-10-15 22:48:33 +00001431 m_decls.push_back(Decl);
Chris Lattner24943d22010-06-08 16:52:24 +00001432
1433 return Decl;
1434}
Sean Callanan8f0dc342010-06-22 23:46:24 +00001435
Greg Claytonb01000f2011-01-17 03:46:26 +00001436clang::NamedDecl *
1437NameSearchContext::AddFunDecl (void *type)
1438{
Sean Callanan30a5dd52012-03-21 17:13:20 +00001439 assert (type && "Type for variable must be non-NULL!");
1440
Sean Callananf76afff2011-10-28 23:38:38 +00001441 clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +00001442 const_cast<DeclContext*>(m_decl_context),
1443 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +00001444 SourceLocation(),
Greg Clayton8de27c72010-10-15 22:48:33 +00001445 m_decl_name.getAsIdentifierInfo(),
1446 QualType::getFromOpaquePtr(type),
1447 NULL,
1448 SC_Static,
1449 SC_Static,
1450 false,
1451 true);
Sean Callanan8f0dc342010-06-22 23:46:24 +00001452
Sean Callananb291abe2010-08-12 23:45:38 +00001453 // We have to do more than just synthesize the FunctionDecl. We have to
1454 // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
1455 // this, we raid the function's FunctionProtoType for types.
1456
Greg Clayton8de27c72010-10-15 22:48:33 +00001457 QualType qual_type (QualType::getFromOpaquePtr(type));
Sean Callanan21f2e192011-12-14 01:13:04 +00001458 const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>();
Sean Callanan8f0dc342010-06-22 23:46:24 +00001459
Greg Clayton8de27c72010-10-15 22:48:33 +00001460 if (func_proto_type)
Sean Callanan3c821cc2010-06-23 18:58:10 +00001461 {
Greg Clayton8de27c72010-10-15 22:48:33 +00001462 unsigned NumArgs = func_proto_type->getNumArgs();
Sean Callanan8f0dc342010-06-22 23:46:24 +00001463 unsigned ArgIndex;
1464
Sean Callananc1535182011-10-07 23:18:13 +00001465 SmallVector<ParmVarDecl *, 5> parm_var_decls;
1466
Sean Callanan8f0dc342010-06-22 23:46:24 +00001467 for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
1468 {
Greg Clayton8de27c72010-10-15 22:48:33 +00001469 QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001470
Sean Callananf76afff2011-10-28 23:38:38 +00001471 parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context,
Sean Callananc1535182011-10-07 23:18:13 +00001472 const_cast<DeclContext*>(m_decl_context),
1473 SourceLocation(),
1474 SourceLocation(),
1475 NULL,
1476 arg_qual_type,
1477 NULL,
1478 SC_Static,
1479 SC_Static,
1480 NULL));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001481 }
1482
Sean Callananc1535182011-10-07 23:18:13 +00001483 func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001484 }
Sean Callanandc5fce12011-12-01 21:04:37 +00001485 else
1486 {
1487 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1488
1489 log->Printf("Function type wasn't a FunctionProtoType");
1490 }
Sean Callanan8f0dc342010-06-22 23:46:24 +00001491
Greg Clayton8de27c72010-10-15 22:48:33 +00001492 m_decls.push_back(func_decl);
Sean Callanan8f0dc342010-06-22 23:46:24 +00001493
Greg Clayton8de27c72010-10-15 22:48:33 +00001494 return func_decl;
Sean Callanan8f0dc342010-06-22 23:46:24 +00001495}
Sean Callanan0fc73582010-07-27 00:55:47 +00001496
Greg Claytonb01000f2011-01-17 03:46:26 +00001497clang::NamedDecl *
1498NameSearchContext::AddGenericFunDecl()
Sean Callanan0fc73582010-07-27 00:55:47 +00001499{
Sean Callananad293092011-01-18 23:32:05 +00001500 FunctionProtoType::ExtProtoInfo proto_info;
1501
1502 proto_info.Variadic = true;
1503
Sean Callananf76afff2011-10-28 23:38:38 +00001504 QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result
1505 NULL, // argument types
1506 0, // number of arguments
1507 proto_info));
Greg Clayton8de27c72010-10-15 22:48:33 +00001508
Sean Callanan0fc73582010-07-27 00:55:47 +00001509 return AddFunDecl(generic_function_type.getAsOpaquePtr());
1510}
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001511
Greg Claytonb01000f2011-01-17 03:46:26 +00001512clang::NamedDecl *
1513NameSearchContext::AddTypeDecl(void *type)
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001514{
Greg Claytona1aaaff2011-01-23 00:34:52 +00001515 if (type)
1516 {
1517 QualType qual_type = QualType::getFromOpaquePtr(type);
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001518
Sean Callanan21f2e192011-12-14 01:13:04 +00001519 if (const TagType *tag_type = qual_type->getAs<TagType>())
Greg Claytona1aaaff2011-01-23 00:34:52 +00001520 {
1521 TagDecl *tag_decl = tag_type->getDecl();
1522
1523 m_decls.push_back(tag_decl);
1524
1525 return tag_decl;
1526 }
Sean Callanan21f2e192011-12-14 01:13:04 +00001527 else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>())
Greg Claytona1aaaff2011-01-23 00:34:52 +00001528 {
1529 ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
1530
1531 m_decls.push_back((NamedDecl*)interface_decl);
1532
1533 return (NamedDecl*)interface_decl;
1534 }
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001535 }
Greg Claytona1aaaff2011-01-23 00:34:52 +00001536 return NULL;
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001537}
Greg Claytone6d72ca2011-06-25 00:44:06 +00001538
1539void
1540NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result)
1541{
1542 for (clang::NamedDecl * const *decl_iterator = result.first;
1543 decl_iterator != result.second;
1544 ++decl_iterator)
1545 m_decls.push_back (*decl_iterator);
1546}
1547
1548void
1549NameSearchContext::AddNamedDecl (clang::NamedDecl *decl)
1550{
1551 m_decls.push_back (decl);
1552}