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
19 ClangUtil::IsClangType(const CompilerType &ct)
20 {
21     if (llvm::dyn_cast_or_null<ClangASTContext>(ct.GetTypeSystem()) == nullptr)
22         return false;
23 
24     if (!ct.GetOpaqueQualType())
25         return false;
26 
27     return true;
28 }
29 
30 QualType
31 ClangUtil::GetQualType(const CompilerType &ct)
32 {
33     // Make sure we have a clang type before making a clang::QualType
34     if (!IsClangType(ct))
35         return QualType();
36 
37     return QualType::getFromOpaquePtr(ct.GetOpaqueQualType());
38 }
39 
40 QualType
41 ClangUtil::GetCanonicalQualType(const CompilerType &ct)
42 {
43     if (!IsClangType(ct))
44         return QualType();
45 
46     return GetQualType(ct).getCanonicalType();
47 }
48 
49 CompilerType
50 ClangUtil::RemoveFastQualifiers(const CompilerType &ct)
51 {
52     if (!IsClangType(ct))
53         return ct;
54 
55     QualType qual_type(GetQualType(ct));
56     qual_type.removeLocalFastQualifiers();
57     return CompilerType(ct.GetTypeSystem(), qual_type.getAsOpaquePtr());
58 }
59