Commit c214c92f authored by Raphael Isemann's avatar Raphael Isemann
Browse files

[lldb][NFC] Remove ClangASTContext::GetBuiltinTypeForEncodingAndBitSize overload

parent bc7f1df6
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -150,9 +150,6 @@ public:
  CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
                                                   size_t bit_size) override;

  static CompilerType GetBuiltinTypeForEncodingAndBitSize(
      clang::ASTContext *ast, lldb::Encoding encoding, uint32_t bit_size);

  CompilerType GetBasicType(lldb::BasicType type);

  CompilerType GetBasicType(ConstString name);
+2 −2
Original line number Diff line number Diff line
@@ -1762,8 +1762,8 @@ void ClangExpressionDeclMap::AddOneRegister(NameSearchContext &context,
  Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));

  CompilerType clang_type =
      ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(
          m_ast_context, reg_info->encoding, reg_info->byte_size * 8);
      m_clang_ast_context->GetBuiltinTypeForEncodingAndBitSize(
          reg_info->encoding, reg_info->byte_size * 8);

  if (!clang_type) {
    LLDB_LOGF(log, "  Tried to add a type for %s, but couldn't get one",
+20 −35
Original line number Diff line number Diff line
@@ -843,76 +843,61 @@ static inline bool QualTypeMatchesBitSize(const uint64_t bit_size,
CompilerType
ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(Encoding encoding,
                                                     size_t bit_size) {
  return ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(
      getASTContext(), encoding, bit_size);
}

CompilerType ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(
    ASTContext *ast, Encoding encoding, uint32_t bit_size) {
  auto *clang_ast_context = ClangASTContext::GetASTContext(ast);
  ASTContext *ast = this->getASTContext();
  if (!ast)
    return CompilerType();
  switch (encoding) {
  case eEncodingInvalid:
    if (QualTypeMatchesBitSize(bit_size, ast, ast->VoidPtrTy))
      return CompilerType(clang_ast_context, ast->VoidPtrTy.getAsOpaquePtr());
      return CompilerType(this, ast->VoidPtrTy.getAsOpaquePtr());
    break;

  case eEncodingUint:
    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedCharTy))
      return CompilerType(clang_ast_context,
                          ast->UnsignedCharTy.getAsOpaquePtr());
      return CompilerType(this, ast->UnsignedCharTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedShortTy))
      return CompilerType(clang_ast_context,
                          ast->UnsignedShortTy.getAsOpaquePtr());
      return CompilerType(this, ast->UnsignedShortTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedIntTy))
      return CompilerType(clang_ast_context,
                          ast->UnsignedIntTy.getAsOpaquePtr());
      return CompilerType(this, ast->UnsignedIntTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongTy))
      return CompilerType(clang_ast_context,
                          ast->UnsignedLongTy.getAsOpaquePtr());
      return CompilerType(this, ast->UnsignedLongTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedLongLongTy))
      return CompilerType(clang_ast_context,
                          ast->UnsignedLongLongTy.getAsOpaquePtr());
      return CompilerType(this, ast->UnsignedLongLongTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->UnsignedInt128Ty))
      return CompilerType(clang_ast_context,
                          ast->UnsignedInt128Ty.getAsOpaquePtr());
      return CompilerType(this, ast->UnsignedInt128Ty.getAsOpaquePtr());
    break;

  case eEncodingSint:
    if (QualTypeMatchesBitSize(bit_size, ast, ast->SignedCharTy))
      return CompilerType(clang_ast_context,
                          ast->SignedCharTy.getAsOpaquePtr());
      return CompilerType(this, ast->SignedCharTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->ShortTy))
      return CompilerType(clang_ast_context, ast->ShortTy.getAsOpaquePtr());
      return CompilerType(this, ast->ShortTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->IntTy))
      return CompilerType(clang_ast_context, ast->IntTy.getAsOpaquePtr());
      return CompilerType(this, ast->IntTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->LongTy))
      return CompilerType(clang_ast_context, ast->LongTy.getAsOpaquePtr());
      return CompilerType(this, ast->LongTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->LongLongTy))
      return CompilerType(clang_ast_context, ast->LongLongTy.getAsOpaquePtr());
      return CompilerType(this, ast->LongLongTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->Int128Ty))
      return CompilerType(clang_ast_context, ast->Int128Ty.getAsOpaquePtr());
      return CompilerType(this, ast->Int128Ty.getAsOpaquePtr());
    break;

  case eEncodingIEEE754:
    if (QualTypeMatchesBitSize(bit_size, ast, ast->FloatTy))
      return CompilerType(clang_ast_context, ast->FloatTy.getAsOpaquePtr());
      return CompilerType(this, ast->FloatTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->DoubleTy))
      return CompilerType(clang_ast_context, ast->DoubleTy.getAsOpaquePtr());
      return CompilerType(this, ast->DoubleTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->LongDoubleTy))
      return CompilerType(clang_ast_context,
                          ast->LongDoubleTy.getAsOpaquePtr());
      return CompilerType(this, ast->LongDoubleTy.getAsOpaquePtr());
    if (QualTypeMatchesBitSize(bit_size, ast, ast->HalfTy))
      return CompilerType(clang_ast_context, ast->HalfTy.getAsOpaquePtr());
      return CompilerType(this, ast->HalfTy.getAsOpaquePtr());
    break;

  case eEncodingVector:
    // Sanity check that bit_size is a multiple of 8's.
    if (bit_size && !(bit_size & 0x7u))
      return CompilerType(
          clang_ast_context,
          ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8)
          this, ast->getExtVectorType(ast->UnsignedCharTy, bit_size / 8)
                    .getAsOpaquePtr());
    break;
  }
