blob: 4c31c223b89c7850229a4eb7399fb99909c149a6 [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:
Sean Callanan0ffff1e2012-04-25 17:46:01 +000079 {
80 clang::IdentifierInfo *identifier_info = clang_decl_name.getAsIdentifierInfo();
81
82 if (!identifier_info ||
83 identifier_info->getBuiltinID() != 0)
84 {
85 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
86 }
87 }
Greg Clayton8de27c72010-10-15 22:48:33 +000088 break;
Chris Lattner24943d22010-06-08 16:52:24 +000089
90 // Operator names. Not important for now.
91 case DeclarationName::CXXOperatorName:
92 case DeclarationName::CXXLiteralOperatorName:
93 return DeclContext::lookup_result();
94
95 // Using directives found in this context.
96 // Tell Sema we didn't find any or we'll end up getting asked a *lot*.
97 case DeclarationName::CXXUsingDirective:
Greg Clayton8de27c72010-10-15 22:48:33 +000098 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
Chris Lattner24943d22010-06-08 16:52:24 +000099
Chris Lattner24943d22010-06-08 16:52:24 +0000100 case DeclarationName::ObjCZeroArgSelector:
101 case DeclarationName::ObjCOneArgSelector:
102 case DeclarationName::ObjCMultiArgSelector:
Sean Callanan9b714842011-11-09 19:33:21 +0000103 {
104 llvm::SmallVector<NamedDecl*, 1> method_decls;
Chris Lattner24943d22010-06-08 16:52:24 +0000105
Sean Callanan9b714842011-11-09 19:33:21 +0000106 NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx);
107
108 FindObjCMethodDecls(method_search_context);
109
110 return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls);
111 }
Chris Lattner24943d22010-06-08 16:52:24 +0000112 // These aren't possible in the global context.
113 case DeclarationName::CXXConstructorName:
114 case DeclarationName::CXXDestructorName:
115 case DeclarationName::CXXConversionFunctionName:
116 return DeclContext::lookup_result();
117 }
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000118
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000119
Sean Callananf76afff2011-10-28 23:38:38 +0000120 if (!GetLookupsEnabled())
Greg Clayton8de27c72010-10-15 22:48:33 +0000121 {
122 // Wait until we see a '$' at the start of a name before we start doing
123 // any lookups so we can avoid lookup up all of the builtin types.
124 if (!decl_name.empty() && decl_name[0] == '$')
125 {
Sean Callananf76afff2011-10-28 23:38:38 +0000126 SetLookupsEnabled (true);
Greg Clayton8de27c72010-10-15 22:48:33 +0000127 }
128 else
129 {
130 return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name);
131 }
Greg Claytonf4c7ae02010-10-15 03:36:13 +0000132 }
Greg Clayton8de27c72010-10-15 22:48:33 +0000133
Greg Clayton8de27c72010-10-15 22:48:33 +0000134 ConstString const_decl_name(decl_name.c_str());
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000135
136 const char *uniqued_const_decl_name = const_decl_name.GetCString();
137 if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end())
138 {
139 // We are currently looking up this name...
140 return DeclContext::lookup_result();
141 }
142 m_active_lookups.insert(uniqued_const_decl_name);
Greg Claytona8b278a2010-11-15 01:34:18 +0000143// static uint32_t g_depth = 0;
144// ++g_depth;
145// printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name);
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000146 llvm::SmallVector<NamedDecl*, 4> name_decls;
147 NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx);
Sean Callananf76afff2011-10-28 23:38:38 +0000148 FindExternalVisibleDecls(name_search_context);
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000149 DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls));
Greg Claytona8b278a2010-11-15 01:34:18 +0000150// --g_depth;
Greg Clayton9ceed1e2010-11-13 04:18:24 +0000151 m_active_lookups.erase (uniqued_const_decl_name);
152 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000153}
154
Greg Claytonb01000f2011-01-17 03:46:26 +0000155void
156ClangASTSource::CompleteType (TagDecl *tag_decl)
Sean Callananbb715f92011-10-29 02:28:18 +0000157{
158 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
159
Sean Callananb2027ec2011-12-08 23:45:45 +0000160 static unsigned int invocation_id = 0;
161 unsigned int current_id = invocation_id++;
162
Sean Callananbb715f92011-10-29 02:28:18 +0000163 if (log)
164 {
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000165 log->Printf(" CompleteTagDecl[%u] on (ASTContext*)%p Completing (TagDecl*)%p named %s",
166 current_id,
Sean Callananb2027ec2011-12-08 23:45:45 +0000167 m_ast_context,
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000168 tag_decl,
Sean Callananb2027ec2011-12-08 23:45:45 +0000169 tag_decl->getName().str().c_str());
170
171 log->Printf(" CTD[%u] Before:", current_id);
Sean Callananbb715f92011-10-29 02:28:18 +0000172 ASTDumper dumper((Decl*)tag_decl);
173 dumper.ToLog(log, " [CTD] ");
174 }
175
Sean Callananb2027ec2011-12-08 23:45:45 +0000176 if (!m_ast_importer->CompleteTagDecl (tag_decl))
177 {
178 // We couldn't complete the type. Maybe there's a definition
179 // somewhere else that can be completed.
180
181 if (log)
182 log->Printf(" CTD[%u] Type could not be completed in the module in which it was first found.", current_id);
183
184 bool found = false;
185
186 DeclContext *decl_ctx = tag_decl->getDeclContext();
187
188 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(decl_ctx))
189 {
190 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
191
192 if (log && log->GetVerbose())
193 log->Printf(" CTD[%u] Inspecting namespace map %p (%d entries)",
194 current_id,
195 namespace_map.get(),
196 (int)namespace_map->size());
197
198 if (!namespace_map)
199 return;
200
201 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
202 i != e && !found;
203 ++i)
204 {
205 if (log)
206 log->Printf(" CTD[%u] Searching namespace %s in module %s",
207 current_id,
208 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
209 i->first->GetFileSpec().GetFilename().GetCString());
210
211 TypeList types;
212
213 SymbolContext null_sc;
214 ConstString name(tag_decl->getName().str().c_str());
215
Greg Claytondc0a38c2012-03-26 23:03:23 +0000216 i->first->FindTypesInNamespace(null_sc, name, &i->second, UINT32_MAX, types);
Sean Callananb2027ec2011-12-08 23:45:45 +0000217
218 for (uint32_t ti = 0, te = types.GetSize();
219 ti != te && !found;
220 ++ti)
221 {
222 lldb::TypeSP type = types.GetTypeAtIndex(ti);
223
224 if (!type)
225 continue;
226
227 lldb::clang_type_t opaque_type = type->GetClangFullType();
228
229 if (!opaque_type)
230 continue;
231
Sean Callanan21f2e192011-12-14 01:13:04 +0000232 const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>();
Sean Callananb2027ec2011-12-08 23:45:45 +0000233
234 if (!tag_type)
235 continue;
236
237 TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
238
239 if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
240 found = true;
241 }
242 }
243 }
244 else
245 {
246 TypeList types;
247
248 SymbolContext null_sc;
249 ConstString name(tag_decl->getName().str().c_str());
250 ClangNamespaceDecl namespace_decl;
251
252 ModuleList &module_list = m_target->GetImages();
253
Greg Claytondc0a38c2012-03-26 23:03:23 +0000254 bool exact_match = false;
Greg Clayton9f95fb62012-04-06 17:41:13 +0000255 module_list.FindTypes (null_sc, name, exact_match, UINT32_MAX, types);
Sean Callananb2027ec2011-12-08 23:45:45 +0000256
257 for (uint32_t ti = 0, te = types.GetSize();
258 ti != te && !found;
259 ++ti)
260 {
261 lldb::TypeSP type = types.GetTypeAtIndex(ti);
262
263 if (!type)
264 continue;
265
266 lldb::clang_type_t opaque_type = type->GetClangFullType();
267
268 if (!opaque_type)
269 continue;
270
Sean Callanan21f2e192011-12-14 01:13:04 +0000271 const TagType *tag_type = QualType::getFromOpaquePtr(opaque_type)->getAs<TagType>();
Sean Callananb2027ec2011-12-08 23:45:45 +0000272
273 if (!tag_type)
274 continue;
275
276 TagDecl *candidate_tag_decl = const_cast<TagDecl*>(tag_type->getDecl());
277
278 if (m_ast_importer->CompleteTagDeclWithOrigin (tag_decl, candidate_tag_decl))
279 found = true;
280 }
281 }
282 }
Sean Callananbb715f92011-10-29 02:28:18 +0000283
284 if (log)
285 {
286 log->Printf(" [CTD] After:");
287 ASTDumper dumper((Decl*)tag_decl);
288 dumper.ToLog(log, " [CTD] ");
289 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000290}
291
292void
Sean Callananbb715f92011-10-29 02:28:18 +0000293ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl)
294{
295 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
296
297 if (log)
298 {
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000299 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 +0000300 log->Printf(" [COID] Before:");
301 ASTDumper dumper((Decl*)interface_decl);
302 dumper.ToLog(log, " [COID] ");
303 }
304
305 m_ast_importer->CompleteObjCInterfaceDecl (interface_decl);
306
307 if (log)
308 {
309 log->Printf(" [COID] After:");
310 ASTDumper dumper((Decl*)interface_decl);
311 dumper.ToLog(log, " [COID] ");
312 }
Greg Claytonb01000f2011-01-17 03:46:26 +0000313}
314
Sean Callanan9b6898f2011-07-30 02:42:06 +0000315clang::ExternalLoadResult
Sean Callananbb715f92011-10-29 02:28:18 +0000316ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context,
317 bool (*predicate)(Decl::Kind),
318 llvm::SmallVectorImpl<Decl*> &decls)
319{
320 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
321
322 const Decl *context_decl = dyn_cast<Decl>(decl_context);
323
324 if (!context_decl)
325 return ELR_Failure;
326
327 static unsigned int invocation_id = 0;
328 unsigned int current_id = invocation_id++;
329
330 if (log)
331 {
332 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000333 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in '%s' (%sDecl*)%p with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000334 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000335 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000336 context_named_decl->getNameAsString().c_str(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000337 context_decl->getDeclKindName(),
338 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000339 (predicate ? "non-null" : "null"));
340 else if(context_decl)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000341 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in (%sDecl*)%p 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 context_decl->getDeclKindName(),
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000345 context_decl,
Sean Callananbb715f92011-10-29 02:28:18 +0000346 (predicate ? "non-null" : "null"));
347 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000348 log->Printf("FindExternalLexicalDecls[%u] on (ASTContext*)%p in a NULL context with %s predicate",
Sean Callananbb715f92011-10-29 02:28:18 +0000349 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000350 m_ast_context,
Sean Callananbb715f92011-10-29 02:28:18 +0000351 (predicate ? "non-null" : "null"));
352 }
353
354 Decl *original_decl = NULL;
355 ASTContext *original_ctx = NULL;
356
357 if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
358 return ELR_Failure;
359
360 if (log)
361 {
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000362 log->Printf(" FELD[%u] Original decl (Decl*)%p:", current_id, original_decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000363 ASTDumper(original_decl).ToLog(log, " ");
364 }
365
366 if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl))
367 {
368 ExternalASTSource *external_source = original_ctx->getExternalSource();
369
370 if (external_source)
371 external_source->CompleteType (original_tag_decl);
372 }
373
Sean Callananb2027ec2011-12-08 23:45:45 +0000374 const DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000375
376 if (!original_decl_context)
377 return ELR_Failure;
378
379 for (TagDecl::decl_iterator iter = original_decl_context->decls_begin();
380 iter != original_decl_context->decls_end();
381 ++iter)
382 {
383 Decl *decl = *iter;
384
385 if (!predicate || predicate(decl->getKind()))
386 {
387 if (log)
388 {
389 ASTDumper ast_dumper(decl);
390 if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl))
391 log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString());
392 else
393 log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString());
394 }
395
Sean Callanan4938bd62011-11-16 18:20:47 +0000396 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, original_ctx, decl);
Sean Callananbb715f92011-10-29 02:28:18 +0000397
Sean Callananddb59332012-03-20 21:11:12 +0000398 if (!copied_decl)
399 continue;
400
Sean Callanane9478392012-03-15 01:53:17 +0000401 if (FieldDecl *copied_field = dyn_cast<FieldDecl>(copied_decl))
402 {
403 QualType copied_field_type = copied_field->getType();
404
405 if (const TagType *copied_field_tag_type = copied_field_type->getAs<TagType>())
406 m_ast_importer->CompleteTagDecl(copied_field_tag_type->getDecl());
407 if (const ObjCObjectType *copied_field_object_type = copied_field_type->getAs<ObjCObjectType>())
408 if (ObjCInterfaceDecl *copied_field_objc_interface_decl = copied_field_object_type->getInterface())
409 m_ast_importer->CompleteObjCInterfaceDecl(copied_field_objc_interface_decl);
410 }
411
Sean Callananbb715f92011-10-29 02:28:18 +0000412 decls.push_back(copied_decl);
413 }
414 }
415
416 return ELR_AlreadyLoaded;
Chris Lattner24943d22010-06-08 16:52:24 +0000417}
418
Sean Callanan9394b5a2011-10-29 19:50:43 +0000419void
420ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context)
421{
422 assert (m_ast_context);
423
424 const ConstString name(context.m_decl_name.getAsString().c_str());
425
426 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
427
428 static unsigned int invocation_id = 0;
429 unsigned int current_id = invocation_id++;
430
431 if (log)
432 {
433 if (!context.m_decl_context)
Sean Callanan6e22e8b2012-01-13 22:05:55 +0000434 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 +0000435 else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context))
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000436 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 +0000437 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000438 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 +0000439 }
440
441 context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap);
442
443 if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
444 {
445 ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
446
447 if (log && log->GetVerbose())
448 log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)",
449 current_id,
450 namespace_map.get(),
451 (int)namespace_map->size());
452
453 if (!namespace_map)
454 return;
455
456 for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
457 i != e;
458 ++i)
459 {
460 if (log)
461 log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s",
462 current_id,
463 i->second.GetNamespaceDecl()->getNameAsString().c_str(),
464 i->first->GetFileSpec().GetFilename().GetCString());
465
466 FindExternalVisibleDecls(context,
467 i->first,
468 i->second,
469 current_id);
470 }
471 }
Sean Callanand3812fa2011-11-15 21:50:18 +0000472 else if (isa<ObjCInterfaceDecl>(context.m_decl_context))
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000473 {
Sean Callanan8f2e3922012-02-04 08:49:35 +0000474 FindObjCPropertyAndIvarDecls(context);
Sean Callanane6ea5fe2011-11-15 02:11:17 +0000475 }
Sean Callanan9394b5a2011-10-29 19:50:43 +0000476 else if (!isa<TranslationUnitDecl>(context.m_decl_context))
477 {
478 // we shouldn't be getting FindExternalVisibleDecls calls for these
479 return;
480 }
481 else
482 {
483 ClangNamespaceDecl namespace_decl;
484
485 if (log)
486 log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id);
487
488 FindExternalVisibleDecls(context,
489 lldb::ModuleSP(),
490 namespace_decl,
491 current_id);
492 }
493
494 if (!context.m_namespace_map->empty())
495 {
496 if (log && log->GetVerbose())
497 log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)",
498 current_id,
499 context.m_namespace_map.get(),
500 (int)context.m_namespace_map->size());
501
502 NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map);
503
504 if (clang_namespace_decl)
505 clang_namespace_decl->setHasExternalVisibleStorage();
506 }
507}
508
509void
510ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context,
511 lldb::ModuleSP module_sp,
512 ClangNamespaceDecl &namespace_decl,
513 unsigned int current_id)
514{
515 assert (m_ast_context);
516
517 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
518
519 SymbolContextList sc_list;
520
521 const ConstString name(context.m_decl_name.getAsString().c_str());
522
523 const char *name_unique_cstr = name.GetCString();
524
Sean Callanan8f2e3922012-02-04 08:49:35 +0000525 static ConstString id_name("id");
526 static ConstString Class_name("Class");
527
528 if (name == id_name || name == Class_name)
529 return;
530
Sean Callanan9394b5a2011-10-29 19:50:43 +0000531 if (name_unique_cstr == NULL)
532 return;
533
534 // The ClangASTSource is not responsible for finding $-names.
535 if (name_unique_cstr[0] == '$')
536 return;
537
538 if (module_sp && namespace_decl)
539 {
540 ClangNamespaceDecl found_namespace_decl;
541
542 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
543
544 if (symbol_vendor)
545 {
546 SymbolContext null_sc;
547
548 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
549
550 if (found_namespace_decl)
551 {
552 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
553
554 if (log)
555 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
556 current_id,
557 name.GetCString(),
558 module_sp->GetFileSpec().GetFilename().GetCString());
559 }
560 }
561 }
562 else
563 {
564 ModuleList &images = m_target->GetImages();
565
566 for (uint32_t i = 0, e = images.GetSize();
567 i != e;
568 ++i)
569 {
570 lldb::ModuleSP image = images.GetModuleAtIndex(i);
571
572 if (!image)
573 continue;
574
575 ClangNamespaceDecl found_namespace_decl;
576
577 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
578
579 if (!symbol_vendor)
580 continue;
581
582 SymbolContext null_sc;
583
584 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl);
585
586 if (found_namespace_decl)
587 {
588 context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
589
590 if (log)
591 log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s",
592 current_id,
593 name.GetCString(),
594 image->GetFileSpec().GetFilename().GetCString());
595 }
596 }
597 }
598
Sean Callanan9394b5a2011-10-29 19:50:43 +0000599 do
600 {
601 TypeList types;
602 SymbolContext null_sc;
Greg Claytondc0a38c2012-03-26 23:03:23 +0000603 const bool exact_match = false;
Sean Callanan0f71d192011-12-19 19:38:39 +0000604
Sean Callanan9394b5a2011-10-29 19:50:43 +0000605 if (module_sp && namespace_decl)
Greg Claytondc0a38c2012-03-26 23:03:23 +0000606 module_sp->FindTypesInNamespace(null_sc, name, &namespace_decl, 1, types);
Sean Callanan0f71d192011-12-19 19:38:39 +0000607 else
Greg Clayton9f95fb62012-04-06 17:41:13 +0000608 m_target->GetImages().FindTypes(null_sc, name, exact_match, 1, types);
Sean Callanan9394b5a2011-10-29 19:50:43 +0000609
610 if (types.GetSize())
611 {
612 lldb::TypeSP type_sp = types.GetTypeAtIndex(0);
613
614 if (log)
615 {
616 const char *name_string = type_sp->GetName().GetCString();
617
618 log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s",
619 current_id,
620 name.GetCString(),
621 (name_string ? name_string : "<anonymous>"));
622 }
623
Sean Callanane1301a62011-12-06 03:41:14 +0000624
Sean Callanan9394b5a2011-10-29 19:50:43 +0000625 void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType());
Sean Callanane1301a62011-12-06 03:41:14 +0000626
Sean Callanandc5fce12011-12-01 21:04:37 +0000627 if (!copied_type)
628 {
629 if (log)
Sean Callanane1301a62011-12-06 03:41:14 +0000630 log->Printf(" CAS::FEVD[%u] - Couldn't export the type for a constant integer result",
631 current_id);
632
Sean Callanandc5fce12011-12-01 21:04:37 +0000633 break;
634 }
635
Sean Callanan9394b5a2011-10-29 19:50:43 +0000636 context.AddTypeDecl(copied_type);
637 }
Sean Callanan673f3db2011-11-30 22:11:59 +0000638
Sean Callanan9394b5a2011-10-29 19:50:43 +0000639 } while(0);
640}
641
Sean Callanan9b714842011-11-09 19:33:21 +0000642void
643ClangASTSource::FindObjCMethodDecls (NameSearchContext &context)
644{
645 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
646
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000647 static unsigned int invocation_id = 0;
648 unsigned int current_id = invocation_id++;
649
Sean Callanan9b714842011-11-09 19:33:21 +0000650 const DeclarationName &decl_name(context.m_decl_name);
651 const DeclContext *decl_ctx(context.m_decl_context);
652
653 const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx);
654
655 if (!interface_decl)
656 return;
657
Sean Callanan8d611562012-04-05 00:12:52 +0000658 do
659 {
660 Decl *original_decl = NULL;
661 ASTContext *original_ctx = NULL;
662
663 m_ast_importer->ResolveDeclOrigin(interface_decl, &original_decl, &original_ctx);
664
665 if (!original_decl)
666 break;
667
668 ObjCInterfaceDecl *original_interface_decl = dyn_cast<ObjCInterfaceDecl>(original_decl);
669
670 Selector original_selector;
671
672 if (decl_name.isObjCZeroArgSelector())
673 {
674 IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString());
675 original_selector = original_ctx->Selectors.getSelector(0, &ident);
676 }
677 else if (decl_name.isObjCOneArgSelector())
678 {
679 const std::string &decl_name_string = decl_name.getAsString();
680 std::string decl_name_string_without_colon(decl_name_string.c_str(), decl_name_string.length() - 1);
681 IdentifierInfo *ident = &original_ctx->Idents.get(decl_name_string_without_colon.c_str());
682 original_selector = original_ctx->Selectors.getSelector(1, &ident);
683 }
684 else
685 {
686 SmallVector<IdentifierInfo *, 4> idents;
687
688 clang::Selector sel = decl_name.getObjCSelector();
689
690 int num_args = sel.getNumArgs();
691
692 for (unsigned i = 0;
693 i != num_args;
694 ++i)
695 {
696 idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i)));
697 }
698
699 original_selector = original_ctx->Selectors.getSelector(num_args, idents.data());
700 }
701
702 DeclarationName original_decl_name(original_selector);
703
704 ObjCInterfaceDecl::lookup_result result = original_interface_decl->lookup(original_decl_name);
705
706 if (result.first == result.second)
707 break;
708
709 if (!*result.first)
710 break;
711
712 ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(*result.first);
713
714 if (!result_method)
715 break;
716
717 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &result_method->getASTContext(), result_method);
718
719 if (!copied_decl)
720 continue;
721
722 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
723
724 if (!copied_method_decl)
725 continue;
726
727 if (log)
728 {
729 ASTDumper dumper((Decl*)copied_method_decl);
730 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
731 }
732
733 context.AddNamedDecl(copied_method_decl);
734
735 return;
736 } while (0);
737
Sean Callanan9b714842011-11-09 19:33:21 +0000738 StreamString ss;
Sean Callanane1301a62011-12-06 03:41:14 +0000739
Sean Callanan9b714842011-11-09 19:33:21 +0000740 if (decl_name.isObjCZeroArgSelector())
741 {
742 ss.Printf("%s", decl_name.getAsString().c_str());
743 }
744 else if (decl_name.isObjCOneArgSelector())
745 {
Sean Callanan1d9ffe22011-11-14 18:29:46 +0000746 ss.Printf("%s", decl_name.getAsString().c_str());
Sean Callanan9b714842011-11-09 19:33:21 +0000747 }
748 else
749 {
750 clang::Selector sel = decl_name.getObjCSelector();
751
752 for (unsigned i = 0, e = sel.getNumArgs();
753 i != e;
754 ++i)
755 {
756 llvm::StringRef r = sel.getNameForSlot(i);
757 ss.Printf("%s:", r.str().c_str());
758 }
759 }
760 ss.Flush();
761
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000762 ConstString selector_name(ss.GetData());
763
Sean Callanan9b714842011-11-09 19:33:21 +0000764 if (log)
Sean Callanan5a55c7a2011-11-18 03:28:09 +0000765 log->Printf("ClangASTSource::FindObjCMethodDecls[%d] on (ASTContext*)%p for selector [%s %s]",
766 current_id,
767 m_ast_context,
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000768 interface_decl->getNameAsString().c_str(),
769 selector_name.AsCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000770 SymbolContextList sc_list;
771
772 const bool include_symbols = false;
Sean Callanan302d78c2012-02-10 22:52:19 +0000773 const bool include_inlines = false;
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000774 const bool append = false;
775
Sean Callanane0028b82012-01-19 02:17:40 +0000776 std::string interface_name = interface_decl->getNameAsString();
777
778 do
779 {
780 StreamString ms;
781 ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString());
782 ms.Flush();
783 ConstString instance_method_name(ms.GetData());
784
Sean Callanan302d78c2012-02-10 22:52:19 +0000785 m_target->GetImages().FindFunctions(instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list);
Sean Callanane0028b82012-01-19 02:17:40 +0000786
787 if (sc_list.GetSize())
788 break;
789
790 ms.Clear();
791 ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString());
792 ms.Flush();
793 ConstString class_method_name(ms.GetData());
794
Sean Callanan302d78c2012-02-10 22:52:19 +0000795 m_target->GetImages().FindFunctions(class_method_name, lldb::eFunctionNameTypeFull, include_symbols, include_inlines, append, sc_list);
Sean Callanane0028b82012-01-19 02:17:40 +0000796
797 if (sc_list.GetSize())
798 break;
799
800 // Fall back and check for methods in categories. If we find methods this way, we need to check that they're actually in
801 // categories on the desired class.
802
803 SymbolContextList candidate_sc_list;
804
Sean Callanan302d78c2012-02-10 22:52:19 +0000805 m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, include_inlines, append, candidate_sc_list);
Sean Callanane0028b82012-01-19 02:17:40 +0000806
807 for (uint32_t ci = 0, ce = candidate_sc_list.GetSize();
808 ci != ce;
809 ++ci)
810 {
811 SymbolContext candidate_sc;
812
813 if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc))
814 continue;
815
816 if (!candidate_sc.function)
817 continue;
818
819 const char *candidate_name = candidate_sc.function->GetName().AsCString();
820
821 const char *cursor = candidate_name;
822
823 if (*cursor != '+' && *cursor != '-')
824 continue;
825
826 ++cursor;
827
828 if (*cursor != '[')
829 continue;
830
831 ++cursor;
832
833 size_t interface_len = interface_name.length();
834
835 if (strncmp(cursor, interface_name.c_str(), interface_len))
836 continue;
837
838 cursor += interface_len;
839
840 if (*cursor == ' ' || *cursor == '(')
841 sc_list.Append(candidate_sc);
842 }
843 }
844 while (0);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000845
846 for (uint32_t i = 0, e = sc_list.GetSize();
847 i != e;
848 ++i)
849 {
850 SymbolContext sc;
851
852 if (!sc_list.GetContextAtIndex(i, sc))
853 continue;
854
855 if (!sc.function)
856 continue;
857
858 DeclContext *function_ctx = sc.function->GetClangDeclContext();
859
860 if (!function_ctx)
861 continue;
862
863 ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx);
864
865 if (!method_decl)
866 continue;
867
868 ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface();
869
870 if (!found_interface_decl)
871 continue;
872
873 if (found_interface_decl->getName() == interface_decl->getName())
874 {
Sean Callanan4938bd62011-11-16 18:20:47 +0000875 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, &method_decl->getASTContext(), method_decl);
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000876
877 if (!copied_decl)
878 continue;
879
880 ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl);
881
882 if (!copied_method_decl)
883 continue;
884
885 if (log)
886 {
887 ASTDumper dumper((Decl*)copied_method_decl);
Sean Callanane1301a62011-12-06 03:41:14 +0000888 log->Printf(" CAS::FOMD[%d] found (in debug info) %s", current_id, dumper.GetCString());
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000889 }
Sean Callanane0028b82012-01-19 02:17:40 +0000890
Sean Callananf2a0a5c2011-11-11 20:37:26 +0000891 context.AddNamedDecl(copied_method_decl);
892 }
893 }
Sean Callanan9b714842011-11-09 19:33:21 +0000894}
895
Sean Callanan8f2e3922012-02-04 08:49:35 +0000896template <class D> class TaggedASTDecl {
897public:
898 TaggedASTDecl() : decl(NULL) { }
899 TaggedASTDecl(D *_decl) : decl(_decl) { }
900 bool IsValid() const { return (decl != NULL); }
901 bool IsInvalid() const { return !IsValid(); }
902 D *operator->() const { return decl; }
903 D *decl;
904};
905
906template <class D2, template <class D> class TD, class D1>
907TD<D2>
908DynCast(TD<D1> source)
909{
910 return TD<D2> (dyn_cast<D2>(source.decl));
911}
912
913template <class D = Decl> class DeclFromParser;
914template <class D = Decl> class DeclFromUser;
915
916template <class D> class DeclFromParser : public TaggedASTDecl<D> {
917public:
918 DeclFromParser() : TaggedASTDecl<D>() { }
919 DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) { }
920
921 DeclFromUser<D> GetOrigin(ClangASTImporter *importer);
922};
923
924template <class D> class DeclFromUser : public TaggedASTDecl<D> {
925public:
926 DeclFromUser() : TaggedASTDecl<D>() { }
927 DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) { }
928
929 DeclFromParser<D> Import(ClangASTImporter *importer, ASTContext &dest_ctx);
930};
931
932template <class D>
933DeclFromUser<D>
934DeclFromParser<D>::GetOrigin(ClangASTImporter *importer)
935{
936 DeclFromUser <> origin_decl;
937 importer->ResolveDeclOrigin(this->decl, &origin_decl.decl, NULL);
938 if (origin_decl.IsInvalid())
939 return DeclFromUser<D>();
940 return DeclFromUser<D>(dyn_cast<D>(origin_decl.decl));
941}
942
943template <class D>
944DeclFromParser<D>
945DeclFromUser<D>::Import(ClangASTImporter *importer, ASTContext &dest_ctx)
946{
947 DeclFromParser <> parser_generic_decl(importer->CopyDecl(&dest_ctx, &this->decl->getASTContext(), this->decl));
948 if (parser_generic_decl.IsInvalid())
949 return DeclFromParser<D>();
950 return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl));
951}
952
Sean Callanan931acec2012-02-22 23:57:45 +0000953static bool
954FindObjCPropertyAndIvarDeclsWithOrigin (unsigned int current_id,
955 NameSearchContext &context,
956 clang::ASTContext &ast_context,
957 ClangASTImporter *ast_importer,
958 DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl)
959{
960 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
961
962 if (origin_iface_decl.IsInvalid())
963 return false;
964
965 std::string name_str = context.m_decl_name.getAsString();
966 StringRef name(name_str.c_str());
967 IdentifierInfo &name_identifier(origin_iface_decl->getASTContext().Idents.get(name));
968
969 DeclFromUser<ObjCPropertyDecl> origin_property_decl(origin_iface_decl->FindPropertyDeclaration(&name_identifier));
970
971 bool found = false;
972
973 if (origin_property_decl.IsValid())
974 {
975 DeclFromParser<ObjCPropertyDecl> parser_property_decl(origin_property_decl.Import(ast_importer, ast_context));
976 if (parser_property_decl.IsValid())
977 {
978 if (log)
979 {
980 ASTDumper dumper((Decl*)parser_property_decl.decl);
981 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
982 }
983
984 context.AddNamedDecl(parser_property_decl.decl);
985 found = true;
986 }
987 }
988
989 DeclFromUser<ObjCIvarDecl> origin_ivar_decl(origin_iface_decl->getIvarDecl(&name_identifier));
990
991 if (origin_ivar_decl.IsValid())
992 {
993 DeclFromParser<ObjCIvarDecl> parser_ivar_decl(origin_ivar_decl.Import(ast_importer, ast_context));
994 if (parser_ivar_decl.IsValid())
995 {
996 if (log)
997 {
998 ASTDumper dumper((Decl*)parser_ivar_decl.decl);
999 log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString());
1000 }
1001
1002 context.AddNamedDecl(parser_ivar_decl.decl);
1003 found = true;
1004 }
1005 }
1006
1007 return found;
1008}
1009
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001010void
Sean Callanan8f2e3922012-02-04 08:49:35 +00001011ClangASTSource::FindObjCPropertyAndIvarDecls (NameSearchContext &context)
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001012{
1013 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1014
1015 static unsigned int invocation_id = 0;
1016 unsigned int current_id = invocation_id++;
1017
Sean Callanan8f2e3922012-02-04 08:49:35 +00001018 DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl(cast<ObjCInterfaceDecl>(context.m_decl_context));
1019 DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl(parser_iface_decl.GetOrigin(m_ast_importer));
Sean Callanan931acec2012-02-22 23:57:45 +00001020
1021 ConstString class_name(parser_iface_decl->getNameAsString().c_str());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001022
1023 if (log)
Sean Callanan8f2e3922012-02-04 08:49:35 +00001024 log->Printf("ClangASTSource::FindObjCPropertyAndIvarDecls[%d] on (ASTContext*)%p for '%s.%s'",
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001025 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001026 m_ast_context,
Sean Callanan8f2e3922012-02-04 08:49:35 +00001027 parser_iface_decl->getNameAsString().c_str(),
Sean Callanan931acec2012-02-22 23:57:45 +00001028 context.m_decl_name.getAsString().c_str());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001029
Sean Callanan931acec2012-02-22 23:57:45 +00001030 if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
1031 context,
1032 *m_ast_context,
1033 m_ast_importer,
1034 origin_iface_decl))
1035 return;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001036
Sean Callanan931acec2012-02-22 23:57:45 +00001037 if (log)
1038 log->Printf("CAS::FOPD[%d] couldn't find the property on origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p, searching elsewhere...",
1039 current_id,
1040 origin_iface_decl.decl,
1041 &origin_iface_decl->getASTContext());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001042
Sean Callanan931acec2012-02-22 23:57:45 +00001043 SymbolContext null_sc;
1044 TypeList type_list;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001045
Sean Callanan931acec2012-02-22 23:57:45 +00001046 lldb::ProcessSP process(m_target->GetProcessSP());
1047
1048 if (!process)
1049 return;
1050
1051 ObjCLanguageRuntime *language_runtime(process->GetObjCLanguageRuntime());
1052
1053 if (!language_runtime)
1054 return;
1055
1056 lldb::TypeSP complete_type_sp(language_runtime->LookupInCompleteClassCache(class_name));
1057
1058 if (!complete_type_sp)
1059 return;
1060
1061 TypeFromUser complete_type = TypeFromUser(complete_type_sp->GetClangFullType(), complete_type_sp->GetClangAST());
1062 lldb::clang_type_t complete_opaque_type = complete_type.GetOpaqueQualType();
1063
1064 if (!complete_opaque_type)
1065 return;
1066
1067 const clang::Type *complete_clang_type = QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr();
1068 const ObjCInterfaceType *complete_interface_type = dyn_cast<ObjCInterfaceType>(complete_clang_type);
1069
1070 if (!complete_interface_type)
1071 return;
1072
1073 DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl(complete_interface_type->getDecl());
1074
1075 if (complete_iface_decl.decl == origin_iface_decl.decl)
1076 return; // already checked this one
1077
1078 if (log)
1079 log->Printf("CAS::FOPD[%d] trying origin (ObjCInterfaceDecl*)%p/(ASTContext*)%p...",
1080 current_id,
1081 complete_iface_decl.decl,
1082 &complete_iface_decl->getASTContext());
1083
1084
1085 if (FindObjCPropertyAndIvarDeclsWithOrigin(current_id,
1086 context,
1087 *m_ast_context,
1088 m_ast_importer,
1089 complete_iface_decl))
1090 return;
Sean Callanan8f2e3922012-02-04 08:49:35 +00001091}
1092
1093typedef llvm::DenseMap <const FieldDecl *, uint64_t> FieldOffsetMap;
1094typedef llvm::DenseMap <const CXXRecordDecl *, CharUnits> BaseOffsetMap;
1095
1096template <class D, class O>
1097static bool
1098ImportOffsetMap (llvm::DenseMap <const D*, O> &destination_map,
1099 llvm::DenseMap <const D*, O> &source_map,
1100 ClangASTImporter *importer,
1101 ASTContext &dest_ctx)
1102{
1103 typedef llvm::DenseMap <const D*, O> MapType;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001104
Sean Callanan8f2e3922012-02-04 08:49:35 +00001105 for (typename MapType::iterator fi = source_map.begin(), fe = source_map.end();
1106 fi != fe;
1107 ++fi)
1108 {
1109 DeclFromUser <D> user_decl(const_cast<D*>(fi->first));
1110 DeclFromParser <D> parser_decl(user_decl.Import(importer, dest_ctx));
1111 if (parser_decl.IsInvalid())
1112 return false;
1113 destination_map.insert(std::pair<const D *, O>(parser_decl.decl, fi->second));
1114 }
1115
1116 return true;
1117}
1118
1119template <bool IsVirtual> bool ExtractBaseOffsets (const ASTRecordLayout &record_layout,
1120 DeclFromUser<const CXXRecordDecl> &record,
1121 BaseOffsetMap &base_offsets)
1122{
1123 for (CXXRecordDecl::base_class_const_iterator
1124 bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()),
1125 be = (IsVirtual ? record->vbases_end() : record->bases_end());
1126 bi != be;
1127 ++bi)
1128 {
1129 if (!IsVirtual && bi->isVirtual())
1130 continue;
1131
1132 const clang::Type *origin_base_type = bi->getType().getTypePtr();
1133 const clang::RecordType *origin_base_record_type = origin_base_type->getAs<RecordType>();
1134
1135 if (!origin_base_record_type)
1136 return false;
1137
1138 DeclFromUser <RecordDecl> origin_base_record(origin_base_record_type->getDecl());
1139
1140 if (origin_base_record.IsInvalid())
1141 return false;
1142
1143 DeclFromUser <CXXRecordDecl> origin_base_cxx_record(DynCast<CXXRecordDecl>(origin_base_record));
1144
1145 if (origin_base_cxx_record.IsInvalid())
1146 return false;
1147
1148 CharUnits base_offset;
1149
1150 if (IsVirtual)
1151 base_offset = record_layout.getVBaseClassOffset(origin_base_cxx_record.decl);
1152 else
1153 base_offset = record_layout.getBaseClassOffset(origin_base_cxx_record.decl);
1154
1155 base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>(origin_base_cxx_record.decl, base_offset));
1156 }
1157
1158 return true;
1159}
1160
1161bool
1162ClangASTSource::layoutRecordType(const RecordDecl *record,
1163 uint64_t &size,
1164 uint64_t &alignment,
1165 FieldOffsetMap &field_offsets,
1166 BaseOffsetMap &base_offsets,
1167 BaseOffsetMap &virtual_base_offsets)
1168{
1169 static unsigned int invocation_id = 0;
1170 unsigned int current_id = invocation_id++;
1171
1172 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1173
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001174 if (log)
1175 {
Sean Callanan8f2e3922012-02-04 08:49:35 +00001176 log->Printf("LayoutRecordType[%u] on (RecordDecl*)%p [name = '%s']",
1177 current_id,
1178 m_ast_context,
1179 record->getNameAsString().c_str());
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001180 }
Sean Callanan8f2e3922012-02-04 08:49:35 +00001181
1182
1183 DeclFromParser <const RecordDecl> parser_record(record);
1184 DeclFromUser <const RecordDecl> origin_record(parser_record.GetOrigin(m_ast_importer));
1185
1186 if (origin_record.IsInvalid())
1187 return false;
1188
1189 FieldOffsetMap origin_field_offsets;
1190 BaseOffsetMap origin_base_offsets;
1191 BaseOffsetMap origin_virtual_base_offsets;
1192
Sean Callanan33bff9a2012-04-07 00:06:00 +00001193 ClangASTContext::GetCompleteDecl(&origin_record->getASTContext(), const_cast<RecordDecl*>(origin_record.decl));
1194
1195 if (!origin_record.decl->getDefinition())
1196 return false;
1197
Sean Callanan8f2e3922012-02-04 08:49:35 +00001198 const ASTRecordLayout &record_layout(origin_record->getASTContext().getASTRecordLayout(origin_record.decl));
1199
1200 int field_idx = 0;
1201
1202 for (RecordDecl::field_iterator fi = origin_record->field_begin(), fe = origin_record->field_end();
1203 fi != fe;
1204 ++fi)
1205 {
1206 uint64_t field_offset = record_layout.getFieldOffset(field_idx);
1207
1208 origin_field_offsets.insert(std::pair<const FieldDecl *, uint64_t>(*fi, field_offset));
1209
1210 field_idx++;
1211 }
1212
1213 ASTContext &parser_ast_context(record->getASTContext());
1214
1215 DeclFromUser <const CXXRecordDecl> origin_cxx_record(DynCast<const CXXRecordDecl>(origin_record));
1216
1217 if (origin_cxx_record.IsValid())
1218 {
1219 if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record, origin_base_offsets) ||
1220 !ExtractBaseOffsets<true>(record_layout, origin_cxx_record, origin_virtual_base_offsets))
1221 return false;
1222 }
1223
1224 if (!ImportOffsetMap(field_offsets, origin_field_offsets, m_ast_importer, parser_ast_context) ||
1225 !ImportOffsetMap(base_offsets, origin_base_offsets, m_ast_importer, parser_ast_context) ||
1226 !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, m_ast_importer, parser_ast_context))
1227 return false;
1228
1229 size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth();
1230 alignment = record_layout.getAlignment().getQuantity() * m_ast_context->getCharWidth();
1231
1232 if (log)
1233 {
1234 log->Printf("LRT[%u] returned:", current_id);
1235 log->Printf("LRT[%u] Original = (RecordDecl*)%p", current_id, origin_record.decl);
1236 log->Printf("LRT[%u] Size = %lld", current_id, size);
1237 log->Printf("LRT[%u] Alignment = %lld", current_id, alignment);
1238 log->Printf("LRT[%u] Fields:", current_id);
1239 for (RecordDecl::field_iterator fi = record->field_begin(), fe = record->field_end();
1240 fi != fe;
1241 ++fi)
1242 {
1243 log->Printf("LRT[%u] (FieldDecl*)%p, Name = '%s', Offset = %lld bits",
1244 current_id,
1245 *fi,
1246 fi->getNameAsString().c_str(),
1247 field_offsets[*fi]);
1248 }
1249 DeclFromParser <const CXXRecordDecl> parser_cxx_record = DynCast<const CXXRecordDecl>(parser_record);
1250 if (parser_cxx_record.IsValid())
1251 {
1252 log->Printf("LRT[%u] Bases:", current_id);
1253 for (CXXRecordDecl::base_class_const_iterator bi = parser_cxx_record->bases_begin(), be = parser_cxx_record->bases_end();
1254 bi != be;
1255 ++bi)
1256 {
1257 bool is_virtual = bi->isVirtual();
1258
1259 QualType base_type = bi->getType();
1260 const RecordType *base_record_type = base_type->getAs<RecordType>();
1261 DeclFromParser <RecordDecl> base_record(base_record_type->getDecl());
1262 DeclFromParser <CXXRecordDecl> base_cxx_record = DynCast<CXXRecordDecl>(base_record);
1263
1264 log->Printf("LRT[%u] %s(CXXRecordDecl*)%p, Name = '%s', Offset = %lld chars",
1265 current_id,
1266 (is_virtual ? "Virtual " : ""),
1267 base_cxx_record.decl,
1268 base_cxx_record.decl->getNameAsString().c_str(),
1269 (is_virtual ? virtual_base_offsets[base_cxx_record.decl].getQuantity() :
1270 base_offsets[base_cxx_record.decl].getQuantity()));
1271 }
1272 }
1273 else
1274 {
1275 log->Printf("LRD[%u] Not a CXXRecord, so no bases", current_id);
1276 }
1277 }
1278
1279 return true;
Sean Callanane6ea5fe2011-11-15 02:11:17 +00001280}
1281
Sean Callanan73b520f2011-10-29 01:58:46 +00001282void
1283ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
1284 const ConstString &name,
1285 ClangASTImporter::NamespaceMapSP &parent_map) const
1286{
1287 static unsigned int invocation_id = 0;
1288 unsigned int current_id = invocation_id++;
1289
1290 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1291
1292 if (log)
1293 {
1294 if (parent_map && parent_map->size())
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001295 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s in namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +00001296 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001297 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +00001298 name.GetCString(),
1299 parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str());
1300 else
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001301 log->Printf("CompleteNamespaceMap[%u] on (ASTContext*)%p Searching for namespace %s",
Sean Callanan73b520f2011-10-29 01:58:46 +00001302 current_id,
Sean Callanan5a55c7a2011-11-18 03:28:09 +00001303 m_ast_context,
Sean Callanan73b520f2011-10-29 01:58:46 +00001304 name.GetCString());
1305 }
1306
1307
1308 if (parent_map)
1309 {
1310 for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
1311 i != e;
1312 ++i)
1313 {
1314 ClangNamespaceDecl found_namespace_decl;
1315
1316 lldb::ModuleSP module_sp = i->first;
1317 ClangNamespaceDecl module_parent_namespace_decl = i->second;
1318
1319 SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
1320
1321 if (!symbol_vendor)
1322 continue;
1323
1324 SymbolContext null_sc;
1325
1326 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
1327
1328 if (!found_namespace_decl)
1329 continue;
1330
1331 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
1332
1333 if (log)
1334 log->Printf(" CMN[%u] Found namespace %s in module %s",
1335 current_id,
1336 name.GetCString(),
1337 module_sp->GetFileSpec().GetFilename().GetCString());
1338 }
1339 }
1340 else
1341 {
1342 ModuleList &images = m_target->GetImages();
1343 ClangNamespaceDecl null_namespace_decl;
1344
1345 for (uint32_t i = 0, e = images.GetSize();
1346 i != e;
1347 ++i)
1348 {
1349 lldb::ModuleSP image = images.GetModuleAtIndex(i);
1350
1351 if (!image)
1352 continue;
1353
1354 ClangNamespaceDecl found_namespace_decl;
1355
1356 SymbolVendor *symbol_vendor = image->GetSymbolVendor();
1357
1358 if (!symbol_vendor)
1359 continue;
1360
1361 SymbolContext null_sc;
1362
1363 found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
1364
1365 if (!found_namespace_decl)
1366 continue;
1367
1368 namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
1369
1370 if (log)
1371 log->Printf(" CMN[%u] Found namespace %s in module %s",
1372 current_id,
1373 name.GetCString(),
1374 image->GetFileSpec().GetFilename().GetCString());
1375 }
1376 }
1377}
1378
Sean Callananbb715f92011-10-29 02:28:18 +00001379NamespaceDecl *
1380ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls)
1381{
Greg Clayton13d24fb2012-01-29 20:56:30 +00001382 if (!namespace_decls)
Sean Callananbb715f92011-10-29 02:28:18 +00001383 return NULL;
1384
1385 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1386
1387 const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
1388
Sean Callanan4938bd62011-11-16 18:20:47 +00001389 Decl *copied_decl = m_ast_importer->CopyDecl(m_ast_context, namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl());
Sean Callananbb715f92011-10-29 02:28:18 +00001390
Sean Callananddb59332012-03-20 21:11:12 +00001391 if (!copied_decl)
1392 return NULL;
1393
Sean Callananbb715f92011-10-29 02:28:18 +00001394 NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
1395
1396 m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
1397
1398 return dyn_cast<NamespaceDecl>(copied_decl);
1399}
1400
Sean Callanan9394b5a2011-10-29 19:50:43 +00001401void *
1402ClangASTSource::GuardedCopyType (ASTContext *dest_context,
1403 ASTContext *source_context,
1404 void *clang_type)
1405{
1406 SetImportInProgress(true);
1407
Sean Callanan4938bd62011-11-16 18:20:47 +00001408 QualType ret_qual_type = m_ast_importer->CopyType (m_ast_context, source_context, QualType::getFromOpaquePtr(clang_type));
Sean Callanan9394b5a2011-10-29 19:50:43 +00001409
1410 void *ret = ret_qual_type.getAsOpaquePtr();
1411
1412 SetImportInProgress(false);
1413
Sean Callananddb59332012-03-20 21:11:12 +00001414 if (ret && ret_qual_type->getCanonicalTypeInternal().isNull())
Sean Callananaa11af82012-02-27 19:22:39 +00001415 // this shouldn't happen, but we're hardening because the AST importer seems to be generating bad types
1416 // on occasion.
1417 return NULL;
1418
Sean Callanan9394b5a2011-10-29 19:50:43 +00001419 return ret;
1420}
1421
Greg Claytonb01000f2011-01-17 03:46:26 +00001422clang::NamedDecl *
1423NameSearchContext::AddVarDecl(void *type)
1424{
Greg Clayton8de27c72010-10-15 22:48:33 +00001425 IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo();
Sean Callanan1ddd9fe2010-11-30 00:27:43 +00001426
1427 assert (type && "Type for variable must be non-NULL!");
Sean Callanancc074622010-09-14 21:59:34 +00001428
Sean Callananf76afff2011-10-28 23:38:38 +00001429 clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +00001430 const_cast<DeclContext*>(m_decl_context),
Chris Lattner24943d22010-06-08 16:52:24 +00001431 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +00001432 SourceLocation(),
Sean Callanancc074622010-09-14 21:59:34 +00001433 ii,
Chris Lattner24943d22010-06-08 16:52:24 +00001434 QualType::getFromOpaquePtr(type),
1435 0,
Sean Callanan47a5c4c2010-09-23 03:01:22 +00001436 SC_Static,
1437 SC_Static);
Greg Clayton8de27c72010-10-15 22:48:33 +00001438 m_decls.push_back(Decl);
Chris Lattner24943d22010-06-08 16:52:24 +00001439
1440 return Decl;
1441}
Sean Callanan8f0dc342010-06-22 23:46:24 +00001442
Greg Claytonb01000f2011-01-17 03:46:26 +00001443clang::NamedDecl *
1444NameSearchContext::AddFunDecl (void *type)
1445{
Sean Callanan30a5dd52012-03-21 17:13:20 +00001446 assert (type && "Type for variable must be non-NULL!");
1447
Sean Callananf76afff2011-10-28 23:38:38 +00001448 clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context,
Greg Clayton8de27c72010-10-15 22:48:33 +00001449 const_cast<DeclContext*>(m_decl_context),
1450 SourceLocation(),
Sean Callanan279584c2011-03-15 00:17:19 +00001451 SourceLocation(),
Greg Clayton8de27c72010-10-15 22:48:33 +00001452 m_decl_name.getAsIdentifierInfo(),
1453 QualType::getFromOpaquePtr(type),
1454 NULL,
1455 SC_Static,
1456 SC_Static,
1457 false,
1458 true);
Sean Callanan8f0dc342010-06-22 23:46:24 +00001459
Sean Callananb291abe2010-08-12 23:45:38 +00001460 // We have to do more than just synthesize the FunctionDecl. We have to
1461 // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do
1462 // this, we raid the function's FunctionProtoType for types.
1463
Greg Clayton8de27c72010-10-15 22:48:33 +00001464 QualType qual_type (QualType::getFromOpaquePtr(type));
Sean Callanan21f2e192011-12-14 01:13:04 +00001465 const FunctionProtoType *func_proto_type = qual_type.getTypePtr()->getAs<FunctionProtoType>();
Sean Callanan8f0dc342010-06-22 23:46:24 +00001466
Greg Clayton8de27c72010-10-15 22:48:33 +00001467 if (func_proto_type)
Sean Callanan3c821cc2010-06-23 18:58:10 +00001468 {
Greg Clayton8de27c72010-10-15 22:48:33 +00001469 unsigned NumArgs = func_proto_type->getNumArgs();
Sean Callanan8f0dc342010-06-22 23:46:24 +00001470 unsigned ArgIndex;
1471
Sean Callananc1535182011-10-07 23:18:13 +00001472 SmallVector<ParmVarDecl *, 5> parm_var_decls;
1473
Sean Callanan8f0dc342010-06-22 23:46:24 +00001474 for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex)
1475 {
Greg Clayton8de27c72010-10-15 22:48:33 +00001476 QualType arg_qual_type (func_proto_type->getArgType(ArgIndex));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001477
Sean Callananf76afff2011-10-28 23:38:38 +00001478 parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context,
Sean Callananc1535182011-10-07 23:18:13 +00001479 const_cast<DeclContext*>(m_decl_context),
1480 SourceLocation(),
1481 SourceLocation(),
1482 NULL,
1483 arg_qual_type,
1484 NULL,
1485 SC_Static,
1486 SC_Static,
1487 NULL));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001488 }
1489
Sean Callananc1535182011-10-07 23:18:13 +00001490 func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls));
Sean Callanan8f0dc342010-06-22 23:46:24 +00001491 }
Sean Callanandc5fce12011-12-01 21:04:37 +00001492 else
1493 {
1494 lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
1495
1496 log->Printf("Function type wasn't a FunctionProtoType");
1497 }
Sean Callanan8f0dc342010-06-22 23:46:24 +00001498
Greg Clayton8de27c72010-10-15 22:48:33 +00001499 m_decls.push_back(func_decl);
Sean Callanan8f0dc342010-06-22 23:46:24 +00001500
Greg Clayton8de27c72010-10-15 22:48:33 +00001501 return func_decl;
Sean Callanan8f0dc342010-06-22 23:46:24 +00001502}
Sean Callanan0fc73582010-07-27 00:55:47 +00001503
Greg Claytonb01000f2011-01-17 03:46:26 +00001504clang::NamedDecl *
1505NameSearchContext::AddGenericFunDecl()
Sean Callanan0fc73582010-07-27 00:55:47 +00001506{
Sean Callananad293092011-01-18 23:32:05 +00001507 FunctionProtoType::ExtProtoInfo proto_info;
1508
1509 proto_info.Variadic = true;
1510
Sean Callananf76afff2011-10-28 23:38:38 +00001511 QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result
1512 NULL, // argument types
1513 0, // number of arguments
1514 proto_info));
Greg Clayton8de27c72010-10-15 22:48:33 +00001515
Sean Callanan0fc73582010-07-27 00:55:47 +00001516 return AddFunDecl(generic_function_type.getAsOpaquePtr());
1517}
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001518
Greg Claytonb01000f2011-01-17 03:46:26 +00001519clang::NamedDecl *
1520NameSearchContext::AddTypeDecl(void *type)
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001521{
Greg Claytona1aaaff2011-01-23 00:34:52 +00001522 if (type)
1523 {
1524 QualType qual_type = QualType::getFromOpaquePtr(type);
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001525
Sean Callanan21f2e192011-12-14 01:13:04 +00001526 if (const TagType *tag_type = qual_type->getAs<TagType>())
Greg Claytona1aaaff2011-01-23 00:34:52 +00001527 {
1528 TagDecl *tag_decl = tag_type->getDecl();
1529
1530 m_decls.push_back(tag_decl);
1531
1532 return tag_decl;
1533 }
Sean Callanan21f2e192011-12-14 01:13:04 +00001534 else if (const ObjCObjectType *objc_object_type = qual_type->getAs<ObjCObjectType>())
Greg Claytona1aaaff2011-01-23 00:34:52 +00001535 {
1536 ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface();
1537
1538 m_decls.push_back((NamedDecl*)interface_decl);
1539
1540 return (NamedDecl*)interface_decl;
1541 }
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001542 }
Greg Claytona1aaaff2011-01-23 00:34:52 +00001543 return NULL;
Sean Callanan93a4b1a2010-08-04 01:02:13 +00001544}
Greg Claytone6d72ca2011-06-25 00:44:06 +00001545
1546void
1547NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result)
1548{
1549 for (clang::NamedDecl * const *decl_iterator = result.first;
1550 decl_iterator != result.second;
1551 ++decl_iterator)
1552 m_decls.push_back (*decl_iterator);
1553}
1554
1555void
1556NameSearchContext::AddNamedDecl (clang::NamedDecl *decl)
1557{
1558 m_decls.push_back (decl);
1559}