LLDB  mainline
ClangASTImporter.cpp
Go to the documentation of this file.
1 //===-- ClangASTImporter.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 "lldb/Core/Module.h"
11 #include "lldb/Utility/Log.h"
12 #include "clang/AST/Decl.h"
13 #include "clang/AST/DeclCXX.h"
14 #include "clang/AST/DeclObjC.h"
15 #include "clang/Sema/Lookup.h"
16 #include "clang/Sema/Sema.h"
17 #include "llvm/Support/raw_ostream.h"
18 
25 
26 #include <memory>
27 
28 using namespace lldb_private;
29 using namespace clang;
30 
32  const CompilerType &src_type) {
33  clang::ASTContext &dst_clang_ast = dst_ast.getASTContext();
34 
35  TypeSystemClang *src_ast =
36  llvm::dyn_cast_or_null<TypeSystemClang>(src_type.GetTypeSystem());
37  if (!src_ast)
38  return CompilerType();
39 
40  clang::ASTContext &src_clang_ast = src_ast->getASTContext();
41 
42  clang::QualType src_qual_type = ClangUtil::GetQualType(src_type);
43 
44  ImporterDelegateSP delegate_sp(GetDelegate(&dst_clang_ast, &src_clang_ast));
45  if (!delegate_sp)
46  return CompilerType();
47 
48  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, &dst_clang_ast);
49 
50  llvm::Expected<QualType> ret_or_error = delegate_sp->Import(src_qual_type);
51  if (!ret_or_error) {
52  Log *log =
54  LLDB_LOG_ERROR(log, ret_or_error.takeError(),
55  "Couldn't import type: {0}");
56  return CompilerType();
57  }
58 
59  lldb::opaque_compiler_type_t dst_clang_type = ret_or_error->getAsOpaquePtr();
60 
61  if (dst_clang_type)
62  return CompilerType(&dst_ast, dst_clang_type);
63  return CompilerType();
64 }
65 
66 clang::Decl *ClangASTImporter::CopyDecl(clang::ASTContext *dst_ast,
67  clang::Decl *decl) {
68  ImporterDelegateSP delegate_sp;
69 
70  clang::ASTContext *src_ast = &decl->getASTContext();
71  delegate_sp = GetDelegate(dst_ast, src_ast);
72 
73  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
74 
75  if (!delegate_sp)
76  return nullptr;
77 
78  llvm::Expected<clang::Decl *> result = delegate_sp->Import(decl);
79  if (!result) {
81  LLDB_LOG_ERROR(log, result.takeError(), "Couldn't import decl: {0}");
82  if (log) {
84  ClangASTMetadata *metadata = GetDeclMetadata(decl);
85  if (metadata)
86  user_id = metadata->GetUserID();
87 
88  if (NamedDecl *named_decl = dyn_cast<NamedDecl>(decl))
89  LLDB_LOG(log,
90  " [ClangASTImporter] WARNING: Failed to import a {0} "
91  "'{1}', metadata {2}",
92  decl->getDeclKindName(), named_decl->getNameAsString(),
93  user_id);
94  else
95  LLDB_LOG(log,
96  " [ClangASTImporter] WARNING: Failed to import a {0}, "
97  "metadata {1}",
98  decl->getDeclKindName(), user_id);
99  }
100  return nullptr;
101  }
102 
103  return *result;
104 }
105 
107 private:
108  struct Backup {
109  clang::DeclContext *decl_context;
110  clang::DeclContext *lexical_decl_context;
111  };
112 
113  llvm::DenseMap<clang::Decl *, Backup> m_backups;
114 
115  void OverrideOne(clang::Decl *decl) {
116  if (m_backups.find(decl) != m_backups.end()) {
117  return;
118  }
119 
120  m_backups[decl] = {decl->getDeclContext(), decl->getLexicalDeclContext()};
121 
122  decl->setDeclContext(decl->getASTContext().getTranslationUnitDecl());
123  decl->setLexicalDeclContext(decl->getASTContext().getTranslationUnitDecl());
124  }
125 
127  clang::Decl *decl, clang::DeclContext *base,
128  clang::DeclContext *(clang::Decl::*contextFromDecl)(),
129  clang::DeclContext *(clang::DeclContext::*contextFromContext)()) {
130  for (DeclContext *decl_ctx = (decl->*contextFromDecl)(); decl_ctx;
131  decl_ctx = (decl_ctx->*contextFromContext)()) {
132  if (decl_ctx == base) {
133  return true;
134  }
135  }
136 
137  return false;
138  }
139 
140  clang::Decl *GetEscapedChild(clang::Decl *decl,
141  clang::DeclContext *base = nullptr) {
142  if (base) {
143  // decl's DeclContext chains must pass through base.
144 
145  if (!ChainPassesThrough(decl, base, &clang::Decl::getDeclContext,
146  &clang::DeclContext::getParent) ||
147  !ChainPassesThrough(decl, base, &clang::Decl::getLexicalDeclContext,
148  &clang::DeclContext::getLexicalParent)) {
149  return decl;
150  }
151  } else {
152  base = clang::dyn_cast<clang::DeclContext>(decl);
153 
154  if (!base) {
155  return nullptr;
156  }
157  }
158 
159  if (clang::DeclContext *context =
160  clang::dyn_cast<clang::DeclContext>(decl)) {
161  for (clang::Decl *decl : context->decls()) {
162  if (clang::Decl *escaped_child = GetEscapedChild(decl)) {
163  return escaped_child;
164  }
165  }
166  }
167 
168  return nullptr;
169  }
170 
171  void Override(clang::Decl *decl) {
172  if (clang::Decl *escaped_child = GetEscapedChild(decl)) {
174 
175  LLDB_LOG(log,
176  " [ClangASTImporter] DeclContextOverride couldn't "
177  "override ({0}Decl*){1} - its child ({2}Decl*){3} escapes",
178  decl->getDeclKindName(), decl, escaped_child->getDeclKindName(),
179  escaped_child);
180  lldbassert(0 && "Couldn't override!");
181  }
182 
183  OverrideOne(decl);
184  }
185 
186 public:
188 
189  void OverrideAllDeclsFromContainingFunction(clang::Decl *decl) {
190  for (DeclContext *decl_context = decl->getLexicalDeclContext();
191  decl_context; decl_context = decl_context->getLexicalParent()) {
192  DeclContext *redecl_context = decl_context->getRedeclContext();
193 
194  if (llvm::isa<FunctionDecl>(redecl_context) &&
195  llvm::isa<TranslationUnitDecl>(redecl_context->getLexicalParent())) {
196  for (clang::Decl *child_decl : decl_context->decls()) {
197  Override(child_decl);
198  }
199  }
200  }
201  }
202 
204  for (const std::pair<clang::Decl *, Backup> &backup : m_backups) {
205  backup.first->setDeclContext(backup.second.decl_context);
206  backup.first->setLexicalDeclContext(backup.second.lexical_decl_context);
207  }
208  }
209 };
210 
211 namespace {
212 /// Completes all imported TagDecls at the end of the scope.
213 ///
214 /// While in a CompleteTagDeclsScope, every decl that could be completed will
215 /// be completed at the end of the scope (including all Decls that are
216 /// imported while completing the original Decls).
217 class CompleteTagDeclsScope : public ClangASTImporter::NewDeclListener {
219  /// List of declarations in the target context that need to be completed.
220  /// Every declaration should only be completed once and therefore should only
221  /// be once in this list.
222  llvm::SetVector<NamedDecl *> m_decls_to_complete;
223  /// Set of declarations that already were successfully completed (not just
224  /// added to m_decls_to_complete).
225  llvm::SmallPtrSet<NamedDecl *, 32> m_decls_already_completed;
226  clang::ASTContext *m_dst_ctx;
227  clang::ASTContext *m_src_ctx;
228  ClangASTImporter &importer;
229 
230 public:
231  /// Constructs a CompleteTagDeclsScope.
232  /// \param importer The ClangASTImporter that we should observe.
233  /// \param dst_ctx The ASTContext to which Decls are imported.
234  /// \param src_ctx The ASTContext from which Decls are imported.
235  explicit CompleteTagDeclsScope(ClangASTImporter &importer,
236  clang::ASTContext *dst_ctx,
237  clang::ASTContext *src_ctx)
238  : m_delegate(importer.GetDelegate(dst_ctx, src_ctx)), m_dst_ctx(dst_ctx),
239  m_src_ctx(src_ctx), importer(importer) {
240  m_delegate->SetImportListener(this);
241  }
242 
243  virtual ~CompleteTagDeclsScope() {
245  importer.GetContextMetadata(m_dst_ctx);
246 
247  // Complete all decls we collected until now.
248  while (!m_decls_to_complete.empty()) {
249  NamedDecl *decl = m_decls_to_complete.pop_back_val();
250  m_decls_already_completed.insert(decl);
251 
252  // The decl that should be completed has to be imported into the target
253  // context from some other context.
254  assert(to_context_md->hasOrigin(decl));
255  // We should only complete decls coming from the source context.
256  assert(to_context_md->getOrigin(decl).ctx == m_src_ctx);
257 
258  Decl *original_decl = to_context_md->getOrigin(decl).decl;
259 
260  // Complete the decl now.
261  TypeSystemClang::GetCompleteDecl(m_src_ctx, original_decl);
262  if (auto *tag_decl = dyn_cast<TagDecl>(decl)) {
263  if (auto *original_tag_decl = dyn_cast<TagDecl>(original_decl)) {
264  if (original_tag_decl->isCompleteDefinition()) {
265  m_delegate->ImportDefinitionTo(tag_decl, original_tag_decl);
266  tag_decl->setCompleteDefinition(true);
267  }
268  }
269 
270  tag_decl->setHasExternalLexicalStorage(false);
271  tag_decl->setHasExternalVisibleStorage(false);
272  } else if (auto *container_decl = dyn_cast<ObjCContainerDecl>(decl)) {
273  container_decl->setHasExternalLexicalStorage(false);
274  container_decl->setHasExternalVisibleStorage(false);
275  }
276 
277  to_context_md->removeOrigin(decl);
278  }
279 
280  // Stop listening to imported decls. We do this after clearing the
281  // Decls we needed to import to catch all Decls they might have pulled in.
282  m_delegate->RemoveImportListener();
283  }
284 
285  void NewDeclImported(clang::Decl *from, clang::Decl *to) override {
286  // Filter out decls that we can't complete later.
287  if (!isa<TagDecl>(to) && !isa<ObjCInterfaceDecl>(to))
288  return;
289  RecordDecl *from_record_decl = dyn_cast<RecordDecl>(from);
290  // We don't need to complete injected class name decls.
291  if (from_record_decl && from_record_decl->isInjectedClassName())
292  return;
293 
294  NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to);
295  // Check if we already completed this type.
296  if (m_decls_already_completed.count(to_named_decl) != 0)
297  return;
298  // Queue this type to be completed.
299  m_decls_to_complete.insert(to_named_decl);
300  }
301 };
302 } // namespace
303 
305  const CompilerType &src_type) {
307 
308  TypeSystemClang *src_ctxt =
309  llvm::cast<TypeSystemClang>(src_type.GetTypeSystem());
310 
311  LLDB_LOG(log,
312  " [ClangASTImporter] DeportType called on ({0}Type*){1} "
313  "from (ASTContext*){2} to (ASTContext*){3}",
314  src_type.GetTypeName(), src_type.GetOpaqueQualType(),
315  &src_ctxt->getASTContext(), &dst.getASTContext());
316 
317  DeclContextOverride decl_context_override;
318 
319  if (auto *t = ClangUtil::GetQualType(src_type)->getAs<TagType>())
320  decl_context_override.OverrideAllDeclsFromContainingFunction(t->getDecl());
321 
322  CompleteTagDeclsScope complete_scope(*this, &dst.getASTContext(),
323  &src_ctxt->getASTContext());
324  return CopyType(dst, src_type);
325 }
326 
327 clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,
328  clang::Decl *decl) {
330 
331  clang::ASTContext *src_ctx = &decl->getASTContext();
332  LLDB_LOG(log,
333  " [ClangASTImporter] DeportDecl called on ({0}Decl*){1} from "
334  "(ASTContext*){2} to (ASTContext*){3}",
335  decl->getDeclKindName(), decl, src_ctx, dst_ctx);
336 
337  DeclContextOverride decl_context_override;
338 
339  decl_context_override.OverrideAllDeclsFromContainingFunction(decl);
340 
341  clang::Decl *result;
342  {
343  CompleteTagDeclsScope complete_scope(*this, dst_ctx, src_ctx);
344  result = CopyDecl(dst_ctx, decl);
345  }
346 
347  if (!result)
348  return nullptr;
349 
350  LLDB_LOG(log,
351  " [ClangASTImporter] DeportDecl deported ({0}Decl*){1} to "
352  "({2}Decl*){3}",
353  decl->getDeclKindName(), decl, result->getDeclKindName(), result);
354 
355  return result;
356 }
357 
359  if (!ClangUtil::IsClangType(type))
360  return false;
361 
362  clang::QualType qual_type(
364 
365  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
366  switch (type_class) {
367  case clang::Type::Record: {
368  const clang::CXXRecordDecl *cxx_record_decl =
369  qual_type->getAsCXXRecordDecl();
370  if (cxx_record_decl) {
371  if (GetDeclOrigin(cxx_record_decl).Valid())
372  return true;
373  }
374  } break;
375 
376  case clang::Type::Enum: {
377  clang::EnumDecl *enum_decl =
378  llvm::cast<clang::EnumType>(qual_type)->getDecl();
379  if (enum_decl) {
380  if (GetDeclOrigin(enum_decl).Valid())
381  return true;
382  }
383  } break;
384 
385  case clang::Type::ObjCObject:
386  case clang::Type::ObjCInterface: {
387  const clang::ObjCObjectType *objc_class_type =
388  llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
389  if (objc_class_type) {
390  clang::ObjCInterfaceDecl *class_interface_decl =
391  objc_class_type->getInterface();
392  // We currently can't complete objective C types through the newly added
393  // ASTContext because it only supports TagDecl objects right now...
394  if (class_interface_decl) {
395  if (GetDeclOrigin(class_interface_decl).Valid())
396  return true;
397  }
398  }
399  } break;
400 
401  case clang::Type::Typedef:
402  return CanImport(CompilerType(type.GetTypeSystem(),
403  llvm::cast<clang::TypedefType>(qual_type)
404  ->getDecl()
405  ->getUnderlyingType()
406  .getAsOpaquePtr()));
407 
408  case clang::Type::Auto:
409  return CanImport(CompilerType(type.GetTypeSystem(),
410  llvm::cast<clang::AutoType>(qual_type)
411  ->getDeducedType()
412  .getAsOpaquePtr()));
413 
414  case clang::Type::Elaborated:
415  return CanImport(CompilerType(type.GetTypeSystem(),
416  llvm::cast<clang::ElaboratedType>(qual_type)
417  ->getNamedType()
418  .getAsOpaquePtr()));
419 
420  case clang::Type::Paren:
421  return CanImport(CompilerType(
422  type.GetTypeSystem(),
423  llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
424 
425  default:
426  break;
427  }
428 
429  return false;
430 }
431 
433  if (!ClangUtil::IsClangType(type))
434  return false;
435 
436  clang::QualType qual_type(
438 
439  const clang::Type::TypeClass type_class = qual_type->getTypeClass();
440  switch (type_class) {
441  case clang::Type::Record: {
442  const clang::CXXRecordDecl *cxx_record_decl =
443  qual_type->getAsCXXRecordDecl();
444  if (cxx_record_decl) {
445  if (GetDeclOrigin(cxx_record_decl).Valid())
446  return CompleteAndFetchChildren(qual_type);
447  }
448  } break;
449 
450  case clang::Type::Enum: {
451  clang::EnumDecl *enum_decl =
452  llvm::cast<clang::EnumType>(qual_type)->getDecl();
453  if (enum_decl) {
454  if (GetDeclOrigin(enum_decl).Valid())
455  return CompleteAndFetchChildren(qual_type);
456  }
457  } break;
458 
459  case clang::Type::ObjCObject:
460  case clang::Type::ObjCInterface: {
461  const clang::ObjCObjectType *objc_class_type =
462  llvm::dyn_cast<clang::ObjCObjectType>(qual_type);
463  if (objc_class_type) {
464  clang::ObjCInterfaceDecl *class_interface_decl =
465  objc_class_type->getInterface();
466  // We currently can't complete objective C types through the newly added
467  // ASTContext because it only supports TagDecl objects right now...
468  if (class_interface_decl) {
469  if (GetDeclOrigin(class_interface_decl).Valid())
470  return CompleteAndFetchChildren(qual_type);
471  }
472  }
473  } break;
474 
475  case clang::Type::Typedef:
476  return Import(CompilerType(type.GetTypeSystem(),
477  llvm::cast<clang::TypedefType>(qual_type)
478  ->getDecl()
479  ->getUnderlyingType()
480  .getAsOpaquePtr()));
481 
482  case clang::Type::Auto:
483  return Import(CompilerType(type.GetTypeSystem(),
484  llvm::cast<clang::AutoType>(qual_type)
485  ->getDeducedType()
486  .getAsOpaquePtr()));
487 
488  case clang::Type::Elaborated:
489  return Import(CompilerType(type.GetTypeSystem(),
490  llvm::cast<clang::ElaboratedType>(qual_type)
491  ->getNamedType()
492  .getAsOpaquePtr()));
493 
494  case clang::Type::Paren:
495  return Import(CompilerType(
496  type.GetTypeSystem(),
497  llvm::cast<clang::ParenType>(qual_type)->desugar().getAsOpaquePtr()));
498 
499  default:
500  break;
501  }
502  return false;
503 }
504 
505 bool ClangASTImporter::CompleteType(const CompilerType &compiler_type) {
506  if (!CanImport(compiler_type))
507  return false;
508 
509  if (Import(compiler_type)) {
511  return true;
512  }
513 
515  false);
516  return false;
517 }
518 
520  const clang::RecordDecl *record_decl, uint64_t &bit_size,
521  uint64_t &alignment,
522  llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
523  llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
524  &base_offsets,
525  llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits>
526  &vbase_offsets) {
527  RecordDeclToLayoutMap::iterator pos =
528  m_record_decl_to_layout_map.find(record_decl);
529  bool success = false;
530  base_offsets.clear();
531  vbase_offsets.clear();
532  if (pos != m_record_decl_to_layout_map.end()) {
533  bit_size = pos->second.bit_size;
534  alignment = pos->second.alignment;
535  field_offsets.swap(pos->second.field_offsets);
536  base_offsets.swap(pos->second.base_offsets);
537  vbase_offsets.swap(pos->second.vbase_offsets);
538  m_record_decl_to_layout_map.erase(pos);
539  success = true;
540  } else {
541  bit_size = 0;
542  alignment = 0;
543  field_offsets.clear();
544  }
545  return success;
546 }
547 
548 void ClangASTImporter::SetRecordLayout(clang::RecordDecl *decl,
549  const LayoutInfo &layout) {
550  m_record_decl_to_layout_map.insert(std::make_pair(decl, layout));
551 }
552 
553 bool ClangASTImporter::CompleteTagDecl(clang::TagDecl *decl) {
554  DeclOrigin decl_origin = GetDeclOrigin(decl);
555 
556  if (!decl_origin.Valid())
557  return false;
558 
559  if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
560  return false;
561 
562  ImporterDelegateSP delegate_sp(
563  GetDelegate(&decl->getASTContext(), decl_origin.ctx));
564 
565  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp,
566  &decl->getASTContext());
567  if (delegate_sp)
568  delegate_sp->ImportDefinitionTo(decl, decl_origin.decl);
569 
570  return true;
571 }
572 
574  clang::TagDecl *origin_decl) {
575  clang::ASTContext *origin_ast_ctx = &origin_decl->getASTContext();
576 
577  if (!TypeSystemClang::GetCompleteDecl(origin_ast_ctx, origin_decl))
578  return false;
579 
580  ImporterDelegateSP delegate_sp(
581  GetDelegate(&decl->getASTContext(), origin_ast_ctx));
582 
583  if (delegate_sp)
584  delegate_sp->ImportDefinitionTo(decl, origin_decl);
585 
586  ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
587 
588  context_md->setOrigin(decl, DeclOrigin(origin_ast_ctx, origin_decl));
589  return true;
590 }
591 
593  clang::ObjCInterfaceDecl *interface_decl) {
594  DeclOrigin decl_origin = GetDeclOrigin(interface_decl);
595 
596  if (!decl_origin.Valid())
597  return false;
598 
599  if (!TypeSystemClang::GetCompleteDecl(decl_origin.ctx, decl_origin.decl))
600  return false;
601 
602  ImporterDelegateSP delegate_sp(
603  GetDelegate(&interface_decl->getASTContext(), decl_origin.ctx));
604 
605  if (delegate_sp)
606  delegate_sp->ImportDefinitionTo(interface_decl, decl_origin.decl);
607 
608  if (ObjCInterfaceDecl *super_class = interface_decl->getSuperClass())
609  RequireCompleteType(clang::QualType(super_class->getTypeForDecl(), 0));
610 
611  return true;
612 }
613 
614 bool ClangASTImporter::CompleteAndFetchChildren(clang::QualType type) {
615  if (!RequireCompleteType(type))
616  return false;
617 
619 
620  if (const TagType *tag_type = type->getAs<TagType>()) {
621  TagDecl *tag_decl = tag_type->getDecl();
622 
623  DeclOrigin decl_origin = GetDeclOrigin(tag_decl);
624 
625  if (!decl_origin.Valid())
626  return false;
627 
628  ImporterDelegateSP delegate_sp(
629  GetDelegate(&tag_decl->getASTContext(), decl_origin.ctx));
630 
631  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp,
632  &tag_decl->getASTContext());
633 
634  TagDecl *origin_tag_decl = llvm::dyn_cast<TagDecl>(decl_origin.decl);
635 
636  for (Decl *origin_child_decl : origin_tag_decl->decls()) {
637  llvm::Expected<Decl *> imported_or_err =
638  delegate_sp->Import(origin_child_decl);
639  if (!imported_or_err) {
640  LLDB_LOG_ERROR(log, imported_or_err.takeError(),
641  "Couldn't import decl: {0}");
642  return false;
643  }
644  }
645 
646  if (RecordDecl *record_decl = dyn_cast<RecordDecl>(origin_tag_decl))
647  record_decl->setHasLoadedFieldsFromExternalStorage(true);
648 
649  return true;
650  }
651 
652  if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>()) {
653  if (ObjCInterfaceDecl *objc_interface_decl =
654  objc_object_type->getInterface()) {
655  DeclOrigin decl_origin = GetDeclOrigin(objc_interface_decl);
656 
657  if (!decl_origin.Valid())
658  return false;
659 
660  ImporterDelegateSP delegate_sp(
661  GetDelegate(&objc_interface_decl->getASTContext(), decl_origin.ctx));
662 
663  ObjCInterfaceDecl *origin_interface_decl =
664  llvm::dyn_cast<ObjCInterfaceDecl>(decl_origin.decl);
665 
666  for (Decl *origin_child_decl : origin_interface_decl->decls()) {
667  llvm::Expected<Decl *> imported_or_err =
668  delegate_sp->Import(origin_child_decl);
669  if (!imported_or_err) {
670  LLDB_LOG_ERROR(log, imported_or_err.takeError(),
671  "Couldn't import decl: {0}");
672  return false;
673  }
674  }
675 
676  return true;
677  }
678  return false;
679  }
680 
681  return true;
682 }
683 
684 bool ClangASTImporter::RequireCompleteType(clang::QualType type) {
685  if (type.isNull())
686  return false;
687 
688  if (const TagType *tag_type = type->getAs<TagType>()) {
689  TagDecl *tag_decl = tag_type->getDecl();
690 
691  if (tag_decl->getDefinition() || tag_decl->isBeingDefined())
692  return true;
693 
694  return CompleteTagDecl(tag_decl);
695  }
696  if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>()) {
697  if (ObjCInterfaceDecl *objc_interface_decl =
698  objc_object_type->getInterface())
699  return CompleteObjCInterfaceDecl(objc_interface_decl);
700  return false;
701  }
702  if (const ArrayType *array_type = type->getAsArrayTypeUnsafe())
703  return RequireCompleteType(array_type->getElementType());
704  if (const AtomicType *atomic_type = type->getAs<AtomicType>())
705  return RequireCompleteType(atomic_type->getPointeeType());
706 
707  return true;
708 }
709 
711  DeclOrigin decl_origin = GetDeclOrigin(decl);
712 
713  if (decl_origin.Valid()) {
715  return ast->GetMetadata(decl_origin.decl);
716  }
717  TypeSystemClang *ast = TypeSystemClang::GetASTContext(&decl->getASTContext());
718  return ast->GetMetadata(decl);
719 }
720 
722 ClangASTImporter::GetDeclOrigin(const clang::Decl *decl) {
723  ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
724 
725  return context_md->getOrigin(decl);
726 }
727 
728 void ClangASTImporter::SetDeclOrigin(const clang::Decl *decl,
729  clang::Decl *original_decl) {
730  ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
731  context_md->setOrigin(
732  decl, DeclOrigin(&original_decl->getASTContext(), original_decl));
733 }
734 
735 void ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
736  NamespaceMapSP &namespace_map) {
737  ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
738 
739  context_md->m_namespace_maps[decl] = namespace_map;
740 }
741 
743 ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl) {
744  ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
745 
746  NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps;
747 
748  NamespaceMetaMap::iterator iter = namespace_maps.find(decl);
749 
750  if (iter != namespace_maps.end())
751  return iter->second;
752  return NamespaceMapSP();
753 }
754 
755 void ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl) {
756  assert(decl);
757  ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
758 
759  const DeclContext *parent_context = decl->getDeclContext();
760  const NamespaceDecl *parent_namespace =
761  dyn_cast<NamespaceDecl>(parent_context);
762  NamespaceMapSP parent_map;
763 
764  if (parent_namespace)
765  parent_map = GetNamespaceMap(parent_namespace);
766 
767  NamespaceMapSP new_map;
768 
769  new_map = std::make_shared<NamespaceMap>();
770 
771  if (context_md->m_map_completer) {
772  std::string namespace_string = decl->getDeclName().getAsString();
773 
774  context_md->m_map_completer->CompleteNamespaceMap(
775  new_map, ConstString(namespace_string.c_str()), parent_map);
776  }
777 
778  context_md->m_namespace_maps[decl] = new_map;
779 }
780 
781 void ClangASTImporter::ForgetDestination(clang::ASTContext *dst_ast) {
783 
784  LLDB_LOG(log,
785  " [ClangASTImporter] Forgetting destination (ASTContext*){0}",
786  dst_ast);
787 
788  m_metadata_map.erase(dst_ast);
789 }
790 
791 void ClangASTImporter::ForgetSource(clang::ASTContext *dst_ast,
792  clang::ASTContext *src_ast) {
793  ASTContextMetadataSP md = MaybeGetContextMetadata(dst_ast);
794 
796 
797  LLDB_LOG(log,
798  " [ClangASTImporter] Forgetting source->dest "
799  "(ASTContext*){0}->(ASTContext*){1}",
800  src_ast, dst_ast);
801 
802  if (!md)
803  return;
804 
805  md->m_delegates.erase(src_ast);
806  md->removeOriginsWithContext(src_ast);
807 }
808 
810 
811 llvm::Expected<Decl *>
813  if (m_std_handler) {
814  llvm::Optional<Decl *> D = m_std_handler->Import(From);
815  if (D) {
816  // Make sure we don't use this decl later to map it back to it's original
817  // decl. The decl the CxxModuleHandler created has nothing to do with
818  // the one from debug info, and linking those two would just cause the
819  // ASTImporter to try 'updating' the module decl with the minimal one from
820  // the debug info.
821  m_decls_to_ignore.insert(*D);
822  return *D;
823  }
824  }
825 
826  // Check which ASTContext this declaration originally came from.
827  DeclOrigin origin = m_master.GetDeclOrigin(From);
828 
829  // Prevent infinite recursion when the origin tracking contains a cycle.
830  assert(origin.decl != From && "Origin points to itself?");
831 
832  // If it originally came from the target ASTContext then we can just
833  // pretend that the original is the one we imported. This can happen for
834  // example when inspecting a persistent declaration from the scratch
835  // ASTContext (which will provide the declaration when parsing the
836  // expression and then we later try to copy the declaration back to the
837  // scratch ASTContext to store the result).
838  // Without this check we would ask the ASTImporter to import a declaration
839  // into the same ASTContext where it came from (which doesn't make a lot of
840  // sense).
841  if (origin.Valid() && origin.ctx == &getToContext()) {
842  RegisterImportedDecl(From, origin.decl);
843  return origin.decl;
844  }
845 
846  // This declaration came originally from another ASTContext. Instead of
847  // copying our potentially incomplete 'From' Decl we instead go to the
848  // original ASTContext and copy the original to the target. This is not
849  // only faster than first completing our current decl and then copying it
850  // to the target, but it also prevents that indirectly copying the same
851  // declaration to the same target requires the ASTImporter to merge all
852  // the different decls that appear to come from different ASTContexts (even
853  // though all these different source ASTContexts just got a copy from
854  // one source AST).
855  if (origin.Valid()) {
856  auto R = m_master.CopyDecl(&getToContext(), origin.decl);
857  if (R) {
858  RegisterImportedDecl(From, R);
859  return R;
860  }
861  }
862 
863  // If we have a forcefully completed type, try to find an actual definition
864  // for it in other modules.
865  const ClangASTMetadata *md = m_master.GetDeclMetadata(From);
866  auto *td = dyn_cast<TagDecl>(From);
867  if (td && md && md->IsForcefullyCompleted()) {
869  LLDB_LOG(log,
870  "[ClangASTImporter] Searching for a complete definition of {0} in "
871  "other modules",
872  td->getName());
873  Expected<DeclContext *> dc_or_err = ImportContext(td->getDeclContext());
874  if (!dc_or_err)
875  return dc_or_err.takeError();
876  Expected<DeclarationName> dn_or_err = Import(td->getDeclName());
877  if (!dn_or_err)
878  return dn_or_err.takeError();
879  DeclContext *dc = *dc_or_err;
880  DeclContext::lookup_result lr = dc->lookup(*dn_or_err);
881  for (clang::Decl *candidate : lr) {
882  if (candidate->getKind() == From->getKind()) {
883  RegisterImportedDecl(From, candidate);
884  m_decls_to_ignore.insert(candidate);
885  return candidate;
886  }
887  }
888  LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
889  }
890 
891  return ASTImporter::ImportImpl(From);
892 }
893 
895  clang::Decl *to, clang::Decl *from) {
896  // We might have a forward declaration from a shared library that we
897  // gave external lexical storage so that Clang asks us about the full
898  // definition when it needs it. In this case the ASTImporter isn't aware
899  // that the forward decl from the shared library is the actual import
900  // target but would create a second declaration that would then be defined.
901  // We want that 'to' is actually complete after this function so let's
902  // tell the ASTImporter that 'to' was imported from 'from'.
903  MapImported(from, to);
904  ASTImporter::Imported(from, to);
905 
907 
908  if (llvm::Error err = ImportDefinition(from)) {
909  LLDB_LOG_ERROR(log, std::move(err),
910  "[ClangASTImporter] Error during importing definition: {0}");
911  return;
912  }
913 
914  if (clang::TagDecl *to_tag = dyn_cast<clang::TagDecl>(to)) {
915  if (clang::TagDecl *from_tag = dyn_cast<clang::TagDecl>(from)) {
916  to_tag->setCompleteDefinition(from_tag->isCompleteDefinition());
917 
918  if (Log *log_ast =
920  std::string name_string;
921  if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) {
922  llvm::raw_string_ostream name_stream(name_string);
923  from_named_decl->printName(name_stream);
924  name_stream.flush();
925  }
926  LLDB_LOG(log_ast, "==== [ClangASTImporter][TUDecl: {0}] Imported "
927  "({1}Decl*){2}, named {3} (from "
928  "(Decl*){4})",
929  static_cast<void *>(to->getTranslationUnitDecl()),
930  from->getDeclKindName(), static_cast<void *>(to), name_string,
931  static_cast<void *>(from));
932 
933  // Log the AST of the TU.
934  std::string ast_string;
935  llvm::raw_string_ostream ast_stream(ast_string);
936  to->getTranslationUnitDecl()->dump(ast_stream);
937  LLDB_LOG(log_ast, "{0}", ast_string);
938  }
939  }
940  }
941 
942  // If we're dealing with an Objective-C class, ensure that the inheritance
943  // has been set up correctly. The ASTImporter may not do this correctly if
944  // the class was originally sourced from symbols.
945 
946  if (ObjCInterfaceDecl *to_objc_interface = dyn_cast<ObjCInterfaceDecl>(to)) {
947  do {
948  ObjCInterfaceDecl *to_superclass = to_objc_interface->getSuperClass();
949 
950  if (to_superclass)
951  break; // we're not going to override it if it's set
952 
953  ObjCInterfaceDecl *from_objc_interface =
954  dyn_cast<ObjCInterfaceDecl>(from);
955 
956  if (!from_objc_interface)
957  break;
958 
959  ObjCInterfaceDecl *from_superclass = from_objc_interface->getSuperClass();
960 
961  if (!from_superclass)
962  break;
963 
964  llvm::Expected<Decl *> imported_from_superclass_decl =
965  Import(from_superclass);
966 
967  if (!imported_from_superclass_decl) {
968  LLDB_LOG_ERROR(log, imported_from_superclass_decl.takeError(),
969  "Couldn't import decl: {0}");
970  break;
971  }
972 
973  ObjCInterfaceDecl *imported_from_superclass =
974  dyn_cast<ObjCInterfaceDecl>(*imported_from_superclass_decl);
975 
976  if (!imported_from_superclass)
977  break;
978 
979  if (!to_objc_interface->hasDefinition())
980  to_objc_interface->startDefinition();
981 
982  to_objc_interface->setSuperClass(m_source_ctx->getTrivialTypeSourceInfo(
983  m_source_ctx->getObjCInterfaceType(imported_from_superclass)));
984  } while (false);
985  }
986 }
987 
988 /// Takes a CXXMethodDecl and completes the return type if necessary. This
989 /// is currently only necessary for virtual functions with covariant return
990 /// types where Clang's CodeGen expects that the underlying records are already
991 /// completed.
993  CXXMethodDecl *to_method) {
994  if (!to_method->isVirtual())
995  return;
996  QualType return_type = to_method->getReturnType();
997  if (!return_type->isPointerType() && !return_type->isReferenceType())
998  return;
999 
1000  clang::RecordDecl *rd = return_type->getPointeeType()->getAsRecordDecl();
1001  if (!rd)
1002  return;
1003  if (rd->getDefinition())
1004  return;
1005 
1006  importer.CompleteTagDecl(rd);
1007 }
1008 
1009 /// Recreate a module with its parents in \p to_source and return its id.
1010 static OptionalClangModuleID
1012  ClangExternalASTSourceCallbacks &from_source,
1013  ClangExternalASTSourceCallbacks &to_source) {
1014  if (!from_id.HasValue())
1015  return {};
1016  clang::Module *module = from_source.getModule(from_id.GetValue());
1018  from_source.GetIDForModule(module->Parent), from_source, to_source);
1019  TypeSystemClang &to_ts = to_source.GetTypeSystem();
1020  return to_ts.GetOrCreateClangModule(module->Name, parent, module->IsFramework,
1021  module->IsExplicit);
1022 }
1023 
1025  clang::Decl *to) {
1027 
1028  // Some decls shouldn't be tracked here because they were not created by
1029  // copying 'from' to 'to'. Just exit early for those.
1030  if (m_decls_to_ignore.count(to))
1031  return clang::ASTImporter::Imported(from, to);
1032 
1033  // Transfer module ownership information.
1034  auto *from_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1035  getFromContext().getExternalSource());
1036  // Can also be a ClangASTSourceProxy.
1037  auto *to_source = llvm::dyn_cast_or_null<ClangExternalASTSourceCallbacks>(
1038  getToContext().getExternalSource());
1039  if (from_source && to_source) {
1040  OptionalClangModuleID from_id(from->getOwningModuleID());
1041  OptionalClangModuleID to_id =
1042  RemapModule(from_id, *from_source, *to_source);
1043  TypeSystemClang &to_ts = to_source->GetTypeSystem();
1044  to_ts.SetOwningModule(to, to_id);
1045  }
1046 
1048  ClangASTMetadata *metadata = m_master.GetDeclMetadata(from);
1049  if (metadata)
1050  user_id = metadata->GetUserID();
1051 
1052  if (log) {
1053  if (NamedDecl *from_named_decl = dyn_cast<clang::NamedDecl>(from)) {
1054  std::string name_string;
1055  llvm::raw_string_ostream name_stream(name_string);
1056  from_named_decl->printName(name_stream);
1057  name_stream.flush();
1058 
1059  LLDB_LOG(log,
1060  " [ClangASTImporter] Imported ({0}Decl*){1}, named {2} (from "
1061  "(Decl*){3}), metadata {4}",
1062  from->getDeclKindName(), to, name_string, from, user_id);
1063  } else {
1064  LLDB_LOG(log,
1065  " [ClangASTImporter] Imported ({0}Decl*){1} (from "
1066  "(Decl*){2}), metadata {3}",
1067  from->getDeclKindName(), to, from, user_id);
1068  }
1069  }
1070 
1071  ASTContextMetadataSP to_context_md =
1072  m_master.GetContextMetadata(&to->getASTContext());
1073  ASTContextMetadataSP from_context_md =
1074  m_master.MaybeGetContextMetadata(m_source_ctx);
1075 
1076  if (from_context_md) {
1077  DeclOrigin origin = from_context_md->getOrigin(from);
1078 
1079  if (origin.Valid()) {
1080  if (origin.ctx != &to->getASTContext()) {
1081  if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
1082  to_context_md->setOrigin(to, origin);
1083 
1084  ImporterDelegateSP direct_completer =
1085  m_master.GetDelegate(&to->getASTContext(), origin.ctx);
1086 
1087  if (direct_completer.get() != this)
1088  direct_completer->ASTImporter::Imported(origin.decl, to);
1089 
1090  LLDB_LOG(log,
1091  " [ClangASTImporter] Propagated origin "
1092  "(Decl*){0}/(ASTContext*){1} from (ASTContext*){2} to "
1093  "(ASTContext*){3}",
1094  origin.decl, origin.ctx, &from->getASTContext(),
1095  &to->getASTContext());
1096  }
1097  } else {
1098  if (m_new_decl_listener)
1099  m_new_decl_listener->NewDeclImported(from, to);
1100 
1101  if (!to_context_md->hasOrigin(to) || user_id != LLDB_INVALID_UID)
1102  to_context_md->setOrigin(to, DeclOrigin(m_source_ctx, from));
1103 
1104  LLDB_LOG(log,
1105  " [ClangASTImporter] Decl has no origin information in "
1106  "(ASTContext*){0}",
1107  &from->getASTContext());
1108  }
1109 
1110  if (auto *to_namespace = dyn_cast<clang::NamespaceDecl>(to)) {
1111  auto *from_namespace = cast<clang::NamespaceDecl>(from);
1112 
1113  NamespaceMetaMap &namespace_maps = from_context_md->m_namespace_maps;
1114 
1115  NamespaceMetaMap::iterator namespace_map_iter =
1116  namespace_maps.find(from_namespace);
1117 
1118  if (namespace_map_iter != namespace_maps.end())
1119  to_context_md->m_namespace_maps[to_namespace] =
1120  namespace_map_iter->second;
1121  }
1122  } else {
1123  to_context_md->setOrigin(to, DeclOrigin(m_source_ctx, from));
1124 
1125  LLDB_LOG(log,
1126  " [ClangASTImporter] Sourced origin "
1127  "(Decl*){0}/(ASTContext*){1} into (ASTContext*){2}",
1128  from, m_source_ctx, &to->getASTContext());
1129  }
1130 
1131  if (auto *to_tag_decl = dyn_cast<TagDecl>(to)) {
1132  to_tag_decl->setHasExternalLexicalStorage();
1133  to_tag_decl->getPrimaryContext()->setMustBuildLookupTable();
1134  auto from_tag_decl = cast<TagDecl>(from);
1135 
1136  LLDB_LOG(
1137  log,
1138  " [ClangASTImporter] To is a TagDecl - attributes {0}{1} [{2}->{3}]",
1139  (to_tag_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
1140  (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""),
1141  (from_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"),
1142  (to_tag_decl->isCompleteDefinition() ? "complete" : "incomplete"));
1143  }
1144 
1145  if (auto *to_namespace_decl = dyn_cast<NamespaceDecl>(to)) {
1146  m_master.BuildNamespaceMap(to_namespace_decl);
1147  to_namespace_decl->setHasExternalVisibleStorage();
1148  }
1149 
1150  if (auto *to_container_decl = dyn_cast<ObjCContainerDecl>(to)) {
1151  to_container_decl->setHasExternalLexicalStorage();
1152  to_container_decl->setHasExternalVisibleStorage();
1153 
1154  if (log) {
1155  if (ObjCInterfaceDecl *to_interface_decl =
1156  llvm::dyn_cast<ObjCInterfaceDecl>(to_container_decl)) {
1157  LLDB_LOG(
1158  log,
1159  " [ClangASTImporter] To is an ObjCInterfaceDecl - attributes "
1160  "{0}{1}{2}",
1161  (to_interface_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
1162  (to_interface_decl->hasExternalVisibleStorage() ? " Visible" : ""),
1163  (to_interface_decl->hasDefinition() ? " HasDefinition" : ""));
1164  } else {
1165  LLDB_LOG(
1166  log, " [ClangASTImporter] To is an {0}Decl - attributes {1}{2}",
1167  ((Decl *)to_container_decl)->getDeclKindName(),
1168  (to_container_decl->hasExternalLexicalStorage() ? " Lexical" : ""),
1169  (to_container_decl->hasExternalVisibleStorage() ? " Visible" : ""));
1170  }
1171  }
1172  }
1173 
1174  if (clang::CXXMethodDecl *to_method = dyn_cast<CXXMethodDecl>(to))
1175  MaybeCompleteReturnType(m_master, to_method);
1176 }
1177 
1178 clang::Decl *
1180  return m_master.GetDeclOrigin(To).decl;
1181 }
lldb_private::ClangASTImporter::Import
bool Import(const CompilerType &type)
If the given type was copied from another TypeSystemClang then copy over all missing information (e....
Definition: ClangASTImporter.cpp:432
DeclContextOverride::DeclContextOverride
DeclContextOverride()
Definition: ClangASTImporter.cpp:187
lldb_private::ClangASTImporter::CopyType
CompilerType CopyType(TypeSystemClang &dst, const CompilerType &src_type)
Copies the given type and the respective declarations to the destination type system.
Definition: ClangASTImporter.cpp:31
lldb_private::OptionalClangModuleID::HasValue
bool HasValue() const
Definition: TypeSystemClang.h:63
lldb_private::ClangASTImporter::GetNamespaceMap
NamespaceMapSP GetNamespaceMap(const clang::NamespaceDecl *decl)
Definition: ClangASTImporter.cpp:743
lldb_private::ClangASTImporter::MapCompleter::~MapCompleter
virtual ~MapCompleter()
Definition: ClangASTImporter.cpp:809
lldb_private::TypeSystemClang::getASTContext
clang::ASTContext & getASTContext()
Returns the clang::ASTContext instance managed by this TypeSystemClang.
Definition: TypeSystemClang.cpp:694
lldb_private::ClangASTImporter::CompleteAndFetchChildren
bool CompleteAndFetchChildren(clang::QualType type)
Definition: ClangASTImporter.cpp:614
lldb_private::TypeSystemClang::GetMetadata
ClangASTMetadata * GetMetadata(const clang::Decl *object)
Definition: TypeSystemClang.cpp:2460
lldb_private::TypeSystemClang::GetASTContext
static TypeSystemClang * GetASTContext(clang::ASTContext *ast_ctx)
Definition: TypeSystemClang.cpp:768
LLDB_INVALID_UID
#define LLDB_INVALID_UID
Definition: lldb-defines.h:91
lldb_private::OptionalClangModuleID::GetValue
unsigned GetValue() const
Definition: TypeSystemClang.h:64
DeclContextOverride::Backup::lexical_decl_context
clang::DeclContext * lexical_decl_context
Definition: ClangASTImporter.cpp:110
lldb_private::ClangASTImporter::ASTImporterDelegate::ImportDefinitionTo
void ImportDefinitionTo(clang::Decl *to, clang::Decl *from)
Definition: ClangASTImporter.cpp:894
Module.h
lldb_private::ClangUtil::GetCanonicalQualType
static clang::QualType GetCanonicalQualType(const CompilerType &ct)
Definition: ClangUtil.cpp:44
lldb_private::ClangASTImporter::LayoutInfo
Definition: ClangASTImporter.h:66
lldb_private::CompilerType::GetOpaqueQualType
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:173
lldb_private::ClangASTImporter::RequireCompleteType
bool RequireCompleteType(clang::QualType type)
Definition: ClangASTImporter.cpp:684
lldb_private::ClangUtil::RemoveFastQualifiers
static CompilerType RemoveFastQualifiers(const CompilerType &ct)
Definition: ClangUtil.cpp:51
DeclContextOverride::m_backups
llvm::DenseMap< clang::Decl *, Backup > m_backups
Definition: ClangASTImporter.cpp:113
RemapModule
static OptionalClangModuleID RemapModule(OptionalClangModuleID from_id, ClangExternalASTSourceCallbacks &from_source, ClangExternalASTSourceCallbacks &to_source)
Recreate a module with its parents in to_source and return its id.
Definition: ClangASTImporter.cpp:1011
DeclContextOverride::OverrideOne
void OverrideOne(clang::Decl *decl)
Definition: ClangASTImporter.cpp:115
lldb_private::ClangExternalASTSourceCallbacks::GetTypeSystem
TypeSystemClang & GetTypeSystem() const
Definition: ClangExternalASTSourceCallbacks.h:48
lldb_private::ClangASTImporter::DeportType
CompilerType DeportType(TypeSystemClang &dst, const CompilerType &src_type)
Copies the given type and the respective declarations to the destination type system.
Definition: ClangASTImporter.cpp:304
ClangUtil.h
lldb_private::ClangASTImporter::GetContextMetadata
ASTContextMetadataSP GetContextMetadata(clang::ASTContext *dst_ctx)
Definition: ClangASTImporter.h:414
lldb_private::ClangUtil::IsClangType
static bool IsClangType(const CompilerType &ct)
Definition: ClangUtil.cpp:17
lldb_private::ClangASTImporter::DeclOrigin
Definition: ClangASTImporter.h:218
ClangASTSource.h
lldb_private::ClangUtil::GetQualType
static clang::QualType GetQualType(const CompilerType &ct)
Definition: ClangUtil.cpp:36
LIBLLDB_LOG_EXPRESSIONS
#define LIBLLDB_LOG_EXPRESSIONS
Definition: Logging.h:22
lldb_private::ClangASTImporter::DeportDecl
clang::Decl * DeportDecl(clang::ASTContext *dst_ctx, clang::Decl *decl)
Copies the given decl to the destination type system.
Definition: ClangASTImporter.cpp:327
lldb_private::ClangASTImporter::ForgetDestination
void ForgetDestination(clang::ASTContext *dst_ctx)
Definition: ClangASTImporter.cpp:781
lldb_private::ClangASTImporter::ImporterDelegateSP
std::shared_ptr< ASTImporterDelegate > ImporterDelegateSP
Definition: ClangASTImporter.h:339
LIBLLDB_LOG_AST
#define LIBLLDB_LOG_AST
Definition: Logging.h:45
LLDBAssert.h
ClangASTMetadata.h
Log.h
lldb_private::ClangASTImporter::ASTImporterDelegate::Imported
void Imported(clang::Decl *from, clang::Decl *to) override
Definition: ClangASTImporter.cpp:1024
lldb_private::ClangExternalASTSourceCallbacks::getModule
clang::Module * getModule(unsigned ID) override
Definition: ClangExternalASTSourceCallbacks.cpp:79
TypeSystemClang.h
DeclContextOverride
Definition: ClangASTImporter.cpp:106
lldb_private::ClangASTImporter::LayoutRecordType
bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, llvm::DenseMap< const clang::FieldDecl *, uint64_t > &field_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &base_offsets, llvm::DenseMap< const clang::CXXRecordDecl *, clang::CharUnits > &vbase_offsets)
Definition: ClangASTImporter.cpp:519
lldb_private::ClangExternalASTSourceCallbacks
Definition: ClangExternalASTSourceCallbacks.h:17
lldb_private::ClangASTImporter::CopyDecl
clang::Decl * CopyDecl(clang::ASTContext *dst_ctx, clang::Decl *decl)
Definition: ClangASTImporter.cpp:66
lldb_private::ClangASTImporter::CompleteType
bool CompleteType(const CompilerType &compiler_type)
Definition: ClangASTImporter.cpp:505
lldb_private::ClangASTImporter::CompleteTagDecl
bool CompleteTagDecl(clang::TagDecl *decl)
Definition: ClangASTImporter.cpp:553
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
MaybeCompleteReturnType
static void MaybeCompleteReturnType(ClangASTImporter &importer, CXXMethodDecl *to_method)
Takes a CXXMethodDecl and completes the return type if necessary.
Definition: ClangASTImporter.cpp:992
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::ClangASTMetadata::IsForcefullyCompleted
bool IsForcefullyCompleted() const
A type is "forcefully completed" if it was declared complete to satisfy an AST invariant (e....
Definition: ClangASTMetadata.h:90
DeclContextOverride::ChainPassesThrough
bool ChainPassesThrough(clang::Decl *decl, clang::DeclContext *base, clang::DeclContext *(clang::Decl::*contextFromDecl)(), clang::DeclContext *(clang::DeclContext::*contextFromContext)())
Definition: ClangASTImporter.cpp:126
lldb_private::ClangASTMetadata
Definition: ClangASTMetadata.h:18
lldb_private::TypeSystemClang::GetOrCreateClangModule
OptionalClangModuleID GetOrCreateClangModule(llvm::StringRef name, OptionalClangModuleID parent, bool is_framework=false, bool is_explicit=false)
Synthesize a clang::Module and return its ID or a default-constructed ID.
Definition: TypeSystemClang.cpp:1250
DeclContextOverride::GetEscapedChild
clang::Decl * GetEscapedChild(clang::Decl *decl, clang::DeclContext *base=nullptr)
Definition: ClangASTImporter.cpp:140
lldb_private::TypeSystemClang::SetOwningModule
static void SetOwningModule(clang::Decl *decl, OptionalClangModuleID owning_module)
Set the owning module for decl.
Definition: TypeSystemClang.cpp:1239
lldb_private::ClangASTMetadata::GetUserID
lldb::user_id_t GetUserID() const
Definition: ClangASTMetadata.h:35
lldb_private::ClangASTImporter::GetDeclOrigin
DeclOrigin GetDeclOrigin(const clang::Decl *decl)
Definition: ClangASTImporter.cpp:722
lldb_private::ClangASTImporter::SetRecordLayout
void SetRecordLayout(clang::RecordDecl *decl, const LayoutInfo &layout)
Sets the layout for the given RecordDecl.
Definition: ClangASTImporter.cpp:548
lldb_private::ClangASTImporter::ASTImporterDelegate::CxxModuleScope
Scope guard that attaches a CxxModuleHandler to an ASTImporterDelegate and deattaches it at the end o...
Definition: ClangASTImporter.h:283
lldb_private::ClangASTImporter::NamespaceMapSP
std::shared_ptr< NamespaceMap > NamespaceMapSP
Definition: ClangASTImporter.h:178
lldbassert
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb_private::ClangASTImporter::CompleteObjCInterfaceDecl
bool CompleteObjCInterfaceDecl(clang::ObjCInterfaceDecl *interface_decl)
Definition: ClangASTImporter.cpp:592
lldb_private::OptionalClangModuleID
A Clang module ID.
Definition: TypeSystemClang.h:57
lldb_private::ClangASTImporter::GetDeclMetadata
ClangASTMetadata * GetDeclMetadata(const clang::Decl *decl)
Definition: ClangASTImporter.cpp:710
lldb_private::TypeSystemClang::GetCompleteDecl
bool GetCompleteDecl(clang::Decl *decl)
Definition: TypeSystemClang.h:180
lldb_private::ClangASTImporter::DeclOrigin::decl
clang::Decl * decl
Definition: ClangASTImporter.h:240
lldb_private::ClangASTImporter::RegisterNamespaceMap
void RegisterNamespaceMap(const clang::NamespaceDecl *decl, NamespaceMapSP &namespace_map)
Definition: ClangASTImporter.cpp:735
lldb_private::CompilerType::GetTypeSystem
TypeSystem * GetTypeSystem() const
Accessors.
Definition: CompilerType.h:162
lldb_private::ClangASTImporter::SetDeclOrigin
void SetDeclOrigin(const clang::Decl *decl, clang::Decl *original_decl)
Updates the internal origin-tracking information so that the given 'original' decl is from now on use...
Definition: ClangASTImporter.cpp:728
lldb_private::CompilerType::GetTypeName
ConstString GetTypeName() const
Definition: CompilerType.cpp:277
DeclContextOverride::Backup::decl_context
clang::DeclContext * decl_context
Definition: ClangASTImporter.cpp:109
RequireCompleteType
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
Definition: DWARFASTParserClang.cpp:246
lldb_private::ClangASTImporter::ASTContextMetadataSP
std::shared_ptr< ASTContextMetadata > ASTContextMetadataSP
Definition: ClangASTImporter.h:408
DeclContextOverride::Backup
Definition: ClangASTImporter.cpp:108
lldb_private::ClangASTImporter::BuildNamespaceMap
void BuildNamespaceMap(const clang::NamespaceDecl *decl)
Definition: ClangASTImporter.cpp:755
lldb_private::ClangASTImporter
Manages and observes all Clang AST node importing in LLDB.
Definition: ClangASTImporter.h:64
lldb_private::ClangASTImporter::NewDeclListener
Listener interface used by the ASTImporterDelegate to inform other code about decls that have been im...
Definition: ClangASTImporter.h:245
DeclContextOverride::Override
void Override(clang::Decl *decl)
Definition: ClangASTImporter.cpp:171
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:242
clang
Definition: ASTResultSynthesizer.h:15
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
DeclContextOverride::~DeclContextOverride
~DeclContextOverride()
Definition: ClangASTImporter.cpp:203
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private::ClangASTImporter::DeclOrigin::ctx
clang::ASTContext * ctx
Definition: ClangASTImporter.h:239
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ClangExternalASTSourceCallbacks::GetIDForModule
OptionalClangModuleID GetIDForModule(clang::Module *module)
Definition: ClangExternalASTSourceCallbacks.cpp:86
lldb_private::ClangASTImporter::ASTImporterDelegate::ImportImpl
llvm::Expected< clang::Decl * > ImportImpl(clang::Decl *From) override
Definition: ClangASTImporter.cpp:812
Error
llvm::Error Error
Definition: UdtRecordCompleter.cpp:29
lldb_private::ClangASTImporter::ForgetSource
void ForgetSource(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx)
Definition: ClangASTImporter.cpp:791
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:106
lldb_private::ClangASTImporter::CompleteTagDeclWithOrigin
bool CompleteTagDeclWithOrigin(clang::TagDecl *decl, clang::TagDecl *origin)
Definition: ClangASTImporter.cpp:573
arm64_dwarf::lr
@ lr
Definition: ARM64_DWARF_Registers.h:49
ClangASTImporter.h
lldb_private::TypeSystemClang::SetHasExternalStorage
static bool SetHasExternalStorage(lldb::opaque_compiler_type_t type, bool has_extern)
Definition: TypeSystemClang.cpp:8045
lldb_private::Log
Definition: Log.h:49
lldb_private::ClangASTImporter::DeclOrigin::Valid
bool Valid() const
Definition: ClangASTImporter.h:237
lldb_private::ClangASTImporter::CanImport
bool CanImport(const CompilerType &type)
Returns true iff the given type was copied from another TypeSystemClang and the original type in this...
Definition: ClangASTImporter.cpp:358
lldb_private::ClangASTImporter::ASTImporterDelegate::GetOriginalDecl
clang::Decl * GetOriginalDecl(clang::Decl *To) override
Definition: ClangASTImporter.cpp:1179
lldb_private::ClangASTImporter::NamespaceMetaMap
llvm::DenseMap< const clang::NamespaceDecl *, NamespaceMapSP > NamespaceMetaMap
Definition: ClangASTImporter.h:342
lldb_private::TypeSystemClang::CompleteTagDeclarationDefinition
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
Definition: TypeSystemClang.cpp:8123
LLDB_LOG_ERROR
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:265
lldb::opaque_compiler_type_t
void * opaque_compiler_type_t
Definition: lldb-types.h:90
DeclContextOverride::OverrideAllDeclsFromContainingFunction
void OverrideAllDeclsFromContainingFunction(clang::Decl *decl)
Definition: ClangASTImporter.cpp:189
ClangExternalASTSourceCallbacks.h