Commit 75e8a91c authored by Raphael Isemann's avatar Raphael Isemann
Browse files

[lldb][NFC] Remove all overloads of Copy/DeportType in ClangASTImporter

The overloads that don't take a CompilerType serve no purpose as we
always have a CompilerType in the scope where we call them. Instead
just call the overload that takes a CompilerType and delete the
now unused other overloaded methods.
parent ea2805a0
Loading
Loading
Loading
Loading
+1 −10
Original line number Diff line number Diff line
@@ -48,21 +48,12 @@ public:
      : m_file_manager(clang::FileSystemOptions(),
                       FileSystem::Instance().GetVirtualFileSystem()) {}

  clang::QualType CopyType(clang::ASTContext *dst_ctx,
                           clang::ASTContext *src_ctx, clang::QualType type);

  lldb::opaque_compiler_type_t CopyType(clang::ASTContext *dst_ctx,
                                        clang::ASTContext *src_ctx,
                                        lldb::opaque_compiler_type_t type);

  CompilerType CopyType(ClangASTContext &dst, const CompilerType &src_type);

  clang::Decl *CopyDecl(clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx,
                        clang::Decl *decl);

  lldb::opaque_compiler_type_t DeportType(clang::ASTContext *dst_ctx,
                                          clang::ASTContext *src_ctx,
                                          lldb::opaque_compiler_type_t type);
  CompilerType DeportType(ClangASTContext &dst, const CompilerType &src_type);

  clang::Decl *DeportDecl(clang::ASTContext *dst_ctx,
                          clang::ASTContext *src_ctx, clang::Decl *decl);
