]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Symbol/ClangUtil.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Symbol / ClangUtil.cpp
1 //===-- ClangUtil.cpp -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 // A collection of helper methods and data structures for manipulating clang
9 // types and decls.
10 //===----------------------------------------------------------------------===//
11
12 #include "lldb/Symbol/ClangUtil.h"
13 #include "lldb/Symbol/ClangASTContext.h"
14
15 using namespace clang;
16 using namespace lldb_private;
17
18 bool ClangUtil::IsClangType(const CompilerType &ct) {
19   if (llvm::dyn_cast_or_null<ClangASTContext>(ct.GetTypeSystem()) == nullptr)
20     return false;
21
22   if (!ct.GetOpaqueQualType())
23     return false;
24
25   return true;
26 }
27
28 QualType ClangUtil::GetQualType(const CompilerType &ct) {
29   // Make sure we have a clang type before making a clang::QualType
30   if (!IsClangType(ct))
31     return QualType();
32
33   return QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
34 }
35
36 QualType ClangUtil::GetCanonicalQualType(const CompilerType &ct) {
37   if (!IsClangType(ct))
38     return QualType();
39
40   return GetQualType(ct).getCanonicalType();
41 }
42
43 CompilerType ClangUtil::RemoveFastQualifiers(const CompilerType &ct) {
44   if (!IsClangType(ct))
45     return ct;
46
47   QualType qual_type(GetQualType(ct));
48   qual_type.removeLocalFastQualifiers();
49   return CompilerType(ct.GetTypeSystem(), qual_type.getAsOpaquePtr());
50 }
51
52 clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) {
53   clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
54   if (qual_type.isNull())
55     return nullptr;
56
57   return qual_type->getAsTagDecl();
58 }