File: | src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp |
Warning: | line 762, column 38 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===-- ClangASTSource.cpp ------------------------------------------------===// | ||||
2 | // | ||||
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
4 | // See https://llvm.org/LICENSE.txt for license information. | ||||
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
6 | // | ||||
7 | //===----------------------------------------------------------------------===// | ||||
8 | |||||
9 | #include "ClangASTSource.h" | ||||
10 | |||||
11 | #include "ClangDeclVendor.h" | ||||
12 | #include "ClangModulesDeclVendor.h" | ||||
13 | |||||
14 | #include "lldb/Core/Module.h" | ||||
15 | #include "lldb/Core/ModuleList.h" | ||||
16 | #include "lldb/Symbol/CompilerDeclContext.h" | ||||
17 | #include "lldb/Symbol/Function.h" | ||||
18 | #include "lldb/Symbol/SymbolFile.h" | ||||
19 | #include "lldb/Symbol/TaggedASTType.h" | ||||
20 | #include "lldb/Target/Target.h" | ||||
21 | #include "lldb/Utility/Log.h" | ||||
22 | #include "clang/AST/ASTContext.h" | ||||
23 | #include "clang/AST/RecordLayout.h" | ||||
24 | #include "clang/Basic/SourceManager.h" | ||||
25 | |||||
26 | #include "Plugins/ExpressionParser/Clang/ClangUtil.h" | ||||
27 | #include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h" | ||||
28 | #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" | ||||
29 | |||||
30 | #include <memory> | ||||
31 | #include <vector> | ||||
32 | |||||
33 | using namespace clang; | ||||
34 | using namespace lldb_private; | ||||
35 | |||||
36 | // Scoped class that will remove an active lexical decl from the set when it | ||||
37 | // goes out of scope. | ||||
38 | namespace { | ||||
39 | class ScopedLexicalDeclEraser { | ||||
40 | public: | ||||
41 | ScopedLexicalDeclEraser(std::set<const clang::Decl *> &decls, | ||||
42 | const clang::Decl *decl) | ||||
43 | : m_active_lexical_decls(decls), m_decl(decl) {} | ||||
44 | |||||
45 | ~ScopedLexicalDeclEraser() { m_active_lexical_decls.erase(m_decl); } | ||||
46 | |||||
47 | private: | ||||
48 | std::set<const clang::Decl *> &m_active_lexical_decls; | ||||
49 | const clang::Decl *m_decl; | ||||
50 | }; | ||||
51 | } | ||||
52 | |||||
53 | ClangASTSource::ClangASTSource( | ||||
54 | const lldb::TargetSP &target, | ||||
55 | const std::shared_ptr<ClangASTImporter> &importer) | ||||
56 | : m_lookups_enabled(false), m_target(target), m_ast_context(nullptr), | ||||
57 | m_ast_importer_sp(importer), m_active_lexical_decls(), | ||||
58 | m_active_lookups() { | ||||
59 | assert(m_ast_importer_sp && "No ClangASTImporter passed to ClangASTSource?")((void)0); | ||||
60 | } | ||||
61 | |||||
62 | void ClangASTSource::InstallASTContext(TypeSystemClang &clang_ast_context) { | ||||
63 | m_ast_context = &clang_ast_context.getASTContext(); | ||||
64 | m_clang_ast_context = &clang_ast_context; | ||||
65 | m_file_manager = &m_ast_context->getSourceManager().getFileManager(); | ||||
66 | m_ast_importer_sp->InstallMapCompleter(m_ast_context, *this); | ||||
67 | } | ||||
68 | |||||
69 | ClangASTSource::~ClangASTSource() { | ||||
70 | m_ast_importer_sp->ForgetDestination(m_ast_context); | ||||
71 | |||||
72 | if (!m_target) | ||||
73 | return; | ||||
74 | |||||
75 | // Unregister the current ASTContext as a source for all scratch | ||||
76 | // ASTContexts in the ClangASTImporter. Without this the scratch AST might | ||||
77 | // query the deleted ASTContext for additional type information. | ||||
78 | // We unregister from *all* scratch ASTContexts in case a type got exported | ||||
79 | // to a scratch AST that isn't the best fitting scratch ASTContext. | ||||
80 | TypeSystemClang *scratch_ast = ScratchTypeSystemClang::GetForTarget( | ||||
81 | *m_target, ScratchTypeSystemClang::DefaultAST, false); | ||||
82 | |||||
83 | if (!scratch_ast) | ||||
84 | return; | ||||
85 | |||||
86 | ScratchTypeSystemClang *default_scratch_ast = | ||||
87 | llvm::cast<ScratchTypeSystemClang>(scratch_ast); | ||||
88 | // Unregister from the default scratch AST (and all sub-ASTs). | ||||
89 | default_scratch_ast->ForgetSource(m_ast_context, *m_ast_importer_sp); | ||||
90 | } | ||||
91 | |||||
92 | void ClangASTSource::StartTranslationUnit(ASTConsumer *Consumer) { | ||||
93 | if (!m_ast_context) | ||||
94 | return; | ||||
95 | |||||
96 | m_ast_context->getTranslationUnitDecl()->setHasExternalVisibleStorage(); | ||||
97 | m_ast_context->getTranslationUnitDecl()->setHasExternalLexicalStorage(); | ||||
98 | } | ||||
99 | |||||
100 | // The core lookup interface. | ||||
101 | bool ClangASTSource::FindExternalVisibleDeclsByName( | ||||
102 | const DeclContext *decl_ctx, DeclarationName clang_decl_name) { | ||||
103 | if (!m_ast_context) { | ||||
104 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); | ||||
105 | return false; | ||||
106 | } | ||||
107 | |||||
108 | std::string decl_name(clang_decl_name.getAsString()); | ||||
109 | |||||
110 | switch (clang_decl_name.getNameKind()) { | ||||
111 | // Normal identifiers. | ||||
112 | case DeclarationName::Identifier: { | ||||
113 | clang::IdentifierInfo *identifier_info = | ||||
114 | clang_decl_name.getAsIdentifierInfo(); | ||||
115 | |||||
116 | if (!identifier_info || identifier_info->getBuiltinID() != 0) { | ||||
117 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); | ||||
118 | return false; | ||||
119 | } | ||||
120 | } break; | ||||
121 | |||||
122 | // Operator names. | ||||
123 | case DeclarationName::CXXOperatorName: | ||||
124 | case DeclarationName::CXXLiteralOperatorName: | ||||
125 | break; | ||||
126 | |||||
127 | // Using directives found in this context. | ||||
128 | // Tell Sema we didn't find any or we'll end up getting asked a *lot*. | ||||
129 | case DeclarationName::CXXUsingDirective: | ||||
130 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); | ||||
131 | return false; | ||||
132 | |||||
133 | case DeclarationName::ObjCZeroArgSelector: | ||||
134 | case DeclarationName::ObjCOneArgSelector: | ||||
135 | case DeclarationName::ObjCMultiArgSelector: { | ||||
136 | llvm::SmallVector<NamedDecl *, 1> method_decls; | ||||
137 | |||||
138 | NameSearchContext method_search_context(*m_clang_ast_context, method_decls, | ||||
139 | clang_decl_name, decl_ctx); | ||||
140 | |||||
141 | FindObjCMethodDecls(method_search_context); | ||||
142 | |||||
143 | SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, method_decls); | ||||
144 | return (method_decls.size() > 0); | ||||
145 | } | ||||
146 | // These aren't possible in the global context. | ||||
147 | case DeclarationName::CXXConstructorName: | ||||
148 | case DeclarationName::CXXDestructorName: | ||||
149 | case DeclarationName::CXXConversionFunctionName: | ||||
150 | case DeclarationName::CXXDeductionGuideName: | ||||
151 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); | ||||
152 | return false; | ||||
153 | } | ||||
154 | |||||
155 | if (!GetLookupsEnabled()) { | ||||
156 | // Wait until we see a '$' at the start of a name before we start doing any | ||||
157 | // lookups so we can avoid lookup up all of the builtin types. | ||||
158 | if (!decl_name.empty() && decl_name[0] == '$') { | ||||
159 | SetLookupsEnabled(true); | ||||
160 | } else { | ||||
161 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); | ||||
162 | return false; | ||||
163 | } | ||||
164 | } | ||||
165 | |||||
166 | ConstString const_decl_name(decl_name.c_str()); | ||||
167 | |||||
168 | const char *uniqued_const_decl_name = const_decl_name.GetCString(); | ||||
169 | if (m_active_lookups.find(uniqued_const_decl_name) != | ||||
170 | m_active_lookups.end()) { | ||||
171 | // We are currently looking up this name... | ||||
172 | SetNoExternalVisibleDeclsForName(decl_ctx, clang_decl_name); | ||||
173 | return false; | ||||
174 | } | ||||
175 | m_active_lookups.insert(uniqued_const_decl_name); | ||||
176 | llvm::SmallVector<NamedDecl *, 4> name_decls; | ||||
177 | NameSearchContext name_search_context(*m_clang_ast_context, name_decls, | ||||
178 | clang_decl_name, decl_ctx); | ||||
179 | FindExternalVisibleDecls(name_search_context); | ||||
180 | SetExternalVisibleDeclsForName(decl_ctx, clang_decl_name, name_decls); | ||||
181 | m_active_lookups.erase(uniqued_const_decl_name); | ||||
182 | return (name_decls.size() != 0); | ||||
183 | } | ||||
184 | |||||
185 | TagDecl *ClangASTSource::FindCompleteType(const TagDecl *decl) { | ||||
186 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
187 | |||||
188 | if (const NamespaceDecl *namespace_context = | ||||
189 | dyn_cast<NamespaceDecl>(decl->getDeclContext())) { | ||||
190 | ClangASTImporter::NamespaceMapSP namespace_map = | ||||
191 | m_ast_importer_sp->GetNamespaceMap(namespace_context); | ||||
192 | |||||
193 | LLDB_LOGV(log, " CTD Inspecting namespace map{0} ({1} entries)",do { ::lldb_private::Log *log_private = (log); if (log_private && log_private->GetVerbose()) log_private->Format ("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CTD Inspecting namespace map{0} ({1} entries)" , namespace_map.get(), namespace_map->size()); } while (0) | ||||
194 | namespace_map.get(), namespace_map->size())do { ::lldb_private::Log *log_private = (log); if (log_private && log_private->GetVerbose()) log_private->Format ("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CTD Inspecting namespace map{0} ({1} entries)" , namespace_map.get(), namespace_map->size()); } while (0); | ||||
195 | |||||
196 | if (!namespace_map) | ||||
197 | return nullptr; | ||||
198 | |||||
199 | for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) { | ||||
200 | LLDB_LOG(log, " CTD Searching namespace {0} in module {1}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CTD Searching namespace {0} in module {1}" , item.second.GetName(), item.first->GetFileSpec().GetFilename ()); } while (0) | ||||
201 | item.second.GetName(), item.first->GetFileSpec().GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CTD Searching namespace {0} in module {1}" , item.second.GetName(), item.first->GetFileSpec().GetFilename ()); } while (0); | ||||
202 | |||||
203 | TypeList types; | ||||
204 | |||||
205 | ConstString name(decl->getName()); | ||||
206 | |||||
207 | item.first->FindTypesInNamespace(name, item.second, UINT32_MAX0xffffffffU, types); | ||||
208 | |||||
209 | for (uint32_t ti = 0, te = types.GetSize(); ti != te; ++ti) { | ||||
210 | lldb::TypeSP type = types.GetTypeAtIndex(ti); | ||||
211 | |||||
212 | if (!type) | ||||
213 | continue; | ||||
214 | |||||
215 | CompilerType clang_type(type->GetFullCompilerType()); | ||||
216 | |||||
217 | if (!ClangUtil::IsClangType(clang_type)) | ||||
218 | continue; | ||||
219 | |||||
220 | const TagType *tag_type = | ||||
221 | ClangUtil::GetQualType(clang_type)->getAs<TagType>(); | ||||
222 | |||||
223 | if (!tag_type) | ||||
224 | continue; | ||||
225 | |||||
226 | TagDecl *candidate_tag_decl = | ||||
227 | const_cast<TagDecl *>(tag_type->getDecl()); | ||||
228 | |||||
229 | if (TypeSystemClang::GetCompleteDecl( | ||||
230 | &candidate_tag_decl->getASTContext(), candidate_tag_decl)) | ||||
231 | return candidate_tag_decl; | ||||
232 | } | ||||
233 | } | ||||
234 | } else { | ||||
235 | TypeList types; | ||||
236 | |||||
237 | ConstString name(decl->getName()); | ||||
238 | |||||
239 | const ModuleList &module_list = m_target->GetImages(); | ||||
240 | |||||
241 | bool exact_match = false; | ||||
242 | llvm::DenseSet<SymbolFile *> searched_symbol_files; | ||||
243 | module_list.FindTypes(nullptr, name, exact_match, UINT32_MAX0xffffffffU, | ||||
244 | searched_symbol_files, types); | ||||
245 | |||||
246 | for (uint32_t ti = 0, te = types.GetSize(); ti != te; ++ti) { | ||||
247 | lldb::TypeSP type = types.GetTypeAtIndex(ti); | ||||
248 | |||||
249 | if (!type) | ||||
250 | continue; | ||||
251 | |||||
252 | CompilerType clang_type(type->GetFullCompilerType()); | ||||
253 | |||||
254 | if (!ClangUtil::IsClangType(clang_type)) | ||||
255 | continue; | ||||
256 | |||||
257 | const TagType *tag_type = | ||||
258 | ClangUtil::GetQualType(clang_type)->getAs<TagType>(); | ||||
259 | |||||
260 | if (!tag_type) | ||||
261 | continue; | ||||
262 | |||||
263 | TagDecl *candidate_tag_decl = const_cast<TagDecl *>(tag_type->getDecl()); | ||||
264 | |||||
265 | // We have found a type by basename and we need to make sure the decl | ||||
266 | // contexts are the same before we can try to complete this type with | ||||
267 | // another | ||||
268 | if (!TypeSystemClang::DeclsAreEquivalent(const_cast<TagDecl *>(decl), | ||||
269 | candidate_tag_decl)) | ||||
270 | continue; | ||||
271 | |||||
272 | if (TypeSystemClang::GetCompleteDecl(&candidate_tag_decl->getASTContext(), | ||||
273 | candidate_tag_decl)) | ||||
274 | return candidate_tag_decl; | ||||
275 | } | ||||
276 | } | ||||
277 | return nullptr; | ||||
278 | } | ||||
279 | |||||
280 | void ClangASTSource::CompleteType(TagDecl *tag_decl) { | ||||
281 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
282 | |||||
283 | if (log) { | ||||
284 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CompleteTagDecl on (ASTContext*){0} Completing " "(TagDecl*){1} named {2}", m_clang_ast_context->getDisplayName (), tag_decl, tag_decl->getName()); } while (0) | ||||
285 | " CompleteTagDecl on (ASTContext*){0} Completing "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CompleteTagDecl on (ASTContext*){0} Completing " "(TagDecl*){1} named {2}", m_clang_ast_context->getDisplayName (), tag_decl, tag_decl->getName()); } while (0) | ||||
286 | "(TagDecl*){1} named {2}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CompleteTagDecl on (ASTContext*){0} Completing " "(TagDecl*){1} named {2}", m_clang_ast_context->getDisplayName (), tag_decl, tag_decl->getName()); } while (0) | ||||
287 | m_clang_ast_context->getDisplayName(), tag_decl,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CompleteTagDecl on (ASTContext*){0} Completing " "(TagDecl*){1} named {2}", m_clang_ast_context->getDisplayName (), tag_decl, tag_decl->getName()); } while (0) | ||||
288 | tag_decl->getName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CompleteTagDecl on (ASTContext*){0} Completing " "(TagDecl*){1} named {2}", m_clang_ast_context->getDisplayName (), tag_decl, tag_decl->getName()); } while (0); | ||||
289 | |||||
290 | LLDB_LOG(log, " CTD Before:\n{0}", ClangUtil::DumpDecl(tag_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CTD Before:\n{0}", ClangUtil::DumpDecl(tag_decl )); } while (0); | ||||
291 | } | ||||
292 | |||||
293 | auto iter = m_active_lexical_decls.find(tag_decl); | ||||
294 | if (iter != m_active_lexical_decls.end()) | ||||
295 | return; | ||||
296 | m_active_lexical_decls.insert(tag_decl); | ||||
297 | ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl); | ||||
298 | |||||
299 | if (!m_ast_importer_sp->CompleteTagDecl(tag_decl)) { | ||||
300 | // We couldn't complete the type. Maybe there's a definition somewhere | ||||
301 | // else that can be completed. | ||||
302 | if (TagDecl *alternate = FindCompleteType(tag_decl)) | ||||
303 | m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl, alternate); | ||||
304 | } | ||||
305 | |||||
306 | LLDB_LOG(log, " [CTD] After:\n{0}", ClangUtil::DumpDecl(tag_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [CTD] After:\n{0}", ClangUtil::DumpDecl(tag_decl )); } while (0); | ||||
307 | } | ||||
308 | |||||
309 | void ClangASTSource::CompleteType(clang::ObjCInterfaceDecl *interface_decl) { | ||||
310 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
311 | |||||
312 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [CompleteObjCInterfaceDecl] on (ASTContext*){0} '{1}' " "Completing an ObjCInterfaceDecl named {1}", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName()); } while (0) | ||||
313 | " [CompleteObjCInterfaceDecl] on (ASTContext*){0} '{1}' "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [CompleteObjCInterfaceDecl] on (ASTContext*){0} '{1}' " "Completing an ObjCInterfaceDecl named {1}", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName()); } while (0) | ||||
314 | "Completing an ObjCInterfaceDecl named {1}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [CompleteObjCInterfaceDecl] on (ASTContext*){0} '{1}' " "Completing an ObjCInterfaceDecl named {1}", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName()); } while (0) | ||||
315 | m_ast_context, m_clang_ast_context->getDisplayName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [CompleteObjCInterfaceDecl] on (ASTContext*){0} '{1}' " "Completing an ObjCInterfaceDecl named {1}", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName()); } while (0) | ||||
316 | interface_decl->getName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [CompleteObjCInterfaceDecl] on (ASTContext*){0} '{1}' " "Completing an ObjCInterfaceDecl named {1}", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName()); } while (0); | ||||
317 | LLDB_LOG(log, " [COID] Before:\n{0}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [COID] Before:\n{0}", ClangUtil::DumpDecl( interface_decl)); } while (0) | ||||
318 | ClangUtil::DumpDecl(interface_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [COID] Before:\n{0}", ClangUtil::DumpDecl( interface_decl)); } while (0); | ||||
319 | |||||
320 | ClangASTImporter::DeclOrigin original = m_ast_importer_sp->GetDeclOrigin(interface_decl); | ||||
321 | |||||
322 | if (original.Valid()) { | ||||
323 | if (ObjCInterfaceDecl *original_iface_decl = | ||||
324 | dyn_cast<ObjCInterfaceDecl>(original.decl)) { | ||||
325 | ObjCInterfaceDecl *complete_iface_decl = | ||||
326 | GetCompleteObjCInterface(original_iface_decl); | ||||
327 | |||||
328 | if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) { | ||||
329 | m_ast_importer_sp->SetDeclOrigin(interface_decl, complete_iface_decl); | ||||
330 | } | ||||
331 | } | ||||
332 | } | ||||
333 | |||||
334 | m_ast_importer_sp->CompleteObjCInterfaceDecl(interface_decl); | ||||
335 | |||||
336 | if (interface_decl->getSuperClass() && | ||||
337 | interface_decl->getSuperClass() != interface_decl) | ||||
338 | CompleteType(interface_decl->getSuperClass()); | ||||
339 | |||||
340 | LLDB_LOG(log, " [COID] After:")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [COID] After:"); } while (0); | ||||
341 | LLDB_LOG(log, " [COID] {0}", ClangUtil::DumpDecl(interface_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " [COID] {0}", ClangUtil::DumpDecl(interface_decl )); } while (0); | ||||
342 | } | ||||
343 | |||||
344 | clang::ObjCInterfaceDecl *ClangASTSource::GetCompleteObjCInterface( | ||||
345 | const clang::ObjCInterfaceDecl *interface_decl) { | ||||
346 | lldb::ProcessSP process(m_target->GetProcessSP()); | ||||
347 | |||||
348 | if (!process) | ||||
349 | return nullptr; | ||||
350 | |||||
351 | ObjCLanguageRuntime *language_runtime(ObjCLanguageRuntime::Get(*process)); | ||||
352 | |||||
353 | if (!language_runtime) | ||||
354 | return nullptr; | ||||
355 | |||||
356 | ConstString class_name(interface_decl->getNameAsString().c_str()); | ||||
357 | |||||
358 | lldb::TypeSP complete_type_sp( | ||||
359 | language_runtime->LookupInCompleteClassCache(class_name)); | ||||
360 | |||||
361 | if (!complete_type_sp) | ||||
362 | return nullptr; | ||||
363 | |||||
364 | TypeFromUser complete_type = | ||||
365 | TypeFromUser(complete_type_sp->GetFullCompilerType()); | ||||
366 | lldb::opaque_compiler_type_t complete_opaque_type = | ||||
367 | complete_type.GetOpaqueQualType(); | ||||
368 | |||||
369 | if (!complete_opaque_type) | ||||
370 | return nullptr; | ||||
371 | |||||
372 | const clang::Type *complete_clang_type = | ||||
373 | QualType::getFromOpaquePtr(complete_opaque_type).getTypePtr(); | ||||
374 | const ObjCInterfaceType *complete_interface_type = | ||||
375 | dyn_cast<ObjCInterfaceType>(complete_clang_type); | ||||
376 | |||||
377 | if (!complete_interface_type) | ||||
378 | return nullptr; | ||||
379 | |||||
380 | ObjCInterfaceDecl *complete_iface_decl(complete_interface_type->getDecl()); | ||||
381 | |||||
382 | return complete_iface_decl; | ||||
383 | } | ||||
384 | |||||
385 | void ClangASTSource::FindExternalLexicalDecls( | ||||
386 | const DeclContext *decl_context, | ||||
387 | llvm::function_ref<bool(Decl::Kind)> predicate, | ||||
388 | llvm::SmallVectorImpl<Decl *> &decls) { | ||||
389 | |||||
390 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
391 | |||||
392 | const Decl *context_decl = dyn_cast<Decl>(decl_context); | ||||
393 | |||||
394 | if (!context_decl) | ||||
395 | return; | ||||
396 | |||||
397 | auto iter = m_active_lexical_decls.find(context_decl); | ||||
398 | if (iter != m_active_lexical_decls.end()) | ||||
399 | return; | ||||
400 | m_active_lexical_decls.insert(context_decl); | ||||
401 | ScopedLexicalDeclEraser eraser(m_active_lexical_decls, context_decl); | ||||
402 | |||||
403 | if (log) { | ||||
404 | if (const NamedDecl *context_named_decl = dyn_cast<NamedDecl>(context_decl)) | ||||
405 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
406 | "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
407 | "'{2}' (%sDecl*){3}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
408 | m_ast_context, m_clang_ast_context->getDisplayName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
409 | context_named_decl->getNameAsString().c_str(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
410 | context_decl->getDeclKindName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
411 | static_cast<const void *>(context_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "'{2}' (%sDecl*){3}", m_ast_context, m_clang_ast_context-> getDisplayName(), context_named_decl->getNameAsString().c_str (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0); | ||||
412 | else if (context_decl) | ||||
413 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "({2}Decl*){3}", m_ast_context, m_clang_ast_context->getDisplayName (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
414 | "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "({2}Decl*){3}", m_ast_context, m_clang_ast_context->getDisplayName (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
415 | "({2}Decl*){3}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "({2}Decl*){3}", m_ast_context, m_clang_ast_context->getDisplayName (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
416 | m_ast_context, m_clang_ast_context->getDisplayName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "({2}Decl*){3}", m_ast_context, m_clang_ast_context->getDisplayName (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
417 | context_decl->getDeclKindName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "({2}Decl*){3}", m_ast_context, m_clang_ast_context->getDisplayName (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0) | ||||
418 | static_cast<const void *>(context_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in " "({2}Decl*){3}", m_ast_context, m_clang_ast_context->getDisplayName (), context_decl->getDeclKindName(), static_cast<const void *>(context_decl)); } while (0); | ||||
419 | else | ||||
420 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in a " "NULL context", m_ast_context, m_clang_ast_context->getDisplayName ()); } while (0) | ||||
421 | "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in a "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in a " "NULL context", m_ast_context, m_clang_ast_context->getDisplayName ()); } while (0) | ||||
422 | "NULL context",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in a " "NULL context", m_ast_context, m_clang_ast_context->getDisplayName ()); } while (0) | ||||
423 | m_ast_context, m_clang_ast_context->getDisplayName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "FindExternalLexicalDecls on (ASTContext*){0} '{1}' in a " "NULL context", m_ast_context, m_clang_ast_context->getDisplayName ()); } while (0); | ||||
424 | } | ||||
425 | |||||
426 | ClangASTImporter::DeclOrigin original = m_ast_importer_sp->GetDeclOrigin(context_decl); | ||||
427 | |||||
428 | if (!original.Valid()) | ||||
429 | return; | ||||
430 | |||||
431 | LLDB_LOG(log, " FELD Original decl {0} (Decl*){1:x}:\n{2}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Original decl {0} (Decl*){1:x}:\n{2}", static_cast <void *>(original.ctx), static_cast<void *>(original .decl), ClangUtil::DumpDecl(original.decl)); } while (0) | ||||
432 | static_cast<void *>(original.ctx),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Original decl {0} (Decl*){1:x}:\n{2}", static_cast <void *>(original.ctx), static_cast<void *>(original .decl), ClangUtil::DumpDecl(original.decl)); } while (0) | ||||
433 | static_cast<void *>(original.decl),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Original decl {0} (Decl*){1:x}:\n{2}", static_cast <void *>(original.ctx), static_cast<void *>(original .decl), ClangUtil::DumpDecl(original.decl)); } while (0) | ||||
434 | ClangUtil::DumpDecl(original.decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Original decl {0} (Decl*){1:x}:\n{2}", static_cast <void *>(original.ctx), static_cast<void *>(original .decl), ClangUtil::DumpDecl(original.decl)); } while (0); | ||||
435 | |||||
436 | if (ObjCInterfaceDecl *original_iface_decl = | ||||
437 | dyn_cast<ObjCInterfaceDecl>(original.decl)) { | ||||
438 | ObjCInterfaceDecl *complete_iface_decl = | ||||
439 | GetCompleteObjCInterface(original_iface_decl); | ||||
440 | |||||
441 | if (complete_iface_decl && (complete_iface_decl != original_iface_decl)) { | ||||
442 | original.decl = complete_iface_decl; | ||||
443 | original.ctx = &complete_iface_decl->getASTContext(); | ||||
444 | |||||
445 | m_ast_importer_sp->SetDeclOrigin(context_decl, complete_iface_decl); | ||||
446 | } | ||||
447 | } | ||||
448 | |||||
449 | if (TagDecl *original_tag_decl = dyn_cast<TagDecl>(original.decl)) { | ||||
450 | ExternalASTSource *external_source = original.ctx->getExternalSource(); | ||||
451 | |||||
452 | if (external_source) | ||||
453 | external_source->CompleteType(original_tag_decl); | ||||
454 | } | ||||
455 | |||||
456 | const DeclContext *original_decl_context = | ||||
457 | dyn_cast<DeclContext>(original.decl); | ||||
458 | |||||
459 | if (!original_decl_context) | ||||
460 | return; | ||||
461 | |||||
462 | // Indicates whether we skipped any Decls of the original DeclContext. | ||||
463 | bool SkippedDecls = false; | ||||
464 | for (Decl *decl : original_decl_context->decls()) { | ||||
465 | // The predicate function returns true if the passed declaration kind is | ||||
466 | // the one we are looking for. | ||||
467 | // See clang::ExternalASTSource::FindExternalLexicalDecls() | ||||
468 | if (predicate(decl->getKind())) { | ||||
469 | if (log) { | ||||
470 | std::string ast_dump = ClangUtil::DumpDecl(decl); | ||||
471 | if (const NamedDecl *context_named_decl = | ||||
472 | dyn_cast<NamedDecl>(context_decl)) | ||||
473 | LLDB_LOG(log, " FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}" , context_named_decl->getDeclKindName(), context_named_decl ->getName(), decl->getDeclKindName(), ast_dump); } while (0) | ||||
474 | context_named_decl->getDeclKindName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}" , context_named_decl->getDeclKindName(), context_named_decl ->getName(), decl->getDeclKindName(), ast_dump); } while (0) | ||||
475 | context_named_decl->getName(), decl->getDeclKindName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}" , context_named_decl->getDeclKindName(), context_named_decl ->getName(), decl->getDeclKindName(), ast_dump); } while (0) | ||||
476 | ast_dump)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Adding [to {0}Decl {1}] lexical {2}Decl {3}" , context_named_decl->getDeclKindName(), context_named_decl ->getName(), decl->getDeclKindName(), ast_dump); } while (0); | ||||
477 | else | ||||
478 | LLDB_LOG(log, " FELD Adding lexical {0}Decl {1}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Adding lexical {0}Decl {1}", decl->getDeclKindName (), ast_dump); } while (0) | ||||
479 | decl->getDeclKindName(), ast_dump)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " FELD Adding lexical {0}Decl {1}", decl->getDeclKindName (), ast_dump); } while (0); | ||||
480 | } | ||||
481 | |||||
482 | CopyDecl(decl); | ||||
483 | |||||
484 | // FIXME: We should add the copied decl to the 'decls' list. This would | ||||
485 | // add the copied Decl into the DeclContext and make sure that we | ||||
486 | // correctly propagate that we added some Decls back to Clang. | ||||
487 | // By leaving 'decls' empty we incorrectly return false from | ||||
488 | // DeclContext::LoadLexicalDeclsFromExternalStorage which might cause | ||||
489 | // lookup issues later on. | ||||
490 | // We can't just add them for now as the ASTImporter already added the | ||||
491 | // decl into the DeclContext and this would add it twice. | ||||
492 | } else { | ||||
493 | SkippedDecls = true; | ||||
494 | } | ||||
495 | } | ||||
496 | |||||
497 | // CopyDecl may build a lookup table which may set up ExternalLexicalStorage | ||||
498 | // to false. However, since we skipped some of the external Decls we must | ||||
499 | // set it back! | ||||
500 | if (SkippedDecls) { | ||||
501 | decl_context->setHasExternalLexicalStorage(true); | ||||
502 | // This sets HasLazyExternalLexicalLookups to true. By setting this bit we | ||||
503 | // ensure that the lookup table is rebuilt, which means the external source | ||||
504 | // is consulted again when a clang::DeclContext::lookup is called. | ||||
505 | const_cast<DeclContext *>(decl_context)->setMustBuildLookupTable(); | ||||
506 | } | ||||
507 | |||||
508 | return; | ||||
509 | } | ||||
510 | |||||
511 | void ClangASTSource::FindExternalVisibleDecls(NameSearchContext &context) { | ||||
512 | assert(m_ast_context)((void)0); | ||||
513 | |||||
514 | const ConstString name(context.m_decl_name.getAsString().c_str()); | ||||
515 | |||||
516 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
517 | |||||
518 | if (log) { | ||||
519 | if (!context.m_decl_context) | ||||
520 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a NULL DeclContext" , m_ast_context, m_clang_ast_context->getDisplayName(), name ); } while (0) | ||||
521 | "ClangASTSource::FindExternalVisibleDecls on "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a NULL DeclContext" , m_ast_context, m_clang_ast_context->getDisplayName(), name ); } while (0) | ||||
522 | "(ASTContext*){0} '{1}' for '{2}' in a NULL DeclContext",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a NULL DeclContext" , m_ast_context, m_clang_ast_context->getDisplayName(), name ); } while (0) | ||||
523 | m_ast_context, m_clang_ast_context->getDisplayName(), name)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a NULL DeclContext" , m_ast_context, m_clang_ast_context->getDisplayName(), name ); } while (0); | ||||
524 | else if (const NamedDecl *context_named_decl = | ||||
525 | dyn_cast<NamedDecl>(context.m_decl_context)) | ||||
526 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context_named_decl->getName()); } while (0) | ||||
527 | "ClangASTSource::FindExternalVisibleDecls on "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context_named_decl->getName()); } while (0) | ||||
528 | "(ASTContext*){0} '{1}' for '{2}' in '{3}'",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context_named_decl->getName()); } while (0) | ||||
529 | m_ast_context, m_clang_ast_context->getDisplayName(), name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context_named_decl->getName()); } while (0) | ||||
530 | context_named_decl->getName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context_named_decl->getName()); } while (0); | ||||
531 | else | ||||
532 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context.m_decl_context->getDeclKindName()); } while (0) | ||||
533 | "ClangASTSource::FindExternalVisibleDecls on "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context.m_decl_context->getDeclKindName()); } while (0) | ||||
534 | "(ASTContext*){0} '{1}' for '{2}' in a '{3}'",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context.m_decl_context->getDeclKindName()); } while (0) | ||||
535 | m_ast_context, m_clang_ast_context->getDisplayName(), name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context.m_decl_context->getDeclKindName()); } while (0) | ||||
536 | context.m_decl_context->getDeclKindName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindExternalVisibleDecls on " "(ASTContext*){0} '{1}' for '{2}' in a '{3}'" , m_ast_context, m_clang_ast_context->getDisplayName(), name , context.m_decl_context->getDeclKindName()); } while (0); | ||||
537 | } | ||||
538 | |||||
539 | if (isa<NamespaceDecl>(context.m_decl_context)) { | ||||
540 | LookupInNamespace(context); | ||||
541 | } else if (isa<ObjCInterfaceDecl>(context.m_decl_context)) { | ||||
542 | FindObjCPropertyAndIvarDecls(context); | ||||
543 | } else if (!isa<TranslationUnitDecl>(context.m_decl_context)) { | ||||
544 | // we shouldn't be getting FindExternalVisibleDecls calls for these | ||||
545 | return; | ||||
546 | } else { | ||||
547 | CompilerDeclContext namespace_decl; | ||||
548 | |||||
549 | LLDB_LOG(log, " CAS::FEVD Searching the root namespace")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Searching the root namespace"); } while (0); | ||||
550 | |||||
551 | FindExternalVisibleDecls(context, lldb::ModuleSP(), namespace_decl); | ||||
552 | } | ||||
553 | |||||
554 | if (!context.m_namespace_map->empty()) { | ||||
555 | if (log && log->GetVerbose()) | ||||
556 | LLDB_LOG(log, " CAS::FEVD Registering namespace map {0} ({1} entries)",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Registering namespace map {0} ({1} entries)" , context.m_namespace_map.get(), context.m_namespace_map-> size()); } while (0) | ||||
557 | context.m_namespace_map.get(), context.m_namespace_map->size())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Registering namespace map {0} ({1} entries)" , context.m_namespace_map.get(), context.m_namespace_map-> size()); } while (0); | ||||
558 | |||||
559 | NamespaceDecl *clang_namespace_decl = | ||||
560 | AddNamespace(context, context.m_namespace_map); | ||||
561 | |||||
562 | if (clang_namespace_decl) | ||||
563 | clang_namespace_decl->setHasExternalVisibleStorage(); | ||||
564 | } | ||||
565 | } | ||||
566 | |||||
567 | clang::Sema *ClangASTSource::getSema() { | ||||
568 | return m_clang_ast_context->getSema(); | ||||
569 | } | ||||
570 | |||||
571 | bool ClangASTSource::IgnoreName(const ConstString name, | ||||
572 | bool ignore_all_dollar_names) { | ||||
573 | static const ConstString id_name("id"); | ||||
574 | static const ConstString Class_name("Class"); | ||||
575 | |||||
576 | if (m_ast_context->getLangOpts().ObjC) | ||||
577 | if (name == id_name || name == Class_name) | ||||
578 | return true; | ||||
579 | |||||
580 | StringRef name_string_ref = name.GetStringRef(); | ||||
581 | |||||
582 | // The ClangASTSource is not responsible for finding $-names. | ||||
583 | return name_string_ref.empty() || | ||||
584 | (ignore_all_dollar_names && name_string_ref.startswith("$")) || | ||||
585 | name_string_ref.startswith("_$"); | ||||
586 | } | ||||
587 | |||||
588 | void ClangASTSource::FindExternalVisibleDecls( | ||||
589 | NameSearchContext &context, lldb::ModuleSP module_sp, | ||||
590 | CompilerDeclContext &namespace_decl) { | ||||
591 | assert(m_ast_context)((void)0); | ||||
592 | |||||
593 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
594 | |||||
595 | SymbolContextList sc_list; | ||||
596 | |||||
597 | const ConstString name(context.m_decl_name.getAsString().c_str()); | ||||
598 | if (IgnoreName(name, true)) | ||||
599 | return; | ||||
600 | |||||
601 | if (!m_target) | ||||
602 | return; | ||||
603 | |||||
604 | FillNamespaceMap(context, module_sp, namespace_decl); | ||||
605 | |||||
606 | if (context.m_found_type) | ||||
607 | return; | ||||
608 | |||||
609 | TypeList types; | ||||
610 | const bool exact_match = true; | ||||
611 | llvm::DenseSet<lldb_private::SymbolFile *> searched_symbol_files; | ||||
612 | if (module_sp && namespace_decl) | ||||
613 | module_sp->FindTypesInNamespace(name, namespace_decl, 1, types); | ||||
614 | else { | ||||
615 | m_target->GetImages().FindTypes(module_sp.get(), name, exact_match, 1, | ||||
616 | searched_symbol_files, types); | ||||
617 | } | ||||
618 | |||||
619 | if (size_t num_types = types.GetSize()) { | ||||
620 | for (size_t ti = 0; ti < num_types; ++ti) { | ||||
621 | lldb::TypeSP type_sp = types.GetTypeAtIndex(ti); | ||||
622 | |||||
623 | if (log) { | ||||
624 | const char *name_string = type_sp->GetName().GetCString(); | ||||
625 | |||||
626 | LLDB_LOG(log, " CAS::FEVD Matching type found for \"{0}\": {1}", name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Matching type found for \"{0}\": {1}" , name, (name_string ? name_string : "<anonymous>")); } while (0) | ||||
627 | (name_string ? name_string : "<anonymous>"))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Matching type found for \"{0}\": {1}" , name, (name_string ? name_string : "<anonymous>")); } while (0); | ||||
628 | } | ||||
629 | |||||
630 | CompilerType full_type = type_sp->GetFullCompilerType(); | ||||
631 | |||||
632 | CompilerType copied_clang_type(GuardedCopyType(full_type)); | ||||
633 | |||||
634 | if (!copied_clang_type) { | ||||
635 | LLDB_LOG(log, " CAS::FEVD - Couldn't export a type")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD - Couldn't export a type"); } while ( 0); | ||||
636 | |||||
637 | continue; | ||||
638 | } | ||||
639 | |||||
640 | context.AddTypeDecl(copied_clang_type); | ||||
641 | |||||
642 | context.m_found_type = true; | ||||
643 | break; | ||||
644 | } | ||||
645 | } | ||||
646 | |||||
647 | if (!context.m_found_type) { | ||||
648 | // Try the modules next. | ||||
649 | FindDeclInModules(context, name); | ||||
650 | } | ||||
651 | |||||
652 | if (!context.m_found_type) { | ||||
653 | FindDeclInObjCRuntime(context, name); | ||||
654 | } | ||||
655 | } | ||||
656 | |||||
657 | void ClangASTSource::FillNamespaceMap( | ||||
658 | NameSearchContext &context, lldb::ModuleSP module_sp, | ||||
659 | const CompilerDeclContext &namespace_decl) { | ||||
660 | const ConstString name(context.m_decl_name.getAsString().c_str()); | ||||
661 | if (IgnoreName(name, true)) | ||||
662 | return; | ||||
663 | |||||
664 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
665 | |||||
666 | if (module_sp && namespace_decl) { | ||||
667 | CompilerDeclContext found_namespace_decl; | ||||
668 | |||||
669 | if (SymbolFile *symbol_file = module_sp->GetSymbolFile()) { | ||||
670 | found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl); | ||||
671 | |||||
672 | if (found_namespace_decl) { | ||||
673 | context.m_namespace_map->push_back( | ||||
674 | std::pair<lldb::ModuleSP, CompilerDeclContext>( | ||||
675 | module_sp, found_namespace_decl)); | ||||
676 | |||||
677 | LLDB_LOG(log, " CAS::FEVD Found namespace {0} in module {1}", name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Found namespace {0} in module {1}", name , module_sp->GetFileSpec().GetFilename()); } while (0) | ||||
678 | module_sp->GetFileSpec().GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Found namespace {0} in module {1}", name , module_sp->GetFileSpec().GetFilename()); } while (0); | ||||
679 | } | ||||
680 | } | ||||
681 | return; | ||||
682 | } | ||||
683 | |||||
684 | for (lldb::ModuleSP image : m_target->GetImages().Modules()) { | ||||
685 | if (!image) | ||||
686 | continue; | ||||
687 | |||||
688 | CompilerDeclContext found_namespace_decl; | ||||
689 | |||||
690 | SymbolFile *symbol_file = image->GetSymbolFile(); | ||||
691 | |||||
692 | if (!symbol_file) | ||||
693 | continue; | ||||
694 | |||||
695 | found_namespace_decl = symbol_file->FindNamespace(name, namespace_decl); | ||||
696 | |||||
697 | if (found_namespace_decl) { | ||||
698 | context.m_namespace_map->push_back( | ||||
699 | std::pair<lldb::ModuleSP, CompilerDeclContext>(image, | ||||
700 | found_namespace_decl)); | ||||
701 | |||||
702 | LLDB_LOG(log, " CAS::FEVD Found namespace {0} in module {1}", name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Found namespace {0} in module {1}", name , image->GetFileSpec().GetFilename()); } while (0) | ||||
703 | image->GetFileSpec().GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Found namespace {0} in module {1}", name , image->GetFileSpec().GetFilename()); } while (0); | ||||
704 | } | ||||
705 | } | ||||
706 | } | ||||
707 | |||||
708 | template <class D> class TaggedASTDecl { | ||||
709 | public: | ||||
710 | TaggedASTDecl() : decl(nullptr) {} | ||||
711 | TaggedASTDecl(D *_decl) : decl(_decl) {} | ||||
712 | bool IsValid() const { return (decl != nullptr); } | ||||
713 | bool IsInvalid() const { return !IsValid(); } | ||||
714 | D *operator->() const { return decl; } | ||||
715 | D *decl; | ||||
716 | }; | ||||
717 | |||||
718 | template <class D2, template <class D> class TD, class D1> | ||||
719 | TD<D2> DynCast(TD<D1> source) { | ||||
720 | return TD<D2>(dyn_cast<D2>(source.decl)); | ||||
721 | } | ||||
722 | |||||
723 | template <class D = Decl> class DeclFromParser; | ||||
724 | template <class D = Decl> class DeclFromUser; | ||||
725 | |||||
726 | template <class D> class DeclFromParser : public TaggedASTDecl<D> { | ||||
727 | public: | ||||
728 | DeclFromParser() : TaggedASTDecl<D>() {} | ||||
729 | DeclFromParser(D *_decl) : TaggedASTDecl<D>(_decl) {} | ||||
730 | |||||
731 | DeclFromUser<D> GetOrigin(ClangASTSource &source); | ||||
732 | }; | ||||
733 | |||||
734 | template <class D> class DeclFromUser : public TaggedASTDecl<D> { | ||||
735 | public: | ||||
736 | DeclFromUser() : TaggedASTDecl<D>() {} | ||||
737 | DeclFromUser(D *_decl) : TaggedASTDecl<D>(_decl) {} | ||||
738 | |||||
739 | DeclFromParser<D> Import(ClangASTSource &source); | ||||
740 | }; | ||||
741 | |||||
742 | template <class D> | ||||
743 | DeclFromUser<D> DeclFromParser<D>::GetOrigin(ClangASTSource &source) { | ||||
744 | ClangASTImporter::DeclOrigin origin = source.GetDeclOrigin(this->decl); | ||||
745 | if (!origin.Valid()) | ||||
746 | return DeclFromUser<D>(); | ||||
747 | return DeclFromUser<D>(dyn_cast<D>(origin.decl)); | ||||
748 | } | ||||
749 | |||||
750 | template <class D> | ||||
751 | DeclFromParser<D> DeclFromUser<D>::Import(ClangASTSource &source) { | ||||
752 | DeclFromParser<> parser_generic_decl(source.CopyDecl(this->decl)); | ||||
753 | if (parser_generic_decl.IsInvalid()) | ||||
754 | return DeclFromParser<D>(); | ||||
755 | return DeclFromParser<D>(dyn_cast<D>(parser_generic_decl.decl)); | ||||
756 | } | ||||
757 | |||||
758 | bool ClangASTSource::FindObjCMethodDeclsWithOrigin( | ||||
759 | NameSearchContext &context, ObjCInterfaceDecl *original_interface_decl, | ||||
760 | const char *log_info) { | ||||
761 | const DeclarationName &decl_name(context.m_decl_name); | ||||
762 | clang::ASTContext *original_ctx = &original_interface_decl->getASTContext(); | ||||
| |||||
763 | |||||
764 | Selector original_selector; | ||||
765 | |||||
766 | if (decl_name.isObjCZeroArgSelector()) { | ||||
767 | IdentifierInfo *ident = &original_ctx->Idents.get(decl_name.getAsString()); | ||||
768 | original_selector = original_ctx->Selectors.getSelector(0, &ident); | ||||
769 | } else if (decl_name.isObjCOneArgSelector()) { | ||||
770 | const std::string &decl_name_string = decl_name.getAsString(); | ||||
771 | std::string decl_name_string_without_colon(decl_name_string.c_str(), | ||||
772 | decl_name_string.length() - 1); | ||||
773 | IdentifierInfo *ident = | ||||
774 | &original_ctx->Idents.get(decl_name_string_without_colon); | ||||
775 | original_selector = original_ctx->Selectors.getSelector(1, &ident); | ||||
776 | } else { | ||||
777 | SmallVector<IdentifierInfo *, 4> idents; | ||||
778 | |||||
779 | clang::Selector sel = decl_name.getObjCSelector(); | ||||
780 | |||||
781 | unsigned num_args = sel.getNumArgs(); | ||||
782 | |||||
783 | for (unsigned i = 0; i != num_args; ++i) { | ||||
784 | idents.push_back(&original_ctx->Idents.get(sel.getNameForSlot(i))); | ||||
785 | } | ||||
786 | |||||
787 | original_selector = | ||||
788 | original_ctx->Selectors.getSelector(num_args, idents.data()); | ||||
789 | } | ||||
790 | |||||
791 | DeclarationName original_decl_name(original_selector); | ||||
792 | |||||
793 | llvm::SmallVector<NamedDecl *, 1> methods; | ||||
794 | |||||
795 | TypeSystemClang::GetCompleteDecl(original_ctx, original_interface_decl); | ||||
796 | |||||
797 | if (ObjCMethodDecl *instance_method_decl = | ||||
798 | original_interface_decl->lookupInstanceMethod(original_selector)) { | ||||
799 | methods.push_back(instance_method_decl); | ||||
800 | } else if (ObjCMethodDecl *class_method_decl = | ||||
801 | original_interface_decl->lookupClassMethod( | ||||
802 | original_selector)) { | ||||
803 | methods.push_back(class_method_decl); | ||||
804 | } | ||||
805 | |||||
806 | if (methods.empty()) { | ||||
807 | return false; | ||||
808 | } | ||||
809 | |||||
810 | for (NamedDecl *named_decl : methods) { | ||||
811 | if (!named_decl) | ||||
812 | continue; | ||||
813 | |||||
814 | ObjCMethodDecl *result_method = dyn_cast<ObjCMethodDecl>(named_decl); | ||||
815 | |||||
816 | if (!result_method) | ||||
817 | continue; | ||||
818 | |||||
819 | Decl *copied_decl = CopyDecl(result_method); | ||||
820 | |||||
821 | if (!copied_decl) | ||||
822 | continue; | ||||
823 | |||||
824 | ObjCMethodDecl *copied_method_decl = dyn_cast<ObjCMethodDecl>(copied_decl); | ||||
825 | |||||
826 | if (!copied_method_decl) | ||||
827 | continue; | ||||
828 | |||||
829 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
830 | |||||
831 | LLDB_LOG(log, " CAS::FOMD found ({0}) {1}", log_info,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOMD found ({0}) {1}", log_info, ClangUtil ::DumpDecl(copied_method_decl)); } while (0) | ||||
832 | ClangUtil::DumpDecl(copied_method_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOMD found ({0}) {1}", log_info, ClangUtil ::DumpDecl(copied_method_decl)); } while (0); | ||||
833 | |||||
834 | context.AddNamedDecl(copied_method_decl); | ||||
835 | } | ||||
836 | |||||
837 | return true; | ||||
838 | } | ||||
839 | |||||
840 | void ClangASTSource::FindDeclInModules(NameSearchContext &context, | ||||
841 | ConstString name) { | ||||
842 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
843 | |||||
844 | std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor = | ||||
845 | GetClangModulesDeclVendor(); | ||||
846 | if (!modules_decl_vendor) | ||||
847 | return; | ||||
848 | |||||
849 | bool append = false; | ||||
850 | uint32_t max_matches = 1; | ||||
851 | std::vector<clang::NamedDecl *> decls; | ||||
852 | |||||
853 | if (!modules_decl_vendor->FindDecls(name, append, max_matches, decls)) | ||||
854 | return; | ||||
855 | |||||
856 | LLDB_LOG(log, " CAS::FEVD Matching entity found for \"{0}\" in the modules",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Matching entity found for \"{0}\" in the modules" , name); } while (0) | ||||
857 | name)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Matching entity found for \"{0}\" in the modules" , name); } while (0); | ||||
858 | |||||
859 | clang::NamedDecl *const decl_from_modules = decls[0]; | ||||
860 | |||||
861 | if (llvm::isa<clang::TypeDecl>(decl_from_modules) || | ||||
862 | llvm::isa<clang::ObjCContainerDecl>(decl_from_modules) || | ||||
863 | llvm::isa<clang::EnumConstantDecl>(decl_from_modules)) { | ||||
864 | clang::Decl *copied_decl = CopyDecl(decl_from_modules); | ||||
865 | clang::NamedDecl *copied_named_decl = | ||||
866 | copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr; | ||||
867 | |||||
868 | if (!copied_named_decl) { | ||||
869 | LLDB_LOG(log, " CAS::FEVD - Couldn't export a type from the modules")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD - Couldn't export a type from the modules" ); } while (0); | ||||
870 | |||||
871 | return; | ||||
872 | } | ||||
873 | |||||
874 | context.AddNamedDecl(copied_named_decl); | ||||
875 | |||||
876 | context.m_found_type = true; | ||||
877 | } | ||||
878 | } | ||||
879 | |||||
880 | void ClangASTSource::FindDeclInObjCRuntime(NameSearchContext &context, | ||||
881 | ConstString name) { | ||||
882 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
883 | |||||
884 | lldb::ProcessSP process(m_target->GetProcessSP()); | ||||
885 | |||||
886 | if (!process) | ||||
887 | return; | ||||
888 | |||||
889 | ObjCLanguageRuntime *language_runtime(ObjCLanguageRuntime::Get(*process)); | ||||
890 | |||||
891 | if (!language_runtime) | ||||
892 | return; | ||||
893 | |||||
894 | DeclVendor *decl_vendor = language_runtime->GetDeclVendor(); | ||||
895 | |||||
896 | if (!decl_vendor) | ||||
897 | return; | ||||
898 | |||||
899 | bool append = false; | ||||
900 | uint32_t max_matches = 1; | ||||
901 | std::vector<clang::NamedDecl *> decls; | ||||
902 | |||||
903 | auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor); | ||||
904 | if (!clang_decl_vendor->FindDecls(name, append, max_matches, decls)) | ||||
905 | return; | ||||
906 | |||||
907 | LLDB_LOG(log, " CAS::FEVD Matching type found for \"{0}\" in the runtime",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Matching type found for \"{0}\" in the runtime" , name); } while (0) | ||||
908 | name)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Matching type found for \"{0}\" in the runtime" , name); } while (0); | ||||
909 | |||||
910 | clang::Decl *copied_decl = CopyDecl(decls[0]); | ||||
911 | clang::NamedDecl *copied_named_decl = | ||||
912 | copied_decl ? dyn_cast<clang::NamedDecl>(copied_decl) : nullptr; | ||||
913 | |||||
914 | if (!copied_named_decl) { | ||||
915 | LLDB_LOG(log, " CAS::FEVD - Couldn't export a type from the runtime")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD - Couldn't export a type from the runtime" ); } while (0); | ||||
916 | |||||
917 | return; | ||||
918 | } | ||||
919 | |||||
920 | context.AddNamedDecl(copied_named_decl); | ||||
921 | } | ||||
922 | |||||
923 | void ClangASTSource::FindObjCMethodDecls(NameSearchContext &context) { | ||||
924 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
925 | |||||
926 | const DeclarationName &decl_name(context.m_decl_name); | ||||
927 | const DeclContext *decl_ctx(context.m_decl_context); | ||||
928 | |||||
929 | const ObjCInterfaceDecl *interface_decl = | ||||
930 | dyn_cast<ObjCInterfaceDecl>(decl_ctx); | ||||
| |||||
931 | |||||
932 | if (!interface_decl
| ||||
933 | return; | ||||
934 | |||||
935 | do { | ||||
936 | ClangASTImporter::DeclOrigin original = m_ast_importer_sp->GetDeclOrigin(interface_decl); | ||||
937 | |||||
938 | if (!original.Valid()) | ||||
939 | break; | ||||
940 | |||||
941 | ObjCInterfaceDecl *original_interface_decl = | ||||
942 | dyn_cast<ObjCInterfaceDecl>(original.decl); | ||||
943 | |||||
944 | if (FindObjCMethodDeclsWithOrigin(context, original_interface_decl, | ||||
945 | "at origin")) | ||||
946 | return; // found it, no need to look any further | ||||
947 | } while (false); | ||||
948 | |||||
949 | StreamString ss; | ||||
950 | |||||
951 | if (decl_name.isObjCZeroArgSelector()) { | ||||
952 | ss.Printf("%s", decl_name.getAsString().c_str()); | ||||
953 | } else if (decl_name.isObjCOneArgSelector()) { | ||||
954 | ss.Printf("%s", decl_name.getAsString().c_str()); | ||||
955 | } else { | ||||
956 | clang::Selector sel = decl_name.getObjCSelector(); | ||||
957 | |||||
958 | for (unsigned i = 0, e = sel.getNumArgs(); i != e; ++i) { | ||||
959 | llvm::StringRef r = sel.getNameForSlot(i); | ||||
960 | ss.Printf("%s:", r.str().c_str()); | ||||
961 | } | ||||
962 | } | ||||
963 | ss.Flush(); | ||||
964 | |||||
965 | if (ss.GetString().contains("$__lldb")) | ||||
966 | return; // we don't need any results | ||||
967 | |||||
968 | ConstString selector_name(ss.GetString()); | ||||
969 | |||||
970 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0} '{1}' " "for selector [{2} {3}]", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName(), selector_name ); } while (0) | ||||
971 | "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0} '{1}' "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0} '{1}' " "for selector [{2} {3}]", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName(), selector_name ); } while (0) | ||||
972 | "for selector [{2} {3}]",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0} '{1}' " "for selector [{2} {3}]", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName(), selector_name ); } while (0) | ||||
973 | m_ast_context, m_clang_ast_context->getDisplayName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0} '{1}' " "for selector [{2} {3}]", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName(), selector_name ); } while (0) | ||||
974 | interface_decl->getName(), selector_name)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCMethodDecls on (ASTContext*){0} '{1}' " "for selector [{2} {3}]", m_ast_context, m_clang_ast_context ->getDisplayName(), interface_decl->getName(), selector_name ); } while (0); | ||||
975 | SymbolContextList sc_list; | ||||
976 | |||||
977 | const bool include_symbols = false; | ||||
978 | const bool include_inlines = false; | ||||
979 | |||||
980 | std::string interface_name = interface_decl->getNameAsString(); | ||||
981 | |||||
982 | do { | ||||
983 | StreamString ms; | ||||
984 | ms.Printf("-[%s %s]", interface_name.c_str(), selector_name.AsCString()); | ||||
985 | ms.Flush(); | ||||
986 | ConstString instance_method_name(ms.GetString()); | ||||
987 | |||||
988 | sc_list.Clear(); | ||||
989 | m_target->GetImages().FindFunctions( | ||||
990 | instance_method_name, lldb::eFunctionNameTypeFull, include_symbols, | ||||
991 | include_inlines, sc_list); | ||||
992 | |||||
993 | if (sc_list.GetSize()) | ||||
994 | break; | ||||
995 | |||||
996 | ms.Clear(); | ||||
997 | ms.Printf("+[%s %s]", interface_name.c_str(), selector_name.AsCString()); | ||||
998 | ms.Flush(); | ||||
999 | ConstString class_method_name(ms.GetString()); | ||||
1000 | |||||
1001 | sc_list.Clear(); | ||||
1002 | m_target->GetImages().FindFunctions( | ||||
1003 | class_method_name, lldb::eFunctionNameTypeFull, include_symbols, | ||||
1004 | include_inlines, sc_list); | ||||
1005 | |||||
1006 | if (sc_list.GetSize()) | ||||
1007 | break; | ||||
1008 | |||||
1009 | // Fall back and check for methods in categories. If we find methods this | ||||
1010 | // way, we need to check that they're actually in categories on the desired | ||||
1011 | // class. | ||||
1012 | |||||
1013 | SymbolContextList candidate_sc_list; | ||||
1014 | |||||
1015 | m_target->GetImages().FindFunctions( | ||||
1016 | selector_name, lldb::eFunctionNameTypeSelector, include_symbols, | ||||
1017 | include_inlines, candidate_sc_list); | ||||
1018 | |||||
1019 | for (uint32_t ci = 0, ce = candidate_sc_list.GetSize(); ci != ce; ++ci) { | ||||
1020 | SymbolContext candidate_sc; | ||||
1021 | |||||
1022 | if (!candidate_sc_list.GetContextAtIndex(ci, candidate_sc)) | ||||
1023 | continue; | ||||
1024 | |||||
1025 | if (!candidate_sc.function) | ||||
1026 | continue; | ||||
1027 | |||||
1028 | const char *candidate_name = candidate_sc.function->GetName().AsCString(); | ||||
1029 | |||||
1030 | const char *cursor = candidate_name; | ||||
1031 | |||||
1032 | if (*cursor != '+' && *cursor != '-') | ||||
1033 | continue; | ||||
1034 | |||||
1035 | ++cursor; | ||||
1036 | |||||
1037 | if (*cursor != '[') | ||||
1038 | continue; | ||||
1039 | |||||
1040 | ++cursor; | ||||
1041 | |||||
1042 | size_t interface_len = interface_name.length(); | ||||
1043 | |||||
1044 | if (strncmp(cursor, interface_name.c_str(), interface_len)) | ||||
1045 | continue; | ||||
1046 | |||||
1047 | cursor += interface_len; | ||||
1048 | |||||
1049 | if (*cursor == ' ' || *cursor == '(') | ||||
1050 | sc_list.Append(candidate_sc); | ||||
1051 | } | ||||
1052 | } while (false); | ||||
1053 | |||||
1054 | if (sc_list.GetSize()) { | ||||
1055 | // We found a good function symbol. Use that. | ||||
1056 | |||||
1057 | for (uint32_t i = 0, e = sc_list.GetSize(); i != e; ++i) { | ||||
1058 | SymbolContext sc; | ||||
1059 | |||||
1060 | if (!sc_list.GetContextAtIndex(i, sc)) | ||||
1061 | continue; | ||||
1062 | |||||
1063 | if (!sc.function) | ||||
1064 | continue; | ||||
1065 | |||||
1066 | CompilerDeclContext function_decl_ctx = sc.function->GetDeclContext(); | ||||
1067 | if (!function_decl_ctx) | ||||
1068 | continue; | ||||
1069 | |||||
1070 | ObjCMethodDecl *method_decl = | ||||
1071 | TypeSystemClang::DeclContextGetAsObjCMethodDecl(function_decl_ctx); | ||||
1072 | |||||
1073 | if (!method_decl) | ||||
1074 | continue; | ||||
1075 | |||||
1076 | ObjCInterfaceDecl *found_interface_decl = | ||||
1077 | method_decl->getClassInterface(); | ||||
1078 | |||||
1079 | if (!found_interface_decl) | ||||
1080 | continue; | ||||
1081 | |||||
1082 | if (found_interface_decl->getName() == interface_decl->getName()) { | ||||
1083 | Decl *copied_decl = CopyDecl(method_decl); | ||||
1084 | |||||
1085 | if (!copied_decl) | ||||
1086 | continue; | ||||
1087 | |||||
1088 | ObjCMethodDecl *copied_method_decl = | ||||
1089 | dyn_cast<ObjCMethodDecl>(copied_decl); | ||||
1090 | |||||
1091 | if (!copied_method_decl) | ||||
1092 | continue; | ||||
1093 | |||||
1094 | LLDB_LOG(log, " CAS::FOMD found (in symbols)\n{0}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOMD found (in symbols)\n{0}", ClangUtil:: DumpDecl(copied_method_decl)); } while (0) | ||||
1095 | ClangUtil::DumpDecl(copied_method_decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOMD found (in symbols)\n{0}", ClangUtil:: DumpDecl(copied_method_decl)); } while (0); | ||||
1096 | |||||
1097 | context.AddNamedDecl(copied_method_decl); | ||||
1098 | } | ||||
1099 | } | ||||
1100 | |||||
1101 | return; | ||||
1102 | } | ||||
1103 | |||||
1104 | // Try the debug information. | ||||
1105 | |||||
1106 | do { | ||||
1107 | ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface( | ||||
1108 | const_cast<ObjCInterfaceDecl *>(interface_decl)); | ||||
1109 | |||||
1110 | if (!complete_interface_decl) | ||||
1111 | break; | ||||
1112 | |||||
1113 | // We found the complete interface. The runtime never needs to be queried | ||||
1114 | // in this scenario. | ||||
1115 | |||||
1116 | DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl( | ||||
1117 | complete_interface_decl); | ||||
1118 | |||||
1119 | if (complete_interface_decl == interface_decl) | ||||
1120 | break; // already checked this one | ||||
1121 | |||||
1122 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_interface_decl, &complete_iface_decl->getASTContext ()); } while (0) | ||||
1123 | "CAS::FOPD trying origin "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_interface_decl, &complete_iface_decl->getASTContext ()); } while (0) | ||||
1124 | "(ObjCInterfaceDecl*){0}/(ASTContext*){1}...",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_interface_decl, &complete_iface_decl->getASTContext ()); } while (0) | ||||
1125 | complete_interface_decl, &complete_iface_decl->getASTContext())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_interface_decl, &complete_iface_decl->getASTContext ()); } while (0); | ||||
1126 | |||||
1127 | FindObjCMethodDeclsWithOrigin(context, complete_interface_decl, | ||||
1128 | "in debug info"); | ||||
1129 | |||||
1130 | return; | ||||
1131 | } while (false); | ||||
1132 | |||||
1133 | do { | ||||
1134 | // Check the modules only if the debug information didn't have a complete | ||||
1135 | // interface. | ||||
1136 | |||||
1137 | if (std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor = | ||||
1138 | GetClangModulesDeclVendor()) { | ||||
1139 | ConstString interface_name(interface_decl->getNameAsString().c_str()); | ||||
1140 | bool append = false; | ||||
1141 | uint32_t max_matches = 1; | ||||
1142 | std::vector<clang::NamedDecl *> decls; | ||||
1143 | |||||
1144 | if (!modules_decl_vendor->FindDecls(interface_name, append, max_matches, | ||||
1145 | decls)) | ||||
1146 | break; | ||||
1147 | |||||
1148 | ObjCInterfaceDecl *interface_decl_from_modules = | ||||
1149 | dyn_cast<ObjCInterfaceDecl>(decls[0]); | ||||
1150 | |||||
1151 | if (!interface_decl_from_modules) | ||||
1152 | break; | ||||
1153 | |||||
1154 | if (FindObjCMethodDeclsWithOrigin(context, interface_decl_from_modules, | ||||
1155 | "in modules")) | ||||
1156 | return; | ||||
1157 | } | ||||
1158 | } while (false); | ||||
1159 | |||||
1160 | do { | ||||
1161 | // Check the runtime only if the debug information didn't have a complete | ||||
1162 | // interface and the modules don't get us anywhere. | ||||
1163 | |||||
1164 | lldb::ProcessSP process(m_target->GetProcessSP()); | ||||
1165 | |||||
1166 | if (!process) | ||||
1167 | break; | ||||
1168 | |||||
1169 | ObjCLanguageRuntime *language_runtime(ObjCLanguageRuntime::Get(*process)); | ||||
1170 | |||||
1171 | if (!language_runtime) | ||||
1172 | break; | ||||
1173 | |||||
1174 | DeclVendor *decl_vendor = language_runtime->GetDeclVendor(); | ||||
1175 | |||||
1176 | if (!decl_vendor) | ||||
1177 | break; | ||||
1178 | |||||
1179 | ConstString interface_name(interface_decl->getNameAsString().c_str()); | ||||
1180 | bool append = false; | ||||
1181 | uint32_t max_matches = 1; | ||||
1182 | std::vector<clang::NamedDecl *> decls; | ||||
1183 | |||||
1184 | auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor); | ||||
1185 | if (!clang_decl_vendor->FindDecls(interface_name, append, max_matches, | ||||
1186 | decls)) | ||||
1187 | break; | ||||
1188 | |||||
1189 | ObjCInterfaceDecl *runtime_interface_decl = | ||||
1190 | dyn_cast<ObjCInterfaceDecl>(decls[0]); | ||||
1191 | |||||
1192 | if (!runtime_interface_decl) | ||||
1193 | break; | ||||
1194 | |||||
1195 | FindObjCMethodDeclsWithOrigin(context, runtime_interface_decl, | ||||
1196 | "in runtime"); | ||||
1197 | } while (false); | ||||
1198 | } | ||||
1199 | |||||
1200 | static bool FindObjCPropertyAndIvarDeclsWithOrigin( | ||||
1201 | NameSearchContext &context, ClangASTSource &source, | ||||
1202 | DeclFromUser<const ObjCInterfaceDecl> &origin_iface_decl) { | ||||
1203 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
1204 | |||||
1205 | if (origin_iface_decl.IsInvalid()) | ||||
1206 | return false; | ||||
1207 | |||||
1208 | std::string name_str = context.m_decl_name.getAsString(); | ||||
1209 | StringRef name(name_str); | ||||
1210 | IdentifierInfo &name_identifier( | ||||
1211 | origin_iface_decl->getASTContext().Idents.get(name)); | ||||
1212 | |||||
1213 | DeclFromUser<ObjCPropertyDecl> origin_property_decl( | ||||
1214 | origin_iface_decl->FindPropertyDeclaration( | ||||
1215 | &name_identifier, ObjCPropertyQueryKind::OBJC_PR_query_instance)); | ||||
1216 | |||||
1217 | bool found = false; | ||||
1218 | |||||
1219 | if (origin_property_decl.IsValid()) { | ||||
1220 | DeclFromParser<ObjCPropertyDecl> parser_property_decl( | ||||
1221 | origin_property_decl.Import(source)); | ||||
1222 | if (parser_property_decl.IsValid()) { | ||||
1223 | LLDB_LOG(log, " CAS::FOPD found\n{0}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOPD found\n{0}", ClangUtil::DumpDecl(parser_property_decl .decl)); } while (0) | ||||
1224 | ClangUtil::DumpDecl(parser_property_decl.decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOPD found\n{0}", ClangUtil::DumpDecl(parser_property_decl .decl)); } while (0); | ||||
1225 | |||||
1226 | context.AddNamedDecl(parser_property_decl.decl); | ||||
1227 | found = true; | ||||
1228 | } | ||||
1229 | } | ||||
1230 | |||||
1231 | DeclFromUser<ObjCIvarDecl> origin_ivar_decl( | ||||
1232 | origin_iface_decl->getIvarDecl(&name_identifier)); | ||||
1233 | |||||
1234 | if (origin_ivar_decl.IsValid()) { | ||||
1235 | DeclFromParser<ObjCIvarDecl> parser_ivar_decl( | ||||
1236 | origin_ivar_decl.Import(source)); | ||||
1237 | if (parser_ivar_decl.IsValid()) { | ||||
1238 | LLDB_LOG(log, " CAS::FOPD found\n{0}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOPD found\n{0}", ClangUtil::DumpDecl(parser_ivar_decl .decl)); } while (0) | ||||
1239 | ClangUtil::DumpDecl(parser_ivar_decl.decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FOPD found\n{0}", ClangUtil::DumpDecl(parser_ivar_decl .decl)); } while (0); | ||||
1240 | |||||
1241 | context.AddNamedDecl(parser_ivar_decl.decl); | ||||
1242 | found = true; | ||||
1243 | } | ||||
1244 | } | ||||
1245 | |||||
1246 | return found; | ||||
1247 | } | ||||
1248 | |||||
1249 | void ClangASTSource::FindObjCPropertyAndIvarDecls(NameSearchContext &context) { | ||||
1250 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
1251 | |||||
1252 | DeclFromParser<const ObjCInterfaceDecl> parser_iface_decl( | ||||
1253 | cast<ObjCInterfaceDecl>(context.m_decl_context)); | ||||
1254 | DeclFromUser<const ObjCInterfaceDecl> origin_iface_decl( | ||||
1255 | parser_iface_decl.GetOrigin(*this)); | ||||
1256 | |||||
1257 | ConstString class_name(parser_iface_decl->getNameAsString().c_str()); | ||||
1258 | |||||
1259 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCPropertyAndIvarDecls on " "(ASTContext*){0} '{1}' for '{2}.{3}'", m_ast_context, m_clang_ast_context ->getDisplayName(), parser_iface_decl->getName(), context .m_decl_name.getAsString()); } while (0) | ||||
1260 | "ClangASTSource::FindObjCPropertyAndIvarDecls on "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCPropertyAndIvarDecls on " "(ASTContext*){0} '{1}' for '{2}.{3}'", m_ast_context, m_clang_ast_context ->getDisplayName(), parser_iface_decl->getName(), context .m_decl_name.getAsString()); } while (0) | ||||
1261 | "(ASTContext*){0} '{1}' for '{2}.{3}'",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCPropertyAndIvarDecls on " "(ASTContext*){0} '{1}' for '{2}.{3}'", m_ast_context, m_clang_ast_context ->getDisplayName(), parser_iface_decl->getName(), context .m_decl_name.getAsString()); } while (0) | ||||
1262 | m_ast_context, m_clang_ast_context->getDisplayName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCPropertyAndIvarDecls on " "(ASTContext*){0} '{1}' for '{2}.{3}'", m_ast_context, m_clang_ast_context ->getDisplayName(), parser_iface_decl->getName(), context .m_decl_name.getAsString()); } while (0) | ||||
1263 | parser_iface_decl->getName(), context.m_decl_name.getAsString())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "ClangASTSource::FindObjCPropertyAndIvarDecls on " "(ASTContext*){0} '{1}' for '{2}.{3}'", m_ast_context, m_clang_ast_context ->getDisplayName(), parser_iface_decl->getName(), context .m_decl_name.getAsString()); } while (0); | ||||
1264 | |||||
1265 | if (FindObjCPropertyAndIvarDeclsWithOrigin(context, *this, origin_iface_decl)) | ||||
1266 | return; | ||||
1267 | |||||
1268 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD couldn't find the property on origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}, searching " "elsewhere..." , origin_iface_decl.decl, &origin_iface_decl->getASTContext ()); } while (0) | ||||
1269 | "CAS::FOPD couldn't find the property on origin "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD couldn't find the property on origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}, searching " "elsewhere..." , origin_iface_decl.decl, &origin_iface_decl->getASTContext ()); } while (0) | ||||
1270 | "(ObjCInterfaceDecl*){0}/(ASTContext*){1}, searching "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD couldn't find the property on origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}, searching " "elsewhere..." , origin_iface_decl.decl, &origin_iface_decl->getASTContext ()); } while (0) | ||||
1271 | "elsewhere...",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD couldn't find the property on origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}, searching " "elsewhere..." , origin_iface_decl.decl, &origin_iface_decl->getASTContext ()); } while (0) | ||||
1272 | origin_iface_decl.decl, &origin_iface_decl->getASTContext())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD couldn't find the property on origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}, searching " "elsewhere..." , origin_iface_decl.decl, &origin_iface_decl->getASTContext ()); } while (0); | ||||
1273 | |||||
1274 | SymbolContext null_sc; | ||||
1275 | TypeList type_list; | ||||
1276 | |||||
1277 | do { | ||||
1278 | ObjCInterfaceDecl *complete_interface_decl = GetCompleteObjCInterface( | ||||
1279 | const_cast<ObjCInterfaceDecl *>(parser_iface_decl.decl)); | ||||
1280 | |||||
1281 | if (!complete_interface_decl) | ||||
1282 | break; | ||||
1283 | |||||
1284 | // We found the complete interface. The runtime never needs to be queried | ||||
1285 | // in this scenario. | ||||
1286 | |||||
1287 | DeclFromUser<const ObjCInterfaceDecl> complete_iface_decl( | ||||
1288 | complete_interface_decl); | ||||
1289 | |||||
1290 | if (complete_iface_decl.decl == origin_iface_decl.decl) | ||||
1291 | break; // already checked this one | ||||
1292 | |||||
1293 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_iface_decl.decl, &complete_iface_decl->getASTContext ()); } while (0) | ||||
1294 | "CAS::FOPD trying origin "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_iface_decl.decl, &complete_iface_decl->getASTContext ()); } while (0) | ||||
1295 | "(ObjCInterfaceDecl*){0}/(ASTContext*){1}...",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_iface_decl.decl, &complete_iface_decl->getASTContext ()); } while (0) | ||||
1296 | complete_iface_decl.decl, &complete_iface_decl->getASTContext())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD trying origin " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , complete_iface_decl.decl, &complete_iface_decl->getASTContext ()); } while (0); | ||||
1297 | |||||
1298 | FindObjCPropertyAndIvarDeclsWithOrigin(context, *this, complete_iface_decl); | ||||
1299 | |||||
1300 | return; | ||||
1301 | } while (false); | ||||
1302 | |||||
1303 | do { | ||||
1304 | // Check the modules only if the debug information didn't have a complete | ||||
1305 | // interface. | ||||
1306 | |||||
1307 | std::shared_ptr<ClangModulesDeclVendor> modules_decl_vendor = | ||||
1308 | GetClangModulesDeclVendor(); | ||||
1309 | |||||
1310 | if (!modules_decl_vendor) | ||||
1311 | break; | ||||
1312 | |||||
1313 | bool append = false; | ||||
1314 | uint32_t max_matches = 1; | ||||
1315 | std::vector<clang::NamedDecl *> decls; | ||||
1316 | |||||
1317 | if (!modules_decl_vendor->FindDecls(class_name, append, max_matches, decls)) | ||||
1318 | break; | ||||
1319 | |||||
1320 | DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_modules( | ||||
1321 | dyn_cast<ObjCInterfaceDecl>(decls[0])); | ||||
1322 | |||||
1323 | if (!interface_decl_from_modules.IsValid()) | ||||
1324 | break; | ||||
1325 | |||||
1326 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying module " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_modules.decl, &interface_decl_from_modules ->getASTContext()); } while (0) | ||||
1327 | "CAS::FOPD[{0}] trying module "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying module " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_modules.decl, &interface_decl_from_modules ->getASTContext()); } while (0) | ||||
1328 | "(ObjCInterfaceDecl*){0}/(ASTContext*){1}...",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying module " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_modules.decl, &interface_decl_from_modules ->getASTContext()); } while (0) | ||||
1329 | interface_decl_from_modules.decl,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying module " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_modules.decl, &interface_decl_from_modules ->getASTContext()); } while (0) | ||||
1330 | &interface_decl_from_modules->getASTContext())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying module " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_modules.decl, &interface_decl_from_modules ->getASTContext()); } while (0); | ||||
1331 | |||||
1332 | if (FindObjCPropertyAndIvarDeclsWithOrigin(context, *this, | ||||
1333 | interface_decl_from_modules)) | ||||
1334 | return; | ||||
1335 | } while (false); | ||||
1336 | |||||
1337 | do { | ||||
1338 | // Check the runtime only if the debug information didn't have a complete | ||||
1339 | // interface and nothing was in the modules. | ||||
1340 | |||||
1341 | lldb::ProcessSP process(m_target->GetProcessSP()); | ||||
1342 | |||||
1343 | if (!process) | ||||
1344 | return; | ||||
1345 | |||||
1346 | ObjCLanguageRuntime *language_runtime(ObjCLanguageRuntime::Get(*process)); | ||||
1347 | |||||
1348 | if (!language_runtime) | ||||
1349 | return; | ||||
1350 | |||||
1351 | DeclVendor *decl_vendor = language_runtime->GetDeclVendor(); | ||||
1352 | |||||
1353 | if (!decl_vendor) | ||||
1354 | break; | ||||
1355 | |||||
1356 | bool append = false; | ||||
1357 | uint32_t max_matches = 1; | ||||
1358 | std::vector<clang::NamedDecl *> decls; | ||||
1359 | |||||
1360 | auto *clang_decl_vendor = llvm::cast<ClangDeclVendor>(decl_vendor); | ||||
1361 | if (!clang_decl_vendor->FindDecls(class_name, append, max_matches, decls)) | ||||
1362 | break; | ||||
1363 | |||||
1364 | DeclFromUser<const ObjCInterfaceDecl> interface_decl_from_runtime( | ||||
1365 | dyn_cast<ObjCInterfaceDecl>(decls[0])); | ||||
1366 | |||||
1367 | if (!interface_decl_from_runtime.IsValid()) | ||||
1368 | break; | ||||
1369 | |||||
1370 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying runtime " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_runtime.decl, &interface_decl_from_runtime ->getASTContext()); } while (0) | ||||
1371 | "CAS::FOPD[{0}] trying runtime "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying runtime " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_runtime.decl, &interface_decl_from_runtime ->getASTContext()); } while (0) | ||||
1372 | "(ObjCInterfaceDecl*){0}/(ASTContext*){1}...",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying runtime " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_runtime.decl, &interface_decl_from_runtime ->getASTContext()); } while (0) | ||||
1373 | interface_decl_from_runtime.decl,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying runtime " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_runtime.decl, &interface_decl_from_runtime ->getASTContext()); } while (0) | ||||
1374 | &interface_decl_from_runtime->getASTContext())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CAS::FOPD[{0}] trying runtime " "(ObjCInterfaceDecl*){0}/(ASTContext*){1}..." , interface_decl_from_runtime.decl, &interface_decl_from_runtime ->getASTContext()); } while (0); | ||||
1375 | |||||
1376 | if (FindObjCPropertyAndIvarDeclsWithOrigin(context, *this, | ||||
1377 | interface_decl_from_runtime)) | ||||
1378 | return; | ||||
1379 | } while (false); | ||||
1380 | } | ||||
1381 | |||||
1382 | void ClangASTSource::LookupInNamespace(NameSearchContext &context) { | ||||
1383 | const NamespaceDecl *namespace_context = | ||||
1384 | dyn_cast<NamespaceDecl>(context.m_decl_context); | ||||
1385 | |||||
1386 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
1387 | |||||
1388 | ClangASTImporter::NamespaceMapSP namespace_map = | ||||
1389 | m_ast_importer_sp->GetNamespaceMap(namespace_context); | ||||
1390 | |||||
1391 | LLDB_LOGV(log, " CAS::FEVD Inspecting namespace map {0} ({1} entries)",do { ::lldb_private::Log *log_private = (log); if (log_private && log_private->GetVerbose()) log_private->Format ("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Inspecting namespace map {0} ({1} entries)" , namespace_map.get(), namespace_map->size()); } while (0) | ||||
1392 | namespace_map.get(), namespace_map->size())do { ::lldb_private::Log *log_private = (log); if (log_private && log_private->GetVerbose()) log_private->Format ("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Inspecting namespace map {0} ({1} entries)" , namespace_map.get(), namespace_map->size()); } while (0); | ||||
1393 | |||||
1394 | if (!namespace_map) | ||||
1395 | return; | ||||
1396 | |||||
1397 | for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), | ||||
1398 | e = namespace_map->end(); | ||||
1399 | i != e; ++i) { | ||||
1400 | LLDB_LOG(log, " CAS::FEVD Searching namespace {0} in module {1}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Searching namespace {0} in module {1}" , i->second.GetName(), i->first->GetFileSpec().GetFilename ()); } while (0) | ||||
1401 | i->second.GetName(), i->first->GetFileSpec().GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CAS::FEVD Searching namespace {0} in module {1}" , i->second.GetName(), i->first->GetFileSpec().GetFilename ()); } while (0); | ||||
1402 | |||||
1403 | FindExternalVisibleDecls(context, i->first, i->second); | ||||
1404 | } | ||||
1405 | } | ||||
1406 | |||||
1407 | typedef llvm::DenseMap<const FieldDecl *, uint64_t> FieldOffsetMap; | ||||
1408 | typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetMap; | ||||
1409 | |||||
1410 | template <class D, class O> | ||||
1411 | static bool ImportOffsetMap(llvm::DenseMap<const D *, O> &destination_map, | ||||
1412 | llvm::DenseMap<const D *, O> &source_map, | ||||
1413 | ClangASTSource &source) { | ||||
1414 | // When importing fields into a new record, clang has a hard requirement that | ||||
1415 | // fields be imported in field offset order. Since they are stored in a | ||||
1416 | // DenseMap with a pointer as the key type, this means we cannot simply | ||||
1417 | // iterate over the map, as the order will be non-deterministic. Instead we | ||||
1418 | // have to sort by the offset and then insert in sorted order. | ||||
1419 | typedef llvm::DenseMap<const D *, O> MapType; | ||||
1420 | typedef typename MapType::value_type PairType; | ||||
1421 | std::vector<PairType> sorted_items; | ||||
1422 | sorted_items.reserve(source_map.size()); | ||||
1423 | sorted_items.assign(source_map.begin(), source_map.end()); | ||||
1424 | llvm::sort(sorted_items.begin(), sorted_items.end(), | ||||
1425 | [](const PairType &lhs, const PairType &rhs) { | ||||
1426 | return lhs.second < rhs.second; | ||||
1427 | }); | ||||
1428 | |||||
1429 | for (const auto &item : sorted_items) { | ||||
1430 | DeclFromUser<D> user_decl(const_cast<D *>(item.first)); | ||||
1431 | DeclFromParser<D> parser_decl(user_decl.Import(source)); | ||||
1432 | if (parser_decl.IsInvalid()) | ||||
1433 | return false; | ||||
1434 | destination_map.insert( | ||||
1435 | std::pair<const D *, O>(parser_decl.decl, item.second)); | ||||
1436 | } | ||||
1437 | |||||
1438 | return true; | ||||
1439 | } | ||||
1440 | |||||
1441 | template <bool IsVirtual> | ||||
1442 | bool ExtractBaseOffsets(const ASTRecordLayout &record_layout, | ||||
1443 | DeclFromUser<const CXXRecordDecl> &record, | ||||
1444 | BaseOffsetMap &base_offsets) { | ||||
1445 | for (CXXRecordDecl::base_class_const_iterator | ||||
1446 | bi = (IsVirtual ? record->vbases_begin() : record->bases_begin()), | ||||
1447 | be = (IsVirtual ? record->vbases_end() : record->bases_end()); | ||||
1448 | bi != be; ++bi) { | ||||
1449 | if (!IsVirtual && bi->isVirtual()) | ||||
1450 | continue; | ||||
1451 | |||||
1452 | const clang::Type *origin_base_type = bi->getType().getTypePtr(); | ||||
1453 | const clang::RecordType *origin_base_record_type = | ||||
1454 | origin_base_type->getAs<RecordType>(); | ||||
1455 | |||||
1456 | if (!origin_base_record_type) | ||||
1457 | return false; | ||||
1458 | |||||
1459 | DeclFromUser<RecordDecl> origin_base_record( | ||||
1460 | origin_base_record_type->getDecl()); | ||||
1461 | |||||
1462 | if (origin_base_record.IsInvalid()) | ||||
1463 | return false; | ||||
1464 | |||||
1465 | DeclFromUser<CXXRecordDecl> origin_base_cxx_record( | ||||
1466 | DynCast<CXXRecordDecl>(origin_base_record)); | ||||
1467 | |||||
1468 | if (origin_base_cxx_record.IsInvalid()) | ||||
1469 | return false; | ||||
1470 | |||||
1471 | CharUnits base_offset; | ||||
1472 | |||||
1473 | if (IsVirtual) | ||||
1474 | base_offset = | ||||
1475 | record_layout.getVBaseClassOffset(origin_base_cxx_record.decl); | ||||
1476 | else | ||||
1477 | base_offset = | ||||
1478 | record_layout.getBaseClassOffset(origin_base_cxx_record.decl); | ||||
1479 | |||||
1480 | base_offsets.insert(std::pair<const CXXRecordDecl *, CharUnits>( | ||||
1481 | origin_base_cxx_record.decl, base_offset)); | ||||
1482 | } | ||||
1483 | |||||
1484 | return true; | ||||
1485 | } | ||||
1486 | |||||
1487 | bool ClangASTSource::layoutRecordType(const RecordDecl *record, uint64_t &size, | ||||
1488 | uint64_t &alignment, | ||||
1489 | FieldOffsetMap &field_offsets, | ||||
1490 | BaseOffsetMap &base_offsets, | ||||
1491 | BaseOffsetMap &virtual_base_offsets) { | ||||
1492 | |||||
1493 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
1494 | |||||
1495 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LayoutRecordType on (ASTContext*){0} '{1}' for (RecordDecl*)" "{3} [name = '{4}']", m_ast_context, m_clang_ast_context-> getDisplayName(), record, record->getName()); } while (0) | ||||
1496 | "LayoutRecordType on (ASTContext*){0} '{1}' for (RecordDecl*)"do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LayoutRecordType on (ASTContext*){0} '{1}' for (RecordDecl*)" "{3} [name = '{4}']", m_ast_context, m_clang_ast_context-> getDisplayName(), record, record->getName()); } while (0) | ||||
1497 | "{3} [name = '{4}']",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LayoutRecordType on (ASTContext*){0} '{1}' for (RecordDecl*)" "{3} [name = '{4}']", m_ast_context, m_clang_ast_context-> getDisplayName(), record, record->getName()); } while (0) | ||||
1498 | m_ast_context, m_clang_ast_context->getDisplayName(), record,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LayoutRecordType on (ASTContext*){0} '{1}' for (RecordDecl*)" "{3} [name = '{4}']", m_ast_context, m_clang_ast_context-> getDisplayName(), record, record->getName()); } while (0) | ||||
1499 | record->getName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LayoutRecordType on (ASTContext*){0} '{1}' for (RecordDecl*)" "{3} [name = '{4}']", m_ast_context, m_clang_ast_context-> getDisplayName(), record, record->getName()); } while (0); | ||||
1500 | |||||
1501 | DeclFromParser<const RecordDecl> parser_record(record); | ||||
1502 | DeclFromUser<const RecordDecl> origin_record( | ||||
1503 | parser_record.GetOrigin(*this)); | ||||
1504 | |||||
1505 | if (origin_record.IsInvalid()) | ||||
1506 | return false; | ||||
1507 | |||||
1508 | FieldOffsetMap origin_field_offsets; | ||||
1509 | BaseOffsetMap origin_base_offsets; | ||||
1510 | BaseOffsetMap origin_virtual_base_offsets; | ||||
1511 | |||||
1512 | TypeSystemClang::GetCompleteDecl( | ||||
1513 | &origin_record->getASTContext(), | ||||
1514 | const_cast<RecordDecl *>(origin_record.decl)); | ||||
1515 | |||||
1516 | clang::RecordDecl *definition = origin_record.decl->getDefinition(); | ||||
1517 | if (!definition || !definition->isCompleteDefinition()) | ||||
1518 | return false; | ||||
1519 | |||||
1520 | const ASTRecordLayout &record_layout( | ||||
1521 | origin_record->getASTContext().getASTRecordLayout(origin_record.decl)); | ||||
1522 | |||||
1523 | int field_idx = 0, field_count = record_layout.getFieldCount(); | ||||
1524 | |||||
1525 | for (RecordDecl::field_iterator fi = origin_record->field_begin(), | ||||
1526 | fe = origin_record->field_end(); | ||||
1527 | fi != fe; ++fi) { | ||||
1528 | if (field_idx >= field_count) | ||||
1529 | return false; // Layout didn't go well. Bail out. | ||||
1530 | |||||
1531 | uint64_t field_offset = record_layout.getFieldOffset(field_idx); | ||||
1532 | |||||
1533 | origin_field_offsets.insert( | ||||
1534 | std::pair<const FieldDecl *, uint64_t>(*fi, field_offset)); | ||||
1535 | |||||
1536 | field_idx++; | ||||
1537 | } | ||||
1538 | |||||
1539 | lldbassert(&record->getASTContext() == m_ast_context)lldb_private::lldb_assert(static_cast<bool>(&record ->getASTContext() == m_ast_context), "&record->getASTContext() == m_ast_context" , __FUNCTION__, "/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , 1539); | ||||
1540 | |||||
1541 | DeclFromUser<const CXXRecordDecl> origin_cxx_record( | ||||
1542 | DynCast<const CXXRecordDecl>(origin_record)); | ||||
1543 | |||||
1544 | if (origin_cxx_record.IsValid()) { | ||||
1545 | if (!ExtractBaseOffsets<false>(record_layout, origin_cxx_record, | ||||
1546 | origin_base_offsets) || | ||||
1547 | !ExtractBaseOffsets<true>(record_layout, origin_cxx_record, | ||||
1548 | origin_virtual_base_offsets)) | ||||
1549 | return false; | ||||
1550 | } | ||||
1551 | |||||
1552 | if (!ImportOffsetMap(field_offsets, origin_field_offsets, *this) || | ||||
1553 | !ImportOffsetMap(base_offsets, origin_base_offsets, *this) || | ||||
1554 | !ImportOffsetMap(virtual_base_offsets, origin_virtual_base_offsets, | ||||
1555 | *this)) | ||||
1556 | return false; | ||||
1557 | |||||
1558 | size = record_layout.getSize().getQuantity() * m_ast_context->getCharWidth(); | ||||
1559 | alignment = record_layout.getAlignment().getQuantity() * | ||||
1560 | m_ast_context->getCharWidth(); | ||||
1561 | |||||
1562 | if (log) { | ||||
1563 | LLDB_LOG(log, "LRT returned:")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT returned:"); } while (0); | ||||
1564 | LLDB_LOG(log, "LRT Original = (RecordDecl*){0}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT Original = (RecordDecl*){0}", static_cast< const void *>(origin_record.decl)); } while (0) | ||||
1565 | static_cast<const void *>(origin_record.decl))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT Original = (RecordDecl*){0}", static_cast< const void *>(origin_record.decl)); } while (0); | ||||
1566 | LLDB_LOG(log, "LRT Size = {0}", size)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT Size = {0}", size); } while (0); | ||||
1567 | LLDB_LOG(log, "LRT Alignment = {0}", alignment)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT Alignment = {0}", alignment); } while (0); | ||||
1568 | LLDB_LOG(log, "LRT Fields:")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT Fields:"); } while (0); | ||||
1569 | for (RecordDecl::field_iterator fi = record->field_begin(), | ||||
1570 | fe = record->field_end(); | ||||
1571 | fi != fe; ++fi) { | ||||
1572 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT (FieldDecl*){0}, Name = '{1}', Offset = {2} bits" , *fi, fi->getName(), field_offsets[*fi]); } while (0) | ||||
1573 | "LRT (FieldDecl*){0}, Name = '{1}', Offset = {2} bits",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT (FieldDecl*){0}, Name = '{1}', Offset = {2} bits" , *fi, fi->getName(), field_offsets[*fi]); } while (0) | ||||
1574 | *fi, fi->getName(), field_offsets[*fi])do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT (FieldDecl*){0}, Name = '{1}', Offset = {2} bits" , *fi, fi->getName(), field_offsets[*fi]); } while (0); | ||||
1575 | } | ||||
1576 | DeclFromParser<const CXXRecordDecl> parser_cxx_record = | ||||
1577 | DynCast<const CXXRecordDecl>(parser_record); | ||||
1578 | if (parser_cxx_record.IsValid()) { | ||||
1579 | LLDB_LOG(log, "LRT Bases:")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT Bases:"); } while (0); | ||||
1580 | for (CXXRecordDecl::base_class_const_iterator | ||||
1581 | bi = parser_cxx_record->bases_begin(), | ||||
1582 | be = parser_cxx_record->bases_end(); | ||||
1583 | bi != be; ++bi) { | ||||
1584 | bool is_virtual = bi->isVirtual(); | ||||
1585 | |||||
1586 | QualType base_type = bi->getType(); | ||||
1587 | const RecordType *base_record_type = base_type->getAs<RecordType>(); | ||||
1588 | DeclFromParser<RecordDecl> base_record(base_record_type->getDecl()); | ||||
1589 | DeclFromParser<CXXRecordDecl> base_cxx_record = | ||||
1590 | DynCast<CXXRecordDecl>(base_record); | ||||
1591 | |||||
1592 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1593 | "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1594 | "{3} chars",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1595 | (is_virtual ? "Virtual " : ""), base_cxx_record.decl,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1596 | base_cxx_record.decl->getName(),do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1597 | (is_virtualdo { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1598 | ? virtual_base_offsets[base_cxx_record.decl].getQuantity()do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0) | ||||
1599 | : base_offsets[base_cxx_record.decl].getQuantity()))do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRT {0}(CXXRecordDecl*){1}, Name = '{2}', Offset = " "{3} chars", (is_virtual ? "Virtual " : ""), base_cxx_record .decl, base_cxx_record.decl->getName(), (is_virtual ? virtual_base_offsets [base_cxx_record.decl].getQuantity() : base_offsets[base_cxx_record .decl].getQuantity())); } while (0); | ||||
1600 | } | ||||
1601 | } else { | ||||
1602 | LLDB_LOG(log, "LRD Not a CXXRecord, so no bases")do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "LRD Not a CXXRecord, so no bases"); } while (0 ); | ||||
1603 | } | ||||
1604 | } | ||||
1605 | |||||
1606 | return true; | ||||
1607 | } | ||||
1608 | |||||
1609 | void ClangASTSource::CompleteNamespaceMap( | ||||
1610 | ClangASTImporter::NamespaceMapSP &namespace_map, ConstString name, | ||||
1611 | ClangASTImporter::NamespaceMapSP &parent_map) const { | ||||
1612 | |||||
1613 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS(1u << 8))); | ||||
1614 | |||||
1615 | if (log) { | ||||
1616 | if (parent_map && parent_map->size()) | ||||
1617 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2} in namespace {3}", m_ast_context, m_clang_ast_context ->getDisplayName(), name, parent_map->begin()->second .GetName()); } while (0) | ||||
1618 | "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2} in namespace {3}", m_ast_context, m_clang_ast_context ->getDisplayName(), name, parent_map->begin()->second .GetName()); } while (0) | ||||
1619 | "for namespace {2} in namespace {3}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2} in namespace {3}", m_ast_context, m_clang_ast_context ->getDisplayName(), name, parent_map->begin()->second .GetName()); } while (0) | ||||
1620 | m_ast_context, m_clang_ast_context->getDisplayName(), name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2} in namespace {3}", m_ast_context, m_clang_ast_context ->getDisplayName(), name, parent_map->begin()->second .GetName()); } while (0) | ||||
1621 | parent_map->begin()->second.GetName())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2} in namespace {3}", m_ast_context, m_clang_ast_context ->getDisplayName(), name, parent_map->begin()->second .GetName()); } while (0); | ||||
1622 | else | ||||
1623 | LLDB_LOG(log,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2}", m_ast_context, m_clang_ast_context-> getDisplayName(), name); } while (0) | ||||
1624 | "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching "do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2}", m_ast_context, m_clang_ast_context-> getDisplayName(), name); } while (0) | ||||
1625 | "for namespace {2}",do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2}", m_ast_context, m_clang_ast_context-> getDisplayName(), name); } while (0) | ||||
1626 | m_ast_context, m_clang_ast_context->getDisplayName(), name)do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, "CompleteNamespaceMap on (ASTContext*){0} '{1}' Searching " "for namespace {2}", m_ast_context, m_clang_ast_context-> getDisplayName(), name); } while (0); | ||||
1627 | } | ||||
1628 | |||||
1629 | if (parent_map) { | ||||
1630 | for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), | ||||
1631 | e = parent_map->end(); | ||||
1632 | i != e; ++i) { | ||||
1633 | CompilerDeclContext found_namespace_decl; | ||||
1634 | |||||
1635 | lldb::ModuleSP module_sp = i->first; | ||||
1636 | CompilerDeclContext module_parent_namespace_decl = i->second; | ||||
1637 | |||||
1638 | SymbolFile *symbol_file = module_sp->GetSymbolFile(); | ||||
1639 | |||||
1640 | if (!symbol_file) | ||||
1641 | continue; | ||||
1642 | |||||
1643 | found_namespace_decl = | ||||
1644 | symbol_file->FindNamespace(name, module_parent_namespace_decl); | ||||
1645 | |||||
1646 | if (!found_namespace_decl) | ||||
1647 | continue; | ||||
1648 | |||||
1649 | namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>( | ||||
1650 | module_sp, found_namespace_decl)); | ||||
1651 | |||||
1652 | LLDB_LOG(log, " CMN Found namespace {0} in module {1}", name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CMN Found namespace {0} in module {1}", name, module_sp ->GetFileSpec().GetFilename()); } while (0) | ||||
1653 | module_sp->GetFileSpec().GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CMN Found namespace {0} in module {1}", name, module_sp ->GetFileSpec().GetFilename()); } while (0); | ||||
1654 | } | ||||
1655 | } else { | ||||
1656 | CompilerDeclContext null_namespace_decl; | ||||
1657 | for (lldb::ModuleSP image : m_target->GetImages().Modules()) { | ||||
1658 | if (!image) | ||||
1659 | continue; | ||||
1660 | |||||
1661 | CompilerDeclContext found_namespace_decl; | ||||
1662 | |||||
1663 | SymbolFile *symbol_file = image->GetSymbolFile(); | ||||
1664 | |||||
1665 | if (!symbol_file) | ||||
1666 | continue; | ||||
1667 | |||||
1668 | found_namespace_decl = | ||||
1669 | symbol_file->FindNamespace(name, null_namespace_decl); | ||||
1670 | |||||
1671 | if (!found_namespace_decl) | ||||
1672 | continue; | ||||
1673 | |||||
1674 | namespace_map->push_back(std::pair<lldb::ModuleSP, CompilerDeclContext>( | ||||
1675 | image, found_namespace_decl)); | ||||
1676 | |||||
1677 | LLDB_LOG(log, " CMN[{0}] Found namespace {0} in module {1}", name,do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CMN[{0}] Found namespace {0} in module {1}", name , image->GetFileSpec().GetFilename()); } while (0) | ||||
1678 | image->GetFileSpec().GetFilename())do { ::lldb_private::Log *log_private = (log); if (log_private ) log_private->Format("/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp" , __func__, " CMN[{0}] Found namespace {0} in module {1}", name , image->GetFileSpec().GetFilename()); } while (0); | ||||
1679 | } | ||||
1680 | } | ||||
1681 | } | ||||
1682 | |||||
1683 | NamespaceDecl *ClangASTSource::AddNamespace( | ||||
1684 | NameSearchContext &context, | ||||
1685 | ClangASTImporter::NamespaceMapSP &namespace_decls) { | ||||
1686 | if (!namespace_decls) | ||||
1687 | return nullptr; | ||||
1688 | |||||
1689 | const CompilerDeclContext &namespace_decl = namespace_decls->begin()->second; | ||||
1690 | |||||
1691 | clang::ASTContext *src_ast = | ||||
1692 | TypeSystemClang::DeclContextGetTypeSystemClang(namespace_decl); | ||||
1693 | if (!src_ast) | ||||
1694 | return nullptr; | ||||
1695 | clang::NamespaceDecl *src_namespace_decl = | ||||
1696 | TypeSystemClang::DeclContextGetAsNamespaceDecl(namespace_decl); | ||||
1697 | |||||
1698 | if (!src_namespace_decl) | ||||
1699 | return nullptr; | ||||
1700 | |||||
1701 | Decl *copied_decl = CopyDecl(src_namespace_decl); | ||||
1702 | |||||
1703 | if (!copied_decl) | ||||
1704 | return nullptr; | ||||
1705 | |||||
1706 | NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl); | ||||
1707 | |||||
1708 | if (!copied_namespace_decl) | ||||
1709 | return nullptr; | ||||
1710 | |||||
1711 | context.m_decls.push_back(copied_namespace_decl); | ||||
1712 | |||||
1713 | m_ast_importer_sp->RegisterNamespaceMap(copied_namespace_decl, | ||||
1714 | namespace_decls); | ||||
1715 | |||||
1716 | return dyn_cast<NamespaceDecl>(copied_decl); | ||||
1717 | } | ||||
1718 | |||||
1719 | clang::Decl *ClangASTSource::CopyDecl(Decl *src_decl) { | ||||
1720 | return m_ast_importer_sp->CopyDecl(m_ast_context, src_decl); | ||||
1721 | } | ||||
1722 | |||||
1723 | ClangASTImporter::DeclOrigin ClangASTSource::GetDeclOrigin(const clang::Decl *decl) { | ||||
1724 | return m_ast_importer_sp->GetDeclOrigin(decl); | ||||
1725 | } | ||||
1726 | |||||
1727 | CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) { | ||||
1728 | TypeSystemClang *src_ast = | ||||
1729 | llvm::dyn_cast_or_null<TypeSystemClang>(src_type.GetTypeSystem()); | ||||
1730 | if (src_ast == nullptr) | ||||
1731 | return CompilerType(); | ||||
1732 | |||||
1733 | QualType copied_qual_type = ClangUtil::GetQualType( | ||||
1734 | m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type)); | ||||
1735 | |||||
1736 | if (copied_qual_type.getAsOpaquePtr() && | ||||
1737 | copied_qual_type->getCanonicalTypeInternal().isNull()) | ||||
1738 | // this shouldn't happen, but we're hardening because the AST importer | ||||
1739 | // seems to be generating bad types on occasion. | ||||
1740 | return CompilerType(); | ||||
1741 | |||||
1742 | return m_clang_ast_context->GetType(copied_qual_type); | ||||
1743 | } | ||||
1744 | |||||
1745 | std::shared_ptr<ClangModulesDeclVendor> | ||||
1746 | ClangASTSource::GetClangModulesDeclVendor() { | ||||
1747 | auto persistent_vars = llvm::cast<ClangPersistentVariables>( | ||||
1748 | m_target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC)); | ||||
1749 | return persistent_vars->GetClangModulesDeclVendor(); | ||||
1750 | } |
1 | //===-- ClangASTImporter.h --------------------------------------*- C++ -*-===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H |
10 | #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H |
11 | |
12 | #include <map> |
13 | #include <memory> |
14 | #include <set> |
15 | #include <vector> |
16 | |
17 | #include "clang/AST/ASTImporter.h" |
18 | #include "clang/AST/CharUnits.h" |
19 | #include "clang/AST/Decl.h" |
20 | #include "clang/AST/DeclCXX.h" |
21 | #include "clang/Basic/FileManager.h" |
22 | #include "clang/Basic/FileSystemOptions.h" |
23 | |
24 | #include "lldb/Host/FileSystem.h" |
25 | #include "lldb/Symbol/CompilerDeclContext.h" |
26 | #include "lldb/Utility/LLDBAssert.h" |
27 | #include "lldb/lldb-types.h" |
28 | |
29 | #include "Plugins/ExpressionParser/Clang/CxxModuleHandler.h" |
30 | |
31 | #include "llvm/ADT/DenseMap.h" |
32 | |
33 | namespace lldb_private { |
34 | |
35 | class ClangASTMetadata; |
36 | class TypeSystemClang; |
37 | |
38 | /// Manages and observes all Clang AST node importing in LLDB. |
39 | /// |
40 | /// The ClangASTImporter takes care of two things: |
41 | /// |
42 | /// 1. Keeps track of all ASTImporter instances in LLDB. |
43 | /// |
44 | /// Clang's ASTImporter takes care of importing types from one ASTContext to |
45 | /// another. This class expands this concept by allowing copying from several |
46 | /// ASTContext instances to several other ASTContext instances. Instead of |
47 | /// constructing a new ASTImporter manually to copy over a type/decl, this class |
48 | /// can be asked to do this. It will construct a ASTImporter for the caller (and |
49 | /// will cache the ASTImporter instance for later use) and then perform the |
50 | /// import. |
51 | /// |
52 | /// This mainly prevents that a caller might construct several ASTImporter |
53 | /// instances for the same source/target ASTContext combination. As the |
54 | /// ASTImporter has an internal state that keeps track of already imported |
55 | /// declarations and so on, using only one ASTImporter instance is more |
56 | /// efficient and less error-prone than using multiple. |
57 | /// |
58 | /// 2. Keeps track of from where declarations were imported (origin-tracking). |
59 | /// The ASTImporter instances in this class usually only performa a minimal |
60 | /// import, i.e., only a shallow copy is made that is filled out on demand |
61 | /// when more information is requested later on. This requires record-keeping |
62 | /// of where any shallow clone originally came from so that the right original |
63 | /// declaration can be found and used as the source of any missing information. |
64 | class ClangASTImporter { |
65 | public: |
66 | struct LayoutInfo { |
67 | LayoutInfo() = default; |
68 | typedef llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
69 | OffsetMap; |
70 | |
71 | uint64_t bit_size = 0; |
72 | uint64_t alignment = 0; |
73 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> field_offsets; |
74 | OffsetMap base_offsets; |
75 | OffsetMap vbase_offsets; |
76 | }; |
77 | |
78 | ClangASTImporter() |
79 | : m_file_manager(clang::FileSystemOptions(), |
80 | FileSystem::Instance().GetVirtualFileSystem()) {} |
81 | |
82 | /// Copies the given type and the respective declarations to the destination |
83 | /// type system. |
84 | /// |
85 | /// This function does a shallow copy and requires that the target AST |
86 | /// has an ExternalASTSource which queries this ClangASTImporter instance |
87 | /// for any additional information that is maybe lacking in the shallow copy. |
88 | /// This also means that the type system of src_type can *not* be deleted |
89 | /// after this function has been called. If you need to delete the source |
90 | /// type system you either need to delete the destination type system first |
91 | /// or use \ref ClangASTImporter::DeportType. |
92 | /// |
93 | /// \see ClangASTImporter::DeportType |
94 | CompilerType CopyType(TypeSystemClang &dst, const CompilerType &src_type); |
95 | |
96 | /// \see ClangASTImporter::CopyType |
97 | clang::Decl *CopyDecl(clang::ASTContext *dst_ctx, clang::Decl *decl); |
98 | |
99 | /// Copies the given type and the respective declarations to the destination |
100 | /// type system. |
101 | /// |
102 | /// Unlike CopyType this function ensures that types/declarations which are |
103 | /// originally from the AST of src_type are fully copied over. The type |
104 | /// system of src_type can safely be deleted after calling this function. |
105 | /// \see ClangASTImporter::CopyType |
106 | CompilerType DeportType(TypeSystemClang &dst, const CompilerType &src_type); |
107 | |
108 | /// Copies the given decl to the destination type system. |
109 | /// \see ClangASTImporter::DeportType |
110 | clang::Decl *DeportDecl(clang::ASTContext *dst_ctx, clang::Decl *decl); |
111 | |
112 | /// Sets the layout for the given RecordDecl. The layout will later be |
113 | /// used by Clang's during code generation. Not calling this function for |
114 | /// a RecordDecl will cause that Clang's codegen tries to layout the |
115 | /// record by itself. |
116 | /// |
117 | /// \param decl The RecordDecl to set the layout for. |
118 | /// \param layout The layout for the record. |
119 | void SetRecordLayout(clang::RecordDecl *decl, const LayoutInfo &layout); |
120 | |
121 | bool LayoutRecordType( |
122 | const clang::RecordDecl *record_decl, uint64_t &bit_size, |
123 | uint64_t &alignment, |
124 | llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets, |
125 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
126 | &base_offsets, |
127 | llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> |
128 | &vbase_offsets); |
129 | |
130 | /// Returns true iff the given type was copied from another TypeSystemClang |
131 | /// and the original type in this other TypeSystemClang might contain |
132 | /// additional information (e.g., the definition of a 'class' type) that could |
133 | /// be imported. |
134 | /// |
135 | /// \see ClangASTImporter::Import |
136 | bool CanImport(const CompilerType &type); |
137 | |
138 | /// If the given type was copied from another TypeSystemClang then copy over |
139 | /// all missing information (e.g., the definition of a 'class' type). |
140 | /// |
141 | /// \return True iff an original type in another TypeSystemClang was found. |
142 | /// Note: Does *not* return false if an original type was found but |
143 | /// no information was imported over. |
144 | /// |
145 | /// \see ClangASTImporter::Import |
146 | bool Import(const CompilerType &type); |
147 | |
148 | bool CompleteType(const CompilerType &compiler_type); |
149 | |
150 | bool CompleteTagDecl(clang::TagDecl *decl); |
151 | |
152 | bool CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin); |
153 | |
154 | bool CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *interface_decl); |
155 | |
156 | bool CompleteAndFetchChildren(clang::QualType type); |
157 | |
158 | bool RequireCompleteType(clang::QualType type); |
159 | |
160 | /// Updates the internal origin-tracking information so that the given |
161 | /// 'original' decl is from now on used to import additional information |
162 | /// into the given decl. |
163 | /// |
164 | /// Usually the origin-tracking in the ClangASTImporter is automatically |
165 | /// updated when a declaration is imported, so the only valid reason to ever |
166 | /// call this is if there is a 'better' original decl and the target decl |
167 | /// is only a shallow clone that lacks any contents. |
168 | void SetDeclOrigin(const clang::Decl *decl, clang::Decl *original_decl); |
169 | |
170 | ClangASTMetadata *GetDeclMetadata(const clang::Decl *decl); |
171 | |
172 | // |
173 | // Namespace maps |
174 | // |
175 | |
176 | typedef std::pair<lldb::ModuleSP, CompilerDeclContext> NamespaceMapItem; |
177 | typedef std::vector<NamespaceMapItem> NamespaceMap; |
178 | typedef std::shared_ptr<NamespaceMap> NamespaceMapSP; |
179 | |
180 | void RegisterNamespaceMap(const clang::NamespaceDecl *decl, |
181 | NamespaceMapSP &namespace_map); |
182 | |
183 | NamespaceMapSP GetNamespaceMap(const clang::NamespaceDecl *decl); |
184 | |
185 | void BuildNamespaceMap(const clang::NamespaceDecl *decl); |
186 | |
187 | // |
188 | // Completers for maps |
189 | // |
190 | |
191 | class MapCompleter { |
192 | public: |
193 | virtual ~MapCompleter(); |
194 | |
195 | virtual void CompleteNamespaceMap(NamespaceMapSP &namespace_map, |
196 | ConstString name, |
197 | NamespaceMapSP &parent_map) const = 0; |
198 | }; |
199 | |
200 | void InstallMapCompleter(clang::ASTContext *dst_ctx, |
201 | MapCompleter &completer) { |
202 | ASTContextMetadataSP context_md; |
203 | ContextMetadataMap::iterator context_md_iter = m_metadata_map.find(dst_ctx); |
204 | |
205 | if (context_md_iter == m_metadata_map.end()) { |
206 | context_md = ASTContextMetadataSP(new ASTContextMetadata(dst_ctx)); |
207 | m_metadata_map[dst_ctx] = context_md; |
208 | } else { |
209 | context_md = context_md_iter->second; |
210 | } |
211 | |
212 | context_md->m_map_completer = &completer; |
213 | } |
214 | |
215 | void ForgetDestination(clang::ASTContext *dst_ctx); |
216 | void ForgetSource(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx); |
217 | |
218 | struct DeclOrigin { |
219 | DeclOrigin() = default; |
220 | |
221 | DeclOrigin(clang::ASTContext *_ctx, clang::Decl *_decl) |
222 | : ctx(_ctx), decl(_decl) { |
223 | // The decl has to be in its associated ASTContext. |
224 | assert(_decl == nullptr || &_decl->getASTContext() == _ctx)((void)0); |
225 | } |
226 | |
227 | DeclOrigin(const DeclOrigin &rhs) { |
228 | ctx = rhs.ctx; |
229 | decl = rhs.decl; |
230 | } |
231 | |
232 | void operator=(const DeclOrigin &rhs) { |
233 | ctx = rhs.ctx; |
234 | decl = rhs.decl; |
235 | } |
236 | |
237 | bool Valid() const { return (ctx != nullptr || decl != nullptr); } |
238 | |
239 | clang::ASTContext *ctx = nullptr; |
240 | clang::Decl *decl = nullptr; |
241 | }; |
242 | |
243 | /// Listener interface used by the ASTImporterDelegate to inform other code |
244 | /// about decls that have been imported the first time. |
245 | struct NewDeclListener { |
246 | virtual ~NewDeclListener() = default; |
247 | /// A decl has been imported for the first time. |
248 | virtual void NewDeclImported(clang::Decl *from, clang::Decl *to) = 0; |
249 | }; |
250 | |
251 | /// ASTImporter that intercepts and records the import process of the |
252 | /// underlying ASTImporter. |
253 | /// |
254 | /// This class updates the map from declarations to their original |
255 | /// declarations and can record declarations that have been imported in a |
256 | /// certain interval. |
257 | /// |
258 | /// When intercepting a declaration import, the ASTImporterDelegate uses the |
259 | /// CxxModuleHandler to replace any missing or malformed declarations with |
260 | /// their counterpart from a C++ module. |
261 | struct ASTImporterDelegate : public clang::ASTImporter { |
262 | ASTImporterDelegate(ClangASTImporter &master, clang::ASTContext *target_ctx, |
263 | clang::ASTContext *source_ctx) |
264 | : clang::ASTImporter(*target_ctx, master.m_file_manager, *source_ctx, |
265 | master.m_file_manager, true /*minimal*/), |
266 | m_master(master), m_source_ctx(source_ctx) { |
267 | // Target and source ASTContext shouldn't be identical. Importing AST |
268 | // nodes within the same AST doesn't make any sense as the whole idea |
269 | // is to import them to a different AST. |
270 | lldbassert(target_ctx != source_ctx && "Can't import into itself")lldb_private::lldb_assert(static_cast<bool>(target_ctx != source_ctx && "Can't import into itself"), "target_ctx != source_ctx && \"Can't import into itself\"" , __FUNCTION__, "/usr/src/gnu/usr.bin/clang/liblldbPluginExpressionParser/../../../llvm/lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h" , 270); |
271 | // This is always doing a minimal import of any declarations. This means |
272 | // that there has to be an ExternalASTSource in the target ASTContext |
273 | // (that should implement the callbacks that complete any declarations |
274 | // on demand). Without an ExternalASTSource, this ASTImporter will just |
275 | // do a minimal import and the imported declarations won't be completed. |
276 | assert(target_ctx->getExternalSource() && "Missing ExternalSource")((void)0); |
277 | setODRHandling(clang::ASTImporter::ODRHandlingType::Liberal); |
278 | } |
279 | |
280 | /// Scope guard that attaches a CxxModuleHandler to an ASTImporterDelegate |
281 | /// and deattaches it at the end of the scope. Supports being used multiple |
282 | /// times on the same ASTImporterDelegate instance in nested scopes. |
283 | class CxxModuleScope { |
284 | /// The handler we attach to the ASTImporterDelegate. |
285 | CxxModuleHandler m_handler; |
286 | /// The ASTImporterDelegate we are supposed to attach the handler to. |
287 | ASTImporterDelegate &m_delegate; |
288 | /// True iff we attached the handler to the ASTImporterDelegate. |
289 | bool m_valid = false; |
290 | |
291 | public: |
292 | CxxModuleScope(ASTImporterDelegate &delegate, clang::ASTContext *dst_ctx) |
293 | : m_delegate(delegate) { |
294 | // If the delegate doesn't have a CxxModuleHandler yet, create one |
295 | // and attach it. |
296 | if (!delegate.m_std_handler) { |
297 | m_handler = CxxModuleHandler(delegate, dst_ctx); |
298 | m_valid = true; |
299 | delegate.m_std_handler = &m_handler; |
300 | } |
301 | } |
302 | ~CxxModuleScope() { |
303 | if (m_valid) { |
304 | // Make sure no one messed with the handler we placed. |
305 | assert(m_delegate.m_std_handler == &m_handler)((void)0); |
306 | m_delegate.m_std_handler = nullptr; |
307 | } |
308 | } |
309 | }; |
310 | |
311 | void ImportDefinitionTo(clang::Decl *to, clang::Decl *from); |
312 | |
313 | void Imported(clang::Decl *from, clang::Decl *to) override; |
314 | |
315 | clang::Decl *GetOriginalDecl(clang::Decl *To) override; |
316 | |
317 | void SetImportListener(NewDeclListener *listener) { |
318 | assert(m_new_decl_listener == nullptr && "Already attached a listener?")((void)0); |
319 | m_new_decl_listener = listener; |
320 | } |
321 | void RemoveImportListener() { m_new_decl_listener = nullptr; } |
322 | |
323 | protected: |
324 | llvm::Expected<clang::Decl *> ImportImpl(clang::Decl *From) override; |
325 | |
326 | private: |
327 | /// Decls we should ignore when mapping decls back to their original |
328 | /// ASTContext. Used by the CxxModuleHandler to mark declarations that |
329 | /// were created from the 'std' C++ module to prevent that the Importer |
330 | /// tries to sync them with the broken equivalent in the debug info AST. |
331 | llvm::SmallPtrSet<clang::Decl *, 16> m_decls_to_ignore; |
332 | ClangASTImporter &m_master; |
333 | clang::ASTContext *m_source_ctx; |
334 | CxxModuleHandler *m_std_handler = nullptr; |
335 | /// The currently attached listener. |
336 | NewDeclListener *m_new_decl_listener = nullptr; |
337 | }; |
338 | |
339 | typedef std::shared_ptr<ASTImporterDelegate> ImporterDelegateSP; |
340 | typedef llvm::DenseMap<clang::ASTContext *, ImporterDelegateSP> DelegateMap; |
341 | typedef llvm::DenseMap<const clang::NamespaceDecl *, NamespaceMapSP> |
342 | NamespaceMetaMap; |
343 | |
344 | class ASTContextMetadata { |
345 | typedef llvm::DenseMap<const clang::Decl *, DeclOrigin> OriginMap; |
346 | |
347 | public: |
348 | ASTContextMetadata(clang::ASTContext *dst_ctx) : m_dst_ctx(dst_ctx) {} |
349 | |
350 | clang::ASTContext *m_dst_ctx; |
351 | DelegateMap m_delegates; |
352 | |
353 | NamespaceMetaMap m_namespace_maps; |
354 | MapCompleter *m_map_completer = nullptr; |
355 | |
356 | /// Sets the DeclOrigin for the given Decl and overwrites any existing |
357 | /// DeclOrigin. |
358 | void setOrigin(const clang::Decl *decl, DeclOrigin origin) { |
359 | // Setting the origin of any decl to itself (or to a different decl |
360 | // in the same ASTContext) doesn't make any sense. It will also cause |
361 | // ASTImporterDelegate::ImportImpl to infinite recurse when trying to find |
362 | // the 'original' Decl when importing code. |
363 | assert(&decl->getASTContext() != origin.ctx &&((void)0) |
364 | "Trying to set decl origin to its own ASTContext?")((void)0); |
365 | assert(decl != origin.decl && "Trying to set decl origin to itself?")((void)0); |
366 | m_origins[decl] = origin; |
367 | } |
368 | |
369 | /// Removes any tracked DeclOrigin for the given decl. |
370 | void removeOrigin(const clang::Decl *decl) { m_origins.erase(decl); } |
371 | |
372 | /// Remove all DeclOrigin entries that point to the given ASTContext. |
373 | /// Useful when an ASTContext is about to be deleted and all the dangling |
374 | /// pointers to it need to be removed. |
375 | void removeOriginsWithContext(clang::ASTContext *ctx) { |
376 | for (OriginMap::iterator iter = m_origins.begin(); |
377 | iter != m_origins.end();) { |
378 | if (iter->second.ctx == ctx) |
379 | m_origins.erase(iter++); |
380 | else |
381 | ++iter; |
382 | } |
383 | } |
384 | |
385 | /// Returns the DeclOrigin for the given Decl or an invalid DeclOrigin |
386 | /// instance if there no known DeclOrigin for the given Decl. |
387 | DeclOrigin getOrigin(const clang::Decl *decl) const { |
388 | auto iter = m_origins.find(decl); |
389 | if (iter == m_origins.end()) |
390 | return DeclOrigin(); |
391 | return iter->second; |
392 | } |
393 | |
394 | /// Returns true there is a known DeclOrigin for the given Decl. |
395 | bool hasOrigin(const clang::Decl *decl) const { |
396 | return getOrigin(decl).Valid(); |
397 | } |
398 | |
399 | private: |
400 | /// Maps declarations to the ASTContext/Decl from which they were imported |
401 | /// from. If a declaration is from an ASTContext which has been deleted |
402 | /// since the declaration was imported or the declaration wasn't created by |
403 | /// the ASTImporter, then it doesn't have a DeclOrigin and will not be |
404 | /// tracked here. |
405 | OriginMap m_origins; |
406 | }; |
407 | |
408 | typedef std::shared_ptr<ASTContextMetadata> ASTContextMetadataSP; |
409 | typedef llvm::DenseMap<const clang::ASTContext *, ASTContextMetadataSP> |
410 | ContextMetadataMap; |
411 | |
412 | ContextMetadataMap m_metadata_map; |
413 | |
414 | ASTContextMetadataSP GetContextMetadata(clang::ASTContext *dst_ctx) { |
415 | ContextMetadataMap::iterator context_md_iter = m_metadata_map.find(dst_ctx); |
416 | |
417 | if (context_md_iter == m_metadata_map.end()) { |
418 | ASTContextMetadataSP context_md = |
419 | ASTContextMetadataSP(new ASTContextMetadata(dst_ctx)); |
420 | m_metadata_map[dst_ctx] = context_md; |
421 | return context_md; |
422 | } |
423 | return context_md_iter->second; |
424 | } |
425 | |
426 | ASTContextMetadataSP MaybeGetContextMetadata(clang::ASTContext *dst_ctx) { |
427 | ContextMetadataMap::iterator context_md_iter = m_metadata_map.find(dst_ctx); |
428 | |
429 | if (context_md_iter != m_metadata_map.end()) |
430 | return context_md_iter->second; |
431 | return ASTContextMetadataSP(); |
432 | } |
433 | |
434 | ImporterDelegateSP GetDelegate(clang::ASTContext *dst_ctx, |
435 | clang::ASTContext *src_ctx) { |
436 | ASTContextMetadataSP context_md = GetContextMetadata(dst_ctx); |
437 | |
438 | DelegateMap &delegates = context_md->m_delegates; |
439 | DelegateMap::iterator delegate_iter = delegates.find(src_ctx); |
440 | |
441 | if (delegate_iter == delegates.end()) { |
442 | ImporterDelegateSP delegate = |
443 | ImporterDelegateSP(new ASTImporterDelegate(*this, dst_ctx, src_ctx)); |
444 | delegates[src_ctx] = delegate; |
445 | return delegate; |
446 | } |
447 | return delegate_iter->second; |
448 | } |
449 | |
450 | DeclOrigin GetDeclOrigin(const clang::Decl *decl); |
451 | |
452 | clang::FileManager m_file_manager; |
453 | typedef llvm::DenseMap<const clang::RecordDecl *, LayoutInfo> |
454 | RecordDeclToLayoutMap; |
455 | |
456 | RecordDeclToLayoutMap m_record_decl_to_layout_map; |
457 | }; |
458 | |
459 | } // namespace lldb_private |
460 | |
461 | #endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGASTIMPORTER_H |