+2 −3
Original line number Diff line number Diff line
@@ -2022,9 +2022,8 @@ CompilerType ClangASTSource::GuardedCopyType(const CompilerType &src_type) {
  QualType copied_qual_type;

  if (m_ast_importer_sp) {
    copied_qual_type =
        m_ast_importer_sp->CopyType(m_ast_context, src_ast->getASTContext(),
                                    ClangUtil::GetQualType(src_type));
    copied_qual_type = ClangUtil::GetQualType(
        m_ast_importer_sp->CopyType(*m_clang_ast_context, src_type));
  } else if (m_merger_up) {
    copied_qual_type =
        CopyTypeWithMerger(*src_ast->getASTContext(), *m_merger_up,
+1 −4
Original line number Diff line number Diff line
@@ -206,10 +206,7 @@ TypeFromUser ClangExpressionDeclMap::DeportType(ClangASTContext &target,
  assert(source.getASTContext() == m_ast_context);

  if (m_ast_importer_sp) {
    return TypeFromUser(m_ast_importer_sp->DeportType(
                            target.getASTContext(), source.getASTContext(),
                            parser_type.GetOpaqueQualType()),
                        &target);
    return TypeFromUser(m_ast_importer_sp->DeportType(target, parser_type));
  } else if (m_merger_up) {
    clang::FileID source_file =
        source.getASTContext()->getSourceManager().getFileID(
+38 −55
Original line number Diff line number Diff line
@@ -25,52 +25,42 @@
using namespace lldb_private;
using namespace clang;

clang::QualType ClangASTImporter::CopyType(clang::ASTContext *dst_ast,
                                           clang::ASTContext *src_ast,
                                           clang::QualType type) {
  ImporterDelegateSP delegate_sp(GetDelegate(dst_ast, src_ast));
CompilerType ClangASTImporter::CopyType(ClangASTContext &dst_ast,
                                        const CompilerType &src_type) {
  clang::ASTContext *dst_clang_ast = dst_ast.getASTContext();
  if (!dst_clang_ast)
    return CompilerType();

  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
  ClangASTContext *src_ast =
      llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
  if (!src_ast)
    return CompilerType();

  clang::ASTContext *src_clang_ast = src_ast->getASTContext();
  if (!src_clang_ast)
    return CompilerType();

  clang::QualType src_qual_type = ClangUtil::GetQualType(src_type);

  ImporterDelegateSP delegate_sp(GetDelegate(dst_clang_ast, src_clang_ast));
  if (!delegate_sp)
    return QualType();
    return CompilerType();

  llvm::Expected<QualType> ret_or_error = delegate_sp->Import(type);
  ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_clang_ast);

  llvm::Expected<QualType> ret_or_error = delegate_sp->Import(src_qual_type);
  if (!ret_or_error) {
    Log *log =
      lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS);
    LLDB_LOG_ERROR(log, ret_or_error.takeError(),
        "Couldn't import type: {0}");
    return QualType();
  }
  return *ret_or_error;
    return CompilerType();
  }

lldb::opaque_compiler_type_t
ClangASTImporter::CopyType(clang::ASTContext *dst_ast,
                           clang::ASTContext *src_ast,
                           lldb::opaque_compiler_type_t type) {
  return CopyType(dst_ast, src_ast, QualType::getFromOpaquePtr(type))
      .getAsOpaquePtr();
}

CompilerType ClangASTImporter::CopyType(ClangASTContext &dst_ast,
                                        const CompilerType &src_type) {
  clang::ASTContext *dst_clang_ast = dst_ast.getASTContext();
  if (dst_clang_ast) {
    ClangASTContext *src_ast =
        llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem());
    if (src_ast) {
      clang::ASTContext *src_clang_ast = src_ast->getASTContext();
      if (src_clang_ast) {
        lldb::opaque_compiler_type_t dst_clang_type = CopyType(
            dst_clang_ast, src_clang_ast, src_type.GetOpaqueQualType());
  lldb::opaque_compiler_type_t dst_clang_type = ret_or_error->getAsOpaquePtr();

  if (dst_clang_type)
    return CompilerType(&dst_ast, dst_clang_type);
      }
    }
  }
  return CompilerType();
}

@@ -306,34 +296,27 @@ public:
};
} // namespace

lldb::opaque_compiler_type_t
ClangASTImporter::DeportType(clang::ASTContext *dst_ctx,
                             clang::ASTContext *src_ctx,
                             lldb::opaque_compiler_type_t type) {
CompilerType ClangASTImporter::DeportType(ClangASTContext &dst,
                                          const CompilerType &src_type) {
  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));

  LLDB_LOGF(log,
            "    [ClangASTImporter] DeportType called on (%sType*)0x%llx "
            "from (ASTContext*)%p to (ASTContext*)%p",
            QualType::getFromOpaquePtr(type)->getTypeClassName(),
            (unsigned long long)type, static_cast<void *>(src_ctx),
            static_cast<void *>(dst_ctx));
  ClangASTContext *src_ctxt =
      llvm::cast<ClangASTContext>(src_type.GetTypeSystem());

  LLDB_LOG(log,
           "    [ClangASTImporter] DeportType called on ({0}Type*){1:x} "
           "from (ASTContext*){2:x} to (ASTContext*){3:x}",
           src_type.GetTypeName(), src_type.GetOpaqueQualType(),
           src_ctxt->getASTContext(), dst.getASTContext());

  DeclContextOverride decl_context_override;

  if (auto *t = QualType::getFromOpaquePtr(type)->getAs<TagType>())
  if (auto *t = ClangUtil::GetQualType(src_type)->getAs<TagType>())
    decl_context_override.OverrideAllDeclsFromContainingFunction(t->getDecl());

  lldb::opaque_compiler_type_t result;
  {
    CompleteTagDeclsScope complete_scope(*this, dst_ctx, src_ctx);
    result = CopyType(dst_ctx, src_ctx, type);
  }

  if (!result)
    return nullptr;

  return result;
  CompleteTagDeclsScope complete_scope(*this, dst.getASTContext(),
                                       src_ctxt->getASTContext());
  return CopyType(dst, src_type);
}

clang::Decl *ClangASTImporter::DeportDecl(clang::ASTContext *dst_ctx,