+19 −19
Original line number Diff line number Diff line
@@ -169,10 +169,12 @@ TEST_F(TestClangASTContext, TestGetBasicTypeFromName) {
  EXPECT_EQ(GetBasicQualType(eBasicTypeNullPtr), GetBasicQualType("nullptr"));
}

void VerifyEncodingAndBitSize(clang::ASTContext *context,
void VerifyEncodingAndBitSize(ClangASTContext &clang_context,
                              lldb::Encoding encoding, unsigned int bit_size) {
  CompilerType type = ClangASTContext::GetBuiltinTypeForEncodingAndBitSize(
      context, encoding, bit_size);
  clang::ASTContext *context = clang_context.getASTContext();

  CompilerType type =
      clang_context.GetBuiltinTypeForEncodingAndBitSize(encoding, bit_size);
  EXPECT_TRUE(type.IsValid());

  QualType qtype = ClangUtil::GetQualType(type);
@@ -206,8 +208,6 @@ void VerifyEncodingAndBitSize(clang::ASTContext *context,
}

TEST_F(TestClangASTContext, TestBuiltinTypeForEncodingAndBitSize) {
  clang::ASTContext *context = m_ast->getASTContext();

  // Make sure we can get types of every possible size in every possible
  // encoding.
  // We can't make any guarantee about which specific type we get, because the
@@ -215,20 +215,20 @@ TEST_F(TestClangASTContext, TestBuiltinTypeForEncodingAndBitSize) {
  // isn't that specific.  We only need to make sure the compiler hands us some
  // type that
  // is both a builtin type and matches the requested bit size.
  VerifyEncodingAndBitSize(context, eEncodingSint, 8);
  VerifyEncodingAndBitSize(context, eEncodingSint, 16);
  VerifyEncodingAndBitSize(context, eEncodingSint, 32);
  VerifyEncodingAndBitSize(context, eEncodingSint, 64);
  VerifyEncodingAndBitSize(context, eEncodingSint, 128);

  VerifyEncodingAndBitSize(context, eEncodingUint, 8);
  VerifyEncodingAndBitSize(context, eEncodingUint, 16);
  VerifyEncodingAndBitSize(context, eEncodingUint, 32);
  VerifyEncodingAndBitSize(context, eEncodingUint, 64);
  VerifyEncodingAndBitSize(context, eEncodingUint, 128);

  VerifyEncodingAndBitSize(context, eEncodingIEEE754, 32);
  VerifyEncodingAndBitSize(context, eEncodingIEEE754, 64);
  VerifyEncodingAndBitSize(*m_ast, eEncodingSint, 8);
  VerifyEncodingAndBitSize(*m_ast, eEncodingSint, 16);
  VerifyEncodingAndBitSize(*m_ast, eEncodingSint, 32);
  VerifyEncodingAndBitSize(*m_ast, eEncodingSint, 64);
  VerifyEncodingAndBitSize(*m_ast, eEncodingSint, 128);

  VerifyEncodingAndBitSize(*m_ast, eEncodingUint, 8);
  VerifyEncodingAndBitSize(*m_ast, eEncodingUint, 16);
  VerifyEncodingAndBitSize(*m_ast, eEncodingUint, 32);
  VerifyEncodingAndBitSize(*m_ast, eEncodingUint, 64);
  VerifyEncodingAndBitSize(*m_ast, eEncodingUint, 128);

  VerifyEncodingAndBitSize(*m_ast, eEncodingIEEE754, 32);
  VerifyEncodingAndBitSize(*m_ast, eEncodingIEEE754, 64);
}

TEST_F(TestClangASTContext, TestIsClangType) {