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