]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/source/Symbol/ClangUtil.cpp
Fix a memory leak in if_delgroups() introduced in r334118.
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / source / Symbol / ClangUtil.cpp
1 //===-- ClangUtil.cpp -------------------------------------------*- 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 // A collection of helper methods and data structures for manipulating clang
8 // types and decls.
9 //===----------------------------------------------------------------------===//
10
11 #include "lldb/Symbol/ClangUtil.h"
12 #include "lldb/Symbol/ClangASTContext.h"
13
14 using namespace clang;
15 using namespace lldb_private;
16
17 bool ClangUtil::IsClangType(const CompilerType &ct) {
18   if (llvm::dyn_cast_or_null<ClangASTContext>(ct.GetTypeSystem()) == nullptr)
19     return false;
20
21   if (!ct.GetOpaqueQualType())
22     return false;
23
24   return true;
25 }
26
27 QualType ClangUtil::GetQualType(const CompilerType &ct) {
28   // Make sure we have a clang type before making a clang::QualType
29   if (!IsClangType(ct))
30     return QualType();
31
32   return QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
33 }
34
35 QualType ClangUtil::GetCanonicalQualType(const CompilerType &ct) {
36   if (!IsClangType(ct))
37     return QualType();
38
39   return GetQualType(ct).getCanonicalType();
40 }
41
42 CompilerType ClangUtil::RemoveFastQualifiers(const CompilerType &ct) {
43   if (!IsClangType(ct))
44     return ct;
45
46   QualType qual_type(GetQualType(ct));
47   qual_type.removeLocalFastQualifiers();
48   return CompilerType(ct.GetTypeSystem(), qual_type.getAsOpaquePtr());
49 }
50
51 clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) {
52   clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
53   if (qual_type.isNull())
54     return nullptr;
55
56   return qual_type->getAsTagDecl();
57 }