Greg Clayton | 1e591ce | 2010-07-16 18:28:27 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 10 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | #include "clang/AST/ASTContext.h" |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Log.h" |
Greg Clayton | 6e0101c | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ModuleList.h" |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 15 | #include "lldb/Expression/ASTDumper.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Expression/ClangASTSource.h" |
| 17 | #include "lldb/Expression/ClangExpression.h" |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/ClangNamespaceDecl.h" |
| 19 | #include "lldb/Symbol/SymbolVendor.h" |
| 20 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace clang; |
| 23 | using namespace lldb_private; |
| 24 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 25 | ClangASTSource::~ClangASTSource() |
| 26 | { |
| 27 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 29 | void |
| 30 | ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) |
| 31 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 32 | if (!m_ast_context) |
| 33 | return; |
| 34 | |
| 35 | m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 36 | m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | // The core lookup interface. |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 40 | DeclContext::lookup_result |
| 41 | ClangASTSource::FindExternalVisibleDeclsByName |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 42 | ( |
| 43 | const DeclContext *decl_ctx, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 44 | DeclarationName clang_decl_name |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 45 | ) |
| 46 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 47 | if (!m_ast_context) |
| 48 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 49 | |
| 50 | if (GetImportInProgress()) |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 51 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 52 | |
| 53 | std::string decl_name (clang_decl_name.getAsString()); |
| 54 | |
| 55 | // if (m_decl_map.DoingASTImport ()) |
| 56 | // return DeclContext::lookup_result(); |
| 57 | // |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 58 | switch (clang_decl_name.getNameKind()) { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | // Normal identifiers. |
| 60 | case DeclarationName::Identifier: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 61 | if (clang_decl_name.getAsIdentifierInfo()->getBuiltinID() != 0) |
| 62 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 63 | break; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
| 65 | // Operator names. Not important for now. |
| 66 | case DeclarationName::CXXOperatorName: |
| 67 | case DeclarationName::CXXLiteralOperatorName: |
| 68 | return DeclContext::lookup_result(); |
| 69 | |
| 70 | // Using directives found in this context. |
| 71 | // Tell Sema we didn't find any or we'll end up getting asked a *lot*. |
| 72 | case DeclarationName::CXXUsingDirective: |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 73 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | case DeclarationName::ObjCZeroArgSelector: |
| 76 | case DeclarationName::ObjCOneArgSelector: |
| 77 | case DeclarationName::ObjCMultiArgSelector: |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 78 | { |
| 79 | llvm::SmallVector<NamedDecl*, 1> method_decls; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 81 | NameSearchContext method_search_context (*this, method_decls, clang_decl_name, decl_ctx); |
| 82 | |
| 83 | FindObjCMethodDecls(method_search_context); |
| 84 | |
| 85 | return SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, method_decls); |
| 86 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | // These aren't possible in the global context. |
| 88 | case DeclarationName::CXXConstructorName: |
| 89 | case DeclarationName::CXXDestructorName: |
| 90 | case DeclarationName::CXXConversionFunctionName: |
| 91 | return DeclContext::lookup_result(); |
| 92 | } |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 93 | |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 94 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 95 | if (!GetLookupsEnabled()) |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 96 | { |
| 97 | // Wait until we see a '$' at the start of a name before we start doing |
| 98 | // any lookups so we can avoid lookup up all of the builtin types. |
| 99 | if (!decl_name.empty() && decl_name[0] == '$') |
| 100 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 101 | SetLookupsEnabled (true); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 102 | } |
| 103 | else |
| 104 | { |
| 105 | return SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); |
| 106 | } |
Greg Clayton | f4c7ae0 | 2010-10-15 03:36:13 +0000 | [diff] [blame] | 107 | } |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 108 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 109 | ConstString const_decl_name(decl_name.c_str()); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 110 | |
| 111 | const char *uniqued_const_decl_name = const_decl_name.GetCString(); |
| 112 | if (m_active_lookups.find (uniqued_const_decl_name) != m_active_lookups.end()) |
| 113 | { |
| 114 | // We are currently looking up this name... |
| 115 | return DeclContext::lookup_result(); |
| 116 | } |
| 117 | m_active_lookups.insert(uniqued_const_decl_name); |
Greg Clayton | a8b278a | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 118 | // static uint32_t g_depth = 0; |
| 119 | // ++g_depth; |
| 120 | // printf("[%5u] FindExternalVisibleDeclsByName() \"%s\"\n", g_depth, uniqued_const_decl_name); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 121 | llvm::SmallVector<NamedDecl*, 4> name_decls; |
| 122 | NameSearchContext name_search_context(*this, name_decls, clang_decl_name, decl_ctx); |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 123 | FindExternalVisibleDecls(name_search_context); |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 124 | DeclContext::lookup_result result (SetExternalVisibleDeclsForName (decl_ctx, clang_decl_name, name_decls)); |
Greg Clayton | a8b278a | 2010-11-15 01:34:18 +0000 | [diff] [blame] | 125 | // --g_depth; |
Greg Clayton | 9ceed1e | 2010-11-13 04:18:24 +0000 | [diff] [blame] | 126 | m_active_lookups.erase (uniqued_const_decl_name); |
| 127 | return result; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 130 | void |
| 131 | ClangASTSource::CompleteType (TagDecl *tag_decl) |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 132 | { |
| 133 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 134 | |
| 135 | if (log) |
| 136 | { |
| 137 | log->Printf(" [CompleteTagDecl] Completing a TagDecl named %s", tag_decl->getName().str().c_str()); |
| 138 | log->Printf(" [CTD] Before:"); |
| 139 | ASTDumper dumper((Decl*)tag_decl); |
| 140 | dumper.ToLog(log, " [CTD] "); |
| 141 | } |
| 142 | |
| 143 | m_ast_importer->CompleteTagDecl (tag_decl); |
| 144 | |
| 145 | if (log) |
| 146 | { |
| 147 | log->Printf(" [CTD] After:"); |
| 148 | ASTDumper dumper((Decl*)tag_decl); |
| 149 | dumper.ToLog(log, " [CTD] "); |
| 150 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | void |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 154 | ClangASTSource::CompleteType (clang::ObjCInterfaceDecl *interface_decl) |
| 155 | { |
| 156 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 157 | |
| 158 | if (log) |
| 159 | { |
| 160 | log->Printf(" [CompleteObjCInterfaceDecl] Completing an ObjCInterfaceDecl named %s", interface_decl->getName().str().c_str()); |
| 161 | log->Printf(" [COID] Before:"); |
| 162 | ASTDumper dumper((Decl*)interface_decl); |
| 163 | dumper.ToLog(log, " [COID] "); |
| 164 | } |
| 165 | |
| 166 | m_ast_importer->CompleteObjCInterfaceDecl (interface_decl); |
| 167 | |
| 168 | if (log) |
| 169 | { |
| 170 | log->Printf(" [COID] After:"); |
| 171 | ASTDumper dumper((Decl*)interface_decl); |
| 172 | dumper.ToLog(log, " [COID] "); |
| 173 | } |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Sean Callanan | 9b6898f | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 176 | clang::ExternalLoadResult |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 177 | ClangASTSource::FindExternalLexicalDecls (const DeclContext *decl_context, |
| 178 | bool (*predicate)(Decl::Kind), |
| 179 | llvm::SmallVectorImpl<Decl*> &decls) |
| 180 | { |
| 181 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 182 | |
| 183 | const Decl *context_decl = dyn_cast<Decl>(decl_context); |
| 184 | |
| 185 | if (!context_decl) |
| 186 | return ELR_Failure; |
| 187 | |
| 188 | static unsigned int invocation_id = 0; |
| 189 | unsigned int current_id = invocation_id++; |
| 190 | |
| 191 | if (log) |
| 192 | { |
| 193 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
| 194 | log->Printf("FindExternalLexicalDecls[%u] in '%s' (a %s) with %s predicate", |
| 195 | current_id, |
| 196 | context_named_decl->getNameAsString().c_str(), |
| 197 | context_decl->getDeclKindName(), |
| 198 | (predicate ? "non-null" : "null")); |
| 199 | else if(context_decl) |
| 200 | log->Printf("FindExternalLexicalDecls[%u] in a %s with %s predicate", |
| 201 | current_id, |
| 202 | context_decl->getDeclKindName(), |
| 203 | (predicate ? "non-null" : "null")); |
| 204 | else |
| 205 | log->Printf("FindExternalLexicalDecls[%u] in a NULL context with %s predicate", |
| 206 | current_id, |
| 207 | (predicate ? "non-null" : "null")); |
| 208 | } |
| 209 | |
| 210 | Decl *original_decl = NULL; |
| 211 | ASTContext *original_ctx = NULL; |
| 212 | |
| 213 | if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx)) |
| 214 | return ELR_Failure; |
| 215 | |
| 216 | if (log) |
| 217 | { |
| 218 | log->Printf(" FELD[%u] Original decl:", current_id); |
| 219 | ASTDumper(original_decl).ToLog(log, " "); |
| 220 | } |
| 221 | |
| 222 | if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original_decl)) |
| 223 | { |
| 224 | ExternalASTSource *external_source = original_ctx->getExternalSource(); |
| 225 | |
| 226 | if (external_source) |
| 227 | external_source->CompleteType (original_tag_decl); |
| 228 | } |
| 229 | |
| 230 | DeclContext *original_decl_context = dyn_cast<DeclContext>(original_decl); |
| 231 | |
| 232 | if (!original_decl_context) |
| 233 | return ELR_Failure; |
| 234 | |
| 235 | for (TagDecl::decl_iterator iter = original_decl_context->decls_begin(); |
| 236 | iter != original_decl_context->decls_end(); |
| 237 | ++iter) |
| 238 | { |
| 239 | Decl *decl = *iter; |
| 240 | |
| 241 | if (!predicate || predicate(decl->getKind())) |
| 242 | { |
| 243 | if (log) |
| 244 | { |
| 245 | ASTDumper ast_dumper(decl); |
| 246 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) |
| 247 | log->Printf(" FELD[%d] Adding [to %s] lexical decl %s", current_id, context_named_decl->getNameAsString().c_str(), ast_dumper.GetCString()); |
| 248 | else |
| 249 | log->Printf(" FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString()); |
| 250 | } |
| 251 | |
| 252 | Decl *copied_decl = m_ast_importer->CopyDecl(original_ctx, decl); |
| 253 | |
| 254 | decls.push_back(copied_decl); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return ELR_AlreadyLoaded; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 261 | void |
| 262 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context) |
| 263 | { |
| 264 | assert (m_ast_context); |
| 265 | |
| 266 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 267 | |
| 268 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 269 | |
| 270 | static unsigned int invocation_id = 0; |
| 271 | unsigned int current_id = invocation_id++; |
| 272 | |
| 273 | if (log) |
| 274 | { |
| 275 | if (!context.m_decl_context) |
| 276 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] for '%s' in a NULL DeclContext", current_id, name.GetCString()); |
| 277 | else if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context.m_decl_context)) |
| 278 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] for '%s' in '%s'", current_id, name.GetCString(), context_named_decl->getNameAsString().c_str()); |
| 279 | else |
| 280 | log->Printf("ClangASTSource::FindExternalVisibleDecls[%u] for '%s' in a '%s'", current_id, name.GetCString(), context.m_decl_context->getDeclKindName()); |
| 281 | } |
| 282 | |
| 283 | context.m_namespace_map.reset(new ClangASTImporter::NamespaceMap); |
| 284 | |
| 285 | if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context)) |
| 286 | { |
| 287 | ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context); |
| 288 | |
| 289 | if (log && log->GetVerbose()) |
| 290 | log->Printf(" CAS::FEVD[%u] Inspecting namespace map %p (%d entries)", |
| 291 | current_id, |
| 292 | namespace_map.get(), |
| 293 | (int)namespace_map->size()); |
| 294 | |
| 295 | if (!namespace_map) |
| 296 | return; |
| 297 | |
| 298 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end(); |
| 299 | i != e; |
| 300 | ++i) |
| 301 | { |
| 302 | if (log) |
| 303 | log->Printf(" CAS::FEVD[%u] Searching namespace %s in module %s", |
| 304 | current_id, |
| 305 | i->second.GetNamespaceDecl()->getNameAsString().c_str(), |
| 306 | i->first->GetFileSpec().GetFilename().GetCString()); |
| 307 | |
| 308 | FindExternalVisibleDecls(context, |
| 309 | i->first, |
| 310 | i->second, |
| 311 | current_id); |
| 312 | } |
| 313 | } |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame^] | 314 | else if (const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(context.m_decl_context)) |
| 315 | { |
| 316 | FindObjCPropertyDecls(context); |
| 317 | } |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 318 | else if (!isa<TranslationUnitDecl>(context.m_decl_context)) |
| 319 | { |
| 320 | // we shouldn't be getting FindExternalVisibleDecls calls for these |
| 321 | return; |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | ClangNamespaceDecl namespace_decl; |
| 326 | |
| 327 | if (log) |
| 328 | log->Printf(" CAS::FEVD[%u] Searching the root namespace", current_id); |
| 329 | |
| 330 | FindExternalVisibleDecls(context, |
| 331 | lldb::ModuleSP(), |
| 332 | namespace_decl, |
| 333 | current_id); |
| 334 | } |
| 335 | |
| 336 | if (!context.m_namespace_map->empty()) |
| 337 | { |
| 338 | if (log && log->GetVerbose()) |
| 339 | log->Printf(" CAS::FEVD[%u] Registering namespace map %p (%d entries)", |
| 340 | current_id, |
| 341 | context.m_namespace_map.get(), |
| 342 | (int)context.m_namespace_map->size()); |
| 343 | |
| 344 | NamespaceDecl *clang_namespace_decl = AddNamespace(context, context.m_namespace_map); |
| 345 | |
| 346 | if (clang_namespace_decl) |
| 347 | clang_namespace_decl->setHasExternalVisibleStorage(); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | void |
| 352 | ClangASTSource::FindExternalVisibleDecls (NameSearchContext &context, |
| 353 | lldb::ModuleSP module_sp, |
| 354 | ClangNamespaceDecl &namespace_decl, |
| 355 | unsigned int current_id) |
| 356 | { |
| 357 | assert (m_ast_context); |
| 358 | |
| 359 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 360 | |
| 361 | SymbolContextList sc_list; |
| 362 | |
| 363 | const ConstString name(context.m_decl_name.getAsString().c_str()); |
| 364 | |
| 365 | const char *name_unique_cstr = name.GetCString(); |
| 366 | |
| 367 | if (name_unique_cstr == NULL) |
| 368 | return; |
| 369 | |
| 370 | // The ClangASTSource is not responsible for finding $-names. |
| 371 | if (name_unique_cstr[0] == '$') |
| 372 | return; |
| 373 | |
| 374 | if (module_sp && namespace_decl) |
| 375 | { |
| 376 | ClangNamespaceDecl found_namespace_decl; |
| 377 | |
| 378 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 379 | |
| 380 | if (symbol_vendor) |
| 381 | { |
| 382 | SymbolContext null_sc; |
| 383 | |
| 384 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 385 | |
| 386 | if (found_namespace_decl) |
| 387 | { |
| 388 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 389 | |
| 390 | if (log) |
| 391 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 392 | current_id, |
| 393 | name.GetCString(), |
| 394 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | ModuleList &images = m_target->GetImages(); |
| 401 | |
| 402 | for (uint32_t i = 0, e = images.GetSize(); |
| 403 | i != e; |
| 404 | ++i) |
| 405 | { |
| 406 | lldb::ModuleSP image = images.GetModuleAtIndex(i); |
| 407 | |
| 408 | if (!image) |
| 409 | continue; |
| 410 | |
| 411 | ClangNamespaceDecl found_namespace_decl; |
| 412 | |
| 413 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 414 | |
| 415 | if (!symbol_vendor) |
| 416 | continue; |
| 417 | |
| 418 | SymbolContext null_sc; |
| 419 | |
| 420 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &namespace_decl); |
| 421 | |
| 422 | if (found_namespace_decl) |
| 423 | { |
| 424 | context.m_namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 425 | |
| 426 | if (log) |
| 427 | log->Printf(" CAS::FEVD[%u] Found namespace %s in module %s", |
| 428 | current_id, |
| 429 | name.GetCString(), |
| 430 | image->GetFileSpec().GetFilename().GetCString()); |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | static ConstString id_name("id"); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 436 | static ConstString Class_name("Class"); |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 437 | |
| 438 | do |
| 439 | { |
| 440 | TypeList types; |
| 441 | SymbolContext null_sc; |
| 442 | |
| 443 | if (module_sp && namespace_decl) |
| 444 | module_sp->FindTypes(null_sc, name, &namespace_decl, true, 1, types); |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 445 | else if(name != id_name && name != Class_name) |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 446 | m_target->GetImages().FindTypes (null_sc, name, true, 1, types); |
| 447 | else |
| 448 | break; |
| 449 | |
| 450 | if (types.GetSize()) |
| 451 | { |
| 452 | lldb::TypeSP type_sp = types.GetTypeAtIndex(0); |
| 453 | |
| 454 | if (log) |
| 455 | { |
| 456 | const char *name_string = type_sp->GetName().GetCString(); |
| 457 | |
| 458 | log->Printf(" CAS::FEVD[%u] Matching type found for \"%s\": %s", |
| 459 | current_id, |
| 460 | name.GetCString(), |
| 461 | (name_string ? name_string : "<anonymous>")); |
| 462 | } |
| 463 | |
| 464 | void *copied_type = GuardedCopyType(m_ast_context, type_sp->GetClangAST(), type_sp->GetClangFullType()); |
| 465 | |
| 466 | context.AddTypeDecl(copied_type); |
| 467 | } |
| 468 | } while(0); |
| 469 | } |
| 470 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 471 | void |
| 472 | ClangASTSource::FindObjCMethodDecls (NameSearchContext &context) |
| 473 | { |
| 474 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 475 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 476 | static unsigned int invocation_id = 0; |
| 477 | unsigned int current_id = invocation_id++; |
| 478 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 479 | const DeclarationName &decl_name(context.m_decl_name); |
| 480 | const DeclContext *decl_ctx(context.m_decl_context); |
| 481 | |
| 482 | const ObjCInterfaceDecl *interface_decl = dyn_cast<ObjCInterfaceDecl>(decl_ctx); |
| 483 | |
| 484 | if (!interface_decl) |
| 485 | return; |
| 486 | |
| 487 | StreamString ss; |
| 488 | if (decl_name.isObjCZeroArgSelector()) |
| 489 | { |
| 490 | ss.Printf("%s", decl_name.getAsString().c_str()); |
| 491 | } |
| 492 | else if (decl_name.isObjCOneArgSelector()) |
| 493 | { |
Sean Callanan | 1d9ffe2 | 2011-11-14 18:29:46 +0000 | [diff] [blame] | 494 | ss.Printf("%s", decl_name.getAsString().c_str()); |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 495 | } |
| 496 | else |
| 497 | { |
| 498 | clang::Selector sel = decl_name.getObjCSelector(); |
| 499 | |
| 500 | for (unsigned i = 0, e = sel.getNumArgs(); |
| 501 | i != e; |
| 502 | ++i) |
| 503 | { |
| 504 | llvm::StringRef r = sel.getNameForSlot(i); |
| 505 | ss.Printf("%s:", r.str().c_str()); |
| 506 | } |
| 507 | } |
| 508 | ss.Flush(); |
| 509 | |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 510 | ConstString selector_name(ss.GetData()); |
| 511 | |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 512 | if (log) |
Sean Callanan | f2a0a5c | 2011-11-11 20:37:26 +0000 | [diff] [blame] | 513 | log->Printf("ClangASTSource::FindObjCMethodDecls[%d] for selector [%s %s]", |
| 514 | current_id, |
| 515 | interface_decl->getNameAsString().c_str(), |
| 516 | selector_name.AsCString()); |
| 517 | |
| 518 | SymbolContextList sc_list; |
| 519 | |
| 520 | const bool include_symbols = false; |
| 521 | const bool append = false; |
| 522 | |
| 523 | m_target->GetImages().FindFunctions(selector_name, lldb::eFunctionNameTypeSelector, include_symbols, append, sc_list); |
| 524 | |
| 525 | for (uint32_t i = 0, e = sc_list.GetSize(); |
| 526 | i != e; |
| 527 | ++i) |
| 528 | { |
| 529 | SymbolContext sc; |
| 530 | |
| 531 | if (!sc_list.GetContextAtIndex(i, sc)) |
| 532 | continue; |
| 533 | |
| 534 | if (!sc.function) |
| 535 | continue; |
| 536 | |
| 537 | DeclContext *function_ctx = sc.function->GetClangDeclContext(); |
| 538 | |
| 539 | if (!function_ctx) |
| 540 | continue; |
| 541 | |
| 542 | ObjCMethodDecl *method_decl = dyn_cast<ObjCMethodDecl>(function_ctx); |
| 543 | |
| 544 | if (!method_decl) |
| 545 | continue; |
| 546 | |
| 547 | ObjCInterfaceDecl *found_interface_decl = method_decl->getClassInterface(); |
| 548 | |
| 549 | if (!found_interface_decl) |
| 550 | continue; |
| 551 | |
| 552 | if (found_interface_decl->getName() == interface_decl->getName()) |
| 553 | { |
| 554 | Decl *copied_decl = m_ast_importer->CopyDecl(&method_decl->getASTContext(), method_decl); |
| 555 | |
| 556 | if (!copied_decl) |
| 557 | continue; |
| 558 | |
| 559 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); |
| 560 | |
| 561 | if (!copied_method_decl) |
| 562 | continue; |
| 563 | |
| 564 | if (log) |
| 565 | { |
| 566 | ASTDumper dumper((Decl*)copied_method_decl); |
| 567 | log->Printf(" CAS::FOMD[%d] found %s", current_id, dumper.GetCString()); |
| 568 | } |
| 569 | |
| 570 | context.AddNamedDecl(copied_method_decl); |
| 571 | } |
| 572 | } |
Sean Callanan | 9b71484 | 2011-11-09 19:33:21 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Sean Callanan | e6ea5fe | 2011-11-15 02:11:17 +0000 | [diff] [blame^] | 575 | void |
| 576 | ClangASTSource::FindObjCPropertyDecls (NameSearchContext &context) |
| 577 | { |
| 578 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 579 | |
| 580 | static unsigned int invocation_id = 0; |
| 581 | unsigned int current_id = invocation_id++; |
| 582 | |
| 583 | const ObjCInterfaceDecl *iface_decl = cast<ObjCInterfaceDecl>(context.m_decl_context); |
| 584 | Decl *orig_decl; |
| 585 | ASTContext *orig_ast_ctx; |
| 586 | |
| 587 | m_ast_importer->ResolveDeclOrigin(iface_decl, &orig_decl, &orig_ast_ctx); |
| 588 | |
| 589 | if (!orig_decl) |
| 590 | return; |
| 591 | |
| 592 | ObjCInterfaceDecl *orig_iface_decl = dyn_cast<ObjCInterfaceDecl>(orig_decl); |
| 593 | |
| 594 | if (!orig_iface_decl) |
| 595 | return; |
| 596 | |
| 597 | if (!ClangASTContext::GetCompleteDecl(orig_ast_ctx, orig_iface_decl)) |
| 598 | return; |
| 599 | |
| 600 | std::string property_name_str = context.m_decl_name.getAsString(); |
| 601 | StringRef property_name(property_name_str.c_str()); |
| 602 | ObjCPropertyDecl *property_decl = orig_iface_decl->FindPropertyDeclaration(&orig_ast_ctx->Idents.get(property_name)); |
| 603 | |
| 604 | if (log) |
| 605 | log->Printf("ClangASTSource::FindObjCPropertyDecls[%d] for property '%s.%s'", |
| 606 | current_id, |
| 607 | iface_decl->getNameAsString().c_str(), |
| 608 | property_name_str.c_str()); |
| 609 | |
| 610 | if (!property_decl) |
| 611 | return; |
| 612 | |
| 613 | Decl *copied_decl = m_ast_importer->CopyDecl(orig_ast_ctx, property_decl); |
| 614 | |
| 615 | if (!copied_decl) |
| 616 | return; |
| 617 | |
| 618 | ObjCPropertyDecl *copied_property_decl = dyn_cast<ObjCPropertyDecl>(copied_decl); |
| 619 | |
| 620 | if (!copied_property_decl) |
| 621 | return; |
| 622 | |
| 623 | if (log) |
| 624 | { |
| 625 | ASTDumper dumper((Decl*)copied_property_decl); |
| 626 | log->Printf(" CAS::FOPD[%d] found %s", current_id, dumper.GetCString()); |
| 627 | } |
| 628 | |
| 629 | context.AddNamedDecl(copied_property_decl); |
| 630 | } |
| 631 | |
Sean Callanan | 73b520f | 2011-10-29 01:58:46 +0000 | [diff] [blame] | 632 | void |
| 633 | ClangASTSource::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map, |
| 634 | const ConstString &name, |
| 635 | ClangASTImporter::NamespaceMapSP &parent_map) const |
| 636 | { |
| 637 | static unsigned int invocation_id = 0; |
| 638 | unsigned int current_id = invocation_id++; |
| 639 | |
| 640 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 641 | |
| 642 | if (log) |
| 643 | { |
| 644 | if (parent_map && parent_map->size()) |
| 645 | log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s in namespace %s", |
| 646 | current_id, |
| 647 | name.GetCString(), |
| 648 | parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str()); |
| 649 | else |
| 650 | log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s", |
| 651 | current_id, |
| 652 | name.GetCString()); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | if (parent_map) |
| 657 | { |
| 658 | for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end(); |
| 659 | i != e; |
| 660 | ++i) |
| 661 | { |
| 662 | ClangNamespaceDecl found_namespace_decl; |
| 663 | |
| 664 | lldb::ModuleSP module_sp = i->first; |
| 665 | ClangNamespaceDecl module_parent_namespace_decl = i->second; |
| 666 | |
| 667 | SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor(); |
| 668 | |
| 669 | if (!symbol_vendor) |
| 670 | continue; |
| 671 | |
| 672 | SymbolContext null_sc; |
| 673 | |
| 674 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl); |
| 675 | |
| 676 | if (!found_namespace_decl) |
| 677 | continue; |
| 678 | |
| 679 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl)); |
| 680 | |
| 681 | if (log) |
| 682 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 683 | current_id, |
| 684 | name.GetCString(), |
| 685 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 686 | } |
| 687 | } |
| 688 | else |
| 689 | { |
| 690 | ModuleList &images = m_target->GetImages(); |
| 691 | ClangNamespaceDecl null_namespace_decl; |
| 692 | |
| 693 | for (uint32_t i = 0, e = images.GetSize(); |
| 694 | i != e; |
| 695 | ++i) |
| 696 | { |
| 697 | lldb::ModuleSP image = images.GetModuleAtIndex(i); |
| 698 | |
| 699 | if (!image) |
| 700 | continue; |
| 701 | |
| 702 | ClangNamespaceDecl found_namespace_decl; |
| 703 | |
| 704 | SymbolVendor *symbol_vendor = image->GetSymbolVendor(); |
| 705 | |
| 706 | if (!symbol_vendor) |
| 707 | continue; |
| 708 | |
| 709 | SymbolContext null_sc; |
| 710 | |
| 711 | found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl); |
| 712 | |
| 713 | if (!found_namespace_decl) |
| 714 | continue; |
| 715 | |
| 716 | namespace_map->push_back(std::pair<lldb::ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl)); |
| 717 | |
| 718 | if (log) |
| 719 | log->Printf(" CMN[%u] Found namespace %s in module %s", |
| 720 | current_id, |
| 721 | name.GetCString(), |
| 722 | image->GetFileSpec().GetFilename().GetCString()); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | |
Sean Callanan | bb715f9 | 2011-10-29 02:28:18 +0000 | [diff] [blame] | 727 | NamespaceDecl * |
| 728 | ClangASTSource::AddNamespace (NameSearchContext &context, ClangASTImporter::NamespaceMapSP &namespace_decls) |
| 729 | { |
| 730 | if (namespace_decls.empty()) |
| 731 | return NULL; |
| 732 | |
| 733 | lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); |
| 734 | |
| 735 | const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second; |
| 736 | |
| 737 | Decl *copied_decl = m_ast_importer->CopyDecl(namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl()); |
| 738 | |
| 739 | NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); |
| 740 | |
| 741 | m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls); |
| 742 | |
| 743 | return dyn_cast<NamespaceDecl>(copied_decl); |
| 744 | } |
| 745 | |
Sean Callanan | 9394b5a | 2011-10-29 19:50:43 +0000 | [diff] [blame] | 746 | void * |
| 747 | ClangASTSource::GuardedCopyType (ASTContext *dest_context, |
| 748 | ASTContext *source_context, |
| 749 | void *clang_type) |
| 750 | { |
| 751 | SetImportInProgress(true); |
| 752 | |
| 753 | QualType ret_qual_type = m_ast_importer->CopyType (source_context, QualType::getFromOpaquePtr(clang_type)); |
| 754 | |
| 755 | void *ret = ret_qual_type.getAsOpaquePtr(); |
| 756 | |
| 757 | SetImportInProgress(false); |
| 758 | |
| 759 | return ret; |
| 760 | } |
| 761 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 762 | clang::NamedDecl * |
| 763 | NameSearchContext::AddVarDecl(void *type) |
| 764 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 765 | IdentifierInfo *ii = m_decl_name.getAsIdentifierInfo(); |
Sean Callanan | 1ddd9fe | 2010-11-30 00:27:43 +0000 | [diff] [blame] | 766 | |
| 767 | assert (type && "Type for variable must be non-NULL!"); |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 768 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 769 | clang::NamedDecl *Decl = VarDecl::Create(*m_ast_source.m_ast_context, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 770 | const_cast<DeclContext*>(m_decl_context), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 771 | SourceLocation(), |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 772 | SourceLocation(), |
Sean Callanan | cc07462 | 2010-09-14 21:59:34 +0000 | [diff] [blame] | 773 | ii, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 774 | QualType::getFromOpaquePtr(type), |
| 775 | 0, |
Sean Callanan | 47a5c4c | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 776 | SC_Static, |
| 777 | SC_Static); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 778 | m_decls.push_back(Decl); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 779 | |
| 780 | return Decl; |
| 781 | } |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 782 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 783 | clang::NamedDecl * |
| 784 | NameSearchContext::AddFunDecl (void *type) |
| 785 | { |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 786 | clang::FunctionDecl *func_decl = FunctionDecl::Create (*m_ast_source.m_ast_context, |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 787 | const_cast<DeclContext*>(m_decl_context), |
| 788 | SourceLocation(), |
Sean Callanan | 279584c | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 789 | SourceLocation(), |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 790 | m_decl_name.getAsIdentifierInfo(), |
| 791 | QualType::getFromOpaquePtr(type), |
| 792 | NULL, |
| 793 | SC_Static, |
| 794 | SC_Static, |
| 795 | false, |
| 796 | true); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 797 | |
Sean Callanan | b291abe | 2010-08-12 23:45:38 +0000 | [diff] [blame] | 798 | // We have to do more than just synthesize the FunctionDecl. We have to |
| 799 | // synthesize ParmVarDecls for all of the FunctionDecl's arguments. To do |
| 800 | // this, we raid the function's FunctionProtoType for types. |
| 801 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 802 | QualType qual_type (QualType::getFromOpaquePtr(type)); |
| 803 | const FunctionProtoType *func_proto_type = qual_type->getAs<FunctionProtoType>(); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 804 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 805 | if (func_proto_type) |
Sean Callanan | 3c821cc | 2010-06-23 18:58:10 +0000 | [diff] [blame] | 806 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 807 | unsigned NumArgs = func_proto_type->getNumArgs(); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 808 | unsigned ArgIndex; |
| 809 | |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 810 | SmallVector<ParmVarDecl *, 5> parm_var_decls; |
| 811 | |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 812 | for (ArgIndex = 0; ArgIndex < NumArgs; ++ArgIndex) |
| 813 | { |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 814 | QualType arg_qual_type (func_proto_type->getArgType(ArgIndex)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 815 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 816 | parm_var_decls.push_back(ParmVarDecl::Create (*m_ast_source.m_ast_context, |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 817 | const_cast<DeclContext*>(m_decl_context), |
| 818 | SourceLocation(), |
| 819 | SourceLocation(), |
| 820 | NULL, |
| 821 | arg_qual_type, |
| 822 | NULL, |
| 823 | SC_Static, |
| 824 | SC_Static, |
| 825 | NULL)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Sean Callanan | c153518 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 828 | func_decl->setParams(ArrayRef<ParmVarDecl*>(parm_var_decls)); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 831 | m_decls.push_back(func_decl); |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 832 | |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 833 | return func_decl; |
Sean Callanan | 8f0dc34 | 2010-06-22 23:46:24 +0000 | [diff] [blame] | 834 | } |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 835 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 836 | clang::NamedDecl * |
| 837 | NameSearchContext::AddGenericFunDecl() |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 838 | { |
Sean Callanan | ad29309 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 839 | FunctionProtoType::ExtProtoInfo proto_info; |
| 840 | |
| 841 | proto_info.Variadic = true; |
| 842 | |
Sean Callanan | f76afff | 2011-10-28 23:38:38 +0000 | [diff] [blame] | 843 | QualType generic_function_type(m_ast_source.m_ast_context->getFunctionType (m_ast_source.m_ast_context->UnknownAnyTy, // result |
| 844 | NULL, // argument types |
| 845 | 0, // number of arguments |
| 846 | proto_info)); |
Greg Clayton | 8de27c7 | 2010-10-15 22:48:33 +0000 | [diff] [blame] | 847 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 848 | return AddFunDecl(generic_function_type.getAsOpaquePtr()); |
| 849 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 850 | |
Greg Clayton | b01000f | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 851 | clang::NamedDecl * |
| 852 | NameSearchContext::AddTypeDecl(void *type) |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 853 | { |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 854 | if (type) |
| 855 | { |
| 856 | QualType qual_type = QualType::getFromOpaquePtr(type); |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 857 | |
Sean Callanan | d5b3c35 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 858 | if (const TagType *tag_type = dyn_cast<clang::TagType>(qual_type)) |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 859 | { |
| 860 | TagDecl *tag_decl = tag_type->getDecl(); |
| 861 | |
| 862 | m_decls.push_back(tag_decl); |
| 863 | |
| 864 | return tag_decl; |
| 865 | } |
Sean Callanan | d5b3c35 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 866 | else if (const ObjCObjectType *objc_object_type = dyn_cast<clang::ObjCObjectType>(qual_type)) |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 867 | { |
| 868 | ObjCInterfaceDecl *interface_decl = objc_object_type->getInterface(); |
| 869 | |
| 870 | m_decls.push_back((NamedDecl*)interface_decl); |
| 871 | |
| 872 | return (NamedDecl*)interface_decl; |
| 873 | } |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 874 | } |
Greg Clayton | a1aaaff | 2011-01-23 00:34:52 +0000 | [diff] [blame] | 875 | return NULL; |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 876 | } |
Greg Clayton | e6d72ca | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 877 | |
| 878 | void |
| 879 | NameSearchContext::AddLookupResult (clang::DeclContextLookupConstResult result) |
| 880 | { |
| 881 | for (clang::NamedDecl * const *decl_iterator = result.first; |
| 882 | decl_iterator != result.second; |
| 883 | ++decl_iterator) |
| 884 | m_decls.push_back (*decl_iterator); |
| 885 | } |
| 886 | |
| 887 | void |
| 888 | NameSearchContext::AddNamedDecl (clang::NamedDecl *decl) |
| 889 | { |
| 890 | m_decls.push_back (decl); |
| 891 | } |