Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangUtil.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- ClangUtil.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
// A collection of helper methods and data structures for manipulating clang
8
// types and decls.
9
//===----------------------------------------------------------------------===//
10
11
#include "Plugins/ExpressionParser/Clang/ClangUtil.h"
12
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
13
14
using namespace clang;
15
using namespace lldb_private;
16
17
1.38M
bool ClangUtil::IsClangType(const CompilerType &ct) {
18
  // Invalid types are never Clang types.
19
1.38M
  if (!ct)
20
2.01k
    return false;
21
22
1.38M
  if (llvm::dyn_cast_or_null<TypeSystemClang>(ct.GetTypeSystem()) == nullptr)
23
0
    return false;
24
25
1.38M
  if (!ct.GetOpaqueQualType())
26
0
    return false;
27
28
1.38M
  return true;
29
1.38M
}
30
31
1.20k
clang::Decl *ClangUtil::GetDecl(const CompilerDecl &decl) {
32
1.20k
  assert(llvm::isa<TypeSystemClang>(decl.GetTypeSystem()));
33
0
  return static_cast<clang::Decl *>(decl.GetOpaqueDecl());
34
1.20k
}
35
36
822k
QualType ClangUtil::GetQualType(const CompilerType &ct) {
37
  // Make sure we have a clang type before making a clang::QualType
38
822k
  if (!IsClangType(ct))
39
2.01k
    return QualType();
40
41
820k
  return QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
42
822k
}
43
44
180k
QualType ClangUtil::GetCanonicalQualType(const CompilerType &ct) {
45
180k
  if (!IsClangType(ct))
46
0
    return QualType();
47
48
180k
  return GetQualType(ct).getCanonicalType();
49
180k
}
50
51
167k
CompilerType ClangUtil::RemoveFastQualifiers(const CompilerType &ct) {
52
167k
  if (!IsClangType(ct))
53
0
    return ct;
54
55
167k
  QualType qual_type(GetQualType(ct));
56
167k
  qual_type.removeLocalFastQualifiers();
57
167k
  return CompilerType(ct.GetTypeSystem(), qual_type.getAsOpaquePtr());
58
167k
}
59
60
804
clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) {
61
804
  clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
62
804
  if (qual_type.isNull())
63
0
    return nullptr;
64
65
804
  return qual_type->getAsTagDecl();
66
804
}
67
68
36
std::string ClangUtil::DumpDecl(const clang::Decl *d) {
69
36
  if (!d)
70
0
    return "nullptr";
71
72
36
  std::string result;
73
36
  llvm::raw_string_ostream stream(result);
74
36
  bool deserialize = false;
75
36
  d->dump(stream, deserialize);
76
77
36
  stream.flush();
78
36
  return result;
79
36
}
80
81
0
std::string ClangUtil::ToString(const clang::Type *t) {
82
0
  return clang::QualType(t, 0).getAsString();
83
0
}
84
85
36
std::string ClangUtil::ToString(const CompilerType &c) {
86
36
  return ClangUtil::GetQualType(c).getAsString();
87
36
}